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