]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * WPA Supplicant - Driver event processing | |
3 | * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi> | |
4 | * | |
5 | * This software may be distributed under the terms of the BSD license. | |
6 | * See README for more details. | |
7 | */ | |
8 | ||
9 | #include "includes.h" | |
10 | ||
11 | #include "common.h" | |
12 | #include "eapol_supp/eapol_supp_sm.h" | |
13 | #include "rsn_supp/wpa.h" | |
14 | #include "eloop.h" | |
15 | #include "config.h" | |
16 | #include "l2_packet/l2_packet.h" | |
17 | #include "wpa_supplicant_i.h" | |
18 | #include "driver_i.h" | |
19 | #include "pcsc_funcs.h" | |
20 | #include "rsn_supp/preauth.h" | |
21 | #include "rsn_supp/pmksa_cache.h" | |
22 | #include "common/wpa_ctrl.h" | |
23 | #include "eap_peer/eap.h" | |
24 | #include "ap/hostapd.h" | |
25 | #include "p2p/p2p.h" | |
26 | #include "notify.h" | |
27 | #include "common/ieee802_11_defs.h" | |
28 | #include "common/ieee802_11_common.h" | |
29 | #include "crypto/random.h" | |
30 | #include "blacklist.h" | |
31 | #include "wpas_glue.h" | |
32 | #include "wps_supplicant.h" | |
33 | #include "ibss_rsn.h" | |
34 | #include "sme.h" | |
35 | #include "gas_query.h" | |
36 | #include "p2p_supplicant.h" | |
37 | #include "bgscan.h" | |
38 | #include "ap.h" | |
39 | #include "bss.h" | |
40 | #include "scan.h" | |
41 | #include "offchannel.h" | |
42 | ||
43 | ||
44 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) | |
45 | { | |
46 | struct wpa_ssid *ssid, *old_ssid; | |
47 | ||
48 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) | |
49 | return 0; | |
50 | ||
51 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " | |
52 | "information"); | |
53 | ssid = wpa_supplicant_get_ssid(wpa_s); | |
54 | if (ssid == NULL) { | |
55 | wpa_msg(wpa_s, MSG_INFO, | |
56 | "No network configuration found for the current AP"); | |
57 | return -1; | |
58 | } | |
59 | ||
60 | if (ssid->disabled) { | |
61 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); | |
62 | return -1; | |
63 | } | |
64 | ||
65 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " | |
66 | "current AP"); | |
67 | if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { | |
68 | u8 wpa_ie[80]; | |
69 | size_t wpa_ie_len = sizeof(wpa_ie); | |
70 | wpa_supplicant_set_suites(wpa_s, NULL, ssid, | |
71 | wpa_ie, &wpa_ie_len); | |
72 | } else { | |
73 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
74 | } | |
75 | ||
76 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) | |
77 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
78 | old_ssid = wpa_s->current_ssid; | |
79 | wpa_s->current_ssid = ssid; | |
80 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); | |
81 | wpa_supplicant_initiate_eapol(wpa_s); | |
82 | if (old_ssid != wpa_s->current_ssid) | |
83 | wpas_notify_network_changed(wpa_s); | |
84 | ||
85 | return 0; | |
86 | } | |
87 | ||
88 | ||
89 | void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx) | |
90 | { | |
91 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
92 | ||
93 | if (wpa_s->countermeasures) { | |
94 | wpa_s->countermeasures = 0; | |
95 | wpa_drv_set_countermeasures(wpa_s, 0); | |
96 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); | |
97 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
98 | } | |
99 | } | |
100 | ||
101 | ||
102 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) | |
103 | { | |
104 | int bssid_changed; | |
105 | ||
106 | #ifdef CONFIG_IBSS_RSN | |
107 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
108 | wpa_s->ibss_rsn = NULL; | |
109 | #endif /* CONFIG_IBSS_RSN */ | |
110 | ||
111 | #ifdef CONFIG_AP | |
112 | wpa_supplicant_ap_deinit(wpa_s); | |
113 | #endif /* CONFIG_AP */ | |
114 | ||
115 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) | |
116 | return; | |
117 | ||
118 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
119 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); | |
120 | os_memset(wpa_s->bssid, 0, ETH_ALEN); | |
121 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
122 | #ifdef CONFIG_P2P | |
123 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); | |
124 | #endif /* CONFIG_P2P */ | |
125 | wpa_s->current_bss = NULL; | |
126 | wpa_s->assoc_freq = 0; | |
127 | #ifdef CONFIG_IEEE80211R | |
128 | #ifdef CONFIG_SME | |
129 | if (wpa_s->sme.ft_ies) | |
130 | sme_update_ft_ies(wpa_s, NULL, NULL, 0); | |
131 | #endif /* CONFIG_SME */ | |
132 | #endif /* CONFIG_IEEE80211R */ | |
133 | ||
134 | if (bssid_changed) | |
135 | wpas_notify_bssid_changed(wpa_s); | |
136 | ||
137 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
138 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
139 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) | |
140 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); | |
141 | wpa_s->ap_ies_from_associnfo = 0; | |
142 | } | |
143 | ||
144 | ||
145 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) | |
146 | { | |
147 | struct wpa_ie_data ie; | |
148 | int pmksa_set = -1; | |
149 | size_t i; | |
150 | ||
151 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || | |
152 | ie.pmkid == NULL) | |
153 | return; | |
154 | ||
155 | for (i = 0; i < ie.num_pmkid; i++) { | |
156 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, | |
157 | ie.pmkid + i * PMKID_LEN, | |
158 | NULL, NULL, 0); | |
159 | if (pmksa_set == 0) { | |
160 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1); | |
161 | break; | |
162 | } | |
163 | } | |
164 | ||
165 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " | |
166 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); | |
167 | } | |
168 | ||
169 | ||
170 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, | |
171 | union wpa_event_data *data) | |
172 | { | |
173 | if (data == NULL) { | |
174 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " | |
175 | "event"); | |
176 | return; | |
177 | } | |
178 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR | |
179 | " index=%d preauth=%d", | |
180 | MAC2STR(data->pmkid_candidate.bssid), | |
181 | data->pmkid_candidate.index, | |
182 | data->pmkid_candidate.preauth); | |
183 | ||
184 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, | |
185 | data->pmkid_candidate.index, | |
186 | data->pmkid_candidate.preauth); | |
187 | } | |
188 | ||
189 | ||
190 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) | |
191 | { | |
192 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
193 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
194 | return 0; | |
195 | ||
196 | #ifdef IEEE8021X_EAPOL | |
197 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | |
198 | wpa_s->current_ssid && | |
199 | !(wpa_s->current_ssid->eapol_flags & | |
200 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
201 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { | |
202 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either | |
203 | * plaintext or static WEP keys). */ | |
204 | return 0; | |
205 | } | |
206 | #endif /* IEEE8021X_EAPOL */ | |
207 | ||
208 | return 1; | |
209 | } | |
210 | ||
211 | ||
212 | /** | |
213 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC | |
214 | * @wpa_s: pointer to wpa_supplicant data | |
215 | * @ssid: Configuration data for the network | |
216 | * Returns: 0 on success, -1 on failure | |
217 | * | |
218 | * This function is called when starting authentication with a network that is | |
219 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). | |
220 | */ | |
221 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, | |
222 | struct wpa_ssid *ssid) | |
223 | { | |
224 | #ifdef IEEE8021X_EAPOL | |
225 | #ifdef PCSC_FUNCS | |
226 | int aka = 0, sim = 0, type; | |
227 | ||
228 | if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL) | |
229 | return 0; | |
230 | ||
231 | if (ssid->eap.eap_methods == NULL) { | |
232 | sim = 1; | |
233 | aka = 1; | |
234 | } else { | |
235 | struct eap_method_type *eap = ssid->eap.eap_methods; | |
236 | while (eap->vendor != EAP_VENDOR_IETF || | |
237 | eap->method != EAP_TYPE_NONE) { | |
238 | if (eap->vendor == EAP_VENDOR_IETF) { | |
239 | if (eap->method == EAP_TYPE_SIM) | |
240 | sim = 1; | |
241 | else if (eap->method == EAP_TYPE_AKA) | |
242 | aka = 1; | |
243 | } | |
244 | eap++; | |
245 | } | |
246 | } | |
247 | ||
248 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) | |
249 | sim = 0; | |
250 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL) | |
251 | aka = 0; | |
252 | ||
253 | if (!sim && !aka) { | |
254 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " | |
255 | "use SIM, but neither EAP-SIM nor EAP-AKA are " | |
256 | "enabled"); | |
257 | return 0; | |
258 | } | |
259 | ||
260 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " | |
261 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); | |
262 | if (sim && aka) | |
263 | type = SCARD_TRY_BOTH; | |
264 | else if (aka) | |
265 | type = SCARD_USIM_ONLY; | |
266 | else | |
267 | type = SCARD_GSM_SIM_ONLY; | |
268 | ||
269 | wpa_s->scard = scard_init(type, NULL); | |
270 | if (wpa_s->scard == NULL) { | |
271 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " | |
272 | "(pcsc-lite)"); | |
273 | return -1; | |
274 | } | |
275 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
276 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
277 | #endif /* PCSC_FUNCS */ | |
278 | #endif /* IEEE8021X_EAPOL */ | |
279 | ||
280 | return 0; | |
281 | } | |
282 | ||
283 | ||
284 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
285 | static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss, | |
286 | struct wpa_ssid *ssid) | |
287 | { | |
288 | int i, privacy = 0; | |
289 | ||
290 | if (ssid->mixed_cell) | |
291 | return 1; | |
292 | ||
293 | #ifdef CONFIG_WPS | |
294 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) | |
295 | return 1; | |
296 | #endif /* CONFIG_WPS */ | |
297 | ||
298 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
299 | if (ssid->wep_key_len[i]) { | |
300 | privacy = 1; | |
301 | break; | |
302 | } | |
303 | } | |
304 | #ifdef IEEE8021X_EAPOL | |
305 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
306 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
307 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) | |
308 | privacy = 1; | |
309 | #endif /* IEEE8021X_EAPOL */ | |
310 | ||
311 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
312 | privacy = 1; | |
313 | ||
314 | if (bss->caps & IEEE80211_CAP_PRIVACY) | |
315 | return privacy; | |
316 | return !privacy; | |
317 | } | |
318 | ||
319 | ||
320 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, | |
321 | struct wpa_ssid *ssid, | |
322 | struct wpa_scan_res *bss) | |
323 | { | |
324 | struct wpa_ie_data ie; | |
325 | int proto_match = 0; | |
326 | const u8 *rsn_ie, *wpa_ie; | |
327 | int ret; | |
328 | int wep_ok; | |
329 | ||
330 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); | |
331 | if (ret >= 0) | |
332 | return ret; | |
333 | ||
334 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ | |
335 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && | |
336 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
337 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || | |
338 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); | |
339 | ||
340 | rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); | |
341 | while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { | |
342 | proto_match++; | |
343 | ||
344 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { | |
345 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse " | |
346 | "failed"); | |
347 | break; | |
348 | } | |
349 | ||
350 | if (wep_ok && | |
351 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
352 | { | |
353 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " | |
354 | "in RSN IE"); | |
355 | return 1; | |
356 | } | |
357 | ||
358 | if (!(ie.proto & ssid->proto)) { | |
359 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto " | |
360 | "mismatch"); | |
361 | break; | |
362 | } | |
363 | ||
364 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
365 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK " | |
366 | "cipher mismatch"); | |
367 | break; | |
368 | } | |
369 | ||
370 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
371 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK " | |
372 | "cipher mismatch"); | |
373 | break; | |
374 | } | |
375 | ||
376 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
377 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt " | |
378 | "mismatch"); | |
379 | break; | |
380 | } | |
381 | ||
382 | #ifdef CONFIG_IEEE80211W | |
383 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && | |
384 | ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) { | |
385 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt " | |
386 | "frame protection"); | |
387 | break; | |
388 | } | |
389 | #endif /* CONFIG_IEEE80211W */ | |
390 | ||
391 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE"); | |
392 | return 1; | |
393 | } | |
394 | ||
395 | wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
396 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { | |
397 | proto_match++; | |
398 | ||
399 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { | |
400 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse " | |
401 | "failed"); | |
402 | break; | |
403 | } | |
404 | ||
405 | if (wep_ok && | |
406 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
407 | { | |
408 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " | |
409 | "in WPA IE"); | |
410 | return 1; | |
411 | } | |
412 | ||
413 | if (!(ie.proto & ssid->proto)) { | |
414 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto " | |
415 | "mismatch"); | |
416 | break; | |
417 | } | |
418 | ||
419 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
420 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK " | |
421 | "cipher mismatch"); | |
422 | break; | |
423 | } | |
424 | ||
425 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
426 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK " | |
427 | "cipher mismatch"); | |
428 | break; | |
429 | } | |
430 | ||
431 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
432 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt " | |
433 | "mismatch"); | |
434 | break; | |
435 | } | |
436 | ||
437 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE"); | |
438 | return 1; | |
439 | } | |
440 | ||
441 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && | |
442 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { | |
443 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match"); | |
444 | return 0; | |
445 | } | |
446 | ||
447 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { | |
448 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); | |
449 | return 1; | |
450 | } | |
451 | ||
452 | wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with " | |
453 | "WPA/WPA2"); | |
454 | ||
455 | return 0; | |
456 | } | |
457 | ||
458 | ||
459 | static int freq_allowed(int *freqs, int freq) | |
460 | { | |
461 | int i; | |
462 | ||
463 | if (freqs == NULL) | |
464 | return 1; | |
465 | ||
466 | for (i = 0; freqs[i]; i++) | |
467 | if (freqs[i] == freq) | |
468 | return 1; | |
469 | return 0; | |
470 | } | |
471 | ||
472 | ||
473 | static int ht_supported(const struct hostapd_hw_modes *mode) | |
474 | { | |
475 | if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) { | |
476 | /* | |
477 | * The driver did not indicate whether it supports HT. Assume | |
478 | * it does to avoid connection issues. | |
479 | */ | |
480 | return 1; | |
481 | } | |
482 | ||
483 | /* | |
484 | * IEEE Std 802.11n-2009 20.1.1: | |
485 | * An HT non-AP STA shall support all EQM rates for one spatial stream. | |
486 | */ | |
487 | return mode->mcs_set[0] == 0xff; | |
488 | } | |
489 | ||
490 | ||
491 | static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss) | |
492 | { | |
493 | const struct hostapd_hw_modes *mode = NULL, *modes; | |
494 | const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; | |
495 | const u8 *rate_ie; | |
496 | int i, j, k; | |
497 | ||
498 | if (bss->freq == 0) | |
499 | return 1; /* Cannot do matching without knowing band */ | |
500 | ||
501 | modes = wpa_s->hw.modes; | |
502 | if (modes == NULL) { | |
503 | /* | |
504 | * The driver does not provide any additional information | |
505 | * about the utilized hardware, so allow the connection attempt | |
506 | * to continue. | |
507 | */ | |
508 | return 1; | |
509 | } | |
510 | ||
511 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
512 | for (j = 0; j < modes[i].num_channels; j++) { | |
513 | int freq = modes[i].channels[j].freq; | |
514 | if (freq == bss->freq) { | |
515 | if (mode && | |
516 | mode->mode == HOSTAPD_MODE_IEEE80211G) | |
517 | break; /* do not allow 802.11b replace | |
518 | * 802.11g */ | |
519 | mode = &modes[i]; | |
520 | break; | |
521 | } | |
522 | } | |
523 | } | |
524 | ||
525 | if (mode == NULL) | |
526 | return 0; | |
527 | ||
528 | for (i = 0; i < (int) sizeof(scan_ie); i++) { | |
529 | rate_ie = wpa_scan_get_ie(bss, scan_ie[i]); | |
530 | if (rate_ie == NULL) | |
531 | continue; | |
532 | ||
533 | for (j = 2; j < rate_ie[1] + 2; j++) { | |
534 | int flagged = !!(rate_ie[j] & 0x80); | |
535 | int r = (rate_ie[j] & 0x7f) * 5; | |
536 | ||
537 | /* | |
538 | * IEEE Std 802.11n-2009 7.3.2.2: | |
539 | * The new BSS Membership selector value is encoded | |
540 | * like a legacy basic rate, but it is not a rate and | |
541 | * only indicates if the BSS members are required to | |
542 | * support the mandatory features of Clause 20 [HT PHY] | |
543 | * in order to join the BSS. | |
544 | */ | |
545 | if (flagged && ((rate_ie[j] & 0x7f) == | |
546 | BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { | |
547 | if (!ht_supported(mode)) { | |
548 | wpa_dbg(wpa_s, MSG_DEBUG, | |
549 | " hardware does not support " | |
550 | "HT PHY"); | |
551 | return 0; | |
552 | } | |
553 | continue; | |
554 | } | |
555 | ||
556 | if (!flagged) | |
557 | continue; | |
558 | ||
559 | /* check for legacy basic rates */ | |
560 | for (k = 0; k < mode->num_rates; k++) { | |
561 | if (mode->rates[k] == r) | |
562 | break; | |
563 | } | |
564 | if (k == mode->num_rates) { | |
565 | /* | |
566 | * IEEE Std 802.11-2007 7.3.2.2 demands that in | |
567 | * order to join a BSS all required rates | |
568 | * have to be supported by the hardware. | |
569 | */ | |
570 | wpa_dbg(wpa_s, MSG_DEBUG, " hardware does " | |
571 | "not support required rate %d.%d Mbps", | |
572 | r / 10, r % 10); | |
573 | return 0; | |
574 | } | |
575 | } | |
576 | } | |
577 | ||
578 | return 1; | |
579 | } | |
580 | ||
581 | ||
582 | static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, | |
583 | int i, struct wpa_scan_res *bss, | |
584 | struct wpa_ssid *group) | |
585 | { | |
586 | const u8 *ssid_; | |
587 | u8 wpa_ie_len, rsn_ie_len, ssid_len; | |
588 | int wpa; | |
589 | struct wpa_blacklist *e; | |
590 | const u8 *ie; | |
591 | struct wpa_ssid *ssid; | |
592 | ||
593 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); | |
594 | ssid_ = ie ? ie + 2 : (u8 *) ""; | |
595 | ssid_len = ie ? ie[1] : 0; | |
596 | ||
597 | ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
598 | wpa_ie_len = ie ? ie[1] : 0; | |
599 | ||
600 | ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); | |
601 | rsn_ie_len = ie ? ie[1] : 0; | |
602 | ||
603 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' " | |
604 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s", | |
605 | i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len), | |
606 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, | |
607 | wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : ""); | |
608 | ||
609 | e = wpa_blacklist_get(wpa_s, bss->bssid); | |
610 | if (e) { | |
611 | int limit = 1; | |
612 | if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) { | |
613 | /* | |
614 | * When only a single network is enabled, we can | |
615 | * trigger blacklisting on the first failure. This | |
616 | * should not be done with multiple enabled networks to | |
617 | * avoid getting forced to move into a worse ESS on | |
618 | * single error if there are no other BSSes of the | |
619 | * current ESS. | |
620 | */ | |
621 | limit = 0; | |
622 | } | |
623 | if (e->count > limit) { | |
624 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " | |
625 | "(count=%d limit=%d)", e->count, limit); | |
626 | return NULL; | |
627 | } | |
628 | } | |
629 | ||
630 | if (ssid_len == 0) { | |
631 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); | |
632 | return NULL; | |
633 | } | |
634 | ||
635 | wpa = wpa_ie_len > 0 || rsn_ie_len > 0; | |
636 | ||
637 | for (ssid = group; ssid; ssid = ssid->pnext) { | |
638 | int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); | |
639 | ||
640 | if (ssid->disabled) { | |
641 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); | |
642 | continue; | |
643 | } | |
644 | ||
645 | #ifdef CONFIG_WPS | |
646 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) { | |
647 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " | |
648 | "(WPS)"); | |
649 | continue; | |
650 | } | |
651 | ||
652 | if (wpa && ssid->ssid_len == 0 && | |
653 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) | |
654 | check_ssid = 0; | |
655 | ||
656 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { | |
657 | /* Only allow wildcard SSID match if an AP | |
658 | * advertises active WPS operation that matches | |
659 | * with our mode. */ | |
660 | check_ssid = 1; | |
661 | if (ssid->ssid_len == 0 && | |
662 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) | |
663 | check_ssid = 0; | |
664 | } | |
665 | #endif /* CONFIG_WPS */ | |
666 | ||
667 | if (ssid->bssid_set && ssid->ssid_len == 0 && | |
668 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) | |
669 | check_ssid = 0; | |
670 | ||
671 | if (check_ssid && | |
672 | (ssid_len != ssid->ssid_len || | |
673 | os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) { | |
674 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); | |
675 | continue; | |
676 | } | |
677 | ||
678 | if (ssid->bssid_set && | |
679 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { | |
680 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); | |
681 | continue; | |
682 | } | |
683 | ||
684 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) | |
685 | continue; | |
686 | ||
687 | if (!wpa && | |
688 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
689 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && | |
690 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { | |
691 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network " | |
692 | "not allowed"); | |
693 | continue; | |
694 | } | |
695 | ||
696 | if (!wpa_supplicant_match_privacy(bss, ssid)) { | |
697 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy " | |
698 | "mismatch"); | |
699 | continue; | |
700 | } | |
701 | ||
702 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
703 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) " | |
704 | "network"); | |
705 | continue; | |
706 | } | |
707 | ||
708 | if (!freq_allowed(ssid->freq_list, bss->freq)) { | |
709 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not " | |
710 | "allowed"); | |
711 | continue; | |
712 | } | |
713 | ||
714 | if (!rate_match(wpa_s, bss)) { | |
715 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do " | |
716 | "not match"); | |
717 | continue; | |
718 | } | |
719 | ||
720 | #ifdef CONFIG_P2P | |
721 | /* | |
722 | * TODO: skip the AP if its P2P IE has Group Formation | |
723 | * bit set in the P2P Group Capability Bitmap and we | |
724 | * are not in Group Formation with that device. | |
725 | */ | |
726 | #endif /* CONFIG_P2P */ | |
727 | ||
728 | /* Matching configuration found */ | |
729 | return ssid; | |
730 | } | |
731 | ||
732 | /* No matching configuration found */ | |
733 | return NULL; | |
734 | } | |
735 | ||
736 | ||
737 | static struct wpa_bss * | |
738 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, | |
739 | struct wpa_scan_results *scan_res, | |
740 | struct wpa_ssid *group, | |
741 | struct wpa_ssid **selected_ssid) | |
742 | { | |
743 | size_t i; | |
744 | ||
745 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", | |
746 | group->priority); | |
747 | ||
748 | for (i = 0; i < scan_res->num; i++) { | |
749 | struct wpa_scan_res *bss = scan_res->res[i]; | |
750 | const u8 *ie, *ssid; | |
751 | u8 ssid_len; | |
752 | ||
753 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group); | |
754 | if (!*selected_ssid) | |
755 | continue; | |
756 | ||
757 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); | |
758 | ssid = ie ? ie + 2 : (u8 *) ""; | |
759 | ssid_len = ie ? ie[1] : 0; | |
760 | ||
761 | wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR | |
762 | " ssid='%s'", | |
763 | MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len)); | |
764 | return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len); | |
765 | } | |
766 | ||
767 | return NULL; | |
768 | } | |
769 | ||
770 | ||
771 | static struct wpa_bss * | |
772 | wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, | |
773 | struct wpa_scan_results *scan_res, | |
774 | struct wpa_ssid **selected_ssid) | |
775 | { | |
776 | struct wpa_bss *selected = NULL; | |
777 | int prio; | |
778 | ||
779 | while (selected == NULL) { | |
780 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
781 | selected = wpa_supplicant_select_bss( | |
782 | wpa_s, scan_res, wpa_s->conf->pssid[prio], | |
783 | selected_ssid); | |
784 | if (selected) | |
785 | break; | |
786 | } | |
787 | ||
788 | if (selected == NULL && wpa_s->blacklist && | |
789 | !wpa_s->countermeasures) { | |
790 | wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear " | |
791 | "blacklist and try again"); | |
792 | wpa_blacklist_clear(wpa_s); | |
793 | wpa_s->blacklist_cleared++; | |
794 | } else if (selected == NULL) | |
795 | break; | |
796 | } | |
797 | ||
798 | return selected; | |
799 | } | |
800 | ||
801 | ||
802 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, | |
803 | int timeout_sec, int timeout_usec) | |
804 | { | |
805 | if (!wpa_supplicant_enabled_networks(wpa_s->conf)) { | |
806 | /* | |
807 | * No networks are enabled; short-circuit request so | |
808 | * we don't wait timeout seconds before transitioning | |
809 | * to INACTIVE state. | |
810 | */ | |
811 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
812 | return; | |
813 | } | |
814 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); | |
815 | } | |
816 | ||
817 | ||
818 | int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, | |
819 | struct wpa_bss *selected, | |
820 | struct wpa_ssid *ssid) | |
821 | { | |
822 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { | |
823 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP | |
824 | "PBC session overlap"); | |
825 | #ifdef CONFIG_P2P | |
826 | if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1) | |
827 | return -1; | |
828 | #endif /* CONFIG_P2P */ | |
829 | ||
830 | #ifdef CONFIG_WPS | |
831 | wpas_wps_cancel(wpa_s); | |
832 | #endif /* CONFIG_WPS */ | |
833 | return -1; | |
834 | } | |
835 | ||
836 | /* | |
837 | * Do not trigger new association unless the BSSID has changed or if | |
838 | * reassociation is requested. If we are in process of associating with | |
839 | * the selected BSSID, do not trigger new attempt. | |
840 | */ | |
841 | if (wpa_s->reassociate || | |
842 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && | |
843 | ((wpa_s->wpa_state != WPA_ASSOCIATING && | |
844 | wpa_s->wpa_state != WPA_AUTHENTICATING) || | |
845 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != | |
846 | 0))) { | |
847 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { | |
848 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); | |
849 | return 0; | |
850 | } | |
851 | wpa_msg(wpa_s, MSG_DEBUG, "Request association: " | |
852 | "reassociate: %d selected: "MACSTR " bssid: " MACSTR | |
853 | " pending: " MACSTR " wpa_state: %s", | |
854 | wpa_s->reassociate, MAC2STR(selected->bssid), | |
855 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), | |
856 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
857 | wpa_supplicant_associate(wpa_s, selected, ssid); | |
858 | } else { | |
859 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the " | |
860 | "selected AP"); | |
861 | } | |
862 | ||
863 | return 0; | |
864 | } | |
865 | ||
866 | ||
867 | static struct wpa_ssid * | |
868 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) | |
869 | { | |
870 | int prio; | |
871 | struct wpa_ssid *ssid; | |
872 | ||
873 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
874 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) | |
875 | { | |
876 | if (ssid->disabled) | |
877 | continue; | |
878 | if (ssid->mode == IEEE80211_MODE_IBSS || | |
879 | ssid->mode == IEEE80211_MODE_AP) | |
880 | return ssid; | |
881 | } | |
882 | } | |
883 | return NULL; | |
884 | } | |
885 | ||
886 | ||
887 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based | |
888 | * on BSS added and BSS changed events */ | |
889 | static void wpa_supplicant_rsn_preauth_scan_results( | |
890 | struct wpa_supplicant *wpa_s) | |
891 | { | |
892 | struct wpa_bss *bss; | |
893 | ||
894 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) | |
895 | return; | |
896 | ||
897 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { | |
898 | const u8 *ssid, *rsn; | |
899 | ||
900 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); | |
901 | if (ssid == NULL) | |
902 | continue; | |
903 | ||
904 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); | |
905 | if (rsn == NULL) | |
906 | continue; | |
907 | ||
908 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); | |
909 | } | |
910 | ||
911 | } | |
912 | ||
913 | ||
914 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, | |
915 | struct wpa_bss *selected, | |
916 | struct wpa_ssid *ssid, | |
917 | struct wpa_scan_results *scan_res) | |
918 | { | |
919 | size_t i; | |
920 | struct wpa_scan_res *current_bss = NULL; | |
921 | int min_diff; | |
922 | ||
923 | if (wpa_s->reassociate) | |
924 | return 1; /* explicit request to reassociate */ | |
925 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
926 | return 1; /* we are not associated; continue */ | |
927 | if (wpa_s->current_ssid == NULL) | |
928 | return 1; /* unknown current SSID */ | |
929 | if (wpa_s->current_ssid != ssid) | |
930 | return 1; /* different network block */ | |
931 | ||
932 | if (wpas_driver_bss_selection(wpa_s)) | |
933 | return 0; /* Driver-based roaming */ | |
934 | ||
935 | for (i = 0; i < scan_res->num; i++) { | |
936 | struct wpa_scan_res *res = scan_res->res[i]; | |
937 | const u8 *ie; | |
938 | if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0) | |
939 | continue; | |
940 | ||
941 | ie = wpa_scan_get_ie(res, WLAN_EID_SSID); | |
942 | if (ie == NULL) | |
943 | continue; | |
944 | if (ie[1] != wpa_s->current_ssid->ssid_len || | |
945 | os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0) | |
946 | continue; | |
947 | current_bss = res; | |
948 | break; | |
949 | } | |
950 | ||
951 | if (!current_bss) | |
952 | return 1; /* current BSS not seen in scan results */ | |
953 | ||
954 | #ifndef CONFIG_NO_ROAMING | |
955 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); | |
956 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d", | |
957 | MAC2STR(current_bss->bssid), current_bss->level); | |
958 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d", | |
959 | MAC2STR(selected->bssid), selected->level); | |
960 | ||
961 | if (wpa_s->current_ssid->bssid_set && | |
962 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == | |
963 | 0) { | |
964 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " | |
965 | "has preferred BSSID"); | |
966 | return 1; | |
967 | } | |
968 | ||
969 | min_diff = 2; | |
970 | if (current_bss->level < 0) { | |
971 | if (current_bss->level < -85) | |
972 | min_diff = 1; | |
973 | else if (current_bss->level < -80) | |
974 | min_diff = 2; | |
975 | else if (current_bss->level < -75) | |
976 | min_diff = 3; | |
977 | else if (current_bss->level < -70) | |
978 | min_diff = 4; | |
979 | else | |
980 | min_diff = 5; | |
981 | } | |
982 | if (abs(current_bss->level - selected->level) < min_diff) { | |
983 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference " | |
984 | "in signal level"); | |
985 | return 0; | |
986 | } | |
987 | ||
988 | return 1; | |
989 | #else /* CONFIG_NO_ROAMING */ | |
990 | return 0; | |
991 | #endif /* CONFIG_NO_ROAMING */ | |
992 | } | |
993 | ||
994 | ||
995 | /* Return < 0 if no scan results could be fetched. */ | |
996 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, | |
997 | union wpa_event_data *data) | |
998 | { | |
999 | struct wpa_bss *selected; | |
1000 | struct wpa_ssid *ssid = NULL; | |
1001 | struct wpa_scan_results *scan_res; | |
1002 | int ap = 0; | |
1003 | ||
1004 | #ifdef CONFIG_AP | |
1005 | if (wpa_s->ap_iface) | |
1006 | ap = 1; | |
1007 | #endif /* CONFIG_AP */ | |
1008 | ||
1009 | wpa_supplicant_notify_scanning(wpa_s, 0); | |
1010 | ||
1011 | #ifdef CONFIG_P2P | |
1012 | if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled && | |
1013 | wpa_s->global->p2p != NULL) { | |
1014 | wpa_s->p2p_cb_on_scan_complete = 0; | |
1015 | if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) { | |
1016 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation " | |
1017 | "stopped scan processing"); | |
1018 | return -1; | |
1019 | } | |
1020 | } | |
1021 | #endif /* CONFIG_P2P */ | |
1022 | ||
1023 | scan_res = wpa_supplicant_get_scan_results(wpa_s, | |
1024 | data ? &data->scan_info : | |
1025 | NULL, 1); | |
1026 | if (scan_res == NULL) { | |
1027 | if (wpa_s->conf->ap_scan == 2 || ap) | |
1028 | return -1; | |
1029 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " | |
1030 | "scanning again"); | |
1031 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); | |
1032 | return -1; | |
1033 | } | |
1034 | ||
1035 | #ifndef CONFIG_NO_RANDOM_POOL | |
1036 | size_t i, num; | |
1037 | num = scan_res->num; | |
1038 | if (num > 10) | |
1039 | num = 10; | |
1040 | for (i = 0; i < num; i++) { | |
1041 | u8 buf[5]; | |
1042 | struct wpa_scan_res *res = scan_res->res[i]; | |
1043 | buf[0] = res->bssid[5]; | |
1044 | buf[1] = res->qual & 0xff; | |
1045 | buf[2] = res->noise & 0xff; | |
1046 | buf[3] = res->level & 0xff; | |
1047 | buf[4] = res->tsf & 0xff; | |
1048 | random_add_randomness(buf, sizeof(buf)); | |
1049 | } | |
1050 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
1051 | ||
1052 | if (wpa_s->scan_res_handler) { | |
1053 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, | |
1054 | struct wpa_scan_results *scan_res); | |
1055 | ||
1056 | scan_res_handler = wpa_s->scan_res_handler; | |
1057 | wpa_s->scan_res_handler = NULL; | |
1058 | scan_res_handler(wpa_s, scan_res); | |
1059 | ||
1060 | wpa_scan_results_free(scan_res); | |
1061 | return 0; | |
1062 | } | |
1063 | ||
1064 | if (ap) { | |
1065 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); | |
1066 | #ifdef CONFIG_AP | |
1067 | if (wpa_s->ap_iface->scan_cb) | |
1068 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); | |
1069 | #endif /* CONFIG_AP */ | |
1070 | wpa_scan_results_free(scan_res); | |
1071 | return 0; | |
1072 | } | |
1073 | ||
1074 | wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); | |
1075 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); | |
1076 | wpas_notify_scan_results(wpa_s); | |
1077 | ||
1078 | wpas_notify_scan_done(wpa_s, 1); | |
1079 | ||
1080 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) { | |
1081 | wpa_scan_results_free(scan_res); | |
1082 | return 0; | |
1083 | } | |
1084 | ||
1085 | if (wpa_s->disconnected) { | |
1086 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
1087 | wpa_scan_results_free(scan_res); | |
1088 | return 0; | |
1089 | } | |
1090 | ||
1091 | if (!wpas_driver_bss_selection(wpa_s) && | |
1092 | bgscan_notify_scan(wpa_s, scan_res) == 1) { | |
1093 | wpa_scan_results_free(scan_res); | |
1094 | return 0; | |
1095 | } | |
1096 | ||
1097 | selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid); | |
1098 | ||
1099 | if (selected) { | |
1100 | int skip; | |
1101 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid, | |
1102 | scan_res); | |
1103 | wpa_scan_results_free(scan_res); | |
1104 | if (skip) { | |
1105 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
1106 | return 0; | |
1107 | } | |
1108 | ||
1109 | if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { | |
1110 | wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); | |
1111 | return -1; | |
1112 | } | |
1113 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
1114 | } else { | |
1115 | wpa_scan_results_free(scan_res); | |
1116 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); | |
1117 | ssid = wpa_supplicant_pick_new_network(wpa_s); | |
1118 | if (ssid) { | |
1119 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); | |
1120 | wpa_supplicant_associate(wpa_s, NULL, ssid); | |
1121 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
1122 | } else { | |
1123 | int timeout_sec = wpa_s->scan_interval; | |
1124 | int timeout_usec = 0; | |
1125 | #ifdef CONFIG_P2P | |
1126 | if (wpa_s->p2p_in_provisioning) { | |
1127 | /* | |
1128 | * Use shorter wait during P2P Provisioning | |
1129 | * state to speed up group formation. | |
1130 | */ | |
1131 | timeout_sec = 0; | |
1132 | timeout_usec = 250000; | |
1133 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
1134 | timeout_usec); | |
1135 | return 0; | |
1136 | } | |
1137 | #endif /* CONFIG_P2P */ | |
1138 | if (wpa_supplicant_req_sched_scan(wpa_s)) | |
1139 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
1140 | timeout_usec); | |
1141 | } | |
1142 | } | |
1143 | return 0; | |
1144 | } | |
1145 | ||
1146 | ||
1147 | static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, | |
1148 | union wpa_event_data *data) | |
1149 | { | |
1150 | const char *rn, *rn2; | |
1151 | struct wpa_supplicant *ifs; | |
1152 | ||
1153 | if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) { | |
1154 | /* | |
1155 | * If no scan results could be fetched, then no need to | |
1156 | * notify those interfaces that did not actually request | |
1157 | * this scan. | |
1158 | */ | |
1159 | return; | |
1160 | } | |
1161 | ||
1162 | /* | |
1163 | * Check other interfaces to see if they have the same radio-name. If | |
1164 | * so, they get updated with this same scan info. | |
1165 | */ | |
1166 | if (!wpa_s->driver->get_radio_name) | |
1167 | return; | |
1168 | ||
1169 | rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv); | |
1170 | if (rn == NULL || rn[0] == '\0') | |
1171 | return; | |
1172 | ||
1173 | wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces " | |
1174 | "sharing same radio (%s) in event_scan_results", rn); | |
1175 | ||
1176 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { | |
1177 | if (ifs == wpa_s || !ifs->driver->get_radio_name) | |
1178 | continue; | |
1179 | ||
1180 | rn2 = ifs->driver->get_radio_name(ifs->drv_priv); | |
1181 | if (rn2 && os_strcmp(rn, rn2) == 0) { | |
1182 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " | |
1183 | "sibling", ifs->ifname); | |
1184 | _wpa_supplicant_event_scan_results(ifs, data); | |
1185 | } | |
1186 | } | |
1187 | } | |
1188 | ||
1189 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
1190 | ||
1191 | ||
1192 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, | |
1193 | union wpa_event_data *data) | |
1194 | { | |
1195 | int l, len, found = 0, wpa_found, rsn_found; | |
1196 | const u8 *p; | |
1197 | ||
1198 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); | |
1199 | if (data->assoc_info.req_ies) | |
1200 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, | |
1201 | data->assoc_info.req_ies_len); | |
1202 | if (data->assoc_info.resp_ies) { | |
1203 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, | |
1204 | data->assoc_info.resp_ies_len); | |
1205 | #ifdef CONFIG_TDLS | |
1206 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, | |
1207 | data->assoc_info.resp_ies_len); | |
1208 | #endif /* CONFIG_TDLS */ | |
1209 | } | |
1210 | if (data->assoc_info.beacon_ies) | |
1211 | wpa_hexdump(MSG_DEBUG, "beacon_ies", | |
1212 | data->assoc_info.beacon_ies, | |
1213 | data->assoc_info.beacon_ies_len); | |
1214 | if (data->assoc_info.freq) | |
1215 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", | |
1216 | data->assoc_info.freq); | |
1217 | ||
1218 | p = data->assoc_info.req_ies; | |
1219 | l = data->assoc_info.req_ies_len; | |
1220 | ||
1221 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ | |
1222 | while (p && l >= 2) { | |
1223 | len = p[1] + 2; | |
1224 | if (len > l) { | |
1225 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1226 | p, l); | |
1227 | break; | |
1228 | } | |
1229 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1230 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || | |
1231 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { | |
1232 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) | |
1233 | break; | |
1234 | found = 1; | |
1235 | wpa_find_assoc_pmkid(wpa_s); | |
1236 | break; | |
1237 | } | |
1238 | l -= len; | |
1239 | p += len; | |
1240 | } | |
1241 | if (!found && data->assoc_info.req_ies) | |
1242 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
1243 | ||
1244 | #ifdef CONFIG_IEEE80211R | |
1245 | #ifdef CONFIG_SME | |
1246 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { | |
1247 | u8 bssid[ETH_ALEN]; | |
1248 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || | |
1249 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
1250 | data->assoc_info.resp_ies, | |
1251 | data->assoc_info.resp_ies_len, | |
1252 | bssid) < 0) { | |
1253 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " | |
1254 | "Reassociation Response failed"); | |
1255 | wpa_supplicant_deauthenticate( | |
1256 | wpa_s, WLAN_REASON_INVALID_IE); | |
1257 | return -1; | |
1258 | } | |
1259 | } | |
1260 | ||
1261 | p = data->assoc_info.resp_ies; | |
1262 | l = data->assoc_info.resp_ies_len; | |
1263 | ||
1264 | #ifdef CONFIG_WPS_STRICT | |
1265 | if (p && wpa_s->current_ssid && | |
1266 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { | |
1267 | struct wpabuf *wps; | |
1268 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); | |
1269 | if (wps == NULL) { | |
1270 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " | |
1271 | "include WPS IE in (Re)Association Response"); | |
1272 | return -1; | |
1273 | } | |
1274 | ||
1275 | if (wps_validate_assoc_resp(wps) < 0) { | |
1276 | wpabuf_free(wps); | |
1277 | wpa_supplicant_deauthenticate( | |
1278 | wpa_s, WLAN_REASON_INVALID_IE); | |
1279 | return -1; | |
1280 | } | |
1281 | wpabuf_free(wps); | |
1282 | } | |
1283 | #endif /* CONFIG_WPS_STRICT */ | |
1284 | ||
1285 | /* Go through the IEs and make a copy of the MDIE, if present. */ | |
1286 | while (p && l >= 2) { | |
1287 | len = p[1] + 2; | |
1288 | if (len > l) { | |
1289 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1290 | p, l); | |
1291 | break; | |
1292 | } | |
1293 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && | |
1294 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
1295 | wpa_s->sme.ft_used = 1; | |
1296 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, | |
1297 | MOBILITY_DOMAIN_ID_LEN); | |
1298 | break; | |
1299 | } | |
1300 | l -= len; | |
1301 | p += len; | |
1302 | } | |
1303 | #endif /* CONFIG_SME */ | |
1304 | ||
1305 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, | |
1306 | data->assoc_info.resp_ies_len); | |
1307 | #endif /* CONFIG_IEEE80211R */ | |
1308 | ||
1309 | /* WPA/RSN IE from Beacon/ProbeResp */ | |
1310 | p = data->assoc_info.beacon_ies; | |
1311 | l = data->assoc_info.beacon_ies_len; | |
1312 | ||
1313 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. | |
1314 | */ | |
1315 | wpa_found = rsn_found = 0; | |
1316 | while (p && l >= 2) { | |
1317 | len = p[1] + 2; | |
1318 | if (len > l) { | |
1319 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", | |
1320 | p, l); | |
1321 | break; | |
1322 | } | |
1323 | if (!wpa_found && | |
1324 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1325 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { | |
1326 | wpa_found = 1; | |
1327 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); | |
1328 | } | |
1329 | ||
1330 | if (!rsn_found && | |
1331 | p[0] == WLAN_EID_RSN && p[1] >= 2) { | |
1332 | rsn_found = 1; | |
1333 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); | |
1334 | } | |
1335 | ||
1336 | l -= len; | |
1337 | p += len; | |
1338 | } | |
1339 | ||
1340 | if (!wpa_found && data->assoc_info.beacon_ies) | |
1341 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
1342 | if (!rsn_found && data->assoc_info.beacon_ies) | |
1343 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
1344 | if (wpa_found || rsn_found) | |
1345 | wpa_s->ap_ies_from_associnfo = 1; | |
1346 | ||
1347 | if (wpa_s->assoc_freq && data->assoc_info.freq && | |
1348 | wpa_s->assoc_freq != data->assoc_info.freq) { | |
1349 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " | |
1350 | "%u to %u MHz", | |
1351 | wpa_s->assoc_freq, data->assoc_info.freq); | |
1352 | wpa_supplicant_update_scan_results(wpa_s); | |
1353 | } | |
1354 | ||
1355 | wpa_s->assoc_freq = data->assoc_info.freq; | |
1356 | ||
1357 | return 0; | |
1358 | } | |
1359 | ||
1360 | ||
1361 | static struct wpa_bss * wpa_supplicant_get_new_bss( | |
1362 | struct wpa_supplicant *wpa_s, const u8 *bssid) | |
1363 | { | |
1364 | struct wpa_bss *bss = NULL; | |
1365 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1366 | ||
1367 | if (ssid->ssid_len > 0) | |
1368 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | |
1369 | if (!bss) | |
1370 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
1371 | ||
1372 | return bss; | |
1373 | } | |
1374 | ||
1375 | ||
1376 | static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) | |
1377 | { | |
1378 | const u8 *bss_wpa = NULL, *bss_rsn = NULL; | |
1379 | ||
1380 | if (!wpa_s->current_bss || !wpa_s->current_ssid) | |
1381 | return -1; | |
1382 | ||
1383 | if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) | |
1384 | return 0; | |
1385 | ||
1386 | bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, | |
1387 | WPA_IE_VENDOR_TYPE); | |
1388 | bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN); | |
1389 | ||
1390 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, | |
1391 | bss_wpa ? 2 + bss_wpa[1] : 0) || | |
1392 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, | |
1393 | bss_rsn ? 2 + bss_rsn[1] : 0)) | |
1394 | return -1; | |
1395 | ||
1396 | return 0; | |
1397 | } | |
1398 | ||
1399 | ||
1400 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, | |
1401 | union wpa_event_data *data) | |
1402 | { | |
1403 | u8 bssid[ETH_ALEN]; | |
1404 | int ft_completed; | |
1405 | int bssid_changed; | |
1406 | struct wpa_driver_capa capa; | |
1407 | ||
1408 | #ifdef CONFIG_AP | |
1409 | if (wpa_s->ap_iface) { | |
1410 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], | |
1411 | data->assoc_info.addr, | |
1412 | data->assoc_info.req_ies, | |
1413 | data->assoc_info.req_ies_len, | |
1414 | data->assoc_info.reassoc); | |
1415 | return; | |
1416 | } | |
1417 | #endif /* CONFIG_AP */ | |
1418 | ||
1419 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); | |
1420 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) | |
1421 | return; | |
1422 | ||
1423 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); | |
1424 | if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 && | |
1425 | os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { | |
1426 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" | |
1427 | MACSTR, MAC2STR(bssid)); | |
1428 | random_add_randomness(bssid, ETH_ALEN); | |
1429 | bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN); | |
1430 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); | |
1431 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
1432 | if (bssid_changed) | |
1433 | wpas_notify_bssid_changed(wpa_s); | |
1434 | ||
1435 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { | |
1436 | wpa_clear_keys(wpa_s, bssid); | |
1437 | } | |
1438 | if (wpa_supplicant_select_config(wpa_s) < 0) { | |
1439 | wpa_supplicant_disassociate( | |
1440 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1441 | return; | |
1442 | } | |
1443 | if (wpa_s->current_ssid) { | |
1444 | struct wpa_bss *bss = NULL; | |
1445 | ||
1446 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); | |
1447 | if (!bss) { | |
1448 | wpa_supplicant_update_scan_results(wpa_s); | |
1449 | ||
1450 | /* Get the BSS from the new scan results */ | |
1451 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); | |
1452 | } | |
1453 | ||
1454 | if (bss) | |
1455 | wpa_s->current_bss = bss; | |
1456 | } | |
1457 | ||
1458 | if (wpa_s->conf->ap_scan == 1 && | |
1459 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { | |
1460 | if (wpa_supplicant_assoc_update_ie(wpa_s) < 0) | |
1461 | wpa_msg(wpa_s, MSG_WARNING, | |
1462 | "WPA/RSN IEs not updated"); | |
1463 | } | |
1464 | } | |
1465 | ||
1466 | #ifdef CONFIG_SME | |
1467 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); | |
1468 | wpa_s->sme.prev_bssid_set = 1; | |
1469 | #endif /* CONFIG_SME */ | |
1470 | ||
1471 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); | |
1472 | if (wpa_s->current_ssid) { | |
1473 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be | |
1474 | * initialized before association, but for other modes, | |
1475 | * initialize PC/SC here, if the current configuration needs | |
1476 | * smartcard or SIM/USIM. */ | |
1477 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); | |
1478 | } | |
1479 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); | |
1480 | if (wpa_s->l2) | |
1481 | l2_packet_notify_auth_start(wpa_s->l2); | |
1482 | ||
1483 | /* | |
1484 | * Set portEnabled first to FALSE in order to get EAP state machine out | |
1485 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE | |
1486 | * state machine may transit to AUTHENTICATING state based on obsolete | |
1487 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to | |
1488 | * AUTHENTICATED without ever giving chance to EAP state machine to | |
1489 | * reset the state. | |
1490 | */ | |
1491 | if (!ft_completed) { | |
1492 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
1493 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
1494 | } | |
1495 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) | |
1496 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); | |
1497 | /* 802.1X::portControl = Auto */ | |
1498 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); | |
1499 | wpa_s->eapol_received = 0; | |
1500 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
1501 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || | |
1502 | (wpa_s->current_ssid && | |
1503 | wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { | |
1504 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1505 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1506 | } else if (!ft_completed) { | |
1507 | /* Timeout for receiving the first EAPOL packet */ | |
1508 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); | |
1509 | } | |
1510 | wpa_supplicant_cancel_scan(wpa_s); | |
1511 | ||
1512 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && | |
1513 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { | |
1514 | /* | |
1515 | * We are done; the driver will take care of RSN 4-way | |
1516 | * handshake. | |
1517 | */ | |
1518 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1519 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1520 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1521 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
1522 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && | |
1523 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
1524 | /* | |
1525 | * The driver will take care of RSN 4-way handshake, so we need | |
1526 | * to allow EAPOL supplicant to complete its work without | |
1527 | * waiting for WPA supplicant. | |
1528 | */ | |
1529 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1530 | } else if (ft_completed) { | |
1531 | /* | |
1532 | * FT protocol completed - make sure EAPOL state machine ends | |
1533 | * up in authenticated. | |
1534 | */ | |
1535 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1536 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1537 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1538 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
1539 | } | |
1540 | ||
1541 | if (wpa_s->pending_eapol_rx) { | |
1542 | struct os_time now, age; | |
1543 | os_get_time(&now); | |
1544 | os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age); | |
1545 | if (age.sec == 0 && age.usec < 100000 && | |
1546 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == | |
1547 | 0) { | |
1548 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " | |
1549 | "frame that was received just before " | |
1550 | "association notification"); | |
1551 | wpa_supplicant_rx_eapol( | |
1552 | wpa_s, wpa_s->pending_eapol_rx_src, | |
1553 | wpabuf_head(wpa_s->pending_eapol_rx), | |
1554 | wpabuf_len(wpa_s->pending_eapol_rx)); | |
1555 | } | |
1556 | wpabuf_free(wpa_s->pending_eapol_rx); | |
1557 | wpa_s->pending_eapol_rx = NULL; | |
1558 | } | |
1559 | ||
1560 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
1561 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
1562 | wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 && | |
1563 | capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) { | |
1564 | /* Set static WEP keys again */ | |
1565 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); | |
1566 | } | |
1567 | ||
1568 | #ifdef CONFIG_IBSS_RSN | |
1569 | if (wpa_s->current_ssid && | |
1570 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
1571 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && | |
1572 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && | |
1573 | wpa_s->ibss_rsn == NULL) { | |
1574 | wpa_s->ibss_rsn = ibss_rsn_init(wpa_s); | |
1575 | if (!wpa_s->ibss_rsn) { | |
1576 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); | |
1577 | wpa_supplicant_deauthenticate( | |
1578 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1579 | return; | |
1580 | } | |
1581 | ||
1582 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); | |
1583 | } | |
1584 | #endif /* CONFIG_IBSS_RSN */ | |
1585 | } | |
1586 | ||
1587 | ||
1588 | static int disconnect_reason_recoverable(u16 reason_code) | |
1589 | { | |
1590 | return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || | |
1591 | reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || | |
1592 | reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; | |
1593 | } | |
1594 | ||
1595 | ||
1596 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, | |
1597 | u16 reason_code, | |
1598 | int locally_generated) | |
1599 | { | |
1600 | const u8 *bssid; | |
1601 | int authenticating; | |
1602 | u8 prev_pending_bssid[ETH_ALEN]; | |
1603 | struct wpa_bss *fast_reconnect = NULL; | |
1604 | struct wpa_ssid *fast_reconnect_ssid = NULL; | |
1605 | ||
1606 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; | |
1607 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); | |
1608 | ||
1609 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
1610 | /* | |
1611 | * At least Host AP driver and a Prism3 card seemed to be | |
1612 | * generating streams of disconnected events when configuring | |
1613 | * IBSS for WPA-None. Ignore them for now. | |
1614 | */ | |
1615 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " | |
1616 | "IBSS/WPA-None mode"); | |
1617 | return; | |
1618 | } | |
1619 | ||
1620 | if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE && | |
1621 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { | |
1622 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " | |
1623 | "pre-shared key may be incorrect"); | |
1624 | } | |
1625 | if (!wpa_s->auto_reconnect_disabled || | |
1626 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { | |
1627 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " | |
1628 | "reconnect (wps=%d wpa_state=%d)", | |
1629 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, | |
1630 | wpa_s->wpa_state); | |
1631 | if (wpa_s->wpa_state == WPA_COMPLETED && | |
1632 | wpa_s->current_ssid && | |
1633 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && | |
1634 | !locally_generated && | |
1635 | disconnect_reason_recoverable(reason_code)) { | |
1636 | /* | |
1637 | * It looks like the AP has dropped association with | |
1638 | * us, but could allow us to get back in. Try to | |
1639 | * reconnect to the same BSS without full scan to save | |
1640 | * time for some common cases. | |
1641 | */ | |
1642 | fast_reconnect = wpa_s->current_bss; | |
1643 | fast_reconnect_ssid = wpa_s->current_ssid; | |
1644 | } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) | |
1645 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
1646 | else | |
1647 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " | |
1648 | "immediate scan"); | |
1649 | } else { | |
1650 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " | |
1651 | "try to re-connect"); | |
1652 | wpa_s->reassociate = 0; | |
1653 | wpa_s->disconnected = 1; | |
1654 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
1655 | } | |
1656 | bssid = wpa_s->bssid; | |
1657 | if (is_zero_ether_addr(bssid)) | |
1658 | bssid = wpa_s->pending_bssid; | |
1659 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) | |
1660 | wpas_connection_failed(wpa_s, bssid); | |
1661 | wpa_sm_notify_disassoc(wpa_s->wpa); | |
1662 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR | |
1663 | " reason=%d", | |
1664 | MAC2STR(bssid), reason_code); | |
1665 | if (wpa_supplicant_dynamic_keys(wpa_s)) { | |
1666 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); | |
1667 | wpa_s->keys_cleared = 0; | |
1668 | wpa_clear_keys(wpa_s, wpa_s->bssid); | |
1669 | } | |
1670 | wpa_supplicant_mark_disassoc(wpa_s); | |
1671 | ||
1672 | if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
1673 | sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); | |
1674 | ||
1675 | if (fast_reconnect) { | |
1676 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
1677 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); | |
1678 | if (wpa_supplicant_connect(wpa_s, fast_reconnect, | |
1679 | fast_reconnect_ssid) < 0) { | |
1680 | /* Recover through full scan */ | |
1681 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
1682 | } | |
1683 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
1684 | } | |
1685 | } | |
1686 | ||
1687 | ||
1688 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
1689 | void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx) | |
1690 | { | |
1691 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1692 | ||
1693 | if (!wpa_s->pending_mic_error_report) | |
1694 | return; | |
1695 | ||
1696 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); | |
1697 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); | |
1698 | wpa_s->pending_mic_error_report = 0; | |
1699 | } | |
1700 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1701 | ||
1702 | ||
1703 | static void | |
1704 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, | |
1705 | union wpa_event_data *data) | |
1706 | { | |
1707 | int pairwise; | |
1708 | struct os_time t; | |
1709 | ||
1710 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); | |
1711 | pairwise = (data && data->michael_mic_failure.unicast); | |
1712 | os_get_time(&t); | |
1713 | if ((wpa_s->last_michael_mic_error && | |
1714 | t.sec - wpa_s->last_michael_mic_error <= 60) || | |
1715 | wpa_s->pending_mic_error_report) { | |
1716 | if (wpa_s->pending_mic_error_report) { | |
1717 | /* | |
1718 | * Send the pending MIC error report immediately since | |
1719 | * we are going to start countermeasures and AP better | |
1720 | * do the same. | |
1721 | */ | |
1722 | wpa_sm_key_request(wpa_s->wpa, 1, | |
1723 | wpa_s->pending_mic_error_pairwise); | |
1724 | } | |
1725 | ||
1726 | /* Send the new MIC error report immediately since we are going | |
1727 | * to start countermeasures and AP better do the same. | |
1728 | */ | |
1729 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1730 | ||
1731 | /* initialize countermeasures */ | |
1732 | wpa_s->countermeasures = 1; | |
1733 | ||
1734 | wpa_blacklist_add(wpa_s, wpa_s->bssid); | |
1735 | ||
1736 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); | |
1737 | ||
1738 | /* | |
1739 | * Need to wait for completion of request frame. We do not get | |
1740 | * any callback for the message completion, so just wait a | |
1741 | * short while and hope for the best. */ | |
1742 | os_sleep(0, 10000); | |
1743 | ||
1744 | wpa_drv_set_countermeasures(wpa_s, 1); | |
1745 | wpa_supplicant_deauthenticate(wpa_s, | |
1746 | WLAN_REASON_MICHAEL_MIC_FAILURE); | |
1747 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, | |
1748 | wpa_s, NULL); | |
1749 | eloop_register_timeout(60, 0, | |
1750 | wpa_supplicant_stop_countermeasures, | |
1751 | wpa_s, NULL); | |
1752 | /* TODO: mark the AP rejected for 60 second. STA is | |
1753 | * allowed to associate with another AP.. */ | |
1754 | } else { | |
1755 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
1756 | if (wpa_s->mic_errors_seen) { | |
1757 | /* | |
1758 | * Reduce the effectiveness of Michael MIC error | |
1759 | * reports as a means for attacking against TKIP if | |
1760 | * more than one MIC failure is noticed with the same | |
1761 | * PTK. We delay the transmission of the reports by a | |
1762 | * random time between 0 and 60 seconds in order to | |
1763 | * force the attacker wait 60 seconds before getting | |
1764 | * the information on whether a frame resulted in a MIC | |
1765 | * failure. | |
1766 | */ | |
1767 | u8 rval[4]; | |
1768 | int sec; | |
1769 | ||
1770 | if (os_get_random(rval, sizeof(rval)) < 0) | |
1771 | sec = os_random() % 60; | |
1772 | else | |
1773 | sec = WPA_GET_BE32(rval) % 60; | |
1774 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " | |
1775 | "report %d seconds", sec); | |
1776 | wpa_s->pending_mic_error_report = 1; | |
1777 | wpa_s->pending_mic_error_pairwise = pairwise; | |
1778 | eloop_cancel_timeout( | |
1779 | wpa_supplicant_delayed_mic_error_report, | |
1780 | wpa_s, NULL); | |
1781 | eloop_register_timeout( | |
1782 | sec, os_random() % 1000000, | |
1783 | wpa_supplicant_delayed_mic_error_report, | |
1784 | wpa_s, NULL); | |
1785 | } else { | |
1786 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1787 | } | |
1788 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1789 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1790 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1791 | } | |
1792 | wpa_s->last_michael_mic_error = t.sec; | |
1793 | wpa_s->mic_errors_seen++; | |
1794 | } | |
1795 | ||
1796 | ||
1797 | #ifdef CONFIG_TERMINATE_ONLASTIF | |
1798 | static int any_interfaces(struct wpa_supplicant *head) | |
1799 | { | |
1800 | struct wpa_supplicant *wpa_s; | |
1801 | ||
1802 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) | |
1803 | if (!wpa_s->interface_removed) | |
1804 | return 1; | |
1805 | return 0; | |
1806 | } | |
1807 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
1808 | ||
1809 | ||
1810 | static void | |
1811 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, | |
1812 | union wpa_event_data *data) | |
1813 | { | |
1814 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) | |
1815 | return; | |
1816 | ||
1817 | switch (data->interface_status.ievent) { | |
1818 | case EVENT_INTERFACE_ADDED: | |
1819 | if (!wpa_s->interface_removed) | |
1820 | break; | |
1821 | wpa_s->interface_removed = 0; | |
1822 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); | |
1823 | if (wpa_supplicant_driver_init(wpa_s) < 0) { | |
1824 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " | |
1825 | "driver after interface was added"); | |
1826 | } | |
1827 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
1828 | break; | |
1829 | case EVENT_INTERFACE_REMOVED: | |
1830 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); | |
1831 | wpa_s->interface_removed = 1; | |
1832 | wpa_supplicant_mark_disassoc(wpa_s); | |
1833 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); | |
1834 | l2_packet_deinit(wpa_s->l2); | |
1835 | wpa_s->l2 = NULL; | |
1836 | #ifdef CONFIG_IBSS_RSN | |
1837 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
1838 | wpa_s->ibss_rsn = NULL; | |
1839 | #endif /* CONFIG_IBSS_RSN */ | |
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 */ | |
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 | ||
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: | |
1873 | wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer, | |
1874 | data->tdls.reason_code); | |
1875 | break; | |
1876 | } | |
1877 | } | |
1878 | #endif /* CONFIG_TDLS */ | |
1879 | ||
1880 | ||
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, | |
1892 | data->ft_ies.target_ap, | |
1893 | data->ft_ies.ric_ies, | |
1894 | data->ft_ies.ric_ies_len) < 0) { | |
1895 | /* TODO: prevent MLME/driver from trying to associate? */ | |
1896 | } | |
1897 | } | |
1898 | #endif /* CONFIG_IEEE80211R */ | |
1899 | ||
1900 | ||
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 | { | |
1905 | struct wpa_ssid *ssid; | |
1906 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
1907 | return; | |
1908 | if (data == NULL) | |
1909 | return; | |
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 | ||
1916 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); | |
1917 | } | |
1918 | #endif /* CONFIG_IBSS_RSN */ | |
1919 | ||
1920 | ||
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); | |
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); | |
1941 | ||
1942 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { | |
1943 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR | |
1944 | " in FT Action Response", MAC2STR(sta_addr)); | |
1945 | return; | |
1946 | } | |
1947 | ||
1948 | if (status) { | |
1949 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " | |
1950 | "failure (status code %d)", status); | |
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 | ||
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; | |
1966 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; | |
1967 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, | |
1968 | WLAN_AUTH_FT); | |
1969 | } | |
1970 | #endif /* CONFIG_SME */ | |
1971 | } | |
1972 | #endif /* CONFIG_IEEE80211R */ | |
1973 | ||
1974 | ||
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 | ||
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 | ||
2045 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, | |
2046 | union wpa_event_data *data) | |
2047 | { | |
2048 | struct wpa_supplicant *wpa_s = ctx; | |
2049 | u16 reason_code = 0; | |
2050 | int locally_generated = 0; | |
2051 | ||
2052 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && | |
2053 | event != EVENT_INTERFACE_ENABLED && | |
2054 | event != EVENT_INTERFACE_STATUS && | |
2055 | event != EVENT_SCHED_SCAN_STOPPED) { | |
2056 | wpa_dbg(wpa_s, MSG_DEBUG, | |
2057 | "Ignore event %s (%d) while interface is disabled", | |
2058 | event_to_string(event), event); | |
2059 | return; | |
2060 | } | |
2061 | ||
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", | |
2078 | event_to_string(event), event); | |
2079 | } | |
2080 | #endif /* CONFIG_NO_STDOUT_DEBUG */ | |
2081 | ||
2082 | switch (event) { | |
2083 | case EVENT_AUTH: | |
2084 | sme_event_auth(wpa_s, data); | |
2085 | break; | |
2086 | case EVENT_ASSOC: | |
2087 | wpa_supplicant_event_assoc(wpa_s, data); | |
2088 | break; | |
2089 | case EVENT_DISASSOC: | |
2090 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); | |
2091 | if (data) { | |
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)" : ""); | |
2096 | if (data->disassoc_info.addr) | |
2097 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, | |
2098 | MAC2STR(data->disassoc_info.addr)); | |
2099 | } | |
2100 | #ifdef CONFIG_AP | |
2101 | if (wpa_s->ap_iface && data && data->disassoc_info.addr) { | |
2102 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], | |
2103 | data->disassoc_info.addr); | |
2104 | break; | |
2105 | } | |
2106 | if (wpa_s->ap_iface) { | |
2107 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in " | |
2108 | "AP mode"); | |
2109 | break; | |
2110 | } | |
2111 | #endif /* CONFIG_AP */ | |
2112 | if (data) { | |
2113 | reason_code = data->disassoc_info.reason_code; | |
2114 | locally_generated = | |
2115 | data->disassoc_info.locally_generated; | |
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 | } | |
2126 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) | |
2127 | sme_event_disassoc(wpa_s, data); | |
2128 | /* fall through */ | |
2129 | case EVENT_DEAUTH: | |
2130 | if (event == EVENT_DEAUTH) { | |
2131 | wpa_dbg(wpa_s, MSG_DEBUG, | |
2132 | "Deauthentication notification"); | |
2133 | if (data) { | |
2134 | reason_code = data->deauth_info.reason_code; | |
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)" : ""); | |
2141 | if (data->deauth_info.addr) { | |
2142 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " | |
2143 | MACSTR, | |
2144 | MAC2STR(data->deauth_info. | |
2145 | addr)); | |
2146 | } | |
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 */ | |
2158 | } | |
2159 | } | |
2160 | #ifdef CONFIG_AP | |
2161 | if (wpa_s->ap_iface && data && data->deauth_info.addr) { | |
2162 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], | |
2163 | data->deauth_info.addr); | |
2164 | break; | |
2165 | } | |
2166 | if (wpa_s->ap_iface) { | |
2167 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in " | |
2168 | "AP mode"); | |
2169 | break; | |
2170 | } | |
2171 | #endif /* CONFIG_AP */ | |
2172 | wpa_supplicant_event_disassoc(wpa_s, reason_code, | |
2173 | locally_generated); | |
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: | |
2180 | wpa_supplicant_event_scan_results(wpa_s, data); | |
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 */ | |
2197 | #ifdef CONFIG_TDLS | |
2198 | case EVENT_TDLS: | |
2199 | wpa_supplicant_event_tdls(wpa_s, data); | |
2200 | break; | |
2201 | #endif /* CONFIG_TDLS */ | |
2202 | #ifdef CONFIG_IEEE80211R | |
2203 | case EVENT_FT_RESPONSE: | |
2204 | wpa_supplicant_event_ft_response(wpa_s, data); | |
2205 | break; | |
2206 | #endif /* CONFIG_IEEE80211R */ | |
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 */ | |
2212 | case EVENT_ASSOC_REJECT: | |
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); | |
2222 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) | |
2223 | sme_event_assoc_reject(wpa_s, data); | |
2224 | break; | |
2225 | case EVENT_AUTH_TIMED_OUT: | |
2226 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) | |
2227 | sme_event_auth_timed_out(wpa_s, data); | |
2228 | break; | |
2229 | case EVENT_ASSOC_TIMED_OUT: | |
2230 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) | |
2231 | sme_event_assoc_timed_out(wpa_s, data); | |
2232 | break; | |
2233 | case EVENT_TX_STATUS: | |
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); | |
2238 | #ifdef CONFIG_AP | |
2239 | if (wpa_s->ap_iface == NULL) { | |
2240 | #ifdef CONFIG_OFFCHANNEL | |
2241 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && | |
2242 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) | |
2243 | offchannel_send_action_tx_status( | |
2244 | wpa_s, data->tx_status.dst, | |
2245 | data->tx_status.data, | |
2246 | data->tx_status.data_len, | |
2247 | data->tx_status.ack ? | |
2248 | OFFCHANNEL_SEND_ACTION_SUCCESS : | |
2249 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
2250 | #endif /* CONFIG_OFFCHANNEL */ | |
2251 | break; | |
2252 | } | |
2253 | #endif /* CONFIG_AP */ | |
2254 | #ifdef CONFIG_OFFCHANNEL | |
2255 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" | |
2256 | MACSTR, MAC2STR(wpa_s->parent->pending_action_dst)); | |
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) { | |
2265 | offchannel_send_action_tx_status( | |
2266 | wpa_s->parent, data->tx_status.dst, | |
2267 | data->tx_status.data, | |
2268 | data->tx_status.data_len, | |
2269 | data->tx_status.ack ? | |
2270 | OFFCHANNEL_SEND_ACTION_SUCCESS : | |
2271 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
2272 | break; | |
2273 | } | |
2274 | #endif /* CONFIG_OFFCHANNEL */ | |
2275 | #ifdef CONFIG_AP | |
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 | } | |
2290 | #endif /* CONFIG_AP */ | |
2291 | break; | |
2292 | #ifdef CONFIG_AP | |
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; | |
2299 | case EVENT_DRIVER_CLIENT_POLL_OK: | |
2300 | ap_client_poll_ok(wpa_s, data->client_poll.addr); | |
2301 | break; | |
2302 | case EVENT_RX_FROM_UNKNOWN: | |
2303 | if (wpa_s->ap_iface == NULL) | |
2304 | break; | |
2305 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, | |
2306 | data->rx_from_unknown.wds); | |
2307 | break; | |
2308 | case EVENT_RX_MGMT: | |
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); | |
2324 | wpas_p2p_probe_req_rx(wpa_s, src, mgmt->da, | |
2325 | mgmt->bssid, ie, ie_len); | |
2326 | break; | |
2327 | } | |
2328 | #endif /* CONFIG_P2P */ | |
2329 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " | |
2330 | "management frame in non-AP mode"); | |
2331 | break; | |
2332 | } | |
2333 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); | |
2334 | break; | |
2335 | #endif /* CONFIG_AP */ | |
2336 | case EVENT_RX_ACTION: | |
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); | |
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 */ | |
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 */ | |
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 */ | |
2367 | if (data->rx_action.category == WLAN_ACTION_WNM) { | |
2368 | wnm_action_rx(wpa_s, &data->rx_action); | |
2369 | break; | |
2370 | } | |
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 */ | |
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); | |
2388 | #endif /* CONFIG_P2P */ | |
2389 | break; | |
2390 | case EVENT_RX_PROBE_REQ: | |
2391 | if (data->rx_probe_req.sa == NULL || | |
2392 | data->rx_probe_req.ie == NULL) | |
2393 | break; | |
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, | |
2398 | data->rx_probe_req.da, | |
2399 | data->rx_probe_req.bssid, | |
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, | |
2407 | data->rx_probe_req.da, | |
2408 | data->rx_probe_req.bssid, | |
2409 | data->rx_probe_req.ie, | |
2410 | data->rx_probe_req.ie_len); | |
2411 | #endif /* CONFIG_P2P */ | |
2412 | break; | |
2413 | case EVENT_REMAIN_ON_CHANNEL: | |
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 | |
2420 | wpas_p2p_remain_on_channel_cb( | |
2421 | wpa_s, data->remain_on_channel.freq, | |
2422 | data->remain_on_channel.duration); | |
2423 | #endif /* CONFIG_P2P */ | |
2424 | break; | |
2425 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: | |
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 | |
2431 | wpas_p2p_cancel_remain_on_channel_cb( | |
2432 | wpa_s, data->remain_on_channel.freq); | |
2433 | #endif /* CONFIG_P2P */ | |
2434 | break; | |
2435 | #ifdef CONFIG_P2P | |
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 | ||
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); | |
2461 | break; | |
2462 | } | |
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, | |
2478 | data->p2p_prov_disc_req.group_capab, | |
2479 | NULL, 0); | |
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; | |
2499 | #endif /* CONFIG_P2P */ | |
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; | |
2505 | case EVENT_SIGNAL_CHANGE: | |
2506 | bgscan_notify_signal_change( | |
2507 | wpa_s, data->signal_change.above_threshold, | |
2508 | data->signal_change.current_signal, | |
2509 | data->signal_change.current_noise, | |
2510 | data->signal_change.current_txrate); | |
2511 | break; | |
2512 | case EVENT_INTERFACE_ENABLED: | |
2513 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); | |
2514 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { | |
2515 | wpa_supplicant_update_mac_addr(wpa_s); | |
2516 | #ifdef CONFIG_AP | |
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); | |
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 */ | |
2528 | } | |
2529 | break; | |
2530 | case EVENT_INTERFACE_DISABLED: | |
2531 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); | |
2532 | wpa_supplicant_mark_disassoc(wpa_s); | |
2533 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); | |
2534 | break; | |
2535 | case EVENT_CHANNEL_LIST_CHANGED: | |
2536 | if (wpa_s->drv_priv == NULL) | |
2537 | break; /* Ignore event during drv initialization */ | |
2538 | #ifdef CONFIG_P2P | |
2539 | wpas_p2p_update_channel_list(wpa_s); | |
2540 | #endif /* CONFIG_P2P */ | |
2541 | break; | |
2542 | case EVENT_INTERFACE_UNAVAILABLE: | |
2543 | #ifdef CONFIG_P2P | |
2544 | wpas_p2p_interface_unavailable(wpa_s); | |
2545 | #endif /* CONFIG_P2P */ | |
2546 | break; | |
2547 | case EVENT_BEST_CHANNEL: | |
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); | |
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); | |
2559 | #endif /* CONFIG_P2P */ | |
2560 | break; | |
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; | |
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 */ | |
2575 | #ifdef CONFIG_TDLS | |
2576 | if (data) | |
2577 | wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr); | |
2578 | #endif /* CONFIG_TDLS */ | |
2579 | break; | |
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; | |
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; | |
2594 | case EVENT_SCHED_SCAN_STOPPED: | |
2595 | wpa_s->sched_scanning = 0; | |
2596 | wpa_supplicant_notify_scanning(wpa_s, 0); | |
2597 | ||
2598 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) | |
2599 | break; | |
2600 | ||
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; | |
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; | |
2613 | default: | |
2614 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); | |
2615 | break; | |
2616 | } | |
2617 | } |