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