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