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