blob: 03a6c7d657b5257756adf05965de614d0d5e7127 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
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 "common/ptksa_cache.h"
34#include "crypto/random.h"
35#include "bssid_ignore.h"
36#include "wpas_glue.h"
37#include "wps_supplicant.h"
38#include "ibss_rsn.h"
39#include "sme.h"
40#include "gas_query.h"
41#include "p2p_supplicant.h"
42#include "bgscan.h"
43#include "autoscan.h"
44#include "ap.h"
45#include "bss.h"
46#include "scan.h"
47#include "offchannel.h"
48#include "interworking.h"
49#include "mesh.h"
50#include "mesh_mpm.h"
51#include "wmm_ac.h"
52#include "dpp_supplicant.h"
53
54
55#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
56
57
58#ifndef CONFIG_NO_SCAN_PROCESSING
59static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
60 int new_scan, int own_request);
61#endif /* CONFIG_NO_SCAN_PROCESSING */
62#ifdef CONFIG_OWE
63static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
64 const u8 **ret_ssid, size_t *ret_ssid_len);
65#endif /* CONFIG_OWE */
66
67
68int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
69{
70 struct os_reltime now;
71
72 if (ssid == NULL || ssid->disabled_until.sec == 0)
73 return 0;
74
75 os_get_reltime(&now);
76 if (ssid->disabled_until.sec > now.sec)
77 return ssid->disabled_until.sec - now.sec;
78
79 wpas_clear_temp_disabled(wpa_s, ssid, 0);
80
81 return 0;
82}
83
84
85#ifndef CONFIG_NO_SCAN_PROCESSING
86/**
87 * wpas_reenabled_network_time - Time until first network is re-enabled
88 * @wpa_s: Pointer to wpa_supplicant data
89 * Returns: If all enabled networks are temporarily disabled, returns the time
90 * (in sec) until the first network is re-enabled. Otherwise returns 0.
91 *
92 * This function is used in case all enabled networks are temporarily disabled,
93 * in which case it returns the time (in sec) that the first network will be
94 * re-enabled. The function assumes that at least one network is enabled.
95 */
96static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
97{
98 struct wpa_ssid *ssid;
99 int disabled_for, res = 0;
100
101#ifdef CONFIG_INTERWORKING
102 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
103 wpa_s->conf->cred)
104 return 0;
105#endif /* CONFIG_INTERWORKING */
106
107 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
108 if (ssid->disabled)
109 continue;
110
111 disabled_for = wpas_temp_disabled(wpa_s, ssid);
112 if (!disabled_for)
113 return 0;
114
115 if (!res || disabled_for < res)
116 res = disabled_for;
117 }
118
119 return res;
120}
121#endif /* CONFIG_NO_SCAN_PROCESSING */
122
123
124void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
125{
126 struct wpa_supplicant *wpa_s = eloop_ctx;
127
128 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
129 return;
130
131 wpa_dbg(wpa_s, MSG_DEBUG,
132 "Try to associate due to network getting re-enabled");
133 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
134 wpa_supplicant_cancel_sched_scan(wpa_s);
135 wpa_supplicant_req_scan(wpa_s, 0, 0);
136 }
137}
138
139
140static struct wpa_bss * wpa_supplicant_get_new_bss(
141 struct wpa_supplicant *wpa_s, const u8 *bssid)
142{
143 struct wpa_bss *bss = NULL;
144 struct wpa_ssid *ssid = wpa_s->current_ssid;
145
146 if (ssid && ssid->ssid_len > 0)
147 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
148 if (!bss)
149 bss = wpa_bss_get_bssid(wpa_s, bssid);
150
151 return bss;
152}
153
154
155static struct wpa_bss *
156wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
157{
158 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
159
160 if (!bss) {
161 wpa_supplicant_update_scan_results(wpa_s);
162
163 /* Get the BSS from the new scan results */
164 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
165 }
166
167 if (bss)
168 wpa_s->current_bss = bss;
169
170 return bss;
171}
172
173
174static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
175 u8 link_id, const u8 *bssid)
176{
177 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
178
179 if (!bss) {
180 wpa_supplicant_update_scan_results(wpa_s);
181 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
182 }
183
184 if (bss)
185 wpa_s->links[link_id].bss = bss;
186}
187
188
189static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
190 union wpa_event_data *data)
191{
192 struct wpa_ssid *ssid, *old_ssid;
193 struct wpa_bss *bss;
194 u8 drv_ssid[SSID_MAX_LEN];
195 size_t drv_ssid_len;
196 int res;
197
198 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
199 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
200
201 if (wpa_s->current_ssid->ssid_len == 0)
202 return 0; /* current profile still in use */
203 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
204 if (res < 0) {
205 wpa_msg(wpa_s, MSG_INFO,
206 "Failed to read SSID from driver");
207 return 0; /* try to use current profile */
208 }
209 drv_ssid_len = res;
210
211 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
212 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
213 drv_ssid_len) == 0)
214 return 0; /* current profile still in use */
215
216#ifdef CONFIG_OWE
217 if (wpa_s->current_bss &&
218 !(wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION)) {
219 const u8 *match_ssid;
220 size_t match_ssid_len;
221
222 owe_trans_ssid(wpa_s, wpa_s->current_bss,
223 &match_ssid, &match_ssid_len);
224 }
225 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
226 wpa_s->current_bss &&
227 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
228 drv_ssid_len == wpa_s->current_bss->ssid_len &&
229 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
230 drv_ssid_len) == 0)
231 return 0; /* current profile still in use */
232#endif /* CONFIG_OWE */
233
234 wpa_msg(wpa_s, MSG_DEBUG,
235 "Driver-initiated BSS selection changed the SSID to %s",
236 wpa_ssid_txt(drv_ssid, drv_ssid_len));
237 /* continue selecting a new network profile */
238 }
239
240 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
241 "information");
242 ssid = wpa_supplicant_get_ssid(wpa_s);
243 if (ssid == NULL) {
244 wpa_msg(wpa_s, MSG_INFO,
245 "No network configuration found for the current AP");
246 return -1;
247 }
248
249 if (wpas_network_disabled(wpa_s, ssid)) {
250 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
251 return -1;
252 }
253
254 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
255 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
256 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
257 return -1;
258 }
259
260 res = wpas_temp_disabled(wpa_s, ssid);
261 if (res > 0) {
262 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
263 "disabled for %d second(s)", res);
264 return -1;
265 }
266
267 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
268 "current AP");
269 bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
270 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
271 u8 wpa_ie[80];
272 size_t wpa_ie_len = sizeof(wpa_ie);
273 bool skip_default_rsne;
274
275 /* Do not override RSNE/RSNXE with the default values if the
276 * driver indicated the actual values used in the
277 * (Re)Association Request frame. */
278 skip_default_rsne = data && data->assoc_info.req_ies;
279 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
280 wpa_ie, &wpa_ie_len,
281 skip_default_rsne) < 0)
282 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
283 } else {
284 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
285 }
286
287 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
288 eapol_sm_invalidate_cached_session(wpa_s->eapol);
289 old_ssid = wpa_s->current_ssid;
290 wpa_s->current_ssid = ssid;
291
292 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
293 wpa_supplicant_initiate_eapol(wpa_s);
294 if (old_ssid != wpa_s->current_ssid)
295 wpas_notify_network_changed(wpa_s);
296
297 return 0;
298}
299
300
301void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
302{
303 struct wpa_supplicant *wpa_s = eloop_ctx;
304
305 if (wpa_s->countermeasures) {
306 wpa_s->countermeasures = 0;
307 wpa_drv_set_countermeasures(wpa_s, 0);
308 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
309
310 /*
311 * It is possible that the device is sched scanning, which means
312 * that a connection attempt will be done only when we receive
313 * scan results. However, in this case, it would be preferable
314 * to scan and connect immediately, so cancel the sched_scan and
315 * issue a regular scan flow.
316 */
317 wpa_supplicant_cancel_sched_scan(wpa_s);
318 wpa_supplicant_req_scan(wpa_s, 0, 0);
319 }
320}
321
322
323void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
324{
325 if (!wpa_s->valid_links)
326 return;
327
328 wpa_s->valid_links = 0;
329 wpa_s->mlo_assoc_link_id = 0;
330 os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN);
331 os_memset(wpa_s->links, 0, sizeof(wpa_s->links));
332}
333
334
335void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
336{
337 int bssid_changed;
338
339 wnm_bss_keep_alive_deinit(wpa_s);
340
341#ifdef CONFIG_IBSS_RSN
342 ibss_rsn_deinit(wpa_s->ibss_rsn);
343 wpa_s->ibss_rsn = NULL;
344#endif /* CONFIG_IBSS_RSN */
345
346#ifdef CONFIG_AP
347 wpa_supplicant_ap_deinit(wpa_s);
348#endif /* CONFIG_AP */
349
350#ifdef CONFIG_HS20
351 /* Clear possibly configured frame filters */
352 wpa_drv_configure_frame_filters(wpa_s, 0);
353#endif /* CONFIG_HS20 */
354
355 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
356 return;
357
358 if (os_reltime_initialized(&wpa_s->session_start)) {
359 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
360 wpa_s->session_start.sec = 0;
361 wpa_s->session_start.usec = 0;
362 wpas_notify_session_length(wpa_s);
363 }
364
365 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
366 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
367 os_memset(wpa_s->bssid, 0, ETH_ALEN);
368 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
369 sme_clear_on_disassoc(wpa_s);
370 wpa_s->current_bss = NULL;
371 wpa_s->assoc_freq = 0;
372
373 if (bssid_changed)
374 wpas_notify_bssid_changed(wpa_s);
375
376 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
377 eapol_sm_notify_portValid(wpa_s->eapol, false);
378 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
379 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
380 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
381 eapol_sm_notify_eap_success(wpa_s->eapol, false);
382 wpa_s->drv_authorized_port = 0;
383 wpa_s->ap_ies_from_associnfo = 0;
384 wpa_s->current_ssid = NULL;
385 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
386 wpa_s->key_mgmt = 0;
387 wpa_s->allowed_key_mgmts = 0;
388
389 wpas_rrm_reset(wpa_s);
390 wpa_s->wnmsleep_used = 0;
391 wnm_clear_coloc_intf_reporting(wpa_s);
392 wpa_s->disable_mbo_oce = 0;
393
394#ifdef CONFIG_TESTING_OPTIONS
395 wpa_s->last_tk_alg = WPA_ALG_NONE;
396 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
397#endif /* CONFIG_TESTING_OPTIONS */
398 wpa_s->ieee80211ac = 0;
399
400 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
401 wpa_s->enabled_4addr_mode = 0;
402
403 wpa_s->wps_scan_done = false;
404 wpas_reset_mlo_info(wpa_s);
405}
406
407
408static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
409{
410 struct wpa_ie_data ie;
411 int pmksa_set = -1;
412 size_t i;
413 struct rsn_pmksa_cache_entry *cur_pmksa;
414
415 /* Start with assumption of no PMKSA cache entry match for cases other
416 * than SAE. In particular, this is needed to generate the PMKSA cache
417 * entries for Suite B cases with driver-based roaming indication. */
418 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
419 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
420 pmksa_cache_clear_current(wpa_s->wpa);
421
422 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
423 ie.pmkid == NULL)
424 return;
425
426 for (i = 0; i < ie.num_pmkid; i++) {
427 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
428 ie.pmkid + i * PMKID_LEN,
429 NULL, NULL, 0, NULL, 0);
430 if (pmksa_set == 0) {
431 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
432 if (authorized)
433 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
434 break;
435 }
436 }
437
438 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
439 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
440}
441
442
443static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
444 union wpa_event_data *data)
445{
446 if (data == NULL) {
447 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
448 "event");
449 return;
450 }
451 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
452 " index=%d preauth=%d",
453 MAC2STR(data->pmkid_candidate.bssid),
454 data->pmkid_candidate.index,
455 data->pmkid_candidate.preauth);
456
457 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
458 data->pmkid_candidate.index,
459 data->pmkid_candidate.preauth);
460}
461
462
463static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
464{
465 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
466 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
467 return 0;
468
469#ifdef IEEE8021X_EAPOL
470 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
471 wpa_s->current_ssid &&
472 !(wpa_s->current_ssid->eapol_flags &
473 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
474 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
475 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
476 * plaintext or static WEP keys). */
477 return 0;
478 }
479#endif /* IEEE8021X_EAPOL */
480
481 return 1;
482}
483
484
485/**
486 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
487 * @wpa_s: pointer to wpa_supplicant data
488 * @ssid: Configuration data for the network
489 * Returns: 0 on success, -1 on failure
490 *
491 * This function is called when starting authentication with a network that is
492 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
493 */
494int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
495 struct wpa_ssid *ssid)
496{
497#ifdef IEEE8021X_EAPOL
498#ifdef PCSC_FUNCS
499 int aka = 0, sim = 0;
500
501 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
502 wpa_s->scard != NULL || wpa_s->conf->external_sim)
503 return 0;
504
505 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
506 sim = 1;
507 aka = 1;
508 } else {
509 struct eap_method_type *eap = ssid->eap.eap_methods;
510 while (eap->vendor != EAP_VENDOR_IETF ||
511 eap->method != EAP_TYPE_NONE) {
512 if (eap->vendor == EAP_VENDOR_IETF) {
513 if (eap->method == EAP_TYPE_SIM)
514 sim = 1;
515 else if (eap->method == EAP_TYPE_AKA ||
516 eap->method == EAP_TYPE_AKA_PRIME)
517 aka = 1;
518 }
519 eap++;
520 }
521 }
522
523 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
524 sim = 0;
525 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
526 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
527 NULL)
528 aka = 0;
529
530 if (!sim && !aka) {
531 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
532 "use SIM, but neither EAP-SIM nor EAP-AKA are "
533 "enabled");
534 return 0;
535 }
536
537 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
538 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
539
540 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
541 if (wpa_s->scard == NULL) {
542 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
543 "(pcsc-lite)");
544 return -1;
545 }
546 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
547 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
548#endif /* PCSC_FUNCS */
549#endif /* IEEE8021X_EAPOL */
550
551 return 0;
552}
553
554
555#ifndef CONFIG_NO_SCAN_PROCESSING
556
557#ifdef CONFIG_WEP
558static int has_wep_key(struct wpa_ssid *ssid)
559{
560 int i;
561
562 for (i = 0; i < NUM_WEP_KEYS; i++) {
563 if (ssid->wep_key_len[i])
564 return 1;
565 }
566
567 return 0;
568}
569#endif /* CONFIG_WEP */
570
571
572static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
573 struct wpa_ssid *ssid)
574{
575 int privacy = 0;
576
577 if (ssid->mixed_cell)
578 return 1;
579
580#ifdef CONFIG_WPS
581 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
582 return 1;
583#endif /* CONFIG_WPS */
584
585#ifdef CONFIG_OWE
586 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
587 return 1;
588#endif /* CONFIG_OWE */
589
590#ifdef CONFIG_WEP
591 if (has_wep_key(ssid))
592 privacy = 1;
593#endif /* CONFIG_WEP */
594
595#ifdef IEEE8021X_EAPOL
596 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
597 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
598 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
599 privacy = 1;
600#endif /* IEEE8021X_EAPOL */
601
602 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
603 privacy = 1;
604
605 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
606 privacy = 1;
607
608 if (bss->caps & IEEE80211_CAP_PRIVACY)
609 return privacy;
610 return !privacy;
611}
612
613
614static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
615 struct wpa_ssid *ssid,
616 struct wpa_bss *bss, int debug_print)
617{
618 struct wpa_ie_data ie;
619 int proto_match = 0;
620 const u8 *rsn_ie, *wpa_ie;
621 int ret;
622#ifdef CONFIG_WEP
623 int wep_ok;
624#endif /* CONFIG_WEP */
625 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
626
627 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
628 if (ret >= 0)
629 return ret;
630
631#ifdef CONFIG_WEP
632 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
633 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
634 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
635 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
636 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
637#endif /* CONFIG_WEP */
638
639 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
640 if (is_6ghz_bss && !rsn_ie) {
641 if (debug_print)
642 wpa_dbg(wpa_s, MSG_DEBUG,
643 " skip - 6 GHz BSS without RSNE");
644 return 0;
645 }
646
647 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
648 proto_match++;
649
650 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
651 if (debug_print)
652 wpa_dbg(wpa_s, MSG_DEBUG,
653 " skip RSN IE - parse failed");
654 break;
655 }
656 if (!ie.has_pairwise)
657 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
658 if (!ie.has_group)
659 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
660
661 if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
662 /* WEP and TKIP are not allowed on 6 GHz/MLD */
663 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
664 WPA_CIPHER_WEP104 |
665 WPA_CIPHER_TKIP);
666 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
667 WPA_CIPHER_WEP104 |
668 WPA_CIPHER_TKIP);
669 }
670
671#ifdef CONFIG_WEP
672 if (wep_ok &&
673 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
674 {
675 if (debug_print)
676 wpa_dbg(wpa_s, MSG_DEBUG,
677 " selected based on TSN in RSN IE");
678 return 1;
679 }
680#endif /* CONFIG_WEP */
681
682 if (!(ie.proto & ssid->proto) &&
683 !(ssid->proto & WPA_PROTO_OSEN)) {
684 if (debug_print)
685 wpa_dbg(wpa_s, MSG_DEBUG,
686 " skip RSN IE - proto mismatch");
687 break;
688 }
689
690 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
691 if (debug_print)
692 wpa_dbg(wpa_s, MSG_DEBUG,
693 " skip RSN IE - PTK cipher mismatch");
694 break;
695 }
696
697 if (!(ie.group_cipher & ssid->group_cipher)) {
698 if (debug_print)
699 wpa_dbg(wpa_s, MSG_DEBUG,
700 " skip RSN IE - GTK cipher mismatch");
701 break;
702 }
703
704 if (ssid->group_mgmt_cipher &&
705 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
706 if (debug_print)
707 wpa_dbg(wpa_s, MSG_DEBUG,
708 " skip RSN IE - group mgmt cipher mismatch");
709 break;
710 }
711
712 if (is_6ghz_bss) {
713 /* MFPC must be supported on 6 GHz */
714 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
715 if (debug_print)
716 wpa_dbg(wpa_s, MSG_DEBUG,
717 " skip RSNE - 6 GHz without MFPC");
718 break;
719 }
720
721 /* WPA PSK is not allowed on the 6 GHz band */
722 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
723 WPA_KEY_MGMT_FT_PSK |
724 WPA_KEY_MGMT_PSK_SHA256);
725 }
726
727 if (!(ie.key_mgmt & ssid->key_mgmt)) {
728 if (debug_print)
729 wpa_dbg(wpa_s, MSG_DEBUG,
730 " skip RSN IE - key mgmt mismatch");
731 break;
732 }
733
734 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
735 wpas_get_ssid_pmf(wpa_s, ssid) ==
736 MGMT_FRAME_PROTECTION_REQUIRED) {
737 if (debug_print)
738 wpa_dbg(wpa_s, MSG_DEBUG,
739 " skip RSN IE - no mgmt frame protection");
740 break;
741 }
742 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
743 wpas_get_ssid_pmf(wpa_s, ssid) ==
744 NO_MGMT_FRAME_PROTECTION) {
745 if (debug_print)
746 wpa_dbg(wpa_s, MSG_DEBUG,
747 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
748 break;
749 }
750
751 if (debug_print)
752 wpa_dbg(wpa_s, MSG_DEBUG,
753 " selected based on RSN IE");
754 return 1;
755 }
756
757 if (is_6ghz_bss) {
758 if (debug_print)
759 wpa_dbg(wpa_s, MSG_DEBUG,
760 " skip - 6 GHz BSS without matching RSNE");
761 return 0;
762 }
763
764 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
765 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
766 if (debug_print)
767 wpa_dbg(wpa_s, MSG_DEBUG,
768 " skip - MFP Required but network not MFP Capable");
769 return 0;
770 }
771
772 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
773 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
774 proto_match++;
775
776 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
777 if (debug_print)
778 wpa_dbg(wpa_s, MSG_DEBUG,
779 " skip WPA IE - parse failed");
780 break;
781 }
782
783#ifdef CONFIG_WEP
784 if (wep_ok &&
785 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
786 {
787 if (debug_print)
788 wpa_dbg(wpa_s, MSG_DEBUG,
789 " selected based on TSN in WPA IE");
790 return 1;
791 }
792#endif /* CONFIG_WEP */
793
794 if (!(ie.proto & ssid->proto)) {
795 if (debug_print)
796 wpa_dbg(wpa_s, MSG_DEBUG,
797 " skip WPA IE - proto mismatch");
798 break;
799 }
800
801 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
802 if (debug_print)
803 wpa_dbg(wpa_s, MSG_DEBUG,
804 " skip WPA IE - PTK cipher mismatch");
805 break;
806 }
807
808 if (!(ie.group_cipher & ssid->group_cipher)) {
809 if (debug_print)
810 wpa_dbg(wpa_s, MSG_DEBUG,
811 " skip WPA IE - GTK cipher mismatch");
812 break;
813 }
814
815 if (!(ie.key_mgmt & ssid->key_mgmt)) {
816 if (debug_print)
817 wpa_dbg(wpa_s, MSG_DEBUG,
818 " skip WPA IE - key mgmt mismatch");
819 break;
820 }
821
822 if (debug_print)
823 wpa_dbg(wpa_s, MSG_DEBUG,
824 " selected based on WPA IE");
825 return 1;
826 }
827
828 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
829 !rsn_ie) {
830 if (debug_print)
831 wpa_dbg(wpa_s, MSG_DEBUG,
832 " allow for non-WPA IEEE 802.1X");
833 return 1;
834 }
835
836#ifdef CONFIG_OWE
837 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
838 !wpa_ie && !rsn_ie) {
839 if (wpa_s->owe_transition_select &&
840 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
841 ssid->owe_transition_bss_select_count + 1 <=
842 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
843 ssid->owe_transition_bss_select_count++;
844 if (debug_print)
845 wpa_dbg(wpa_s, MSG_DEBUG,
846 " skip OWE transition BSS (selection count %d does not exceed %d)",
847 ssid->owe_transition_bss_select_count,
848 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
849 wpa_s->owe_transition_search = 1;
850 return 0;
851 }
852 if (debug_print)
853 wpa_dbg(wpa_s, MSG_DEBUG,
854 " allow in OWE transition mode");
855 return 1;
856 }
857#endif /* CONFIG_OWE */
858
859 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
860 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
861 if (debug_print)
862 wpa_dbg(wpa_s, MSG_DEBUG,
863 " skip - no WPA/RSN proto match");
864 return 0;
865 }
866
867 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
868 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
869 if (debug_print)
870 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
871 return 1;
872 }
873
874 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
875 if (debug_print)
876 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
877 return 1;
878 }
879
880 if (debug_print)
881 wpa_dbg(wpa_s, MSG_DEBUG,
882 " reject due to mismatch with WPA/WPA2");
883
884 return 0;
885}
886
887
888static int freq_allowed(int *freqs, int freq)
889{
890 int i;
891
892 if (freqs == NULL)
893 return 1;
894
895 for (i = 0; freqs[i]; i++)
896 if (freqs[i] == freq)
897 return 1;
898 return 0;
899}
900
901
902static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
903 struct wpa_bss *bss, int debug_print)
904{
905 const struct hostapd_hw_modes *mode = NULL, *modes;
906 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
907 const u8 *rate_ie;
908 int i, j, k;
909
910 if (bss->freq == 0)
911 return 1; /* Cannot do matching without knowing band */
912
913 modes = wpa_s->hw.modes;
914 if (modes == NULL) {
915 /*
916 * The driver does not provide any additional information
917 * about the utilized hardware, so allow the connection attempt
918 * to continue.
919 */
920 return 1;
921 }
922
923 for (i = 0; i < wpa_s->hw.num_modes; i++) {
924 for (j = 0; j < modes[i].num_channels; j++) {
925 int freq = modes[i].channels[j].freq;
926 if (freq == bss->freq) {
927 if (mode &&
928 mode->mode == HOSTAPD_MODE_IEEE80211G)
929 break; /* do not allow 802.11b replace
930 * 802.11g */
931 mode = &modes[i];
932 break;
933 }
934 }
935 }
936
937 if (mode == NULL)
938 return 0;
939
940 for (i = 0; i < (int) sizeof(scan_ie); i++) {
941 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
942 if (rate_ie == NULL)
943 continue;
944
945 for (j = 2; j < rate_ie[1] + 2; j++) {
946 int flagged = !!(rate_ie[j] & 0x80);
947 int r = (rate_ie[j] & 0x7f) * 5;
948
949 /*
950 * IEEE Std 802.11n-2009 7.3.2.2:
951 * The new BSS Membership selector value is encoded
952 * like a legacy basic rate, but it is not a rate and
953 * only indicates if the BSS members are required to
954 * support the mandatory features of Clause 20 [HT PHY]
955 * in order to join the BSS.
956 */
957 if (flagged && ((rate_ie[j] & 0x7f) ==
958 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
959 if (!ht_supported(mode)) {
960 if (debug_print)
961 wpa_dbg(wpa_s, MSG_DEBUG,
962 " hardware does not support HT PHY");
963 return 0;
964 }
965 continue;
966 }
967
968 /* There's also a VHT selector for 802.11ac */
969 if (flagged && ((rate_ie[j] & 0x7f) ==
970 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
971 if (!vht_supported(mode)) {
972 if (debug_print)
973 wpa_dbg(wpa_s, MSG_DEBUG,
974 " hardware does not support VHT PHY");
975 return 0;
976 }
977 continue;
978 }
979
980 if (flagged && ((rate_ie[j] & 0x7f) ==
981 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
982 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
983 if (debug_print)
984 wpa_dbg(wpa_s, MSG_DEBUG,
985 " hardware does not support HE PHY");
986 return 0;
987 }
988 continue;
989 }
990
991#ifdef CONFIG_SAE
992 if (flagged && ((rate_ie[j] & 0x7f) ==
993 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
994 if (wpa_s->conf->sae_pwe ==
995 SAE_PWE_HUNT_AND_PECK &&
996 !ssid->sae_password_id &&
997 !is_6ghz_freq(bss->freq) &&
998 wpa_key_mgmt_sae(ssid->key_mgmt)) {
999 if (debug_print)
1000 wpa_dbg(wpa_s, MSG_DEBUG,
1001 " SAE H2E disabled");
1002#ifdef CONFIG_TESTING_OPTIONS
1003 if (wpa_s->ignore_sae_h2e_only) {
1004 wpa_dbg(wpa_s, MSG_DEBUG,
1005 "TESTING: Ignore SAE H2E requirement mismatch");
1006 continue;
1007 }
1008#endif /* CONFIG_TESTING_OPTIONS */
1009 return 0;
1010 }
1011 continue;
1012 }
1013#endif /* CONFIG_SAE */
1014
1015 if (!flagged)
1016 continue;
1017
1018 /* check for legacy basic rates */
1019 for (k = 0; k < mode->num_rates; k++) {
1020 if (mode->rates[k] == r)
1021 break;
1022 }
1023 if (k == mode->num_rates) {
1024 /*
1025 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1026 * order to join a BSS all required rates
1027 * have to be supported by the hardware.
1028 */
1029 if (debug_print)
1030 wpa_dbg(wpa_s, MSG_DEBUG,
1031 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1032 r / 10, r % 10,
1033 bss->freq, mode->mode, mode->num_rates);
1034 return 0;
1035 }
1036 }
1037 }
1038
1039 return 1;
1040}
1041
1042
1043/*
1044 * Test whether BSS is in an ESS.
1045 * This is done differently in DMG (60 GHz) and non-DMG bands
1046 */
1047static int bss_is_ess(struct wpa_bss *bss)
1048{
1049 if (bss_is_dmg(bss)) {
1050 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1051 IEEE80211_CAP_DMG_AP;
1052 }
1053
1054 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1055 IEEE80211_CAP_ESS);
1056}
1057
1058
1059static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1060{
1061 size_t i;
1062
1063 for (i = 0; i < ETH_ALEN; i++) {
1064 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1065 return 0;
1066 }
1067 return 1;
1068}
1069
1070
1071static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1072{
1073 size_t i;
1074
1075 for (i = 0; i < num; i++) {
1076 const u8 *a = list + i * ETH_ALEN * 2;
1077 const u8 *m = a + ETH_ALEN;
1078
1079 if (match_mac_mask(a, addr, m))
1080 return 1;
1081 }
1082 return 0;
1083}
1084
1085
1086static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1087 const u8 **ret_ssid, size_t *ret_ssid_len)
1088{
1089#ifdef CONFIG_OWE
1090 const u8 *owe, *pos, *end, *bssid;
1091 u8 ssid_len;
1092 struct wpa_bss *open_bss;
1093
1094 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1095 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
1096 return;
1097
1098 pos = owe + 6;
1099 end = owe + 2 + owe[1];
1100
1101 if (end - pos < ETH_ALEN + 1)
1102 return;
1103 bssid = pos;
1104 pos += ETH_ALEN;
1105 ssid_len = *pos++;
1106 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1107 return;
1108
1109 /* Match the profile SSID against the OWE transition mode SSID on the
1110 * open network. */
1111 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1112 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1113 *ret_ssid = pos;
1114 *ret_ssid_len = ssid_len;
1115
1116 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1117 struct wpa_ssid *ssid;
1118
1119 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1120 if (wpas_network_disabled(wpa_s, ssid))
1121 continue;
1122 if (ssid->ssid_len == ssid_len &&
1123 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1124 /* OWE BSS in transition mode for a currently
1125 * enabled OWE network. */
1126 wpa_dbg(wpa_s, MSG_DEBUG,
1127 "OWE: transition mode OWE SSID for active OWE profile");
1128 bss->flags |= WPA_BSS_OWE_TRANSITION;
1129 break;
1130 }
1131 }
1132 }
1133
1134 if (bss->ssid_len > 0)
1135 return;
1136
1137 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1138 if (!open_bss)
1139 return;
1140 if (ssid_len != open_bss->ssid_len ||
1141 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1142 wpa_dbg(wpa_s, MSG_DEBUG,
1143 "OWE: transition mode SSID mismatch: %s",
1144 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1145 return;
1146 }
1147
1148 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1149 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1150 wpa_dbg(wpa_s, MSG_DEBUG,
1151 "OWE: transition mode open BSS unexpected info");
1152 return;
1153 }
1154
1155 pos = owe + 6;
1156 end = owe + 2 + owe[1];
1157
1158 if (end - pos < ETH_ALEN + 1)
1159 return;
1160 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1161 wpa_dbg(wpa_s, MSG_DEBUG,
1162 "OWE: transition mode BSSID mismatch: " MACSTR,
1163 MAC2STR(pos));
1164 return;
1165 }
1166 pos += ETH_ALEN;
1167 ssid_len = *pos++;
1168 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1169 return;
1170 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1171 wpa_ssid_txt(pos, ssid_len));
1172 os_memcpy(bss->ssid, pos, ssid_len);
1173 bss->ssid_len = ssid_len;
1174 bss->flags |= WPA_BSS_OWE_TRANSITION;
1175#endif /* CONFIG_OWE */
1176}
1177
1178
1179int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
1180{
1181 int i, j;
1182
1183 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1184 return 0;
1185
1186 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1187 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1188
1189 for (i = 0; i < mode->num_channels; i++) {
1190 struct hostapd_channel_data *chan = &mode->channels[i];
1191
1192 if (chan->freq == freq)
1193 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1194 }
1195 }
1196
1197 return 1;
1198}
1199
1200
1201static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1202 const u8 *match_ssid, size_t match_ssid_len,
1203 struct wpa_bss *bss, int bssid_ignore_count,
1204 bool debug_print);
1205
1206
1207#ifdef CONFIG_SAE_PK
1208static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1209 struct wpa_bss *orig_bss,
1210 struct wpa_ssid *ssid,
1211 const u8 *match_ssid,
1212 size_t match_ssid_len)
1213{
1214 struct wpa_bss *bss;
1215
1216 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1217 int count;
1218 const u8 *ie;
1219
1220 if (bss == orig_bss)
1221 continue;
1222 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1223 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
1224 continue;
1225
1226 /* TODO: Could be more thorough in checking what kind of
1227 * signal strength or throughput estimate would be acceptable
1228 * compared to the originally selected BSS. */
1229 if (bss->est_throughput < 2000)
1230 return false;
1231
1232 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1233 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1234 bss, count, 0))
1235 return true;
1236 }
1237
1238 return false;
1239}
1240#endif /* CONFIG_SAE_PK */
1241
1242
1243static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1244 const u8 *match_ssid, size_t match_ssid_len,
1245 struct wpa_bss *bss, int bssid_ignore_count,
1246 bool debug_print)
1247{
1248 int res;
1249 bool wpa, check_ssid, osen, rsn_osen = false;
1250 struct wpa_ie_data data;
1251#ifdef CONFIG_MBO
1252 const u8 *assoc_disallow;
1253#endif /* CONFIG_MBO */
1254#ifdef CONFIG_SAE
1255 u8 rsnxe_capa = 0;
1256#endif /* CONFIG_SAE */
1257 const u8 *ie;
1258
1259 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1260 wpa = ie && ie[1];
1261 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1262 wpa |= ie && ie[1];
1263 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1264 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1265 rsn_osen = true;
1266 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1267 osen = ie != NULL;
1268
1269#ifdef CONFIG_SAE
1270 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1271 if (ie && ie[1] >= 1)
1272 rsnxe_capa = ie[2];
1273#endif /* CONFIG_SAE */
1274
1275 check_ssid = wpa || ssid->ssid_len > 0;
1276
1277 if (wpas_network_disabled(wpa_s, ssid)) {
1278 if (debug_print)
1279 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1280 return false;
1281 }
1282
1283 res = wpas_temp_disabled(wpa_s, ssid);
1284 if (res > 0) {
1285 if (debug_print)
1286 wpa_dbg(wpa_s, MSG_DEBUG,
1287 " skip - disabled temporarily for %d second(s)",
1288 res);
1289 return false;
1290 }
1291
1292#ifdef CONFIG_WPS
1293 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
1294 if (debug_print)
1295 wpa_dbg(wpa_s, MSG_DEBUG,
1296 " skip - BSSID ignored (WPS)");
1297 return false;
1298 }
1299
1300 if (wpa && ssid->ssid_len == 0 &&
1301 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1302 check_ssid = false;
1303
1304 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1305 /* Only allow wildcard SSID match if an AP advertises active
1306 * WPS operation that matches our mode. */
1307 check_ssid = ssid->ssid_len > 0 ||
1308 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1309 }
1310#endif /* CONFIG_WPS */
1311
1312 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1313 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1314 check_ssid = false;
1315
1316 if (check_ssid &&
1317 (match_ssid_len != ssid->ssid_len ||
1318 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1319 if (debug_print)
1320 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1321 return false;
1322 }
1323
1324 if (ssid->bssid_set &&
1325 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1326 if (debug_print)
1327 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1328 return false;
1329 }
1330
1331 /* check the list of BSSIDs to ignore */
1332 if (ssid->num_bssid_ignore &&
1333 addr_in_list(bss->bssid, ssid->bssid_ignore,
1334 ssid->num_bssid_ignore)) {
1335 if (debug_print)
1336 wpa_dbg(wpa_s, MSG_DEBUG,
1337 " skip - BSSID configured to be ignored");
1338 return false;
1339 }
1340
1341 /* if there is a list of accepted BSSIDs, only accept those APs */
1342 if (ssid->num_bssid_accept &&
1343 !addr_in_list(bss->bssid, ssid->bssid_accept,
1344 ssid->num_bssid_accept)) {
1345 if (debug_print)
1346 wpa_dbg(wpa_s, MSG_DEBUG,
1347 " skip - BSSID not in list of accepted values");
1348 return false;
1349 }
1350
1351 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1352 return false;
1353
1354 if (!osen && !wpa &&
1355 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1356 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1357 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1358 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1359 if (debug_print)
1360 wpa_dbg(wpa_s, MSG_DEBUG,
1361 " skip - non-WPA network not allowed");
1362 return false;
1363 }
1364
1365#ifdef CONFIG_WEP
1366 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1367 if (debug_print)
1368 wpa_dbg(wpa_s, MSG_DEBUG,
1369 " skip - ignore WPA/WPA2 AP for WEP network block");
1370 return false;
1371 }
1372#endif /* CONFIG_WEP */
1373
1374 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1375 if (debug_print)
1376 wpa_dbg(wpa_s, MSG_DEBUG,
1377 " skip - non-OSEN network not allowed");
1378 return false;
1379 }
1380
1381 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1382 if (debug_print)
1383 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1384 return false;
1385 }
1386
1387 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1388 !bss_is_pbss(bss)) {
1389 if (debug_print)
1390 wpa_dbg(wpa_s, MSG_DEBUG,
1391 " skip - not ESS, PBSS, or MBSS");
1392 return false;
1393 }
1394
1395 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1396 if (debug_print)
1397 wpa_dbg(wpa_s, MSG_DEBUG,
1398 " skip - PBSS mismatch (ssid %d bss %d)",
1399 ssid->pbss, bss_is_pbss(bss));
1400 return false;
1401 }
1402
1403 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1404 if (debug_print)
1405 wpa_dbg(wpa_s, MSG_DEBUG,
1406 " skip - frequency not allowed");
1407 return false;
1408 }
1409
1410#ifdef CONFIG_MESH
1411 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1412 ssid->frequency != bss->freq) {
1413 if (debug_print)
1414 wpa_dbg(wpa_s, MSG_DEBUG,
1415 " skip - frequency not allowed (mesh)");
1416 return false;
1417 }
1418#endif /* CONFIG_MESH */
1419
1420 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1421 if (debug_print)
1422 wpa_dbg(wpa_s, MSG_DEBUG,
1423 " skip - rate sets do not match");
1424 return false;
1425 }
1426
1427#ifdef CONFIG_SAE
1428 /* When using SAE Password Identifier and when operationg on the 6 GHz
1429 * band, only H2E is allowed. */
1430 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1431 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1432 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1433 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1434 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1435 if (debug_print)
1436 wpa_dbg(wpa_s, MSG_DEBUG,
1437 " skip - SAE H2E required, but not supported by the AP");
1438 return false;
1439 }
1440#endif /* CONFIG_SAE */
1441
1442#ifdef CONFIG_SAE_PK
1443 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1444 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1445 if (debug_print)
1446 wpa_dbg(wpa_s, MSG_DEBUG,
1447 " skip - SAE-PK required, but not supported by the AP");
1448 return false;
1449 }
1450#endif /* CONFIG_SAE_PK */
1451
1452#ifndef CONFIG_IBSS_RSN
1453 if (ssid->mode == WPAS_MODE_IBSS &&
1454 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1455 if (debug_print)
1456 wpa_dbg(wpa_s, MSG_DEBUG,
1457 " skip - IBSS RSN not supported in the build");
1458 return false;
1459 }
1460#endif /* !CONFIG_IBSS_RSN */
1461
1462#ifdef CONFIG_P2P
1463 if (ssid->p2p_group &&
1464 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1465 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1466 if (debug_print)
1467 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1468 return false;
1469 }
1470
1471 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1472 struct wpabuf *p2p_ie;
1473 u8 dev_addr[ETH_ALEN];
1474
1475 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1476 if (!ie) {
1477 if (debug_print)
1478 wpa_dbg(wpa_s, MSG_DEBUG,
1479 " skip - no P2P element");
1480 return false;
1481 }
1482 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1483 if (!p2p_ie) {
1484 if (debug_print)
1485 wpa_dbg(wpa_s, MSG_DEBUG,
1486 " skip - could not fetch P2P element");
1487 return false;
1488 }
1489
1490 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1491 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1492 if (debug_print)
1493 wpa_dbg(wpa_s, MSG_DEBUG,
1494 " skip - no matching GO P2P Device Address in P2P element");
1495 wpabuf_free(p2p_ie);
1496 return false;
1497 }
1498 wpabuf_free(p2p_ie);
1499 }
1500
1501 /*
1502 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1503 * P2P Group Capability Bitmap and we are not in Group Formation with
1504 * that device.
1505 */
1506#endif /* CONFIG_P2P */
1507
1508 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1509 struct os_reltime diff;
1510
1511 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1512 if (debug_print)
1513 wpa_dbg(wpa_s, MSG_DEBUG,
1514 " skip - scan result not recent enough (%u.%06u seconds too old)",
1515 (unsigned int) diff.sec,
1516 (unsigned int) diff.usec);
1517 return false;
1518 }
1519#ifdef CONFIG_MBO
1520#ifdef CONFIG_TESTING_OPTIONS
1521 if (wpa_s->ignore_assoc_disallow)
1522 goto skip_assoc_disallow;
1523#endif /* CONFIG_TESTING_OPTIONS */
1524 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
1525 if (assoc_disallow && assoc_disallow[1] >= 1) {
1526 if (debug_print)
1527 wpa_dbg(wpa_s, MSG_DEBUG,
1528 " skip - MBO association disallowed (reason %u)",
1529 assoc_disallow[2]);
1530 return false;
1531 }
1532
1533 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1534 if (debug_print)
1535 wpa_dbg(wpa_s, MSG_DEBUG,
1536 " skip - AP temporarily disallowed");
1537 return false;
1538 }
1539#ifdef CONFIG_TESTING_OPTIONS
1540skip_assoc_disallow:
1541#endif /* CONFIG_TESTING_OPTIONS */
1542#endif /* CONFIG_MBO */
1543
1544#ifdef CONFIG_DPP
1545 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1546 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1547 ssid) &&
1548 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1549 !ssid->dpp_csign)) {
1550 if (debug_print)
1551 wpa_dbg(wpa_s, MSG_DEBUG,
1552 " skip - no PMKSA entry for DPP");
1553 return false;
1554 }
1555#endif /* CONFIG_DPP */
1556
1557#ifdef CONFIG_SAE_PK
1558 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1559 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1560 ((ssid->sae_password &&
1561 sae_pk_valid_password(ssid->sae_password)) ||
1562 (!ssid->sae_password && ssid->passphrase &&
1563 sae_pk_valid_password(ssid->passphrase))) &&
1564 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1565 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1566 match_ssid_len)) {
1567 if (debug_print)
1568 wpa_dbg(wpa_s, MSG_DEBUG,
1569 " skip - another acceptable BSS with SAE-PK in the same ESS");
1570 return false;
1571 }
1572#endif /* CONFIG_SAE_PK */
1573
1574 if (bss->ssid_len == 0) {
1575 if (debug_print)
1576 wpa_dbg(wpa_s, MSG_DEBUG,
1577 " skip - no SSID known for the BSS");
1578 return false;
1579 }
1580
1581 /* Matching configuration found */
1582 return true;
1583}
1584
1585
1586struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1587 int i, struct wpa_bss *bss,
1588 struct wpa_ssid *group,
1589 int only_first_ssid, int debug_print)
1590{
1591 u8 wpa_ie_len, rsn_ie_len;
1592 const u8 *ie;
1593 struct wpa_ssid *ssid;
1594 int osen;
1595 const u8 *match_ssid;
1596 size_t match_ssid_len;
1597 int bssid_ignore_count;
1598
1599 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1600 wpa_ie_len = ie ? ie[1] : 0;
1601
1602 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1603 rsn_ie_len = ie ? ie[1] : 0;
1604
1605 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1606 osen = ie != NULL;
1607
1608 if (debug_print) {
1609 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1610 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1611 i, MAC2STR(bss->bssid),
1612 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1613 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1614 bss->freq,
1615 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1616 " wps" : "",
1617 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1618 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1619 ? " p2p" : "",
1620 osen ? " osen=1" : "");
1621 }
1622
1623 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1624 if (bssid_ignore_count) {
1625 int limit = 1;
1626 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
1627 /*
1628 * When only a single network is enabled, we can
1629 * trigger BSSID ignoring on the first failure. This
1630 * should not be done with multiple enabled networks to
1631 * avoid getting forced to move into a worse ESS on
1632 * single error if there are no other BSSes of the
1633 * current ESS.
1634 */
1635 limit = 0;
1636 }
1637 if (bssid_ignore_count > limit) {
1638 if (debug_print) {
1639 wpa_dbg(wpa_s, MSG_DEBUG,
1640 " skip - BSSID ignored (count=%d limit=%d)",
1641 bssid_ignore_count, limit);
1642 }
1643 return NULL;
1644 }
1645 }
1646
1647 match_ssid = bss->ssid;
1648 match_ssid_len = bss->ssid_len;
1649 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1650
1651 if (match_ssid_len == 0) {
1652 if (debug_print)
1653 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
1654 return NULL;
1655 }
1656
1657 if (disallowed_bssid(wpa_s, bss->bssid)) {
1658 if (debug_print)
1659 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
1660 return NULL;
1661 }
1662
1663 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
1664 if (debug_print)
1665 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
1666 return NULL;
1667 }
1668
1669 if (disabled_freq(wpa_s, bss->freq)) {
1670 if (debug_print)
1671 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1672 return NULL;
1673 }
1674
1675 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
1676 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1677 bss, bssid_ignore_count, debug_print))
1678 return ssid;
1679 }
1680
1681 /* No matching configuration found */
1682 return NULL;
1683}
1684
1685
1686static struct wpa_bss *
1687wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1688 struct wpa_ssid *group,
1689 struct wpa_ssid **selected_ssid,
1690 int only_first_ssid)
1691{
1692 unsigned int i;
1693
1694 if (wpa_s->current_ssid) {
1695 struct wpa_ssid *ssid;
1696
1697 wpa_dbg(wpa_s, MSG_DEBUG,
1698 "Scan results matching the currently selected network");
1699 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1700 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1701
1702 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1703 only_first_ssid, 0);
1704 if (ssid != wpa_s->current_ssid)
1705 continue;
1706 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1707 " freq=%d level=%d snr=%d est_throughput=%u",
1708 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1709 bss->snr, bss->est_throughput);
1710 }
1711 }
1712
1713 if (only_first_ssid)
1714 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1715 group->id);
1716 else
1717 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1718 group->priority);
1719
1720 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1721 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1722
1723 wpa_s->owe_transition_select = 1;
1724 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1725 only_first_ssid, 1);
1726 wpa_s->owe_transition_select = 0;
1727 if (!*selected_ssid)
1728 continue;
1729 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
1730 " ssid='%s'",
1731 bss == wpa_s->current_bss ? "current ": "",
1732 MAC2STR(bss->bssid),
1733 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1734 return bss;
1735 }
1736
1737 return NULL;
1738}
1739
1740
1741struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1742 struct wpa_ssid **selected_ssid)
1743{
1744 struct wpa_bss *selected = NULL;
1745 size_t prio;
1746 struct wpa_ssid *next_ssid = NULL;
1747 struct wpa_ssid *ssid;
1748
1749 if (wpa_s->last_scan_res == NULL ||
1750 wpa_s->last_scan_res_used == 0)
1751 return NULL; /* no scan results from last update */
1752
1753 if (wpa_s->next_ssid) {
1754 /* check that next_ssid is still valid */
1755 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1756 if (ssid == wpa_s->next_ssid)
1757 break;
1758 }
1759 next_ssid = ssid;
1760 wpa_s->next_ssid = NULL;
1761 }
1762
1763 while (selected == NULL) {
1764 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1765 if (next_ssid && next_ssid->priority ==
1766 wpa_s->conf->pssid[prio]->priority) {
1767 selected = wpa_supplicant_select_bss(
1768 wpa_s, next_ssid, selected_ssid, 1);
1769 if (selected)
1770 break;
1771 }
1772 selected = wpa_supplicant_select_bss(
1773 wpa_s, wpa_s->conf->pssid[prio],
1774 selected_ssid, 0);
1775 if (selected)
1776 break;
1777 }
1778
1779 if (selected == NULL && wpa_s->bssid_ignore &&
1780 !wpa_s->countermeasures) {
1781 wpa_dbg(wpa_s, MSG_DEBUG,
1782 "No APs found - clear BSSID ignore list and try again");
1783 wpa_bssid_ignore_clear(wpa_s);
1784 wpa_s->bssid_ignore_cleared = true;
1785 } else if (selected == NULL)
1786 break;
1787 }
1788
1789 ssid = *selected_ssid;
1790 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1791 !ssid->passphrase && !ssid->ext_psk) {
1792 const char *field_name, *txt = NULL;
1793
1794 wpa_dbg(wpa_s, MSG_DEBUG,
1795 "PSK/passphrase not yet available for the selected network");
1796
1797 wpas_notify_network_request(wpa_s, ssid,
1798 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1799
1800 field_name = wpa_supplicant_ctrl_req_to_string(
1801 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1802 if (field_name == NULL)
1803 return NULL;
1804
1805 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1806
1807 selected = NULL;
1808 }
1809
1810 return selected;
1811}
1812
1813
1814static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1815 int timeout_sec, int timeout_usec)
1816{
1817 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1818 /*
1819 * No networks are enabled; short-circuit request so
1820 * we don't wait timeout seconds before transitioning
1821 * to INACTIVE state.
1822 */
1823 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1824 "since there are no enabled networks");
1825 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1826 return;
1827 }
1828
1829 wpa_s->scan_for_connection = 1;
1830 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1831}
1832
1833
1834int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1835 struct wpa_bss *selected,
1836 struct wpa_ssid *ssid)
1837{
1838#ifdef IEEE8021X_EAPOL
1839 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
1840 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
1841 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1842 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1843 "PBC session overlap");
1844 wpas_notify_wps_event_pbc_overlap(wpa_s);
1845 wpa_s->wps_overlap = true;
1846#ifdef CONFIG_P2P
1847 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1848 wpa_s->p2p_in_provisioning) {
1849 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1850 wpa_s, NULL);
1851 return -1;
1852 }
1853#endif /* CONFIG_P2P */
1854
1855#ifdef CONFIG_WPS
1856 wpas_wps_pbc_overlap(wpa_s);
1857 wpas_wps_cancel(wpa_s);
1858#endif /* CONFIG_WPS */
1859 return -1;
1860 }
1861#endif /* IEEE8021X_EAPOL */
1862
1863 wpa_msg(wpa_s, MSG_DEBUG,
1864 "Considering connect request: reassociate: %d selected: "
1865 MACSTR " bssid: " MACSTR " pending: " MACSTR
1866 " wpa_state: %s ssid=%p current_ssid=%p",
1867 wpa_s->reassociate, MAC2STR(selected->bssid),
1868 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1869 wpa_supplicant_state_txt(wpa_s->wpa_state),
1870 ssid, wpa_s->current_ssid);
1871
1872 /*
1873 * Do not trigger new association unless the BSSID has changed or if
1874 * reassociation is requested. If we are in process of associating with
1875 * the selected BSSID, do not trigger new attempt.
1876 */
1877 if (wpa_s->reassociate ||
1878 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1879 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1880 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1881 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1882 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1883 0) ||
1884 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1885 ssid != wpa_s->current_ssid)))) {
1886 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1887 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1888 return 0;
1889 }
1890 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1891 MAC2STR(selected->bssid));
1892 wpa_supplicant_associate(wpa_s, selected, ssid);
1893 } else {
1894 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1895 "connect with the selected AP");
1896 }
1897
1898 return 0;
1899}
1900
1901
1902static struct wpa_ssid *
1903wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1904{
1905 size_t prio;
1906 struct wpa_ssid *ssid;
1907
1908 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1909 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1910 {
1911 if (wpas_network_disabled(wpa_s, ssid))
1912 continue;
1913#ifndef CONFIG_IBSS_RSN
1914 if (ssid->mode == WPAS_MODE_IBSS &&
1915 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1916 WPA_KEY_MGMT_WPA_NONE))) {
1917 wpa_msg(wpa_s, MSG_INFO,
1918 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1919 wpa_ssid_txt(ssid->ssid,
1920 ssid->ssid_len));
1921 continue;
1922 }
1923#endif /* !CONFIG_IBSS_RSN */
1924 if (ssid->mode == WPAS_MODE_IBSS ||
1925 ssid->mode == WPAS_MODE_AP ||
1926 ssid->mode == WPAS_MODE_MESH)
1927 return ssid;
1928 }
1929 }
1930 return NULL;
1931}
1932
1933
1934/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1935 * on BSS added and BSS changed events */
1936static void wpa_supplicant_rsn_preauth_scan_results(
1937 struct wpa_supplicant *wpa_s)
1938{
1939 struct wpa_bss *bss;
1940
1941 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1942 return;
1943
1944 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1945 const u8 *ssid, *rsn;
1946
1947 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1948 if (ssid == NULL)
1949 continue;
1950
1951 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1952 if (rsn == NULL)
1953 continue;
1954
1955 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1956 }
1957
1958}
1959
1960
1961#ifndef CONFIG_NO_ROAMING
1962
1963static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1964{
1965 if (noise == WPA_INVALID_NOISE)
1966 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1967 DEFAULT_NOISE_FLOOR_2GHZ;
1968 return avg_signal - noise;
1969}
1970
1971
1972static unsigned int
1973wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1974 const struct wpa_bss *bss, int snr)
1975{
1976 int rate = wpa_bss_get_max_rate(bss);
1977 const u8 *ies = wpa_bss_ie_ptr(bss);
1978 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1979
1980 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
1981}
1982
1983
1984int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1985 struct wpa_bss *current_bss,
1986 struct wpa_bss *selected)
1987{
1988 int min_diff, diff;
1989 int to_5ghz, to_6ghz;
1990 int cur_level;
1991 unsigned int cur_est, sel_est;
1992 struct wpa_signal_info si;
1993 int cur_snr = 0;
1994 int ret = 0;
1995
1996 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1997 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1998 " freq=%d level=%d snr=%d est_throughput=%u",
1999 MAC2STR(current_bss->bssid),
2000 current_bss->freq, current_bss->level,
2001 current_bss->snr, current_bss->est_throughput);
2002 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
2003 " freq=%d level=%d snr=%d est_throughput=%u",
2004 MAC2STR(selected->bssid), selected->freq, selected->level,
2005 selected->snr, selected->est_throughput);
2006
2007 if (wpa_s->current_ssid->bssid_set &&
2008 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
2009 0) {
2010 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2011 "has preferred BSSID");
2012 return 1;
2013 }
2014
2015 cur_level = current_bss->level;
2016 cur_est = current_bss->est_throughput;
2017 sel_est = selected->est_throughput;
2018
2019 /*
2020 * Try to poll the signal from the driver since this will allow to get
2021 * more accurate values. In some cases, there can be big differences
2022 * between the RSSI of the Probe Response frames of the AP we are
2023 * associated with and the Beacon frames we hear from the same AP after
2024 * association. This can happen, e.g., when there are two antennas that
2025 * hear the AP very differently. If the driver chooses to hear the
2026 * Probe Response frames during the scan on the "bad" antenna because
2027 * it wants to save power, but knows to choose the other antenna after
2028 * association, we will hear our AP with a low RSSI as part of the
2029 * scan even when we can hear it decently on the other antenna. To cope
2030 * with this, ask the driver to teach us how it hears the AP. Also, the
2031 * scan results may be a bit old, since we can very quickly get fresh
2032 * information about our currently associated AP.
2033 */
2034 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
2035 (si.data.avg_beacon_signal || si.data.avg_signal)) {
2036 cur_level = si.data.avg_beacon_signal ?
2037 si.data.avg_beacon_signal : si.data.avg_signal;
2038 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2039 si.current_noise);
2040
2041 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2042 current_bss,
2043 cur_snr);
2044 wpa_dbg(wpa_s, MSG_DEBUG,
2045 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2046 cur_level, cur_snr, cur_est);
2047 }
2048
2049 if (sel_est > cur_est + 5000) {
2050 wpa_dbg(wpa_s, MSG_DEBUG,
2051 "Allow reassociation - selected BSS has better estimated throughput");
2052 return 1;
2053 }
2054
2055 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
2056 to_6ghz = is_6ghz_freq(selected->freq) &&
2057 !is_6ghz_freq(current_bss->freq);
2058
2059 if (cur_level < 0 &&
2060 cur_level > selected->level + to_5ghz * 2 + to_6ghz * 2 &&
2061 sel_est < cur_est * 1.2) {
2062 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2063 "signal level");
2064 return 0;
2065 }
2066
2067 if (cur_est > sel_est + 5000) {
2068 wpa_dbg(wpa_s, MSG_DEBUG,
2069 "Skip roam - Current BSS has better estimated throughput");
2070 return 0;
2071 }
2072
2073 if (cur_snr > GREAT_SNR) {
2074 wpa_dbg(wpa_s, MSG_DEBUG,
2075 "Skip roam - Current BSS has good SNR (%u > %u)",
2076 cur_snr, GREAT_SNR);
2077 return 0;
2078 }
2079
2080 if (cur_level < -85) /* ..-86 dBm */
2081 min_diff = 1;
2082 else if (cur_level < -80) /* -85..-81 dBm */
2083 min_diff = 2;
2084 else if (cur_level < -75) /* -80..-76 dBm */
2085 min_diff = 3;
2086 else if (cur_level < -70) /* -75..-71 dBm */
2087 min_diff = 4;
2088 else if (cur_level < 0) /* -70..-1 dBm */
2089 min_diff = 5;
2090 else /* unspecified units (not in dBm) */
2091 min_diff = 2;
2092
2093 if (cur_est > sel_est * 1.5)
2094 min_diff += 10;
2095 else if (cur_est > sel_est * 1.2)
2096 min_diff += 5;
2097 else if (cur_est > sel_est * 1.1)
2098 min_diff += 2;
2099 else if (cur_est > sel_est)
2100 min_diff++;
2101 else if (sel_est > cur_est * 1.5)
2102 min_diff -= 10;
2103 else if (sel_est > cur_est * 1.2)
2104 min_diff -= 5;
2105 else if (sel_est > cur_est * 1.1)
2106 min_diff -= 2;
2107 else if (sel_est > cur_est)
2108 min_diff--;
2109
2110 if (to_5ghz)
2111 min_diff -= 2;
2112 if (to_6ghz)
2113 min_diff -= 2;
2114 diff = selected->level - cur_level;
2115 if (diff < min_diff) {
2116 wpa_dbg(wpa_s, MSG_DEBUG,
2117 "Skip roam - too small difference in signal level (%d < %d)",
2118 diff, min_diff);
2119 ret = 0;
2120 } else {
2121 wpa_dbg(wpa_s, MSG_DEBUG,
2122 "Allow reassociation due to difference in signal level (%d >= %d)",
2123 diff, min_diff);
2124 ret = 1;
2125 }
2126 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2127 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2128 " sel_freq=%d sel_level=%d sel_est=%d",
2129 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2130 MAC2STR(current_bss->bssid),
2131 current_bss->freq, cur_level, cur_est,
2132 MAC2STR(selected->bssid),
2133 selected->freq, selected->level, sel_est);
2134 return ret;
2135}
2136
2137#endif /* CONFIG_NO_ROAMING */
2138
2139
2140static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2141 struct wpa_bss *selected,
2142 struct wpa_ssid *ssid)
2143{
2144 struct wpa_bss *current_bss = NULL;
2145
2146 if (wpa_s->reassociate)
2147 return 1; /* explicit request to reassociate */
2148 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2149 return 1; /* we are not associated; continue */
2150 if (wpa_s->current_ssid == NULL)
2151 return 1; /* unknown current SSID */
2152 if (wpa_s->current_ssid != ssid)
2153 return 1; /* different network block */
2154
2155 if (wpas_driver_bss_selection(wpa_s))
2156 return 0; /* Driver-based roaming */
2157
2158 if (wpa_s->current_ssid->ssid)
2159 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2160 wpa_s->current_ssid->ssid,
2161 wpa_s->current_ssid->ssid_len);
2162 if (!current_bss)
2163 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2164
2165 if (!current_bss)
2166 return 1; /* current BSS not seen in scan results */
2167
2168 if (current_bss == selected)
2169 return 0;
2170
2171 if (selected->last_update_idx > current_bss->last_update_idx)
2172 return 1; /* current BSS not seen in the last scan */
2173
2174#ifndef CONFIG_NO_ROAMING
2175 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2176 selected);
2177#else /* CONFIG_NO_ROAMING */
2178 return 0;
2179#endif /* CONFIG_NO_ROAMING */
2180}
2181
2182
2183/*
2184 * Return a negative value if no scan results could be fetched or if scan
2185 * results should not be shared with other virtual interfaces.
2186 * Return 0 if scan results were fetched and may be shared with other
2187 * interfaces.
2188 * Return 1 if scan results may be shared with other virtual interfaces but may
2189 * not trigger any operations.
2190 * Return 2 if the interface was removed and cannot be used.
2191 */
2192static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2193 union wpa_event_data *data,
2194 int own_request, int update_only)
2195{
2196 struct wpa_scan_results *scan_res = NULL;
2197 int ret = 0;
2198 int ap = 0;
2199#ifndef CONFIG_NO_RANDOM_POOL
2200 size_t i, num;
2201#endif /* CONFIG_NO_RANDOM_POOL */
2202
2203#ifdef CONFIG_AP
2204 if (wpa_s->ap_iface)
2205 ap = 1;
2206#endif /* CONFIG_AP */
2207
2208 wpa_supplicant_notify_scanning(wpa_s, 0);
2209
2210 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2211 data ? &data->scan_info :
2212 NULL, 1);
2213 if (scan_res == NULL) {
2214 if (wpa_s->conf->ap_scan == 2 || ap ||
2215 wpa_s->scan_res_handler == scan_only_handler)
2216 return -1;
2217 if (!own_request)
2218 return -1;
2219 if (data && data->scan_info.external_scan)
2220 return -1;
2221 if (wpa_s->scan_res_fail_handler) {
2222 void (*handler)(struct wpa_supplicant *wpa_s);
2223
2224 handler = wpa_s->scan_res_fail_handler;
2225 wpa_s->scan_res_fail_handler = NULL;
2226 handler(wpa_s);
2227 } else {
2228 wpa_dbg(wpa_s, MSG_DEBUG,
2229 "Failed to get scan results - try scanning again");
2230 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2231 }
2232
2233 ret = -1;
2234 goto scan_work_done;
2235 }
2236
2237#ifndef CONFIG_NO_RANDOM_POOL
2238 num = scan_res->num;
2239 if (num > 10)
2240 num = 10;
2241 for (i = 0; i < num; i++) {
2242 u8 buf[5];
2243 struct wpa_scan_res *res = scan_res->res[i];
2244 buf[0] = res->bssid[5];
2245 buf[1] = res->qual & 0xff;
2246 buf[2] = res->noise & 0xff;
2247 buf[3] = res->level & 0xff;
2248 buf[4] = res->tsf & 0xff;
2249 random_add_randomness(buf, sizeof(buf));
2250 }
2251#endif /* CONFIG_NO_RANDOM_POOL */
2252
2253 if (update_only) {
2254 ret = 1;
2255 goto scan_work_done;
2256 }
2257
2258 if (own_request && wpa_s->scan_res_handler &&
2259 !(data && data->scan_info.external_scan)) {
2260 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2261 struct wpa_scan_results *scan_res);
2262
2263 scan_res_handler = wpa_s->scan_res_handler;
2264 wpa_s->scan_res_handler = NULL;
2265 scan_res_handler(wpa_s, scan_res);
2266 ret = 1;
2267 goto scan_work_done;
2268 }
2269
2270 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
2271 wpa_s->own_scan_running,
2272 data ? data->scan_info.external_scan : 0);
2273 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
2274 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2275 own_request && !(data && data->scan_info.external_scan)) {
2276 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2277 wpa_s->manual_scan_id);
2278 wpa_s->manual_scan_use_id = 0;
2279 } else {
2280 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2281 }
2282 wpas_notify_scan_results(wpa_s);
2283
2284 wpas_notify_scan_done(wpa_s, 1);
2285
2286 if (ap) {
2287 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2288#ifdef CONFIG_AP
2289 if (wpa_s->ap_iface->scan_cb)
2290 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2291#endif /* CONFIG_AP */
2292 goto scan_work_done;
2293 }
2294
2295 if (data && data->scan_info.external_scan) {
2296 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
2297 wpa_scan_results_free(scan_res);
2298 return 0;
2299 }
2300
2301 if (wnm_scan_process(wpa_s, 1) > 0)
2302 goto scan_work_done;
2303
2304 if (sme_proc_obss_scan(wpa_s) > 0)
2305 goto scan_work_done;
2306
2307 if (own_request && data &&
2308 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2309 goto scan_work_done;
2310
2311 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2312 goto scan_work_done;
2313
2314 if (autoscan_notify_scan(wpa_s, scan_res))
2315 goto scan_work_done;
2316
2317 if (wpa_s->disconnected) {
2318 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2319 goto scan_work_done;
2320 }
2321
2322 if (!wpas_driver_bss_selection(wpa_s) &&
2323 bgscan_notify_scan(wpa_s, scan_res) == 1)
2324 goto scan_work_done;
2325
2326 wpas_wps_update_ap_info(wpa_s, scan_res);
2327
2328 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2329 wpa_s->wpa_state < WPA_COMPLETED)
2330 goto scan_work_done;
2331
2332 wpa_scan_results_free(scan_res);
2333
2334 if (own_request && wpa_s->scan_work) {
2335 struct wpa_radio_work *work = wpa_s->scan_work;
2336 wpa_s->scan_work = NULL;
2337 radio_work_done(work);
2338 }
2339
2340 os_free(wpa_s->last_scan_freqs);
2341 wpa_s->last_scan_freqs = NULL;
2342 wpa_s->num_last_scan_freqs = 0;
2343 if (own_request && data &&
2344 data->scan_info.freqs && data->scan_info.num_freqs) {
2345 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2346 data->scan_info.num_freqs);
2347 if (wpa_s->last_scan_freqs) {
2348 os_memcpy(wpa_s->last_scan_freqs,
2349 data->scan_info.freqs,
2350 sizeof(int) * data->scan_info.num_freqs);
2351 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2352 }
2353 }
2354
2355 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2356 return ret;
2357
2358 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
2359
2360scan_work_done:
2361 wpa_scan_results_free(scan_res);
2362 if (own_request && wpa_s->scan_work) {
2363 struct wpa_radio_work *work = wpa_s->scan_work;
2364 wpa_s->scan_work = NULL;
2365 radio_work_done(work);
2366 }
2367 return ret;
2368}
2369
2370
2371static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
2372 int new_scan, int own_request)
2373{
2374 struct wpa_bss *selected;
2375 struct wpa_ssid *ssid = NULL;
2376 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2377
2378 if (time_to_reenable > 0) {
2379 wpa_dbg(wpa_s, MSG_DEBUG,
2380 "Postpone network selection by %d seconds since all networks are disabled",
2381 time_to_reenable);
2382 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2383 eloop_register_timeout(time_to_reenable, 0,
2384 wpas_network_reenabled, wpa_s, NULL);
2385 return 0;
2386 }
2387
2388 if (wpa_s->p2p_mgmt)
2389 return 0; /* no normal connection on p2p_mgmt interface */
2390
2391 wpa_s->owe_transition_search = 0;
2392 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
2393
2394#ifdef CONFIG_MESH
2395 if (wpa_s->ifmsh) {
2396 wpa_msg(wpa_s, MSG_INFO,
2397 "Avoiding join because we already joined a mesh group");
2398 return 0;
2399 }
2400#endif /* CONFIG_MESH */
2401
2402 if (selected) {
2403 int skip;
2404 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
2405 if (skip) {
2406 if (new_scan)
2407 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2408 return 0;
2409 }
2410
2411 wpa_s->suitable_network++;
2412
2413 if (ssid != wpa_s->current_ssid &&
2414 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2415 wpa_s->own_disconnect_req = 1;
2416 wpa_supplicant_deauthenticate(
2417 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2418 }
2419
2420 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
2421 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
2422 return -1;
2423 }
2424 wpa_s->supp_pbc_active = false;
2425
2426 if (new_scan)
2427 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2428 /*
2429 * Do not allow other virtual radios to trigger operations based
2430 * on these scan results since we do not want them to start
2431 * other associations at the same time.
2432 */
2433 return 1;
2434 } else {
2435 wpa_s->no_suitable_network++;
2436 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2437 ssid = wpa_supplicant_pick_new_network(wpa_s);
2438 if (ssid) {
2439 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2440 wpa_supplicant_associate(wpa_s, NULL, ssid);
2441 if (new_scan)
2442 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2443 } else if (own_request) {
2444 /*
2445 * No SSID found. If SCAN results are as a result of
2446 * own scan request and not due to a scan request on
2447 * another shared interface, try another scan.
2448 */
2449 int timeout_sec = wpa_s->scan_interval;
2450 int timeout_usec = 0;
2451#ifdef CONFIG_P2P
2452 int res;
2453
2454 res = wpas_p2p_scan_no_go_seen(wpa_s);
2455 if (res == 2)
2456 return 2;
2457 if (res == 1)
2458 return 0;
2459
2460 if (wpas_p2p_retry_limit_exceeded(wpa_s))
2461 return 0;
2462
2463 if (wpa_s->p2p_in_provisioning ||
2464 wpa_s->show_group_started ||
2465 wpa_s->p2p_in_invitation) {
2466 /*
2467 * Use shorter wait during P2P Provisioning
2468 * state and during P2P join-a-group operation
2469 * to speed up group formation.
2470 */
2471 timeout_sec = 0;
2472 timeout_usec = 250000;
2473 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2474 timeout_usec);
2475 return 0;
2476 }
2477#endif /* CONFIG_P2P */
2478#ifdef CONFIG_INTERWORKING
2479 if (wpa_s->conf->auto_interworking &&
2480 wpa_s->conf->interworking &&
2481 wpa_s->conf->cred) {
2482 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2483 "start ANQP fetch since no matching "
2484 "networks found");
2485 wpa_s->network_select = 1;
2486 wpa_s->auto_network_select = 1;
2487 interworking_start_fetch_anqp(wpa_s);
2488 return 1;
2489 }
2490#endif /* CONFIG_INTERWORKING */
2491#ifdef CONFIG_WPS
2492 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2493 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2494 timeout_sec = 0;
2495 timeout_usec = 500000;
2496 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2497 timeout_usec);
2498 return 0;
2499 }
2500#endif /* CONFIG_WPS */
2501#ifdef CONFIG_OWE
2502 if (wpa_s->owe_transition_search) {
2503 wpa_dbg(wpa_s, MSG_DEBUG,
2504 "OWE: Use shorter wait during transition mode search");
2505 timeout_sec = 0;
2506 timeout_usec = 500000;
2507 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2508 timeout_usec);
2509 return 0;
2510 }
2511#endif /* CONFIG_OWE */
2512 if (wpa_supplicant_req_sched_scan(wpa_s))
2513 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2514 timeout_usec);
2515
2516 wpa_msg_ctrl(wpa_s, MSG_INFO,
2517 WPA_EVENT_NETWORK_NOT_FOUND);
2518 }
2519 }
2520 return 0;
2521}
2522
2523
2524static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2525 union wpa_event_data *data)
2526{
2527 struct wpa_supplicant *ifs;
2528 int res;
2529
2530 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
2531 if (res == 2) {
2532 /*
2533 * Interface may have been removed, so must not dereference
2534 * wpa_s after this.
2535 */
2536 return 1;
2537 }
2538
2539 if (res < 0) {
2540 /*
2541 * If no scan results could be fetched, then no need to
2542 * notify those interfaces that did not actually request
2543 * this scan. Similarly, if scan results started a new operation on this
2544 * interface, do not notify other interfaces to avoid concurrent
2545 * operations during a connection attempt.
2546 */
2547 return 0;
2548 }
2549
2550 /*
2551 * Check other interfaces to see if they share the same radio. If
2552 * so, they get updated with this same scan info.
2553 */
2554 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2555 radio_list) {
2556 if (ifs != wpa_s) {
2557 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2558 "sibling", ifs->ifname);
2559 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2560 res > 0);
2561 if (res < 0)
2562 return 0;
2563 }
2564 }
2565
2566 return 0;
2567}
2568
2569#endif /* CONFIG_NO_SCAN_PROCESSING */
2570
2571
2572int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2573{
2574#ifdef CONFIG_NO_SCAN_PROCESSING
2575 return -1;
2576#else /* CONFIG_NO_SCAN_PROCESSING */
2577 struct os_reltime now;
2578
2579 wpa_s->ignore_post_flush_scan_res = 0;
2580
2581 if (wpa_s->last_scan_res_used == 0)
2582 return -1;
2583
2584 os_get_reltime(&now);
2585 if (os_reltime_expired(&now, &wpa_s->last_scan,
2586 wpa_s->conf->scan_res_valid_for_connect)) {
2587 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2588 return -1;
2589 }
2590
2591 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
2592#endif /* CONFIG_NO_SCAN_PROCESSING */
2593}
2594
2595
2596int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2597{
2598#ifdef CONFIG_NO_SCAN_PROCESSING
2599 return -1;
2600#else /* CONFIG_NO_SCAN_PROCESSING */
2601 return wpas_select_network_from_last_scan(wpa_s, 1, 1);
2602#endif /* CONFIG_NO_SCAN_PROCESSING */
2603}
2604
2605
2606#ifdef CONFIG_WNM
2607
2608static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2609{
2610 struct wpa_supplicant *wpa_s = eloop_ctx;
2611
2612 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2613 return;
2614
2615 if (!wpa_s->no_keep_alive) {
2616 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2617 MAC2STR(wpa_s->bssid));
2618 /* TODO: could skip this if normal data traffic has been sent */
2619 /* TODO: Consider using some more appropriate data frame for
2620 * this */
2621 if (wpa_s->l2)
2622 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2623 (u8 *) "", 0);
2624 }
2625
2626#ifdef CONFIG_SME
2627 if (wpa_s->sme.bss_max_idle_period) {
2628 unsigned int msec;
2629 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2630 if (msec > 100)
2631 msec -= 100;
2632 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2633 wnm_bss_keep_alive, wpa_s, NULL);
2634 }
2635#endif /* CONFIG_SME */
2636}
2637
2638
2639static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2640 const u8 *ies, size_t ies_len)
2641{
2642 struct ieee802_11_elems elems;
2643
2644 if (ies == NULL)
2645 return;
2646
2647 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2648 return;
2649
2650#ifdef CONFIG_SME
2651 if (elems.bss_max_idle_period) {
2652 unsigned int msec;
2653 wpa_s->sme.bss_max_idle_period =
2654 WPA_GET_LE16(elems.bss_max_idle_period);
2655 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2656 "TU)%s", wpa_s->sme.bss_max_idle_period,
2657 (elems.bss_max_idle_period[2] & 0x01) ?
2658 " (protected keep-live required)" : "");
2659 if (wpa_s->sme.bss_max_idle_period == 0)
2660 wpa_s->sme.bss_max_idle_period = 1;
2661 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2662 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2663 /* msec times 1000 */
2664 msec = wpa_s->sme.bss_max_idle_period * 1024;
2665 if (msec > 100)
2666 msec -= 100;
2667 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2668 wnm_bss_keep_alive, wpa_s,
2669 NULL);
2670 }
2671 }
2672#endif /* CONFIG_SME */
2673}
2674
2675#endif /* CONFIG_WNM */
2676
2677
2678void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2679{
2680#ifdef CONFIG_WNM
2681 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2682#endif /* CONFIG_WNM */
2683}
2684
2685
2686static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2687 size_t len)
2688{
2689 int res;
2690
2691 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2692 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2693 if (res) {
2694 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2695 }
2696
2697 return res;
2698}
2699
2700
2701static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2702 const u8 *ies, size_t ies_len)
2703{
2704 struct ieee802_11_elems elems;
2705
2706 if (ies == NULL)
2707 return;
2708
2709 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2710 return;
2711
2712 if (elems.qos_map_set) {
2713 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2714 elems.qos_map_set_len);
2715 }
2716}
2717
2718
2719static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
2720{
2721 if (wpa_s->enabled_4addr_mode) {
2722 wpa_printf(MSG_DEBUG, "4addr mode already set");
2723 return;
2724 }
2725
2726 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2727 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
2728 goto fail;
2729 }
2730 wpa_s->enabled_4addr_mode = 1;
2731 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
2732 return;
2733
2734fail:
2735 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2736}
2737
2738
2739static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2740 const u8 *ies, size_t ies_len)
2741{
2742 struct ieee802_11_elems elems;
2743 const u8 *map_sub_elem, *pos;
2744 size_t len;
2745
2746 wpa_s->multi_ap_ie = 0;
2747
2748 if (!ies ||
2749 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2750 !elems.multi_ap || elems.multi_ap_len < 7)
2751 return;
2752
2753 pos = elems.multi_ap + 4;
2754 len = elems.multi_ap_len - 4;
2755
2756 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
2757 if (!map_sub_elem || map_sub_elem[1] < 1)
2758 return;
2759
2760 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2761 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2762 MULTI_AP_FRONTHAUL_BSS);
2763 wpa_s->multi_ap_ie = 1;
2764}
2765
2766
2767static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2768{
2769 if (!wpa_s->current_ssid ||
2770 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2771 return;
2772
2773 if (!wpa_s->multi_ap_ie) {
2774 wpa_printf(MSG_INFO,
2775 "AP does not include valid Multi-AP element");
2776 goto fail;
2777 }
2778
2779 if (!wpa_s->multi_ap_backhaul) {
2780 if (wpa_s->multi_ap_fronthaul &&
2781 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2782 wpa_printf(MSG_INFO,
2783 "WPS active, accepting fronthaul-only BSS");
2784 /* Don't set 4addr mode in this case, so just return */
2785 return;
2786 }
2787 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2788 goto fail;
2789 }
2790
2791 wpa_supplicant_set_4addr_mode(wpa_s);
2792 return;
2793
2794fail:
2795 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2796}
2797
2798
2799#ifdef CONFIG_FST
2800static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2801 const u8 *ie, size_t ie_len)
2802{
2803 struct mb_ies_info mb_ies;
2804
2805 if (!ie || !ie_len || !wpa_s->fst)
2806 return -ENOENT;
2807
2808 os_memset(&mb_ies, 0, sizeof(mb_ies));
2809
2810 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2811 size_t len;
2812
2813 len = 2 + ie[1];
2814 if (len > ie_len) {
2815 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2816 ie, ie_len);
2817 break;
2818 }
2819
2820 if (ie[0] == WLAN_EID_MULTI_BAND) {
2821 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2822 (unsigned int) len);
2823 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2824 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2825 mb_ies.nof_ies++;
2826 }
2827
2828 ie_len -= len;
2829 ie += len;
2830 }
2831
2832 if (mb_ies.nof_ies > 0) {
2833 wpabuf_free(wpa_s->received_mb_ies);
2834 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2835 return 0;
2836 }
2837
2838 return -ENOENT;
2839}
2840#endif /* CONFIG_FST */
2841
2842
2843static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2844 union wpa_event_data *data)
2845{
2846 int sel;
2847 const u8 *p;
2848 int l, len;
2849 bool found = false;
2850 struct wpa_ie_data ie;
2851 struct wpa_ssid *ssid = wpa_s->current_ssid;
2852 struct wpa_bss *bss = wpa_s->current_bss;
2853 int pmf;
2854
2855 if (!ssid)
2856 return 0;
2857
2858 p = data->assoc_info.req_ies;
2859 l = data->assoc_info.req_ies_len;
2860
2861 while (p && l >= 2) {
2862 len = p[1] + 2;
2863 if (len > l) {
2864 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2865 p, l);
2866 break;
2867 }
2868 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2869 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2870 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2871 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2872 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2873 found = true;
2874 break;
2875 }
2876 l -= len;
2877 p += len;
2878 }
2879
2880 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
2881 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
2882 return 0;
2883 }
2884
2885 wpa_hexdump(MSG_DEBUG,
2886 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2887 p, l);
2888
2889 /* Update proto from (Re)Association Request frame info */
2890 wpa_s->wpa_proto = ie.proto;
2891 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2892 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2893 !!(wpa_s->wpa_proto &
2894 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2895
2896 /* Update AKMP suite from (Re)Association Request frame info */
2897 sel = ie.key_mgmt;
2898 if (ssid->key_mgmt)
2899 sel &= ssid->key_mgmt;
2900
2901 wpa_dbg(wpa_s, MSG_DEBUG,
2902 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2903 ie.key_mgmt, ssid->key_mgmt, sel);
2904 if (ie.key_mgmt && !sel) {
2905 wpa_supplicant_deauthenticate(
2906 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2907 return -1;
2908 }
2909
2910#ifdef CONFIG_OCV
2911 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
2912 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
2913 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
2914 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
2915#endif /* CONFIG_OCV */
2916
2917 /*
2918 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
2919 * different AKM.
2920 */
2921 if (wpa_s->key_mgmt != ie.key_mgmt &&
2922 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
2923 if (!ssid->psk_set) {
2924 wpa_dbg(wpa_s, MSG_INFO,
2925 "No PSK available for association");
2926 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
2927 return -1;
2928 }
2929
2930 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
2931 if (wpa_s->conf->key_mgmt_offload &&
2932 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
2933 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
2934 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
2935 wpa_dbg(wpa_s, MSG_ERROR,
2936 "WPA: Cannot set PMK for key management offload");
2937 }
2938
2939 wpa_s->key_mgmt = ie.key_mgmt;
2940 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2941 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2942 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2943 wpa_s->wpa_proto);
2944
2945 /* Update pairwise cipher from (Re)Association Request frame info */
2946 sel = ie.pairwise_cipher;
2947 if (ssid->pairwise_cipher)
2948 sel &= ssid->pairwise_cipher;
2949
2950 wpa_dbg(wpa_s, MSG_DEBUG,
2951 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2952 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2953 if (ie.pairwise_cipher && !sel) {
2954 wpa_supplicant_deauthenticate(
2955 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2956 return -1;
2957 }
2958
2959 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2960 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2961 wpa_s->pairwise_cipher);
2962 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2963 wpa_cipher_txt(wpa_s->pairwise_cipher));
2964
2965 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2966 if (!bss) {
2967 wpa_dbg(wpa_s, MSG_DEBUG,
2968 "WPA: current_bss == NULL - skip AP IE check");
2969 return 0;
2970 }
2971
2972 /* Update GTK and IGTK from AP's RSNE */
2973 found = false;
2974
2975 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2976 const u8 *bss_rsn;
2977
2978 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2979 if (bss_rsn) {
2980 p = bss_rsn;
2981 len = 2 + bss_rsn[1];
2982 found = true;
2983 }
2984 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2985 const u8 *bss_wpa;
2986
2987 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2988 if (bss_wpa) {
2989 p = bss_wpa;
2990 len = 2 + bss_wpa[1];
2991 found = true;
2992 }
2993 }
2994
2995 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2996 return 0;
2997
2998 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2999 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3000 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3001 /* AP does not support MFP, local configuration requires it */
3002 wpa_supplicant_deauthenticate(
3003 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3004 return -1;
3005 }
3006 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3007 pmf == NO_MGMT_FRAME_PROTECTION) {
3008 /* AP requires MFP, local configuration disables it */
3009 wpa_supplicant_deauthenticate(
3010 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3011 return -1;
3012 }
3013
3014 /* Update PMF from local configuration now that MFP validation was done
3015 * above */
3016 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3017
3018 /* Update GTK from AP's RSNE */
3019 sel = ie.group_cipher;
3020 if (ssid->group_cipher)
3021 sel &= ssid->group_cipher;
3022
3023 wpa_dbg(wpa_s, MSG_DEBUG,
3024 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3025 ie.group_cipher, ssid->group_cipher, sel);
3026 if (ie.group_cipher && !sel) {
3027 wpa_supplicant_deauthenticate(
3028 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3029 return -1;
3030 }
3031
3032 wpa_s->group_cipher = ie.group_cipher;
3033 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3034 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3035 wpa_cipher_txt(wpa_s->group_cipher));
3036
3037 /* Update IGTK from AP RSN IE */
3038 sel = ie.mgmt_group_cipher;
3039 if (ssid->group_mgmt_cipher)
3040 sel &= ssid->group_mgmt_cipher;
3041
3042 wpa_dbg(wpa_s, MSG_DEBUG,
3043 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3044 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3045
3046 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3047 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3048 wpa_dbg(wpa_s, MSG_DEBUG,
3049 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3050 ie.capabilities);
3051 ie.mgmt_group_cipher = 0;
3052 }
3053
3054 if (ie.mgmt_group_cipher && !sel) {
3055 wpa_supplicant_deauthenticate(
3056 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3057 return -1;
3058 }
3059
3060 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3061 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3062 wpa_s->mgmt_group_cipher);
3063 if (wpa_s->mgmt_group_cipher)
3064 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3065 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3066 else
3067 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3068
3069 return 0;
3070}
3071
3072
3073static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3074 union wpa_event_data *data)
3075{
3076 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
3077 const u8 *p;
3078 u8 bssid[ETH_ALEN];
3079 bool bssid_known;
3080
3081 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
3082 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
3083 if (data->assoc_info.req_ies)
3084 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3085 data->assoc_info.req_ies_len);
3086 if (data->assoc_info.resp_ies) {
3087 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3088 data->assoc_info.resp_ies_len);
3089#ifdef CONFIG_TDLS
3090 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3091 data->assoc_info.resp_ies_len);
3092#endif /* CONFIG_TDLS */
3093#ifdef CONFIG_WNM
3094 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3095 data->assoc_info.resp_ies_len);
3096#endif /* CONFIG_WNM */
3097 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3098 data->assoc_info.resp_ies_len);
3099 if (wpa_s->hw_capab == CAPAB_VHT &&
3100 get_ie(data->assoc_info.resp_ies,
3101 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3102 wpa_s->ieee80211ac = 1;
3103
3104 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3105 data->assoc_info.resp_ies_len);
3106 }
3107 if (data->assoc_info.beacon_ies)
3108 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3109 data->assoc_info.beacon_ies,
3110 data->assoc_info.beacon_ies_len);
3111 if (data->assoc_info.freq)
3112 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3113 data->assoc_info.freq);
3114
3115 wpa_s->connection_set = 0;
3116 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3117 struct ieee802_11_elems req_elems, resp_elems;
3118
3119 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3120 data->assoc_info.req_ies_len,
3121 &req_elems, 0) != ParseFailed &&
3122 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3123 data->assoc_info.resp_ies_len,
3124 &resp_elems, 0) != ParseFailed) {
3125 wpa_s->connection_set = 1;
3126 wpa_s->connection_ht = req_elems.ht_capabilities &&
3127 resp_elems.ht_capabilities;
3128 /* Do not include subset of VHT on 2.4 GHz vendor
3129 * extension in consideration for reporting VHT
3130 * association. */
3131 wpa_s->connection_vht = req_elems.vht_capabilities &&
3132 resp_elems.vht_capabilities &&
3133 (!data->assoc_info.freq ||
3134 wpas_freq_to_band(data->assoc_info.freq) !=
3135 BAND_2_4_GHZ);
3136 wpa_s->connection_he = req_elems.he_capabilities &&
3137 resp_elems.he_capabilities;
3138 wpa_s->connection_eht = req_elems.eht_capabilities &&
3139 resp_elems.eht_capabilities;
3140 }
3141 }
3142
3143 p = data->assoc_info.req_ies;
3144 l = data->assoc_info.req_ies_len;
3145
3146 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3147 while (p && l >= 2) {
3148 len = p[1] + 2;
3149 if (len > l) {
3150 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3151 p, l);
3152 break;
3153 }
3154 if (!found &&
3155 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3156 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3157 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3158 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3159 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3160 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3161 break;
3162 found = 1;
3163 wpa_find_assoc_pmkid(wpa_s,
3164 data->assoc_info.authorized);
3165 }
3166 if (!found_x && p[0] == WLAN_EID_RSNX) {
3167 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3168 break;
3169 found_x = 1;
3170 }
3171 l -= len;
3172 p += len;
3173 }
3174#if 0
3175 if (!found && data->assoc_info.req_ies)
3176 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
3177#endif
3178 if (!found_x && data->assoc_info.req_ies)
3179 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
3180
3181#ifdef CONFIG_FILS
3182#ifdef CONFIG_SME
3183 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3184 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
3185 (!data->assoc_info.resp_frame ||
3186 fils_process_assoc_resp(wpa_s->wpa,
3187 data->assoc_info.resp_frame,
3188 data->assoc_info.resp_frame_len) < 0)) {
3189 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3190 return -1;
3191 }
3192#endif /* CONFIG_SME */
3193
3194 /* Additional processing for FILS when SME is in driver */
3195 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3196 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3197 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
3198#endif /* CONFIG_FILS */
3199
3200#ifdef CONFIG_OWE
3201 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
3202 (!bssid_known ||
3203 owe_process_assoc_resp(wpa_s->wpa,
3204 wpa_s->valid_links ?
3205 wpa_s->ap_mld_addr : bssid,
3206 data->assoc_info.resp_ies,
3207 data->assoc_info.resp_ies_len) < 0)) {
3208 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3209 return -1;
3210 }
3211#endif /* CONFIG_OWE */
3212
3213#ifdef CONFIG_DPP2
3214 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
3215 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3216 wpa_s->dpp_pfs) {
3217 struct ieee802_11_elems elems;
3218
3219 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3220 data->assoc_info.resp_ies_len,
3221 &elems, 0) == ParseFailed ||
3222 !elems.owe_dh)
3223 goto no_pfs;
3224 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3225 elems.owe_dh_len) < 0) {
3226 wpa_supplicant_deauthenticate(wpa_s,
3227 WLAN_REASON_UNSPECIFIED);
3228 return -1;
3229 }
3230
3231 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3232 }
3233no_pfs:
3234#endif /* CONFIG_DPP2 */
3235
3236#ifdef CONFIG_IEEE80211R
3237#ifdef CONFIG_SME
3238 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
3239 if (!bssid_known ||
3240 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3241 data->assoc_info.resp_ies,
3242 data->assoc_info.resp_ies_len,
3243 bssid) < 0) {
3244 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3245 "Reassociation Response failed");
3246 wpa_supplicant_deauthenticate(
3247 wpa_s, WLAN_REASON_INVALID_IE);
3248 return -1;
3249 }
3250 }
3251
3252 p = data->assoc_info.resp_ies;
3253 l = data->assoc_info.resp_ies_len;
3254
3255#ifdef CONFIG_WPS_STRICT
3256 if (p && wpa_s->current_ssid &&
3257 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3258 struct wpabuf *wps;
3259 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3260 if (wps == NULL) {
3261 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3262 "include WPS IE in (Re)Association Response");
3263 return -1;
3264 }
3265
3266 if (wps_validate_assoc_resp(wps) < 0) {
3267 wpabuf_free(wps);
3268 wpa_supplicant_deauthenticate(
3269 wpa_s, WLAN_REASON_INVALID_IE);
3270 return -1;
3271 }
3272 wpabuf_free(wps);
3273 }
3274#endif /* CONFIG_WPS_STRICT */
3275
3276 /* Go through the IEs and make a copy of the MDIE, if present. */
3277 while (p && l >= 2) {
3278 len = p[1] + 2;
3279 if (len > l) {
3280 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3281 p, l);
3282 break;
3283 }
3284 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3285 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3286 wpa_s->sme.ft_used = 1;
3287 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3288 MOBILITY_DOMAIN_ID_LEN);
3289 break;
3290 }
3291 l -= len;
3292 p += len;
3293 }
3294#endif /* CONFIG_SME */
3295
3296 /* Process FT when SME is in the driver */
3297 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3298 wpa_ft_is_completed(wpa_s->wpa)) {
3299 if (!bssid_known ||
3300 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3301 data->assoc_info.resp_ies,
3302 data->assoc_info.resp_ies_len,
3303 bssid) < 0) {
3304 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3305 "Reassociation Response failed");
3306 wpa_supplicant_deauthenticate(
3307 wpa_s, WLAN_REASON_INVALID_IE);
3308 return -1;
3309 }
3310 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3311 }
3312
3313 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3314 data->assoc_info.resp_ies_len);
3315#endif /* CONFIG_IEEE80211R */
3316
3317 if (bssid_known)
3318 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3319 data->assoc_info.resp_ies,
3320 data->assoc_info.resp_ies_len);
3321
3322 /* WPA/RSN IE from Beacon/ProbeResp */
3323 p = data->assoc_info.beacon_ies;
3324 l = data->assoc_info.beacon_ies_len;
3325
3326 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3327 */
3328 wpa_found = rsn_found = 0;
3329 while (p && l >= 2) {
3330 len = p[1] + 2;
3331 if (len > l) {
3332 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3333 p, l);
3334 break;
3335 }
3336 if (!wpa_found &&
3337 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3338 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3339 wpa_found = 1;
3340 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3341 }
3342
3343 if (!rsn_found &&
3344 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3345 rsn_found = 1;
3346 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3347 }
3348
3349 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3350 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3351
3352 l -= len;
3353 p += len;
3354 }
3355
3356 if (!wpa_found && data->assoc_info.beacon_ies)
3357 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
3358 if (!rsn_found && data->assoc_info.beacon_ies) {
3359 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
3360 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3361 }
3362 if (wpa_found || rsn_found)
3363 wpa_s->ap_ies_from_associnfo = 1;
3364
3365 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3366 wpa_s->assoc_freq != data->assoc_info.freq) {
3367 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3368 "%u to %u MHz",
3369 wpa_s->assoc_freq, data->assoc_info.freq);
3370 wpa_supplicant_update_scan_results(wpa_s);
3371 }
3372
3373 wpa_s->assoc_freq = data->assoc_info.freq;
3374
3375 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3376 data->assoc_info.resp_ies_len);
3377
3378 return 0;
3379}
3380
3381
3382static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3383{
3384 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
3385
3386 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3387 return -1;
3388
3389 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3390 return 0;
3391
3392 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3393 WPA_IE_VENDOR_TYPE);
3394 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
3395 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
3396
3397 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3398 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3399 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
3400 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3401 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3402 bss_rsnx ? 2 + bss_rsnx[1] : 0))
3403 return -1;
3404
3405 return 0;
3406}
3407
3408
3409static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3410 union wpa_event_data *data)
3411{
3412#ifdef CONFIG_FST
3413 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3414 struct wpa_bss *bss = wpa_s->current_bss;
3415 const u8 *ieprb, *iebcn;
3416
3417 wpabuf_free(wpa_s->received_mb_ies);
3418 wpa_s->received_mb_ies = NULL;
3419
3420 if (ai &&
3421 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3422 wpa_printf(MSG_DEBUG,
3423 "FST: MB IEs updated from Association Response frame");
3424 return;
3425 }
3426
3427 if (ai &&
3428 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3429 wpa_printf(MSG_DEBUG,
3430 "FST: MB IEs updated from association event Beacon IEs");
3431 return;
3432 }
3433
3434 if (!bss)
3435 return;
3436
3437 ieprb = wpa_bss_ie_ptr(bss);
3438 iebcn = ieprb + bss->ie_len;
3439
3440 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3441 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3442 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3443 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3444#endif /* CONFIG_FST */
3445}
3446
3447
3448static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3449{
3450 struct driver_sta_mlo_info mlo;
3451 int i;
3452
3453 os_memset(&mlo, 0, sizeof(mlo));
3454 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3455 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3456 wpa_supplicant_deauthenticate(wpa_s,
3457 WLAN_REASON_DEAUTH_LEAVING);
3458 return -1;
3459 }
3460
3461 if (wpa_s->valid_links == mlo.valid_links) {
3462 bool match = true;
3463
3464 if (!mlo.valid_links)
3465 return 0;
3466
3467 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3468 if (!(mlo.valid_links & BIT(i)))
3469 continue;
3470
3471 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3472 ETH_ALEN) != 0 ||
3473 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3474 ETH_ALEN) != 0) {
3475 match = false;
3476 break;
3477 }
3478 }
3479
3480 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
3481 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3482 ETH_ALEN) == 0)
3483 return 0;
3484 }
3485
3486 wpa_s->valid_links = mlo.valid_links;
3487 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
3488 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3489 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3490 if (!(wpa_s->valid_links & BIT(i)))
3491 continue;
3492
3493 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3494 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3495 wpa_s->links[i].freq = mlo.links[i].freq;
3496 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3497 }
3498
3499 return 0;
3500}
3501
3502
3503static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
3504{
3505 struct driver_sta_mlo_info drv_mlo;
3506 struct wpa_sm_mlo wpa_mlo;
3507 const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
3508 int i;
3509
3510 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
3511 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
3512 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
3513 return -1;
3514 }
3515
3516 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
3517 if (!drv_mlo.valid_links)
3518 goto out;
3519
3520 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
3521 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
3522 wpa_mlo.valid_links = drv_mlo.valid_links;
3523 wpa_mlo.req_links = drv_mlo.req_links;
3524
3525 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3526 struct wpa_bss *bss;
3527
3528 if (!(drv_mlo.req_links & BIT(i)))
3529 continue;
3530
3531 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
3532 if (!bss) {
3533 wpa_supplicant_update_scan_results(wpa_s);
3534 bss = wpa_supplicant_get_new_bss(
3535 wpa_s, drv_mlo.links[i].bssid);
3536 }
3537
3538 if (!bss) {
3539 wpa_dbg(wpa_s, MSG_INFO,
3540 "Failed to get MLO link %d BSS", i);
3541 return -1;
3542 }
3543
3544 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3545 bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
3546
3547 wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
3548 wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
3549 wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
3550 wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
3551
3552 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
3553 ETH_ALEN);
3554 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
3555 ETH_ALEN);
3556 }
3557
3558out:
3559 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
3560}
3561
3562
3563static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3564 union wpa_event_data *data)
3565{
3566 u8 bssid[ETH_ALEN];
3567 int ft_completed, already_authorized;
3568 int new_bss = 0;
3569#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3570 struct wpa_bss *bss;
3571#endif /* CONFIG_FILS || CONFIG_MBO */
3572
3573#ifdef CONFIG_AP
3574 if (wpa_s->ap_iface) {
3575 if (!data)
3576 return;
3577 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3578 data->assoc_info.addr,
3579 data->assoc_info.req_ies,
3580 data->assoc_info.req_ies_len,
3581 data->assoc_info.reassoc);
3582 return;
3583 }
3584#endif /* CONFIG_AP */
3585
3586 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
3587 wpa_s->own_reconnect_req = 0;
3588
3589 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
3590
3591 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3592 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3593 wpa_supplicant_deauthenticate(
3594 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3595 return;
3596 }
3597
3598 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3599 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3600 wpa_supplicant_deauthenticate(wpa_s,
3601 WLAN_REASON_DEAUTH_LEAVING);
3602 return;
3603 }
3604
3605 if (ft_completed &&
3606 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3607 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3608 MAC2STR(bssid));
3609 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3610 wpa_printf(MSG_ERROR,
3611 "Can't find target AP's information!");
3612 return;
3613 }
3614 wpa_supplicant_assoc_update_ie(wpa_s);
3615 }
3616
3617 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3618 return;
3619 /*
3620 * FILS authentication can share the same mechanism to mark the
3621 * connection fully authenticated, so set ft_completed also based on
3622 * FILS result.
3623 */
3624 if (!ft_completed)
3625 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
3626
3627 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
3628 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
3629 if (os_reltime_initialized(&wpa_s->session_start)) {
3630 os_reltime_age(&wpa_s->session_start,
3631 &wpa_s->session_length);
3632 wpa_s->session_start.sec = 0;
3633 wpa_s->session_start.usec = 0;
3634 wpas_notify_session_length(wpa_s);
3635 } else {
3636 wpas_notify_auth_changed(wpa_s);
3637 os_get_reltime(&wpa_s->session_start);
3638 }
3639 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3640 MACSTR, MAC2STR(bssid));
3641 new_bss = 1;
3642 random_add_randomness(bssid, ETH_ALEN);
3643 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3644 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
3645 wpas_notify_bssid_changed(wpa_s);
3646
3647 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3648 wpa_clear_keys(wpa_s, bssid);
3649 }
3650 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
3651 wpa_supplicant_deauthenticate(
3652 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3653 return;
3654 }
3655 }
3656
3657 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3658 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3659 return;
3660
3661 multi_ap_set_4addr_mode(wpa_s);
3662
3663 if (wpa_s->conf->ap_scan == 1 &&
3664 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
3665 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3666 wpa_msg(wpa_s, MSG_WARNING,
3667 "WPA/RSN IEs not updated");
3668 }
3669
3670 wpas_fst_update_mb_assoc(wpa_s, data);
3671
3672#ifdef CONFIG_SME
3673 /*
3674 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
3675 * (for MLO connection) as the previous BSSID for subsequent
3676 * reassociation requests handled by SME-in-wpa_supplicant.
3677 */
3678 os_memcpy(wpa_s->sme.prev_bssid,
3679 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
3680 wpa_s->sme.prev_bssid_set = 1;
3681 wpa_s->sme.last_unprot_disconnect.sec = 0;
3682#endif /* CONFIG_SME */
3683
3684 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3685 if (wpa_s->current_ssid) {
3686 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3687 * initialized before association, but for other modes,
3688 * initialize PC/SC here, if the current configuration needs
3689 * smartcard or SIM/USIM. */
3690 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3691 }
3692 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3693
3694 if (wpa_sm_set_ml_info(wpa_s)) {
3695 wpa_dbg(wpa_s, MSG_INFO,
3696 "Failed to set MLO connection info to wpa_sm");
3697 wpa_supplicant_deauthenticate(wpa_s,
3698 WLAN_REASON_DEAUTH_LEAVING);
3699 return;
3700 }
3701
3702 if (wpa_s->l2)
3703 l2_packet_notify_auth_start(wpa_s->l2);
3704
3705 already_authorized = data && data->assoc_info.authorized;
3706
3707 /*
3708 * Set portEnabled first to false in order to get EAP state machine out
3709 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3710 * state machine may transit to AUTHENTICATING state based on obsolete
3711 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3712 * AUTHENTICATED without ever giving chance to EAP state machine to
3713 * reset the state.
3714 */
3715 if (!ft_completed && !already_authorized) {
3716 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3717 eapol_sm_notify_portValid(wpa_s->eapol, false);
3718 }
3719 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3720 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3721 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
3722 already_authorized || wpa_s->drv_authorized_port)
3723 eapol_sm_notify_eap_success(wpa_s->eapol, false);
3724 /* 802.1X::portControl = Auto */
3725 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
3726 wpa_s->eapol_received = 0;
3727 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3728 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3729 (wpa_s->current_ssid &&
3730 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
3731 if (wpa_s->current_ssid &&
3732 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
3733 (wpa_s->drv_flags &
3734 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3735 /*
3736 * Set the key after having received joined-IBSS event
3737 * from the driver.
3738 */
3739 wpa_supplicant_set_wpa_none_key(wpa_s,
3740 wpa_s->current_ssid);
3741 }
3742 wpa_supplicant_cancel_auth_timeout(wpa_s);
3743 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3744 } else if (!ft_completed) {
3745 /* Timeout for receiving the first EAPOL packet */
3746 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3747 }
3748 wpa_supplicant_cancel_scan(wpa_s);
3749
3750 if (ft_completed) {
3751 /*
3752 * FT protocol completed - make sure EAPOL state machine ends
3753 * up in authenticated.
3754 */
3755 wpa_supplicant_cancel_auth_timeout(wpa_s);
3756 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3757 eapol_sm_notify_portValid(wpa_s->eapol, true);
3758 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3759 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3760 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3761 if (already_authorized) {
3762 /*
3763 * We are done; the driver will take care of RSN 4-way
3764 * handshake.
3765 */
3766 wpa_supplicant_cancel_auth_timeout(wpa_s);
3767 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3768 eapol_sm_notify_portValid(wpa_s->eapol, true);
3769 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3770 } else {
3771 /* Update port, WPA_COMPLETED state from the
3772 * EVENT_PORT_AUTHORIZED handler when the driver is done
3773 * with the 4-way handshake.
3774 */
3775 wpa_msg(wpa_s, MSG_DEBUG,
3776 "ASSOC INFO: wait for driver port authorized indication");
3777 }
3778 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
3779 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3780 /*
3781 * The driver will take care of RSN 4-way handshake, so we need
3782 * to allow EAPOL supplicant to complete its work without
3783 * waiting for WPA supplicant.
3784 */
3785 eapol_sm_notify_portValid(wpa_s->eapol, true);
3786 }
3787
3788 wpa_s->last_eapol_matches_bssid = 0;
3789
3790#ifdef CONFIG_TESTING_OPTIONS
3791 if (wpa_s->rsne_override_eapol) {
3792 wpa_printf(MSG_DEBUG,
3793 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3794 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3795 wpabuf_head(wpa_s->rsne_override_eapol),
3796 wpabuf_len(wpa_s->rsne_override_eapol));
3797 }
3798 if (wpa_s->rsnxe_override_eapol) {
3799 wpa_printf(MSG_DEBUG,
3800 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3801 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3802 wpabuf_head(wpa_s->rsnxe_override_eapol),
3803 wpabuf_len(wpa_s->rsnxe_override_eapol));
3804 }
3805#endif /* CONFIG_TESTING_OPTIONS */
3806
3807 if (wpa_s->pending_eapol_rx) {
3808 struct os_reltime now, age;
3809 os_get_reltime(&now);
3810 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
3811 if (age.sec == 0 && age.usec < 200000 &&
3812 os_memcmp(wpa_s->pending_eapol_rx_src,
3813 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid,
3814 ETH_ALEN) == 0) {
3815 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3816 "frame that was received just before "
3817 "association notification");
3818 wpa_supplicant_rx_eapol(
3819 wpa_s, wpa_s->pending_eapol_rx_src,
3820 wpabuf_head(wpa_s->pending_eapol_rx),
3821 wpabuf_len(wpa_s->pending_eapol_rx),
3822 wpa_s->pending_eapol_encrypted);
3823 }
3824 wpabuf_free(wpa_s->pending_eapol_rx);
3825 wpa_s->pending_eapol_rx = NULL;
3826 }
3827
3828#ifdef CONFIG_WEP
3829 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3830 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
3831 wpa_s->current_ssid &&
3832 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3833 /* Set static WEP keys again */
3834 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3835 }
3836#endif /* CONFIG_WEP */
3837
3838#ifdef CONFIG_IBSS_RSN
3839 if (wpa_s->current_ssid &&
3840 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3841 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3842 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3843 wpa_s->ibss_rsn == NULL) {
3844 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
3845 if (!wpa_s->ibss_rsn) {
3846 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3847 wpa_supplicant_deauthenticate(
3848 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3849 return;
3850 }
3851
3852 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3853 }
3854#endif /* CONFIG_IBSS_RSN */
3855
3856 wpas_wps_notify_assoc(wpa_s, bssid);
3857
3858 if (data) {
3859 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3860 data->assoc_info.resp_ies_len,
3861 &data->assoc_info.wmm_params);
3862
3863 if (wpa_s->reassoc_same_bss)
3864 wmm_ac_restore_tspecs(wpa_s);
3865 }
3866
3867#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3868 bss = wpa_bss_get_bssid(wpa_s, bssid);
3869#endif /* CONFIG_FILS || CONFIG_MBO */
3870#ifdef CONFIG_FILS
3871 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
3872 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3873
3874 if (fils_cache_id)
3875 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3876 }
3877#endif /* CONFIG_FILS */
3878
3879#ifdef CONFIG_MBO
3880 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3881#endif /* CONFIG_MBO */
3882
3883#ifdef CONFIG_DPP2
3884 wpa_s->dpp_pfs_fallback = 0;
3885#endif /* CONFIG_DPP2 */
3886
3887 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
3888 wpa_supplicant_set_4addr_mode(wpa_s);
3889}
3890
3891
3892static int disconnect_reason_recoverable(u16 reason_code)
3893{
3894 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3895 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3896 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3897}
3898
3899
3900static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
3901 u16 reason_code,
3902 int locally_generated)
3903{
3904 const u8 *bssid;
3905
3906 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3907 /*
3908 * At least Host AP driver and a Prism3 card seemed to be
3909 * generating streams of disconnected events when configuring
3910 * IBSS for WPA-None. Ignore them for now.
3911 */
3912 return;
3913 }
3914
3915 bssid = wpa_s->bssid;
3916 if (is_zero_ether_addr(bssid))
3917 bssid = wpa_s->pending_bssid;
3918
3919 if (!is_zero_ether_addr(bssid) ||
3920 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3921 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3922 " reason=%d%s",
3923 MAC2STR(bssid), reason_code,
3924 locally_generated ? " locally_generated=1" : "");
3925 }
3926}
3927
3928
3929static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3930 int locally_generated)
3931{
3932 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
3933 !wpa_s->new_connection ||
3934 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3935 wpa_key_mgmt_sae(wpa_s->key_mgmt))
3936 return 0; /* Not in initial 4-way handshake with PSK */
3937
3938 /*
3939 * It looks like connection was lost while trying to go through PSK
3940 * 4-way handshake. Filter out known disconnection cases that are caused
3941 * by something else than PSK mismatch to avoid confusing reports.
3942 */
3943
3944 if (locally_generated) {
3945 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3946 return 0;
3947 }
3948
3949 return 1;
3950}
3951
3952
3953static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3954 u16 reason_code,
3955 int locally_generated)
3956{
3957 const u8 *bssid;
3958 int authenticating;
3959 u8 prev_pending_bssid[ETH_ALEN];
3960 struct wpa_bss *fast_reconnect = NULL;
3961 struct wpa_ssid *fast_reconnect_ssid = NULL;
3962 struct wpa_ssid *last_ssid;
3963 struct wpa_bss *curr = NULL;
3964
3965 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3966 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3967
3968 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3969 /*
3970 * At least Host AP driver and a Prism3 card seemed to be
3971 * generating streams of disconnected events when configuring
3972 * IBSS for WPA-None. Ignore them for now.
3973 */
3974 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3975 "IBSS/WPA-None mode");
3976 return;
3977 }
3978
3979 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3980 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3981 locally_generated)
3982 /*
3983 * Remove the inactive AP (which is probably out of range) from
3984 * the BSS list after marking disassociation. In particular
3985 * mac80211-based drivers use the
3986 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3987 * locally generated disconnection events for cases where the
3988 * AP does not reply anymore.
3989 */
3990 curr = wpa_s->current_bss;
3991
3992 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
3993 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3994 "pre-shared key may be incorrect");
3995 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3996 return; /* P2P group removed */
3997 wpas_auth_failed(wpa_s, "WRONG_KEY", prev_pending_bssid);
3998 wpas_notify_psk_mismatch(wpa_s);
3999#ifdef CONFIG_DPP2
4000 wpas_dpp_send_conn_status_result(wpa_s,
4001 DPP_STATUS_AUTH_FAILURE);
4002#endif /* CONFIG_DPP2 */
4003 }
4004 if (!wpa_s->disconnected &&
4005 (!wpa_s->auto_reconnect_disabled ||
4006 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
4007 wpas_wps_searching(wpa_s) ||
4008 wpas_wps_reenable_networks_pending(wpa_s))) {
4009 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
4010 "reconnect (wps=%d/%d wpa_state=%d)",
4011 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
4012 wpas_wps_searching(wpa_s),
4013 wpa_s->wpa_state);
4014 if (wpa_s->wpa_state == WPA_COMPLETED &&
4015 wpa_s->current_ssid &&
4016 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
4017 (wpa_s->own_reconnect_req ||
4018 (!locally_generated &&
4019 disconnect_reason_recoverable(reason_code)))) {
4020 /*
4021 * It looks like the AP has dropped association with
4022 * us, but could allow us to get back in. This is also
4023 * triggered for cases where local reconnection request
4024 * is used to force reassociation with the same BSS.
4025 * Try to reconnect to the same BSS without a full scan
4026 * to save time for some common cases.
4027 */
4028 fast_reconnect = wpa_s->current_bss;
4029 fast_reconnect_ssid = wpa_s->current_ssid;
4030 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
4031 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4032 } else {
4033 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4034 "immediate scan");
4035 }
4036 } else {
4037 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
4038 "try to re-connect");
4039 wpa_s->reassociate = 0;
4040 wpa_s->disconnected = 1;
4041 if (!wpa_s->pno)
4042 wpa_supplicant_cancel_sched_scan(wpa_s);
4043 }
4044 bssid = wpa_s->bssid;
4045 if (is_zero_ether_addr(bssid))
4046 bssid = wpa_s->pending_bssid;
4047 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4048 wpas_connection_failed(wpa_s, bssid);
4049 wpa_sm_notify_disassoc(wpa_s->wpa);
4050 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4051
4052 if (locally_generated)
4053 wpa_s->disconnect_reason = -reason_code;
4054 else
4055 wpa_s->disconnect_reason = reason_code;
4056 wpas_notify_disconnect_reason(wpa_s);
4057 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4058 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
4059 wpa_clear_keys(wpa_s, wpa_s->bssid);
4060 }
4061 last_ssid = wpa_s->current_ssid;
4062 wpa_supplicant_mark_disassoc(wpa_s);
4063
4064 if (curr)
4065 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4066
4067 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
4068 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
4069 wpa_s->current_ssid = last_ssid;
4070 }
4071
4072 if (fast_reconnect &&
4073 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4074 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4075 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4076 fast_reconnect->ssid_len) &&
4077 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
4078 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
4079#ifndef CONFIG_NO_SCAN_PROCESSING
4080 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4081 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4082 fast_reconnect_ssid) < 0) {
4083 /* Recover through full scan */
4084 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4085 }
4086#endif /* CONFIG_NO_SCAN_PROCESSING */
4087 } else if (fast_reconnect) {
4088 /*
4089 * Could not reconnect to the same BSS due to network being
4090 * disabled. Use a new scan to match the alternative behavior
4091 * above, i.e., to continue automatic reconnection attempt in a
4092 * way that enforces disabled network rules.
4093 */
4094 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4095 }
4096}
4097
4098
4099#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4100void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
4101{
4102 struct wpa_supplicant *wpa_s = eloop_ctx;
4103
4104 if (!wpa_s->pending_mic_error_report)
4105 return;
4106
4107 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4108 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4109 wpa_s->pending_mic_error_report = 0;
4110}
4111#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4112
4113
4114static void
4115wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4116 union wpa_event_data *data)
4117{
4118 int pairwise;
4119 struct os_reltime t;
4120
4121 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4122 pairwise = (data && data->michael_mic_failure.unicast);
4123 os_get_reltime(&t);
4124 if ((wpa_s->last_michael_mic_error.sec &&
4125 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
4126 wpa_s->pending_mic_error_report) {
4127 if (wpa_s->pending_mic_error_report) {
4128 /*
4129 * Send the pending MIC error report immediately since
4130 * we are going to start countermeasures and AP better
4131 * do the same.
4132 */
4133 wpa_sm_key_request(wpa_s->wpa, 1,
4134 wpa_s->pending_mic_error_pairwise);
4135 }
4136
4137 /* Send the new MIC error report immediately since we are going
4138 * to start countermeasures and AP better do the same.
4139 */
4140 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4141
4142 /* initialize countermeasures */
4143 wpa_s->countermeasures = 1;
4144
4145 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
4146
4147 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4148
4149 /*
4150 * Need to wait for completion of request frame. We do not get
4151 * any callback for the message completion, so just wait a
4152 * short while and hope for the best. */
4153 os_sleep(0, 10000);
4154
4155 wpa_drv_set_countermeasures(wpa_s, 1);
4156 wpa_supplicant_deauthenticate(wpa_s,
4157 WLAN_REASON_MICHAEL_MIC_FAILURE);
4158 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4159 wpa_s, NULL);
4160 eloop_register_timeout(60, 0,
4161 wpa_supplicant_stop_countermeasures,
4162 wpa_s, NULL);
4163 /* TODO: mark the AP rejected for 60 second. STA is
4164 * allowed to associate with another AP.. */
4165 } else {
4166#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4167 if (wpa_s->mic_errors_seen) {
4168 /*
4169 * Reduce the effectiveness of Michael MIC error
4170 * reports as a means for attacking against TKIP if
4171 * more than one MIC failure is noticed with the same
4172 * PTK. We delay the transmission of the reports by a
4173 * random time between 0 and 60 seconds in order to
4174 * force the attacker wait 60 seconds before getting
4175 * the information on whether a frame resulted in a MIC
4176 * failure.
4177 */
4178 u8 rval[4];
4179 int sec;
4180
4181 if (os_get_random(rval, sizeof(rval)) < 0)
4182 sec = os_random() % 60;
4183 else
4184 sec = WPA_GET_BE32(rval) % 60;
4185 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4186 "report %d seconds", sec);
4187 wpa_s->pending_mic_error_report = 1;
4188 wpa_s->pending_mic_error_pairwise = pairwise;
4189 eloop_cancel_timeout(
4190 wpa_supplicant_delayed_mic_error_report,
4191 wpa_s, NULL);
4192 eloop_register_timeout(
4193 sec, os_random() % 1000000,
4194 wpa_supplicant_delayed_mic_error_report,
4195 wpa_s, NULL);
4196 } else {
4197 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4198 }
4199#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4200 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4201#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4202 }
4203 wpa_s->last_michael_mic_error = t;
4204 wpa_s->mic_errors_seen++;
4205}
4206
4207
4208#ifdef CONFIG_TERMINATE_ONLASTIF
4209static int any_interfaces(struct wpa_supplicant *head)
4210{
4211 struct wpa_supplicant *wpa_s;
4212
4213 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4214 if (!wpa_s->interface_removed)
4215 return 1;
4216 return 0;
4217}
4218#endif /* CONFIG_TERMINATE_ONLASTIF */
4219
4220
4221static void
4222wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4223 union wpa_event_data *data)
4224{
4225 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4226 return;
4227
4228 switch (data->interface_status.ievent) {
4229 case EVENT_INTERFACE_ADDED:
4230 if (!wpa_s->interface_removed)
4231 break;
4232 wpa_s->interface_removed = 0;
4233 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4234 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4235 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4236 "driver after interface was added");
4237 }
4238
4239#ifdef CONFIG_P2P
4240 if (!wpa_s->global->p2p &&
4241 !wpa_s->global->p2p_disabled &&
4242 !wpa_s->conf->p2p_disabled &&
4243 (wpa_s->drv_flags &
4244 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4245 wpas_p2p_add_p2pdev_interface(
4246 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4247 wpa_printf(MSG_INFO,
4248 "P2P: Failed to enable P2P Device interface");
4249 /* Try to continue without. P2P will be disabled. */
4250 }
4251#endif /* CONFIG_P2P */
4252
4253 break;
4254 case EVENT_INTERFACE_REMOVED:
4255 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4256 wpa_s->interface_removed = 1;
4257 wpa_supplicant_mark_disassoc(wpa_s);
4258 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4259 l2_packet_deinit(wpa_s->l2);
4260 wpa_s->l2 = NULL;
4261
4262#ifdef CONFIG_P2P
4263 if (wpa_s->global->p2p &&
4264 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4265 (wpa_s->drv_flags &
4266 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4267 wpa_dbg(wpa_s, MSG_DEBUG,
4268 "Removing P2P Device interface");
4269 wpa_supplicant_remove_iface(
4270 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4271 0);
4272 wpa_s->global->p2p_init_wpa_s = NULL;
4273 }
4274#endif /* CONFIG_P2P */
4275
4276#ifdef CONFIG_MATCH_IFACE
4277 if (wpa_s->matched) {
4278 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4279 break;
4280 }
4281#endif /* CONFIG_MATCH_IFACE */
4282
4283#ifdef CONFIG_TERMINATE_ONLASTIF
4284 /* check if last interface */
4285 if (!any_interfaces(wpa_s->global->ifaces))
4286 eloop_terminate();
4287#endif /* CONFIG_TERMINATE_ONLASTIF */
4288 break;
4289 }
4290}
4291
4292
4293#ifdef CONFIG_TDLS
4294static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4295 union wpa_event_data *data)
4296{
4297 if (data == NULL)
4298 return;
4299 switch (data->tdls.oper) {
4300 case TDLS_REQUEST_SETUP:
4301 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4302 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4303 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4304 else
4305 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
4306 break;
4307 case TDLS_REQUEST_TEARDOWN:
4308 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4309 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4310 data->tdls.reason_code);
4311 else
4312 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4313 data->tdls.peer);
4314 break;
4315 case TDLS_REQUEST_DISCOVER:
4316 wpa_tdls_send_discovery_request(wpa_s->wpa,
4317 data->tdls.peer);
4318 break;
4319 }
4320}
4321#endif /* CONFIG_TDLS */
4322
4323
4324#ifdef CONFIG_WNM
4325static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4326 union wpa_event_data *data)
4327{
4328 if (data == NULL)
4329 return;
4330 switch (data->wnm.oper) {
4331 case WNM_OPER_SLEEP:
4332 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4333 "(action=%d, intval=%d)",
4334 data->wnm.sleep_action, data->wnm.sleep_intval);
4335 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
4336 data->wnm.sleep_intval, NULL);
4337 break;
4338 }
4339}
4340#endif /* CONFIG_WNM */
4341
4342
4343#ifdef CONFIG_IEEE80211R
4344static void
4345wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4346 union wpa_event_data *data)
4347{
4348 if (data == NULL)
4349 return;
4350
4351 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4352 data->ft_ies.ies_len,
4353 data->ft_ies.ft_action,
4354 data->ft_ies.target_ap,
4355 data->ft_ies.ric_ies,
4356 data->ft_ies.ric_ies_len) < 0) {
4357 /* TODO: prevent MLME/driver from trying to associate? */
4358 }
4359}
4360#endif /* CONFIG_IEEE80211R */
4361
4362
4363#ifdef CONFIG_IBSS_RSN
4364static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4365 union wpa_event_data *data)
4366{
4367 struct wpa_ssid *ssid;
4368 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4369 return;
4370 if (data == NULL)
4371 return;
4372 ssid = wpa_s->current_ssid;
4373 if (ssid == NULL)
4374 return;
4375 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4376 return;
4377
4378 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4379}
4380
4381
4382static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4383 union wpa_event_data *data)
4384{
4385 struct wpa_ssid *ssid = wpa_s->current_ssid;
4386
4387 if (ssid == NULL)
4388 return;
4389
4390 /* check if the ssid is correctly configured as IBSS/RSN */
4391 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4392 return;
4393
4394 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4395 data->rx_mgmt.frame_len);
4396}
4397#endif /* CONFIG_IBSS_RSN */
4398
4399
4400#ifdef CONFIG_IEEE80211R
4401static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4402 size_t len)
4403{
4404 const u8 *sta_addr, *target_ap_addr;
4405 u16 status;
4406
4407 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4408 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4409 return; /* only SME case supported for now */
4410 if (len < 1 + 2 * ETH_ALEN + 2)
4411 return;
4412 if (data[0] != 2)
4413 return; /* Only FT Action Response is supported for now */
4414 sta_addr = data + 1;
4415 target_ap_addr = data + 1 + ETH_ALEN;
4416 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4417 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4418 MACSTR " TargetAP " MACSTR " status %u",
4419 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4420
4421 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4422 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4423 " in FT Action Response", MAC2STR(sta_addr));
4424 return;
4425 }
4426
4427 if (status) {
4428 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4429 "failure (status code %d)", status);
4430 /* TODO: report error to FT code(?) */
4431 return;
4432 }
4433
4434 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4435 len - (1 + 2 * ETH_ALEN + 2), 1,
4436 target_ap_addr, NULL, 0) < 0)
4437 return;
4438
4439#ifdef CONFIG_SME
4440 {
4441 struct wpa_bss *bss;
4442 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4443 if (bss)
4444 wpa_s->sme.freq = bss->freq;
4445 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4446 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4447 WLAN_AUTH_FT);
4448 }
4449#endif /* CONFIG_SME */
4450}
4451#endif /* CONFIG_IEEE80211R */
4452
4453
4454static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4455 struct unprot_deauth *e)
4456{
4457 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4458 "dropped: " MACSTR " -> " MACSTR
4459 " (reason code %u)",
4460 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4461 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
4462}
4463
4464
4465static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4466 struct unprot_disassoc *e)
4467{
4468 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4469 "dropped: " MACSTR " -> " MACSTR
4470 " (reason code %u)",
4471 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4472 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
4473}
4474
4475
4476static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4477 u16 reason_code, int locally_generated,
4478 const u8 *ie, size_t ie_len, int deauth)
4479{
4480#ifdef CONFIG_AP
4481 if (wpa_s->ap_iface && addr) {
4482 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4483 return;
4484 }
4485
4486 if (wpa_s->ap_iface) {
4487 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4488 return;
4489 }
4490#endif /* CONFIG_AP */
4491
4492 if (!locally_generated)
4493 wpa_s->own_disconnect_req = 0;
4494
4495 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4496
4497 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4498 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4499 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4500 eapol_sm_failed(wpa_s->eapol))) &&
4501 !wpa_s->eap_expected_failure))
4502 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
4503
4504#ifdef CONFIG_P2P
4505 if (deauth && reason_code > 0) {
4506 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4507 locally_generated) > 0) {
4508 /*
4509 * The interface was removed, so cannot continue
4510 * processing any additional operations after this.
4511 */
4512 return;
4513 }
4514 }
4515#endif /* CONFIG_P2P */
4516
4517 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4518 locally_generated);
4519}
4520
4521
4522static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4523 struct disassoc_info *info)
4524{
4525 u16 reason_code = 0;
4526 int locally_generated = 0;
4527 const u8 *addr = NULL;
4528 const u8 *ie = NULL;
4529 size_t ie_len = 0;
4530
4531 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4532
4533 if (info) {
4534 addr = info->addr;
4535 ie = info->ie;
4536 ie_len = info->ie_len;
4537 reason_code = info->reason_code;
4538 locally_generated = info->locally_generated;
4539 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4540 reason2str(reason_code),
4541 locally_generated ? " locally_generated=1" : "");
4542 if (addr)
4543 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4544 MAC2STR(addr));
4545 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4546 ie, ie_len);
4547 }
4548
4549#ifdef CONFIG_AP
4550 if (wpa_s->ap_iface && info && info->addr) {
4551 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4552 return;
4553 }
4554
4555 if (wpa_s->ap_iface) {
4556 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4557 return;
4558 }
4559#endif /* CONFIG_AP */
4560
4561#ifdef CONFIG_P2P
4562 if (info) {
4563 wpas_p2p_disassoc_notif(
4564 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4565 locally_generated);
4566 }
4567#endif /* CONFIG_P2P */
4568
4569 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4570 sme_event_disassoc(wpa_s, info);
4571
4572 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4573 ie, ie_len, 0);
4574}
4575
4576
4577static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4578 struct deauth_info *info)
4579{
4580 u16 reason_code = 0;
4581 int locally_generated = 0;
4582 const u8 *addr = NULL;
4583 const u8 *ie = NULL;
4584 size_t ie_len = 0;
4585
4586 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4587
4588 if (info) {
4589 addr = info->addr;
4590 ie = info->ie;
4591 ie_len = info->ie_len;
4592 reason_code = info->reason_code;
4593 locally_generated = info->locally_generated;
4594 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4595 reason_code, reason2str(reason_code),
4596 locally_generated ? " locally_generated=1" : "");
4597 if (addr) {
4598 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4599 MAC2STR(addr));
4600 }
4601 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4602 ie, ie_len);
4603 }
4604
4605 wpa_reset_ft_completed(wpa_s->wpa);
4606
4607 wpas_event_disconnect(wpa_s, addr, reason_code,
4608 locally_generated, ie, ie_len, 1);
4609}
4610
4611
4612static const char * reg_init_str(enum reg_change_initiator init)
4613{
4614 switch (init) {
4615 case REGDOM_SET_BY_CORE:
4616 return "CORE";
4617 case REGDOM_SET_BY_USER:
4618 return "USER";
4619 case REGDOM_SET_BY_DRIVER:
4620 return "DRIVER";
4621 case REGDOM_SET_BY_COUNTRY_IE:
4622 return "COUNTRY_IE";
4623 case REGDOM_BEACON_HINT:
4624 return "BEACON_HINT";
4625 }
4626 return "?";
4627}
4628
4629
4630static const char * reg_type_str(enum reg_type type)
4631{
4632 switch (type) {
4633 case REGDOM_TYPE_UNKNOWN:
4634 return "UNKNOWN";
4635 case REGDOM_TYPE_COUNTRY:
4636 return "COUNTRY";
4637 case REGDOM_TYPE_WORLD:
4638 return "WORLD";
4639 case REGDOM_TYPE_CUSTOM_WORLD:
4640 return "CUSTOM_WORLD";
4641 case REGDOM_TYPE_INTERSECTION:
4642 return "INTERSECTION";
4643 }
4644 return "?";
4645}
4646
4647
4648void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4649 struct channel_list_changed *info)
4650{
4651 struct wpa_supplicant *ifs;
4652 u8 dfs_domain;
4653
4654 /*
4655 * To allow backwards compatibility with higher level layers that
4656 * assumed the REGDOM_CHANGE event is sent over the initially added
4657 * interface. Find the highest parent of this interface and use it to
4658 * send the event.
4659 */
4660 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4661 ;
4662
4663 if (info) {
4664 wpa_msg(ifs, MSG_INFO,
4665 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4666 reg_init_str(info->initiator), reg_type_str(info->type),
4667 info->alpha2[0] ? " alpha2=" : "",
4668 info->alpha2[0] ? info->alpha2 : "");
4669 }
4670
4671 if (wpa_s->drv_priv == NULL)
4672 return; /* Ignore event during drv initialization */
4673
4674 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4675 radio_list) {
4676 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4677 ifs->ifname);
4678 free_hw_features(ifs);
4679 ifs->hw.modes = wpa_drv_get_hw_feature_data(
4680 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
4681
4682 /* Restart PNO/sched_scan with updated channel list */
4683 if (ifs->pno) {
4684 wpas_stop_pno(ifs);
4685 wpas_start_pno(ifs);
4686 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4687 wpa_dbg(ifs, MSG_DEBUG,
4688 "Channel list changed - restart sched_scan");
4689 wpas_scan_restart_sched_scan(ifs);
4690 }
4691 }
4692
4693 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
4694}
4695
4696
4697static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
4698 const u8 *frame, size_t len, int freq,
4699 int rssi)
4700{
4701 const struct ieee80211_mgmt *mgmt;
4702 const u8 *payload;
4703 size_t plen;
4704 u8 category;
4705
4706 if (len < IEEE80211_HDRLEN + 2)
4707 return;
4708
4709 mgmt = (const struct ieee80211_mgmt *) frame;
4710 payload = frame + IEEE80211_HDRLEN;
4711 category = *payload++;
4712 plen = len - IEEE80211_HDRLEN - 1;
4713
4714 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4715 " Category=%u DataLen=%d freq=%d MHz",
4716 MAC2STR(mgmt->sa), category, (int) plen, freq);
4717
4718 if (category == WLAN_ACTION_WMM) {
4719 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4720 return;
4721 }
4722
4723#ifdef CONFIG_IEEE80211R
4724 if (category == WLAN_ACTION_FT) {
4725 ft_rx_action(wpa_s, payload, plen);
4726 return;
4727 }
4728#endif /* CONFIG_IEEE80211R */
4729
4730#ifdef CONFIG_SME
4731 if (category == WLAN_ACTION_SA_QUERY) {
4732 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4733 return;
4734 }
4735#endif /* CONFIG_SME */
4736
4737#ifdef CONFIG_WNM
4738 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4739 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4740 return;
4741 }
4742#endif /* CONFIG_WNM */
4743
4744#ifdef CONFIG_GAS
4745 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4746 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4747 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
4748 mgmt->u.action.category,
4749 payload, plen, freq) == 0)
4750 return;
4751#endif /* CONFIG_GAS */
4752
4753#ifdef CONFIG_GAS_SERVER
4754 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4755 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4756 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4757 mgmt->u.action.category,
4758 payload, plen, freq) == 0)
4759 return;
4760#endif /* CONFIG_GAS_SERVER */
4761
4762#ifdef CONFIG_TDLS
4763 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4764 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4765 wpa_dbg(wpa_s, MSG_DEBUG,
4766 "TDLS: Received Discovery Response from " MACSTR,
4767 MAC2STR(mgmt->sa));
4768 return;
4769 }
4770#endif /* CONFIG_TDLS */
4771
4772#ifdef CONFIG_INTERWORKING
4773 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4774 payload[0] == QOS_QOS_MAP_CONFIG) {
4775 const u8 *pos = payload + 1;
4776 size_t qlen = plen - 1;
4777 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4778 MACSTR, MAC2STR(mgmt->sa));
4779 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4780 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4781 pos[1] <= qlen - 2 && pos[1] >= 16)
4782 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4783 return;
4784 }
4785#endif /* CONFIG_INTERWORKING */
4786
4787 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4788 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4789 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
4790 mgmt->da,
4791 payload + 1,
4792 plen - 1);
4793 return;
4794 }
4795
4796 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4797 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4798 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4799 return;
4800 }
4801
4802 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4803 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4804 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4805 payload + 1, plen - 1,
4806 rssi);
4807 return;
4808 }
4809
4810#ifdef CONFIG_FST
4811 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4812 fst_rx_action(wpa_s->fst, mgmt, len);
4813 return;
4814 }
4815#endif /* CONFIG_FST */
4816
4817#ifdef CONFIG_DPP
4818 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4819 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4820 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4821 payload[4] == DPP_OUI_TYPE) {
4822 payload++;
4823 plen--;
4824 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4825 return;
4826 }
4827#endif /* CONFIG_DPP */
4828
4829 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
4830 payload[0] == ROBUST_AV_SCS_RESP) {
4831 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4832 payload + 1, plen - 1);
4833 return;
4834 }
4835
4836 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
4837 payload[0] == ROBUST_AV_MSCS_RESP) {
4838 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4839 payload + 1, plen - 1);
4840 return;
4841 }
4842
4843 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4844 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4845 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4846 payload + 4, plen - 4);
4847 return;
4848 }
4849
4850 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4851 category, payload, plen, freq);
4852 if (wpa_s->ifmsh)
4853 mesh_mpm_action_rx(wpa_s, mgmt, len);
4854}
4855
4856
4857static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4858 union wpa_event_data *event)
4859{
4860 struct wpa_freq_range_list *list;
4861 char *str = NULL;
4862
4863 list = &event->freq_range;
4864
4865 if (list->num)
4866 str = freq_range_list_str(list);
4867 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4868 str ? str : "");
4869
4870#ifdef CONFIG_P2P
4871 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4872 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4873 __func__);
4874 } else {
4875 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
4876
4877 /*
4878 * The update channel flow will also take care of moving a GO
4879 * from the unsafe frequency if needed.
4880 */
4881 wpas_p2p_update_channel_list(wpa_s,
4882 WPAS_P2P_CHANNEL_UPDATE_AVOID);
4883 }
4884#endif /* CONFIG_P2P */
4885
4886 os_free(str);
4887}
4888
4889
4890static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
4891{
4892 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4893 wpa_supplicant_cancel_auth_timeout(wpa_s);
4894 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4895 eapol_sm_notify_portValid(wpa_s->eapol, true);
4896 eapol_sm_notify_eap_success(wpa_s->eapol, true);
4897 wpa_s->drv_authorized_port = 1;
4898 }
4899}
4900
4901
4902static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4903 int freq)
4904{
4905 size_t i;
4906 int j;
4907
4908 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4909 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4910
4911 for (j = 0; j < mode->num_channels; j++) {
4912 const struct hostapd_channel_data *chan;
4913
4914 chan = &mode->channels[j];
4915 if (chan->freq == freq)
4916 return chan->dfs_cac_ms;
4917 }
4918 }
4919
4920 return 0;
4921}
4922
4923
4924static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4925 struct dfs_event *radar)
4926{
4927#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
4928 if (wpa_s->ap_iface || wpa_s->ifmsh) {
4929 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4930 } else
4931#endif /* NEED_AP_MLME && CONFIG_AP */
4932 {
4933 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4934
4935 cac_time /= 1000; /* convert from ms to sec */
4936 if (!cac_time)
4937 cac_time = 10 * 60; /* max timeout: 10 minutes */
4938
4939 /* Restart auth timeout: CAC time added to initial timeout */
4940 wpas_auth_timeout_restart(wpa_s, cac_time);
4941 }
4942}
4943
4944
4945static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4946 struct dfs_event *radar)
4947{
4948#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
4949 if (wpa_s->ap_iface || wpa_s->ifmsh) {
4950 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4951 } else
4952#endif /* NEED_AP_MLME && CONFIG_AP */
4953 {
4954 /* Restart auth timeout with original value after CAC is
4955 * finished */
4956 wpas_auth_timeout_restart(wpa_s, 0);
4957 }
4958}
4959
4960
4961static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4962 struct dfs_event *radar)
4963{
4964#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
4965 if (wpa_s->ap_iface || wpa_s->ifmsh) {
4966 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4967 } else
4968#endif /* NEED_AP_MLME && CONFIG_AP */
4969 {
4970 /* Restart auth timeout with original value after CAC is
4971 * aborted */
4972 wpas_auth_timeout_restart(wpa_s, 0);
4973 }
4974}
4975
4976
4977static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4978 union wpa_event_data *data)
4979{
4980 wpa_dbg(wpa_s, MSG_DEBUG,
4981 "Connection authorized by device, previous state %d",
4982 wpa_s->wpa_state);
4983
4984 wpa_supplicant_event_port_authorized(wpa_s);
4985
4986 wpa_s->last_eapol_matches_bssid = 1;
4987
4988 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4989 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
4990 data->assoc_info.ptk_kck_len,
4991 data->assoc_info.ptk_kek,
4992 data->assoc_info.ptk_kek_len);
4993#ifdef CONFIG_FILS
4994 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4995 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4996 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4997
4998 /* Update ERP next sequence number */
4999 eapol_sm_update_erp_next_seq_num(
5000 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5001
5002 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5003 /* Add the new PMK and PMKID to the PMKSA cache */
5004 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5005 data->assoc_info.fils_pmk,
5006 data->assoc_info.fils_pmk_len,
5007 data->assoc_info.fils_pmkid,
5008 wpa_s->valid_links ?
5009 wpa_s->ap_mld_addr :
5010 wpa_s->bssid,
5011 fils_cache_id);
5012 } else if (data->assoc_info.fils_pmkid) {
5013 /* Update the current PMKSA used for this connection */
5014 pmksa_cache_set_current(wpa_s->wpa,
5015 data->assoc_info.fils_pmkid,
5016 NULL, NULL, 0, NULL, 0);
5017 }
5018 }
5019#endif /* CONFIG_FILS */
5020}
5021
5022
5023static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5024{
5025 switch (code) {
5026 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5027 return "";
5028 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5029 return "no_bss_found";
5030 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5031 return "auth_tx_fail";
5032 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5033 return "auth_no_ack_received";
5034 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5035 return "auth_no_resp_received";
5036 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5037 return "assoc_req_tx_fail";
5038 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5039 return "assoc_no_ack_received";
5040 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5041 return "assoc_no_resp_received";
5042 default:
5043 return "unknown_reason";
5044 }
5045}
5046
5047
5048static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5049 union wpa_event_data *data)
5050{
5051 const u8 *bssid = data->assoc_reject.bssid;
5052#ifdef CONFIG_MBO
5053 struct wpa_bss *reject_bss;
5054#endif /* CONFIG_MBO */
5055
5056 if (!bssid || is_zero_ether_addr(bssid))
5057 bssid = wpa_s->pending_bssid;
5058#ifdef CONFIG_MBO
5059 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5060 reject_bss = wpa_s->current_bss;
5061 else
5062 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5063#endif /* CONFIG_MBO */
5064
5065 if (data->assoc_reject.bssid)
5066 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
5067 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
5068 MAC2STR(data->assoc_reject.bssid),
5069 data->assoc_reject.status_code,
5070 data->assoc_reject.timed_out ? " timeout" : "",
5071 data->assoc_reject.timeout_reason ? "=" : "",
5072 data->assoc_reject.timeout_reason ?
5073 data->assoc_reject.timeout_reason : "",
5074 data->assoc_reject.reason_code !=
5075 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5076 " qca_driver_reason=" : "",
5077 connect_fail_reason(data->assoc_reject.reason_code));
5078 else
5079 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
5080 "status_code=%u%s%s%s%s%s",
5081 data->assoc_reject.status_code,
5082 data->assoc_reject.timed_out ? " timeout" : "",
5083 data->assoc_reject.timeout_reason ? "=" : "",
5084 data->assoc_reject.timeout_reason ?
5085 data->assoc_reject.timeout_reason : "",
5086 data->assoc_reject.reason_code !=
5087 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5088 " qca_driver_reason=" : "",
5089 connect_fail_reason(data->assoc_reject.reason_code));
5090 wpa_s->assoc_status_code = data->assoc_reject.status_code;
5091 wpas_notify_assoc_status_code(wpa_s);
5092
5093#ifdef CONFIG_OWE
5094 if (data->assoc_reject.status_code ==
5095 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5096 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5097 wpa_s->current_ssid &&
5098 wpa_s->current_ssid->owe_group == 0 &&
5099 wpa_s->last_owe_group != 21) {
5100 struct wpa_ssid *ssid = wpa_s->current_ssid;
5101 struct wpa_bss *bss = wpa_s->current_bss;
5102
5103 if (!bss) {
5104 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5105 if (!bss) {
5106 wpas_connection_failed(wpa_s, bssid);
5107 wpa_supplicant_mark_disassoc(wpa_s);
5108 return;
5109 }
5110 }
5111 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5112 wpas_connect_work_done(wpa_s);
5113 wpa_supplicant_mark_disassoc(wpa_s);
5114 wpa_supplicant_connect(wpa_s, bss, ssid);
5115 return;
5116 }
5117#endif /* CONFIG_OWE */
5118
5119#ifdef CONFIG_DPP2
5120 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5121 * the status code defined in the DPP R2 tech spec.
5122 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5123 * interoperability workaround with older hostapd implementation. */
5124 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
5125 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5126 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5127 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
5128 wpa_s->current_ssid->dpp_pfs == 0 &&
5129 (data->assoc_reject.status_code ==
5130 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5131 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5132 struct wpa_ssid *ssid = wpa_s->current_ssid;
5133 struct wpa_bss *bss = wpa_s->current_bss;
5134
5135 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5136 if (!bss)
5137 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5138 if (!bss || wpa_s->dpp_pfs_fallback) {
5139 wpa_printf(MSG_DEBUG,
5140 "DPP: Updated PFS policy for next try");
5141 wpas_connection_failed(wpa_s, bssid);
5142 wpa_supplicant_mark_disassoc(wpa_s);
5143 return;
5144 }
5145 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5146 wpa_s->dpp_pfs_fallback = 1;
5147 wpas_connect_work_done(wpa_s);
5148 wpa_supplicant_mark_disassoc(wpa_s);
5149 wpa_supplicant_connect(wpa_s, bss, ssid);
5150 return;
5151 }
5152#endif /* CONFIG_DPP2 */
5153
5154#ifdef CONFIG_MBO
5155 if (data->assoc_reject.status_code ==
5156 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
5157 reject_bss && data->assoc_reject.resp_ies) {
5158 const u8 *rssi_rej;
5159
5160 rssi_rej = mbo_get_attr_from_ies(
5161 data->assoc_reject.resp_ies,
5162 data->assoc_reject.resp_ies_len,
5163 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5164 if (rssi_rej && rssi_rej[1] == 2) {
5165 wpa_printf(MSG_DEBUG,
5166 "OCE: RSSI-based association rejection from "
5167 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
5168 MAC2STR(reject_bss->bssid),
5169 rssi_rej[2], rssi_rej[3]);
5170 wpa_bss_tmp_disallow(wpa_s,
5171 reject_bss->bssid,
5172 rssi_rej[3],
5173 rssi_rej[2] + reject_bss->level);
5174 }
5175 }
5176#endif /* CONFIG_MBO */
5177
5178 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5179 sme_event_assoc_reject(wpa_s, data);
5180 return;
5181 }
5182
5183 /* Driver-based SME cases */
5184
5185#ifdef CONFIG_SAE
5186 if (wpa_s->current_ssid &&
5187 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5188 !data->assoc_reject.timed_out) {
5189 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5190 wpa_sm_aborted_cached(wpa_s->wpa);
5191 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5192 }
5193#endif /* CONFIG_SAE */
5194
5195#ifdef CONFIG_DPP
5196 if (wpa_s->current_ssid &&
5197 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5198 !data->assoc_reject.timed_out) {
5199 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5200 wpa_sm_aborted_cached(wpa_s->wpa);
5201 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5202 }
5203#endif /* CONFIG_DPP */
5204
5205#ifdef CONFIG_FILS
5206 /* Update ERP next sequence number */
5207 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5208 fils_pmksa_cache_flush(wpa_s);
5209 eapol_sm_update_erp_next_seq_num(
5210 wpa_s->eapol,
5211 data->assoc_reject.fils_erp_next_seq_num);
5212 fils_connection_failure(wpa_s);
5213 }
5214#endif /* CONFIG_FILS */
5215
5216 wpas_connection_failed(wpa_s, bssid);
5217 wpa_supplicant_mark_disassoc(wpa_s);
5218}
5219
5220
5221static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5222 struct unprot_beacon *data)
5223{
5224 struct wpabuf *buf;
5225 int res;
5226
5227 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5228 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5229 return;
5230 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5231 MAC2STR(data->sa));
5232
5233 buf = wpabuf_alloc(4);
5234 if (!buf)
5235 return;
5236
5237 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5238 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5239 wpabuf_put_u8(buf, 1); /* Dialog Token */
5240 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5241
5242 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5243 wpa_s->own_addr, wpa_s->bssid,
5244 wpabuf_head(buf), wpabuf_len(buf), 0);
5245 if (res < 0)
5246 wpa_printf(MSG_DEBUG,
5247 "Failed to send WNM-Notification Request frame");
5248
5249 wpabuf_free(buf);
5250}
5251
5252
5253static const char * bitmap_to_str(u8 value, char *buf)
5254{
5255 char *pos = buf;
5256 int i, k = 0;
5257
5258 for (i = 7; i >= 0; i--)
5259 pos[k++] = (value & BIT(i)) ? '1' : '0';
5260
5261 pos[8] = '\0';
5262 return pos;
5263}
5264
5265
5266static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
5267 struct tid_link_map_info *info)
5268{
5269 char map_info[1000], *pos, *end;
5270 int res, i;
5271
5272 pos = map_info;
5273 end = pos + sizeof(map_info);
5274 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
5275 info->default_map);
5276 if (os_snprintf_error(end - pos, res))
5277 return;
5278 pos += res;
5279
5280 if (!info->default_map) {
5281 for (i = 0; i < MAX_NUM_MLD_LINKS && end > pos; i++) {
5282 char uplink_map_str[9];
5283 char downlink_map_str[9];
5284
5285 if (!(info->valid_links & BIT(i)))
5286 continue;
5287
5288 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
5289 bitmap_to_str(info->t2lmap[i].downlink,
5290 downlink_map_str);
5291
5292 res = os_snprintf(pos, end - pos,
5293 " link_id=%d up_link=%s down_link=%s",
5294 i, uplink_map_str,
5295 downlink_map_str);
5296 if (os_snprintf_error(end - pos, res))
5297 return;
5298 pos += res;
5299 }
5300 }
5301
5302 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
5303}
5304
5305
5306static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
5307{
5308 u8 bssid[ETH_ALEN];
5309
5310 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
5311 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
5312 wpa_supplicant_deauthenticate(wpa_s,
5313 WLAN_REASON_DEAUTH_LEAVING);
5314 return;
5315 }
5316
5317 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
5318 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
5319 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
5320 wpas_notify_bssid_changed(wpa_s);
5321 }
5322
5323 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
5324 wpa_printf(MSG_ERROR,
5325 "LINK_RECONFIG: Failed to get MLO connection info");
5326 wpa_supplicant_deauthenticate(wpa_s,
5327 WLAN_REASON_DEAUTH_LEAVING);
5328 return;
5329 }
5330
5331 if (wpa_sm_set_ml_info(wpa_s)) {
5332 wpa_printf(MSG_ERROR,
5333 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
5334 wpa_supplicant_deauthenticate(wpa_s,
5335 WLAN_REASON_DEAUTH_LEAVING);
5336 return;
5337 }
5338
5339 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
5340 wpa_s->valid_links);
5341}
5342
5343
5344static void
5345supplicant_ch_switch_started(struct wpa_supplicant *wpa_s,
5346 union wpa_event_data *data)
5347{
5348 char buf[256];
5349 size_t len = sizeof(buf);
5350 char *cmd = NULL;
5351 int width = 20;
5352 int ret;
5353
5354 if (!wpa_s->hostapd)
5355 return;
5356
5357 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
5358 "count=%d freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5359 data->ch_switch.count,
5360 data->ch_switch.freq,
5361 data->ch_switch.ht_enabled,
5362 data->ch_switch.ch_offset,
5363 channel_width_to_string(data->ch_switch.ch_width),
5364 data->ch_switch.cf1,
5365 data->ch_switch.cf2);
5366
5367 switch (data->ch_switch.ch_width) {
5368 case CHAN_WIDTH_20_NOHT:
5369 case CHAN_WIDTH_20:
5370 width = 20;
5371 break;
5372 case CHAN_WIDTH_40:
5373 width = 40;
5374 break;
5375 case CHAN_WIDTH_80:
5376 width = 80;
5377 break;
5378 case CHAN_WIDTH_160:
5379 case CHAN_WIDTH_80P80:
5380 width = 160;
5381 break;
5382 }
5383
5384 asprintf(&cmd, "CHAN_SWITCH %d %d sec_channel_offset=%d center_freq1=%d center_freq2=%d, bandwidth=%d auto-ht\n",
5385 data->ch_switch.count - 1,
5386 data->ch_switch.freq,
5387 data->ch_switch.ch_offset,
5388 data->ch_switch.cf1,
5389 data->ch_switch.cf2,
5390 width);
5391 ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
5392 free(cmd);
5393
5394 if (ret < 0)
5395 wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
5396}
5397
5398void supplicant_event(void *ctx, enum wpa_event_type event,
5399 union wpa_event_data *data)
5400{
5401 struct wpa_supplicant *wpa_s = ctx;
5402 int resched;
5403 struct os_reltime age, clear_at;
5404#ifndef CONFIG_NO_STDOUT_DEBUG
5405 int level = MSG_DEBUG;
5406#endif /* CONFIG_NO_STDOUT_DEBUG */
5407
5408 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5409 event != EVENT_INTERFACE_ENABLED &&
5410 event != EVENT_INTERFACE_STATUS &&
5411 event != EVENT_SCAN_RESULTS &&
5412 event != EVENT_SCHED_SCAN_STOPPED) {
5413 wpa_dbg(wpa_s, MSG_DEBUG,
5414 "Ignore event %s (%d) while interface is disabled",
5415 event_to_string(event), event);
5416 return;
5417 }
5418
5419#ifndef CONFIG_NO_STDOUT_DEBUG
5420 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
5421 const struct ieee80211_hdr *hdr;
5422 u16 fc;
5423 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5424 fc = le_to_host16(hdr->frame_control);
5425 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5426 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5427 level = MSG_EXCESSIVE;
5428 }
5429
5430 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5431 event_to_string(event), event);
5432#endif /* CONFIG_NO_STDOUT_DEBUG */
5433
5434 switch (event) {
5435 case EVENT_AUTH:
5436#ifdef CONFIG_FST
5437 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5438 data->auth.ies_len))
5439 wpa_printf(MSG_DEBUG,
5440 "FST: MB IEs updated from auth IE");
5441#endif /* CONFIG_FST */
5442 sme_event_auth(wpa_s, data);
5443 wpa_s->auth_status_code = data->auth.status_code;
5444 wpas_notify_auth_status_code(wpa_s);
5445 break;
5446 case EVENT_ASSOC:
5447#ifdef CONFIG_TESTING_OPTIONS
5448 if (wpa_s->ignore_auth_resp) {
5449 wpa_printf(MSG_INFO,
5450 "EVENT_ASSOC - ignore_auth_resp active!");
5451 break;
5452 }
5453 if (wpa_s->testing_resend_assoc) {
5454 wpa_printf(MSG_INFO,
5455 "EVENT_DEAUTH - testing_resend_assoc");
5456 break;
5457 }
5458#endif /* CONFIG_TESTING_OPTIONS */
5459 if (wpa_s->disconnected) {
5460 wpa_printf(MSG_INFO,
5461 "Ignore unexpected EVENT_ASSOC in disconnected state");
5462 break;
5463 }
5464 wpa_supplicant_event_assoc(wpa_s, data);
5465 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
5466 if (data &&
5467 (data->assoc_info.authorized ||
5468 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5469 wpa_fils_is_completed(wpa_s->wpa))))
5470 wpa_supplicant_event_assoc_auth(wpa_s, data);
5471 if (data) {
5472 wpa_msg(wpa_s, MSG_INFO,
5473 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5474 data->assoc_info.subnet_status);
5475 }
5476 break;
5477 case EVENT_DISASSOC:
5478 wpas_event_disassoc(wpa_s,
5479 data ? &data->disassoc_info : NULL);
5480 break;
5481 case EVENT_DEAUTH:
5482#ifdef CONFIG_TESTING_OPTIONS
5483 if (wpa_s->ignore_auth_resp) {
5484 wpa_printf(MSG_INFO,
5485 "EVENT_DEAUTH - ignore_auth_resp active!");
5486 break;
5487 }
5488 if (wpa_s->testing_resend_assoc) {
5489 wpa_printf(MSG_INFO,
5490 "EVENT_DEAUTH - testing_resend_assoc");
5491 break;
5492 }
5493#endif /* CONFIG_TESTING_OPTIONS */
5494 wpas_event_deauth(wpa_s,
5495 data ? &data->deauth_info : NULL);
5496 break;
5497 case EVENT_LINK_RECONFIG:
5498 wpas_link_reconfig(wpa_s);
5499 break;
5500 case EVENT_MICHAEL_MIC_FAILURE:
5501 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5502 break;
5503#ifndef CONFIG_NO_SCAN_PROCESSING
5504 case EVENT_SCAN_STARTED:
5505 if (wpa_s->own_scan_requested ||
5506 (data && !data->scan_info.external_scan)) {
5507 struct os_reltime diff;
5508
5509 os_get_reltime(&wpa_s->scan_start_time);
5510 os_reltime_sub(&wpa_s->scan_start_time,
5511 &wpa_s->scan_trigger_time, &diff);
5512 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5513 diff.sec, diff.usec);
5514 wpa_s->own_scan_requested = 0;
5515 wpa_s->own_scan_running = 1;
5516 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5517 wpa_s->manual_scan_use_id) {
5518 wpa_msg_ctrl(wpa_s, MSG_INFO,
5519 WPA_EVENT_SCAN_STARTED "id=%u",
5520 wpa_s->manual_scan_id);
5521 } else {
5522 wpa_msg_ctrl(wpa_s, MSG_INFO,
5523 WPA_EVENT_SCAN_STARTED);
5524 }
5525 } else {
5526 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
5527 wpa_s->radio->external_scan_req_interface = wpa_s;
5528 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
5529 }
5530 break;
5531 case EVENT_SCAN_RESULTS:
5532 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5533 wpa_s->scan_res_handler = NULL;
5534 wpa_s->own_scan_running = 0;
5535 wpa_s->radio->external_scan_req_interface = NULL;
5536 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5537 break;
5538 }
5539
5540 if (!(data && data->scan_info.external_scan) &&
5541 os_reltime_initialized(&wpa_s->scan_start_time)) {
5542 struct os_reltime now, diff;
5543 os_get_reltime(&now);
5544 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5545 wpa_s->scan_start_time.sec = 0;
5546 wpa_s->scan_start_time.usec = 0;
5547 wpa_s->wps_scan_done = true;
5548 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5549 diff.sec, diff.usec);
5550 }
5551 if (wpa_supplicant_event_scan_results(wpa_s, data))
5552 break; /* interface may have been removed */
5553 if (!(data && data->scan_info.external_scan))
5554 wpa_s->own_scan_running = 0;
5555 if (data && data->scan_info.nl_scan_event)
5556 wpa_s->radio->external_scan_req_interface = NULL;
5557 radio_work_check_next(wpa_s);
5558 break;
5559#endif /* CONFIG_NO_SCAN_PROCESSING */
5560 case EVENT_ASSOCINFO:
5561 wpa_supplicant_event_associnfo(wpa_s, data);
5562 break;
5563 case EVENT_INTERFACE_STATUS:
5564 wpa_supplicant_event_interface_status(wpa_s, data);
5565 break;
5566 case EVENT_PMKID_CANDIDATE:
5567 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5568 break;
5569#ifdef CONFIG_TDLS
5570 case EVENT_TDLS:
5571 wpa_supplicant_event_tdls(wpa_s, data);
5572 break;
5573#endif /* CONFIG_TDLS */
5574#ifdef CONFIG_WNM
5575 case EVENT_WNM:
5576 wpa_supplicant_event_wnm(wpa_s, data);
5577 break;
5578#endif /* CONFIG_WNM */
5579#ifdef CONFIG_IEEE80211R
5580 case EVENT_FT_RESPONSE:
5581 wpa_supplicant_event_ft_response(wpa_s, data);
5582 break;
5583#endif /* CONFIG_IEEE80211R */
5584#ifdef CONFIG_IBSS_RSN
5585 case EVENT_IBSS_RSN_START:
5586 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5587 break;
5588#endif /* CONFIG_IBSS_RSN */
5589 case EVENT_ASSOC_REJECT:
5590 wpas_event_assoc_reject(wpa_s, data);
5591 break;
5592 case EVENT_AUTH_TIMED_OUT:
5593 /* It is possible to get this event from earlier connection */
5594 if (wpa_s->current_ssid &&
5595 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5596 wpa_dbg(wpa_s, MSG_DEBUG,
5597 "Ignore AUTH_TIMED_OUT in mesh configuration");
5598 break;
5599 }
5600 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5601 sme_event_auth_timed_out(wpa_s, data);
5602 break;
5603 case EVENT_ASSOC_TIMED_OUT:
5604 /* It is possible to get this event from earlier connection */
5605 if (wpa_s->current_ssid &&
5606 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5607 wpa_dbg(wpa_s, MSG_DEBUG,
5608 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5609 break;
5610 }
5611 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5612 sme_event_assoc_timed_out(wpa_s, data);
5613 break;
5614 case EVENT_TX_STATUS:
5615 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5616 " type=%d stype=%d",
5617 MAC2STR(data->tx_status.dst),
5618 data->tx_status.type, data->tx_status.stype);
5619#ifdef CONFIG_PASN
5620 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5621 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5622 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5623 data->tx_status.data_len,
5624 data->tx_status.ack) == 0)
5625 break;
5626#endif /* CONFIG_PASN */
5627#ifdef CONFIG_AP
5628 if (wpa_s->ap_iface == NULL) {
5629#ifdef CONFIG_OFFCHANNEL
5630 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5631 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
5632 offchannel_send_action_tx_status(
5633 wpa_s, data->tx_status.dst,
5634 data->tx_status.data,
5635 data->tx_status.data_len,
5636 data->tx_status.ack ?
5637 OFFCHANNEL_SEND_ACTION_SUCCESS :
5638 OFFCHANNEL_SEND_ACTION_NO_ACK);
5639#endif /* CONFIG_OFFCHANNEL */
5640 break;
5641 }
5642#endif /* CONFIG_AP */
5643#ifdef CONFIG_OFFCHANNEL
5644 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
5645 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
5646 /*
5647 * Catch TX status events for Action frames we sent via group
5648 * interface in GO mode, or via standalone AP interface.
5649 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5650 * except when the primary interface is used as a GO interface
5651 * (for drivers which do not have group interface concurrency)
5652 */
5653 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5654 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
5655 os_memcmp(wpa_s->p2pdev->pending_action_dst,
5656 data->tx_status.dst, ETH_ALEN) == 0) {
5657 offchannel_send_action_tx_status(
5658 wpa_s->p2pdev, data->tx_status.dst,
5659 data->tx_status.data,
5660 data->tx_status.data_len,
5661 data->tx_status.ack ?
5662 OFFCHANNEL_SEND_ACTION_SUCCESS :
5663 OFFCHANNEL_SEND_ACTION_NO_ACK);
5664 break;
5665 }
5666#endif /* CONFIG_OFFCHANNEL */
5667#ifdef CONFIG_AP
5668 switch (data->tx_status.type) {
5669 case WLAN_FC_TYPE_MGMT:
5670 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5671 data->tx_status.data_len,
5672 data->tx_status.stype,
5673 data->tx_status.ack);
5674 break;
5675 case WLAN_FC_TYPE_DATA:
5676 ap_tx_status(wpa_s, data->tx_status.dst,
5677 data->tx_status.data,
5678 data->tx_status.data_len,
5679 data->tx_status.ack);
5680 break;
5681 }
5682#endif /* CONFIG_AP */
5683 break;
5684#ifdef CONFIG_AP
5685 case EVENT_EAPOL_TX_STATUS:
5686 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5687 data->eapol_tx_status.data,
5688 data->eapol_tx_status.data_len,
5689 data->eapol_tx_status.ack);
5690 break;
5691 case EVENT_DRIVER_CLIENT_POLL_OK:
5692 ap_client_poll_ok(wpa_s, data->client_poll.addr);
5693 break;
5694 case EVENT_RX_FROM_UNKNOWN:
5695 if (wpa_s->ap_iface == NULL)
5696 break;
5697 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5698 data->rx_from_unknown.wds);
5699 break;
5700#endif /* CONFIG_AP */
5701
5702 case EVENT_LINK_CH_SWITCH_STARTED:
5703 case EVENT_LINK_CH_SWITCH:
5704 if (!data || !wpa_s->current_ssid ||
5705 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
5706 break;
5707
5708 wpa_msg(wpa_s, MSG_INFO,
5709 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5710 event == EVENT_LINK_CH_SWITCH ?
5711 WPA_EVENT_LINK_CHANNEL_SWITCH :
5712 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
5713 data->ch_switch.freq,
5714 data->ch_switch.link_id,
5715 data->ch_switch.ht_enabled,
5716 data->ch_switch.ch_offset,
5717 channel_width_to_string(data->ch_switch.ch_width),
5718 data->ch_switch.cf1,
5719 data->ch_switch.cf2);
5720 if (event == EVENT_LINK_CH_SWITCH_STARTED)
5721 break;
5722
5723 wpa_s->links[data->ch_switch.link_id].freq =
5724 data->ch_switch.freq;
5725 if (wpa_s->links[data->ch_switch.link_id].bss &&
5726 wpa_s->links[data->ch_switch.link_id].bss->freq !=
5727 data->ch_switch.freq) {
5728 wpa_s->links[data->ch_switch.link_id].bss->freq =
5729 data->ch_switch.freq;
5730 notify_bss_changes(
5731 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5732 wpa_s->links[data->ch_switch.link_id].bss);
5733 }
5734 break;
5735 case EVENT_CH_SWITCH_STARTED:
5736 case EVENT_CH_SWITCH:
5737 if (!data || !wpa_s->current_ssid)
5738 break;
5739
5740 wpa_msg(wpa_s, MSG_INFO,
5741 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5742 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5743 WPA_EVENT_CHANNEL_SWITCH_STARTED,
5744 data->ch_switch.freq,
5745 data->ch_switch.ht_enabled,
5746 data->ch_switch.ch_offset,
5747 channel_width_to_string(data->ch_switch.ch_width),
5748 data->ch_switch.cf1,
5749 data->ch_switch.cf2);
5750 if (event == EVENT_CH_SWITCH_STARTED) {
5751 supplicant_ch_switch_started(wpa_s, data);
5752 break;
5753 }
5754
5755 wpa_s->assoc_freq = data->ch_switch.freq;
5756 wpa_s->current_ssid->frequency = data->ch_switch.freq;
5757 if (wpa_s->current_bss &&
5758 wpa_s->current_bss->freq != data->ch_switch.freq) {
5759 wpa_s->current_bss->freq = data->ch_switch.freq;
5760 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5761 wpa_s->current_bss);
5762 }
5763
5764#ifdef CONFIG_SME
5765 switch (data->ch_switch.ch_offset) {
5766 case 1:
5767 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5768 break;
5769 case -1:
5770 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5771 break;
5772 default:
5773 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5774 break;
5775 }
5776#endif /* CONFIG_SME */
5777
5778#ifdef CONFIG_AP
5779 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5780 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
5781 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
5782 wpa_s->current_ssid->mode ==
5783 WPAS_MODE_P2P_GROUP_FORMATION) {
5784 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5785 data->ch_switch.ht_enabled,
5786 data->ch_switch.ch_offset,
5787 data->ch_switch.ch_width,
5788 data->ch_switch.cf1,
5789 data->ch_switch.cf2,
5790 data->ch_switch.punct_bitmap,
5791 1);
5792 }
5793#endif /* CONFIG_AP */
5794
5795 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5796 sme_event_ch_switch(wpa_s);
5797
5798 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
5799 wnm_clear_coloc_intf_reporting(wpa_s);
5800 break;
5801#ifdef CONFIG_AP
5802#ifdef NEED_AP_MLME
5803 case EVENT_DFS_RADAR_DETECTED:
5804 if (data)
5805 wpas_ap_event_dfs_radar_detected(wpa_s,
5806 &data->dfs_event);
5807 break;
5808 case EVENT_DFS_NOP_FINISHED:
5809 if (data)
5810 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5811 &data->dfs_event);
5812 break;
5813#endif /* NEED_AP_MLME */
5814#endif /* CONFIG_AP */
5815 case EVENT_DFS_CAC_STARTED:
5816 if (data)
5817 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5818 break;
5819 case EVENT_DFS_CAC_FINISHED:
5820 if (data)
5821 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5822 break;
5823 case EVENT_DFS_CAC_ABORTED:
5824 if (data)
5825 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5826 break;
5827 case EVENT_RX_MGMT: {
5828 u16 fc, stype;
5829 const struct ieee80211_mgmt *mgmt;
5830
5831#ifdef CONFIG_TESTING_OPTIONS
5832 if (wpa_s->ext_mgmt_frame_handling) {
5833 struct rx_mgmt *rx = &data->rx_mgmt;
5834 size_t hex_len = 2 * rx->frame_len + 1;
5835 char *hex = os_malloc(hex_len);
5836 if (hex) {
5837 wpa_snprintf_hex(hex, hex_len,
5838 rx->frame, rx->frame_len);
5839 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5840 rx->freq, rx->datarate, rx->ssi_signal,
5841 hex);
5842 os_free(hex);
5843 }
5844 break;
5845 }
5846#endif /* CONFIG_TESTING_OPTIONS */
5847
5848 mgmt = (const struct ieee80211_mgmt *)
5849 data->rx_mgmt.frame;
5850 fc = le_to_host16(mgmt->frame_control);
5851 stype = WLAN_FC_GET_STYPE(fc);
5852
5853#ifdef CONFIG_AP
5854 if (wpa_s->ap_iface == NULL) {
5855#endif /* CONFIG_AP */
5856#ifdef CONFIG_P2P
5857 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
5858 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5859 const u8 *src = mgmt->sa;
5860 const u8 *ie;
5861 size_t ie_len;
5862
5863 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5864 ie_len = data->rx_mgmt.frame_len -
5865 IEEE80211_HDRLEN;
5866 wpas_p2p_probe_req_rx(
5867 wpa_s, src, mgmt->da,
5868 mgmt->bssid, ie, ie_len,
5869 data->rx_mgmt.freq,
5870 data->rx_mgmt.ssi_signal);
5871 break;
5872 }
5873#endif /* CONFIG_P2P */
5874#ifdef CONFIG_IBSS_RSN
5875 if (wpa_s->current_ssid &&
5876 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5877 stype == WLAN_FC_STYPE_AUTH &&
5878 data->rx_mgmt.frame_len >= 30) {
5879 wpa_supplicant_event_ibss_auth(wpa_s, data);
5880 break;
5881 }
5882#endif /* CONFIG_IBSS_RSN */
5883
5884 if (stype == WLAN_FC_STYPE_ACTION) {
5885 wpas_event_rx_mgmt_action(
5886 wpa_s, data->rx_mgmt.frame,
5887 data->rx_mgmt.frame_len,
5888 data->rx_mgmt.freq,
5889 data->rx_mgmt.ssi_signal);
5890 break;
5891 }
5892
5893 if (wpa_s->ifmsh) {
5894 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
5895 break;
5896 }
5897#ifdef CONFIG_PASN
5898 if (stype == WLAN_FC_STYPE_AUTH &&
5899 wpas_pasn_auth_rx(wpa_s, mgmt,
5900 data->rx_mgmt.frame_len) != -2)
5901 break;
5902#endif /* CONFIG_PASN */
5903
5904#ifdef CONFIG_SAE
5905 if (stype == WLAN_FC_STYPE_AUTH &&
5906 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5907 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5908 sme_external_auth_mgmt_rx(
5909 wpa_s, data->rx_mgmt.frame,
5910 data->rx_mgmt.frame_len);
5911 break;
5912 }
5913#endif /* CONFIG_SAE */
5914 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5915 "management frame in non-AP mode");
5916 break;
5917#ifdef CONFIG_AP
5918 }
5919
5920 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
5921 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5922 const u8 *ie;
5923 size_t ie_len;
5924
5925 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5926 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
5927
5928 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5929 mgmt->bssid, ie, ie_len,
5930 data->rx_mgmt.ssi_signal);
5931 }
5932
5933 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
5934#endif /* CONFIG_AP */
5935 break;
5936 }
5937 case EVENT_RX_PROBE_REQ:
5938 if (data->rx_probe_req.sa == NULL ||
5939 data->rx_probe_req.ie == NULL)
5940 break;
5941#ifdef CONFIG_AP
5942 if (wpa_s->ap_iface) {
5943 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5944 data->rx_probe_req.sa,
5945 data->rx_probe_req.da,
5946 data->rx_probe_req.bssid,
5947 data->rx_probe_req.ie,
5948 data->rx_probe_req.ie_len,
5949 data->rx_probe_req.ssi_signal);
5950 break;
5951 }
5952#endif /* CONFIG_AP */
5953 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
5954 data->rx_probe_req.da,
5955 data->rx_probe_req.bssid,
5956 data->rx_probe_req.ie,
5957 data->rx_probe_req.ie_len,
5958 0,
5959 data->rx_probe_req.ssi_signal);
5960 break;
5961 case EVENT_REMAIN_ON_CHANNEL:
5962#ifdef CONFIG_OFFCHANNEL
5963 offchannel_remain_on_channel_cb(
5964 wpa_s, data->remain_on_channel.freq,
5965 data->remain_on_channel.duration);
5966#endif /* CONFIG_OFFCHANNEL */
5967 wpas_p2p_remain_on_channel_cb(
5968 wpa_s, data->remain_on_channel.freq,
5969 data->remain_on_channel.duration);
5970#ifdef CONFIG_DPP
5971 wpas_dpp_remain_on_channel_cb(
5972 wpa_s, data->remain_on_channel.freq,
5973 data->remain_on_channel.duration);
5974#endif /* CONFIG_DPP */
5975 break;
5976 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
5977#ifdef CONFIG_OFFCHANNEL
5978 offchannel_cancel_remain_on_channel_cb(
5979 wpa_s, data->remain_on_channel.freq);
5980#endif /* CONFIG_OFFCHANNEL */
5981 wpas_p2p_cancel_remain_on_channel_cb(
5982 wpa_s, data->remain_on_channel.freq);
5983#ifdef CONFIG_DPP
5984 wpas_dpp_cancel_remain_on_channel_cb(
5985 wpa_s, data->remain_on_channel.freq);
5986#endif /* CONFIG_DPP */
5987 break;
5988 case EVENT_EAPOL_RX:
5989 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5990 data->eapol_rx.data,
5991 data->eapol_rx.data_len,
5992 data->eapol_rx.encrypted);
5993 break;
5994 case EVENT_SIGNAL_CHANGE:
5995 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5996 "above=%d signal=%d noise=%d txrate=%lu",
5997 data->signal_change.above_threshold,
5998 data->signal_change.data.signal,
5999 data->signal_change.current_noise,
6000 data->signal_change.data.current_tx_rate);
6001 wpa_bss_update_level(wpa_s->current_bss,
6002 data->signal_change.data.signal);
6003 bgscan_notify_signal_change(
6004 wpa_s, data->signal_change.above_threshold,
6005 data->signal_change.data.signal,
6006 data->signal_change.current_noise,
6007 data->signal_change.data.current_tx_rate);
6008 os_memcpy(&wpa_s->last_signal_info, data,
6009 sizeof(struct wpa_signal_info));
6010 wpas_notify_signal_change(wpa_s);
6011 break;
6012 case EVENT_INTERFACE_MAC_CHANGED:
6013 wpa_supplicant_update_mac_addr(wpa_s);
6014 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6015 break;
6016 case EVENT_INTERFACE_ENABLED:
6017 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6018 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6019 u8 addr[ETH_ALEN];
6020
6021 eloop_cancel_timeout(wpas_clear_disabled_interface,
6022 wpa_s, NULL);
6023 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
6024 wpa_supplicant_update_mac_addr(wpa_s);
6025 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
6026 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6027 else
6028 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
6029 wpa_supplicant_set_default_scan_ies(wpa_s);
6030 if (wpa_s->p2p_mgmt) {
6031 wpa_supplicant_set_state(wpa_s,
6032 WPA_DISCONNECTED);
6033 break;
6034 }
6035
6036#ifdef CONFIG_AP
6037 if (!wpa_s->ap_iface) {
6038 wpa_supplicant_set_state(wpa_s,
6039 WPA_DISCONNECTED);
6040 wpa_s->scan_req = NORMAL_SCAN_REQ;
6041 wpa_supplicant_req_scan(wpa_s, 0, 0);
6042 } else
6043 wpa_supplicant_set_state(wpa_s,
6044 WPA_COMPLETED);
6045#else /* CONFIG_AP */
6046 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6047 wpa_supplicant_req_scan(wpa_s, 0, 0);
6048#endif /* CONFIG_AP */
6049 }
6050 break;
6051 case EVENT_INTERFACE_DISABLED:
6052 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
6053#ifdef CONFIG_P2P
6054 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6055 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6056 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6057 /*
6058 * Mark interface disabled if this happens to end up not
6059 * being removed as a separate P2P group interface.
6060 */
6061 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6062 /*
6063 * The interface was externally disabled. Remove
6064 * it assuming an external entity will start a
6065 * new session if needed.
6066 */
6067 if (wpa_s->current_ssid &&
6068 wpa_s->current_ssid->p2p_group)
6069 wpas_p2p_interface_unavailable(wpa_s);
6070 else
6071 wpas_p2p_disconnect(wpa_s);
6072 /*
6073 * wpa_s instance may have been freed, so must not use
6074 * it here anymore.
6075 */
6076 break;
6077 }
6078 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6079 p2p_in_progress(wpa_s->global->p2p) > 1) {
6080 /* This radio work will be cancelled, so clear P2P
6081 * state as well.
6082 */
6083 p2p_stop_find(wpa_s->global->p2p);
6084 }
6085#endif /* CONFIG_P2P */
6086
6087 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6088 /*
6089 * Indicate disconnection to keep ctrl_iface events
6090 * consistent.
6091 */
6092 wpa_supplicant_event_disassoc(
6093 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6094 }
6095 wpa_supplicant_mark_disassoc(wpa_s);
6096 os_reltime_age(&wpa_s->last_scan, &age);
6097 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6098 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
6099 clear_at.usec = 0;
6100 } else {
6101 struct os_reltime tmp;
6102
6103 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
6104 tmp.usec = 0;
6105 os_reltime_sub(&tmp, &age, &clear_at);
6106 }
6107 eloop_register_timeout(clear_at.sec, clear_at.usec,
6108 wpas_clear_disabled_interface,
6109 wpa_s, NULL);
6110 radio_remove_works(wpa_s, NULL, 0);
6111
6112 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6113 break;
6114 case EVENT_CHANNEL_LIST_CHANGED:
6115 wpa_supplicant_update_channel_list(
6116 wpa_s, &data->channel_list_changed);
6117 break;
6118 case EVENT_INTERFACE_UNAVAILABLE:
6119 wpas_p2p_interface_unavailable(wpa_s);
6120 break;
6121 case EVENT_BEST_CHANNEL:
6122 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6123 "(%d %d %d)",
6124 data->best_chan.freq_24, data->best_chan.freq_5,
6125 data->best_chan.freq_overall);
6126 wpa_s->best_24_freq = data->best_chan.freq_24;
6127 wpa_s->best_5_freq = data->best_chan.freq_5;
6128 wpa_s->best_overall_freq = data->best_chan.freq_overall;
6129 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6130 data->best_chan.freq_5,
6131 data->best_chan.freq_overall);
6132 break;
6133 case EVENT_UNPROT_DEAUTH:
6134 wpa_supplicant_event_unprot_deauth(wpa_s,
6135 &data->unprot_deauth);
6136 break;
6137 case EVENT_UNPROT_DISASSOC:
6138 wpa_supplicant_event_unprot_disassoc(wpa_s,
6139 &data->unprot_disassoc);
6140 break;
6141 case EVENT_STATION_LOW_ACK:
6142#ifdef CONFIG_AP
6143 if (wpa_s->ap_iface && data)
6144 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6145 data->low_ack.addr);
6146#endif /* CONFIG_AP */
6147#ifdef CONFIG_TDLS
6148 if (data)
6149 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
6150 data->low_ack.addr);
6151#endif /* CONFIG_TDLS */
6152 break;
6153 case EVENT_IBSS_PEER_LOST:
6154#ifdef CONFIG_IBSS_RSN
6155 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6156#endif /* CONFIG_IBSS_RSN */
6157 break;
6158 case EVENT_DRIVER_GTK_REKEY:
6159 if (os_memcmp(data->driver_gtk_rekey.bssid,
6160 wpa_s->bssid, ETH_ALEN))
6161 break;
6162 if (!wpa_s->wpa)
6163 break;
6164 wpa_sm_update_replay_ctr(wpa_s->wpa,
6165 data->driver_gtk_rekey.replay_ctr);
6166 break;
6167 case EVENT_SCHED_SCAN_STOPPED:
6168 wpa_s->sched_scanning = 0;
6169 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
6170 wpa_supplicant_notify_scanning(wpa_s, 0);
6171
6172 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6173 break;
6174
6175 /*
6176 * If the driver stopped scanning without being requested to,
6177 * request a new scan to continue scanning for networks.
6178 */
6179 if (!wpa_s->sched_scan_stop_req &&
6180 wpa_s->wpa_state == WPA_SCANNING) {
6181 wpa_dbg(wpa_s, MSG_DEBUG,
6182 "Restart scanning after unexpected sched_scan stop event");
6183 wpa_supplicant_req_scan(wpa_s, 1, 0);
6184 break;
6185 }
6186
6187 wpa_s->sched_scan_stop_req = 0;
6188
6189 /*
6190 * Start a new sched scan to continue searching for more SSIDs
6191 * either if timed out or PNO schedule scan is pending.
6192 */
6193 if (wpa_s->sched_scan_timed_out) {
6194 wpa_supplicant_req_sched_scan(wpa_s);
6195 } else if (wpa_s->pno_sched_pending) {
6196 wpa_s->pno_sched_pending = 0;
6197 wpas_start_pno(wpa_s);
6198 } else if (resched) {
6199 wpa_supplicant_req_scan(wpa_s, 0, 0);
6200 }
6201
6202 break;
6203 case EVENT_WPS_BUTTON_PUSHED:
6204#ifdef CONFIG_WPS
6205 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
6206#endif /* CONFIG_WPS */
6207 break;
6208 case EVENT_AVOID_FREQUENCIES:
6209 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6210 break;
6211 case EVENT_CONNECT_FAILED_REASON:
6212#ifdef CONFIG_AP
6213 if (!wpa_s->ap_iface || !data)
6214 break;
6215 hostapd_event_connect_failed_reason(
6216 wpa_s->ap_iface->bss[0],
6217 data->connect_failed_reason.addr,
6218 data->connect_failed_reason.code);
6219#endif /* CONFIG_AP */
6220 break;
6221 case EVENT_NEW_PEER_CANDIDATE:
6222#ifdef CONFIG_MESH
6223 if (!wpa_s->ifmsh || !data)
6224 break;
6225 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6226 data->mesh_peer.ies,
6227 data->mesh_peer.ie_len);
6228#endif /* CONFIG_MESH */
6229 break;
6230 case EVENT_SURVEY:
6231#ifdef CONFIG_AP
6232 if (!wpa_s->ap_iface)
6233 break;
6234 hostapd_event_get_survey(wpa_s->ap_iface,
6235 &data->survey_results);
6236#endif /* CONFIG_AP */
6237 break;
6238 case EVENT_ACS_CHANNEL_SELECTED:
6239#ifdef CONFIG_AP
6240#ifdef CONFIG_ACS
6241 if (!wpa_s->ap_iface)
6242 break;
6243 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6244 &data->acs_selected_channels);
6245#endif /* CONFIG_ACS */
6246#endif /* CONFIG_AP */
6247 break;
6248 case EVENT_P2P_LO_STOP:
6249#ifdef CONFIG_P2P
6250 wpa_s->p2p_lo_started = 0;
6251 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6252 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6253 data->p2p_lo_stop.reason_code);
6254#endif /* CONFIG_P2P */
6255 break;
6256 case EVENT_BEACON_LOSS:
6257 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6258 break;
6259 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6260 bgscan_notify_beacon_loss(wpa_s);
6261 break;
6262 case EVENT_EXTERNAL_AUTH:
6263#ifdef CONFIG_SAE
6264 if (!wpa_s->current_ssid) {
6265 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6266 break;
6267 }
6268 sme_external_auth_trigger(wpa_s, data);
6269#endif /* CONFIG_SAE */
6270 break;
6271#ifdef CONFIG_PASN
6272 case EVENT_PASN_AUTH:
6273 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6274 break;
6275#endif /* CONFIG_PASN */
6276 case EVENT_PORT_AUTHORIZED:
6277#ifndef CONFIG_NO_WPA
6278 if (data->port_authorized.td_bitmap_len) {
6279 wpa_printf(MSG_DEBUG,
6280 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
6281 data->port_authorized.td_bitmap[0]);
6282 wpas_transition_disable(
6283 wpa_s, data->port_authorized.td_bitmap[0]);
6284 }
6285#endif /* CONFIG_NO_WPA */
6286 wpa_supplicant_event_port_authorized(wpa_s);
6287 break;
6288 case EVENT_STATION_OPMODE_CHANGED:
6289#ifdef CONFIG_AP
6290 if (!wpa_s->ap_iface || !data)
6291 break;
6292
6293 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6294 data->sta_opmode.addr,
6295 data->sta_opmode.smps_mode,
6296 data->sta_opmode.chan_width,
6297 data->sta_opmode.rx_nss);
6298#endif /* CONFIG_AP */
6299 break;
6300 case EVENT_UNPROT_BEACON:
6301 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6302 break;
6303 case EVENT_TX_WAIT_EXPIRE:
6304#ifdef CONFIG_DPP
6305 wpas_dpp_tx_wait_expire(wpa_s);
6306#endif /* CONFIG_DPP */
6307 break;
6308 case EVENT_TID_LINK_MAP:
6309 if (data)
6310 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
6311 break;
6312 default:
6313 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6314 break;
6315 }
6316}
6317
6318
6319void supplicant_event_global(void *ctx, enum wpa_event_type event,
6320 union wpa_event_data *data)
6321{
6322 struct wpa_supplicant *wpa_s;
6323
6324 if (event != EVENT_INTERFACE_STATUS)
6325 return;
6326
6327 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6328 if (wpa_s && wpa_s->driver->get_ifindex) {
6329 unsigned int ifindex;
6330
6331 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6332 if (ifindex != data->interface_status.ifindex) {
6333 wpa_dbg(wpa_s, MSG_DEBUG,
6334 "interface status ifindex %d mismatch (%d)",
6335 ifindex, data->interface_status.ifindex);
6336 return;
6337 }
6338 }
6339#ifdef CONFIG_MATCH_IFACE
6340 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6341 struct wpa_interface *wpa_i;
6342
6343 wpa_i = wpa_supplicant_match_iface(
6344 ctx, data->interface_status.ifname);
6345 if (!wpa_i)
6346 return;
6347 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6348 os_free(wpa_i);
6349 }
6350#endif /* CONFIG_MATCH_IFACE */
6351
6352 if (wpa_s)
6353 wpa_supplicant_event(wpa_s, event, data);
6354}