scan.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  1. /*
  2. * WPA Supplicant - Scanning
  3. * Copyright (c) 2003-2012, 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 "gas_query.h"
  23. #include "scan.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. if (wpa_s->current_ssid != NULL)
  34. wpas_notify_network_changed(wpa_s);
  35. }
  36. wpa_supplicant_initiate_eapol(wpa_s);
  37. wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with a configured "
  38. "network - generating associated event");
  39. os_memset(&data, 0, sizeof(data));
  40. wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
  41. }
  42. #ifdef CONFIG_WPS
  43. static int wpas_wps_in_use(struct wpa_supplicant *wpa_s,
  44. enum wps_request_type *req_type)
  45. {
  46. struct wpa_ssid *ssid;
  47. int wps = 0;
  48. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  49. if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
  50. continue;
  51. wps = 1;
  52. *req_type = wpas_wps_get_req_type(ssid);
  53. if (!ssid->eap.phase1)
  54. continue;
  55. if (os_strstr(ssid->eap.phase1, "pbc=1"))
  56. return 2;
  57. }
  58. #ifdef CONFIG_P2P
  59. if (!wpa_s->global->p2p_disabled && wpa_s->global->p2p &&
  60. !wpa_s->conf->p2p_disabled) {
  61. wpa_s->wps->dev.p2p = 1;
  62. if (!wps) {
  63. wps = 1;
  64. *req_type = WPS_REQ_ENROLLEE_INFO;
  65. }
  66. }
  67. #endif /* CONFIG_P2P */
  68. return wps;
  69. }
  70. #endif /* CONFIG_WPS */
  71. /**
  72. * wpa_supplicant_enabled_networks - Check whether there are enabled networks
  73. * @wpa_s: Pointer to wpa_supplicant data
  74. * Returns: 0 if no networks are enabled, >0 if networks are enabled
  75. *
  76. * This function is used to figure out whether any networks (or Interworking
  77. * with enabled credentials and auto_interworking) are present in the current
  78. * configuration.
  79. */
  80. int wpa_supplicant_enabled_networks(struct wpa_supplicant *wpa_s)
  81. {
  82. struct wpa_ssid *ssid = wpa_s->conf->ssid;
  83. int count = 0, disabled = 0;
  84. while (ssid) {
  85. if (!wpas_network_disabled(wpa_s, ssid))
  86. count++;
  87. else
  88. disabled++;
  89. ssid = ssid->next;
  90. }
  91. if (wpa_s->conf->cred && wpa_s->conf->interworking &&
  92. wpa_s->conf->auto_interworking)
  93. count++;
  94. if (count == 0 && disabled > 0) {
  95. wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks (%d disabled "
  96. "networks)", disabled);
  97. }
  98. return count;
  99. }
  100. static void wpa_supplicant_assoc_try(struct wpa_supplicant *wpa_s,
  101. struct wpa_ssid *ssid)
  102. {
  103. while (ssid) {
  104. if (!wpas_network_disabled(wpa_s, ssid))
  105. break;
  106. ssid = ssid->next;
  107. }
  108. /* ap_scan=2 mode - try to associate with each SSID. */
  109. if (ssid == NULL) {
  110. wpa_dbg(wpa_s, MSG_DEBUG, "wpa_supplicant_assoc_try: Reached "
  111. "end of scan list - go back to beginning");
  112. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  113. wpa_supplicant_req_scan(wpa_s, 0, 0);
  114. return;
  115. }
  116. if (ssid->next) {
  117. /* Continue from the next SSID on the next attempt. */
  118. wpa_s->prev_scan_ssid = ssid;
  119. } else {
  120. /* Start from the beginning of the SSID list. */
  121. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  122. }
  123. wpa_supplicant_associate(wpa_s, NULL, ssid);
  124. }
  125. /**
  126. * wpa_supplicant_trigger_scan - Request driver to start a scan
  127. * @wpa_s: Pointer to wpa_supplicant data
  128. * @params: Scan parameters
  129. * Returns: 0 on success, -1 on failure
  130. */
  131. int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
  132. struct wpa_driver_scan_params *params)
  133. {
  134. int ret;
  135. wpa_supplicant_notify_scanning(wpa_s, 1);
  136. ret = wpa_drv_scan(wpa_s, params);
  137. if (ret) {
  138. wpa_supplicant_notify_scanning(wpa_s, 0);
  139. wpas_notify_scan_done(wpa_s, 0);
  140. } else {
  141. os_get_reltime(&wpa_s->scan_trigger_time);
  142. wpa_s->scan_runs++;
  143. wpa_s->normal_scans++;
  144. wpa_s->own_scan_requested = 1;
  145. }
  146. return ret;
  147. }
  148. static void
  149. wpa_supplicant_delayed_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx)
  150. {
  151. struct wpa_supplicant *wpa_s = eloop_ctx;
  152. wpa_dbg(wpa_s, MSG_DEBUG, "Starting delayed sched scan");
  153. if (wpa_supplicant_req_sched_scan(wpa_s))
  154. wpa_supplicant_req_scan(wpa_s, 0, 0);
  155. }
  156. static void
  157. wpa_supplicant_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx)
  158. {
  159. struct wpa_supplicant *wpa_s = eloop_ctx;
  160. wpa_dbg(wpa_s, MSG_DEBUG, "Sched scan timeout - stopping it");
  161. wpa_s->sched_scan_timed_out = 1;
  162. wpa_supplicant_cancel_sched_scan(wpa_s);
  163. }
  164. int wpa_supplicant_start_sched_scan(struct wpa_supplicant *wpa_s,
  165. struct wpa_driver_scan_params *params,
  166. int interval)
  167. {
  168. int ret;
  169. wpa_supplicant_notify_scanning(wpa_s, 1);
  170. ret = wpa_drv_sched_scan(wpa_s, params, interval * 1000);
  171. if (ret)
  172. wpa_supplicant_notify_scanning(wpa_s, 0);
  173. else
  174. wpa_s->sched_scanning = 1;
  175. return ret;
  176. }
  177. int wpa_supplicant_stop_sched_scan(struct wpa_supplicant *wpa_s)
  178. {
  179. int ret;
  180. ret = wpa_drv_stop_sched_scan(wpa_s);
  181. if (ret) {
  182. wpa_dbg(wpa_s, MSG_DEBUG, "stopping sched_scan failed!");
  183. /* TODO: what to do if stopping fails? */
  184. return -1;
  185. }
  186. return ret;
  187. }
  188. static struct wpa_driver_scan_filter *
  189. wpa_supplicant_build_filter_ssids(struct wpa_config *conf, size_t *num_ssids)
  190. {
  191. struct wpa_driver_scan_filter *ssids;
  192. struct wpa_ssid *ssid;
  193. size_t count;
  194. *num_ssids = 0;
  195. if (!conf->filter_ssids)
  196. return NULL;
  197. for (count = 0, ssid = conf->ssid; ssid; ssid = ssid->next) {
  198. if (ssid->ssid && ssid->ssid_len)
  199. count++;
  200. }
  201. if (count == 0)
  202. return NULL;
  203. ssids = os_zalloc(count * sizeof(struct wpa_driver_scan_filter));
  204. if (ssids == NULL)
  205. return NULL;
  206. for (ssid = conf->ssid; ssid; ssid = ssid->next) {
  207. if (!ssid->ssid || !ssid->ssid_len)
  208. continue;
  209. os_memcpy(ssids[*num_ssids].ssid, ssid->ssid, ssid->ssid_len);
  210. ssids[*num_ssids].ssid_len = ssid->ssid_len;
  211. (*num_ssids)++;
  212. }
  213. return ssids;
  214. }
  215. static void wpa_supplicant_optimize_freqs(
  216. struct wpa_supplicant *wpa_s, struct wpa_driver_scan_params *params)
  217. {
  218. #ifdef CONFIG_P2P
  219. if (params->freqs == NULL && wpa_s->p2p_in_provisioning &&
  220. wpa_s->go_params) {
  221. /* Optimize provisioning state scan based on GO information */
  222. if (wpa_s->p2p_in_provisioning < 5 &&
  223. wpa_s->go_params->freq > 0) {
  224. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only GO "
  225. "preferred frequency %d MHz",
  226. wpa_s->go_params->freq);
  227. params->freqs = os_zalloc(2 * sizeof(int));
  228. if (params->freqs)
  229. params->freqs[0] = wpa_s->go_params->freq;
  230. } else if (wpa_s->p2p_in_provisioning < 8 &&
  231. wpa_s->go_params->freq_list[0]) {
  232. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only common "
  233. "channels");
  234. int_array_concat(&params->freqs,
  235. wpa_s->go_params->freq_list);
  236. if (params->freqs)
  237. int_array_sort_unique(params->freqs);
  238. }
  239. wpa_s->p2p_in_provisioning++;
  240. }
  241. #endif /* CONFIG_P2P */
  242. #ifdef CONFIG_WPS
  243. if (params->freqs == NULL && wpa_s->after_wps && wpa_s->wps_freq) {
  244. /*
  245. * Optimize post-provisioning scan based on channel used
  246. * during provisioning.
  247. */
  248. wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz "
  249. "that was used during provisioning", wpa_s->wps_freq);
  250. params->freqs = os_zalloc(2 * sizeof(int));
  251. if (params->freqs)
  252. params->freqs[0] = wpa_s->wps_freq;
  253. wpa_s->after_wps--;
  254. } else if (wpa_s->after_wps)
  255. wpa_s->after_wps--;
  256. if (params->freqs == NULL && wpa_s->known_wps_freq && wpa_s->wps_freq)
  257. {
  258. /* Optimize provisioning scan based on already known channel */
  259. wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz",
  260. wpa_s->wps_freq);
  261. params->freqs = os_zalloc(2 * sizeof(int));
  262. if (params->freqs)
  263. params->freqs[0] = wpa_s->wps_freq;
  264. wpa_s->known_wps_freq = 0; /* only do this once */
  265. }
  266. #endif /* CONFIG_WPS */
  267. }
  268. #ifdef CONFIG_INTERWORKING
  269. static void wpas_add_interworking_elements(struct wpa_supplicant *wpa_s,
  270. struct wpabuf *buf)
  271. {
  272. if (wpa_s->conf->interworking == 0)
  273. return;
  274. wpabuf_put_u8(buf, WLAN_EID_EXT_CAPAB);
  275. wpabuf_put_u8(buf, 4);
  276. wpabuf_put_u8(buf, 0x00);
  277. wpabuf_put_u8(buf, 0x00);
  278. wpabuf_put_u8(buf, 0x00);
  279. wpabuf_put_u8(buf, 0x80); /* Bit 31 - Interworking */
  280. wpabuf_put_u8(buf, WLAN_EID_INTERWORKING);
  281. wpabuf_put_u8(buf, is_zero_ether_addr(wpa_s->conf->hessid) ? 1 :
  282. 1 + ETH_ALEN);
  283. wpabuf_put_u8(buf, wpa_s->conf->access_network_type);
  284. /* No Venue Info */
  285. if (!is_zero_ether_addr(wpa_s->conf->hessid))
  286. wpabuf_put_data(buf, wpa_s->conf->hessid, ETH_ALEN);
  287. }
  288. #endif /* CONFIG_INTERWORKING */
  289. static struct wpabuf * wpa_supplicant_extra_ies(struct wpa_supplicant *wpa_s)
  290. {
  291. struct wpabuf *extra_ie = NULL;
  292. #ifdef CONFIG_WPS
  293. int wps = 0;
  294. enum wps_request_type req_type = WPS_REQ_ENROLLEE_INFO;
  295. #endif /* CONFIG_WPS */
  296. #ifdef CONFIG_INTERWORKING
  297. if (wpa_s->conf->interworking &&
  298. wpabuf_resize(&extra_ie, 100) == 0)
  299. wpas_add_interworking_elements(wpa_s, extra_ie);
  300. #endif /* CONFIG_INTERWORKING */
  301. #ifdef CONFIG_WPS
  302. wps = wpas_wps_in_use(wpa_s, &req_type);
  303. if (wps) {
  304. struct wpabuf *wps_ie;
  305. wps_ie = wps_build_probe_req_ie(wps == 2 ? DEV_PW_PUSHBUTTON :
  306. DEV_PW_DEFAULT,
  307. &wpa_s->wps->dev,
  308. wpa_s->wps->uuid, req_type,
  309. 0, NULL);
  310. if (wps_ie) {
  311. if (wpabuf_resize(&extra_ie, wpabuf_len(wps_ie)) == 0)
  312. wpabuf_put_buf(extra_ie, wps_ie);
  313. wpabuf_free(wps_ie);
  314. }
  315. }
  316. #ifdef CONFIG_P2P
  317. if (wps) {
  318. size_t ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
  319. if (wpabuf_resize(&extra_ie, ielen) == 0)
  320. wpas_p2p_scan_ie(wpa_s, extra_ie);
  321. }
  322. #endif /* CONFIG_P2P */
  323. #endif /* CONFIG_WPS */
  324. #ifdef CONFIG_HS20
  325. if (wpa_s->conf->hs20 && wpabuf_resize(&extra_ie, 7) == 0)
  326. wpas_hs20_add_indication(extra_ie);
  327. #endif /* CONFIG_HS20 */
  328. return extra_ie;
  329. }
  330. #ifdef CONFIG_P2P
  331. /*
  332. * Check whether there are any enabled networks or credentials that could be
  333. * used for a non-P2P connection.
  334. */
  335. static int non_p2p_network_enabled(struct wpa_supplicant *wpa_s)
  336. {
  337. struct wpa_ssid *ssid;
  338. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  339. if (wpas_network_disabled(wpa_s, ssid))
  340. continue;
  341. if (!ssid->p2p_group)
  342. return 1;
  343. }
  344. if (wpa_s->conf->cred && wpa_s->conf->interworking &&
  345. wpa_s->conf->auto_interworking)
  346. return 1;
  347. return 0;
  348. }
  349. #endif /* CONFIG_P2P */
  350. static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
  351. u16 num_modes,
  352. enum hostapd_hw_mode mode)
  353. {
  354. u16 i;
  355. for (i = 0; i < num_modes; i++) {
  356. if (modes[i].mode == mode)
  357. return &modes[i];
  358. }
  359. return NULL;
  360. }
  361. static void wpa_setband_scan_freqs_list(struct wpa_supplicant *wpa_s,
  362. enum hostapd_hw_mode band,
  363. struct wpa_driver_scan_params *params)
  364. {
  365. /* Include only supported channels for the specified band */
  366. struct hostapd_hw_modes *mode;
  367. int count, i;
  368. mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, band);
  369. if (mode == NULL) {
  370. /* No channels supported in this band - use empty list */
  371. params->freqs = os_zalloc(sizeof(int));
  372. return;
  373. }
  374. params->freqs = os_zalloc((mode->num_channels + 1) * sizeof(int));
  375. if (params->freqs == NULL)
  376. return;
  377. for (count = 0, i = 0; i < mode->num_channels; i++) {
  378. if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED)
  379. continue;
  380. params->freqs[count++] = mode->channels[i].freq;
  381. }
  382. }
  383. static void wpa_setband_scan_freqs(struct wpa_supplicant *wpa_s,
  384. struct wpa_driver_scan_params *params)
  385. {
  386. if (wpa_s->hw.modes == NULL)
  387. return; /* unknown what channels the driver supports */
  388. if (params->freqs)
  389. return; /* already using a limited channel set */
  390. if (wpa_s->setband == WPA_SETBAND_5G)
  391. wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A,
  392. params);
  393. else if (wpa_s->setband == WPA_SETBAND_2G)
  394. wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G,
  395. params);
  396. }
  397. static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
  398. {
  399. struct wpa_supplicant *wpa_s = eloop_ctx;
  400. struct wpa_ssid *ssid;
  401. int ret;
  402. struct wpabuf *extra_ie = NULL;
  403. struct wpa_driver_scan_params params;
  404. struct wpa_driver_scan_params *scan_params;
  405. size_t max_ssids;
  406. enum wpa_states prev_state;
  407. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  408. wpa_dbg(wpa_s, MSG_DEBUG, "Skip scan - interface disabled");
  409. wpas_p2p_continue_after_scan(wpa_s);
  410. return;
  411. }
  412. if (wpa_s->disconnected && wpa_s->scan_req == NORMAL_SCAN_REQ) {
  413. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnected - do not scan");
  414. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  415. wpas_p2p_continue_after_scan(wpa_s);
  416. return;
  417. }
  418. if (wpa_s->scanning) {
  419. /*
  420. * If we are already in scanning state, we shall reschedule the
  421. * the incoming scan request.
  422. */
  423. wpa_dbg(wpa_s, MSG_DEBUG, "Already scanning - Reschedule the incoming scan req");
  424. wpa_supplicant_req_scan(wpa_s, 1, 0);
  425. return;
  426. }
  427. if (wpa_s->external_scan_running) {
  428. struct os_reltime now, diff;
  429. os_get_reltime(&now);
  430. os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
  431. if (diff.sec < 30) {
  432. wpa_dbg(wpa_s, MSG_DEBUG, "Externally triggered scan running - Reschedule the incoming scan req");
  433. wpa_supplicant_req_scan(wpa_s, 1, 0);
  434. return;
  435. }
  436. }
  437. if (!wpa_supplicant_enabled_networks(wpa_s) &&
  438. wpa_s->scan_req == NORMAL_SCAN_REQ) {
  439. wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks - do not scan");
  440. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  441. wpas_p2p_continue_after_scan(wpa_s);
  442. return;
  443. }
  444. if (wpa_s->conf->ap_scan != 0 &&
  445. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) {
  446. wpa_dbg(wpa_s, MSG_DEBUG, "Using wired authentication - "
  447. "overriding ap_scan configuration");
  448. wpa_s->conf->ap_scan = 0;
  449. wpas_notify_ap_scan_changed(wpa_s);
  450. }
  451. if (wpa_s->conf->ap_scan == 0) {
  452. wpa_supplicant_gen_assoc_event(wpa_s);
  453. return;
  454. }
  455. #ifdef CONFIG_P2P
  456. if (wpas_p2p_in_progress(wpa_s) || wpas_wpa_is_in_progress(wpa_s, 0)) {
  457. if (wpa_s->sta_scan_pending &&
  458. wpas_p2p_in_progress(wpa_s) == 2 &&
  459. wpa_s->global->p2p_cb_on_scan_complete) {
  460. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending station "
  461. "mode scan during P2P search");
  462. } else {
  463. wpa_dbg(wpa_s, MSG_DEBUG, "Delay station mode scan "
  464. "while P2P operation is in progress");
  465. wpa_s->sta_scan_pending = 1;
  466. wpa_supplicant_req_scan(wpa_s, 5, 0);
  467. return;
  468. }
  469. }
  470. #endif /* CONFIG_P2P */
  471. #ifdef CONFIG_GAS
  472. if (gas_query_in_progress(wpa_s->gas)) {
  473. wpa_dbg(wpa_s, MSG_DEBUG, "Delay scan while GAS query is in progress");
  474. wpa_supplicant_req_scan(wpa_s, 1, 0);
  475. return;
  476. }
  477. #endif /* CONFIG_GAS */
  478. if (wpa_s->conf->ap_scan == 2)
  479. max_ssids = 1;
  480. else {
  481. max_ssids = wpa_s->max_scan_ssids;
  482. if (max_ssids > WPAS_MAX_SCAN_SSIDS)
  483. max_ssids = WPAS_MAX_SCAN_SSIDS;
  484. }
  485. wpa_s->last_scan_req = wpa_s->scan_req;
  486. wpa_s->scan_req = NORMAL_SCAN_REQ;
  487. os_memset(&params, 0, sizeof(params));
  488. prev_state = wpa_s->wpa_state;
  489. if (wpa_s->wpa_state == WPA_DISCONNECTED ||
  490. wpa_s->wpa_state == WPA_INACTIVE)
  491. wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
  492. /*
  493. * If autoscan has set its own scanning parameters
  494. */
  495. if (wpa_s->autoscan_params != NULL) {
  496. scan_params = wpa_s->autoscan_params;
  497. goto scan;
  498. }
  499. if (wpa_s->last_scan_req != MANUAL_SCAN_REQ &&
  500. wpa_s->connect_without_scan) {
  501. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  502. if (ssid == wpa_s->connect_without_scan)
  503. break;
  504. }
  505. wpa_s->connect_without_scan = NULL;
  506. if (ssid) {
  507. wpa_printf(MSG_DEBUG, "Start a pre-selected network "
  508. "without scan step");
  509. wpa_supplicant_associate(wpa_s, NULL, ssid);
  510. return;
  511. }
  512. }
  513. #ifdef CONFIG_P2P
  514. if ((wpa_s->p2p_in_provisioning || wpa_s->show_group_started) &&
  515. wpa_s->go_params) {
  516. wpa_printf(MSG_DEBUG, "P2P: Use specific SSID for scan during P2P group formation (p2p_in_provisioning=%d show_group_started=%d)",
  517. wpa_s->p2p_in_provisioning,
  518. wpa_s->show_group_started);
  519. params.ssids[0].ssid = wpa_s->go_params->ssid;
  520. params.ssids[0].ssid_len = wpa_s->go_params->ssid_len;
  521. params.num_ssids = 1;
  522. goto ssid_list_set;
  523. }
  524. #endif /* CONFIG_P2P */
  525. /* Find the starting point from which to continue scanning */
  526. ssid = wpa_s->conf->ssid;
  527. if (wpa_s->prev_scan_ssid != WILDCARD_SSID_SCAN) {
  528. while (ssid) {
  529. if (ssid == wpa_s->prev_scan_ssid) {
  530. ssid = ssid->next;
  531. break;
  532. }
  533. ssid = ssid->next;
  534. }
  535. }
  536. if (wpa_s->last_scan_req != MANUAL_SCAN_REQ &&
  537. wpa_s->conf->ap_scan == 2) {
  538. wpa_s->connect_without_scan = NULL;
  539. wpa_s->prev_scan_wildcard = 0;
  540. wpa_supplicant_assoc_try(wpa_s, ssid);
  541. return;
  542. } else if (wpa_s->conf->ap_scan == 2) {
  543. /*
  544. * User-initiated scan request in ap_scan == 2; scan with
  545. * wildcard SSID.
  546. */
  547. ssid = NULL;
  548. } else {
  549. struct wpa_ssid *start = ssid, *tssid;
  550. int freqs_set = 0;
  551. if (ssid == NULL && max_ssids > 1)
  552. ssid = wpa_s->conf->ssid;
  553. while (ssid) {
  554. if (!wpas_network_disabled(wpa_s, ssid) &&
  555. ssid->scan_ssid) {
  556. wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID",
  557. ssid->ssid, ssid->ssid_len);
  558. params.ssids[params.num_ssids].ssid =
  559. ssid->ssid;
  560. params.ssids[params.num_ssids].ssid_len =
  561. ssid->ssid_len;
  562. params.num_ssids++;
  563. if (params.num_ssids + 1 >= max_ssids)
  564. break;
  565. }
  566. ssid = ssid->next;
  567. if (ssid == start)
  568. break;
  569. if (ssid == NULL && max_ssids > 1 &&
  570. start != wpa_s->conf->ssid)
  571. ssid = wpa_s->conf->ssid;
  572. }
  573. for (tssid = wpa_s->conf->ssid; tssid; tssid = tssid->next) {
  574. if (wpas_network_disabled(wpa_s, tssid))
  575. continue;
  576. if ((params.freqs || !freqs_set) && tssid->scan_freq) {
  577. int_array_concat(&params.freqs,
  578. tssid->scan_freq);
  579. } else {
  580. os_free(params.freqs);
  581. params.freqs = NULL;
  582. }
  583. freqs_set = 1;
  584. }
  585. int_array_sort_unique(params.freqs);
  586. }
  587. if (ssid && max_ssids == 1) {
  588. /*
  589. * If the driver is limited to 1 SSID at a time interleave
  590. * wildcard SSID scans with specific SSID scans to avoid
  591. * waiting a long time for a wildcard scan.
  592. */
  593. if (!wpa_s->prev_scan_wildcard) {
  594. params.ssids[0].ssid = NULL;
  595. params.ssids[0].ssid_len = 0;
  596. wpa_s->prev_scan_wildcard = 1;
  597. wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for "
  598. "wildcard SSID (Interleave with specific)");
  599. } else {
  600. wpa_s->prev_scan_ssid = ssid;
  601. wpa_s->prev_scan_wildcard = 0;
  602. wpa_dbg(wpa_s, MSG_DEBUG,
  603. "Starting AP scan for specific SSID: %s",
  604. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  605. }
  606. } else if (ssid) {
  607. /* max_ssids > 1 */
  608. wpa_s->prev_scan_ssid = ssid;
  609. wpa_dbg(wpa_s, MSG_DEBUG, "Include wildcard SSID in "
  610. "the scan request");
  611. params.num_ssids++;
  612. } else if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
  613. wpa_s->manual_scan_passive && params.num_ssids == 0) {
  614. wpa_dbg(wpa_s, MSG_DEBUG, "Use passive scan based on manual request");
  615. } else {
  616. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  617. params.num_ssids++;
  618. wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for wildcard "
  619. "SSID");
  620. }
  621. #ifdef CONFIG_P2P
  622. ssid_list_set:
  623. #endif /* CONFIG_P2P */
  624. wpa_supplicant_optimize_freqs(wpa_s, &params);
  625. extra_ie = wpa_supplicant_extra_ies(wpa_s);
  626. if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && params.freqs == NULL &&
  627. wpa_s->manual_scan_freqs) {
  628. wpa_dbg(wpa_s, MSG_DEBUG, "Limit manual scan to specified channels");
  629. params.freqs = wpa_s->manual_scan_freqs;
  630. wpa_s->manual_scan_freqs = NULL;
  631. }
  632. if (params.freqs == NULL && wpa_s->next_scan_freqs) {
  633. wpa_dbg(wpa_s, MSG_DEBUG, "Optimize scan based on previously "
  634. "generated frequency list");
  635. params.freqs = wpa_s->next_scan_freqs;
  636. } else
  637. os_free(wpa_s->next_scan_freqs);
  638. wpa_s->next_scan_freqs = NULL;
  639. wpa_setband_scan_freqs(wpa_s, &params);
  640. /* See if user specified frequencies. If so, scan only those. */
  641. if (wpa_s->conf->freq_list && !params.freqs) {
  642. wpa_dbg(wpa_s, MSG_DEBUG,
  643. "Optimize scan based on conf->freq_list");
  644. int_array_concat(&params.freqs, wpa_s->conf->freq_list);
  645. }
  646. /* Use current associated channel? */
  647. if (wpa_s->conf->scan_cur_freq && !params.freqs) {
  648. unsigned int num = wpa_s->num_multichan_concurrent;
  649. params.freqs = os_calloc(num + 1, sizeof(int));
  650. if (params.freqs) {
  651. num = get_shared_radio_freqs(wpa_s, params.freqs, num);
  652. if (num > 0) {
  653. wpa_dbg(wpa_s, MSG_DEBUG, "Scan only the "
  654. "current operating channels since "
  655. "scan_cur_freq is enabled");
  656. } else {
  657. os_free(params.freqs);
  658. params.freqs = NULL;
  659. }
  660. }
  661. }
  662. params.filter_ssids = wpa_supplicant_build_filter_ssids(
  663. wpa_s->conf, &params.num_filter_ssids);
  664. if (extra_ie) {
  665. params.extra_ies = wpabuf_head(extra_ie);
  666. params.extra_ies_len = wpabuf_len(extra_ie);
  667. }
  668. #ifdef CONFIG_P2P
  669. if (wpa_s->p2p_in_provisioning ||
  670. (wpa_s->show_group_started && wpa_s->go_params)) {
  671. /*
  672. * The interface may not yet be in P2P mode, so we have to
  673. * explicitly request P2P probe to disable CCK rates.
  674. */
  675. params.p2p_probe = 1;
  676. }
  677. #endif /* CONFIG_P2P */
  678. scan_params = &params;
  679. scan:
  680. #ifdef CONFIG_P2P
  681. /*
  682. * If the driver does not support multi-channel concurrency and a
  683. * virtual interface that shares the same radio with the wpa_s interface
  684. * is operating there may not be need to scan other channels apart from
  685. * the current operating channel on the other virtual interface. Filter
  686. * out other channels in case we are trying to find a connection for a
  687. * station interface when we are not configured to prefer station
  688. * connection and a concurrent operation is already in process.
  689. */
  690. if (wpa_s->scan_for_connection &&
  691. wpa_s->last_scan_req == NORMAL_SCAN_REQ &&
  692. !scan_params->freqs && !params.freqs &&
  693. wpas_is_p2p_prioritized(wpa_s) &&
  694. wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE &&
  695. non_p2p_network_enabled(wpa_s)) {
  696. unsigned int num = wpa_s->num_multichan_concurrent;
  697. params.freqs = os_calloc(num + 1, sizeof(int));
  698. if (params.freqs) {
  699. num = get_shared_radio_freqs(wpa_s, params.freqs, num);
  700. if (num > 0 && num == wpa_s->num_multichan_concurrent) {
  701. wpa_dbg(wpa_s, MSG_DEBUG, "Scan only the current operating channels since all channels are already used");
  702. } else {
  703. os_free(params.freqs);
  704. params.freqs = NULL;
  705. }
  706. }
  707. }
  708. #endif /* CONFIG_P2P */
  709. ret = wpa_supplicant_trigger_scan(wpa_s, scan_params);
  710. if (ret && wpa_s->last_scan_req == MANUAL_SCAN_REQ && params.freqs &&
  711. !wpa_s->manual_scan_freqs) {
  712. /* Restore manual_scan_freqs for the next attempt */
  713. wpa_s->manual_scan_freqs = params.freqs;
  714. params.freqs = NULL;
  715. }
  716. wpabuf_free(extra_ie);
  717. os_free(params.freqs);
  718. os_free(params.filter_ssids);
  719. if (ret) {
  720. wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate AP scan");
  721. if (prev_state != wpa_s->wpa_state)
  722. wpa_supplicant_set_state(wpa_s, prev_state);
  723. /* Restore scan_req since we will try to scan again */
  724. wpa_s->scan_req = wpa_s->last_scan_req;
  725. wpa_supplicant_req_scan(wpa_s, 1, 0);
  726. } else {
  727. wpa_s->scan_for_connection = 0;
  728. }
  729. }
  730. void wpa_supplicant_update_scan_int(struct wpa_supplicant *wpa_s, int sec)
  731. {
  732. struct os_reltime remaining, new_int;
  733. int cancelled;
  734. cancelled = eloop_cancel_timeout_one(wpa_supplicant_scan, wpa_s, NULL,
  735. &remaining);
  736. new_int.sec = sec;
  737. new_int.usec = 0;
  738. if (cancelled && os_reltime_before(&remaining, &new_int)) {
  739. new_int.sec = remaining.sec;
  740. new_int.usec = remaining.usec;
  741. }
  742. if (cancelled) {
  743. eloop_register_timeout(new_int.sec, new_int.usec,
  744. wpa_supplicant_scan, wpa_s, NULL);
  745. }
  746. wpa_s->scan_interval = sec;
  747. }
  748. /**
  749. * wpa_supplicant_req_scan - Schedule a scan for neighboring access points
  750. * @wpa_s: Pointer to wpa_supplicant data
  751. * @sec: Number of seconds after which to scan
  752. * @usec: Number of microseconds after which to scan
  753. *
  754. * This function is used to schedule a scan for neighboring access points after
  755. * the specified time.
  756. */
  757. void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec)
  758. {
  759. if (eloop_deplete_timeout(sec, usec, wpa_supplicant_scan, wpa_s, NULL))
  760. {
  761. wpa_dbg(wpa_s, MSG_DEBUG, "Rescheduling scan request: %d sec %d usec",
  762. sec, usec);
  763. return;
  764. }
  765. wpa_dbg(wpa_s, MSG_DEBUG, "Setting scan request: %d sec %d usec",
  766. sec, usec);
  767. eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
  768. eloop_register_timeout(sec, usec, wpa_supplicant_scan, wpa_s, NULL);
  769. }
  770. /**
  771. * wpa_supplicant_delayed_sched_scan - Request a delayed scheduled scan
  772. * @wpa_s: Pointer to wpa_supplicant data
  773. * @sec: Number of seconds after which to scan
  774. * @usec: Number of microseconds after which to scan
  775. * Returns: 0 on success or -1 otherwise
  776. *
  777. * This function is used to schedule periodic scans for neighboring
  778. * access points after the specified time.
  779. */
  780. int wpa_supplicant_delayed_sched_scan(struct wpa_supplicant *wpa_s,
  781. int sec, int usec)
  782. {
  783. if (!wpa_s->sched_scan_supported)
  784. return -1;
  785. eloop_register_timeout(sec, usec,
  786. wpa_supplicant_delayed_sched_scan_timeout,
  787. wpa_s, NULL);
  788. return 0;
  789. }
  790. /**
  791. * wpa_supplicant_req_sched_scan - Start a periodic scheduled scan
  792. * @wpa_s: Pointer to wpa_supplicant data
  793. * Returns: 0 is sched_scan was started or -1 otherwise
  794. *
  795. * This function is used to schedule periodic scans for neighboring
  796. * access points repeating the scan continuously.
  797. */
  798. int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s)
  799. {
  800. struct wpa_driver_scan_params params;
  801. struct wpa_driver_scan_params *scan_params;
  802. enum wpa_states prev_state;
  803. struct wpa_ssid *ssid = NULL;
  804. struct wpabuf *extra_ie = NULL;
  805. int ret;
  806. unsigned int max_sched_scan_ssids;
  807. int wildcard = 0;
  808. int need_ssids;
  809. if (!wpa_s->sched_scan_supported)
  810. return -1;
  811. if (wpa_s->max_sched_scan_ssids > WPAS_MAX_SCAN_SSIDS)
  812. max_sched_scan_ssids = WPAS_MAX_SCAN_SSIDS;
  813. else
  814. max_sched_scan_ssids = wpa_s->max_sched_scan_ssids;
  815. if (max_sched_scan_ssids < 1 || wpa_s->conf->disable_scan_offload)
  816. return -1;
  817. if (wpa_s->sched_scanning) {
  818. wpa_dbg(wpa_s, MSG_DEBUG, "Already sched scanning");
  819. return 0;
  820. }
  821. need_ssids = 0;
  822. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  823. if (!wpas_network_disabled(wpa_s, ssid) && !ssid->scan_ssid) {
  824. /* Use wildcard SSID to find this network */
  825. wildcard = 1;
  826. } else if (!wpas_network_disabled(wpa_s, ssid) &&
  827. ssid->ssid_len)
  828. need_ssids++;
  829. #ifdef CONFIG_WPS
  830. if (!wpas_network_disabled(wpa_s, ssid) &&
  831. ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  832. /*
  833. * Normal scan is more reliable and faster for WPS
  834. * operations and since these are for short periods of
  835. * time, the benefit of trying to use sched_scan would
  836. * be limited.
  837. */
  838. wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of "
  839. "sched_scan for WPS");
  840. return -1;
  841. }
  842. #endif /* CONFIG_WPS */
  843. }
  844. if (wildcard)
  845. need_ssids++;
  846. if (wpa_s->normal_scans < 3 &&
  847. (need_ssids <= wpa_s->max_scan_ssids ||
  848. wpa_s->max_scan_ssids >= (int) max_sched_scan_ssids)) {
  849. /*
  850. * When normal scan can speed up operations, use that for the
  851. * first operations before starting the sched_scan to allow
  852. * user space sleep more. We do this only if the normal scan
  853. * has functionality that is suitable for this or if the
  854. * sched_scan does not have better support for multiple SSIDs.
  855. */
  856. wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of "
  857. "sched_scan for initial scans (normal_scans=%d)",
  858. wpa_s->normal_scans);
  859. return -1;
  860. }
  861. os_memset(&params, 0, sizeof(params));
  862. /* If we can't allocate space for the filters, we just don't filter */
  863. params.filter_ssids = os_zalloc(wpa_s->max_match_sets *
  864. sizeof(struct wpa_driver_scan_filter));
  865. prev_state = wpa_s->wpa_state;
  866. if (wpa_s->wpa_state == WPA_DISCONNECTED ||
  867. wpa_s->wpa_state == WPA_INACTIVE)
  868. wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
  869. if (wpa_s->autoscan_params != NULL) {
  870. scan_params = wpa_s->autoscan_params;
  871. goto scan;
  872. }
  873. /* Find the starting point from which to continue scanning */
  874. ssid = wpa_s->conf->ssid;
  875. if (wpa_s->prev_sched_ssid) {
  876. while (ssid) {
  877. if (ssid == wpa_s->prev_sched_ssid) {
  878. ssid = ssid->next;
  879. break;
  880. }
  881. ssid = ssid->next;
  882. }
  883. }
  884. if (!ssid || !wpa_s->prev_sched_ssid) {
  885. wpa_dbg(wpa_s, MSG_DEBUG, "Beginning of SSID list");
  886. if (wpa_s->conf->sched_scan_interval)
  887. wpa_s->sched_scan_interval =
  888. wpa_s->conf->sched_scan_interval;
  889. if (wpa_s->sched_scan_interval == 0)
  890. wpa_s->sched_scan_interval = 10;
  891. wpa_s->sched_scan_timeout = max_sched_scan_ssids * 2;
  892. wpa_s->first_sched_scan = 1;
  893. ssid = wpa_s->conf->ssid;
  894. wpa_s->prev_sched_ssid = ssid;
  895. }
  896. if (wildcard) {
  897. wpa_dbg(wpa_s, MSG_DEBUG, "Add wildcard SSID to sched_scan");
  898. params.num_ssids++;
  899. }
  900. while (ssid) {
  901. if (wpas_network_disabled(wpa_s, ssid))
  902. goto next;
  903. if (params.num_filter_ssids < wpa_s->max_match_sets &&
  904. params.filter_ssids && ssid->ssid && ssid->ssid_len) {
  905. wpa_dbg(wpa_s, MSG_DEBUG, "add to filter ssid: %s",
  906. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  907. os_memcpy(params.filter_ssids[params.num_filter_ssids].ssid,
  908. ssid->ssid, ssid->ssid_len);
  909. params.filter_ssids[params.num_filter_ssids].ssid_len =
  910. ssid->ssid_len;
  911. params.num_filter_ssids++;
  912. } else if (params.filter_ssids && ssid->ssid && ssid->ssid_len)
  913. {
  914. wpa_dbg(wpa_s, MSG_DEBUG, "Not enough room for SSID "
  915. "filter for sched_scan - drop filter");
  916. os_free(params.filter_ssids);
  917. params.filter_ssids = NULL;
  918. params.num_filter_ssids = 0;
  919. }
  920. if (ssid->scan_ssid && ssid->ssid && ssid->ssid_len) {
  921. if (params.num_ssids == max_sched_scan_ssids)
  922. break; /* only room for broadcast SSID */
  923. wpa_dbg(wpa_s, MSG_DEBUG,
  924. "add to active scan ssid: %s",
  925. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  926. params.ssids[params.num_ssids].ssid =
  927. ssid->ssid;
  928. params.ssids[params.num_ssids].ssid_len =
  929. ssid->ssid_len;
  930. params.num_ssids++;
  931. if (params.num_ssids >= max_sched_scan_ssids) {
  932. wpa_s->prev_sched_ssid = ssid;
  933. do {
  934. ssid = ssid->next;
  935. } while (ssid &&
  936. (wpas_network_disabled(wpa_s, ssid) ||
  937. !ssid->scan_ssid));
  938. break;
  939. }
  940. }
  941. next:
  942. wpa_s->prev_sched_ssid = ssid;
  943. ssid = ssid->next;
  944. }
  945. if (params.num_filter_ssids == 0) {
  946. os_free(params.filter_ssids);
  947. params.filter_ssids = NULL;
  948. }
  949. extra_ie = wpa_supplicant_extra_ies(wpa_s);
  950. if (extra_ie) {
  951. params.extra_ies = wpabuf_head(extra_ie);
  952. params.extra_ies_len = wpabuf_len(extra_ie);
  953. }
  954. scan_params = &params;
  955. scan:
  956. if (ssid || !wpa_s->first_sched_scan) {
  957. wpa_dbg(wpa_s, MSG_DEBUG,
  958. "Starting sched scan: interval %d timeout %d",
  959. wpa_s->sched_scan_interval, wpa_s->sched_scan_timeout);
  960. } else {
  961. wpa_dbg(wpa_s, MSG_DEBUG,
  962. "Starting sched scan: interval %d (no timeout)",
  963. wpa_s->sched_scan_interval);
  964. }
  965. wpa_setband_scan_freqs(wpa_s, scan_params);
  966. ret = wpa_supplicant_start_sched_scan(wpa_s, scan_params,
  967. wpa_s->sched_scan_interval);
  968. wpabuf_free(extra_ie);
  969. os_free(params.filter_ssids);
  970. if (ret) {
  971. wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate sched scan");
  972. if (prev_state != wpa_s->wpa_state)
  973. wpa_supplicant_set_state(wpa_s, prev_state);
  974. return ret;
  975. }
  976. /* If we have more SSIDs to scan, add a timeout so we scan them too */
  977. if (ssid || !wpa_s->first_sched_scan) {
  978. wpa_s->sched_scan_timed_out = 0;
  979. eloop_register_timeout(wpa_s->sched_scan_timeout, 0,
  980. wpa_supplicant_sched_scan_timeout,
  981. wpa_s, NULL);
  982. wpa_s->first_sched_scan = 0;
  983. wpa_s->sched_scan_timeout /= 2;
  984. wpa_s->sched_scan_interval *= 2;
  985. if (wpa_s->sched_scan_timeout < wpa_s->sched_scan_interval) {
  986. wpa_s->sched_scan_interval = 10;
  987. wpa_s->sched_scan_timeout = max_sched_scan_ssids * 2;
  988. }
  989. }
  990. /* If there is no more ssids, start next time from the beginning */
  991. if (!ssid)
  992. wpa_s->prev_sched_ssid = NULL;
  993. return 0;
  994. }
  995. /**
  996. * wpa_supplicant_cancel_scan - Cancel a scheduled scan request
  997. * @wpa_s: Pointer to wpa_supplicant data
  998. *
  999. * This function is used to cancel a scan request scheduled with
  1000. * wpa_supplicant_req_scan().
  1001. */
  1002. void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s)
  1003. {
  1004. wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling scan request");
  1005. eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
  1006. wpas_p2p_continue_after_scan(wpa_s);
  1007. }
  1008. /**
  1009. * wpa_supplicant_cancel_delayed_sched_scan - Stop a delayed scheduled scan
  1010. * @wpa_s: Pointer to wpa_supplicant data
  1011. *
  1012. * This function is used to stop a delayed scheduled scan.
  1013. */
  1014. void wpa_supplicant_cancel_delayed_sched_scan(struct wpa_supplicant *wpa_s)
  1015. {
  1016. if (!wpa_s->sched_scan_supported)
  1017. return;
  1018. wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling delayed sched scan");
  1019. eloop_cancel_timeout(wpa_supplicant_delayed_sched_scan_timeout,
  1020. wpa_s, NULL);
  1021. }
  1022. /**
  1023. * wpa_supplicant_cancel_sched_scan - Stop running scheduled scans
  1024. * @wpa_s: Pointer to wpa_supplicant data
  1025. *
  1026. * This function is used to stop a periodic scheduled scan.
  1027. */
  1028. void wpa_supplicant_cancel_sched_scan(struct wpa_supplicant *wpa_s)
  1029. {
  1030. if (!wpa_s->sched_scanning)
  1031. return;
  1032. wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling sched scan");
  1033. eloop_cancel_timeout(wpa_supplicant_sched_scan_timeout, wpa_s, NULL);
  1034. wpa_supplicant_stop_sched_scan(wpa_s);
  1035. }
  1036. /**
  1037. * wpa_supplicant_notify_scanning - Indicate possible scan state change
  1038. * @wpa_s: Pointer to wpa_supplicant data
  1039. * @scanning: Whether scanning is currently in progress
  1040. *
  1041. * This function is to generate scanning notifycations. It is called whenever
  1042. * there may have been a change in scanning (scan started, completed, stopped).
  1043. * wpas_notify_scanning() is called whenever the scanning state changed from the
  1044. * previously notified state.
  1045. */
  1046. void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s,
  1047. int scanning)
  1048. {
  1049. if (wpa_s->scanning != scanning) {
  1050. wpa_s->scanning = scanning;
  1051. wpas_notify_scanning(wpa_s);
  1052. }
  1053. }
  1054. static int wpa_scan_get_max_rate(const struct wpa_scan_res *res)
  1055. {
  1056. int rate = 0;
  1057. const u8 *ie;
  1058. int i;
  1059. ie = wpa_scan_get_ie(res, WLAN_EID_SUPP_RATES);
  1060. for (i = 0; ie && i < ie[1]; i++) {
  1061. if ((ie[i + 2] & 0x7f) > rate)
  1062. rate = ie[i + 2] & 0x7f;
  1063. }
  1064. ie = wpa_scan_get_ie(res, WLAN_EID_EXT_SUPP_RATES);
  1065. for (i = 0; ie && i < ie[1]; i++) {
  1066. if ((ie[i + 2] & 0x7f) > rate)
  1067. rate = ie[i + 2] & 0x7f;
  1068. }
  1069. return rate;
  1070. }
  1071. /**
  1072. * wpa_scan_get_ie - Fetch a specified information element from a scan result
  1073. * @res: Scan result entry
  1074. * @ie: Information element identitifier (WLAN_EID_*)
  1075. * Returns: Pointer to the information element (id field) or %NULL if not found
  1076. *
  1077. * This function returns the first matching information element in the scan
  1078. * result.
  1079. */
  1080. const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
  1081. {
  1082. const u8 *end, *pos;
  1083. pos = (const u8 *) (res + 1);
  1084. end = pos + res->ie_len;
  1085. while (pos + 1 < end) {
  1086. if (pos + 2 + pos[1] > end)
  1087. break;
  1088. if (pos[0] == ie)
  1089. return pos;
  1090. pos += 2 + pos[1];
  1091. }
  1092. return NULL;
  1093. }
  1094. /**
  1095. * wpa_scan_get_vendor_ie - Fetch vendor information element from a scan result
  1096. * @res: Scan result entry
  1097. * @vendor_type: Vendor type (four octets starting the IE payload)
  1098. * Returns: Pointer to the information element (id field) or %NULL if not found
  1099. *
  1100. * This function returns the first matching information element in the scan
  1101. * result.
  1102. */
  1103. const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
  1104. u32 vendor_type)
  1105. {
  1106. const u8 *end, *pos;
  1107. pos = (const u8 *) (res + 1);
  1108. end = pos + res->ie_len;
  1109. while (pos + 1 < end) {
  1110. if (pos + 2 + pos[1] > end)
  1111. break;
  1112. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  1113. vendor_type == WPA_GET_BE32(&pos[2]))
  1114. return pos;
  1115. pos += 2 + pos[1];
  1116. }
  1117. return NULL;
  1118. }
  1119. /**
  1120. * wpa_scan_get_vendor_ie_beacon - Fetch vendor information from a scan result
  1121. * @res: Scan result entry
  1122. * @vendor_type: Vendor type (four octets starting the IE payload)
  1123. * Returns: Pointer to the information element (id field) or %NULL if not found
  1124. *
  1125. * This function returns the first matching information element in the scan
  1126. * result.
  1127. *
  1128. * This function is like wpa_scan_get_vendor_ie(), but uses IE buffer only
  1129. * from Beacon frames instead of either Beacon or Probe Response frames.
  1130. */
  1131. const u8 * wpa_scan_get_vendor_ie_beacon(const struct wpa_scan_res *res,
  1132. u32 vendor_type)
  1133. {
  1134. const u8 *end, *pos;
  1135. if (res->beacon_ie_len == 0)
  1136. return NULL;
  1137. pos = (const u8 *) (res + 1);
  1138. pos += res->ie_len;
  1139. end = pos + res->beacon_ie_len;
  1140. while (pos + 1 < end) {
  1141. if (pos + 2 + pos[1] > end)
  1142. break;
  1143. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  1144. vendor_type == WPA_GET_BE32(&pos[2]))
  1145. return pos;
  1146. pos += 2 + pos[1];
  1147. }
  1148. return NULL;
  1149. }
  1150. /**
  1151. * wpa_scan_get_vendor_ie_multi - Fetch vendor IE data from a scan result
  1152. * @res: Scan result entry
  1153. * @vendor_type: Vendor type (four octets starting the IE payload)
  1154. * Returns: Pointer to the information element payload or %NULL if not found
  1155. *
  1156. * This function returns concatenated payload of possibly fragmented vendor
  1157. * specific information elements in the scan result. The caller is responsible
  1158. * for freeing the returned buffer.
  1159. */
  1160. struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
  1161. u32 vendor_type)
  1162. {
  1163. struct wpabuf *buf;
  1164. const u8 *end, *pos;
  1165. buf = wpabuf_alloc(res->ie_len);
  1166. if (buf == NULL)
  1167. return NULL;
  1168. pos = (const u8 *) (res + 1);
  1169. end = pos + res->ie_len;
  1170. while (pos + 1 < end) {
  1171. if (pos + 2 + pos[1] > end)
  1172. break;
  1173. if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
  1174. vendor_type == WPA_GET_BE32(&pos[2]))
  1175. wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
  1176. pos += 2 + pos[1];
  1177. }
  1178. if (wpabuf_len(buf) == 0) {
  1179. wpabuf_free(buf);
  1180. buf = NULL;
  1181. }
  1182. return buf;
  1183. }
  1184. /*
  1185. * Channels with a great SNR can operate at full rate. What is a great SNR?
  1186. * This doc https://supportforums.cisco.com/docs/DOC-12954 says, "the general
  1187. * rule of thumb is that any SNR above 20 is good." This one
  1188. * http://www.cisco.com/en/US/tech/tk722/tk809/technologies_q_and_a_item09186a00805e9a96.shtml#qa23
  1189. * recommends 25 as a minimum SNR for 54 Mbps data rate. 30 is chosen here as a
  1190. * conservative value.
  1191. */
  1192. #define GREAT_SNR 30
  1193. /* Compare function for sorting scan results. Return >0 if @b is considered
  1194. * better. */
  1195. static int wpa_scan_result_compar(const void *a, const void *b)
  1196. {
  1197. #define IS_5GHZ(n) (n > 4000)
  1198. #define MIN(a,b) a < b ? a : b
  1199. struct wpa_scan_res **_wa = (void *) a;
  1200. struct wpa_scan_res **_wb = (void *) b;
  1201. struct wpa_scan_res *wa = *_wa;
  1202. struct wpa_scan_res *wb = *_wb;
  1203. int wpa_a, wpa_b, maxrate_a, maxrate_b;
  1204. int snr_a, snr_b;
  1205. /* WPA/WPA2 support preferred */
  1206. wpa_a = wpa_scan_get_vendor_ie(wa, WPA_IE_VENDOR_TYPE) != NULL ||
  1207. wpa_scan_get_ie(wa, WLAN_EID_RSN) != NULL;
  1208. wpa_b = wpa_scan_get_vendor_ie(wb, WPA_IE_VENDOR_TYPE) != NULL ||
  1209. wpa_scan_get_ie(wb, WLAN_EID_RSN) != NULL;
  1210. if (wpa_b && !wpa_a)
  1211. return 1;
  1212. if (!wpa_b && wpa_a)
  1213. return -1;
  1214. /* privacy support preferred */
  1215. if ((wa->caps & IEEE80211_CAP_PRIVACY) == 0 &&
  1216. (wb->caps & IEEE80211_CAP_PRIVACY))
  1217. return 1;
  1218. if ((wa->caps & IEEE80211_CAP_PRIVACY) &&
  1219. (wb->caps & IEEE80211_CAP_PRIVACY) == 0)
  1220. return -1;
  1221. if ((wa->flags & wb->flags & WPA_SCAN_LEVEL_DBM) &&
  1222. !((wa->flags | wb->flags) & WPA_SCAN_NOISE_INVALID)) {
  1223. snr_a = MIN(wa->level - wa->noise, GREAT_SNR);
  1224. snr_b = MIN(wb->level - wb->noise, GREAT_SNR);
  1225. } else {
  1226. /* Not suitable information to calculate SNR, so use level */
  1227. snr_a = wa->level;
  1228. snr_b = wb->level;
  1229. }
  1230. /* best/max rate preferred if SNR close enough */
  1231. if ((snr_a && snr_b && abs(snr_b - snr_a) < 5) ||
  1232. (wa->qual && wb->qual && abs(wb->qual - wa->qual) < 10)) {
  1233. maxrate_a = wpa_scan_get_max_rate(wa);
  1234. maxrate_b = wpa_scan_get_max_rate(wb);
  1235. if (maxrate_a != maxrate_b)
  1236. return maxrate_b - maxrate_a;
  1237. if (IS_5GHZ(wa->freq) ^ IS_5GHZ(wb->freq))
  1238. return IS_5GHZ(wa->freq) ? -1 : 1;
  1239. }
  1240. /* use freq for channel preference */
  1241. /* all things being equal, use SNR; if SNRs are
  1242. * identical, use quality values since some drivers may only report
  1243. * that value and leave the signal level zero */
  1244. if (snr_b == snr_a)
  1245. return wb->qual - wa->qual;
  1246. return snr_b - snr_a;
  1247. #undef MIN
  1248. #undef IS_5GHZ
  1249. }
  1250. #ifdef CONFIG_WPS
  1251. /* Compare function for sorting scan results when searching a WPS AP for
  1252. * provisioning. Return >0 if @b is considered better. */
  1253. static int wpa_scan_result_wps_compar(const void *a, const void *b)
  1254. {
  1255. struct wpa_scan_res **_wa = (void *) a;
  1256. struct wpa_scan_res **_wb = (void *) b;
  1257. struct wpa_scan_res *wa = *_wa;
  1258. struct wpa_scan_res *wb = *_wb;
  1259. int uses_wps_a, uses_wps_b;
  1260. struct wpabuf *wps_a, *wps_b;
  1261. int res;
  1262. /* Optimization - check WPS IE existence before allocated memory and
  1263. * doing full reassembly. */
  1264. uses_wps_a = wpa_scan_get_vendor_ie(wa, WPS_IE_VENDOR_TYPE) != NULL;
  1265. uses_wps_b = wpa_scan_get_vendor_ie(wb, WPS_IE_VENDOR_TYPE) != NULL;
  1266. if (uses_wps_a && !uses_wps_b)
  1267. return -1;
  1268. if (!uses_wps_a && uses_wps_b)
  1269. return 1;
  1270. if (uses_wps_a && uses_wps_b) {
  1271. wps_a = wpa_scan_get_vendor_ie_multi(wa, WPS_IE_VENDOR_TYPE);
  1272. wps_b = wpa_scan_get_vendor_ie_multi(wb, WPS_IE_VENDOR_TYPE);
  1273. res = wps_ap_priority_compar(wps_a, wps_b);
  1274. wpabuf_free(wps_a);
  1275. wpabuf_free(wps_b);
  1276. if (res)
  1277. return res;
  1278. }
  1279. /*
  1280. * Do not use current AP security policy as a sorting criteria during
  1281. * WPS provisioning step since the AP may get reconfigured at the
  1282. * completion of provisioning.
  1283. */
  1284. /* all things being equal, use signal level; if signal levels are
  1285. * identical, use quality values since some drivers may only report
  1286. * that value and leave the signal level zero */
  1287. if (wb->level == wa->level)
  1288. return wb->qual - wa->qual;
  1289. return wb->level - wa->level;
  1290. }
  1291. #endif /* CONFIG_WPS */
  1292. static void dump_scan_res(struct wpa_scan_results *scan_res)
  1293. {
  1294. #ifndef CONFIG_NO_STDOUT_DEBUG
  1295. size_t i;
  1296. if (scan_res->res == NULL || scan_res->num == 0)
  1297. return;
  1298. wpa_printf(MSG_EXCESSIVE, "Sorted scan results");
  1299. for (i = 0; i < scan_res->num; i++) {
  1300. struct wpa_scan_res *r = scan_res->res[i];
  1301. u8 *pos;
  1302. if ((r->flags & (WPA_SCAN_LEVEL_DBM | WPA_SCAN_NOISE_INVALID))
  1303. == WPA_SCAN_LEVEL_DBM) {
  1304. int snr = r->level - r->noise;
  1305. wpa_printf(MSG_EXCESSIVE, MACSTR " freq=%d qual=%d "
  1306. "noise=%d level=%d snr=%d%s flags=0x%x "
  1307. "age=%u",
  1308. MAC2STR(r->bssid), r->freq, r->qual,
  1309. r->noise, r->level, snr,
  1310. snr >= GREAT_SNR ? "*" : "", r->flags,
  1311. r->age);
  1312. } else {
  1313. wpa_printf(MSG_EXCESSIVE, MACSTR " freq=%d qual=%d "
  1314. "noise=%d level=%d flags=0x%x age=%u",
  1315. MAC2STR(r->bssid), r->freq, r->qual,
  1316. r->noise, r->level, r->flags, r->age);
  1317. }
  1318. pos = (u8 *) (r + 1);
  1319. if (r->ie_len)
  1320. wpa_hexdump(MSG_EXCESSIVE, "IEs", pos, r->ie_len);
  1321. pos += r->ie_len;
  1322. if (r->beacon_ie_len)
  1323. wpa_hexdump(MSG_EXCESSIVE, "Beacon IEs",
  1324. pos, r->beacon_ie_len);
  1325. }
  1326. #endif /* CONFIG_NO_STDOUT_DEBUG */
  1327. }
  1328. /**
  1329. * wpa_supplicant_filter_bssid_match - Is the specified BSSID allowed
  1330. * @wpa_s: Pointer to wpa_supplicant data
  1331. * @bssid: BSSID to check
  1332. * Returns: 0 if the BSSID is filtered or 1 if not
  1333. *
  1334. * This function is used to filter out specific BSSIDs from scan reslts mainly
  1335. * for testing purposes (SET bssid_filter ctrl_iface command).
  1336. */
  1337. int wpa_supplicant_filter_bssid_match(struct wpa_supplicant *wpa_s,
  1338. const u8 *bssid)
  1339. {
  1340. size_t i;
  1341. if (wpa_s->bssid_filter == NULL)
  1342. return 1;
  1343. for (i = 0; i < wpa_s->bssid_filter_count; i++) {
  1344. if (os_memcmp(wpa_s->bssid_filter + i * ETH_ALEN, bssid,
  1345. ETH_ALEN) == 0)
  1346. return 1;
  1347. }
  1348. return 0;
  1349. }
  1350. static void filter_scan_res(struct wpa_supplicant *wpa_s,
  1351. struct wpa_scan_results *res)
  1352. {
  1353. size_t i, j;
  1354. if (wpa_s->bssid_filter == NULL)
  1355. return;
  1356. for (i = 0, j = 0; i < res->num; i++) {
  1357. if (wpa_supplicant_filter_bssid_match(wpa_s,
  1358. res->res[i]->bssid)) {
  1359. res->res[j++] = res->res[i];
  1360. } else {
  1361. os_free(res->res[i]);
  1362. res->res[i] = NULL;
  1363. }
  1364. }
  1365. if (res->num != j) {
  1366. wpa_printf(MSG_DEBUG, "Filtered out %d scan results",
  1367. (int) (res->num - j));
  1368. res->num = j;
  1369. }
  1370. }
  1371. /**
  1372. * wpa_supplicant_get_scan_results - Get scan results
  1373. * @wpa_s: Pointer to wpa_supplicant data
  1374. * @info: Information about what was scanned or %NULL if not available
  1375. * @new_scan: Whether a new scan was performed
  1376. * Returns: Scan results, %NULL on failure
  1377. *
  1378. * This function request the current scan results from the driver and updates
  1379. * the local BSS list wpa_s->bss. The caller is responsible for freeing the
  1380. * results with wpa_scan_results_free().
  1381. */
  1382. struct wpa_scan_results *
  1383. wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s,
  1384. struct scan_info *info, int new_scan)
  1385. {
  1386. struct wpa_scan_results *scan_res;
  1387. size_t i;
  1388. int (*compar)(const void *, const void *) = wpa_scan_result_compar;
  1389. scan_res = wpa_drv_get_scan_results2(wpa_s);
  1390. if (scan_res == NULL) {
  1391. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results");
  1392. return NULL;
  1393. }
  1394. if (scan_res->fetch_time.sec == 0) {
  1395. /*
  1396. * Make sure we have a valid timestamp if the driver wrapper
  1397. * does not set this.
  1398. */
  1399. os_get_reltime(&scan_res->fetch_time);
  1400. }
  1401. filter_scan_res(wpa_s, scan_res);
  1402. #ifdef CONFIG_WPS
  1403. if (wpas_wps_searching(wpa_s)) {
  1404. wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Order scan results with WPS "
  1405. "provisioning rules");
  1406. compar = wpa_scan_result_wps_compar;
  1407. }
  1408. #endif /* CONFIG_WPS */
  1409. qsort(scan_res->res, scan_res->num, sizeof(struct wpa_scan_res *),
  1410. compar);
  1411. dump_scan_res(scan_res);
  1412. wpa_bss_update_start(wpa_s);
  1413. for (i = 0; i < scan_res->num; i++)
  1414. wpa_bss_update_scan_res(wpa_s, scan_res->res[i],
  1415. &scan_res->fetch_time);
  1416. wpa_bss_update_end(wpa_s, info, new_scan);
  1417. return scan_res;
  1418. }
  1419. /**
  1420. * wpa_supplicant_update_scan_results - Update scan results from the driver
  1421. * @wpa_s: Pointer to wpa_supplicant data
  1422. * Returns: 0 on success, -1 on failure
  1423. *
  1424. * This function updates the BSS table within wpa_supplicant based on the
  1425. * currently available scan results from the driver without requesting a new
  1426. * scan. This is used in cases where the driver indicates an association
  1427. * (including roaming within ESS) and wpa_supplicant does not yet have the
  1428. * needed information to complete the connection (e.g., to perform validation
  1429. * steps in 4-way handshake).
  1430. */
  1431. int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s)
  1432. {
  1433. struct wpa_scan_results *scan_res;
  1434. scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0);
  1435. if (scan_res == NULL)
  1436. return -1;
  1437. wpa_scan_results_free(scan_res);
  1438. return 0;
  1439. }
  1440. /**
  1441. * scan_only_handler - Reports scan results
  1442. */
  1443. void scan_only_handler(struct wpa_supplicant *wpa_s,
  1444. struct wpa_scan_results *scan_res)
  1445. {
  1446. wpa_dbg(wpa_s, MSG_DEBUG, "Scan-only results received");
  1447. if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
  1448. wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
  1449. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
  1450. wpa_s->manual_scan_id);
  1451. wpa_s->manual_scan_use_id = 0;
  1452. } else {
  1453. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  1454. }
  1455. wpas_notify_scan_results(wpa_s);
  1456. wpas_notify_scan_done(wpa_s, 1);
  1457. }
  1458. int wpas_scan_scheduled(struct wpa_supplicant *wpa_s)
  1459. {
  1460. return eloop_is_timeout_registered(wpa_supplicant_scan, wpa_s, NULL);
  1461. }