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