2 * WPA Supplicant - Scanning
3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
15 #include "wpa_supplicant_i.h"
17 #include "wps_supplicant.h"
18 #include "p2p_supplicant.h"
20 #include "hs20_supplicant.h"
26 static void wpa_supplicant_gen_assoc_event(struct wpa_supplicant *wpa_s)
28 struct wpa_ssid *ssid;
29 union wpa_event_data data;
31 ssid = wpa_supplicant_get_ssid(wpa_s);
35 if (wpa_s->current_ssid == NULL) {
36 wpa_s->current_ssid = ssid;
37 if (wpa_s->current_ssid != NULL)
38 wpas_notify_network_changed(wpa_s);
40 wpa_supplicant_initiate_eapol(wpa_s);
41 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with a configured "
42 "network - generating associated event");
43 os_memset(&data, 0, sizeof(data));
44 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
49 static int wpas_wps_in_use(struct wpa_supplicant *wpa_s,
50 enum wps_request_type *req_type)
52 struct wpa_ssid *ssid;
55 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
56 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
60 *req_type = wpas_wps_get_req_type(ssid);
61 if (!ssid->eap.phase1)
64 if (os_strstr(ssid->eap.phase1, "pbc=1"))
69 if (!wpa_s->global->p2p_disabled && wpa_s->global->p2p &&
70 !wpa_s->conf->p2p_disabled) {
71 wpa_s->wps->dev.p2p = 1;
74 *req_type = WPS_REQ_ENROLLEE_INFO;
77 #endif /* CONFIG_P2P */
81 #endif /* CONFIG_WPS */
85 * wpa_supplicant_enabled_networks - Check whether there are enabled networks
86 * @wpa_s: Pointer to wpa_supplicant data
87 * Returns: 0 if no networks are enabled, >0 if networks are enabled
89 * This function is used to figure out whether any networks (or Interworking
90 * with enabled credentials and auto_interworking) are present in the current
93 int wpa_supplicant_enabled_networks(struct wpa_supplicant *wpa_s)
95 struct wpa_ssid *ssid = wpa_s->conf->ssid;
96 int count = 0, disabled = 0;
98 if (!wpas_network_disabled(wpa_s, ssid))
104 if (wpa_s->conf->cred && wpa_s->conf->interworking &&
105 wpa_s->conf->auto_interworking)
107 if (count == 0 && disabled > 0) {
108 wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks (%d disabled "
109 "networks)", disabled);
115 static void wpa_supplicant_assoc_try(struct wpa_supplicant *wpa_s,
116 struct wpa_ssid *ssid)
119 if (!wpas_network_disabled(wpa_s, ssid))
124 /* ap_scan=2 mode - try to associate with each SSID. */
126 wpa_dbg(wpa_s, MSG_DEBUG, "wpa_supplicant_assoc_try: Reached "
127 "end of scan list - go back to beginning");
128 wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
129 wpa_supplicant_req_scan(wpa_s, 0, 0);
133 /* Continue from the next SSID on the next attempt. */
134 wpa_s->prev_scan_ssid = ssid;
136 /* Start from the beginning of the SSID list. */
137 wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
139 wpa_supplicant_associate(wpa_s, NULL, ssid);
143 static int int_array_len(const int *a)
146 for (i = 0; a && a[i]; i++)
152 static void int_array_concat(int **res, const int *a)
157 reslen = int_array_len(*res);
158 alen = int_array_len(a);
160 n = os_realloc_array(*res, reslen + alen + 1, sizeof(int));
166 for (i = 0; i <= alen; i++)
167 n[reslen + i] = a[i];
172 static int freq_cmp(const void *a, const void *b)
185 static void int_array_sort_unique(int *a)
193 alen = int_array_len(a);
194 qsort(a, alen, sizeof(int), freq_cmp);
198 while (a[i] && a[j]) {
212 * wpa_supplicant_trigger_scan - Request driver to start a scan
213 * @wpa_s: Pointer to wpa_supplicant data
214 * @params: Scan parameters
215 * Returns: 0 on success, -1 on failure
217 int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
218 struct wpa_driver_scan_params *params)
222 wpa_supplicant_notify_scanning(wpa_s, 1);
224 ret = wpa_drv_scan(wpa_s, params);
226 wpa_supplicant_notify_scanning(wpa_s, 0);
227 wpas_notify_scan_done(wpa_s, 0);
230 wpa_s->normal_scans++;
238 wpa_supplicant_delayed_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx)
240 struct wpa_supplicant *wpa_s = eloop_ctx;
242 wpa_dbg(wpa_s, MSG_DEBUG, "Starting delayed sched scan");
244 if (wpa_supplicant_req_sched_scan(wpa_s))
245 wpa_supplicant_req_scan(wpa_s, 0, 0);
250 wpa_supplicant_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx)
252 struct wpa_supplicant *wpa_s = eloop_ctx;
254 wpa_dbg(wpa_s, MSG_DEBUG, "Sched scan timeout - stopping it");
256 wpa_s->sched_scan_timed_out = 1;
257 wpa_supplicant_cancel_sched_scan(wpa_s);
262 wpa_supplicant_start_sched_scan(struct wpa_supplicant *wpa_s,
263 struct wpa_driver_scan_params *params,
268 wpa_supplicant_notify_scanning(wpa_s, 1);
269 ret = wpa_drv_sched_scan(wpa_s, params, interval * 1000);
271 wpa_supplicant_notify_scanning(wpa_s, 0);
273 wpa_s->sched_scanning = 1;
279 static int wpa_supplicant_stop_sched_scan(struct wpa_supplicant *wpa_s)
283 ret = wpa_drv_stop_sched_scan(wpa_s);
285 wpa_dbg(wpa_s, MSG_DEBUG, "stopping sched_scan failed!");
286 /* TODO: what to do if stopping fails? */
294 static struct wpa_driver_scan_filter *
295 wpa_supplicant_build_filter_ssids(struct wpa_config *conf, size_t *num_ssids)
297 struct wpa_driver_scan_filter *ssids;
298 struct wpa_ssid *ssid;
302 if (!conf->filter_ssids)
305 for (count = 0, ssid = conf->ssid; ssid; ssid = ssid->next) {
306 if (ssid->ssid && ssid->ssid_len)
311 ssids = os_zalloc(count * sizeof(struct wpa_driver_scan_filter));
315 for (ssid = conf->ssid; ssid; ssid = ssid->next) {
316 if (!ssid->ssid || !ssid->ssid_len)
318 os_memcpy(ssids[*num_ssids].ssid, ssid->ssid, ssid->ssid_len);
319 ssids[*num_ssids].ssid_len = ssid->ssid_len;
327 static void wpa_supplicant_optimize_freqs(
328 struct wpa_supplicant *wpa_s, struct wpa_driver_scan_params *params)
331 if (params->freqs == NULL && wpa_s->p2p_in_provisioning &&
333 /* Optimize provisioning state scan based on GO information */
334 if (wpa_s->p2p_in_provisioning < 5 &&
335 wpa_s->go_params->freq > 0) {
336 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only GO "
337 "preferred frequency %d MHz",
338 wpa_s->go_params->freq);
339 params->freqs = os_zalloc(2 * sizeof(int));
341 params->freqs[0] = wpa_s->go_params->freq;
342 } else if (wpa_s->p2p_in_provisioning < 8 &&
343 wpa_s->go_params->freq_list[0]) {
344 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only common "
346 int_array_concat(¶ms->freqs,
347 wpa_s->go_params->freq_list);
349 int_array_sort_unique(params->freqs);
351 wpa_s->p2p_in_provisioning++;
353 #endif /* CONFIG_P2P */
356 if (params->freqs == NULL && wpa_s->after_wps && wpa_s->wps_freq) {
358 * Optimize post-provisioning scan based on channel used
359 * during provisioning.
361 wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz "
362 "that was used during provisioning", wpa_s->wps_freq);
363 params->freqs = os_zalloc(2 * sizeof(int));
365 params->freqs[0] = wpa_s->wps_freq;
369 if (params->freqs == NULL && wpa_s->known_wps_freq && wpa_s->wps_freq)
371 /* Optimize provisioning scan based on already known channel */
372 wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz",
374 params->freqs = os_zalloc(2 * sizeof(int));
376 params->freqs[0] = wpa_s->wps_freq;
377 wpa_s->known_wps_freq = 0; /* only do this once */
379 #endif /* CONFIG_WPS */
383 #ifdef CONFIG_INTERWORKING
384 static void wpas_add_interworking_elements(struct wpa_supplicant *wpa_s,
387 if (wpa_s->conf->interworking == 0)
390 wpabuf_put_u8(buf, WLAN_EID_EXT_CAPAB);
391 wpabuf_put_u8(buf, 4);
392 wpabuf_put_u8(buf, 0x00);
393 wpabuf_put_u8(buf, 0x00);
394 wpabuf_put_u8(buf, 0x00);
395 wpabuf_put_u8(buf, 0x80); /* Bit 31 - Interworking */
397 wpabuf_put_u8(buf, WLAN_EID_INTERWORKING);
398 wpabuf_put_u8(buf, is_zero_ether_addr(wpa_s->conf->hessid) ? 1 :
400 wpabuf_put_u8(buf, wpa_s->conf->access_network_type);
402 if (!is_zero_ether_addr(wpa_s->conf->hessid))
403 wpabuf_put_data(buf, wpa_s->conf->hessid, ETH_ALEN);
405 #endif /* CONFIG_INTERWORKING */
408 static struct wpabuf * wpa_supplicant_extra_ies(struct wpa_supplicant *wpa_s)
410 struct wpabuf *extra_ie = NULL;
413 enum wps_request_type req_type = WPS_REQ_ENROLLEE_INFO;
414 #endif /* CONFIG_WPS */
416 #ifdef CONFIG_INTERWORKING
417 if (wpa_s->conf->interworking &&
418 wpabuf_resize(&extra_ie, 100) == 0)
419 wpas_add_interworking_elements(wpa_s, extra_ie);
420 #endif /* CONFIG_INTERWORKING */
423 wps = wpas_wps_in_use(wpa_s, &req_type);
426 struct wpabuf *wps_ie;
427 wps_ie = wps_build_probe_req_ie(wps == 2 ? DEV_PW_PUSHBUTTON :
430 wpa_s->wps->uuid, req_type,
433 if (wpabuf_resize(&extra_ie, wpabuf_len(wps_ie)) == 0)
434 wpabuf_put_buf(extra_ie, wps_ie);
441 size_t ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
442 if (wpabuf_resize(&extra_ie, ielen) == 0)
443 wpas_p2p_scan_ie(wpa_s, extra_ie);
445 #endif /* CONFIG_P2P */
447 #endif /* CONFIG_WPS */
456 * Check whether there are any enabled networks or credentials that could be
457 * used for a non-P2P connection.
459 static int non_p2p_network_enabled(struct wpa_supplicant *wpa_s)
461 struct wpa_ssid *ssid;
463 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
464 if (wpas_network_disabled(wpa_s, ssid))
466 if (!ssid->p2p_group)
470 if (wpa_s->conf->cred && wpa_s->conf->interworking &&
471 wpa_s->conf->auto_interworking)
479 * Find the operating frequency of any other virtual interface that is using
480 * the same radio concurrently.
482 static int shared_vif_oper_freq(struct wpa_supplicant *wpa_s)
484 const char *rn, *rn2;
485 struct wpa_supplicant *ifs;
488 if (!wpa_s->driver->get_radio_name)
491 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
492 if (rn == NULL || rn[0] == '\0')
495 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
496 if (ifs == wpa_s || !ifs->driver->get_radio_name)
499 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
500 if (!rn2 || os_strcmp(rn, rn2) != 0)
503 if (ifs->current_ssid == NULL || ifs->assoc_freq == 0)
506 if (ifs->current_ssid->mode == WPAS_MODE_AP ||
507 ifs->current_ssid->mode == WPAS_MODE_P2P_GO)
508 return ifs->current_ssid->frequency;
509 if (wpa_drv_get_bssid(ifs, bssid) == 0)
510 return ifs->assoc_freq;
516 #endif /* CONFIG_P2P */
519 static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
521 struct wpa_supplicant *wpa_s = eloop_ctx;
522 struct wpa_ssid *ssid;
523 enum scan_req_type scan_req = NORMAL_SCAN_REQ;
525 struct wpabuf *extra_ie = NULL;
526 struct wpa_driver_scan_params params;
527 struct wpa_driver_scan_params *scan_params;
529 enum wpa_states prev_state;
531 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
532 wpa_dbg(wpa_s, MSG_DEBUG, "Skip scan - interface disabled");
536 if (wpa_s->disconnected && wpa_s->scan_req == NORMAL_SCAN_REQ) {
537 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnected - do not scan");
538 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
542 if (!wpa_supplicant_enabled_networks(wpa_s) &&
543 wpa_s->scan_req == NORMAL_SCAN_REQ) {
544 wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks - do not scan");
545 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
547 wpa_s->sta_scan_pending = 0;
548 #endif /* CONFIG_P2P */
552 if (wpa_s->conf->ap_scan != 0 &&
553 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) {
554 wpa_dbg(wpa_s, MSG_DEBUG, "Using wired authentication - "
555 "overriding ap_scan configuration");
556 wpa_s->conf->ap_scan = 0;
557 wpas_notify_ap_scan_changed(wpa_s);
560 if (wpa_s->conf->ap_scan == 0) {
561 wpa_supplicant_gen_assoc_event(wpa_s);
566 if (wpas_p2p_in_progress(wpa_s)) {
567 if (wpa_s->sta_scan_pending &&
568 wpas_p2p_in_progress(wpa_s) == 2 &&
569 wpa_s->global->p2p_cb_on_scan_complete) {
570 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending station "
571 "mode scan during P2P search");
573 wpa_dbg(wpa_s, MSG_DEBUG, "Delay station mode scan "
574 "while P2P operation is in progress");
575 wpa_s->sta_scan_pending = 1;
576 wpa_supplicant_req_scan(wpa_s, 5, 0);
580 #endif /* CONFIG_P2P */
582 if (wpa_s->conf->ap_scan == 2)
585 max_ssids = wpa_s->max_scan_ssids;
586 if (max_ssids > WPAS_MAX_SCAN_SSIDS)
587 max_ssids = WPAS_MAX_SCAN_SSIDS;
590 scan_req = wpa_s->scan_req;
591 wpa_s->scan_req = NORMAL_SCAN_REQ;
593 os_memset(¶ms, 0, sizeof(params));
595 prev_state = wpa_s->wpa_state;
596 if (wpa_s->wpa_state == WPA_DISCONNECTED ||
597 wpa_s->wpa_state == WPA_INACTIVE)
598 wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
601 * If autoscan has set its own scanning parameters
603 if (wpa_s->autoscan_params != NULL) {
604 scan_params = wpa_s->autoscan_params;
608 if (scan_req != MANUAL_SCAN_REQ && wpa_s->connect_without_scan) {
609 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
610 if (ssid == wpa_s->connect_without_scan)
613 wpa_s->connect_without_scan = NULL;
615 wpa_printf(MSG_DEBUG, "Start a pre-selected network "
616 "without scan step");
617 wpa_supplicant_associate(wpa_s, NULL, ssid);
623 if ((wpa_s->p2p_in_provisioning || wpa_s->show_group_started) &&
625 wpa_printf(MSG_DEBUG, "P2P: Use specific SSID for scan during "
626 "P2P group formation");
627 params.ssids[0].ssid = wpa_s->go_params->ssid;
628 params.ssids[0].ssid_len = wpa_s->go_params->ssid_len;
629 params.num_ssids = 1;
632 #endif /* CONFIG_P2P */
634 /* Find the starting point from which to continue scanning */
635 ssid = wpa_s->conf->ssid;
636 if (wpa_s->prev_scan_ssid != WILDCARD_SSID_SCAN) {
638 if (ssid == wpa_s->prev_scan_ssid) {
646 if (scan_req != MANUAL_SCAN_REQ && wpa_s->conf->ap_scan == 2) {
647 wpa_s->connect_without_scan = NULL;
648 wpa_s->prev_scan_wildcard = 0;
649 wpa_supplicant_assoc_try(wpa_s, ssid);
651 } else if (wpa_s->conf->ap_scan == 2) {
653 * User-initiated scan request in ap_scan == 2; scan with
658 struct wpa_ssid *start = ssid, *tssid;
660 if (ssid == NULL && max_ssids > 1)
661 ssid = wpa_s->conf->ssid;
663 if (!wpas_network_disabled(wpa_s, ssid) &&
665 wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID",
666 ssid->ssid, ssid->ssid_len);
667 params.ssids[params.num_ssids].ssid =
669 params.ssids[params.num_ssids].ssid_len =
672 if (params.num_ssids + 1 >= max_ssids)
678 if (ssid == NULL && max_ssids > 1 &&
679 start != wpa_s->conf->ssid)
680 ssid = wpa_s->conf->ssid;
683 for (tssid = wpa_s->conf->ssid; tssid; tssid = tssid->next) {
684 if (wpas_network_disabled(wpa_s, tssid))
686 if ((params.freqs || !freqs_set) && tssid->scan_freq) {
687 int_array_concat(¶ms.freqs,
690 os_free(params.freqs);
695 int_array_sort_unique(params.freqs);
698 if (ssid && max_ssids == 1) {
700 * If the driver is limited to 1 SSID at a time interleave
701 * wildcard SSID scans with specific SSID scans to avoid
702 * waiting a long time for a wildcard scan.
704 if (!wpa_s->prev_scan_wildcard) {
705 params.ssids[0].ssid = NULL;
706 params.ssids[0].ssid_len = 0;
707 wpa_s->prev_scan_wildcard = 1;
708 wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for "
709 "wildcard SSID (Interleave with specific)");
711 wpa_s->prev_scan_ssid = ssid;
712 wpa_s->prev_scan_wildcard = 0;
713 wpa_dbg(wpa_s, MSG_DEBUG,
714 "Starting AP scan for specific SSID: %s",
715 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
720 wpa_s->prev_scan_ssid = ssid;
721 wpa_dbg(wpa_s, MSG_DEBUG, "Include wildcard SSID in "
725 wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
727 wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for wildcard "
732 #endif /* CONFIG_P2P */
734 wpa_supplicant_optimize_freqs(wpa_s, ¶ms);
735 extra_ie = wpa_supplicant_extra_ies(wpa_s);
738 if (wpa_s->conf->hs20 && wpabuf_resize(&extra_ie, 7) == 0)
739 wpas_hs20_add_indication(extra_ie);
740 #endif /* CONFIG_HS20 */
742 if (params.freqs == NULL && wpa_s->next_scan_freqs) {
743 wpa_dbg(wpa_s, MSG_DEBUG, "Optimize scan based on previously "
744 "generated frequency list");
745 params.freqs = wpa_s->next_scan_freqs;
747 os_free(wpa_s->next_scan_freqs);
748 wpa_s->next_scan_freqs = NULL;
750 params.filter_ssids = wpa_supplicant_build_filter_ssids(
751 wpa_s->conf, ¶ms.num_filter_ssids);
753 params.extra_ies = wpabuf_head(extra_ie);
754 params.extra_ies_len = wpabuf_len(extra_ie);
758 if (wpa_s->p2p_in_provisioning ||
759 (wpa_s->show_group_started && wpa_s->go_params)) {
761 * The interface may not yet be in P2P mode, so we have to
762 * explicitly request P2P probe to disable CCK rates.
764 params.p2p_probe = 1;
766 #endif /* CONFIG_P2P */
768 scan_params = ¶ms;
773 * If the driver does not support multi-channel concurrency and a
774 * virtual interface that shares the same radio with the wpa_s interface
775 * is operating there may not be need to scan other channels apart from
776 * the current operating channel on the other virtual interface. Filter
777 * out other channels in case we are trying to find a connection for a
778 * station interface when we are not configured to prefer station
779 * connection and a concurrent operation is already in process.
781 if (wpa_s->scan_for_connection && scan_req == NORMAL_SCAN_REQ &&
782 !scan_params->freqs && !params.freqs &&
783 wpas_is_p2p_prioritized(wpa_s) &&
784 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT) &&
785 wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE &&
786 non_p2p_network_enabled(wpa_s)) {
787 int freq = shared_vif_oper_freq(wpa_s);
789 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only the current "
790 "operating channel (%d MHz) since driver does "
791 "not support multi-channel concurrency", freq);
792 params.freqs = os_zalloc(sizeof(int) * 2);
794 params.freqs[0] = freq;
795 scan_params->freqs = params.freqs;
798 #endif /* CONFIG_P2P */
800 ret = wpa_supplicant_trigger_scan(wpa_s, scan_params);
802 wpabuf_free(extra_ie);
803 os_free(params.freqs);
804 os_free(params.filter_ssids);
807 wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate AP scan");
808 if (prev_state != wpa_s->wpa_state)
809 wpa_supplicant_set_state(wpa_s, prev_state);
810 /* Restore scan_req since we will try to scan again */
811 wpa_s->scan_req = scan_req;
812 wpa_supplicant_req_scan(wpa_s, 1, 0);
814 wpa_s->scan_for_connection = 0;
819 void wpa_supplicant_update_scan_int(struct wpa_supplicant *wpa_s, int sec)
821 struct os_time remaining, new_int;
824 cancelled = eloop_cancel_timeout_one(wpa_supplicant_scan, wpa_s, NULL,
829 if (cancelled && os_time_before(&remaining, &new_int)) {
830 new_int.sec = remaining.sec;
831 new_int.usec = remaining.usec;
834 eloop_register_timeout(new_int.sec, new_int.usec, wpa_supplicant_scan,
836 wpa_s->scan_interval = sec;
841 * wpa_supplicant_req_scan - Schedule a scan for neighboring access points
842 * @wpa_s: Pointer to wpa_supplicant data
843 * @sec: Number of seconds after which to scan
844 * @usec: Number of microseconds after which to scan
846 * This function is used to schedule a scan for neighboring access points after
847 * the specified time.
849 void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec)
851 /* If there's at least one network that should be specifically scanned
852 * then don't cancel the scan and reschedule. Some drivers do
853 * background scanning which generates frequent scan results, and that
854 * causes the specific SSID scan to get continually pushed back and
855 * never happen, which causes hidden APs to never get probe-scanned.
857 if (eloop_is_timeout_registered(wpa_supplicant_scan, wpa_s, NULL) &&
858 wpa_s->conf->ap_scan == 1) {
859 struct wpa_ssid *ssid = wpa_s->conf->ssid;
862 if (!wpas_network_disabled(wpa_s, ssid) &&
868 wpa_dbg(wpa_s, MSG_DEBUG, "Not rescheduling scan to "
869 "ensure that specific SSID scans occur");
874 wpa_dbg(wpa_s, MSG_DEBUG, "Setting scan request: %d sec %d usec",
876 eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
877 eloop_register_timeout(sec, usec, wpa_supplicant_scan, wpa_s, NULL);
882 * wpa_supplicant_delayed_sched_scan - Request a delayed scheduled scan
883 * @wpa_s: Pointer to wpa_supplicant data
884 * @sec: Number of seconds after which to scan
885 * @usec: Number of microseconds after which to scan
886 * Returns: 0 on success or -1 otherwise
888 * This function is used to schedule periodic scans for neighboring
889 * access points after the specified time.
891 int wpa_supplicant_delayed_sched_scan(struct wpa_supplicant *wpa_s,
894 if (!wpa_s->sched_scan_supported)
897 eloop_register_timeout(sec, usec,
898 wpa_supplicant_delayed_sched_scan_timeout,
906 * wpa_supplicant_req_sched_scan - Start a periodic scheduled scan
907 * @wpa_s: Pointer to wpa_supplicant data
908 * Returns: 0 is sched_scan was started or -1 otherwise
910 * This function is used to schedule periodic scans for neighboring
911 * access points repeating the scan continuously.
913 int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s)
915 struct wpa_driver_scan_params params;
916 struct wpa_driver_scan_params *scan_params;
917 enum wpa_states prev_state;
918 struct wpa_ssid *ssid = NULL;
919 struct wpabuf *extra_ie = NULL;
921 unsigned int max_sched_scan_ssids;
925 if (!wpa_s->sched_scan_supported)
928 if (wpa_s->max_sched_scan_ssids > WPAS_MAX_SCAN_SSIDS)
929 max_sched_scan_ssids = WPAS_MAX_SCAN_SSIDS;
931 max_sched_scan_ssids = wpa_s->max_sched_scan_ssids;
932 if (max_sched_scan_ssids < 1 || wpa_s->conf->disable_scan_offload)
935 if (wpa_s->sched_scanning) {
936 wpa_dbg(wpa_s, MSG_DEBUG, "Already sched scanning");
941 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
942 if (!wpas_network_disabled(wpa_s, ssid) && !ssid->scan_ssid) {
943 /* Use wildcard SSID to find this network */
945 } else if (!wpas_network_disabled(wpa_s, ssid) &&
950 if (!wpas_network_disabled(wpa_s, ssid) &&
951 ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
953 * Normal scan is more reliable and faster for WPS
954 * operations and since these are for short periods of
955 * time, the benefit of trying to use sched_scan would
958 wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of "
959 "sched_scan for WPS");
962 #endif /* CONFIG_WPS */
967 if (wpa_s->normal_scans < 3 &&
968 (need_ssids <= wpa_s->max_scan_ssids ||
969 wpa_s->max_scan_ssids >= (int) max_sched_scan_ssids)) {
971 * When normal scan can speed up operations, use that for the
972 * first operations before starting the sched_scan to allow
973 * user space sleep more. We do this only if the normal scan
974 * has functionality that is suitable for this or if the
975 * sched_scan does not have better support for multiple SSIDs.
977 wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of "
978 "sched_scan for initial scans (normal_scans=%d)",
979 wpa_s->normal_scans);
983 os_memset(¶ms, 0, sizeof(params));
985 /* If we can't allocate space for the filters, we just don't filter */
986 params.filter_ssids = os_zalloc(wpa_s->max_match_sets *
987 sizeof(struct wpa_driver_scan_filter));
989 prev_state = wpa_s->wpa_state;
990 if (wpa_s->wpa_state == WPA_DISCONNECTED ||
991 wpa_s->wpa_state == WPA_INACTIVE)
992 wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
994 if (wpa_s->autoscan_params != NULL) {
995 scan_params = wpa_s->autoscan_params;
999 /* Find the starting point from which to continue scanning */
1000 ssid = wpa_s->conf->ssid;
1001 if (wpa_s->prev_sched_ssid) {
1003 if (ssid == wpa_s->prev_sched_ssid) {
1011 if (!ssid || !wpa_s->prev_sched_ssid) {
1012 wpa_dbg(wpa_s, MSG_DEBUG, "Beginning of SSID list");
1014 if (wpa_s->sched_scan_interval == 0)
1015 wpa_s->sched_scan_interval = 10;
1016 wpa_s->sched_scan_timeout = max_sched_scan_ssids * 2;
1017 wpa_s->first_sched_scan = 1;
1018 ssid = wpa_s->conf->ssid;
1019 wpa_s->prev_sched_ssid = ssid;
1023 wpa_dbg(wpa_s, MSG_DEBUG, "Add wildcard SSID to sched_scan");
1028 if (wpas_network_disabled(wpa_s, ssid))
1031 if (params.num_filter_ssids < wpa_s->max_match_sets &&
1032 params.filter_ssids && ssid->ssid && ssid->ssid_len) {
1033 wpa_dbg(wpa_s, MSG_DEBUG, "add to filter ssid: %s",
1034 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1035 os_memcpy(params.filter_ssids[params.num_filter_ssids].ssid,
1036 ssid->ssid, ssid->ssid_len);
1037 params.filter_ssids[params.num_filter_ssids].ssid_len =
1039 params.num_filter_ssids++;
1040 } else if (params.filter_ssids && ssid->ssid && ssid->ssid_len)
1042 wpa_dbg(wpa_s, MSG_DEBUG, "Not enough room for SSID "
1043 "filter for sched_scan - drop filter");
1044 os_free(params.filter_ssids);
1045 params.filter_ssids = NULL;
1046 params.num_filter_ssids = 0;
1049 if (ssid->scan_ssid && ssid->ssid && ssid->ssid_len) {
1050 if (params.num_ssids == max_sched_scan_ssids)
1051 break; /* only room for broadcast SSID */
1052 wpa_dbg(wpa_s, MSG_DEBUG,
1053 "add to active scan ssid: %s",
1054 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1055 params.ssids[params.num_ssids].ssid =
1057 params.ssids[params.num_ssids].ssid_len =
1060 if (params.num_ssids >= max_sched_scan_ssids) {
1061 wpa_s->prev_sched_ssid = ssid;
1065 (wpas_network_disabled(wpa_s, ssid) ||
1072 wpa_s->prev_sched_ssid = ssid;
1076 if (params.num_filter_ssids == 0) {
1077 os_free(params.filter_ssids);
1078 params.filter_ssids = NULL;
1081 extra_ie = wpa_supplicant_extra_ies(wpa_s);
1083 params.extra_ies = wpabuf_head(extra_ie);
1084 params.extra_ies_len = wpabuf_len(extra_ie);
1087 scan_params = ¶ms;
1090 if (ssid || !wpa_s->first_sched_scan) {
1091 wpa_dbg(wpa_s, MSG_DEBUG,
1092 "Starting sched scan: interval %d timeout %d",
1093 wpa_s->sched_scan_interval, wpa_s->sched_scan_timeout);
1095 wpa_dbg(wpa_s, MSG_DEBUG,
1096 "Starting sched scan: interval %d (no timeout)",
1097 wpa_s->sched_scan_interval);
1100 ret = wpa_supplicant_start_sched_scan(wpa_s, scan_params,
1101 wpa_s->sched_scan_interval);
1102 wpabuf_free(extra_ie);
1103 os_free(params.filter_ssids);
1105 wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate sched scan");
1106 if (prev_state != wpa_s->wpa_state)
1107 wpa_supplicant_set_state(wpa_s, prev_state);
1111 /* If we have more SSIDs to scan, add a timeout so we scan them too */
1112 if (ssid || !wpa_s->first_sched_scan) {
1113 wpa_s->sched_scan_timed_out = 0;
1114 eloop_register_timeout(wpa_s->sched_scan_timeout, 0,
1115 wpa_supplicant_sched_scan_timeout,
1117 wpa_s->first_sched_scan = 0;
1118 wpa_s->sched_scan_timeout /= 2;
1119 wpa_s->sched_scan_interval *= 2;
1127 * wpa_supplicant_cancel_scan - Cancel a scheduled scan request
1128 * @wpa_s: Pointer to wpa_supplicant data
1130 * This function is used to cancel a scan request scheduled with
1131 * wpa_supplicant_req_scan().
1133 void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s)
1135 wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling scan request");
1136 eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
1141 * wpa_supplicant_cancel_sched_scan - Stop running scheduled scans
1142 * @wpa_s: Pointer to wpa_supplicant data
1144 * This function is used to stop a periodic scheduled scan.
1146 void wpa_supplicant_cancel_sched_scan(struct wpa_supplicant *wpa_s)
1148 if (!wpa_s->sched_scanning)
1151 wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling sched scan");
1152 eloop_cancel_timeout(wpa_supplicant_sched_scan_timeout, wpa_s, NULL);
1153 wpa_supplicant_stop_sched_scan(wpa_s);
1158 * wpa_supplicant_notify_scanning - Indicate possible scan state change
1159 * @wpa_s: Pointer to wpa_supplicant data
1160 * @scanning: Whether scanning is currently in progress
1162 * This function is to generate scanning notifycations. It is called whenever
1163 * there may have been a change in scanning (scan started, completed, stopped).
1164 * wpas_notify_scanning() is called whenever the scanning state changed from the
1165 * previously notified state.
1167 void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s,
1170 if (wpa_s->scanning != scanning) {
1171 wpa_s->scanning = scanning;
1172 wpas_notify_scanning(wpa_s);
1177 static int wpa_scan_get_max_rate(const struct wpa_scan_res *res)
1183 ie = wpa_scan_get_ie(res, WLAN_EID_SUPP_RATES);
1184 for (i = 0; ie && i < ie[1]; i++) {
1185 if ((ie[i + 2] & 0x7f) > rate)
1186 rate = ie[i + 2] & 0x7f;
1189 ie = wpa_scan_get_ie(res, WLAN_EID_EXT_SUPP_RATES);
1190 for (i = 0; ie && i < ie[1]; i++) {
1191 if ((ie[i + 2] & 0x7f) > rate)
1192 rate = ie[i + 2] & 0x7f;
1200 * wpa_scan_get_ie - Fetch a specified information element from a scan result
1201 * @res: Scan result entry
1202 * @ie: Information element identitifier (WLAN_EID_*)
1203 * Returns: Pointer to the information element (id field) or %NULL if not found
1205 * This function returns the first matching information element in the scan
1208 const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
1210 const u8 *end, *pos;
1212 pos = (const u8 *) (res + 1);
1213 end = pos + res->ie_len;
1215 while (pos + 1 < end) {
1216 if (pos + 2 + pos[1] > end)
1228 * wpa_scan_get_vendor_ie - Fetch vendor information element from a scan result
1229 * @res: Scan result entry
1230 * @vendor_type: Vendor type (four octets starting the IE payload)
1231 * Returns: Pointer to the information element (id field) or %NULL if not found
1233 * This function returns the first matching information element in the scan
1236 const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
1239 const u8 *end, *pos;
1241 pos = (const u8 *) (res + 1);
1242 end = pos + res->ie_len;
1244 while (pos + 1 < end) {
1245 if (pos + 2 + pos[1] > end)
1247 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1248 vendor_type == WPA_GET_BE32(&pos[2]))
1258 * wpa_scan_get_vendor_ie_multi - Fetch vendor IE data from a scan result
1259 * @res: Scan result entry
1260 * @vendor_type: Vendor type (four octets starting the IE payload)
1261 * Returns: Pointer to the information element payload or %NULL if not found
1263 * This function returns concatenated payload of possibly fragmented vendor
1264 * specific information elements in the scan result. The caller is responsible
1265 * for freeing the returned buffer.
1267 struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
1271 const u8 *end, *pos;
1273 buf = wpabuf_alloc(res->ie_len);
1277 pos = (const u8 *) (res + 1);
1278 end = pos + res->ie_len;
1280 while (pos + 1 < end) {
1281 if (pos + 2 + pos[1] > end)
1283 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1284 vendor_type == WPA_GET_BE32(&pos[2]))
1285 wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
1289 if (wpabuf_len(buf) == 0) {
1299 * Channels with a great SNR can operate at full rate. What is a great SNR?
1300 * This doc https://supportforums.cisco.com/docs/DOC-12954 says, "the general
1301 * rule of thumb is that any SNR above 20 is good." This one
1302 * http://www.cisco.com/en/US/tech/tk722/tk809/technologies_q_and_a_item09186a00805e9a96.shtml#qa23
1303 * recommends 25 as a minimum SNR for 54 Mbps data rate. 30 is chosen here as a
1304 * conservative value.
1306 #define GREAT_SNR 30
1308 /* Compare function for sorting scan results. Return >0 if @b is considered
1310 static int wpa_scan_result_compar(const void *a, const void *b)
1312 #define IS_5GHZ(n) (n > 4000)
1313 #define MIN(a,b) a < b ? a : b
1314 struct wpa_scan_res **_wa = (void *) a;
1315 struct wpa_scan_res **_wb = (void *) b;
1316 struct wpa_scan_res *wa = *_wa;
1317 struct wpa_scan_res *wb = *_wb;
1318 int wpa_a, wpa_b, maxrate_a, maxrate_b;
1321 /* WPA/WPA2 support preferred */
1322 wpa_a = wpa_scan_get_vendor_ie(wa, WPA_IE_VENDOR_TYPE) != NULL ||
1323 wpa_scan_get_ie(wa, WLAN_EID_RSN) != NULL;
1324 wpa_b = wpa_scan_get_vendor_ie(wb, WPA_IE_VENDOR_TYPE) != NULL ||
1325 wpa_scan_get_ie(wb, WLAN_EID_RSN) != NULL;
1327 if (wpa_b && !wpa_a)
1329 if (!wpa_b && wpa_a)
1332 /* privacy support preferred */
1333 if ((wa->caps & IEEE80211_CAP_PRIVACY) == 0 &&
1334 (wb->caps & IEEE80211_CAP_PRIVACY))
1336 if ((wa->caps & IEEE80211_CAP_PRIVACY) &&
1337 (wb->caps & IEEE80211_CAP_PRIVACY) == 0)
1340 if ((wa->flags & wb->flags & WPA_SCAN_LEVEL_DBM) &&
1341 !((wa->flags | wb->flags) & WPA_SCAN_NOISE_INVALID)) {
1342 snr_a = MIN(wa->level - wa->noise, GREAT_SNR);
1343 snr_b = MIN(wb->level - wb->noise, GREAT_SNR);
1345 /* Not suitable information to calculate SNR, so use level */
1350 /* best/max rate preferred if SNR close enough */
1351 if ((snr_a && snr_b && abs(snr_b - snr_a) < 5) ||
1352 (wa->qual && wb->qual && abs(wb->qual - wa->qual) < 10)) {
1353 maxrate_a = wpa_scan_get_max_rate(wa);
1354 maxrate_b = wpa_scan_get_max_rate(wb);
1355 if (maxrate_a != maxrate_b)
1356 return maxrate_b - maxrate_a;
1357 if (IS_5GHZ(wa->freq) ^ IS_5GHZ(wb->freq))
1358 return IS_5GHZ(wa->freq) ? -1 : 1;
1361 /* use freq for channel preference */
1363 /* all things being equal, use SNR; if SNRs are
1364 * identical, use quality values since some drivers may only report
1365 * that value and leave the signal level zero */
1367 return wb->qual - wa->qual;
1368 return snr_b - snr_a;
1375 /* Compare function for sorting scan results when searching a WPS AP for
1376 * provisioning. Return >0 if @b is considered better. */
1377 static int wpa_scan_result_wps_compar(const void *a, const void *b)
1379 struct wpa_scan_res **_wa = (void *) a;
1380 struct wpa_scan_res **_wb = (void *) b;
1381 struct wpa_scan_res *wa = *_wa;
1382 struct wpa_scan_res *wb = *_wb;
1383 int uses_wps_a, uses_wps_b;
1384 struct wpabuf *wps_a, *wps_b;
1387 /* Optimization - check WPS IE existence before allocated memory and
1388 * doing full reassembly. */
1389 uses_wps_a = wpa_scan_get_vendor_ie(wa, WPS_IE_VENDOR_TYPE) != NULL;
1390 uses_wps_b = wpa_scan_get_vendor_ie(wb, WPS_IE_VENDOR_TYPE) != NULL;
1391 if (uses_wps_a && !uses_wps_b)
1393 if (!uses_wps_a && uses_wps_b)
1396 if (uses_wps_a && uses_wps_b) {
1397 wps_a = wpa_scan_get_vendor_ie_multi(wa, WPS_IE_VENDOR_TYPE);
1398 wps_b = wpa_scan_get_vendor_ie_multi(wb, WPS_IE_VENDOR_TYPE);
1399 res = wps_ap_priority_compar(wps_a, wps_b);
1407 * Do not use current AP security policy as a sorting criteria during
1408 * WPS provisioning step since the AP may get reconfigured at the
1409 * completion of provisioning.
1412 /* all things being equal, use signal level; if signal levels are
1413 * identical, use quality values since some drivers may only report
1414 * that value and leave the signal level zero */
1415 if (wb->level == wa->level)
1416 return wb->qual - wa->qual;
1417 return wb->level - wa->level;
1419 #endif /* CONFIG_WPS */
1422 static void dump_scan_res(struct wpa_scan_results *scan_res)
1424 #ifndef CONFIG_NO_STDOUT_DEBUG
1427 if (scan_res->res == NULL || scan_res->num == 0)
1430 wpa_printf(MSG_EXCESSIVE, "Sorted scan results");
1432 for (i = 0; i < scan_res->num; i++) {
1433 struct wpa_scan_res *r = scan_res->res[i];
1435 if ((r->flags & (WPA_SCAN_LEVEL_DBM | WPA_SCAN_NOISE_INVALID))
1436 == WPA_SCAN_LEVEL_DBM) {
1437 int snr = r->level - r->noise;
1438 wpa_printf(MSG_EXCESSIVE, MACSTR " freq=%d qual=%d "
1439 "noise=%d level=%d snr=%d%s flags=0x%x",
1440 MAC2STR(r->bssid), r->freq, r->qual,
1441 r->noise, r->level, snr,
1442 snr >= GREAT_SNR ? "*" : "", r->flags);
1444 wpa_printf(MSG_EXCESSIVE, MACSTR " freq=%d qual=%d "
1445 "noise=%d level=%d flags=0x%x",
1446 MAC2STR(r->bssid), r->freq, r->qual,
1447 r->noise, r->level, r->flags);
1449 pos = (u8 *) (r + 1);
1451 wpa_hexdump(MSG_EXCESSIVE, "IEs", pos, r->ie_len);
1453 if (r->beacon_ie_len)
1454 wpa_hexdump(MSG_EXCESSIVE, "Beacon IEs",
1455 pos, r->beacon_ie_len);
1457 #endif /* CONFIG_NO_STDOUT_DEBUG */
1462 * wpa_supplicant_filter_bssid_match - Is the specified BSSID allowed
1463 * @wpa_s: Pointer to wpa_supplicant data
1464 * @bssid: BSSID to check
1465 * Returns: 0 if the BSSID is filtered or 1 if not
1467 * This function is used to filter out specific BSSIDs from scan reslts mainly
1468 * for testing purposes (SET bssid_filter ctrl_iface command).
1470 int wpa_supplicant_filter_bssid_match(struct wpa_supplicant *wpa_s,
1475 if (wpa_s->bssid_filter == NULL)
1478 for (i = 0; i < wpa_s->bssid_filter_count; i++) {
1479 if (os_memcmp(wpa_s->bssid_filter + i * ETH_ALEN, bssid,
1488 static void filter_scan_res(struct wpa_supplicant *wpa_s,
1489 struct wpa_scan_results *res)
1493 if (wpa_s->bssid_filter == NULL)
1496 for (i = 0, j = 0; i < res->num; i++) {
1497 if (wpa_supplicant_filter_bssid_match(wpa_s,
1498 res->res[i]->bssid)) {
1499 res->res[j++] = res->res[i];
1501 os_free(res->res[i]);
1506 if (res->num != j) {
1507 wpa_printf(MSG_DEBUG, "Filtered out %d scan results",
1508 (int) (res->num - j));
1515 * wpa_supplicant_get_scan_results - Get scan results
1516 * @wpa_s: Pointer to wpa_supplicant data
1517 * @info: Information about what was scanned or %NULL if not available
1518 * @new_scan: Whether a new scan was performed
1519 * Returns: Scan results, %NULL on failure
1521 * This function request the current scan results from the driver and updates
1522 * the local BSS list wpa_s->bss. The caller is responsible for freeing the
1523 * results with wpa_scan_results_free().
1525 struct wpa_scan_results *
1526 wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s,
1527 struct scan_info *info, int new_scan)
1529 struct wpa_scan_results *scan_res;
1531 int (*compar)(const void *, const void *) = wpa_scan_result_compar;
1533 scan_res = wpa_drv_get_scan_results2(wpa_s);
1534 if (scan_res == NULL) {
1535 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results");
1538 filter_scan_res(wpa_s, scan_res);
1541 if (wpas_wps_in_progress(wpa_s)) {
1542 wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Order scan results with WPS "
1543 "provisioning rules");
1544 compar = wpa_scan_result_wps_compar;
1546 #endif /* CONFIG_WPS */
1548 qsort(scan_res->res, scan_res->num, sizeof(struct wpa_scan_res *),
1550 dump_scan_res(scan_res);
1552 wpa_bss_update_start(wpa_s);
1553 for (i = 0; i < scan_res->num; i++)
1554 wpa_bss_update_scan_res(wpa_s, scan_res->res[i]);
1555 wpa_bss_update_end(wpa_s, info, new_scan);
1562 * wpa_supplicant_update_scan_results - Update scan results from the driver
1563 * @wpa_s: Pointer to wpa_supplicant data
1564 * Returns: 0 on success, -1 on failure
1566 * This function updates the BSS table within wpa_supplicant based on the
1567 * currently available scan results from the driver without requesting a new
1568 * scan. This is used in cases where the driver indicates an association
1569 * (including roaming within ESS) and wpa_supplicant does not yet have the
1570 * needed information to complete the connection (e.g., to perform validation
1571 * steps in 4-way handshake).
1573 int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s)
1575 struct wpa_scan_results *scan_res;
1576 scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0);
1577 if (scan_res == NULL)
1579 wpa_scan_results_free(scan_res);