]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/events.c
Remove CONFIG_IEEE80211W build parameter
[thirdparty/hostap.git] / wpa_supplicant / events.c
1 /*
2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2019, 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 "fst/fst.h"
27 #include "wnm_sta.h"
28 #include "notify.h"
29 #include "common/ieee802_11_defs.h"
30 #include "common/ieee802_11_common.h"
31 #include "common/gas_server.h"
32 #include "common/dpp.h"
33 #include "crypto/random.h"
34 #include "blacklist.h"
35 #include "wpas_glue.h"
36 #include "wps_supplicant.h"
37 #include "ibss_rsn.h"
38 #include "sme.h"
39 #include "gas_query.h"
40 #include "p2p_supplicant.h"
41 #include "bgscan.h"
42 #include "autoscan.h"
43 #include "ap.h"
44 #include "bss.h"
45 #include "scan.h"
46 #include "offchannel.h"
47 #include "interworking.h"
48 #include "mesh.h"
49 #include "mesh_mpm.h"
50 #include "wmm_ac.h"
51 #include "dpp_supplicant.h"
52
53
54 #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
55
56
57 #ifndef CONFIG_NO_SCAN_PROCESSING
58 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
59 int new_scan, int own_request);
60 #endif /* CONFIG_NO_SCAN_PROCESSING */
61
62
63 int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
64 {
65 struct os_reltime now;
66
67 if (ssid == NULL || ssid->disabled_until.sec == 0)
68 return 0;
69
70 os_get_reltime(&now);
71 if (ssid->disabled_until.sec > now.sec)
72 return ssid->disabled_until.sec - now.sec;
73
74 wpas_clear_temp_disabled(wpa_s, ssid, 0);
75
76 return 0;
77 }
78
79
80 #ifndef CONFIG_NO_SCAN_PROCESSING
81 /**
82 * wpas_reenabled_network_time - Time until first network is re-enabled
83 * @wpa_s: Pointer to wpa_supplicant data
84 * Returns: If all enabled networks are temporarily disabled, returns the time
85 * (in sec) until the first network is re-enabled. Otherwise returns 0.
86 *
87 * This function is used in case all enabled networks are temporarily disabled,
88 * in which case it returns the time (in sec) that the first network will be
89 * re-enabled. The function assumes that at least one network is enabled.
90 */
91 static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
92 {
93 struct wpa_ssid *ssid;
94 int disabled_for, res = 0;
95
96 #ifdef CONFIG_INTERWORKING
97 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
98 wpa_s->conf->cred)
99 return 0;
100 #endif /* CONFIG_INTERWORKING */
101
102 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
103 if (ssid->disabled)
104 continue;
105
106 disabled_for = wpas_temp_disabled(wpa_s, ssid);
107 if (!disabled_for)
108 return 0;
109
110 if (!res || disabled_for < res)
111 res = disabled_for;
112 }
113
114 return res;
115 }
116 #endif /* CONFIG_NO_SCAN_PROCESSING */
117
118
119 void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
120 {
121 struct wpa_supplicant *wpa_s = eloop_ctx;
122
123 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
124 return;
125
126 wpa_dbg(wpa_s, MSG_DEBUG,
127 "Try to associate due to network getting re-enabled");
128 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
129 wpa_supplicant_cancel_sched_scan(wpa_s);
130 wpa_supplicant_req_scan(wpa_s, 0, 0);
131 }
132 }
133
134
135 static struct wpa_bss * wpa_supplicant_get_new_bss(
136 struct wpa_supplicant *wpa_s, const u8 *bssid)
137 {
138 struct wpa_bss *bss = NULL;
139 struct wpa_ssid *ssid = wpa_s->current_ssid;
140
141 if (ssid->ssid_len > 0)
142 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
143 if (!bss)
144 bss = wpa_bss_get_bssid(wpa_s, bssid);
145
146 return bss;
147 }
148
149
150 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
151 {
152 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
153
154 if (!bss) {
155 wpa_supplicant_update_scan_results(wpa_s);
156
157 /* Get the BSS from the new scan results */
158 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
159 }
160
161 if (bss)
162 wpa_s->current_bss = bss;
163 }
164
165
166 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
167 {
168 struct wpa_ssid *ssid, *old_ssid;
169 u8 drv_ssid[SSID_MAX_LEN];
170 size_t drv_ssid_len;
171 int res;
172
173 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
174 wpa_supplicant_update_current_bss(wpa_s);
175
176 if (wpa_s->current_ssid->ssid_len == 0)
177 return 0; /* current profile still in use */
178 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
179 if (res < 0) {
180 wpa_msg(wpa_s, MSG_INFO,
181 "Failed to read SSID from driver");
182 return 0; /* try to use current profile */
183 }
184 drv_ssid_len = res;
185
186 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
187 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
188 drv_ssid_len) == 0)
189 return 0; /* current profile still in use */
190
191 wpa_msg(wpa_s, MSG_DEBUG,
192 "Driver-initiated BSS selection changed the SSID to %s",
193 wpa_ssid_txt(drv_ssid, drv_ssid_len));
194 /* continue selecting a new network profile */
195 }
196
197 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
198 "information");
199 ssid = wpa_supplicant_get_ssid(wpa_s);
200 if (ssid == NULL) {
201 wpa_msg(wpa_s, MSG_INFO,
202 "No network configuration found for the current AP");
203 return -1;
204 }
205
206 if (wpas_network_disabled(wpa_s, ssid)) {
207 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
208 return -1;
209 }
210
211 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
212 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
213 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
214 return -1;
215 }
216
217 res = wpas_temp_disabled(wpa_s, ssid);
218 if (res > 0) {
219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
220 "disabled for %d second(s)", res);
221 return -1;
222 }
223
224 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
225 "current AP");
226 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
227 u8 wpa_ie[80];
228 size_t wpa_ie_len = sizeof(wpa_ie);
229 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
230 wpa_ie, &wpa_ie_len) < 0)
231 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
232 } else {
233 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
234 }
235
236 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
237 eapol_sm_invalidate_cached_session(wpa_s->eapol);
238 old_ssid = wpa_s->current_ssid;
239 wpa_s->current_ssid = ssid;
240
241 wpa_supplicant_update_current_bss(wpa_s);
242
243 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
244 wpa_supplicant_initiate_eapol(wpa_s);
245 if (old_ssid != wpa_s->current_ssid)
246 wpas_notify_network_changed(wpa_s);
247
248 return 0;
249 }
250
251
252 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
253 {
254 struct wpa_supplicant *wpa_s = eloop_ctx;
255
256 if (wpa_s->countermeasures) {
257 wpa_s->countermeasures = 0;
258 wpa_drv_set_countermeasures(wpa_s, 0);
259 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
260
261 /*
262 * It is possible that the device is sched scanning, which means
263 * that a connection attempt will be done only when we receive
264 * scan results. However, in this case, it would be preferable
265 * to scan and connect immediately, so cancel the sched_scan and
266 * issue a regular scan flow.
267 */
268 wpa_supplicant_cancel_sched_scan(wpa_s);
269 wpa_supplicant_req_scan(wpa_s, 0, 0);
270 }
271 }
272
273
274 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
275 {
276 int bssid_changed;
277
278 wnm_bss_keep_alive_deinit(wpa_s);
279
280 #ifdef CONFIG_IBSS_RSN
281 ibss_rsn_deinit(wpa_s->ibss_rsn);
282 wpa_s->ibss_rsn = NULL;
283 #endif /* CONFIG_IBSS_RSN */
284
285 #ifdef CONFIG_AP
286 wpa_supplicant_ap_deinit(wpa_s);
287 #endif /* CONFIG_AP */
288
289 #ifdef CONFIG_HS20
290 /* Clear possibly configured frame filters */
291 wpa_drv_configure_frame_filters(wpa_s, 0);
292 #endif /* CONFIG_HS20 */
293
294 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
295 return;
296
297 if (os_reltime_initialized(&wpa_s->session_start)) {
298 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
299 wpa_s->session_start.sec = 0;
300 wpa_s->session_start.usec = 0;
301 wpas_notify_session_length(wpa_s);
302 }
303
304 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
305 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
306 os_memset(wpa_s->bssid, 0, ETH_ALEN);
307 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
308 sme_clear_on_disassoc(wpa_s);
309 wpa_s->current_bss = NULL;
310 wpa_s->assoc_freq = 0;
311
312 if (bssid_changed)
313 wpas_notify_bssid_changed(wpa_s);
314
315 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
316 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
317 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
318 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
319 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
320 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
321 wpa_s->drv_authorized_port = 0;
322 wpa_s->ap_ies_from_associnfo = 0;
323 wpa_s->current_ssid = NULL;
324 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
325 wpa_s->key_mgmt = 0;
326
327 wpas_rrm_reset(wpa_s);
328 wpa_s->wnmsleep_used = 0;
329 wnm_clear_coloc_intf_reporting(wpa_s);
330
331 #ifdef CONFIG_TESTING_OPTIONS
332 wpa_s->last_tk_alg = WPA_ALG_NONE;
333 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
334 #endif /* CONFIG_TESTING_OPTIONS */
335 wpa_s->ieee80211ac = 0;
336
337 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
338 wpa_s->enabled_4addr_mode = 0;
339 }
340
341
342 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
343 {
344 struct wpa_ie_data ie;
345 int pmksa_set = -1;
346 size_t i;
347
348 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
349 ie.pmkid == NULL)
350 return;
351
352 for (i = 0; i < ie.num_pmkid; i++) {
353 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
354 ie.pmkid + i * PMKID_LEN,
355 NULL, NULL, 0, NULL, 0);
356 if (pmksa_set == 0) {
357 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
358 break;
359 }
360 }
361
362 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
363 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
364 }
365
366
367 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
368 union wpa_event_data *data)
369 {
370 if (data == NULL) {
371 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
372 "event");
373 return;
374 }
375 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
376 " index=%d preauth=%d",
377 MAC2STR(data->pmkid_candidate.bssid),
378 data->pmkid_candidate.index,
379 data->pmkid_candidate.preauth);
380
381 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
382 data->pmkid_candidate.index,
383 data->pmkid_candidate.preauth);
384 }
385
386
387 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
388 {
389 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
390 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
391 return 0;
392
393 #ifdef IEEE8021X_EAPOL
394 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
395 wpa_s->current_ssid &&
396 !(wpa_s->current_ssid->eapol_flags &
397 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
398 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
399 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
400 * plaintext or static WEP keys). */
401 return 0;
402 }
403 #endif /* IEEE8021X_EAPOL */
404
405 return 1;
406 }
407
408
409 /**
410 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
411 * @wpa_s: pointer to wpa_supplicant data
412 * @ssid: Configuration data for the network
413 * Returns: 0 on success, -1 on failure
414 *
415 * This function is called when starting authentication with a network that is
416 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
417 */
418 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
419 struct wpa_ssid *ssid)
420 {
421 #ifdef IEEE8021X_EAPOL
422 #ifdef PCSC_FUNCS
423 int aka = 0, sim = 0;
424
425 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
426 wpa_s->scard != NULL || wpa_s->conf->external_sim)
427 return 0;
428
429 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
430 sim = 1;
431 aka = 1;
432 } else {
433 struct eap_method_type *eap = ssid->eap.eap_methods;
434 while (eap->vendor != EAP_VENDOR_IETF ||
435 eap->method != EAP_TYPE_NONE) {
436 if (eap->vendor == EAP_VENDOR_IETF) {
437 if (eap->method == EAP_TYPE_SIM)
438 sim = 1;
439 else if (eap->method == EAP_TYPE_AKA ||
440 eap->method == EAP_TYPE_AKA_PRIME)
441 aka = 1;
442 }
443 eap++;
444 }
445 }
446
447 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
448 sim = 0;
449 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
450 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
451 NULL)
452 aka = 0;
453
454 if (!sim && !aka) {
455 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
456 "use SIM, but neither EAP-SIM nor EAP-AKA are "
457 "enabled");
458 return 0;
459 }
460
461 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
462 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
463
464 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
465 if (wpa_s->scard == NULL) {
466 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
467 "(pcsc-lite)");
468 return -1;
469 }
470 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
471 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
472 #endif /* PCSC_FUNCS */
473 #endif /* IEEE8021X_EAPOL */
474
475 return 0;
476 }
477
478
479 #ifndef CONFIG_NO_SCAN_PROCESSING
480
481 static int has_wep_key(struct wpa_ssid *ssid)
482 {
483 int i;
484
485 for (i = 0; i < NUM_WEP_KEYS; i++) {
486 if (ssid->wep_key_len[i])
487 return 1;
488 }
489
490 return 0;
491 }
492
493
494 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
495 struct wpa_ssid *ssid)
496 {
497 int privacy = 0;
498
499 if (ssid->mixed_cell)
500 return 1;
501
502 #ifdef CONFIG_WPS
503 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
504 return 1;
505 #endif /* CONFIG_WPS */
506
507 #ifdef CONFIG_OWE
508 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
509 return 1;
510 #endif /* CONFIG_OWE */
511
512 if (has_wep_key(ssid))
513 privacy = 1;
514
515 #ifdef IEEE8021X_EAPOL
516 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
517 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
518 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
519 privacy = 1;
520 #endif /* IEEE8021X_EAPOL */
521
522 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
523 privacy = 1;
524
525 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
526 privacy = 1;
527
528 if (bss->caps & IEEE80211_CAP_PRIVACY)
529 return privacy;
530 return !privacy;
531 }
532
533
534 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
535 struct wpa_ssid *ssid,
536 struct wpa_bss *bss, int debug_print)
537 {
538 struct wpa_ie_data ie;
539 int proto_match = 0;
540 const u8 *rsn_ie, *wpa_ie;
541 int ret;
542 int wep_ok;
543 #ifdef CONFIG_MBO
544 const u8 *oce_capa_attr;
545 #endif /* CONFIG_MBO */
546
547 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
548 if (ret >= 0)
549 return ret;
550
551 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
552 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
553 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
554 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
555 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
556
557 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
558 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
559 proto_match++;
560
561 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
562 if (debug_print)
563 wpa_dbg(wpa_s, MSG_DEBUG,
564 " skip RSN IE - parse failed");
565 break;
566 }
567 if (!ie.has_pairwise)
568 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
569 if (!ie.has_group)
570 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
571
572 if (wep_ok &&
573 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
574 {
575 if (debug_print)
576 wpa_dbg(wpa_s, MSG_DEBUG,
577 " selected based on TSN in RSN IE");
578 return 1;
579 }
580
581 if (!(ie.proto & ssid->proto) &&
582 !(ssid->proto & WPA_PROTO_OSEN)) {
583 if (debug_print)
584 wpa_dbg(wpa_s, MSG_DEBUG,
585 " skip RSN IE - proto mismatch");
586 break;
587 }
588
589 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
590 if (debug_print)
591 wpa_dbg(wpa_s, MSG_DEBUG,
592 " skip RSN IE - PTK cipher mismatch");
593 break;
594 }
595
596 if (!(ie.group_cipher & ssid->group_cipher)) {
597 if (debug_print)
598 wpa_dbg(wpa_s, MSG_DEBUG,
599 " skip RSN IE - GTK cipher mismatch");
600 break;
601 }
602
603 if (ssid->group_mgmt_cipher &&
604 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
605 if (debug_print)
606 wpa_dbg(wpa_s, MSG_DEBUG,
607 " skip RSN IE - group mgmt cipher mismatch");
608 break;
609 }
610
611 if (!(ie.key_mgmt & ssid->key_mgmt)) {
612 if (debug_print)
613 wpa_dbg(wpa_s, MSG_DEBUG,
614 " skip RSN IE - key mgmt mismatch");
615 break;
616 }
617
618 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
619 wpas_get_ssid_pmf(wpa_s, ssid) ==
620 MGMT_FRAME_PROTECTION_REQUIRED) {
621 if (debug_print)
622 wpa_dbg(wpa_s, MSG_DEBUG,
623 " skip RSN IE - no mgmt frame protection");
624 break;
625 }
626 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
627 wpas_get_ssid_pmf(wpa_s, ssid) ==
628 NO_MGMT_FRAME_PROTECTION) {
629 if (debug_print)
630 wpa_dbg(wpa_s, MSG_DEBUG,
631 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
632 break;
633 }
634 #ifdef CONFIG_MBO
635 oce_capa_attr = wpas_mbo_get_bss_attr(bss,
636 OCE_ATTR_ID_CAPA_IND);
637 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
638 (wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) ||
639 (oce_capa_attr && oce_capa_attr[1] >= 1 &&
640 !(oce_capa_attr[2] & OCE_IS_STA_CFON))) &&
641 wpas_get_ssid_pmf(wpa_s, ssid) !=
642 NO_MGMT_FRAME_PROTECTION) {
643 if (debug_print)
644 wpa_dbg(wpa_s, MSG_DEBUG,
645 " skip RSN IE - no mgmt frame protection enabled on MBO/OCE AP");
646 break;
647 }
648 #endif /* CONFIG_MBO */
649
650 if (debug_print)
651 wpa_dbg(wpa_s, MSG_DEBUG,
652 " selected based on RSN IE");
653 return 1;
654 }
655
656 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
657 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
658 if (debug_print)
659 wpa_dbg(wpa_s, MSG_DEBUG,
660 " skip - MFP Required but network not MFP Capable");
661 return 0;
662 }
663
664 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
665 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
666 proto_match++;
667
668 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
669 if (debug_print)
670 wpa_dbg(wpa_s, MSG_DEBUG,
671 " skip WPA IE - parse failed");
672 break;
673 }
674
675 if (wep_ok &&
676 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
677 {
678 if (debug_print)
679 wpa_dbg(wpa_s, MSG_DEBUG,
680 " selected based on TSN in WPA IE");
681 return 1;
682 }
683
684 if (!(ie.proto & ssid->proto)) {
685 if (debug_print)
686 wpa_dbg(wpa_s, MSG_DEBUG,
687 " skip WPA IE - proto mismatch");
688 break;
689 }
690
691 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
692 if (debug_print)
693 wpa_dbg(wpa_s, MSG_DEBUG,
694 " skip WPA IE - PTK cipher mismatch");
695 break;
696 }
697
698 if (!(ie.group_cipher & ssid->group_cipher)) {
699 if (debug_print)
700 wpa_dbg(wpa_s, MSG_DEBUG,
701 " skip WPA IE - GTK cipher mismatch");
702 break;
703 }
704
705 if (!(ie.key_mgmt & ssid->key_mgmt)) {
706 if (debug_print)
707 wpa_dbg(wpa_s, MSG_DEBUG,
708 " skip WPA IE - key mgmt mismatch");
709 break;
710 }
711
712 if (debug_print)
713 wpa_dbg(wpa_s, MSG_DEBUG,
714 " selected based on WPA IE");
715 return 1;
716 }
717
718 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
719 !rsn_ie) {
720 if (debug_print)
721 wpa_dbg(wpa_s, MSG_DEBUG,
722 " allow for non-WPA IEEE 802.1X");
723 return 1;
724 }
725
726 #ifdef CONFIG_OWE
727 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
728 !wpa_ie && !rsn_ie) {
729 if (wpa_s->owe_transition_select &&
730 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
731 ssid->owe_transition_bss_select_count + 1 <=
732 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
733 ssid->owe_transition_bss_select_count++;
734 if (debug_print)
735 wpa_dbg(wpa_s, MSG_DEBUG,
736 " skip OWE transition BSS (selection count %d does not exceed %d)",
737 ssid->owe_transition_bss_select_count,
738 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
739 wpa_s->owe_transition_search = 1;
740 return 0;
741 }
742 if (debug_print)
743 wpa_dbg(wpa_s, MSG_DEBUG,
744 " allow in OWE transition mode");
745 return 1;
746 }
747 #endif /* CONFIG_OWE */
748
749 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
750 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
751 if (debug_print)
752 wpa_dbg(wpa_s, MSG_DEBUG,
753 " skip - no WPA/RSN proto match");
754 return 0;
755 }
756
757 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
758 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
759 if (debug_print)
760 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
761 return 1;
762 }
763
764 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
765 if (debug_print)
766 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
767 return 1;
768 }
769
770 if (debug_print)
771 wpa_dbg(wpa_s, MSG_DEBUG,
772 " reject due to mismatch with WPA/WPA2");
773
774 return 0;
775 }
776
777
778 static int freq_allowed(int *freqs, int freq)
779 {
780 int i;
781
782 if (freqs == NULL)
783 return 1;
784
785 for (i = 0; freqs[i]; i++)
786 if (freqs[i] == freq)
787 return 1;
788 return 0;
789 }
790
791
792 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
793 int debug_print)
794 {
795 const struct hostapd_hw_modes *mode = NULL, *modes;
796 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
797 const u8 *rate_ie;
798 int i, j, k;
799
800 if (bss->freq == 0)
801 return 1; /* Cannot do matching without knowing band */
802
803 modes = wpa_s->hw.modes;
804 if (modes == NULL) {
805 /*
806 * The driver does not provide any additional information
807 * about the utilized hardware, so allow the connection attempt
808 * to continue.
809 */
810 return 1;
811 }
812
813 for (i = 0; i < wpa_s->hw.num_modes; i++) {
814 for (j = 0; j < modes[i].num_channels; j++) {
815 int freq = modes[i].channels[j].freq;
816 if (freq == bss->freq) {
817 if (mode &&
818 mode->mode == HOSTAPD_MODE_IEEE80211G)
819 break; /* do not allow 802.11b replace
820 * 802.11g */
821 mode = &modes[i];
822 break;
823 }
824 }
825 }
826
827 if (mode == NULL)
828 return 0;
829
830 for (i = 0; i < (int) sizeof(scan_ie); i++) {
831 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
832 if (rate_ie == NULL)
833 continue;
834
835 for (j = 2; j < rate_ie[1] + 2; j++) {
836 int flagged = !!(rate_ie[j] & 0x80);
837 int r = (rate_ie[j] & 0x7f) * 5;
838
839 /*
840 * IEEE Std 802.11n-2009 7.3.2.2:
841 * The new BSS Membership selector value is encoded
842 * like a legacy basic rate, but it is not a rate and
843 * only indicates if the BSS members are required to
844 * support the mandatory features of Clause 20 [HT PHY]
845 * in order to join the BSS.
846 */
847 if (flagged && ((rate_ie[j] & 0x7f) ==
848 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
849 if (!ht_supported(mode)) {
850 if (debug_print)
851 wpa_dbg(wpa_s, MSG_DEBUG,
852 " hardware does not support HT PHY");
853 return 0;
854 }
855 continue;
856 }
857
858 /* There's also a VHT selector for 802.11ac */
859 if (flagged && ((rate_ie[j] & 0x7f) ==
860 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
861 if (!vht_supported(mode)) {
862 if (debug_print)
863 wpa_dbg(wpa_s, MSG_DEBUG,
864 " hardware does not support VHT PHY");
865 return 0;
866 }
867 continue;
868 }
869
870 if (!flagged)
871 continue;
872
873 /* check for legacy basic rates */
874 for (k = 0; k < mode->num_rates; k++) {
875 if (mode->rates[k] == r)
876 break;
877 }
878 if (k == mode->num_rates) {
879 /*
880 * IEEE Std 802.11-2007 7.3.2.2 demands that in
881 * order to join a BSS all required rates
882 * have to be supported by the hardware.
883 */
884 if (debug_print)
885 wpa_dbg(wpa_s, MSG_DEBUG,
886 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
887 r / 10, r % 10,
888 bss->freq, mode->mode, mode->num_rates);
889 return 0;
890 }
891 }
892 }
893
894 return 1;
895 }
896
897
898 /*
899 * Test whether BSS is in an ESS.
900 * This is done differently in DMG (60 GHz) and non-DMG bands
901 */
902 static int bss_is_ess(struct wpa_bss *bss)
903 {
904 if (bss_is_dmg(bss)) {
905 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
906 IEEE80211_CAP_DMG_AP;
907 }
908
909 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
910 IEEE80211_CAP_ESS);
911 }
912
913
914 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
915 {
916 size_t i;
917
918 for (i = 0; i < ETH_ALEN; i++) {
919 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
920 return 0;
921 }
922 return 1;
923 }
924
925
926 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
927 {
928 size_t i;
929
930 for (i = 0; i < num; i++) {
931 const u8 *a = list + i * ETH_ALEN * 2;
932 const u8 *m = a + ETH_ALEN;
933
934 if (match_mac_mask(a, addr, m))
935 return 1;
936 }
937 return 0;
938 }
939
940
941 static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
942 const u8 **ret_ssid, size_t *ret_ssid_len)
943 {
944 #ifdef CONFIG_OWE
945 const u8 *owe, *pos, *end, *bssid;
946 u8 ssid_len;
947 struct wpa_bss *open_bss;
948
949 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
950 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
951 return;
952
953 pos = owe + 6;
954 end = owe + 2 + owe[1];
955
956 if (end - pos < ETH_ALEN + 1)
957 return;
958 bssid = pos;
959 pos += ETH_ALEN;
960 ssid_len = *pos++;
961 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
962 return;
963
964 /* Match the profile SSID against the OWE transition mode SSID on the
965 * open network. */
966 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
967 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
968 *ret_ssid = pos;
969 *ret_ssid_len = ssid_len;
970
971 if (bss->ssid_len > 0)
972 return;
973
974 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
975 if (!open_bss)
976 return;
977 if (ssid_len != open_bss->ssid_len ||
978 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
979 wpa_dbg(wpa_s, MSG_DEBUG,
980 "OWE: transition mode SSID mismatch: %s",
981 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
982 return;
983 }
984
985 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
986 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
987 wpa_dbg(wpa_s, MSG_DEBUG,
988 "OWE: transition mode open BSS unexpected info");
989 return;
990 }
991
992 pos = owe + 6;
993 end = owe + 2 + owe[1];
994
995 if (end - pos < ETH_ALEN + 1)
996 return;
997 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
998 wpa_dbg(wpa_s, MSG_DEBUG,
999 "OWE: transition mode BSSID mismatch: " MACSTR,
1000 MAC2STR(pos));
1001 return;
1002 }
1003 pos += ETH_ALEN;
1004 ssid_len = *pos++;
1005 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1006 return;
1007 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1008 wpa_ssid_txt(pos, ssid_len));
1009 os_memcpy(bss->ssid, pos, ssid_len);
1010 bss->ssid_len = ssid_len;
1011 #endif /* CONFIG_OWE */
1012 }
1013
1014
1015 struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1016 int i, struct wpa_bss *bss,
1017 struct wpa_ssid *group,
1018 int only_first_ssid, int debug_print)
1019 {
1020 u8 wpa_ie_len, rsn_ie_len;
1021 int wpa;
1022 struct wpa_blacklist *e;
1023 const u8 *ie;
1024 struct wpa_ssid *ssid;
1025 int osen, rsn_osen = 0;
1026 #ifdef CONFIG_MBO
1027 const u8 *assoc_disallow;
1028 #endif /* CONFIG_MBO */
1029 const u8 *match_ssid;
1030 size_t match_ssid_len;
1031 struct wpa_ie_data data;
1032
1033 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1034 wpa_ie_len = ie ? ie[1] : 0;
1035
1036 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1037 rsn_ie_len = ie ? ie[1] : 0;
1038 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1039 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1040 rsn_osen = 1;
1041
1042 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1043 osen = ie != NULL;
1044
1045 if (debug_print) {
1046 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1047 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1048 i, MAC2STR(bss->bssid),
1049 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1050 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1051 bss->freq,
1052 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1053 " wps" : "",
1054 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1055 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1056 ? " p2p" : "",
1057 osen ? " osen=1" : "");
1058 }
1059
1060 e = wpa_blacklist_get(wpa_s, bss->bssid);
1061 if (e) {
1062 int limit = 1;
1063 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
1064 /*
1065 * When only a single network is enabled, we can
1066 * trigger blacklisting on the first failure. This
1067 * should not be done with multiple enabled networks to
1068 * avoid getting forced to move into a worse ESS on
1069 * single error if there are no other BSSes of the
1070 * current ESS.
1071 */
1072 limit = 0;
1073 }
1074 if (e->count > limit) {
1075 if (debug_print) {
1076 wpa_dbg(wpa_s, MSG_DEBUG,
1077 " skip - blacklisted (count=%d limit=%d)",
1078 e->count, limit);
1079 }
1080 return NULL;
1081 }
1082 }
1083
1084 match_ssid = bss->ssid;
1085 match_ssid_len = bss->ssid_len;
1086 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1087
1088 if (match_ssid_len == 0) {
1089 if (debug_print)
1090 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
1091 return NULL;
1092 }
1093
1094 if (disallowed_bssid(wpa_s, bss->bssid)) {
1095 if (debug_print)
1096 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
1097 return NULL;
1098 }
1099
1100 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
1101 if (debug_print)
1102 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
1103 return NULL;
1104 }
1105
1106 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
1107
1108 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
1109 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
1110 int res;
1111
1112 if (wpas_network_disabled(wpa_s, ssid)) {
1113 if (debug_print)
1114 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1115 continue;
1116 }
1117
1118 res = wpas_temp_disabled(wpa_s, ssid);
1119 if (res > 0) {
1120 if (debug_print)
1121 wpa_dbg(wpa_s, MSG_DEBUG,
1122 " skip - disabled temporarily for %d second(s)",
1123 res);
1124 continue;
1125 }
1126
1127 #ifdef CONFIG_WPS
1128 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
1129 if (debug_print)
1130 wpa_dbg(wpa_s, MSG_DEBUG,
1131 " skip - blacklisted (WPS)");
1132 continue;
1133 }
1134
1135 if (wpa && ssid->ssid_len == 0 &&
1136 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1137 check_ssid = 0;
1138
1139 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1140 /* Only allow wildcard SSID match if an AP
1141 * advertises active WPS operation that matches
1142 * with our mode. */
1143 check_ssid = 1;
1144 if (ssid->ssid_len == 0 &&
1145 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1146 check_ssid = 0;
1147 }
1148 #endif /* CONFIG_WPS */
1149
1150 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1151 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1152 check_ssid = 0;
1153
1154 if (check_ssid &&
1155 (match_ssid_len != ssid->ssid_len ||
1156 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1157 if (debug_print)
1158 wpa_dbg(wpa_s, MSG_DEBUG,
1159 " skip - SSID mismatch");
1160 continue;
1161 }
1162
1163 if (ssid->bssid_set &&
1164 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1165 if (debug_print)
1166 wpa_dbg(wpa_s, MSG_DEBUG,
1167 " skip - BSSID mismatch");
1168 continue;
1169 }
1170
1171 /* check blacklist */
1172 if (ssid->num_bssid_blacklist &&
1173 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1174 ssid->num_bssid_blacklist)) {
1175 if (debug_print)
1176 wpa_dbg(wpa_s, MSG_DEBUG,
1177 " skip - BSSID blacklisted");
1178 continue;
1179 }
1180
1181 /* if there is a whitelist, only accept those APs */
1182 if (ssid->num_bssid_whitelist &&
1183 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1184 ssid->num_bssid_whitelist)) {
1185 if (debug_print)
1186 wpa_dbg(wpa_s, MSG_DEBUG,
1187 " skip - BSSID not in whitelist");
1188 continue;
1189 }
1190
1191 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss,
1192 debug_print))
1193 continue;
1194
1195 if (!osen && !wpa &&
1196 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1197 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1198 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1199 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1200 if (debug_print)
1201 wpa_dbg(wpa_s, MSG_DEBUG,
1202 " skip - non-WPA network not allowed");
1203 continue;
1204 }
1205
1206 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1207 has_wep_key(ssid)) {
1208 if (debug_print)
1209 wpa_dbg(wpa_s, MSG_DEBUG,
1210 " skip - ignore WPA/WPA2 AP for WEP network block");
1211 continue;
1212 }
1213
1214 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen &&
1215 !rsn_osen) {
1216 if (debug_print)
1217 wpa_dbg(wpa_s, MSG_DEBUG,
1218 " skip - non-OSEN network not allowed");
1219 continue;
1220 }
1221
1222 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1223 if (debug_print)
1224 wpa_dbg(wpa_s, MSG_DEBUG,
1225 " skip - privacy mismatch");
1226 continue;
1227 }
1228
1229 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1230 !bss_is_pbss(bss)) {
1231 if (debug_print)
1232 wpa_dbg(wpa_s, MSG_DEBUG,
1233 " skip - not ESS, PBSS, or MBSS");
1234 continue;
1235 }
1236
1237 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1238 if (debug_print)
1239 wpa_dbg(wpa_s, MSG_DEBUG,
1240 " skip - PBSS mismatch (ssid %d bss %d)",
1241 ssid->pbss, bss_is_pbss(bss));
1242 continue;
1243 }
1244
1245 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1246 if (debug_print)
1247 wpa_dbg(wpa_s, MSG_DEBUG,
1248 " skip - frequency not allowed");
1249 continue;
1250 }
1251
1252 #ifdef CONFIG_MESH
1253 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1254 ssid->frequency != bss->freq) {
1255 if (debug_print)
1256 wpa_dbg(wpa_s, MSG_DEBUG,
1257 " skip - frequency not allowed (mesh)");
1258 continue;
1259 }
1260 #endif /* CONFIG_MESH */
1261
1262 if (!rate_match(wpa_s, bss, debug_print)) {
1263 if (debug_print)
1264 wpa_dbg(wpa_s, MSG_DEBUG,
1265 " skip - rate sets do not match");
1266 continue;
1267 }
1268
1269 #ifndef CONFIG_IBSS_RSN
1270 if (ssid->mode == WPAS_MODE_IBSS &&
1271 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1272 WPA_KEY_MGMT_WPA_NONE))) {
1273 if (debug_print)
1274 wpa_dbg(wpa_s, MSG_DEBUG,
1275 " skip - IBSS RSN not supported in the build");
1276 continue;
1277 }
1278 #endif /* !CONFIG_IBSS_RSN */
1279
1280 #ifdef CONFIG_P2P
1281 if (ssid->p2p_group &&
1282 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1283 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1284 if (debug_print)
1285 wpa_dbg(wpa_s, MSG_DEBUG,
1286 " skip - no P2P IE seen");
1287 continue;
1288 }
1289
1290 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1291 struct wpabuf *p2p_ie;
1292 u8 dev_addr[ETH_ALEN];
1293
1294 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1295 if (ie == NULL) {
1296 if (debug_print)
1297 wpa_dbg(wpa_s, MSG_DEBUG,
1298 " skip - no P2P element");
1299 continue;
1300 }
1301 p2p_ie = wpa_bss_get_vendor_ie_multi(
1302 bss, P2P_IE_VENDOR_TYPE);
1303 if (p2p_ie == NULL) {
1304 if (debug_print)
1305 wpa_dbg(wpa_s, MSG_DEBUG,
1306 " skip - could not fetch P2P element");
1307 continue;
1308 }
1309
1310 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1311 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1312 ETH_ALEN) != 0) {
1313 if (debug_print)
1314 wpa_dbg(wpa_s, MSG_DEBUG,
1315 " skip - no matching GO P2P Device Address in P2P element");
1316 wpabuf_free(p2p_ie);
1317 continue;
1318 }
1319 wpabuf_free(p2p_ie);
1320 }
1321
1322 /*
1323 * TODO: skip the AP if its P2P IE has Group Formation
1324 * bit set in the P2P Group Capability Bitmap and we
1325 * are not in Group Formation with that device.
1326 */
1327 #endif /* CONFIG_P2P */
1328
1329 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1330 {
1331 struct os_reltime diff;
1332
1333 os_reltime_sub(&wpa_s->scan_min_time,
1334 &bss->last_update, &diff);
1335 if (debug_print)
1336 wpa_dbg(wpa_s, MSG_DEBUG,
1337 " skip - scan result not recent enough (%u.%06u seconds too old)",
1338 (unsigned int) diff.sec,
1339 (unsigned int) diff.usec);
1340 continue;
1341 }
1342 #ifdef CONFIG_MBO
1343 #ifdef CONFIG_TESTING_OPTIONS
1344 if (wpa_s->ignore_assoc_disallow)
1345 goto skip_assoc_disallow;
1346 #endif /* CONFIG_TESTING_OPTIONS */
1347 assoc_disallow = wpas_mbo_get_bss_attr(
1348 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1349 if (assoc_disallow && assoc_disallow[1] >= 1) {
1350 if (debug_print)
1351 wpa_dbg(wpa_s, MSG_DEBUG,
1352 " skip - MBO association disallowed (reason %u)",
1353 assoc_disallow[2]);
1354 continue;
1355 }
1356
1357 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1358 if (debug_print)
1359 wpa_dbg(wpa_s, MSG_DEBUG,
1360 " skip - AP temporarily disallowed");
1361 continue;
1362 }
1363 #ifdef CONFIG_TESTING_OPTIONS
1364 skip_assoc_disallow:
1365 #endif /* CONFIG_TESTING_OPTIONS */
1366 #endif /* CONFIG_MBO */
1367
1368 #ifdef CONFIG_DPP
1369 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1370 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1371 (!ssid->dpp_connector ||
1372 !ssid->dpp_netaccesskey ||
1373 !ssid->dpp_csign)) {
1374 if (debug_print)
1375 wpa_dbg(wpa_s, MSG_DEBUG,
1376 " skip - no PMKSA entry for DPP");
1377 continue;
1378 }
1379 #endif /* CONFIG_DPP */
1380
1381 /* Matching configuration found */
1382 return ssid;
1383 }
1384
1385 /* No matching configuration found */
1386 return NULL;
1387 }
1388
1389
1390 static struct wpa_bss *
1391 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1392 struct wpa_ssid *group,
1393 struct wpa_ssid **selected_ssid,
1394 int only_first_ssid)
1395 {
1396 unsigned int i;
1397
1398 if (wpa_s->current_ssid) {
1399 struct wpa_ssid *ssid;
1400
1401 wpa_dbg(wpa_s, MSG_DEBUG,
1402 "Scan results matching the currently selected network");
1403 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1404 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1405
1406 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1407 only_first_ssid, 0);
1408 if (ssid != wpa_s->current_ssid)
1409 continue;
1410 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1411 " freq=%d level=%d snr=%d est_throughput=%u",
1412 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1413 bss->snr, bss->est_throughput);
1414 }
1415 }
1416
1417 if (only_first_ssid)
1418 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1419 group->id);
1420 else
1421 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1422 group->priority);
1423
1424 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1425 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1426
1427 wpa_s->owe_transition_select = 1;
1428 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1429 only_first_ssid, 1);
1430 wpa_s->owe_transition_select = 0;
1431 if (!*selected_ssid)
1432 continue;
1433 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1434 " ssid='%s'",
1435 MAC2STR(bss->bssid),
1436 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1437 return bss;
1438 }
1439
1440 return NULL;
1441 }
1442
1443
1444 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1445 struct wpa_ssid **selected_ssid)
1446 {
1447 struct wpa_bss *selected = NULL;
1448 int prio;
1449 struct wpa_ssid *next_ssid = NULL;
1450 struct wpa_ssid *ssid;
1451
1452 if (wpa_s->last_scan_res == NULL ||
1453 wpa_s->last_scan_res_used == 0)
1454 return NULL; /* no scan results from last update */
1455
1456 if (wpa_s->next_ssid) {
1457 /* check that next_ssid is still valid */
1458 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1459 if (ssid == wpa_s->next_ssid)
1460 break;
1461 }
1462 next_ssid = ssid;
1463 wpa_s->next_ssid = NULL;
1464 }
1465
1466 while (selected == NULL) {
1467 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1468 if (next_ssid && next_ssid->priority ==
1469 wpa_s->conf->pssid[prio]->priority) {
1470 selected = wpa_supplicant_select_bss(
1471 wpa_s, next_ssid, selected_ssid, 1);
1472 if (selected)
1473 break;
1474 }
1475 selected = wpa_supplicant_select_bss(
1476 wpa_s, wpa_s->conf->pssid[prio],
1477 selected_ssid, 0);
1478 if (selected)
1479 break;
1480 }
1481
1482 if (selected == NULL && wpa_s->blacklist &&
1483 !wpa_s->countermeasures) {
1484 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1485 "blacklist and try again");
1486 wpa_blacklist_clear(wpa_s);
1487 wpa_s->blacklist_cleared++;
1488 } else if (selected == NULL)
1489 break;
1490 }
1491
1492 ssid = *selected_ssid;
1493 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1494 !ssid->passphrase && !ssid->ext_psk) {
1495 const char *field_name, *txt = NULL;
1496
1497 wpa_dbg(wpa_s, MSG_DEBUG,
1498 "PSK/passphrase not yet available for the selected network");
1499
1500 wpas_notify_network_request(wpa_s, ssid,
1501 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1502
1503 field_name = wpa_supplicant_ctrl_req_to_string(
1504 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1505 if (field_name == NULL)
1506 return NULL;
1507
1508 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1509
1510 selected = NULL;
1511 }
1512
1513 return selected;
1514 }
1515
1516
1517 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1518 int timeout_sec, int timeout_usec)
1519 {
1520 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1521 /*
1522 * No networks are enabled; short-circuit request so
1523 * we don't wait timeout seconds before transitioning
1524 * to INACTIVE state.
1525 */
1526 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1527 "since there are no enabled networks");
1528 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1529 return;
1530 }
1531
1532 wpa_s->scan_for_connection = 1;
1533 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1534 }
1535
1536
1537 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1538 struct wpa_bss *selected,
1539 struct wpa_ssid *ssid)
1540 {
1541 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1542 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1543 "PBC session overlap");
1544 wpas_notify_wps_event_pbc_overlap(wpa_s);
1545 #ifdef CONFIG_P2P
1546 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1547 wpa_s->p2p_in_provisioning) {
1548 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1549 wpa_s, NULL);
1550 return -1;
1551 }
1552 #endif /* CONFIG_P2P */
1553
1554 #ifdef CONFIG_WPS
1555 wpas_wps_pbc_overlap(wpa_s);
1556 wpas_wps_cancel(wpa_s);
1557 #endif /* CONFIG_WPS */
1558 return -1;
1559 }
1560
1561 wpa_msg(wpa_s, MSG_DEBUG,
1562 "Considering connect request: reassociate: %d selected: "
1563 MACSTR " bssid: " MACSTR " pending: " MACSTR
1564 " wpa_state: %s ssid=%p current_ssid=%p",
1565 wpa_s->reassociate, MAC2STR(selected->bssid),
1566 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1567 wpa_supplicant_state_txt(wpa_s->wpa_state),
1568 ssid, wpa_s->current_ssid);
1569
1570 /*
1571 * Do not trigger new association unless the BSSID has changed or if
1572 * reassociation is requested. If we are in process of associating with
1573 * the selected BSSID, do not trigger new attempt.
1574 */
1575 if (wpa_s->reassociate ||
1576 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1577 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1578 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1579 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1580 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1581 0) ||
1582 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1583 ssid != wpa_s->current_ssid)))) {
1584 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1585 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1586 return 0;
1587 }
1588 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1589 MAC2STR(selected->bssid));
1590 wpa_supplicant_associate(wpa_s, selected, ssid);
1591 } else {
1592 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1593 "connect with the selected AP");
1594 }
1595
1596 return 0;
1597 }
1598
1599
1600 static struct wpa_ssid *
1601 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1602 {
1603 int prio;
1604 struct wpa_ssid *ssid;
1605
1606 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1607 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1608 {
1609 if (wpas_network_disabled(wpa_s, ssid))
1610 continue;
1611 #ifndef CONFIG_IBSS_RSN
1612 if (ssid->mode == WPAS_MODE_IBSS &&
1613 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1614 WPA_KEY_MGMT_WPA_NONE))) {
1615 wpa_msg(wpa_s, MSG_INFO,
1616 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1617 wpa_ssid_txt(ssid->ssid,
1618 ssid->ssid_len));
1619 continue;
1620 }
1621 #endif /* !CONFIG_IBSS_RSN */
1622 if (ssid->mode == WPAS_MODE_IBSS ||
1623 ssid->mode == WPAS_MODE_AP ||
1624 ssid->mode == WPAS_MODE_MESH)
1625 return ssid;
1626 }
1627 }
1628 return NULL;
1629 }
1630
1631
1632 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1633 * on BSS added and BSS changed events */
1634 static void wpa_supplicant_rsn_preauth_scan_results(
1635 struct wpa_supplicant *wpa_s)
1636 {
1637 struct wpa_bss *bss;
1638
1639 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1640 return;
1641
1642 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1643 const u8 *ssid, *rsn;
1644
1645 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1646 if (ssid == NULL)
1647 continue;
1648
1649 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1650 if (rsn == NULL)
1651 continue;
1652
1653 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1654 }
1655
1656 }
1657
1658
1659 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1660 struct wpa_bss *selected,
1661 struct wpa_ssid *ssid)
1662 {
1663 struct wpa_bss *current_bss = NULL;
1664 #ifndef CONFIG_NO_ROAMING
1665 int min_diff, diff;
1666 int to_5ghz;
1667 int cur_est, sel_est;
1668 #endif /* CONFIG_NO_ROAMING */
1669
1670 if (wpa_s->reassociate)
1671 return 1; /* explicit request to reassociate */
1672 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1673 return 1; /* we are not associated; continue */
1674 if (wpa_s->current_ssid == NULL)
1675 return 1; /* unknown current SSID */
1676 if (wpa_s->current_ssid != ssid)
1677 return 1; /* different network block */
1678
1679 if (wpas_driver_bss_selection(wpa_s))
1680 return 0; /* Driver-based roaming */
1681
1682 if (wpa_s->current_ssid->ssid)
1683 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1684 wpa_s->current_ssid->ssid,
1685 wpa_s->current_ssid->ssid_len);
1686 if (!current_bss)
1687 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1688
1689 if (!current_bss)
1690 return 1; /* current BSS not seen in scan results */
1691
1692 if (current_bss == selected)
1693 return 0;
1694
1695 if (selected->last_update_idx > current_bss->last_update_idx)
1696 return 1; /* current BSS not seen in the last scan */
1697
1698 #ifndef CONFIG_NO_ROAMING
1699 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1700 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1701 " freq=%d level=%d snr=%d est_throughput=%u",
1702 MAC2STR(current_bss->bssid),
1703 current_bss->freq, current_bss->level,
1704 current_bss->snr, current_bss->est_throughput);
1705 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1706 " freq=%d level=%d snr=%d est_throughput=%u",
1707 MAC2STR(selected->bssid), selected->freq, selected->level,
1708 selected->snr, selected->est_throughput);
1709
1710 if (wpa_s->current_ssid->bssid_set &&
1711 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1712 0) {
1713 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1714 "has preferred BSSID");
1715 return 1;
1716 }
1717
1718 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1719 wpa_dbg(wpa_s, MSG_DEBUG,
1720 "Allow reassociation - selected BSS has better estimated throughput");
1721 return 1;
1722 }
1723
1724 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1725
1726 if (current_bss->level < 0 &&
1727 current_bss->level > selected->level + to_5ghz * 2) {
1728 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1729 "signal level");
1730 return 0;
1731 }
1732
1733 if (current_bss->est_throughput > selected->est_throughput + 5000) {
1734 wpa_dbg(wpa_s, MSG_DEBUG,
1735 "Skip roam - Current BSS has better estimated throughput");
1736 return 0;
1737 }
1738
1739 cur_est = current_bss->est_throughput;
1740 sel_est = selected->est_throughput;
1741 min_diff = 2;
1742 if (current_bss->level < 0) {
1743 if (current_bss->level < -85)
1744 min_diff = 1;
1745 else if (current_bss->level < -80)
1746 min_diff = 2;
1747 else if (current_bss->level < -75)
1748 min_diff = 3;
1749 else if (current_bss->level < -70)
1750 min_diff = 4;
1751 else
1752 min_diff = 5;
1753 if (cur_est > sel_est * 1.5)
1754 min_diff += 10;
1755 else if (cur_est > sel_est * 1.2)
1756 min_diff += 5;
1757 else if (cur_est > sel_est * 1.1)
1758 min_diff += 2;
1759 else if (cur_est > sel_est)
1760 min_diff++;
1761 }
1762 if (to_5ghz) {
1763 int reduce = 2;
1764
1765 /* Make it easier to move to 5 GHz band */
1766 if (sel_est > cur_est * 1.5)
1767 reduce = 5;
1768 else if (sel_est > cur_est * 1.2)
1769 reduce = 4;
1770 else if (sel_est > cur_est * 1.1)
1771 reduce = 3;
1772
1773 if (min_diff > reduce)
1774 min_diff -= reduce;
1775 else
1776 min_diff = 0;
1777 }
1778 diff = abs(current_bss->level - selected->level);
1779 if (diff < min_diff) {
1780 wpa_dbg(wpa_s, MSG_DEBUG,
1781 "Skip roam - too small difference in signal level (%d < %d)",
1782 diff, min_diff);
1783 return 0;
1784 }
1785
1786 wpa_dbg(wpa_s, MSG_DEBUG,
1787 "Allow reassociation due to difference in signal level (%d >= %d)",
1788 diff, min_diff);
1789 return 1;
1790 #else /* CONFIG_NO_ROAMING */
1791 return 0;
1792 #endif /* CONFIG_NO_ROAMING */
1793 }
1794
1795
1796 /*
1797 * Return a negative value if no scan results could be fetched or if scan
1798 * results should not be shared with other virtual interfaces.
1799 * Return 0 if scan results were fetched and may be shared with other
1800 * interfaces.
1801 * Return 1 if scan results may be shared with other virtual interfaces but may
1802 * not trigger any operations.
1803 * Return 2 if the interface was removed and cannot be used.
1804 */
1805 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1806 union wpa_event_data *data,
1807 int own_request, int update_only)
1808 {
1809 struct wpa_scan_results *scan_res = NULL;
1810 int ret = 0;
1811 int ap = 0;
1812 #ifndef CONFIG_NO_RANDOM_POOL
1813 size_t i, num;
1814 #endif /* CONFIG_NO_RANDOM_POOL */
1815
1816 #ifdef CONFIG_AP
1817 if (wpa_s->ap_iface)
1818 ap = 1;
1819 #endif /* CONFIG_AP */
1820
1821 wpa_supplicant_notify_scanning(wpa_s, 0);
1822
1823 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1824 data ? &data->scan_info :
1825 NULL, 1);
1826 if (scan_res == NULL) {
1827 if (wpa_s->conf->ap_scan == 2 || ap ||
1828 wpa_s->scan_res_handler == scan_only_handler)
1829 return -1;
1830 if (!own_request)
1831 return -1;
1832 if (data && data->scan_info.external_scan)
1833 return -1;
1834 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1835 "scanning again");
1836 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1837 ret = -1;
1838 goto scan_work_done;
1839 }
1840
1841 #ifndef CONFIG_NO_RANDOM_POOL
1842 num = scan_res->num;
1843 if (num > 10)
1844 num = 10;
1845 for (i = 0; i < num; i++) {
1846 u8 buf[5];
1847 struct wpa_scan_res *res = scan_res->res[i];
1848 buf[0] = res->bssid[5];
1849 buf[1] = res->qual & 0xff;
1850 buf[2] = res->noise & 0xff;
1851 buf[3] = res->level & 0xff;
1852 buf[4] = res->tsf & 0xff;
1853 random_add_randomness(buf, sizeof(buf));
1854 }
1855 #endif /* CONFIG_NO_RANDOM_POOL */
1856
1857 if (update_only) {
1858 ret = 1;
1859 goto scan_work_done;
1860 }
1861
1862 if (own_request && wpa_s->scan_res_handler &&
1863 !(data && data->scan_info.external_scan)) {
1864 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1865 struct wpa_scan_results *scan_res);
1866
1867 scan_res_handler = wpa_s->scan_res_handler;
1868 wpa_s->scan_res_handler = NULL;
1869 scan_res_handler(wpa_s, scan_res);
1870 ret = 1;
1871 goto scan_work_done;
1872 }
1873
1874 if (ap) {
1875 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1876 #ifdef CONFIG_AP
1877 if (wpa_s->ap_iface->scan_cb)
1878 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1879 #endif /* CONFIG_AP */
1880 goto scan_work_done;
1881 }
1882
1883 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1884 wpa_s->own_scan_running,
1885 data ? data->scan_info.external_scan : 0);
1886 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1887 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1888 own_request && !(data && data->scan_info.external_scan)) {
1889 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1890 wpa_s->manual_scan_id);
1891 wpa_s->manual_scan_use_id = 0;
1892 } else {
1893 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1894 }
1895 wpas_notify_scan_results(wpa_s);
1896
1897 wpas_notify_scan_done(wpa_s, 1);
1898
1899 if (data && data->scan_info.external_scan) {
1900 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1901 wpa_scan_results_free(scan_res);
1902 return 0;
1903 }
1904
1905 if (wnm_scan_process(wpa_s, 1) > 0)
1906 goto scan_work_done;
1907
1908 if (sme_proc_obss_scan(wpa_s) > 0)
1909 goto scan_work_done;
1910
1911 if (own_request && data &&
1912 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
1913 goto scan_work_done;
1914
1915 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1916 goto scan_work_done;
1917
1918 if (autoscan_notify_scan(wpa_s, scan_res))
1919 goto scan_work_done;
1920
1921 if (wpa_s->disconnected) {
1922 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1923 goto scan_work_done;
1924 }
1925
1926 if (!wpas_driver_bss_selection(wpa_s) &&
1927 bgscan_notify_scan(wpa_s, scan_res) == 1)
1928 goto scan_work_done;
1929
1930 wpas_wps_update_ap_info(wpa_s, scan_res);
1931
1932 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1933 wpa_s->wpa_state < WPA_COMPLETED)
1934 goto scan_work_done;
1935
1936 wpa_scan_results_free(scan_res);
1937
1938 if (own_request && wpa_s->scan_work) {
1939 struct wpa_radio_work *work = wpa_s->scan_work;
1940 wpa_s->scan_work = NULL;
1941 radio_work_done(work);
1942 }
1943
1944 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1945
1946 scan_work_done:
1947 wpa_scan_results_free(scan_res);
1948 if (own_request && wpa_s->scan_work) {
1949 struct wpa_radio_work *work = wpa_s->scan_work;
1950 wpa_s->scan_work = NULL;
1951 radio_work_done(work);
1952 }
1953 return ret;
1954 }
1955
1956
1957 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1958 int new_scan, int own_request)
1959 {
1960 struct wpa_bss *selected;
1961 struct wpa_ssid *ssid = NULL;
1962 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1963
1964 if (time_to_reenable > 0) {
1965 wpa_dbg(wpa_s, MSG_DEBUG,
1966 "Postpone network selection by %d seconds since all networks are disabled",
1967 time_to_reenable);
1968 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1969 eloop_register_timeout(time_to_reenable, 0,
1970 wpas_network_reenabled, wpa_s, NULL);
1971 return 0;
1972 }
1973
1974 if (wpa_s->p2p_mgmt)
1975 return 0; /* no normal connection on p2p_mgmt interface */
1976
1977 wpa_s->owe_transition_search = 0;
1978 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1979
1980 #ifdef CONFIG_MESH
1981 if (wpa_s->ifmsh) {
1982 wpa_msg(wpa_s, MSG_INFO,
1983 "Avoiding join because we already joined a mesh group");
1984 return 0;
1985 }
1986 #endif /* CONFIG_MESH */
1987
1988 if (selected) {
1989 int skip;
1990 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1991 if (skip) {
1992 if (new_scan)
1993 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1994 return 0;
1995 }
1996
1997 if (ssid != wpa_s->current_ssid &&
1998 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1999 wpa_s->own_disconnect_req = 1;
2000 wpa_supplicant_deauthenticate(
2001 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2002 }
2003
2004 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
2005 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
2006 return -1;
2007 }
2008 if (new_scan)
2009 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2010 /*
2011 * Do not allow other virtual radios to trigger operations based
2012 * on these scan results since we do not want them to start
2013 * other associations at the same time.
2014 */
2015 return 1;
2016 } else {
2017 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2018 ssid = wpa_supplicant_pick_new_network(wpa_s);
2019 if (ssid) {
2020 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2021 wpa_supplicant_associate(wpa_s, NULL, ssid);
2022 if (new_scan)
2023 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2024 } else if (own_request) {
2025 /*
2026 * No SSID found. If SCAN results are as a result of
2027 * own scan request and not due to a scan request on
2028 * another shared interface, try another scan.
2029 */
2030 int timeout_sec = wpa_s->scan_interval;
2031 int timeout_usec = 0;
2032 #ifdef CONFIG_P2P
2033 int res;
2034
2035 res = wpas_p2p_scan_no_go_seen(wpa_s);
2036 if (res == 2)
2037 return 2;
2038 if (res == 1)
2039 return 0;
2040
2041 if (wpa_s->p2p_in_provisioning ||
2042 wpa_s->show_group_started ||
2043 wpa_s->p2p_in_invitation) {
2044 /*
2045 * Use shorter wait during P2P Provisioning
2046 * state and during P2P join-a-group operation
2047 * to speed up group formation.
2048 */
2049 timeout_sec = 0;
2050 timeout_usec = 250000;
2051 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2052 timeout_usec);
2053 return 0;
2054 }
2055 #endif /* CONFIG_P2P */
2056 #ifdef CONFIG_INTERWORKING
2057 if (wpa_s->conf->auto_interworking &&
2058 wpa_s->conf->interworking &&
2059 wpa_s->conf->cred) {
2060 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2061 "start ANQP fetch since no matching "
2062 "networks found");
2063 wpa_s->network_select = 1;
2064 wpa_s->auto_network_select = 1;
2065 interworking_start_fetch_anqp(wpa_s);
2066 return 1;
2067 }
2068 #endif /* CONFIG_INTERWORKING */
2069 #ifdef CONFIG_WPS
2070 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2071 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2072 timeout_sec = 0;
2073 timeout_usec = 500000;
2074 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2075 timeout_usec);
2076 return 0;
2077 }
2078 #endif /* CONFIG_WPS */
2079 #ifdef CONFIG_OWE
2080 if (wpa_s->owe_transition_search) {
2081 wpa_dbg(wpa_s, MSG_DEBUG,
2082 "OWE: Use shorter wait during transition mode search");
2083 timeout_sec = 0;
2084 timeout_usec = 500000;
2085 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2086 timeout_usec);
2087 return 0;
2088 }
2089 #endif /* CONFIG_OWE */
2090 if (wpa_supplicant_req_sched_scan(wpa_s))
2091 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2092 timeout_usec);
2093
2094 wpa_msg_ctrl(wpa_s, MSG_INFO,
2095 WPA_EVENT_NETWORK_NOT_FOUND);
2096 }
2097 }
2098 return 0;
2099 }
2100
2101
2102 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2103 union wpa_event_data *data)
2104 {
2105 struct wpa_supplicant *ifs;
2106 int res;
2107
2108 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
2109 if (res == 2) {
2110 /*
2111 * Interface may have been removed, so must not dereference
2112 * wpa_s after this.
2113 */
2114 return 1;
2115 }
2116
2117 if (res < 0) {
2118 /*
2119 * If no scan results could be fetched, then no need to
2120 * notify those interfaces that did not actually request
2121 * this scan. Similarly, if scan results started a new operation on this
2122 * interface, do not notify other interfaces to avoid concurrent
2123 * operations during a connection attempt.
2124 */
2125 return 0;
2126 }
2127
2128 /*
2129 * Check other interfaces to see if they share the same radio. If
2130 * so, they get updated with this same scan info.
2131 */
2132 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2133 radio_list) {
2134 if (ifs != wpa_s) {
2135 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2136 "sibling", ifs->ifname);
2137 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2138 res > 0);
2139 if (res < 0)
2140 return 0;
2141 }
2142 }
2143
2144 return 0;
2145 }
2146
2147 #endif /* CONFIG_NO_SCAN_PROCESSING */
2148
2149
2150 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2151 {
2152 #ifdef CONFIG_NO_SCAN_PROCESSING
2153 return -1;
2154 #else /* CONFIG_NO_SCAN_PROCESSING */
2155 struct os_reltime now;
2156
2157 wpa_s->ignore_post_flush_scan_res = 0;
2158
2159 if (wpa_s->last_scan_res_used == 0)
2160 return -1;
2161
2162 os_get_reltime(&now);
2163 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
2164 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2165 return -1;
2166 }
2167
2168 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
2169 #endif /* CONFIG_NO_SCAN_PROCESSING */
2170 }
2171
2172 #ifdef CONFIG_WNM
2173
2174 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2175 {
2176 struct wpa_supplicant *wpa_s = eloop_ctx;
2177
2178 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2179 return;
2180
2181 if (!wpa_s->no_keep_alive) {
2182 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2183 MAC2STR(wpa_s->bssid));
2184 /* TODO: could skip this if normal data traffic has been sent */
2185 /* TODO: Consider using some more appropriate data frame for
2186 * this */
2187 if (wpa_s->l2)
2188 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2189 (u8 *) "", 0);
2190 }
2191
2192 #ifdef CONFIG_SME
2193 if (wpa_s->sme.bss_max_idle_period) {
2194 unsigned int msec;
2195 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2196 if (msec > 100)
2197 msec -= 100;
2198 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2199 wnm_bss_keep_alive, wpa_s, NULL);
2200 }
2201 #endif /* CONFIG_SME */
2202 }
2203
2204
2205 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2206 const u8 *ies, size_t ies_len)
2207 {
2208 struct ieee802_11_elems elems;
2209
2210 if (ies == NULL)
2211 return;
2212
2213 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2214 return;
2215
2216 #ifdef CONFIG_SME
2217 if (elems.bss_max_idle_period) {
2218 unsigned int msec;
2219 wpa_s->sme.bss_max_idle_period =
2220 WPA_GET_LE16(elems.bss_max_idle_period);
2221 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2222 "TU)%s", wpa_s->sme.bss_max_idle_period,
2223 (elems.bss_max_idle_period[2] & 0x01) ?
2224 " (protected keep-live required)" : "");
2225 if (wpa_s->sme.bss_max_idle_period == 0)
2226 wpa_s->sme.bss_max_idle_period = 1;
2227 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2228 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2229 /* msec times 1000 */
2230 msec = wpa_s->sme.bss_max_idle_period * 1024;
2231 if (msec > 100)
2232 msec -= 100;
2233 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2234 wnm_bss_keep_alive, wpa_s,
2235 NULL);
2236 }
2237 }
2238 #endif /* CONFIG_SME */
2239 }
2240
2241 #endif /* CONFIG_WNM */
2242
2243
2244 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2245 {
2246 #ifdef CONFIG_WNM
2247 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2248 #endif /* CONFIG_WNM */
2249 }
2250
2251
2252 #ifdef CONFIG_INTERWORKING
2253
2254 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2255 size_t len)
2256 {
2257 int res;
2258
2259 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2260 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2261 if (res) {
2262 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2263 }
2264
2265 return res;
2266 }
2267
2268
2269 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2270 const u8 *ies, size_t ies_len)
2271 {
2272 struct ieee802_11_elems elems;
2273
2274 if (ies == NULL)
2275 return;
2276
2277 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2278 return;
2279
2280 if (elems.qos_map_set) {
2281 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2282 elems.qos_map_set_len);
2283 }
2284 }
2285
2286 #endif /* CONFIG_INTERWORKING */
2287
2288
2289 static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2290 const u8 *ies, size_t ies_len)
2291 {
2292 struct ieee802_11_elems elems;
2293 const u8 *map_sub_elem, *pos;
2294 size_t len;
2295
2296 if (!wpa_s->current_ssid ||
2297 !wpa_s->current_ssid->multi_ap_backhaul_sta ||
2298 !ies ||
2299 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2300 return;
2301
2302 if (!elems.multi_ap || elems.multi_ap_len < 7) {
2303 wpa_printf(MSG_INFO, "AP doesn't support Multi-AP protocol");
2304 goto fail;
2305 }
2306
2307 pos = elems.multi_ap + 4;
2308 len = elems.multi_ap_len - 4;
2309
2310 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
2311 if (!map_sub_elem || map_sub_elem[1] < 1) {
2312 wpa_printf(MSG_INFO, "invalid Multi-AP sub elem type");
2313 goto fail;
2314 }
2315
2316 if (!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS)) {
2317 if ((map_sub_elem[2] & MULTI_AP_FRONTHAUL_BSS) &&
2318 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2319 wpa_printf(MSG_INFO,
2320 "WPS active, accepting fronthaul-only BSS");
2321 /* Don't set 4addr mode in this case, so just return */
2322 return;
2323 }
2324 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2325 goto fail;
2326 }
2327
2328 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2329 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2330 goto fail;
2331 }
2332 wpa_s->enabled_4addr_mode = 1;
2333 return;
2334
2335 fail:
2336 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2337 }
2338
2339
2340 #ifdef CONFIG_FST
2341 static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2342 const u8 *ie, size_t ie_len)
2343 {
2344 struct mb_ies_info mb_ies;
2345
2346 if (!ie || !ie_len || !wpa_s->fst)
2347 return -ENOENT;
2348
2349 os_memset(&mb_ies, 0, sizeof(mb_ies));
2350
2351 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2352 size_t len;
2353
2354 len = 2 + ie[1];
2355 if (len > ie_len) {
2356 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2357 ie, ie_len);
2358 break;
2359 }
2360
2361 if (ie[0] == WLAN_EID_MULTI_BAND) {
2362 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2363 (unsigned int) len);
2364 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2365 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2366 mb_ies.nof_ies++;
2367 }
2368
2369 ie_len -= len;
2370 ie += len;
2371 }
2372
2373 if (mb_ies.nof_ies > 0) {
2374 wpabuf_free(wpa_s->received_mb_ies);
2375 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2376 return 0;
2377 }
2378
2379 return -ENOENT;
2380 }
2381 #endif /* CONFIG_FST */
2382
2383
2384 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2385 union wpa_event_data *data)
2386 {
2387 int l, len, found = 0, wpa_found, rsn_found;
2388 const u8 *p;
2389 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
2390 u8 bssid[ETH_ALEN];
2391 #endif /* CONFIG_IEEE80211R || CONFIG_OWE */
2392
2393 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
2394 if (data->assoc_info.req_ies)
2395 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2396 data->assoc_info.req_ies_len);
2397 if (data->assoc_info.resp_ies) {
2398 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2399 data->assoc_info.resp_ies_len);
2400 #ifdef CONFIG_TDLS
2401 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2402 data->assoc_info.resp_ies_len);
2403 #endif /* CONFIG_TDLS */
2404 #ifdef CONFIG_WNM
2405 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2406 data->assoc_info.resp_ies_len);
2407 #endif /* CONFIG_WNM */
2408 #ifdef CONFIG_INTERWORKING
2409 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2410 data->assoc_info.resp_ies_len);
2411 #endif /* CONFIG_INTERWORKING */
2412 if (wpa_s->hw_capab == CAPAB_VHT &&
2413 get_ie(data->assoc_info.resp_ies,
2414 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2415 wpa_s->ieee80211ac = 1;
2416
2417 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2418 data->assoc_info.resp_ies_len);
2419 }
2420 if (data->assoc_info.beacon_ies)
2421 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2422 data->assoc_info.beacon_ies,
2423 data->assoc_info.beacon_ies_len);
2424 if (data->assoc_info.freq)
2425 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2426 data->assoc_info.freq);
2427
2428 wpa_s->connection_set = 0;
2429 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2430 struct ieee802_11_elems req_elems, resp_elems;
2431
2432 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2433 data->assoc_info.req_ies_len,
2434 &req_elems, 0) != ParseFailed &&
2435 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2436 data->assoc_info.resp_ies_len,
2437 &resp_elems, 0) != ParseFailed) {
2438 wpa_s->connection_set = 1;
2439 wpa_s->connection_ht = req_elems.ht_capabilities &&
2440 resp_elems.ht_capabilities;
2441 wpa_s->connection_vht = req_elems.vht_capabilities &&
2442 resp_elems.vht_capabilities;
2443 wpa_s->connection_he = req_elems.he_capabilities &&
2444 resp_elems.he_capabilities;
2445 }
2446 }
2447
2448 p = data->assoc_info.req_ies;
2449 l = data->assoc_info.req_ies_len;
2450
2451 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2452 while (p && l >= 2) {
2453 len = p[1] + 2;
2454 if (len > l) {
2455 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2456 p, l);
2457 break;
2458 }
2459 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2460 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2461 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2462 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2463 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
2464 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2465 break;
2466 found = 1;
2467 wpa_find_assoc_pmkid(wpa_s);
2468 break;
2469 }
2470 l -= len;
2471 p += len;
2472 }
2473 if (!found && data->assoc_info.req_ies)
2474 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
2475
2476 #ifdef CONFIG_FILS
2477 #ifdef CONFIG_SME
2478 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2479 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
2480 (!data->assoc_info.resp_frame ||
2481 fils_process_assoc_resp(wpa_s->wpa,
2482 data->assoc_info.resp_frame,
2483 data->assoc_info.resp_frame_len) < 0)) {
2484 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2485 return -1;
2486 }
2487 #endif /* CONFIG_SME */
2488
2489 /* Additional processing for FILS when SME is in driver */
2490 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2491 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2492 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
2493 #endif /* CONFIG_FILS */
2494
2495 #ifdef CONFIG_OWE
2496 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
2497 (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2498 owe_process_assoc_resp(wpa_s->wpa, bssid,
2499 data->assoc_info.resp_ies,
2500 data->assoc_info.resp_ies_len) < 0)) {
2501 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2502 return -1;
2503 }
2504 #endif /* CONFIG_OWE */
2505
2506 #ifdef CONFIG_DPP2
2507 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
2508 if (wpa_s->key_mgmt == WPA_KEY_MGMT_DPP && wpa_s->dpp_pfs) {
2509 struct ieee802_11_elems elems;
2510
2511 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2512 data->assoc_info.resp_ies_len,
2513 &elems, 0) == ParseFailed ||
2514 !elems.owe_dh)
2515 goto no_pfs;
2516 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2517 elems.owe_dh_len) < 0) {
2518 wpa_supplicant_deauthenticate(wpa_s,
2519 WLAN_REASON_UNSPECIFIED);
2520 return -1;
2521 }
2522
2523 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2524 }
2525 no_pfs:
2526 #endif /* CONFIG_DPP2 */
2527
2528 #ifdef CONFIG_IEEE80211R
2529 #ifdef CONFIG_SME
2530 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
2531 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2532 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2533 data->assoc_info.resp_ies,
2534 data->assoc_info.resp_ies_len,
2535 bssid) < 0) {
2536 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2537 "Reassociation Response failed");
2538 wpa_supplicant_deauthenticate(
2539 wpa_s, WLAN_REASON_INVALID_IE);
2540 return -1;
2541 }
2542 }
2543
2544 p = data->assoc_info.resp_ies;
2545 l = data->assoc_info.resp_ies_len;
2546
2547 #ifdef CONFIG_WPS_STRICT
2548 if (p && wpa_s->current_ssid &&
2549 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2550 struct wpabuf *wps;
2551 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2552 if (wps == NULL) {
2553 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2554 "include WPS IE in (Re)Association Response");
2555 return -1;
2556 }
2557
2558 if (wps_validate_assoc_resp(wps) < 0) {
2559 wpabuf_free(wps);
2560 wpa_supplicant_deauthenticate(
2561 wpa_s, WLAN_REASON_INVALID_IE);
2562 return -1;
2563 }
2564 wpabuf_free(wps);
2565 }
2566 #endif /* CONFIG_WPS_STRICT */
2567
2568 /* Go through the IEs and make a copy of the MDIE, if present. */
2569 while (p && l >= 2) {
2570 len = p[1] + 2;
2571 if (len > l) {
2572 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2573 p, l);
2574 break;
2575 }
2576 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2577 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2578 wpa_s->sme.ft_used = 1;
2579 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2580 MOBILITY_DOMAIN_ID_LEN);
2581 break;
2582 }
2583 l -= len;
2584 p += len;
2585 }
2586 #endif /* CONFIG_SME */
2587
2588 /* Process FT when SME is in the driver */
2589 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2590 wpa_ft_is_completed(wpa_s->wpa)) {
2591 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2592 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2593 data->assoc_info.resp_ies,
2594 data->assoc_info.resp_ies_len,
2595 bssid) < 0) {
2596 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2597 "Reassociation Response failed");
2598 wpa_supplicant_deauthenticate(
2599 wpa_s, WLAN_REASON_INVALID_IE);
2600 return -1;
2601 }
2602 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2603 }
2604
2605 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2606 data->assoc_info.resp_ies_len);
2607 #endif /* CONFIG_IEEE80211R */
2608
2609 /* WPA/RSN IE from Beacon/ProbeResp */
2610 p = data->assoc_info.beacon_ies;
2611 l = data->assoc_info.beacon_ies_len;
2612
2613 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2614 */
2615 wpa_found = rsn_found = 0;
2616 while (p && l >= 2) {
2617 len = p[1] + 2;
2618 if (len > l) {
2619 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2620 p, l);
2621 break;
2622 }
2623 if (!wpa_found &&
2624 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2625 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2626 wpa_found = 1;
2627 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2628 }
2629
2630 if (!rsn_found &&
2631 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2632 rsn_found = 1;
2633 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2634 }
2635
2636 l -= len;
2637 p += len;
2638 }
2639
2640 if (!wpa_found && data->assoc_info.beacon_ies)
2641 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2642 if (!rsn_found && data->assoc_info.beacon_ies)
2643 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2644 if (wpa_found || rsn_found)
2645 wpa_s->ap_ies_from_associnfo = 1;
2646
2647 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2648 wpa_s->assoc_freq != data->assoc_info.freq) {
2649 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2650 "%u to %u MHz",
2651 wpa_s->assoc_freq, data->assoc_info.freq);
2652 wpa_supplicant_update_scan_results(wpa_s);
2653 }
2654
2655 wpa_s->assoc_freq = data->assoc_info.freq;
2656
2657 return 0;
2658 }
2659
2660
2661 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2662 {
2663 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2664
2665 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2666 return -1;
2667
2668 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2669 return 0;
2670
2671 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2672 WPA_IE_VENDOR_TYPE);
2673 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2674
2675 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2676 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2677 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2678 bss_rsn ? 2 + bss_rsn[1] : 0))
2679 return -1;
2680
2681 return 0;
2682 }
2683
2684
2685 static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2686 union wpa_event_data *data)
2687 {
2688 #ifdef CONFIG_FST
2689 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2690 struct wpa_bss *bss = wpa_s->current_bss;
2691 const u8 *ieprb, *iebcn;
2692
2693 wpabuf_free(wpa_s->received_mb_ies);
2694 wpa_s->received_mb_ies = NULL;
2695
2696 if (ai &&
2697 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2698 wpa_printf(MSG_DEBUG,
2699 "FST: MB IEs updated from Association Response frame");
2700 return;
2701 }
2702
2703 if (ai &&
2704 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2705 wpa_printf(MSG_DEBUG,
2706 "FST: MB IEs updated from association event Beacon IEs");
2707 return;
2708 }
2709
2710 if (!bss)
2711 return;
2712
2713 ieprb = (const u8 *) (bss + 1);
2714 iebcn = ieprb + bss->ie_len;
2715
2716 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2717 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2718 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2719 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2720 #endif /* CONFIG_FST */
2721 }
2722
2723
2724 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2725 union wpa_event_data *data)
2726 {
2727 u8 bssid[ETH_ALEN];
2728 int ft_completed, already_authorized;
2729 int new_bss = 0;
2730
2731 #ifdef CONFIG_AP
2732 if (wpa_s->ap_iface) {
2733 if (!data)
2734 return;
2735 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2736 data->assoc_info.addr,
2737 data->assoc_info.req_ies,
2738 data->assoc_info.req_ies_len,
2739 data->assoc_info.reassoc);
2740 return;
2741 }
2742 #endif /* CONFIG_AP */
2743
2744 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2745
2746 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2747 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2748 return;
2749 /*
2750 * FILS authentication can share the same mechanism to mark the
2751 * connection fully authenticated, so set ft_completed also based on
2752 * FILS result.
2753 */
2754 if (!ft_completed)
2755 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
2756
2757 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2758 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2759 wpa_supplicant_deauthenticate(
2760 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2761 return;
2762 }
2763
2764 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2765 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2766 if (os_reltime_initialized(&wpa_s->session_start)) {
2767 os_reltime_age(&wpa_s->session_start,
2768 &wpa_s->session_length);
2769 wpa_s->session_start.sec = 0;
2770 wpa_s->session_start.usec = 0;
2771 wpas_notify_session_length(wpa_s);
2772 } else {
2773 wpas_notify_auth_changed(wpa_s);
2774 os_get_reltime(&wpa_s->session_start);
2775 }
2776 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2777 MACSTR, MAC2STR(bssid));
2778 new_bss = 1;
2779 random_add_randomness(bssid, ETH_ALEN);
2780 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2781 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2782 wpas_notify_bssid_changed(wpa_s);
2783
2784 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2785 wpa_clear_keys(wpa_s, bssid);
2786 }
2787 if (wpa_supplicant_select_config(wpa_s) < 0) {
2788 wpa_supplicant_deauthenticate(
2789 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2790 return;
2791 }
2792 }
2793
2794 if (wpa_s->conf->ap_scan == 1 &&
2795 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2796 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2797 wpa_msg(wpa_s, MSG_WARNING,
2798 "WPA/RSN IEs not updated");
2799 }
2800
2801 wpas_fst_update_mb_assoc(wpa_s, data);
2802
2803 #ifdef CONFIG_SME
2804 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2805 wpa_s->sme.prev_bssid_set = 1;
2806 wpa_s->sme.last_unprot_disconnect.sec = 0;
2807 #endif /* CONFIG_SME */
2808
2809 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2810 if (wpa_s->current_ssid) {
2811 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2812 * initialized before association, but for other modes,
2813 * initialize PC/SC here, if the current configuration needs
2814 * smartcard or SIM/USIM. */
2815 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2816 }
2817 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2818 if (wpa_s->l2)
2819 l2_packet_notify_auth_start(wpa_s->l2);
2820
2821 already_authorized = data && data->assoc_info.authorized;
2822
2823 /*
2824 * Set portEnabled first to FALSE in order to get EAP state machine out
2825 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2826 * state machine may transit to AUTHENTICATING state based on obsolete
2827 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2828 * AUTHENTICATED without ever giving chance to EAP state machine to
2829 * reset the state.
2830 */
2831 if (!ft_completed && !already_authorized) {
2832 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2833 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2834 }
2835 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
2836 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
2837 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
2838 already_authorized || wpa_s->drv_authorized_port)
2839 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2840 /* 802.1X::portControl = Auto */
2841 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2842 wpa_s->eapol_received = 0;
2843 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2844 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2845 (wpa_s->current_ssid &&
2846 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
2847 if (wpa_s->current_ssid &&
2848 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2849 (wpa_s->drv_flags &
2850 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2851 /*
2852 * Set the key after having received joined-IBSS event
2853 * from the driver.
2854 */
2855 wpa_supplicant_set_wpa_none_key(wpa_s,
2856 wpa_s->current_ssid);
2857 }
2858 wpa_supplicant_cancel_auth_timeout(wpa_s);
2859 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2860 } else if (!ft_completed) {
2861 /* Timeout for receiving the first EAPOL packet */
2862 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2863 }
2864 wpa_supplicant_cancel_scan(wpa_s);
2865
2866 if (ft_completed) {
2867 /*
2868 * FT protocol completed - make sure EAPOL state machine ends
2869 * up in authenticated.
2870 */
2871 wpa_supplicant_cancel_auth_timeout(wpa_s);
2872 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2873 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2874 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2875 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
2876 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2877 /*
2878 * We are done; the driver will take care of RSN 4-way
2879 * handshake.
2880 */
2881 wpa_supplicant_cancel_auth_timeout(wpa_s);
2882 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2883 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2884 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2885 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
2886 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2887 /*
2888 * The driver will take care of RSN 4-way handshake, so we need
2889 * to allow EAPOL supplicant to complete its work without
2890 * waiting for WPA supplicant.
2891 */
2892 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2893 }
2894
2895 wpa_s->last_eapol_matches_bssid = 0;
2896
2897 if (wpa_s->pending_eapol_rx) {
2898 struct os_reltime now, age;
2899 os_get_reltime(&now);
2900 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2901 if (age.sec == 0 && age.usec < 200000 &&
2902 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2903 0) {
2904 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2905 "frame that was received just before "
2906 "association notification");
2907 wpa_supplicant_rx_eapol(
2908 wpa_s, wpa_s->pending_eapol_rx_src,
2909 wpabuf_head(wpa_s->pending_eapol_rx),
2910 wpabuf_len(wpa_s->pending_eapol_rx));
2911 }
2912 wpabuf_free(wpa_s->pending_eapol_rx);
2913 wpa_s->pending_eapol_rx = NULL;
2914 }
2915
2916 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2917 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2918 wpa_s->current_ssid &&
2919 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2920 /* Set static WEP keys again */
2921 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2922 }
2923
2924 #ifdef CONFIG_IBSS_RSN
2925 if (wpa_s->current_ssid &&
2926 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2927 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2928 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2929 wpa_s->ibss_rsn == NULL) {
2930 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
2931 if (!wpa_s->ibss_rsn) {
2932 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2933 wpa_supplicant_deauthenticate(
2934 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2935 return;
2936 }
2937
2938 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2939 }
2940 #endif /* CONFIG_IBSS_RSN */
2941
2942 wpas_wps_notify_assoc(wpa_s, bssid);
2943
2944 if (data) {
2945 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2946 data->assoc_info.resp_ies_len,
2947 &data->assoc_info.wmm_params);
2948
2949 if (wpa_s->reassoc_same_bss)
2950 wmm_ac_restore_tspecs(wpa_s);
2951 }
2952
2953 #ifdef CONFIG_FILS
2954 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
2955 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid);
2956 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
2957
2958 if (fils_cache_id)
2959 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
2960 }
2961 #endif /* CONFIG_FILS */
2962 }
2963
2964
2965 static int disconnect_reason_recoverable(u16 reason_code)
2966 {
2967 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2968 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2969 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2970 }
2971
2972
2973 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2974 u16 reason_code,
2975 int locally_generated)
2976 {
2977 const u8 *bssid;
2978
2979 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2980 /*
2981 * At least Host AP driver and a Prism3 card seemed to be
2982 * generating streams of disconnected events when configuring
2983 * IBSS for WPA-None. Ignore them for now.
2984 */
2985 return;
2986 }
2987
2988 bssid = wpa_s->bssid;
2989 if (is_zero_ether_addr(bssid))
2990 bssid = wpa_s->pending_bssid;
2991
2992 if (!is_zero_ether_addr(bssid) ||
2993 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2994 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2995 " reason=%d%s",
2996 MAC2STR(bssid), reason_code,
2997 locally_generated ? " locally_generated=1" : "");
2998 }
2999 }
3000
3001
3002 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3003 int locally_generated)
3004 {
3005 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
3006 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
3007 return 0; /* Not in 4-way handshake with PSK */
3008
3009 /*
3010 * It looks like connection was lost while trying to go through PSK
3011 * 4-way handshake. Filter out known disconnection cases that are caused
3012 * by something else than PSK mismatch to avoid confusing reports.
3013 */
3014
3015 if (locally_generated) {
3016 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3017 return 0;
3018 }
3019
3020 return 1;
3021 }
3022
3023
3024 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3025 u16 reason_code,
3026 int locally_generated)
3027 {
3028 const u8 *bssid;
3029 int authenticating;
3030 u8 prev_pending_bssid[ETH_ALEN];
3031 struct wpa_bss *fast_reconnect = NULL;
3032 struct wpa_ssid *fast_reconnect_ssid = NULL;
3033 struct wpa_ssid *last_ssid;
3034 struct wpa_bss *curr = NULL;
3035
3036 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3037 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3038
3039 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3040 /*
3041 * At least Host AP driver and a Prism3 card seemed to be
3042 * generating streams of disconnected events when configuring
3043 * IBSS for WPA-None. Ignore them for now.
3044 */
3045 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3046 "IBSS/WPA-None mode");
3047 return;
3048 }
3049
3050 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3051 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3052 locally_generated)
3053 /*
3054 * Remove the inactive AP (which is probably out of range) from
3055 * the BSS list after marking disassociation. In particular
3056 * mac80211-based drivers use the
3057 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3058 * locally generated disconnection events for cases where the
3059 * AP does not reply anymore.
3060 */
3061 curr = wpa_s->current_bss;
3062
3063 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
3064 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3065 "pre-shared key may be incorrect");
3066 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3067 return; /* P2P group removed */
3068 wpas_auth_failed(wpa_s, "WRONG_KEY");
3069 }
3070 if (!wpa_s->disconnected &&
3071 (!wpa_s->auto_reconnect_disabled ||
3072 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
3073 wpas_wps_searching(wpa_s) ||
3074 wpas_wps_reenable_networks_pending(wpa_s))) {
3075 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
3076 "reconnect (wps=%d/%d wpa_state=%d)",
3077 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
3078 wpas_wps_searching(wpa_s),
3079 wpa_s->wpa_state);
3080 if (wpa_s->wpa_state == WPA_COMPLETED &&
3081 wpa_s->current_ssid &&
3082 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
3083 !locally_generated &&
3084 disconnect_reason_recoverable(reason_code)) {
3085 /*
3086 * It looks like the AP has dropped association with
3087 * us, but could allow us to get back in. Try to
3088 * reconnect to the same BSS without full scan to save
3089 * time for some common cases.
3090 */
3091 fast_reconnect = wpa_s->current_bss;
3092 fast_reconnect_ssid = wpa_s->current_ssid;
3093 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
3094 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3095 else
3096 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3097 "immediate scan");
3098 } else {
3099 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
3100 "try to re-connect");
3101 wpa_s->reassociate = 0;
3102 wpa_s->disconnected = 1;
3103 if (!wpa_s->pno)
3104 wpa_supplicant_cancel_sched_scan(wpa_s);
3105 }
3106 bssid = wpa_s->bssid;
3107 if (is_zero_ether_addr(bssid))
3108 bssid = wpa_s->pending_bssid;
3109 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3110 wpas_connection_failed(wpa_s, bssid);
3111 wpa_sm_notify_disassoc(wpa_s->wpa);
3112 if (locally_generated)
3113 wpa_s->disconnect_reason = -reason_code;
3114 else
3115 wpa_s->disconnect_reason = reason_code;
3116 wpas_notify_disconnect_reason(wpa_s);
3117 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3118 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
3119 wpa_clear_keys(wpa_s, wpa_s->bssid);
3120 }
3121 last_ssid = wpa_s->current_ssid;
3122 wpa_supplicant_mark_disassoc(wpa_s);
3123
3124 if (curr)
3125 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3126
3127 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
3128 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
3129 wpa_s->current_ssid = last_ssid;
3130 }
3131
3132 if (fast_reconnect &&
3133 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3134 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3135 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3136 fast_reconnect->ssid_len) &&
3137 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
3138 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
3139 #ifndef CONFIG_NO_SCAN_PROCESSING
3140 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3141 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3142 fast_reconnect_ssid) < 0) {
3143 /* Recover through full scan */
3144 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3145 }
3146 #endif /* CONFIG_NO_SCAN_PROCESSING */
3147 } else if (fast_reconnect) {
3148 /*
3149 * Could not reconnect to the same BSS due to network being
3150 * disabled. Use a new scan to match the alternative behavior
3151 * above, i.e., to continue automatic reconnection attempt in a
3152 * way that enforces disabled network rules.
3153 */
3154 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3155 }
3156 }
3157
3158
3159 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3160 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
3161 {
3162 struct wpa_supplicant *wpa_s = eloop_ctx;
3163
3164 if (!wpa_s->pending_mic_error_report)
3165 return;
3166
3167 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3168 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3169 wpa_s->pending_mic_error_report = 0;
3170 }
3171 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3172
3173
3174 static void
3175 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3176 union wpa_event_data *data)
3177 {
3178 int pairwise;
3179 struct os_reltime t;
3180
3181 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3182 pairwise = (data && data->michael_mic_failure.unicast);
3183 os_get_reltime(&t);
3184 if ((wpa_s->last_michael_mic_error.sec &&
3185 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
3186 wpa_s->pending_mic_error_report) {
3187 if (wpa_s->pending_mic_error_report) {
3188 /*
3189 * Send the pending MIC error report immediately since
3190 * we are going to start countermeasures and AP better
3191 * do the same.
3192 */
3193 wpa_sm_key_request(wpa_s->wpa, 1,
3194 wpa_s->pending_mic_error_pairwise);
3195 }
3196
3197 /* Send the new MIC error report immediately since we are going
3198 * to start countermeasures and AP better do the same.
3199 */
3200 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3201
3202 /* initialize countermeasures */
3203 wpa_s->countermeasures = 1;
3204
3205 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3206
3207 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3208
3209 /*
3210 * Need to wait for completion of request frame. We do not get
3211 * any callback for the message completion, so just wait a
3212 * short while and hope for the best. */
3213 os_sleep(0, 10000);
3214
3215 wpa_drv_set_countermeasures(wpa_s, 1);
3216 wpa_supplicant_deauthenticate(wpa_s,
3217 WLAN_REASON_MICHAEL_MIC_FAILURE);
3218 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3219 wpa_s, NULL);
3220 eloop_register_timeout(60, 0,
3221 wpa_supplicant_stop_countermeasures,
3222 wpa_s, NULL);
3223 /* TODO: mark the AP rejected for 60 second. STA is
3224 * allowed to associate with another AP.. */
3225 } else {
3226 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3227 if (wpa_s->mic_errors_seen) {
3228 /*
3229 * Reduce the effectiveness of Michael MIC error
3230 * reports as a means for attacking against TKIP if
3231 * more than one MIC failure is noticed with the same
3232 * PTK. We delay the transmission of the reports by a
3233 * random time between 0 and 60 seconds in order to
3234 * force the attacker wait 60 seconds before getting
3235 * the information on whether a frame resulted in a MIC
3236 * failure.
3237 */
3238 u8 rval[4];
3239 int sec;
3240
3241 if (os_get_random(rval, sizeof(rval)) < 0)
3242 sec = os_random() % 60;
3243 else
3244 sec = WPA_GET_BE32(rval) % 60;
3245 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3246 "report %d seconds", sec);
3247 wpa_s->pending_mic_error_report = 1;
3248 wpa_s->pending_mic_error_pairwise = pairwise;
3249 eloop_cancel_timeout(
3250 wpa_supplicant_delayed_mic_error_report,
3251 wpa_s, NULL);
3252 eloop_register_timeout(
3253 sec, os_random() % 1000000,
3254 wpa_supplicant_delayed_mic_error_report,
3255 wpa_s, NULL);
3256 } else {
3257 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3258 }
3259 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3260 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3261 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3262 }
3263 wpa_s->last_michael_mic_error = t;
3264 wpa_s->mic_errors_seen++;
3265 }
3266
3267
3268 #ifdef CONFIG_TERMINATE_ONLASTIF
3269 static int any_interfaces(struct wpa_supplicant *head)
3270 {
3271 struct wpa_supplicant *wpa_s;
3272
3273 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3274 if (!wpa_s->interface_removed)
3275 return 1;
3276 return 0;
3277 }
3278 #endif /* CONFIG_TERMINATE_ONLASTIF */
3279
3280
3281 static void
3282 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3283 union wpa_event_data *data)
3284 {
3285 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3286 return;
3287
3288 switch (data->interface_status.ievent) {
3289 case EVENT_INTERFACE_ADDED:
3290 if (!wpa_s->interface_removed)
3291 break;
3292 wpa_s->interface_removed = 0;
3293 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3294 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3295 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3296 "driver after interface was added");
3297 }
3298
3299 #ifdef CONFIG_P2P
3300 if (!wpa_s->global->p2p &&
3301 !wpa_s->global->p2p_disabled &&
3302 !wpa_s->conf->p2p_disabled &&
3303 (wpa_s->drv_flags &
3304 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3305 wpas_p2p_add_p2pdev_interface(
3306 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3307 wpa_printf(MSG_INFO,
3308 "P2P: Failed to enable P2P Device interface");
3309 /* Try to continue without. P2P will be disabled. */
3310 }
3311 #endif /* CONFIG_P2P */
3312
3313 break;
3314 case EVENT_INTERFACE_REMOVED:
3315 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3316 wpa_s->interface_removed = 1;
3317 wpa_supplicant_mark_disassoc(wpa_s);
3318 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3319 l2_packet_deinit(wpa_s->l2);
3320 wpa_s->l2 = NULL;
3321
3322 #ifdef CONFIG_P2P
3323 if (wpa_s->global->p2p &&
3324 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3325 (wpa_s->drv_flags &
3326 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3327 wpa_dbg(wpa_s, MSG_DEBUG,
3328 "Removing P2P Device interface");
3329 wpa_supplicant_remove_iface(
3330 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3331 0);
3332 wpa_s->global->p2p_init_wpa_s = NULL;
3333 }
3334 #endif /* CONFIG_P2P */
3335
3336 #ifdef CONFIG_MATCH_IFACE
3337 if (wpa_s->matched) {
3338 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3339 break;
3340 }
3341 #endif /* CONFIG_MATCH_IFACE */
3342
3343 #ifdef CONFIG_TERMINATE_ONLASTIF
3344 /* check if last interface */
3345 if (!any_interfaces(wpa_s->global->ifaces))
3346 eloop_terminate();
3347 #endif /* CONFIG_TERMINATE_ONLASTIF */
3348 break;
3349 }
3350 }
3351
3352
3353 #ifdef CONFIG_TDLS
3354 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3355 union wpa_event_data *data)
3356 {
3357 if (data == NULL)
3358 return;
3359 switch (data->tdls.oper) {
3360 case TDLS_REQUEST_SETUP:
3361 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3362 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3363 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3364 else
3365 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
3366 break;
3367 case TDLS_REQUEST_TEARDOWN:
3368 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3369 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3370 data->tdls.reason_code);
3371 else
3372 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3373 data->tdls.peer);
3374 break;
3375 case TDLS_REQUEST_DISCOVER:
3376 wpa_tdls_send_discovery_request(wpa_s->wpa,
3377 data->tdls.peer);
3378 break;
3379 }
3380 }
3381 #endif /* CONFIG_TDLS */
3382
3383
3384 #ifdef CONFIG_WNM
3385 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3386 union wpa_event_data *data)
3387 {
3388 if (data == NULL)
3389 return;
3390 switch (data->wnm.oper) {
3391 case WNM_OPER_SLEEP:
3392 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3393 "(action=%d, intval=%d)",
3394 data->wnm.sleep_action, data->wnm.sleep_intval);
3395 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
3396 data->wnm.sleep_intval, NULL);
3397 break;
3398 }
3399 }
3400 #endif /* CONFIG_WNM */
3401
3402
3403 #ifdef CONFIG_IEEE80211R
3404 static void
3405 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3406 union wpa_event_data *data)
3407 {
3408 if (data == NULL)
3409 return;
3410
3411 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3412 data->ft_ies.ies_len,
3413 data->ft_ies.ft_action,
3414 data->ft_ies.target_ap,
3415 data->ft_ies.ric_ies,
3416 data->ft_ies.ric_ies_len) < 0) {
3417 /* TODO: prevent MLME/driver from trying to associate? */
3418 }
3419 }
3420 #endif /* CONFIG_IEEE80211R */
3421
3422
3423 #ifdef CONFIG_IBSS_RSN
3424 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3425 union wpa_event_data *data)
3426 {
3427 struct wpa_ssid *ssid;
3428 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3429 return;
3430 if (data == NULL)
3431 return;
3432 ssid = wpa_s->current_ssid;
3433 if (ssid == NULL)
3434 return;
3435 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3436 return;
3437
3438 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3439 }
3440
3441
3442 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3443 union wpa_event_data *data)
3444 {
3445 struct wpa_ssid *ssid = wpa_s->current_ssid;
3446
3447 if (ssid == NULL)
3448 return;
3449
3450 /* check if the ssid is correctly configured as IBSS/RSN */
3451 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3452 return;
3453
3454 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3455 data->rx_mgmt.frame_len);
3456 }
3457 #endif /* CONFIG_IBSS_RSN */
3458
3459
3460 #ifdef CONFIG_IEEE80211R
3461 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3462 size_t len)
3463 {
3464 const u8 *sta_addr, *target_ap_addr;
3465 u16 status;
3466
3467 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3468 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3469 return; /* only SME case supported for now */
3470 if (len < 1 + 2 * ETH_ALEN + 2)
3471 return;
3472 if (data[0] != 2)
3473 return; /* Only FT Action Response is supported for now */
3474 sta_addr = data + 1;
3475 target_ap_addr = data + 1 + ETH_ALEN;
3476 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3477 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3478 MACSTR " TargetAP " MACSTR " status %u",
3479 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3480
3481 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3482 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3483 " in FT Action Response", MAC2STR(sta_addr));
3484 return;
3485 }
3486
3487 if (status) {
3488 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3489 "failure (status code %d)", status);
3490 /* TODO: report error to FT code(?) */
3491 return;
3492 }
3493
3494 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3495 len - (1 + 2 * ETH_ALEN + 2), 1,
3496 target_ap_addr, NULL, 0) < 0)
3497 return;
3498
3499 #ifdef CONFIG_SME
3500 {
3501 struct wpa_bss *bss;
3502 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3503 if (bss)
3504 wpa_s->sme.freq = bss->freq;
3505 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3506 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3507 WLAN_AUTH_FT);
3508 }
3509 #endif /* CONFIG_SME */
3510 }
3511 #endif /* CONFIG_IEEE80211R */
3512
3513
3514 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3515 struct unprot_deauth *e)
3516 {
3517 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3518 "dropped: " MACSTR " -> " MACSTR
3519 " (reason code %u)",
3520 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3521 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3522 }
3523
3524
3525 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3526 struct unprot_disassoc *e)
3527 {
3528 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3529 "dropped: " MACSTR " -> " MACSTR
3530 " (reason code %u)",
3531 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3532 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3533 }
3534
3535
3536 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3537 u16 reason_code, int locally_generated,
3538 const u8 *ie, size_t ie_len, int deauth)
3539 {
3540 #ifdef CONFIG_AP
3541 if (wpa_s->ap_iface && addr) {
3542 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3543 return;
3544 }
3545
3546 if (wpa_s->ap_iface) {
3547 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3548 return;
3549 }
3550 #endif /* CONFIG_AP */
3551
3552 if (!locally_generated)
3553 wpa_s->own_disconnect_req = 0;
3554
3555 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3556
3557 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3558 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3559 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3560 eapol_sm_failed(wpa_s->eapol))) &&
3561 !wpa_s->eap_expected_failure))
3562 wpas_auth_failed(wpa_s, "AUTH_FAILED");
3563
3564 #ifdef CONFIG_P2P
3565 if (deauth && reason_code > 0) {
3566 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3567 locally_generated) > 0) {
3568 /*
3569 * The interface was removed, so cannot continue
3570 * processing any additional operations after this.
3571 */
3572 return;
3573 }
3574 }
3575 #endif /* CONFIG_P2P */
3576
3577 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3578 locally_generated);
3579 }
3580
3581
3582 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3583 struct disassoc_info *info)
3584 {
3585 u16 reason_code = 0;
3586 int locally_generated = 0;
3587 const u8 *addr = NULL;
3588 const u8 *ie = NULL;
3589 size_t ie_len = 0;
3590
3591 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3592
3593 if (info) {
3594 addr = info->addr;
3595 ie = info->ie;
3596 ie_len = info->ie_len;
3597 reason_code = info->reason_code;
3598 locally_generated = info->locally_generated;
3599 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
3600 reason2str(reason_code),
3601 locally_generated ? " locally_generated=1" : "");
3602 if (addr)
3603 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3604 MAC2STR(addr));
3605 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3606 ie, ie_len);
3607 }
3608
3609 #ifdef CONFIG_AP
3610 if (wpa_s->ap_iface && info && info->addr) {
3611 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3612 return;
3613 }
3614
3615 if (wpa_s->ap_iface) {
3616 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3617 return;
3618 }
3619 #endif /* CONFIG_AP */
3620
3621 #ifdef CONFIG_P2P
3622 if (info) {
3623 wpas_p2p_disassoc_notif(
3624 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3625 locally_generated);
3626 }
3627 #endif /* CONFIG_P2P */
3628
3629 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3630 sme_event_disassoc(wpa_s, info);
3631
3632 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3633 ie, ie_len, 0);
3634 }
3635
3636
3637 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3638 struct deauth_info *info)
3639 {
3640 u16 reason_code = 0;
3641 int locally_generated = 0;
3642 const u8 *addr = NULL;
3643 const u8 *ie = NULL;
3644 size_t ie_len = 0;
3645
3646 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3647
3648 if (info) {
3649 addr = info->addr;
3650 ie = info->ie;
3651 ie_len = info->ie_len;
3652 reason_code = info->reason_code;
3653 locally_generated = info->locally_generated;
3654 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
3655 reason_code, reason2str(reason_code),
3656 locally_generated ? " locally_generated=1" : "");
3657 if (addr) {
3658 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3659 MAC2STR(addr));
3660 }
3661 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3662 ie, ie_len);
3663 }
3664
3665 wpa_reset_ft_completed(wpa_s->wpa);
3666
3667 wpas_event_disconnect(wpa_s, addr, reason_code,
3668 locally_generated, ie, ie_len, 1);
3669 }
3670
3671
3672 static const char * reg_init_str(enum reg_change_initiator init)
3673 {
3674 switch (init) {
3675 case REGDOM_SET_BY_CORE:
3676 return "CORE";
3677 case REGDOM_SET_BY_USER:
3678 return "USER";
3679 case REGDOM_SET_BY_DRIVER:
3680 return "DRIVER";
3681 case REGDOM_SET_BY_COUNTRY_IE:
3682 return "COUNTRY_IE";
3683 case REGDOM_BEACON_HINT:
3684 return "BEACON_HINT";
3685 }
3686 return "?";
3687 }
3688
3689
3690 static const char * reg_type_str(enum reg_type type)
3691 {
3692 switch (type) {
3693 case REGDOM_TYPE_UNKNOWN:
3694 return "UNKNOWN";
3695 case REGDOM_TYPE_COUNTRY:
3696 return "COUNTRY";
3697 case REGDOM_TYPE_WORLD:
3698 return "WORLD";
3699 case REGDOM_TYPE_CUSTOM_WORLD:
3700 return "CUSTOM_WORLD";
3701 case REGDOM_TYPE_INTERSECTION:
3702 return "INTERSECTION";
3703 }
3704 return "?";
3705 }
3706
3707
3708 void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
3709 struct channel_list_changed *info)
3710 {
3711 struct wpa_supplicant *ifs;
3712 u8 dfs_domain;
3713
3714 /*
3715 * To allow backwards compatibility with higher level layers that
3716 * assumed the REGDOM_CHANGE event is sent over the initially added
3717 * interface. Find the highest parent of this interface and use it to
3718 * send the event.
3719 */
3720 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3721 ;
3722
3723 if (info) {
3724 wpa_msg(ifs, MSG_INFO,
3725 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3726 reg_init_str(info->initiator), reg_type_str(info->type),
3727 info->alpha2[0] ? " alpha2=" : "",
3728 info->alpha2[0] ? info->alpha2 : "");
3729 }
3730
3731 if (wpa_s->drv_priv == NULL)
3732 return; /* Ignore event during drv initialization */
3733
3734 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3735 radio_list) {
3736 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3737 ifs->ifname);
3738 free_hw_features(ifs);
3739 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3740 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
3741
3742 /* Restart PNO/sched_scan with updated channel list */
3743 if (ifs->pno) {
3744 wpas_stop_pno(ifs);
3745 wpas_start_pno(ifs);
3746 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
3747 wpa_dbg(ifs, MSG_DEBUG,
3748 "Channel list changed - restart sched_scan");
3749 wpas_scan_restart_sched_scan(ifs);
3750 }
3751 }
3752
3753 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3754 }
3755
3756
3757 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3758 const u8 *frame, size_t len, int freq,
3759 int rssi)
3760 {
3761 const struct ieee80211_mgmt *mgmt;
3762 const u8 *payload;
3763 size_t plen;
3764 u8 category;
3765
3766 if (len < IEEE80211_HDRLEN + 2)
3767 return;
3768
3769 mgmt = (const struct ieee80211_mgmt *) frame;
3770 payload = frame + IEEE80211_HDRLEN;
3771 category = *payload++;
3772 plen = len - IEEE80211_HDRLEN - 1;
3773
3774 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3775 " Category=%u DataLen=%d freq=%d MHz",
3776 MAC2STR(mgmt->sa), category, (int) plen, freq);
3777
3778 if (category == WLAN_ACTION_WMM) {
3779 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3780 return;
3781 }
3782
3783 #ifdef CONFIG_IEEE80211R
3784 if (category == WLAN_ACTION_FT) {
3785 ft_rx_action(wpa_s, payload, plen);
3786 return;
3787 }
3788 #endif /* CONFIG_IEEE80211R */
3789
3790 #ifdef CONFIG_SME
3791 if (category == WLAN_ACTION_SA_QUERY) {
3792 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3793 return;
3794 }
3795 #endif /* CONFIG_SME */
3796
3797 #ifdef CONFIG_WNM
3798 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3799 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3800 return;
3801 }
3802 #endif /* CONFIG_WNM */
3803
3804 #ifdef CONFIG_GAS
3805 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3806 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3807 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3808 mgmt->u.action.category,
3809 payload, plen, freq) == 0)
3810 return;
3811 #endif /* CONFIG_GAS */
3812
3813 #ifdef CONFIG_GAS_SERVER
3814 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3815 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3816 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
3817 mgmt->u.action.category,
3818 payload, plen, freq) == 0)
3819 return;
3820 #endif /* CONFIG_GAS_SERVER */
3821
3822 #ifdef CONFIG_TDLS
3823 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3824 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3825 wpa_dbg(wpa_s, MSG_DEBUG,
3826 "TDLS: Received Discovery Response from " MACSTR,
3827 MAC2STR(mgmt->sa));
3828 return;
3829 }
3830 #endif /* CONFIG_TDLS */
3831
3832 #ifdef CONFIG_INTERWORKING
3833 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3834 payload[0] == QOS_QOS_MAP_CONFIG) {
3835 const u8 *pos = payload + 1;
3836 size_t qlen = plen - 1;
3837 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3838 MACSTR, MAC2STR(mgmt->sa));
3839 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3840 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3841 pos[1] <= qlen - 2 && pos[1] >= 16)
3842 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3843 return;
3844 }
3845 #endif /* CONFIG_INTERWORKING */
3846
3847 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3848 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
3849 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
3850 mgmt->da,
3851 payload + 1,
3852 plen - 1);
3853 return;
3854 }
3855
3856 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3857 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3858 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3859 return;
3860 }
3861
3862 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3863 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3864 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3865 payload + 1, plen - 1,
3866 rssi);
3867 return;
3868 }
3869
3870 #ifdef CONFIG_FST
3871 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3872 fst_rx_action(wpa_s->fst, mgmt, len);
3873 return;
3874 }
3875 #endif /* CONFIG_FST */
3876
3877 #ifdef CONFIG_DPP
3878 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
3879 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
3880 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
3881 payload[4] == DPP_OUI_TYPE) {
3882 payload++;
3883 plen--;
3884 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
3885 return;
3886 }
3887 #endif /* CONFIG_DPP */
3888
3889 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3890 category, payload, plen, freq);
3891 if (wpa_s->ifmsh)
3892 mesh_mpm_action_rx(wpa_s, mgmt, len);
3893 }
3894
3895
3896 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3897 union wpa_event_data *event)
3898 {
3899 struct wpa_freq_range_list *list;
3900 char *str = NULL;
3901
3902 list = &event->freq_range;
3903
3904 if (list->num)
3905 str = freq_range_list_str(list);
3906 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3907 str ? str : "");
3908
3909 #ifdef CONFIG_P2P
3910 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3911 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3912 __func__);
3913 } else {
3914 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3915
3916 /*
3917 * The update channel flow will also take care of moving a GO
3918 * from the unsafe frequency if needed.
3919 */
3920 wpas_p2p_update_channel_list(wpa_s,
3921 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3922 }
3923 #endif /* CONFIG_P2P */
3924
3925 os_free(str);
3926 }
3927
3928
3929 static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
3930 {
3931 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3932 wpa_supplicant_cancel_auth_timeout(wpa_s);
3933 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3934 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3935 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3936 wpa_s->drv_authorized_port = 1;
3937 }
3938 }
3939
3940
3941 static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
3942 int freq)
3943 {
3944 size_t i;
3945 int j;
3946
3947 for (i = 0; i < wpa_s->hw.num_modes; i++) {
3948 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
3949
3950 for (j = 0; j < mode->num_channels; j++) {
3951 const struct hostapd_channel_data *chan;
3952
3953 chan = &mode->channels[j];
3954 if (chan->freq == freq)
3955 return chan->dfs_cac_ms;
3956 }
3957 }
3958
3959 return 0;
3960 }
3961
3962
3963 static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
3964 struct dfs_event *radar)
3965 {
3966 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3967 if (wpa_s->ap_iface || wpa_s->ifmsh) {
3968 wpas_ap_event_dfs_cac_started(wpa_s, radar);
3969 } else
3970 #endif /* NEED_AP_MLME && CONFIG_AP */
3971 {
3972 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
3973
3974 cac_time /= 1000; /* convert from ms to sec */
3975 if (!cac_time)
3976 cac_time = 10 * 60; /* max timeout: 10 minutes */
3977
3978 /* Restart auth timeout: CAC time added to initial timeout */
3979 wpas_auth_timeout_restart(wpa_s, cac_time);
3980 }
3981 }
3982
3983
3984 static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
3985 struct dfs_event *radar)
3986 {
3987 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3988 if (wpa_s->ap_iface || wpa_s->ifmsh) {
3989 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
3990 } else
3991 #endif /* NEED_AP_MLME && CONFIG_AP */
3992 {
3993 /* Restart auth timeout with original value after CAC is
3994 * finished */
3995 wpas_auth_timeout_restart(wpa_s, 0);
3996 }
3997 }
3998
3999
4000 static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4001 struct dfs_event *radar)
4002 {
4003 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
4004 if (wpa_s->ap_iface || wpa_s->ifmsh) {
4005 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4006 } else
4007 #endif /* NEED_AP_MLME && CONFIG_AP */
4008 {
4009 /* Restart auth timeout with original value after CAC is
4010 * aborted */
4011 wpas_auth_timeout_restart(wpa_s, 0);
4012 }
4013 }
4014
4015
4016 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4017 union wpa_event_data *data)
4018 {
4019 wpa_dbg(wpa_s, MSG_DEBUG,
4020 "Connection authorized by device, previous state %d",
4021 wpa_s->wpa_state);
4022
4023 wpa_supplicant_event_port_authorized(wpa_s);
4024
4025 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4026 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
4027 data->assoc_info.ptk_kck_len,
4028 data->assoc_info.ptk_kek,
4029 data->assoc_info.ptk_kek_len);
4030 #ifdef CONFIG_FILS
4031 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4032 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4033 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4034
4035 /* Update ERP next sequence number */
4036 eapol_sm_update_erp_next_seq_num(
4037 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4038
4039 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4040 /* Add the new PMK and PMKID to the PMKSA cache */
4041 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4042 data->assoc_info.fils_pmk,
4043 data->assoc_info.fils_pmk_len,
4044 data->assoc_info.fils_pmkid,
4045 wpa_s->bssid, fils_cache_id);
4046 } else if (data->assoc_info.fils_pmkid) {
4047 /* Update the current PMKSA used for this connection */
4048 pmksa_cache_set_current(wpa_s->wpa,
4049 data->assoc_info.fils_pmkid,
4050 NULL, NULL, 0, NULL, 0);
4051 }
4052 }
4053 #endif /* CONFIG_FILS */
4054 }
4055
4056
4057 static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4058 union wpa_event_data *data)
4059 {
4060 const u8 *bssid = data->assoc_reject.bssid;
4061 #ifdef CONFIG_MBO
4062 struct wpa_bss *reject_bss;
4063 #endif /* CONFIG_MBO */
4064
4065 if (!bssid || is_zero_ether_addr(bssid))
4066 bssid = wpa_s->pending_bssid;
4067 #ifdef CONFIG_MBO
4068 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4069 reject_bss = wpa_s->current_bss;
4070 else
4071 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4072 #endif /* CONFIG_MBO */
4073
4074 if (data->assoc_reject.bssid)
4075 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4076 "bssid=" MACSTR " status_code=%u%s%s%s",
4077 MAC2STR(data->assoc_reject.bssid),
4078 data->assoc_reject.status_code,
4079 data->assoc_reject.timed_out ? " timeout" : "",
4080 data->assoc_reject.timeout_reason ? "=" : "",
4081 data->assoc_reject.timeout_reason ?
4082 data->assoc_reject.timeout_reason : "");
4083 else
4084 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4085 "status_code=%u%s%s%s",
4086 data->assoc_reject.status_code,
4087 data->assoc_reject.timed_out ? " timeout" : "",
4088 data->assoc_reject.timeout_reason ? "=" : "",
4089 data->assoc_reject.timeout_reason ?
4090 data->assoc_reject.timeout_reason : "");
4091 wpa_s->assoc_status_code = data->assoc_reject.status_code;
4092 wpas_notify_assoc_status_code(wpa_s);
4093
4094 #ifdef CONFIG_OWE
4095 if (data->assoc_reject.status_code ==
4096 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4097 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4098 wpa_s->current_ssid &&
4099 wpa_s->current_ssid->owe_group == 0 &&
4100 wpa_s->last_owe_group != 21) {
4101 struct wpa_ssid *ssid = wpa_s->current_ssid;
4102 struct wpa_bss *bss = wpa_s->current_bss;
4103
4104 if (!bss) {
4105 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4106 if (!bss) {
4107 wpas_connection_failed(wpa_s, bssid);
4108 wpa_supplicant_mark_disassoc(wpa_s);
4109 return;
4110 }
4111 }
4112 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4113 wpas_connect_work_done(wpa_s);
4114 wpa_supplicant_mark_disassoc(wpa_s);
4115 wpa_supplicant_connect(wpa_s, bss, ssid);
4116 return;
4117 }
4118 #endif /* CONFIG_OWE */
4119
4120 #ifdef CONFIG_MBO
4121 if (data->assoc_reject.status_code ==
4122 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
4123 reject_bss && data->assoc_reject.resp_ies) {
4124 const u8 *rssi_rej;
4125
4126 rssi_rej = mbo_get_attr_from_ies(
4127 data->assoc_reject.resp_ies,
4128 data->assoc_reject.resp_ies_len,
4129 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4130 if (rssi_rej && rssi_rej[1] == 2) {
4131 wpa_printf(MSG_DEBUG,
4132 "OCE: RSSI-based association rejection from "
4133 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
4134 MAC2STR(reject_bss->bssid),
4135 rssi_rej[2], rssi_rej[3]);
4136 wpa_bss_tmp_disallow(wpa_s,
4137 reject_bss->bssid,
4138 rssi_rej[3],
4139 rssi_rej[2] + reject_bss->level);
4140 }
4141 }
4142 #endif /* CONFIG_MBO */
4143
4144 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4145 sme_event_assoc_reject(wpa_s, data);
4146 return;
4147 }
4148
4149 /* Driver-based SME cases */
4150
4151 #ifdef CONFIG_SAE
4152 if (wpa_s->current_ssid &&
4153 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4154 !data->assoc_reject.timed_out) {
4155 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4156 wpa_sm_aborted_cached(wpa_s->wpa);
4157 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4158 }
4159 #endif /* CONFIG_SAE */
4160
4161 #ifdef CONFIG_DPP
4162 if (wpa_s->current_ssid &&
4163 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4164 !data->assoc_reject.timed_out) {
4165 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4166 wpa_sm_aborted_cached(wpa_s->wpa);
4167 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4168 }
4169 #endif /* CONFIG_DPP */
4170
4171 #ifdef CONFIG_FILS
4172 /* Update ERP next sequence number */
4173 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4174 eapol_sm_update_erp_next_seq_num(
4175 wpa_s->eapol,
4176 data->assoc_reject.fils_erp_next_seq_num);
4177 fils_connection_failure(wpa_s);
4178 }
4179 #endif /* CONFIG_FILS */
4180
4181 wpas_connection_failed(wpa_s, bssid);
4182 wpa_supplicant_mark_disassoc(wpa_s);
4183 }
4184
4185
4186 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4187 union wpa_event_data *data)
4188 {
4189 struct wpa_supplicant *wpa_s = ctx;
4190 int resched;
4191 #ifndef CONFIG_NO_STDOUT_DEBUG
4192 int level = MSG_DEBUG;
4193 #endif /* CONFIG_NO_STDOUT_DEBUG */
4194
4195 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4196 event != EVENT_INTERFACE_ENABLED &&
4197 event != EVENT_INTERFACE_STATUS &&
4198 event != EVENT_SCAN_RESULTS &&
4199 event != EVENT_SCHED_SCAN_STOPPED) {
4200 wpa_dbg(wpa_s, MSG_DEBUG,
4201 "Ignore event %s (%d) while interface is disabled",
4202 event_to_string(event), event);
4203 return;
4204 }
4205
4206 #ifndef CONFIG_NO_STDOUT_DEBUG
4207 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
4208 const struct ieee80211_hdr *hdr;
4209 u16 fc;
4210 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4211 fc = le_to_host16(hdr->frame_control);
4212 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4213 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4214 level = MSG_EXCESSIVE;
4215 }
4216
4217 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4218 event_to_string(event), event);
4219 #endif /* CONFIG_NO_STDOUT_DEBUG */
4220
4221 switch (event) {
4222 case EVENT_AUTH:
4223 #ifdef CONFIG_FST
4224 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4225 data->auth.ies_len))
4226 wpa_printf(MSG_DEBUG,
4227 "FST: MB IEs updated from auth IE");
4228 #endif /* CONFIG_FST */
4229 sme_event_auth(wpa_s, data);
4230 wpa_s->auth_status_code = data->auth.status_code;
4231 wpas_notify_auth_status_code(wpa_s);
4232 break;
4233 case EVENT_ASSOC:
4234 #ifdef CONFIG_TESTING_OPTIONS
4235 if (wpa_s->ignore_auth_resp) {
4236 wpa_printf(MSG_INFO,
4237 "EVENT_ASSOC - ignore_auth_resp active!");
4238 break;
4239 }
4240 if (wpa_s->testing_resend_assoc) {
4241 wpa_printf(MSG_INFO,
4242 "EVENT_DEAUTH - testing_resend_assoc");
4243 break;
4244 }
4245 #endif /* CONFIG_TESTING_OPTIONS */
4246 wpa_supplicant_event_assoc(wpa_s, data);
4247 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
4248 if (data &&
4249 (data->assoc_info.authorized ||
4250 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4251 wpa_fils_is_completed(wpa_s->wpa))))
4252 wpa_supplicant_event_assoc_auth(wpa_s, data);
4253 if (data) {
4254 wpa_msg(wpa_s, MSG_INFO,
4255 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4256 data->assoc_info.subnet_status);
4257 }
4258 break;
4259 case EVENT_DISASSOC:
4260 wpas_event_disassoc(wpa_s,
4261 data ? &data->disassoc_info : NULL);
4262 break;
4263 case EVENT_DEAUTH:
4264 #ifdef CONFIG_TESTING_OPTIONS
4265 if (wpa_s->ignore_auth_resp) {
4266 wpa_printf(MSG_INFO,
4267 "EVENT_DEAUTH - ignore_auth_resp active!");
4268 break;
4269 }
4270 if (wpa_s->testing_resend_assoc) {
4271 wpa_printf(MSG_INFO,
4272 "EVENT_DEAUTH - testing_resend_assoc");
4273 break;
4274 }
4275 #endif /* CONFIG_TESTING_OPTIONS */
4276 wpas_event_deauth(wpa_s,
4277 data ? &data->deauth_info : NULL);
4278 break;
4279 case EVENT_MICHAEL_MIC_FAILURE:
4280 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4281 break;
4282 #ifndef CONFIG_NO_SCAN_PROCESSING
4283 case EVENT_SCAN_STARTED:
4284 if (wpa_s->own_scan_requested ||
4285 (data && !data->scan_info.external_scan)) {
4286 struct os_reltime diff;
4287
4288 os_get_reltime(&wpa_s->scan_start_time);
4289 os_reltime_sub(&wpa_s->scan_start_time,
4290 &wpa_s->scan_trigger_time, &diff);
4291 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4292 diff.sec, diff.usec);
4293 wpa_s->own_scan_requested = 0;
4294 wpa_s->own_scan_running = 1;
4295 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4296 wpa_s->manual_scan_use_id) {
4297 wpa_msg_ctrl(wpa_s, MSG_INFO,
4298 WPA_EVENT_SCAN_STARTED "id=%u",
4299 wpa_s->manual_scan_id);
4300 } else {
4301 wpa_msg_ctrl(wpa_s, MSG_INFO,
4302 WPA_EVENT_SCAN_STARTED);
4303 }
4304 } else {
4305 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
4306 wpa_s->radio->external_scan_running = 1;
4307 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
4308 }
4309 break;
4310 case EVENT_SCAN_RESULTS:
4311 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4312 wpa_s->scan_res_handler = NULL;
4313 wpa_s->own_scan_running = 0;
4314 wpa_s->radio->external_scan_running = 0;
4315 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4316 break;
4317 }
4318
4319 if (!(data && data->scan_info.external_scan) &&
4320 os_reltime_initialized(&wpa_s->scan_start_time)) {
4321 struct os_reltime now, diff;
4322 os_get_reltime(&now);
4323 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4324 wpa_s->scan_start_time.sec = 0;
4325 wpa_s->scan_start_time.usec = 0;
4326 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4327 diff.sec, diff.usec);
4328 }
4329 if (wpa_supplicant_event_scan_results(wpa_s, data))
4330 break; /* interface may have been removed */
4331 if (!(data && data->scan_info.external_scan))
4332 wpa_s->own_scan_running = 0;
4333 if (data && data->scan_info.nl_scan_event)
4334 wpa_s->radio->external_scan_running = 0;
4335 radio_work_check_next(wpa_s);
4336 break;
4337 #endif /* CONFIG_NO_SCAN_PROCESSING */
4338 case EVENT_ASSOCINFO:
4339 wpa_supplicant_event_associnfo(wpa_s, data);
4340 break;
4341 case EVENT_INTERFACE_STATUS:
4342 wpa_supplicant_event_interface_status(wpa_s, data);
4343 break;
4344 case EVENT_PMKID_CANDIDATE:
4345 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4346 break;
4347 #ifdef CONFIG_TDLS
4348 case EVENT_TDLS:
4349 wpa_supplicant_event_tdls(wpa_s, data);
4350 break;
4351 #endif /* CONFIG_TDLS */
4352 #ifdef CONFIG_WNM
4353 case EVENT_WNM:
4354 wpa_supplicant_event_wnm(wpa_s, data);
4355 break;
4356 #endif /* CONFIG_WNM */
4357 #ifdef CONFIG_IEEE80211R
4358 case EVENT_FT_RESPONSE:
4359 wpa_supplicant_event_ft_response(wpa_s, data);
4360 break;
4361 #endif /* CONFIG_IEEE80211R */
4362 #ifdef CONFIG_IBSS_RSN
4363 case EVENT_IBSS_RSN_START:
4364 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4365 break;
4366 #endif /* CONFIG_IBSS_RSN */
4367 case EVENT_ASSOC_REJECT:
4368 wpas_event_assoc_reject(wpa_s, data);
4369 break;
4370 case EVENT_AUTH_TIMED_OUT:
4371 /* It is possible to get this event from earlier connection */
4372 if (wpa_s->current_ssid &&
4373 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4374 wpa_dbg(wpa_s, MSG_DEBUG,
4375 "Ignore AUTH_TIMED_OUT in mesh configuration");
4376 break;
4377 }
4378 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4379 sme_event_auth_timed_out(wpa_s, data);
4380 break;
4381 case EVENT_ASSOC_TIMED_OUT:
4382 /* It is possible to get this event from earlier connection */
4383 if (wpa_s->current_ssid &&
4384 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4385 wpa_dbg(wpa_s, MSG_DEBUG,
4386 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4387 break;
4388 }
4389 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4390 sme_event_assoc_timed_out(wpa_s, data);
4391 break;
4392 case EVENT_TX_STATUS:
4393 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4394 " type=%d stype=%d",
4395 MAC2STR(data->tx_status.dst),
4396 data->tx_status.type, data->tx_status.stype);
4397 #ifdef CONFIG_AP
4398 if (wpa_s->ap_iface == NULL) {
4399 #ifdef CONFIG_OFFCHANNEL
4400 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4401 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
4402 offchannel_send_action_tx_status(
4403 wpa_s, data->tx_status.dst,
4404 data->tx_status.data,
4405 data->tx_status.data_len,
4406 data->tx_status.ack ?
4407 OFFCHANNEL_SEND_ACTION_SUCCESS :
4408 OFFCHANNEL_SEND_ACTION_NO_ACK);
4409 #endif /* CONFIG_OFFCHANNEL */
4410 break;
4411 }
4412 #endif /* CONFIG_AP */
4413 #ifdef CONFIG_OFFCHANNEL
4414 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
4415 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
4416 /*
4417 * Catch TX status events for Action frames we sent via group
4418 * interface in GO mode, or via standalone AP interface.
4419 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4420 * except when the primary interface is used as a GO interface
4421 * (for drivers which do not have group interface concurrency)
4422 */
4423 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4424 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
4425 os_memcmp(wpa_s->p2pdev->pending_action_dst,
4426 data->tx_status.dst, ETH_ALEN) == 0) {
4427 offchannel_send_action_tx_status(
4428 wpa_s->p2pdev, data->tx_status.dst,
4429 data->tx_status.data,
4430 data->tx_status.data_len,
4431 data->tx_status.ack ?
4432 OFFCHANNEL_SEND_ACTION_SUCCESS :
4433 OFFCHANNEL_SEND_ACTION_NO_ACK);
4434 break;
4435 }
4436 #endif /* CONFIG_OFFCHANNEL */
4437 #ifdef CONFIG_AP
4438 switch (data->tx_status.type) {
4439 case WLAN_FC_TYPE_MGMT:
4440 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4441 data->tx_status.data_len,
4442 data->tx_status.stype,
4443 data->tx_status.ack);
4444 break;
4445 case WLAN_FC_TYPE_DATA:
4446 ap_tx_status(wpa_s, data->tx_status.dst,
4447 data->tx_status.data,
4448 data->tx_status.data_len,
4449 data->tx_status.ack);
4450 break;
4451 }
4452 #endif /* CONFIG_AP */
4453 break;
4454 #ifdef CONFIG_AP
4455 case EVENT_EAPOL_TX_STATUS:
4456 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4457 data->eapol_tx_status.data,
4458 data->eapol_tx_status.data_len,
4459 data->eapol_tx_status.ack);
4460 break;
4461 case EVENT_DRIVER_CLIENT_POLL_OK:
4462 ap_client_poll_ok(wpa_s, data->client_poll.addr);
4463 break;
4464 case EVENT_RX_FROM_UNKNOWN:
4465 if (wpa_s->ap_iface == NULL)
4466 break;
4467 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4468 data->rx_from_unknown.wds);
4469 break;
4470 #endif /* CONFIG_AP */
4471
4472 case EVENT_CH_SWITCH_STARTED:
4473 case EVENT_CH_SWITCH:
4474 if (!data || !wpa_s->current_ssid)
4475 break;
4476
4477 wpa_msg(wpa_s, MSG_INFO,
4478 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4479 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
4480 WPA_EVENT_CHANNEL_SWITCH_STARTED,
4481 data->ch_switch.freq,
4482 data->ch_switch.ht_enabled,
4483 data->ch_switch.ch_offset,
4484 channel_width_to_string(data->ch_switch.ch_width),
4485 data->ch_switch.cf1,
4486 data->ch_switch.cf2);
4487 if (event == EVENT_CH_SWITCH_STARTED)
4488 break;
4489
4490 wpa_s->assoc_freq = data->ch_switch.freq;
4491 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4492
4493 #ifdef CONFIG_AP
4494 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4495 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
4496 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
4497 wpa_s->current_ssid->mode ==
4498 WPAS_MODE_P2P_GROUP_FORMATION) {
4499 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4500 data->ch_switch.ht_enabled,
4501 data->ch_switch.ch_offset,
4502 data->ch_switch.ch_width,
4503 data->ch_switch.cf1,
4504 data->ch_switch.cf2,
4505 1);
4506 }
4507 #endif /* CONFIG_AP */
4508
4509 sme_event_ch_switch(wpa_s);
4510 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
4511 wnm_clear_coloc_intf_reporting(wpa_s);
4512 break;
4513 #ifdef CONFIG_AP
4514 #ifdef NEED_AP_MLME
4515 case EVENT_DFS_RADAR_DETECTED:
4516 if (data)
4517 wpas_ap_event_dfs_radar_detected(wpa_s,
4518 &data->dfs_event);
4519 break;
4520 case EVENT_DFS_NOP_FINISHED:
4521 if (data)
4522 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
4523 &data->dfs_event);
4524 break;
4525 #endif /* NEED_AP_MLME */
4526 #endif /* CONFIG_AP */
4527 case EVENT_DFS_CAC_STARTED:
4528 if (data)
4529 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
4530 break;
4531 case EVENT_DFS_CAC_FINISHED:
4532 if (data)
4533 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
4534 break;
4535 case EVENT_DFS_CAC_ABORTED:
4536 if (data)
4537 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
4538 break;
4539 case EVENT_RX_MGMT: {
4540 u16 fc, stype;
4541 const struct ieee80211_mgmt *mgmt;
4542
4543 #ifdef CONFIG_TESTING_OPTIONS
4544 if (wpa_s->ext_mgmt_frame_handling) {
4545 struct rx_mgmt *rx = &data->rx_mgmt;
4546 size_t hex_len = 2 * rx->frame_len + 1;
4547 char *hex = os_malloc(hex_len);
4548 if (hex) {
4549 wpa_snprintf_hex(hex, hex_len,
4550 rx->frame, rx->frame_len);
4551 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4552 rx->freq, rx->datarate, rx->ssi_signal,
4553 hex);
4554 os_free(hex);
4555 }
4556 break;
4557 }
4558 #endif /* CONFIG_TESTING_OPTIONS */
4559
4560 mgmt = (const struct ieee80211_mgmt *)
4561 data->rx_mgmt.frame;
4562 fc = le_to_host16(mgmt->frame_control);
4563 stype = WLAN_FC_GET_STYPE(fc);
4564
4565 #ifdef CONFIG_AP
4566 if (wpa_s->ap_iface == NULL) {
4567 #endif /* CONFIG_AP */
4568 #ifdef CONFIG_P2P
4569 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
4570 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4571 const u8 *src = mgmt->sa;
4572 const u8 *ie;
4573 size_t ie_len;
4574
4575 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4576 ie_len = data->rx_mgmt.frame_len -
4577 IEEE80211_HDRLEN;
4578 wpas_p2p_probe_req_rx(
4579 wpa_s, src, mgmt->da,
4580 mgmt->bssid, ie, ie_len,
4581 data->rx_mgmt.freq,
4582 data->rx_mgmt.ssi_signal);
4583 break;
4584 }
4585 #endif /* CONFIG_P2P */
4586 #ifdef CONFIG_IBSS_RSN
4587 if (wpa_s->current_ssid &&
4588 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4589 stype == WLAN_FC_STYPE_AUTH &&
4590 data->rx_mgmt.frame_len >= 30) {
4591 wpa_supplicant_event_ibss_auth(wpa_s, data);
4592 break;
4593 }
4594 #endif /* CONFIG_IBSS_RSN */
4595
4596 if (stype == WLAN_FC_STYPE_ACTION) {
4597 wpas_event_rx_mgmt_action(
4598 wpa_s, data->rx_mgmt.frame,
4599 data->rx_mgmt.frame_len,
4600 data->rx_mgmt.freq,
4601 data->rx_mgmt.ssi_signal);
4602 break;
4603 }
4604
4605 if (wpa_s->ifmsh) {
4606 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
4607 break;
4608 }
4609
4610 #ifdef CONFIG_SAE
4611 if (stype == WLAN_FC_STYPE_AUTH &&
4612 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4613 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4614 sme_external_auth_mgmt_rx(
4615 wpa_s, data->rx_mgmt.frame,
4616 data->rx_mgmt.frame_len);
4617 break;
4618 }
4619 #endif /* CONFIG_SAE */
4620 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
4621 "management frame in non-AP mode");
4622 break;
4623 #ifdef CONFIG_AP
4624 }
4625
4626 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
4627 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4628 const u8 *ie;
4629 size_t ie_len;
4630
4631 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4632 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
4633
4634 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
4635 mgmt->bssid, ie, ie_len,
4636 data->rx_mgmt.ssi_signal);
4637 }
4638
4639 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
4640 #endif /* CONFIG_AP */
4641 break;
4642 }
4643 case EVENT_RX_PROBE_REQ:
4644 if (data->rx_probe_req.sa == NULL ||
4645 data->rx_probe_req.ie == NULL)
4646 break;
4647 #ifdef CONFIG_AP
4648 if (wpa_s->ap_iface) {
4649 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
4650 data->rx_probe_req.sa,
4651 data->rx_probe_req.da,
4652 data->rx_probe_req.bssid,
4653 data->rx_probe_req.ie,
4654 data->rx_probe_req.ie_len,
4655 data->rx_probe_req.ssi_signal);
4656 break;
4657 }
4658 #endif /* CONFIG_AP */
4659 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
4660 data->rx_probe_req.da,
4661 data->rx_probe_req.bssid,
4662 data->rx_probe_req.ie,
4663 data->rx_probe_req.ie_len,
4664 0,
4665 data->rx_probe_req.ssi_signal);
4666 break;
4667 case EVENT_REMAIN_ON_CHANNEL:
4668 #ifdef CONFIG_OFFCHANNEL
4669 offchannel_remain_on_channel_cb(
4670 wpa_s, data->remain_on_channel.freq,
4671 data->remain_on_channel.duration);
4672 #endif /* CONFIG_OFFCHANNEL */
4673 wpas_p2p_remain_on_channel_cb(
4674 wpa_s, data->remain_on_channel.freq,
4675 data->remain_on_channel.duration);
4676 break;
4677 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
4678 #ifdef CONFIG_OFFCHANNEL
4679 offchannel_cancel_remain_on_channel_cb(
4680 wpa_s, data->remain_on_channel.freq);
4681 #endif /* CONFIG_OFFCHANNEL */
4682 wpas_p2p_cancel_remain_on_channel_cb(
4683 wpa_s, data->remain_on_channel.freq);
4684 #ifdef CONFIG_DPP
4685 wpas_dpp_cancel_remain_on_channel_cb(
4686 wpa_s, data->remain_on_channel.freq);
4687 #endif /* CONFIG_DPP */
4688 break;
4689 case EVENT_EAPOL_RX:
4690 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
4691 data->eapol_rx.data,
4692 data->eapol_rx.data_len);
4693 break;
4694 case EVENT_SIGNAL_CHANGE:
4695 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
4696 "above=%d signal=%d noise=%d txrate=%d",
4697 data->signal_change.above_threshold,
4698 data->signal_change.current_signal,
4699 data->signal_change.current_noise,
4700 data->signal_change.current_txrate);
4701 wpa_bss_update_level(wpa_s->current_bss,
4702 data->signal_change.current_signal);
4703 bgscan_notify_signal_change(
4704 wpa_s, data->signal_change.above_threshold,
4705 data->signal_change.current_signal,
4706 data->signal_change.current_noise,
4707 data->signal_change.current_txrate);
4708 break;
4709 case EVENT_INTERFACE_MAC_CHANGED:
4710 wpa_supplicant_update_mac_addr(wpa_s);
4711 break;
4712 case EVENT_INTERFACE_ENABLED:
4713 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
4714 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4715 wpa_supplicant_update_mac_addr(wpa_s);
4716 wpa_supplicant_set_default_scan_ies(wpa_s);
4717 if (wpa_s->p2p_mgmt) {
4718 wpa_supplicant_set_state(wpa_s,
4719 WPA_DISCONNECTED);
4720 break;
4721 }
4722
4723 #ifdef CONFIG_AP
4724 if (!wpa_s->ap_iface) {
4725 wpa_supplicant_set_state(wpa_s,
4726 WPA_DISCONNECTED);
4727 wpa_s->scan_req = NORMAL_SCAN_REQ;
4728 wpa_supplicant_req_scan(wpa_s, 0, 0);
4729 } else
4730 wpa_supplicant_set_state(wpa_s,
4731 WPA_COMPLETED);
4732 #else /* CONFIG_AP */
4733 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
4734 wpa_supplicant_req_scan(wpa_s, 0, 0);
4735 #endif /* CONFIG_AP */
4736 }
4737 break;
4738 case EVENT_INTERFACE_DISABLED:
4739 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
4740 #ifdef CONFIG_P2P
4741 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
4742 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
4743 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
4744 /*
4745 * Mark interface disabled if this happens to end up not
4746 * being removed as a separate P2P group interface.
4747 */
4748 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4749 /*
4750 * The interface was externally disabled. Remove
4751 * it assuming an external entity will start a
4752 * new session if needed.
4753 */
4754 if (wpa_s->current_ssid &&
4755 wpa_s->current_ssid->p2p_group)
4756 wpas_p2p_interface_unavailable(wpa_s);
4757 else
4758 wpas_p2p_disconnect(wpa_s);
4759 /*
4760 * wpa_s instance may have been freed, so must not use
4761 * it here anymore.
4762 */
4763 break;
4764 }
4765 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
4766 p2p_in_progress(wpa_s->global->p2p) > 1) {
4767 /* This radio work will be cancelled, so clear P2P
4768 * state as well.
4769 */
4770 p2p_stop_find(wpa_s->global->p2p);
4771 }
4772 #endif /* CONFIG_P2P */
4773
4774 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4775 /*
4776 * Indicate disconnection to keep ctrl_iface events
4777 * consistent.
4778 */
4779 wpa_supplicant_event_disassoc(
4780 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
4781 }
4782 wpa_supplicant_mark_disassoc(wpa_s);
4783 wpa_bss_flush(wpa_s);
4784 radio_remove_works(wpa_s, NULL, 0);
4785
4786 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4787 break;
4788 case EVENT_CHANNEL_LIST_CHANGED:
4789 wpa_supplicant_update_channel_list(
4790 wpa_s, &data->channel_list_changed);
4791 break;
4792 case EVENT_INTERFACE_UNAVAILABLE:
4793 wpas_p2p_interface_unavailable(wpa_s);
4794 break;
4795 case EVENT_BEST_CHANNEL:
4796 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
4797 "(%d %d %d)",
4798 data->best_chan.freq_24, data->best_chan.freq_5,
4799 data->best_chan.freq_overall);
4800 wpa_s->best_24_freq = data->best_chan.freq_24;
4801 wpa_s->best_5_freq = data->best_chan.freq_5;
4802 wpa_s->best_overall_freq = data->best_chan.freq_overall;
4803 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
4804 data->best_chan.freq_5,
4805 data->best_chan.freq_overall);
4806 break;
4807 case EVENT_UNPROT_DEAUTH:
4808 wpa_supplicant_event_unprot_deauth(wpa_s,
4809 &data->unprot_deauth);
4810 break;
4811 case EVENT_UNPROT_DISASSOC:
4812 wpa_supplicant_event_unprot_disassoc(wpa_s,
4813 &data->unprot_disassoc);
4814 break;
4815 case EVENT_STATION_LOW_ACK:
4816 #ifdef CONFIG_AP
4817 if (wpa_s->ap_iface && data)
4818 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
4819 data->low_ack.addr);
4820 #endif /* CONFIG_AP */
4821 #ifdef CONFIG_TDLS
4822 if (data)
4823 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
4824 data->low_ack.addr);
4825 #endif /* CONFIG_TDLS */
4826 break;
4827 case EVENT_IBSS_PEER_LOST:
4828 #ifdef CONFIG_IBSS_RSN
4829 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
4830 #endif /* CONFIG_IBSS_RSN */
4831 break;
4832 case EVENT_DRIVER_GTK_REKEY:
4833 if (os_memcmp(data->driver_gtk_rekey.bssid,
4834 wpa_s->bssid, ETH_ALEN))
4835 break;
4836 if (!wpa_s->wpa)
4837 break;
4838 wpa_sm_update_replay_ctr(wpa_s->wpa,
4839 data->driver_gtk_rekey.replay_ctr);
4840 break;
4841 case EVENT_SCHED_SCAN_STOPPED:
4842 wpa_s->sched_scanning = 0;
4843 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
4844 wpa_supplicant_notify_scanning(wpa_s, 0);
4845
4846 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4847 break;
4848
4849 /*
4850 * If the driver stopped scanning without being requested to,
4851 * request a new scan to continue scanning for networks.
4852 */
4853 if (!wpa_s->sched_scan_stop_req &&
4854 wpa_s->wpa_state == WPA_SCANNING) {
4855 wpa_dbg(wpa_s, MSG_DEBUG,
4856 "Restart scanning after unexpected sched_scan stop event");
4857 wpa_supplicant_req_scan(wpa_s, 1, 0);
4858 break;
4859 }
4860
4861 wpa_s->sched_scan_stop_req = 0;
4862
4863 /*
4864 * Start a new sched scan to continue searching for more SSIDs
4865 * either if timed out or PNO schedule scan is pending.
4866 */
4867 if (wpa_s->sched_scan_timed_out) {
4868 wpa_supplicant_req_sched_scan(wpa_s);
4869 } else if (wpa_s->pno_sched_pending) {
4870 wpa_s->pno_sched_pending = 0;
4871 wpas_start_pno(wpa_s);
4872 } else if (resched) {
4873 wpa_supplicant_req_scan(wpa_s, 0, 0);
4874 }
4875
4876 break;
4877 case EVENT_WPS_BUTTON_PUSHED:
4878 #ifdef CONFIG_WPS
4879 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
4880 #endif /* CONFIG_WPS */
4881 break;
4882 case EVENT_AVOID_FREQUENCIES:
4883 wpa_supplicant_notify_avoid_freq(wpa_s, data);
4884 break;
4885 case EVENT_CONNECT_FAILED_REASON:
4886 #ifdef CONFIG_AP
4887 if (!wpa_s->ap_iface || !data)
4888 break;
4889 hostapd_event_connect_failed_reason(
4890 wpa_s->ap_iface->bss[0],
4891 data->connect_failed_reason.addr,
4892 data->connect_failed_reason.code);
4893 #endif /* CONFIG_AP */
4894 break;
4895 case EVENT_NEW_PEER_CANDIDATE:
4896 #ifdef CONFIG_MESH
4897 if (!wpa_s->ifmsh || !data)
4898 break;
4899 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4900 data->mesh_peer.ies,
4901 data->mesh_peer.ie_len);
4902 #endif /* CONFIG_MESH */
4903 break;
4904 case EVENT_SURVEY:
4905 #ifdef CONFIG_AP
4906 if (!wpa_s->ap_iface)
4907 break;
4908 hostapd_event_get_survey(wpa_s->ap_iface,
4909 &data->survey_results);
4910 #endif /* CONFIG_AP */
4911 break;
4912 case EVENT_ACS_CHANNEL_SELECTED:
4913 #ifdef CONFIG_AP
4914 #ifdef CONFIG_ACS
4915 if (!wpa_s->ap_iface)
4916 break;
4917 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4918 &data->acs_selected_channels);
4919 #endif /* CONFIG_ACS */
4920 #endif /* CONFIG_AP */
4921 break;
4922 case EVENT_P2P_LO_STOP:
4923 #ifdef CONFIG_P2P
4924 wpa_s->p2p_lo_started = 0;
4925 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
4926 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
4927 data->p2p_lo_stop.reason_code);
4928 #endif /* CONFIG_P2P */
4929 break;
4930 case EVENT_BEACON_LOSS:
4931 if (!wpa_s->current_bss || !wpa_s->current_ssid)
4932 break;
4933 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
4934 bgscan_notify_beacon_loss(wpa_s);
4935 break;
4936 case EVENT_EXTERNAL_AUTH:
4937 #ifdef CONFIG_SAE
4938 if (!wpa_s->current_ssid) {
4939 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
4940 break;
4941 }
4942 sme_external_auth_trigger(wpa_s, data);
4943 #endif /* CONFIG_SAE */
4944 break;
4945 case EVENT_PORT_AUTHORIZED:
4946 wpa_supplicant_event_port_authorized(wpa_s);
4947 break;
4948 case EVENT_STATION_OPMODE_CHANGED:
4949 #ifdef CONFIG_AP
4950 if (!wpa_s->ap_iface || !data)
4951 break;
4952
4953 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
4954 data->sta_opmode.addr,
4955 data->sta_opmode.smps_mode,
4956 data->sta_opmode.chan_width,
4957 data->sta_opmode.rx_nss);
4958 #endif /* CONFIG_AP */
4959 break;
4960 default:
4961 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4962 break;
4963 }
4964 }
4965
4966
4967 void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
4968 union wpa_event_data *data)
4969 {
4970 struct wpa_supplicant *wpa_s;
4971
4972 if (event != EVENT_INTERFACE_STATUS)
4973 return;
4974
4975 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
4976 if (wpa_s && wpa_s->driver->get_ifindex) {
4977 unsigned int ifindex;
4978
4979 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
4980 if (ifindex != data->interface_status.ifindex) {
4981 wpa_dbg(wpa_s, MSG_DEBUG,
4982 "interface status ifindex %d mismatch (%d)",
4983 ifindex, data->interface_status.ifindex);
4984 return;
4985 }
4986 }
4987 #ifdef CONFIG_MATCH_IFACE
4988 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
4989 struct wpa_interface *wpa_i;
4990
4991 wpa_i = wpa_supplicant_match_iface(
4992 ctx, data->interface_status.ifname);
4993 if (!wpa_i)
4994 return;
4995 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
4996 os_free(wpa_i);
4997 if (wpa_s)
4998 wpa_s->matched = 1;
4999 }
5000 #endif /* CONFIG_MATCH_IFACE */
5001
5002 if (wpa_s)
5003 wpa_supplicant_event(wpa_s, event, data);
5004 }