]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant - Driver event processing | |
3d9975d5 | 3 | * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi> |
6fc6879b JM |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License version 2 as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * Alternatively, this software may be distributed under the terms of BSD | |
10 | * license. | |
11 | * | |
12 | * See README and COPYING for more details. | |
13 | */ | |
14 | ||
15 | #include "includes.h" | |
16 | ||
17 | #include "common.h" | |
18 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 19 | #include "rsn_supp/wpa.h" |
6fc6879b | 20 | #include "eloop.h" |
6fc6879b JM |
21 | #include "config.h" |
22 | #include "l2_packet/l2_packet.h" | |
23 | #include "wpa_supplicant_i.h" | |
2d5b792d | 24 | #include "driver_i.h" |
6fc6879b | 25 | #include "pcsc_funcs.h" |
3acb5005 JM |
26 | #include "rsn_supp/preauth.h" |
27 | #include "rsn_supp/pmksa_cache.h" | |
90973fb2 | 28 | #include "common/wpa_ctrl.h" |
6fc6879b | 29 | #include "eap_peer/eap.h" |
1d041bec | 30 | #include "ap/hostapd.h" |
93b7ddd0 | 31 | #include "p2p/p2p.h" |
8bac466b | 32 | #include "notify.h" |
90973fb2 | 33 | #include "common/ieee802_11_defs.h" |
54f489be | 34 | #include "common/ieee802_11_common.h" |
bbb921da | 35 | #include "crypto/random.h" |
6fc6879b JM |
36 | #include "blacklist.h" |
37 | #include "wpas_glue.h" | |
351f09a2 | 38 | #include "wps_supplicant.h" |
11ef8d35 | 39 | #include "ibss_rsn.h" |
c2a04078 | 40 | #include "sme.h" |
04ea7b79 | 41 | #include "gas_query.h" |
9bae1be0 | 42 | #include "p2p_supplicant.h" |
60b94c98 | 43 | #include "bgscan.h" |
f8b1f695 | 44 | #include "ap.h" |
6fa81a3b | 45 | #include "bss.h" |
9ba9fa07 | 46 | #include "scan.h" |
24f6497c | 47 | #include "offchannel.h" |
6fc6879b JM |
48 | |
49 | ||
50 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) | |
51 | { | |
8bac466b | 52 | struct wpa_ssid *ssid, *old_ssid; |
6fc6879b JM |
53 | |
54 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) | |
55 | return 0; | |
56 | ||
f049052b BG |
57 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " |
58 | "information"); | |
6fc6879b JM |
59 | ssid = wpa_supplicant_get_ssid(wpa_s); |
60 | if (ssid == NULL) { | |
f049052b BG |
61 | wpa_msg(wpa_s, MSG_INFO, |
62 | "No network configuration found for the current AP"); | |
6fc6879b JM |
63 | return -1; |
64 | } | |
65 | ||
66 | if (ssid->disabled) { | |
f049052b | 67 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); |
6fc6879b JM |
68 | return -1; |
69 | } | |
70 | ||
f049052b BG |
71 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " |
72 | "current AP"); | |
0bf927a0 | 73 | if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
6fc6879b JM |
74 | u8 wpa_ie[80]; |
75 | size_t wpa_ie_len = sizeof(wpa_ie); | |
76 | wpa_supplicant_set_suites(wpa_s, NULL, ssid, | |
77 | wpa_ie, &wpa_ie_len); | |
78 | } else { | |
79 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
80 | } | |
81 | ||
82 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) | |
83 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
8bac466b | 84 | old_ssid = wpa_s->current_ssid; |
6fc6879b JM |
85 | wpa_s->current_ssid = ssid; |
86 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); | |
87 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
88 | if (old_ssid != wpa_s->current_ssid) |
89 | wpas_notify_network_changed(wpa_s); | |
6fc6879b JM |
90 | |
91 | return 0; | |
92 | } | |
93 | ||
94 | ||
01a17491 | 95 | void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx) |
6fc6879b JM |
96 | { |
97 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
98 | ||
99 | if (wpa_s->countermeasures) { | |
100 | wpa_s->countermeasures = 0; | |
101 | wpa_drv_set_countermeasures(wpa_s, 0); | |
102 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); | |
103 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
104 | } | |
105 | } | |
106 | ||
107 | ||
108 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) | |
109 | { | |
8bac466b JM |
110 | int bssid_changed; |
111 | ||
78177a00 JM |
112 | #ifdef CONFIG_IBSS_RSN |
113 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
114 | wpa_s->ibss_rsn = NULL; | |
115 | #endif /* CONFIG_IBSS_RSN */ | |
116 | ||
ca62e114 JM |
117 | #ifdef CONFIG_AP |
118 | wpa_supplicant_ap_deinit(wpa_s); | |
119 | #endif /* CONFIG_AP */ | |
120 | ||
8401a6b0 JM |
121 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
122 | return; | |
123 | ||
6fc6879b | 124 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
8bac466b | 125 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
6fc6879b JM |
126 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
127 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
b1aebbc4 JM |
128 | #ifdef CONFIG_P2P |
129 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); | |
130 | #endif /* CONFIG_P2P */ | |
be8be671 | 131 | wpa_s->current_bss = NULL; |
3c85f144 | 132 | wpa_s->assoc_freq = 0; |
8fd0f0f3 HW |
133 | #ifdef CONFIG_IEEE80211R |
134 | #ifdef CONFIG_SME | |
135 | if (wpa_s->sme.ft_ies) | |
136 | sme_update_ft_ies(wpa_s, NULL, NULL, 0); | |
137 | #endif /* CONFIG_SME */ | |
138 | #endif /* CONFIG_IEEE80211R */ | |
139 | ||
8bac466b JM |
140 | if (bssid_changed) |
141 | wpas_notify_bssid_changed(wpa_s); | |
142 | ||
6fc6879b JM |
143 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
144 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
56586197 | 145 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) |
6fc6879b JM |
146 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
147 | wpa_s->ap_ies_from_associnfo = 0; | |
148 | } | |
149 | ||
150 | ||
151 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) | |
152 | { | |
153 | struct wpa_ie_data ie; | |
154 | int pmksa_set = -1; | |
155 | size_t i; | |
156 | ||
157 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || | |
158 | ie.pmkid == NULL) | |
159 | return; | |
160 | ||
161 | for (i = 0; i < ie.num_pmkid; i++) { | |
162 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, | |
163 | ie.pmkid + i * PMKID_LEN, | |
164 | NULL, NULL, 0); | |
165 | if (pmksa_set == 0) { | |
166 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1); | |
167 | break; | |
168 | } | |
169 | } | |
170 | ||
f049052b BG |
171 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " |
172 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); | |
6fc6879b JM |
173 | } |
174 | ||
175 | ||
176 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, | |
177 | union wpa_event_data *data) | |
178 | { | |
179 | if (data == NULL) { | |
f049052b BG |
180 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " |
181 | "event"); | |
6fc6879b JM |
182 | return; |
183 | } | |
f049052b BG |
184 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR |
185 | " index=%d preauth=%d", | |
186 | MAC2STR(data->pmkid_candidate.bssid), | |
187 | data->pmkid_candidate.index, | |
188 | data->pmkid_candidate.preauth); | |
6fc6879b JM |
189 | |
190 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, | |
191 | data->pmkid_candidate.index, | |
192 | data->pmkid_candidate.preauth); | |
193 | } | |
194 | ||
195 | ||
196 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) | |
197 | { | |
198 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
199 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
200 | return 0; | |
201 | ||
202 | #ifdef IEEE8021X_EAPOL | |
203 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | |
204 | wpa_s->current_ssid && | |
205 | !(wpa_s->current_ssid->eapol_flags & | |
206 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
207 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { | |
208 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either | |
209 | * plaintext or static WEP keys). */ | |
210 | return 0; | |
211 | } | |
212 | #endif /* IEEE8021X_EAPOL */ | |
213 | ||
214 | return 1; | |
215 | } | |
216 | ||
217 | ||
218 | /** | |
219 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC | |
220 | * @wpa_s: pointer to wpa_supplicant data | |
221 | * @ssid: Configuration data for the network | |
222 | * Returns: 0 on success, -1 on failure | |
223 | * | |
224 | * This function is called when starting authentication with a network that is | |
225 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). | |
226 | */ | |
227 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, | |
228 | struct wpa_ssid *ssid) | |
229 | { | |
230 | #ifdef IEEE8021X_EAPOL | |
b832d34c | 231 | #ifdef PCSC_FUNCS |
6fc6879b JM |
232 | int aka = 0, sim = 0, type; |
233 | ||
234 | if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL) | |
235 | return 0; | |
236 | ||
237 | if (ssid->eap.eap_methods == NULL) { | |
238 | sim = 1; | |
239 | aka = 1; | |
240 | } else { | |
241 | struct eap_method_type *eap = ssid->eap.eap_methods; | |
242 | while (eap->vendor != EAP_VENDOR_IETF || | |
243 | eap->method != EAP_TYPE_NONE) { | |
244 | if (eap->vendor == EAP_VENDOR_IETF) { | |
245 | if (eap->method == EAP_TYPE_SIM) | |
246 | sim = 1; | |
247 | else if (eap->method == EAP_TYPE_AKA) | |
248 | aka = 1; | |
249 | } | |
250 | eap++; | |
251 | } | |
252 | } | |
253 | ||
254 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) | |
255 | sim = 0; | |
256 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL) | |
257 | aka = 0; | |
258 | ||
259 | if (!sim && !aka) { | |
f049052b BG |
260 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " |
261 | "use SIM, but neither EAP-SIM nor EAP-AKA are " | |
262 | "enabled"); | |
6fc6879b JM |
263 | return 0; |
264 | } | |
265 | ||
f049052b BG |
266 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " |
267 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); | |
6fc6879b JM |
268 | if (sim && aka) |
269 | type = SCARD_TRY_BOTH; | |
270 | else if (aka) | |
271 | type = SCARD_USIM_ONLY; | |
272 | else | |
273 | type = SCARD_GSM_SIM_ONLY; | |
274 | ||
275 | wpa_s->scard = scard_init(type); | |
276 | if (wpa_s->scard == NULL) { | |
f049052b BG |
277 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " |
278 | "(pcsc-lite)"); | |
6fc6879b JM |
279 | return -1; |
280 | } | |
281 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
282 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
b832d34c | 283 | #endif /* PCSC_FUNCS */ |
6fc6879b JM |
284 | #endif /* IEEE8021X_EAPOL */ |
285 | ||
286 | return 0; | |
287 | } | |
288 | ||
289 | ||
290 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
291 | static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss, | |
292 | struct wpa_ssid *ssid) | |
293 | { | |
294 | int i, privacy = 0; | |
295 | ||
296 | if (ssid->mixed_cell) | |
297 | return 1; | |
298 | ||
0632542b AT |
299 | #ifdef CONFIG_WPS |
300 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) | |
301 | return 1; | |
302 | #endif /* CONFIG_WPS */ | |
303 | ||
6fc6879b JM |
304 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
305 | if (ssid->wep_key_len[i]) { | |
306 | privacy = 1; | |
307 | break; | |
308 | } | |
309 | } | |
310 | #ifdef IEEE8021X_EAPOL | |
311 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
312 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
313 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) | |
314 | privacy = 1; | |
315 | #endif /* IEEE8021X_EAPOL */ | |
316 | ||
29fbc522 JM |
317 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) |
318 | privacy = 1; | |
319 | ||
6fc6879b JM |
320 | if (bss->caps & IEEE80211_CAP_PRIVACY) |
321 | return privacy; | |
322 | return !privacy; | |
323 | } | |
324 | ||
325 | ||
a6099152 JM |
326 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
327 | struct wpa_ssid *ssid, | |
6fc6879b JM |
328 | struct wpa_scan_res *bss) |
329 | { | |
330 | struct wpa_ie_data ie; | |
331 | int proto_match = 0; | |
332 | const u8 *rsn_ie, *wpa_ie; | |
351f09a2 | 333 | int ret; |
43882f1e | 334 | int wep_ok; |
6fc6879b | 335 | |
a6099152 | 336 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
351f09a2 JM |
337 | if (ret >= 0) |
338 | return ret; | |
ad08c363 | 339 | |
43882f1e JM |
340 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ |
341 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && | |
342 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
343 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || | |
344 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); | |
345 | ||
6fc6879b JM |
346 | rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); |
347 | while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { | |
348 | proto_match++; | |
349 | ||
350 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { | |
f049052b BG |
351 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse " |
352 | "failed"); | |
6fc6879b JM |
353 | break; |
354 | } | |
43882f1e JM |
355 | |
356 | if (wep_ok && | |
357 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
358 | { | |
f049052b BG |
359 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
360 | "in RSN IE"); | |
43882f1e JM |
361 | return 1; |
362 | } | |
363 | ||
6fc6879b | 364 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
365 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto " |
366 | "mismatch"); | |
6fc6879b JM |
367 | break; |
368 | } | |
369 | ||
370 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
371 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK " |
372 | "cipher mismatch"); | |
6fc6879b JM |
373 | break; |
374 | } | |
375 | ||
376 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
377 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK " |
378 | "cipher mismatch"); | |
6fc6879b JM |
379 | break; |
380 | } | |
381 | ||
382 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
383 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt " |
384 | "mismatch"); | |
6fc6879b JM |
385 | break; |
386 | } | |
387 | ||
388 | #ifdef CONFIG_IEEE80211W | |
0b60b0aa | 389 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
70f8cc8e | 390 | ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) { |
f049052b BG |
391 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt " |
392 | "frame protection"); | |
6fc6879b JM |
393 | break; |
394 | } | |
395 | #endif /* CONFIG_IEEE80211W */ | |
396 | ||
f049052b | 397 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE"); |
6fc6879b JM |
398 | return 1; |
399 | } | |
400 | ||
401 | wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
402 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { | |
403 | proto_match++; | |
404 | ||
405 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { | |
f049052b BG |
406 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse " |
407 | "failed"); | |
6fc6879b JM |
408 | break; |
409 | } | |
43882f1e JM |
410 | |
411 | if (wep_ok && | |
412 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
413 | { | |
f049052b BG |
414 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
415 | "in WPA IE"); | |
43882f1e JM |
416 | return 1; |
417 | } | |
418 | ||
6fc6879b | 419 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
420 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto " |
421 | "mismatch"); | |
6fc6879b JM |
422 | break; |
423 | } | |
424 | ||
425 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
426 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK " |
427 | "cipher mismatch"); | |
6fc6879b JM |
428 | break; |
429 | } | |
430 | ||
431 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
432 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK " |
433 | "cipher mismatch"); | |
6fc6879b JM |
434 | break; |
435 | } | |
436 | ||
437 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
438 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt " |
439 | "mismatch"); | |
6fc6879b JM |
440 | break; |
441 | } | |
442 | ||
f049052b | 443 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE"); |
6fc6879b JM |
444 | return 1; |
445 | } | |
446 | ||
cc5e390d | 447 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && |
df83fb7d | 448 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { |
f049052b | 449 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match"); |
cc5e390d JM |
450 | return 0; |
451 | } | |
6fc6879b | 452 | |
c2f1fe41 JM |
453 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
454 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); | |
455 | return 1; | |
456 | } | |
457 | ||
458 | wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with " | |
459 | "WPA/WPA2"); | |
460 | ||
461 | return 0; | |
6fc6879b JM |
462 | } |
463 | ||
464 | ||
b766a9a2 JM |
465 | static int freq_allowed(int *freqs, int freq) |
466 | { | |
467 | int i; | |
468 | ||
469 | if (freqs == NULL) | |
470 | return 1; | |
471 | ||
472 | for (i = 0; freqs[i]; i++) | |
473 | if (freqs[i] == freq) | |
474 | return 1; | |
475 | return 0; | |
476 | } | |
477 | ||
478 | ||
e1e8cae3 CL |
479 | static int ht_supported(const struct hostapd_hw_modes *mode) |
480 | { | |
481 | if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) { | |
482 | /* | |
483 | * The driver did not indicate whether it supports HT. Assume | |
484 | * it does to avoid connection issues. | |
485 | */ | |
486 | return 1; | |
487 | } | |
488 | ||
489 | /* | |
490 | * IEEE Std 802.11n-2009 20.1.1: | |
491 | * An HT non-AP STA shall support all EQM rates for one spatial stream. | |
492 | */ | |
493 | return mode->mcs_set[0] == 0xff; | |
494 | } | |
495 | ||
496 | ||
497 | static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss) | |
498 | { | |
499 | const struct hostapd_hw_modes *mode = NULL, *modes; | |
500 | const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; | |
501 | const u8 *rate_ie; | |
502 | int i, j, k; | |
503 | ||
a6d94e1b JM |
504 | if (bss->freq == 0) |
505 | return 1; /* Cannot do matching without knowing band */ | |
506 | ||
e1e8cae3 CL |
507 | modes = wpa_s->hw.modes; |
508 | if (modes == NULL) { | |
509 | /* | |
510 | * The driver does not provide any additional information | |
511 | * about the utilized hardware, so allow the connection attempt | |
512 | * to continue. | |
513 | */ | |
514 | return 1; | |
515 | } | |
516 | ||
517 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
518 | for (j = 0; j < modes[i].num_channels; j++) { | |
519 | int freq = modes[i].channels[j].freq; | |
520 | if (freq == bss->freq) { | |
521 | if (mode && | |
522 | mode->mode == HOSTAPD_MODE_IEEE80211G) | |
523 | break; /* do not allow 802.11b replace | |
524 | * 802.11g */ | |
525 | mode = &modes[i]; | |
526 | break; | |
527 | } | |
528 | } | |
529 | } | |
530 | ||
531 | if (mode == NULL) | |
532 | return 0; | |
533 | ||
534 | for (i = 0; i < (int) sizeof(scan_ie); i++) { | |
535 | rate_ie = wpa_scan_get_ie(bss, scan_ie[i]); | |
536 | if (rate_ie == NULL) | |
537 | continue; | |
538 | ||
539 | for (j = 2; j < rate_ie[1] + 2; j++) { | |
540 | int flagged = !!(rate_ie[j] & 0x80); | |
541 | int r = (rate_ie[j] & 0x7f) * 5; | |
542 | ||
543 | /* | |
544 | * IEEE Std 802.11n-2009 7.3.2.2: | |
545 | * The new BSS Membership selector value is encoded | |
546 | * like a legacy basic rate, but it is not a rate and | |
547 | * only indicates if the BSS members are required to | |
548 | * support the mandatory features of Clause 20 [HT PHY] | |
549 | * in order to join the BSS. | |
550 | */ | |
551 | if (flagged && ((rate_ie[j] & 0x7f) == | |
552 | BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { | |
553 | if (!ht_supported(mode)) { | |
554 | wpa_dbg(wpa_s, MSG_DEBUG, | |
555 | " hardware does not support " | |
556 | "HT PHY"); | |
557 | return 0; | |
558 | } | |
559 | continue; | |
560 | } | |
561 | ||
562 | if (!flagged) | |
563 | continue; | |
564 | ||
565 | /* check for legacy basic rates */ | |
566 | for (k = 0; k < mode->num_rates; k++) { | |
567 | if (mode->rates[k] == r) | |
568 | break; | |
569 | } | |
570 | if (k == mode->num_rates) { | |
571 | /* | |
572 | * IEEE Std 802.11-2007 7.3.2.2 demands that in | |
573 | * order to join a BSS all required rates | |
574 | * have to be supported by the hardware. | |
575 | */ | |
576 | wpa_dbg(wpa_s, MSG_DEBUG, " hardware does " | |
577 | "not support required rate %d.%d Mbps", | |
578 | r / 10, r % 10); | |
579 | return 0; | |
580 | } | |
581 | } | |
582 | } | |
583 | ||
584 | return 1; | |
585 | } | |
586 | ||
587 | ||
d8d940b7 JM |
588 | static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
589 | int i, struct wpa_scan_res *bss, | |
590 | struct wpa_ssid *group) | |
6fc6879b | 591 | { |
d8d940b7 JM |
592 | const u8 *ssid_; |
593 | u8 wpa_ie_len, rsn_ie_len, ssid_len; | |
594 | int wpa; | |
6fc6879b JM |
595 | struct wpa_blacklist *e; |
596 | const u8 *ie; | |
d8d940b7 | 597 | struct wpa_ssid *ssid; |
6fc6879b | 598 | |
d8d940b7 JM |
599 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); |
600 | ssid_ = ie ? ie + 2 : (u8 *) ""; | |
601 | ssid_len = ie ? ie[1] : 0; | |
6fc6879b | 602 | |
d8d940b7 JM |
603 | ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
604 | wpa_ie_len = ie ? ie[1] : 0; | |
6fc6879b | 605 | |
d8d940b7 JM |
606 | ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); |
607 | rsn_ie_len = ie ? ie[1] : 0; | |
6fc6879b | 608 | |
f049052b BG |
609 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' " |
610 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s", | |
611 | i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len), | |
612 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, | |
613 | wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : ""); | |
9cf32261 | 614 | |
d8d940b7 | 615 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
5471c343 JM |
616 | if (e) { |
617 | int limit = 1; | |
618 | if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) { | |
619 | /* | |
620 | * When only a single network is enabled, we can | |
621 | * trigger blacklisting on the first failure. This | |
622 | * should not be done with multiple enabled networks to | |
623 | * avoid getting forced to move into a worse ESS on | |
624 | * single error if there are no other BSSes of the | |
625 | * current ESS. | |
626 | */ | |
627 | limit = 0; | |
628 | } | |
629 | if (e->count > limit) { | |
f049052b BG |
630 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
631 | "(count=%d limit=%d)", e->count, limit); | |
c2197bc9 | 632 | return NULL; |
5471c343 | 633 | } |
d8d940b7 | 634 | } |
6fc6879b | 635 | |
d8d940b7 | 636 | if (ssid_len == 0) { |
f049052b | 637 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); |
c2197bc9 | 638 | return NULL; |
d8d940b7 | 639 | } |
e81634cd | 640 | |
d8d940b7 | 641 | wpa = wpa_ie_len > 0 || rsn_ie_len > 0; |
6fc6879b | 642 | |
d8d940b7 JM |
643 | for (ssid = group; ssid; ssid = ssid->pnext) { |
644 | int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); | |
ad08c363 | 645 | |
d8d940b7 | 646 | if (ssid->disabled) { |
f049052b | 647 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); |
0c703df3 | 648 | continue; |
d8d940b7 | 649 | } |
9cf32261 | 650 | |
ad08c363 | 651 | #ifdef CONFIG_WPS |
f648bc7d | 652 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) { |
f049052b BG |
653 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
654 | "(WPS)"); | |
f648bc7d JM |
655 | continue; |
656 | } | |
657 | ||
d8d940b7 JM |
658 | if (wpa && ssid->ssid_len == 0 && |
659 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) | |
660 | check_ssid = 0; | |
661 | ||
662 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { | |
663 | /* Only allow wildcard SSID match if an AP | |
664 | * advertises active WPS operation that matches | |
665 | * with our mode. */ | |
666 | check_ssid = 1; | |
ad08c363 | 667 | if (ssid->ssid_len == 0 && |
a6099152 | 668 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
ad08c363 | 669 | check_ssid = 0; |
d8d940b7 | 670 | } |
ad08c363 JM |
671 | #endif /* CONFIG_WPS */ |
672 | ||
7d232e23 ZC |
673 | if (ssid->bssid_set && ssid->ssid_len == 0 && |
674 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) | |
675 | check_ssid = 0; | |
676 | ||
d8d940b7 JM |
677 | if (check_ssid && |
678 | (ssid_len != ssid->ssid_len || | |
679 | os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) { | |
f049052b | 680 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); |
0c703df3 | 681 | continue; |
6fc6879b | 682 | } |
6fc6879b | 683 | |
d8d940b7 JM |
684 | if (ssid->bssid_set && |
685 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { | |
f049052b | 686 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); |
0c703df3 | 687 | continue; |
d8d940b7 | 688 | } |
6fc6879b | 689 | |
cc5e390d | 690 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) |
0c703df3 | 691 | continue; |
9cf32261 | 692 | |
d8d940b7 JM |
693 | if (!wpa && |
694 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
695 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && | |
696 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { | |
f049052b BG |
697 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network " |
698 | "not allowed"); | |
0c703df3 | 699 | continue; |
6fc6879b | 700 | } |
9cf32261 | 701 | |
29fbc522 | 702 | if (!wpa_supplicant_match_privacy(bss, ssid)) { |
f049052b BG |
703 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy " |
704 | "mismatch"); | |
0c703df3 | 705 | continue; |
e81634cd JM |
706 | } |
707 | ||
29fbc522 | 708 | if (bss->caps & IEEE80211_CAP_IBSS) { |
f049052b BG |
709 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) " |
710 | "network"); | |
0c703df3 | 711 | continue; |
d8d940b7 | 712 | } |
b766a9a2 | 713 | |
d8d940b7 | 714 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
f049052b BG |
715 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not " |
716 | "allowed"); | |
0c703df3 | 717 | continue; |
6fc6879b | 718 | } |
d8d940b7 | 719 | |
e1e8cae3 CL |
720 | if (!rate_match(wpa_s, bss)) { |
721 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do " | |
722 | "not match"); | |
723 | continue; | |
724 | } | |
725 | ||
73e49269 JM |
726 | #ifdef CONFIG_P2P |
727 | /* | |
728 | * TODO: skip the AP if its P2P IE has Group Formation | |
729 | * bit set in the P2P Group Capability Bitmap and we | |
730 | * are not in Group Formation with that device. | |
731 | */ | |
732 | #endif /* CONFIG_P2P */ | |
733 | ||
d8d940b7 JM |
734 | /* Matching configuration found */ |
735 | return ssid; | |
6fc6879b JM |
736 | } |
737 | ||
d8d940b7 | 738 | /* No matching configuration found */ |
c2197bc9 | 739 | return NULL; |
9cf32261 JM |
740 | } |
741 | ||
742 | ||
6fa81a3b | 743 | static struct wpa_bss * |
a1fd2ce5 JM |
744 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
745 | struct wpa_scan_results *scan_res, | |
746 | struct wpa_ssid *group, | |
9cf32261 JM |
747 | struct wpa_ssid **selected_ssid) |
748 | { | |
d8d940b7 | 749 | size_t i; |
9cf32261 | 750 | |
f049052b BG |
751 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", |
752 | group->priority); | |
9cf32261 | 753 | |
d8d940b7 JM |
754 | for (i = 0; i < scan_res->num; i++) { |
755 | struct wpa_scan_res *bss = scan_res->res[i]; | |
756 | const u8 *ie, *ssid; | |
757 | u8 ssid_len; | |
758 | ||
759 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group); | |
760 | if (!*selected_ssid) | |
761 | continue; | |
762 | ||
763 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); | |
764 | ssid = ie ? ie + 2 : (u8 *) ""; | |
765 | ssid_len = ie ? ie[1] : 0; | |
9cf32261 | 766 | |
f049052b BG |
767 | wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR |
768 | " ssid='%s'", | |
769 | MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len)); | |
d8d940b7 JM |
770 | return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len); |
771 | } | |
772 | ||
773 | return NULL; | |
6fc6879b JM |
774 | } |
775 | ||
776 | ||
6fa81a3b | 777 | static struct wpa_bss * |
09b9df4e | 778 | wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
a1fd2ce5 | 779 | struct wpa_scan_results *scan_res, |
09b9df4e | 780 | struct wpa_ssid **selected_ssid) |
6fc6879b | 781 | { |
6fa81a3b | 782 | struct wpa_bss *selected = NULL; |
09b9df4e JM |
783 | int prio; |
784 | ||
785 | while (selected == NULL) { | |
786 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
787 | selected = wpa_supplicant_select_bss( | |
a1fd2ce5 | 788 | wpa_s, scan_res, wpa_s->conf->pssid[prio], |
09b9df4e JM |
789 | selected_ssid); |
790 | if (selected) | |
791 | break; | |
792 | } | |
793 | ||
8945cc45 BM |
794 | if (selected == NULL && wpa_s->blacklist && |
795 | !wpa_s->countermeasures) { | |
f049052b BG |
796 | wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear " |
797 | "blacklist and try again"); | |
09b9df4e JM |
798 | wpa_blacklist_clear(wpa_s); |
799 | wpa_s->blacklist_cleared++; | |
800 | } else if (selected == NULL) | |
801 | break; | |
802 | } | |
803 | ||
804 | return selected; | |
805 | } | |
806 | ||
807 | ||
808 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, | |
977b1174 | 809 | int timeout_sec, int timeout_usec) |
09b9df4e | 810 | { |
24f76940 | 811 | if (!wpa_supplicant_enabled_networks(wpa_s->conf)) { |
4f34d51a SL |
812 | /* |
813 | * No networks are enabled; short-circuit request so | |
814 | * we don't wait timeout seconds before transitioning | |
815 | * to INACTIVE state. | |
816 | */ | |
817 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
818 | return; | |
09b9df4e | 819 | } |
977b1174 | 820 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
09b9df4e JM |
821 | } |
822 | ||
823 | ||
5cbd88d9 JJ |
824 | int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
825 | struct wpa_bss *selected, | |
826 | struct wpa_ssid *ssid) | |
09b9df4e JM |
827 | { |
828 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { | |
829 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP | |
830 | "PBC session overlap"); | |
b73bf0a7 JM |
831 | #ifdef CONFIG_P2P |
832 | if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1) | |
5cbd88d9 | 833 | return -1; |
b73bf0a7 | 834 | #endif /* CONFIG_P2P */ |
199716ad BG |
835 | |
836 | #ifdef CONFIG_WPS | |
7736f18b | 837 | wpas_wps_cancel(wpa_s); |
199716ad | 838 | #endif /* CONFIG_WPS */ |
5cbd88d9 | 839 | return -1; |
09b9df4e JM |
840 | } |
841 | ||
842 | /* | |
843 | * Do not trigger new association unless the BSSID has changed or if | |
844 | * reassociation is requested. If we are in process of associating with | |
845 | * the selected BSSID, do not trigger new attempt. | |
846 | */ | |
847 | if (wpa_s->reassociate || | |
848 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && | |
e29853bb BG |
849 | ((wpa_s->wpa_state != WPA_ASSOCIATING && |
850 | wpa_s->wpa_state != WPA_AUTHENTICATING) || | |
09b9df4e JM |
851 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != |
852 | 0))) { | |
853 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { | |
977b1174 | 854 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
5cbd88d9 | 855 | return 0; |
09b9df4e | 856 | } |
e29853bb BG |
857 | wpa_msg(wpa_s, MSG_DEBUG, "Request association: " |
858 | "reassociate: %d selected: "MACSTR " bssid: " MACSTR | |
859 | " pending: " MACSTR " wpa_state: %s", | |
860 | wpa_s->reassociate, MAC2STR(selected->bssid), | |
861 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), | |
862 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
09b9df4e JM |
863 | wpa_supplicant_associate(wpa_s, selected, ssid); |
864 | } else { | |
f049052b BG |
865 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the " |
866 | "selected AP"); | |
09b9df4e | 867 | } |
5cbd88d9 JJ |
868 | |
869 | return 0; | |
09b9df4e JM |
870 | } |
871 | ||
872 | ||
b55aaa5f JM |
873 | static struct wpa_ssid * |
874 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) | |
875 | { | |
876 | int prio; | |
877 | struct wpa_ssid *ssid; | |
878 | ||
879 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
880 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) | |
881 | { | |
882 | if (ssid->disabled) | |
883 | continue; | |
884 | if (ssid->mode == IEEE80211_MODE_IBSS || | |
885 | ssid->mode == IEEE80211_MODE_AP) | |
886 | return ssid; | |
887 | } | |
888 | } | |
889 | return NULL; | |
890 | } | |
891 | ||
892 | ||
a1fd2ce5 JM |
893 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
894 | * on BSS added and BSS changed events */ | |
6ae93185 | 895 | static void wpa_supplicant_rsn_preauth_scan_results( |
6d28fb96 | 896 | struct wpa_supplicant *wpa_s) |
6ae93185 | 897 | { |
6d28fb96 | 898 | struct wpa_bss *bss; |
6ae93185 JM |
899 | |
900 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) | |
901 | return; | |
902 | ||
6d28fb96 | 903 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
6ae93185 | 904 | const u8 *ssid, *rsn; |
6ae93185 | 905 | |
6d28fb96 | 906 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); |
6ae93185 JM |
907 | if (ssid == NULL) |
908 | continue; | |
909 | ||
6d28fb96 | 910 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6ae93185 JM |
911 | if (rsn == NULL) |
912 | continue; | |
913 | ||
6d28fb96 | 914 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); |
6ae93185 JM |
915 | } |
916 | ||
917 | } | |
918 | ||
919 | ||
48563d86 JM |
920 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
921 | struct wpa_bss *selected, | |
922 | struct wpa_ssid *ssid, | |
923 | struct wpa_scan_results *scan_res) | |
924 | { | |
925 | size_t i; | |
926 | struct wpa_scan_res *current_bss = NULL; | |
927 | int min_diff; | |
928 | ||
929 | if (wpa_s->reassociate) | |
930 | return 1; /* explicit request to reassociate */ | |
931 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
932 | return 1; /* we are not associated; continue */ | |
933 | if (wpa_s->current_ssid == NULL) | |
934 | return 1; /* unknown current SSID */ | |
935 | if (wpa_s->current_ssid != ssid) | |
936 | return 1; /* different network block */ | |
937 | ||
22628eca JM |
938 | if (wpas_driver_bss_selection(wpa_s)) |
939 | return 0; /* Driver-based roaming */ | |
940 | ||
48563d86 JM |
941 | for (i = 0; i < scan_res->num; i++) { |
942 | struct wpa_scan_res *res = scan_res->res[i]; | |
943 | const u8 *ie; | |
944 | if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0) | |
945 | continue; | |
946 | ||
947 | ie = wpa_scan_get_ie(res, WLAN_EID_SSID); | |
948 | if (ie == NULL) | |
949 | continue; | |
950 | if (ie[1] != wpa_s->current_ssid->ssid_len || | |
951 | os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0) | |
952 | continue; | |
953 | current_bss = res; | |
954 | break; | |
955 | } | |
956 | ||
957 | if (!current_bss) | |
958 | return 1; /* current BSS not seen in scan results */ | |
959 | ||
f049052b BG |
960 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); |
961 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d", | |
962 | MAC2STR(current_bss->bssid), current_bss->level); | |
963 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d", | |
964 | MAC2STR(selected->bssid), selected->level); | |
48563d86 | 965 | |
ac26ebd8 JM |
966 | if (wpa_s->current_ssid->bssid_set && |
967 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == | |
968 | 0) { | |
f049052b BG |
969 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " |
970 | "has preferred BSSID"); | |
ac26ebd8 JM |
971 | return 1; |
972 | } | |
973 | ||
48563d86 JM |
974 | min_diff = 2; |
975 | if (current_bss->level < 0) { | |
976 | if (current_bss->level < -85) | |
977 | min_diff = 1; | |
978 | else if (current_bss->level < -80) | |
979 | min_diff = 2; | |
980 | else if (current_bss->level < -75) | |
981 | min_diff = 3; | |
982 | else if (current_bss->level < -70) | |
983 | min_diff = 4; | |
984 | else | |
985 | min_diff = 5; | |
986 | } | |
987 | if (abs(current_bss->level - selected->level) < min_diff) { | |
f049052b BG |
988 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference " |
989 | "in signal level"); | |
48563d86 JM |
990 | return 0; |
991 | } | |
992 | ||
993 | return 1; | |
994 | } | |
995 | ||
cd2f4ddf SM |
996 | |
997 | static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) | |
998 | { | |
999 | const u8 *bss_wpa = NULL, *bss_rsn = NULL; | |
1000 | ||
1001 | if (!wpa_s->current_bss || !wpa_s->current_ssid) | |
1002 | return -1; | |
1003 | ||
1004 | if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) | |
1005 | return 0; | |
1006 | ||
1007 | bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, | |
1008 | WPA_IE_VENDOR_TYPE); | |
1009 | bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN); | |
1010 | ||
1011 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, | |
1012 | bss_wpa ? 2 + bss_wpa[1] : 0) || | |
1013 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, | |
1014 | bss_rsn ? 2 + bss_rsn[1] : 0)) | |
1015 | return -1; | |
1016 | ||
1017 | return 0; | |
1018 | } | |
1019 | ||
1020 | ||
e1504976 BG |
1021 | /* Return < 0 if no scan results could be fetched. */ |
1022 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, | |
1023 | union wpa_event_data *data) | |
09b9df4e | 1024 | { |
6fa81a3b | 1025 | struct wpa_bss *selected; |
6fc6879b | 1026 | struct wpa_ssid *ssid = NULL; |
a1fd2ce5 | 1027 | struct wpa_scan_results *scan_res; |
5bc0cdb7 JM |
1028 | int ap = 0; |
1029 | ||
1030 | #ifdef CONFIG_AP | |
1031 | if (wpa_s->ap_iface) | |
1032 | ap = 1; | |
1033 | #endif /* CONFIG_AP */ | |
6fc6879b | 1034 | |
cb8564b1 DW |
1035 | wpa_supplicant_notify_scanning(wpa_s, 0); |
1036 | ||
39185dfa JM |
1037 | #ifdef CONFIG_P2P |
1038 | if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled && | |
1039 | wpa_s->global->p2p != NULL) { | |
1040 | wpa_s->p2p_cb_on_scan_complete = 0; | |
1041 | if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) { | |
1042 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation " | |
1043 | "stopped scan processing"); | |
1044 | return -1; | |
1045 | } | |
1046 | } | |
1047 | #endif /* CONFIG_P2P */ | |
1048 | ||
a1fd2ce5 JM |
1049 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
1050 | data ? &data->scan_info : | |
1051 | NULL, 1); | |
1052 | if (scan_res == NULL) { | |
5bc0cdb7 | 1053 | if (wpa_s->conf->ap_scan == 2 || ap) |
e1504976 | 1054 | return -1; |
f049052b BG |
1055 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " |
1056 | "scanning again"); | |
977b1174 | 1057 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
e1504976 | 1058 | return -1; |
6fc6879b JM |
1059 | } |
1060 | ||
bbb921da JM |
1061 | #ifndef CONFIG_NO_RANDOM_POOL |
1062 | size_t i, num; | |
1063 | num = scan_res->num; | |
1064 | if (num > 10) | |
1065 | num = 10; | |
1066 | for (i = 0; i < num; i++) { | |
1067 | u8 buf[5]; | |
1068 | struct wpa_scan_res *res = scan_res->res[i]; | |
1069 | buf[0] = res->bssid[5]; | |
1070 | buf[1] = res->qual & 0xff; | |
1071 | buf[2] = res->noise & 0xff; | |
1072 | buf[3] = res->level & 0xff; | |
1073 | buf[4] = res->tsf & 0xff; | |
1074 | random_add_randomness(buf, sizeof(buf)); | |
1075 | } | |
1076 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
1077 | ||
64e58f51 | 1078 | if (wpa_s->scan_res_handler) { |
860fddbb JB |
1079 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
1080 | struct wpa_scan_results *scan_res); | |
1081 | ||
1082 | scan_res_handler = wpa_s->scan_res_handler; | |
64e58f51 | 1083 | wpa_s->scan_res_handler = NULL; |
860fddbb JB |
1084 | scan_res_handler(wpa_s, scan_res); |
1085 | ||
64e58f51 | 1086 | wpa_scan_results_free(scan_res); |
e1504976 | 1087 | return 0; |
64e58f51 JM |
1088 | } |
1089 | ||
5bc0cdb7 | 1090 | if (ap) { |
f049052b | 1091 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); |
c202f19c JB |
1092 | #ifdef CONFIG_AP |
1093 | if (wpa_s->ap_iface->scan_cb) | |
1094 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); | |
1095 | #endif /* CONFIG_AP */ | |
5bc0cdb7 | 1096 | wpa_scan_results_free(scan_res); |
e1504976 | 1097 | return 0; |
5bc0cdb7 JM |
1098 | } |
1099 | ||
f049052b | 1100 | wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); |
24f76940 JM |
1101 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); |
1102 | wpas_notify_scan_results(wpa_s); | |
6fc6879b | 1103 | |
8bac466b JM |
1104 | wpas_notify_scan_done(wpa_s, 1); |
1105 | ||
a1fd2ce5 JM |
1106 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) { |
1107 | wpa_scan_results_free(scan_res); | |
e1504976 | 1108 | return 0; |
a1fd2ce5 | 1109 | } |
6fc6879b | 1110 | |
3180d7a2 SO |
1111 | if (wpa_s->disconnected) { |
1112 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
a1fd2ce5 | 1113 | wpa_scan_results_free(scan_res); |
e1504976 | 1114 | return 0; |
3180d7a2 SO |
1115 | } |
1116 | ||
22628eca JM |
1117 | if (!wpas_driver_bss_selection(wpa_s) && |
1118 | bgscan_notify_scan(wpa_s, scan_res) == 1) { | |
a1fd2ce5 | 1119 | wpa_scan_results_free(scan_res); |
e1504976 | 1120 | return 0; |
a1fd2ce5 JM |
1121 | } |
1122 | ||
a1fd2ce5 | 1123 | selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid); |
6ae93185 | 1124 | |
6fc6879b | 1125 | if (selected) { |
48563d86 JM |
1126 | int skip; |
1127 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid, | |
1128 | scan_res); | |
1129 | wpa_scan_results_free(scan_res); | |
1bbff09e JM |
1130 | if (skip) { |
1131 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
e1504976 | 1132 | return 0; |
1bbff09e | 1133 | } |
5cbd88d9 JJ |
1134 | |
1135 | if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { | |
1136 | wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); | |
1137 | return -1; | |
1138 | } | |
6d28fb96 | 1139 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
6fc6879b | 1140 | } else { |
48563d86 | 1141 | wpa_scan_results_free(scan_res); |
f049052b | 1142 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); |
b55aaa5f JM |
1143 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
1144 | if (ssid) { | |
f049052b | 1145 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); |
b55aaa5f | 1146 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
6d28fb96 | 1147 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
977b1174 | 1148 | } else { |
67b9bd08 | 1149 | int timeout_sec = wpa_s->scan_interval; |
977b1174 | 1150 | int timeout_usec = 0; |
0817de90 JM |
1151 | #ifdef CONFIG_P2P |
1152 | if (wpa_s->p2p_in_provisioning) { | |
1153 | /* | |
1154 | * Use shorter wait during P2P Provisioning | |
1155 | * state to speed up group formation. | |
1156 | */ | |
1157 | timeout_sec = 0; | |
1158 | timeout_usec = 250000; | |
a4cba8f1 LC |
1159 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
1160 | timeout_usec); | |
1161 | return 0; | |
0817de90 JM |
1162 | } |
1163 | #endif /* CONFIG_P2P */ | |
a4cba8f1 LC |
1164 | if (wpa_supplicant_req_sched_scan(wpa_s)) |
1165 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
1166 | timeout_usec); | |
977b1174 | 1167 | } |
6fc6879b | 1168 | } |
e1504976 | 1169 | return 0; |
6fc6879b | 1170 | } |
6859f1cb BG |
1171 | |
1172 | ||
1173 | static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, | |
1174 | union wpa_event_data *data) | |
1175 | { | |
1176 | const char *rn, *rn2; | |
1177 | struct wpa_supplicant *ifs; | |
1178 | ||
e1504976 BG |
1179 | if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) { |
1180 | /* | |
1181 | * If no scan results could be fetched, then no need to | |
1182 | * notify those interfaces that did not actually request | |
1183 | * this scan. | |
1184 | */ | |
1185 | return; | |
1186 | } | |
6859f1cb BG |
1187 | |
1188 | /* | |
1189 | * Check other interfaces to see if they have the same radio-name. If | |
1190 | * so, they get updated with this same scan info. | |
1191 | */ | |
1192 | if (!wpa_s->driver->get_radio_name) | |
1193 | return; | |
1194 | ||
1195 | rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv); | |
1196 | if (rn == NULL || rn[0] == '\0') | |
1197 | return; | |
1198 | ||
f049052b BG |
1199 | wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces " |
1200 | "sharing same radio (%s) in event_scan_results", rn); | |
6859f1cb BG |
1201 | |
1202 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { | |
1203 | if (ifs == wpa_s || !ifs->driver->get_radio_name) | |
1204 | continue; | |
1205 | ||
1206 | rn2 = ifs->driver->get_radio_name(ifs->drv_priv); | |
1207 | if (rn2 && os_strcmp(rn, rn2) == 0) { | |
1208 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " | |
1209 | "sibling", ifs->ifname); | |
1210 | _wpa_supplicant_event_scan_results(ifs, data); | |
1211 | } | |
1212 | } | |
1213 | } | |
1214 | ||
6fc6879b JM |
1215 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
1216 | ||
1217 | ||
579ce771 JM |
1218 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
1219 | union wpa_event_data *data) | |
6fc6879b JM |
1220 | { |
1221 | int l, len, found = 0, wpa_found, rsn_found; | |
c2a04078 | 1222 | const u8 *p; |
6fc6879b | 1223 | |
f049052b | 1224 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); |
6fc6879b JM |
1225 | if (data->assoc_info.req_ies) |
1226 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, | |
1227 | data->assoc_info.req_ies_len); | |
52c9e6f3 | 1228 | if (data->assoc_info.resp_ies) { |
6fc6879b JM |
1229 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, |
1230 | data->assoc_info.resp_ies_len); | |
52c9e6f3 JM |
1231 | #ifdef CONFIG_TDLS |
1232 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, | |
1233 | data->assoc_info.resp_ies_len); | |
1234 | #endif /* CONFIG_TDLS */ | |
1235 | } | |
6fc6879b JM |
1236 | if (data->assoc_info.beacon_ies) |
1237 | wpa_hexdump(MSG_DEBUG, "beacon_ies", | |
1238 | data->assoc_info.beacon_ies, | |
1239 | data->assoc_info.beacon_ies_len); | |
4832ecd7 | 1240 | if (data->assoc_info.freq) |
f049052b BG |
1241 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", |
1242 | data->assoc_info.freq); | |
6fc6879b JM |
1243 | |
1244 | p = data->assoc_info.req_ies; | |
1245 | l = data->assoc_info.req_ies_len; | |
1246 | ||
1247 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ | |
1248 | while (p && l >= 2) { | |
1249 | len = p[1] + 2; | |
1250 | if (len > l) { | |
1251 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1252 | p, l); | |
1253 | break; | |
1254 | } | |
1255 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1256 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || | |
1257 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { | |
1258 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) | |
1259 | break; | |
1260 | found = 1; | |
1261 | wpa_find_assoc_pmkid(wpa_s); | |
1262 | break; | |
1263 | } | |
1264 | l -= len; | |
1265 | p += len; | |
1266 | } | |
1267 | if (!found && data->assoc_info.req_ies) | |
1268 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
1269 | ||
c2a04078 | 1270 | #ifdef CONFIG_IEEE80211R |
62c72d72 JM |
1271 | #ifdef CONFIG_SME |
1272 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { | |
1273 | u8 bssid[ETH_ALEN]; | |
1274 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || | |
1275 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
1276 | data->assoc_info.resp_ies, | |
1277 | data->assoc_info.resp_ies_len, | |
1278 | bssid) < 0) { | |
f049052b BG |
1279 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
1280 | "Reassociation Response failed"); | |
579ce771 JM |
1281 | wpa_supplicant_deauthenticate( |
1282 | wpa_s, WLAN_REASON_INVALID_IE); | |
1283 | return -1; | |
62c72d72 JM |
1284 | } |
1285 | } | |
62c72d72 | 1286 | |
c2a04078 JM |
1287 | p = data->assoc_info.resp_ies; |
1288 | l = data->assoc_info.resp_ies_len; | |
1289 | ||
54f489be | 1290 | #ifdef CONFIG_WPS_STRICT |
5dac11e0 | 1291 | if (p && wpa_s->current_ssid && |
54f489be JM |
1292 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
1293 | struct wpabuf *wps; | |
1294 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); | |
1295 | if (wps == NULL) { | |
f049052b BG |
1296 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " |
1297 | "include WPS IE in (Re)Association Response"); | |
54f489be JM |
1298 | return -1; |
1299 | } | |
1300 | ||
1301 | if (wps_validate_assoc_resp(wps) < 0) { | |
1302 | wpabuf_free(wps); | |
1303 | wpa_supplicant_deauthenticate( | |
1304 | wpa_s, WLAN_REASON_INVALID_IE); | |
1305 | return -1; | |
1306 | } | |
1307 | wpabuf_free(wps); | |
1308 | } | |
1309 | #endif /* CONFIG_WPS_STRICT */ | |
1310 | ||
e7846b68 | 1311 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
c2a04078 JM |
1312 | while (p && l >= 2) { |
1313 | len = p[1] + 2; | |
1314 | if (len > l) { | |
1315 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1316 | p, l); | |
1317 | break; | |
1318 | } | |
e7846b68 JM |
1319 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
1320 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
1321 | wpa_s->sme.ft_used = 1; | |
1322 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, | |
1323 | MOBILITY_DOMAIN_ID_LEN); | |
1324 | break; | |
1325 | } | |
c2a04078 JM |
1326 | l -= len; |
1327 | p += len; | |
1328 | } | |
e7846b68 | 1329 | #endif /* CONFIG_SME */ |
c2a04078 | 1330 | |
e7846b68 JM |
1331 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
1332 | data->assoc_info.resp_ies_len); | |
c2a04078 JM |
1333 | #endif /* CONFIG_IEEE80211R */ |
1334 | ||
6fc6879b JM |
1335 | /* WPA/RSN IE from Beacon/ProbeResp */ |
1336 | p = data->assoc_info.beacon_ies; | |
1337 | l = data->assoc_info.beacon_ies_len; | |
1338 | ||
1339 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. | |
1340 | */ | |
1341 | wpa_found = rsn_found = 0; | |
1342 | while (p && l >= 2) { | |
1343 | len = p[1] + 2; | |
1344 | if (len > l) { | |
1345 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", | |
1346 | p, l); | |
1347 | break; | |
1348 | } | |
1349 | if (!wpa_found && | |
1350 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1351 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { | |
1352 | wpa_found = 1; | |
1353 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); | |
1354 | } | |
1355 | ||
1356 | if (!rsn_found && | |
1357 | p[0] == WLAN_EID_RSN && p[1] >= 2) { | |
1358 | rsn_found = 1; | |
1359 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); | |
1360 | } | |
1361 | ||
1362 | l -= len; | |
1363 | p += len; | |
1364 | } | |
1365 | ||
1366 | if (!wpa_found && data->assoc_info.beacon_ies) | |
1367 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
1368 | if (!rsn_found && data->assoc_info.beacon_ies) | |
1369 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
1370 | if (wpa_found || rsn_found) | |
1371 | wpa_s->ap_ies_from_associnfo = 1; | |
4832ecd7 | 1372 | |
117e812d JM |
1373 | if (wpa_s->assoc_freq && data->assoc_info.freq && |
1374 | wpa_s->assoc_freq != data->assoc_info.freq) { | |
1375 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " | |
1376 | "%u to %u MHz", | |
1377 | wpa_s->assoc_freq, data->assoc_info.freq); | |
1378 | wpa_supplicant_update_scan_results(wpa_s); | |
1379 | } | |
1380 | ||
4832ecd7 | 1381 | wpa_s->assoc_freq = data->assoc_info.freq; |
579ce771 JM |
1382 | |
1383 | return 0; | |
6fc6879b JM |
1384 | } |
1385 | ||
1386 | ||
cd2f4ddf SM |
1387 | static struct wpa_bss * wpa_supplicant_get_new_bss( |
1388 | struct wpa_supplicant *wpa_s, const u8 *bssid) | |
1389 | { | |
1390 | struct wpa_bss *bss = NULL; | |
1391 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1392 | ||
1393 | if (ssid->ssid_len > 0) | |
1394 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | |
1395 | if (!bss) | |
1396 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
1397 | ||
1398 | return bss; | |
1399 | } | |
1400 | ||
1401 | ||
6fc6879b JM |
1402 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, |
1403 | union wpa_event_data *data) | |
1404 | { | |
1405 | u8 bssid[ETH_ALEN]; | |
1d041bec | 1406 | int ft_completed; |
8bac466b | 1407 | int bssid_changed; |
0194fedb | 1408 | struct wpa_driver_capa capa; |
6fc6879b | 1409 | |
1d041bec JM |
1410 | #ifdef CONFIG_AP |
1411 | if (wpa_s->ap_iface) { | |
1412 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], | |
1413 | data->assoc_info.addr, | |
1414 | data->assoc_info.req_ies, | |
39b08b5f SP |
1415 | data->assoc_info.req_ies_len, |
1416 | data->assoc_info.reassoc); | |
1d041bec JM |
1417 | return; |
1418 | } | |
1419 | #endif /* CONFIG_AP */ | |
1420 | ||
1421 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); | |
579ce771 JM |
1422 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
1423 | return; | |
6fc6879b JM |
1424 | |
1425 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); | |
17fbb751 JM |
1426 | if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 && |
1427 | os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { | |
f049052b | 1428 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" |
6fc6879b | 1429 | MACSTR, MAC2STR(bssid)); |
bbb921da | 1430 | random_add_randomness(bssid, ETH_ALEN); |
8bac466b | 1431 | bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN); |
6fc6879b JM |
1432 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
1433 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
8bac466b JM |
1434 | if (bssid_changed) |
1435 | wpas_notify_bssid_changed(wpa_s); | |
1436 | ||
6fc6879b JM |
1437 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
1438 | wpa_clear_keys(wpa_s, bssid); | |
1439 | } | |
1440 | if (wpa_supplicant_select_config(wpa_s) < 0) { | |
1441 | wpa_supplicant_disassociate( | |
1442 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1443 | return; | |
1444 | } | |
8f770587 JM |
1445 | if (wpa_s->current_ssid) { |
1446 | struct wpa_bss *bss = NULL; | |
cd2f4ddf SM |
1447 | |
1448 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); | |
1449 | if (!bss) { | |
1450 | wpa_supplicant_update_scan_results(wpa_s); | |
1451 | ||
1452 | /* Get the BSS from the new scan results */ | |
1453 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); | |
1454 | } | |
1455 | ||
8f770587 JM |
1456 | if (bss) |
1457 | wpa_s->current_bss = bss; | |
1458 | } | |
cd2f4ddf SM |
1459 | |
1460 | if (wpa_s->conf->ap_scan == 1 && | |
1461 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { | |
1462 | if (wpa_supplicant_assoc_update_ie(wpa_s) < 0) | |
1463 | wpa_msg(wpa_s, MSG_WARNING, | |
1464 | "WPA/RSN IEs not updated"); | |
1465 | } | |
6fc6879b JM |
1466 | } |
1467 | ||
62fa124c JM |
1468 | #ifdef CONFIG_SME |
1469 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); | |
1470 | wpa_s->sme.prev_bssid_set = 1; | |
1471 | #endif /* CONFIG_SME */ | |
1472 | ||
6fc6879b JM |
1473 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
1474 | if (wpa_s->current_ssid) { | |
1475 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be | |
1476 | * initialized before association, but for other modes, | |
1477 | * initialize PC/SC here, if the current configuration needs | |
1478 | * smartcard or SIM/USIM. */ | |
1479 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); | |
1480 | } | |
1481 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); | |
3f967fe0 JM |
1482 | if (wpa_s->l2) |
1483 | l2_packet_notify_auth_start(wpa_s->l2); | |
6fc6879b JM |
1484 | |
1485 | /* | |
1486 | * Set portEnabled first to FALSE in order to get EAP state machine out | |
1487 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE | |
1488 | * state machine may transit to AUTHENTICATING state based on obsolete | |
1489 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to | |
1490 | * AUTHENTICATED without ever giving chance to EAP state machine to | |
1491 | * reset the state. | |
1492 | */ | |
1493 | if (!ft_completed) { | |
1494 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
1495 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
1496 | } | |
56586197 | 1497 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) |
6fc6879b JM |
1498 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
1499 | /* 802.1X::portControl = Auto */ | |
1500 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); | |
1501 | wpa_s->eapol_received = 0; | |
1502 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
9c972abb JM |
1503 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
1504 | (wpa_s->current_ssid && | |
1505 | wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { | |
6fc6879b JM |
1506 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
1507 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1508 | } else if (!ft_completed) { | |
1509 | /* Timeout for receiving the first EAPOL packet */ | |
1510 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); | |
1511 | } | |
1512 | wpa_supplicant_cancel_scan(wpa_s); | |
1513 | ||
c2a04078 | 1514 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
56586197 | 1515 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1516 | /* |
1517 | * We are done; the driver will take care of RSN 4-way | |
1518 | * handshake. | |
1519 | */ | |
1520 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1521 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1522 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1523 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
98ea9431 JM |
1524 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
1525 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
1526 | /* | |
1527 | * The driver will take care of RSN 4-way handshake, so we need | |
1528 | * to allow EAPOL supplicant to complete its work without | |
1529 | * waiting for WPA supplicant. | |
1530 | */ | |
1531 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
16a83d29 JM |
1532 | } else if (ft_completed) { |
1533 | /* | |
1534 | * FT protocol completed - make sure EAPOL state machine ends | |
1535 | * up in authenticated. | |
1536 | */ | |
1537 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1538 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1539 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1540 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
6fc6879b | 1541 | } |
1ff73338 JM |
1542 | |
1543 | if (wpa_s->pending_eapol_rx) { | |
1544 | struct os_time now, age; | |
1545 | os_get_time(&now); | |
1546 | os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age); | |
1547 | if (age.sec == 0 && age.usec < 100000 && | |
1548 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == | |
1549 | 0) { | |
f049052b BG |
1550 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " |
1551 | "frame that was received just before " | |
1552 | "association notification"); | |
1ff73338 JM |
1553 | wpa_supplicant_rx_eapol( |
1554 | wpa_s, wpa_s->pending_eapol_rx_src, | |
1555 | wpabuf_head(wpa_s->pending_eapol_rx), | |
1556 | wpabuf_len(wpa_s->pending_eapol_rx)); | |
1557 | } | |
1558 | wpabuf_free(wpa_s->pending_eapol_rx); | |
1559 | wpa_s->pending_eapol_rx = NULL; | |
1560 | } | |
60b94c98 | 1561 | |
0194fedb JB |
1562 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
1563 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
1564 | wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 && | |
1565 | capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) { | |
1566 | /* Set static WEP keys again */ | |
1567 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); | |
1568 | } | |
50b05780 JM |
1569 | |
1570 | #ifdef CONFIG_IBSS_RSN | |
1571 | if (wpa_s->current_ssid && | |
1572 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
1573 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && | |
78177a00 JM |
1574 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && |
1575 | wpa_s->ibss_rsn == NULL) { | |
1576 | wpa_s->ibss_rsn = ibss_rsn_init(wpa_s); | |
1577 | if (!wpa_s->ibss_rsn) { | |
1578 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); | |
1579 | wpa_supplicant_deauthenticate( | |
1580 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1581 | return; | |
1582 | } | |
1583 | ||
1584 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); | |
1585 | } | |
50b05780 | 1586 | #endif /* CONFIG_IBSS_RSN */ |
6fc6879b JM |
1587 | } |
1588 | ||
1589 | ||
d00821e9 JM |
1590 | static int disconnect_reason_recoverable(u16 reason_code) |
1591 | { | |
1592 | return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || | |
1593 | reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || | |
1594 | reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; | |
1595 | } | |
1596 | ||
1597 | ||
0544b242 | 1598 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
3d9975d5 JM |
1599 | u16 reason_code, |
1600 | int locally_generated) | |
6fc6879b JM |
1601 | { |
1602 | const u8 *bssid; | |
6d6f4bb8 JM |
1603 | int authenticating; |
1604 | u8 prev_pending_bssid[ETH_ALEN]; | |
d00821e9 JM |
1605 | struct wpa_bss *fast_reconnect = NULL; |
1606 | struct wpa_ssid *fast_reconnect_ssid = NULL; | |
6d6f4bb8 JM |
1607 | |
1608 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; | |
1609 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); | |
6fc6879b JM |
1610 | |
1611 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
1612 | /* | |
1613 | * At least Host AP driver and a Prism3 card seemed to be | |
1614 | * generating streams of disconnected events when configuring | |
1615 | * IBSS for WPA-None. Ignore them for now. | |
1616 | */ | |
f049052b BG |
1617 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " |
1618 | "IBSS/WPA-None mode"); | |
6fc6879b JM |
1619 | return; |
1620 | } | |
1621 | ||
1622 | if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE && | |
56586197 | 1623 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1624 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
1625 | "pre-shared key may be incorrect"); | |
1626 | } | |
0d0a8ca1 AC |
1627 | if (!wpa_s->auto_reconnect_disabled || |
1628 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { | |
d00821e9 | 1629 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " |
f7da5a9e JM |
1630 | "reconnect (wps=%d wpa_state=%d)", |
1631 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, | |
1632 | wpa_s->wpa_state); | |
d00821e9 JM |
1633 | if (wpa_s->wpa_state == WPA_COMPLETED && |
1634 | wpa_s->current_ssid && | |
1635 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && | |
3d9975d5 | 1636 | !locally_generated && |
d00821e9 JM |
1637 | disconnect_reason_recoverable(reason_code)) { |
1638 | /* | |
1639 | * It looks like the AP has dropped association with | |
1640 | * us, but could allow us to get back in. Try to | |
1641 | * reconnect to the same BSS without full scan to save | |
1642 | * time for some common cases. | |
1643 | */ | |
1644 | fast_reconnect = wpa_s->current_bss; | |
1645 | fast_reconnect_ssid = wpa_s->current_ssid; | |
1646 | } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) | |
0d0a8ca1 | 1647 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
f7da5a9e JM |
1648 | else |
1649 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " | |
1650 | "immediate scan"); | |
0d0a8ca1 | 1651 | } else { |
d00821e9 | 1652 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " |
f049052b | 1653 | "try to re-connect"); |
0d0a8ca1 AC |
1654 | wpa_s->reassociate = 0; |
1655 | wpa_s->disconnected = 1; | |
433cd2ce | 1656 | wpa_supplicant_cancel_sched_scan(wpa_s); |
0d0a8ca1 | 1657 | } |
6fc6879b | 1658 | bssid = wpa_s->bssid; |
a8e16edc | 1659 | if (is_zero_ether_addr(bssid)) |
6fc6879b | 1660 | bssid = wpa_s->pending_bssid; |
56d24b4e JM |
1661 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
1662 | wpas_connection_failed(wpa_s, bssid); | |
6fc6879b | 1663 | wpa_sm_notify_disassoc(wpa_s->wpa); |
0544b242 JM |
1664 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR |
1665 | " reason=%d", | |
1666 | MAC2STR(bssid), reason_code); | |
6fc6879b | 1667 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
f049052b | 1668 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); |
6fc6879b JM |
1669 | wpa_s->keys_cleared = 0; |
1670 | wpa_clear_keys(wpa_s, wpa_s->bssid); | |
1671 | } | |
1672 | wpa_supplicant_mark_disassoc(wpa_s); | |
e29853bb BG |
1673 | |
1674 | if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
1675 | sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); | |
d00821e9 JM |
1676 | |
1677 | if (fast_reconnect) { | |
5928411e | 1678 | #ifndef CONFIG_NO_SCAN_PROCESSING |
d00821e9 JM |
1679 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); |
1680 | if (wpa_supplicant_connect(wpa_s, fast_reconnect, | |
1681 | fast_reconnect_ssid) < 0) { | |
1682 | /* Recover through full scan */ | |
1683 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
1684 | } | |
5928411e | 1685 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
d00821e9 | 1686 | } |
6fc6879b JM |
1687 | } |
1688 | ||
1689 | ||
46690a3b | 1690 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
01a17491 | 1691 | void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx) |
46690a3b JM |
1692 | { |
1693 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1694 | ||
1695 | if (!wpa_s->pending_mic_error_report) | |
1696 | return; | |
1697 | ||
f049052b | 1698 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); |
46690a3b JM |
1699 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); |
1700 | wpa_s->pending_mic_error_report = 0; | |
1701 | } | |
1702 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1703 | ||
1704 | ||
6fc6879b JM |
1705 | static void |
1706 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, | |
1707 | union wpa_event_data *data) | |
1708 | { | |
1709 | int pairwise; | |
1710 | struct os_time t; | |
1711 | ||
1712 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); | |
1713 | pairwise = (data && data->michael_mic_failure.unicast); | |
6fc6879b | 1714 | os_get_time(&t); |
46690a3b JM |
1715 | if ((wpa_s->last_michael_mic_error && |
1716 | t.sec - wpa_s->last_michael_mic_error <= 60) || | |
1717 | wpa_s->pending_mic_error_report) { | |
1718 | if (wpa_s->pending_mic_error_report) { | |
1719 | /* | |
1720 | * Send the pending MIC error report immediately since | |
1721 | * we are going to start countermeasures and AP better | |
1722 | * do the same. | |
1723 | */ | |
1724 | wpa_sm_key_request(wpa_s->wpa, 1, | |
1725 | wpa_s->pending_mic_error_pairwise); | |
1726 | } | |
1727 | ||
1728 | /* Send the new MIC error report immediately since we are going | |
1729 | * to start countermeasures and AP better do the same. | |
1730 | */ | |
1731 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1732 | ||
6fc6879b JM |
1733 | /* initialize countermeasures */ |
1734 | wpa_s->countermeasures = 1; | |
8945cc45 BM |
1735 | |
1736 | wpa_blacklist_add(wpa_s, wpa_s->bssid); | |
1737 | ||
6fc6879b JM |
1738 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); |
1739 | ||
1740 | /* | |
1741 | * Need to wait for completion of request frame. We do not get | |
1742 | * any callback for the message completion, so just wait a | |
1743 | * short while and hope for the best. */ | |
1744 | os_sleep(0, 10000); | |
1745 | ||
1746 | wpa_drv_set_countermeasures(wpa_s, 1); | |
1747 | wpa_supplicant_deauthenticate(wpa_s, | |
1748 | WLAN_REASON_MICHAEL_MIC_FAILURE); | |
1749 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, | |
1750 | wpa_s, NULL); | |
1751 | eloop_register_timeout(60, 0, | |
1752 | wpa_supplicant_stop_countermeasures, | |
1753 | wpa_s, NULL); | |
1754 | /* TODO: mark the AP rejected for 60 second. STA is | |
1755 | * allowed to associate with another AP.. */ | |
46690a3b JM |
1756 | } else { |
1757 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
1758 | if (wpa_s->mic_errors_seen) { | |
1759 | /* | |
1760 | * Reduce the effectiveness of Michael MIC error | |
1761 | * reports as a means for attacking against TKIP if | |
1762 | * more than one MIC failure is noticed with the same | |
1763 | * PTK. We delay the transmission of the reports by a | |
1764 | * random time between 0 and 60 seconds in order to | |
1765 | * force the attacker wait 60 seconds before getting | |
1766 | * the information on whether a frame resulted in a MIC | |
1767 | * failure. | |
1768 | */ | |
1769 | u8 rval[4]; | |
1770 | int sec; | |
1771 | ||
1772 | if (os_get_random(rval, sizeof(rval)) < 0) | |
1773 | sec = os_random() % 60; | |
1774 | else | |
1775 | sec = WPA_GET_BE32(rval) % 60; | |
f049052b BG |
1776 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " |
1777 | "report %d seconds", sec); | |
46690a3b JM |
1778 | wpa_s->pending_mic_error_report = 1; |
1779 | wpa_s->pending_mic_error_pairwise = pairwise; | |
1780 | eloop_cancel_timeout( | |
1781 | wpa_supplicant_delayed_mic_error_report, | |
1782 | wpa_s, NULL); | |
1783 | eloop_register_timeout( | |
1784 | sec, os_random() % 1000000, | |
1785 | wpa_supplicant_delayed_mic_error_report, | |
1786 | wpa_s, NULL); | |
1787 | } else { | |
1788 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1789 | } | |
1790 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1791 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1792 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
6fc6879b JM |
1793 | } |
1794 | wpa_s->last_michael_mic_error = t.sec; | |
46690a3b | 1795 | wpa_s->mic_errors_seen++; |
6fc6879b JM |
1796 | } |
1797 | ||
1798 | ||
a83d9c96 SL |
1799 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1800 | static int any_interfaces(struct wpa_supplicant *head) | |
1801 | { | |
1802 | struct wpa_supplicant *wpa_s; | |
1803 | ||
1804 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) | |
1805 | if (!wpa_s->interface_removed) | |
1806 | return 1; | |
1807 | return 0; | |
1808 | } | |
1809 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
1810 | ||
1811 | ||
6fc6879b JM |
1812 | static void |
1813 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, | |
1814 | union wpa_event_data *data) | |
1815 | { | |
1816 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) | |
1817 | return; | |
1818 | ||
1819 | switch (data->interface_status.ievent) { | |
1820 | case EVENT_INTERFACE_ADDED: | |
1821 | if (!wpa_s->interface_removed) | |
1822 | break; | |
1823 | wpa_s->interface_removed = 0; | |
f049052b | 1824 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); |
6fc6879b | 1825 | if (wpa_supplicant_driver_init(wpa_s) < 0) { |
f049052b BG |
1826 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " |
1827 | "driver after interface was added"); | |
6fc6879b JM |
1828 | } |
1829 | break; | |
1830 | case EVENT_INTERFACE_REMOVED: | |
f049052b | 1831 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); |
6fc6879b JM |
1832 | wpa_s->interface_removed = 1; |
1833 | wpa_supplicant_mark_disassoc(wpa_s); | |
1834 | l2_packet_deinit(wpa_s->l2); | |
1835 | wpa_s->l2 = NULL; | |
ea244d21 | 1836 | #ifdef CONFIG_IBSS_RSN |
78177a00 JM |
1837 | ibss_rsn_deinit(wpa_s->ibss_rsn); |
1838 | wpa_s->ibss_rsn = NULL; | |
ea244d21 | 1839 | #endif /* CONFIG_IBSS_RSN */ |
a83d9c96 SL |
1840 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1841 | /* check if last interface */ | |
1842 | if (!any_interfaces(wpa_s->global->ifaces)) | |
1843 | eloop_terminate(); | |
1844 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
6fc6879b JM |
1845 | break; |
1846 | } | |
1847 | } | |
1848 | ||
1849 | ||
1850 | #ifdef CONFIG_PEERKEY | |
1851 | static void | |
1852 | wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, | |
1853 | union wpa_event_data *data) | |
1854 | { | |
1855 | if (data == NULL) | |
1856 | return; | |
1857 | wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); | |
1858 | } | |
1859 | #endif /* CONFIG_PEERKEY */ | |
1860 | ||
1861 | ||
281ff0aa GP |
1862 | #ifdef CONFIG_TDLS |
1863 | static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, | |
1864 | union wpa_event_data *data) | |
1865 | { | |
1866 | if (data == NULL) | |
1867 | return; | |
1868 | switch (data->tdls.oper) { | |
1869 | case TDLS_REQUEST_SETUP: | |
1870 | wpa_tdls_start(wpa_s->wpa, data->tdls.peer); | |
1871 | break; | |
1872 | case TDLS_REQUEST_TEARDOWN: | |
7de27409 AN |
1873 | wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer, |
1874 | data->tdls.reason_code); | |
281ff0aa GP |
1875 | break; |
1876 | } | |
1877 | } | |
1878 | #endif /* CONFIG_TDLS */ | |
1879 | ||
1880 | ||
6fc6879b JM |
1881 | #ifdef CONFIG_IEEE80211R |
1882 | static void | |
1883 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, | |
1884 | union wpa_event_data *data) | |
1885 | { | |
1886 | if (data == NULL) | |
1887 | return; | |
1888 | ||
1889 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, | |
1890 | data->ft_ies.ies_len, | |
1891 | data->ft_ies.ft_action, | |
babfbf15 JM |
1892 | data->ft_ies.target_ap, |
1893 | data->ft_ies.ric_ies, | |
1894 | data->ft_ies.ric_ies_len) < 0) { | |
6fc6879b JM |
1895 | /* TODO: prevent MLME/driver from trying to associate? */ |
1896 | } | |
1897 | } | |
1898 | #endif /* CONFIG_IEEE80211R */ | |
1899 | ||
1900 | ||
11ef8d35 JM |
1901 | #ifdef CONFIG_IBSS_RSN |
1902 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, | |
1903 | union wpa_event_data *data) | |
1904 | { | |
df4bc509 | 1905 | struct wpa_ssid *ssid; |
df418245 XC |
1906 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
1907 | return; | |
11ef8d35 JM |
1908 | if (data == NULL) |
1909 | return; | |
df4bc509 JM |
1910 | ssid = wpa_s->current_ssid; |
1911 | if (ssid == NULL) | |
1912 | return; | |
1913 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
1914 | return; | |
1915 | ||
11ef8d35 JM |
1916 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); |
1917 | } | |
1918 | #endif /* CONFIG_IBSS_RSN */ | |
1919 | ||
1920 | ||
036f7c4a JM |
1921 | #ifdef CONFIG_IEEE80211R |
1922 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, | |
1923 | size_t len) | |
1924 | { | |
1925 | const u8 *sta_addr, *target_ap_addr; | |
1926 | u16 status; | |
1927 | ||
1928 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); | |
1929 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
1930 | return; /* only SME case supported for now */ | |
1931 | if (len < 1 + 2 * ETH_ALEN + 2) | |
1932 | return; | |
1933 | if (data[0] != 2) | |
1934 | return; /* Only FT Action Response is supported for now */ | |
1935 | sta_addr = data + 1; | |
1936 | target_ap_addr = data + 1 + ETH_ALEN; | |
1937 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); | |
f049052b BG |
1938 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " |
1939 | MACSTR " TargetAP " MACSTR " status %u", | |
1940 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); | |
036f7c4a JM |
1941 | |
1942 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { | |
f049052b BG |
1943 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR |
1944 | " in FT Action Response", MAC2STR(sta_addr)); | |
036f7c4a JM |
1945 | return; |
1946 | } | |
1947 | ||
1948 | if (status) { | |
f049052b BG |
1949 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " |
1950 | "failure (status code %d)", status); | |
036f7c4a JM |
1951 | /* TODO: report error to FT code(?) */ |
1952 | return; | |
1953 | } | |
1954 | ||
1955 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, | |
1956 | len - (1 + 2 * ETH_ALEN + 2), 1, | |
1957 | target_ap_addr, NULL, 0) < 0) | |
1958 | return; | |
1959 | ||
fe191985 JM |
1960 | #ifdef CONFIG_SME |
1961 | { | |
1962 | struct wpa_bss *bss; | |
1963 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); | |
1964 | if (bss) | |
1965 | wpa_s->sme.freq = bss->freq; | |
62c72d72 | 1966 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
fe191985 JM |
1967 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
1968 | WLAN_AUTH_FT); | |
1969 | } | |
1970 | #endif /* CONFIG_SME */ | |
036f7c4a JM |
1971 | } |
1972 | #endif /* CONFIG_IEEE80211R */ | |
1973 | ||
1974 | ||
7d878ca7 JM |
1975 | static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, |
1976 | struct unprot_deauth *e) | |
1977 | { | |
1978 | #ifdef CONFIG_IEEE80211W | |
1979 | wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " | |
1980 | "dropped: " MACSTR " -> " MACSTR | |
1981 | " (reason code %u)", | |
1982 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
1983 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
1984 | #endif /* CONFIG_IEEE80211W */ | |
1985 | } | |
1986 | ||
1987 | ||
1988 | static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, | |
1989 | struct unprot_disassoc *e) | |
1990 | { | |
1991 | #ifdef CONFIG_IEEE80211W | |
1992 | wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " | |
1993 | "dropped: " MACSTR " -> " MACSTR | |
1994 | " (reason code %u)", | |
1995 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
1996 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
1997 | #endif /* CONFIG_IEEE80211W */ | |
1998 | } | |
1999 | ||
2000 | ||
71269b37 JM |
2001 | static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx) |
2002 | { | |
2003 | u8 action, mode; | |
2004 | const u8 *pos, *end; | |
2005 | ||
2006 | if (rx->data == NULL || rx->len == 0) | |
2007 | return; | |
2008 | ||
2009 | pos = rx->data; | |
2010 | end = pos + rx->len; | |
2011 | action = *pos++; | |
2012 | ||
2013 | wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR, | |
2014 | action, MAC2STR(rx->sa)); | |
2015 | switch (action) { | |
2016 | case WNM_BSS_TRANS_MGMT_REQ: | |
2017 | if (pos + 5 > end) | |
2018 | break; | |
2019 | wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management " | |
2020 | "Request: dialog_token=%u request_mode=0x%x " | |
2021 | "disassoc_timer=%u validity_interval=%u", | |
2022 | pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]); | |
2023 | mode = pos[1]; | |
2024 | pos += 5; | |
2025 | if (mode & 0x08) | |
2026 | pos += 12; /* BSS Termination Duration */ | |
2027 | if (mode & 0x10) { | |
2028 | char url[256]; | |
2029 | if (pos + 1 > end || pos + 1 + pos[0] > end) { | |
2030 | wpa_printf(MSG_DEBUG, "WNM: Invalid BSS " | |
2031 | "Transition Management Request " | |
2032 | "(URL)"); | |
2033 | break; | |
2034 | } | |
2035 | os_memcpy(url, pos + 1, pos[0]); | |
2036 | url[pos[0]] = '\0'; | |
2037 | wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation " | |
2038 | "Imminent - session_info_url=%s", url); | |
2039 | } | |
2040 | break; | |
2041 | } | |
2042 | } | |
2043 | ||
2044 | ||
9646a8ab | 2045 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
6fc6879b JM |
2046 | union wpa_event_data *data) |
2047 | { | |
2048 | struct wpa_supplicant *wpa_s = ctx; | |
0544b242 | 2049 | u16 reason_code = 0; |
3d9975d5 | 2050 | int locally_generated = 0; |
6fc6879b | 2051 | |
8401a6b0 JM |
2052 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
2053 | event != EVENT_INTERFACE_ENABLED && | |
9b6f44cb JM |
2054 | event != EVENT_INTERFACE_STATUS && |
2055 | event != EVENT_SCHED_SCAN_STOPPED) { | |
6c3771d7 BG |
2056 | wpa_dbg(wpa_s, MSG_DEBUG, |
2057 | "Ignore event %s (%d) while interface is disabled", | |
2058 | event_to_string(event), event); | |
8401a6b0 JM |
2059 | return; |
2060 | } | |
2061 | ||
74781dfc JM |
2062 | #ifndef CONFIG_NO_STDOUT_DEBUG |
2063 | { | |
2064 | int level = MSG_DEBUG; | |
2065 | ||
2066 | if (event == EVENT_RX_MGMT && data && data->rx_mgmt.frame && | |
2067 | data->rx_mgmt.frame_len >= 24) { | |
2068 | const struct ieee80211_hdr *hdr; | |
2069 | u16 fc; | |
2070 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; | |
2071 | fc = le_to_host16(hdr->frame_control); | |
2072 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
2073 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
2074 | level = MSG_EXCESSIVE; | |
2075 | } | |
2076 | ||
2077 | wpa_dbg(wpa_s, level, "Event %s (%d) received", | |
6c3771d7 | 2078 | event_to_string(event), event); |
74781dfc JM |
2079 | } |
2080 | #endif /* CONFIG_NO_STDOUT_DEBUG */ | |
9b7124b2 | 2081 | |
6fc6879b | 2082 | switch (event) { |
c2a04078 JM |
2083 | case EVENT_AUTH: |
2084 | sme_event_auth(wpa_s, data); | |
2085 | break; | |
6fc6879b JM |
2086 | case EVENT_ASSOC: |
2087 | wpa_supplicant_event_assoc(wpa_s, data); | |
2088 | break; | |
2089 | case EVENT_DISASSOC: | |
f049052b | 2090 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); |
2e75a2b3 | 2091 | if (data) { |
3d9975d5 JM |
2092 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", |
2093 | data->disassoc_info.reason_code, | |
2094 | data->disassoc_info.locally_generated ? | |
2095 | " (locally generated)" : ""); | |
2e75a2b3 | 2096 | if (data->disassoc_info.addr) |
f049052b BG |
2097 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, |
2098 | MAC2STR(data->disassoc_info.addr)); | |
2e75a2b3 | 2099 | } |
1d041bec | 2100 | #ifdef CONFIG_AP |
7f542069 | 2101 | if (wpa_s->ap_iface && data && data->disassoc_info.addr) { |
1d041bec JM |
2102 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], |
2103 | data->disassoc_info.addr); | |
2104 | break; | |
2105 | } | |
4551dd90 JM |
2106 | if (wpa_s->ap_iface) { |
2107 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in " | |
2108 | "AP mode"); | |
2109 | break; | |
2110 | } | |
1d041bec | 2111 | #endif /* CONFIG_AP */ |
9fdd0fad JM |
2112 | if (data) { |
2113 | reason_code = data->disassoc_info.reason_code; | |
3d9975d5 JM |
2114 | locally_generated = |
2115 | data->disassoc_info.locally_generated; | |
9fdd0fad JM |
2116 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", |
2117 | data->disassoc_info.ie, | |
2118 | data->disassoc_info.ie_len); | |
2119 | #ifdef CONFIG_P2P | |
2120 | wpas_p2p_disassoc_notif( | |
2121 | wpa_s, data->disassoc_info.addr, reason_code, | |
2122 | data->disassoc_info.ie, | |
2123 | data->disassoc_info.ie_len); | |
2124 | #endif /* CONFIG_P2P */ | |
2125 | } | |
0e379654 JM |
2126 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
2127 | sme_event_disassoc(wpa_s, data); | |
a84ed99e JM |
2128 | /* fall through */ |
2129 | case EVENT_DEAUTH: | |
0544b242 | 2130 | if (event == EVENT_DEAUTH) { |
f049052b BG |
2131 | wpa_dbg(wpa_s, MSG_DEBUG, |
2132 | "Deauthentication notification"); | |
2e75a2b3 | 2133 | if (data) { |
0544b242 | 2134 | reason_code = data->deauth_info.reason_code; |
3d9975d5 JM |
2135 | locally_generated = |
2136 | data->deauth_info.locally_generated; | |
2137 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", | |
2138 | data->deauth_info.reason_code, | |
2139 | data->deauth_info.locally_generated ? | |
2140 | " (locally generated)" : ""); | |
2e75a2b3 | 2141 | if (data->deauth_info.addr) { |
f049052b BG |
2142 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " |
2143 | MACSTR, | |
2144 | MAC2STR(data->deauth_info. | |
2145 | addr)); | |
2e75a2b3 | 2146 | } |
9fdd0fad JM |
2147 | wpa_hexdump(MSG_DEBUG, |
2148 | "Deauthentication frame IE(s)", | |
2149 | data->deauth_info.ie, | |
2150 | data->deauth_info.ie_len); | |
2151 | #ifdef CONFIG_P2P | |
2152 | wpas_p2p_deauth_notif( | |
2153 | wpa_s, data->deauth_info.addr, | |
2154 | reason_code, | |
2155 | data->deauth_info.ie, | |
2156 | data->deauth_info.ie_len); | |
2157 | #endif /* CONFIG_P2P */ | |
2e75a2b3 | 2158 | } |
0544b242 | 2159 | } |
1d041bec | 2160 | #ifdef CONFIG_AP |
7f542069 | 2161 | if (wpa_s->ap_iface && data && data->deauth_info.addr) { |
1d041bec JM |
2162 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], |
2163 | data->deauth_info.addr); | |
2164 | break; | |
2165 | } | |
4551dd90 JM |
2166 | if (wpa_s->ap_iface) { |
2167 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in " | |
2168 | "AP mode"); | |
2169 | break; | |
2170 | } | |
1d041bec | 2171 | #endif /* CONFIG_AP */ |
3d9975d5 JM |
2172 | wpa_supplicant_event_disassoc(wpa_s, reason_code, |
2173 | locally_generated); | |
6fc6879b JM |
2174 | break; |
2175 | case EVENT_MICHAEL_MIC_FAILURE: | |
2176 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); | |
2177 | break; | |
2178 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
2179 | case EVENT_SCAN_RESULTS: | |
8d923a4a | 2180 | wpa_supplicant_event_scan_results(wpa_s, data); |
6fc6879b JM |
2181 | break; |
2182 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
2183 | case EVENT_ASSOCINFO: | |
2184 | wpa_supplicant_event_associnfo(wpa_s, data); | |
2185 | break; | |
2186 | case EVENT_INTERFACE_STATUS: | |
2187 | wpa_supplicant_event_interface_status(wpa_s, data); | |
2188 | break; | |
2189 | case EVENT_PMKID_CANDIDATE: | |
2190 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); | |
2191 | break; | |
2192 | #ifdef CONFIG_PEERKEY | |
2193 | case EVENT_STKSTART: | |
2194 | wpa_supplicant_event_stkstart(wpa_s, data); | |
2195 | break; | |
2196 | #endif /* CONFIG_PEERKEY */ | |
281ff0aa GP |
2197 | #ifdef CONFIG_TDLS |
2198 | case EVENT_TDLS: | |
2199 | wpa_supplicant_event_tdls(wpa_s, data); | |
2200 | break; | |
2201 | #endif /* CONFIG_TDLS */ | |
6fc6879b JM |
2202 | #ifdef CONFIG_IEEE80211R |
2203 | case EVENT_FT_RESPONSE: | |
2204 | wpa_supplicant_event_ft_response(wpa_s, data); | |
2205 | break; | |
2206 | #endif /* CONFIG_IEEE80211R */ | |
11ef8d35 JM |
2207 | #ifdef CONFIG_IBSS_RSN |
2208 | case EVENT_IBSS_RSN_START: | |
2209 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); | |
2210 | break; | |
2211 | #endif /* CONFIG_IBSS_RSN */ | |
efa46078 | 2212 | case EVENT_ASSOC_REJECT: |
c05d6d18 JM |
2213 | if (data->assoc_reject.bssid) |
2214 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
2215 | "bssid=" MACSTR " status_code=%u", | |
2216 | MAC2STR(data->assoc_reject.bssid), | |
2217 | data->assoc_reject.status_code); | |
2218 | else | |
2219 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
2220 | "status_code=%u", | |
2221 | data->assoc_reject.status_code); | |
ea78c315 JM |
2222 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
2223 | sme_event_assoc_reject(wpa_s, data); | |
efa46078 | 2224 | break; |
da1fb17c | 2225 | case EVENT_AUTH_TIMED_OUT: |
ea78c315 JM |
2226 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
2227 | sme_event_auth_timed_out(wpa_s, data); | |
da1fb17c JM |
2228 | break; |
2229 | case EVENT_ASSOC_TIMED_OUT: | |
ea78c315 JM |
2230 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
2231 | sme_event_assoc_timed_out(wpa_s, data); | |
da1fb17c | 2232 | break; |
f8b1f695 | 2233 | case EVENT_TX_STATUS: |
f049052b BG |
2234 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR |
2235 | " type=%d stype=%d", | |
2236 | MAC2STR(data->tx_status.dst), | |
2237 | data->tx_status.type, data->tx_status.stype); | |
24f6497c | 2238 | #ifdef CONFIG_AP |
9bae1be0 | 2239 | if (wpa_s->ap_iface == NULL) { |
24f6497c | 2240 | #ifdef CONFIG_OFFCHANNEL |
9bae1be0 JM |
2241 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
2242 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) | |
24f6497c | 2243 | offchannel_send_action_tx_status( |
9bae1be0 JM |
2244 | wpa_s, data->tx_status.dst, |
2245 | data->tx_status.data, | |
2246 | data->tx_status.data_len, | |
93b7ddd0 | 2247 | data->tx_status.ack ? |
24f6497c JM |
2248 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
2249 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
2250 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
2251 | break; |
2252 | } | |
24f6497c JM |
2253 | #endif /* CONFIG_AP */ |
2254 | #ifdef CONFIG_OFFCHANNEL | |
f049052b BG |
2255 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" |
2256 | MACSTR, MAC2STR(wpa_s->parent->pending_action_dst)); | |
9bae1be0 JM |
2257 | /* |
2258 | * Catch TX status events for Action frames we sent via group | |
2259 | * interface in GO mode. | |
2260 | */ | |
2261 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && | |
2262 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && | |
2263 | os_memcmp(wpa_s->parent->pending_action_dst, | |
2264 | data->tx_status.dst, ETH_ALEN) == 0) { | |
24f6497c | 2265 | offchannel_send_action_tx_status( |
9bae1be0 JM |
2266 | wpa_s->parent, data->tx_status.dst, |
2267 | data->tx_status.data, | |
2268 | data->tx_status.data_len, | |
1d39378a | 2269 | data->tx_status.ack ? |
24f6497c JM |
2270 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
2271 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
f8b1f695 | 2272 | break; |
9bae1be0 | 2273 | } |
24f6497c JM |
2274 | #endif /* CONFIG_OFFCHANNEL */ |
2275 | #ifdef CONFIG_AP | |
f8b1f695 JM |
2276 | switch (data->tx_status.type) { |
2277 | case WLAN_FC_TYPE_MGMT: | |
2278 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, | |
2279 | data->tx_status.data_len, | |
2280 | data->tx_status.stype, | |
2281 | data->tx_status.ack); | |
2282 | break; | |
2283 | case WLAN_FC_TYPE_DATA: | |
2284 | ap_tx_status(wpa_s, data->tx_status.dst, | |
2285 | data->tx_status.data, | |
2286 | data->tx_status.data_len, | |
2287 | data->tx_status.ack); | |
2288 | break; | |
2289 | } | |
24f6497c | 2290 | #endif /* CONFIG_AP */ |
f8b1f695 | 2291 | break; |
24f6497c | 2292 | #ifdef CONFIG_AP |
dd840f79 JB |
2293 | case EVENT_EAPOL_TX_STATUS: |
2294 | ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst, | |
2295 | data->eapol_tx_status.data, | |
2296 | data->eapol_tx_status.data_len, | |
2297 | data->eapol_tx_status.ack); | |
2298 | break; | |
bcf24348 JB |
2299 | case EVENT_DRIVER_CLIENT_POLL_OK: |
2300 | ap_client_poll_ok(wpa_s, data->client_poll.addr); | |
2301 | break; | |
f8b1f695 JM |
2302 | case EVENT_RX_FROM_UNKNOWN: |
2303 | if (wpa_s->ap_iface == NULL) | |
2304 | break; | |
9b90955e JB |
2305 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, |
2306 | data->rx_from_unknown.wds); | |
f8b1f695 JM |
2307 | break; |
2308 | case EVENT_RX_MGMT: | |
9bae1be0 JM |
2309 | if (wpa_s->ap_iface == NULL) { |
2310 | #ifdef CONFIG_P2P | |
2311 | u16 fc, stype; | |
2312 | const struct ieee80211_mgmt *mgmt; | |
2313 | mgmt = (const struct ieee80211_mgmt *) | |
2314 | data->rx_mgmt.frame; | |
2315 | fc = le_to_host16(mgmt->frame_control); | |
2316 | stype = WLAN_FC_GET_STYPE(fc); | |
2317 | if (stype == WLAN_FC_STYPE_PROBE_REQ && | |
2318 | data->rx_mgmt.frame_len > 24) { | |
2319 | const u8 *src = mgmt->sa; | |
2320 | const u8 *ie = mgmt->u.probe_req.variable; | |
2321 | size_t ie_len = data->rx_mgmt.frame_len - | |
2322 | (mgmt->u.probe_req.variable - | |
2323 | data->rx_mgmt.frame); | |
04a85e44 JM |
2324 | wpas_p2p_probe_req_rx(wpa_s, src, mgmt->da, |
2325 | mgmt->bssid, ie, ie_len); | |
9bae1be0 JM |
2326 | break; |
2327 | } | |
2328 | #endif /* CONFIG_P2P */ | |
f049052b BG |
2329 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " |
2330 | "management frame in non-AP mode"); | |
f8b1f695 | 2331 | break; |
9bae1be0 | 2332 | } |
2a8b7416 | 2333 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
f8b1f695 JM |
2334 | break; |
2335 | #endif /* CONFIG_AP */ | |
036f7c4a | 2336 | case EVENT_RX_ACTION: |
f049052b BG |
2337 | wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR |
2338 | " Category=%u DataLen=%d freq=%d MHz", | |
2339 | MAC2STR(data->rx_action.sa), | |
2340 | data->rx_action.category, (int) data->rx_action.len, | |
2341 | data->rx_action.freq); | |
036f7c4a JM |
2342 | #ifdef CONFIG_IEEE80211R |
2343 | if (data->rx_action.category == WLAN_ACTION_FT) { | |
2344 | ft_rx_action(wpa_s, data->rx_action.data, | |
2345 | data->rx_action.len); | |
2346 | break; | |
2347 | } | |
2348 | #endif /* CONFIG_IEEE80211R */ | |
7d878ca7 JM |
2349 | #ifdef CONFIG_IEEE80211W |
2350 | #ifdef CONFIG_SME | |
2351 | if (data->rx_action.category == WLAN_ACTION_SA_QUERY) { | |
2352 | sme_sa_query_rx(wpa_s, data->rx_action.sa, | |
2353 | data->rx_action.data, | |
2354 | data->rx_action.len); | |
2355 | break; | |
2356 | } | |
2357 | #endif /* CONFIG_SME */ | |
2358 | #endif /* CONFIG_IEEE80211W */ | |
04ea7b79 JM |
2359 | #ifdef CONFIG_GAS |
2360 | if (data->rx_action.category == WLAN_ACTION_PUBLIC && | |
2361 | gas_query_rx(wpa_s->gas, data->rx_action.da, | |
2362 | data->rx_action.sa, data->rx_action.bssid, | |
2363 | data->rx_action.data, data->rx_action.len, | |
2364 | data->rx_action.freq) == 0) | |
2365 | break; | |
2366 | #endif /* CONFIG_GAS */ | |
71269b37 JM |
2367 | if (data->rx_action.category == WLAN_ACTION_WNM) { |
2368 | wnm_action_rx(wpa_s, &data->rx_action); | |
2369 | break; | |
2370 | } | |
35287637 AN |
2371 | #ifdef CONFIG_TDLS |
2372 | if (data->rx_action.category == WLAN_ACTION_PUBLIC && | |
2373 | data->rx_action.len >= 4 && | |
2374 | data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { | |
2375 | wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery " | |
2376 | "Response from " MACSTR, | |
2377 | MAC2STR(data->rx_action.sa)); | |
2378 | break; | |
2379 | } | |
2380 | #endif /* CONFIG_TDLS */ | |
9bae1be0 JM |
2381 | #ifdef CONFIG_P2P |
2382 | wpas_p2p_rx_action(wpa_s, data->rx_action.da, | |
2383 | data->rx_action.sa, | |
2384 | data->rx_action.bssid, | |
2385 | data->rx_action.category, | |
2386 | data->rx_action.data, | |
2387 | data->rx_action.len, data->rx_action.freq); | |
e67b55fb JM |
2388 | #endif /* CONFIG_P2P */ |
2389 | break; | |
2390 | case EVENT_RX_PROBE_REQ: | |
b211f3eb JM |
2391 | if (data->rx_probe_req.sa == NULL || |
2392 | data->rx_probe_req.ie == NULL) | |
2393 | break; | |
e67b55fb JM |
2394 | #ifdef CONFIG_AP |
2395 | if (wpa_s->ap_iface) { | |
2396 | hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], | |
2397 | data->rx_probe_req.sa, | |
04a85e44 JM |
2398 | data->rx_probe_req.da, |
2399 | data->rx_probe_req.bssid, | |
e67b55fb JM |
2400 | data->rx_probe_req.ie, |
2401 | data->rx_probe_req.ie_len); | |
2402 | break; | |
2403 | } | |
2404 | #endif /* CONFIG_AP */ | |
2405 | #ifdef CONFIG_P2P | |
2406 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, | |
04a85e44 JM |
2407 | data->rx_probe_req.da, |
2408 | data->rx_probe_req.bssid, | |
e67b55fb JM |
2409 | data->rx_probe_req.ie, |
2410 | data->rx_probe_req.ie_len); | |
9bae1be0 | 2411 | #endif /* CONFIG_P2P */ |
036f7c4a | 2412 | break; |
9bae1be0 | 2413 | case EVENT_REMAIN_ON_CHANNEL: |
24f6497c JM |
2414 | #ifdef CONFIG_OFFCHANNEL |
2415 | offchannel_remain_on_channel_cb( | |
2416 | wpa_s, data->remain_on_channel.freq, | |
2417 | data->remain_on_channel.duration); | |
2418 | #endif /* CONFIG_OFFCHANNEL */ | |
2419 | #ifdef CONFIG_P2P | |
9bae1be0 JM |
2420 | wpas_p2p_remain_on_channel_cb( |
2421 | wpa_s, data->remain_on_channel.freq, | |
2422 | data->remain_on_channel.duration); | |
24f6497c | 2423 | #endif /* CONFIG_P2P */ |
9bae1be0 JM |
2424 | break; |
2425 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: | |
24f6497c JM |
2426 | #ifdef CONFIG_OFFCHANNEL |
2427 | offchannel_cancel_remain_on_channel_cb( | |
2428 | wpa_s, data->remain_on_channel.freq); | |
2429 | #endif /* CONFIG_OFFCHANNEL */ | |
2430 | #ifdef CONFIG_P2P | |
9bae1be0 JM |
2431 | wpas_p2p_cancel_remain_on_channel_cb( |
2432 | wpa_s, data->remain_on_channel.freq); | |
24f6497c | 2433 | #endif /* CONFIG_P2P */ |
9bae1be0 | 2434 | break; |
24f6497c | 2435 | #ifdef CONFIG_P2P |
c5db8e51 KRK |
2436 | case EVENT_P2P_DEV_FOUND: { |
2437 | struct p2p_peer_info peer_info; | |
2438 | ||
2439 | os_memset(&peer_info, 0, sizeof(peer_info)); | |
2440 | if (data->p2p_dev_found.dev_addr) | |
2441 | os_memcpy(peer_info.p2p_device_addr, | |
2442 | data->p2p_dev_found.dev_addr, ETH_ALEN); | |
2443 | if (data->p2p_dev_found.pri_dev_type) | |
2444 | os_memcpy(peer_info.pri_dev_type, | |
2445 | data->p2p_dev_found.pri_dev_type, | |
2446 | sizeof(peer_info.pri_dev_type)); | |
2447 | if (data->p2p_dev_found.dev_name) | |
2448 | os_strlcpy(peer_info.device_name, | |
2449 | data->p2p_dev_found.dev_name, | |
2450 | sizeof(peer_info.device_name)); | |
2451 | peer_info.config_methods = data->p2p_dev_found.config_methods; | |
2452 | peer_info.dev_capab = data->p2p_dev_found.dev_capab; | |
2453 | peer_info.group_capab = data->p2p_dev_found.group_capab; | |
2454 | ||
8fd7dc1b JB |
2455 | /* |
2456 | * FIX: new_device=1 is not necessarily correct. We should | |
2457 | * maintain a P2P peer database in wpa_supplicant and update | |
2458 | * this information based on whether the peer is truly new. | |
2459 | */ | |
2460 | wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1); | |
3ac17eba | 2461 | break; |
c5db8e51 | 2462 | } |
3ac17eba JM |
2463 | case EVENT_P2P_GO_NEG_REQ_RX: |
2464 | wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src, | |
2465 | data->p2p_go_neg_req_rx.dev_passwd_id); | |
2466 | break; | |
2467 | case EVENT_P2P_GO_NEG_COMPLETED: | |
2468 | wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res); | |
2469 | break; | |
2470 | case EVENT_P2P_PROV_DISC_REQUEST: | |
2471 | wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer, | |
2472 | data->p2p_prov_disc_req.config_methods, | |
2473 | data->p2p_prov_disc_req.dev_addr, | |
2474 | data->p2p_prov_disc_req.pri_dev_type, | |
2475 | data->p2p_prov_disc_req.dev_name, | |
2476 | data->p2p_prov_disc_req.supp_config_methods, | |
2477 | data->p2p_prov_disc_req.dev_capab, | |
c3f42784 JM |
2478 | data->p2p_prov_disc_req.group_capab, |
2479 | NULL, 0); | |
3ac17eba JM |
2480 | break; |
2481 | case EVENT_P2P_PROV_DISC_RESPONSE: | |
2482 | wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer, | |
2483 | data->p2p_prov_disc_resp.config_methods); | |
2484 | break; | |
2485 | case EVENT_P2P_SD_REQUEST: | |
2486 | wpas_sd_request(wpa_s, data->p2p_sd_req.freq, | |
2487 | data->p2p_sd_req.sa, | |
2488 | data->p2p_sd_req.dialog_token, | |
2489 | data->p2p_sd_req.update_indic, | |
2490 | data->p2p_sd_req.tlvs, | |
2491 | data->p2p_sd_req.tlvs_len); | |
2492 | break; | |
2493 | case EVENT_P2P_SD_RESPONSE: | |
2494 | wpas_sd_response(wpa_s, data->p2p_sd_resp.sa, | |
2495 | data->p2p_sd_resp.update_indic, | |
2496 | data->p2p_sd_resp.tlvs, | |
2497 | data->p2p_sd_resp.tlvs_len); | |
2498 | break; | |
9bae1be0 | 2499 | #endif /* CONFIG_P2P */ |
a8e0505b JM |
2500 | case EVENT_EAPOL_RX: |
2501 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, | |
2502 | data->eapol_rx.data, | |
2503 | data->eapol_rx.data_len); | |
2504 | break; | |
e2f74005 JM |
2505 | case EVENT_SIGNAL_CHANGE: |
2506 | bgscan_notify_signal_change( | |
60a972a6 | 2507 | wpa_s, data->signal_change.above_threshold, |
174fa789 PS |
2508 | data->signal_change.current_signal, |
2509 | data->signal_change.current_noise, | |
2510 | data->signal_change.current_txrate); | |
e2f74005 | 2511 | break; |
8401a6b0 | 2512 | case EVENT_INTERFACE_ENABLED: |
f049052b | 2513 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); |
8401a6b0 | 2514 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
bfba8deb | 2515 | wpa_supplicant_update_mac_addr(wpa_s); |
199716ad | 2516 | #ifdef CONFIG_AP |
9919f7a2 JB |
2517 | if (!wpa_s->ap_iface) { |
2518 | wpa_supplicant_set_state(wpa_s, | |
2519 | WPA_DISCONNECTED); | |
2520 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2521 | } else | |
2522 | wpa_supplicant_set_state(wpa_s, | |
2523 | WPA_COMPLETED); | |
199716ad BG |
2524 | #else /* CONFIG_AP */ |
2525 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
2526 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2527 | #endif /* CONFIG_AP */ | |
8401a6b0 JM |
2528 | } |
2529 | break; | |
2530 | case EVENT_INTERFACE_DISABLED: | |
f049052b | 2531 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); |
8401a6b0 JM |
2532 | wpa_supplicant_mark_disassoc(wpa_s); |
2533 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); | |
2534 | break; | |
b5c9da8d | 2535 | case EVENT_CHANNEL_LIST_CHANGED: |
35c5d610 JM |
2536 | if (wpa_s->drv_priv == NULL) |
2537 | break; /* Ignore event during drv initialization */ | |
b5c9da8d JM |
2538 | #ifdef CONFIG_P2P |
2539 | wpas_p2p_update_channel_list(wpa_s); | |
c973f386 JM |
2540 | #endif /* CONFIG_P2P */ |
2541 | break; | |
2542 | case EVENT_INTERFACE_UNAVAILABLE: | |
2543 | #ifdef CONFIG_P2P | |
2544 | wpas_p2p_interface_unavailable(wpa_s); | |
7cfc4ac3 AGS |
2545 | #endif /* CONFIG_P2P */ |
2546 | break; | |
2547 | case EVENT_BEST_CHANNEL: | |
f049052b BG |
2548 | wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " |
2549 | "(%d %d %d)", | |
2550 | data->best_chan.freq_24, data->best_chan.freq_5, | |
2551 | data->best_chan.freq_overall); | |
7cfc4ac3 AGS |
2552 | wpa_s->best_24_freq = data->best_chan.freq_24; |
2553 | wpa_s->best_5_freq = data->best_chan.freq_5; | |
2554 | wpa_s->best_overall_freq = data->best_chan.freq_overall; | |
2555 | #ifdef CONFIG_P2P | |
2556 | wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, | |
2557 | data->best_chan.freq_5, | |
2558 | data->best_chan.freq_overall); | |
b5c9da8d JM |
2559 | #endif /* CONFIG_P2P */ |
2560 | break; | |
7d878ca7 JM |
2561 | case EVENT_UNPROT_DEAUTH: |
2562 | wpa_supplicant_event_unprot_deauth(wpa_s, | |
2563 | &data->unprot_deauth); | |
2564 | break; | |
2565 | case EVENT_UNPROT_DISASSOC: | |
2566 | wpa_supplicant_event_unprot_disassoc(wpa_s, | |
2567 | &data->unprot_disassoc); | |
2568 | break; | |
0d7e5a3a JB |
2569 | case EVENT_STATION_LOW_ACK: |
2570 | #ifdef CONFIG_AP | |
2571 | if (wpa_s->ap_iface && data) | |
2572 | hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], | |
2573 | data->low_ack.addr); | |
2574 | #endif /* CONFIG_AP */ | |
8f15f711 AN |
2575 | #ifdef CONFIG_TDLS |
2576 | if (data) | |
2577 | wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr); | |
2578 | #endif /* CONFIG_TDLS */ | |
0d7e5a3a | 2579 | break; |
ea244d21 XC |
2580 | case EVENT_IBSS_PEER_LOST: |
2581 | #ifdef CONFIG_IBSS_RSN | |
2582 | ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); | |
2583 | #endif /* CONFIG_IBSS_RSN */ | |
2584 | break; | |
b14a210c JB |
2585 | case EVENT_DRIVER_GTK_REKEY: |
2586 | if (os_memcmp(data->driver_gtk_rekey.bssid, | |
2587 | wpa_s->bssid, ETH_ALEN)) | |
2588 | break; | |
2589 | if (!wpa_s->wpa) | |
2590 | break; | |
2591 | wpa_sm_update_replay_ctr(wpa_s->wpa, | |
2592 | data->driver_gtk_rekey.replay_ctr); | |
2593 | break; | |
cbdf3507 LC |
2594 | case EVENT_SCHED_SCAN_STOPPED: |
2595 | wpa_s->sched_scanning = 0; | |
2596 | wpa_supplicant_notify_scanning(wpa_s, 0); | |
2597 | ||
9b6f44cb JM |
2598 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
2599 | break; | |
2600 | ||
cbdf3507 LC |
2601 | /* |
2602 | * If we timed out, start a new sched scan to continue | |
2603 | * searching for more SSIDs. | |
2604 | */ | |
2605 | if (wpa_s->sched_scan_timed_out) | |
2606 | wpa_supplicant_req_sched_scan(wpa_s); | |
2607 | break; | |
783fcb7d GG |
2608 | case EVENT_WPS_BUTTON_PUSHED: |
2609 | #ifdef CONFIG_WPS | |
2610 | wpas_wps_start_pbc(wpa_s, NULL, 0); | |
2611 | #endif /* CONFIG_WPS */ | |
2612 | break; | |
6fc6879b | 2613 | default: |
f049052b | 2614 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); |
6fc6879b JM |
2615 | break; |
2616 | } | |
2617 | } |