1f8cb4597ec4af877461bf997b52596ff5a2aa98
[openwrt/svn-archive/archive.git] / package / wpa_supplicant / patches / 130-scanning.patch
1 Add a scan result cache to improve roaming speed if the driver gave us a background scan before losing the connection.
2
3 --- a/wpa_supplicant/config.h
4 +++ b/wpa_supplicant/config.h
5 @@ -97,6 +97,12 @@ struct wpa_config {
6 int ap_scan;
7
8 /**
9 + * scan_cache - controls the time in seconds after the last scan results
10 + * before a new scan may be initiated
11 + */
12 + int scan_cache;
13 +
14 + /**
15 * ctrl_interface - Parameters for the control interface
16 *
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
20 @@ -306,6 +306,13 @@ static int wpa_config_parse_int(const st
21 return 0;
22 }
23
24 +static int wpa_config_process_scan_cache(struct wpa_config *config, char *pos)
25 +{
26 + config->scan_cache = atoi(pos);
27 + wpa_printf(MSG_DEBUG, "scan_cache=%d", config->scan_cache);
28 + return 0;
29 +}
30 +
31
32 static int wpa_config_parse_str(const struct global_parse_data *data,
33 struct wpa_config *config, int line,
34 @@ -433,6 +440,7 @@ static const struct global_parse_data gl
35 #endif /* CONFIG_CTRL_IFACE */
36 { INT_RANGE(eapol_version, 1, 2) },
37 { INT(ap_scan) },
38 + { INT(scan_cache) },
39 { INT(fast_reauth) },
40 #ifdef EAP_TLS_OPENSSL
41 { STR(opensc_engine_path) },
42 @@ -834,6 +842,8 @@ static void wpa_config_write_global(FILE
43 fprintf(f, "eapol_version=%d\n", config->eapol_version);
44 if (config->ap_scan != DEFAULT_AP_SCAN)
45 fprintf(f, "ap_scan=%d\n", config->ap_scan);
46 + if (config->scan_cache != 0)
47 + fprintf(f, "scan_cache=%d\n", config->scan_cache);
48 if (config->fast_reauth != DEFAULT_FAST_REAUTH)
49 fprintf(f, "fast_reauth=%d\n", config->fast_reauth);
50 #ifdef EAP_TLS_OPENSSL
51 --- a/wpa_supplicant/events.c
52 +++ b/wpa_supplicant/events.c
53 @@ -633,6 +633,9 @@ static void wpa_supplicant_event_scan_re
54 wpa_s->disconnected)
55 return;
56
57 + if (wpa_s->wpa_state > WPA_ASSOCIATED)
58 + goto done;
59 +
60 while (selected == NULL) {
61 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
62 selected = wpa_supplicant_select_bss(
63 @@ -645,6 +648,7 @@ static void wpa_supplicant_event_scan_re
64 wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
65 "and try again");
66 wpa_blacklist_clear(wpa_s);
67 + memset(&wpa_s->last_scan_results, 0, sizeof(wpa_s->last_scan_results));
68 } else if (selected == NULL) {
69 break;
70 }
71 @@ -679,10 +683,12 @@ static void wpa_supplicant_event_scan_re
72 rsn_preauth_scan_results(wpa_s->wpa, wpa_s->scan_res);
73 } else {
74 wpa_printf(MSG_DEBUG, "No suitable AP found.");
75 - timeout = 5;
76 + timeout = 0;
77 goto req_scan;
78 }
79
80 +done:
81 + os_get_time(&wpa_s->last_scan_results);
82 return;
83
84 req_scan:
85 @@ -886,6 +892,9 @@ static void wpa_supplicant_event_disasso
86 }
87 if (wpa_s->wpa_state >= WPA_ASSOCIATED)
88 wpa_supplicant_req_scan(wpa_s, 0, 100000);
89 + else if (wpa_s->wpa_state == WPA_ASSOCIATING)
90 + wpa_supplicant_req_auth_timeout(wpa_s, 0, 100000);
91 +
92 bssid = wpa_s->bssid;
93 if (is_zero_ether_addr(bssid))
94 bssid = wpa_s->pending_bssid;
95 --- a/wpa_supplicant/wpa_supplicant_i.h
96 +++ b/wpa_supplicant/wpa_supplicant_i.h
97 @@ -349,6 +349,7 @@ struct wpa_supplicant {
98 struct wpa_client_mlme mlme;
99 int use_client_mlme;
100 int driver_4way_handshake;
101 + struct os_time last_scan_results;
102
103 int pending_mic_error_report;
104 int pending_mic_error_pairwise;
105 @@ -402,6 +403,7 @@ int wpa_supplicant_scard_init(struct wpa
106
107 /* scan.c */
108 void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec);
109 +int wpa_supplicant_may_scan(struct wpa_supplicant *wpa_s);
110 void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s);
111
112 /* events.c */
113 --- a/wpa_supplicant/scan.c
114 +++ b/wpa_supplicant/scan.c
115 @@ -40,6 +40,18 @@ static void wpa_supplicant_gen_assoc_eve
116 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
117 }
118
119 +int wpa_supplicant_may_scan(struct wpa_supplicant *wpa_s)
120 +{
121 + struct os_time time;
122 +
123 + if (wpa_s->conf->scan_cache > 0) {
124 + os_get_time(&time);
125 + time.sec -= wpa_s->conf->scan_cache;
126 + if (os_time_before(&time, &wpa_s->last_scan_results))
127 + return 0;
128 + }
129 + return 1;
130 +}
131
132 #ifdef CONFIG_WPS
133 static int wpas_wps_in_use(struct wpa_config *conf,
134 @@ -183,8 +195,9 @@ static void wpa_supplicant_scan(void *el
135 wps = wpas_wps_in_use(wpa_s->conf, &req_type);
136 #endif /* CONFIG_WPS */
137
138 - if (wpa_s->scan_res_tried == 0 && wpa_s->conf->ap_scan == 1 &&
139 - !wpa_s->use_client_mlme && wps != 2) {
140 + if (!wpa_supplicant_may_scan(wpa_s) ||
141 + (wpa_s->scan_res_tried == 0 && wpa_s->conf->ap_scan == 1 &&
142 + !wpa_s->use_client_mlme && wps != 2)) {
143 wpa_s->scan_res_tried++;
144 wpa_s->scan_req = scan_req;
145 wpa_printf(MSG_DEBUG, "Trying to get current scan results "
146 --- a/wpa_supplicant/wpa_supplicant.c
147 +++ b/wpa_supplicant/wpa_supplicant.c
148 @@ -1491,6 +1491,9 @@ void wpa_supplicant_rx_eapol(void *ctx,
149 {
150 struct wpa_supplicant *wpa_s = ctx;
151
152 + if (wpa_s->wpa_state < WPA_ASSOCIATING)
153 + return;
154 +
155 wpa_printf(MSG_DEBUG, "RX EAPOL from " MACSTR, MAC2STR(src_addr));
156 wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len);
157