]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant - Driver event processing | |
98cd3d1c | 3 | * Copyright (c) 2003-2015, 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 | ||
9 | #include "includes.h" | |
10 | ||
11 | #include "common.h" | |
12 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 13 | #include "rsn_supp/wpa.h" |
6fc6879b | 14 | #include "eloop.h" |
6fc6879b JM |
15 | #include "config.h" |
16 | #include "l2_packet/l2_packet.h" | |
17 | #include "wpa_supplicant_i.h" | |
2d5b792d | 18 | #include "driver_i.h" |
6fc6879b | 19 | #include "pcsc_funcs.h" |
3acb5005 JM |
20 | #include "rsn_supp/preauth.h" |
21 | #include "rsn_supp/pmksa_cache.h" | |
90973fb2 | 22 | #include "common/wpa_ctrl.h" |
6fc6879b | 23 | #include "eap_peer/eap.h" |
1d041bec | 24 | #include "ap/hostapd.h" |
93b7ddd0 | 25 | #include "p2p/p2p.h" |
9fbfd1b0 | 26 | #include "fst/fst.h" |
75cad1a0 | 27 | #include "wnm_sta.h" |
8bac466b | 28 | #include "notify.h" |
90973fb2 | 29 | #include "common/ieee802_11_defs.h" |
54f489be | 30 | #include "common/ieee802_11_common.h" |
bbb921da | 31 | #include "crypto/random.h" |
6fc6879b JM |
32 | #include "blacklist.h" |
33 | #include "wpas_glue.h" | |
351f09a2 | 34 | #include "wps_supplicant.h" |
11ef8d35 | 35 | #include "ibss_rsn.h" |
c2a04078 | 36 | #include "sme.h" |
04ea7b79 | 37 | #include "gas_query.h" |
9bae1be0 | 38 | #include "p2p_supplicant.h" |
60b94c98 | 39 | #include "bgscan.h" |
7c865c68 | 40 | #include "autoscan.h" |
f8b1f695 | 41 | #include "ap.h" |
6fa81a3b | 42 | #include "bss.h" |
9ba9fa07 | 43 | #include "scan.h" |
24f6497c | 44 | #include "offchannel.h" |
4d5bda5f | 45 | #include "interworking.h" |
8319e312 | 46 | #include "mesh.h" |
5f92659d | 47 | #include "mesh_mpm.h" |
a0413b17 | 48 | #include "wmm_ac.h" |
6fc6879b JM |
49 | |
50 | ||
5d5c4ee5 | 51 | #ifndef CONFIG_NO_SCAN_PROCESSING |
06b7f58d | 52 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
cc4952ad | 53 | int new_scan, int own_request); |
5d5c4ee5 | 54 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
d6bbcce4 JM |
55 | |
56 | ||
00e5e3d5 JM |
57 | static int wpas_temp_disabled(struct wpa_supplicant *wpa_s, |
58 | struct wpa_ssid *ssid) | |
59 | { | |
4e1eae1d | 60 | struct os_reltime now; |
00e5e3d5 JM |
61 | |
62 | if (ssid == NULL || ssid->disabled_until.sec == 0) | |
63 | return 0; | |
64 | ||
4e1eae1d | 65 | os_get_reltime(&now); |
00e5e3d5 JM |
66 | if (ssid->disabled_until.sec > now.sec) |
67 | return ssid->disabled_until.sec - now.sec; | |
68 | ||
69 | wpas_clear_temp_disabled(wpa_s, ssid, 0); | |
70 | ||
71 | return 0; | |
72 | } | |
73 | ||
74 | ||
eb926f12 | 75 | #ifndef CONFIG_NO_SCAN_PROCESSING |
9bd566a3 AS |
76 | /** |
77 | * wpas_reenabled_network_time - Time until first network is re-enabled | |
78 | * @wpa_s: Pointer to wpa_supplicant data | |
79 | * Returns: If all enabled networks are temporarily disabled, returns the time | |
80 | * (in sec) until the first network is re-enabled. Otherwise returns 0. | |
81 | * | |
82 | * This function is used in case all enabled networks are temporarily disabled, | |
83 | * in which case it returns the time (in sec) that the first network will be | |
84 | * re-enabled. The function assumes that at least one network is enabled. | |
85 | */ | |
86 | static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s) | |
87 | { | |
88 | struct wpa_ssid *ssid; | |
89 | int disabled_for, res = 0; | |
90 | ||
91 | #ifdef CONFIG_INTERWORKING | |
92 | if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking && | |
93 | wpa_s->conf->cred) | |
94 | return 0; | |
95 | #endif /* CONFIG_INTERWORKING */ | |
96 | ||
97 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { | |
98 | if (ssid->disabled) | |
99 | continue; | |
100 | ||
101 | disabled_for = wpas_temp_disabled(wpa_s, ssid); | |
102 | if (!disabled_for) | |
103 | return 0; | |
104 | ||
105 | if (!res || disabled_for < res) | |
106 | res = disabled_for; | |
107 | } | |
108 | ||
109 | return res; | |
110 | } | |
eb926f12 | 111 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
9bd566a3 AS |
112 | |
113 | ||
114 | void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx) | |
115 | { | |
116 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
117 | ||
118 | if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING) | |
119 | return; | |
120 | ||
121 | wpa_dbg(wpa_s, MSG_DEBUG, | |
122 | "Try to associate due to network getting re-enabled"); | |
123 | if (wpa_supplicant_fast_associate(wpa_s) != 1) { | |
124 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
125 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
126 | } | |
127 | } | |
128 | ||
129 | ||
5cd47405 JM |
130 | static struct wpa_bss * wpa_supplicant_get_new_bss( |
131 | struct wpa_supplicant *wpa_s, const u8 *bssid) | |
132 | { | |
133 | struct wpa_bss *bss = NULL; | |
134 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
135 | ||
136 | if (ssid->ssid_len > 0) | |
137 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | |
138 | if (!bss) | |
139 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
140 | ||
141 | return bss; | |
142 | } | |
143 | ||
144 | ||
068e3877 JM |
145 | static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s) |
146 | { | |
147 | struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid); | |
148 | ||
149 | if (!bss) { | |
150 | wpa_supplicant_update_scan_results(wpa_s); | |
151 | ||
152 | /* Get the BSS from the new scan results */ | |
153 | bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid); | |
154 | } | |
155 | ||
156 | if (bss) | |
157 | wpa_s->current_bss = bss; | |
158 | } | |
159 | ||
160 | ||
6fc6879b JM |
161 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) |
162 | { | |
8bac466b | 163 | struct wpa_ssid *ssid, *old_ssid; |
eaa8eefe | 164 | u8 drv_ssid[SSID_MAX_LEN]; |
c41d0840 | 165 | size_t drv_ssid_len; |
00e5e3d5 | 166 | int res; |
6fc6879b | 167 | |
068e3877 JM |
168 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) { |
169 | wpa_supplicant_update_current_bss(wpa_s); | |
c41d0840 KV |
170 | |
171 | if (wpa_s->current_ssid->ssid_len == 0) | |
172 | return 0; /* current profile still in use */ | |
173 | res = wpa_drv_get_ssid(wpa_s, drv_ssid); | |
174 | if (res < 0) { | |
175 | wpa_msg(wpa_s, MSG_INFO, | |
176 | "Failed to read SSID from driver"); | |
177 | return 0; /* try to use current profile */ | |
178 | } | |
179 | drv_ssid_len = res; | |
180 | ||
181 | if (drv_ssid_len == wpa_s->current_ssid->ssid_len && | |
182 | os_memcmp(drv_ssid, wpa_s->current_ssid->ssid, | |
183 | drv_ssid_len) == 0) | |
184 | return 0; /* current profile still in use */ | |
185 | ||
186 | wpa_msg(wpa_s, MSG_DEBUG, | |
187 | "Driver-initiated BSS selection changed the SSID to %s", | |
188 | wpa_ssid_txt(drv_ssid, drv_ssid_len)); | |
189 | /* continue selecting a new network profile */ | |
068e3877 | 190 | } |
6fc6879b | 191 | |
f049052b BG |
192 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " |
193 | "information"); | |
6fc6879b JM |
194 | ssid = wpa_supplicant_get_ssid(wpa_s); |
195 | if (ssid == NULL) { | |
f049052b BG |
196 | wpa_msg(wpa_s, MSG_INFO, |
197 | "No network configuration found for the current AP"); | |
6fc6879b JM |
198 | return -1; |
199 | } | |
200 | ||
349493bd | 201 | if (wpas_network_disabled(wpa_s, ssid)) { |
f049052b | 202 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); |
6fc6879b JM |
203 | return -1; |
204 | } | |
205 | ||
6407f413 JM |
206 | if (disallowed_bssid(wpa_s, wpa_s->bssid) || |
207 | disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) { | |
208 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed"); | |
209 | return -1; | |
210 | } | |
211 | ||
00e5e3d5 JM |
212 | res = wpas_temp_disabled(wpa_s, ssid); |
213 | if (res > 0) { | |
214 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily " | |
215 | "disabled for %d second(s)", res); | |
216 | return -1; | |
217 | } | |
218 | ||
f049052b BG |
219 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " |
220 | "current AP"); | |
0bf927a0 | 221 | if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
6fc6879b JM |
222 | u8 wpa_ie[80]; |
223 | size_t wpa_ie_len = sizeof(wpa_ie); | |
cbf61176 JM |
224 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, |
225 | wpa_ie, &wpa_ie_len) < 0) | |
226 | wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites"); | |
6fc6879b JM |
227 | } else { |
228 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
229 | } | |
230 | ||
231 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) | |
232 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
8bac466b | 233 | old_ssid = wpa_s->current_ssid; |
6fc6879b | 234 | wpa_s->current_ssid = ssid; |
5cd47405 | 235 | |
068e3877 | 236 | wpa_supplicant_update_current_bss(wpa_s); |
5cd47405 | 237 | |
6fc6879b JM |
238 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
239 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
240 | if (old_ssid != wpa_s->current_ssid) |
241 | wpas_notify_network_changed(wpa_s); | |
6fc6879b JM |
242 | |
243 | return 0; | |
244 | } | |
245 | ||
246 | ||
01a17491 | 247 | void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx) |
6fc6879b JM |
248 | { |
249 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
250 | ||
251 | if (wpa_s->countermeasures) { | |
252 | wpa_s->countermeasures = 0; | |
253 | wpa_drv_set_countermeasures(wpa_s, 0); | |
254 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); | |
f1609f11 IP |
255 | |
256 | /* | |
257 | * It is possible that the device is sched scanning, which means | |
258 | * that a connection attempt will be done only when we receive | |
259 | * scan results. However, in this case, it would be preferable | |
260 | * to scan and connect immediately, so cancel the sched_scan and | |
261 | * issue a regular scan flow. | |
262 | */ | |
263 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
6fc6879b JM |
264 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
265 | } | |
266 | } | |
267 | ||
268 | ||
269 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) | |
270 | { | |
8bac466b JM |
271 | int bssid_changed; |
272 | ||
b6668734 JM |
273 | wnm_bss_keep_alive_deinit(wpa_s); |
274 | ||
78177a00 JM |
275 | #ifdef CONFIG_IBSS_RSN |
276 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
277 | wpa_s->ibss_rsn = NULL; | |
278 | #endif /* CONFIG_IBSS_RSN */ | |
279 | ||
ca62e114 JM |
280 | #ifdef CONFIG_AP |
281 | wpa_supplicant_ap_deinit(wpa_s); | |
282 | #endif /* CONFIG_AP */ | |
283 | ||
8401a6b0 JM |
284 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
285 | return; | |
286 | ||
6fc6879b | 287 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
8bac466b | 288 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
6fc6879b JM |
289 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
290 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
4e70bbf1 | 291 | sme_clear_on_disassoc(wpa_s); |
be8be671 | 292 | wpa_s->current_bss = NULL; |
3c85f144 | 293 | wpa_s->assoc_freq = 0; |
8fd0f0f3 | 294 | |
8bac466b JM |
295 | if (bssid_changed) |
296 | wpas_notify_bssid_changed(wpa_s); | |
297 | ||
6fc6879b JM |
298 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
299 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
56586197 | 300 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) |
6fc6879b JM |
301 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
302 | wpa_s->ap_ies_from_associnfo = 0; | |
0d30cc24 | 303 | wpa_s->current_ssid = NULL; |
25a8f9e3 | 304 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
0d30cc24 | 305 | wpa_s->key_mgmt = 0; |
b361d580 AK |
306 | |
307 | wpas_rrm_reset(wpa_s); | |
03ed0a52 | 308 | wpa_s->wnmsleep_used = 0; |
6fc6879b JM |
309 | } |
310 | ||
311 | ||
312 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) | |
313 | { | |
314 | struct wpa_ie_data ie; | |
315 | int pmksa_set = -1; | |
316 | size_t i; | |
317 | ||
318 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || | |
319 | ie.pmkid == NULL) | |
320 | return; | |
321 | ||
322 | for (i = 0; i < ie.num_pmkid; i++) { | |
323 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, | |
324 | ie.pmkid + i * PMKID_LEN, | |
325 | NULL, NULL, 0); | |
326 | if (pmksa_set == 0) { | |
ba422613 | 327 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
6fc6879b JM |
328 | break; |
329 | } | |
330 | } | |
331 | ||
f049052b BG |
332 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " |
333 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); | |
6fc6879b JM |
334 | } |
335 | ||
336 | ||
337 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, | |
338 | union wpa_event_data *data) | |
339 | { | |
340 | if (data == NULL) { | |
f049052b BG |
341 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " |
342 | "event"); | |
6fc6879b JM |
343 | return; |
344 | } | |
f049052b BG |
345 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR |
346 | " index=%d preauth=%d", | |
347 | MAC2STR(data->pmkid_candidate.bssid), | |
348 | data->pmkid_candidate.index, | |
349 | data->pmkid_candidate.preauth); | |
6fc6879b JM |
350 | |
351 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, | |
352 | data->pmkid_candidate.index, | |
353 | data->pmkid_candidate.preauth); | |
354 | } | |
355 | ||
356 | ||
357 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) | |
358 | { | |
359 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
360 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
361 | return 0; | |
362 | ||
363 | #ifdef IEEE8021X_EAPOL | |
364 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | |
365 | wpa_s->current_ssid && | |
366 | !(wpa_s->current_ssid->eapol_flags & | |
367 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
368 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { | |
369 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either | |
370 | * plaintext or static WEP keys). */ | |
371 | return 0; | |
372 | } | |
373 | #endif /* IEEE8021X_EAPOL */ | |
374 | ||
375 | return 1; | |
376 | } | |
377 | ||
378 | ||
379 | /** | |
380 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC | |
381 | * @wpa_s: pointer to wpa_supplicant data | |
382 | * @ssid: Configuration data for the network | |
383 | * Returns: 0 on success, -1 on failure | |
384 | * | |
385 | * This function is called when starting authentication with a network that is | |
386 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). | |
387 | */ | |
388 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, | |
389 | struct wpa_ssid *ssid) | |
390 | { | |
391 | #ifdef IEEE8021X_EAPOL | |
b832d34c | 392 | #ifdef PCSC_FUNCS |
eb324600 | 393 | int aka = 0, sim = 0; |
6fc6879b | 394 | |
62f736dd JT |
395 | if ((ssid != NULL && ssid->eap.pcsc == NULL) || |
396 | wpa_s->scard != NULL || wpa_s->conf->external_sim) | |
6fc6879b JM |
397 | return 0; |
398 | ||
62f736dd | 399 | if (ssid == NULL || ssid->eap.eap_methods == NULL) { |
6fc6879b JM |
400 | sim = 1; |
401 | aka = 1; | |
402 | } else { | |
403 | struct eap_method_type *eap = ssid->eap.eap_methods; | |
404 | while (eap->vendor != EAP_VENDOR_IETF || | |
405 | eap->method != EAP_TYPE_NONE) { | |
406 | if (eap->vendor == EAP_VENDOR_IETF) { | |
407 | if (eap->method == EAP_TYPE_SIM) | |
408 | sim = 1; | |
3d332fe7 JM |
409 | else if (eap->method == EAP_TYPE_AKA || |
410 | eap->method == EAP_TYPE_AKA_PRIME) | |
6fc6879b JM |
411 | aka = 1; |
412 | } | |
413 | eap++; | |
414 | } | |
415 | } | |
416 | ||
417 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) | |
418 | sim = 0; | |
3d332fe7 JM |
419 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL && |
420 | eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) == | |
421 | NULL) | |
6fc6879b JM |
422 | aka = 0; |
423 | ||
424 | if (!sim && !aka) { | |
f049052b BG |
425 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " |
426 | "use SIM, but neither EAP-SIM nor EAP-AKA are " | |
427 | "enabled"); | |
6fc6879b JM |
428 | return 0; |
429 | } | |
430 | ||
f049052b BG |
431 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " |
432 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); | |
eb324600 | 433 | |
5a620604 | 434 | wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader); |
6fc6879b | 435 | if (wpa_s->scard == NULL) { |
f049052b BG |
436 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " |
437 | "(pcsc-lite)"); | |
6fc6879b JM |
438 | return -1; |
439 | } | |
440 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
441 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
b832d34c | 442 | #endif /* PCSC_FUNCS */ |
6fc6879b JM |
443 | #endif /* IEEE8021X_EAPOL */ |
444 | ||
445 | return 0; | |
446 | } | |
447 | ||
448 | ||
449 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
86bd1410 JM |
450 | |
451 | static int has_wep_key(struct wpa_ssid *ssid) | |
452 | { | |
453 | int i; | |
454 | ||
455 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
456 | if (ssid->wep_key_len[i]) | |
457 | return 1; | |
458 | } | |
459 | ||
460 | return 0; | |
461 | } | |
462 | ||
463 | ||
620c7837 | 464 | static int wpa_supplicant_match_privacy(struct wpa_bss *bss, |
6fc6879b JM |
465 | struct wpa_ssid *ssid) |
466 | { | |
86bd1410 | 467 | int privacy = 0; |
6fc6879b JM |
468 | |
469 | if (ssid->mixed_cell) | |
470 | return 1; | |
471 | ||
0632542b AT |
472 | #ifdef CONFIG_WPS |
473 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) | |
474 | return 1; | |
475 | #endif /* CONFIG_WPS */ | |
476 | ||
86bd1410 JM |
477 | if (has_wep_key(ssid)) |
478 | privacy = 1; | |
479 | ||
6fc6879b JM |
480 | #ifdef IEEE8021X_EAPOL |
481 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
482 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
483 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) | |
484 | privacy = 1; | |
485 | #endif /* IEEE8021X_EAPOL */ | |
486 | ||
29fbc522 JM |
487 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) |
488 | privacy = 1; | |
489 | ||
df0f01d9 JM |
490 | if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) |
491 | privacy = 1; | |
492 | ||
6fc6879b JM |
493 | if (bss->caps & IEEE80211_CAP_PRIVACY) |
494 | return privacy; | |
495 | return !privacy; | |
496 | } | |
497 | ||
498 | ||
a6099152 JM |
499 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
500 | struct wpa_ssid *ssid, | |
620c7837 | 501 | struct wpa_bss *bss) |
6fc6879b JM |
502 | { |
503 | struct wpa_ie_data ie; | |
504 | int proto_match = 0; | |
505 | const u8 *rsn_ie, *wpa_ie; | |
351f09a2 | 506 | int ret; |
43882f1e | 507 | int wep_ok; |
6fc6879b | 508 | |
a6099152 | 509 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
351f09a2 JM |
510 | if (ret >= 0) |
511 | return ret; | |
ad08c363 | 512 | |
43882f1e JM |
513 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ |
514 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && | |
515 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
516 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || | |
517 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); | |
518 | ||
620c7837 | 519 | rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6fc6879b JM |
520 | while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { |
521 | proto_match++; | |
522 | ||
523 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { | |
f049052b BG |
524 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse " |
525 | "failed"); | |
6fc6879b JM |
526 | break; |
527 | } | |
43882f1e JM |
528 | |
529 | if (wep_ok && | |
530 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
531 | { | |
f049052b BG |
532 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
533 | "in RSN IE"); | |
43882f1e JM |
534 | return 1; |
535 | } | |
536 | ||
6fc6879b | 537 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
538 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto " |
539 | "mismatch"); | |
6fc6879b JM |
540 | break; |
541 | } | |
542 | ||
543 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
544 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK " |
545 | "cipher mismatch"); | |
6fc6879b JM |
546 | break; |
547 | } | |
548 | ||
549 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
550 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK " |
551 | "cipher mismatch"); | |
6fc6879b JM |
552 | break; |
553 | } | |
554 | ||
555 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
556 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt " |
557 | "mismatch"); | |
6fc6879b JM |
558 | break; |
559 | } | |
560 | ||
561 | #ifdef CONFIG_IEEE80211W | |
0b60b0aa | 562 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
3f56a2b7 | 563 | wpas_get_ssid_pmf(wpa_s, ssid) == |
62d49803 | 564 | MGMT_FRAME_PROTECTION_REQUIRED) { |
f049052b BG |
565 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt " |
566 | "frame protection"); | |
6fc6879b JM |
567 | break; |
568 | } | |
569 | #endif /* CONFIG_IEEE80211W */ | |
fa464267 JM |
570 | if ((ie.capabilities & WPA_CAPABILITY_MFPR) && |
571 | wpas_get_ssid_pmf(wpa_s, ssid) == | |
572 | NO_MGMT_FRAME_PROTECTION) { | |
573 | wpa_dbg(wpa_s, MSG_DEBUG, | |
574 | " skip RSN IE - no mgmt frame protection enabled but AP requires it"); | |
575 | break; | |
576 | } | |
940491ce JM |
577 | #ifdef CONFIG_MBO |
578 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && | |
579 | wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) && | |
580 | wpas_get_ssid_pmf(wpa_s, ssid) != | |
581 | NO_MGMT_FRAME_PROTECTION) { | |
582 | wpa_dbg(wpa_s, MSG_DEBUG, | |
583 | " skip RSN IE - no mgmt frame protection enabled on MBO AP"); | |
584 | break; | |
585 | } | |
586 | #endif /* CONFIG_MBO */ | |
6fc6879b | 587 | |
f049052b | 588 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE"); |
6fc6879b JM |
589 | return 1; |
590 | } | |
591 | ||
620c7837 | 592 | wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
593 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { |
594 | proto_match++; | |
595 | ||
596 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { | |
f049052b BG |
597 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse " |
598 | "failed"); | |
6fc6879b JM |
599 | break; |
600 | } | |
43882f1e JM |
601 | |
602 | if (wep_ok && | |
603 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
604 | { | |
f049052b BG |
605 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
606 | "in WPA IE"); | |
43882f1e JM |
607 | return 1; |
608 | } | |
609 | ||
6fc6879b | 610 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
611 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto " |
612 | "mismatch"); | |
6fc6879b JM |
613 | break; |
614 | } | |
615 | ||
616 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
617 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK " |
618 | "cipher mismatch"); | |
6fc6879b JM |
619 | break; |
620 | } | |
621 | ||
622 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
623 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK " |
624 | "cipher mismatch"); | |
6fc6879b JM |
625 | break; |
626 | } | |
627 | ||
628 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
629 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt " |
630 | "mismatch"); | |
6fc6879b JM |
631 | break; |
632 | } | |
633 | ||
f049052b | 634 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE"); |
6fc6879b JM |
635 | return 1; |
636 | } | |
637 | ||
a3f7e518 JM |
638 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie && |
639 | !rsn_ie) { | |
640 | wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X"); | |
641 | return 1; | |
642 | } | |
643 | ||
cc5e390d | 644 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && |
df83fb7d | 645 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { |
f049052b | 646 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match"); |
cc5e390d JM |
647 | return 0; |
648 | } | |
6fc6879b | 649 | |
df0f01d9 JM |
650 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && |
651 | wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) { | |
652 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN"); | |
653 | return 1; | |
654 | } | |
655 | ||
c2f1fe41 JM |
656 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
657 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); | |
658 | return 1; | |
659 | } | |
660 | ||
661 | wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with " | |
662 | "WPA/WPA2"); | |
663 | ||
664 | return 0; | |
6fc6879b JM |
665 | } |
666 | ||
667 | ||
b766a9a2 JM |
668 | static int freq_allowed(int *freqs, int freq) |
669 | { | |
670 | int i; | |
671 | ||
672 | if (freqs == NULL) | |
673 | return 1; | |
674 | ||
675 | for (i = 0; freqs[i]; i++) | |
676 | if (freqs[i] == freq) | |
677 | return 1; | |
678 | return 0; | |
679 | } | |
680 | ||
681 | ||
620c7837 | 682 | static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
e1e8cae3 CL |
683 | { |
684 | const struct hostapd_hw_modes *mode = NULL, *modes; | |
685 | const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; | |
686 | const u8 *rate_ie; | |
687 | int i, j, k; | |
688 | ||
a6d94e1b JM |
689 | if (bss->freq == 0) |
690 | return 1; /* Cannot do matching without knowing band */ | |
691 | ||
e1e8cae3 CL |
692 | modes = wpa_s->hw.modes; |
693 | if (modes == NULL) { | |
694 | /* | |
695 | * The driver does not provide any additional information | |
696 | * about the utilized hardware, so allow the connection attempt | |
697 | * to continue. | |
698 | */ | |
699 | return 1; | |
700 | } | |
701 | ||
702 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
703 | for (j = 0; j < modes[i].num_channels; j++) { | |
704 | int freq = modes[i].channels[j].freq; | |
705 | if (freq == bss->freq) { | |
706 | if (mode && | |
707 | mode->mode == HOSTAPD_MODE_IEEE80211G) | |
708 | break; /* do not allow 802.11b replace | |
709 | * 802.11g */ | |
710 | mode = &modes[i]; | |
711 | break; | |
712 | } | |
713 | } | |
714 | } | |
715 | ||
716 | if (mode == NULL) | |
717 | return 0; | |
718 | ||
719 | for (i = 0; i < (int) sizeof(scan_ie); i++) { | |
620c7837 | 720 | rate_ie = wpa_bss_get_ie(bss, scan_ie[i]); |
e1e8cae3 CL |
721 | if (rate_ie == NULL) |
722 | continue; | |
723 | ||
724 | for (j = 2; j < rate_ie[1] + 2; j++) { | |
725 | int flagged = !!(rate_ie[j] & 0x80); | |
726 | int r = (rate_ie[j] & 0x7f) * 5; | |
727 | ||
728 | /* | |
729 | * IEEE Std 802.11n-2009 7.3.2.2: | |
730 | * The new BSS Membership selector value is encoded | |
731 | * like a legacy basic rate, but it is not a rate and | |
732 | * only indicates if the BSS members are required to | |
733 | * support the mandatory features of Clause 20 [HT PHY] | |
734 | * in order to join the BSS. | |
735 | */ | |
736 | if (flagged && ((rate_ie[j] & 0x7f) == | |
737 | BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { | |
738 | if (!ht_supported(mode)) { | |
739 | wpa_dbg(wpa_s, MSG_DEBUG, | |
740 | " hardware does not support " | |
741 | "HT PHY"); | |
742 | return 0; | |
743 | } | |
744 | continue; | |
745 | } | |
746 | ||
c8ebeda4 MK |
747 | /* There's also a VHT selector for 802.11ac */ |
748 | if (flagged && ((rate_ie[j] & 0x7f) == | |
749 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) { | |
750 | if (!vht_supported(mode)) { | |
751 | wpa_dbg(wpa_s, MSG_DEBUG, | |
752 | " hardware does not support " | |
753 | "VHT PHY"); | |
754 | return 0; | |
755 | } | |
756 | continue; | |
757 | } | |
758 | ||
e1e8cae3 CL |
759 | if (!flagged) |
760 | continue; | |
761 | ||
762 | /* check for legacy basic rates */ | |
763 | for (k = 0; k < mode->num_rates; k++) { | |
764 | if (mode->rates[k] == r) | |
765 | break; | |
766 | } | |
767 | if (k == mode->num_rates) { | |
768 | /* | |
769 | * IEEE Std 802.11-2007 7.3.2.2 demands that in | |
770 | * order to join a BSS all required rates | |
771 | * have to be supported by the hardware. | |
772 | */ | |
1d246a1d JM |
773 | wpa_dbg(wpa_s, MSG_DEBUG, |
774 | " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)", | |
775 | r / 10, r % 10, | |
776 | bss->freq, mode->mode, mode->num_rates); | |
e1e8cae3 CL |
777 | return 0; |
778 | } | |
779 | } | |
780 | } | |
781 | ||
782 | return 1; | |
783 | } | |
784 | ||
785 | ||
ff3ad3c5 VK |
786 | /* |
787 | * Test whether BSS is in an ESS. | |
788 | * This is done differently in DMG (60 GHz) and non-DMG bands | |
789 | */ | |
790 | static int bss_is_ess(struct wpa_bss *bss) | |
791 | { | |
792 | if (bss_is_dmg(bss)) { | |
793 | return (bss->caps & IEEE80211_CAP_DMG_MASK) == | |
794 | IEEE80211_CAP_DMG_AP; | |
795 | } | |
796 | ||
797 | return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == | |
798 | IEEE80211_CAP_ESS); | |
799 | } | |
800 | ||
801 | ||
79cd993a ST |
802 | static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask) |
803 | { | |
804 | size_t i; | |
805 | ||
806 | for (i = 0; i < ETH_ALEN; i++) { | |
807 | if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i])) | |
808 | return 0; | |
809 | } | |
810 | return 1; | |
811 | } | |
812 | ||
813 | ||
b83e4554 ST |
814 | static int addr_in_list(const u8 *addr, const u8 *list, size_t num) |
815 | { | |
816 | size_t i; | |
817 | ||
818 | for (i = 0; i < num; i++) { | |
79cd993a ST |
819 | const u8 *a = list + i * ETH_ALEN * 2; |
820 | const u8 *m = a + ETH_ALEN; | |
b83e4554 | 821 | |
79cd993a | 822 | if (match_mac_mask(a, addr, m)) |
b83e4554 ST |
823 | return 1; |
824 | } | |
825 | return 0; | |
826 | } | |
827 | ||
828 | ||
84d1c0fd AS |
829 | struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
830 | int i, struct wpa_bss *bss, | |
831 | struct wpa_ssid *group, | |
832 | int only_first_ssid) | |
6fc6879b | 833 | { |
620c7837 | 834 | u8 wpa_ie_len, rsn_ie_len; |
d8d940b7 | 835 | int wpa; |
6fc6879b JM |
836 | struct wpa_blacklist *e; |
837 | const u8 *ie; | |
d8d940b7 | 838 | struct wpa_ssid *ssid; |
df0f01d9 | 839 | int osen; |
cb06cf34 DS |
840 | #ifdef CONFIG_MBO |
841 | const u8 *assoc_disallow; | |
842 | #endif /* CONFIG_MBO */ | |
6fc6879b | 843 | |
620c7837 | 844 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
d8d940b7 | 845 | wpa_ie_len = ie ? ie[1] : 0; |
6fc6879b | 846 | |
620c7837 | 847 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
d8d940b7 | 848 | rsn_ie_len = ie ? ie[1] : 0; |
6fc6879b | 849 | |
df0f01d9 JM |
850 | ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
851 | osen = ie != NULL; | |
852 | ||
f049052b | 853 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' " |
dcc8bc82 | 854 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s", |
620c7837 | 855 | i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len), |
dcc8bc82 | 856 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq, |
b16696ff JM |
857 | wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "", |
858 | (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || | |
859 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ? | |
df0f01d9 JM |
860 | " p2p" : "", |
861 | osen ? " osen=1" : ""); | |
9cf32261 | 862 | |
d8d940b7 | 863 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
5471c343 JM |
864 | if (e) { |
865 | int limit = 1; | |
349493bd | 866 | if (wpa_supplicant_enabled_networks(wpa_s) == 1) { |
5471c343 JM |
867 | /* |
868 | * When only a single network is enabled, we can | |
869 | * trigger blacklisting on the first failure. This | |
870 | * should not be done with multiple enabled networks to | |
871 | * avoid getting forced to move into a worse ESS on | |
872 | * single error if there are no other BSSes of the | |
873 | * current ESS. | |
874 | */ | |
875 | limit = 0; | |
876 | } | |
877 | if (e->count > limit) { | |
f049052b BG |
878 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
879 | "(count=%d limit=%d)", e->count, limit); | |
c2197bc9 | 880 | return NULL; |
5471c343 | 881 | } |
d8d940b7 | 882 | } |
6fc6879b | 883 | |
620c7837 | 884 | if (bss->ssid_len == 0) { |
f049052b | 885 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); |
c2197bc9 | 886 | return NULL; |
d8d940b7 | 887 | } |
e81634cd | 888 | |
6407f413 JM |
889 | if (disallowed_bssid(wpa_s, bss->bssid)) { |
890 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed"); | |
891 | return NULL; | |
892 | } | |
893 | ||
894 | if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) { | |
895 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed"); | |
896 | return NULL; | |
897 | } | |
898 | ||
d8d940b7 | 899 | wpa = wpa_ie_len > 0 || rsn_ie_len > 0; |
6fc6879b | 900 | |
3d910ef4 | 901 | for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) { |
d8d940b7 | 902 | int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); |
00e5e3d5 | 903 | int res; |
ad08c363 | 904 | |
349493bd | 905 | if (wpas_network_disabled(wpa_s, ssid)) { |
f049052b | 906 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); |
0c703df3 | 907 | continue; |
d8d940b7 | 908 | } |
9cf32261 | 909 | |
00e5e3d5 JM |
910 | res = wpas_temp_disabled(wpa_s, ssid); |
911 | if (res > 0) { | |
912 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled " | |
913 | "temporarily for %d second(s)", res); | |
914 | continue; | |
915 | } | |
916 | ||
ad08c363 | 917 | #ifdef CONFIG_WPS |
f648bc7d | 918 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) { |
f049052b BG |
919 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
920 | "(WPS)"); | |
f648bc7d JM |
921 | continue; |
922 | } | |
923 | ||
d8d940b7 JM |
924 | if (wpa && ssid->ssid_len == 0 && |
925 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) | |
926 | check_ssid = 0; | |
927 | ||
928 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { | |
929 | /* Only allow wildcard SSID match if an AP | |
930 | * advertises active WPS operation that matches | |
931 | * with our mode. */ | |
932 | check_ssid = 1; | |
ad08c363 | 933 | if (ssid->ssid_len == 0 && |
a6099152 | 934 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
ad08c363 | 935 | check_ssid = 0; |
d8d940b7 | 936 | } |
ad08c363 JM |
937 | #endif /* CONFIG_WPS */ |
938 | ||
7d232e23 ZC |
939 | if (ssid->bssid_set && ssid->ssid_len == 0 && |
940 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) | |
941 | check_ssid = 0; | |
942 | ||
d8d940b7 | 943 | if (check_ssid && |
620c7837 JM |
944 | (bss->ssid_len != ssid->ssid_len || |
945 | os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) { | |
f049052b | 946 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); |
0c703df3 | 947 | continue; |
6fc6879b | 948 | } |
6fc6879b | 949 | |
d8d940b7 JM |
950 | if (ssid->bssid_set && |
951 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { | |
f049052b | 952 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); |
0c703df3 | 953 | continue; |
d8d940b7 | 954 | } |
6fc6879b | 955 | |
b83e4554 ST |
956 | /* check blacklist */ |
957 | if (ssid->num_bssid_blacklist && | |
958 | addr_in_list(bss->bssid, ssid->bssid_blacklist, | |
959 | ssid->num_bssid_blacklist)) { | |
960 | wpa_dbg(wpa_s, MSG_DEBUG, | |
961 | " skip - BSSID blacklisted"); | |
962 | continue; | |
963 | } | |
964 | ||
965 | /* if there is a whitelist, only accept those APs */ | |
966 | if (ssid->num_bssid_whitelist && | |
967 | !addr_in_list(bss->bssid, ssid->bssid_whitelist, | |
968 | ssid->num_bssid_whitelist)) { | |
969 | wpa_dbg(wpa_s, MSG_DEBUG, | |
970 | " skip - BSSID not in whitelist"); | |
971 | continue; | |
972 | } | |
973 | ||
cc5e390d | 974 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) |
0c703df3 | 975 | continue; |
9cf32261 | 976 | |
df0f01d9 | 977 | if (!osen && !wpa && |
d8d940b7 JM |
978 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
979 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && | |
980 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { | |
f049052b BG |
981 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network " |
982 | "not allowed"); | |
0c703df3 | 983 | continue; |
6fc6879b | 984 | } |
9cf32261 | 985 | |
86bd1410 JM |
986 | if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && |
987 | has_wep_key(ssid)) { | |
988 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block"); | |
989 | continue; | |
990 | } | |
991 | ||
df0f01d9 JM |
992 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) { |
993 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network " | |
994 | "not allowed"); | |
995 | continue; | |
996 | } | |
997 | ||
29fbc522 | 998 | if (!wpa_supplicant_match_privacy(bss, ssid)) { |
f049052b BG |
999 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy " |
1000 | "mismatch"); | |
0c703df3 | 1001 | continue; |
e81634cd JM |
1002 | } |
1003 | ||
b9074912 LD |
1004 | if (!bss_is_ess(bss) && !bss_is_pbss(bss)) { |
1005 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - neither ESS nor PBSS network"); | |
1006 | continue; | |
1007 | } | |
1008 | ||
1009 | if (ssid->pbss != bss_is_pbss(bss)) { | |
1010 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - PBSS mismatch (ssid %d bss %d)", | |
1011 | ssid->pbss, bss_is_pbss(bss)); | |
0c703df3 | 1012 | continue; |
d8d940b7 | 1013 | } |
b766a9a2 | 1014 | |
d8d940b7 | 1015 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
f049052b BG |
1016 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not " |
1017 | "allowed"); | |
0c703df3 | 1018 | continue; |
6fc6879b | 1019 | } |
d8d940b7 | 1020 | |
e1e8cae3 CL |
1021 | if (!rate_match(wpa_s, bss)) { |
1022 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do " | |
1023 | "not match"); | |
1024 | continue; | |
1025 | } | |
1026 | ||
73e49269 | 1027 | #ifdef CONFIG_P2P |
b72e14e5 JM |
1028 | if (ssid->p2p_group && |
1029 | !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && | |
1030 | !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | |
1031 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen"); | |
1032 | continue; | |
1033 | } | |
1034 | ||
9ec87666 JM |
1035 | if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) { |
1036 | struct wpabuf *p2p_ie; | |
1037 | u8 dev_addr[ETH_ALEN]; | |
1038 | ||
1039 | ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); | |
1040 | if (ie == NULL) { | |
1041 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element"); | |
1042 | continue; | |
1043 | } | |
1044 | p2p_ie = wpa_bss_get_vendor_ie_multi( | |
1045 | bss, P2P_IE_VENDOR_TYPE); | |
1046 | if (p2p_ie == NULL) { | |
1047 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element"); | |
1048 | continue; | |
1049 | } | |
1050 | ||
1051 | if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 | |
1052 | || os_memcmp(dev_addr, ssid->go_p2p_dev_addr, | |
1053 | ETH_ALEN) != 0) { | |
1054 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element"); | |
1055 | wpabuf_free(p2p_ie); | |
1056 | continue; | |
1057 | } | |
1058 | wpabuf_free(p2p_ie); | |
1059 | } | |
1060 | ||
73e49269 JM |
1061 | /* |
1062 | * TODO: skip the AP if its P2P IE has Group Formation | |
1063 | * bit set in the P2P Group Capability Bitmap and we | |
1064 | * are not in Group Formation with that device. | |
1065 | */ | |
1066 | #endif /* CONFIG_P2P */ | |
1067 | ||
dfaf11d6 JM |
1068 | if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) |
1069 | { | |
1070 | struct os_reltime diff; | |
1071 | ||
1072 | os_reltime_sub(&wpa_s->scan_min_time, | |
1073 | &bss->last_update, &diff); | |
1074 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1075 | " skip - scan result not recent enough (%u.%06u seconds too old)", | |
1076 | (unsigned int) diff.sec, | |
1077 | (unsigned int) diff.usec); | |
1078 | continue; | |
1079 | } | |
cb06cf34 DS |
1080 | #ifdef CONFIG_MBO |
1081 | assoc_disallow = wpas_mbo_get_bss_attr( | |
1082 | bss, MBO_ATTR_ID_ASSOC_DISALLOW); | |
1083 | if (assoc_disallow && assoc_disallow[1] >= 1) { | |
1084 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1085 | " skip - MBO association disallowed (reason %u)", | |
1086 | assoc_disallow[2]); | |
1087 | continue; | |
1088 | } | |
dd599908 AS |
1089 | |
1090 | if (wpa_is_bss_tmp_disallowed(wpa_s, bss->bssid)) { | |
1091 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1092 | " skip - MBO retry delay has not passed yet"); | |
1093 | continue; | |
1094 | } | |
cb06cf34 | 1095 | #endif /* CONFIG_MBO */ |
dfaf11d6 | 1096 | |
d8d940b7 JM |
1097 | /* Matching configuration found */ |
1098 | return ssid; | |
6fc6879b JM |
1099 | } |
1100 | ||
d8d940b7 | 1101 | /* No matching configuration found */ |
c2197bc9 | 1102 | return NULL; |
9cf32261 JM |
1103 | } |
1104 | ||
1105 | ||
6fa81a3b | 1106 | static struct wpa_bss * |
a1fd2ce5 | 1107 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
a1fd2ce5 | 1108 | struct wpa_ssid *group, |
3d910ef4 JM |
1109 | struct wpa_ssid **selected_ssid, |
1110 | int only_first_ssid) | |
9cf32261 | 1111 | { |
620c7837 | 1112 | unsigned int i; |
9cf32261 | 1113 | |
3d910ef4 JM |
1114 | if (only_first_ssid) |
1115 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d", | |
1116 | group->id); | |
1117 | else | |
1118 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", | |
1119 | group->priority); | |
9cf32261 | 1120 | |
620c7837 JM |
1121 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
1122 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; | |
3d910ef4 JM |
1123 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group, |
1124 | only_first_ssid); | |
d8d940b7 JM |
1125 | if (!*selected_ssid) |
1126 | continue; | |
f049052b BG |
1127 | wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR |
1128 | " ssid='%s'", | |
620c7837 JM |
1129 | MAC2STR(bss->bssid), |
1130 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | |
1131 | return bss; | |
d8d940b7 JM |
1132 | } |
1133 | ||
1134 | return NULL; | |
6fc6879b JM |
1135 | } |
1136 | ||
1137 | ||
97236cee MH |
1138 | struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
1139 | struct wpa_ssid **selected_ssid) | |
6fc6879b | 1140 | { |
6fa81a3b | 1141 | struct wpa_bss *selected = NULL; |
09b9df4e | 1142 | int prio; |
7c373ac2 | 1143 | struct wpa_ssid *next_ssid = NULL; |
a52410c2 | 1144 | struct wpa_ssid *ssid; |
09b9df4e | 1145 | |
620c7837 JM |
1146 | if (wpa_s->last_scan_res == NULL || |
1147 | wpa_s->last_scan_res_used == 0) | |
1148 | return NULL; /* no scan results from last update */ | |
1149 | ||
7c373ac2 | 1150 | if (wpa_s->next_ssid) { |
7c373ac2 JM |
1151 | /* check that next_ssid is still valid */ |
1152 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { | |
1153 | if (ssid == wpa_s->next_ssid) | |
1154 | break; | |
1155 | } | |
1156 | next_ssid = ssid; | |
1157 | wpa_s->next_ssid = NULL; | |
1158 | } | |
3d910ef4 | 1159 | |
7c373ac2 JM |
1160 | while (selected == NULL) { |
1161 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
1162 | if (next_ssid && next_ssid->priority == | |
1163 | wpa_s->conf->pssid[prio]->priority) { | |
3d910ef4 | 1164 | selected = wpa_supplicant_select_bss( |
7c373ac2 | 1165 | wpa_s, next_ssid, selected_ssid, 1); |
3d910ef4 JM |
1166 | if (selected) |
1167 | break; | |
1168 | } | |
09b9df4e | 1169 | selected = wpa_supplicant_select_bss( |
620c7837 | 1170 | wpa_s, wpa_s->conf->pssid[prio], |
3d910ef4 | 1171 | selected_ssid, 0); |
09b9df4e JM |
1172 | if (selected) |
1173 | break; | |
1174 | } | |
1175 | ||
8945cc45 BM |
1176 | if (selected == NULL && wpa_s->blacklist && |
1177 | !wpa_s->countermeasures) { | |
f049052b BG |
1178 | wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear " |
1179 | "blacklist and try again"); | |
09b9df4e JM |
1180 | wpa_blacklist_clear(wpa_s); |
1181 | wpa_s->blacklist_cleared++; | |
1182 | } else if (selected == NULL) | |
1183 | break; | |
1184 | } | |
1185 | ||
a52410c2 JM |
1186 | ssid = *selected_ssid; |
1187 | if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set && | |
1188 | !ssid->passphrase && !ssid->ext_psk) { | |
1189 | const char *field_name, *txt = NULL; | |
1190 | ||
1191 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1192 | "PSK/passphrase not yet available for the selected network"); | |
1193 | ||
1194 | wpas_notify_network_request(wpa_s, ssid, | |
1195 | WPA_CTRL_REQ_PSK_PASSPHRASE, NULL); | |
1196 | ||
1197 | field_name = wpa_supplicant_ctrl_req_to_string( | |
1198 | WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt); | |
1199 | if (field_name == NULL) | |
1200 | return NULL; | |
1201 | ||
1202 | wpas_send_ctrl_req(wpa_s, ssid, field_name, txt); | |
1203 | ||
1204 | selected = NULL; | |
1205 | } | |
1206 | ||
09b9df4e JM |
1207 | return selected; |
1208 | } | |
1209 | ||
1210 | ||
1211 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, | |
977b1174 | 1212 | int timeout_sec, int timeout_usec) |
09b9df4e | 1213 | { |
349493bd | 1214 | if (!wpa_supplicant_enabled_networks(wpa_s)) { |
4f34d51a SL |
1215 | /* |
1216 | * No networks are enabled; short-circuit request so | |
1217 | * we don't wait timeout seconds before transitioning | |
1218 | * to INACTIVE state. | |
1219 | */ | |
ac06fb12 JM |
1220 | wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request " |
1221 | "since there are no enabled networks"); | |
4f34d51a SL |
1222 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
1223 | return; | |
09b9df4e | 1224 | } |
5cc70322 JM |
1225 | |
1226 | wpa_s->scan_for_connection = 1; | |
977b1174 | 1227 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
09b9df4e JM |
1228 | } |
1229 | ||
1230 | ||
5cbd88d9 JJ |
1231 | int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
1232 | struct wpa_bss *selected, | |
1233 | struct wpa_ssid *ssid) | |
09b9df4e JM |
1234 | { |
1235 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { | |
1236 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP | |
1237 | "PBC session overlap"); | |
1a2f7ca1 | 1238 | wpas_notify_wps_event_pbc_overlap(wpa_s); |
b73bf0a7 | 1239 | #ifdef CONFIG_P2P |
ace0fbdb AS |
1240 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
1241 | wpa_s->p2p_in_provisioning) { | |
1242 | eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, | |
1243 | wpa_s, NULL); | |
5cbd88d9 | 1244 | return -1; |
ace0fbdb | 1245 | } |
b73bf0a7 | 1246 | #endif /* CONFIG_P2P */ |
199716ad BG |
1247 | |
1248 | #ifdef CONFIG_WPS | |
0a7b2a02 | 1249 | wpas_wps_pbc_overlap(wpa_s); |
7736f18b | 1250 | wpas_wps_cancel(wpa_s); |
199716ad | 1251 | #endif /* CONFIG_WPS */ |
5cbd88d9 | 1252 | return -1; |
09b9df4e JM |
1253 | } |
1254 | ||
b0680017 JM |
1255 | wpa_msg(wpa_s, MSG_DEBUG, |
1256 | "Considering connect request: reassociate: %d selected: " | |
1257 | MACSTR " bssid: " MACSTR " pending: " MACSTR | |
1258 | " wpa_state: %s ssid=%p current_ssid=%p", | |
1259 | wpa_s->reassociate, MAC2STR(selected->bssid), | |
1260 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), | |
1261 | wpa_supplicant_state_txt(wpa_s->wpa_state), | |
1262 | ssid, wpa_s->current_ssid); | |
1263 | ||
09b9df4e JM |
1264 | /* |
1265 | * Do not trigger new association unless the BSSID has changed or if | |
1266 | * reassociation is requested. If we are in process of associating with | |
1267 | * the selected BSSID, do not trigger new attempt. | |
1268 | */ | |
1269 | if (wpa_s->reassociate || | |
1270 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && | |
e29853bb BG |
1271 | ((wpa_s->wpa_state != WPA_ASSOCIATING && |
1272 | wpa_s->wpa_state != WPA_AUTHENTICATING) || | |
b0680017 JM |
1273 | (!is_zero_ether_addr(wpa_s->pending_bssid) && |
1274 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != | |
1275 | 0) || | |
1276 | (is_zero_ether_addr(wpa_s->pending_bssid) && | |
1277 | ssid != wpa_s->current_ssid)))) { | |
09b9df4e | 1278 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { |
977b1174 | 1279 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
5cbd88d9 | 1280 | return 0; |
09b9df4e | 1281 | } |
b0680017 JM |
1282 | wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR, |
1283 | MAC2STR(selected->bssid)); | |
09b9df4e JM |
1284 | wpa_supplicant_associate(wpa_s, selected, ssid); |
1285 | } else { | |
b0680017 JM |
1286 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to " |
1287 | "connect with the selected AP"); | |
09b9df4e | 1288 | } |
5cbd88d9 JJ |
1289 | |
1290 | return 0; | |
09b9df4e JM |
1291 | } |
1292 | ||
1293 | ||
b55aaa5f JM |
1294 | static struct wpa_ssid * |
1295 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) | |
1296 | { | |
1297 | int prio; | |
1298 | struct wpa_ssid *ssid; | |
1299 | ||
1300 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
1301 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) | |
1302 | { | |
349493bd | 1303 | if (wpas_network_disabled(wpa_s, ssid)) |
b55aaa5f JM |
1304 | continue; |
1305 | if (ssid->mode == IEEE80211_MODE_IBSS || | |
476e6bb6 TP |
1306 | ssid->mode == IEEE80211_MODE_AP || |
1307 | ssid->mode == IEEE80211_MODE_MESH) | |
b55aaa5f JM |
1308 | return ssid; |
1309 | } | |
1310 | } | |
1311 | return NULL; | |
1312 | } | |
1313 | ||
1314 | ||
a1fd2ce5 JM |
1315 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
1316 | * on BSS added and BSS changed events */ | |
6ae93185 | 1317 | static void wpa_supplicant_rsn_preauth_scan_results( |
6d28fb96 | 1318 | struct wpa_supplicant *wpa_s) |
6ae93185 | 1319 | { |
6d28fb96 | 1320 | struct wpa_bss *bss; |
6ae93185 JM |
1321 | |
1322 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) | |
1323 | return; | |
1324 | ||
6d28fb96 | 1325 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
6ae93185 | 1326 | const u8 *ssid, *rsn; |
6ae93185 | 1327 | |
6d28fb96 | 1328 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); |
6ae93185 JM |
1329 | if (ssid == NULL) |
1330 | continue; | |
1331 | ||
6d28fb96 | 1332 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6ae93185 JM |
1333 | if (rsn == NULL) |
1334 | continue; | |
1335 | ||
6d28fb96 | 1336 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); |
6ae93185 JM |
1337 | } |
1338 | ||
1339 | } | |
1340 | ||
1341 | ||
48563d86 JM |
1342 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
1343 | struct wpa_bss *selected, | |
20ed5e40 | 1344 | struct wpa_ssid *ssid) |
48563d86 | 1345 | { |
20ed5e40 | 1346 | struct wpa_bss *current_bss = NULL; |
ce18c107 | 1347 | #ifndef CONFIG_NO_ROAMING |
48563d86 | 1348 | int min_diff; |
954e10e4 | 1349 | int to_5ghz; |
ce18c107 | 1350 | #endif /* CONFIG_NO_ROAMING */ |
48563d86 JM |
1351 | |
1352 | if (wpa_s->reassociate) | |
1353 | return 1; /* explicit request to reassociate */ | |
1354 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
1355 | return 1; /* we are not associated; continue */ | |
1356 | if (wpa_s->current_ssid == NULL) | |
1357 | return 1; /* unknown current SSID */ | |
1358 | if (wpa_s->current_ssid != ssid) | |
1359 | return 1; /* different network block */ | |
1360 | ||
22628eca JM |
1361 | if (wpas_driver_bss_selection(wpa_s)) |
1362 | return 0; /* Driver-based roaming */ | |
1363 | ||
20ed5e40 JM |
1364 | if (wpa_s->current_ssid->ssid) |
1365 | current_bss = wpa_bss_get(wpa_s, wpa_s->bssid, | |
1366 | wpa_s->current_ssid->ssid, | |
1367 | wpa_s->current_ssid->ssid_len); | |
1368 | if (!current_bss) | |
1369 | current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid); | |
48563d86 JM |
1370 | |
1371 | if (!current_bss) | |
1372 | return 1; /* current BSS not seen in scan results */ | |
1373 | ||
20ed5e40 JM |
1374 | if (current_bss == selected) |
1375 | return 0; | |
1376 | ||
1377 | if (selected->last_update_idx > current_bss->last_update_idx) | |
1378 | return 1; /* current BSS not seen in the last scan */ | |
1379 | ||
e9af53ad | 1380 | #ifndef CONFIG_NO_ROAMING |
f049052b | 1381 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); |
0d2030ee JM |
1382 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR |
1383 | " level=%d snr=%d est_throughput=%u", | |
1384 | MAC2STR(current_bss->bssid), current_bss->level, | |
1385 | current_bss->snr, current_bss->est_throughput); | |
1386 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR | |
1387 | " level=%d snr=%d est_throughput=%u", | |
1388 | MAC2STR(selected->bssid), selected->level, | |
1389 | selected->snr, selected->est_throughput); | |
48563d86 | 1390 | |
ac26ebd8 JM |
1391 | if (wpa_s->current_ssid->bssid_set && |
1392 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == | |
1393 | 0) { | |
f049052b BG |
1394 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " |
1395 | "has preferred BSSID"); | |
ac26ebd8 JM |
1396 | return 1; |
1397 | } | |
1398 | ||
0d2030ee JM |
1399 | if (selected->est_throughput > current_bss->est_throughput + 5000) { |
1400 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1401 | "Allow reassociation - selected BSS has better estimated throughput"); | |
1402 | return 1; | |
1403 | } | |
1404 | ||
954e10e4 JM |
1405 | to_5ghz = selected->freq > 4000 && current_bss->freq < 4000; |
1406 | ||
1407 | if (current_bss->level < 0 && | |
1408 | current_bss->level > selected->level + to_5ghz * 2) { | |
bff954e9 RS |
1409 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better " |
1410 | "signal level"); | |
1411 | return 0; | |
1412 | } | |
1413 | ||
48563d86 JM |
1414 | min_diff = 2; |
1415 | if (current_bss->level < 0) { | |
1416 | if (current_bss->level < -85) | |
1417 | min_diff = 1; | |
1418 | else if (current_bss->level < -80) | |
1419 | min_diff = 2; | |
1420 | else if (current_bss->level < -75) | |
1421 | min_diff = 3; | |
1422 | else if (current_bss->level < -70) | |
1423 | min_diff = 4; | |
1424 | else | |
1425 | min_diff = 5; | |
1426 | } | |
954e10e4 JM |
1427 | if (to_5ghz) { |
1428 | /* Make it easier to move to 5 GHz band */ | |
1429 | if (min_diff > 2) | |
1430 | min_diff -= 2; | |
1431 | else | |
1432 | min_diff = 0; | |
1433 | } | |
48563d86 | 1434 | if (abs(current_bss->level - selected->level) < min_diff) { |
f049052b BG |
1435 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference " |
1436 | "in signal level"); | |
48563d86 JM |
1437 | return 0; |
1438 | } | |
1439 | ||
1440 | return 1; | |
e9af53ad DS |
1441 | #else /* CONFIG_NO_ROAMING */ |
1442 | return 0; | |
1443 | #endif /* CONFIG_NO_ROAMING */ | |
48563d86 JM |
1444 | } |
1445 | ||
cd2f4ddf | 1446 | |
0dd54313 | 1447 | /* Return != 0 if no scan results could be fetched or if scan results should not |
10ac7ddf | 1448 | * be shared with other virtual interfaces. */ |
e1504976 | 1449 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
cfd31b50 JM |
1450 | union wpa_event_data *data, |
1451 | int own_request) | |
09b9df4e | 1452 | { |
d12a51b5 JM |
1453 | struct wpa_scan_results *scan_res = NULL; |
1454 | int ret = 0; | |
5bc0cdb7 | 1455 | int ap = 0; |
7b1aa4fe JM |
1456 | #ifndef CONFIG_NO_RANDOM_POOL |
1457 | size_t i, num; | |
1458 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
5bc0cdb7 JM |
1459 | |
1460 | #ifdef CONFIG_AP | |
1461 | if (wpa_s->ap_iface) | |
1462 | ap = 1; | |
1463 | #endif /* CONFIG_AP */ | |
6fc6879b | 1464 | |
cb8564b1 DW |
1465 | wpa_supplicant_notify_scanning(wpa_s, 0); |
1466 | ||
a1fd2ce5 JM |
1467 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
1468 | data ? &data->scan_info : | |
1469 | NULL, 1); | |
1470 | if (scan_res == NULL) { | |
66fe0f70 DS |
1471 | if (wpa_s->conf->ap_scan == 2 || ap || |
1472 | wpa_s->scan_res_handler == scan_only_handler) | |
e1504976 | 1473 | return -1; |
cfd31b50 JM |
1474 | if (!own_request) |
1475 | return -1; | |
adcd7c4b KV |
1476 | if (data && data->scan_info.external_scan) |
1477 | return -1; | |
f049052b BG |
1478 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " |
1479 | "scanning again"); | |
977b1174 | 1480 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
d12a51b5 JM |
1481 | ret = -1; |
1482 | goto scan_work_done; | |
6fc6879b JM |
1483 | } |
1484 | ||
bbb921da | 1485 | #ifndef CONFIG_NO_RANDOM_POOL |
bbb921da JM |
1486 | num = scan_res->num; |
1487 | if (num > 10) | |
1488 | num = 10; | |
1489 | for (i = 0; i < num; i++) { | |
1490 | u8 buf[5]; | |
1491 | struct wpa_scan_res *res = scan_res->res[i]; | |
1492 | buf[0] = res->bssid[5]; | |
1493 | buf[1] = res->qual & 0xff; | |
1494 | buf[2] = res->noise & 0xff; | |
1495 | buf[3] = res->level & 0xff; | |
1496 | buf[4] = res->tsf & 0xff; | |
1497 | random_add_randomness(buf, sizeof(buf)); | |
1498 | } | |
1499 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
1500 | ||
06f9acce | 1501 | if (own_request && wpa_s->scan_res_handler && |
adcd7c4b | 1502 | !(data && data->scan_info.external_scan)) { |
860fddbb JB |
1503 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
1504 | struct wpa_scan_results *scan_res); | |
1505 | ||
1506 | scan_res_handler = wpa_s->scan_res_handler; | |
64e58f51 | 1507 | wpa_s->scan_res_handler = NULL; |
860fddbb | 1508 | scan_res_handler(wpa_s, scan_res); |
d12a51b5 JM |
1509 | ret = -2; |
1510 | goto scan_work_done; | |
64e58f51 JM |
1511 | } |
1512 | ||
5bc0cdb7 | 1513 | if (ap) { |
f049052b | 1514 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); |
c202f19c JB |
1515 | #ifdef CONFIG_AP |
1516 | if (wpa_s->ap_iface->scan_cb) | |
1517 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); | |
1518 | #endif /* CONFIG_AP */ | |
d12a51b5 | 1519 | goto scan_work_done; |
5bc0cdb7 JM |
1520 | } |
1521 | ||
a5f40eff | 1522 | wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)", |
adcd7c4b KV |
1523 | wpa_s->own_scan_running, |
1524 | data ? data->scan_info.external_scan : 0); | |
d81c73be | 1525 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
adcd7c4b KV |
1526 | wpa_s->manual_scan_use_id && wpa_s->own_scan_running && |
1527 | own_request && !(data && data->scan_info.external_scan)) { | |
d81c73be JM |
1528 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u", |
1529 | wpa_s->manual_scan_id); | |
1530 | wpa_s->manual_scan_use_id = 0; | |
1531 | } else { | |
1532 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); | |
1533 | } | |
24f76940 | 1534 | wpas_notify_scan_results(wpa_s); |
6fc6879b | 1535 | |
8bac466b JM |
1536 | wpas_notify_scan_done(wpa_s, 1); |
1537 | ||
adcd7c4b | 1538 | if (data && data->scan_info.external_scan) { |
015af91f JM |
1539 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection"); |
1540 | wpa_scan_results_free(scan_res); | |
1541 | return 0; | |
1542 | } | |
1543 | ||
75d65857 | 1544 | if (wnm_scan_process(wpa_s, 1) > 0) |
d0b9ab69 JM |
1545 | goto scan_work_done; |
1546 | ||
d12a51b5 JM |
1547 | if (sme_proc_obss_scan(wpa_s) > 0) |
1548 | goto scan_work_done; | |
c3701c66 | 1549 | |
d12a51b5 JM |
1550 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) |
1551 | goto scan_work_done; | |
6fc6879b | 1552 | |
d12a51b5 JM |
1553 | if (autoscan_notify_scan(wpa_s, scan_res)) |
1554 | goto scan_work_done; | |
7c865c68 | 1555 | |
3180d7a2 SO |
1556 | if (wpa_s->disconnected) { |
1557 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
d12a51b5 | 1558 | goto scan_work_done; |
3180d7a2 SO |
1559 | } |
1560 | ||
22628eca | 1561 | if (!wpas_driver_bss_selection(wpa_s) && |
d12a51b5 JM |
1562 | bgscan_notify_scan(wpa_s, scan_res) == 1) |
1563 | goto scan_work_done; | |
a1fd2ce5 | 1564 | |
f9f0526b JM |
1565 | wpas_wps_update_ap_info(wpa_s, scan_res); |
1566 | ||
706e11a4 AN |
1567 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING && |
1568 | wpa_s->wpa_state < WPA_COMPLETED) | |
1569 | goto scan_work_done; | |
1570 | ||
20ed5e40 JM |
1571 | wpa_scan_results_free(scan_res); |
1572 | ||
adcd7c4b | 1573 | if (own_request && wpa_s->scan_work) { |
d12a51b5 JM |
1574 | struct wpa_radio_work *work = wpa_s->scan_work; |
1575 | wpa_s->scan_work = NULL; | |
1576 | radio_work_done(work); | |
1577 | } | |
1578 | ||
cc4952ad | 1579 | return wpas_select_network_from_last_scan(wpa_s, 1, own_request); |
d12a51b5 JM |
1580 | |
1581 | scan_work_done: | |
1582 | wpa_scan_results_free(scan_res); | |
adcd7c4b | 1583 | if (own_request && wpa_s->scan_work) { |
d12a51b5 JM |
1584 | struct wpa_radio_work *work = wpa_s->scan_work; |
1585 | wpa_s->scan_work = NULL; | |
1586 | radio_work_done(work); | |
1587 | } | |
1588 | return ret; | |
a594e2a9 JM |
1589 | } |
1590 | ||
1591 | ||
06b7f58d | 1592 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
cc4952ad | 1593 | int new_scan, int own_request) |
a594e2a9 JM |
1594 | { |
1595 | struct wpa_bss *selected; | |
1596 | struct wpa_ssid *ssid = NULL; | |
9bd566a3 AS |
1597 | int time_to_reenable = wpas_reenabled_network_time(wpa_s); |
1598 | ||
1599 | if (time_to_reenable > 0) { | |
1600 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1601 | "Postpone network selection by %d seconds since all networks are disabled", | |
1602 | time_to_reenable); | |
1603 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); | |
1604 | eloop_register_timeout(time_to_reenable, 0, | |
1605 | wpas_network_reenabled, wpa_s, NULL); | |
1606 | return 0; | |
1607 | } | |
a594e2a9 | 1608 | |
44b9ea5b JM |
1609 | if (wpa_s->p2p_mgmt) |
1610 | return 0; /* no normal connection on p2p_mgmt interface */ | |
1611 | ||
620c7837 JM |
1612 | selected = wpa_supplicant_pick_network(wpa_s, &ssid); |
1613 | ||
6fc6879b | 1614 | if (selected) { |
48563d86 | 1615 | int skip; |
20ed5e40 | 1616 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid); |
1bbff09e | 1617 | if (skip) { |
06b7f58d JM |
1618 | if (new_scan) |
1619 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
e1504976 | 1620 | return 0; |
1bbff09e | 1621 | } |
5cbd88d9 | 1622 | |
0e6a2cf2 AB |
1623 | if (ssid != wpa_s->current_ssid && |
1624 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { | |
1625 | wpa_s->own_disconnect_req = 1; | |
1626 | wpa_supplicant_deauthenticate( | |
1627 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1628 | } | |
1629 | ||
5cbd88d9 JJ |
1630 | if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { |
1631 | wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); | |
1632 | return -1; | |
1633 | } | |
06b7f58d JM |
1634 | if (new_scan) |
1635 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
0dd54313 JM |
1636 | /* |
1637 | * Do not notify other virtual radios of scan results since we do not | |
1638 | * want them to start other associations at the same time. | |
1639 | */ | |
1640 | return 1; | |
6fc6879b | 1641 | } else { |
a3335ef5 TP |
1642 | #ifdef CONFIG_MESH |
1643 | if (wpa_s->ifmsh) { | |
1644 | wpa_msg(wpa_s, MSG_INFO, | |
1645 | "Avoiding join because we already joined a mesh group"); | |
1646 | return 0; | |
1647 | } | |
1648 | #endif /* CONFIG_MESH */ | |
f049052b | 1649 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); |
b55aaa5f JM |
1650 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
1651 | if (ssid) { | |
f049052b | 1652 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); |
b55aaa5f | 1653 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
06b7f58d JM |
1654 | if (new_scan) |
1655 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
cc4952ad JJ |
1656 | } else if (own_request) { |
1657 | /* | |
1658 | * No SSID found. If SCAN results are as a result of | |
1659 | * own scan request and not due to a scan request on | |
1660 | * another shared interface, try another scan. | |
1661 | */ | |
67b9bd08 | 1662 | int timeout_sec = wpa_s->scan_interval; |
977b1174 | 1663 | int timeout_usec = 0; |
0817de90 | 1664 | #ifdef CONFIG_P2P |
b0e669be JM |
1665 | int res; |
1666 | ||
1667 | res = wpas_p2p_scan_no_go_seen(wpa_s); | |
1668 | if (res == 2) | |
1669 | return 2; | |
1670 | if (res == 1) | |
aa9bb764 JM |
1671 | return 0; |
1672 | ||
6fc48481 | 1673 | if (wpa_s->p2p_in_provisioning || |
41d5ce9e RR |
1674 | wpa_s->show_group_started || |
1675 | wpa_s->p2p_in_invitation) { | |
0817de90 JM |
1676 | /* |
1677 | * Use shorter wait during P2P Provisioning | |
6fc48481 RR |
1678 | * state and during P2P join-a-group operation |
1679 | * to speed up group formation. | |
0817de90 JM |
1680 | */ |
1681 | timeout_sec = 0; | |
1682 | timeout_usec = 250000; | |
a4cba8f1 LC |
1683 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
1684 | timeout_usec); | |
1685 | return 0; | |
0817de90 JM |
1686 | } |
1687 | #endif /* CONFIG_P2P */ | |
4d5bda5f JM |
1688 | #ifdef CONFIG_INTERWORKING |
1689 | if (wpa_s->conf->auto_interworking && | |
1690 | wpa_s->conf->interworking && | |
1691 | wpa_s->conf->cred) { | |
1692 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: " | |
1693 | "start ANQP fetch since no matching " | |
1694 | "networks found"); | |
1695 | wpa_s->network_select = 1; | |
1696 | wpa_s->auto_network_select = 1; | |
1697 | interworking_start_fetch_anqp(wpa_s); | |
0dd54313 | 1698 | return 1; |
4d5bda5f JM |
1699 | } |
1700 | #endif /* CONFIG_INTERWORKING */ | |
662b40b1 | 1701 | #ifdef CONFIG_WPS |
538d6f4b | 1702 | if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) { |
662b40b1 JM |
1703 | wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing"); |
1704 | timeout_sec = 0; | |
1705 | timeout_usec = 500000; | |
1706 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
1707 | timeout_usec); | |
1708 | return 0; | |
1709 | } | |
1710 | #endif /* CONFIG_WPS */ | |
a4cba8f1 LC |
1711 | if (wpa_supplicant_req_sched_scan(wpa_s)) |
1712 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
1713 | timeout_usec); | |
4f39908b DS |
1714 | |
1715 | wpa_msg_ctrl(wpa_s, MSG_INFO, | |
1716 | WPA_EVENT_NETWORK_NOT_FOUND); | |
977b1174 | 1717 | } |
6fc6879b | 1718 | } |
e1504976 | 1719 | return 0; |
6fc6879b | 1720 | } |
6859f1cb BG |
1721 | |
1722 | ||
b0e669be JM |
1723 | static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
1724 | union wpa_event_data *data) | |
6859f1cb | 1725 | { |
6859f1cb | 1726 | struct wpa_supplicant *ifs; |
b0e669be | 1727 | int res; |
6859f1cb | 1728 | |
b0e669be JM |
1729 | res = _wpa_supplicant_event_scan_results(wpa_s, data, 1); |
1730 | if (res == 2) { | |
1731 | /* | |
1732 | * Interface may have been removed, so must not dereference | |
1733 | * wpa_s after this. | |
1734 | */ | |
1735 | return 1; | |
1736 | } | |
1737 | if (res != 0) { | |
e1504976 BG |
1738 | /* |
1739 | * If no scan results could be fetched, then no need to | |
1740 | * notify those interfaces that did not actually request | |
0dd54313 JM |
1741 | * this scan. Similarly, if scan results started a new operation on this |
1742 | * interface, do not notify other interfaces to avoid concurrent | |
1743 | * operations during a connection attempt. | |
e1504976 | 1744 | */ |
b0e669be | 1745 | return 0; |
e1504976 | 1746 | } |
6859f1cb BG |
1747 | |
1748 | /* | |
f88f19b4 | 1749 | * Check other interfaces to see if they share the same radio. If |
6859f1cb BG |
1750 | * so, they get updated with this same scan info. |
1751 | */ | |
f88f19b4 JM |
1752 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
1753 | radio_list) { | |
1754 | if (ifs != wpa_s) { | |
6859f1cb BG |
1755 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " |
1756 | "sibling", ifs->ifname); | |
cfd31b50 | 1757 | _wpa_supplicant_event_scan_results(ifs, data, 0); |
6859f1cb BG |
1758 | } |
1759 | } | |
b0e669be JM |
1760 | |
1761 | return 0; | |
6859f1cb BG |
1762 | } |
1763 | ||
6fc6879b JM |
1764 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
1765 | ||
1766 | ||
cecdddc1 PS |
1767 | int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s) |
1768 | { | |
1769 | #ifdef CONFIG_NO_SCAN_PROCESSING | |
1770 | return -1; | |
1771 | #else /* CONFIG_NO_SCAN_PROCESSING */ | |
a12d3454 | 1772 | struct os_reltime now; |
cecdddc1 | 1773 | |
c1a14ef4 | 1774 | if (wpa_s->last_scan_res_used == 0) |
cecdddc1 PS |
1775 | return -1; |
1776 | ||
a12d3454 JB |
1777 | os_get_reltime(&now); |
1778 | if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) { | |
cecdddc1 PS |
1779 | wpa_printf(MSG_DEBUG, "Fast associate: Old scan results"); |
1780 | return -1; | |
1781 | } | |
1782 | ||
cc4952ad | 1783 | return wpas_select_network_from_last_scan(wpa_s, 0, 1); |
cecdddc1 PS |
1784 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
1785 | } | |
1786 | ||
b6668734 JM |
1787 | #ifdef CONFIG_WNM |
1788 | ||
1789 | static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx) | |
1790 | { | |
1791 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1792 | ||
1793 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
1794 | return; | |
1795 | ||
2ec535fd JM |
1796 | if (!wpa_s->no_keep_alive) { |
1797 | wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR, | |
1798 | MAC2STR(wpa_s->bssid)); | |
1799 | /* TODO: could skip this if normal data traffic has been sent */ | |
1800 | /* TODO: Consider using some more appropriate data frame for | |
1801 | * this */ | |
1802 | if (wpa_s->l2) | |
1803 | l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, | |
1804 | (u8 *) "", 0); | |
1805 | } | |
b6668734 | 1806 | |
597c7a8d | 1807 | #ifdef CONFIG_SME |
b6668734 JM |
1808 | if (wpa_s->sme.bss_max_idle_period) { |
1809 | unsigned int msec; | |
1810 | msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */ | |
1811 | if (msec > 100) | |
1812 | msec -= 100; | |
1813 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, | |
1814 | wnm_bss_keep_alive, wpa_s, NULL); | |
1815 | } | |
597c7a8d | 1816 | #endif /* CONFIG_SME */ |
b6668734 JM |
1817 | } |
1818 | ||
1819 | ||
1820 | static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s, | |
1821 | const u8 *ies, size_t ies_len) | |
1822 | { | |
1823 | struct ieee802_11_elems elems; | |
1824 | ||
1825 | if (ies == NULL) | |
1826 | return; | |
1827 | ||
1828 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) | |
1829 | return; | |
1830 | ||
1831 | #ifdef CONFIG_SME | |
1832 | if (elems.bss_max_idle_period) { | |
1833 | unsigned int msec; | |
1834 | wpa_s->sme.bss_max_idle_period = | |
1835 | WPA_GET_LE16(elems.bss_max_idle_period); | |
1836 | wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 " | |
1837 | "TU)%s", wpa_s->sme.bss_max_idle_period, | |
1838 | (elems.bss_max_idle_period[2] & 0x01) ? | |
1839 | " (protected keep-live required)" : ""); | |
1840 | if (wpa_s->sme.bss_max_idle_period == 0) | |
1841 | wpa_s->sme.bss_max_idle_period = 1; | |
1842 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { | |
1843 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); | |
1844 | /* msec times 1000 */ | |
1845 | msec = wpa_s->sme.bss_max_idle_period * 1024; | |
1846 | if (msec > 100) | |
1847 | msec -= 100; | |
1848 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, | |
1849 | wnm_bss_keep_alive, wpa_s, | |
1850 | NULL); | |
1851 | } | |
1852 | } | |
1853 | #endif /* CONFIG_SME */ | |
1854 | } | |
1855 | ||
1856 | #endif /* CONFIG_WNM */ | |
1857 | ||
1858 | ||
1859 | void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s) | |
1860 | { | |
1861 | #ifdef CONFIG_WNM | |
1862 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); | |
1863 | #endif /* CONFIG_WNM */ | |
1864 | } | |
1865 | ||
1866 | ||
56f5af48 JM |
1867 | #ifdef CONFIG_INTERWORKING |
1868 | ||
1869 | static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map, | |
1870 | size_t len) | |
1871 | { | |
1872 | int res; | |
1873 | ||
1874 | wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len); | |
1875 | res = wpa_drv_set_qos_map(wpa_s, qos_map, len); | |
1876 | if (res) { | |
1877 | wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver"); | |
1878 | } | |
1879 | ||
1880 | return res; | |
1881 | } | |
1882 | ||
1883 | ||
1884 | static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s, | |
1885 | const u8 *ies, size_t ies_len) | |
1886 | { | |
1887 | struct ieee802_11_elems elems; | |
1888 | ||
1889 | if (ies == NULL) | |
1890 | return; | |
1891 | ||
1892 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) | |
1893 | return; | |
1894 | ||
1895 | if (elems.qos_map_set) { | |
1896 | wpas_qos_map_set(wpa_s, elems.qos_map_set, | |
1897 | elems.qos_map_set_len); | |
1898 | } | |
1899 | } | |
1900 | ||
1901 | #endif /* CONFIG_INTERWORKING */ | |
1902 | ||
1903 | ||
ea708118 DL |
1904 | #ifdef CONFIG_FST |
1905 | static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s, | |
1906 | const u8 *ie, size_t ie_len) | |
1907 | { | |
1908 | struct mb_ies_info mb_ies; | |
1909 | ||
1910 | if (!ie || !ie_len || !wpa_s->fst) | |
1911 | return -ENOENT; | |
1912 | ||
1913 | os_memset(&mb_ies, 0, sizeof(mb_ies)); | |
1914 | ||
1915 | while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) { | |
1916 | size_t len; | |
1917 | ||
1918 | len = 2 + ie[1]; | |
1919 | if (len > ie_len) { | |
1920 | wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found", | |
1921 | ie, ie_len); | |
1922 | break; | |
1923 | } | |
1924 | ||
1925 | if (ie[0] == WLAN_EID_MULTI_BAND) { | |
1926 | wpa_printf(MSG_DEBUG, "MB IE of %u bytes found", | |
1927 | (unsigned int) len); | |
1928 | mb_ies.ies[mb_ies.nof_ies].ie = ie + 2; | |
1929 | mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2; | |
1930 | mb_ies.nof_ies++; | |
1931 | } | |
1932 | ||
1933 | ie_len -= len; | |
1934 | ie += len; | |
1935 | } | |
1936 | ||
1937 | if (mb_ies.nof_ies > 0) { | |
1938 | wpabuf_free(wpa_s->received_mb_ies); | |
1939 | wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies); | |
1940 | return 0; | |
1941 | } | |
1942 | ||
1943 | return -ENOENT; | |
1944 | } | |
1945 | #endif /* CONFIG_FST */ | |
1946 | ||
1947 | ||
579ce771 JM |
1948 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
1949 | union wpa_event_data *data) | |
6fc6879b JM |
1950 | { |
1951 | int l, len, found = 0, wpa_found, rsn_found; | |
c2a04078 | 1952 | const u8 *p; |
b6714ca1 | 1953 | #ifdef CONFIG_IEEE80211R |
6a1ce395 | 1954 | u8 bssid[ETH_ALEN]; |
b6714ca1 | 1955 | #endif /* CONFIG_IEEE80211R */ |
6fc6879b | 1956 | |
f049052b | 1957 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); |
6fc6879b JM |
1958 | if (data->assoc_info.req_ies) |
1959 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, | |
1960 | data->assoc_info.req_ies_len); | |
52c9e6f3 | 1961 | if (data->assoc_info.resp_ies) { |
6fc6879b JM |
1962 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, |
1963 | data->assoc_info.resp_ies_len); | |
52c9e6f3 JM |
1964 | #ifdef CONFIG_TDLS |
1965 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, | |
1966 | data->assoc_info.resp_ies_len); | |
1967 | #endif /* CONFIG_TDLS */ | |
b6668734 JM |
1968 | #ifdef CONFIG_WNM |
1969 | wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, | |
1970 | data->assoc_info.resp_ies_len); | |
1971 | #endif /* CONFIG_WNM */ | |
56f5af48 JM |
1972 | #ifdef CONFIG_INTERWORKING |
1973 | interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, | |
1974 | data->assoc_info.resp_ies_len); | |
1975 | #endif /* CONFIG_INTERWORKING */ | |
52c9e6f3 | 1976 | } |
6fc6879b JM |
1977 | if (data->assoc_info.beacon_ies) |
1978 | wpa_hexdump(MSG_DEBUG, "beacon_ies", | |
1979 | data->assoc_info.beacon_ies, | |
1980 | data->assoc_info.beacon_ies_len); | |
4832ecd7 | 1981 | if (data->assoc_info.freq) |
f049052b BG |
1982 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", |
1983 | data->assoc_info.freq); | |
6fc6879b JM |
1984 | |
1985 | p = data->assoc_info.req_ies; | |
1986 | l = data->assoc_info.req_ies_len; | |
1987 | ||
1988 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ | |
1989 | while (p && l >= 2) { | |
1990 | len = p[1] + 2; | |
1991 | if (len > l) { | |
1992 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1993 | p, l); | |
1994 | break; | |
1995 | } | |
1996 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1997 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || | |
192964dd DN |
1998 | (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 && |
1999 | (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) || | |
6fc6879b JM |
2000 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { |
2001 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) | |
2002 | break; | |
2003 | found = 1; | |
2004 | wpa_find_assoc_pmkid(wpa_s); | |
2005 | break; | |
2006 | } | |
2007 | l -= len; | |
2008 | p += len; | |
2009 | } | |
2010 | if (!found && data->assoc_info.req_ies) | |
2011 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
2012 | ||
c2a04078 | 2013 | #ifdef CONFIG_IEEE80211R |
62c72d72 JM |
2014 | #ifdef CONFIG_SME |
2015 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { | |
62c72d72 JM |
2016 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || |
2017 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
2018 | data->assoc_info.resp_ies, | |
2019 | data->assoc_info.resp_ies_len, | |
2020 | bssid) < 0) { | |
f049052b BG |
2021 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
2022 | "Reassociation Response failed"); | |
579ce771 JM |
2023 | wpa_supplicant_deauthenticate( |
2024 | wpa_s, WLAN_REASON_INVALID_IE); | |
2025 | return -1; | |
62c72d72 JM |
2026 | } |
2027 | } | |
62c72d72 | 2028 | |
c2a04078 JM |
2029 | p = data->assoc_info.resp_ies; |
2030 | l = data->assoc_info.resp_ies_len; | |
2031 | ||
54f489be | 2032 | #ifdef CONFIG_WPS_STRICT |
5dac11e0 | 2033 | if (p && wpa_s->current_ssid && |
54f489be JM |
2034 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
2035 | struct wpabuf *wps; | |
2036 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); | |
2037 | if (wps == NULL) { | |
f049052b BG |
2038 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " |
2039 | "include WPS IE in (Re)Association Response"); | |
54f489be JM |
2040 | return -1; |
2041 | } | |
2042 | ||
2043 | if (wps_validate_assoc_resp(wps) < 0) { | |
2044 | wpabuf_free(wps); | |
2045 | wpa_supplicant_deauthenticate( | |
2046 | wpa_s, WLAN_REASON_INVALID_IE); | |
2047 | return -1; | |
2048 | } | |
2049 | wpabuf_free(wps); | |
2050 | } | |
2051 | #endif /* CONFIG_WPS_STRICT */ | |
2052 | ||
e7846b68 | 2053 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
c2a04078 JM |
2054 | while (p && l >= 2) { |
2055 | len = p[1] + 2; | |
2056 | if (len > l) { | |
2057 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
2058 | p, l); | |
2059 | break; | |
2060 | } | |
e7846b68 JM |
2061 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
2062 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
2063 | wpa_s->sme.ft_used = 1; | |
2064 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, | |
2065 | MOBILITY_DOMAIN_ID_LEN); | |
2066 | break; | |
2067 | } | |
c2a04078 JM |
2068 | l -= len; |
2069 | p += len; | |
2070 | } | |
e7846b68 | 2071 | #endif /* CONFIG_SME */ |
c2a04078 | 2072 | |
6a1ce395 DG |
2073 | /* Process FT when SME is in the driver */ |
2074 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
2075 | wpa_ft_is_completed(wpa_s->wpa)) { | |
2076 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || | |
2077 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
2078 | data->assoc_info.resp_ies, | |
2079 | data->assoc_info.resp_ies_len, | |
2080 | bssid) < 0) { | |
2081 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " | |
2082 | "Reassociation Response failed"); | |
2083 | wpa_supplicant_deauthenticate( | |
2084 | wpa_s, WLAN_REASON_INVALID_IE); | |
2085 | return -1; | |
2086 | } | |
2087 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done"); | |
2088 | } | |
2089 | ||
e7846b68 JM |
2090 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
2091 | data->assoc_info.resp_ies_len); | |
c2a04078 JM |
2092 | #endif /* CONFIG_IEEE80211R */ |
2093 | ||
6fc6879b JM |
2094 | /* WPA/RSN IE from Beacon/ProbeResp */ |
2095 | p = data->assoc_info.beacon_ies; | |
2096 | l = data->assoc_info.beacon_ies_len; | |
2097 | ||
2098 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. | |
2099 | */ | |
2100 | wpa_found = rsn_found = 0; | |
2101 | while (p && l >= 2) { | |
2102 | len = p[1] + 2; | |
2103 | if (len > l) { | |
2104 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", | |
2105 | p, l); | |
2106 | break; | |
2107 | } | |
2108 | if (!wpa_found && | |
2109 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
2110 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { | |
2111 | wpa_found = 1; | |
2112 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); | |
2113 | } | |
2114 | ||
2115 | if (!rsn_found && | |
2116 | p[0] == WLAN_EID_RSN && p[1] >= 2) { | |
2117 | rsn_found = 1; | |
2118 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); | |
2119 | } | |
2120 | ||
2121 | l -= len; | |
2122 | p += len; | |
2123 | } | |
2124 | ||
2125 | if (!wpa_found && data->assoc_info.beacon_ies) | |
2126 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
2127 | if (!rsn_found && data->assoc_info.beacon_ies) | |
2128 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
2129 | if (wpa_found || rsn_found) | |
2130 | wpa_s->ap_ies_from_associnfo = 1; | |
4832ecd7 | 2131 | |
117e812d JM |
2132 | if (wpa_s->assoc_freq && data->assoc_info.freq && |
2133 | wpa_s->assoc_freq != data->assoc_info.freq) { | |
2134 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " | |
2135 | "%u to %u MHz", | |
2136 | wpa_s->assoc_freq, data->assoc_info.freq); | |
2137 | wpa_supplicant_update_scan_results(wpa_s); | |
2138 | } | |
2139 | ||
4832ecd7 | 2140 | wpa_s->assoc_freq = data->assoc_info.freq; |
579ce771 JM |
2141 | |
2142 | return 0; | |
6fc6879b JM |
2143 | } |
2144 | ||
2145 | ||
ad9ee4d4 JM |
2146 | static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) |
2147 | { | |
2148 | const u8 *bss_wpa = NULL, *bss_rsn = NULL; | |
2149 | ||
2150 | if (!wpa_s->current_bss || !wpa_s->current_ssid) | |
2151 | return -1; | |
2152 | ||
2153 | if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) | |
2154 | return 0; | |
2155 | ||
2156 | bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, | |
2157 | WPA_IE_VENDOR_TYPE); | |
2158 | bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN); | |
2159 | ||
2160 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, | |
2161 | bss_wpa ? 2 + bss_wpa[1] : 0) || | |
2162 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, | |
2163 | bss_rsn ? 2 + bss_rsn[1] : 0)) | |
2164 | return -1; | |
2165 | ||
2166 | return 0; | |
2167 | } | |
2168 | ||
2169 | ||
ea708118 DL |
2170 | static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s, |
2171 | union wpa_event_data *data) | |
2172 | { | |
2173 | #ifdef CONFIG_FST | |
2174 | struct assoc_info *ai = data ? &data->assoc_info : NULL; | |
2175 | struct wpa_bss *bss = wpa_s->current_bss; | |
2176 | const u8 *ieprb, *iebcn; | |
2177 | ||
2178 | wpabuf_free(wpa_s->received_mb_ies); | |
2179 | wpa_s->received_mb_ies = NULL; | |
2180 | ||
2181 | if (ai && | |
2182 | !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) { | |
2183 | wpa_printf(MSG_DEBUG, | |
2184 | "FST: MB IEs updated from Association Response frame"); | |
2185 | return; | |
2186 | } | |
2187 | ||
2188 | if (ai && | |
2189 | !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) { | |
2190 | wpa_printf(MSG_DEBUG, | |
2191 | "FST: MB IEs updated from association event Beacon IEs"); | |
2192 | return; | |
2193 | } | |
2194 | ||
2195 | if (!bss) | |
2196 | return; | |
2197 | ||
2198 | ieprb = (const u8 *) (bss + 1); | |
2199 | iebcn = ieprb + bss->ie_len; | |
2200 | ||
2201 | if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len)) | |
2202 | wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE"); | |
2203 | else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len)) | |
2204 | wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE"); | |
2205 | #endif /* CONFIG_FST */ | |
2206 | } | |
2207 | ||
2208 | ||
6fc6879b JM |
2209 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, |
2210 | union wpa_event_data *data) | |
2211 | { | |
2212 | u8 bssid[ETH_ALEN]; | |
1d041bec | 2213 | int ft_completed; |
ce7d0eb1 | 2214 | int new_bss = 0; |
6fc6879b | 2215 | |
1d041bec JM |
2216 | #ifdef CONFIG_AP |
2217 | if (wpa_s->ap_iface) { | |
a01acc50 JM |
2218 | if (!data) |
2219 | return; | |
1d041bec JM |
2220 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], |
2221 | data->assoc_info.addr, | |
2222 | data->assoc_info.req_ies, | |
39b08b5f SP |
2223 | data->assoc_info.req_ies_len, |
2224 | data->assoc_info.reassoc); | |
1d041bec JM |
2225 | return; |
2226 | } | |
2227 | #endif /* CONFIG_AP */ | |
2228 | ||
9bd566a3 AS |
2229 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
2230 | ||
1d041bec | 2231 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); |
579ce771 JM |
2232 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
2233 | return; | |
6fc6879b | 2234 | |
0a0c38f6 MH |
2235 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
2236 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID"); | |
07783eaa | 2237 | wpa_supplicant_deauthenticate( |
0a0c38f6 MH |
2238 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
2239 | return; | |
2240 | } | |
2241 | ||
6fc6879b | 2242 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); |
0a0c38f6 | 2243 | if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { |
f049052b | 2244 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" |
6fc6879b | 2245 | MACSTR, MAC2STR(bssid)); |
ce7d0eb1 | 2246 | new_bss = 1; |
bbb921da | 2247 | random_add_randomness(bssid, ETH_ALEN); |
6fc6879b JM |
2248 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
2249 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
e485286c | 2250 | wpas_notify_bssid_changed(wpa_s); |
8bac466b | 2251 | |
6fc6879b JM |
2252 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
2253 | wpa_clear_keys(wpa_s, bssid); | |
2254 | } | |
2255 | if (wpa_supplicant_select_config(wpa_s) < 0) { | |
07783eaa | 2256 | wpa_supplicant_deauthenticate( |
6fc6879b JM |
2257 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
2258 | return; | |
2259 | } | |
ce7d0eb1 | 2260 | } |
cd2f4ddf | 2261 | |
cb201af5 DS |
2262 | #ifdef ANDROID |
2263 | if (wpa_s->conf->ap_scan == 1) { | |
2264 | #else /* ANDROID */ | |
ce7d0eb1 SD |
2265 | if (wpa_s->conf->ap_scan == 1 && |
2266 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { | |
cb201af5 | 2267 | #endif /* ANDROID */ |
ce7d0eb1 SD |
2268 | if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss) |
2269 | wpa_msg(wpa_s, MSG_WARNING, | |
2270 | "WPA/RSN IEs not updated"); | |
6fc6879b JM |
2271 | } |
2272 | ||
ea708118 DL |
2273 | wpas_fst_update_mb_assoc(wpa_s, data); |
2274 | ||
62fa124c JM |
2275 | #ifdef CONFIG_SME |
2276 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); | |
2277 | wpa_s->sme.prev_bssid_set = 1; | |
3302b7c2 | 2278 | wpa_s->sme.last_unprot_disconnect.sec = 0; |
62fa124c JM |
2279 | #endif /* CONFIG_SME */ |
2280 | ||
6fc6879b JM |
2281 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
2282 | if (wpa_s->current_ssid) { | |
2283 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be | |
2284 | * initialized before association, but for other modes, | |
2285 | * initialize PC/SC here, if the current configuration needs | |
2286 | * smartcard or SIM/USIM. */ | |
2287 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); | |
2288 | } | |
2289 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); | |
3f967fe0 JM |
2290 | if (wpa_s->l2) |
2291 | l2_packet_notify_auth_start(wpa_s->l2); | |
6fc6879b JM |
2292 | |
2293 | /* | |
2294 | * Set portEnabled first to FALSE in order to get EAP state machine out | |
2295 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE | |
2296 | * state machine may transit to AUTHENTICATING state based on obsolete | |
2297 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to | |
2298 | * AUTHENTICATED without ever giving chance to EAP state machine to | |
2299 | * reset the state. | |
2300 | */ | |
2301 | if (!ft_completed) { | |
2302 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
2303 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
2304 | } | |
56586197 | 2305 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) |
6fc6879b JM |
2306 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
2307 | /* 802.1X::portControl = Auto */ | |
2308 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); | |
2309 | wpa_s->eapol_received = 0; | |
2310 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
9c972abb JM |
2311 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
2312 | (wpa_s->current_ssid && | |
2313 | wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { | |
fb958ea7 JM |
2314 | if (wpa_s->current_ssid && |
2315 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE && | |
6ea1f413 JM |
2316 | (wpa_s->drv_flags & |
2317 | WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { | |
2318 | /* | |
2319 | * Set the key after having received joined-IBSS event | |
2320 | * from the driver. | |
2321 | */ | |
2322 | wpa_supplicant_set_wpa_none_key(wpa_s, | |
2323 | wpa_s->current_ssid); | |
2324 | } | |
6fc6879b JM |
2325 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
2326 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2327 | } else if (!ft_completed) { | |
2328 | /* Timeout for receiving the first EAPOL packet */ | |
2329 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); | |
2330 | } | |
2331 | wpa_supplicant_cancel_scan(wpa_s); | |
2332 | ||
c2a04078 | 2333 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
56586197 | 2334 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
2335 | /* |
2336 | * We are done; the driver will take care of RSN 4-way | |
2337 | * handshake. | |
2338 | */ | |
2339 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
2340 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2341 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
2342 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
98ea9431 JM |
2343 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
2344 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
2345 | /* | |
2346 | * The driver will take care of RSN 4-way handshake, so we need | |
2347 | * to allow EAPOL supplicant to complete its work without | |
2348 | * waiting for WPA supplicant. | |
2349 | */ | |
2350 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
16a83d29 JM |
2351 | } else if (ft_completed) { |
2352 | /* | |
2353 | * FT protocol completed - make sure EAPOL state machine ends | |
2354 | * up in authenticated. | |
2355 | */ | |
2356 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
2357 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2358 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
2359 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
6fc6879b | 2360 | } |
1ff73338 | 2361 | |
3ab35a66 JM |
2362 | wpa_s->last_eapol_matches_bssid = 0; |
2363 | ||
1ff73338 | 2364 | if (wpa_s->pending_eapol_rx) { |
c2be937c JB |
2365 | struct os_reltime now, age; |
2366 | os_get_reltime(&now); | |
2367 | os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age); | |
1ff73338 JM |
2368 | if (age.sec == 0 && age.usec < 100000 && |
2369 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == | |
2370 | 0) { | |
f049052b BG |
2371 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " |
2372 | "frame that was received just before " | |
2373 | "association notification"); | |
1ff73338 JM |
2374 | wpa_supplicant_rx_eapol( |
2375 | wpa_s, wpa_s->pending_eapol_rx_src, | |
2376 | wpabuf_head(wpa_s->pending_eapol_rx), | |
2377 | wpabuf_len(wpa_s->pending_eapol_rx)); | |
2378 | } | |
2379 | wpabuf_free(wpa_s->pending_eapol_rx); | |
2380 | wpa_s->pending_eapol_rx = NULL; | |
2381 | } | |
60b94c98 | 2382 | |
0194fedb JB |
2383 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
2384 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
66562e9c JM |
2385 | wpa_s->current_ssid && |
2386 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { | |
0194fedb JB |
2387 | /* Set static WEP keys again */ |
2388 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); | |
2389 | } | |
50b05780 JM |
2390 | |
2391 | #ifdef CONFIG_IBSS_RSN | |
2392 | if (wpa_s->current_ssid && | |
2393 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
2394 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && | |
78177a00 JM |
2395 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && |
2396 | wpa_s->ibss_rsn == NULL) { | |
2397 | wpa_s->ibss_rsn = ibss_rsn_init(wpa_s); | |
2398 | if (!wpa_s->ibss_rsn) { | |
2399 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); | |
2400 | wpa_supplicant_deauthenticate( | |
2401 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
2402 | return; | |
2403 | } | |
2404 | ||
2405 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); | |
2406 | } | |
50b05780 | 2407 | #endif /* CONFIG_IBSS_RSN */ |
f9f0526b JM |
2408 | |
2409 | wpas_wps_notify_assoc(wpa_s, bssid); | |
a0413b17 MB |
2410 | |
2411 | if (data) { | |
2412 | wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies, | |
2413 | data->assoc_info.resp_ies_len, | |
2414 | &data->assoc_info.wmm_params); | |
8c42b369 EP |
2415 | |
2416 | if (wpa_s->reassoc_same_bss) | |
2417 | wmm_ac_restore_tspecs(wpa_s); | |
a0413b17 | 2418 | } |
6fc6879b JM |
2419 | } |
2420 | ||
2421 | ||
d00821e9 JM |
2422 | static int disconnect_reason_recoverable(u16 reason_code) |
2423 | { | |
2424 | return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || | |
2425 | reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || | |
2426 | reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; | |
2427 | } | |
2428 | ||
2429 | ||
0544b242 | 2430 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
3d9975d5 JM |
2431 | u16 reason_code, |
2432 | int locally_generated) | |
6fc6879b JM |
2433 | { |
2434 | const u8 *bssid; | |
0aadd568 JM |
2435 | |
2436 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
2437 | /* | |
2438 | * At least Host AP driver and a Prism3 card seemed to be | |
2439 | * generating streams of disconnected events when configuring | |
2440 | * IBSS for WPA-None. Ignore them for now. | |
2441 | */ | |
2442 | return; | |
2443 | } | |
2444 | ||
2445 | bssid = wpa_s->bssid; | |
2446 | if (is_zero_ether_addr(bssid)) | |
2447 | bssid = wpa_s->pending_bssid; | |
2448 | ||
2449 | if (!is_zero_ether_addr(bssid) || | |
2450 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { | |
2451 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR | |
2452 | " reason=%d%s", | |
2453 | MAC2STR(bssid), reason_code, | |
2454 | locally_generated ? " locally_generated=1" : ""); | |
2455 | } | |
2456 | } | |
2457 | ||
2458 | ||
c9a82218 JM |
2459 | static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code, |
2460 | int locally_generated) | |
2461 | { | |
2462 | if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE || | |
2463 | !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) | |
2464 | return 0; /* Not in 4-way handshake with PSK */ | |
2465 | ||
2466 | /* | |
2467 | * It looks like connection was lost while trying to go through PSK | |
2468 | * 4-way handshake. Filter out known disconnection cases that are caused | |
2469 | * by something else than PSK mismatch to avoid confusing reports. | |
2470 | */ | |
2471 | ||
2472 | if (locally_generated) { | |
2473 | if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS) | |
2474 | return 0; | |
2475 | } | |
2476 | ||
2477 | return 1; | |
2478 | } | |
2479 | ||
2480 | ||
0aadd568 JM |
2481 | static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s, |
2482 | u16 reason_code, | |
2483 | int locally_generated) | |
2484 | { | |
2485 | const u8 *bssid; | |
6d6f4bb8 JM |
2486 | int authenticating; |
2487 | u8 prev_pending_bssid[ETH_ALEN]; | |
d00821e9 JM |
2488 | struct wpa_bss *fast_reconnect = NULL; |
2489 | struct wpa_ssid *fast_reconnect_ssid = NULL; | |
bcdf2096 | 2490 | struct wpa_ssid *last_ssid; |
6d6f4bb8 JM |
2491 | |
2492 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; | |
2493 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); | |
6fc6879b JM |
2494 | |
2495 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
2496 | /* | |
2497 | * At least Host AP driver and a Prism3 card seemed to be | |
2498 | * generating streams of disconnected events when configuring | |
2499 | * IBSS for WPA-None. Ignore them for now. | |
2500 | */ | |
f049052b BG |
2501 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " |
2502 | "IBSS/WPA-None mode"); | |
6fc6879b JM |
2503 | return; |
2504 | } | |
2505 | ||
c9a82218 | 2506 | if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) { |
6fc6879b JM |
2507 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
2508 | "pre-shared key may be incorrect"); | |
5bf9a6c8 JM |
2509 | if (wpas_p2p_4way_hs_failed(wpa_s) > 0) |
2510 | return; /* P2P group removed */ | |
b19c098e | 2511 | wpas_auth_failed(wpa_s, "WRONG_KEY"); |
6fc6879b | 2512 | } |
3636b891 JM |
2513 | if (!wpa_s->disconnected && |
2514 | (!wpa_s->auto_reconnect_disabled || | |
6e252b0d | 2515 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS || |
5e238cc6 SD |
2516 | wpas_wps_searching(wpa_s) || |
2517 | wpas_wps_reenable_networks_pending(wpa_s))) { | |
d00821e9 | 2518 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " |
6e252b0d | 2519 | "reconnect (wps=%d/%d wpa_state=%d)", |
f7da5a9e | 2520 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, |
6e252b0d | 2521 | wpas_wps_searching(wpa_s), |
f7da5a9e | 2522 | wpa_s->wpa_state); |
d00821e9 JM |
2523 | if (wpa_s->wpa_state == WPA_COMPLETED && |
2524 | wpa_s->current_ssid && | |
2525 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && | |
3d9975d5 | 2526 | !locally_generated && |
d00821e9 JM |
2527 | disconnect_reason_recoverable(reason_code)) { |
2528 | /* | |
2529 | * It looks like the AP has dropped association with | |
2530 | * us, but could allow us to get back in. Try to | |
2531 | * reconnect to the same BSS without full scan to save | |
2532 | * time for some common cases. | |
2533 | */ | |
2534 | fast_reconnect = wpa_s->current_bss; | |
2535 | fast_reconnect_ssid = wpa_s->current_ssid; | |
2536 | } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) | |
0d0a8ca1 | 2537 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
f7da5a9e JM |
2538 | else |
2539 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " | |
2540 | "immediate scan"); | |
0d0a8ca1 | 2541 | } else { |
d00821e9 | 2542 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " |
f049052b | 2543 | "try to re-connect"); |
0d0a8ca1 AC |
2544 | wpa_s->reassociate = 0; |
2545 | wpa_s->disconnected = 1; | |
0d0f7ecb MS |
2546 | if (!wpa_s->pno) |
2547 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
0d0a8ca1 | 2548 | } |
6fc6879b | 2549 | bssid = wpa_s->bssid; |
a8e16edc | 2550 | if (is_zero_ether_addr(bssid)) |
6fc6879b | 2551 | bssid = wpa_s->pending_bssid; |
56d24b4e JM |
2552 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
2553 | wpas_connection_failed(wpa_s, bssid); | |
6fc6879b | 2554 | wpa_sm_notify_disassoc(wpa_s->wpa); |
0bb1e425 GM |
2555 | if (locally_generated) |
2556 | wpa_s->disconnect_reason = -reason_code; | |
2557 | else | |
2558 | wpa_s->disconnect_reason = reason_code; | |
2559 | wpas_notify_disconnect_reason(wpa_s); | |
6fc6879b | 2560 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
f049052b | 2561 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); |
6fc6879b JM |
2562 | wpa_clear_keys(wpa_s, wpa_s->bssid); |
2563 | } | |
bcdf2096 | 2564 | last_ssid = wpa_s->current_ssid; |
6fc6879b | 2565 | wpa_supplicant_mark_disassoc(wpa_s); |
e29853bb | 2566 | |
bcdf2096 | 2567 | if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) { |
e29853bb | 2568 | sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); |
bcdf2096 JM |
2569 | wpa_s->current_ssid = last_ssid; |
2570 | } | |
d00821e9 | 2571 | |
eef7235d JM |
2572 | if (fast_reconnect && |
2573 | !wpas_network_disabled(wpa_s, fast_reconnect_ssid) && | |
2574 | !disallowed_bssid(wpa_s, fast_reconnect->bssid) && | |
2575 | !disallowed_ssid(wpa_s, fast_reconnect->ssid, | |
2576 | fast_reconnect->ssid_len) && | |
dd599908 AS |
2577 | !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) && |
2578 | !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect->bssid)) { | |
5928411e | 2579 | #ifndef CONFIG_NO_SCAN_PROCESSING |
d00821e9 JM |
2580 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); |
2581 | if (wpa_supplicant_connect(wpa_s, fast_reconnect, | |
2582 | fast_reconnect_ssid) < 0) { | |
2583 | /* Recover through full scan */ | |
2584 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
2585 | } | |
5928411e | 2586 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
eef7235d JM |
2587 | } else if (fast_reconnect) { |
2588 | /* | |
2589 | * Could not reconnect to the same BSS due to network being | |
2590 | * disabled. Use a new scan to match the alternative behavior | |
2591 | * above, i.e., to continue automatic reconnection attempt in a | |
2592 | * way that enforces disabled network rules. | |
2593 | */ | |
2594 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
d00821e9 | 2595 | } |
6fc6879b JM |
2596 | } |
2597 | ||
2598 | ||
46690a3b | 2599 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
01a17491 | 2600 | void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx) |
46690a3b JM |
2601 | { |
2602 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
2603 | ||
2604 | if (!wpa_s->pending_mic_error_report) | |
2605 | return; | |
2606 | ||
f049052b | 2607 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); |
46690a3b JM |
2608 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); |
2609 | wpa_s->pending_mic_error_report = 0; | |
2610 | } | |
2611 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
2612 | ||
2613 | ||
6fc6879b JM |
2614 | static void |
2615 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, | |
2616 | union wpa_event_data *data) | |
2617 | { | |
2618 | int pairwise; | |
6473e5c8 | 2619 | struct os_reltime t; |
6fc6879b JM |
2620 | |
2621 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); | |
2622 | pairwise = (data && data->michael_mic_failure.unicast); | |
6473e5c8 JB |
2623 | os_get_reltime(&t); |
2624 | if ((wpa_s->last_michael_mic_error.sec && | |
2625 | !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) || | |
46690a3b JM |
2626 | wpa_s->pending_mic_error_report) { |
2627 | if (wpa_s->pending_mic_error_report) { | |
2628 | /* | |
2629 | * Send the pending MIC error report immediately since | |
2630 | * we are going to start countermeasures and AP better | |
2631 | * do the same. | |
2632 | */ | |
2633 | wpa_sm_key_request(wpa_s->wpa, 1, | |
2634 | wpa_s->pending_mic_error_pairwise); | |
2635 | } | |
2636 | ||
2637 | /* Send the new MIC error report immediately since we are going | |
2638 | * to start countermeasures and AP better do the same. | |
2639 | */ | |
2640 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
2641 | ||
6fc6879b JM |
2642 | /* initialize countermeasures */ |
2643 | wpa_s->countermeasures = 1; | |
8945cc45 BM |
2644 | |
2645 | wpa_blacklist_add(wpa_s, wpa_s->bssid); | |
2646 | ||
6fc6879b JM |
2647 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); |
2648 | ||
2649 | /* | |
2650 | * Need to wait for completion of request frame. We do not get | |
2651 | * any callback for the message completion, so just wait a | |
2652 | * short while and hope for the best. */ | |
2653 | os_sleep(0, 10000); | |
2654 | ||
2655 | wpa_drv_set_countermeasures(wpa_s, 1); | |
2656 | wpa_supplicant_deauthenticate(wpa_s, | |
2657 | WLAN_REASON_MICHAEL_MIC_FAILURE); | |
2658 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, | |
2659 | wpa_s, NULL); | |
2660 | eloop_register_timeout(60, 0, | |
2661 | wpa_supplicant_stop_countermeasures, | |
2662 | wpa_s, NULL); | |
2663 | /* TODO: mark the AP rejected for 60 second. STA is | |
2664 | * allowed to associate with another AP.. */ | |
46690a3b JM |
2665 | } else { |
2666 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
2667 | if (wpa_s->mic_errors_seen) { | |
2668 | /* | |
2669 | * Reduce the effectiveness of Michael MIC error | |
2670 | * reports as a means for attacking against TKIP if | |
2671 | * more than one MIC failure is noticed with the same | |
2672 | * PTK. We delay the transmission of the reports by a | |
2673 | * random time between 0 and 60 seconds in order to | |
2674 | * force the attacker wait 60 seconds before getting | |
2675 | * the information on whether a frame resulted in a MIC | |
2676 | * failure. | |
2677 | */ | |
2678 | u8 rval[4]; | |
2679 | int sec; | |
2680 | ||
2681 | if (os_get_random(rval, sizeof(rval)) < 0) | |
2682 | sec = os_random() % 60; | |
2683 | else | |
2684 | sec = WPA_GET_BE32(rval) % 60; | |
f049052b BG |
2685 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " |
2686 | "report %d seconds", sec); | |
46690a3b JM |
2687 | wpa_s->pending_mic_error_report = 1; |
2688 | wpa_s->pending_mic_error_pairwise = pairwise; | |
2689 | eloop_cancel_timeout( | |
2690 | wpa_supplicant_delayed_mic_error_report, | |
2691 | wpa_s, NULL); | |
2692 | eloop_register_timeout( | |
2693 | sec, os_random() % 1000000, | |
2694 | wpa_supplicant_delayed_mic_error_report, | |
2695 | wpa_s, NULL); | |
2696 | } else { | |
2697 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
2698 | } | |
2699 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
2700 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
2701 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
6fc6879b | 2702 | } |
6473e5c8 | 2703 | wpa_s->last_michael_mic_error = t; |
46690a3b | 2704 | wpa_s->mic_errors_seen++; |
6fc6879b JM |
2705 | } |
2706 | ||
2707 | ||
a83d9c96 SL |
2708 | #ifdef CONFIG_TERMINATE_ONLASTIF |
2709 | static int any_interfaces(struct wpa_supplicant *head) | |
2710 | { | |
2711 | struct wpa_supplicant *wpa_s; | |
2712 | ||
2713 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) | |
2714 | if (!wpa_s->interface_removed) | |
2715 | return 1; | |
2716 | return 0; | |
2717 | } | |
2718 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
2719 | ||
2720 | ||
6fc6879b JM |
2721 | static void |
2722 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, | |
2723 | union wpa_event_data *data) | |
2724 | { | |
2725 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) | |
2726 | return; | |
2727 | ||
2728 | switch (data->interface_status.ievent) { | |
2729 | case EVENT_INTERFACE_ADDED: | |
2730 | if (!wpa_s->interface_removed) | |
2731 | break; | |
2732 | wpa_s->interface_removed = 0; | |
f049052b | 2733 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); |
6fc6879b | 2734 | if (wpa_supplicant_driver_init(wpa_s) < 0) { |
f049052b BG |
2735 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " |
2736 | "driver after interface was added"); | |
6fc6879b | 2737 | } |
f43c1ae7 IP |
2738 | |
2739 | #ifdef CONFIG_P2P | |
2740 | if (!wpa_s->global->p2p && | |
2741 | !wpa_s->global->p2p_disabled && | |
2742 | !wpa_s->conf->p2p_disabled && | |
2743 | (wpa_s->drv_flags & | |
2744 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && | |
2745 | wpas_p2p_add_p2pdev_interface( | |
2746 | wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) { | |
2747 | wpa_printf(MSG_INFO, | |
2748 | "P2P: Failed to enable P2P Device interface"); | |
2749 | /* Try to continue without. P2P will be disabled. */ | |
2750 | } | |
2751 | #endif /* CONFIG_P2P */ | |
2752 | ||
6fc6879b JM |
2753 | break; |
2754 | case EVENT_INTERFACE_REMOVED: | |
f049052b | 2755 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); |
6fc6879b JM |
2756 | wpa_s->interface_removed = 1; |
2757 | wpa_supplicant_mark_disassoc(wpa_s); | |
cb6710a4 | 2758 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
6fc6879b JM |
2759 | l2_packet_deinit(wpa_s->l2); |
2760 | wpa_s->l2 = NULL; | |
f43c1ae7 IP |
2761 | |
2762 | #ifdef CONFIG_P2P | |
2763 | if (wpa_s->global->p2p && | |
2764 | wpa_s->global->p2p_init_wpa_s->parent == wpa_s && | |
2765 | (wpa_s->drv_flags & | |
2766 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) { | |
2767 | wpa_dbg(wpa_s, MSG_DEBUG, | |
2768 | "Removing P2P Device interface"); | |
2769 | wpa_supplicant_remove_iface( | |
2770 | wpa_s->global, wpa_s->global->p2p_init_wpa_s, | |
2771 | 0); | |
2772 | wpa_s->global->p2p_init_wpa_s = NULL; | |
2773 | } | |
2774 | #endif /* CONFIG_P2P */ | |
2775 | ||
2e997eec RM |
2776 | #ifdef CONFIG_MATCH_IFACE |
2777 | if (wpa_s->matched) { | |
2778 | wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0); | |
2779 | break; | |
2780 | } | |
2781 | #endif /* CONFIG_MATCH_IFACE */ | |
2782 | ||
a83d9c96 SL |
2783 | #ifdef CONFIG_TERMINATE_ONLASTIF |
2784 | /* check if last interface */ | |
2785 | if (!any_interfaces(wpa_s->global->ifaces)) | |
2786 | eloop_terminate(); | |
2787 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
6fc6879b JM |
2788 | break; |
2789 | } | |
2790 | } | |
2791 | ||
2792 | ||
2793 | #ifdef CONFIG_PEERKEY | |
2794 | static void | |
2795 | wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, | |
2796 | union wpa_event_data *data) | |
2797 | { | |
2798 | if (data == NULL) | |
2799 | return; | |
2800 | wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); | |
2801 | } | |
2802 | #endif /* CONFIG_PEERKEY */ | |
2803 | ||
2804 | ||
281ff0aa GP |
2805 | #ifdef CONFIG_TDLS |
2806 | static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, | |
2807 | union wpa_event_data *data) | |
2808 | { | |
2809 | if (data == NULL) | |
2810 | return; | |
2811 | switch (data->tdls.oper) { | |
2812 | case TDLS_REQUEST_SETUP: | |
3887878e SD |
2813 | wpa_tdls_remove(wpa_s->wpa, data->tdls.peer); |
2814 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
2815 | wpa_tdls_start(wpa_s->wpa, data->tdls.peer); | |
2816 | else | |
2817 | wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer); | |
281ff0aa GP |
2818 | break; |
2819 | case TDLS_REQUEST_TEARDOWN: | |
f130b105 SD |
2820 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
2821 | wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer, | |
2822 | data->tdls.reason_code); | |
2823 | else | |
2824 | wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, | |
2825 | data->tdls.peer); | |
281ff0aa | 2826 | break; |
c10ca2a6 SD |
2827 | case TDLS_REQUEST_DISCOVER: |
2828 | wpa_tdls_send_discovery_request(wpa_s->wpa, | |
2829 | data->tdls.peer); | |
2830 | break; | |
281ff0aa GP |
2831 | } |
2832 | } | |
2833 | #endif /* CONFIG_TDLS */ | |
2834 | ||
2835 | ||
ad3872a3 | 2836 | #ifdef CONFIG_WNM |
75cad1a0 XC |
2837 | static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s, |
2838 | union wpa_event_data *data) | |
2839 | { | |
2840 | if (data == NULL) | |
2841 | return; | |
2842 | switch (data->wnm.oper) { | |
2843 | case WNM_OPER_SLEEP: | |
2844 | wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request " | |
2845 | "(action=%d, intval=%d)", | |
2846 | data->wnm.sleep_action, data->wnm.sleep_intval); | |
2847 | ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action, | |
cd0ef657 | 2848 | data->wnm.sleep_intval, NULL); |
75cad1a0 XC |
2849 | break; |
2850 | } | |
2851 | } | |
ad3872a3 | 2852 | #endif /* CONFIG_WNM */ |
75cad1a0 XC |
2853 | |
2854 | ||
6fc6879b JM |
2855 | #ifdef CONFIG_IEEE80211R |
2856 | static void | |
2857 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, | |
2858 | union wpa_event_data *data) | |
2859 | { | |
2860 | if (data == NULL) | |
2861 | return; | |
2862 | ||
2863 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, | |
2864 | data->ft_ies.ies_len, | |
2865 | data->ft_ies.ft_action, | |
babfbf15 JM |
2866 | data->ft_ies.target_ap, |
2867 | data->ft_ies.ric_ies, | |
2868 | data->ft_ies.ric_ies_len) < 0) { | |
6fc6879b JM |
2869 | /* TODO: prevent MLME/driver from trying to associate? */ |
2870 | } | |
2871 | } | |
2872 | #endif /* CONFIG_IEEE80211R */ | |
2873 | ||
2874 | ||
11ef8d35 JM |
2875 | #ifdef CONFIG_IBSS_RSN |
2876 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, | |
2877 | union wpa_event_data *data) | |
2878 | { | |
df4bc509 | 2879 | struct wpa_ssid *ssid; |
df418245 XC |
2880 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
2881 | return; | |
11ef8d35 JM |
2882 | if (data == NULL) |
2883 | return; | |
df4bc509 JM |
2884 | ssid = wpa_s->current_ssid; |
2885 | if (ssid == NULL) | |
2886 | return; | |
2887 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
2888 | return; | |
2889 | ||
11ef8d35 JM |
2890 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); |
2891 | } | |
13adc57b AQ |
2892 | |
2893 | ||
2894 | static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s, | |
2895 | union wpa_event_data *data) | |
2896 | { | |
2897 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2898 | ||
2899 | if (ssid == NULL) | |
2900 | return; | |
2901 | ||
2902 | /* check if the ssid is correctly configured as IBSS/RSN */ | |
2903 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
2904 | return; | |
2905 | ||
2906 | ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame, | |
2907 | data->rx_mgmt.frame_len); | |
2908 | } | |
11ef8d35 JM |
2909 | #endif /* CONFIG_IBSS_RSN */ |
2910 | ||
2911 | ||
036f7c4a JM |
2912 | #ifdef CONFIG_IEEE80211R |
2913 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, | |
2914 | size_t len) | |
2915 | { | |
2916 | const u8 *sta_addr, *target_ap_addr; | |
2917 | u16 status; | |
2918 | ||
2919 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); | |
2920 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
2921 | return; /* only SME case supported for now */ | |
2922 | if (len < 1 + 2 * ETH_ALEN + 2) | |
2923 | return; | |
2924 | if (data[0] != 2) | |
2925 | return; /* Only FT Action Response is supported for now */ | |
2926 | sta_addr = data + 1; | |
2927 | target_ap_addr = data + 1 + ETH_ALEN; | |
2928 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); | |
f049052b BG |
2929 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " |
2930 | MACSTR " TargetAP " MACSTR " status %u", | |
2931 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); | |
036f7c4a JM |
2932 | |
2933 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { | |
f049052b BG |
2934 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR |
2935 | " in FT Action Response", MAC2STR(sta_addr)); | |
036f7c4a JM |
2936 | return; |
2937 | } | |
2938 | ||
2939 | if (status) { | |
f049052b BG |
2940 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " |
2941 | "failure (status code %d)", status); | |
036f7c4a JM |
2942 | /* TODO: report error to FT code(?) */ |
2943 | return; | |
2944 | } | |
2945 | ||
2946 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, | |
2947 | len - (1 + 2 * ETH_ALEN + 2), 1, | |
2948 | target_ap_addr, NULL, 0) < 0) | |
2949 | return; | |
2950 | ||
fe191985 JM |
2951 | #ifdef CONFIG_SME |
2952 | { | |
2953 | struct wpa_bss *bss; | |
2954 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); | |
2955 | if (bss) | |
2956 | wpa_s->sme.freq = bss->freq; | |
62c72d72 | 2957 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
fe191985 JM |
2958 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
2959 | WLAN_AUTH_FT); | |
2960 | } | |
2961 | #endif /* CONFIG_SME */ | |
036f7c4a JM |
2962 | } |
2963 | #endif /* CONFIG_IEEE80211R */ | |
2964 | ||
2965 | ||
7d878ca7 JM |
2966 | static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, |
2967 | struct unprot_deauth *e) | |
2968 | { | |
2969 | #ifdef CONFIG_IEEE80211W | |
2970 | wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " | |
2971 | "dropped: " MACSTR " -> " MACSTR | |
2972 | " (reason code %u)", | |
2973 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
2974 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
2975 | #endif /* CONFIG_IEEE80211W */ | |
2976 | } | |
2977 | ||
2978 | ||
2979 | static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, | |
2980 | struct unprot_disassoc *e) | |
2981 | { | |
2982 | #ifdef CONFIG_IEEE80211W | |
2983 | wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " | |
2984 | "dropped: " MACSTR " -> " MACSTR | |
2985 | " (reason code %u)", | |
2986 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
2987 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
2988 | #endif /* CONFIG_IEEE80211W */ | |
2989 | } | |
2990 | ||
2991 | ||
d7df0fa7 JM |
2992 | static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr, |
2993 | u16 reason_code, int locally_generated, | |
2994 | const u8 *ie, size_t ie_len, int deauth) | |
2995 | { | |
2996 | #ifdef CONFIG_AP | |
2997 | if (wpa_s->ap_iface && addr) { | |
2998 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr); | |
2999 | return; | |
3000 | } | |
3001 | ||
3002 | if (wpa_s->ap_iface) { | |
3003 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode"); | |
3004 | return; | |
3005 | } | |
3006 | #endif /* CONFIG_AP */ | |
3007 | ||
c2805909 JM |
3008 | if (!locally_generated) |
3009 | wpa_s->own_disconnect_req = 0; | |
3010 | ||
d7df0fa7 JM |
3011 | wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated); |
3012 | ||
c60ba9f7 JM |
3013 | if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED || |
3014 | ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || | |
3015 | (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) && | |
3016 | eapol_sm_failed(wpa_s->eapol))) && | |
3017 | !wpa_s->eap_expected_failure)) | |
b19c098e | 3018 | wpas_auth_failed(wpa_s, "AUTH_FAILED"); |
d7df0fa7 JM |
3019 | |
3020 | #ifdef CONFIG_P2P | |
43ee4704 | 3021 | if (deauth && reason_code > 0) { |
d7df0fa7 JM |
3022 | if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len, |
3023 | locally_generated) > 0) { | |
3024 | /* | |
3025 | * The interface was removed, so cannot continue | |
3026 | * processing any additional operations after this. | |
3027 | */ | |
3028 | return; | |
3029 | } | |
3030 | } | |
3031 | #endif /* CONFIG_P2P */ | |
3032 | ||
3033 | wpa_supplicant_event_disassoc_finish(wpa_s, reason_code, | |
3034 | locally_generated); | |
3035 | } | |
3036 | ||
3037 | ||
3038 | static void wpas_event_disassoc(struct wpa_supplicant *wpa_s, | |
3039 | struct disassoc_info *info) | |
3040 | { | |
3041 | u16 reason_code = 0; | |
3042 | int locally_generated = 0; | |
3043 | const u8 *addr = NULL; | |
3044 | const u8 *ie = NULL; | |
3045 | size_t ie_len = 0; | |
3046 | ||
3047 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); | |
3048 | ||
3049 | if (info) { | |
3050 | addr = info->addr; | |
3051 | ie = info->ie; | |
3052 | ie_len = info->ie_len; | |
3053 | reason_code = info->reason_code; | |
3054 | locally_generated = info->locally_generated; | |
3055 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code, | |
3056 | locally_generated ? " (locally generated)" : ""); | |
3057 | if (addr) | |
3058 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, | |
3059 | MAC2STR(addr)); | |
3060 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", | |
3061 | ie, ie_len); | |
3062 | } | |
3063 | ||
3064 | #ifdef CONFIG_AP | |
3065 | if (wpa_s->ap_iface && info && info->addr) { | |
3066 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr); | |
3067 | return; | |
3068 | } | |
3069 | ||
3070 | if (wpa_s->ap_iface) { | |
3071 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode"); | |
3072 | return; | |
3073 | } | |
3074 | #endif /* CONFIG_AP */ | |
3075 | ||
3076 | #ifdef CONFIG_P2P | |
3077 | if (info) { | |
3078 | wpas_p2p_disassoc_notif( | |
3079 | wpa_s, info->addr, reason_code, info->ie, info->ie_len, | |
3080 | locally_generated); | |
3081 | } | |
3082 | #endif /* CONFIG_P2P */ | |
3083 | ||
3084 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) | |
3085 | sme_event_disassoc(wpa_s, info); | |
3086 | ||
3087 | wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated, | |
3088 | ie, ie_len, 0); | |
3089 | } | |
3090 | ||
3091 | ||
3092 | static void wpas_event_deauth(struct wpa_supplicant *wpa_s, | |
3093 | struct deauth_info *info) | |
3094 | { | |
3095 | u16 reason_code = 0; | |
3096 | int locally_generated = 0; | |
3097 | const u8 *addr = NULL; | |
3098 | const u8 *ie = NULL; | |
3099 | size_t ie_len = 0; | |
3100 | ||
3101 | wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification"); | |
3102 | ||
3103 | if (info) { | |
3104 | addr = info->addr; | |
3105 | ie = info->ie; | |
3106 | ie_len = info->ie_len; | |
3107 | reason_code = info->reason_code; | |
3108 | locally_generated = info->locally_generated; | |
3109 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", | |
3110 | reason_code, | |
3111 | locally_generated ? " (locally generated)" : ""); | |
3112 | if (addr) { | |
3113 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, | |
3114 | MAC2STR(addr)); | |
3115 | } | |
3116 | wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)", | |
3117 | ie, ie_len); | |
3118 | } | |
3119 | ||
3120 | wpa_reset_ft_completed(wpa_s->wpa); | |
3121 | ||
3122 | wpas_event_disconnect(wpa_s, addr, reason_code, | |
3123 | locally_generated, ie, ie_len, 1); | |
3124 | } | |
3125 | ||
3126 | ||
142817b2 JM |
3127 | static const char * reg_init_str(enum reg_change_initiator init) |
3128 | { | |
3129 | switch (init) { | |
3130 | case REGDOM_SET_BY_CORE: | |
3131 | return "CORE"; | |
3132 | case REGDOM_SET_BY_USER: | |
3133 | return "USER"; | |
3134 | case REGDOM_SET_BY_DRIVER: | |
3135 | return "DRIVER"; | |
3136 | case REGDOM_SET_BY_COUNTRY_IE: | |
3137 | return "COUNTRY_IE"; | |
3138 | case REGDOM_BEACON_HINT: | |
3139 | return "BEACON_HINT"; | |
3140 | } | |
3141 | return "?"; | |
3142 | } | |
3143 | ||
3144 | ||
3145 | static const char * reg_type_str(enum reg_type type) | |
3146 | { | |
3147 | switch (type) { | |
3148 | case REGDOM_TYPE_UNKNOWN: | |
3149 | return "UNKNOWN"; | |
3150 | case REGDOM_TYPE_COUNTRY: | |
3151 | return "COUNTRY"; | |
3152 | case REGDOM_TYPE_WORLD: | |
3153 | return "WORLD"; | |
3154 | case REGDOM_TYPE_CUSTOM_WORLD: | |
3155 | return "CUSTOM_WORLD"; | |
3156 | case REGDOM_TYPE_INTERSECTION: | |
3157 | return "INTERSECTION"; | |
3158 | } | |
3159 | return "?"; | |
3160 | } | |
3161 | ||
3162 | ||
3163 | static void wpa_supplicant_update_channel_list( | |
3164 | struct wpa_supplicant *wpa_s, struct channel_list_changed *info) | |
731ca636 | 3165 | { |
731ca636 VKE |
3166 | struct wpa_supplicant *ifs; |
3167 | ||
142817b2 | 3168 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s", |
42619d68 | 3169 | reg_init_str(info->initiator), reg_type_str(info->type), |
142817b2 JM |
3170 | info->alpha2[0] ? " alpha2=" : "", |
3171 | info->alpha2[0] ? info->alpha2 : ""); | |
3172 | ||
731ca636 VKE |
3173 | if (wpa_s->drv_priv == NULL) |
3174 | return; /* Ignore event during drv initialization */ | |
3175 | ||
c67e7e2a JM |
3176 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
3177 | radio_list) { | |
0f4bccdb AN |
3178 | wpa_printf(MSG_DEBUG, "%s: Updating hw mode", |
3179 | ifs->ifname); | |
3180 | free_hw_features(ifs); | |
3181 | ifs->hw.modes = wpa_drv_get_hw_feature_data( | |
3182 | ifs, &ifs->hw.num_modes, &ifs->hw.flags); | |
731ca636 | 3183 | } |
6ceea4c3 VG |
3184 | |
3185 | /* Restart sched_scan with updated channel list */ | |
3186 | if (wpa_s->sched_scanning) { | |
3187 | wpa_dbg(wpa_s, MSG_DEBUG, | |
3188 | "Channel list changed restart sched scan."); | |
3189 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3190 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
3191 | } | |
0f4bccdb | 3192 | |
3a8f008a | 3193 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER); |
731ca636 VKE |
3194 | } |
3195 | ||
3196 | ||
dbfb8e82 | 3197 | static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s, |
70d1e728 AO |
3198 | const u8 *frame, size_t len, int freq, |
3199 | int rssi) | |
dbfb8e82 | 3200 | { |
70d95373 | 3201 | const struct ieee80211_mgmt *mgmt; |
dbfb8e82 JM |
3202 | const u8 *payload; |
3203 | size_t plen; | |
3204 | u8 category; | |
3205 | ||
3206 | if (len < IEEE80211_HDRLEN + 2) | |
3207 | return; | |
3208 | ||
70d95373 JM |
3209 | mgmt = (const struct ieee80211_mgmt *) frame; |
3210 | payload = frame + IEEE80211_HDRLEN; | |
dbfb8e82 | 3211 | category = *payload++; |
70d95373 | 3212 | plen = len - IEEE80211_HDRLEN - 1; |
dbfb8e82 JM |
3213 | |
3214 | wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR | |
3215 | " Category=%u DataLen=%d freq=%d MHz", | |
3216 | MAC2STR(mgmt->sa), category, (int) plen, freq); | |
3217 | ||
d1f88001 MB |
3218 | if (category == WLAN_ACTION_WMM) { |
3219 | wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen); | |
3220 | return; | |
3221 | } | |
3222 | ||
dbfb8e82 JM |
3223 | #ifdef CONFIG_IEEE80211R |
3224 | if (category == WLAN_ACTION_FT) { | |
3225 | ft_rx_action(wpa_s, payload, plen); | |
3226 | return; | |
3227 | } | |
3228 | #endif /* CONFIG_IEEE80211R */ | |
3229 | ||
3230 | #ifdef CONFIG_IEEE80211W | |
3231 | #ifdef CONFIG_SME | |
3232 | if (category == WLAN_ACTION_SA_QUERY) { | |
3233 | sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen); | |
3234 | return; | |
3235 | } | |
3236 | #endif /* CONFIG_SME */ | |
3237 | #endif /* CONFIG_IEEE80211W */ | |
3238 | ||
3239 | #ifdef CONFIG_WNM | |
3240 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { | |
3241 | ieee802_11_rx_wnm_action(wpa_s, mgmt, len); | |
3242 | return; | |
3243 | } | |
3244 | #endif /* CONFIG_WNM */ | |
3245 | ||
3246 | #ifdef CONFIG_GAS | |
c5a64e2d JM |
3247 | if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC || |
3248 | mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) && | |
dbfb8e82 | 3249 | gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid, |
c5a64e2d | 3250 | mgmt->u.action.category, |
dbfb8e82 JM |
3251 | payload, plen, freq) == 0) |
3252 | return; | |
3253 | #endif /* CONFIG_GAS */ | |
3254 | ||
3255 | #ifdef CONFIG_TDLS | |
3256 | if (category == WLAN_ACTION_PUBLIC && plen >= 4 && | |
3257 | payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { | |
3258 | wpa_dbg(wpa_s, MSG_DEBUG, | |
3259 | "TDLS: Received Discovery Response from " MACSTR, | |
3260 | MAC2STR(mgmt->sa)); | |
3261 | return; | |
3262 | } | |
3263 | #endif /* CONFIG_TDLS */ | |
3264 | ||
3265 | #ifdef CONFIG_INTERWORKING | |
3266 | if (category == WLAN_ACTION_QOS && plen >= 1 && | |
3267 | payload[0] == QOS_QOS_MAP_CONFIG) { | |
3268 | const u8 *pos = payload + 1; | |
3269 | size_t qlen = plen - 1; | |
3270 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from " | |
3271 | MACSTR, MAC2STR(mgmt->sa)); | |
3272 | if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 && | |
3273 | qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET && | |
3274 | pos[1] <= qlen - 2 && pos[1] >= 16) | |
3275 | wpas_qos_map_set(wpa_s, pos + 2, pos[1]); | |
3276 | return; | |
3277 | } | |
3278 | #endif /* CONFIG_INTERWORKING */ | |
3279 | ||
d89c0701 AK |
3280 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
3281 | payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) { | |
3282 | wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1); | |
3283 | return; | |
3284 | } | |
3285 | ||
70d1e728 AO |
3286 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
3287 | payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) { | |
3288 | wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa, | |
3289 | payload + 1, plen - 1, | |
3290 | rssi); | |
3291 | return; | |
3292 | } | |
3293 | ||
9fbfd1b0 AN |
3294 | #ifdef CONFIG_FST |
3295 | if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) { | |
3296 | fst_rx_action(wpa_s->fst, mgmt, len); | |
3297 | return; | |
3298 | } | |
3299 | #endif /* CONFIG_FST */ | |
3300 | ||
dbfb8e82 JM |
3301 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
3302 | category, payload, plen, freq); | |
5f92659d BC |
3303 | if (wpa_s->ifmsh) |
3304 | mesh_mpm_action_rx(wpa_s, mgmt, len); | |
dbfb8e82 JM |
3305 | } |
3306 | ||
3307 | ||
253f2e37 AH |
3308 | static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s, |
3309 | union wpa_event_data *event) | |
3310 | { | |
253f2e37 AH |
3311 | struct wpa_freq_range_list *list; |
3312 | char *str = NULL; | |
3313 | ||
3314 | list = &event->freq_range; | |
3315 | ||
3316 | if (list->num) | |
3317 | str = freq_range_list_str(list); | |
3318 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s", | |
3319 | str ? str : ""); | |
3320 | ||
3321 | #ifdef CONFIG_P2P | |
3322 | if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) { | |
3323 | wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range", | |
3324 | __func__); | |
3325 | } else { | |
3326 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event"); | |
253f2e37 | 3327 | |
a7160f7e IP |
3328 | /* |
3329 | * The update channel flow will also take care of moving a GO | |
3330 | * from the unsafe frequency if needed. | |
3331 | */ | |
3a8f008a IP |
3332 | wpas_p2p_update_channel_list(wpa_s, |
3333 | WPAS_P2P_CHANNEL_UPDATE_AVOID); | |
253f2e37 AH |
3334 | } |
3335 | #endif /* CONFIG_P2P */ | |
3336 | ||
3337 | os_free(str); | |
3338 | } | |
3339 | ||
3340 | ||
b41f2684 CL |
3341 | static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s, |
3342 | union wpa_event_data *data) | |
3343 | { | |
3344 | wpa_dbg(wpa_s, MSG_DEBUG, | |
3345 | "Connection authorized by device, previous state %d", | |
3346 | wpa_s->wpa_state); | |
3347 | if (wpa_s->wpa_state == WPA_ASSOCIATED) { | |
3348 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
3349 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
3350 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
3351 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
3352 | } | |
3353 | wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr); | |
3354 | wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck, | |
98cd3d1c JM |
3355 | data->assoc_info.ptk_kck_len, |
3356 | data->assoc_info.ptk_kek, | |
3357 | data->assoc_info.ptk_kek_len); | |
b41f2684 CL |
3358 | } |
3359 | ||
3360 | ||
9646a8ab | 3361 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
6fc6879b JM |
3362 | union wpa_event_data *data) |
3363 | { | |
3364 | struct wpa_supplicant *wpa_s = ctx; | |
02e122a9 | 3365 | int resched; |
6fc6879b | 3366 | |
8401a6b0 JM |
3367 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
3368 | event != EVENT_INTERFACE_ENABLED && | |
9b6f44cb | 3369 | event != EVENT_INTERFACE_STATUS && |
1446afc8 | 3370 | event != EVENT_SCAN_RESULTS && |
9b6f44cb | 3371 | event != EVENT_SCHED_SCAN_STOPPED) { |
6c3771d7 BG |
3372 | wpa_dbg(wpa_s, MSG_DEBUG, |
3373 | "Ignore event %s (%d) while interface is disabled", | |
3374 | event_to_string(event), event); | |
8401a6b0 JM |
3375 | return; |
3376 | } | |
3377 | ||
74781dfc JM |
3378 | #ifndef CONFIG_NO_STDOUT_DEBUG |
3379 | { | |
3380 | int level = MSG_DEBUG; | |
3381 | ||
eab6f5e0 | 3382 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) { |
74781dfc JM |
3383 | const struct ieee80211_hdr *hdr; |
3384 | u16 fc; | |
3385 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; | |
3386 | fc = le_to_host16(hdr->frame_control); | |
3387 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
3388 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
3389 | level = MSG_EXCESSIVE; | |
3390 | } | |
3391 | ||
3392 | wpa_dbg(wpa_s, level, "Event %s (%d) received", | |
6c3771d7 | 3393 | event_to_string(event), event); |
74781dfc JM |
3394 | } |
3395 | #endif /* CONFIG_NO_STDOUT_DEBUG */ | |
9b7124b2 | 3396 | |
6fc6879b | 3397 | switch (event) { |
c2a04078 | 3398 | case EVENT_AUTH: |
ea708118 | 3399 | #ifdef CONFIG_FST |
58059e6c JM |
3400 | if (!wpas_fst_update_mbie(wpa_s, data->auth.ies, |
3401 | data->auth.ies_len)) | |
3402 | wpa_printf(MSG_DEBUG, | |
3403 | "FST: MB IEs updated from auth IE"); | |
ea708118 | 3404 | #endif /* CONFIG_FST */ |
c2a04078 JM |
3405 | sme_event_auth(wpa_s, data); |
3406 | break; | |
6fc6879b JM |
3407 | case EVENT_ASSOC: |
3408 | wpa_supplicant_event_assoc(wpa_s, data); | |
b41f2684 CL |
3409 | if (data && data->assoc_info.authorized) |
3410 | wpa_supplicant_event_assoc_auth(wpa_s, data); | |
f32227ed RJ |
3411 | if (data) { |
3412 | wpa_msg(wpa_s, MSG_INFO, | |
3413 | WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u", | |
3414 | data->assoc_info.subnet_status); | |
3415 | } | |
6fc6879b JM |
3416 | break; |
3417 | case EVENT_DISASSOC: | |
d7df0fa7 JM |
3418 | wpas_event_disassoc(wpa_s, |
3419 | data ? &data->disassoc_info : NULL); | |
3420 | break; | |
a84ed99e | 3421 | case EVENT_DEAUTH: |
d7df0fa7 JM |
3422 | wpas_event_deauth(wpa_s, |
3423 | data ? &data->deauth_info : NULL); | |
6fc6879b JM |
3424 | break; |
3425 | case EVENT_MICHAEL_MIC_FAILURE: | |
3426 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); | |
3427 | break; | |
3428 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
a5f40eff | 3429 | case EVENT_SCAN_STARTED: |
adcd7c4b KV |
3430 | if (wpa_s->own_scan_requested || |
3431 | (data && !data->scan_info.external_scan)) { | |
dc3906cb JM |
3432 | struct os_reltime diff; |
3433 | ||
adcd7c4b | 3434 | os_get_reltime(&wpa_s->scan_start_time); |
dc3906cb JM |
3435 | os_reltime_sub(&wpa_s->scan_start_time, |
3436 | &wpa_s->scan_trigger_time, &diff); | |
3437 | wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds", | |
3438 | diff.sec, diff.usec); | |
a5f40eff JM |
3439 | wpa_s->own_scan_requested = 0; |
3440 | wpa_s->own_scan_running = 1; | |
d81c73be JM |
3441 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
3442 | wpa_s->manual_scan_use_id) { | |
abc05534 DS |
3443 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
3444 | WPA_EVENT_SCAN_STARTED "id=%u", | |
3445 | wpa_s->manual_scan_id); | |
d81c73be | 3446 | } else { |
abc05534 DS |
3447 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
3448 | WPA_EVENT_SCAN_STARTED); | |
d81c73be | 3449 | } |
a5f40eff JM |
3450 | } else { |
3451 | wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan"); | |
d90bfa97 | 3452 | wpa_s->radio->external_scan_running = 1; |
abc05534 | 3453 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED); |
a5f40eff JM |
3454 | } |
3455 | break; | |
6fc6879b | 3456 | case EVENT_SCAN_RESULTS: |
1446afc8 IP |
3457 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
3458 | wpa_s->scan_res_handler = NULL; | |
3459 | wpa_s->own_scan_running = 0; | |
3460 | wpa_s->radio->external_scan_running = 0; | |
3461 | wpa_s->last_scan_req = NORMAL_SCAN_REQ; | |
3462 | break; | |
3463 | } | |
3464 | ||
adcd7c4b KV |
3465 | if (!(data && data->scan_info.external_scan) && |
3466 | os_reltime_initialized(&wpa_s->scan_start_time)) { | |
dc3906cb JM |
3467 | struct os_reltime now, diff; |
3468 | os_get_reltime(&now); | |
3469 | os_reltime_sub(&now, &wpa_s->scan_start_time, &diff); | |
3470 | wpa_s->scan_start_time.sec = 0; | |
3471 | wpa_s->scan_start_time.usec = 0; | |
3472 | wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds", | |
3473 | diff.sec, diff.usec); | |
3474 | } | |
b0e669be JM |
3475 | if (wpa_supplicant_event_scan_results(wpa_s, data)) |
3476 | break; /* interface may have been removed */ | |
adcd7c4b KV |
3477 | if (!(data && data->scan_info.external_scan)) |
3478 | wpa_s->own_scan_running = 0; | |
3479 | if (data && data->scan_info.nl_scan_event) | |
3480 | wpa_s->radio->external_scan_running = 0; | |
6428d0a7 | 3481 | radio_work_check_next(wpa_s); |
6fc6879b JM |
3482 | break; |
3483 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
3484 | case EVENT_ASSOCINFO: | |
3485 | wpa_supplicant_event_associnfo(wpa_s, data); | |
3486 | break; | |
3487 | case EVENT_INTERFACE_STATUS: | |
3488 | wpa_supplicant_event_interface_status(wpa_s, data); | |
3489 | break; | |
3490 | case EVENT_PMKID_CANDIDATE: | |
3491 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); | |
3492 | break; | |
3493 | #ifdef CONFIG_PEERKEY | |
3494 | case EVENT_STKSTART: | |
3495 | wpa_supplicant_event_stkstart(wpa_s, data); | |
3496 | break; | |
3497 | #endif /* CONFIG_PEERKEY */ | |
281ff0aa GP |
3498 | #ifdef CONFIG_TDLS |
3499 | case EVENT_TDLS: | |
3500 | wpa_supplicant_event_tdls(wpa_s, data); | |
3501 | break; | |
3502 | #endif /* CONFIG_TDLS */ | |
ad3872a3 | 3503 | #ifdef CONFIG_WNM |
75cad1a0 XC |
3504 | case EVENT_WNM: |
3505 | wpa_supplicant_event_wnm(wpa_s, data); | |
3506 | break; | |
ad3872a3 | 3507 | #endif /* CONFIG_WNM */ |
6fc6879b JM |
3508 | #ifdef CONFIG_IEEE80211R |
3509 | case EVENT_FT_RESPONSE: | |
3510 | wpa_supplicant_event_ft_response(wpa_s, data); | |
3511 | break; | |
3512 | #endif /* CONFIG_IEEE80211R */ | |
11ef8d35 JM |
3513 | #ifdef CONFIG_IBSS_RSN |
3514 | case EVENT_IBSS_RSN_START: | |
3515 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); | |
3516 | break; | |
3517 | #endif /* CONFIG_IBSS_RSN */ | |
efa46078 | 3518 | case EVENT_ASSOC_REJECT: |
c05d6d18 JM |
3519 | if (data->assoc_reject.bssid) |
3520 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
3521 | "bssid=" MACSTR " status_code=%u", | |
3522 | MAC2STR(data->assoc_reject.bssid), | |
3523 | data->assoc_reject.status_code); | |
3524 | else | |
3525 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
3526 | "status_code=%u", | |
3527 | data->assoc_reject.status_code); | |
c7fb678f NS |
3528 | wpa_s->assoc_status_code = data->assoc_reject.status_code; |
3529 | wpas_notify_assoc_status_code(wpa_s); | |
ea78c315 JM |
3530 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
3531 | sme_event_assoc_reject(wpa_s, data); | |
10737aba JM |
3532 | else { |
3533 | const u8 *bssid = data->assoc_reject.bssid; | |
3534 | if (bssid == NULL || is_zero_ether_addr(bssid)) | |
3535 | bssid = wpa_s->pending_bssid; | |
3536 | wpas_connection_failed(wpa_s, bssid); | |
3537 | wpa_supplicant_mark_disassoc(wpa_s); | |
3538 | } | |
efa46078 | 3539 | break; |
da1fb17c | 3540 | case EVENT_AUTH_TIMED_OUT: |
9a700ff9 JM |
3541 | /* It is possible to get this event from earlier connection */ |
3542 | if (wpa_s->current_ssid && | |
3543 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { | |
3544 | wpa_dbg(wpa_s, MSG_DEBUG, | |
3545 | "Ignore AUTH_TIMED_OUT in mesh configuration"); | |
3546 | break; | |
3547 | } | |
ea78c315 JM |
3548 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
3549 | sme_event_auth_timed_out(wpa_s, data); | |
da1fb17c JM |
3550 | break; |
3551 | case EVENT_ASSOC_TIMED_OUT: | |
9a700ff9 JM |
3552 | /* It is possible to get this event from earlier connection */ |
3553 | if (wpa_s->current_ssid && | |
3554 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { | |
3555 | wpa_dbg(wpa_s, MSG_DEBUG, | |
3556 | "Ignore ASSOC_TIMED_OUT in mesh configuration"); | |
3557 | break; | |
3558 | } | |
ea78c315 JM |
3559 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
3560 | sme_event_assoc_timed_out(wpa_s, data); | |
da1fb17c | 3561 | break; |
f8b1f695 | 3562 | case EVENT_TX_STATUS: |
f049052b BG |
3563 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR |
3564 | " type=%d stype=%d", | |
3565 | MAC2STR(data->tx_status.dst), | |
3566 | data->tx_status.type, data->tx_status.stype); | |
24f6497c | 3567 | #ifdef CONFIG_AP |
9bae1be0 | 3568 | if (wpa_s->ap_iface == NULL) { |
24f6497c | 3569 | #ifdef CONFIG_OFFCHANNEL |
9bae1be0 JM |
3570 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
3571 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) | |
24f6497c | 3572 | offchannel_send_action_tx_status( |
9bae1be0 JM |
3573 | wpa_s, data->tx_status.dst, |
3574 | data->tx_status.data, | |
3575 | data->tx_status.data_len, | |
93b7ddd0 | 3576 | data->tx_status.ack ? |
24f6497c JM |
3577 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
3578 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
3579 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
3580 | break; |
3581 | } | |
24f6497c JM |
3582 | #endif /* CONFIG_AP */ |
3583 | #ifdef CONFIG_OFFCHANNEL | |
f049052b BG |
3584 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" |
3585 | MACSTR, MAC2STR(wpa_s->parent->pending_action_dst)); | |
9bae1be0 JM |
3586 | /* |
3587 | * Catch TX status events for Action frames we sent via group | |
3588 | * interface in GO mode. | |
3589 | */ | |
3590 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && | |
3591 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && | |
3592 | os_memcmp(wpa_s->parent->pending_action_dst, | |
3593 | data->tx_status.dst, ETH_ALEN) == 0) { | |
24f6497c | 3594 | offchannel_send_action_tx_status( |
9bae1be0 JM |
3595 | wpa_s->parent, data->tx_status.dst, |
3596 | data->tx_status.data, | |
3597 | data->tx_status.data_len, | |
1d39378a | 3598 | data->tx_status.ack ? |
24f6497c JM |
3599 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
3600 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
f8b1f695 | 3601 | break; |
9bae1be0 | 3602 | } |
24f6497c JM |
3603 | #endif /* CONFIG_OFFCHANNEL */ |
3604 | #ifdef CONFIG_AP | |
f8b1f695 JM |
3605 | switch (data->tx_status.type) { |
3606 | case WLAN_FC_TYPE_MGMT: | |
3607 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, | |
3608 | data->tx_status.data_len, | |
3609 | data->tx_status.stype, | |
3610 | data->tx_status.ack); | |
3611 | break; | |
3612 | case WLAN_FC_TYPE_DATA: | |
3613 | ap_tx_status(wpa_s, data->tx_status.dst, | |
3614 | data->tx_status.data, | |
3615 | data->tx_status.data_len, | |
3616 | data->tx_status.ack); | |
3617 | break; | |
3618 | } | |
24f6497c | 3619 | #endif /* CONFIG_AP */ |
f8b1f695 | 3620 | break; |
24f6497c | 3621 | #ifdef CONFIG_AP |
dd840f79 JB |
3622 | case EVENT_EAPOL_TX_STATUS: |
3623 | ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst, | |
3624 | data->eapol_tx_status.data, | |
3625 | data->eapol_tx_status.data_len, | |
3626 | data->eapol_tx_status.ack); | |
3627 | break; | |
bcf24348 JB |
3628 | case EVENT_DRIVER_CLIENT_POLL_OK: |
3629 | ap_client_poll_ok(wpa_s, data->client_poll.addr); | |
3630 | break; | |
f8b1f695 JM |
3631 | case EVENT_RX_FROM_UNKNOWN: |
3632 | if (wpa_s->ap_iface == NULL) | |
3633 | break; | |
9b90955e JB |
3634 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, |
3635 | data->rx_from_unknown.wds); | |
f8b1f695 | 3636 | break; |
1b487b8b | 3637 | case EVENT_CH_SWITCH: |
61f121d9 | 3638 | if (!data || !wpa_s->current_ssid) |
1b487b8b | 3639 | break; |
1b487b8b | 3640 | |
61f121d9 IP |
3641 | wpa_s->assoc_freq = data->ch_switch.freq; |
3642 | wpa_s->current_ssid->frequency = data->ch_switch.freq; | |
3643 | ||
3644 | if (wpa_s->current_ssid->mode == WPAS_MODE_AP || | |
3645 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO || | |
3646 | wpa_s->current_ssid->mode == | |
3647 | WPAS_MODE_P2P_GROUP_FORMATION) { | |
3648 | wpas_ap_ch_switch(wpa_s, data->ch_switch.freq, | |
3649 | data->ch_switch.ht_enabled, | |
3650 | data->ch_switch.ch_offset, | |
3651 | data->ch_switch.ch_width, | |
3652 | data->ch_switch.cf1, | |
3653 | data->ch_switch.cf2); | |
3654 | } | |
3bafb0d8 AO |
3655 | |
3656 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS); | |
1b487b8b | 3657 | break; |
bd0f68c4 AK |
3658 | #ifdef NEED_AP_MLME |
3659 | case EVENT_DFS_RADAR_DETECTED: | |
3660 | if (data) | |
3661 | wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event); | |
3662 | break; | |
3663 | case EVENT_DFS_CAC_STARTED: | |
3664 | if (data) | |
3665 | wpas_event_dfs_cac_started(wpa_s, &data->dfs_event); | |
3666 | break; | |
3667 | case EVENT_DFS_CAC_FINISHED: | |
3668 | if (data) | |
3669 | wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event); | |
3670 | break; | |
3671 | case EVENT_DFS_CAC_ABORTED: | |
3672 | if (data) | |
3673 | wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event); | |
3674 | break; | |
3675 | case EVENT_DFS_NOP_FINISHED: | |
3676 | if (data) | |
3677 | wpas_event_dfs_cac_nop_finished(wpa_s, | |
3678 | &data->dfs_event); | |
3679 | break; | |
3680 | #endif /* NEED_AP_MLME */ | |
13adc57b | 3681 | #endif /* CONFIG_AP */ |
2d43d37f JB |
3682 | case EVENT_RX_MGMT: { |
3683 | u16 fc, stype; | |
3684 | const struct ieee80211_mgmt *mgmt; | |
3685 | ||
60b893df JM |
3686 | #ifdef CONFIG_TESTING_OPTIONS |
3687 | if (wpa_s->ext_mgmt_frame_handling) { | |
3688 | struct rx_mgmt *rx = &data->rx_mgmt; | |
3689 | size_t hex_len = 2 * rx->frame_len + 1; | |
3690 | char *hex = os_malloc(hex_len); | |
3691 | if (hex) { | |
3692 | wpa_snprintf_hex(hex, hex_len, | |
3693 | rx->frame, rx->frame_len); | |
3694 | wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s", | |
3695 | rx->freq, rx->datarate, rx->ssi_signal, | |
3696 | hex); | |
3697 | os_free(hex); | |
3698 | } | |
3699 | break; | |
3700 | } | |
3701 | #endif /* CONFIG_TESTING_OPTIONS */ | |
3702 | ||
2d43d37f JB |
3703 | mgmt = (const struct ieee80211_mgmt *) |
3704 | data->rx_mgmt.frame; | |
3705 | fc = le_to_host16(mgmt->frame_control); | |
3706 | stype = WLAN_FC_GET_STYPE(fc); | |
3707 | ||
13adc57b | 3708 | #ifdef CONFIG_AP |
9bae1be0 | 3709 | if (wpa_s->ap_iface == NULL) { |
13adc57b | 3710 | #endif /* CONFIG_AP */ |
9bae1be0 | 3711 | #ifdef CONFIG_P2P |
9bae1be0 | 3712 | if (stype == WLAN_FC_STYPE_PROBE_REQ && |
c01120a0 | 3713 | data->rx_mgmt.frame_len > IEEE80211_HDRLEN) { |
9bae1be0 | 3714 | const u8 *src = mgmt->sa; |
c01120a0 JM |
3715 | const u8 *ie; |
3716 | size_t ie_len; | |
3717 | ||
3718 | ie = data->rx_mgmt.frame + IEEE80211_HDRLEN; | |
3719 | ie_len = data->rx_mgmt.frame_len - | |
3720 | IEEE80211_HDRLEN; | |
baf513d6 JB |
3721 | wpas_p2p_probe_req_rx( |
3722 | wpa_s, src, mgmt->da, | |
3723 | mgmt->bssid, ie, ie_len, | |
734ddf61 | 3724 | data->rx_mgmt.freq, |
baf513d6 | 3725 | data->rx_mgmt.ssi_signal); |
9bae1be0 JM |
3726 | break; |
3727 | } | |
3728 | #endif /* CONFIG_P2P */ | |
13adc57b | 3729 | #ifdef CONFIG_IBSS_RSN |
5f92659d BC |
3730 | if (wpa_s->current_ssid && |
3731 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
3732 | stype == WLAN_FC_STYPE_AUTH && | |
13adc57b AQ |
3733 | data->rx_mgmt.frame_len >= 30) { |
3734 | wpa_supplicant_event_ibss_auth(wpa_s, data); | |
3735 | break; | |
3736 | } | |
3737 | #endif /* CONFIG_IBSS_RSN */ | |
dbfb8e82 JM |
3738 | |
3739 | if (stype == WLAN_FC_STYPE_ACTION) { | |
3740 | wpas_event_rx_mgmt_action( | |
70d95373 JM |
3741 | wpa_s, data->rx_mgmt.frame, |
3742 | data->rx_mgmt.frame_len, | |
70d1e728 AO |
3743 | data->rx_mgmt.freq, |
3744 | data->rx_mgmt.ssi_signal); | |
dbfb8e82 JM |
3745 | break; |
3746 | } | |
3747 | ||
5f92659d BC |
3748 | if (wpa_s->ifmsh) { |
3749 | mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt); | |
3750 | break; | |
3751 | } | |
3752 | ||
f049052b BG |
3753 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " |
3754 | "management frame in non-AP mode"); | |
f8b1f695 | 3755 | break; |
13adc57b | 3756 | #ifdef CONFIG_AP |
9bae1be0 | 3757 | } |
2d43d37f JB |
3758 | |
3759 | if (stype == WLAN_FC_STYPE_PROBE_REQ && | |
c01120a0 JM |
3760 | data->rx_mgmt.frame_len > IEEE80211_HDRLEN) { |
3761 | const u8 *ie; | |
3762 | size_t ie_len; | |
3763 | ||
3764 | ie = data->rx_mgmt.frame + IEEE80211_HDRLEN; | |
3765 | ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN; | |
2d43d37f JB |
3766 | |
3767 | wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da, | |
3768 | mgmt->bssid, ie, ie_len, | |
3769 | data->rx_mgmt.ssi_signal); | |
2d43d37f JB |
3770 | } |
3771 | ||
2a8b7416 | 3772 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
13adc57b | 3773 | #endif /* CONFIG_AP */ |
f8b1f695 | 3774 | break; |
2d43d37f | 3775 | } |
e67b55fb | 3776 | case EVENT_RX_PROBE_REQ: |
b211f3eb JM |
3777 | if (data->rx_probe_req.sa == NULL || |
3778 | data->rx_probe_req.ie == NULL) | |
3779 | break; | |
e67b55fb JM |
3780 | #ifdef CONFIG_AP |
3781 | if (wpa_s->ap_iface) { | |
3782 | hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], | |
3783 | data->rx_probe_req.sa, | |
04a85e44 JM |
3784 | data->rx_probe_req.da, |
3785 | data->rx_probe_req.bssid, | |
e67b55fb | 3786 | data->rx_probe_req.ie, |
baf513d6 JB |
3787 | data->rx_probe_req.ie_len, |
3788 | data->rx_probe_req.ssi_signal); | |
e67b55fb JM |
3789 | break; |
3790 | } | |
3791 | #endif /* CONFIG_AP */ | |
e67b55fb | 3792 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, |
04a85e44 JM |
3793 | data->rx_probe_req.da, |
3794 | data->rx_probe_req.bssid, | |
e67b55fb | 3795 | data->rx_probe_req.ie, |
baf513d6 | 3796 | data->rx_probe_req.ie_len, |
734ddf61 | 3797 | 0, |
baf513d6 | 3798 | data->rx_probe_req.ssi_signal); |
036f7c4a | 3799 | break; |
9bae1be0 | 3800 | case EVENT_REMAIN_ON_CHANNEL: |
24f6497c JM |
3801 | #ifdef CONFIG_OFFCHANNEL |
3802 | offchannel_remain_on_channel_cb( | |
3803 | wpa_s, data->remain_on_channel.freq, | |
3804 | data->remain_on_channel.duration); | |
3805 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
3806 | wpas_p2p_remain_on_channel_cb( |
3807 | wpa_s, data->remain_on_channel.freq, | |
3808 | data->remain_on_channel.duration); | |
3809 | break; | |
3810 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: | |
24f6497c JM |
3811 | #ifdef CONFIG_OFFCHANNEL |
3812 | offchannel_cancel_remain_on_channel_cb( | |
3813 | wpa_s, data->remain_on_channel.freq); | |
3814 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
3815 | wpas_p2p_cancel_remain_on_channel_cb( |
3816 | wpa_s, data->remain_on_channel.freq); | |
3817 | break; | |
a8e0505b JM |
3818 | case EVENT_EAPOL_RX: |
3819 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, | |
3820 | data->eapol_rx.data, | |
3821 | data->eapol_rx.data_len); | |
3822 | break; | |
e2f74005 | 3823 | case EVENT_SIGNAL_CHANGE: |
0cd86028 JM |
3824 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE |
3825 | "above=%d signal=%d noise=%d txrate=%d", | |
3826 | data->signal_change.above_threshold, | |
3827 | data->signal_change.current_signal, | |
3828 | data->signal_change.current_noise, | |
3829 | data->signal_change.current_txrate); | |
71d77adb MM |
3830 | wpa_bss_update_level(wpa_s->current_bss, |
3831 | data->signal_change.current_signal); | |
e2f74005 | 3832 | bgscan_notify_signal_change( |
60a972a6 | 3833 | wpa_s, data->signal_change.above_threshold, |
174fa789 PS |
3834 | data->signal_change.current_signal, |
3835 | data->signal_change.current_noise, | |
3836 | data->signal_change.current_txrate); | |
e2f74005 | 3837 | break; |
8401a6b0 | 3838 | case EVENT_INTERFACE_ENABLED: |
f049052b | 3839 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); |
8401a6b0 | 3840 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
bfba8deb | 3841 | wpa_supplicant_update_mac_addr(wpa_s); |
782e2f78 IP |
3842 | if (wpa_s->p2p_mgmt) { |
3843 | wpa_supplicant_set_state(wpa_s, | |
3844 | WPA_DISCONNECTED); | |
3845 | break; | |
3846 | } | |
3847 | ||
199716ad | 3848 | #ifdef CONFIG_AP |
9919f7a2 JB |
3849 | if (!wpa_s->ap_iface) { |
3850 | wpa_supplicant_set_state(wpa_s, | |
3851 | WPA_DISCONNECTED); | |
635874b5 | 3852 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
9919f7a2 JB |
3853 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
3854 | } else | |
3855 | wpa_supplicant_set_state(wpa_s, | |
3856 | WPA_COMPLETED); | |
199716ad BG |
3857 | #else /* CONFIG_AP */ |
3858 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
3859 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
3860 | #endif /* CONFIG_AP */ | |
8401a6b0 JM |
3861 | } |
3862 | break; | |
3863 | case EVENT_INTERFACE_DISABLED: | |
f049052b | 3864 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); |
6f72577f IP |
3865 | #ifdef CONFIG_P2P |
3866 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || | |
3867 | (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group && | |
3868 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) { | |
635874b5 JM |
3869 | /* |
3870 | * Mark interface disabled if this happens to end up not | |
3871 | * being removed as a separate P2P group interface. | |
3872 | */ | |
3873 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); | |
6f72577f IP |
3874 | /* |
3875 | * The interface was externally disabled. Remove | |
3876 | * it assuming an external entity will start a | |
3877 | * new session if needed. | |
3878 | */ | |
8f2cf379 JM |
3879 | if (wpa_s->current_ssid && |
3880 | wpa_s->current_ssid->p2p_group) | |
3881 | wpas_p2p_interface_unavailable(wpa_s); | |
3882 | else | |
3883 | wpas_p2p_disconnect(wpa_s); | |
635874b5 JM |
3884 | /* |
3885 | * wpa_s instance may have been freed, so must not use | |
3886 | * it here anymore. | |
3887 | */ | |
6f72577f IP |
3888 | break; |
3889 | } | |
c71c2416 JM |
3890 | if (wpa_s->p2p_scan_work && wpa_s->global->p2p && |
3891 | p2p_in_progress(wpa_s->global->p2p) > 1) { | |
3892 | /* This radio work will be cancelled, so clear P2P | |
3893 | * state as well. | |
3894 | */ | |
3895 | p2p_stop_find(wpa_s->global->p2p); | |
3896 | } | |
6f72577f IP |
3897 | #endif /* CONFIG_P2P */ |
3898 | ||
b7a6702f JM |
3899 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
3900 | /* | |
3901 | * Indicate disconnection to keep ctrl_iface events | |
3902 | * consistent. | |
3903 | */ | |
3904 | wpa_supplicant_event_disassoc( | |
3905 | wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1); | |
3906 | } | |
8401a6b0 | 3907 | wpa_supplicant_mark_disassoc(wpa_s); |
b3253ebb AO |
3908 | radio_remove_works(wpa_s, NULL, 0); |
3909 | ||
8401a6b0 JM |
3910 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
3911 | break; | |
b5c9da8d | 3912 | case EVENT_CHANNEL_LIST_CHANGED: |
142817b2 JM |
3913 | wpa_supplicant_update_channel_list( |
3914 | wpa_s, &data->channel_list_changed); | |
c973f386 JM |
3915 | break; |
3916 | case EVENT_INTERFACE_UNAVAILABLE: | |
c973f386 | 3917 | wpas_p2p_interface_unavailable(wpa_s); |
7cfc4ac3 AGS |
3918 | break; |
3919 | case EVENT_BEST_CHANNEL: | |
f049052b BG |
3920 | wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " |
3921 | "(%d %d %d)", | |
3922 | data->best_chan.freq_24, data->best_chan.freq_5, | |
3923 | data->best_chan.freq_overall); | |
7cfc4ac3 AGS |
3924 | wpa_s->best_24_freq = data->best_chan.freq_24; |
3925 | wpa_s->best_5_freq = data->best_chan.freq_5; | |
3926 | wpa_s->best_overall_freq = data->best_chan.freq_overall; | |
7cfc4ac3 AGS |
3927 | wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, |
3928 | data->best_chan.freq_5, | |
3929 | data->best_chan.freq_overall); | |
b5c9da8d | 3930 | break; |
7d878ca7 JM |
3931 | case EVENT_UNPROT_DEAUTH: |
3932 | wpa_supplicant_event_unprot_deauth(wpa_s, | |
3933 | &data->unprot_deauth); | |
3934 | break; | |
3935 | case EVENT_UNPROT_DISASSOC: | |
3936 | wpa_supplicant_event_unprot_disassoc(wpa_s, | |
3937 | &data->unprot_disassoc); | |
3938 | break; | |
0d7e5a3a JB |
3939 | case EVENT_STATION_LOW_ACK: |
3940 | #ifdef CONFIG_AP | |
3941 | if (wpa_s->ap_iface && data) | |
3942 | hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], | |
3943 | data->low_ack.addr); | |
3944 | #endif /* CONFIG_AP */ | |
8f15f711 AN |
3945 | #ifdef CONFIG_TDLS |
3946 | if (data) | |
947f900f AN |
3947 | wpa_tdls_disable_unreachable_link(wpa_s->wpa, |
3948 | data->low_ack.addr); | |
8f15f711 | 3949 | #endif /* CONFIG_TDLS */ |
0d7e5a3a | 3950 | break; |
ea244d21 XC |
3951 | case EVENT_IBSS_PEER_LOST: |
3952 | #ifdef CONFIG_IBSS_RSN | |
3953 | ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); | |
3954 | #endif /* CONFIG_IBSS_RSN */ | |
3955 | break; | |
b14a210c JB |
3956 | case EVENT_DRIVER_GTK_REKEY: |
3957 | if (os_memcmp(data->driver_gtk_rekey.bssid, | |
3958 | wpa_s->bssid, ETH_ALEN)) | |
3959 | break; | |
3960 | if (!wpa_s->wpa) | |
3961 | break; | |
3962 | wpa_sm_update_replay_ctr(wpa_s->wpa, | |
3963 | data->driver_gtk_rekey.replay_ctr); | |
3964 | break; | |
cbdf3507 | 3965 | case EVENT_SCHED_SCAN_STOPPED: |
dd271857 | 3966 | wpa_s->pno = 0; |
cbdf3507 | 3967 | wpa_s->sched_scanning = 0; |
bef5e9a8 | 3968 | resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s); |
cbdf3507 LC |
3969 | wpa_supplicant_notify_scanning(wpa_s, 0); |
3970 | ||
9b6f44cb JM |
3971 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
3972 | break; | |
3973 | ||
cbdf3507 | 3974 | /* |
cf70d298 RM |
3975 | * Start a new sched scan to continue searching for more SSIDs |
3976 | * either if timed out or PNO schedule scan is pending. | |
cbdf3507 | 3977 | */ |
5e3ddf4d AB |
3978 | if (wpa_s->sched_scan_timed_out) { |
3979 | wpa_supplicant_req_sched_scan(wpa_s); | |
3980 | } else if (wpa_s->pno_sched_pending) { | |
3981 | wpa_s->pno_sched_pending = 0; | |
3982 | wpas_start_pno(wpa_s); | |
02e122a9 DS |
3983 | } else if (resched) { |
3984 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
cf70d298 RM |
3985 | } |
3986 | ||
cbdf3507 | 3987 | break; |
783fcb7d GG |
3988 | case EVENT_WPS_BUTTON_PUSHED: |
3989 | #ifdef CONFIG_WPS | |
3990 | wpas_wps_start_pbc(wpa_s, NULL, 0); | |
3991 | #endif /* CONFIG_WPS */ | |
3992 | break; | |
253f2e37 AH |
3993 | case EVENT_AVOID_FREQUENCIES: |
3994 | wpa_supplicant_notify_avoid_freq(wpa_s, data); | |
3995 | break; | |
3140803b RM |
3996 | case EVENT_CONNECT_FAILED_REASON: |
3997 | #ifdef CONFIG_AP | |
3998 | if (!wpa_s->ap_iface || !data) | |
3999 | break; | |
4000 | hostapd_event_connect_failed_reason( | |
4001 | wpa_s->ap_iface->bss[0], | |
4002 | data->connect_failed_reason.addr, | |
4003 | data->connect_failed_reason.code); | |
4004 | #endif /* CONFIG_AP */ | |
4005 | break; | |
8319e312 | 4006 | case EVENT_NEW_PEER_CANDIDATE: |
eac02316 MH |
4007 | #ifdef CONFIG_MESH |
4008 | if (!wpa_s->ifmsh || !data) | |
4009 | break; | |
8319e312 TP |
4010 | wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer, |
4011 | data->mesh_peer.ies, | |
4012 | data->mesh_peer.ie_len); | |
eac02316 | 4013 | #endif /* CONFIG_MESH */ |
8319e312 | 4014 | break; |
96bc5086 TB |
4015 | case EVENT_SURVEY: |
4016 | #ifdef CONFIG_AP | |
4017 | if (!wpa_s->ap_iface) | |
4018 | break; | |
4019 | hostapd_event_get_survey(wpa_s->ap_iface, | |
4020 | &data->survey_results); | |
4021 | #endif /* CONFIG_AP */ | |
4022 | break; | |
d9909717 TB |
4023 | case EVENT_ACS_CHANNEL_SELECTED: |
4024 | #ifdef CONFIG_ACS | |
4025 | if (!wpa_s->ap_iface) | |
4026 | break; | |
4027 | hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0], | |
4028 | &data->acs_selected_channels); | |
4029 | #endif /* CONFIG_ACS */ | |
4030 | break; | |
6fc6879b | 4031 | default: |
f049052b | 4032 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); |
6fc6879b JM |
4033 | break; |
4034 | } | |
4035 | } | |
45e3fc72 RM |
4036 | |
4037 | ||
4038 | void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event, | |
4039 | union wpa_event_data *data) | |
4040 | { | |
4041 | struct wpa_supplicant *wpa_s; | |
4042 | ||
4043 | if (event != EVENT_INTERFACE_STATUS) | |
4044 | return; | |
4045 | ||
4046 | wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname); | |
4047 | if (wpa_s && wpa_s->driver->get_ifindex) { | |
4048 | unsigned int ifindex; | |
4049 | ||
4050 | ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv); | |
4051 | if (ifindex != data->interface_status.ifindex) { | |
4052 | wpa_dbg(wpa_s, MSG_DEBUG, | |
4053 | "interface status ifindex %d mismatch (%d)", | |
4054 | ifindex, data->interface_status.ifindex); | |
4055 | return; | |
4056 | } | |
4057 | } | |
2e997eec RM |
4058 | #ifdef CONFIG_MATCH_IFACE |
4059 | else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) { | |
4060 | struct wpa_interface *wpa_i; | |
4061 | ||
4062 | wpa_i = wpa_supplicant_match_iface( | |
4063 | ctx, data->interface_status.ifname); | |
4064 | if (!wpa_i) | |
4065 | return; | |
4066 | wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL); | |
4067 | os_free(wpa_i); | |
4068 | if (wpa_s) | |
4069 | wpa_s->matched = 1; | |
4070 | } | |
4071 | #endif /* CONFIG_MATCH_IFACE */ | |
45e3fc72 RM |
4072 | |
4073 | if (wpa_s) | |
4074 | wpa_supplicant_event(wpa_s, event, data); | |
4075 | } |