Remove the GPL notification from files contributed by Jouni Malinen
[mech_eap.git] / wpa_supplicant / scan.c
1 /*
2  * WPA Supplicant - Scanning
3  * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8
9 #include "utils/includes.h"
10
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "config.h"
15 #include "wpa_supplicant_i.h"
16 #include "driver_i.h"
17 #include "wps_supplicant.h"
18 #include "p2p_supplicant.h"
19 #include "p2p/p2p.h"
20 #include "notify.h"
21 #include "bss.h"
22 #include "scan.h"
23
24
25 static void wpa_supplicant_gen_assoc_event(struct wpa_supplicant *wpa_s)
26 {
27         struct wpa_ssid *ssid;
28         union wpa_event_data data;
29
30         ssid = wpa_supplicant_get_ssid(wpa_s);
31         if (ssid == NULL)
32                 return;
33
34         if (wpa_s->current_ssid == NULL) {
35                 wpa_s->current_ssid = ssid;
36                 if (wpa_s->current_ssid != NULL)
37                         wpas_notify_network_changed(wpa_s);
38         }
39         wpa_supplicant_initiate_eapol(wpa_s);
40         wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with a configured "
41                 "network - generating associated event");
42         os_memset(&data, 0, sizeof(data));
43         wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
44 }
45
46
47 #ifdef CONFIG_WPS
48 static int wpas_wps_in_use(struct wpa_supplicant *wpa_s,
49                            enum wps_request_type *req_type)
50 {
51         struct wpa_ssid *ssid;
52         int wps = 0;
53
54         for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
55                 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
56                         continue;
57
58                 wps = 1;
59                 *req_type = wpas_wps_get_req_type(ssid);
60                 if (!ssid->eap.phase1)
61                         continue;
62
63                 if (os_strstr(ssid->eap.phase1, "pbc=1"))
64                         return 2;
65         }
66
67 #ifdef CONFIG_P2P
68         if (!wpa_s->global->p2p_disabled && wpa_s->global->p2p) {
69                 wpa_s->wps->dev.p2p = 1;
70                 if (!wps) {
71                         wps = 1;
72                         *req_type = WPS_REQ_ENROLLEE_INFO;
73                 }
74         }
75 #endif /* CONFIG_P2P */
76
77         return wps;
78 }
79 #endif /* CONFIG_WPS */
80
81
82 int wpa_supplicant_enabled_networks(struct wpa_config *conf)
83 {
84         struct wpa_ssid *ssid = conf->ssid;
85         int count = 0;
86         while (ssid) {
87                 if (!ssid->disabled)
88                         count++;
89                 ssid = ssid->next;
90         }
91         return count;
92 }
93
94
95 static void wpa_supplicant_assoc_try(struct wpa_supplicant *wpa_s,
96                                      struct wpa_ssid *ssid)
97 {
98         while (ssid) {
99                 if (!ssid->disabled)
100                         break;
101                 ssid = ssid->next;
102         }
103
104         /* ap_scan=2 mode - try to associate with each SSID. */
105         if (ssid == NULL) {
106                 wpa_dbg(wpa_s, MSG_DEBUG, "wpa_supplicant_assoc_try: Reached "
107                         "end of scan list - go back to beginning");
108                 wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
109                 wpa_supplicant_req_scan(wpa_s, 0, 0);
110                 return;
111         }
112         if (ssid->next) {
113                 /* Continue from the next SSID on the next attempt. */
114                 wpa_s->prev_scan_ssid = ssid;
115         } else {
116                 /* Start from the beginning of the SSID list. */
117                 wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
118         }
119         wpa_supplicant_associate(wpa_s, NULL, ssid);
120 }
121
122
123 static int int_array_len(const int *a)
124 {
125         int i;
126         for (i = 0; a && a[i]; i++)
127                 ;
128         return i;
129 }
130
131
132 static void int_array_concat(int **res, const int *a)
133 {
134         int reslen, alen, i;
135         int *n;
136
137         reslen = int_array_len(*res);
138         alen = int_array_len(a);
139
140         n = os_realloc(*res, (reslen + alen + 1) * sizeof(int));
141         if (n == NULL) {
142                 os_free(*res);
143                 *res = NULL;
144                 return;
145         }
146         for (i = 0; i <= alen; i++)
147                 n[reslen + i] = a[i];
148         *res = n;
149 }
150
151
152 static int freq_cmp(const void *a, const void *b)
153 {
154         int _a = *(int *) a;
155         int _b = *(int *) b;
156
157         if (_a == 0)
158                 return 1;
159         if (_b == 0)
160                 return -1;
161         return _a - _b;
162 }
163
164
165 static void int_array_sort_unique(int *a)
166 {
167         int alen;
168         int i, j;
169
170         if (a == NULL)
171                 return;
172
173         alen = int_array_len(a);
174         qsort(a, alen, sizeof(int), freq_cmp);
175
176         i = 0;
177         j = 1;
178         while (a[i] && a[j]) {
179                 if (a[i] == a[j]) {
180                         j++;
181                         continue;
182                 }
183                 a[++i] = a[j++];
184         }
185         if (a[i])
186                 i++;
187         a[i] = 0;
188 }
189
190
191 int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
192                                 struct wpa_driver_scan_params *params)
193 {
194         int ret;
195
196         wpa_supplicant_notify_scanning(wpa_s, 1);
197
198         ret = wpa_drv_scan(wpa_s, params);
199         if (ret) {
200                 wpa_supplicant_notify_scanning(wpa_s, 0);
201                 wpas_notify_scan_done(wpa_s, 0);
202         } else {
203                 wpa_s->scan_runs++;
204                 wpa_s->normal_scans++;
205         }
206
207         return ret;
208 }
209
210
211 static void
212 wpa_supplicant_delayed_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx)
213 {
214         struct wpa_supplicant *wpa_s = eloop_ctx;
215
216         wpa_dbg(wpa_s, MSG_DEBUG, "Starting delayed sched scan");
217
218         if (wpa_supplicant_req_sched_scan(wpa_s))
219                 wpa_supplicant_req_scan(wpa_s, 0, 0);
220 }
221
222
223 static void
224 wpa_supplicant_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx)
225 {
226         struct wpa_supplicant *wpa_s = eloop_ctx;
227
228         wpa_dbg(wpa_s, MSG_DEBUG, "Sched scan timeout - stopping it");
229
230         wpa_s->sched_scan_timed_out = 1;
231         wpa_supplicant_cancel_sched_scan(wpa_s);
232 }
233
234
235 static int
236 wpa_supplicant_start_sched_scan(struct wpa_supplicant *wpa_s,
237                                 struct wpa_driver_scan_params *params,
238                                 int interval)
239 {
240         int ret;
241
242         wpa_supplicant_notify_scanning(wpa_s, 1);
243         ret = wpa_drv_sched_scan(wpa_s, params, interval * 1000);
244         if (ret)
245                 wpa_supplicant_notify_scanning(wpa_s, 0);
246         else
247                 wpa_s->sched_scanning = 1;
248
249         return ret;
250 }
251
252
253 static int wpa_supplicant_stop_sched_scan(struct wpa_supplicant *wpa_s)
254 {
255         int ret;
256
257         ret = wpa_drv_stop_sched_scan(wpa_s);
258         if (ret) {
259                 wpa_dbg(wpa_s, MSG_DEBUG, "stopping sched_scan failed!");
260                 /* TODO: what to do if stopping fails? */
261                 return -1;
262         }
263
264         return ret;
265 }
266
267
268 static struct wpa_driver_scan_filter *
269 wpa_supplicant_build_filter_ssids(struct wpa_config *conf, size_t *num_ssids)
270 {
271         struct wpa_driver_scan_filter *ssids;
272         struct wpa_ssid *ssid;
273         size_t count;
274
275         *num_ssids = 0;
276         if (!conf->filter_ssids)
277                 return NULL;
278
279         for (count = 0, ssid = conf->ssid; ssid; ssid = ssid->next) {
280                 if (ssid->ssid && ssid->ssid_len)
281                         count++;
282         }
283         if (count == 0)
284                 return NULL;
285         ssids = os_zalloc(count * sizeof(struct wpa_driver_scan_filter));
286         if (ssids == NULL)
287                 return NULL;
288
289         for (ssid = conf->ssid; ssid; ssid = ssid->next) {
290                 if (!ssid->ssid || !ssid->ssid_len)
291                         continue;
292                 os_memcpy(ssids[*num_ssids].ssid, ssid->ssid, ssid->ssid_len);
293                 ssids[*num_ssids].ssid_len = ssid->ssid_len;
294                 (*num_ssids)++;
295         }
296
297         return ssids;
298 }
299
300
301 static void wpa_supplicant_optimize_freqs(
302         struct wpa_supplicant *wpa_s, struct wpa_driver_scan_params *params)
303 {
304 #ifdef CONFIG_P2P
305         if (params->freqs == NULL && wpa_s->p2p_in_provisioning &&
306             wpa_s->go_params) {
307                 /* Optimize provisioning state scan based on GO information */
308                 if (wpa_s->p2p_in_provisioning < 5 &&
309                     wpa_s->go_params->freq > 0) {
310                         wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only GO "
311                                 "preferred frequency %d MHz",
312                                 wpa_s->go_params->freq);
313                         params->freqs = os_zalloc(2 * sizeof(int));
314                         if (params->freqs)
315                                 params->freqs[0] = wpa_s->go_params->freq;
316                 } else if (wpa_s->p2p_in_provisioning < 8 &&
317                            wpa_s->go_params->freq_list[0]) {
318                         wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only common "
319                                 "channels");
320                         int_array_concat(&params->freqs,
321                                          wpa_s->go_params->freq_list);
322                         if (params->freqs)
323                                 int_array_sort_unique(params->freqs);
324                 }
325                 wpa_s->p2p_in_provisioning++;
326         }
327 #endif /* CONFIG_P2P */
328
329 #ifdef CONFIG_WPS
330         if (params->freqs == NULL && wpa_s->after_wps && wpa_s->wps_freq) {
331                 /*
332                  * Optimize post-provisioning scan based on channel used
333                  * during provisioning.
334                  */
335                 wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz "
336                         "that was used during provisioning", wpa_s->wps_freq);
337                 params->freqs = os_zalloc(2 * sizeof(int));
338                 if (params->freqs)
339                         params->freqs[0] = wpa_s->wps_freq;
340                 wpa_s->after_wps--;
341         }
342
343         if (params->freqs == NULL && wpa_s->known_wps_freq && wpa_s->wps_freq)
344         {
345                 /* Optimize provisioning scan based on already known channel */
346                 wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz",
347                         wpa_s->wps_freq);
348                 params->freqs = os_zalloc(2 * sizeof(int));
349                 if (params->freqs)
350                         params->freqs[0] = wpa_s->wps_freq;
351                 wpa_s->known_wps_freq = 0; /* only do this once */
352         }
353 #endif /* CONFIG_WPS */
354 }
355
356
357 #ifdef CONFIG_INTERWORKING
358 static void wpas_add_interworking_elements(struct wpa_supplicant *wpa_s,
359                                            struct wpabuf *buf)
360 {
361         if (wpa_s->conf->interworking == 0)
362                 return;
363
364         wpabuf_put_u8(buf, WLAN_EID_EXT_CAPAB);
365         wpabuf_put_u8(buf, 4);
366         wpabuf_put_u8(buf, 0x00);
367         wpabuf_put_u8(buf, 0x00);
368         wpabuf_put_u8(buf, 0x00);
369         wpabuf_put_u8(buf, 0x80); /* Bit 31 - Interworking */
370
371         wpabuf_put_u8(buf, WLAN_EID_INTERWORKING);
372         wpabuf_put_u8(buf, is_zero_ether_addr(wpa_s->conf->hessid) ? 1 :
373                       1 + ETH_ALEN);
374         wpabuf_put_u8(buf, wpa_s->conf->access_network_type);
375         /* No Venue Info */
376         if (!is_zero_ether_addr(wpa_s->conf->hessid))
377                 wpabuf_put_data(buf, wpa_s->conf->hessid, ETH_ALEN);
378 }
379 #endif /* CONFIG_INTERWORKING */
380
381
382 static struct wpabuf *
383 wpa_supplicant_extra_ies(struct wpa_supplicant *wpa_s,
384                          struct wpa_driver_scan_params *params)
385 {
386         struct wpabuf *extra_ie = NULL;
387 #ifdef CONFIG_WPS
388         int wps = 0;
389         enum wps_request_type req_type = WPS_REQ_ENROLLEE_INFO;
390 #endif /* CONFIG_WPS */
391
392 #ifdef CONFIG_INTERWORKING
393         if (wpa_s->conf->interworking &&
394             wpabuf_resize(&extra_ie, 100) == 0)
395                 wpas_add_interworking_elements(wpa_s, extra_ie);
396 #endif /* CONFIG_INTERWORKING */
397
398 #ifdef CONFIG_WPS
399         wps = wpas_wps_in_use(wpa_s, &req_type);
400
401         if (wps) {
402                 struct wpabuf *wps_ie;
403                 wps_ie = wps_build_probe_req_ie(wps == 2, &wpa_s->wps->dev,
404                                                 wpa_s->wps->uuid, req_type,
405                                                 0, NULL);
406                 if (wps_ie) {
407                         if (wpabuf_resize(&extra_ie, wpabuf_len(wps_ie)) == 0)
408                                 wpabuf_put_buf(extra_ie, wps_ie);
409                         wpabuf_free(wps_ie);
410                 }
411         }
412
413 #ifdef CONFIG_P2P
414         if (wps) {
415                 size_t ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
416                 if (wpabuf_resize(&extra_ie, ielen) == 0)
417                         wpas_p2p_scan_ie(wpa_s, extra_ie);
418         }
419 #endif /* CONFIG_P2P */
420
421 #endif /* CONFIG_WPS */
422
423         return extra_ie;
424 }
425
426
427 static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
428 {
429         struct wpa_supplicant *wpa_s = eloop_ctx;
430         struct wpa_ssid *ssid;
431         int scan_req = 0, ret;
432         struct wpabuf *extra_ie;
433         struct wpa_driver_scan_params params;
434         size_t max_ssids;
435         enum wpa_states prev_state;
436
437         if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
438                 wpa_dbg(wpa_s, MSG_DEBUG, "Skip scan - interface disabled");
439                 return;
440         }
441
442         if (wpa_s->disconnected && !wpa_s->scan_req) {
443                 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
444                 return;
445         }
446
447         if (!wpa_supplicant_enabled_networks(wpa_s->conf) &&
448             !wpa_s->scan_req) {
449                 wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks - do not scan");
450                 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
451                 return;
452         }
453
454         if (wpa_s->conf->ap_scan != 0 &&
455             (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) {
456                 wpa_dbg(wpa_s, MSG_DEBUG, "Using wired authentication - "
457                         "overriding ap_scan configuration");
458                 wpa_s->conf->ap_scan = 0;
459                 wpas_notify_ap_scan_changed(wpa_s);
460         }
461
462         if (wpa_s->conf->ap_scan == 0) {
463                 wpa_supplicant_gen_assoc_event(wpa_s);
464                 return;
465         }
466
467 #ifdef CONFIG_P2P
468         if (wpas_p2p_in_progress(wpa_s)) {
469                 if (wpa_s->wpa_state == WPA_SCANNING) {
470                         wpa_dbg(wpa_s, MSG_DEBUG, "Delay station mode scan "
471                                 "while P2P operation is in progress");
472                         wpa_supplicant_req_scan(wpa_s, 5, 0);
473                 } else {
474                         wpa_dbg(wpa_s, MSG_DEBUG, "Do not request scan while "
475                                 "P2P operation is in progress");
476                 }
477                 return;
478         }
479 #endif /* CONFIG_P2P */
480
481         if (wpa_s->conf->ap_scan == 2)
482                 max_ssids = 1;
483         else {
484                 max_ssids = wpa_s->max_scan_ssids;
485                 if (max_ssids > WPAS_MAX_SCAN_SSIDS)
486                         max_ssids = WPAS_MAX_SCAN_SSIDS;
487         }
488
489         scan_req = wpa_s->scan_req;
490         wpa_s->scan_req = 0;
491
492         os_memset(&params, 0, sizeof(params));
493
494         prev_state = wpa_s->wpa_state;
495         if (wpa_s->wpa_state == WPA_DISCONNECTED ||
496             wpa_s->wpa_state == WPA_INACTIVE)
497                 wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
498
499         if (scan_req != 2 && wpa_s->connect_without_scan) {
500                 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
501                         if (ssid == wpa_s->connect_without_scan)
502                                 break;
503                 }
504                 wpa_s->connect_without_scan = NULL;
505                 if (ssid) {
506                         wpa_printf(MSG_DEBUG, "Start a pre-selected network "
507                                    "without scan step");
508                         wpa_supplicant_associate(wpa_s, NULL, ssid);
509                         return;
510                 }
511         }
512
513         /* Find the starting point from which to continue scanning */
514         ssid = wpa_s->conf->ssid;
515         if (wpa_s->prev_scan_ssid != WILDCARD_SSID_SCAN) {
516                 while (ssid) {
517                         if (ssid == wpa_s->prev_scan_ssid) {
518                                 ssid = ssid->next;
519                                 break;
520                         }
521                         ssid = ssid->next;
522                 }
523         }
524
525         if (scan_req != 2 && wpa_s->conf->ap_scan == 2) {
526                 wpa_s->connect_without_scan = NULL;
527                 wpa_s->prev_scan_wildcard = 0;
528                 wpa_supplicant_assoc_try(wpa_s, ssid);
529                 return;
530         } else if (wpa_s->conf->ap_scan == 2) {
531                 /*
532                  * User-initiated scan request in ap_scan == 2; scan with
533                  * wildcard SSID.
534                  */
535                 ssid = NULL;
536         } else {
537                 struct wpa_ssid *start = ssid, *tssid;
538                 int freqs_set = 0;
539                 if (ssid == NULL && max_ssids > 1)
540                         ssid = wpa_s->conf->ssid;
541                 while (ssid) {
542                         if (!ssid->disabled && ssid->scan_ssid) {
543                                 wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID",
544                                                   ssid->ssid, ssid->ssid_len);
545                                 params.ssids[params.num_ssids].ssid =
546                                         ssid->ssid;
547                                 params.ssids[params.num_ssids].ssid_len =
548                                         ssid->ssid_len;
549                                 params.num_ssids++;
550                                 if (params.num_ssids + 1 >= max_ssids)
551                                         break;
552                         }
553                         ssid = ssid->next;
554                         if (ssid == start)
555                                 break;
556                         if (ssid == NULL && max_ssids > 1 &&
557                             start != wpa_s->conf->ssid)
558                                 ssid = wpa_s->conf->ssid;
559                 }
560
561                 for (tssid = wpa_s->conf->ssid; tssid; tssid = tssid->next) {
562                         if (tssid->disabled)
563                                 continue;
564                         if ((params.freqs || !freqs_set) && tssid->scan_freq) {
565                                 int_array_concat(&params.freqs,
566                                                  tssid->scan_freq);
567                         } else {
568                                 os_free(params.freqs);
569                                 params.freqs = NULL;
570                         }
571                         freqs_set = 1;
572                 }
573                 int_array_sort_unique(params.freqs);
574         }
575
576         if (ssid && max_ssids == 1) {
577                 /*
578                  * If the driver is limited to 1 SSID at a time interleave
579                  * wildcard SSID scans with specific SSID scans to avoid
580                  * waiting a long time for a wildcard scan.
581                  */
582                 if (!wpa_s->prev_scan_wildcard) {
583                         params.ssids[0].ssid = NULL;
584                         params.ssids[0].ssid_len = 0;
585                         wpa_s->prev_scan_wildcard = 1;
586                         wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for "
587                                 "wildcard SSID (Interleave with specific)");
588                 } else {
589                         wpa_s->prev_scan_ssid = ssid;
590                         wpa_s->prev_scan_wildcard = 0;
591                         wpa_dbg(wpa_s, MSG_DEBUG,
592                                 "Starting AP scan for specific SSID: %s",
593                                 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
594                 }
595         } else if (ssid) {
596                 /* max_ssids > 1 */
597
598                 wpa_s->prev_scan_ssid = ssid;
599                 wpa_dbg(wpa_s, MSG_DEBUG, "Include wildcard SSID in "
600                         "the scan request");
601                 params.num_ssids++;
602         } else {
603                 wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
604                 params.num_ssids++;
605                 wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for wildcard "
606                         "SSID");
607         }
608
609         wpa_supplicant_optimize_freqs(wpa_s, &params);
610         extra_ie = wpa_supplicant_extra_ies(wpa_s, &params);
611
612         if (params.freqs == NULL && wpa_s->next_scan_freqs) {
613                 wpa_dbg(wpa_s, MSG_DEBUG, "Optimize scan based on previously "
614                         "generated frequency list");
615                 params.freqs = wpa_s->next_scan_freqs;
616         } else
617                 os_free(wpa_s->next_scan_freqs);
618         wpa_s->next_scan_freqs = NULL;
619
620         params.filter_ssids = wpa_supplicant_build_filter_ssids(
621                 wpa_s->conf, &params.num_filter_ssids);
622         if (extra_ie) {
623                 params.extra_ies = wpabuf_head(extra_ie);
624                 params.extra_ies_len = wpabuf_len(extra_ie);
625         }
626
627 #ifdef CONFIG_P2P
628         if (wpa_s->p2p_in_provisioning) {
629                 /*
630                  * The interface may not yet be in P2P mode, so we have to
631                  * explicitly request P2P probe to disable CCK rates.
632                  */
633                 params.p2p_probe = 1;
634         }
635 #endif /* CONFIG_P2P */
636
637         ret = wpa_supplicant_trigger_scan(wpa_s, &params);
638
639         wpabuf_free(extra_ie);
640         os_free(params.freqs);
641         os_free(params.filter_ssids);
642
643         if (ret) {
644                 wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate AP scan");
645                 if (prev_state != wpa_s->wpa_state)
646                         wpa_supplicant_set_state(wpa_s, prev_state);
647                 wpa_supplicant_req_scan(wpa_s, 1, 0);
648         }
649 }
650
651
652 /**
653  * wpa_supplicant_req_scan - Schedule a scan for neighboring access points
654  * @wpa_s: Pointer to wpa_supplicant data
655  * @sec: Number of seconds after which to scan
656  * @usec: Number of microseconds after which to scan
657  *
658  * This function is used to schedule a scan for neighboring access points after
659  * the specified time.
660  */
661 void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec)
662 {
663         /* If there's at least one network that should be specifically scanned
664          * then don't cancel the scan and reschedule.  Some drivers do
665          * background scanning which generates frequent scan results, and that
666          * causes the specific SSID scan to get continually pushed back and
667          * never happen, which causes hidden APs to never get probe-scanned.
668          */
669         if (eloop_is_timeout_registered(wpa_supplicant_scan, wpa_s, NULL) &&
670             wpa_s->conf->ap_scan == 1) {
671                 struct wpa_ssid *ssid = wpa_s->conf->ssid;
672
673                 while (ssid) {
674                         if (!ssid->disabled && ssid->scan_ssid)
675                                 break;
676                         ssid = ssid->next;
677                 }
678                 if (ssid) {
679                         wpa_dbg(wpa_s, MSG_DEBUG, "Not rescheduling scan to "
680                                 "ensure that specific SSID scans occur");
681                         return;
682                 }
683         }
684
685         wpa_dbg(wpa_s, MSG_DEBUG, "Setting scan request: %d sec %d usec",
686                 sec, usec);
687         eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
688         eloop_register_timeout(sec, usec, wpa_supplicant_scan, wpa_s, NULL);
689 }
690
691
692 /**
693  * wpa_supplicant_delayed_sched_scan - Request a delayed scheduled scan
694  * @wpa_s: Pointer to wpa_supplicant data
695  * @sec: Number of seconds after which to scan
696  * @usec: Number of microseconds after which to scan
697  *
698  * This function is used to schedule periodic scans for neighboring
699  * access points after the specified time.
700  */
701 int wpa_supplicant_delayed_sched_scan(struct wpa_supplicant *wpa_s,
702                                       int sec, int usec)
703 {
704         if (!wpa_s->sched_scan_supported)
705                 return -1;
706
707         eloop_register_timeout(sec, usec,
708                                wpa_supplicant_delayed_sched_scan_timeout,
709                                wpa_s, NULL);
710
711         return 0;
712 }
713
714
715 /**
716  * wpa_supplicant_req_sched_scan - Start a periodic scheduled scan
717  * @wpa_s: Pointer to wpa_supplicant data
718  *
719  * This function is used to schedule periodic scans for neighboring
720  * access points repeating the scan continuously.
721  */
722 int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s)
723 {
724         struct wpa_driver_scan_params params;
725         enum wpa_states prev_state;
726         struct wpa_ssid *ssid;
727         struct wpabuf *wps_ie = NULL;
728         int ret;
729         unsigned int max_sched_scan_ssids;
730         int wildcard = 0;
731         int need_ssids;
732
733         if (!wpa_s->sched_scan_supported)
734                 return -1;
735
736         if (wpa_s->max_sched_scan_ssids > WPAS_MAX_SCAN_SSIDS)
737                 max_sched_scan_ssids = WPAS_MAX_SCAN_SSIDS;
738         else
739                 max_sched_scan_ssids = wpa_s->max_sched_scan_ssids;
740         if (max_sched_scan_ssids < 1)
741                 return -1;
742
743         if (wpa_s->sched_scanning) {
744                 wpa_dbg(wpa_s, MSG_DEBUG, "Already sched scanning");
745                 return 0;
746         }
747
748         need_ssids = 0;
749         for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
750                 if (!ssid->disabled && !ssid->scan_ssid) {
751                         /* Use wildcard SSID to find this network */
752                         wildcard = 1;
753                 } else if (!ssid->disabled && ssid->ssid_len)
754                         need_ssids++;
755         }
756         if (wildcard)
757                 need_ssids++;
758
759         if (wpa_s->normal_scans < 3 &&
760             (need_ssids <= wpa_s->max_scan_ssids ||
761              wpa_s->max_scan_ssids >= (int) max_sched_scan_ssids)) {
762                 /*
763                  * When normal scan can speed up operations, use that for the
764                  * first operations before starting the sched_scan to allow
765                  * user space sleep more. We do this only if the normal scan
766                  * has functionality that is suitable for this or if the
767                  * sched_scan does not have better support for multiple SSIDs.
768                  */
769                 wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of "
770                         "sched_scan for initial scans (normal_scans=%d)",
771                         wpa_s->normal_scans);
772                 return -1;
773         }
774
775         os_memset(&params, 0, sizeof(params));
776
777         /* If we can't allocate space for the filters, we just don't filter */
778         params.filter_ssids = os_zalloc(wpa_s->max_match_sets *
779                                         sizeof(struct wpa_driver_scan_filter));
780
781         prev_state = wpa_s->wpa_state;
782         if (wpa_s->wpa_state == WPA_DISCONNECTED ||
783             wpa_s->wpa_state == WPA_INACTIVE)
784                 wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
785
786         /* Find the starting point from which to continue scanning */
787         ssid = wpa_s->conf->ssid;
788         if (wpa_s->prev_sched_ssid) {
789                 while (ssid) {
790                         if (ssid == wpa_s->prev_sched_ssid) {
791                                 ssid = ssid->next;
792                                 break;
793                         }
794                         ssid = ssid->next;
795                 }
796         }
797
798         if (!ssid || !wpa_s->prev_sched_ssid) {
799                 wpa_dbg(wpa_s, MSG_DEBUG, "Beginning of SSID list");
800
801                 wpa_s->sched_scan_interval = 10;
802                 wpa_s->sched_scan_timeout = max_sched_scan_ssids * 2;
803                 wpa_s->first_sched_scan = 1;
804                 ssid = wpa_s->conf->ssid;
805                 wpa_s->prev_sched_ssid = ssid;
806         }
807
808         if (wildcard) {
809                 wpa_dbg(wpa_s, MSG_DEBUG, "Add wildcard SSID to sched_scan");
810                 params.num_ssids++;
811         }
812
813         while (ssid) {
814                 if (ssid->disabled)
815                         goto next;
816
817                 if (params.num_filter_ssids < wpa_s->max_match_sets &&
818                     params.filter_ssids && ssid->ssid && ssid->ssid_len) {
819                         wpa_dbg(wpa_s, MSG_DEBUG, "add to filter ssid: %s",
820                                 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
821                         os_memcpy(params.filter_ssids[params.num_filter_ssids].ssid,
822                                   ssid->ssid, ssid->ssid_len);
823                         params.filter_ssids[params.num_filter_ssids].ssid_len =
824                                 ssid->ssid_len;
825                         params.num_filter_ssids++;
826                 } else if (params.filter_ssids && ssid->ssid && ssid->ssid_len)
827                 {
828                         wpa_dbg(wpa_s, MSG_DEBUG, "Not enough room for SSID "
829                                 "filter for sched_scan - drop filter");
830                         os_free(params.filter_ssids);
831                         params.filter_ssids = NULL;
832                         params.num_filter_ssids = 0;
833                 }
834
835                 if (ssid->scan_ssid && ssid->ssid && ssid->ssid_len) {
836                         if (params.num_ssids == max_sched_scan_ssids)
837                                 break; /* only room for broadcast SSID */
838                         wpa_dbg(wpa_s, MSG_DEBUG,
839                                 "add to active scan ssid: %s",
840                                 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
841                         params.ssids[params.num_ssids].ssid =
842                                 ssid->ssid;
843                         params.ssids[params.num_ssids].ssid_len =
844                                 ssid->ssid_len;
845                         params.num_ssids++;
846                         if (params.num_ssids >= max_sched_scan_ssids) {
847                                 wpa_s->prev_sched_ssid = ssid;
848                                 break;
849                         }
850                 }
851
852         next:
853                 wpa_s->prev_sched_ssid = ssid;
854                 ssid = ssid->next;
855         }
856
857         if (params.num_filter_ssids == 0) {
858                 os_free(params.filter_ssids);
859                 params.filter_ssids = NULL;
860         }
861
862         if (wpa_s->wps)
863                 wps_ie = wpa_supplicant_extra_ies(wpa_s, &params);
864
865         if (ssid || !wpa_s->first_sched_scan) {
866                 wpa_dbg(wpa_s, MSG_DEBUG,
867                         "Starting sched scan: interval %d (no timeout)",
868                         wpa_s->sched_scan_interval);
869         } else {
870                 wpa_dbg(wpa_s, MSG_DEBUG,
871                         "Starting sched scan: interval %d timeout %d",
872                         wpa_s->sched_scan_interval, wpa_s->sched_scan_timeout);
873         }
874
875         ret = wpa_supplicant_start_sched_scan(wpa_s, &params,
876                                               wpa_s->sched_scan_interval);
877         wpabuf_free(wps_ie);
878         os_free(params.filter_ssids);
879         if (ret) {
880                 wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate sched scan");
881                 if (prev_state != wpa_s->wpa_state)
882                         wpa_supplicant_set_state(wpa_s, prev_state);
883                 return ret;
884         }
885
886         /* If we have more SSIDs to scan, add a timeout so we scan them too */
887         if (ssid || !wpa_s->first_sched_scan) {
888                 wpa_s->sched_scan_timed_out = 0;
889                 eloop_register_timeout(wpa_s->sched_scan_timeout, 0,
890                                        wpa_supplicant_sched_scan_timeout,
891                                        wpa_s, NULL);
892                 wpa_s->first_sched_scan = 0;
893                 wpa_s->sched_scan_timeout /= 2;
894                 wpa_s->sched_scan_interval *= 2;
895         }
896
897         return 0;
898 }
899
900
901 /**
902  * wpa_supplicant_cancel_scan - Cancel a scheduled scan request
903  * @wpa_s: Pointer to wpa_supplicant data
904  *
905  * This function is used to cancel a scan request scheduled with
906  * wpa_supplicant_req_scan().
907  */
908 void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s)
909 {
910         wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling scan request");
911         eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
912 }
913
914
915 /**
916  * wpa_supplicant_cancel_sched_scan - Stop running scheduled scans
917  * @wpa_s: Pointer to wpa_supplicant data
918  *
919  * This function is used to stop a periodic scheduled scan.
920  */
921 void wpa_supplicant_cancel_sched_scan(struct wpa_supplicant *wpa_s)
922 {
923         if (!wpa_s->sched_scanning)
924                 return;
925
926         wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling sched scan");
927         eloop_cancel_timeout(wpa_supplicant_sched_scan_timeout, wpa_s, NULL);
928         wpa_supplicant_stop_sched_scan(wpa_s);
929 }
930
931
932 void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s,
933                                     int scanning)
934 {
935         if (wpa_s->scanning != scanning) {
936                 wpa_s->scanning = scanning;
937                 wpas_notify_scanning(wpa_s);
938         }
939 }
940
941
942 static int wpa_scan_get_max_rate(const struct wpa_scan_res *res)
943 {
944         int rate = 0;
945         const u8 *ie;
946         int i;
947
948         ie = wpa_scan_get_ie(res, WLAN_EID_SUPP_RATES);
949         for (i = 0; ie && i < ie[1]; i++) {
950                 if ((ie[i + 2] & 0x7f) > rate)
951                         rate = ie[i + 2] & 0x7f;
952         }
953
954         ie = wpa_scan_get_ie(res, WLAN_EID_EXT_SUPP_RATES);
955         for (i = 0; ie && i < ie[1]; i++) {
956                 if ((ie[i + 2] & 0x7f) > rate)
957                         rate = ie[i + 2] & 0x7f;
958         }
959
960         return rate;
961 }
962
963
964 const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie)
965 {
966         const u8 *end, *pos;
967
968         pos = (const u8 *) (res + 1);
969         end = pos + res->ie_len;
970
971         while (pos + 1 < end) {
972                 if (pos + 2 + pos[1] > end)
973                         break;
974                 if (pos[0] == ie)
975                         return pos;
976                 pos += 2 + pos[1];
977         }
978
979         return NULL;
980 }
981
982
983 const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
984                                   u32 vendor_type)
985 {
986         const u8 *end, *pos;
987
988         pos = (const u8 *) (res + 1);
989         end = pos + res->ie_len;
990
991         while (pos + 1 < end) {
992                 if (pos + 2 + pos[1] > end)
993                         break;
994                 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
995                     vendor_type == WPA_GET_BE32(&pos[2]))
996                         return pos;
997                 pos += 2 + pos[1];
998         }
999
1000         return NULL;
1001 }
1002
1003
1004 struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
1005                                              u32 vendor_type)
1006 {
1007         struct wpabuf *buf;
1008         const u8 *end, *pos;
1009
1010         buf = wpabuf_alloc(res->ie_len);
1011         if (buf == NULL)
1012                 return NULL;
1013
1014         pos = (const u8 *) (res + 1);
1015         end = pos + res->ie_len;
1016
1017         while (pos + 1 < end) {
1018                 if (pos + 2 + pos[1] > end)
1019                         break;
1020                 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1021                     vendor_type == WPA_GET_BE32(&pos[2]))
1022                         wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
1023                 pos += 2 + pos[1];
1024         }
1025
1026         if (wpabuf_len(buf) == 0) {
1027                 wpabuf_free(buf);
1028                 buf = NULL;
1029         }
1030
1031         return buf;
1032 }
1033
1034
1035 struct wpabuf * wpa_scan_get_vendor_ie_multi_beacon(
1036         const struct wpa_scan_res *res, u32 vendor_type)
1037 {
1038         struct wpabuf *buf;
1039         const u8 *end, *pos;
1040
1041         if (res->beacon_ie_len == 0)
1042                 return NULL;
1043         buf = wpabuf_alloc(res->beacon_ie_len);
1044         if (buf == NULL)
1045                 return NULL;
1046
1047         pos = (const u8 *) (res + 1);
1048         pos += res->ie_len;
1049         end = pos + res->beacon_ie_len;
1050
1051         while (pos + 1 < end) {
1052                 if (pos + 2 + pos[1] > end)
1053                         break;
1054                 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1055                     vendor_type == WPA_GET_BE32(&pos[2]))
1056                         wpabuf_put_data(buf, pos + 2 + 4, pos[1] - 4);
1057                 pos += 2 + pos[1];
1058         }
1059
1060         if (wpabuf_len(buf) == 0) {
1061                 wpabuf_free(buf);
1062                 buf = NULL;
1063         }
1064
1065         return buf;
1066 }
1067
1068
1069 /*
1070  * Channels with a great SNR can operate at full rate. What is a great SNR?
1071  * This doc https://supportforums.cisco.com/docs/DOC-12954 says, "the general
1072  * rule of thumb is that any SNR above 20 is good." This one
1073  * http://www.cisco.com/en/US/tech/tk722/tk809/technologies_q_and_a_item09186a00805e9a96.shtml#qa23
1074  * recommends 25 as a minimum SNR for 54 Mbps data rate. 30 is chosen here as a
1075  * conservative value.
1076  */
1077 #define GREAT_SNR 30
1078
1079 /* Compare function for sorting scan results. Return >0 if @b is considered
1080  * better. */
1081 static int wpa_scan_result_compar(const void *a, const void *b)
1082 {
1083 #define IS_5GHZ(n) (n > 4000)
1084 #define MIN(a,b) a < b ? a : b
1085         struct wpa_scan_res **_wa = (void *) a;
1086         struct wpa_scan_res **_wb = (void *) b;
1087         struct wpa_scan_res *wa = *_wa;
1088         struct wpa_scan_res *wb = *_wb;
1089         int wpa_a, wpa_b, maxrate_a, maxrate_b;
1090         int snr_a, snr_b;
1091
1092         /* WPA/WPA2 support preferred */
1093         wpa_a = wpa_scan_get_vendor_ie(wa, WPA_IE_VENDOR_TYPE) != NULL ||
1094                 wpa_scan_get_ie(wa, WLAN_EID_RSN) != NULL;
1095         wpa_b = wpa_scan_get_vendor_ie(wb, WPA_IE_VENDOR_TYPE) != NULL ||
1096                 wpa_scan_get_ie(wb, WLAN_EID_RSN) != NULL;
1097
1098         if (wpa_b && !wpa_a)
1099                 return 1;
1100         if (!wpa_b && wpa_a)
1101                 return -1;
1102
1103         /* privacy support preferred */
1104         if ((wa->caps & IEEE80211_CAP_PRIVACY) == 0 &&
1105             (wb->caps & IEEE80211_CAP_PRIVACY))
1106                 return 1;
1107         if ((wa->caps & IEEE80211_CAP_PRIVACY) &&
1108             (wb->caps & IEEE80211_CAP_PRIVACY) == 0)
1109                 return -1;
1110
1111         if ((wa->flags & wb->flags & WPA_SCAN_LEVEL_DBM) &&
1112             !((wa->flags | wb->flags) & WPA_SCAN_NOISE_INVALID)) {
1113                 snr_a = MIN(wa->level - wa->noise, GREAT_SNR);
1114                 snr_b = MIN(wb->level - wb->noise, GREAT_SNR);
1115         } else {
1116                 /* Not suitable information to calculate SNR, so use level */
1117                 snr_a = wa->level;
1118                 snr_b = wb->level;
1119         }
1120
1121         /* best/max rate preferred if SNR close enough */
1122         if ((snr_a && snr_b && abs(snr_b - snr_a) < 5) ||
1123             (wa->qual && wb->qual && abs(wb->qual - wa->qual) < 10)) {
1124                 maxrate_a = wpa_scan_get_max_rate(wa);
1125                 maxrate_b = wpa_scan_get_max_rate(wb);
1126                 if (maxrate_a != maxrate_b)
1127                         return maxrate_b - maxrate_a;
1128                 if (IS_5GHZ(wa->freq) ^ IS_5GHZ(wb->freq))
1129                         return IS_5GHZ(wa->freq) ? -1 : 1;
1130         }
1131
1132         /* use freq for channel preference */
1133
1134         /* all things being equal, use SNR; if SNRs are
1135          * identical, use quality values since some drivers may only report
1136          * that value and leave the signal level zero */
1137         if (snr_b == snr_a)
1138                 return wb->qual - wa->qual;
1139         return snr_b - snr_a;
1140 #undef MIN
1141 #undef IS_5GHZ
1142 }
1143
1144
1145 #ifdef CONFIG_WPS
1146 /* Compare function for sorting scan results when searching a WPS AP for
1147  * provisioning. Return >0 if @b is considered better. */
1148 static int wpa_scan_result_wps_compar(const void *a, const void *b)
1149 {
1150         struct wpa_scan_res **_wa = (void *) a;
1151         struct wpa_scan_res **_wb = (void *) b;
1152         struct wpa_scan_res *wa = *_wa;
1153         struct wpa_scan_res *wb = *_wb;
1154         int uses_wps_a, uses_wps_b;
1155         struct wpabuf *wps_a, *wps_b;
1156         int res;
1157
1158         /* Optimization - check WPS IE existence before allocated memory and
1159          * doing full reassembly. */
1160         uses_wps_a = wpa_scan_get_vendor_ie(wa, WPS_IE_VENDOR_TYPE) != NULL;
1161         uses_wps_b = wpa_scan_get_vendor_ie(wb, WPS_IE_VENDOR_TYPE) != NULL;
1162         if (uses_wps_a && !uses_wps_b)
1163                 return -1;
1164         if (!uses_wps_a && uses_wps_b)
1165                 return 1;
1166
1167         if (uses_wps_a && uses_wps_b) {
1168                 wps_a = wpa_scan_get_vendor_ie_multi(wa, WPS_IE_VENDOR_TYPE);
1169                 wps_b = wpa_scan_get_vendor_ie_multi(wb, WPS_IE_VENDOR_TYPE);
1170                 res = wps_ap_priority_compar(wps_a, wps_b);
1171                 wpabuf_free(wps_a);
1172                 wpabuf_free(wps_b);
1173                 if (res)
1174                         return res;
1175         }
1176
1177         /*
1178          * Do not use current AP security policy as a sorting criteria during
1179          * WPS provisioning step since the AP may get reconfigured at the
1180          * completion of provisioning.
1181          */
1182
1183         /* all things being equal, use signal level; if signal levels are
1184          * identical, use quality values since some drivers may only report
1185          * that value and leave the signal level zero */
1186         if (wb->level == wa->level)
1187                 return wb->qual - wa->qual;
1188         return wb->level - wa->level;
1189 }
1190 #endif /* CONFIG_WPS */
1191
1192
1193 static void dump_scan_res(struct wpa_scan_results *scan_res)
1194 {
1195 #ifndef CONFIG_NO_STDOUT_DEBUG
1196         size_t i;
1197
1198         if (scan_res->res == NULL || scan_res->num == 0)
1199                 return;
1200
1201         wpa_printf(MSG_EXCESSIVE, "Sorted scan results");
1202
1203         for (i = 0; i < scan_res->num; i++) {
1204                 struct wpa_scan_res *r = scan_res->res[i];
1205                 if ((r->flags & (WPA_SCAN_LEVEL_DBM | WPA_SCAN_NOISE_INVALID))
1206                     == WPA_SCAN_LEVEL_DBM) {
1207                         int snr = r->level - r->noise;
1208                         wpa_printf(MSG_EXCESSIVE, MACSTR " freq=%d qual=%d "
1209                                    "noise=%d level=%d snr=%d%s flags=0x%x",
1210                                    MAC2STR(r->bssid), r->freq, r->qual,
1211                                    r->noise, r->level, snr,
1212                                    snr >= GREAT_SNR ? "*" : "", r->flags);
1213                 } else {
1214                         wpa_printf(MSG_EXCESSIVE, MACSTR " freq=%d qual=%d "
1215                                    "noise=%d level=%d flags=0x%x",
1216                                    MAC2STR(r->bssid), r->freq, r->qual,
1217                                    r->noise, r->level, r->flags);
1218                 }
1219         }
1220 #endif /* CONFIG_NO_STDOUT_DEBUG */
1221 }
1222
1223
1224 /**
1225  * wpa_supplicant_get_scan_results - Get scan results
1226  * @wpa_s: Pointer to wpa_supplicant data
1227  * @info: Information about what was scanned or %NULL if not available
1228  * @new_scan: Whether a new scan was performed
1229  * Returns: Scan results, %NULL on failure
1230  *
1231  * This function request the current scan results from the driver and updates
1232  * the local BSS list wpa_s->bss. The caller is responsible for freeing the
1233  * results with wpa_scan_results_free().
1234  */
1235 struct wpa_scan_results *
1236 wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s,
1237                                 struct scan_info *info, int new_scan)
1238 {
1239         struct wpa_scan_results *scan_res;
1240         size_t i;
1241         int (*compar)(const void *, const void *) = wpa_scan_result_compar;
1242
1243         scan_res = wpa_drv_get_scan_results2(wpa_s);
1244         if (scan_res == NULL) {
1245                 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results");
1246                 return NULL;
1247         }
1248
1249 #ifdef CONFIG_WPS
1250         if (wpas_wps_in_progress(wpa_s)) {
1251                 wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Order scan results with WPS "
1252                         "provisioning rules");
1253                 compar = wpa_scan_result_wps_compar;
1254         }
1255 #endif /* CONFIG_WPS */
1256
1257         qsort(scan_res->res, scan_res->num, sizeof(struct wpa_scan_res *),
1258               compar);
1259         dump_scan_res(scan_res);
1260
1261         wpa_bss_update_start(wpa_s);
1262         for (i = 0; i < scan_res->num; i++)
1263                 wpa_bss_update_scan_res(wpa_s, scan_res->res[i]);
1264         wpa_bss_update_end(wpa_s, info, new_scan);
1265
1266         return scan_res;
1267 }
1268
1269
1270 int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s)
1271 {
1272         struct wpa_scan_results *scan_res;
1273         scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0);
1274         if (scan_res == NULL)
1275                 return -1;
1276         wpa_scan_results_free(scan_res);
1277
1278         return 0;
1279 }