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"
14 #include "common/wpa_ctrl.h"
16 #include "wpa_supplicant_i.h"
18 #include "wps_supplicant.h"
19 #include "p2p_supplicant.h"
21 #include "hs20_supplicant.h"
27 static void wpa_supplicant_gen_assoc_event(struct wpa_supplicant
*wpa_s
)
29 struct wpa_ssid
*ssid
;
30 union wpa_event_data data
;
32 ssid
= wpa_supplicant_get_ssid(wpa_s
);
36 if (wpa_s
->current_ssid
== NULL
) {
37 wpa_s
->current_ssid
= ssid
;
38 if (wpa_s
->current_ssid
!= NULL
)
39 wpas_notify_network_changed(wpa_s
);
41 wpa_supplicant_initiate_eapol(wpa_s
);
42 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated with a configured "
43 "network - generating associated event");
44 os_memset(&data
, 0, sizeof(data
));
45 wpa_supplicant_event(wpa_s
, EVENT_ASSOC
, &data
);
50 static int wpas_wps_in_use(struct wpa_supplicant
*wpa_s
,
51 enum wps_request_type
*req_type
)
53 struct wpa_ssid
*ssid
;
56 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
57 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
))
61 *req_type
= wpas_wps_get_req_type(ssid
);
62 if (!ssid
->eap
.phase1
)
65 if (os_strstr(ssid
->eap
.phase1
, "pbc=1"))
70 if (!wpa_s
->global
->p2p_disabled
&& wpa_s
->global
->p2p
&&
71 !wpa_s
->conf
->p2p_disabled
) {
72 wpa_s
->wps
->dev
.p2p
= 1;
75 *req_type
= WPS_REQ_ENROLLEE_INFO
;
78 #endif /* CONFIG_P2P */
82 #endif /* CONFIG_WPS */
86 * wpa_supplicant_enabled_networks - Check whether there are enabled networks
87 * @wpa_s: Pointer to wpa_supplicant data
88 * Returns: 0 if no networks are enabled, >0 if networks are enabled
90 * This function is used to figure out whether any networks (or Interworking
91 * with enabled credentials and auto_interworking) are present in the current
94 int wpa_supplicant_enabled_networks(struct wpa_supplicant
*wpa_s
)
96 struct wpa_ssid
*ssid
= wpa_s
->conf
->ssid
;
97 int count
= 0, disabled
= 0;
99 if (!wpas_network_disabled(wpa_s
, ssid
))
105 if (wpa_s
->conf
->cred
&& wpa_s
->conf
->interworking
&&
106 wpa_s
->conf
->auto_interworking
)
108 if (count
== 0 && disabled
> 0) {
109 wpa_dbg(wpa_s
, MSG_DEBUG
, "No enabled networks (%d disabled "
110 "networks)", disabled
);
116 static void wpa_supplicant_assoc_try(struct wpa_supplicant
*wpa_s
,
117 struct wpa_ssid
*ssid
)
120 if (!wpas_network_disabled(wpa_s
, ssid
))
125 /* ap_scan=2 mode - try to associate with each SSID. */
127 wpa_dbg(wpa_s
, MSG_DEBUG
, "wpa_supplicant_assoc_try: Reached "
128 "end of scan list - go back to beginning");
129 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
130 wpa_supplicant_req_scan(wpa_s
, 0, 0);
134 /* Continue from the next SSID on the next attempt. */
135 wpa_s
->prev_scan_ssid
= ssid
;
137 /* Start from the beginning of the SSID list. */
138 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
140 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
144 static int int_array_len(const int *a
)
147 for (i
= 0; a
&& a
[i
]; i
++)
153 static void int_array_concat(int **res
, const int *a
)
158 reslen
= int_array_len(*res
);
159 alen
= int_array_len(a
);
161 n
= os_realloc_array(*res
, reslen
+ alen
+ 1, sizeof(int));
167 for (i
= 0; i
<= alen
; i
++)
168 n
[reslen
+ i
] = a
[i
];
173 static int freq_cmp(const void *a
, const void *b
)
186 static void int_array_sort_unique(int *a
)
194 alen
= int_array_len(a
);
195 qsort(a
, alen
, sizeof(int), freq_cmp
);
199 while (a
[i
] && a
[j
]) {
213 * wpa_supplicant_trigger_scan - Request driver to start a scan
214 * @wpa_s: Pointer to wpa_supplicant data
215 * @params: Scan parameters
216 * Returns: 0 on success, -1 on failure
218 int wpa_supplicant_trigger_scan(struct wpa_supplicant
*wpa_s
,
219 struct wpa_driver_scan_params
*params
)
223 wpa_supplicant_notify_scanning(wpa_s
, 1);
225 ret
= wpa_drv_scan(wpa_s
, params
);
227 wpa_supplicant_notify_scanning(wpa_s
, 0);
228 wpas_notify_scan_done(wpa_s
, 0);
231 wpa_s
->normal_scans
++;
239 wpa_supplicant_delayed_sched_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
241 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
243 wpa_dbg(wpa_s
, MSG_DEBUG
, "Starting delayed sched scan");
245 if (wpa_supplicant_req_sched_scan(wpa_s
))
246 wpa_supplicant_req_scan(wpa_s
, 0, 0);
251 wpa_supplicant_sched_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
253 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
255 wpa_dbg(wpa_s
, MSG_DEBUG
, "Sched scan timeout - stopping it");
257 wpa_s
->sched_scan_timed_out
= 1;
258 wpa_supplicant_cancel_sched_scan(wpa_s
);
263 wpa_supplicant_start_sched_scan(struct wpa_supplicant
*wpa_s
,
264 struct wpa_driver_scan_params
*params
,
269 wpa_supplicant_notify_scanning(wpa_s
, 1);
270 ret
= wpa_drv_sched_scan(wpa_s
, params
, interval
* 1000);
272 wpa_supplicant_notify_scanning(wpa_s
, 0);
274 wpa_s
->sched_scanning
= 1;
280 static int wpa_supplicant_stop_sched_scan(struct wpa_supplicant
*wpa_s
)
284 ret
= wpa_drv_stop_sched_scan(wpa_s
);
286 wpa_dbg(wpa_s
, MSG_DEBUG
, "stopping sched_scan failed!");
287 /* TODO: what to do if stopping fails? */
295 static struct wpa_driver_scan_filter
*
296 wpa_supplicant_build_filter_ssids(struct wpa_config
*conf
, size_t *num_ssids
)
298 struct wpa_driver_scan_filter
*ssids
;
299 struct wpa_ssid
*ssid
;
303 if (!conf
->filter_ssids
)
306 for (count
= 0, ssid
= conf
->ssid
; ssid
; ssid
= ssid
->next
) {
307 if (ssid
->ssid
&& ssid
->ssid_len
)
312 ssids
= os_zalloc(count
* sizeof(struct wpa_driver_scan_filter
));
316 for (ssid
= conf
->ssid
; ssid
; ssid
= ssid
->next
) {
317 if (!ssid
->ssid
|| !ssid
->ssid_len
)
319 os_memcpy(ssids
[*num_ssids
].ssid
, ssid
->ssid
, ssid
->ssid_len
);
320 ssids
[*num_ssids
].ssid_len
= ssid
->ssid_len
;
328 static void wpa_supplicant_optimize_freqs(
329 struct wpa_supplicant
*wpa_s
, struct wpa_driver_scan_params
*params
)
332 if (params
->freqs
== NULL
&& wpa_s
->p2p_in_provisioning
&&
334 /* Optimize provisioning state scan based on GO information */
335 if (wpa_s
->p2p_in_provisioning
< 5 &&
336 wpa_s
->go_params
->freq
> 0) {
337 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Scan only GO "
338 "preferred frequency %d MHz",
339 wpa_s
->go_params
->freq
);
340 params
->freqs
= os_zalloc(2 * sizeof(int));
342 params
->freqs
[0] = wpa_s
->go_params
->freq
;
343 } else if (wpa_s
->p2p_in_provisioning
< 8 &&
344 wpa_s
->go_params
->freq_list
[0]) {
345 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Scan only common "
347 int_array_concat(¶ms
->freqs
,
348 wpa_s
->go_params
->freq_list
);
350 int_array_sort_unique(params
->freqs
);
352 wpa_s
->p2p_in_provisioning
++;
354 #endif /* CONFIG_P2P */
357 if (params
->freqs
== NULL
&& wpa_s
->after_wps
&& wpa_s
->wps_freq
) {
359 * Optimize post-provisioning scan based on channel used
360 * during provisioning.
362 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPS: Scan only frequency %u MHz "
363 "that was used during provisioning", wpa_s
->wps_freq
);
364 params
->freqs
= os_zalloc(2 * sizeof(int));
366 params
->freqs
[0] = wpa_s
->wps_freq
;
370 if (params
->freqs
== NULL
&& wpa_s
->known_wps_freq
&& wpa_s
->wps_freq
)
372 /* Optimize provisioning scan based on already known channel */
373 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPS: Scan only frequency %u MHz",
375 params
->freqs
= os_zalloc(2 * sizeof(int));
377 params
->freqs
[0] = wpa_s
->wps_freq
;
378 wpa_s
->known_wps_freq
= 0; /* only do this once */
380 #endif /* CONFIG_WPS */
384 #ifdef CONFIG_INTERWORKING
385 static void wpas_add_interworking_elements(struct wpa_supplicant
*wpa_s
,
388 if (wpa_s
->conf
->interworking
== 0)
391 wpabuf_put_u8(buf
, WLAN_EID_EXT_CAPAB
);
392 wpabuf_put_u8(buf
, 4);
393 wpabuf_put_u8(buf
, 0x00);
394 wpabuf_put_u8(buf
, 0x00);
395 wpabuf_put_u8(buf
, 0x00);
396 wpabuf_put_u8(buf
, 0x80); /* Bit 31 - Interworking */
398 wpabuf_put_u8(buf
, WLAN_EID_INTERWORKING
);
399 wpabuf_put_u8(buf
, is_zero_ether_addr(wpa_s
->conf
->hessid
) ? 1 :
401 wpabuf_put_u8(buf
, wpa_s
->conf
->access_network_type
);
403 if (!is_zero_ether_addr(wpa_s
->conf
->hessid
))
404 wpabuf_put_data(buf
, wpa_s
->conf
->hessid
, ETH_ALEN
);
406 #endif /* CONFIG_INTERWORKING */
409 static struct wpabuf
* wpa_supplicant_extra_ies(struct wpa_supplicant
*wpa_s
)
411 struct wpabuf
*extra_ie
= NULL
;
414 enum wps_request_type req_type
= WPS_REQ_ENROLLEE_INFO
;
415 #endif /* CONFIG_WPS */
417 #ifdef CONFIG_INTERWORKING
418 if (wpa_s
->conf
->interworking
&&
419 wpabuf_resize(&extra_ie
, 100) == 0)
420 wpas_add_interworking_elements(wpa_s
, extra_ie
);
421 #endif /* CONFIG_INTERWORKING */
424 wps
= wpas_wps_in_use(wpa_s
, &req_type
);
427 struct wpabuf
*wps_ie
;
428 wps_ie
= wps_build_probe_req_ie(wps
== 2 ? DEV_PW_PUSHBUTTON
:
431 wpa_s
->wps
->uuid
, req_type
,
434 if (wpabuf_resize(&extra_ie
, wpabuf_len(wps_ie
)) == 0)
435 wpabuf_put_buf(extra_ie
, wps_ie
);
442 size_t ielen
= p2p_scan_ie_buf_len(wpa_s
->global
->p2p
);
443 if (wpabuf_resize(&extra_ie
, ielen
) == 0)
444 wpas_p2p_scan_ie(wpa_s
, extra_ie
);
446 #endif /* CONFIG_P2P */
448 #endif /* CONFIG_WPS */
457 * Check whether there are any enabled networks or credentials that could be
458 * used for a non-P2P connection.
460 static int non_p2p_network_enabled(struct wpa_supplicant
*wpa_s
)
462 struct wpa_ssid
*ssid
;
464 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
465 if (wpas_network_disabled(wpa_s
, ssid
))
467 if (!ssid
->p2p_group
)
471 if (wpa_s
->conf
->cred
&& wpa_s
->conf
->interworking
&&
472 wpa_s
->conf
->auto_interworking
)
480 * Find the operating frequency of any other virtual interface that is using
481 * the same radio concurrently.
483 static int shared_vif_oper_freq(struct wpa_supplicant
*wpa_s
)
485 const char *rn
, *rn2
;
486 struct wpa_supplicant
*ifs
;
489 if (!wpa_s
->driver
->get_radio_name
)
492 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
493 if (rn
== NULL
|| rn
[0] == '\0')
496 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
497 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
500 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
501 if (!rn2
|| os_strcmp(rn
, rn2
) != 0)
504 if (ifs
->current_ssid
== NULL
|| ifs
->assoc_freq
== 0)
507 if (ifs
->current_ssid
->mode
== WPAS_MODE_AP
||
508 ifs
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)
509 return ifs
->current_ssid
->frequency
;
510 if (wpa_drv_get_bssid(ifs
, bssid
) == 0)
511 return ifs
->assoc_freq
;
517 #endif /* CONFIG_P2P */
520 static void wpa_supplicant_scan(void *eloop_ctx
, void *timeout_ctx
)
522 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
523 struct wpa_ssid
*ssid
;
524 enum scan_req_type scan_req
= NORMAL_SCAN_REQ
;
526 struct wpabuf
*extra_ie
= NULL
;
527 struct wpa_driver_scan_params params
;
528 struct wpa_driver_scan_params
*scan_params
;
530 enum wpa_states prev_state
;
532 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
533 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip scan - interface disabled");
537 if (wpa_s
->disconnected
&& wpa_s
->scan_req
== NORMAL_SCAN_REQ
) {
538 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnected - do not scan");
539 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
543 if (!wpa_supplicant_enabled_networks(wpa_s
) &&
544 wpa_s
->scan_req
== NORMAL_SCAN_REQ
) {
545 wpa_dbg(wpa_s
, MSG_DEBUG
, "No enabled networks - do not scan");
546 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
548 wpa_s
->sta_scan_pending
= 0;
549 #endif /* CONFIG_P2P */
553 if (wpa_s
->conf
->ap_scan
!= 0 &&
554 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
)) {
555 wpa_dbg(wpa_s
, MSG_DEBUG
, "Using wired authentication - "
556 "overriding ap_scan configuration");
557 wpa_s
->conf
->ap_scan
= 0;
558 wpas_notify_ap_scan_changed(wpa_s
);
561 if (wpa_s
->conf
->ap_scan
== 0) {
562 wpa_supplicant_gen_assoc_event(wpa_s
);
567 if (wpas_p2p_in_progress(wpa_s
)) {
568 if (wpa_s
->sta_scan_pending
&&
569 wpas_p2p_in_progress(wpa_s
) == 2 &&
570 wpa_s
->global
->p2p_cb_on_scan_complete
) {
571 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending station "
572 "mode scan during P2P search");
574 wpa_dbg(wpa_s
, MSG_DEBUG
, "Delay station mode scan "
575 "while P2P operation is in progress");
576 wpa_s
->sta_scan_pending
= 1;
577 wpa_supplicant_req_scan(wpa_s
, 5, 0);
581 #endif /* CONFIG_P2P */
583 if (wpa_s
->conf
->ap_scan
== 2)
586 max_ssids
= wpa_s
->max_scan_ssids
;
587 if (max_ssids
> WPAS_MAX_SCAN_SSIDS
)
588 max_ssids
= WPAS_MAX_SCAN_SSIDS
;
591 scan_req
= wpa_s
->scan_req
;
592 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
594 os_memset(¶ms
, 0, sizeof(params
));
596 prev_state
= wpa_s
->wpa_state
;
597 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
||
598 wpa_s
->wpa_state
== WPA_INACTIVE
)
599 wpa_supplicant_set_state(wpa_s
, WPA_SCANNING
);
602 * If autoscan has set its own scanning parameters
604 if (wpa_s
->autoscan_params
!= NULL
) {
605 scan_params
= wpa_s
->autoscan_params
;
609 if (scan_req
!= MANUAL_SCAN_REQ
&& wpa_s
->connect_without_scan
) {
610 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
611 if (ssid
== wpa_s
->connect_without_scan
)
614 wpa_s
->connect_without_scan
= NULL
;
616 wpa_printf(MSG_DEBUG
, "Start a pre-selected network "
617 "without scan step");
618 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
624 if ((wpa_s
->p2p_in_provisioning
|| wpa_s
->show_group_started
) &&
626 wpa_printf(MSG_DEBUG
, "P2P: Use specific SSID for scan during "
627 "P2P group formation");
628 params
.ssids
[0].ssid
= wpa_s
->go_params
->ssid
;
629 params
.ssids
[0].ssid_len
= wpa_s
->go_params
->ssid_len
;
630 params
.num_ssids
= 1;
633 #endif /* CONFIG_P2P */
635 /* Find the starting point from which to continue scanning */
636 ssid
= wpa_s
->conf
->ssid
;
637 if (wpa_s
->prev_scan_ssid
!= WILDCARD_SSID_SCAN
) {
639 if (ssid
== wpa_s
->prev_scan_ssid
) {
647 if (scan_req
!= MANUAL_SCAN_REQ
&& wpa_s
->conf
->ap_scan
== 2) {
648 wpa_s
->connect_without_scan
= NULL
;
649 wpa_s
->prev_scan_wildcard
= 0;
650 wpa_supplicant_assoc_try(wpa_s
, ssid
);
652 } else if (wpa_s
->conf
->ap_scan
== 2) {
654 * User-initiated scan request in ap_scan == 2; scan with
659 struct wpa_ssid
*start
= ssid
, *tssid
;
661 if (ssid
== NULL
&& max_ssids
> 1)
662 ssid
= wpa_s
->conf
->ssid
;
664 if (!wpas_network_disabled(wpa_s
, ssid
) &&
666 wpa_hexdump_ascii(MSG_DEBUG
, "Scan SSID",
667 ssid
->ssid
, ssid
->ssid_len
);
668 params
.ssids
[params
.num_ssids
].ssid
=
670 params
.ssids
[params
.num_ssids
].ssid_len
=
673 if (params
.num_ssids
+ 1 >= max_ssids
)
679 if (ssid
== NULL
&& max_ssids
> 1 &&
680 start
!= wpa_s
->conf
->ssid
)
681 ssid
= wpa_s
->conf
->ssid
;
684 for (tssid
= wpa_s
->conf
->ssid
; tssid
; tssid
= tssid
->next
) {
685 if (wpas_network_disabled(wpa_s
, tssid
))
687 if ((params
.freqs
|| !freqs_set
) && tssid
->scan_freq
) {
688 int_array_concat(¶ms
.freqs
,
691 os_free(params
.freqs
);
696 int_array_sort_unique(params
.freqs
);
699 if (ssid
&& max_ssids
== 1) {
701 * If the driver is limited to 1 SSID at a time interleave
702 * wildcard SSID scans with specific SSID scans to avoid
703 * waiting a long time for a wildcard scan.
705 if (!wpa_s
->prev_scan_wildcard
) {
706 params
.ssids
[0].ssid
= NULL
;
707 params
.ssids
[0].ssid_len
= 0;
708 wpa_s
->prev_scan_wildcard
= 1;
709 wpa_dbg(wpa_s
, MSG_DEBUG
, "Starting AP scan for "
710 "wildcard SSID (Interleave with specific)");
712 wpa_s
->prev_scan_ssid
= ssid
;
713 wpa_s
->prev_scan_wildcard
= 0;
714 wpa_dbg(wpa_s
, MSG_DEBUG
,
715 "Starting AP scan for specific SSID: %s",
716 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
721 wpa_s
->prev_scan_ssid
= ssid
;
722 wpa_dbg(wpa_s
, MSG_DEBUG
, "Include wildcard SSID in "
726 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
728 wpa_dbg(wpa_s
, MSG_DEBUG
, "Starting AP scan for wildcard "
733 #endif /* CONFIG_P2P */
735 wpa_supplicant_optimize_freqs(wpa_s
, ¶ms
);
736 extra_ie
= wpa_supplicant_extra_ies(wpa_s
);
739 if (wpa_s
->conf
->hs20
&& wpabuf_resize(&extra_ie
, 7) == 0)
740 wpas_hs20_add_indication(extra_ie
);
741 #endif /* CONFIG_HS20 */
743 if (params
.freqs
== NULL
&& wpa_s
->next_scan_freqs
) {
744 wpa_dbg(wpa_s
, MSG_DEBUG
, "Optimize scan based on previously "
745 "generated frequency list");
746 params
.freqs
= wpa_s
->next_scan_freqs
;
748 os_free(wpa_s
->next_scan_freqs
);
749 wpa_s
->next_scan_freqs
= NULL
;
751 params
.filter_ssids
= wpa_supplicant_build_filter_ssids(
752 wpa_s
->conf
, ¶ms
.num_filter_ssids
);
754 params
.extra_ies
= wpabuf_head(extra_ie
);
755 params
.extra_ies_len
= wpabuf_len(extra_ie
);
759 if (wpa_s
->p2p_in_provisioning
||
760 (wpa_s
->show_group_started
&& wpa_s
->go_params
)) {
762 * The interface may not yet be in P2P mode, so we have to
763 * explicitly request P2P probe to disable CCK rates.
765 params
.p2p_probe
= 1;
767 #endif /* CONFIG_P2P */
769 scan_params
= ¶ms
;
774 * If the driver does not support multi-channel concurrency and a
775 * virtual interface that shares the same radio with the wpa_s interface
776 * is operating there may not be need to scan other channels apart from
777 * the current operating channel on the other virtual interface. Filter
778 * out other channels in case we are trying to find a connection for a
779 * station interface when we are not configured to prefer station
780 * connection and a concurrent operation is already in process.
782 if (wpa_s
->scan_for_connection
&& scan_req
== NORMAL_SCAN_REQ
&&
783 !scan_params
->freqs
&& !params
.freqs
&&
784 wpas_is_p2p_prioritized(wpa_s
) &&
785 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
) &&
786 wpa_s
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
&&
787 non_p2p_network_enabled(wpa_s
)) {
788 int freq
= shared_vif_oper_freq(wpa_s
);
790 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Scan only the current "
791 "operating channel (%d MHz) since driver does "
792 "not support multi-channel concurrency", freq
);
793 params
.freqs
= os_zalloc(sizeof(int) * 2);
795 params
.freqs
[0] = freq
;
796 scan_params
->freqs
= params
.freqs
;
799 #endif /* CONFIG_P2P */
801 ret
= wpa_supplicant_trigger_scan(wpa_s
, scan_params
);
803 wpabuf_free(extra_ie
);
804 os_free(params
.freqs
);
805 os_free(params
.filter_ssids
);
808 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initiate AP scan");
809 if (prev_state
!= wpa_s
->wpa_state
)
810 wpa_supplicant_set_state(wpa_s
, prev_state
);
811 /* Restore scan_req since we will try to scan again */
812 wpa_s
->scan_req
= scan_req
;
813 wpa_supplicant_req_scan(wpa_s
, 1, 0);
815 wpa_s
->scan_for_connection
= 0;
820 void wpa_supplicant_update_scan_int(struct wpa_supplicant
*wpa_s
, int sec
)
822 struct os_time remaining
, new_int
;
825 cancelled
= eloop_cancel_timeout_one(wpa_supplicant_scan
, wpa_s
, NULL
,
830 if (cancelled
&& os_time_before(&remaining
, &new_int
)) {
831 new_int
.sec
= remaining
.sec
;
832 new_int
.usec
= remaining
.usec
;
835 eloop_register_timeout(new_int
.sec
, new_int
.usec
, wpa_supplicant_scan
,
837 wpa_s
->scan_interval
= sec
;
842 * wpa_supplicant_req_scan - Schedule a scan for neighboring access points
843 * @wpa_s: Pointer to wpa_supplicant data
844 * @sec: Number of seconds after which to scan
845 * @usec: Number of microseconds after which to scan
847 * This function is used to schedule a scan for neighboring access points after
848 * the specified time.
850 void wpa_supplicant_req_scan(struct wpa_supplicant
*wpa_s
, int sec
, int usec
)
852 /* If there's at least one network that should be specifically scanned
853 * then don't cancel the scan and reschedule. Some drivers do
854 * background scanning which generates frequent scan results, and that
855 * causes the specific SSID scan to get continually pushed back and
856 * never happen, which causes hidden APs to never get probe-scanned.
858 if (eloop_is_timeout_registered(wpa_supplicant_scan
, wpa_s
, NULL
) &&
859 wpa_s
->conf
->ap_scan
== 1) {
860 struct wpa_ssid
*ssid
= wpa_s
->conf
->ssid
;
863 if (!wpas_network_disabled(wpa_s
, ssid
) &&
869 wpa_dbg(wpa_s
, MSG_DEBUG
, "Not rescheduling scan to "
870 "ensure that specific SSID scans occur");
875 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setting scan request: %d sec %d usec",
877 eloop_cancel_timeout(wpa_supplicant_scan
, wpa_s
, NULL
);
878 eloop_register_timeout(sec
, usec
, wpa_supplicant_scan
, wpa_s
, NULL
);
883 * wpa_supplicant_delayed_sched_scan - Request a delayed scheduled scan
884 * @wpa_s: Pointer to wpa_supplicant data
885 * @sec: Number of seconds after which to scan
886 * @usec: Number of microseconds after which to scan
887 * Returns: 0 on success or -1 otherwise
889 * This function is used to schedule periodic scans for neighboring
890 * access points after the specified time.
892 int wpa_supplicant_delayed_sched_scan(struct wpa_supplicant
*wpa_s
,
895 if (!wpa_s
->sched_scan_supported
)
898 eloop_register_timeout(sec
, usec
,
899 wpa_supplicant_delayed_sched_scan_timeout
,
907 * wpa_supplicant_req_sched_scan - Start a periodic scheduled scan
908 * @wpa_s: Pointer to wpa_supplicant data
909 * Returns: 0 is sched_scan was started or -1 otherwise
911 * This function is used to schedule periodic scans for neighboring
912 * access points repeating the scan continuously.
914 int wpa_supplicant_req_sched_scan(struct wpa_supplicant
*wpa_s
)
916 struct wpa_driver_scan_params params
;
917 struct wpa_driver_scan_params
*scan_params
;
918 enum wpa_states prev_state
;
919 struct wpa_ssid
*ssid
= NULL
;
920 struct wpabuf
*extra_ie
= NULL
;
922 unsigned int max_sched_scan_ssids
;
926 if (!wpa_s
->sched_scan_supported
)
929 if (wpa_s
->max_sched_scan_ssids
> WPAS_MAX_SCAN_SSIDS
)
930 max_sched_scan_ssids
= WPAS_MAX_SCAN_SSIDS
;
932 max_sched_scan_ssids
= wpa_s
->max_sched_scan_ssids
;
933 if (max_sched_scan_ssids
< 1 || wpa_s
->conf
->disable_scan_offload
)
936 if (wpa_s
->sched_scanning
) {
937 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already sched scanning");
942 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
943 if (!wpas_network_disabled(wpa_s
, ssid
) && !ssid
->scan_ssid
) {
944 /* Use wildcard SSID to find this network */
946 } else if (!wpas_network_disabled(wpa_s
, ssid
) &&
951 if (!wpas_network_disabled(wpa_s
, ssid
) &&
952 ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
954 * Normal scan is more reliable and faster for WPS
955 * operations and since these are for short periods of
956 * time, the benefit of trying to use sched_scan would
959 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use normal scan instead of "
960 "sched_scan for WPS");
963 #endif /* CONFIG_WPS */
968 if (wpa_s
->normal_scans
< 3 &&
969 (need_ssids
<= wpa_s
->max_scan_ssids
||
970 wpa_s
->max_scan_ssids
>= (int) max_sched_scan_ssids
)) {
972 * When normal scan can speed up operations, use that for the
973 * first operations before starting the sched_scan to allow
974 * user space sleep more. We do this only if the normal scan
975 * has functionality that is suitable for this or if the
976 * sched_scan does not have better support for multiple SSIDs.
978 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use normal scan instead of "
979 "sched_scan for initial scans (normal_scans=%d)",
980 wpa_s
->normal_scans
);
984 os_memset(¶ms
, 0, sizeof(params
));
986 /* If we can't allocate space for the filters, we just don't filter */
987 params
.filter_ssids
= os_zalloc(wpa_s
->max_match_sets
*
988 sizeof(struct wpa_driver_scan_filter
));
990 prev_state
= wpa_s
->wpa_state
;
991 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
||
992 wpa_s
->wpa_state
== WPA_INACTIVE
)
993 wpa_supplicant_set_state(wpa_s
, WPA_SCANNING
);
995 if (wpa_s
->autoscan_params
!= NULL
) {
996 scan_params
= wpa_s
->autoscan_params
;
1000 /* Find the starting point from which to continue scanning */
1001 ssid
= wpa_s
->conf
->ssid
;
1002 if (wpa_s
->prev_sched_ssid
) {
1004 if (ssid
== wpa_s
->prev_sched_ssid
) {
1012 if (!ssid
|| !wpa_s
->prev_sched_ssid
) {
1013 wpa_dbg(wpa_s
, MSG_DEBUG
, "Beginning of SSID list");
1015 if (wpa_s
->sched_scan_interval
== 0)
1016 wpa_s
->sched_scan_interval
= 10;
1017 wpa_s
->sched_scan_timeout
= max_sched_scan_ssids
* 2;
1018 wpa_s
->first_sched_scan
= 1;
1019 ssid
= wpa_s
->conf
->ssid
;
1020 wpa_s
->prev_sched_ssid
= ssid
;
1024 wpa_dbg(wpa_s
, MSG_DEBUG
, "Add wildcard SSID to sched_scan");
1029 if (wpas_network_disabled(wpa_s
, ssid
))
1032 if (params
.num_filter_ssids
< wpa_s
->max_match_sets
&&
1033 params
.filter_ssids
&& ssid
->ssid
&& ssid
->ssid_len
) {
1034 wpa_dbg(wpa_s
, MSG_DEBUG
, "add to filter ssid: %s",
1035 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1036 os_memcpy(params
.filter_ssids
[params
.num_filter_ssids
].ssid
,
1037 ssid
->ssid
, ssid
->ssid_len
);
1038 params
.filter_ssids
[params
.num_filter_ssids
].ssid_len
=
1040 params
.num_filter_ssids
++;
1041 } else if (params
.filter_ssids
&& ssid
->ssid
&& ssid
->ssid_len
)
1043 wpa_dbg(wpa_s
, MSG_DEBUG
, "Not enough room for SSID "
1044 "filter for sched_scan - drop filter");
1045 os_free(params
.filter_ssids
);
1046 params
.filter_ssids
= NULL
;
1047 params
.num_filter_ssids
= 0;
1050 if (ssid
->scan_ssid
&& ssid
->ssid
&& ssid
->ssid_len
) {
1051 if (params
.num_ssids
== max_sched_scan_ssids
)
1052 break; /* only room for broadcast SSID */
1053 wpa_dbg(wpa_s
, MSG_DEBUG
,
1054 "add to active scan ssid: %s",
1055 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1056 params
.ssids
[params
.num_ssids
].ssid
=
1058 params
.ssids
[params
.num_ssids
].ssid_len
=
1061 if (params
.num_ssids
>= max_sched_scan_ssids
) {
1062 wpa_s
->prev_sched_ssid
= ssid
;
1066 (wpas_network_disabled(wpa_s
, ssid
) ||
1073 wpa_s
->prev_sched_ssid
= ssid
;
1077 if (params
.num_filter_ssids
== 0) {
1078 os_free(params
.filter_ssids
);
1079 params
.filter_ssids
= NULL
;
1082 extra_ie
= wpa_supplicant_extra_ies(wpa_s
);
1084 params
.extra_ies
= wpabuf_head(extra_ie
);
1085 params
.extra_ies_len
= wpabuf_len(extra_ie
);
1088 scan_params
= ¶ms
;
1091 if (ssid
|| !wpa_s
->first_sched_scan
) {
1092 wpa_dbg(wpa_s
, MSG_DEBUG
,
1093 "Starting sched scan: interval %d timeout %d",
1094 wpa_s
->sched_scan_interval
, wpa_s
->sched_scan_timeout
);
1096 wpa_dbg(wpa_s
, MSG_DEBUG
,
1097 "Starting sched scan: interval %d (no timeout)",
1098 wpa_s
->sched_scan_interval
);
1101 ret
= wpa_supplicant_start_sched_scan(wpa_s
, scan_params
,
1102 wpa_s
->sched_scan_interval
);
1103 wpabuf_free(extra_ie
);
1104 os_free(params
.filter_ssids
);
1106 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initiate sched scan");
1107 if (prev_state
!= wpa_s
->wpa_state
)
1108 wpa_supplicant_set_state(wpa_s
, prev_state
);
1112 /* If we have more SSIDs to scan, add a timeout so we scan them too */
1113 if (ssid
|| !wpa_s
->first_sched_scan
) {
1114 wpa_s
->sched_scan_timed_out
= 0;
1115 eloop_register_timeout(wpa_s
->sched_scan_timeout
, 0,
1116 wpa_supplicant_sched_scan_timeout
,
1118 wpa_s
->first_sched_scan
= 0;
1119 wpa_s
->sched_scan_timeout
/= 2;
1120 wpa_s
->sched_scan_interval
*= 2;
1128 * wpa_supplicant_cancel_scan - Cancel a scheduled scan request
1129 * @wpa_s: Pointer to wpa_supplicant data
1131 * This function is used to cancel a scan request scheduled with
1132 * wpa_supplicant_req_scan().
1134 void wpa_supplicant_cancel_scan(struct wpa_supplicant
*wpa_s
)
1136 wpa_dbg(wpa_s
, MSG_DEBUG
, "Cancelling scan request");
1137 eloop_cancel_timeout(wpa_supplicant_scan
, wpa_s
, NULL
);
1142 * wpa_supplicant_cancel_sched_scan - Stop running scheduled scans
1143 * @wpa_s: Pointer to wpa_supplicant data
1145 * This function is used to stop a periodic scheduled scan.
1147 void wpa_supplicant_cancel_sched_scan(struct wpa_supplicant
*wpa_s
)
1149 if (!wpa_s
->sched_scanning
)
1152 wpa_dbg(wpa_s
, MSG_DEBUG
, "Cancelling sched scan");
1153 eloop_cancel_timeout(wpa_supplicant_sched_scan_timeout
, wpa_s
, NULL
);
1154 wpa_supplicant_stop_sched_scan(wpa_s
);
1159 * wpa_supplicant_notify_scanning - Indicate possible scan state change
1160 * @wpa_s: Pointer to wpa_supplicant data
1161 * @scanning: Whether scanning is currently in progress
1163 * This function is to generate scanning notifycations. It is called whenever
1164 * there may have been a change in scanning (scan started, completed, stopped).
1165 * wpas_notify_scanning() is called whenever the scanning state changed from the
1166 * previously notified state.
1168 void wpa_supplicant_notify_scanning(struct wpa_supplicant
*wpa_s
,
1171 if (wpa_s
->scanning
!= scanning
) {
1172 wpa_s
->scanning
= scanning
;
1173 wpas_notify_scanning(wpa_s
);
1178 static int wpa_scan_get_max_rate(const struct wpa_scan_res
*res
)
1184 ie
= wpa_scan_get_ie(res
, WLAN_EID_SUPP_RATES
);
1185 for (i
= 0; ie
&& i
< ie
[1]; i
++) {
1186 if ((ie
[i
+ 2] & 0x7f) > rate
)
1187 rate
= ie
[i
+ 2] & 0x7f;
1190 ie
= wpa_scan_get_ie(res
, WLAN_EID_EXT_SUPP_RATES
);
1191 for (i
= 0; ie
&& i
< ie
[1]; i
++) {
1192 if ((ie
[i
+ 2] & 0x7f) > rate
)
1193 rate
= ie
[i
+ 2] & 0x7f;
1201 * wpa_scan_get_ie - Fetch a specified information element from a scan result
1202 * @res: Scan result entry
1203 * @ie: Information element identitifier (WLAN_EID_*)
1204 * Returns: Pointer to the information element (id field) or %NULL if not found
1206 * This function returns the first matching information element in the scan
1209 const u8
* wpa_scan_get_ie(const struct wpa_scan_res
*res
, u8 ie
)
1211 const u8
*end
, *pos
;
1213 pos
= (const u8
*) (res
+ 1);
1214 end
= pos
+ res
->ie_len
;
1216 while (pos
+ 1 < end
) {
1217 if (pos
+ 2 + pos
[1] > end
)
1229 * wpa_scan_get_vendor_ie - Fetch vendor information element from a scan result
1230 * @res: Scan result entry
1231 * @vendor_type: Vendor type (four octets starting the IE payload)
1232 * Returns: Pointer to the information element (id field) or %NULL if not found
1234 * This function returns the first matching information element in the scan
1237 const u8
* wpa_scan_get_vendor_ie(const struct wpa_scan_res
*res
,
1240 const u8
*end
, *pos
;
1242 pos
= (const u8
*) (res
+ 1);
1243 end
= pos
+ res
->ie_len
;
1245 while (pos
+ 1 < end
) {
1246 if (pos
+ 2 + pos
[1] > end
)
1248 if (pos
[0] == WLAN_EID_VENDOR_SPECIFIC
&& pos
[1] >= 4 &&
1249 vendor_type
== WPA_GET_BE32(&pos
[2]))
1259 * wpa_scan_get_vendor_ie_multi - Fetch vendor IE data from a scan result
1260 * @res: Scan result entry
1261 * @vendor_type: Vendor type (four octets starting the IE payload)
1262 * Returns: Pointer to the information element payload or %NULL if not found
1264 * This function returns concatenated payload of possibly fragmented vendor
1265 * specific information elements in the scan result. The caller is responsible
1266 * for freeing the returned buffer.
1268 struct wpabuf
* wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res
*res
,
1272 const u8
*end
, *pos
;
1274 buf
= wpabuf_alloc(res
->ie_len
);
1278 pos
= (const u8
*) (res
+ 1);
1279 end
= pos
+ res
->ie_len
;
1281 while (pos
+ 1 < end
) {
1282 if (pos
+ 2 + pos
[1] > end
)
1284 if (pos
[0] == WLAN_EID_VENDOR_SPECIFIC
&& pos
[1] >= 4 &&
1285 vendor_type
== WPA_GET_BE32(&pos
[2]))
1286 wpabuf_put_data(buf
, pos
+ 2 + 4, pos
[1] - 4);
1290 if (wpabuf_len(buf
) == 0) {
1300 * Channels with a great SNR can operate at full rate. What is a great SNR?
1301 * This doc https://supportforums.cisco.com/docs/DOC-12954 says, "the general
1302 * rule of thumb is that any SNR above 20 is good." This one
1303 * http://www.cisco.com/en/US/tech/tk722/tk809/technologies_q_and_a_item09186a00805e9a96.shtml#qa23
1304 * recommends 25 as a minimum SNR for 54 Mbps data rate. 30 is chosen here as a
1305 * conservative value.
1307 #define GREAT_SNR 30
1309 /* Compare function for sorting scan results. Return >0 if @b is considered
1311 static int wpa_scan_result_compar(const void *a
, const void *b
)
1313 #define IS_5GHZ(n) (n > 4000)
1314 #define MIN(a,b) a < b ? a : b
1315 struct wpa_scan_res
**_wa
= (void *) a
;
1316 struct wpa_scan_res
**_wb
= (void *) b
;
1317 struct wpa_scan_res
*wa
= *_wa
;
1318 struct wpa_scan_res
*wb
= *_wb
;
1319 int wpa_a
, wpa_b
, maxrate_a
, maxrate_b
;
1322 /* WPA/WPA2 support preferred */
1323 wpa_a
= wpa_scan_get_vendor_ie(wa
, WPA_IE_VENDOR_TYPE
) != NULL
||
1324 wpa_scan_get_ie(wa
, WLAN_EID_RSN
) != NULL
;
1325 wpa_b
= wpa_scan_get_vendor_ie(wb
, WPA_IE_VENDOR_TYPE
) != NULL
||
1326 wpa_scan_get_ie(wb
, WLAN_EID_RSN
) != NULL
;
1328 if (wpa_b
&& !wpa_a
)
1330 if (!wpa_b
&& wpa_a
)
1333 /* privacy support preferred */
1334 if ((wa
->caps
& IEEE80211_CAP_PRIVACY
) == 0 &&
1335 (wb
->caps
& IEEE80211_CAP_PRIVACY
))
1337 if ((wa
->caps
& IEEE80211_CAP_PRIVACY
) &&
1338 (wb
->caps
& IEEE80211_CAP_PRIVACY
) == 0)
1341 if ((wa
->flags
& wb
->flags
& WPA_SCAN_LEVEL_DBM
) &&
1342 !((wa
->flags
| wb
->flags
) & WPA_SCAN_NOISE_INVALID
)) {
1343 snr_a
= MIN(wa
->level
- wa
->noise
, GREAT_SNR
);
1344 snr_b
= MIN(wb
->level
- wb
->noise
, GREAT_SNR
);
1346 /* Not suitable information to calculate SNR, so use level */
1351 /* best/max rate preferred if SNR close enough */
1352 if ((snr_a
&& snr_b
&& abs(snr_b
- snr_a
) < 5) ||
1353 (wa
->qual
&& wb
->qual
&& abs(wb
->qual
- wa
->qual
) < 10)) {
1354 maxrate_a
= wpa_scan_get_max_rate(wa
);
1355 maxrate_b
= wpa_scan_get_max_rate(wb
);
1356 if (maxrate_a
!= maxrate_b
)
1357 return maxrate_b
- maxrate_a
;
1358 if (IS_5GHZ(wa
->freq
) ^ IS_5GHZ(wb
->freq
))
1359 return IS_5GHZ(wa
->freq
) ? -1 : 1;
1362 /* use freq for channel preference */
1364 /* all things being equal, use SNR; if SNRs are
1365 * identical, use quality values since some drivers may only report
1366 * that value and leave the signal level zero */
1368 return wb
->qual
- wa
->qual
;
1369 return snr_b
- snr_a
;
1376 /* Compare function for sorting scan results when searching a WPS AP for
1377 * provisioning. Return >0 if @b is considered better. */
1378 static int wpa_scan_result_wps_compar(const void *a
, const void *b
)
1380 struct wpa_scan_res
**_wa
= (void *) a
;
1381 struct wpa_scan_res
**_wb
= (void *) b
;
1382 struct wpa_scan_res
*wa
= *_wa
;
1383 struct wpa_scan_res
*wb
= *_wb
;
1384 int uses_wps_a
, uses_wps_b
;
1385 struct wpabuf
*wps_a
, *wps_b
;
1388 /* Optimization - check WPS IE existence before allocated memory and
1389 * doing full reassembly. */
1390 uses_wps_a
= wpa_scan_get_vendor_ie(wa
, WPS_IE_VENDOR_TYPE
) != NULL
;
1391 uses_wps_b
= wpa_scan_get_vendor_ie(wb
, WPS_IE_VENDOR_TYPE
) != NULL
;
1392 if (uses_wps_a
&& !uses_wps_b
)
1394 if (!uses_wps_a
&& uses_wps_b
)
1397 if (uses_wps_a
&& uses_wps_b
) {
1398 wps_a
= wpa_scan_get_vendor_ie_multi(wa
, WPS_IE_VENDOR_TYPE
);
1399 wps_b
= wpa_scan_get_vendor_ie_multi(wb
, WPS_IE_VENDOR_TYPE
);
1400 res
= wps_ap_priority_compar(wps_a
, wps_b
);
1408 * Do not use current AP security policy as a sorting criteria during
1409 * WPS provisioning step since the AP may get reconfigured at the
1410 * completion of provisioning.
1413 /* all things being equal, use signal level; if signal levels are
1414 * identical, use quality values since some drivers may only report
1415 * that value and leave the signal level zero */
1416 if (wb
->level
== wa
->level
)
1417 return wb
->qual
- wa
->qual
;
1418 return wb
->level
- wa
->level
;
1420 #endif /* CONFIG_WPS */
1423 static void dump_scan_res(struct wpa_scan_results
*scan_res
)
1425 #ifndef CONFIG_NO_STDOUT_DEBUG
1428 if (scan_res
->res
== NULL
|| scan_res
->num
== 0)
1431 wpa_printf(MSG_EXCESSIVE
, "Sorted scan results");
1433 for (i
= 0; i
< scan_res
->num
; i
++) {
1434 struct wpa_scan_res
*r
= scan_res
->res
[i
];
1436 if ((r
->flags
& (WPA_SCAN_LEVEL_DBM
| WPA_SCAN_NOISE_INVALID
))
1437 == WPA_SCAN_LEVEL_DBM
) {
1438 int snr
= r
->level
- r
->noise
;
1439 wpa_printf(MSG_EXCESSIVE
, MACSTR
" freq=%d qual=%d "
1440 "noise=%d level=%d snr=%d%s flags=0x%x",
1441 MAC2STR(r
->bssid
), r
->freq
, r
->qual
,
1442 r
->noise
, r
->level
, snr
,
1443 snr
>= GREAT_SNR
? "*" : "", r
->flags
);
1445 wpa_printf(MSG_EXCESSIVE
, MACSTR
" freq=%d qual=%d "
1446 "noise=%d level=%d flags=0x%x",
1447 MAC2STR(r
->bssid
), r
->freq
, r
->qual
,
1448 r
->noise
, r
->level
, r
->flags
);
1450 pos
= (u8
*) (r
+ 1);
1452 wpa_hexdump(MSG_EXCESSIVE
, "IEs", pos
, r
->ie_len
);
1454 if (r
->beacon_ie_len
)
1455 wpa_hexdump(MSG_EXCESSIVE
, "Beacon IEs",
1456 pos
, r
->beacon_ie_len
);
1458 #endif /* CONFIG_NO_STDOUT_DEBUG */
1463 * wpa_supplicant_filter_bssid_match - Is the specified BSSID allowed
1464 * @wpa_s: Pointer to wpa_supplicant data
1465 * @bssid: BSSID to check
1466 * Returns: 0 if the BSSID is filtered or 1 if not
1468 * This function is used to filter out specific BSSIDs from scan reslts mainly
1469 * for testing purposes (SET bssid_filter ctrl_iface command).
1471 int wpa_supplicant_filter_bssid_match(struct wpa_supplicant
*wpa_s
,
1476 if (wpa_s
->bssid_filter
== NULL
)
1479 for (i
= 0; i
< wpa_s
->bssid_filter_count
; i
++) {
1480 if (os_memcmp(wpa_s
->bssid_filter
+ i
* ETH_ALEN
, bssid
,
1489 static void filter_scan_res(struct wpa_supplicant
*wpa_s
,
1490 struct wpa_scan_results
*res
)
1494 if (wpa_s
->bssid_filter
== NULL
)
1497 for (i
= 0, j
= 0; i
< res
->num
; i
++) {
1498 if (wpa_supplicant_filter_bssid_match(wpa_s
,
1499 res
->res
[i
]->bssid
)) {
1500 res
->res
[j
++] = res
->res
[i
];
1502 os_free(res
->res
[i
]);
1507 if (res
->num
!= j
) {
1508 wpa_printf(MSG_DEBUG
, "Filtered out %d scan results",
1509 (int) (res
->num
- j
));
1516 * wpa_supplicant_get_scan_results - Get scan results
1517 * @wpa_s: Pointer to wpa_supplicant data
1518 * @info: Information about what was scanned or %NULL if not available
1519 * @new_scan: Whether a new scan was performed
1520 * Returns: Scan results, %NULL on failure
1522 * This function request the current scan results from the driver and updates
1523 * the local BSS list wpa_s->bss. The caller is responsible for freeing the
1524 * results with wpa_scan_results_free().
1526 struct wpa_scan_results
*
1527 wpa_supplicant_get_scan_results(struct wpa_supplicant
*wpa_s
,
1528 struct scan_info
*info
, int new_scan
)
1530 struct wpa_scan_results
*scan_res
;
1532 int (*compar
)(const void *, const void *) = wpa_scan_result_compar
;
1534 scan_res
= wpa_drv_get_scan_results2(wpa_s
);
1535 if (scan_res
== NULL
) {
1536 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results");
1539 filter_scan_res(wpa_s
, scan_res
);
1542 if (wpas_wps_in_progress(wpa_s
)) {
1543 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPS: Order scan results with WPS "
1544 "provisioning rules");
1545 compar
= wpa_scan_result_wps_compar
;
1547 #endif /* CONFIG_WPS */
1549 qsort(scan_res
->res
, scan_res
->num
, sizeof(struct wpa_scan_res
*),
1551 dump_scan_res(scan_res
);
1553 wpa_bss_update_start(wpa_s
);
1554 for (i
= 0; i
< scan_res
->num
; i
++)
1555 wpa_bss_update_scan_res(wpa_s
, scan_res
->res
[i
]);
1556 wpa_bss_update_end(wpa_s
, info
, new_scan
);
1563 * wpa_supplicant_update_scan_results - Update scan results from the driver
1564 * @wpa_s: Pointer to wpa_supplicant data
1565 * Returns: 0 on success, -1 on failure
1567 * This function updates the BSS table within wpa_supplicant based on the
1568 * currently available scan results from the driver without requesting a new
1569 * scan. This is used in cases where the driver indicates an association
1570 * (including roaming within ESS) and wpa_supplicant does not yet have the
1571 * needed information to complete the connection (e.g., to perform validation
1572 * steps in 4-way handshake).
1574 int wpa_supplicant_update_scan_results(struct wpa_supplicant
*wpa_s
)
1576 struct wpa_scan_results
*scan_res
;
1577 scan_res
= wpa_supplicant_get_scan_results(wpa_s
, NULL
, 0);
1578 if (scan_res
== NULL
)
1580 wpa_scan_results_free(scan_res
);
1587 * scan_only_handler - Reports scan results
1589 void scan_only_handler(struct wpa_supplicant
*wpa_s
,
1590 struct wpa_scan_results
*scan_res
)
1592 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan-only results received");
1593 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1594 wpas_notify_scan_results(wpa_s
);
1595 wpas_notify_scan_done(wpa_s
, 1);