]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant - Driver event processing | |
8d923a4a | 3 | * Copyright (c) 2003-2010, 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" |
8bac466b | 31 | #include "notify.h" |
90973fb2 | 32 | #include "common/ieee802_11_defs.h" |
54f489be | 33 | #include "common/ieee802_11_common.h" |
6fc6879b JM |
34 | #include "blacklist.h" |
35 | #include "wpas_glue.h" | |
351f09a2 | 36 | #include "wps_supplicant.h" |
11ef8d35 | 37 | #include "ibss_rsn.h" |
c2a04078 | 38 | #include "sme.h" |
9bae1be0 | 39 | #include "p2p_supplicant.h" |
60b94c98 | 40 | #include "bgscan.h" |
f8b1f695 | 41 | #include "ap.h" |
6fa81a3b | 42 | #include "bss.h" |
245519e0 | 43 | #include "mlme.h" |
9ba9fa07 | 44 | #include "scan.h" |
6fc6879b JM |
45 | |
46 | ||
47 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) | |
48 | { | |
8bac466b | 49 | struct wpa_ssid *ssid, *old_ssid; |
6fc6879b JM |
50 | |
51 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) | |
52 | return 0; | |
53 | ||
54 | wpa_printf(MSG_DEBUG, "Select network based on association " | |
55 | "information"); | |
56 | ssid = wpa_supplicant_get_ssid(wpa_s); | |
57 | if (ssid == NULL) { | |
58 | wpa_printf(MSG_INFO, "No network configuration found for the " | |
59 | "current AP"); | |
60 | return -1; | |
61 | } | |
62 | ||
63 | if (ssid->disabled) { | |
64 | wpa_printf(MSG_DEBUG, "Selected network is disabled"); | |
65 | return -1; | |
66 | } | |
67 | ||
68 | wpa_printf(MSG_DEBUG, "Network configuration found for the current " | |
69 | "AP"); | |
70 | if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X | | |
71 | WPA_KEY_MGMT_WPA_NONE | | |
56586197 JM |
72 | WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X | |
73 | WPA_KEY_MGMT_PSK_SHA256 | | |
74 | WPA_KEY_MGMT_IEEE8021X_SHA256)) { | |
6fc6879b JM |
75 | u8 wpa_ie[80]; |
76 | size_t wpa_ie_len = sizeof(wpa_ie); | |
77 | wpa_supplicant_set_suites(wpa_s, NULL, ssid, | |
78 | wpa_ie, &wpa_ie_len); | |
79 | } else { | |
80 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
81 | } | |
82 | ||
83 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) | |
84 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
8bac466b | 85 | old_ssid = wpa_s->current_ssid; |
6fc6879b JM |
86 | wpa_s->current_ssid = ssid; |
87 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); | |
88 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
89 | if (old_ssid != wpa_s->current_ssid) |
90 | wpas_notify_network_changed(wpa_s); | |
6fc6879b JM |
91 | |
92 | return 0; | |
93 | } | |
94 | ||
95 | ||
96 | static void wpa_supplicant_stop_countermeasures(void *eloop_ctx, | |
97 | void *sock_ctx) | |
98 | { | |
99 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
100 | ||
101 | if (wpa_s->countermeasures) { | |
102 | wpa_s->countermeasures = 0; | |
103 | wpa_drv_set_countermeasures(wpa_s, 0); | |
104 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); | |
105 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
106 | } | |
107 | } | |
108 | ||
109 | ||
110 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) | |
111 | { | |
8bac466b JM |
112 | int bssid_changed; |
113 | ||
8401a6b0 JM |
114 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
115 | return; | |
116 | ||
6fc6879b | 117 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
8bac466b | 118 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
6fc6879b JM |
119 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
120 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
be8be671 | 121 | wpa_s->current_bss = NULL; |
8bac466b JM |
122 | if (bssid_changed) |
123 | wpas_notify_bssid_changed(wpa_s); | |
124 | ||
6fc6879b JM |
125 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
126 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
56586197 | 127 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) |
6fc6879b JM |
128 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
129 | wpa_s->ap_ies_from_associnfo = 0; | |
130 | } | |
131 | ||
132 | ||
133 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) | |
134 | { | |
135 | struct wpa_ie_data ie; | |
136 | int pmksa_set = -1; | |
137 | size_t i; | |
138 | ||
139 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || | |
140 | ie.pmkid == NULL) | |
141 | return; | |
142 | ||
143 | for (i = 0; i < ie.num_pmkid; i++) { | |
144 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, | |
145 | ie.pmkid + i * PMKID_LEN, | |
146 | NULL, NULL, 0); | |
147 | if (pmksa_set == 0) { | |
148 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1); | |
149 | break; | |
150 | } | |
151 | } | |
152 | ||
153 | wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA " | |
154 | "cache", pmksa_set == 0 ? "" : "not "); | |
155 | } | |
156 | ||
157 | ||
158 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, | |
159 | union wpa_event_data *data) | |
160 | { | |
161 | if (data == NULL) { | |
162 | wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event"); | |
163 | return; | |
164 | } | |
165 | wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR | |
166 | " index=%d preauth=%d", | |
167 | MAC2STR(data->pmkid_candidate.bssid), | |
168 | data->pmkid_candidate.index, | |
169 | data->pmkid_candidate.preauth); | |
170 | ||
171 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, | |
172 | data->pmkid_candidate.index, | |
173 | data->pmkid_candidate.preauth); | |
174 | } | |
175 | ||
176 | ||
177 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) | |
178 | { | |
179 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
180 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
181 | return 0; | |
182 | ||
183 | #ifdef IEEE8021X_EAPOL | |
184 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | |
185 | wpa_s->current_ssid && | |
186 | !(wpa_s->current_ssid->eapol_flags & | |
187 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
188 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { | |
189 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either | |
190 | * plaintext or static WEP keys). */ | |
191 | return 0; | |
192 | } | |
193 | #endif /* IEEE8021X_EAPOL */ | |
194 | ||
195 | return 1; | |
196 | } | |
197 | ||
198 | ||
199 | /** | |
200 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC | |
201 | * @wpa_s: pointer to wpa_supplicant data | |
202 | * @ssid: Configuration data for the network | |
203 | * Returns: 0 on success, -1 on failure | |
204 | * | |
205 | * This function is called when starting authentication with a network that is | |
206 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). | |
207 | */ | |
208 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, | |
209 | struct wpa_ssid *ssid) | |
210 | { | |
211 | #ifdef IEEE8021X_EAPOL | |
212 | int aka = 0, sim = 0, type; | |
213 | ||
214 | if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL) | |
215 | return 0; | |
216 | ||
217 | if (ssid->eap.eap_methods == NULL) { | |
218 | sim = 1; | |
219 | aka = 1; | |
220 | } else { | |
221 | struct eap_method_type *eap = ssid->eap.eap_methods; | |
222 | while (eap->vendor != EAP_VENDOR_IETF || | |
223 | eap->method != EAP_TYPE_NONE) { | |
224 | if (eap->vendor == EAP_VENDOR_IETF) { | |
225 | if (eap->method == EAP_TYPE_SIM) | |
226 | sim = 1; | |
227 | else if (eap->method == EAP_TYPE_AKA) | |
228 | aka = 1; | |
229 | } | |
230 | eap++; | |
231 | } | |
232 | } | |
233 | ||
234 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) | |
235 | sim = 0; | |
236 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL) | |
237 | aka = 0; | |
238 | ||
239 | if (!sim && !aka) { | |
240 | wpa_printf(MSG_DEBUG, "Selected network is configured to use " | |
241 | "SIM, but neither EAP-SIM nor EAP-AKA are enabled"); | |
242 | return 0; | |
243 | } | |
244 | ||
245 | wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM " | |
246 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); | |
247 | if (sim && aka) | |
248 | type = SCARD_TRY_BOTH; | |
249 | else if (aka) | |
250 | type = SCARD_USIM_ONLY; | |
251 | else | |
252 | type = SCARD_GSM_SIM_ONLY; | |
253 | ||
254 | wpa_s->scard = scard_init(type); | |
255 | if (wpa_s->scard == NULL) { | |
256 | wpa_printf(MSG_WARNING, "Failed to initialize SIM " | |
257 | "(pcsc-lite)"); | |
258 | return -1; | |
259 | } | |
260 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
261 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
262 | #endif /* IEEE8021X_EAPOL */ | |
263 | ||
264 | return 0; | |
265 | } | |
266 | ||
267 | ||
268 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
269 | static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss, | |
270 | struct wpa_ssid *ssid) | |
271 | { | |
272 | int i, privacy = 0; | |
273 | ||
274 | if (ssid->mixed_cell) | |
275 | return 1; | |
276 | ||
0632542b AT |
277 | #ifdef CONFIG_WPS |
278 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) | |
279 | return 1; | |
280 | #endif /* CONFIG_WPS */ | |
281 | ||
6fc6879b JM |
282 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
283 | if (ssid->wep_key_len[i]) { | |
284 | privacy = 1; | |
285 | break; | |
286 | } | |
287 | } | |
288 | #ifdef IEEE8021X_EAPOL | |
289 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
290 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
291 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) | |
292 | privacy = 1; | |
293 | #endif /* IEEE8021X_EAPOL */ | |
294 | ||
295 | if (bss->caps & IEEE80211_CAP_PRIVACY) | |
296 | return privacy; | |
297 | return !privacy; | |
298 | } | |
299 | ||
300 | ||
a6099152 JM |
301 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
302 | struct wpa_ssid *ssid, | |
6fc6879b JM |
303 | struct wpa_scan_res *bss) |
304 | { | |
305 | struct wpa_ie_data ie; | |
306 | int proto_match = 0; | |
307 | const u8 *rsn_ie, *wpa_ie; | |
351f09a2 | 308 | int ret; |
6fc6879b | 309 | |
a6099152 | 310 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
351f09a2 JM |
311 | if (ret >= 0) |
312 | return ret; | |
ad08c363 | 313 | |
6fc6879b JM |
314 | rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); |
315 | while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { | |
316 | proto_match++; | |
317 | ||
318 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { | |
319 | wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed"); | |
320 | break; | |
321 | } | |
322 | if (!(ie.proto & ssid->proto)) { | |
323 | wpa_printf(MSG_DEBUG, " skip RSN IE - proto " | |
324 | "mismatch"); | |
325 | break; | |
326 | } | |
327 | ||
328 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
329 | wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher " | |
330 | "mismatch"); | |
331 | break; | |
332 | } | |
333 | ||
334 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
335 | wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher " | |
336 | "mismatch"); | |
337 | break; | |
338 | } | |
339 | ||
340 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
341 | wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt " | |
342 | "mismatch"); | |
343 | break; | |
344 | } | |
345 | ||
346 | #ifdef CONFIG_IEEE80211W | |
0b60b0aa | 347 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
70f8cc8e | 348 | ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) { |
6fc6879b JM |
349 | wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame " |
350 | "protection"); | |
351 | break; | |
352 | } | |
353 | #endif /* CONFIG_IEEE80211W */ | |
354 | ||
355 | wpa_printf(MSG_DEBUG, " selected based on RSN IE"); | |
356 | return 1; | |
357 | } | |
358 | ||
359 | wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
360 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { | |
361 | proto_match++; | |
362 | ||
363 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { | |
364 | wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed"); | |
365 | break; | |
366 | } | |
367 | if (!(ie.proto & ssid->proto)) { | |
368 | wpa_printf(MSG_DEBUG, " skip WPA IE - proto " | |
369 | "mismatch"); | |
370 | break; | |
371 | } | |
372 | ||
373 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
374 | wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher " | |
375 | "mismatch"); | |
376 | break; | |
377 | } | |
378 | ||
379 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
380 | wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher " | |
381 | "mismatch"); | |
382 | break; | |
383 | } | |
384 | ||
385 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
386 | wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt " | |
387 | "mismatch"); | |
388 | break; | |
389 | } | |
390 | ||
391 | wpa_printf(MSG_DEBUG, " selected based on WPA IE"); | |
392 | return 1; | |
393 | } | |
394 | ||
395 | if (proto_match == 0) | |
396 | wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match"); | |
397 | ||
398 | return 0; | |
399 | } | |
400 | ||
401 | ||
b766a9a2 JM |
402 | static int freq_allowed(int *freqs, int freq) |
403 | { | |
404 | int i; | |
405 | ||
406 | if (freqs == NULL) | |
407 | return 1; | |
408 | ||
409 | for (i = 0; freqs[i]; i++) | |
410 | if (freqs[i] == freq) | |
411 | return 1; | |
412 | return 0; | |
413 | } | |
414 | ||
415 | ||
d8d940b7 JM |
416 | static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
417 | int i, struct wpa_scan_res *bss, | |
418 | struct wpa_ssid *group) | |
6fc6879b | 419 | { |
d8d940b7 JM |
420 | const u8 *ssid_; |
421 | u8 wpa_ie_len, rsn_ie_len, ssid_len; | |
422 | int wpa; | |
6fc6879b JM |
423 | struct wpa_blacklist *e; |
424 | const u8 *ie; | |
d8d940b7 | 425 | struct wpa_ssid *ssid; |
6fc6879b | 426 | |
d8d940b7 JM |
427 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); |
428 | ssid_ = ie ? ie + 2 : (u8 *) ""; | |
429 | ssid_len = ie ? ie[1] : 0; | |
6fc6879b | 430 | |
d8d940b7 JM |
431 | ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
432 | wpa_ie_len = ie ? ie[1] : 0; | |
6fc6879b | 433 | |
d8d940b7 JM |
434 | ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); |
435 | rsn_ie_len = ie ? ie[1] : 0; | |
6fc6879b | 436 | |
d8d940b7 JM |
437 | wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' " |
438 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s", | |
439 | i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len), | |
440 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, | |
441 | wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? | |
442 | " wps" : ""); | |
9cf32261 | 443 | |
d8d940b7 JM |
444 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
445 | if (e && e->count > 1) { | |
446 | wpa_printf(MSG_DEBUG, " skip - blacklisted"); | |
447 | return 0; | |
448 | } | |
6fc6879b | 449 | |
d8d940b7 JM |
450 | if (ssid_len == 0) { |
451 | wpa_printf(MSG_DEBUG, " skip - SSID not known"); | |
452 | return 0; | |
453 | } | |
e81634cd | 454 | |
d8d940b7 | 455 | wpa = wpa_ie_len > 0 || rsn_ie_len > 0; |
6fc6879b | 456 | |
d8d940b7 JM |
457 | for (ssid = group; ssid; ssid = ssid->pnext) { |
458 | int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); | |
ad08c363 | 459 | |
d8d940b7 JM |
460 | if (ssid->disabled) { |
461 | wpa_printf(MSG_DEBUG, " skip - disabled"); | |
0c703df3 | 462 | continue; |
d8d940b7 | 463 | } |
9cf32261 | 464 | |
ad08c363 | 465 | #ifdef CONFIG_WPS |
d8d940b7 JM |
466 | if (wpa && ssid->ssid_len == 0 && |
467 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) | |
468 | check_ssid = 0; | |
469 | ||
470 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { | |
471 | /* Only allow wildcard SSID match if an AP | |
472 | * advertises active WPS operation that matches | |
473 | * with our mode. */ | |
474 | check_ssid = 1; | |
ad08c363 | 475 | if (ssid->ssid_len == 0 && |
a6099152 | 476 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
ad08c363 | 477 | check_ssid = 0; |
d8d940b7 | 478 | } |
ad08c363 JM |
479 | #endif /* CONFIG_WPS */ |
480 | ||
d8d940b7 JM |
481 | if (check_ssid && |
482 | (ssid_len != ssid->ssid_len || | |
483 | os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) { | |
484 | wpa_printf(MSG_DEBUG, " skip - SSID mismatch"); | |
0c703df3 | 485 | continue; |
6fc6879b | 486 | } |
6fc6879b | 487 | |
d8d940b7 JM |
488 | if (ssid->bssid_set && |
489 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { | |
490 | wpa_printf(MSG_DEBUG, " skip - BSSID mismatch"); | |
0c703df3 | 491 | continue; |
d8d940b7 | 492 | } |
6fc6879b | 493 | |
d8d940b7 | 494 | if (wpa && !wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) |
0c703df3 | 495 | continue; |
9cf32261 | 496 | |
d8d940b7 JM |
497 | if (!wpa && |
498 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
499 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && | |
500 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { | |
501 | wpa_printf(MSG_DEBUG, " skip - non-WPA network not " | |
502 | "allowed"); | |
0c703df3 | 503 | continue; |
6fc6879b | 504 | } |
9cf32261 | 505 | |
d8d940b7 JM |
506 | if (!wpa && !wpa_supplicant_match_privacy(bss, ssid)) { |
507 | wpa_printf(MSG_DEBUG, " skip - privacy mismatch"); | |
0c703df3 | 508 | continue; |
e81634cd JM |
509 | } |
510 | ||
d8d940b7 JM |
511 | if (!wpa && (bss->caps & IEEE80211_CAP_IBSS)) { |
512 | wpa_printf(MSG_DEBUG, " skip - IBSS (adhoc) " | |
513 | "network"); | |
0c703df3 | 514 | continue; |
d8d940b7 | 515 | } |
b766a9a2 | 516 | |
d8d940b7 JM |
517 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
518 | wpa_printf(MSG_DEBUG, " skip - frequency not " | |
519 | "allowed"); | |
0c703df3 | 520 | continue; |
6fc6879b | 521 | } |
d8d940b7 | 522 | |
73e49269 JM |
523 | #ifdef CONFIG_P2P |
524 | /* | |
525 | * TODO: skip the AP if its P2P IE has Group Formation | |
526 | * bit set in the P2P Group Capability Bitmap and we | |
527 | * are not in Group Formation with that device. | |
528 | */ | |
529 | #endif /* CONFIG_P2P */ | |
530 | ||
d8d940b7 JM |
531 | /* Matching configuration found */ |
532 | return ssid; | |
6fc6879b JM |
533 | } |
534 | ||
d8d940b7 JM |
535 | /* No matching configuration found */ |
536 | return 0; | |
9cf32261 JM |
537 | } |
538 | ||
539 | ||
6fa81a3b | 540 | static struct wpa_bss * |
a1fd2ce5 JM |
541 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
542 | struct wpa_scan_results *scan_res, | |
543 | struct wpa_ssid *group, | |
9cf32261 JM |
544 | struct wpa_ssid **selected_ssid) |
545 | { | |
d8d940b7 | 546 | size_t i; |
9cf32261 JM |
547 | |
548 | wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d", | |
549 | group->priority); | |
550 | ||
d8d940b7 JM |
551 | for (i = 0; i < scan_res->num; i++) { |
552 | struct wpa_scan_res *bss = scan_res->res[i]; | |
553 | const u8 *ie, *ssid; | |
554 | u8 ssid_len; | |
555 | ||
556 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group); | |
557 | if (!*selected_ssid) | |
558 | continue; | |
559 | ||
560 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); | |
561 | ssid = ie ? ie + 2 : (u8 *) ""; | |
562 | ssid_len = ie ? ie[1] : 0; | |
9cf32261 | 563 | |
d8d940b7 JM |
564 | wpa_printf(MSG_DEBUG, " selected BSS " MACSTR " ssid='%s'", |
565 | MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len)); | |
566 | return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len); | |
567 | } | |
568 | ||
569 | return NULL; | |
6fc6879b JM |
570 | } |
571 | ||
572 | ||
6fa81a3b | 573 | static struct wpa_bss * |
09b9df4e | 574 | wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
a1fd2ce5 | 575 | struct wpa_scan_results *scan_res, |
09b9df4e | 576 | struct wpa_ssid **selected_ssid) |
6fc6879b | 577 | { |
6fa81a3b | 578 | struct wpa_bss *selected = NULL; |
09b9df4e JM |
579 | int prio; |
580 | ||
581 | while (selected == NULL) { | |
582 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
583 | selected = wpa_supplicant_select_bss( | |
a1fd2ce5 | 584 | wpa_s, scan_res, wpa_s->conf->pssid[prio], |
09b9df4e JM |
585 | selected_ssid); |
586 | if (selected) | |
587 | break; | |
588 | } | |
589 | ||
590 | if (selected == NULL && wpa_s->blacklist) { | |
591 | wpa_printf(MSG_DEBUG, "No APs found - clear blacklist " | |
592 | "and try again"); | |
593 | wpa_blacklist_clear(wpa_s); | |
594 | wpa_s->blacklist_cleared++; | |
595 | } else if (selected == NULL) | |
596 | break; | |
597 | } | |
598 | ||
599 | return selected; | |
600 | } | |
601 | ||
602 | ||
603 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, | |
977b1174 | 604 | int timeout_sec, int timeout_usec) |
09b9df4e | 605 | { |
24f76940 | 606 | if (!wpa_supplicant_enabled_networks(wpa_s->conf)) { |
4f34d51a SL |
607 | /* |
608 | * No networks are enabled; short-circuit request so | |
609 | * we don't wait timeout seconds before transitioning | |
610 | * to INACTIVE state. | |
611 | */ | |
612 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
613 | return; | |
09b9df4e | 614 | } |
977b1174 | 615 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
09b9df4e JM |
616 | } |
617 | ||
618 | ||
86d4f806 JM |
619 | void wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
620 | struct wpa_bss *selected, | |
621 | struct wpa_ssid *ssid) | |
09b9df4e JM |
622 | { |
623 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { | |
624 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP | |
625 | "PBC session overlap"); | |
b73bf0a7 JM |
626 | #ifdef CONFIG_P2P |
627 | if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1) | |
628 | return; | |
629 | #endif /* CONFIG_P2P */ | |
977b1174 | 630 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
09b9df4e JM |
631 | return; |
632 | } | |
633 | ||
634 | /* | |
635 | * Do not trigger new association unless the BSSID has changed or if | |
636 | * reassociation is requested. If we are in process of associating with | |
637 | * the selected BSSID, do not trigger new attempt. | |
638 | */ | |
639 | if (wpa_s->reassociate || | |
640 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && | |
641 | (wpa_s->wpa_state != WPA_ASSOCIATING || | |
642 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != | |
643 | 0))) { | |
644 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { | |
977b1174 | 645 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
09b9df4e JM |
646 | return; |
647 | } | |
648 | wpa_supplicant_associate(wpa_s, selected, ssid); | |
649 | } else { | |
650 | wpa_printf(MSG_DEBUG, "Already associated with the selected " | |
651 | "AP"); | |
652 | } | |
09b9df4e JM |
653 | } |
654 | ||
655 | ||
b55aaa5f JM |
656 | static struct wpa_ssid * |
657 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) | |
658 | { | |
659 | int prio; | |
660 | struct wpa_ssid *ssid; | |
661 | ||
662 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
663 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) | |
664 | { | |
665 | if (ssid->disabled) | |
666 | continue; | |
667 | if (ssid->mode == IEEE80211_MODE_IBSS || | |
668 | ssid->mode == IEEE80211_MODE_AP) | |
669 | return ssid; | |
670 | } | |
671 | } | |
672 | return NULL; | |
673 | } | |
674 | ||
675 | ||
a1fd2ce5 JM |
676 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
677 | * on BSS added and BSS changed events */ | |
6ae93185 | 678 | static void wpa_supplicant_rsn_preauth_scan_results( |
a1fd2ce5 | 679 | struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res) |
6ae93185 JM |
680 | { |
681 | int i; | |
682 | ||
683 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) | |
684 | return; | |
685 | ||
a1fd2ce5 | 686 | for (i = scan_res->num - 1; i >= 0; i--) { |
6ae93185 JM |
687 | const u8 *ssid, *rsn; |
688 | struct wpa_scan_res *r; | |
689 | ||
a1fd2ce5 | 690 | r = scan_res->res[i]; |
6ae93185 JM |
691 | |
692 | ssid = wpa_scan_get_ie(r, WLAN_EID_SSID); | |
693 | if (ssid == NULL) | |
694 | continue; | |
695 | ||
696 | rsn = wpa_scan_get_ie(r, WLAN_EID_RSN); | |
697 | if (rsn == NULL) | |
698 | continue; | |
699 | ||
700 | rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn); | |
701 | } | |
702 | ||
703 | } | |
704 | ||
705 | ||
48563d86 JM |
706 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
707 | struct wpa_bss *selected, | |
708 | struct wpa_ssid *ssid, | |
709 | struct wpa_scan_results *scan_res) | |
710 | { | |
711 | size_t i; | |
712 | struct wpa_scan_res *current_bss = NULL; | |
713 | int min_diff; | |
714 | ||
715 | if (wpa_s->reassociate) | |
716 | return 1; /* explicit request to reassociate */ | |
717 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
718 | return 1; /* we are not associated; continue */ | |
719 | if (wpa_s->current_ssid == NULL) | |
720 | return 1; /* unknown current SSID */ | |
721 | if (wpa_s->current_ssid != ssid) | |
722 | return 1; /* different network block */ | |
723 | ||
724 | for (i = 0; i < scan_res->num; i++) { | |
725 | struct wpa_scan_res *res = scan_res->res[i]; | |
726 | const u8 *ie; | |
727 | if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0) | |
728 | continue; | |
729 | ||
730 | ie = wpa_scan_get_ie(res, WLAN_EID_SSID); | |
731 | if (ie == NULL) | |
732 | continue; | |
733 | if (ie[1] != wpa_s->current_ssid->ssid_len || | |
734 | os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0) | |
735 | continue; | |
736 | current_bss = res; | |
737 | break; | |
738 | } | |
739 | ||
740 | if (!current_bss) | |
741 | return 1; /* current BSS not seen in scan results */ | |
742 | ||
743 | wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation"); | |
744 | wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d", | |
745 | MAC2STR(current_bss->bssid), current_bss->level); | |
746 | wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d", | |
747 | MAC2STR(selected->bssid), selected->level); | |
748 | ||
ac26ebd8 JM |
749 | if (wpa_s->current_ssid->bssid_set && |
750 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == | |
751 | 0) { | |
752 | wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has " | |
753 | "preferred BSSID"); | |
754 | return 1; | |
755 | } | |
756 | ||
48563d86 JM |
757 | min_diff = 2; |
758 | if (current_bss->level < 0) { | |
759 | if (current_bss->level < -85) | |
760 | min_diff = 1; | |
761 | else if (current_bss->level < -80) | |
762 | min_diff = 2; | |
763 | else if (current_bss->level < -75) | |
764 | min_diff = 3; | |
765 | else if (current_bss->level < -70) | |
766 | min_diff = 4; | |
767 | else | |
768 | min_diff = 5; | |
769 | } | |
770 | if (abs(current_bss->level - selected->level) < min_diff) { | |
771 | wpa_printf(MSG_DEBUG, "Skip roam - too small difference in " | |
772 | "signal level"); | |
773 | return 0; | |
774 | } | |
775 | ||
776 | return 1; | |
777 | } | |
778 | ||
779 | ||
8d923a4a JM |
780 | static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
781 | union wpa_event_data *data) | |
09b9df4e | 782 | { |
6fa81a3b | 783 | struct wpa_bss *selected; |
6fc6879b | 784 | struct wpa_ssid *ssid = NULL; |
a1fd2ce5 | 785 | struct wpa_scan_results *scan_res; |
5bc0cdb7 JM |
786 | int ap = 0; |
787 | ||
788 | #ifdef CONFIG_AP | |
789 | if (wpa_s->ap_iface) | |
790 | ap = 1; | |
791 | #endif /* CONFIG_AP */ | |
6fc6879b | 792 | |
cb8564b1 DW |
793 | wpa_supplicant_notify_scanning(wpa_s, 0); |
794 | ||
a1fd2ce5 JM |
795 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
796 | data ? &data->scan_info : | |
797 | NULL, 1); | |
798 | if (scan_res == NULL) { | |
5bc0cdb7 | 799 | if (wpa_s->conf->ap_scan == 2 || ap) |
6fc6879b JM |
800 | return; |
801 | wpa_printf(MSG_DEBUG, "Failed to get scan results - try " | |
802 | "scanning again"); | |
977b1174 | 803 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
09b9df4e | 804 | return; |
6fc6879b JM |
805 | } |
806 | ||
64e58f51 JM |
807 | if (wpa_s->scan_res_handler) { |
808 | wpa_s->scan_res_handler(wpa_s, scan_res); | |
809 | wpa_s->scan_res_handler = NULL; | |
810 | wpa_scan_results_free(scan_res); | |
811 | return; | |
812 | } | |
813 | ||
5bc0cdb7 JM |
814 | if (ap) { |
815 | wpa_printf(MSG_DEBUG, "Ignore scan results in AP mode"); | |
816 | wpa_scan_results_free(scan_res); | |
817 | return; | |
818 | } | |
819 | ||
24f76940 JM |
820 | wpa_printf(MSG_DEBUG, "New scan results available"); |
821 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); | |
822 | wpas_notify_scan_results(wpa_s); | |
6fc6879b | 823 | |
8bac466b JM |
824 | wpas_notify_scan_done(wpa_s, 1); |
825 | ||
a1fd2ce5 JM |
826 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) { |
827 | wpa_scan_results_free(scan_res); | |
6fc6879b | 828 | return; |
a1fd2ce5 | 829 | } |
6fc6879b | 830 | |
3180d7a2 SO |
831 | if (wpa_s->disconnected) { |
832 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
a1fd2ce5 | 833 | wpa_scan_results_free(scan_res); |
3180d7a2 SO |
834 | return; |
835 | } | |
836 | ||
c2594c36 | 837 | if (bgscan_notify_scan(wpa_s, scan_res) == 1) { |
a1fd2ce5 | 838 | wpa_scan_results_free(scan_res); |
60b94c98 | 839 | return; |
a1fd2ce5 JM |
840 | } |
841 | ||
842 | wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res); | |
60b94c98 | 843 | |
a1fd2ce5 | 844 | selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid); |
6ae93185 | 845 | |
6fc6879b | 846 | if (selected) { |
48563d86 JM |
847 | int skip; |
848 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid, | |
849 | scan_res); | |
850 | wpa_scan_results_free(scan_res); | |
851 | if (skip) | |
852 | return; | |
09b9df4e | 853 | wpa_supplicant_connect(wpa_s, selected, ssid); |
6fc6879b | 854 | } else { |
48563d86 | 855 | wpa_scan_results_free(scan_res); |
09b9df4e | 856 | wpa_printf(MSG_DEBUG, "No suitable network found"); |
b55aaa5f JM |
857 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
858 | if (ssid) { | |
859 | wpa_printf(MSG_DEBUG, "Setup a new network"); | |
860 | wpa_supplicant_associate(wpa_s, NULL, ssid); | |
977b1174 JM |
861 | } else { |
862 | int timeout_sec = 5; | |
863 | int timeout_usec = 0; | |
0817de90 JM |
864 | #ifdef CONFIG_P2P |
865 | if (wpa_s->p2p_in_provisioning) { | |
866 | /* | |
867 | * Use shorter wait during P2P Provisioning | |
868 | * state to speed up group formation. | |
869 | */ | |
870 | timeout_sec = 0; | |
871 | timeout_usec = 250000; | |
872 | } | |
873 | #endif /* CONFIG_P2P */ | |
977b1174 JM |
874 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
875 | timeout_usec); | |
876 | } | |
6fc6879b | 877 | } |
6fc6879b JM |
878 | } |
879 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
880 | ||
881 | ||
579ce771 JM |
882 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
883 | union wpa_event_data *data) | |
6fc6879b JM |
884 | { |
885 | int l, len, found = 0, wpa_found, rsn_found; | |
c2a04078 | 886 | const u8 *p; |
6fc6879b JM |
887 | |
888 | wpa_printf(MSG_DEBUG, "Association info event"); | |
889 | if (data->assoc_info.req_ies) | |
890 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, | |
891 | data->assoc_info.req_ies_len); | |
892 | if (data->assoc_info.resp_ies) | |
893 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, | |
894 | data->assoc_info.resp_ies_len); | |
895 | if (data->assoc_info.beacon_ies) | |
896 | wpa_hexdump(MSG_DEBUG, "beacon_ies", | |
897 | data->assoc_info.beacon_ies, | |
898 | data->assoc_info.beacon_ies_len); | |
4832ecd7 JM |
899 | if (data->assoc_info.freq) |
900 | wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq); | |
6fc6879b JM |
901 | |
902 | p = data->assoc_info.req_ies; | |
903 | l = data->assoc_info.req_ies_len; | |
904 | ||
905 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ | |
906 | while (p && l >= 2) { | |
907 | len = p[1] + 2; | |
908 | if (len > l) { | |
909 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
910 | p, l); | |
911 | break; | |
912 | } | |
913 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
914 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || | |
915 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { | |
916 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) | |
917 | break; | |
918 | found = 1; | |
919 | wpa_find_assoc_pmkid(wpa_s); | |
920 | break; | |
921 | } | |
922 | l -= len; | |
923 | p += len; | |
924 | } | |
925 | if (!found && data->assoc_info.req_ies) | |
926 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
927 | ||
c2a04078 | 928 | #ifdef CONFIG_IEEE80211R |
62c72d72 JM |
929 | #ifdef CONFIG_SME |
930 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { | |
931 | u8 bssid[ETH_ALEN]; | |
932 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || | |
933 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
934 | data->assoc_info.resp_ies, | |
935 | data->assoc_info.resp_ies_len, | |
936 | bssid) < 0) { | |
937 | wpa_printf(MSG_DEBUG, "FT: Validation of " | |
938 | "Reassociation Response failed"); | |
579ce771 JM |
939 | wpa_supplicant_deauthenticate( |
940 | wpa_s, WLAN_REASON_INVALID_IE); | |
941 | return -1; | |
62c72d72 JM |
942 | } |
943 | } | |
62c72d72 | 944 | |
c2a04078 JM |
945 | p = data->assoc_info.resp_ies; |
946 | l = data->assoc_info.resp_ies_len; | |
947 | ||
54f489be JM |
948 | #ifdef CONFIG_WPS_STRICT |
949 | if (wpa_s->current_ssid && | |
950 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { | |
951 | struct wpabuf *wps; | |
952 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); | |
953 | if (wps == NULL) { | |
954 | wpa_printf(MSG_INFO, "WPS-STRICT: AP did not include " | |
955 | "WPS IE in (Re)Association Response"); | |
956 | return -1; | |
957 | } | |
958 | ||
959 | if (wps_validate_assoc_resp(wps) < 0) { | |
960 | wpabuf_free(wps); | |
961 | wpa_supplicant_deauthenticate( | |
962 | wpa_s, WLAN_REASON_INVALID_IE); | |
963 | return -1; | |
964 | } | |
965 | wpabuf_free(wps); | |
966 | } | |
967 | #endif /* CONFIG_WPS_STRICT */ | |
968 | ||
e7846b68 | 969 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
c2a04078 JM |
970 | while (p && l >= 2) { |
971 | len = p[1] + 2; | |
972 | if (len > l) { | |
973 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
974 | p, l); | |
975 | break; | |
976 | } | |
e7846b68 JM |
977 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
978 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
979 | wpa_s->sme.ft_used = 1; | |
980 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, | |
981 | MOBILITY_DOMAIN_ID_LEN); | |
982 | break; | |
983 | } | |
c2a04078 JM |
984 | l -= len; |
985 | p += len; | |
986 | } | |
e7846b68 | 987 | #endif /* CONFIG_SME */ |
c2a04078 | 988 | |
e7846b68 JM |
989 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
990 | data->assoc_info.resp_ies_len); | |
c2a04078 JM |
991 | #endif /* CONFIG_IEEE80211R */ |
992 | ||
6fc6879b JM |
993 | /* WPA/RSN IE from Beacon/ProbeResp */ |
994 | p = data->assoc_info.beacon_ies; | |
995 | l = data->assoc_info.beacon_ies_len; | |
996 | ||
997 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. | |
998 | */ | |
999 | wpa_found = rsn_found = 0; | |
1000 | while (p && l >= 2) { | |
1001 | len = p[1] + 2; | |
1002 | if (len > l) { | |
1003 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", | |
1004 | p, l); | |
1005 | break; | |
1006 | } | |
1007 | if (!wpa_found && | |
1008 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1009 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { | |
1010 | wpa_found = 1; | |
1011 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); | |
1012 | } | |
1013 | ||
1014 | if (!rsn_found && | |
1015 | p[0] == WLAN_EID_RSN && p[1] >= 2) { | |
1016 | rsn_found = 1; | |
1017 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); | |
1018 | } | |
1019 | ||
1020 | l -= len; | |
1021 | p += len; | |
1022 | } | |
1023 | ||
1024 | if (!wpa_found && data->assoc_info.beacon_ies) | |
1025 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
1026 | if (!rsn_found && data->assoc_info.beacon_ies) | |
1027 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
1028 | if (wpa_found || rsn_found) | |
1029 | wpa_s->ap_ies_from_associnfo = 1; | |
4832ecd7 JM |
1030 | |
1031 | wpa_s->assoc_freq = data->assoc_info.freq; | |
579ce771 JM |
1032 | |
1033 | return 0; | |
6fc6879b JM |
1034 | } |
1035 | ||
1036 | ||
1037 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, | |
1038 | union wpa_event_data *data) | |
1039 | { | |
1040 | u8 bssid[ETH_ALEN]; | |
1d041bec | 1041 | int ft_completed; |
8bac466b | 1042 | int bssid_changed; |
0194fedb | 1043 | struct wpa_driver_capa capa; |
6fc6879b | 1044 | |
1d041bec JM |
1045 | #ifdef CONFIG_AP |
1046 | if (wpa_s->ap_iface) { | |
1047 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], | |
1048 | data->assoc_info.addr, | |
1049 | data->assoc_info.req_ies, | |
1050 | data->assoc_info.req_ies_len); | |
1051 | return; | |
1052 | } | |
1053 | #endif /* CONFIG_AP */ | |
1054 | ||
1055 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); | |
579ce771 JM |
1056 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
1057 | return; | |
6fc6879b JM |
1058 | |
1059 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); | |
c2a04078 | 1060 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) |
6fc6879b | 1061 | os_memcpy(bssid, wpa_s->bssid, ETH_ALEN); |
c2a04078 | 1062 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) || |
6fc6879b JM |
1063 | (wpa_drv_get_bssid(wpa_s, bssid) >= 0 && |
1064 | os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) { | |
1065 | wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" | |
1066 | MACSTR, MAC2STR(bssid)); | |
8bac466b | 1067 | bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN); |
6fc6879b JM |
1068 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
1069 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
8bac466b JM |
1070 | if (bssid_changed) |
1071 | wpas_notify_bssid_changed(wpa_s); | |
1072 | ||
6fc6879b JM |
1073 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
1074 | wpa_clear_keys(wpa_s, bssid); | |
1075 | } | |
1076 | if (wpa_supplicant_select_config(wpa_s) < 0) { | |
1077 | wpa_supplicant_disassociate( | |
1078 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1079 | return; | |
1080 | } | |
8f770587 JM |
1081 | if (wpa_s->current_ssid) { |
1082 | struct wpa_bss *bss = NULL; | |
1083 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1084 | if (ssid->ssid_len > 0) | |
1085 | bss = wpa_bss_get(wpa_s, bssid, | |
1086 | ssid->ssid, ssid->ssid_len); | |
1087 | if (!bss) | |
1088 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
1089 | if (bss) | |
1090 | wpa_s->current_bss = bss; | |
1091 | } | |
6fc6879b JM |
1092 | } |
1093 | ||
62fa124c JM |
1094 | #ifdef CONFIG_SME |
1095 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); | |
1096 | wpa_s->sme.prev_bssid_set = 1; | |
1097 | #endif /* CONFIG_SME */ | |
1098 | ||
6fc6879b JM |
1099 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
1100 | if (wpa_s->current_ssid) { | |
1101 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be | |
1102 | * initialized before association, but for other modes, | |
1103 | * initialize PC/SC here, if the current configuration needs | |
1104 | * smartcard or SIM/USIM. */ | |
1105 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); | |
1106 | } | |
1107 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); | |
3f967fe0 JM |
1108 | if (wpa_s->l2) |
1109 | l2_packet_notify_auth_start(wpa_s->l2); | |
6fc6879b JM |
1110 | |
1111 | /* | |
1112 | * Set portEnabled first to FALSE in order to get EAP state machine out | |
1113 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE | |
1114 | * state machine may transit to AUTHENTICATING state based on obsolete | |
1115 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to | |
1116 | * AUTHENTICATED without ever giving chance to EAP state machine to | |
1117 | * reset the state. | |
1118 | */ | |
1119 | if (!ft_completed) { | |
1120 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
1121 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
1122 | } | |
56586197 | 1123 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) |
6fc6879b JM |
1124 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
1125 | /* 802.1X::portControl = Auto */ | |
1126 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); | |
1127 | wpa_s->eapol_received = 0; | |
1128 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
9c972abb JM |
1129 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
1130 | (wpa_s->current_ssid && | |
1131 | wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { | |
6fc6879b JM |
1132 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
1133 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1134 | } else if (!ft_completed) { | |
1135 | /* Timeout for receiving the first EAPOL packet */ | |
1136 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); | |
1137 | } | |
1138 | wpa_supplicant_cancel_scan(wpa_s); | |
1139 | ||
c2a04078 | 1140 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
56586197 | 1141 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1142 | /* |
1143 | * We are done; the driver will take care of RSN 4-way | |
1144 | * handshake. | |
1145 | */ | |
1146 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1147 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1148 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1149 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
1150 | } | |
1ff73338 JM |
1151 | |
1152 | if (wpa_s->pending_eapol_rx) { | |
1153 | struct os_time now, age; | |
1154 | os_get_time(&now); | |
1155 | os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age); | |
1156 | if (age.sec == 0 && age.usec < 100000 && | |
1157 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == | |
1158 | 0) { | |
1159 | wpa_printf(MSG_DEBUG, "Process pending EAPOL frame " | |
1160 | "that was received just before association " | |
1161 | "notification"); | |
1162 | wpa_supplicant_rx_eapol( | |
1163 | wpa_s, wpa_s->pending_eapol_rx_src, | |
1164 | wpabuf_head(wpa_s->pending_eapol_rx), | |
1165 | wpabuf_len(wpa_s->pending_eapol_rx)); | |
1166 | } | |
1167 | wpabuf_free(wpa_s->pending_eapol_rx); | |
1168 | wpa_s->pending_eapol_rx = NULL; | |
1169 | } | |
60b94c98 JM |
1170 | |
1171 | #ifdef CONFIG_BGSCAN | |
1172 | if (wpa_s->current_ssid != wpa_s->bgscan_ssid) { | |
1173 | bgscan_deinit(wpa_s); | |
1174 | if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) { | |
1175 | if (bgscan_init(wpa_s, wpa_s->current_ssid)) { | |
1176 | wpa_printf(MSG_DEBUG, "Failed to initialize " | |
1177 | "bgscan"); | |
1178 | /* | |
1179 | * Live without bgscan; it is only used as a | |
1180 | * roaming optimization, so the initial | |
1181 | * connection is not affected. | |
1182 | */ | |
1183 | } else | |
1184 | wpa_s->bgscan_ssid = wpa_s->current_ssid; | |
1185 | } else | |
1186 | wpa_s->bgscan_ssid = NULL; | |
1187 | } | |
1188 | #endif /* CONFIG_BGSCAN */ | |
0194fedb JB |
1189 | |
1190 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
1191 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
1192 | wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 && | |
1193 | capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) { | |
1194 | /* Set static WEP keys again */ | |
1195 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); | |
1196 | } | |
6fc6879b JM |
1197 | } |
1198 | ||
1199 | ||
0544b242 JM |
1200 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
1201 | u16 reason_code) | |
6fc6879b JM |
1202 | { |
1203 | const u8 *bssid; | |
6d6f4bb8 JM |
1204 | #ifdef CONFIG_SME |
1205 | int authenticating; | |
1206 | u8 prev_pending_bssid[ETH_ALEN]; | |
1207 | ||
1208 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; | |
1209 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); | |
1210 | #endif /* CONFIG_SME */ | |
6fc6879b JM |
1211 | |
1212 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
1213 | /* | |
1214 | * At least Host AP driver and a Prism3 card seemed to be | |
1215 | * generating streams of disconnected events when configuring | |
1216 | * IBSS for WPA-None. Ignore them for now. | |
1217 | */ | |
1218 | wpa_printf(MSG_DEBUG, "Disconnect event - ignore in " | |
1219 | "IBSS/WPA-None mode"); | |
1220 | return; | |
1221 | } | |
1222 | ||
1223 | if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE && | |
56586197 | 1224 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1225 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
1226 | "pre-shared key may be incorrect"); | |
1227 | } | |
0d0a8ca1 AC |
1228 | if (!wpa_s->auto_reconnect_disabled || |
1229 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { | |
1230 | wpa_printf(MSG_DEBUG, "WPA: Auto connect enabled: try to " | |
1231 | "reconnect (wps=%d)", | |
1232 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS); | |
ea184114 | 1233 | if (wpa_s->wpa_state >= WPA_ASSOCIATING) |
0d0a8ca1 AC |
1234 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
1235 | } else { | |
1236 | wpa_printf(MSG_DEBUG, "WPA: Auto connect disabled: do not try " | |
1237 | "to re-connect"); | |
1238 | wpa_s->reassociate = 0; | |
1239 | wpa_s->disconnected = 1; | |
1240 | } | |
6fc6879b | 1241 | bssid = wpa_s->bssid; |
a8e16edc | 1242 | if (is_zero_ether_addr(bssid)) |
6fc6879b JM |
1243 | bssid = wpa_s->pending_bssid; |
1244 | wpa_blacklist_add(wpa_s, bssid); | |
1245 | wpa_sm_notify_disassoc(wpa_s->wpa); | |
0544b242 JM |
1246 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR |
1247 | " reason=%d", | |
1248 | MAC2STR(bssid), reason_code); | |
6fc6879b | 1249 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
0544b242 | 1250 | wpa_printf(MSG_DEBUG, "Disconnect event - remove keys"); |
6fc6879b JM |
1251 | wpa_s->keys_cleared = 0; |
1252 | wpa_clear_keys(wpa_s, wpa_s->bssid); | |
1253 | } | |
1254 | wpa_supplicant_mark_disassoc(wpa_s); | |
60b94c98 | 1255 | bgscan_deinit(wpa_s); |
3b038d79 | 1256 | wpa_s->bgscan_ssid = NULL; |
6d6f4bb8 JM |
1257 | #ifdef CONFIG_SME |
1258 | if (authenticating && | |
1259 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) { | |
1260 | /* | |
1261 | * mac80211-workaround to force deauth on failed auth cmd, | |
1262 | * requires us to remain in authenticating state to allow the | |
1263 | * second authentication attempt to be continued properly. | |
1264 | */ | |
1265 | wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to " | |
1266 | "proceed after disconnection event"); | |
1267 | wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING); | |
1268 | os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN); | |
1269 | } | |
1270 | #endif /* CONFIG_SME */ | |
6fc6879b JM |
1271 | } |
1272 | ||
1273 | ||
46690a3b JM |
1274 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
1275 | static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, | |
1276 | void *sock_ctx) | |
1277 | { | |
1278 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1279 | ||
1280 | if (!wpa_s->pending_mic_error_report) | |
1281 | return; | |
1282 | ||
1283 | wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report"); | |
1284 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); | |
1285 | wpa_s->pending_mic_error_report = 0; | |
1286 | } | |
1287 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1288 | ||
1289 | ||
6fc6879b JM |
1290 | static void |
1291 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, | |
1292 | union wpa_event_data *data) | |
1293 | { | |
1294 | int pairwise; | |
1295 | struct os_time t; | |
1296 | ||
1297 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); | |
1298 | pairwise = (data && data->michael_mic_failure.unicast); | |
6fc6879b | 1299 | os_get_time(&t); |
46690a3b JM |
1300 | if ((wpa_s->last_michael_mic_error && |
1301 | t.sec - wpa_s->last_michael_mic_error <= 60) || | |
1302 | wpa_s->pending_mic_error_report) { | |
1303 | if (wpa_s->pending_mic_error_report) { | |
1304 | /* | |
1305 | * Send the pending MIC error report immediately since | |
1306 | * we are going to start countermeasures and AP better | |
1307 | * do the same. | |
1308 | */ | |
1309 | wpa_sm_key_request(wpa_s->wpa, 1, | |
1310 | wpa_s->pending_mic_error_pairwise); | |
1311 | } | |
1312 | ||
1313 | /* Send the new MIC error report immediately since we are going | |
1314 | * to start countermeasures and AP better do the same. | |
1315 | */ | |
1316 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1317 | ||
6fc6879b JM |
1318 | /* initialize countermeasures */ |
1319 | wpa_s->countermeasures = 1; | |
1320 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); | |
1321 | ||
1322 | /* | |
1323 | * Need to wait for completion of request frame. We do not get | |
1324 | * any callback for the message completion, so just wait a | |
1325 | * short while and hope for the best. */ | |
1326 | os_sleep(0, 10000); | |
1327 | ||
1328 | wpa_drv_set_countermeasures(wpa_s, 1); | |
1329 | wpa_supplicant_deauthenticate(wpa_s, | |
1330 | WLAN_REASON_MICHAEL_MIC_FAILURE); | |
1331 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, | |
1332 | wpa_s, NULL); | |
1333 | eloop_register_timeout(60, 0, | |
1334 | wpa_supplicant_stop_countermeasures, | |
1335 | wpa_s, NULL); | |
1336 | /* TODO: mark the AP rejected for 60 second. STA is | |
1337 | * allowed to associate with another AP.. */ | |
46690a3b JM |
1338 | } else { |
1339 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
1340 | if (wpa_s->mic_errors_seen) { | |
1341 | /* | |
1342 | * Reduce the effectiveness of Michael MIC error | |
1343 | * reports as a means for attacking against TKIP if | |
1344 | * more than one MIC failure is noticed with the same | |
1345 | * PTK. We delay the transmission of the reports by a | |
1346 | * random time between 0 and 60 seconds in order to | |
1347 | * force the attacker wait 60 seconds before getting | |
1348 | * the information on whether a frame resulted in a MIC | |
1349 | * failure. | |
1350 | */ | |
1351 | u8 rval[4]; | |
1352 | int sec; | |
1353 | ||
1354 | if (os_get_random(rval, sizeof(rval)) < 0) | |
1355 | sec = os_random() % 60; | |
1356 | else | |
1357 | sec = WPA_GET_BE32(rval) % 60; | |
1358 | wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d " | |
1359 | "seconds", sec); | |
1360 | wpa_s->pending_mic_error_report = 1; | |
1361 | wpa_s->pending_mic_error_pairwise = pairwise; | |
1362 | eloop_cancel_timeout( | |
1363 | wpa_supplicant_delayed_mic_error_report, | |
1364 | wpa_s, NULL); | |
1365 | eloop_register_timeout( | |
1366 | sec, os_random() % 1000000, | |
1367 | wpa_supplicant_delayed_mic_error_report, | |
1368 | wpa_s, NULL); | |
1369 | } else { | |
1370 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1371 | } | |
1372 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1373 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1374 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
6fc6879b JM |
1375 | } |
1376 | wpa_s->last_michael_mic_error = t.sec; | |
46690a3b | 1377 | wpa_s->mic_errors_seen++; |
6fc6879b JM |
1378 | } |
1379 | ||
1380 | ||
a83d9c96 SL |
1381 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1382 | static int any_interfaces(struct wpa_supplicant *head) | |
1383 | { | |
1384 | struct wpa_supplicant *wpa_s; | |
1385 | ||
1386 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) | |
1387 | if (!wpa_s->interface_removed) | |
1388 | return 1; | |
1389 | return 0; | |
1390 | } | |
1391 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
1392 | ||
1393 | ||
6fc6879b JM |
1394 | static void |
1395 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, | |
1396 | union wpa_event_data *data) | |
1397 | { | |
1398 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) | |
1399 | return; | |
1400 | ||
1401 | switch (data->interface_status.ievent) { | |
1402 | case EVENT_INTERFACE_ADDED: | |
1403 | if (!wpa_s->interface_removed) | |
1404 | break; | |
1405 | wpa_s->interface_removed = 0; | |
1406 | wpa_printf(MSG_DEBUG, "Configured interface was added."); | |
1407 | if (wpa_supplicant_driver_init(wpa_s) < 0) { | |
1408 | wpa_printf(MSG_INFO, "Failed to initialize the driver " | |
1409 | "after interface was added."); | |
1410 | } | |
1411 | break; | |
1412 | case EVENT_INTERFACE_REMOVED: | |
1413 | wpa_printf(MSG_DEBUG, "Configured interface was removed."); | |
1414 | wpa_s->interface_removed = 1; | |
1415 | wpa_supplicant_mark_disassoc(wpa_s); | |
1416 | l2_packet_deinit(wpa_s->l2); | |
1417 | wpa_s->l2 = NULL; | |
a83d9c96 SL |
1418 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1419 | /* check if last interface */ | |
1420 | if (!any_interfaces(wpa_s->global->ifaces)) | |
1421 | eloop_terminate(); | |
1422 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
6fc6879b JM |
1423 | break; |
1424 | } | |
1425 | } | |
1426 | ||
1427 | ||
1428 | #ifdef CONFIG_PEERKEY | |
1429 | static void | |
1430 | wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, | |
1431 | union wpa_event_data *data) | |
1432 | { | |
1433 | if (data == NULL) | |
1434 | return; | |
1435 | wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); | |
1436 | } | |
1437 | #endif /* CONFIG_PEERKEY */ | |
1438 | ||
1439 | ||
1440 | #ifdef CONFIG_IEEE80211R | |
1441 | static void | |
1442 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, | |
1443 | union wpa_event_data *data) | |
1444 | { | |
1445 | if (data == NULL) | |
1446 | return; | |
1447 | ||
1448 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, | |
1449 | data->ft_ies.ies_len, | |
1450 | data->ft_ies.ft_action, | |
babfbf15 JM |
1451 | data->ft_ies.target_ap, |
1452 | data->ft_ies.ric_ies, | |
1453 | data->ft_ies.ric_ies_len) < 0) { | |
6fc6879b JM |
1454 | /* TODO: prevent MLME/driver from trying to associate? */ |
1455 | } | |
1456 | } | |
1457 | #endif /* CONFIG_IEEE80211R */ | |
1458 | ||
1459 | ||
11ef8d35 JM |
1460 | #ifdef CONFIG_IBSS_RSN |
1461 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, | |
1462 | union wpa_event_data *data) | |
1463 | { | |
1464 | if (data == NULL) | |
1465 | return; | |
1466 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); | |
1467 | } | |
1468 | #endif /* CONFIG_IBSS_RSN */ | |
1469 | ||
1470 | ||
036f7c4a JM |
1471 | #ifdef CONFIG_IEEE80211R |
1472 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, | |
1473 | size_t len) | |
1474 | { | |
1475 | const u8 *sta_addr, *target_ap_addr; | |
1476 | u16 status; | |
1477 | ||
1478 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); | |
1479 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
1480 | return; /* only SME case supported for now */ | |
1481 | if (len < 1 + 2 * ETH_ALEN + 2) | |
1482 | return; | |
1483 | if (data[0] != 2) | |
1484 | return; /* Only FT Action Response is supported for now */ | |
1485 | sta_addr = data + 1; | |
1486 | target_ap_addr = data + 1 + ETH_ALEN; | |
1487 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); | |
1488 | wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR | |
1489 | " TargetAP " MACSTR " status %u", | |
1490 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); | |
1491 | ||
1492 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { | |
1493 | wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR | |
1494 | " in FT Action Response", MAC2STR(sta_addr)); | |
1495 | return; | |
1496 | } | |
1497 | ||
1498 | if (status) { | |
1499 | wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates " | |
1500 | "failure (status code %d)", status); | |
1501 | /* TODO: report error to FT code(?) */ | |
1502 | return; | |
1503 | } | |
1504 | ||
1505 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, | |
1506 | len - (1 + 2 * ETH_ALEN + 2), 1, | |
1507 | target_ap_addr, NULL, 0) < 0) | |
1508 | return; | |
1509 | ||
fe191985 JM |
1510 | #ifdef CONFIG_SME |
1511 | { | |
1512 | struct wpa_bss *bss; | |
1513 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); | |
1514 | if (bss) | |
1515 | wpa_s->sme.freq = bss->freq; | |
62c72d72 | 1516 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
fe191985 JM |
1517 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
1518 | WLAN_AUTH_FT); | |
1519 | } | |
1520 | #endif /* CONFIG_SME */ | |
036f7c4a JM |
1521 | } |
1522 | #endif /* CONFIG_IEEE80211R */ | |
1523 | ||
1524 | ||
9646a8ab | 1525 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
6fc6879b JM |
1526 | union wpa_event_data *data) |
1527 | { | |
1528 | struct wpa_supplicant *wpa_s = ctx; | |
0544b242 | 1529 | u16 reason_code = 0; |
6fc6879b | 1530 | |
8401a6b0 JM |
1531 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
1532 | event != EVENT_INTERFACE_ENABLED && | |
1533 | event != EVENT_INTERFACE_STATUS) { | |
1534 | wpa_printf(MSG_DEBUG, "Ignore event %d while interface is " | |
1535 | "disabled", event); | |
1536 | return; | |
1537 | } | |
1538 | ||
9b7124b2 JM |
1539 | wpa_printf(MSG_DEBUG, "Event %d received on interface %s", |
1540 | event, wpa_s->ifname); | |
1541 | ||
6fc6879b | 1542 | switch (event) { |
c2a04078 JM |
1543 | case EVENT_AUTH: |
1544 | sme_event_auth(wpa_s, data); | |
1545 | break; | |
6fc6879b JM |
1546 | case EVENT_ASSOC: |
1547 | wpa_supplicant_event_assoc(wpa_s, data); | |
1548 | break; | |
1549 | case EVENT_DISASSOC: | |
159dd3e2 | 1550 | wpa_printf(MSG_DEBUG, "Disassociation notification"); |
2e75a2b3 JM |
1551 | if (data) { |
1552 | wpa_printf(MSG_DEBUG, " * reason %u", | |
1553 | data->disassoc_info.reason_code); | |
1554 | if (data->disassoc_info.addr) | |
1555 | wpa_printf(MSG_DEBUG, " * address " MACSTR, | |
1556 | MAC2STR(data->disassoc_info.addr)); | |
1557 | } | |
1d041bec | 1558 | #ifdef CONFIG_AP |
7f542069 | 1559 | if (wpa_s->ap_iface && data && data->disassoc_info.addr) { |
1d041bec JM |
1560 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], |
1561 | data->disassoc_info.addr); | |
1562 | break; | |
1563 | } | |
1564 | #endif /* CONFIG_AP */ | |
9fdd0fad JM |
1565 | if (data) { |
1566 | reason_code = data->disassoc_info.reason_code; | |
1567 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", | |
1568 | data->disassoc_info.ie, | |
1569 | data->disassoc_info.ie_len); | |
1570 | #ifdef CONFIG_P2P | |
1571 | wpas_p2p_disassoc_notif( | |
1572 | wpa_s, data->disassoc_info.addr, reason_code, | |
1573 | data->disassoc_info.ie, | |
1574 | data->disassoc_info.ie_len); | |
1575 | #endif /* CONFIG_P2P */ | |
1576 | } | |
0e379654 JM |
1577 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
1578 | sme_event_disassoc(wpa_s, data); | |
a84ed99e JM |
1579 | /* fall through */ |
1580 | case EVENT_DEAUTH: | |
0544b242 | 1581 | if (event == EVENT_DEAUTH) { |
159dd3e2 | 1582 | wpa_printf(MSG_DEBUG, "Deauthentication notification"); |
2e75a2b3 | 1583 | if (data) { |
0544b242 | 1584 | reason_code = data->deauth_info.reason_code; |
2e75a2b3 JM |
1585 | wpa_printf(MSG_DEBUG, " * reason %u", |
1586 | data->deauth_info.reason_code); | |
1587 | if (data->deauth_info.addr) { | |
1588 | wpa_printf(MSG_DEBUG, " * address " | |
1589 | MACSTR, | |
1590 | MAC2STR(data->deauth_info. | |
1591 | addr)); | |
1592 | } | |
9fdd0fad JM |
1593 | wpa_hexdump(MSG_DEBUG, |
1594 | "Deauthentication frame IE(s)", | |
1595 | data->deauth_info.ie, | |
1596 | data->deauth_info.ie_len); | |
1597 | #ifdef CONFIG_P2P | |
1598 | wpas_p2p_deauth_notif( | |
1599 | wpa_s, data->deauth_info.addr, | |
1600 | reason_code, | |
1601 | data->deauth_info.ie, | |
1602 | data->deauth_info.ie_len); | |
1603 | #endif /* CONFIG_P2P */ | |
2e75a2b3 | 1604 | } |
0544b242 | 1605 | } |
1d041bec | 1606 | #ifdef CONFIG_AP |
7f542069 | 1607 | if (wpa_s->ap_iface && data && data->deauth_info.addr) { |
1d041bec JM |
1608 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], |
1609 | data->deauth_info.addr); | |
1610 | break; | |
1611 | } | |
1612 | #endif /* CONFIG_AP */ | |
0544b242 | 1613 | wpa_supplicant_event_disassoc(wpa_s, reason_code); |
6fc6879b JM |
1614 | break; |
1615 | case EVENT_MICHAEL_MIC_FAILURE: | |
1616 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); | |
1617 | break; | |
1618 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
1619 | case EVENT_SCAN_RESULTS: | |
8d923a4a | 1620 | wpa_supplicant_event_scan_results(wpa_s, data); |
6fc6879b JM |
1621 | break; |
1622 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
1623 | case EVENT_ASSOCINFO: | |
1624 | wpa_supplicant_event_associnfo(wpa_s, data); | |
1625 | break; | |
1626 | case EVENT_INTERFACE_STATUS: | |
1627 | wpa_supplicant_event_interface_status(wpa_s, data); | |
1628 | break; | |
1629 | case EVENT_PMKID_CANDIDATE: | |
1630 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); | |
1631 | break; | |
1632 | #ifdef CONFIG_PEERKEY | |
1633 | case EVENT_STKSTART: | |
1634 | wpa_supplicant_event_stkstart(wpa_s, data); | |
1635 | break; | |
1636 | #endif /* CONFIG_PEERKEY */ | |
1637 | #ifdef CONFIG_IEEE80211R | |
1638 | case EVENT_FT_RESPONSE: | |
1639 | wpa_supplicant_event_ft_response(wpa_s, data); | |
1640 | break; | |
1641 | #endif /* CONFIG_IEEE80211R */ | |
11ef8d35 JM |
1642 | #ifdef CONFIG_IBSS_RSN |
1643 | case EVENT_IBSS_RSN_START: | |
1644 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); | |
1645 | break; | |
1646 | #endif /* CONFIG_IBSS_RSN */ | |
efa46078 JM |
1647 | case EVENT_ASSOC_REJECT: |
1648 | sme_event_assoc_reject(wpa_s, data); | |
1649 | break; | |
da1fb17c JM |
1650 | case EVENT_AUTH_TIMED_OUT: |
1651 | sme_event_auth_timed_out(wpa_s, data); | |
1652 | break; | |
1653 | case EVENT_ASSOC_TIMED_OUT: | |
1654 | sme_event_assoc_timed_out(wpa_s, data); | |
1655 | break; | |
f8b1f695 JM |
1656 | #ifdef CONFIG_AP |
1657 | case EVENT_TX_STATUS: | |
9bae1be0 JM |
1658 | wpa_printf(MSG_DEBUG, "EVENT_TX_STATUS on %s dst=" MACSTR |
1659 | " type=%d stype=%d pending_dst=" MACSTR, | |
1660 | wpa_s->ifname, MAC2STR(data->tx_status.dst), | |
1661 | data->tx_status.type, data->tx_status.stype, | |
1662 | MAC2STR(wpa_s->parent->pending_action_dst)); | |
1663 | if (wpa_s->ap_iface == NULL) { | |
1664 | #ifdef CONFIG_P2P | |
1665 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && | |
1666 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) | |
1667 | wpas_send_action_tx_status( | |
1668 | wpa_s, data->tx_status.dst, | |
1669 | data->tx_status.data, | |
1670 | data->tx_status.data_len, | |
1671 | data->tx_status.ack); | |
1672 | #endif /* CONFIG_P2P */ | |
1673 | break; | |
1674 | } | |
1675 | #ifdef CONFIG_P2P | |
1676 | /* | |
1677 | * Catch TX status events for Action frames we sent via group | |
1678 | * interface in GO mode. | |
1679 | */ | |
1680 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && | |
1681 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && | |
1682 | os_memcmp(wpa_s->parent->pending_action_dst, | |
1683 | data->tx_status.dst, ETH_ALEN) == 0) { | |
1684 | wpas_send_action_tx_status( | |
1685 | wpa_s->parent, data->tx_status.dst, | |
1686 | data->tx_status.data, | |
1687 | data->tx_status.data_len, | |
1688 | data->tx_status.ack); | |
f8b1f695 | 1689 | break; |
9bae1be0 JM |
1690 | } |
1691 | #endif /* CONFIG_P2P */ | |
f8b1f695 JM |
1692 | switch (data->tx_status.type) { |
1693 | case WLAN_FC_TYPE_MGMT: | |
1694 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, | |
1695 | data->tx_status.data_len, | |
1696 | data->tx_status.stype, | |
1697 | data->tx_status.ack); | |
1698 | break; | |
1699 | case WLAN_FC_TYPE_DATA: | |
1700 | ap_tx_status(wpa_s, data->tx_status.dst, | |
1701 | data->tx_status.data, | |
1702 | data->tx_status.data_len, | |
1703 | data->tx_status.ack); | |
1704 | break; | |
1705 | } | |
1706 | break; | |
1707 | case EVENT_RX_FROM_UNKNOWN: | |
1708 | if (wpa_s->ap_iface == NULL) | |
1709 | break; | |
fdbe50ed | 1710 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame, |
f8b1f695 JM |
1711 | data->rx_from_unknown.len); |
1712 | break; | |
1713 | case EVENT_RX_MGMT: | |
9bae1be0 JM |
1714 | if (wpa_s->ap_iface == NULL) { |
1715 | #ifdef CONFIG_P2P | |
1716 | u16 fc, stype; | |
1717 | const struct ieee80211_mgmt *mgmt; | |
1718 | mgmt = (const struct ieee80211_mgmt *) | |
1719 | data->rx_mgmt.frame; | |
1720 | fc = le_to_host16(mgmt->frame_control); | |
1721 | stype = WLAN_FC_GET_STYPE(fc); | |
1722 | if (stype == WLAN_FC_STYPE_PROBE_REQ && | |
1723 | data->rx_mgmt.frame_len > 24) { | |
1724 | const u8 *src = mgmt->sa; | |
1725 | const u8 *ie = mgmt->u.probe_req.variable; | |
1726 | size_t ie_len = data->rx_mgmt.frame_len - | |
1727 | (mgmt->u.probe_req.variable - | |
1728 | data->rx_mgmt.frame); | |
1729 | wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len); | |
1730 | break; | |
1731 | } | |
1732 | #endif /* CONFIG_P2P */ | |
1733 | wpa_printf(MSG_DEBUG, "AP: ignore received management " | |
1734 | "frame in non-AP mode"); | |
f8b1f695 | 1735 | break; |
9bae1be0 | 1736 | } |
2a8b7416 | 1737 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
f8b1f695 JM |
1738 | break; |
1739 | #endif /* CONFIG_AP */ | |
036f7c4a JM |
1740 | case EVENT_RX_ACTION: |
1741 | wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR | |
1742 | " Category=%u DataLen=%d freq=%d MHz", | |
1743 | MAC2STR(data->rx_action.sa), | |
1744 | data->rx_action.category, (int) data->rx_action.len, | |
1745 | data->rx_action.freq); | |
1746 | #ifdef CONFIG_IEEE80211R | |
1747 | if (data->rx_action.category == WLAN_ACTION_FT) { | |
1748 | ft_rx_action(wpa_s, data->rx_action.data, | |
1749 | data->rx_action.len); | |
1750 | break; | |
1751 | } | |
1752 | #endif /* CONFIG_IEEE80211R */ | |
9bae1be0 JM |
1753 | #ifdef CONFIG_P2P |
1754 | wpas_p2p_rx_action(wpa_s, data->rx_action.da, | |
1755 | data->rx_action.sa, | |
1756 | data->rx_action.bssid, | |
1757 | data->rx_action.category, | |
1758 | data->rx_action.data, | |
1759 | data->rx_action.len, data->rx_action.freq); | |
1760 | #endif /* CONFIG_P2P */ | |
036f7c4a | 1761 | break; |
9bae1be0 JM |
1762 | #ifdef CONFIG_P2P |
1763 | case EVENT_REMAIN_ON_CHANNEL: | |
1764 | wpas_p2p_remain_on_channel_cb( | |
1765 | wpa_s, data->remain_on_channel.freq, | |
1766 | data->remain_on_channel.duration); | |
1767 | break; | |
1768 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: | |
1769 | wpas_p2p_cancel_remain_on_channel_cb( | |
1770 | wpa_s, data->remain_on_channel.freq); | |
1771 | break; | |
1772 | case EVENT_RX_PROBE_REQ: | |
1773 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, | |
1774 | data->rx_probe_req.ie, | |
1775 | data->rx_probe_req.ie_len); | |
1776 | break; | |
1777 | #endif /* CONFIG_P2P */ | |
245519e0 JM |
1778 | #ifdef CONFIG_CLIENT_MLME |
1779 | case EVENT_MLME_RX: { | |
1780 | struct ieee80211_rx_status rx_status; | |
1781 | os_memset(&rx_status, 0, sizeof(rx_status)); | |
1782 | rx_status.freq = data->mlme_rx.freq; | |
1783 | rx_status.channel = data->mlme_rx.channel; | |
1784 | rx_status.ssi = data->mlme_rx.ssi; | |
1785 | ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len, | |
1786 | &rx_status); | |
1787 | break; | |
1788 | } | |
1789 | #endif /* CONFIG_CLIENT_MLME */ | |
a8e0505b JM |
1790 | case EVENT_EAPOL_RX: |
1791 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, | |
1792 | data->eapol_rx.data, | |
1793 | data->eapol_rx.data_len); | |
1794 | break; | |
e2f74005 JM |
1795 | case EVENT_SIGNAL_CHANGE: |
1796 | bgscan_notify_signal_change( | |
60a972a6 JM |
1797 | wpa_s, data->signal_change.above_threshold, |
1798 | data->signal_change.current_signal); | |
e2f74005 | 1799 | break; |
8401a6b0 JM |
1800 | case EVENT_INTERFACE_ENABLED: |
1801 | wpa_printf(MSG_DEBUG, "Interface was enabled"); | |
1802 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | |
1803 | wpa_supplicant_set_state(wpa_s, | |
1804 | WPA_DISCONNECTED); | |
1805 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
1806 | } | |
1807 | break; | |
1808 | case EVENT_INTERFACE_DISABLED: | |
1809 | wpa_printf(MSG_DEBUG, "Interface was disabled"); | |
1810 | wpa_supplicant_mark_disassoc(wpa_s); | |
1811 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); | |
1812 | break; | |
6fc6879b JM |
1813 | default: |
1814 | wpa_printf(MSG_INFO, "Unknown event %d", event); | |
1815 | break; | |
1816 | } | |
1817 | } |