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