1 Add a scan result cache to improve roaming speed if the driver gave us a background scan before losing the connection.
3 --- a/wpa_supplicant/config.h
4 +++ b/wpa_supplicant/config.h
9 + * scan_cache - controls the time in seconds after the last scan results
10 + * before a new scan may be initiated
15 * ctrl_interface - Parameters for the control interface
17 * If this is specified, %wpa_supplicant will open a control interface
18 --- a/wpa_supplicant/config_file.c
19 +++ b/wpa_supplicant/config_file.c
24 +static int wpa_config_process_scan_cache(struct wpa_config *config, char *pos)
26 + config->scan_cache = atoi(pos);
27 + wpa_printf(MSG_DEBUG, "scan_cache=%d", config->scan_cache);
32 static int wpa_config_process_fast_reauth(struct wpa_config *config, char *pos)
35 if (os_strncmp(pos, "ap_scan=", 8) == 0)
36 return wpa_config_process_ap_scan(config, pos + 8);
38 + if (os_strncmp(pos, "scan_cache=", 11) == 0)
39 + return wpa_config_process_scan_cache(config, pos + 11);
41 if (os_strncmp(pos, "fast_reauth=", 12) == 0)
42 return wpa_config_process_fast_reauth(config, pos + 12);
45 fprintf(f, "eapol_version=%d\n", config->eapol_version);
46 if (config->ap_scan != DEFAULT_AP_SCAN)
47 fprintf(f, "ap_scan=%d\n", config->ap_scan);
48 + if (config->scan_cache != 0)
49 + fprintf(f, "scan_cache=%d\n", config->scan_cache);
50 if (config->fast_reauth != DEFAULT_FAST_REAUTH)
51 fprintf(f, "fast_reauth=%d\n", config->fast_reauth);
52 #ifdef EAP_TLS_OPENSSL
53 --- a/wpa_supplicant/events.c
54 +++ b/wpa_supplicant/events.c
56 if (wpa_s->conf->ap_scan == 2 || wpa_s->disconnected)
59 + if (wpa_s->wpa_state > WPA_ASSOCIATED)
62 while (selected == NULL) {
63 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
64 selected = wpa_supplicant_select_bss(
66 wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
68 wpa_blacklist_clear(wpa_s);
69 + memset(&wpa_s->last_scan_results, 0, sizeof(wpa_s->last_scan_results));
70 } else if (selected == NULL) {
74 rsn_preauth_scan_results(wpa_s->wpa, wpa_s->scan_res);
76 wpa_printf(MSG_DEBUG, "No suitable AP found.");
83 + os_get_time(&wpa_s->last_scan_results);
89 if (wpa_s->wpa_state >= WPA_ASSOCIATED)
90 wpa_supplicant_req_scan(wpa_s, 0, 100000);
91 + else if (wpa_s->wpa_state == WPA_ASSOCIATING)
92 + wpa_supplicant_req_auth_timeout(wpa_s, 0, 100000);
95 if (os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
96 bssid = wpa_s->pending_bssid;
97 --- a/wpa_supplicant/wpa_supplicant_i.h
98 +++ b/wpa_supplicant/wpa_supplicant_i.h
100 struct wpa_client_mlme mlme;
102 int driver_4way_handshake;
103 + struct os_time last_scan_results;
105 int pending_mic_error_report;
106 int pending_mic_error_pairwise;
110 void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec);
111 +int wpa_supplicant_may_scan(struct wpa_supplicant *wpa_s);
112 void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s);
115 --- a/wpa_supplicant/scan.c
116 +++ b/wpa_supplicant/scan.c
118 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
121 +int wpa_supplicant_may_scan(struct wpa_supplicant *wpa_s)
123 + struct os_time time;
125 + if (wpa_s->conf->scan_cache > 0) {
126 + os_get_time(&time);
127 + time.sec -= wpa_s->conf->scan_cache;
128 + if (os_time_before(&time, &wpa_s->last_scan_results))
134 static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
138 wpa_s->prev_scan_ssid = BROADCAST_SSID_SCAN;
140 - if (wpa_s->scan_res_tried == 0 && wpa_s->conf->ap_scan == 1 &&
141 - !wpa_s->use_client_mlme) {
142 + if (!wpa_supplicant_may_scan(wpa_s) ||
143 + (wpa_s->scan_res_tried == 0 && wpa_s->conf->ap_scan == 1 &&
144 + !wpa_s->use_client_mlme)) {
145 wpa_s->scan_res_tried++;
146 wpa_printf(MSG_DEBUG, "Trying to get current scan results "
147 "first without requesting a new scan to speed up "
148 --- a/wpa_supplicant/wpa_supplicant.c
149 +++ b/wpa_supplicant/wpa_supplicant.c
150 @@ -1441,6 +1441,9 @@
152 struct wpa_supplicant *wpa_s = ctx;
154 + if (wpa_s->wpa_state < WPA_ASSOCIATING)
157 wpa_printf(MSG_DEBUG, "RX EAPOL from " MACSTR, MAC2STR(src_addr));
158 wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len);