scan.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815
  1. /*
  2. * WPA Supplicant - Scanning
  3. * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "common/ieee802_11_defs.h"
  12. #include "common/wpa_ctrl.h"
  13. #include "config.h"
  14. #include "wpa_supplicant_i.h"
  15. #include "driver_i.h"
  16. #include "wps_supplicant.h"
  17. #include "p2p_supplicant.h"
  18. #include "p2p/p2p.h"
  19. #include "hs20_supplicant.h"
  20. #include "notify.h"
  21. #include "bss.h"
  22. #include "scan.h"
  23. #include "mesh.h"
  24. static void wpa_supplicant_gen_assoc_event(struct wpa_supplicant *wpa_s)
  25. {
  26. struct wpa_ssid *ssid;
  27. union wpa_event_data data;
  28. ssid = wpa_supplicant_get_ssid(wpa_s);
  29. if (ssid == NULL)
  30. return;
  31. if (wpa_s->current_ssid == NULL) {
  32. wpa_s->current_ssid = ssid;
  33. wpas_notify_network_changed(wpa_s);
  34. }
  35. wpa_supplicant_initiate_eapol(wpa_s);
  36. wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with a configured "
  37. "network - generating associated event");
  38. os_memset(&data, 0, sizeof(data));
  39. wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
  40. }
  41. #ifdef CONFIG_WPS
  42. static int wpas_wps_in_use(struct wpa_supplicant *wpa_s,
  43. enum wps_request_type *req_type)
  44. {
  45. struct wpa_ssid *ssid;
  46. int wps = 0;
  47. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  48. if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
  49. continue;
  50. wps = 1;
  51. *req_type = wpas_wps_get_req_type(ssid);
  52. if (ssid->eap.phase1 && os_strstr(ssid->eap.phase1, "pbc=1"))
  53. return 2;
  54. }
  55. #ifdef CONFIG_P2P
  56. if (!wpa_s->global->p2p_disabled && wpa_s->global->p2p &&
  57. !wpa_s->conf->p2p_disabled) {
  58. wpa_s->wps->dev.p2p = 1;
  59. if (!wps) {
  60. wps = 1;
  61. *req_type = WPS_REQ_ENROLLEE_INFO;
  62. }
  63. }
  64. #endif /* CONFIG_P2P */
  65. return wps;
  66. }
  67. #endif /* CONFIG_WPS */
  68. /**
  69. * wpa_supplicant_enabled_networks - Check whether there are enabled networks
  70. * @wpa_s: Pointer to wpa_supplicant data
  71. * Returns: 0 if no networks are enabled, >0 if networks are enabled
  72. *
  73. * This function is used to figure out whether any networks (or Interworking
  74. * with enabled credentials and auto_interworking) are present in the current
  75. * configuration.
  76. */
  77. int wpa_supplicant_enabled_networks(struct wpa_supplicant *wpa_s)
  78. {
  79. struct wpa_ssid *ssid = wpa_s->conf->ssid;
  80. int count = 0, disabled = 0;
  81. if (wpa_s->p2p_mgmt)
  82. return 0; /* no normal network profiles on p2p_mgmt interface */
  83. while (ssid) {
  84. if (!wpas_network_disabled(wpa_s, ssid))
  85. count++;
  86. else
  87. disabled++;
  88. ssid = ssid->next;
  89. }
  90. if (wpa_s->conf->cred && wpa_s->conf->interworking &&
  91. wpa_s->conf->auto_interworking)
  92. count++;
  93. if (count == 0 && disabled > 0) {
  94. wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks (%d disabled "
  95. "networks)", disabled);
  96. }
  97. return count;
  98. }
  99. static void wpa_supplicant_assoc_try(struct wpa_supplicant *wpa_s,
  100. struct wpa_ssid *ssid)
  101. {
  102. while (ssid) {
  103. if (!wpas_network_disabled(wpa_s, ssid))
  104. break;
  105. ssid = ssid->next;
  106. }
  107. /* ap_scan=2 mode - try to associate with each SSID. */
  108. if (ssid == NULL) {
  109. wpa_dbg(wpa_s, MSG_DEBUG, "wpa_supplicant_assoc_try: Reached "
  110. "end of scan list - go back to beginning");
  111. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  112. wpa_supplicant_req_scan(wpa_s, 0, 0);
  113. return;
  114. }
  115. if (ssid->next) {
  116. /* Continue from the next SSID on the next attempt. */
  117. wpa_s->prev_scan_ssid = ssid;
  118. } else {
  119. /* Start from the beginning of the SSID list. */
  120. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  121. }
  122. wpa_supplicant_associate(wpa_s, NULL, ssid);
  123. }
  124. static void wpas_trigger_scan_cb(struct wpa_radio_work *work, int deinit)
  125. {
  126. struct wpa_supplicant *wpa_s = work->wpa_s;
  127. struct wpa_driver_scan_params *params = work->ctx;
  128. int ret;
  129. if (deinit) {
  130. if (!work->started) {
  131. wpa_scan_free_params(params);
  132. return;
  133. }
  134. wpa_supplicant_notify_scanning(wpa_s, 0);
  135. wpas_notify_scan_done(wpa_s, 0);
  136. wpa_s->scan_work = NULL;
  137. return;
  138. }
  139. if (wpas_update_random_addr_disassoc(wpa_s) < 0) {
  140. wpa_msg(wpa_s, MSG_INFO,
  141. "Failed to assign random MAC address for a scan");
  142. wpa_scan_free_params(params);
  143. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_FAILED "ret=-1");
  144. radio_work_done(work);
  145. return;
  146. }
  147. wpa_supplicant_notify_scanning(wpa_s, 1);
  148. if (wpa_s->clear_driver_scan_cache) {
  149. wpa_printf(MSG_DEBUG,
  150. "Request driver to clear scan cache due to local BSS flush");
  151. params->only_new_results = 1;
  152. }
  153. ret = wpa_drv_scan(wpa_s, params);
  154. /*
  155. * Store the obtained vendor scan cookie (if any) in wpa_s context.
  156. * The current design is to allow only one scan request on each
  157. * interface, hence having this scan cookie stored in wpa_s context is
  158. * fine for now.
  159. *
  160. * Revisit this logic if concurrent scan operations per interface
  161. * is supported.
  162. */
  163. if (ret == 0)
  164. wpa_s->curr_scan_cookie = params->scan_cookie;
  165. wpa_scan_free_params(params);
  166. work->ctx = NULL;
  167. if (ret) {
  168. int retry = wpa_s->last_scan_req != MANUAL_SCAN_REQ;
  169. if (wpa_s->disconnected)
  170. retry = 0;
  171. wpa_supplicant_notify_scanning(wpa_s, 0);
  172. wpas_notify_scan_done(wpa_s, 0);
  173. if (wpa_s->wpa_state == WPA_SCANNING)
  174. wpa_supplicant_set_state(wpa_s,
  175. wpa_s->scan_prev_wpa_state);
  176. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_FAILED "ret=%d%s",
  177. ret, retry ? " retry=1" : "");
  178. radio_work_done(work);
  179. if (retry) {
  180. /* Restore scan_req since we will try to scan again */
  181. wpa_s->scan_req = wpa_s->last_scan_req;
  182. wpa_supplicant_req_scan(wpa_s, 1, 0);
  183. }
  184. return;
  185. }
  186. os_get_reltime(&wpa_s->scan_trigger_time);
  187. wpa_s->scan_runs++;
  188. wpa_s->normal_scans++;
  189. wpa_s->own_scan_requested = 1;
  190. wpa_s->clear_driver_scan_cache = 0;
  191. wpa_s->scan_work = work;
  192. }
  193. /**
  194. * wpa_supplicant_trigger_scan - Request driver to start a scan
  195. * @wpa_s: Pointer to wpa_supplicant data
  196. * @params: Scan parameters
  197. * Returns: 0 on success, -1 on failure
  198. */
  199. int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
  200. struct wpa_driver_scan_params *params)
  201. {
  202. struct wpa_driver_scan_params *ctx;
  203. if (wpa_s->scan_work) {
  204. wpa_dbg(wpa_s, MSG_INFO, "Reject scan trigger since one is already pending");
  205. return -1;
  206. }
  207. ctx = wpa_scan_clone_params(params);
  208. if (!ctx ||
  209. radio_add_work(wpa_s, 0, "scan", 0, wpas_trigger_scan_cb, ctx) < 0)
  210. {
  211. wpa_scan_free_params(ctx);
  212. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_FAILED "ret=-1");
  213. return -1;
  214. }
  215. return 0;
  216. }
  217. static void
  218. wpa_supplicant_delayed_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx)
  219. {
  220. struct wpa_supplicant *wpa_s = eloop_ctx;
  221. wpa_dbg(wpa_s, MSG_DEBUG, "Starting delayed sched scan");
  222. if (wpa_supplicant_req_sched_scan(wpa_s))
  223. wpa_supplicant_req_scan(wpa_s, 0, 0);
  224. }
  225. static void
  226. wpa_supplicant_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx)
  227. {
  228. struct wpa_supplicant *wpa_s = eloop_ctx;
  229. wpa_dbg(wpa_s, MSG_DEBUG, "Sched scan timeout - stopping it");
  230. wpa_s->sched_scan_timed_out = 1;
  231. wpa_supplicant_cancel_sched_scan(wpa_s);
  232. }
  233. static int
  234. wpa_supplicant_start_sched_scan(struct wpa_supplicant *wpa_s,
  235. struct wpa_driver_scan_params *params)
  236. {
  237. int ret;
  238. wpa_supplicant_notify_scanning(wpa_s, 1);
  239. ret = wpa_drv_sched_scan(wpa_s, params);
  240. if (ret)
  241. wpa_supplicant_notify_scanning(wpa_s, 0);
  242. else
  243. wpa_s->sched_scanning = 1;
  244. return ret;
  245. }
  246. static int wpa_supplicant_stop_sched_scan(struct wpa_supplicant *wpa_s)
  247. {
  248. int ret;
  249. ret = wpa_drv_stop_sched_scan(wpa_s);
  250. if (ret) {
  251. wpa_dbg(wpa_s, MSG_DEBUG, "stopping sched_scan failed!");
  252. /* TODO: what to do if stopping fails? */
  253. return -1;
  254. }
  255. return ret;
  256. }
  257. static struct wpa_driver_scan_filter *
  258. wpa_supplicant_build_filter_ssids(struct wpa_config *conf, size_t *num_ssids)
  259. {
  260. struct wpa_driver_scan_filter *ssids;
  261. struct wpa_ssid *ssid;
  262. size_t count;
  263. *num_ssids = 0;
  264. if (!conf->filter_ssids)
  265. return NULL;
  266. for (count = 0, ssid = conf->ssid; ssid; ssid = ssid->next) {
  267. if (ssid->ssid && ssid->ssid_len)
  268. count++;
  269. }
  270. if (count == 0)
  271. return NULL;
  272. ssids = os_calloc(count, sizeof(struct wpa_driver_scan_filter));
  273. if (ssids == NULL)
  274. return NULL;
  275. for (ssid = conf->ssid; ssid; ssid = ssid->next) {
  276. if (!ssid->ssid || !ssid->ssid_len)
  277. continue;
  278. os_memcpy(ssids[*num_ssids].ssid, ssid->ssid, ssid->ssid_len);
  279. ssids[*num_ssids].ssid_len = ssid->ssid_len;
  280. (*num_ssids)++;
  281. }
  282. return ssids;
  283. }
  284. static void wpa_supplicant_optimize_freqs(
  285. struct wpa_supplicant *wpa_s, struct wpa_driver_scan_params *params)
  286. {
  287. #ifdef CONFIG_P2P
  288. if (params->freqs == NULL && wpa_s->p2p_in_provisioning &&
  289. wpa_s->go_params) {
  290. /* Optimize provisioning state scan based on GO information */
  291. if (wpa_s->p2p_in_provisioning < 5 &&
  292. wpa_s->go_params->freq > 0) {
  293. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only GO "
  294. "preferred frequency %d MHz",
  295. wpa_s->go_params->freq);
  296. params->freqs = os_calloc(2, sizeof(int));
  297. if (params->freqs)
  298. params->freqs[0] = wpa_s->go_params->freq;
  299. } else if (wpa_s->p2p_in_provisioning < 8 &&
  300. wpa_s->go_params->freq_list[0]) {
  301. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only common "
  302. "channels");
  303. int_array_concat(&params->freqs,
  304. wpa_s->go_params->freq_list);
  305. if (params->freqs)
  306. int_array_sort_unique(params->freqs);
  307. }
  308. wpa_s->p2p_in_provisioning++;
  309. }
  310. if (params->freqs == NULL && wpa_s->p2p_in_invitation) {
  311. /*
  312. * Optimize scan based on GO information during persistent
  313. * group reinvocation
  314. */
  315. if (wpa_s->p2p_in_invitation < 5 &&
  316. wpa_s->p2p_invite_go_freq > 0) {
  317. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only GO preferred frequency %d MHz during invitation",
  318. wpa_s->p2p_invite_go_freq);
  319. params->freqs = os_calloc(2, sizeof(int));
  320. if (params->freqs)
  321. params->freqs[0] = wpa_s->p2p_invite_go_freq;
  322. }
  323. wpa_s->p2p_in_invitation++;
  324. if (wpa_s->p2p_in_invitation > 20) {
  325. /*
  326. * This should not really happen since the variable is
  327. * cleared on group removal, but if it does happen, make
  328. * sure we do not get stuck in special invitation scan
  329. * mode.
  330. */
  331. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Clear p2p_in_invitation");
  332. wpa_s->p2p_in_invitation = 0;
  333. }
  334. }
  335. #endif /* CONFIG_P2P */
  336. #ifdef CONFIG_WPS
  337. if (params->freqs == NULL && wpa_s->after_wps && wpa_s->wps_freq) {
  338. /*
  339. * Optimize post-provisioning scan based on channel used
  340. * during provisioning.
  341. */
  342. wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz "
  343. "that was used during provisioning", wpa_s->wps_freq);
  344. params->freqs = os_calloc(2, sizeof(int));
  345. if (params->freqs)
  346. params->freqs[0] = wpa_s->wps_freq;
  347. wpa_s->after_wps--;
  348. } else if (wpa_s->after_wps)
  349. wpa_s->after_wps--;
  350. if (params->freqs == NULL && wpa_s->known_wps_freq && wpa_s->wps_freq)
  351. {
  352. /* Optimize provisioning scan based on already known channel */
  353. wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz",
  354. wpa_s->wps_freq);
  355. params->freqs = os_calloc(2, sizeof(int));
  356. if (params->freqs)
  357. params->freqs[0] = wpa_s->wps_freq;
  358. wpa_s->known_wps_freq = 0; /* only do this once */
  359. }
  360. #endif /* CONFIG_WPS */
  361. }
  362. #ifdef CONFIG_INTERWORKING
  363. static void wpas_add_interworking_elements(struct wpa_supplicant *wpa_s,
  364. struct wpabuf *buf)
  365. {
  366. wpabuf_put_u8(buf, WLAN_EID_INTERWORKING);
  367. wpabuf_put_u8(buf, is_zero_ether_addr(wpa_s->conf->hessid) ? 1 :
  368. 1 + ETH_ALEN);
  369. wpabuf_put_u8(buf, wpa_s->conf->access_network_type);
  370. /* No Venue Info */
  371. if (!is_zero_ether_addr(wpa_s->conf->hessid))
  372. wpabuf_put_data(buf, wpa_s->conf->hessid, ETH_ALEN);
  373. }
  374. #endif /* CONFIG_INTERWORKING */
  375. void wpa_supplicant_set_default_scan_ies(struct wpa_supplicant *wpa_s)
  376. {
  377. struct wpabuf *default_ies = NULL;
  378. u8 ext_capab[18];
  379. int ext_capab_len;
  380. enum wpa_driver_if_type type = WPA_IF_STATION;
  381. #ifdef CONFIG_P2P
  382. if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT)
  383. type = WPA_IF_P2P_CLIENT;
  384. #endif /* CONFIG_P2P */
  385. wpa_drv_get_ext_capa(wpa_s, type);
  386. ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab,
  387. sizeof(ext_capab));
  388. if (ext_capab_len > 0 &&
  389. wpabuf_resize(&default_ies, ext_capab_len) == 0)
  390. wpabuf_put_data(default_ies, ext_capab, ext_capab_len);
  391. #ifdef CONFIG_MBO
  392. /* Send cellular capabilities for potential MBO STAs */
  393. if (wpabuf_resize(&default_ies, 9) == 0)
  394. wpas_mbo_scan_ie(wpa_s, default_ies);
  395. #endif /* CONFIG_MBO */
  396. if (default_ies)
  397. wpa_drv_set_default_scan_ies(wpa_s, wpabuf_head(default_ies),
  398. wpabuf_len(default_ies));
  399. wpabuf_free(default_ies);
  400. }
  401. static struct wpabuf * wpa_supplicant_extra_ies(struct wpa_supplicant *wpa_s)
  402. {
  403. struct wpabuf *extra_ie = NULL;
  404. u8 ext_capab[18];
  405. int ext_capab_len;
  406. #ifdef CONFIG_WPS
  407. int wps = 0;
  408. enum wps_request_type req_type = WPS_REQ_ENROLLEE_INFO;
  409. #endif /* CONFIG_WPS */
  410. #ifdef CONFIG_P2P
  411. if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT)
  412. wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_CLIENT);
  413. else
  414. #endif /* CONFIG_P2P */
  415. wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION);
  416. ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab,
  417. sizeof(ext_capab));
  418. if (ext_capab_len > 0 &&
  419. wpabuf_resize(&extra_ie, ext_capab_len) == 0)
  420. wpabuf_put_data(extra_ie, ext_capab, ext_capab_len);
  421. #ifdef CONFIG_INTERWORKING
  422. if (wpa_s->conf->interworking &&
  423. wpabuf_resize(&extra_ie, 100) == 0)
  424. wpas_add_interworking_elements(wpa_s, extra_ie);
  425. #endif /* CONFIG_INTERWORKING */
  426. #ifdef CONFIG_WPS
  427. wps = wpas_wps_in_use(wpa_s, &req_type);
  428. if (wps) {
  429. struct wpabuf *wps_ie;
  430. wps_ie = wps_build_probe_req_ie(wps == 2 ? DEV_PW_PUSHBUTTON :
  431. DEV_PW_DEFAULT,
  432. &wpa_s->wps->dev,
  433. wpa_s->wps->uuid, req_type,
  434. 0, NULL);
  435. if (wps_ie) {
  436. if (wpabuf_resize(&extra_ie, wpabuf_len(wps_ie)) == 0)
  437. wpabuf_put_buf(extra_ie, wps_ie);
  438. wpabuf_free(wps_ie);
  439. }
  440. }
  441. #ifdef CONFIG_P2P
  442. if (wps) {
  443. size_t ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
  444. if (wpabuf_resize(&extra_ie, ielen) == 0)
  445. wpas_p2p_scan_ie(wpa_s, extra_ie);
  446. }
  447. #endif /* CONFIG_P2P */
  448. wpa_supplicant_mesh_add_scan_ie(wpa_s, &extra_ie);
  449. #endif /* CONFIG_WPS */
  450. #ifdef CONFIG_HS20
  451. if (wpa_s->conf->hs20 && wpabuf_resize(&extra_ie, 7) == 0)
  452. wpas_hs20_add_indication(extra_ie, -1);
  453. #endif /* CONFIG_HS20 */
  454. #ifdef CONFIG_FST
  455. if (wpa_s->fst_ies &&
  456. wpabuf_resize(&extra_ie, wpabuf_len(wpa_s->fst_ies)) == 0)
  457. wpabuf_put_buf(extra_ie, wpa_s->fst_ies);
  458. #endif /* CONFIG_FST */
  459. #ifdef CONFIG_MBO
  460. /* Send cellular capabilities for potential MBO STAs */
  461. if (wpabuf_resize(&extra_ie, 9) == 0)
  462. wpas_mbo_scan_ie(wpa_s, extra_ie);
  463. #endif /* CONFIG_MBO */
  464. if (wpa_s->vendor_elem[VENDOR_ELEM_PROBE_REQ]) {
  465. struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_PROBE_REQ];
  466. if (wpabuf_resize(&extra_ie, wpabuf_len(buf)) == 0)
  467. wpabuf_put_buf(extra_ie, buf);
  468. }
  469. return extra_ie;
  470. }
  471. #ifdef CONFIG_P2P
  472. /*
  473. * Check whether there are any enabled networks or credentials that could be
  474. * used for a non-P2P connection.
  475. */
  476. static int non_p2p_network_enabled(struct wpa_supplicant *wpa_s)
  477. {
  478. struct wpa_ssid *ssid;
  479. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  480. if (wpas_network_disabled(wpa_s, ssid))
  481. continue;
  482. if (!ssid->p2p_group)
  483. return 1;
  484. }
  485. if (wpa_s->conf->cred && wpa_s->conf->interworking &&
  486. wpa_s->conf->auto_interworking)
  487. return 1;
  488. return 0;
  489. }
  490. #endif /* CONFIG_P2P */
  491. static void wpa_setband_scan_freqs_list(struct wpa_supplicant *wpa_s,
  492. enum hostapd_hw_mode band,
  493. struct wpa_driver_scan_params *params)
  494. {
  495. /* Include only supported channels for the specified band */
  496. struct hostapd_hw_modes *mode;
  497. int count, i;
  498. mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, band);
  499. if (mode == NULL) {
  500. /* No channels supported in this band - use empty list */
  501. params->freqs = os_zalloc(sizeof(int));
  502. return;
  503. }
  504. params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
  505. if (params->freqs == NULL)
  506. return;
  507. for (count = 0, i = 0; i < mode->num_channels; i++) {
  508. if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED)
  509. continue;
  510. params->freqs[count++] = mode->channels[i].freq;
  511. }
  512. }
  513. static void wpa_setband_scan_freqs(struct wpa_supplicant *wpa_s,
  514. struct wpa_driver_scan_params *params)
  515. {
  516. if (wpa_s->hw.modes == NULL)
  517. return; /* unknown what channels the driver supports */
  518. if (params->freqs)
  519. return; /* already using a limited channel set */
  520. if (wpa_s->setband == WPA_SETBAND_5G)
  521. wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A,
  522. params);
  523. else if (wpa_s->setband == WPA_SETBAND_2G)
  524. wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G,
  525. params);
  526. }
  527. static void wpa_set_scan_ssids(struct wpa_supplicant *wpa_s,
  528. struct wpa_driver_scan_params *params,
  529. size_t max_ssids)
  530. {
  531. unsigned int i;
  532. struct wpa_ssid *ssid;
  533. /*
  534. * For devices with max_ssids greater than 1, leave the last slot empty
  535. * for adding the wildcard scan entry.
  536. */
  537. max_ssids = max_ssids > 1 ? max_ssids - 1 : max_ssids;
  538. for (i = 0; i < wpa_s->scan_id_count; i++) {
  539. unsigned int j;
  540. ssid = wpa_config_get_network(wpa_s->conf, wpa_s->scan_id[i]);
  541. if (!ssid || !ssid->scan_ssid)
  542. continue;
  543. for (j = 0; j < params->num_ssids; j++) {
  544. if (params->ssids[j].ssid_len == ssid->ssid_len &&
  545. params->ssids[j].ssid &&
  546. os_memcmp(params->ssids[j].ssid, ssid->ssid,
  547. ssid->ssid_len) == 0)
  548. break;
  549. }
  550. if (j < params->num_ssids)
  551. continue; /* already in the list */
  552. if (params->num_ssids + 1 > max_ssids) {
  553. wpa_printf(MSG_DEBUG,
  554. "Over max scan SSIDs for manual request");
  555. break;
  556. }
  557. wpa_printf(MSG_DEBUG, "Scan SSID (manual request): %s",
  558. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  559. params->ssids[params->num_ssids].ssid = ssid->ssid;
  560. params->ssids[params->num_ssids].ssid_len = ssid->ssid_len;
  561. params->num_ssids++;
  562. }
  563. wpa_s->scan_id_count = 0;
  564. }
  565. static int wpa_set_ssids_from_scan_req(struct wpa_supplicant *wpa_s,
  566. struct wpa_driver_scan_params *params,
  567. size_t max_ssids)
  568. {
  569. unsigned int i;
  570. if (wpa_s->ssids_from_scan_req == NULL ||
  571. wpa_s->num_ssids_from_scan_req == 0)
  572. return 0;
  573. if (wpa_s->num_ssids_from_scan_req > max_ssids) {
  574. wpa_s->num_ssids_from_scan_req = max_ssids;
  575. wpa_printf(MSG_DEBUG, "Over max scan SSIDs from scan req: %u",
  576. (unsigned int) max_ssids);
  577. }
  578. for (i = 0; i < wpa_s->num_ssids_from_scan_req; i++) {
  579. params->ssids[i].ssid = wpa_s->ssids_from_scan_req[i].ssid;
  580. params->ssids[i].ssid_len =
  581. wpa_s->ssids_from_scan_req[i].ssid_len;
  582. wpa_hexdump_ascii(MSG_DEBUG, "specific SSID",
  583. params->ssids[i].ssid,
  584. params->ssids[i].ssid_len);
  585. }
  586. params->num_ssids = wpa_s->num_ssids_from_scan_req;
  587. wpa_s->num_ssids_from_scan_req = 0;
  588. return 1;
  589. }
  590. static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
  591. {
  592. struct wpa_supplicant *wpa_s = eloop_ctx;
  593. struct wpa_ssid *ssid;
  594. int ret, p2p_in_prog;
  595. struct wpabuf *extra_ie = NULL;
  596. struct wpa_driver_scan_params params;
  597. struct wpa_driver_scan_params *scan_params;
  598. size_t max_ssids;
  599. int connect_without_scan = 0;
  600. wpa_s->ignore_post_flush_scan_res = 0;
  601. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  602. wpa_dbg(wpa_s, MSG_DEBUG, "Skip scan - interface disabled");
  603. return;
  604. }
  605. if (wpa_s->disconnected && wpa_s->scan_req == NORMAL_SCAN_REQ) {
  606. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnected - do not scan");
  607. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  608. return;
  609. }
  610. if (wpa_s->scanning) {
  611. /*
  612. * If we are already in scanning state, we shall reschedule the
  613. * the incoming scan request.
  614. */
  615. wpa_dbg(wpa_s, MSG_DEBUG, "Already scanning - Reschedule the incoming scan req");
  616. wpa_supplicant_req_scan(wpa_s, 1, 0);
  617. return;
  618. }
  619. if (!wpa_supplicant_enabled_networks(wpa_s) &&
  620. wpa_s->scan_req == NORMAL_SCAN_REQ) {
  621. wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks - do not scan");
  622. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  623. return;
  624. }
  625. if (wpa_s->conf->ap_scan != 0 &&
  626. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) {
  627. wpa_dbg(wpa_s, MSG_DEBUG, "Using wired authentication - "
  628. "overriding ap_scan configuration");
  629. wpa_s->conf->ap_scan = 0;
  630. wpas_notify_ap_scan_changed(wpa_s);
  631. }
  632. if (wpa_s->conf->ap_scan == 0) {
  633. wpa_supplicant_gen_assoc_event(wpa_s);
  634. return;
  635. }
  636. ssid = NULL;
  637. if (wpa_s->scan_req != MANUAL_SCAN_REQ &&
  638. wpa_s->connect_without_scan) {
  639. connect_without_scan = 1;
  640. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  641. if (ssid == wpa_s->connect_without_scan)
  642. break;
  643. }
  644. }
  645. p2p_in_prog = wpas_p2p_in_progress(wpa_s);
  646. if (p2p_in_prog && p2p_in_prog != 2 &&
  647. (!ssid ||
  648. (ssid->mode != WPAS_MODE_AP && ssid->mode != WPAS_MODE_P2P_GO))) {
  649. wpa_dbg(wpa_s, MSG_DEBUG, "Delay station mode scan while P2P operation is in progress");
  650. wpa_supplicant_req_scan(wpa_s, 5, 0);
  651. return;
  652. }
  653. /*
  654. * Don't cancel the scan based on ongoing PNO; defer it. Some scans are
  655. * used for changing modes inside wpa_supplicant (roaming,
  656. * auto-reconnect, etc). Discarding the scan might hurt these processes.
  657. * The normal use case for PNO is to suspend the host immediately after
  658. * starting PNO, so the periodic 100 ms attempts to run the scan do not
  659. * normally happen in practice multiple times, i.e., this is simply
  660. * restarting scanning once the host is woken up and PNO stopped.
  661. */
  662. if (wpa_s->pno || wpa_s->pno_sched_pending) {
  663. wpa_dbg(wpa_s, MSG_DEBUG, "Defer scan - PNO is in progress");
  664. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  665. return;
  666. }
  667. if (wpa_s->conf->ap_scan == 2)
  668. max_ssids = 1;
  669. else {
  670. max_ssids = wpa_s->max_scan_ssids;
  671. if (max_ssids > WPAS_MAX_SCAN_SSIDS)
  672. max_ssids = WPAS_MAX_SCAN_SSIDS;
  673. }
  674. wpa_s->last_scan_req = wpa_s->scan_req;
  675. wpa_s->scan_req = NORMAL_SCAN_REQ;
  676. if (connect_without_scan) {
  677. wpa_s->connect_without_scan = NULL;
  678. if (ssid) {
  679. wpa_printf(MSG_DEBUG, "Start a pre-selected network "
  680. "without scan step");
  681. wpa_supplicant_associate(wpa_s, NULL, ssid);
  682. return;
  683. }
  684. }
  685. os_memset(&params, 0, sizeof(params));
  686. wpa_s->scan_prev_wpa_state = wpa_s->wpa_state;
  687. if (wpa_s->wpa_state == WPA_DISCONNECTED ||
  688. wpa_s->wpa_state == WPA_INACTIVE)
  689. wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
  690. /*
  691. * If autoscan has set its own scanning parameters
  692. */
  693. if (wpa_s->autoscan_params != NULL) {
  694. scan_params = wpa_s->autoscan_params;
  695. goto scan;
  696. }
  697. if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
  698. wpa_set_ssids_from_scan_req(wpa_s, &params, max_ssids)) {
  699. wpa_printf(MSG_DEBUG, "Use specific SSIDs from SCAN command");
  700. goto ssid_list_set;
  701. }
  702. #ifdef CONFIG_P2P
  703. if ((wpa_s->p2p_in_provisioning || wpa_s->show_group_started) &&
  704. wpa_s->go_params && !wpa_s->conf->passive_scan) {
  705. wpa_printf(MSG_DEBUG, "P2P: Use specific SSID for scan during P2P group formation (p2p_in_provisioning=%d show_group_started=%d)",
  706. wpa_s->p2p_in_provisioning,
  707. wpa_s->show_group_started);
  708. params.ssids[0].ssid = wpa_s->go_params->ssid;
  709. params.ssids[0].ssid_len = wpa_s->go_params->ssid_len;
  710. params.num_ssids = 1;
  711. goto ssid_list_set;
  712. }
  713. if (wpa_s->p2p_in_invitation) {
  714. if (wpa_s->current_ssid) {
  715. wpa_printf(MSG_DEBUG, "P2P: Use specific SSID for scan during invitation");
  716. params.ssids[0].ssid = wpa_s->current_ssid->ssid;
  717. params.ssids[0].ssid_len =
  718. wpa_s->current_ssid->ssid_len;
  719. params.num_ssids = 1;
  720. } else {
  721. wpa_printf(MSG_DEBUG, "P2P: No specific SSID known for scan during invitation");
  722. }
  723. goto ssid_list_set;
  724. }
  725. #endif /* CONFIG_P2P */
  726. /* Find the starting point from which to continue scanning */
  727. ssid = wpa_s->conf->ssid;
  728. if (wpa_s->prev_scan_ssid != WILDCARD_SSID_SCAN) {
  729. while (ssid) {
  730. if (ssid == wpa_s->prev_scan_ssid) {
  731. ssid = ssid->next;
  732. break;
  733. }
  734. ssid = ssid->next;
  735. }
  736. }
  737. if (wpa_s->last_scan_req != MANUAL_SCAN_REQ &&
  738. #ifdef CONFIG_AP
  739. !wpa_s->ap_iface &&
  740. #endif /* CONFIG_AP */
  741. wpa_s->conf->ap_scan == 2) {
  742. wpa_s->connect_without_scan = NULL;
  743. wpa_s->prev_scan_wildcard = 0;
  744. wpa_supplicant_assoc_try(wpa_s, ssid);
  745. return;
  746. } else if (wpa_s->conf->ap_scan == 2) {
  747. /*
  748. * User-initiated scan request in ap_scan == 2; scan with
  749. * wildcard SSID.
  750. */
  751. ssid = NULL;
  752. } else if (wpa_s->reattach && wpa_s->current_ssid != NULL) {
  753. /*
  754. * Perform single-channel single-SSID scan for
  755. * reassociate-to-same-BSS operation.
  756. */
  757. /* Setup SSID */
  758. ssid = wpa_s->current_ssid;
  759. wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID",
  760. ssid->ssid, ssid->ssid_len);
  761. params.ssids[0].ssid = ssid->ssid;
  762. params.ssids[0].ssid_len = ssid->ssid_len;
  763. params.num_ssids = 1;
  764. /*
  765. * Allocate memory for frequency array, allocate one extra
  766. * slot for the zero-terminator.
  767. */
  768. params.freqs = os_malloc(sizeof(int) * 2);
  769. if (params.freqs) {
  770. params.freqs[0] = wpa_s->assoc_freq;
  771. params.freqs[1] = 0;
  772. }
  773. /*
  774. * Reset the reattach flag so that we fall back to full scan if
  775. * this scan fails.
  776. */
  777. wpa_s->reattach = 0;
  778. } else {
  779. struct wpa_ssid *start = ssid, *tssid;
  780. int freqs_set = 0;
  781. if (ssid == NULL && max_ssids > 1)
  782. ssid = wpa_s->conf->ssid;
  783. while (ssid) {
  784. if (!wpas_network_disabled(wpa_s, ssid) &&
  785. ssid->scan_ssid) {
  786. wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID",
  787. ssid->ssid, ssid->ssid_len);
  788. params.ssids[params.num_ssids].ssid =
  789. ssid->ssid;
  790. params.ssids[params.num_ssids].ssid_len =
  791. ssid->ssid_len;
  792. params.num_ssids++;
  793. if (params.num_ssids + 1 >= max_ssids)
  794. break;
  795. }
  796. ssid = ssid->next;
  797. if (ssid == start)
  798. break;
  799. if (ssid == NULL && max_ssids > 1 &&
  800. start != wpa_s->conf->ssid)
  801. ssid = wpa_s->conf->ssid;
  802. }
  803. if (wpa_s->scan_id_count &&
  804. wpa_s->last_scan_req == MANUAL_SCAN_REQ)
  805. wpa_set_scan_ssids(wpa_s, &params, max_ssids);
  806. for (tssid = wpa_s->conf->ssid;
  807. wpa_s->last_scan_req != MANUAL_SCAN_REQ && tssid;
  808. tssid = tssid->next) {
  809. if (wpas_network_disabled(wpa_s, tssid))
  810. continue;
  811. if ((params.freqs || !freqs_set) && tssid->scan_freq) {
  812. int_array_concat(&params.freqs,
  813. tssid->scan_freq);
  814. } else {
  815. os_free(params.freqs);
  816. params.freqs = NULL;
  817. }
  818. freqs_set = 1;
  819. }
  820. int_array_sort_unique(params.freqs);
  821. }
  822. if (ssid && max_ssids == 1) {
  823. /*
  824. * If the driver is limited to 1 SSID at a time interleave
  825. * wildcard SSID scans with specific SSID scans to avoid
  826. * waiting a long time for a wildcard scan.
  827. */
  828. if (!wpa_s->prev_scan_wildcard) {
  829. params.ssids[0].ssid = NULL;
  830. params.ssids[0].ssid_len = 0;
  831. wpa_s->prev_scan_wildcard = 1;
  832. wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for "
  833. "wildcard SSID (Interleave with specific)");
  834. } else {
  835. wpa_s->prev_scan_ssid = ssid;
  836. wpa_s->prev_scan_wildcard = 0;
  837. wpa_dbg(wpa_s, MSG_DEBUG,
  838. "Starting AP scan for specific SSID: %s",
  839. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  840. }
  841. } else if (ssid) {
  842. /* max_ssids > 1 */
  843. wpa_s->prev_scan_ssid = ssid;
  844. wpa_dbg(wpa_s, MSG_DEBUG, "Include wildcard SSID in "
  845. "the scan request");
  846. params.num_ssids++;
  847. } else if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
  848. wpa_s->manual_scan_passive && params.num_ssids == 0) {
  849. wpa_dbg(wpa_s, MSG_DEBUG, "Use passive scan based on manual request");
  850. } else if (wpa_s->conf->passive_scan) {
  851. wpa_dbg(wpa_s, MSG_DEBUG,
  852. "Use passive scan based on configuration");
  853. } else {
  854. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  855. params.num_ssids++;
  856. wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for wildcard "
  857. "SSID");
  858. }
  859. ssid_list_set:
  860. wpa_supplicant_optimize_freqs(wpa_s, &params);
  861. extra_ie = wpa_supplicant_extra_ies(wpa_s);
  862. if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
  863. wpa_s->manual_scan_only_new) {
  864. wpa_printf(MSG_DEBUG,
  865. "Request driver to clear scan cache due to manual only_new=1 scan");
  866. params.only_new_results = 1;
  867. }
  868. if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && params.freqs == NULL &&
  869. wpa_s->manual_scan_freqs) {
  870. wpa_dbg(wpa_s, MSG_DEBUG, "Limit manual scan to specified channels");
  871. params.freqs = wpa_s->manual_scan_freqs;
  872. wpa_s->manual_scan_freqs = NULL;
  873. }
  874. if (params.freqs == NULL && wpa_s->next_scan_freqs) {
  875. wpa_dbg(wpa_s, MSG_DEBUG, "Optimize scan based on previously "
  876. "generated frequency list");
  877. params.freqs = wpa_s->next_scan_freqs;
  878. } else
  879. os_free(wpa_s->next_scan_freqs);
  880. wpa_s->next_scan_freqs = NULL;
  881. wpa_setband_scan_freqs(wpa_s, &params);
  882. /* See if user specified frequencies. If so, scan only those. */
  883. if (wpa_s->conf->freq_list && !params.freqs) {
  884. wpa_dbg(wpa_s, MSG_DEBUG,
  885. "Optimize scan based on conf->freq_list");
  886. int_array_concat(&params.freqs, wpa_s->conf->freq_list);
  887. }
  888. /* Use current associated channel? */
  889. if (wpa_s->conf->scan_cur_freq && !params.freqs) {
  890. unsigned int num = wpa_s->num_multichan_concurrent;
  891. params.freqs = os_calloc(num + 1, sizeof(int));
  892. if (params.freqs) {
  893. num = get_shared_radio_freqs(wpa_s, params.freqs, num);
  894. if (num > 0) {
  895. wpa_dbg(wpa_s, MSG_DEBUG, "Scan only the "
  896. "current operating channels since "
  897. "scan_cur_freq is enabled");
  898. } else {
  899. os_free(params.freqs);
  900. params.freqs = NULL;
  901. }
  902. }
  903. }
  904. params.filter_ssids = wpa_supplicant_build_filter_ssids(
  905. wpa_s->conf, &params.num_filter_ssids);
  906. if (extra_ie) {
  907. params.extra_ies = wpabuf_head(extra_ie);
  908. params.extra_ies_len = wpabuf_len(extra_ie);
  909. }
  910. #ifdef CONFIG_P2P
  911. if (wpa_s->p2p_in_provisioning || wpa_s->p2p_in_invitation ||
  912. (wpa_s->show_group_started && wpa_s->go_params)) {
  913. /*
  914. * The interface may not yet be in P2P mode, so we have to
  915. * explicitly request P2P probe to disable CCK rates.
  916. */
  917. params.p2p_probe = 1;
  918. }
  919. #endif /* CONFIG_P2P */
  920. if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCAN) &&
  921. wpa_s->wpa_state <= WPA_SCANNING) {
  922. params.mac_addr_rand = 1;
  923. if (wpa_s->mac_addr_scan) {
  924. params.mac_addr = wpa_s->mac_addr_scan;
  925. params.mac_addr_mask = wpa_s->mac_addr_scan + ETH_ALEN;
  926. }
  927. }
  928. if (!is_zero_ether_addr(wpa_s->next_scan_bssid)) {
  929. struct wpa_bss *bss;
  930. params.bssid = wpa_s->next_scan_bssid;
  931. bss = wpa_bss_get_bssid_latest(wpa_s, params.bssid);
  932. if (bss && bss->ssid_len && params.num_ssids == 1 &&
  933. params.ssids[0].ssid_len == 0) {
  934. params.ssids[0].ssid = bss->ssid;
  935. params.ssids[0].ssid_len = bss->ssid_len;
  936. wpa_dbg(wpa_s, MSG_DEBUG,
  937. "Scan a previously specified BSSID " MACSTR
  938. " and SSID %s",
  939. MAC2STR(params.bssid),
  940. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  941. } else {
  942. wpa_dbg(wpa_s, MSG_DEBUG,
  943. "Scan a previously specified BSSID " MACSTR,
  944. MAC2STR(params.bssid));
  945. }
  946. }
  947. scan_params = &params;
  948. scan:
  949. #ifdef CONFIG_P2P
  950. /*
  951. * If the driver does not support multi-channel concurrency and a
  952. * virtual interface that shares the same radio with the wpa_s interface
  953. * is operating there may not be need to scan other channels apart from
  954. * the current operating channel on the other virtual interface. Filter
  955. * out other channels in case we are trying to find a connection for a
  956. * station interface when we are not configured to prefer station
  957. * connection and a concurrent operation is already in process.
  958. */
  959. if (wpa_s->scan_for_connection &&
  960. wpa_s->last_scan_req == NORMAL_SCAN_REQ &&
  961. !scan_params->freqs && !params.freqs &&
  962. wpas_is_p2p_prioritized(wpa_s) &&
  963. wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE &&
  964. non_p2p_network_enabled(wpa_s)) {
  965. unsigned int num = wpa_s->num_multichan_concurrent;
  966. params.freqs = os_calloc(num + 1, sizeof(int));
  967. if (params.freqs) {
  968. num = get_shared_radio_freqs(wpa_s, params.freqs, num);
  969. if (num > 0 && num == wpa_s->num_multichan_concurrent) {
  970. wpa_dbg(wpa_s, MSG_DEBUG, "Scan only the current operating channels since all channels are already used");
  971. } else {
  972. os_free(params.freqs);
  973. params.freqs = NULL;
  974. }
  975. }
  976. }
  977. #endif /* CONFIG_P2P */
  978. ret = wpa_supplicant_trigger_scan(wpa_s, scan_params);
  979. if (ret && wpa_s->last_scan_req == MANUAL_SCAN_REQ && params.freqs &&
  980. !wpa_s->manual_scan_freqs) {
  981. /* Restore manual_scan_freqs for the next attempt */
  982. wpa_s->manual_scan_freqs = params.freqs;
  983. params.freqs = NULL;
  984. }
  985. wpabuf_free(extra_ie);
  986. os_free(params.freqs);
  987. os_free(params.filter_ssids);
  988. if (ret) {
  989. wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate AP scan");
  990. if (wpa_s->scan_prev_wpa_state != wpa_s->wpa_state)
  991. wpa_supplicant_set_state(wpa_s,
  992. wpa_s->scan_prev_wpa_state);
  993. /* Restore scan_req since we will try to scan again */
  994. wpa_s->scan_req = wpa_s->last_scan_req;
  995. wpa_supplicant_req_scan(wpa_s, 1, 0);
  996. } else {
  997. wpa_s->scan_for_connection = 0;
  998. #ifdef CONFIG_INTERWORKING
  999. wpa_s->interworking_fast_assoc_tried = 0;
  1000. #endif /* CONFIG_INTERWORKING */
  1001. if (params.bssid)
  1002. os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
  1003. }
  1004. }
  1005. void wpa_supplicant_update_scan_int(struct wpa_supplicant *wpa_s, int sec)
  1006. {
  1007. struct os_reltime remaining, new_int;
  1008. int cancelled;
  1009. cancelled = eloop_cancel_timeout_one(wpa_supplicant_scan, wpa_s, NULL,
  1010. &remaining);
  1011. new_int.sec = sec;
  1012. new_int.usec = 0;
  1013. if (cancelled && os_reltime_before(&remaining, &new_int)) {
  1014. new_int.sec = remaining.sec;
  1015. new_int.usec = remaining.usec;
  1016. }
  1017. if (cancelled) {
  1018. eloop_register_timeout(new_int.sec, new_int.usec,
  1019. wpa_supplicant_scan, wpa_s, NULL);
  1020. }
  1021. wpa_s->scan_interval = sec;
  1022. }
  1023. /**
  1024. * wpa_supplicant_req_scan - Schedule a scan for neighboring access points
  1025. * @wpa_s: Pointer to wpa_supplicant data
  1026. * @sec: Number of seconds after which to scan
  1027. * @usec: Number of microseconds after which to scan
  1028. *
  1029. * This function is used to schedule a scan for neighboring access points after
  1030. * the specified time.
  1031. */
  1032. void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec)
  1033. {
  1034. int res;
  1035. if (wpa_s->p2p_mgmt) {
  1036. wpa_dbg(wpa_s, MSG_DEBUG,
  1037. "Ignore scan request (%d.%06d sec) on p2p_mgmt interface",
  1038. sec, usec);
  1039. return;
  1040. }
  1041. res = eloop_deplete_timeout(sec, usec, wpa_supplicant_scan, wpa_s,
  1042. NULL);
  1043. if (res == 1) {
  1044. wpa_dbg(wpa_s, MSG_DEBUG, "Rescheduling scan request: %d.%06d sec",
  1045. sec, usec);
  1046. } else if (res == 0) {
  1047. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore new scan request for %d.%06d sec since an earlier request is scheduled to trigger sooner",
  1048. sec, usec);
  1049. } else {
  1050. wpa_dbg(wpa_s, MSG_DEBUG, "Setting scan request: %d.%06d sec",
  1051. sec, usec);
  1052. eloop_register_timeout(sec, usec, wpa_supplicant_scan, wpa_s, NULL);
  1053. }
  1054. }
  1055. /**
  1056. * wpa_supplicant_delayed_sched_scan - Request a delayed scheduled scan
  1057. * @wpa_s: Pointer to wpa_supplicant data
  1058. * @sec: Number of seconds after which to scan
  1059. * @usec: Number of microseconds after which to scan
  1060. * Returns: 0 on success or -1 otherwise
  1061. *
  1062. * This function is used to schedule periodic scans for neighboring
  1063. * access points after the specified time.
  1064. */
  1065. int wpa_supplicant_delayed_sched_scan(struct wpa_supplicant *wpa_s,
  1066. int sec, int usec)
  1067. {
  1068. if (!wpa_s->sched_scan_supported)
  1069. return -1;
  1070. eloop_register_timeout(sec, usec,
  1071. wpa_supplicant_delayed_sched_scan_timeout,
  1072. wpa_s, NULL);
  1073. return 0;
  1074. }
  1075. /**
  1076. * wpa_supplicant_req_sched_scan - Start a periodic scheduled scan
  1077. * @wpa_s: Pointer to wpa_supplicant data
  1078. * Returns: 0 is sched_scan was started or -1 otherwise
  1079. *
  1080. * This function is used to schedule periodic scans for neighboring
  1081. * access points repeating the scan continuously.
  1082. */
  1083. int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s)
  1084. {
  1085. struct wpa_driver_scan_params params;
  1086. struct wpa_driver_scan_params *scan_params;
  1087. enum wpa_states prev_state;
  1088. struct wpa_ssid *ssid = NULL;
  1089. struct wpabuf *extra_ie = NULL;
  1090. int ret;
  1091. unsigned int max_sched_scan_ssids;
  1092. int wildcard = 0;
  1093. int need_ssids;
  1094. struct sched_scan_plan scan_plan;
  1095. if (!wpa_s->sched_scan_supported)
  1096. return -1;
  1097. if (wpa_s->max_sched_scan_ssids > WPAS_MAX_SCAN_SSIDS)
  1098. max_sched_scan_ssids = WPAS_MAX_SCAN_SSIDS;
  1099. else
  1100. max_sched_scan_ssids = wpa_s->max_sched_scan_ssids;
  1101. if (max_sched_scan_ssids < 1 || wpa_s->conf->disable_scan_offload)
  1102. return -1;
  1103. wpa_s->sched_scan_stop_req = 0;
  1104. if (wpa_s->sched_scanning) {
  1105. wpa_dbg(wpa_s, MSG_DEBUG, "Already sched scanning");
  1106. return 0;
  1107. }
  1108. need_ssids = 0;
  1109. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  1110. if (!wpas_network_disabled(wpa_s, ssid) && !ssid->scan_ssid) {
  1111. /* Use wildcard SSID to find this network */
  1112. wildcard = 1;
  1113. } else if (!wpas_network_disabled(wpa_s, ssid) &&
  1114. ssid->ssid_len)
  1115. need_ssids++;
  1116. #ifdef CONFIG_WPS
  1117. if (!wpas_network_disabled(wpa_s, ssid) &&
  1118. ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  1119. /*
  1120. * Normal scan is more reliable and faster for WPS
  1121. * operations and since these are for short periods of
  1122. * time, the benefit of trying to use sched_scan would
  1123. * be limited.
  1124. */
  1125. wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of "
  1126. "sched_scan for WPS");
  1127. return -1;
  1128. }
  1129. #endif /* CONFIG_WPS */
  1130. }
  1131. if (wildcard)
  1132. need_ssids++;
  1133. if (wpa_s->normal_scans < 3 &&
  1134. (need_ssids <= wpa_s->max_scan_ssids ||
  1135. wpa_s->max_scan_ssids >= (int) max_sched_scan_ssids)) {
  1136. /*
  1137. * When normal scan can speed up operations, use that for the
  1138. * first operations before starting the sched_scan to allow
  1139. * user space sleep more. We do this only if the normal scan
  1140. * has functionality that is suitable for this or if the
  1141. * sched_scan does not have better support for multiple SSIDs.
  1142. */
  1143. wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of "
  1144. "sched_scan for initial scans (normal_scans=%d)",
  1145. wpa_s->normal_scans);
  1146. return -1;
  1147. }
  1148. os_memset(&params, 0, sizeof(params));
  1149. /* If we can't allocate space for the filters, we just don't filter */
  1150. params.filter_ssids = os_calloc(wpa_s->max_match_sets,
  1151. sizeof(struct wpa_driver_scan_filter));
  1152. prev_state = wpa_s->wpa_state;
  1153. if (wpa_s->wpa_state == WPA_DISCONNECTED ||
  1154. wpa_s->wpa_state == WPA_INACTIVE)
  1155. wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
  1156. if (wpa_s->autoscan_params != NULL) {
  1157. scan_params = wpa_s->autoscan_params;
  1158. goto scan;
  1159. }
  1160. /* Find the starting point from which to continue scanning */
  1161. ssid = wpa_s->conf->ssid;
  1162. if (wpa_s->prev_sched_ssid) {
  1163. while (ssid) {
  1164. if (ssid == wpa_s->prev_sched_ssid) {
  1165. ssid = ssid->next;
  1166. break;
  1167. }
  1168. ssid = ssid->next;
  1169. }
  1170. }
  1171. if (!ssid || !wpa_s->prev_sched_ssid) {
  1172. wpa_dbg(wpa_s, MSG_DEBUG, "Beginning of SSID list");
  1173. wpa_s->sched_scan_timeout = max_sched_scan_ssids * 2;
  1174. wpa_s->first_sched_scan = 1;
  1175. ssid = wpa_s->conf->ssid;
  1176. wpa_s->prev_sched_ssid = ssid;
  1177. }
  1178. if (wildcard) {
  1179. wpa_dbg(wpa_s, MSG_DEBUG, "Add wildcard SSID to sched_scan");
  1180. params.num_ssids++;
  1181. }
  1182. while (ssid) {
  1183. if (wpas_network_disabled(wpa_s, ssid))
  1184. goto next;
  1185. if (params.num_filter_ssids < wpa_s->max_match_sets &&
  1186. params.filter_ssids && ssid->ssid && ssid->ssid_len) {
  1187. wpa_dbg(wpa_s, MSG_DEBUG, "add to filter ssid: %s",
  1188. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1189. os_memcpy(params.filter_ssids[params.num_filter_ssids].ssid,
  1190. ssid->ssid, ssid->ssid_len);
  1191. params.filter_ssids[params.num_filter_ssids].ssid_len =
  1192. ssid->ssid_len;
  1193. params.num_filter_ssids++;
  1194. } else if (params.filter_ssids && ssid->ssid && ssid->ssid_len)
  1195. {
  1196. wpa_dbg(wpa_s, MSG_DEBUG, "Not enough room for SSID "
  1197. "filter for sched_scan - drop filter");
  1198. os_free(params.filter_ssids);
  1199. params.filter_ssids = NULL;
  1200. params.num_filter_ssids = 0;
  1201. }
  1202. if (ssid->scan_ssid && ssid->ssid && ssid->ssid_len) {
  1203. if (params.num_ssids == max_sched_scan_ssids)
  1204. break; /* only room for broadcast SSID */
  1205. wpa_dbg(wpa_s, MSG_DEBUG,
  1206. "add to active scan ssid: %s",
  1207. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1208. params.ssids[params.num_ssids].ssid =
  1209. ssid->ssid;
  1210. params.ssids[params.num_ssids].ssid_len =
  1211. ssid->ssid_len;
  1212. params.num_ssids++;
  1213. if (params.num_ssids >= max_sched_scan_ssids) {
  1214. wpa_s->prev_sched_ssid = ssid;
  1215. do {
  1216. ssid = ssid->next;
  1217. } while (ssid &&
  1218. (wpas_network_disabled(wpa_s, ssid) ||
  1219. !ssid->scan_ssid));
  1220. break;
  1221. }
  1222. }
  1223. next:
  1224. wpa_s->prev_sched_ssid = ssid;
  1225. ssid = ssid->next;
  1226. }
  1227. if (params.num_filter_ssids == 0) {
  1228. os_free(params.filter_ssids);
  1229. params.filter_ssids = NULL;
  1230. }
  1231. extra_ie = wpa_supplicant_extra_ies(wpa_s);
  1232. if (extra_ie) {
  1233. params.extra_ies = wpabuf_head(extra_ie);
  1234. params.extra_ies_len = wpabuf_len(extra_ie);
  1235. }
  1236. if (wpa_s->conf->filter_rssi)
  1237. params.filter_rssi = wpa_s->conf->filter_rssi;
  1238. /* See if user specified frequencies. If so, scan only those. */
  1239. if (wpa_s->conf->freq_list && !params.freqs) {
  1240. wpa_dbg(wpa_s, MSG_DEBUG,
  1241. "Optimize scan based on conf->freq_list");
  1242. int_array_concat(&params.freqs, wpa_s->conf->freq_list);
  1243. }
  1244. scan_params = &params;
  1245. scan:
  1246. wpa_s->sched_scan_timed_out = 0;
  1247. /*
  1248. * We cannot support multiple scan plans if the scan request includes
  1249. * too many SSID's, so in this case use only the last scan plan and make
  1250. * it run infinitely. It will be stopped by the timeout.
  1251. */
  1252. if (wpa_s->sched_scan_plans_num == 1 ||
  1253. (wpa_s->sched_scan_plans_num && !ssid && wpa_s->first_sched_scan)) {
  1254. params.sched_scan_plans = wpa_s->sched_scan_plans;
  1255. params.sched_scan_plans_num = wpa_s->sched_scan_plans_num;
  1256. } else if (wpa_s->sched_scan_plans_num > 1) {
  1257. wpa_dbg(wpa_s, MSG_DEBUG,
  1258. "Too many SSIDs. Default to using single scheduled_scan plan");
  1259. params.sched_scan_plans =
  1260. &wpa_s->sched_scan_plans[wpa_s->sched_scan_plans_num -
  1261. 1];
  1262. params.sched_scan_plans_num = 1;
  1263. } else {
  1264. if (wpa_s->conf->sched_scan_interval)
  1265. scan_plan.interval = wpa_s->conf->sched_scan_interval;
  1266. else
  1267. scan_plan.interval = 10;
  1268. if (scan_plan.interval > wpa_s->max_sched_scan_plan_interval) {
  1269. wpa_printf(MSG_WARNING,
  1270. "Scan interval too long(%u), use the maximum allowed(%u)",
  1271. scan_plan.interval,
  1272. wpa_s->max_sched_scan_plan_interval);
  1273. scan_plan.interval =
  1274. wpa_s->max_sched_scan_plan_interval;
  1275. }
  1276. scan_plan.iterations = 0;
  1277. params.sched_scan_plans = &scan_plan;
  1278. params.sched_scan_plans_num = 1;
  1279. }
  1280. if (ssid || !wpa_s->first_sched_scan) {
  1281. wpa_dbg(wpa_s, MSG_DEBUG,
  1282. "Starting sched scan: interval %u timeout %d",
  1283. params.sched_scan_plans[0].interval,
  1284. wpa_s->sched_scan_timeout);
  1285. } else {
  1286. wpa_dbg(wpa_s, MSG_DEBUG, "Starting sched scan (no timeout)");
  1287. }
  1288. wpa_setband_scan_freqs(wpa_s, scan_params);
  1289. if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCHED_SCAN) &&
  1290. wpa_s->wpa_state <= WPA_SCANNING) {
  1291. params.mac_addr_rand = 1;
  1292. if (wpa_s->mac_addr_sched_scan) {
  1293. params.mac_addr = wpa_s->mac_addr_sched_scan;
  1294. params.mac_addr_mask = wpa_s->mac_addr_sched_scan +
  1295. ETH_ALEN;
  1296. }
  1297. }
  1298. ret = wpa_supplicant_start_sched_scan(wpa_s, scan_params);
  1299. wpabuf_free(extra_ie);
  1300. os_free(params.filter_ssids);
  1301. if (ret) {
  1302. wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate sched scan");
  1303. if (prev_state != wpa_s->wpa_state)
  1304. wpa_supplicant_set_state(wpa_s, prev_state);
  1305. return ret;
  1306. }
  1307. /* If we have more SSIDs to scan, add a timeout so we scan them too */
  1308. if (ssid || !wpa_s->first_sched_scan) {
  1309. wpa_s->sched_scan_timed_out = 0;
  1310. eloop_register_timeout(wpa_s->sched_scan_timeout, 0,
  1311. wpa_supplicant_sched_scan_timeout,
  1312. wpa_s, NULL);
  1313. wpa_s->first_sched_scan = 0;
  1314. wpa_s->sched_scan_timeout /= 2;
  1315. params.sched_scan_plans[0].interval *= 2;
  1316. if ((unsigned int) wpa_s->sched_scan_timeout <
  1317. params.sched_scan_plans[0].interval ||
  1318. params.sched_scan_plans[0].interval >
  1319. wpa_s->max_sched_scan_plan_interval) {
  1320. params.sched_scan_plans[0].interval = 10;
  1321. wpa_s->sched_scan_timeout = max_sched_scan_ssids * 2;
  1322. }
  1323. }
  1324. /* If there is no more ssids, start next time from the beginning */
  1325. if (!ssid)
  1326. wpa_s->prev_sched_ssid = NULL;
  1327. return 0;
  1328. }
  1329. /**
  1330. * wpa_supplicant_cancel_scan - Cancel a scheduled scan request
  1331. * @wpa_s: Pointer to wpa_supplicant data
  1332. *
  1333. * This function is used to cancel a scan request scheduled with
  1334. * wpa_supplicant_req_scan().
  1335. */
  1336. void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s)
  1337. {
  1338. wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling scan request");
  1339. eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
  1340. }
  1341. /**
  1342. * wpa_supplicant_cancel_delayed_sched_scan - Stop a delayed scheduled scan
  1343. * @wpa_s: Pointer to wpa_supplicant data
  1344. *
  1345. * This function is used to stop a delayed scheduled scan.
  1346. */
  1347. void wpa_supplicant_cancel_delayed_sched_scan(struct wpa_supplicant *wpa_s)
  1348. {
  1349. if (!wpa_s->sched_scan_supported)
  1350. return;
  1351. wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling delayed sched scan");
  1352. eloop_cancel_timeout(wpa_supplicant_delayed_sched_scan_timeout,
  1353. wpa_s, NULL);
  1354. }
  1355. /**
  1356. * wpa_supplicant_cancel_sched_scan - Stop running scheduled scans
  1357. * @wpa_s: Pointer to wpa_supplicant data
  1358. *
  1359. * This function is used to stop a periodic scheduled scan.
  1360. */
  1361. void wpa_supplicant_cancel_sched_scan(struct wpa_supplicant *wpa_s)
  1362. {
  1363. if (!wpa_s->sched_scanning)
  1364. return;
  1365. if (wpa_s->sched_scanning)
  1366. wpa_s->sched_scan_stop_req = 1;
  1367. wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling sched scan");
  1368. eloop_cancel_timeout(wpa_supplicant_sched_scan_timeout, wpa_s, NULL);
  1369. wpa_supplicant_stop_sched_scan(wpa_s);
  1370. }
  1371. /**
  1372. * wpa_supplicant_notify_scanning - Indicate possible scan state change
  1373. * @wpa_s: Pointer to wpa_supplicant data
  1374. * @scanning: Whether scanning is currently in progress
  1375. *
  1376. * This function is to generate scanning notifycations. It is called whenever
  1377. * there may have been a change in scanning (scan started, completed, stopped).
  1378. * wpas_notify_scanning() is called whenever the scanning state changed from the
  1379. * previously notified state.
  1380. */
  1381. void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s,
  1382. int scanning)
  1383. {
  1384. if (wpa_s->scanning != scanning) {
  1385. wpa_s->scanning = scanning;
  1386. wpas_notify_scanning(wpa_s);
  1387. }
  1388. }
  1389. static int wpa_scan_get_max_rate(const struct wpa_scan_res *res)
  1390. {
  1391. int rate = 0;
  1392. const u8 *ie;
  1393. int i;
  1394. ie = wpa_scan_get_ie(res, WLAN_EID_SUPP_RATES);
  1395. for (i = 0; ie && i < ie[1]; i++) {
  1396. if ((ie[i + 2] & 0x7f) > rate)
  1397. rate = ie[i + 2] & 0x7f;
  1398. }
  1399. ie = wpa_scan_get_ie(res, WLAN_EID_EXT_SUPP_RATES);
  1400. for (i = 0; ie && i < ie[1]; i++) {
  1401. if ((ie[i + 2] & 0x7f) > rate)
  1402. rate = ie[i + 2] & 0x7f;
  1403. }
  1404. return rate;
  1405. }
  1406. /**
  1407. * wpa_scan_get_ie - Fetch a specified information element from a scan result
  1408. * @res: Scan result entry
  1409. * @ie: Information element identitifier (WLAN_EID_*)
  1410. * Returns: Pointer to the information element (id field) or %NULL if not found
  1411. *
  1412. * This function returns the first matching information element in the scan
  1413. * result.
  1414. */
  1415. const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
  1416. {
  1417. size_t ie_len = res->ie_len;
  1418. /* Use the Beacon frame IEs if res->ie_len is not available */
  1419. if (!ie_len)
  1420. ie_len = res->beacon_ie_len;
  1421. return get_ie((const u8 *) (res + 1), ie_len, ie);
  1422. }
  1423. /**
  1424. * wpa_scan_get_vendor_ie - Fetch vendor information element from a scan result
  1425. * @res: Scan result entry
  1426. * @vendor_type: Vendor type (four octets starting the IE payload)
  1427. * Returns: Pointer to the information element (id field) or %NULL if not found
  1428. *
  1429. * This function returns the first matching information element in the scan
  1430. * result.
  1431. */
  1432. const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
  1433. u32 vendor_type)
  1434. {
  1435. const u8 *end, *pos;
  1436. pos = (const u8 *) (res + 1);
  1437. end = pos + res->ie_len;
  1438. while (end - pos > 1) {
  1439. if (2 + pos[1] > end - pos)
  1440. break;
  1441. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  1442. vendor_type == WPA_GET_BE32(&pos[2]))
  1443. return pos;
  1444. pos += 2 + pos[1];
  1445. }
  1446. return NULL;
  1447. }
  1448. /**
  1449. * wpa_scan_get_vendor_ie_beacon - Fetch vendor information from a scan result
  1450. * @res: Scan result entry
  1451. * @vendor_type: Vendor type (four octets starting the IE payload)
  1452. * Returns: Pointer to the information element (id field) or %NULL if not found
  1453. *
  1454. * This function returns the first matching information element in the scan
  1455. * result.
  1456. *
  1457. * This function is like wpa_scan_get_vendor_ie(), but uses IE buffer only
  1458. * from Beacon frames instead of either Beacon or Probe Response frames.
  1459. */
  1460. const u8 * wpa_scan_get_vendor_ie_beacon(const struct wpa_scan_res *res,
  1461. u32 vendor_type)
  1462. {
  1463. const u8 *end, *pos;
  1464. if (res->beacon_ie_len == 0)
  1465. return NULL;
  1466. pos = (const u8 *) (res + 1);
  1467. pos += res->ie_len;
  1468. end = pos + res->beacon_ie_len;
  1469. while (end - pos > 1) {
  1470. if (2 + pos[1] > end - pos)
  1471. break;
  1472. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  1473. vendor_type == WPA_GET_BE32(&pos[2]))
  1474. return pos;
  1475. pos += 2 + pos[1];
  1476. }
  1477. return NULL;
  1478. }
  1479. /**
  1480. * wpa_scan_get_vendor_ie_multi - Fetch vendor IE data from a scan result
  1481. * @res: Scan result entry
  1482. * @vendor_type: Vendor type (four octets starting the IE payload)
  1483. * Returns: Pointer to the information element payload or %NULL if not found
  1484. *
  1485. * This function returns concatenated payload of possibly fragmented vendor
  1486. * specific information elements in the scan result. The caller is responsible
  1487. * for freeing the returned buffer.
  1488. */
  1489. struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
  1490. u32 vendor_type)
  1491. {
  1492. struct wpabuf *buf;
  1493. const u8 *end, *pos;
  1494. buf = wpabuf_alloc(res->ie_len);
  1495. if (buf == NULL)
  1496. return NULL;
  1497. pos = (const u8 *) (res + 1);
  1498. end = pos + res->ie_len;
  1499. while (end - pos > 1) {
  1500. if (2 + pos[1] > end - pos)
  1501. break;
  1502. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  1503. vendor_type == WPA_GET_BE32(&pos[2]))
  1504. wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
  1505. pos += 2 + pos[1];
  1506. }
  1507. if (wpabuf_len(buf) == 0) {
  1508. wpabuf_free(buf);
  1509. buf = NULL;
  1510. }
  1511. return buf;
  1512. }
  1513. /*
  1514. * Channels with a great SNR can operate at full rate. What is a great SNR?
  1515. * This doc https://supportforums.cisco.com/docs/DOC-12954 says, "the general
  1516. * rule of thumb is that any SNR above 20 is good." This one
  1517. * http://www.cisco.com/en/US/tech/tk722/tk809/technologies_q_and_a_item09186a00805e9a96.shtml#qa23
  1518. * recommends 25 as a minimum SNR for 54 Mbps data rate. 30 is chosen here as a
  1519. * conservative value.
  1520. */
  1521. #define GREAT_SNR 30
  1522. #define IS_5GHZ(n) (n > 4000)
  1523. /* Compare function for sorting scan results. Return >0 if @b is considered
  1524. * better. */
  1525. static int wpa_scan_result_compar(const void *a, const void *b)
  1526. {
  1527. #define MIN(a,b) a < b ? a : b
  1528. struct wpa_scan_res **_wa = (void *) a;
  1529. struct wpa_scan_res **_wb = (void *) b;
  1530. struct wpa_scan_res *wa = *_wa;
  1531. struct wpa_scan_res *wb = *_wb;
  1532. int wpa_a, wpa_b;
  1533. int snr_a, snr_b, snr_a_full, snr_b_full;
  1534. /* WPA/WPA2 support preferred */
  1535. wpa_a = wpa_scan_get_vendor_ie(wa, WPA_IE_VENDOR_TYPE) != NULL ||
  1536. wpa_scan_get_ie(wa, WLAN_EID_RSN) != NULL;
  1537. wpa_b = wpa_scan_get_vendor_ie(wb, WPA_IE_VENDOR_TYPE) != NULL ||
  1538. wpa_scan_get_ie(wb, WLAN_EID_RSN) != NULL;
  1539. if (wpa_b && !wpa_a)
  1540. return 1;
  1541. if (!wpa_b && wpa_a)
  1542. return -1;
  1543. /* privacy support preferred */
  1544. if ((wa->caps & IEEE80211_CAP_PRIVACY) == 0 &&
  1545. (wb->caps & IEEE80211_CAP_PRIVACY))
  1546. return 1;
  1547. if ((wa->caps & IEEE80211_CAP_PRIVACY) &&
  1548. (wb->caps & IEEE80211_CAP_PRIVACY) == 0)
  1549. return -1;
  1550. if (wa->flags & wb->flags & WPA_SCAN_LEVEL_DBM) {
  1551. snr_a_full = wa->snr;
  1552. snr_a = MIN(wa->snr, GREAT_SNR);
  1553. snr_b_full = wb->snr;
  1554. snr_b = MIN(wb->snr, GREAT_SNR);
  1555. } else {
  1556. /* Level is not in dBm, so we can't calculate
  1557. * SNR. Just use raw level (units unknown). */
  1558. snr_a = snr_a_full = wa->level;
  1559. snr_b = snr_b_full = wb->level;
  1560. }
  1561. /* if SNR is close, decide by max rate or frequency band */
  1562. if ((snr_a && snr_b && abs(snr_b - snr_a) < 5) ||
  1563. (wa->qual && wb->qual && abs(wb->qual - wa->qual) < 10)) {
  1564. if (wa->est_throughput != wb->est_throughput)
  1565. return wb->est_throughput - wa->est_throughput;
  1566. if (IS_5GHZ(wa->freq) ^ IS_5GHZ(wb->freq))
  1567. return IS_5GHZ(wa->freq) ? -1 : 1;
  1568. }
  1569. /* all things being equal, use SNR; if SNRs are
  1570. * identical, use quality values since some drivers may only report
  1571. * that value and leave the signal level zero */
  1572. if (snr_b_full == snr_a_full)
  1573. return wb->qual - wa->qual;
  1574. return snr_b_full - snr_a_full;
  1575. #undef MIN
  1576. }
  1577. #ifdef CONFIG_WPS
  1578. /* Compare function for sorting scan results when searching a WPS AP for
  1579. * provisioning. Return >0 if @b is considered better. */
  1580. static int wpa_scan_result_wps_compar(const void *a, const void *b)
  1581. {
  1582. struct wpa_scan_res **_wa = (void *) a;
  1583. struct wpa_scan_res **_wb = (void *) b;
  1584. struct wpa_scan_res *wa = *_wa;
  1585. struct wpa_scan_res *wb = *_wb;
  1586. int uses_wps_a, uses_wps_b;
  1587. struct wpabuf *wps_a, *wps_b;
  1588. int res;
  1589. /* Optimization - check WPS IE existence before allocated memory and
  1590. * doing full reassembly. */
  1591. uses_wps_a = wpa_scan_get_vendor_ie(wa, WPS_IE_VENDOR_TYPE) != NULL;
  1592. uses_wps_b = wpa_scan_get_vendor_ie(wb, WPS_IE_VENDOR_TYPE) != NULL;
  1593. if (uses_wps_a && !uses_wps_b)
  1594. return -1;
  1595. if (!uses_wps_a && uses_wps_b)
  1596. return 1;
  1597. if (uses_wps_a && uses_wps_b) {
  1598. wps_a = wpa_scan_get_vendor_ie_multi(wa, WPS_IE_VENDOR_TYPE);
  1599. wps_b = wpa_scan_get_vendor_ie_multi(wb, WPS_IE_VENDOR_TYPE);
  1600. res = wps_ap_priority_compar(wps_a, wps_b);
  1601. wpabuf_free(wps_a);
  1602. wpabuf_free(wps_b);
  1603. if (res)
  1604. return res;
  1605. }
  1606. /*
  1607. * Do not use current AP security policy as a sorting criteria during
  1608. * WPS provisioning step since the AP may get reconfigured at the
  1609. * completion of provisioning.
  1610. */
  1611. /* all things being equal, use signal level; if signal levels are
  1612. * identical, use quality values since some drivers may only report
  1613. * that value and leave the signal level zero */
  1614. if (wb->level == wa->level)
  1615. return wb->qual - wa->qual;
  1616. return wb->level - wa->level;
  1617. }
  1618. #endif /* CONFIG_WPS */
  1619. static void dump_scan_res(struct wpa_scan_results *scan_res)
  1620. {
  1621. #ifndef CONFIG_NO_STDOUT_DEBUG
  1622. size_t i;
  1623. if (scan_res->res == NULL || scan_res->num == 0)
  1624. return;
  1625. wpa_printf(MSG_EXCESSIVE, "Sorted scan results");
  1626. for (i = 0; i < scan_res->num; i++) {
  1627. struct wpa_scan_res *r = scan_res->res[i];
  1628. u8 *pos;
  1629. if (r->flags & WPA_SCAN_LEVEL_DBM) {
  1630. int noise_valid = !(r->flags & WPA_SCAN_NOISE_INVALID);
  1631. wpa_printf(MSG_EXCESSIVE, MACSTR " freq=%d qual=%d "
  1632. "noise=%d%s level=%d snr=%d%s flags=0x%x age=%u est=%u",
  1633. MAC2STR(r->bssid), r->freq, r->qual,
  1634. r->noise, noise_valid ? "" : "~", r->level,
  1635. r->snr, r->snr >= GREAT_SNR ? "*" : "",
  1636. r->flags,
  1637. r->age, r->est_throughput);
  1638. } else {
  1639. wpa_printf(MSG_EXCESSIVE, MACSTR " freq=%d qual=%d "
  1640. "noise=%d level=%d flags=0x%x age=%u est=%u",
  1641. MAC2STR(r->bssid), r->freq, r->qual,
  1642. r->noise, r->level, r->flags, r->age,
  1643. r->est_throughput);
  1644. }
  1645. pos = (u8 *) (r + 1);
  1646. if (r->ie_len)
  1647. wpa_hexdump(MSG_EXCESSIVE, "IEs", pos, r->ie_len);
  1648. pos += r->ie_len;
  1649. if (r->beacon_ie_len)
  1650. wpa_hexdump(MSG_EXCESSIVE, "Beacon IEs",
  1651. pos, r->beacon_ie_len);
  1652. }
  1653. #endif /* CONFIG_NO_STDOUT_DEBUG */
  1654. }
  1655. /**
  1656. * wpa_supplicant_filter_bssid_match - Is the specified BSSID allowed
  1657. * @wpa_s: Pointer to wpa_supplicant data
  1658. * @bssid: BSSID to check
  1659. * Returns: 0 if the BSSID is filtered or 1 if not
  1660. *
  1661. * This function is used to filter out specific BSSIDs from scan reslts mainly
  1662. * for testing purposes (SET bssid_filter ctrl_iface command).
  1663. */
  1664. int wpa_supplicant_filter_bssid_match(struct wpa_supplicant *wpa_s,
  1665. const u8 *bssid)
  1666. {
  1667. size_t i;
  1668. if (wpa_s->bssid_filter == NULL)
  1669. return 1;
  1670. for (i = 0; i < wpa_s->bssid_filter_count; i++) {
  1671. if (os_memcmp(wpa_s->bssid_filter + i * ETH_ALEN, bssid,
  1672. ETH_ALEN) == 0)
  1673. return 1;
  1674. }
  1675. return 0;
  1676. }
  1677. void filter_scan_res(struct wpa_supplicant *wpa_s,
  1678. struct wpa_scan_results *res)
  1679. {
  1680. size_t i, j;
  1681. if (wpa_s->bssid_filter == NULL)
  1682. return;
  1683. for (i = 0, j = 0; i < res->num; i++) {
  1684. if (wpa_supplicant_filter_bssid_match(wpa_s,
  1685. res->res[i]->bssid)) {
  1686. res->res[j++] = res->res[i];
  1687. } else {
  1688. os_free(res->res[i]);
  1689. res->res[i] = NULL;
  1690. }
  1691. }
  1692. if (res->num != j) {
  1693. wpa_printf(MSG_DEBUG, "Filtered out %d scan results",
  1694. (int) (res->num - j));
  1695. res->num = j;
  1696. }
  1697. }
  1698. /*
  1699. * Noise floor values to use when we have signal strength
  1700. * measurements, but no noise floor measurements. These values were
  1701. * measured in an office environment with many APs.
  1702. */
  1703. #define DEFAULT_NOISE_FLOOR_2GHZ (-89)
  1704. #define DEFAULT_NOISE_FLOOR_5GHZ (-92)
  1705. void scan_snr(struct wpa_scan_res *res)
  1706. {
  1707. if (res->flags & WPA_SCAN_NOISE_INVALID) {
  1708. res->noise = IS_5GHZ(res->freq) ?
  1709. DEFAULT_NOISE_FLOOR_5GHZ :
  1710. DEFAULT_NOISE_FLOOR_2GHZ;
  1711. }
  1712. if (res->flags & WPA_SCAN_LEVEL_DBM) {
  1713. res->snr = res->level - res->noise;
  1714. } else {
  1715. /* Level is not in dBm, so we can't calculate
  1716. * SNR. Just use raw level (units unknown). */
  1717. res->snr = res->level;
  1718. }
  1719. }
  1720. static unsigned int max_ht20_rate(int snr)
  1721. {
  1722. if (snr < 6)
  1723. return 6500; /* HT20 MCS0 */
  1724. if (snr < 8)
  1725. return 13000; /* HT20 MCS1 */
  1726. if (snr < 13)
  1727. return 19500; /* HT20 MCS2 */
  1728. if (snr < 17)
  1729. return 26000; /* HT20 MCS3 */
  1730. if (snr < 20)
  1731. return 39000; /* HT20 MCS4 */
  1732. if (snr < 23)
  1733. return 52000; /* HT20 MCS5 */
  1734. if (snr < 24)
  1735. return 58500; /* HT20 MCS6 */
  1736. return 65000; /* HT20 MCS7 */
  1737. }
  1738. static unsigned int max_ht40_rate(int snr)
  1739. {
  1740. if (snr < 3)
  1741. return 13500; /* HT40 MCS0 */
  1742. if (snr < 6)
  1743. return 27000; /* HT40 MCS1 */
  1744. if (snr < 10)
  1745. return 40500; /* HT40 MCS2 */
  1746. if (snr < 15)
  1747. return 54000; /* HT40 MCS3 */
  1748. if (snr < 17)
  1749. return 81000; /* HT40 MCS4 */
  1750. if (snr < 22)
  1751. return 108000; /* HT40 MCS5 */
  1752. if (snr < 24)
  1753. return 121500; /* HT40 MCS6 */
  1754. return 135000; /* HT40 MCS7 */
  1755. }
  1756. static unsigned int max_vht80_rate(int snr)
  1757. {
  1758. if (snr < 1)
  1759. return 0;
  1760. if (snr < 2)
  1761. return 29300; /* VHT80 MCS0 */
  1762. if (snr < 5)
  1763. return 58500; /* VHT80 MCS1 */
  1764. if (snr < 9)
  1765. return 87800; /* VHT80 MCS2 */
  1766. if (snr < 11)
  1767. return 117000; /* VHT80 MCS3 */
  1768. if (snr < 15)
  1769. return 175500; /* VHT80 MCS4 */
  1770. if (snr < 16)
  1771. return 234000; /* VHT80 MCS5 */
  1772. if (snr < 18)
  1773. return 263300; /* VHT80 MCS6 */
  1774. if (snr < 20)
  1775. return 292500; /* VHT80 MCS7 */
  1776. if (snr < 22)
  1777. return 351000; /* VHT80 MCS8 */
  1778. return 390000; /* VHT80 MCS9 */
  1779. }
  1780. void scan_est_throughput(struct wpa_supplicant *wpa_s,
  1781. struct wpa_scan_res *res)
  1782. {
  1783. enum local_hw_capab capab = wpa_s->hw_capab;
  1784. int rate; /* max legacy rate in 500 kb/s units */
  1785. const u8 *ie;
  1786. unsigned int est, tmp;
  1787. int snr = res->snr;
  1788. if (res->est_throughput)
  1789. return;
  1790. /* Get maximum legacy rate */
  1791. rate = wpa_scan_get_max_rate(res);
  1792. /* Limit based on estimated SNR */
  1793. if (rate > 1 * 2 && snr < 1)
  1794. rate = 1 * 2;
  1795. else if (rate > 2 * 2 && snr < 4)
  1796. rate = 2 * 2;
  1797. else if (rate > 6 * 2 && snr < 5)
  1798. rate = 6 * 2;
  1799. else if (rate > 9 * 2 && snr < 6)
  1800. rate = 9 * 2;
  1801. else if (rate > 12 * 2 && snr < 7)
  1802. rate = 12 * 2;
  1803. else if (rate > 18 * 2 && snr < 10)
  1804. rate = 18 * 2;
  1805. else if (rate > 24 * 2 && snr < 11)
  1806. rate = 24 * 2;
  1807. else if (rate > 36 * 2 && snr < 15)
  1808. rate = 36 * 2;
  1809. else if (rate > 48 * 2 && snr < 19)
  1810. rate = 48 * 2;
  1811. else if (rate > 54 * 2 && snr < 21)
  1812. rate = 54 * 2;
  1813. est = rate * 500;
  1814. if (capab == CAPAB_HT || capab == CAPAB_HT40 || capab == CAPAB_VHT) {
  1815. ie = wpa_scan_get_ie(res, WLAN_EID_HT_CAP);
  1816. if (ie) {
  1817. tmp = max_ht20_rate(snr);
  1818. if (tmp > est)
  1819. est = tmp;
  1820. }
  1821. }
  1822. if (capab == CAPAB_HT40 || capab == CAPAB_VHT) {
  1823. ie = wpa_scan_get_ie(res, WLAN_EID_HT_OPERATION);
  1824. if (ie && ie[1] >= 2 &&
  1825. (ie[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)) {
  1826. tmp = max_ht40_rate(snr);
  1827. if (tmp > est)
  1828. est = tmp;
  1829. }
  1830. }
  1831. if (capab == CAPAB_VHT) {
  1832. /* Use +1 to assume VHT is always faster than HT */
  1833. ie = wpa_scan_get_ie(res, WLAN_EID_VHT_CAP);
  1834. if (ie) {
  1835. tmp = max_ht20_rate(snr) + 1;
  1836. if (tmp > est)
  1837. est = tmp;
  1838. ie = wpa_scan_get_ie(res, WLAN_EID_HT_OPERATION);
  1839. if (ie && ie[1] >= 2 &&
  1840. (ie[3] &
  1841. HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)) {
  1842. tmp = max_ht40_rate(snr) + 1;
  1843. if (tmp > est)
  1844. est = tmp;
  1845. }
  1846. ie = wpa_scan_get_ie(res, WLAN_EID_VHT_OPERATION);
  1847. if (ie && ie[1] >= 1 &&
  1848. (ie[2] & VHT_OPMODE_CHANNEL_WIDTH_MASK)) {
  1849. tmp = max_vht80_rate(snr) + 1;
  1850. if (tmp > est)
  1851. est = tmp;
  1852. }
  1853. }
  1854. }
  1855. /* TODO: channel utilization and AP load (e.g., from AP Beacon) */
  1856. res->est_throughput = est;
  1857. }
  1858. /**
  1859. * wpa_supplicant_get_scan_results - Get scan results
  1860. * @wpa_s: Pointer to wpa_supplicant data
  1861. * @info: Information about what was scanned or %NULL if not available
  1862. * @new_scan: Whether a new scan was performed
  1863. * Returns: Scan results, %NULL on failure
  1864. *
  1865. * This function request the current scan results from the driver and updates
  1866. * the local BSS list wpa_s->bss. The caller is responsible for freeing the
  1867. * results with wpa_scan_results_free().
  1868. */
  1869. struct wpa_scan_results *
  1870. wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s,
  1871. struct scan_info *info, int new_scan)
  1872. {
  1873. struct wpa_scan_results *scan_res;
  1874. size_t i;
  1875. int (*compar)(const void *, const void *) = wpa_scan_result_compar;
  1876. scan_res = wpa_drv_get_scan_results2(wpa_s);
  1877. if (scan_res == NULL) {
  1878. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results");
  1879. return NULL;
  1880. }
  1881. if (scan_res->fetch_time.sec == 0) {
  1882. /*
  1883. * Make sure we have a valid timestamp if the driver wrapper
  1884. * does not set this.
  1885. */
  1886. os_get_reltime(&scan_res->fetch_time);
  1887. }
  1888. filter_scan_res(wpa_s, scan_res);
  1889. for (i = 0; i < scan_res->num; i++) {
  1890. struct wpa_scan_res *scan_res_item = scan_res->res[i];
  1891. scan_snr(scan_res_item);
  1892. scan_est_throughput(wpa_s, scan_res_item);
  1893. }
  1894. #ifdef CONFIG_WPS
  1895. if (wpas_wps_searching(wpa_s)) {
  1896. wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Order scan results with WPS "
  1897. "provisioning rules");
  1898. compar = wpa_scan_result_wps_compar;
  1899. }
  1900. #endif /* CONFIG_WPS */
  1901. if (scan_res->res) {
  1902. qsort(scan_res->res, scan_res->num,
  1903. sizeof(struct wpa_scan_res *), compar);
  1904. }
  1905. dump_scan_res(scan_res);
  1906. if (wpa_s->ignore_post_flush_scan_res) {
  1907. /* FLUSH command aborted an ongoing scan and these are the
  1908. * results from the aborted scan. Do not process the results to
  1909. * maintain flushed state. */
  1910. wpa_dbg(wpa_s, MSG_DEBUG,
  1911. "Do not update BSS table based on pending post-FLUSH scan results");
  1912. wpa_s->ignore_post_flush_scan_res = 0;
  1913. return scan_res;
  1914. }
  1915. wpa_bss_update_start(wpa_s);
  1916. for (i = 0; i < scan_res->num; i++)
  1917. wpa_bss_update_scan_res(wpa_s, scan_res->res[i],
  1918. &scan_res->fetch_time);
  1919. wpa_bss_update_end(wpa_s, info, new_scan);
  1920. return scan_res;
  1921. }
  1922. /**
  1923. * wpa_supplicant_update_scan_results - Update scan results from the driver
  1924. * @wpa_s: Pointer to wpa_supplicant data
  1925. * Returns: 0 on success, -1 on failure
  1926. *
  1927. * This function updates the BSS table within wpa_supplicant based on the
  1928. * currently available scan results from the driver without requesting a new
  1929. * scan. This is used in cases where the driver indicates an association
  1930. * (including roaming within ESS) and wpa_supplicant does not yet have the
  1931. * needed information to complete the connection (e.g., to perform validation
  1932. * steps in 4-way handshake).
  1933. */
  1934. int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s)
  1935. {
  1936. struct wpa_scan_results *scan_res;
  1937. scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0);
  1938. if (scan_res == NULL)
  1939. return -1;
  1940. wpa_scan_results_free(scan_res);
  1941. return 0;
  1942. }
  1943. /**
  1944. * scan_only_handler - Reports scan results
  1945. */
  1946. void scan_only_handler(struct wpa_supplicant *wpa_s,
  1947. struct wpa_scan_results *scan_res)
  1948. {
  1949. wpa_dbg(wpa_s, MSG_DEBUG, "Scan-only results received");
  1950. if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
  1951. wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
  1952. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
  1953. wpa_s->manual_scan_id);
  1954. wpa_s->manual_scan_use_id = 0;
  1955. } else {
  1956. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  1957. }
  1958. wpas_notify_scan_results(wpa_s);
  1959. wpas_notify_scan_done(wpa_s, 1);
  1960. if (wpa_s->scan_work) {
  1961. struct wpa_radio_work *work = wpa_s->scan_work;
  1962. wpa_s->scan_work = NULL;
  1963. radio_work_done(work);
  1964. }
  1965. if (wpa_s->wpa_state == WPA_SCANNING)
  1966. wpa_supplicant_set_state(wpa_s, wpa_s->scan_prev_wpa_state);
  1967. }
  1968. int wpas_scan_scheduled(struct wpa_supplicant *wpa_s)
  1969. {
  1970. return eloop_is_timeout_registered(wpa_supplicant_scan, wpa_s, NULL);
  1971. }
  1972. struct wpa_driver_scan_params *
  1973. wpa_scan_clone_params(const struct wpa_driver_scan_params *src)
  1974. {
  1975. struct wpa_driver_scan_params *params;
  1976. size_t i;
  1977. u8 *n;
  1978. params = os_zalloc(sizeof(*params));
  1979. if (params == NULL)
  1980. return NULL;
  1981. for (i = 0; i < src->num_ssids; i++) {
  1982. if (src->ssids[i].ssid) {
  1983. n = os_malloc(src->ssids[i].ssid_len);
  1984. if (n == NULL)
  1985. goto failed;
  1986. os_memcpy(n, src->ssids[i].ssid,
  1987. src->ssids[i].ssid_len);
  1988. params->ssids[i].ssid = n;
  1989. params->ssids[i].ssid_len = src->ssids[i].ssid_len;
  1990. }
  1991. }
  1992. params->num_ssids = src->num_ssids;
  1993. if (src->extra_ies) {
  1994. n = os_malloc(src->extra_ies_len);
  1995. if (n == NULL)
  1996. goto failed;
  1997. os_memcpy(n, src->extra_ies, src->extra_ies_len);
  1998. params->extra_ies = n;
  1999. params->extra_ies_len = src->extra_ies_len;
  2000. }
  2001. if (src->freqs) {
  2002. int len = int_array_len(src->freqs);
  2003. params->freqs = os_malloc((len + 1) * sizeof(int));
  2004. if (params->freqs == NULL)
  2005. goto failed;
  2006. os_memcpy(params->freqs, src->freqs, (len + 1) * sizeof(int));
  2007. }
  2008. if (src->filter_ssids) {
  2009. params->filter_ssids = os_malloc(sizeof(*params->filter_ssids) *
  2010. src->num_filter_ssids);
  2011. if (params->filter_ssids == NULL)
  2012. goto failed;
  2013. os_memcpy(params->filter_ssids, src->filter_ssids,
  2014. sizeof(*params->filter_ssids) *
  2015. src->num_filter_ssids);
  2016. params->num_filter_ssids = src->num_filter_ssids;
  2017. }
  2018. params->filter_rssi = src->filter_rssi;
  2019. params->p2p_probe = src->p2p_probe;
  2020. params->only_new_results = src->only_new_results;
  2021. params->low_priority = src->low_priority;
  2022. if (src->sched_scan_plans_num > 0) {
  2023. params->sched_scan_plans =
  2024. os_malloc(sizeof(*src->sched_scan_plans) *
  2025. src->sched_scan_plans_num);
  2026. if (!params->sched_scan_plans)
  2027. goto failed;
  2028. os_memcpy(params->sched_scan_plans, src->sched_scan_plans,
  2029. sizeof(*src->sched_scan_plans) *
  2030. src->sched_scan_plans_num);
  2031. params->sched_scan_plans_num = src->sched_scan_plans_num;
  2032. }
  2033. if (src->mac_addr_rand) {
  2034. params->mac_addr_rand = src->mac_addr_rand;
  2035. if (src->mac_addr && src->mac_addr_mask) {
  2036. u8 *mac_addr;
  2037. mac_addr = os_malloc(2 * ETH_ALEN);
  2038. if (!mac_addr)
  2039. goto failed;
  2040. os_memcpy(mac_addr, src->mac_addr, ETH_ALEN);
  2041. os_memcpy(mac_addr + ETH_ALEN, src->mac_addr_mask,
  2042. ETH_ALEN);
  2043. params->mac_addr = mac_addr;
  2044. params->mac_addr_mask = mac_addr + ETH_ALEN;
  2045. }
  2046. }
  2047. if (src->bssid) {
  2048. u8 *bssid;
  2049. bssid = os_malloc(ETH_ALEN);
  2050. if (!bssid)
  2051. goto failed;
  2052. os_memcpy(bssid, src->bssid, ETH_ALEN);
  2053. params->bssid = bssid;
  2054. }
  2055. return params;
  2056. failed:
  2057. wpa_scan_free_params(params);
  2058. return NULL;
  2059. }
  2060. void wpa_scan_free_params(struct wpa_driver_scan_params *params)
  2061. {
  2062. size_t i;
  2063. if (params == NULL)
  2064. return;
  2065. for (i = 0; i < params->num_ssids; i++)
  2066. os_free((u8 *) params->ssids[i].ssid);
  2067. os_free((u8 *) params->extra_ies);
  2068. os_free(params->freqs);
  2069. os_free(params->filter_ssids);
  2070. os_free(params->sched_scan_plans);
  2071. /*
  2072. * Note: params->mac_addr_mask points to same memory allocation and
  2073. * must not be freed separately.
  2074. */
  2075. os_free((u8 *) params->mac_addr);
  2076. os_free((u8 *) params->bssid);
  2077. os_free(params);
  2078. }
  2079. int wpas_start_pno(struct wpa_supplicant *wpa_s)
  2080. {
  2081. int ret, prio;
  2082. size_t i, num_ssid, num_match_ssid;
  2083. struct wpa_ssid *ssid;
  2084. struct wpa_driver_scan_params params;
  2085. struct sched_scan_plan scan_plan;
  2086. unsigned int max_sched_scan_ssids;
  2087. if (!wpa_s->sched_scan_supported)
  2088. return -1;
  2089. if (wpa_s->max_sched_scan_ssids > WPAS_MAX_SCAN_SSIDS)
  2090. max_sched_scan_ssids = WPAS_MAX_SCAN_SSIDS;
  2091. else
  2092. max_sched_scan_ssids = wpa_s->max_sched_scan_ssids;
  2093. if (max_sched_scan_ssids < 1)
  2094. return -1;
  2095. if (wpa_s->pno || wpa_s->pno_sched_pending)
  2096. return 0;
  2097. if ((wpa_s->wpa_state > WPA_SCANNING) &&
  2098. (wpa_s->wpa_state <= WPA_COMPLETED)) {
  2099. wpa_printf(MSG_ERROR, "PNO: In assoc process");
  2100. return -EAGAIN;
  2101. }
  2102. if (wpa_s->wpa_state == WPA_SCANNING) {
  2103. wpa_supplicant_cancel_scan(wpa_s);
  2104. if (wpa_s->sched_scanning) {
  2105. wpa_printf(MSG_DEBUG, "Schedule PNO on completion of "
  2106. "ongoing sched scan");
  2107. wpa_supplicant_cancel_sched_scan(wpa_s);
  2108. wpa_s->pno_sched_pending = 1;
  2109. return 0;
  2110. }
  2111. }
  2112. if (wpa_s->sched_scan_stop_req) {
  2113. wpa_printf(MSG_DEBUG,
  2114. "Schedule PNO after previous sched scan has stopped");
  2115. wpa_s->pno_sched_pending = 1;
  2116. return 0;
  2117. }
  2118. os_memset(&params, 0, sizeof(params));
  2119. num_ssid = num_match_ssid = 0;
  2120. ssid = wpa_s->conf->ssid;
  2121. while (ssid) {
  2122. if (!wpas_network_disabled(wpa_s, ssid)) {
  2123. num_match_ssid++;
  2124. if (ssid->scan_ssid)
  2125. num_ssid++;
  2126. }
  2127. ssid = ssid->next;
  2128. }
  2129. if (num_match_ssid == 0) {
  2130. wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
  2131. return -1;
  2132. }
  2133. if (num_match_ssid > num_ssid) {
  2134. params.num_ssids++; /* wildcard */
  2135. num_ssid++;
  2136. }
  2137. if (num_ssid > max_sched_scan_ssids) {
  2138. wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
  2139. "%u", max_sched_scan_ssids, (unsigned int) num_ssid);
  2140. num_ssid = max_sched_scan_ssids;
  2141. }
  2142. if (num_match_ssid > wpa_s->max_match_sets) {
  2143. num_match_ssid = wpa_s->max_match_sets;
  2144. wpa_dbg(wpa_s, MSG_DEBUG, "PNO: Too many SSIDs to match");
  2145. }
  2146. params.filter_ssids = os_calloc(num_match_ssid,
  2147. sizeof(struct wpa_driver_scan_filter));
  2148. if (params.filter_ssids == NULL)
  2149. return -1;
  2150. i = 0;
  2151. prio = 0;
  2152. ssid = wpa_s->conf->pssid[prio];
  2153. while (ssid) {
  2154. if (!wpas_network_disabled(wpa_s, ssid)) {
  2155. if (ssid->scan_ssid && params.num_ssids < num_ssid) {
  2156. params.ssids[params.num_ssids].ssid =
  2157. ssid->ssid;
  2158. params.ssids[params.num_ssids].ssid_len =
  2159. ssid->ssid_len;
  2160. params.num_ssids++;
  2161. }
  2162. os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
  2163. ssid->ssid_len);
  2164. params.filter_ssids[i].ssid_len = ssid->ssid_len;
  2165. params.num_filter_ssids++;
  2166. i++;
  2167. if (i == num_match_ssid)
  2168. break;
  2169. }
  2170. if (ssid->pnext)
  2171. ssid = ssid->pnext;
  2172. else if (prio + 1 == wpa_s->conf->num_prio)
  2173. break;
  2174. else
  2175. ssid = wpa_s->conf->pssid[++prio];
  2176. }
  2177. if (wpa_s->conf->filter_rssi)
  2178. params.filter_rssi = wpa_s->conf->filter_rssi;
  2179. if (wpa_s->sched_scan_plans_num) {
  2180. params.sched_scan_plans = wpa_s->sched_scan_plans;
  2181. params.sched_scan_plans_num = wpa_s->sched_scan_plans_num;
  2182. } else {
  2183. /* Set one scan plan that will run infinitely */
  2184. if (wpa_s->conf->sched_scan_interval)
  2185. scan_plan.interval = wpa_s->conf->sched_scan_interval;
  2186. else
  2187. scan_plan.interval = 10;
  2188. scan_plan.iterations = 0;
  2189. params.sched_scan_plans = &scan_plan;
  2190. params.sched_scan_plans_num = 1;
  2191. }
  2192. if (params.freqs == NULL && wpa_s->manual_sched_scan_freqs) {
  2193. wpa_dbg(wpa_s, MSG_DEBUG, "Limit sched scan to specified channels");
  2194. params.freqs = wpa_s->manual_sched_scan_freqs;
  2195. }
  2196. if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_PNO) &&
  2197. wpa_s->wpa_state <= WPA_SCANNING) {
  2198. params.mac_addr_rand = 1;
  2199. if (wpa_s->mac_addr_pno) {
  2200. params.mac_addr = wpa_s->mac_addr_pno;
  2201. params.mac_addr_mask = wpa_s->mac_addr_pno + ETH_ALEN;
  2202. }
  2203. }
  2204. ret = wpa_supplicant_start_sched_scan(wpa_s, &params);
  2205. os_free(params.filter_ssids);
  2206. if (ret == 0)
  2207. wpa_s->pno = 1;
  2208. else
  2209. wpa_msg(wpa_s, MSG_ERROR, "Failed to schedule PNO");
  2210. return ret;
  2211. }
  2212. int wpas_stop_pno(struct wpa_supplicant *wpa_s)
  2213. {
  2214. int ret = 0;
  2215. if (!wpa_s->pno)
  2216. return 0;
  2217. ret = wpa_supplicant_stop_sched_scan(wpa_s);
  2218. wpa_s->sched_scan_stop_req = 1;
  2219. wpa_s->pno = 0;
  2220. wpa_s->pno_sched_pending = 0;
  2221. if (wpa_s->wpa_state == WPA_SCANNING)
  2222. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2223. return ret;
  2224. }
  2225. void wpas_mac_addr_rand_scan_clear(struct wpa_supplicant *wpa_s,
  2226. unsigned int type)
  2227. {
  2228. type &= MAC_ADDR_RAND_ALL;
  2229. wpa_s->mac_addr_rand_enable &= ~type;
  2230. if (type & MAC_ADDR_RAND_SCAN) {
  2231. os_free(wpa_s->mac_addr_scan);
  2232. wpa_s->mac_addr_scan = NULL;
  2233. }
  2234. if (type & MAC_ADDR_RAND_SCHED_SCAN) {
  2235. os_free(wpa_s->mac_addr_sched_scan);
  2236. wpa_s->mac_addr_sched_scan = NULL;
  2237. }
  2238. if (type & MAC_ADDR_RAND_PNO) {
  2239. os_free(wpa_s->mac_addr_pno);
  2240. wpa_s->mac_addr_pno = NULL;
  2241. }
  2242. }
  2243. int wpas_mac_addr_rand_scan_set(struct wpa_supplicant *wpa_s,
  2244. unsigned int type, const u8 *addr,
  2245. const u8 *mask)
  2246. {
  2247. u8 *tmp = NULL;
  2248. wpas_mac_addr_rand_scan_clear(wpa_s, type);
  2249. if (addr) {
  2250. tmp = os_malloc(2 * ETH_ALEN);
  2251. if (!tmp)
  2252. return -1;
  2253. os_memcpy(tmp, addr, ETH_ALEN);
  2254. os_memcpy(tmp + ETH_ALEN, mask, ETH_ALEN);
  2255. }
  2256. if (type == MAC_ADDR_RAND_SCAN) {
  2257. wpa_s->mac_addr_scan = tmp;
  2258. } else if (type == MAC_ADDR_RAND_SCHED_SCAN) {
  2259. wpa_s->mac_addr_sched_scan = tmp;
  2260. } else if (type == MAC_ADDR_RAND_PNO) {
  2261. wpa_s->mac_addr_pno = tmp;
  2262. } else {
  2263. wpa_printf(MSG_INFO,
  2264. "scan: Invalid MAC randomization type=0x%x",
  2265. type);
  2266. os_free(tmp);
  2267. return -1;
  2268. }
  2269. wpa_s->mac_addr_rand_enable |= type;
  2270. return 0;
  2271. }
  2272. int wpas_abort_ongoing_scan(struct wpa_supplicant *wpa_s)
  2273. {
  2274. struct wpa_radio_work *work;
  2275. struct wpa_radio *radio = wpa_s->radio;
  2276. dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) {
  2277. if (work->wpa_s != wpa_s || !work->started ||
  2278. (os_strcmp(work->type, "scan") != 0 &&
  2279. os_strcmp(work->type, "p2p-scan") != 0))
  2280. continue;
  2281. wpa_dbg(wpa_s, MSG_DEBUG, "Abort an ongoing scan");
  2282. return wpa_drv_abort_scan(wpa_s, wpa_s->curr_scan_cookie);
  2283. }
  2284. wpa_dbg(wpa_s, MSG_DEBUG, "No ongoing scan/p2p-scan found to abort");
  2285. return -1;
  2286. }
  2287. int wpas_sched_scan_plans_set(struct wpa_supplicant *wpa_s, const char *cmd)
  2288. {
  2289. struct sched_scan_plan *scan_plans = NULL;
  2290. const char *token, *context = NULL;
  2291. unsigned int num = 0;
  2292. if (!cmd)
  2293. return -1;
  2294. if (!cmd[0]) {
  2295. wpa_printf(MSG_DEBUG, "Clear sched scan plans");
  2296. os_free(wpa_s->sched_scan_plans);
  2297. wpa_s->sched_scan_plans = NULL;
  2298. wpa_s->sched_scan_plans_num = 0;
  2299. return 0;
  2300. }
  2301. while ((token = cstr_token(cmd, " ", &context))) {
  2302. int ret;
  2303. struct sched_scan_plan *scan_plan, *n;
  2304. n = os_realloc_array(scan_plans, num + 1, sizeof(*scan_plans));
  2305. if (!n)
  2306. goto fail;
  2307. scan_plans = n;
  2308. scan_plan = &scan_plans[num];
  2309. num++;
  2310. ret = sscanf(token, "%u:%u", &scan_plan->interval,
  2311. &scan_plan->iterations);
  2312. if (ret <= 0 || ret > 2 || !scan_plan->interval) {
  2313. wpa_printf(MSG_ERROR,
  2314. "Invalid sched scan plan input: %s", token);
  2315. goto fail;
  2316. }
  2317. if (scan_plan->interval > wpa_s->max_sched_scan_plan_interval) {
  2318. wpa_printf(MSG_WARNING,
  2319. "scan plan %u: Scan interval too long(%u), use the maximum allowed(%u)",
  2320. num, scan_plan->interval,
  2321. wpa_s->max_sched_scan_plan_interval);
  2322. scan_plan->interval =
  2323. wpa_s->max_sched_scan_plan_interval;
  2324. }
  2325. if (ret == 1) {
  2326. scan_plan->iterations = 0;
  2327. break;
  2328. }
  2329. if (!scan_plan->iterations) {
  2330. wpa_printf(MSG_ERROR,
  2331. "scan plan %u: Number of iterations cannot be zero",
  2332. num);
  2333. goto fail;
  2334. }
  2335. if (scan_plan->iterations >
  2336. wpa_s->max_sched_scan_plan_iterations) {
  2337. wpa_printf(MSG_WARNING,
  2338. "scan plan %u: Too many iterations(%u), use the maximum allowed(%u)",
  2339. num, scan_plan->iterations,
  2340. wpa_s->max_sched_scan_plan_iterations);
  2341. scan_plan->iterations =
  2342. wpa_s->max_sched_scan_plan_iterations;
  2343. }
  2344. wpa_printf(MSG_DEBUG,
  2345. "scan plan %u: interval=%u iterations=%u",
  2346. num, scan_plan->interval, scan_plan->iterations);
  2347. }
  2348. if (!scan_plans) {
  2349. wpa_printf(MSG_ERROR, "Invalid scan plans entry");
  2350. goto fail;
  2351. }
  2352. if (cstr_token(cmd, " ", &context) || scan_plans[num - 1].iterations) {
  2353. wpa_printf(MSG_ERROR,
  2354. "All scan plans but the last must specify a number of iterations");
  2355. goto fail;
  2356. }
  2357. wpa_printf(MSG_DEBUG, "scan plan %u (last plan): interval=%u",
  2358. num, scan_plans[num - 1].interval);
  2359. if (num > wpa_s->max_sched_scan_plans) {
  2360. wpa_printf(MSG_WARNING,
  2361. "Too many scheduled scan plans (only %u supported)",
  2362. wpa_s->max_sched_scan_plans);
  2363. wpa_printf(MSG_WARNING,
  2364. "Use only the first %u scan plans, and the last one (in infinite loop)",
  2365. wpa_s->max_sched_scan_plans - 1);
  2366. os_memcpy(&scan_plans[wpa_s->max_sched_scan_plans - 1],
  2367. &scan_plans[num - 1], sizeof(*scan_plans));
  2368. num = wpa_s->max_sched_scan_plans;
  2369. }
  2370. os_free(wpa_s->sched_scan_plans);
  2371. wpa_s->sched_scan_plans = scan_plans;
  2372. wpa_s->sched_scan_plans_num = num;
  2373. return 0;
  2374. fail:
  2375. os_free(scan_plans);
  2376. wpa_printf(MSG_ERROR, "invalid scan plans list");
  2377. return -1;
  2378. }
  2379. /**
  2380. * wpas_scan_reset_sched_scan - Reset sched_scan state
  2381. * @wpa_s: Pointer to wpa_supplicant data
  2382. *
  2383. * This function is used to cancel a running scheduled scan and to reset an
  2384. * internal scan state to continue with a regular scan on the following
  2385. * wpa_supplicant_req_scan() calls.
  2386. */
  2387. void wpas_scan_reset_sched_scan(struct wpa_supplicant *wpa_s)
  2388. {
  2389. wpa_s->normal_scans = 0;
  2390. if (wpa_s->sched_scanning) {
  2391. wpa_s->sched_scan_timed_out = 0;
  2392. wpa_s->prev_sched_ssid = NULL;
  2393. wpa_supplicant_cancel_sched_scan(wpa_s);
  2394. }
  2395. }
  2396. void wpas_scan_restart_sched_scan(struct wpa_supplicant *wpa_s)
  2397. {
  2398. /* simulate timeout to restart the sched scan */
  2399. wpa_s->sched_scan_timed_out = 1;
  2400. wpa_s->prev_sched_ssid = NULL;
  2401. wpa_supplicant_cancel_sched_scan(wpa_s);
  2402. }