blob: 2a665d7cda6dc4975bfc79968da0669f801dda96 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Hai Shalom021b0b52019-04-10 11:17:58 -07003 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
Sunil Ravic0f5d412024-09-11 22:12:49 +000012#include "utils/crc32.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013#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"
Sunil Ravi2a14cf12023-11-21 00:54:38 +000026#include "ap/sta_info.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080028#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070029#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "notify.h"
31#include "common/ieee802_11_defs.h"
32#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070033#include "common/gas_server.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070034#include "common/dpp.h"
Hai Shalom60840252021-02-19 19:02:11 -080035#include "common/ptksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "crypto/random.h"
Hai Shalom60840252021-02-19 19:02:11 -080037#include "bssid_ignore.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#include "wpas_glue.h"
39#include "wps_supplicant.h"
40#include "ibss_rsn.h"
41#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080042#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "p2p_supplicant.h"
44#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070045#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#include "ap.h"
47#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080049#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070050#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080051#include "mesh.h"
52#include "mesh_mpm.h"
53#include "wmm_ac.h"
Sunil Ravib0ac25f2024-07-12 01:42:03 +000054#include "nan_usd.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070055#include "dpp_supplicant.h"
Mir Ali677e7482020-11-12 19:49:02 +053056#include "rsn_supp/wpa_i.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070057
58
Hai Shalom39ba6fc2019-01-22 12:40:38 -080059#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
60
61
Dmitry Shmidt34af3062013-07-11 10:46:32 -070062#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070063static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000064 int new_scan, int own_request,
65 bool trigger_6ghz_scan,
66 union wpa_event_data *data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070067#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080068
69
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070070int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070071{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080072 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070073
74 if (ssid == NULL || ssid->disabled_until.sec == 0)
75 return 0;
76
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080077 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070078 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}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070085
86
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080087#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070088/**
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 */
98static 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}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800123#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700124
125
126void 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
Sunil Ravi7f769292024-07-23 22:21:32 +0000142static 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
153static 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
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800169static 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;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000174 u8 drv_ssid[SSID_MAX_LEN];
175 int res;
Sunil Ravi7f769292024-07-23 22:21:32 +0000176 bool try_update_scan_results = true;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800177
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000178 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
Sunil Ravi7f769292024-07-23 22:21:32 +0000179 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 }
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800190 if (!bss)
Sunil Ravi7f769292024-07-23 22:21:32 +0000191 bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, NULL, 0,
192 try_update_scan_results);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800193
194 return bss;
195}
196
197
Sunil Ravia04bd252022-05-02 22:54:18 -0700198static struct wpa_bss *
199wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700200{
Sunil Ravia04bd252022-05-02 22:54:18 -0700201 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700202
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700203 if (bss)
204 wpa_s->current_bss = bss;
Sunil Ravia04bd252022-05-02 22:54:18 -0700205
206 return bss;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700207}
208
209
Sunil Ravi89eba102022-09-13 21:04:37 -0700210static 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
Sunil Ravi89eba102022-09-13 21:04:37 -0700215 if (bss)
216 wpa_s->links[link_id].bss = bss;
217}
218
219
Sunil Ravi77d572f2023-01-17 23:58:31 +0000220static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
221 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222{
223 struct wpa_ssid *ssid, *old_ssid;
Sunil Ravi640215c2023-06-28 23:08:09 +0000224 struct wpa_bss *bss;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700225 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700226 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700227 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700229 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700230 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700231
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
Hai Shalomfdcde762020-04-02 11:19:20 -0700247#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
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700257 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 */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700261 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262
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
Dmitry Shmidt04949592012-07-19 12:16:46 -0700272 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
274 return -1;
275 }
276
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800277 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
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700283 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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700290 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
291 "current AP");
Sunil Ravi640215c2023-06-28 23:08:09 +0000292 bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800293 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 u8 wpa_ie[80];
295 size_t wpa_ie_len = sizeof(wpa_ie);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000296 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;
Sunil Ravi640215c2023-06-28 23:08:09 +0000302 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000303 wpa_ie, &wpa_ie_len,
304 skip_default_rsne) < 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800305 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700306 } 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;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800314
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 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
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800324void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325{
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");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800332
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);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700341 wpa_supplicant_req_scan(wpa_s, 0, 0);
342 }
343}
344
345
Sunil Ravi77d572f2023-01-17 23:58:31 +0000346void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
Sunil Ravi89eba102022-09-13 21:04:37 -0700347{
Sunil Ravi89eba102022-09-13 21:04:37 -0700348 if (!wpa_s->valid_links)
349 return;
350
351 wpa_s->valid_links = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000352 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));
Sunil Ravi89eba102022-09-13 21:04:37 -0700355}
356
357
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700358void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
359{
360 int bssid_changed;
361
Dmitry Shmidt04949592012-07-19 12:16:46 -0700362 wnm_bss_keep_alive_deinit(wpa_s);
363
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364#ifdef CONFIG_IBSS_RSN
365 ibss_rsn_deinit(wpa_s->ibss_rsn);
366 wpa_s->ibss_rsn = NULL;
367#endif /* CONFIG_IBSS_RSN */
368
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700369#ifdef CONFIG_AP
370 wpa_supplicant_ap_deinit(wpa_s);
371#endif /* CONFIG_AP */
372
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700373#ifdef CONFIG_HS20
374 /* Clear possibly configured frame filters */
375 wpa_drv_configure_frame_filters(wpa_s, 0);
376#endif /* CONFIG_HS20 */
377
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700378 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
379 return;
380
Hai Shalom74f70d42019-02-11 14:42:39 -0800381 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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388 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);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800392 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700393 wpa_s->current_bss = NULL;
394 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 if (bssid_changed)
397 wpas_notify_bssid_changed(wpa_s);
398
Hai Shalome21d4e82020-04-29 16:34:06 -0700399 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
400 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700401 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
402 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700403 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700404 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700405 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700406 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700407 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700408 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700409 wpa_s->key_mgmt = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700410 wpa_s->allowed_key_mgmts = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800411
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000412#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800413 wpas_rrm_reset(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000414#endif /* CONFIG_NO_RRM */
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800415 wpa_s->wnmsleep_used = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000416#ifdef CONFIG_WNM
417 wpa_s->wnm_mode = 0;
418#endif /* CONFIG_WNM */
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800419 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700420 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700421
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 */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700426 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800427
428 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
429 wpa_s->enabled_4addr_mode = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700430
Sunil Ravi77d572f2023-01-17 23:58:31 +0000431 wpa_s->wps_scan_done = false;
Sunil Ravi89eba102022-09-13 21:04:37 -0700432 wpas_reset_mlo_info(wpa_s);
Sunil Ravi7f769292024-07-23 22:21:32 +0000433
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;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440}
441
442
Sunil Ravi036cec52023-03-29 11:35:17 -0700443static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444{
445 struct wpa_ie_data ie;
446 int pmksa_set = -1;
447 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800448 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700449
Hai Shalomc1a21442022-02-04 13:43:00 -0800450 /* Start with assumption of no PMKSA cache entry match for cases other
451 * than SAE. In particular, this is needed to generate the PMKSA cache
452 * entries for Suite B cases with driver-based roaming indication. */
453 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
454 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
455 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700456
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
458 ie.pmkid == NULL)
459 return;
460
461 for (i = 0; i < ie.num_pmkid; i++) {
462 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
463 ie.pmkid + i * PMKID_LEN,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000464 NULL, NULL, 0, NULL, 0,
465 true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800467 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Sunil Ravi036cec52023-03-29 11:35:17 -0700468 if (authorized)
469 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470 break;
471 }
472 }
473
474 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
475 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
476}
477
478
479static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
480 union wpa_event_data *data)
481{
482 if (data == NULL) {
483 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
484 "event");
485 return;
486 }
487 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
488 " index=%d preauth=%d",
489 MAC2STR(data->pmkid_candidate.bssid),
490 data->pmkid_candidate.index,
491 data->pmkid_candidate.preauth);
492
493 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
494 data->pmkid_candidate.index,
495 data->pmkid_candidate.preauth);
496}
497
498
499static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
500{
501 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
502 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
503 return 0;
504
505#ifdef IEEE8021X_EAPOL
506 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
507 wpa_s->current_ssid &&
508 !(wpa_s->current_ssid->eapol_flags &
509 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
510 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
511 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
512 * plaintext or static WEP keys). */
513 return 0;
514 }
515#endif /* IEEE8021X_EAPOL */
516
517 return 1;
518}
519
520
521/**
522 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
523 * @wpa_s: pointer to wpa_supplicant data
524 * @ssid: Configuration data for the network
525 * Returns: 0 on success, -1 on failure
526 *
527 * This function is called when starting authentication with a network that is
528 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
529 */
530int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
531 struct wpa_ssid *ssid)
532{
533#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800534#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700535 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700537 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
538 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539 return 0;
540
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700541 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542 sim = 1;
543 aka = 1;
544 } else {
545 struct eap_method_type *eap = ssid->eap.eap_methods;
546 while (eap->vendor != EAP_VENDOR_IETF ||
547 eap->method != EAP_TYPE_NONE) {
548 if (eap->vendor == EAP_VENDOR_IETF) {
549 if (eap->method == EAP_TYPE_SIM)
550 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700551 else if (eap->method == EAP_TYPE_AKA ||
552 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553 aka = 1;
554 }
555 eap++;
556 }
557 }
558
559 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
560 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700561 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
562 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
563 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 aka = 0;
565
566 if (!sim && !aka) {
567 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
568 "use SIM, but neither EAP-SIM nor EAP-AKA are "
569 "enabled");
570 return 0;
571 }
572
573 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
574 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700576 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577 if (wpa_s->scard == NULL) {
578 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
579 "(pcsc-lite)");
580 return -1;
581 }
582 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
583 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800584#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585#endif /* IEEE8021X_EAPOL */
586
587 return 0;
588}
589
590
591#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700592
Hai Shalomfdcde762020-04-02 11:19:20 -0700593#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700594static int has_wep_key(struct wpa_ssid *ssid)
595{
596 int i;
597
598 for (i = 0; i < NUM_WEP_KEYS; i++) {
599 if (ssid->wep_key_len[i])
600 return 1;
601 }
602
603 return 0;
604}
Hai Shalomfdcde762020-04-02 11:19:20 -0700605#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700606
607
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700608static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 struct wpa_ssid *ssid)
610{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700611 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700612
613 if (ssid->mixed_cell)
614 return 1;
615
616#ifdef CONFIG_WPS
617 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
618 return 1;
619#endif /* CONFIG_WPS */
620
Roshan Pius3a1667e2018-07-03 15:17:14 -0700621#ifdef CONFIG_OWE
622 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
623 return 1;
624#endif /* CONFIG_OWE */
625
Hai Shalomfdcde762020-04-02 11:19:20 -0700626#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700627 if (has_wep_key(ssid))
628 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700629#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700630
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631#ifdef IEEE8021X_EAPOL
632 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
633 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
634 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
635 privacy = 1;
636#endif /* IEEE8021X_EAPOL */
637
Jouni Malinen75ecf522011-06-27 15:19:46 -0700638 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
639 privacy = 1;
640
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800641 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
642 privacy = 1;
643
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 if (bss->caps & IEEE80211_CAP_PRIVACY)
645 return privacy;
646 return !privacy;
647}
648
649
650static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
651 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800652 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700653{
654 struct wpa_ie_data ie;
655 int proto_match = 0;
656 const u8 *rsn_ie, *wpa_ie;
657 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700658#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700659 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700660#endif /* CONFIG_WEP */
Sunil Ravi640215c2023-06-28 23:08:09 +0000661 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662
663 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
664 if (ret >= 0)
665 return ret;
666
Hai Shalomfdcde762020-04-02 11:19:20 -0700667#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
669 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
670 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
671 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
672 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700673#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674
Sunil Ravi7f769292024-07-23 22:21:32 +0000675 rsn_ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
Sunil Ravi640215c2023-06-28 23:08:09 +0000676 if (is_6ghz_bss && !rsn_ie) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700677 if (debug_print)
678 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000679 " skip - 6 GHz BSS without RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700680 return 0;
681 }
682
Roshan Pius3a1667e2018-07-03 15:17:14 -0700683 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 proto_match++;
685
686 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800687 if (debug_print)
688 wpa_dbg(wpa_s, MSG_DEBUG,
689 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690 break;
691 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700692 if (!ie.has_pairwise)
693 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
694 if (!ie.has_group)
695 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696
Sunil Ravi640215c2023-06-28 23:08:09 +0000697 if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
698 /* WEP and TKIP are not allowed on 6 GHz/MLD */
Sunil Ravia04bd252022-05-02 22:54:18 -0700699 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
700 WPA_CIPHER_WEP104 |
701 WPA_CIPHER_TKIP);
702 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
703 WPA_CIPHER_WEP104 |
704 WPA_CIPHER_TKIP);
705 }
706
Hai Shalomfdcde762020-04-02 11:19:20 -0700707#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700708 if (wep_ok &&
709 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
710 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800711 if (debug_print)
712 wpa_dbg(wpa_s, MSG_DEBUG,
713 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700714 return 1;
715 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700716#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717
Roshan Pius3a1667e2018-07-03 15:17:14 -0700718 if (!(ie.proto & ssid->proto) &&
719 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800720 if (debug_print)
721 wpa_dbg(wpa_s, MSG_DEBUG,
722 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723 break;
724 }
725
726 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800727 if (debug_print)
728 wpa_dbg(wpa_s, MSG_DEBUG,
729 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 break;
731 }
732
733 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800734 if (debug_print)
735 wpa_dbg(wpa_s, MSG_DEBUG,
736 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737 break;
738 }
739
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700740 if (ssid->group_mgmt_cipher &&
741 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
742 if (debug_print)
743 wpa_dbg(wpa_s, MSG_DEBUG,
744 " skip RSN IE - group mgmt cipher mismatch");
745 break;
746 }
747
Sunil Ravi640215c2023-06-28 23:08:09 +0000748 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700749 /* MFPC must be supported on 6 GHz */
750 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
751 if (debug_print)
752 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000753 " skip RSNE - 6 GHz without MFPC");
Sunil Ravia04bd252022-05-02 22:54:18 -0700754 break;
755 }
756
757 /* WPA PSK is not allowed on the 6 GHz band */
758 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
759 WPA_KEY_MGMT_FT_PSK |
760 WPA_KEY_MGMT_PSK_SHA256);
761 }
762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800764 if (debug_print)
765 wpa_dbg(wpa_s, MSG_DEBUG,
766 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767 break;
768 }
769
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800771 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800772 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800773 if (debug_print)
774 wpa_dbg(wpa_s, MSG_DEBUG,
775 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776 break;
777 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800778 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
779 wpas_get_ssid_pmf(wpa_s, ssid) ==
780 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800781 if (debug_print)
782 wpa_dbg(wpa_s, MSG_DEBUG,
783 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800784 break;
785 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700786
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800787 if (debug_print)
788 wpa_dbg(wpa_s, MSG_DEBUG,
789 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790 return 1;
791 }
792
Sunil Ravi640215c2023-06-28 23:08:09 +0000793 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700794 if (debug_print)
795 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000796 " skip - 6 GHz BSS without matching RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700797 return 0;
798 }
799
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000800 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
801
Roshan Pius3a1667e2018-07-03 15:17:14 -0700802 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
803 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000804#ifdef CONFIG_OWE
805 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && ssid->owe_only &&
806 !wpa_ie && !rsn_ie &&
807 wpa_s->owe_transition_select &&
808 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
809 ssid->owe_transition_bss_select_count + 1 <=
810 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
811 ssid->owe_transition_bss_select_count++;
812 if (debug_print)
813 wpa_dbg(wpa_s, MSG_DEBUG,
814 " skip OWE open BSS (selection count %d does not exceed %d)",
815 ssid->owe_transition_bss_select_count,
816 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
817 wpa_s->owe_transition_search = 1;
818 return 0;
819 }
820#endif /* CONFIG_OWE */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800821 if (debug_print)
822 wpa_dbg(wpa_s, MSG_DEBUG,
823 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700824 return 0;
825 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700826
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
828 proto_match++;
829
830 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800831 if (debug_print)
832 wpa_dbg(wpa_s, MSG_DEBUG,
833 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700834 break;
835 }
836
Hai Shalomfdcde762020-04-02 11:19:20 -0700837#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 if (wep_ok &&
839 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
840 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800841 if (debug_print)
842 wpa_dbg(wpa_s, MSG_DEBUG,
843 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844 return 1;
845 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700846#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847
848 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800849 if (debug_print)
850 wpa_dbg(wpa_s, MSG_DEBUG,
851 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700852 break;
853 }
854
855 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800856 if (debug_print)
857 wpa_dbg(wpa_s, MSG_DEBUG,
858 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700859 break;
860 }
861
862 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800863 if (debug_print)
864 wpa_dbg(wpa_s, MSG_DEBUG,
865 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866 break;
867 }
868
869 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800870 if (debug_print)
871 wpa_dbg(wpa_s, MSG_DEBUG,
872 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700873 break;
874 }
875
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800876 if (debug_print)
877 wpa_dbg(wpa_s, MSG_DEBUG,
878 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879 return 1;
880 }
881
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700882 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
883 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800884 if (debug_print)
885 wpa_dbg(wpa_s, MSG_DEBUG,
886 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700887 return 1;
888 }
889
Roshan Pius3a1667e2018-07-03 15:17:14 -0700890#ifdef CONFIG_OWE
891 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
892 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800893 if (wpa_s->owe_transition_select &&
894 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
895 ssid->owe_transition_bss_select_count + 1 <=
896 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
897 ssid->owe_transition_bss_select_count++;
898 if (debug_print)
899 wpa_dbg(wpa_s, MSG_DEBUG,
900 " skip OWE transition BSS (selection count %d does not exceed %d)",
901 ssid->owe_transition_bss_select_count,
902 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
903 wpa_s->owe_transition_search = 1;
904 return 0;
905 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700906 if (debug_print)
907 wpa_dbg(wpa_s, MSG_DEBUG,
908 " allow in OWE transition mode");
909 return 1;
910 }
911#endif /* CONFIG_OWE */
912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
914 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800915 if (debug_print)
916 wpa_dbg(wpa_s, MSG_DEBUG,
917 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918 return 0;
919 }
920
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800921 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
922 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800923 if (debug_print)
924 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800925 return 1;
926 }
927
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800929 if (debug_print)
930 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 return 1;
932 }
933
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800934 if (debug_print)
935 wpa_dbg(wpa_s, MSG_DEBUG,
936 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700937
938 return 0;
939}
940
941
942static int freq_allowed(int *freqs, int freq)
943{
944 int i;
945
946 if (freqs == NULL)
947 return 1;
948
949 for (i = 0; freqs[i]; i++)
950 if (freqs[i] == freq)
951 return 1;
952 return 0;
953}
954
955
Hai Shalomfdcde762020-04-02 11:19:20 -0700956static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
957 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800958{
959 const struct hostapd_hw_modes *mode = NULL, *modes;
960 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
961 const u8 *rate_ie;
962 int i, j, k;
963
964 if (bss->freq == 0)
965 return 1; /* Cannot do matching without knowing band */
966
967 modes = wpa_s->hw.modes;
968 if (modes == NULL) {
969 /*
970 * The driver does not provide any additional information
971 * about the utilized hardware, so allow the connection attempt
972 * to continue.
973 */
974 return 1;
975 }
976
977 for (i = 0; i < wpa_s->hw.num_modes; i++) {
978 for (j = 0; j < modes[i].num_channels; j++) {
979 int freq = modes[i].channels[j].freq;
980 if (freq == bss->freq) {
981 if (mode &&
982 mode->mode == HOSTAPD_MODE_IEEE80211G)
983 break; /* do not allow 802.11b replace
984 * 802.11g */
985 mode = &modes[i];
986 break;
987 }
988 }
989 }
990
991 if (mode == NULL)
992 return 0;
993
994 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700995 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800996 if (rate_ie == NULL)
997 continue;
998
999 for (j = 2; j < rate_ie[1] + 2; j++) {
1000 int flagged = !!(rate_ie[j] & 0x80);
1001 int r = (rate_ie[j] & 0x7f) * 5;
1002
1003 /*
1004 * IEEE Std 802.11n-2009 7.3.2.2:
1005 * The new BSS Membership selector value is encoded
1006 * like a legacy basic rate, but it is not a rate and
1007 * only indicates if the BSS members are required to
1008 * support the mandatory features of Clause 20 [HT PHY]
1009 * in order to join the BSS.
1010 */
1011 if (flagged && ((rate_ie[j] & 0x7f) ==
1012 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
1013 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001014 if (debug_print)
1015 wpa_dbg(wpa_s, MSG_DEBUG,
1016 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001017 return 0;
1018 }
1019 continue;
1020 }
1021
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001022 /* There's also a VHT selector for 802.11ac */
1023 if (flagged && ((rate_ie[j] & 0x7f) ==
1024 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
1025 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001026 if (debug_print)
1027 wpa_dbg(wpa_s, MSG_DEBUG,
1028 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001029 return 0;
1030 }
1031 continue;
1032 }
1033
Sunil Ravi77d572f2023-01-17 23:58:31 +00001034 if (flagged && ((rate_ie[j] & 0x7f) ==
1035 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
1036 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
1037 if (debug_print)
1038 wpa_dbg(wpa_s, MSG_DEBUG,
1039 " hardware does not support HE PHY");
1040 return 0;
1041 }
1042 continue;
1043 }
1044
Hai Shalomc3565922019-10-28 11:58:20 -07001045#ifdef CONFIG_SAE
1046 if (flagged && ((rate_ie[j] & 0x7f) ==
1047 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001048 if (wpa_s->conf->sae_pwe ==
1049 SAE_PWE_HUNT_AND_PECK &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001050 !ssid->sae_password_id &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001051 !is_6ghz_freq(bss->freq) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001052 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -07001053 if (debug_print)
1054 wpa_dbg(wpa_s, MSG_DEBUG,
1055 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001056#ifdef CONFIG_TESTING_OPTIONS
1057 if (wpa_s->ignore_sae_h2e_only) {
1058 wpa_dbg(wpa_s, MSG_DEBUG,
1059 "TESTING: Ignore SAE H2E requirement mismatch");
1060 continue;
1061 }
1062#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -07001063 return 0;
1064 }
1065 continue;
1066 }
1067#endif /* CONFIG_SAE */
1068
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001069 if (!flagged)
1070 continue;
1071
1072 /* check for legacy basic rates */
1073 for (k = 0; k < mode->num_rates; k++) {
1074 if (mode->rates[k] == r)
1075 break;
1076 }
1077 if (k == mode->num_rates) {
1078 /*
1079 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1080 * order to join a BSS all required rates
1081 * have to be supported by the hardware.
1082 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001083 if (debug_print)
1084 wpa_dbg(wpa_s, MSG_DEBUG,
1085 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1086 r / 10, r % 10,
1087 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001088 return 0;
1089 }
1090 }
1091 }
1092
1093 return 1;
1094}
1095
1096
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001097/*
1098 * Test whether BSS is in an ESS.
1099 * This is done differently in DMG (60 GHz) and non-DMG bands
1100 */
1101static int bss_is_ess(struct wpa_bss *bss)
1102{
1103 if (bss_is_dmg(bss)) {
1104 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1105 IEEE80211_CAP_DMG_AP;
1106 }
1107
1108 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1109 IEEE80211_CAP_ESS);
1110}
1111
1112
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001113static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1114{
1115 size_t i;
1116
1117 for (i = 0; i < ETH_ALEN; i++) {
1118 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1119 return 0;
1120 }
1121 return 1;
1122}
1123
1124
1125static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1126{
1127 size_t i;
1128
1129 for (i = 0; i < num; i++) {
1130 const u8 *a = list + i * ETH_ALEN * 2;
1131 const u8 *m = a + ETH_ALEN;
1132
1133 if (match_mac_mask(a, addr, m))
1134 return 1;
1135 }
1136 return 0;
1137}
1138
1139
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001140static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1141 const u8 **ret_ssid, size_t *ret_ssid_len)
1142{
1143#ifdef CONFIG_OWE
Sunil Ravic0f5d412024-09-11 22:12:49 +00001144 const u8 *owe, *bssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001145
1146 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
Sunil Ravi7f769292024-07-23 22:21:32 +00001147 if (!owe || !wpa_bss_get_rsne(wpa_s, bss, NULL, false))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001148 return;
1149
Sunil Ravic0f5d412024-09-11 22:12:49 +00001150 if (wpas_get_owe_trans_network(owe, &bssid, ret_ssid, ret_ssid_len))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001151 return;
1152
1153 /* Match the profile SSID against the OWE transition mode SSID on the
1154 * open network. */
1155 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
Sunil Ravic0f5d412024-09-11 22:12:49 +00001156 " SSID: %s", MAC2STR(bssid),
1157 wpa_ssid_txt(*ret_ssid, *ret_ssid_len));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001158
Hai Shalomfdcde762020-04-02 11:19:20 -07001159 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1160 struct wpa_ssid *ssid;
1161
1162 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1163 if (wpas_network_disabled(wpa_s, ssid))
1164 continue;
Sunil Ravic0f5d412024-09-11 22:12:49 +00001165 if (ssid->ssid_len == *ret_ssid_len &&
1166 os_memcmp(ssid->ssid, ret_ssid, *ret_ssid_len) == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001167 /* OWE BSS in transition mode for a currently
1168 * enabled OWE network. */
1169 wpa_dbg(wpa_s, MSG_DEBUG,
1170 "OWE: transition mode OWE SSID for active OWE profile");
1171 bss->flags |= WPA_BSS_OWE_TRANSITION;
1172 break;
1173 }
1174 }
1175 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001176#endif /* CONFIG_OWE */
1177}
1178
1179
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001180static bool wpas_valid_ml_bss(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001181{
1182 u16 removed_links;
1183
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001184 if (wpa_bss_parse_basic_ml_element(wpa_s, bss, NULL, NULL, NULL, NULL))
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001185 return true;
1186
Sunil Ravi99c035e2024-07-12 01:42:03 +00001187 if (!bss->valid_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001188 return true;
1189
1190 /* Check if the current BSS is going to be removed */
1191 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss);
Sunil Ravi99c035e2024-07-12 01:42:03 +00001192 if (BIT(bss->mld_link_id) & removed_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001193 return false;
1194
1195 return true;
1196}
1197
1198
Sunil Ravi26978f32021-04-30 15:19:18 -07001199int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001200{
1201 int i, j;
1202
1203 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1204 return 0;
1205
1206 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1207 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1208
1209 for (i = 0; i < mode->num_channels; i++) {
1210 struct hostapd_channel_data *chan = &mode->channels[i];
1211
1212 if (chan->freq == freq)
1213 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1214 }
1215 }
1216
1217 return 1;
1218}
1219
1220
Hai Shalom899fcc72020-10-19 14:38:18 -07001221static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1222 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001223 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001224 bool debug_print);
1225
1226
1227#ifdef CONFIG_SAE_PK
1228static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1229 struct wpa_bss *orig_bss,
1230 struct wpa_ssid *ssid,
1231 const u8 *match_ssid,
1232 size_t match_ssid_len)
1233{
1234 struct wpa_bss *bss;
1235
1236 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1237 int count;
1238 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001239
1240 if (bss == orig_bss)
1241 continue;
Sunil Ravi7f769292024-07-23 22:21:32 +00001242 ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
Hai Shalomc1a21442022-02-04 13:43:00 -08001243 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001244 continue;
1245
1246 /* TODO: Could be more thorough in checking what kind of
1247 * signal strength or throughput estimate would be acceptable
1248 * compared to the originally selected BSS. */
1249 if (bss->est_throughput < 2000)
1250 return false;
1251
Hai Shalom60840252021-02-19 19:02:11 -08001252 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001253 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1254 bss, count, 0))
1255 return true;
1256 }
1257
1258 return false;
1259}
1260#endif /* CONFIG_SAE_PK */
1261
1262
1263static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1264 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001265 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001266 bool debug_print)
1267{
1268 int res;
1269 bool wpa, check_ssid, osen, rsn_osen = false;
1270 struct wpa_ie_data data;
1271#ifdef CONFIG_MBO
1272 const u8 *assoc_disallow;
1273#endif /* CONFIG_MBO */
1274#ifdef CONFIG_SAE
1275 u8 rsnxe_capa = 0;
1276#endif /* CONFIG_SAE */
1277 const u8 *ie;
1278
1279 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1280 wpa = ie && ie[1];
Sunil Ravi7f769292024-07-23 22:21:32 +00001281 ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
Hai Shalom899fcc72020-10-19 14:38:18 -07001282 wpa |= ie && ie[1];
1283 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1284 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1285 rsn_osen = true;
1286 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1287 osen = ie != NULL;
1288
1289#ifdef CONFIG_SAE
Sunil Ravi7f769292024-07-23 22:21:32 +00001290 ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
1291 if (ie && ie[0] == WLAN_EID_VENDOR_SPECIFIC && ie[1] >= 4 + 1)
1292 rsnxe_capa = ie[4 + 2];
1293 else if (ie && ie[1] >= 1)
Hai Shalom899fcc72020-10-19 14:38:18 -07001294 rsnxe_capa = ie[2];
1295#endif /* CONFIG_SAE */
1296
1297 check_ssid = wpa || ssid->ssid_len > 0;
1298
1299 if (wpas_network_disabled(wpa_s, ssid)) {
1300 if (debug_print)
1301 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1302 return false;
1303 }
1304
1305 res = wpas_temp_disabled(wpa_s, ssid);
1306 if (res > 0) {
1307 if (debug_print)
1308 wpa_dbg(wpa_s, MSG_DEBUG,
1309 " skip - disabled temporarily for %d second(s)",
1310 res);
1311 return false;
1312 }
1313
1314#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001315 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001316 if (debug_print)
1317 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001318 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001319 return false;
1320 }
1321
1322 if (wpa && ssid->ssid_len == 0 &&
1323 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1324 check_ssid = false;
1325
1326 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1327 /* Only allow wildcard SSID match if an AP advertises active
1328 * WPS operation that matches our mode. */
1329 check_ssid = ssid->ssid_len > 0 ||
1330 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1331 }
1332#endif /* CONFIG_WPS */
1333
1334 if (ssid->bssid_set && ssid->ssid_len == 0 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001335 ether_addr_equal(bss->bssid, ssid->bssid))
Hai Shalom899fcc72020-10-19 14:38:18 -07001336 check_ssid = false;
1337
1338 if (check_ssid &&
1339 (match_ssid_len != ssid->ssid_len ||
1340 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1341 if (debug_print)
1342 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1343 return false;
1344 }
1345
1346 if (ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001347 !ether_addr_equal(bss->bssid, ssid->bssid)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001348 if (debug_print)
1349 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1350 return false;
1351 }
1352
Hai Shalom60840252021-02-19 19:02:11 -08001353 /* check the list of BSSIDs to ignore */
1354 if (ssid->num_bssid_ignore &&
1355 addr_in_list(bss->bssid, ssid->bssid_ignore,
1356 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001357 if (debug_print)
1358 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001359 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001360 return false;
1361 }
1362
Hai Shalom60840252021-02-19 19:02:11 -08001363 /* if there is a list of accepted BSSIDs, only accept those APs */
1364 if (ssid->num_bssid_accept &&
1365 !addr_in_list(bss->bssid, ssid->bssid_accept,
1366 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001367 if (debug_print)
1368 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001369 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001370 return false;
1371 }
1372
1373 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1374 return false;
1375
1376 if (!osen && !wpa &&
1377 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1378 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1379 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1380 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1381 if (debug_print)
1382 wpa_dbg(wpa_s, MSG_DEBUG,
1383 " skip - non-WPA network not allowed");
1384 return false;
1385 }
1386
1387#ifdef CONFIG_WEP
1388 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1389 if (debug_print)
1390 wpa_dbg(wpa_s, MSG_DEBUG,
1391 " skip - ignore WPA/WPA2 AP for WEP network block");
1392 return false;
1393 }
1394#endif /* CONFIG_WEP */
1395
1396 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1397 if (debug_print)
1398 wpa_dbg(wpa_s, MSG_DEBUG,
1399 " skip - non-OSEN network not allowed");
1400 return false;
1401 }
1402
1403 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1404 if (debug_print)
1405 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1406 return false;
1407 }
1408
1409 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1410 !bss_is_pbss(bss)) {
1411 if (debug_print)
1412 wpa_dbg(wpa_s, MSG_DEBUG,
1413 " skip - not ESS, PBSS, or MBSS");
1414 return false;
1415 }
1416
1417 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1418 if (debug_print)
1419 wpa_dbg(wpa_s, MSG_DEBUG,
1420 " skip - PBSS mismatch (ssid %d bss %d)",
1421 ssid->pbss, bss_is_pbss(bss));
1422 return false;
1423 }
1424
1425 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1426 if (debug_print)
1427 wpa_dbg(wpa_s, MSG_DEBUG,
1428 " skip - frequency not allowed");
1429 return false;
1430 }
1431
1432#ifdef CONFIG_MESH
1433 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1434 ssid->frequency != bss->freq) {
1435 if (debug_print)
1436 wpa_dbg(wpa_s, MSG_DEBUG,
1437 " skip - frequency not allowed (mesh)");
1438 return false;
1439 }
1440#endif /* CONFIG_MESH */
1441
1442 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1443 if (debug_print)
1444 wpa_dbg(wpa_s, MSG_DEBUG,
1445 " skip - rate sets do not match");
1446 return false;
1447 }
1448
1449#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001450 /* When using SAE Password Identifier and when operationg on the 6 GHz
1451 * band, only H2E is allowed. */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001452 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1453 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1454 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1455 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001456#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301457 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001458#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001459 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1460 if (debug_print)
1461 wpa_dbg(wpa_s, MSG_DEBUG,
1462 " skip - SAE H2E required, but not supported by the AP");
1463 return false;
1464 }
1465#endif /* CONFIG_SAE */
1466
1467#ifdef CONFIG_SAE_PK
1468 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1469 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1470 if (debug_print)
1471 wpa_dbg(wpa_s, MSG_DEBUG,
1472 " skip - SAE-PK required, but not supported by the AP");
1473 return false;
1474 }
1475#endif /* CONFIG_SAE_PK */
1476
1477#ifndef CONFIG_IBSS_RSN
1478 if (ssid->mode == WPAS_MODE_IBSS &&
1479 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1480 if (debug_print)
1481 wpa_dbg(wpa_s, MSG_DEBUG,
1482 " skip - IBSS RSN not supported in the build");
1483 return false;
1484 }
1485#endif /* !CONFIG_IBSS_RSN */
1486
1487#ifdef CONFIG_P2P
1488 if (ssid->p2p_group &&
1489 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1490 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1491 if (debug_print)
1492 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1493 return false;
1494 }
1495
1496 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1497 struct wpabuf *p2p_ie;
1498 u8 dev_addr[ETH_ALEN];
1499
1500 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1501 if (!ie) {
1502 if (debug_print)
1503 wpa_dbg(wpa_s, MSG_DEBUG,
1504 " skip - no P2P element");
1505 return false;
1506 }
1507 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1508 if (!p2p_ie) {
1509 if (debug_print)
1510 wpa_dbg(wpa_s, MSG_DEBUG,
1511 " skip - could not fetch P2P element");
1512 return false;
1513 }
1514
1515 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001516 !ether_addr_equal(dev_addr, ssid->go_p2p_dev_addr)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001517 if (debug_print)
1518 wpa_dbg(wpa_s, MSG_DEBUG,
1519 " skip - no matching GO P2P Device Address in P2P element");
1520 wpabuf_free(p2p_ie);
1521 return false;
1522 }
1523 wpabuf_free(p2p_ie);
1524 }
1525
1526 /*
1527 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1528 * P2P Group Capability Bitmap and we are not in Group Formation with
1529 * that device.
1530 */
1531#endif /* CONFIG_P2P */
1532
1533 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1534 struct os_reltime diff;
1535
1536 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1537 if (debug_print)
1538 wpa_dbg(wpa_s, MSG_DEBUG,
1539 " skip - scan result not recent enough (%u.%06u seconds too old)",
1540 (unsigned int) diff.sec,
1541 (unsigned int) diff.usec);
1542 return false;
1543 }
1544#ifdef CONFIG_MBO
1545#ifdef CONFIG_TESTING_OPTIONS
1546 if (wpa_s->ignore_assoc_disallow)
1547 goto skip_assoc_disallow;
1548#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001549 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001550 if (assoc_disallow && assoc_disallow[1] >= 1) {
1551 if (debug_print)
1552 wpa_dbg(wpa_s, MSG_DEBUG,
1553 " skip - MBO association disallowed (reason %u)",
1554 assoc_disallow[2]);
1555 return false;
1556 }
1557
1558 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1559 if (debug_print)
1560 wpa_dbg(wpa_s, MSG_DEBUG,
1561 " skip - AP temporarily disallowed");
1562 return false;
1563 }
1564#ifdef CONFIG_TESTING_OPTIONS
1565skip_assoc_disallow:
1566#endif /* CONFIG_TESTING_OPTIONS */
1567#endif /* CONFIG_MBO */
1568
1569#ifdef CONFIG_DPP
1570 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001571 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1572 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001573 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1574 !ssid->dpp_csign)) {
1575 if (debug_print)
1576 wpa_dbg(wpa_s, MSG_DEBUG,
1577 " skip - no PMKSA entry for DPP");
1578 return false;
1579 }
1580#endif /* CONFIG_DPP */
1581
1582#ifdef CONFIG_SAE_PK
1583 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1584 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1585 ((ssid->sae_password &&
1586 sae_pk_valid_password(ssid->sae_password)) ||
1587 (!ssid->sae_password && ssid->passphrase &&
1588 sae_pk_valid_password(ssid->passphrase))) &&
1589 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1590 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1591 match_ssid_len)) {
1592 if (debug_print)
1593 wpa_dbg(wpa_s, MSG_DEBUG,
1594 " skip - another acceptable BSS with SAE-PK in the same ESS");
1595 return false;
1596 }
1597#endif /* CONFIG_SAE_PK */
1598
1599 if (bss->ssid_len == 0) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001600#ifdef CONFIG_OWE
1601 const u8 *owe_ssid = NULL;
1602 size_t owe_ssid_len = 0;
1603
1604 owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len);
1605 if (owe_ssid && owe_ssid_len &&
1606 owe_ssid_len == ssid->ssid_len &&
1607 os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) {
1608 if (debug_print)
1609 wpa_dbg(wpa_s, MSG_DEBUG,
1610 " skip - no SSID in BSS entry for a possible OWE transition mode BSS");
1611 int_array_add_unique(&wpa_s->owe_trans_scan_freq,
1612 bss->freq);
1613 return false;
1614 }
1615#endif /* CONFIG_OWE */
Hai Shalom899fcc72020-10-19 14:38:18 -07001616 if (debug_print)
1617 wpa_dbg(wpa_s, MSG_DEBUG,
1618 " skip - no SSID known for the BSS");
1619 return false;
1620 }
1621
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001622 if (!wpas_valid_ml_bss(wpa_s, bss)) {
1623 if (debug_print)
1624 wpa_dbg(wpa_s, MSG_DEBUG,
1625 " skip - ML BSS going to be removed");
1626 return false;
1627 }
1628
Hai Shalom899fcc72020-10-19 14:38:18 -07001629 /* Matching configuration found */
1630 return true;
1631}
1632
1633
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001634struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1635 int i, struct wpa_bss *bss,
1636 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001637 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001638{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001639 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001640 const u8 *ie;
1641 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001642 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001643 const u8 *match_ssid;
1644 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001645 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001646
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001647 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001648 wpa_ie_len = ie ? ie[1] : 0;
1649
Sunil Ravi7f769292024-07-23 22:21:32 +00001650 ie = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001651 rsn_ie_len = ie ? ie[1] : 0;
1652
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001653 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1654 osen = ie != NULL;
1655
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001656 if (debug_print) {
1657 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1658 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1659 i, MAC2STR(bss->bssid),
1660 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1661 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1662 bss->freq,
1663 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1664 " wps" : "",
1665 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1666 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1667 ? " p2p" : "",
1668 osen ? " osen=1" : "");
1669 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001670
Hai Shalom60840252021-02-19 19:02:11 -08001671 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1672 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001673 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001674 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675 /*
1676 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001677 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001678 * should not be done with multiple enabled networks to
1679 * avoid getting forced to move into a worse ESS on
1680 * single error if there are no other BSSes of the
1681 * current ESS.
1682 */
1683 limit = 0;
1684 }
Hai Shalom60840252021-02-19 19:02:11 -08001685 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001686 if (debug_print) {
1687 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001688 " skip - BSSID ignored (count=%d limit=%d)",
1689 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001690 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001691 return NULL;
1692 }
1693 }
1694
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001695 match_ssid = bss->ssid;
1696 match_ssid_len = bss->ssid_len;
1697 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1698
1699 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001700 if (debug_print)
1701 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001702 return NULL;
1703 }
1704
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001705 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001706 if (debug_print)
1707 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001708 return NULL;
1709 }
1710
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001711 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001712 if (debug_print)
1713 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001714 return NULL;
1715 }
1716
Hai Shalomfdcde762020-04-02 11:19:20 -07001717 if (disabled_freq(wpa_s, bss->freq)) {
1718 if (debug_print)
1719 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1720 return NULL;
1721 }
1722
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001723 if (wnm_is_bss_excluded(wpa_s, bss)) {
1724 if (debug_print)
1725 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID excluded");
1726 return NULL;
1727 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001728
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001729 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001730 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001731 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001732 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001733 }
1734
1735 /* No matching configuration found */
1736 return NULL;
1737}
1738
1739
1740static struct wpa_bss *
1741wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001742 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001743 struct wpa_ssid **selected_ssid,
1744 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001745{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001746 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001747
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001748 if (wpa_s->current_ssid) {
1749 struct wpa_ssid *ssid;
1750
1751 wpa_dbg(wpa_s, MSG_DEBUG,
1752 "Scan results matching the currently selected network");
1753 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1754 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1755
1756 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1757 only_first_ssid, 0);
1758 if (ssid != wpa_s->current_ssid)
1759 continue;
1760 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1761 " freq=%d level=%d snr=%d est_throughput=%u",
1762 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1763 bss->snr, bss->est_throughput);
1764 }
1765 }
1766
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001767 if (only_first_ssid)
1768 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1769 group->id);
1770 else
1771 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1772 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001773
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001774 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1775 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001776
1777 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001778 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001779 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001780 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001781 if (!*selected_ssid)
1782 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001783 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001784 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001785 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001786 MAC2STR(bss->bssid),
1787 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1788 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001789 }
1790
1791 return NULL;
1792}
1793
1794
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001795struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1796 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797{
1798 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001799 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001800 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001801 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001802
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001803 if (wpa_s->last_scan_res == NULL ||
1804 wpa_s->last_scan_res_used == 0)
1805 return NULL; /* no scan results from last update */
1806
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001807 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001808 /* check that next_ssid is still valid */
1809 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1810 if (ssid == wpa_s->next_ssid)
1811 break;
1812 }
1813 next_ssid = ssid;
1814 wpa_s->next_ssid = NULL;
1815 }
1816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001818 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1819 if (next_ssid && next_ssid->priority ==
1820 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001821 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001822 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001823 if (selected)
1824 break;
1825 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001826 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001827 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001828 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001829 if (selected)
1830 break;
1831 }
1832
Sunil Ravi99c035e2024-07-12 01:42:03 +00001833 if (!selected &&
1834 (wpa_s->bssid_ignore || wnm_active_bss_trans_mgmt(wpa_s)) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001835 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001836 wpa_dbg(wpa_s, MSG_DEBUG,
1837 "No APs found - clear BSSID ignore list and try again");
Sunil Ravi99c035e2024-07-12 01:42:03 +00001838 wnm_btm_reset(wpa_s);
Hai Shalom60840252021-02-19 19:02:11 -08001839 wpa_bssid_ignore_clear(wpa_s);
1840 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 } else if (selected == NULL)
1842 break;
1843 }
1844
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001845 ssid = *selected_ssid;
1846 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1847 !ssid->passphrase && !ssid->ext_psk) {
1848 const char *field_name, *txt = NULL;
1849
1850 wpa_dbg(wpa_s, MSG_DEBUG,
1851 "PSK/passphrase not yet available for the selected network");
1852
1853 wpas_notify_network_request(wpa_s, ssid,
1854 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1855
1856 field_name = wpa_supplicant_ctrl_req_to_string(
1857 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1858 if (field_name == NULL)
1859 return NULL;
1860
1861 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1862
1863 selected = NULL;
1864 }
1865
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001866 return selected;
1867}
1868
1869
1870static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1871 int timeout_sec, int timeout_usec)
1872{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001873 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874 /*
1875 * No networks are enabled; short-circuit request so
1876 * we don't wait timeout seconds before transitioning
1877 * to INACTIVE state.
1878 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001879 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1880 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001881 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1882 return;
1883 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001884
1885 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001886 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1887}
1888
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001889
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001890static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s)
1891{
1892 if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss)
1893 return false;
1894
1895 wpa_msg(wpa_s, MSG_DEBUG,
1896 "Request association with " MACSTR " after ML probe",
1897 MAC2STR(wpa_s->ml_connect_probe_bss->bssid));
1898
1899 wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss,
1900 wpa_s->ml_connect_probe_ssid);
1901
1902 wpa_s->ml_connect_probe_ssid = NULL;
1903 wpa_s->ml_connect_probe_bss = NULL;
1904
1905 return true;
1906}
1907
1908
1909static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s,
1910 struct wpa_bss *selected,
1911 struct wpa_ssid *ssid)
1912{
1913 int *freqs;
1914 u16 missing_links = 0, removed_links;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001915 u8 ap_mld_id;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001916
1917 if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
1918 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)))
1919 return 0;
1920
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001921 if (wpa_bss_parse_basic_ml_element(wpa_s, selected, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001922 &missing_links, ssid,
1923 &ap_mld_id) ||
1924 !missing_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001925 return 0;
1926
1927 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected);
1928 missing_links &= ~removed_links;
1929
1930 if (!missing_links)
1931 return 0;
1932
1933 wpa_dbg(wpa_s, MSG_DEBUG,
1934 "MLD: Doing an ML probe for missing links 0x%04x",
1935 missing_links);
1936
1937 freqs = os_malloc(sizeof(int) * 2);
1938 if (!freqs)
1939 return 0;
1940
1941 wpa_s->ml_connect_probe_ssid = ssid;
1942 wpa_s->ml_connect_probe_bss = selected;
1943
1944 freqs[0] = selected->freq;
1945 freqs[1] = 0;
1946
1947 wpa_s->manual_scan_passive = 0;
1948 wpa_s->manual_scan_use_id = 0;
1949 wpa_s->manual_scan_only_new = 0;
1950 wpa_s->scan_id_count = 0;
1951 os_free(wpa_s->manual_scan_freqs);
1952 wpa_s->manual_scan_freqs = freqs;
1953
1954 os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001955
1956 /*
1957 * In case the ML probe request is intended to retrieve information from
1958 * the transmitted BSS, the AP MLD ID should be included and should be
1959 * set to zero.
1960 * In case the ML probe requested is intended to retrieve information
1961 * from a non-transmitted BSS, the AP MLD ID should not be included.
1962 */
1963 if (ap_mld_id)
1964 wpa_s->ml_probe_mld_id = -1;
1965 else
1966 wpa_s->ml_probe_mld_id = 0;
1967
1968 if (ssid && ssid->ssid_len) {
1969 os_free(wpa_s->ssids_from_scan_req);
1970 wpa_s->num_ssids_from_scan_req = 0;
1971
1972 wpa_s->ssids_from_scan_req =
1973 os_zalloc(sizeof(struct wpa_ssid_value));
1974 if (wpa_s->ssids_from_scan_req) {
1975 wpa_printf(MSG_DEBUG,
1976 "MLD: ML probe: With direct SSID");
1977
1978 wpa_s->num_ssids_from_scan_req = 1;
1979 wpa_s->ssids_from_scan_req[0].ssid_len = ssid->ssid_len;
1980 os_memcpy(wpa_s->ssids_from_scan_req[0].ssid,
1981 ssid->ssid, ssid->ssid_len);
1982 }
1983 }
1984
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001985 wpa_s->ml_probe_links = missing_links;
1986
1987 wpa_s->normal_scans = 0;
1988 wpa_s->scan_req = MANUAL_SCAN_REQ;
1989 wpa_s->after_wps = 0;
1990 wpa_s->known_wps_freq = 0;
1991 wpa_supplicant_req_scan(wpa_s, 0, 0);
1992
1993 return 1;
1994}
1995
1996
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001997int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001998 struct wpa_bss *selected,
1999 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002000{
Sunil Ravi640215c2023-06-28 23:08:09 +00002001#ifdef IEEE8021X_EAPOL
Sunil Ravi036cec52023-03-29 11:35:17 -07002002 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
2003 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00002004 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002005 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
2006 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07002007 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002008 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002009#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002010 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
2011 wpa_s->p2p_in_provisioning) {
2012 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
2013 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002014 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002015 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002016#endif /* CONFIG_P2P */
2017
2018#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002019 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002020 wpas_wps_cancel(wpa_s);
2021#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002022 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002023 }
Sunil Ravi640215c2023-06-28 23:08:09 +00002024#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002026 wpa_msg(wpa_s, MSG_DEBUG,
2027 "Considering connect request: reassociate: %d selected: "
2028 MACSTR " bssid: " MACSTR " pending: " MACSTR
2029 " wpa_state: %s ssid=%p current_ssid=%p",
2030 wpa_s->reassociate, MAC2STR(selected->bssid),
2031 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
2032 wpa_supplicant_state_txt(wpa_s->wpa_state),
2033 ssid, wpa_s->current_ssid);
2034
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002035 /*
2036 * Do not trigger new association unless the BSSID has changed or if
2037 * reassociation is requested. If we are in process of associating with
2038 * the selected BSSID, do not trigger new attempt.
2039 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002040 if (wpa_s->reassociate ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002041 (!ether_addr_equal(selected->bssid, wpa_s->bssid) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002042 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
2043 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002044 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002045 !ether_addr_equal(selected->bssid, wpa_s->pending_bssid)) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002046 (is_zero_ether_addr(wpa_s->pending_bssid) &&
2047 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002048 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
2049 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002050 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002051 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002052
2053 if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid))
2054 return 0;
2055
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002056 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
2057 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002058 wpa_supplicant_associate(wpa_s, selected, ssid);
2059 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002060 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
2061 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002062 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002063
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002064 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002065}
2066
2067
2068static struct wpa_ssid *
2069wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
2070{
Hai Shalomfdcde762020-04-02 11:19:20 -07002071 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002072 struct wpa_ssid *ssid;
2073
2074 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
2075 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
2076 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002077 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002078 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002079#ifndef CONFIG_IBSS_RSN
2080 if (ssid->mode == WPAS_MODE_IBSS &&
2081 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
2082 WPA_KEY_MGMT_WPA_NONE))) {
2083 wpa_msg(wpa_s, MSG_INFO,
2084 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
2085 wpa_ssid_txt(ssid->ssid,
2086 ssid->ssid_len));
2087 continue;
2088 }
2089#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07002090 if (ssid->mode == WPAS_MODE_IBSS ||
2091 ssid->mode == WPAS_MODE_AP ||
2092 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002093 return ssid;
2094 }
2095 }
2096 return NULL;
2097}
2098
2099
2100/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
2101 * on BSS added and BSS changed events */
2102static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03002103 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002104{
Jouni Malinen87fd2792011-05-16 18:35:42 +03002105 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002106
2107 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
2108 return;
2109
Jouni Malinen87fd2792011-05-16 18:35:42 +03002110 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002111 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002112
Jouni Malinen87fd2792011-05-16 18:35:42 +03002113 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002114 if (ssid == NULL)
2115 continue;
2116
Sunil Ravi7f769292024-07-23 22:21:32 +00002117 rsn = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002118 if (rsn == NULL)
2119 continue;
2120
Jouni Malinen87fd2792011-05-16 18:35:42 +03002121 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002122 }
2123
2124}
2125
2126
Hai Shalomfdcde762020-04-02 11:19:20 -07002127#ifndef CONFIG_NO_ROAMING
2128
2129static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
2130{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002131 if (noise == WPA_INVALID_NOISE) {
2132 if (IS_5GHZ(frequency)) {
2133 noise = DEFAULT_NOISE_FLOOR_5GHZ;
2134 } else if (is_6ghz_freq(frequency)) {
2135 noise = DEFAULT_NOISE_FLOOR_6GHZ;
2136 } else {
2137 noise = DEFAULT_NOISE_FLOOR_2GHZ;
2138 }
2139 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002140 return avg_signal - noise;
2141}
2142
2143
2144static unsigned int
2145wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
2146 const struct wpa_bss *bss, int snr)
2147{
2148 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08002149 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07002150 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002151 enum chan_width max_cw = CHAN_WIDTH_UNKNOWN;
Hai Shalomfdcde762020-04-02 11:19:20 -07002152
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002153 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq,
2154 &max_cw);
Hai Shalomfdcde762020-04-02 11:19:20 -07002155}
2156
Hai Shalomfdcde762020-04-02 11:19:20 -07002157
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002158static int wpas_evaluate_band_score(int frequency)
2159{
2160 if (is_6ghz_freq(frequency))
2161 return 2;
2162 if (IS_5GHZ(frequency))
2163 return 1;
2164 return 0;
2165}
2166
2167
Hai Shalom899fcc72020-10-19 14:38:18 -07002168int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
2169 struct wpa_bss *current_bss,
2170 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002171{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002172 int min_diff, diff;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002173 int cur_band_score, sel_band_score;
Sunil Ravi036cec52023-03-29 11:35:17 -07002174 int to_5ghz, to_6ghz;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002175 int cur_level, sel_level;
Hai Shalomfdcde762020-04-02 11:19:20 -07002176 unsigned int cur_est, sel_est;
2177 struct wpa_signal_info si;
2178 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07002179 int ret = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002180 const u8 *cur_ies = wpa_bss_ie_ptr(current_bss);
2181 const u8 *sel_ies = wpa_bss_ie_ptr(selected);
2182 size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len :
2183 current_bss->beacon_ie_len;
2184 size_t sel_ie_len = selected->ie_len ? selected->ie_len :
2185 selected->beacon_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002187 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002188 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002189 " freq=%d level=%d snr=%d est_throughput=%u",
2190 MAC2STR(current_bss->bssid),
2191 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002192 current_bss->snr, current_bss->est_throughput);
2193 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002194 " freq=%d level=%d snr=%d est_throughput=%u",
2195 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002196 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002197
Sunil Ravi7f769292024-07-23 22:21:32 +00002198 if (wpas_ap_link_address(wpa_s, selected->bssid)) {
2199 wpa_dbg(wpa_s, MSG_DEBUG, "MLD: associated to selected BSS");
2200 return 0;
2201 }
2202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002203 if (wpa_s->current_ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002204 ether_addr_equal(selected->bssid, wpa_s->current_ssid->bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002205 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2206 "has preferred BSSID");
2207 return 1;
2208 }
2209
Hai Shalomfdcde762020-04-02 11:19:20 -07002210 /*
2211 * Try to poll the signal from the driver since this will allow to get
2212 * more accurate values. In some cases, there can be big differences
2213 * between the RSSI of the Probe Response frames of the AP we are
2214 * associated with and the Beacon frames we hear from the same AP after
2215 * association. This can happen, e.g., when there are two antennas that
2216 * hear the AP very differently. If the driver chooses to hear the
2217 * Probe Response frames during the scan on the "bad" antenna because
2218 * it wants to save power, but knows to choose the other antenna after
2219 * association, we will hear our AP with a low RSSI as part of the
2220 * scan even when we can hear it decently on the other antenna. To cope
2221 * with this, ask the driver to teach us how it hears the AP. Also, the
2222 * scan results may be a bit old, since we can very quickly get fresh
2223 * information about our currently associated AP.
2224 */
2225 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002226 (si.data.avg_beacon_signal || si.data.avg_signal)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002227 /*
2228 * Normalize avg_signal to the RSSI over 20 MHz, as the
2229 * throughput is estimated based on the RSSI over 20 MHz
2230 */
Sunil Ravi77d572f2023-01-17 23:58:31 +00002231 cur_level = si.data.avg_beacon_signal ?
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002232 si.data.avg_beacon_signal :
2233 (si.data.avg_signal -
2234 wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2235 si.chanwidth));
Hai Shalomfdcde762020-04-02 11:19:20 -07002236 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2237 si.current_noise);
2238
2239 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2240 current_bss,
2241 cur_snr);
2242 wpa_dbg(wpa_s, MSG_DEBUG,
2243 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2244 cur_level, cur_snr, cur_est);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002245 } else {
2246 /* Level and SNR are measured over 20 MHz channel */
2247 cur_level = current_bss->level;
2248 cur_snr = current_bss->snr;
2249 cur_est = current_bss->est_throughput;
Hai Shalomfdcde762020-04-02 11:19:20 -07002250 }
2251
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002252 /* Adjust the SNR of BSSes based on the channel width. */
2253 cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2254 current_bss->max_cw);
2255 cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len,
2256 current_bss->max_cw, cur_snr);
2257
2258 sel_est = selected->est_throughput;
2259 sel_level = selected->level +
2260 wpas_channel_width_rssi_bump(sel_ies, sel_ie_len,
2261 selected->max_cw);
2262
Hai Shalomfdcde762020-04-02 11:19:20 -07002263 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002264 wpa_dbg(wpa_s, MSG_DEBUG,
2265 "Allow reassociation - selected BSS has better estimated throughput");
2266 return 1;
2267 }
2268
Dmitry Shmidte4663042016-04-04 10:07:49 -07002269 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
Sunil Ravi036cec52023-03-29 11:35:17 -07002270 to_6ghz = is_6ghz_freq(selected->freq) &&
2271 !is_6ghz_freq(current_bss->freq);
Dmitry Shmidte4663042016-04-04 10:07:49 -07002272
Sunil Ravi036cec52023-03-29 11:35:17 -07002273 if (cur_level < 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002274 cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002275 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002276 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2277 "signal level");
2278 return 0;
2279 }
2280
Hai Shalomfdcde762020-04-02 11:19:20 -07002281 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002282 wpa_dbg(wpa_s, MSG_DEBUG,
2283 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002284 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002285 }
2286
Hai Shalomfdcde762020-04-02 11:19:20 -07002287 if (cur_snr > GREAT_SNR) {
2288 wpa_dbg(wpa_s, MSG_DEBUG,
2289 "Skip roam - Current BSS has good SNR (%u > %u)",
2290 cur_snr, GREAT_SNR);
2291 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002292 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002293
Hai Shalomfdcde762020-04-02 11:19:20 -07002294 if (cur_level < -85) /* ..-86 dBm */
2295 min_diff = 1;
2296 else if (cur_level < -80) /* -85..-81 dBm */
2297 min_diff = 2;
2298 else if (cur_level < -75) /* -80..-76 dBm */
2299 min_diff = 3;
2300 else if (cur_level < -70) /* -75..-71 dBm */
2301 min_diff = 4;
2302 else if (cur_level < 0) /* -70..-1 dBm */
2303 min_diff = 5;
2304 else /* unspecified units (not in dBm) */
2305 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002306
Hai Shalomfdcde762020-04-02 11:19:20 -07002307 if (cur_est > sel_est * 1.5)
2308 min_diff += 10;
2309 else if (cur_est > sel_est * 1.2)
2310 min_diff += 5;
2311 else if (cur_est > sel_est * 1.1)
2312 min_diff += 2;
2313 else if (cur_est > sel_est)
2314 min_diff++;
2315 else if (sel_est > cur_est * 1.5)
2316 min_diff -= 10;
2317 else if (sel_est > cur_est * 1.2)
2318 min_diff -= 5;
2319 else if (sel_est > cur_est * 1.1)
2320 min_diff -= 2;
2321 else if (sel_est > cur_est)
2322 min_diff--;
2323
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002324 cur_band_score = wpas_evaluate_band_score(current_bss->freq);
2325 sel_band_score = wpas_evaluate_band_score(selected->freq);
2326 min_diff += (cur_band_score - sel_band_score) * 2;
2327 if (wpa_s->signal_threshold && cur_level <= wpa_s->signal_threshold &&
2328 sel_level > wpa_s->signal_threshold)
Sunil Ravi036cec52023-03-29 11:35:17 -07002329 min_diff -= 2;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002330 diff = sel_level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002331 if (diff < min_diff) {
2332 wpa_dbg(wpa_s, MSG_DEBUG,
2333 "Skip roam - too small difference in signal level (%d < %d)",
2334 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002335 ret = 0;
2336 } else {
2337 wpa_dbg(wpa_s, MSG_DEBUG,
2338 "Allow reassociation due to difference in signal level (%d >= %d)",
2339 diff, min_diff);
2340 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002341 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002342 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2343 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2344 " sel_freq=%d sel_level=%d sel_est=%d",
2345 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2346 MAC2STR(current_bss->bssid),
2347 current_bss->freq, cur_level, cur_est,
2348 MAC2STR(selected->bssid),
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002349 selected->freq, sel_level, sel_est);
Hai Shalom899fcc72020-10-19 14:38:18 -07002350 return ret;
2351}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002352
Hai Shalom899fcc72020-10-19 14:38:18 -07002353#endif /* CONFIG_NO_ROAMING */
2354
2355
2356static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2357 struct wpa_bss *selected,
2358 struct wpa_ssid *ssid)
2359{
2360 struct wpa_bss *current_bss = NULL;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002361 const u8 *bssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07002362
2363 if (wpa_s->reassociate)
2364 return 1; /* explicit request to reassociate */
2365 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2366 return 1; /* we are not associated; continue */
2367 if (wpa_s->current_ssid == NULL)
2368 return 1; /* unknown current SSID */
2369 if (wpa_s->current_ssid != ssid)
2370 return 1; /* different network block */
2371
2372 if (wpas_driver_bss_selection(wpa_s))
2373 return 0; /* Driver-based roaming */
2374
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002375 if (wpa_s->valid_links)
2376 bssid = wpa_s->links[wpa_s->mlo_assoc_link_id].bssid;
2377 else
2378 bssid = wpa_s->bssid;
2379
Hai Shalom899fcc72020-10-19 14:38:18 -07002380 if (wpa_s->current_ssid->ssid)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002381 current_bss = wpa_bss_get(wpa_s, bssid,
Hai Shalom899fcc72020-10-19 14:38:18 -07002382 wpa_s->current_ssid->ssid,
2383 wpa_s->current_ssid->ssid_len);
2384 if (!current_bss)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002385 current_bss = wpa_bss_get_bssid(wpa_s, bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07002386
2387 if (!current_bss)
2388 return 1; /* current BSS not seen in scan results */
2389
2390 if (current_bss == selected)
2391 return 0;
2392
2393 if (selected->last_update_idx > current_bss->last_update_idx)
2394 return 1; /* current BSS not seen in the last scan */
2395
2396#ifndef CONFIG_NO_ROAMING
2397 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2398 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002399#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002400 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002401#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002402}
2403
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002404
Sunil Ravic0f5d412024-09-11 22:12:49 +00002405static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s,
2406 union wpa_event_data *data)
2407{
2408 struct wpa_driver_scan_params params;
2409 unsigned int j;
2410
2411 wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan");
2412 os_memset(&params, 0, sizeof(params));
2413 params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz;
2414 for (j = 0; j < data->scan_info.num_ssids; j++)
2415 params.ssids[j] = data->scan_info.ssids[j];
2416 params.num_ssids = data->scan_info.num_ssids;
2417 wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
2418 true, false, false);
2419 if (!wpa_supplicant_trigger_scan(wpa_s, &params, true, true)) {
2420 wpa_s->scan_in_progress_6ghz = true;
2421 wpas_notify_scan_in_progress_6ghz(wpa_s);
2422 os_free(params.freqs);
2423 return 1;
2424 }
2425 wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan");
2426 os_free(params.freqs);
2427 return 0;
2428}
2429
2430
2431static bool wpas_short_ssid_match(struct wpa_supplicant *wpa_s,
2432 struct wpa_scan_results *scan_res)
2433{
2434 size_t i;
2435 struct wpa_ssid *ssid = wpa_s->current_ssid;
2436 u32 current_ssid_short = ieee80211_crc32(ssid->ssid, ssid->ssid_len);
2437
2438 for (i = 0; i < scan_res->num; i++) {
2439 struct wpa_scan_res *res = scan_res->res[i];
2440 const u8 *rnr_ie, *ie_end;
2441 const struct ieee80211_neighbor_ap_info *info;
2442 size_t left;
2443
2444 rnr_ie = wpa_scan_get_ie(res, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
2445 if (!rnr_ie)
2446 continue;
2447
2448 ie_end = rnr_ie + 2 + rnr_ie[1];
2449 rnr_ie += 2;
2450
2451 left = ie_end - rnr_ie;
2452 if (left < sizeof(struct ieee80211_neighbor_ap_info))
2453 continue;
2454
2455 info = (const struct ieee80211_neighbor_ap_info *) rnr_ie;
2456 if (info->tbtt_info_len < 11)
2457 continue; /* short SSID not included */
2458 left -= sizeof(struct ieee80211_neighbor_ap_info);
2459 rnr_ie += sizeof(struct ieee80211_neighbor_ap_info);
2460
2461 while (left >= info->tbtt_info_len && rnr_ie + 11 <= ie_end) {
2462 /* Skip TBTT offset and BSSID */
2463 u32 short_ssid = WPA_GET_LE32(rnr_ie + 1 + ETH_ALEN);
2464
2465 if (short_ssid == current_ssid_short)
2466 return true;
2467
2468 left -= info->tbtt_info_len;
2469 rnr_ie += info->tbtt_info_len;
2470 }
2471 }
2472
2473 return false;
2474}
2475
2476
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002477/*
2478 * Return a negative value if no scan results could be fetched or if scan
2479 * results should not be shared with other virtual interfaces.
2480 * Return 0 if scan results were fetched and may be shared with other
2481 * interfaces.
2482 * Return 1 if scan results may be shared with other virtual interfaces but may
2483 * not trigger any operations.
2484 * Return 2 if the interface was removed and cannot be used.
2485 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002486static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002487 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002488 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002489{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002490 struct wpa_scan_results *scan_res = NULL;
2491 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002492 int ap = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002493 bool trigger_6ghz_scan;
Sunil Ravic0f5d412024-09-11 22:12:49 +00002494 bool short_ssid_match_found = false;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002495#ifndef CONFIG_NO_RANDOM_POOL
2496 size_t i, num;
2497#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002498
2499#ifdef CONFIG_AP
2500 if (wpa_s->ap_iface)
2501 ap = 1;
2502#endif /* CONFIG_AP */
2503
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002504 trigger_6ghz_scan = wpa_s->crossed_6ghz_dom &&
2505 wpa_s->last_scan_all_chan;
2506 wpa_s->crossed_6ghz_dom = false;
2507 wpa_s->last_scan_all_chan = false;
2508
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002509 wpa_supplicant_notify_scanning(wpa_s, 0);
2510
2511 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2512 data ? &data->scan_info :
Sunil Ravi99c035e2024-07-12 01:42:03 +00002513 NULL, 1, NULL);
Sunil Ravic0f5d412024-09-11 22:12:49 +00002514
2515 if (wpa_s->scan_in_progress_6ghz) {
2516 wpa_s->scan_in_progress_6ghz = false;
2517 wpas_notify_scan_in_progress_6ghz(wpa_s);
2518 }
2519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002520 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002521 if (wpa_s->conf->ap_scan == 2 || ap ||
2522 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002523 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002524 if (!own_request)
2525 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002526 if (data && data->scan_info.external_scan)
2527 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002528 if (wpa_s->scan_res_fail_handler) {
2529 void (*handler)(struct wpa_supplicant *wpa_s);
2530
2531 handler = wpa_s->scan_res_fail_handler;
2532 wpa_s->scan_res_fail_handler = NULL;
2533 handler(wpa_s);
2534 } else {
2535 wpa_dbg(wpa_s, MSG_DEBUG,
2536 "Failed to get scan results - try scanning again");
2537 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2538 }
2539
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002540 ret = -1;
2541 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002542 }
2543
2544#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002545 num = scan_res->num;
2546 if (num > 10)
2547 num = 10;
2548 for (i = 0; i < num; i++) {
2549 u8 buf[5];
2550 struct wpa_scan_res *res = scan_res->res[i];
2551 buf[0] = res->bssid[5];
2552 buf[1] = res->qual & 0xff;
2553 buf[2] = res->noise & 0xff;
2554 buf[3] = res->level & 0xff;
2555 buf[4] = res->tsf & 0xff;
2556 random_add_randomness(buf, sizeof(buf));
2557 }
2558#endif /* CONFIG_NO_RANDOM_POOL */
2559
Sunil Ravi7f769292024-07-23 22:21:32 +00002560 wpa_s->last_scan_external = data && data->scan_info.external_scan;
2561
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002562 if (update_only) {
2563 ret = 1;
2564 goto scan_work_done;
2565 }
2566
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002567 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002568 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002569 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2570 struct wpa_scan_results *scan_res);
2571
2572 scan_res_handler = wpa_s->scan_res_handler;
2573 wpa_s->scan_res_handler = NULL;
2574 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002575 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002576 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002577 }
2578
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002579 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002580 wpa_s->own_scan_running,
2581 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002582 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002583 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2584 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002585 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2586 wpa_s->manual_scan_id);
2587 wpa_s->manual_scan_use_id = 0;
2588 } else {
2589 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2590 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002591 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002592
2593 wpas_notify_scan_done(wpa_s, 1);
2594
Hai Shalomfdcde762020-04-02 11:19:20 -07002595 if (ap) {
2596 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2597#ifdef CONFIG_AP
2598 if (wpa_s->ap_iface->scan_cb)
2599 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2600#endif /* CONFIG_AP */
2601 goto scan_work_done;
2602 }
2603
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002604 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002605 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
Dmitry Shmidt04949592012-07-19 12:16:46 -07002606 wpa_scan_results_free(scan_res);
2607 return 0;
2608 }
2609
Hai Shalomc1a21442022-02-04 13:43:00 -08002610 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002611 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002612
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002613#ifndef CONFIG_NO_RRM
Hai Shalom021b0b52019-04-10 11:17:58 -07002614 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002615 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2616 goto scan_work_done;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002617#endif /* CONFIG_NO_RRM */
Dmitry Shmidt29333592017-01-09 12:27:11 -08002618
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002619 if (ml_link_probe_scan(wpa_s))
2620 goto scan_work_done;
2621
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002622 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2623 goto scan_work_done;
2624
2625 if (autoscan_notify_scan(wpa_s, scan_res))
2626 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002627
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002628 if (wpa_s->disconnected) {
2629 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002630 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002631 }
2632
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002633 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002634 bgscan_notify_scan(wpa_s, scan_res) == 1)
2635 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002636
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002637 wpas_wps_update_ap_info(wpa_s, scan_res);
2638
Sunil Ravic0f5d412024-09-11 22:12:49 +00002639 if (wnm_scan_process(wpa_s, false) > 0)
2640 goto scan_work_done;
2641
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002642 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2643 wpa_s->wpa_state < WPA_COMPLETED)
2644 goto scan_work_done;
2645
Sunil Ravic0f5d412024-09-11 22:12:49 +00002646 if (wpa_s->current_ssid && trigger_6ghz_scan && own_request && data &&
2647 wpas_short_ssid_match(wpa_s, scan_res)) {
2648 wpa_dbg(wpa_s, MSG_INFO, "Short SSID match in scan results");
2649 short_ssid_match_found = true;
2650 }
2651
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002652 wpa_scan_results_free(scan_res);
2653
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002654 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002655 struct wpa_radio_work *work = wpa_s->scan_work;
2656 wpa_s->scan_work = NULL;
2657 radio_work_done(work);
2658 }
2659
Hai Shalomc3565922019-10-28 11:58:20 -07002660 os_free(wpa_s->last_scan_freqs);
2661 wpa_s->last_scan_freqs = NULL;
2662 wpa_s->num_last_scan_freqs = 0;
2663 if (own_request && data &&
2664 data->scan_info.freqs && data->scan_info.num_freqs) {
2665 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2666 data->scan_info.num_freqs);
2667 if (wpa_s->last_scan_freqs) {
2668 os_memcpy(wpa_s->last_scan_freqs,
2669 data->scan_info.freqs,
2670 sizeof(int) * data->scan_info.num_freqs);
2671 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2672 }
2673 }
2674
Sunil Ravi77d572f2023-01-17 23:58:31 +00002675 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2676 return ret;
2677
Sunil Ravic0f5d412024-09-11 22:12:49 +00002678 if (short_ssid_match_found && wpas_trigger_6ghz_scan(wpa_s, data) > 0)
2679 return 1;
2680
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002681 return wpas_select_network_from_last_scan(wpa_s, 1, own_request,
2682 trigger_6ghz_scan, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002683
2684scan_work_done:
2685 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002686 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002687 struct wpa_radio_work *work = wpa_s->scan_work;
2688 wpa_s->scan_work = NULL;
2689 radio_work_done(work);
2690 }
2691 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002692}
2693
2694
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002695/**
2696 * Select a network from the last scan
2697 * @wpa_s: Pointer to wpa_supplicant data
2698 * @new_scan: Whether this function was called right after a scan has finished
2699 * @own_request: Whether the scan was requested by this interface
2700 * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable
2701 * @data: Scan data from scan that finished if applicable
2702 *
2703 * See _wpa_supplicant_event_scan_results() for return values.
2704 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002705static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002706 int new_scan, int own_request,
2707 bool trigger_6ghz_scan,
2708 union wpa_event_data *data)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002709{
2710 struct wpa_bss *selected;
2711 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002712 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2713
2714 if (time_to_reenable > 0) {
2715 wpa_dbg(wpa_s, MSG_DEBUG,
2716 "Postpone network selection by %d seconds since all networks are disabled",
2717 time_to_reenable);
2718 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2719 eloop_register_timeout(time_to_reenable, 0,
2720 wpas_network_reenabled, wpa_s, NULL);
2721 return 0;
2722 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002723
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002724 if (wpa_s->p2p_mgmt)
2725 return 0; /* no normal connection on p2p_mgmt interface */
2726
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002727 wpa_s->owe_transition_search = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002728#ifdef CONFIG_OWE
2729 os_free(wpa_s->owe_trans_scan_freq);
2730 wpa_s->owe_trans_scan_freq = NULL;
2731#endif /* CONFIG_OWE */
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002732 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002734#ifdef CONFIG_MESH
2735 if (wpa_s->ifmsh) {
2736 wpa_msg(wpa_s, MSG_INFO,
2737 "Avoiding join because we already joined a mesh group");
2738 return 0;
2739 }
2740#endif /* CONFIG_MESH */
2741
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002742 if (selected) {
2743 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002744 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002745 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002746 if (new_scan)
2747 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002749 }
2750
Hai Shalomc3565922019-10-28 11:58:20 -07002751 wpa_s->suitable_network++;
2752
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002753 if (ssid != wpa_s->current_ssid &&
2754 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2755 wpa_s->own_disconnect_req = 1;
2756 wpa_supplicant_deauthenticate(
2757 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2758 }
2759
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002760 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002761 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002762 return -1;
2763 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002764 wpa_s->supp_pbc_active = false;
2765
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002766 if (new_scan)
2767 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002768 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002769 * Do not allow other virtual radios to trigger operations based
2770 * on these scan results since we do not want them to start
2771 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002772 */
2773 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002774 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002775 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2777 ssid = wpa_supplicant_pick_new_network(wpa_s);
2778 if (ssid) {
2779 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2780 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002781 if (new_scan)
2782 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002783 } else if (own_request) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002784 if (wpa_s->support_6ghz && trigger_6ghz_scan && data &&
Sunil Ravic0f5d412024-09-11 22:12:49 +00002785 wpas_trigger_6ghz_scan(wpa_s, data) > 0)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002786 return 1;
2787
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002788 /*
2789 * No SSID found. If SCAN results are as a result of
2790 * own scan request and not due to a scan request on
2791 * another shared interface, try another scan.
2792 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002793 int timeout_sec = wpa_s->scan_interval;
2794 int timeout_usec = 0;
2795#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002796 int res;
2797
2798 res = wpas_p2p_scan_no_go_seen(wpa_s);
2799 if (res == 2)
2800 return 2;
2801 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002802 return 0;
2803
Sunil Ravi77d572f2023-01-17 23:58:31 +00002804 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002805 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002806
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002807 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002808 wpa_s->show_group_started ||
2809 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002810 /*
2811 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002812 * state and during P2P join-a-group operation
2813 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002814 */
2815 timeout_sec = 0;
2816 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002817 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2818 timeout_usec);
2819 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002820 }
2821#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002822#ifdef CONFIG_INTERWORKING
2823 if (wpa_s->conf->auto_interworking &&
2824 wpa_s->conf->interworking &&
2825 wpa_s->conf->cred) {
2826 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2827 "start ANQP fetch since no matching "
2828 "networks found");
2829 wpa_s->network_select = 1;
2830 wpa_s->auto_network_select = 1;
2831 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002832 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002833 }
2834#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002835#ifdef CONFIG_WPS
2836 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2837 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2838 timeout_sec = 0;
2839 timeout_usec = 500000;
2840 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2841 timeout_usec);
2842 return 0;
2843 }
2844#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002845#ifdef CONFIG_OWE
2846 if (wpa_s->owe_transition_search) {
2847 wpa_dbg(wpa_s, MSG_DEBUG,
2848 "OWE: Use shorter wait during transition mode search");
2849 timeout_sec = 0;
2850 timeout_usec = 500000;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002851 if (wpa_s->owe_trans_scan_freq) {
2852 os_free(wpa_s->next_scan_freqs);
2853 wpa_s->next_scan_freqs =
2854 wpa_s->owe_trans_scan_freq;
2855 wpa_s->owe_trans_scan_freq = NULL;
2856 timeout_usec = 100000;
2857 }
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002858 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2859 timeout_usec);
2860 return 0;
2861 }
2862#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002863 if (wpa_supplicant_req_sched_scan(wpa_s))
2864 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2865 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002866
2867 wpa_msg_ctrl(wpa_s, MSG_INFO,
2868 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002869 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002870 }
2871 }
2872 return 0;
2873}
2874
2875
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002876static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2877 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002879 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002880 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002881
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002882 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002883 if (res == 2) {
2884 /*
2885 * Interface may have been removed, so must not dereference
2886 * wpa_s after this.
2887 */
2888 return 1;
2889 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002890
2891 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002892 /*
2893 * If no scan results could be fetched, then no need to
2894 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002895 * this scan. Similarly, if scan results started a new operation on this
2896 * interface, do not notify other interfaces to avoid concurrent
2897 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002898 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002899 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002900 }
2901
2902 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002903 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904 * so, they get updated with this same scan info.
2905 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002906 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2907 radio_list) {
2908 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002909 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2910 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002911 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2912 res > 0);
2913 if (res < 0)
2914 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002915 }
2916 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002917
2918 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002919}
2920
2921#endif /* CONFIG_NO_SCAN_PROCESSING */
2922
2923
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002924int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2925{
2926#ifdef CONFIG_NO_SCAN_PROCESSING
2927 return -1;
2928#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002929 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002930
Dmitry Shmidt29333592017-01-09 12:27:11 -08002931 wpa_s->ignore_post_flush_scan_res = 0;
2932
Dmitry Shmidt41712582015-06-29 11:02:15 -07002933 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002934 return -1;
2935
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002936 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002937 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002938 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002939 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2940 return -1;
Sunil Ravi7f769292024-07-23 22:21:32 +00002941 } else if (wpa_s->crossed_6ghz_dom) {
2942 wpa_printf(MSG_DEBUG, "Fast associate: Crossed 6 GHz domain");
2943 return -1;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002944 }
2945
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002946 return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002947#endif /* CONFIG_NO_SCAN_PROCESSING */
2948}
2949
Sunil Ravi77d572f2023-01-17 23:58:31 +00002950
2951int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2952{
2953#ifdef CONFIG_NO_SCAN_PROCESSING
2954 return -1;
2955#else /* CONFIG_NO_SCAN_PROCESSING */
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002956 return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002957#endif /* CONFIG_NO_SCAN_PROCESSING */
2958}
2959
2960
Dmitry Shmidt04949592012-07-19 12:16:46 -07002961#ifdef CONFIG_WNM
2962
2963static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2964{
2965 struct wpa_supplicant *wpa_s = eloop_ctx;
2966
2967 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2968 return;
2969
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002970 if (!wpa_s->no_keep_alive) {
2971 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2972 MAC2STR(wpa_s->bssid));
2973 /* TODO: could skip this if normal data traffic has been sent */
2974 /* TODO: Consider using some more appropriate data frame for
2975 * this */
2976 if (wpa_s->l2)
2977 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2978 (u8 *) "", 0);
2979 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002980
2981#ifdef CONFIG_SME
2982 if (wpa_s->sme.bss_max_idle_period) {
2983 unsigned int msec;
2984 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2985 if (msec > 100)
2986 msec -= 100;
2987 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2988 wnm_bss_keep_alive, wpa_s, NULL);
2989 }
2990#endif /* CONFIG_SME */
2991}
2992
2993
2994static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2995 const u8 *ies, size_t ies_len)
2996{
2997 struct ieee802_11_elems elems;
2998
2999 if (ies == NULL)
3000 return;
3001
3002 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
3003 return;
3004
3005#ifdef CONFIG_SME
3006 if (elems.bss_max_idle_period) {
3007 unsigned int msec;
3008 wpa_s->sme.bss_max_idle_period =
3009 WPA_GET_LE16(elems.bss_max_idle_period);
3010 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
3011 "TU)%s", wpa_s->sme.bss_max_idle_period,
3012 (elems.bss_max_idle_period[2] & 0x01) ?
3013 " (protected keep-live required)" : "");
3014 if (wpa_s->sme.bss_max_idle_period == 0)
3015 wpa_s->sme.bss_max_idle_period = 1;
3016 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
3017 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
3018 /* msec times 1000 */
3019 msec = wpa_s->sme.bss_max_idle_period * 1024;
3020 if (msec > 100)
3021 msec -= 100;
3022 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
3023 wnm_bss_keep_alive, wpa_s,
3024 NULL);
3025 }
Sunil Ravi7f769292024-07-23 22:21:32 +00003026 } else {
3027 wpa_s->sme.bss_max_idle_period = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003028 }
3029#endif /* CONFIG_SME */
3030}
3031
3032#endif /* CONFIG_WNM */
3033
3034
3035void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
3036{
3037#ifdef CONFIG_WNM
3038 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
3039#endif /* CONFIG_WNM */
3040}
3041
3042
Dmitry Shmidt051af732013-10-22 13:52:46 -07003043static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
3044 size_t len)
3045{
3046 int res;
3047
3048 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
3049 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
3050 if (res) {
3051 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
3052 }
3053
3054 return res;
3055}
3056
3057
3058static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
3059 const u8 *ies, size_t ies_len)
3060{
3061 struct ieee802_11_elems elems;
3062
3063 if (ies == NULL)
3064 return;
3065
3066 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
3067 return;
3068
3069 if (elems.qos_map_set) {
3070 wpas_qos_map_set(wpa_s, elems.qos_map_set,
3071 elems.qos_map_set_len);
3072 }
3073}
3074
Dmitry Shmidt051af732013-10-22 13:52:46 -07003075
Sunil Ravi036cec52023-03-29 11:35:17 -07003076static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
3077{
3078 if (wpa_s->enabled_4addr_mode) {
3079 wpa_printf(MSG_DEBUG, "4addr mode already set");
3080 return;
3081 }
3082
3083 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
3084 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
3085 goto fail;
3086 }
3087 wpa_s->enabled_4addr_mode = 1;
3088 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
3089 return;
3090
3091fail:
3092 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3093}
3094
3095
Hai Shalom74f70d42019-02-11 14:42:39 -08003096static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
3097 const u8 *ies, size_t ies_len)
3098{
3099 struct ieee802_11_elems elems;
Sunil Ravi99c035e2024-07-12 01:42:03 +00003100 struct multi_ap_params multi_ap;
3101 u16 status;
Hai Shalom74f70d42019-02-11 14:42:39 -08003102
Hai Shalomfdcde762020-04-02 11:19:20 -07003103 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08003104
Hai Shalomfdcde762020-04-02 11:19:20 -07003105 if (!ies ||
3106 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
Sunil Ravi99c035e2024-07-12 01:42:03 +00003107 !elems.multi_ap)
Hai Shalomfdcde762020-04-02 11:19:20 -07003108 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08003109
Sunil Ravi99c035e2024-07-12 01:42:03 +00003110 status = check_multi_ap_ie(elems.multi_ap + 4, elems.multi_ap_len - 4,
3111 &multi_ap);
3112 if (status != WLAN_STATUS_SUCCESS)
Hai Shalomfdcde762020-04-02 11:19:20 -07003113 return;
3114
Sunil Ravi99c035e2024-07-12 01:42:03 +00003115 wpa_s->multi_ap_backhaul = !!(multi_ap.capability &
3116 MULTI_AP_BACKHAUL_BSS);
3117 wpa_s->multi_ap_fronthaul = !!(multi_ap.capability &
Hai Shalomfdcde762020-04-02 11:19:20 -07003118 MULTI_AP_FRONTHAUL_BSS);
3119 wpa_s->multi_ap_ie = 1;
3120}
3121
3122
3123static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
3124{
3125 if (!wpa_s->current_ssid ||
3126 !wpa_s->current_ssid->multi_ap_backhaul_sta)
3127 return;
3128
3129 if (!wpa_s->multi_ap_ie) {
3130 wpa_printf(MSG_INFO,
3131 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08003132 goto fail;
3133 }
3134
Hai Shalomfdcde762020-04-02 11:19:20 -07003135 if (!wpa_s->multi_ap_backhaul) {
3136 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07003137 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
3138 wpa_printf(MSG_INFO,
3139 "WPS active, accepting fronthaul-only BSS");
3140 /* Don't set 4addr mode in this case, so just return */
3141 return;
3142 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003143 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
3144 goto fail;
3145 }
3146
Sunil Ravi036cec52023-03-29 11:35:17 -07003147 wpa_supplicant_set_4addr_mode(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08003148 return;
3149
3150fail:
3151 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3152}
3153
3154
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003155#ifdef CONFIG_FST
3156static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
3157 const u8 *ie, size_t ie_len)
3158{
3159 struct mb_ies_info mb_ies;
3160
3161 if (!ie || !ie_len || !wpa_s->fst)
3162 return -ENOENT;
3163
3164 os_memset(&mb_ies, 0, sizeof(mb_ies));
3165
3166 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
3167 size_t len;
3168
3169 len = 2 + ie[1];
3170 if (len > ie_len) {
3171 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
3172 ie, ie_len);
3173 break;
3174 }
3175
3176 if (ie[0] == WLAN_EID_MULTI_BAND) {
3177 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
3178 (unsigned int) len);
3179 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
3180 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
3181 mb_ies.nof_ies++;
3182 }
3183
3184 ie_len -= len;
3185 ie += len;
3186 }
3187
3188 if (mb_ies.nof_ies > 0) {
3189 wpabuf_free(wpa_s->received_mb_ies);
3190 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
3191 return 0;
3192 }
3193
3194 return -ENOENT;
3195}
3196#endif /* CONFIG_FST */
3197
3198
Hai Shalomc1a21442022-02-04 13:43:00 -08003199static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
3200 union wpa_event_data *data)
3201{
3202 int sel;
3203 const u8 *p;
3204 int l, len;
3205 bool found = false;
3206 struct wpa_ie_data ie;
3207 struct wpa_ssid *ssid = wpa_s->current_ssid;
3208 struct wpa_bss *bss = wpa_s->current_bss;
3209 int pmf;
3210
3211 if (!ssid)
3212 return 0;
3213
3214 p = data->assoc_info.req_ies;
3215 l = data->assoc_info.req_ies_len;
3216
3217 while (p && l >= 2) {
3218 len = p[1] + 2;
3219 if (len > l) {
3220 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3221 p, l);
3222 break;
3223 }
3224 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3225 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3226 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3227 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3228 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3229 found = true;
3230 break;
3231 }
3232 l -= len;
3233 p += len;
3234 }
3235
Sunil Ravi036cec52023-03-29 11:35:17 -07003236 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
3237 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
Hai Shalomc1a21442022-02-04 13:43:00 -08003238 return 0;
Sunil Ravi036cec52023-03-29 11:35:17 -07003239 }
Hai Shalomc1a21442022-02-04 13:43:00 -08003240
3241 wpa_hexdump(MSG_DEBUG,
3242 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
3243 p, l);
3244
3245 /* Update proto from (Re)Association Request frame info */
3246 wpa_s->wpa_proto = ie.proto;
3247 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
3248 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
3249 !!(wpa_s->wpa_proto &
3250 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
3251
3252 /* Update AKMP suite from (Re)Association Request frame info */
3253 sel = ie.key_mgmt;
3254 if (ssid->key_mgmt)
3255 sel &= ssid->key_mgmt;
3256
3257 wpa_dbg(wpa_s, MSG_DEBUG,
3258 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
3259 ie.key_mgmt, ssid->key_mgmt, sel);
3260 if (ie.key_mgmt && !sel) {
3261 wpa_supplicant_deauthenticate(
3262 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
3263 return -1;
3264 }
3265
Sunil Ravi036cec52023-03-29 11:35:17 -07003266#ifdef CONFIG_OCV
3267 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
3268 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
3269 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
3270 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
3271#endif /* CONFIG_OCV */
3272
Sunil Ravi89eba102022-09-13 21:04:37 -07003273 /*
3274 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
3275 * different AKM.
3276 */
3277 if (wpa_s->key_mgmt != ie.key_mgmt &&
3278 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
3279 if (!ssid->psk_set) {
3280 wpa_dbg(wpa_s, MSG_INFO,
3281 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00003282 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07003283 return -1;
3284 }
3285
3286 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
3287 if (wpa_s->conf->key_mgmt_offload &&
3288 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003289 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
3290 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07003291 wpa_dbg(wpa_s, MSG_ERROR,
3292 "WPA: Cannot set PMK for key management offload");
3293 }
3294
Hai Shalomc1a21442022-02-04 13:43:00 -08003295 wpa_s->key_mgmt = ie.key_mgmt;
3296 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3297 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
3298 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
3299 wpa_s->wpa_proto);
3300
3301 /* Update pairwise cipher from (Re)Association Request frame info */
3302 sel = ie.pairwise_cipher;
3303 if (ssid->pairwise_cipher)
3304 sel &= ssid->pairwise_cipher;
3305
3306 wpa_dbg(wpa_s, MSG_DEBUG,
3307 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
3308 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
3309 if (ie.pairwise_cipher && !sel) {
3310 wpa_supplicant_deauthenticate(
3311 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
3312 return -1;
3313 }
3314
3315 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3316 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3317 wpa_s->pairwise_cipher);
3318 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
3319 wpa_cipher_txt(wpa_s->pairwise_cipher));
3320
3321 /* Update other parameters based on AP's WPA IE/RSNE, if available */
3322 if (!bss) {
3323 wpa_dbg(wpa_s, MSG_DEBUG,
3324 "WPA: current_bss == NULL - skip AP IE check");
3325 return 0;
3326 }
3327
3328 /* Update GTK and IGTK from AP's RSNE */
3329 found = false;
3330
3331 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
3332 const u8 *bss_rsn;
3333
Sunil Ravi7f769292024-07-23 22:21:32 +00003334 bss_rsn = wpa_bss_get_rsne(wpa_s, bss, ssid,
3335 wpa_s->valid_links);
Hai Shalomc1a21442022-02-04 13:43:00 -08003336 if (bss_rsn) {
3337 p = bss_rsn;
3338 len = 2 + bss_rsn[1];
3339 found = true;
3340 }
3341 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
3342 const u8 *bss_wpa;
3343
3344 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3345 if (bss_wpa) {
3346 p = bss_wpa;
3347 len = 2 + bss_wpa[1];
3348 found = true;
3349 }
3350 }
3351
3352 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
3353 return 0;
3354
3355 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
3356 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3357 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3358 /* AP does not support MFP, local configuration requires it */
3359 wpa_supplicant_deauthenticate(
3360 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3361 return -1;
3362 }
3363 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3364 pmf == NO_MGMT_FRAME_PROTECTION) {
3365 /* AP requires MFP, local configuration disables it */
3366 wpa_supplicant_deauthenticate(
3367 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3368 return -1;
3369 }
3370
3371 /* Update PMF from local configuration now that MFP validation was done
3372 * above */
3373 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3374
3375 /* Update GTK from AP's RSNE */
3376 sel = ie.group_cipher;
3377 if (ssid->group_cipher)
3378 sel &= ssid->group_cipher;
3379
3380 wpa_dbg(wpa_s, MSG_DEBUG,
3381 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3382 ie.group_cipher, ssid->group_cipher, sel);
3383 if (ie.group_cipher && !sel) {
3384 wpa_supplicant_deauthenticate(
3385 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3386 return -1;
3387 }
3388
3389 wpa_s->group_cipher = ie.group_cipher;
3390 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3391 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3392 wpa_cipher_txt(wpa_s->group_cipher));
3393
3394 /* Update IGTK from AP RSN IE */
3395 sel = ie.mgmt_group_cipher;
3396 if (ssid->group_mgmt_cipher)
3397 sel &= ssid->group_mgmt_cipher;
3398
3399 wpa_dbg(wpa_s, MSG_DEBUG,
3400 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3401 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3402
3403 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3404 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3405 wpa_dbg(wpa_s, MSG_DEBUG,
3406 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3407 ie.capabilities);
3408 ie.mgmt_group_cipher = 0;
3409 }
3410
3411 if (ie.mgmt_group_cipher && !sel) {
3412 wpa_supplicant_deauthenticate(
3413 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3414 return -1;
3415 }
3416
3417 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3418 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3419 wpa_s->mgmt_group_cipher);
3420 if (wpa_s->mgmt_group_cipher)
3421 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3422 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3423 else
3424 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3425
3426 return 0;
3427}
3428
3429
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003430static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3431 union wpa_event_data *data)
3432{
Matthew Wang9ed1c792024-12-02 14:05:18 +00003433 int l, len, found = 0, wpa_found, rsn_found;
3434#ifndef CONFIG_NO_WPA
3435 int found_x = 0;
3436#endif /* CONFIG_NO_WPA */
Sunil Ravic0f5d412024-09-11 22:12:49 +00003437 const u8 *p, *ie;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003438 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003439 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003440#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Sunil Ravic0f5d412024-09-11 22:12:49 +00003441 struct wpa_ie_data wpa_ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003442#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Sunil Ravic0f5d412024-09-11 22:12:49 +00003443 enum wpa_rsn_override rsn_override;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003444
3445 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Sunil Ravi7f769292024-07-23 22:21:32 +00003446 wpa_s->ssid_verified = false;
3447 wpa_s->bigtk_set = false;
3448#ifdef CONFIG_SAE
3449#ifdef CONFIG_SME
3450 /* SAE H2E binds the SSID into PT and that verifies the SSID
3451 * implicitly. */
3452 if (wpa_s->sme.sae.state == SAE_ACCEPTED && wpa_s->sme.sae.h2e)
3453 wpa_s->ssid_verified = true;
3454#endif /* CONFIG_SME */
3455#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -07003456 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003457 if (data->assoc_info.req_ies)
3458 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3459 data->assoc_info.req_ies_len);
3460 if (data->assoc_info.resp_ies) {
3461 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3462 data->assoc_info.resp_ies_len);
3463#ifdef CONFIG_TDLS
3464 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3465 data->assoc_info.resp_ies_len);
3466#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003467#ifdef CONFIG_WNM
3468 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3469 data->assoc_info.resp_ies_len);
3470#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003471 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3472 data->assoc_info.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003473 if (wpa_s->hw_capab == CAPAB_VHT &&
3474 get_ie(data->assoc_info.resp_ies,
3475 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3476 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003477
3478 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3479 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003480 }
3481 if (data->assoc_info.beacon_ies)
3482 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3483 data->assoc_info.beacon_ies,
3484 data->assoc_info.beacon_ies_len);
3485 if (data->assoc_info.freq)
3486 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3487 data->assoc_info.freq);
3488
Hai Shalom021b0b52019-04-10 11:17:58 -07003489 wpa_s->connection_set = 0;
3490 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3491 struct ieee802_11_elems req_elems, resp_elems;
3492
3493 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3494 data->assoc_info.req_ies_len,
3495 &req_elems, 0) != ParseFailed &&
3496 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3497 data->assoc_info.resp_ies_len,
3498 &resp_elems, 0) != ParseFailed) {
3499 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003500 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3501 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003502 wpa_s->connection_ht = req_elems.ht_capabilities &&
3503 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003504 /* Do not include subset of VHT on 2.4 GHz vendor
3505 * extension in consideration for reporting VHT
3506 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003507 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003508 resp_elems.vht_capabilities &&
3509 (!data->assoc_info.freq ||
3510 wpas_freq_to_band(data->assoc_info.freq) !=
3511 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003512 wpa_s->connection_he = req_elems.he_capabilities &&
3513 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003514 wpa_s->connection_eht = req_elems.eht_capabilities &&
3515 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003516
3517 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3518 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3519 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3520 max_nss_rx_req : max_nss_rx_resp;
3521 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3522 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3523 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3524 max_nss_tx_req : max_nss_tx_resp;
3525
3526 struct supported_chan_width sta_supported_chan_width =
3527 get_supported_channel_width(&req_elems);
3528 enum chan_width ap_operation_chan_width =
3529 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303530 if (wpa_s->connection_vht || wpa_s->connection_he ||
3531 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003532 wpa_s->connection_channel_bandwidth =
3533 get_sta_operation_chan_width(ap_operation_chan_width,
3534 sta_supported_chan_width);
3535 } else if (wpa_s->connection_ht) {
3536 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3537 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3538 } else {
3539 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3540 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003541 if (req_elems.rrm_enabled)
3542 wpa_s->rrm.rrm_used = 1;
Ainy Kumari322d4fd2024-02-14 13:05:40 +05303543 wpa_s->ap_t2lm_negotiation_support =
3544 is_ap_t2lm_negotiation_supported(resp_elems.basic_mle,
3545 resp_elems.basic_mle_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07003546 }
3547 }
3548
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003549 p = data->assoc_info.req_ies;
3550 l = data->assoc_info.req_ies_len;
3551
3552 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3553 while (p && l >= 2) {
3554 len = p[1] + 2;
3555 if (len > l) {
3556 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3557 p, l);
3558 break;
3559 }
Hai Shalomc3565922019-10-28 11:58:20 -07003560 if (!found &&
3561 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3562 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3563 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3564 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3565 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003566 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3567 break;
3568 found = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07003569 wpa_find_assoc_pmkid(wpa_s,
3570 data->assoc_info.authorized);
Hai Shalomc3565922019-10-28 11:58:20 -07003571 }
Matthew Wang9ed1c792024-12-02 14:05:18 +00003572#ifndef CONFIG_NO_WPA
Hai Shalomc3565922019-10-28 11:58:20 -07003573 if (!found_x && p[0] == WLAN_EID_RSNX) {
3574 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3575 break;
3576 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003577 }
Matthew Wang9ed1c792024-12-02 14:05:18 +00003578#endif /* CONFIG_NO_WPA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003579 l -= len;
3580 p += len;
3581 }
3582 if (!found && data->assoc_info.req_ies)
3583 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Matthew Wang9ed1c792024-12-02 14:05:18 +00003584#ifndef CONFIG_NO_WPA
Hai Shalomc3565922019-10-28 11:58:20 -07003585 if (!found_x && data->assoc_info.req_ies)
3586 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Matthew Wang9ed1c792024-12-02 14:05:18 +00003587#endif /* CONFIG_NO_WPA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003588
Winnie Chen4138eec2022-11-10 16:32:53 +08003589#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303590 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3591 * to a different security type, update the current supplicant configuration to use the AKM
3592 * and pairwise suites from the assoc IE passed by the driver.
3593 */
3594 if (wpas_driver_bss_selection(wpa_s)) {
Sunil Ravic0f5d412024-09-11 22:12:49 +00003595 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &wpa_ie) < 0)) {
Vinayak Yadawad14709082022-03-17 14:25:11 +05303596 /* Check if firmware has roamed to a different security network */
Sunil Ravic0f5d412024-09-11 22:12:49 +00003597 if(wpa_s->key_mgmt != wpa_ie.key_mgmt) {
Vinayak Yadawad14709082022-03-17 14:25:11 +05303598 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
Sunil Ravic0f5d412024-09-11 22:12:49 +00003599 wpa_ie.key_mgmt);
3600 wpa_s->key_mgmt = wpa_ie.key_mgmt;
Vinayak Yadawad14709082022-03-17 14:25:11 +05303601 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3602
3603 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3604 /* Restore PMK as it can get overwritten if the previous
3605 * association was to 802.1X.
3606 */
3607 if ((!(wpa_s->drv_flags &
3608 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3609 (wpa_s->current_ssid) &&
3610 (wpa_s->current_ssid->psk_set)) {
3611 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3612 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3613 "BSSID");
3614 wpa_supplicant_deauthenticate(
3615 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3616 return -1;
3617 }
3618 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3619 PMK_LEN, NULL, bssid);
3620 }
3621 }
3622 }
Sunil Ravic0f5d412024-09-11 22:12:49 +00003623 if(wpa_s->pairwise_cipher != wpa_ie.pairwise_cipher) {
Vinayak Yadawad14709082022-03-17 14:25:11 +05303624 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
Sunil Ravic0f5d412024-09-11 22:12:49 +00003625 "from Assoc IE", wpa_ie.pairwise_cipher);
3626 wpa_s->pairwise_cipher = wpa_ie.pairwise_cipher;
Vinayak Yadawad14709082022-03-17 14:25:11 +05303627 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3628 wpa_s->pairwise_cipher);
3629 }
3630 // TODO: Notify the framework about security type change b/230766005
3631 }
3632 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003633#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303634
Sunil Ravic0f5d412024-09-11 22:12:49 +00003635 rsn_override = RSN_OVERRIDE_NOT_USED;
3636 ie = get_vendor_ie(data->assoc_info.req_ies,
3637 data->assoc_info.req_ies_len,
3638 RSN_SELECTION_IE_VENDOR_TYPE);
3639 if (ie && ie[1] >= 4 + 1) {
3640 switch (ie[2 + 4]) {
3641 case RSN_SELECTION_RSNE:
3642 rsn_override = RSN_OVERRIDE_RSNE;
3643 break;
3644 case RSN_SELECTION_RSNE_OVERRIDE:
3645 rsn_override = RSN_OVERRIDE_RSNE_OVERRIDE;
3646 break;
3647 case RSN_SELECTION_RSNE_OVERRIDE_2:
3648 rsn_override = RSN_OVERRIDE_RSNE_OVERRIDE_2;
3649 break;
3650 }
3651 }
3652 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_OVERRIDE, rsn_override);
3653
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003654#ifdef CONFIG_FILS
3655#ifdef CONFIG_SME
Sunil Ravi7f769292024-07-23 22:21:32 +00003656 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3657 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) {
3658 if (!data->assoc_info.resp_frame ||
3659 fils_process_assoc_resp(wpa_s->wpa,
3660 data->assoc_info.resp_frame,
3661 data->assoc_info.resp_frame_len) <
3662 0) {
3663 wpa_supplicant_deauthenticate(wpa_s,
3664 WLAN_REASON_UNSPECIFIED);
3665 return -1;
3666 }
3667
3668 /* FILS use of an AEAD cipher include the SSID element in
3669 * (Re)Association Request frame in the AAD and since the AP
3670 * accepted that, the SSID was verified. */
3671 wpa_s->ssid_verified = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003672 }
3673#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003674
3675 /* Additional processing for FILS when SME is in driver */
3676 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3677 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3678 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003679#endif /* CONFIG_FILS */
3680
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003681#ifdef CONFIG_OWE
3682 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003683 !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003684 (!bssid_known ||
Sunil Ravi036cec52023-03-29 11:35:17 -07003685 owe_process_assoc_resp(wpa_s->wpa,
3686 wpa_s->valid_links ?
3687 wpa_s->ap_mld_addr : bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003688 data->assoc_info.resp_ies,
3689 data->assoc_info.resp_ies_len) < 0)) {
3690 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3691 return -1;
3692 }
3693#endif /* CONFIG_OWE */
3694
Hai Shalom021b0b52019-04-10 11:17:58 -07003695#ifdef CONFIG_DPP2
3696 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003697 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3698 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003699 struct ieee802_11_elems elems;
3700
3701 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3702 data->assoc_info.resp_ies_len,
3703 &elems, 0) == ParseFailed ||
3704 !elems.owe_dh)
3705 goto no_pfs;
3706 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3707 elems.owe_dh_len) < 0) {
3708 wpa_supplicant_deauthenticate(wpa_s,
3709 WLAN_REASON_UNSPECIFIED);
3710 return -1;
3711 }
3712
3713 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3714 }
3715no_pfs:
3716#endif /* CONFIG_DPP2 */
3717
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003718#ifdef CONFIG_IEEE80211R
3719#ifdef CONFIG_SME
3720 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003721 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003722 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3723 data->assoc_info.resp_ies,
3724 data->assoc_info.resp_ies_len,
3725 bssid) < 0) {
3726 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3727 "Reassociation Response failed");
3728 wpa_supplicant_deauthenticate(
3729 wpa_s, WLAN_REASON_INVALID_IE);
3730 return -1;
3731 }
Sunil Ravi7f769292024-07-23 22:21:32 +00003732 /* SSID is included in PMK-R0 derivation, so it is verified
3733 * implicitly. */
3734 wpa_s->ssid_verified = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003735 }
3736
3737 p = data->assoc_info.resp_ies;
3738 l = data->assoc_info.resp_ies_len;
3739
3740#ifdef CONFIG_WPS_STRICT
3741 if (p && wpa_s->current_ssid &&
3742 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3743 struct wpabuf *wps;
3744 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3745 if (wps == NULL) {
3746 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3747 "include WPS IE in (Re)Association Response");
3748 return -1;
3749 }
3750
3751 if (wps_validate_assoc_resp(wps) < 0) {
3752 wpabuf_free(wps);
3753 wpa_supplicant_deauthenticate(
3754 wpa_s, WLAN_REASON_INVALID_IE);
3755 return -1;
3756 }
3757 wpabuf_free(wps);
3758 }
3759#endif /* CONFIG_WPS_STRICT */
3760
3761 /* Go through the IEs and make a copy of the MDIE, if present. */
3762 while (p && l >= 2) {
3763 len = p[1] + 2;
3764 if (len > l) {
3765 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3766 p, l);
3767 break;
3768 }
3769 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3770 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3771 wpa_s->sme.ft_used = 1;
3772 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3773 MOBILITY_DOMAIN_ID_LEN);
3774 break;
3775 }
3776 l -= len;
3777 p += len;
3778 }
3779#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003780#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303781 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3782 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3783 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
Vinayak Yadawadf473bef2024-04-04 15:33:29 +05303784 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) ||
3785 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303786 wpa_ft_is_completed(wpa_s->wpa)) {
3787 return 0;
3788 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003789#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003790
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003791 /* Process FT when SME is in the driver */
3792 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3793 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003794 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003795 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3796 data->assoc_info.resp_ies,
3797 data->assoc_info.resp_ies_len,
3798 bssid) < 0) {
3799 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3800 "Reassociation Response failed");
3801 wpa_supplicant_deauthenticate(
3802 wpa_s, WLAN_REASON_INVALID_IE);
3803 return -1;
3804 }
3805 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
Sunil Ravi7f769292024-07-23 22:21:32 +00003806 /* SSID is included in PMK-R0 derivation, so it is verified
3807 * implicitly. */
3808 wpa_s->ssid_verified = true;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003809 }
3810
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003811 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3812 data->assoc_info.resp_ies_len);
3813#endif /* CONFIG_IEEE80211R */
3814
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003815#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07003816 if (bssid_known)
3817 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3818 data->assoc_info.resp_ies,
3819 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003820#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -07003821
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003822 /* WPA/RSN IE from Beacon/ProbeResp */
3823 p = data->assoc_info.beacon_ies;
3824 l = data->assoc_info.beacon_ies_len;
3825
3826 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3827 */
3828 wpa_found = rsn_found = 0;
3829 while (p && l >= 2) {
3830 len = p[1] + 2;
3831 if (len > l) {
3832 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3833 p, l);
3834 break;
3835 }
3836 if (!wpa_found &&
3837 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3838 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3839 wpa_found = 1;
3840 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3841 }
3842
3843 if (!rsn_found &&
3844 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3845 rsn_found = 1;
3846 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3847 }
3848
Sunil Ravic0f5d412024-09-11 22:12:49 +00003849 if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3850 WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_2_IE_VENDOR_TYPE)
3851 wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, p, len);
Sunil Ravi7f769292024-07-23 22:21:32 +00003852
Sunil Ravic0f5d412024-09-11 22:12:49 +00003853 if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3854 WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_IE_VENDOR_TYPE)
3855 wpa_sm_set_ap_rsne_override(wpa_s->wpa, p, len);
Sunil Ravi7f769292024-07-23 22:21:32 +00003856
Hai Shalomc3565922019-10-28 11:58:20 -07003857 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3858 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3859
Sunil Ravic0f5d412024-09-11 22:12:49 +00003860 if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
Sunil Ravi7f769292024-07-23 22:21:32 +00003861 WPA_GET_BE32(&p[2]) == RSNXE_OVERRIDE_IE_VENDOR_TYPE)
Sunil Ravic0f5d412024-09-11 22:12:49 +00003862 wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, p, len);
Sunil Ravi7f769292024-07-23 22:21:32 +00003863
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003864 l -= len;
3865 p += len;
3866 }
3867
3868 if (!wpa_found && data->assoc_info.beacon_ies)
3869 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003870 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003871 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003872 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
Sunil Ravic0f5d412024-09-11 22:12:49 +00003873 wpa_sm_set_ap_rsne_override(wpa_s->wpa, NULL, 0);
3874 wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, NULL, 0);
3875 wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003876 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003877 if (wpa_found || rsn_found)
3878 wpa_s->ap_ies_from_associnfo = 1;
3879
Sunil Ravi99c035e2024-07-12 01:42:03 +00003880 if (wpa_s->assoc_freq && data->assoc_info.freq) {
3881 struct wpa_bss *bss;
3882 unsigned int freq = 0;
3883
3884 if (bssid_known) {
3885 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
3886 if (bss)
3887 freq = bss->freq;
3888 }
3889 if (freq != data->assoc_info.freq) {
3890 wpa_printf(MSG_DEBUG,
3891 "Operating frequency changed from %u to %u MHz",
3892 wpa_s->assoc_freq, data->assoc_info.freq);
3893 wpa_supplicant_update_scan_results(wpa_s, bssid);
3894 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03003895 }
3896
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003897 wpa_s->assoc_freq = data->assoc_info.freq;
3898
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003899#ifndef CONFIG_NO_ROBUST_AV
Hai Shalomc1a21442022-02-04 13:43:00 -08003900 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3901 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003902#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08003903
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003904 return 0;
3905}
3906
3907
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003908static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3909{
Hai Shalomc3565922019-10-28 11:58:20 -07003910 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Sunil Ravic0f5d412024-09-11 22:12:49 +00003911 const u8 *rsnoe, *rsno2e, *rsnxoe;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003912
3913 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3914 return -1;
3915
3916 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3917 return 0;
3918
3919 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3920 WPA_IE_VENDOR_TYPE);
Sunil Ravic0f5d412024-09-11 22:12:49 +00003921 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
3922 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
3923 rsnoe = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3924 RSNE_OVERRIDE_IE_VENDOR_TYPE);
3925 rsno2e = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3926 RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
3927 rsnxoe = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3928 RSNXE_OVERRIDE_IE_VENDOR_TYPE);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003929
3930 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3931 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3932 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003933 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3934 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
Sunil Ravic0f5d412024-09-11 22:12:49 +00003935 bss_rsnx ? 2 + bss_rsnx[1] : 0) ||
3936 wpa_sm_set_ap_rsne_override(wpa_s->wpa, rsnoe,
3937 rsnoe ? 2 + rsnoe[1] : 0) ||
3938 wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, rsno2e,
3939 rsno2e ? 2 + rsno2e[1] : 0) ||
3940 wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, rsnxoe,
3941 rsnxoe ? 2 + rsnxoe[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003942 return -1;
3943
3944 return 0;
3945}
3946
3947
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003948static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3949 union wpa_event_data *data)
3950{
3951#ifdef CONFIG_FST
3952 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3953 struct wpa_bss *bss = wpa_s->current_bss;
3954 const u8 *ieprb, *iebcn;
3955
3956 wpabuf_free(wpa_s->received_mb_ies);
3957 wpa_s->received_mb_ies = NULL;
3958
3959 if (ai &&
3960 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3961 wpa_printf(MSG_DEBUG,
3962 "FST: MB IEs updated from Association Response frame");
3963 return;
3964 }
3965
3966 if (ai &&
3967 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3968 wpa_printf(MSG_DEBUG,
3969 "FST: MB IEs updated from association event Beacon IEs");
3970 return;
3971 }
3972
3973 if (!bss)
3974 return;
3975
Hai Shalom60840252021-02-19 19:02:11 -08003976 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003977 iebcn = ieprb + bss->ie_len;
3978
3979 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3980 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3981 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3982 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3983#endif /* CONFIG_FST */
3984}
3985
3986
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003987static unsigned int wpas_ml_parse_assoc(struct wpa_supplicant *wpa_s,
3988 struct ieee802_11_elems *elems,
3989 struct ml_sta_link_info *ml_info)
3990{
3991 struct wpabuf *mlbuf;
3992 struct ieee80211_eht_ml *ml;
3993 size_t ml_len;
3994 struct eht_ml_basic_common_info *common_info;
3995 const u8 *pos;
3996 u16 eml_capa = 0, mld_capa = 0;
3997 const u16 control =
3998 host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC |
3999 BASIC_MULTI_LINK_CTRL_PRES_LINK_ID |
4000 BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT);
4001 u8 expected_common_info_len = 9;
4002 unsigned int i = 0;
4003 u16 ml_control;
4004
4005 if (!wpa_s->valid_links || !elems->basic_mle || !elems->basic_mle_len)
4006 return 0;
4007
4008 mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
4009 if (!mlbuf)
4010 return 0;
4011
4012 ml = (struct ieee80211_eht_ml *) wpabuf_head(mlbuf);
4013 ml_len = wpabuf_len(mlbuf);
4014 if (ml_len < sizeof(*ml))
4015 goto out;
4016
4017 os_memset(ml_info, 0, sizeof(*ml_info) * MAX_NUM_MLD_LINKS);
4018
4019 ml_control = le_to_host16(ml->ml_control);
4020
4021 if ((ml_control & control) != control) {
4022 wpa_printf(MSG_DEBUG, "MLD: Invalid presence BM=0x%x",
4023 ml_control);
4024 goto out;
4025 }
4026
4027 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
4028 wpa_printf(MSG_DEBUG, "MLD: EML capabilities included");
4029 expected_common_info_len += 2;
4030 }
4031
4032 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
4033 wpa_printf(MSG_DEBUG, "MLD: MLD capabilities included");
4034 expected_common_info_len += 2;
4035 }
4036
4037 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
4038 wpa_printf(MSG_DEBUG,
4039 "MLD: Unexpected: medium sync delay info present");
4040 expected_common_info_len += 2;
4041 }
4042
4043 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
4044 wpa_printf(MSG_DEBUG,
4045 "MLD: Unexpected: MLD ID present");
4046 expected_common_info_len++;
4047 }
4048
4049 if (sizeof(*ml) + expected_common_info_len > ml_len) {
4050 wpa_printf(MSG_DEBUG,
4051 "MLD: Not enough bytes for common info. ml_len=%zu",
4052 ml_len);
4053 goto out;
4054 }
4055
4056 common_info = (struct eht_ml_basic_common_info *) ml->variable;
4057 if (common_info->len != expected_common_info_len) {
4058 wpa_printf(MSG_DEBUG,
4059 "MLD: Invalid common info len=%u. expected=%u",
4060 common_info->len, expected_common_info_len);
4061 goto out;
4062 }
4063
4064 wpa_printf(MSG_DEBUG, "MLD: address: " MACSTR,
4065 MAC2STR(common_info->mld_addr));
4066
4067 if (!ether_addr_equal(wpa_s->ap_mld_addr, common_info->mld_addr)) {
4068 wpa_printf(MSG_DEBUG, "MLD: Mismatching MLD address (expected "
4069 MACSTR ")", MAC2STR(wpa_s->ap_mld_addr));
4070 goto out;
4071 }
4072
4073 pos = common_info->variable;
4074
4075 /* Store the information for the association link */
4076 ml_info[i].link_id = *pos;
4077 pos++;
4078
4079 /* Skip the BSS Parameters Change Count */
4080 pos++;
4081
4082 /* Skip the Medium Synchronization Delay Information if present */
4083 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO)
4084 pos += 2;
4085
4086 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
4087 eml_capa = WPA_GET_LE16(pos);
4088 pos += 2;
4089 }
4090
4091 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
4092 mld_capa = WPA_GET_LE16(pos);
4093 pos += 2;
4094 }
4095
4096 wpa_printf(MSG_DEBUG,
4097 "MLD: link_id=%u, eml=0x%x, mld=0x%x",
4098 ml_info[i].link_id, eml_capa, mld_capa);
4099
4100 i++;
4101
4102 pos = ((u8 *) common_info) + common_info->len;
4103 ml_len -= sizeof(*ml) + common_info->len;
4104 while (ml_len > 2 && i < MAX_NUM_MLD_LINKS) {
4105 u8 sub_elem_len = pos[1];
4106 u8 sta_info_len;
4107 u8 nstr_bitmap_len = 0;
4108 u16 ctrl;
4109 const u8 *end;
4110
4111 wpa_printf(MSG_DEBUG, "MLD: Subelement len=%u", sub_elem_len);
4112
4113 if (sub_elem_len > ml_len - 2) {
4114 wpa_printf(MSG_DEBUG,
4115 "MLD: Invalid link info len: %u > %zu",
4116 2 + sub_elem_len, ml_len);
4117 goto out;
4118 }
4119
4120 switch (*pos) {
4121 case EHT_ML_SUB_ELEM_PER_STA_PROFILE:
4122 break;
4123 case EHT_ML_SUB_ELEM_FRAGMENT:
4124 case EHT_ML_SUB_ELEM_VENDOR:
4125 wpa_printf(MSG_DEBUG,
4126 "MLD: Skip subelement id=%u, len=%u",
4127 *pos, sub_elem_len);
4128 pos += 2 + sub_elem_len;
4129 ml_len -= 2 + sub_elem_len;
4130 continue;
4131 default:
4132 wpa_printf(MSG_DEBUG, "MLD: Unknown subelement ID=%u",
4133 *pos);
4134 goto out;
4135 }
4136
4137 end = pos + 2 + sub_elem_len;
4138
4139 /* Skip the subelement ID and the length */
4140 pos += 2;
4141 ml_len -= 2;
4142
4143 if (end - pos < 2)
4144 goto out;
4145
4146 /* Get the station control field */
4147 ctrl = WPA_GET_LE16(pos);
4148
4149 pos += 2;
4150 ml_len -= 2;
4151
4152 if (!(ctrl & EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK)) {
4153 wpa_printf(MSG_DEBUG,
4154 "MLD: Per STA complete profile expected");
4155 goto out;
4156 }
4157
4158 if (!(ctrl & EHT_PER_STA_CTRL_MAC_ADDR_PRESENT_MSK)) {
4159 wpa_printf(MSG_DEBUG,
4160 "MLD: Per STA MAC address not present");
4161 goto out;
4162 }
4163
4164 if (!(ctrl & EHT_PER_STA_CTRL_TSF_OFFSET_PRESENT_MSK)) {
4165 wpa_printf(MSG_DEBUG,
4166 "MLD: Per STA TSF offset not present");
4167 goto out;
4168 }
4169
4170 if (!(ctrl & EHT_PER_STA_CTRL_BEACON_INTERVAL_PRESENT_MSK)) {
4171 wpa_printf(MSG_DEBUG,
4172 "MLD: Beacon interval not present");
4173 goto out;
4174 }
4175
4176 if (!(ctrl & EHT_PER_STA_CTRL_DTIM_INFO_PRESENT_MSK)) {
4177 wpa_printf(MSG_DEBUG,
4178 "MLD: DTIM information not present");
4179 goto out;
4180 }
4181
4182 if (ctrl & EHT_PER_STA_CTRL_NSTR_LINK_PAIR_PRESENT_MSK) {
4183 if (ctrl & EHT_PER_STA_CTRL_NSTR_BM_SIZE_MSK)
4184 nstr_bitmap_len = 2;
4185 else
4186 nstr_bitmap_len = 1;
4187 }
4188
4189 if (!(ctrl & EHT_PER_STA_CTRL_BSS_PARAM_CNT_PRESENT_MSK)) {
4190 wpa_printf(MSG_DEBUG,
4191 "MLD: BSS params change count not present");
4192 goto out;
4193 }
4194
4195 sta_info_len = 1 + ETH_ALEN + 8 + 2 + 2 + 1 + nstr_bitmap_len;
4196 if (sta_info_len > ml_len || sta_info_len > end - pos ||
4197 sta_info_len + 2 > sub_elem_len ||
4198 sta_info_len != *pos) {
4199 wpa_printf(MSG_DEBUG,
4200 "MLD: Invalid STA info len=%u, len=%u",
4201 sta_info_len, *pos);
4202 goto out;
4203 }
4204
4205 /* Get the link address */
4206 wpa_printf(MSG_DEBUG,
4207 "MLD: link addr: " MACSTR " nstr BM len=%u",
4208 MAC2STR(pos + 1), nstr_bitmap_len);
4209
4210 ml_info[i].link_id = ctrl & EHT_PER_STA_CTRL_LINK_ID_MSK;
4211 os_memcpy(ml_info[i].bssid, pos + 1, ETH_ALEN);
4212
4213 pos += sta_info_len;
4214 ml_len -= sta_info_len;
4215
4216 wpa_printf(MSG_DEBUG, "MLD: sub_elem_len=%u, sta_info_len=%u",
4217 sub_elem_len, sta_info_len);
4218
4219 sub_elem_len -= sta_info_len + 2;
4220 if (sub_elem_len < 4) {
4221 wpa_printf(MSG_DEBUG, "MLD: Per STA profile too short");
4222 goto out;
4223 }
4224
4225 wpa_hexdump(MSG_MSGDUMP, "MLD: STA profile", pos, sub_elem_len);
4226 ml_info[i].status = WPA_GET_LE16(pos + 2);
4227
4228 pos += sub_elem_len;
4229 ml_len -= sub_elem_len;
4230
4231 i++;
4232 }
4233
4234 wpabuf_free(mlbuf);
4235 return i;
4236out:
4237 wpabuf_free(mlbuf);
4238 return 0;
4239}
4240
4241
Sunil Ravi89eba102022-09-13 21:04:37 -07004242static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
4243{
4244 struct driver_sta_mlo_info mlo;
4245 int i;
4246
Sunil Ravi77d572f2023-01-17 23:58:31 +00004247 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07004248 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
4249 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
4250 wpa_supplicant_deauthenticate(wpa_s,
4251 WLAN_REASON_DEAUTH_LEAVING);
4252 return -1;
4253 }
4254
4255 if (wpa_s->valid_links == mlo.valid_links) {
4256 bool match = true;
4257
4258 if (!mlo.valid_links)
4259 return 0;
4260
Sunil Ravi99c035e2024-07-12 01:42:03 +00004261 for_each_link(mlo.valid_links, i) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004262 if (!ether_addr_equal(wpa_s->links[i].addr,
4263 mlo.links[i].addr) ||
4264 !ether_addr_equal(wpa_s->links[i].bssid,
4265 mlo.links[i].bssid)) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004266 match = false;
4267 break;
4268 }
4269 }
4270
Sunil Ravi77d572f2023-01-17 23:58:31 +00004271 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004272 ether_addr_equal(wpa_s->ap_mld_addr, mlo.ap_mld_addr))
Sunil Ravi89eba102022-09-13 21:04:37 -07004273 return 0;
4274 }
4275
4276 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004277 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07004278 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
Sunil Ravi99c035e2024-07-12 01:42:03 +00004279 for_each_link(wpa_s->valid_links, i) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004280 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
4281 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
4282 wpa_s->links[i].freq = mlo.links[i].freq;
4283 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
4284 }
4285
4286 return 0;
4287}
4288
4289
Sunil Ravi77d572f2023-01-17 23:58:31 +00004290static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
4291{
4292 struct driver_sta_mlo_info drv_mlo;
4293 struct wpa_sm_mlo wpa_mlo;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004294 int i;
4295
4296 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
4297 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
4298 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
4299 return -1;
4300 }
4301
4302 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
4303 if (!drv_mlo.valid_links)
4304 goto out;
4305
4306 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
4307 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
4308 wpa_mlo.valid_links = drv_mlo.valid_links;
4309 wpa_mlo.req_links = drv_mlo.req_links;
4310
Sunil Ravi99c035e2024-07-12 01:42:03 +00004311 for_each_link(drv_mlo.req_links, i) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004312 struct wpa_bss *bss;
Sunil Ravic0f5d412024-09-11 22:12:49 +00004313 const u8 *rsne, *rsnxe, *rsnoe, *rsno2e, *rsnxoe;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004314
Sunil Ravi77d572f2023-01-17 23:58:31 +00004315 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
4316 if (!bss) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004317 wpa_dbg(wpa_s, MSG_INFO,
4318 "Failed to get MLO link %d BSS", i);
4319 return -1;
4320 }
4321
Sunil Ravic0f5d412024-09-11 22:12:49 +00004322 rsne = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4323 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
4324 rsnoe = wpa_bss_get_vendor_ie(bss,
4325 RSNE_OVERRIDE_IE_VENDOR_TYPE);
4326 rsno2e = wpa_bss_get_vendor_ie(bss,
4327 RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
4328 rsnxoe = wpa_bss_get_vendor_ie(bss,
4329 RSNXE_OVERRIDE_IE_VENDOR_TYPE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004330
Sunil Ravic0f5d412024-09-11 22:12:49 +00004331 wpa_mlo.links[i].ap_rsne = rsne ? (u8 *) rsne : NULL;
4332 wpa_mlo.links[i].ap_rsne_len = rsne ? 2 + rsne[1] : 0;
4333 wpa_mlo.links[i].ap_rsnxe = rsnxe ? (u8 *) rsnxe : NULL;
4334 wpa_mlo.links[i].ap_rsnxe_len = rsnxe ? 2 + rsnxe[1] : 0;
4335 wpa_mlo.links[i].ap_rsnoe = rsnoe ? (u8 *) rsnoe : NULL;
4336 wpa_mlo.links[i].ap_rsnoe_len = rsnoe ? 2 + rsnoe[1] : 0;
4337 wpa_mlo.links[i].ap_rsno2e = rsno2e ? (u8 *) rsno2e : NULL;
4338 wpa_mlo.links[i].ap_rsno2e_len = rsno2e ? 2 + rsno2e[1] : 0;
4339 wpa_mlo.links[i].ap_rsnxoe = rsnxoe ? (u8 *) rsnxoe : NULL;
4340 wpa_mlo.links[i].ap_rsnxoe_len = rsnxoe ? 2 + rsnxoe[1] : 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004341
4342 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
4343 ETH_ALEN);
4344 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
4345 ETH_ALEN);
4346 }
4347
4348out:
4349 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
4350}
4351
4352
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004353static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
4354 union wpa_event_data *data)
4355{
4356 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004357 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004358 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07004359#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4360 struct wpa_bss *bss;
4361#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08004362#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304363 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08004364#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004365
4366#ifdef CONFIG_AP
4367 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004368 if (!data)
4369 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004370 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
4371 data->assoc_info.addr,
4372 data->assoc_info.req_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004373 data->assoc_info.req_ies_len, NULL, 0,
4374 NULL, data->assoc_info.reassoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004375 return;
4376 }
4377#endif /* CONFIG_AP */
4378
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004379 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07004380 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004381
Andy Kuoaba17c12022-04-14 16:05:31 +08004382#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304383 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
4384 struct wpa_ft_ies parse;
4385 /* Check for FT reassociation is done by the driver */
4386#ifdef CONFIG_IEEE80211R
4387 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05304388 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05304389 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004390 data->assoc_info.resp_ies_len, &parse, use_sha384, false) < 0) {
Mir Ali677e7482020-11-12 19:49:02 +05304391 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
4392 return;
4393 }
4394 if (parse.rsn_pmkid != NULL) {
4395 wpa_set_ft_completed(wpa_s->wpa);
4396 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
4397 }
4398 }
4399#endif /* CONFIG_IEEE80211R */
4400 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004401#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05304402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004403 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07004404
4405 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4406 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
4407 wpa_supplicant_deauthenticate(
4408 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4409 return;
4410 }
4411
Sunil Ravi89eba102022-09-13 21:04:37 -07004412 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
4413 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
4414 wpa_supplicant_deauthenticate(wpa_s,
4415 WLAN_REASON_DEAUTH_LEAVING);
4416 return;
4417 }
4418
Sunil Ravia04bd252022-05-02 22:54:18 -07004419 if (ft_completed &&
4420 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
4421 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
4422 MAC2STR(bssid));
4423 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
4424 wpa_printf(MSG_ERROR,
4425 "Can't find target AP's information!");
4426 return;
4427 }
4428 wpa_supplicant_assoc_update_ie(wpa_s);
4429 }
4430
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004431 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
4432 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004433 /*
4434 * FILS authentication can share the same mechanism to mark the
4435 * connection fully authenticated, so set ft_completed also based on
4436 * FILS result.
4437 */
4438 if (!ft_completed)
4439 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004440
Andy Kuoaba17c12022-04-14 16:05:31 +08004441#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304442 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
4443 /*
4444 * For driver based roaming, insert PSK during
4445 * the initial association
4446 */
4447 if (is_zero_ether_addr(wpa_s->bssid) &&
4448 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
4449 /*
4450 * In case the driver wants to handle re-assocs,
4451 * pass it down the PMK.
4452 */
4453 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
4454 wpa_sm_install_pmk(wpa_s->wpa);
4455 }
Mir Ali677e7482020-11-12 19:49:02 +05304456 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304457#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08004458
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004459 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004460 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004461 if (os_reltime_initialized(&wpa_s->session_start)) {
4462 os_reltime_age(&wpa_s->session_start,
4463 &wpa_s->session_length);
4464 wpa_s->session_start.sec = 0;
4465 wpa_s->session_start.usec = 0;
4466 wpas_notify_session_length(wpa_s);
4467 } else {
4468 wpas_notify_auth_changed(wpa_s);
4469 os_get_reltime(&wpa_s->session_start);
4470 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004471 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
4472 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004473 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004474 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004475 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4476 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004477 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004478
4479 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
4480 wpa_clear_keys(wpa_s, bssid);
4481 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00004482 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004483 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004484 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4485 return;
4486 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004487 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004488
Hai Shalomc1a21442022-02-04 13:43:00 -08004489 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4490 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
4491 return;
4492
Hai Shalomfdcde762020-04-02 11:19:20 -07004493 multi_ap_set_4addr_mode(wpa_s);
4494
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004495 if (wpa_s->conf->ap_scan == 1 &&
4496 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004497 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
4498 wpa_msg(wpa_s, MSG_WARNING,
4499 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004500 }
4501
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004502 wpas_fst_update_mb_assoc(wpa_s, data);
4503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004504#ifdef CONFIG_SME
Sunil Ravi640215c2023-06-28 23:08:09 +00004505 /*
4506 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
4507 * (for MLO connection) as the previous BSSID for subsequent
4508 * reassociation requests handled by SME-in-wpa_supplicant.
4509 */
4510 os_memcpy(wpa_s->sme.prev_bssid,
4511 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004512 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07004513 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004514#endif /* CONFIG_SME */
4515
4516 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
4517 if (wpa_s->current_ssid) {
4518 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
4519 * initialized before association, but for other modes,
4520 * initialize PC/SC here, if the current configuration needs
4521 * smartcard or SIM/USIM. */
4522 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
4523 }
4524 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004525
4526 if (wpa_sm_set_ml_info(wpa_s)) {
4527 wpa_dbg(wpa_s, MSG_INFO,
4528 "Failed to set MLO connection info to wpa_sm");
4529 wpa_supplicant_deauthenticate(wpa_s,
4530 WLAN_REASON_DEAUTH_LEAVING);
4531 return;
4532 }
4533
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004534 if (wpa_s->l2)
4535 l2_packet_notify_auth_start(wpa_s->l2);
4536
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004537 already_authorized = data && data->assoc_info.authorized;
4538
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004539 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07004540 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004541 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
4542 * state machine may transit to AUTHENTICATING state based on obsolete
4543 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
4544 * AUTHENTICATED without ever giving chance to EAP state machine to
4545 * reset the state.
4546 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004547 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07004548 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4549 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004550 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004551 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4552 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
4553 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07004554 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07004555 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004556 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07004557 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004558 wpa_s->eapol_received = 0;
4559 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4560 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4561 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004562 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004563 if (wpa_s->current_ssid &&
4564 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004565 (wpa_s->drv_flags &
4566 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4567 /*
4568 * Set the key after having received joined-IBSS event
4569 * from the driver.
4570 */
4571 wpa_supplicant_set_wpa_none_key(wpa_s,
4572 wpa_s->current_ssid);
4573 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004574 wpa_supplicant_cancel_auth_timeout(wpa_s);
4575 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4576 } else if (!ft_completed) {
4577 /* Timeout for receiving the first EAPOL packet */
4578 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
4579 }
4580 wpa_supplicant_cancel_scan(wpa_s);
4581
Hai Shalom5f92bc92019-04-18 11:54:11 -07004582 if (ft_completed) {
4583 /*
4584 * FT protocol completed - make sure EAPOL state machine ends
4585 * up in authenticated.
4586 */
4587 wpa_supplicant_cancel_auth_timeout(wpa_s);
4588 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004589 eapol_sm_notify_portValid(wpa_s->eapol, true);
4590 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07004591 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4592 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304593 if (already_authorized) {
4594 /*
4595 * We are done; the driver will take care of RSN 4-way
4596 * handshake.
4597 */
4598 wpa_supplicant_cancel_auth_timeout(wpa_s);
4599 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4600 eapol_sm_notify_portValid(wpa_s->eapol, true);
4601 eapol_sm_notify_eap_success(wpa_s->eapol, true);
4602 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004603 /* Update port, WPA_COMPLETED state from the
4604 * EVENT_PORT_AUTHORIZED handler when the driver is done
4605 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304606 */
Sunil Ravi167279a2023-05-31 01:12:34 +00004607 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004608 wpa_msg(wpa_s, MSG_INFO,
4609 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304610 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004611 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004612 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4613 /*
4614 * The driver will take care of RSN 4-way handshake, so we need
4615 * to allow EAPOL supplicant to complete its work without
4616 * waiting for WPA supplicant.
4617 */
Hai Shalome21d4e82020-04-29 16:34:06 -07004618 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004619 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004620#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05304621 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
4622 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4623 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
4624 wpa_s->key_mgmt);
4625 wpa_supplicant_deauthenticate(
4626 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4627 return;
4628 }
4629 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4630 wpa_s->assoc_freq = data->assoc_info.freq;
4631 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
4632 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004633#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
4634
Jouni Malinena05074c2012-12-21 21:35:35 +02004635 wpa_s->last_eapol_matches_bssid = 0;
4636
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004637#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07004638 if (wpa_s->rsne_override_eapol) {
4639 wpa_printf(MSG_DEBUG,
4640 "TESTING: RSNE EAPOL-Key msg 2/4 override");
4641 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4642 wpabuf_head(wpa_s->rsne_override_eapol),
4643 wpabuf_len(wpa_s->rsne_override_eapol));
4644 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004645 if (wpa_s->rsnxe_override_eapol) {
4646 wpa_printf(MSG_DEBUG,
4647 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4648 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4649 wpabuf_head(wpa_s->rsnxe_override_eapol),
4650 wpabuf_len(wpa_s->rsnxe_override_eapol));
4651 }
4652#endif /* CONFIG_TESTING_OPTIONS */
4653
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004654 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004655 struct os_reltime now, age;
4656 os_get_reltime(&now);
4657 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08004658 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004659 ether_addr_equal(wpa_s->pending_eapol_rx_src,
4660 wpa_s->valid_links ? wpa_s->ap_mld_addr :
4661 bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004662 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4663 "frame that was received just before "
4664 "association notification");
4665 wpa_supplicant_rx_eapol(
4666 wpa_s, wpa_s->pending_eapol_rx_src,
4667 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00004668 wpabuf_len(wpa_s->pending_eapol_rx),
4669 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004670 }
4671 wpabuf_free(wpa_s->pending_eapol_rx);
4672 wpa_s->pending_eapol_rx = NULL;
4673 }
4674
Hai Shalomfdcde762020-04-02 11:19:20 -07004675#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004676 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4677 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004678 wpa_s->current_ssid &&
4679 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004680 /* Set static WEP keys again */
4681 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4682 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004683#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004684
4685#ifdef CONFIG_IBSS_RSN
4686 if (wpa_s->current_ssid &&
4687 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4688 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4689 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4690 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004691 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004692 if (!wpa_s->ibss_rsn) {
4693 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4694 wpa_supplicant_deauthenticate(
4695 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4696 return;
4697 }
4698
4699 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4700 }
4701#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004702
4703 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004704
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004705#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004706 if (data) {
4707 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4708 data->assoc_info.resp_ies_len,
4709 &data->assoc_info.wmm_params);
4710
4711 if (wpa_s->reassoc_same_bss)
4712 wmm_ac_restore_tspecs(wpa_s);
4713 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004714#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004715
Hai Shalomc3565922019-10-28 11:58:20 -07004716#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4717 bss = wpa_bss_get_bssid(wpa_s, bssid);
4718#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004719#ifdef CONFIG_FILS
4720 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004721 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4722
4723 if (fils_cache_id)
4724 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4725 }
4726#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004727
4728#ifdef CONFIG_MBO
4729 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4730#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004731
4732#ifdef CONFIG_DPP2
4733 wpa_s->dpp_pfs_fallback = 0;
4734#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004735
4736 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4737 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004738}
4739
4740
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004741static int disconnect_reason_recoverable(u16 reason_code)
4742{
4743 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4744 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4745 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4746}
4747
4748
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004749static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004750 u16 reason_code,
4751 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004752{
4753 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004754
4755 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4756 /*
4757 * At least Host AP driver and a Prism3 card seemed to be
4758 * generating streams of disconnected events when configuring
4759 * IBSS for WPA-None. Ignore them for now.
4760 */
4761 return;
4762 }
4763
4764 bssid = wpa_s->bssid;
4765 if (is_zero_ether_addr(bssid))
4766 bssid = wpa_s->pending_bssid;
4767
4768 if (!is_zero_ether_addr(bssid) ||
4769 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4770 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4771 " reason=%d%s",
4772 MAC2STR(bssid), reason_code,
4773 locally_generated ? " locally_generated=1" : "");
4774 }
4775}
4776
4777
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004778static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4779 int locally_generated)
4780{
4781 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004782 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004783 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4784 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004785 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004786
4787 /*
4788 * It looks like connection was lost while trying to go through PSK
4789 * 4-way handshake. Filter out known disconnection cases that are caused
4790 * by something else than PSK mismatch to avoid confusing reports.
4791 */
4792
4793 if (locally_generated) {
4794 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4795 return 0;
4796 }
4797
4798 return 1;
4799}
4800
4801
Jouni Malinen2b89da82012-08-31 22:04:41 +03004802static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4803 u16 reason_code,
4804 int locally_generated)
4805{
4806 const u8 *bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004807 struct wpa_bss *fast_reconnect = NULL;
4808 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004809 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004810
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004811 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4812 /*
4813 * At least Host AP driver and a Prism3 card seemed to be
4814 * generating streams of disconnected events when configuring
4815 * IBSS for WPA-None. Ignore them for now.
4816 */
4817 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4818 "IBSS/WPA-None mode");
4819 return;
4820 }
4821
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004822 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4823 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4824 locally_generated)
4825 /*
4826 * Remove the inactive AP (which is probably out of range) from
4827 * the BSS list after marking disassociation. In particular
4828 * mac80211-based drivers use the
4829 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4830 * locally generated disconnection events for cases where the
4831 * AP does not reply anymore.
4832 */
4833 curr = wpa_s->current_bss;
4834
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004835 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004836 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4837 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004838 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4839 return; /* P2P group removed */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004840 wpas_auth_failed(wpa_s, "WRONG_KEY", wpa_s->pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004841 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004842#ifdef CONFIG_DPP2
4843 wpas_dpp_send_conn_status_result(wpa_s,
4844 DPP_STATUS_AUTH_FAILURE);
4845#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004846 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004847 if (!wpa_s->disconnected &&
4848 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004849 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004850 wpas_wps_searching(wpa_s) ||
4851 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004852 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004853 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004854 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004855 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004856 wpa_s->wpa_state);
4857 if (wpa_s->wpa_state == WPA_COMPLETED &&
4858 wpa_s->current_ssid &&
4859 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004860 (wpa_s->own_reconnect_req ||
4861 (!locally_generated &&
4862 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004863 /*
4864 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004865 * us, but could allow us to get back in. This is also
4866 * triggered for cases where local reconnection request
4867 * is used to force reassociation with the same BSS.
4868 * Try to reconnect to the same BSS without a full scan
4869 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004870 */
4871 fast_reconnect = wpa_s->current_bss;
4872 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004873 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004874 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004875 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004876 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4877 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004878 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004879 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004880 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004881 "try to re-connect");
4882 wpa_s->reassociate = 0;
4883 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004884 if (!wpa_s->pno)
4885 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004886 }
4887 bssid = wpa_s->bssid;
4888 if (is_zero_ether_addr(bssid))
4889 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004890 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004891 wpas_connection_failed(wpa_s, bssid, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004892 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004893 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4894
Dmitry Shmidt04949592012-07-19 12:16:46 -07004895 if (locally_generated)
4896 wpa_s->disconnect_reason = -reason_code;
4897 else
4898 wpa_s->disconnect_reason = reason_code;
4899 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004900 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4901 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004902 wpa_clear_keys(wpa_s, wpa_s->bssid);
4903 }
4904 wpa_supplicant_mark_disassoc(wpa_s);
4905
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004906 if (curr)
4907 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4908
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004909 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) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004914 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004915 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004916#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 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004924 } 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);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004932 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004933}
4934
4935
4936#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004937void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004938{
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
4951static void
4952wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4953 union wpa_event_data *data)
4954{
4955 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004956 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004957
4958 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4959 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004960 os_get_reltime(&t);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004961 if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004962 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004963 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;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004981
Hai Shalom60840252021-02-19 19:02:11 -08004982 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004983
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004984 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 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005040 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005041 wpa_s->mic_errors_seen++;
5042}
5043
5044
5045#ifdef CONFIG_TERMINATE_ONLASTIF
5046static 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
5058static void
5059wpa_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 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005075
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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005090 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);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005095 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005096 l2_packet_deinit(wpa_s->l2);
5097 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005098
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
Dmitry Shmidte4663042016-04-04 10:07:49 -07005113#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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005120#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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005130#ifdef CONFIG_TDLS
5131static 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:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005138 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);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005143 break;
5144 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03005145 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);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005151 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07005152 case TDLS_REQUEST_DISCOVER:
5153 wpa_tdls_send_discovery_request(wpa_s->wpa,
5154 data->tdls.peer);
5155 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005156 }
5157}
5158#endif /* CONFIG_TDLS */
5159
5160
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005161#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005162static 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,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005173 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005174 break;
5175 }
5176}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005177#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005178
5179
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005180#ifdef CONFIG_IEEE80211R
5181static void
5182wpa_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
5201static 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}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005217
5218
5219static 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}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005234#endif /* CONFIG_IBSS_RSN */
5235
5236
5237#ifdef CONFIG_IEEE80211R
5238static 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
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005258 if (!ether_addr_equal(sta_addr, wpa_s->own_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005259 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
5291static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
5292 struct unprot_deauth *e)
5293{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005294 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);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005299}
5300
5301
5302static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
5303 struct unprot_disassoc *e)
5304{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005305 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);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005310}
5311
5312
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005313static 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
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005329 if (!locally_generated)
5330 wpa_s->own_disconnect_req = 0;
5331
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005332 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
5333
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005334 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))
Sunil Ravi77d572f2023-01-17 23:58:31 +00005339 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005340
5341#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07005342 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005343 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
5359static 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;
Hai Shalom81f62d82019-07-22 12:10:00 -07005376 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
5377 reason2str(reason_code),
5378 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005379 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
5414static 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;
Hai Shalom81f62d82019-07-22 12:10:00 -07005431 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
5432 reason_code, reason2str(reason_code),
5433 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005434 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
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005449static 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
5467static 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
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005485static 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
Hai Shalom74f70d42019-02-11 14:42:39 -08005499void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
5500 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005501{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005502 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005503 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005504
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005505 /*
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
Hai Shalom74f70d42019-02-11 14:42:39 -08005514 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 : "");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005520
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 }
Hai Shalom74f70d42019-02-11 14:42:39 -08005527 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005528
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005529 if (wpa_s->drv_priv == NULL)
5530 return; /* Ignore event during drv initialization */
5531
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005532 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
5533 radio_list) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005534 bool was_6ghz_enabled;
5535
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005536 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(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005540 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005541
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005542 was_6ghz_enabled = ifs->is_6ghz_enabled;
5543 ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5544
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005545 /* 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);
Sunil Ravi7f769292024-07-23 22:21:32 +00005553 } else if (!was_6ghz_enabled && ifs->is_6ghz_enabled) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005554 wpa_dbg(ifs, MSG_INFO,
Sunil Ravi7f769292024-07-23 22:21:32 +00005555 "Channel list changed: 6 GHz was enabled");
5556
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005557 ifs->crossed_6ghz_dom = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005558 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005559 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005560
5561 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005562}
5563
5564
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005565static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005566 const u8 *frame, size_t len, int freq,
5567 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005568{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005569 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005570 const u8 *payload;
5571 size_t plen;
5572 u8 category;
5573
5574 if (len < IEEE80211_HDRLEN + 2)
5575 return;
5576
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005577 mgmt = (const struct ieee80211_mgmt *) frame;
5578 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005579 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005580 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005581
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
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005586#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005587 if (category == WLAN_ACTION_WMM) {
5588 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5589 return;
5590 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005591#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005592
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005593#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
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005600#ifdef CONFIG_SME
5601 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005602 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005603 return;
5604 }
5605#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005606
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
Dmitry Shmidt18463232014-01-24 12:29:41 -08005615 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5616 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005617 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08005618 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005619 payload, plen, freq) == 0)
5620 return;
5621#endif /* CONFIG_GAS */
5622
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005623#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
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005632#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));
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005638 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));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005644 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));
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005655 if (ether_addr_equal(mgmt->sa, wpa_s->bssid) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005656 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
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005663#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005664 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005665 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5666 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005667 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005668 payload + 1,
5669 plen - 1);
5670 return;
5671 }
5672
5673 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005674 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 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005686#endif /* CONFIG_NO_RRM */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005687
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005688#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
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005695#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, freq, payload, plen);
5702 return;
5703 }
5704#endif /* CONFIG_NAN_USD */
5705
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005706#ifdef CONFIG_DPP
5707 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5708 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5709 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
5710 payload[4] == DPP_OUI_TYPE) {
5711 payload++;
5712 plen--;
5713 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
5714 return;
5715 }
5716#endif /* CONFIG_DPP */
5717
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005718#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07005719 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08005720 payload[0] == ROBUST_AV_SCS_RESP) {
5721 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
5722 payload + 1, plen - 1);
5723 return;
5724 }
5725
5726 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005727 payload[0] == ROBUST_AV_MSCS_RESP) {
5728 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5729 payload + 1, plen - 1);
5730 return;
5731 }
5732
Hai Shalomc1a21442022-02-04 13:43:00 -08005733 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
5734 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
5735 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
5736 payload + 4, plen - 4);
5737 return;
5738 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005739#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08005740
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005741 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5742 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005743 if (wpa_s->ifmsh)
5744 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005745}
5746
5747
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005748static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5749 union wpa_event_data *event)
5750{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005751 struct wpa_freq_range_list *list;
5752 char *str = NULL;
5753
5754 list = &event->freq_range;
5755
5756 if (list->num)
5757 str = freq_range_list_str(list);
5758 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5759 str ? str : "");
5760
5761#ifdef CONFIG_P2P
5762 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5763 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5764 __func__);
5765 } else {
5766 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005767
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005768 /*
5769 * The update channel flow will also take care of moving a GO
5770 * from the unsafe frequency if needed.
5771 */
5772 wpas_p2p_update_channel_list(wpa_s,
5773 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005774 }
5775#endif /* CONFIG_P2P */
5776
5777 os_free(str);
5778}
5779
5780
Roshan Pius3a1667e2018-07-03 15:17:14 -07005781static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005782{
Sunil Ravi167279a2023-05-31 01:12:34 +00005783 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005784 wpa_supplicant_cancel_auth_timeout(wpa_s);
5785 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005786 eapol_sm_notify_portValid(wpa_s->eapol, true);
5787 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005788 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005789 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005790}
5791
5792
5793static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5794 int freq)
5795{
5796 size_t i;
5797 int j;
5798
5799 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5800 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5801
5802 for (j = 0; j < mode->num_channels; j++) {
5803 const struct hostapd_channel_data *chan;
5804
5805 chan = &mode->channels[j];
5806 if (chan->freq == freq)
5807 return chan->dfs_cac_ms;
5808 }
5809 }
5810
5811 return 0;
5812}
5813
5814
5815static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5816 struct dfs_event *radar)
5817{
5818#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005819 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005820 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5821 } else
5822#endif /* NEED_AP_MLME && CONFIG_AP */
5823 {
5824 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5825
5826 cac_time /= 1000; /* convert from ms to sec */
5827 if (!cac_time)
5828 cac_time = 10 * 60; /* max timeout: 10 minutes */
5829
5830 /* Restart auth timeout: CAC time added to initial timeout */
5831 wpas_auth_timeout_restart(wpa_s, cac_time);
5832 }
5833}
5834
5835
5836static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5837 struct dfs_event *radar)
5838{
5839#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005840 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005841 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5842 } else
5843#endif /* NEED_AP_MLME && CONFIG_AP */
5844 {
5845 /* Restart auth timeout with original value after CAC is
5846 * finished */
5847 wpas_auth_timeout_restart(wpa_s, 0);
5848 }
5849}
5850
5851
5852static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5853 struct dfs_event *radar)
5854{
5855#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005856 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005857 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5858 } else
5859#endif /* NEED_AP_MLME && CONFIG_AP */
5860 {
5861 /* Restart auth timeout with original value after CAC is
5862 * aborted */
5863 wpas_auth_timeout_restart(wpa_s, 0);
5864 }
5865}
5866
5867
5868static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5869 union wpa_event_data *data)
5870{
5871 wpa_dbg(wpa_s, MSG_DEBUG,
5872 "Connection authorized by device, previous state %d",
5873 wpa_s->wpa_state);
5874
5875 wpa_supplicant_event_port_authorized(wpa_s);
5876
Hai Shalomc1a21442022-02-04 13:43:00 -08005877 wpa_s->last_eapol_matches_bssid = 1;
5878
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005879 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5880 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005881 data->assoc_info.ptk_kck_len,
5882 data->assoc_info.ptk_kek,
5883 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005884#ifdef CONFIG_FILS
5885 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5886 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5887 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5888
5889 /* Update ERP next sequence number */
5890 eapol_sm_update_erp_next_seq_num(
5891 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5892
5893 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5894 /* Add the new PMK and PMKID to the PMKSA cache */
5895 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5896 data->assoc_info.fils_pmk,
5897 data->assoc_info.fils_pmk_len,
5898 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005899 wpa_s->valid_links ?
5900 wpa_s->ap_mld_addr :
5901 wpa_s->bssid,
5902 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005903 } else if (data->assoc_info.fils_pmkid) {
5904 /* Update the current PMKSA used for this connection */
5905 pmksa_cache_set_current(wpa_s->wpa,
5906 data->assoc_info.fils_pmkid,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005907 NULL, NULL, 0, NULL, 0, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005908 }
5909 }
5910#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005911}
5912
5913
Hai Shalom60840252021-02-19 19:02:11 -08005914static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5915{
5916 switch (code) {
5917 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5918 return "";
5919 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5920 return "no_bss_found";
5921 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5922 return "auth_tx_fail";
5923 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5924 return "auth_no_ack_received";
5925 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5926 return "auth_no_resp_received";
5927 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5928 return "assoc_req_tx_fail";
5929 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5930 return "assoc_no_ack_received";
5931 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5932 return "assoc_no_resp_received";
5933 default:
5934 return "unknown_reason";
5935 }
5936}
5937
5938
Roshan Pius3a1667e2018-07-03 15:17:14 -07005939static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5940 union wpa_event_data *data)
5941{
5942 const u8 *bssid = data->assoc_reject.bssid;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005943 struct ieee802_11_elems elems;
Sunil Ravi7f769292024-07-23 22:21:32 +00005944 struct ml_sta_link_info ml_info[MAX_NUM_MLD_LINKS];
5945 const u8 *link_bssids[MAX_NUM_MLD_LINKS + 1];
Hai Shalom81f62d82019-07-22 12:10:00 -07005946#ifdef CONFIG_MBO
5947 struct wpa_bss *reject_bss;
5948#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005949
5950 if (!bssid || is_zero_ether_addr(bssid))
5951 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005952#ifdef CONFIG_MBO
5953 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5954 reject_bss = wpa_s->current_bss;
5955 else
5956 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5957#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005958
5959 if (data->assoc_reject.bssid)
5960 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005961 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005962 MAC2STR(data->assoc_reject.bssid),
5963 data->assoc_reject.status_code,
5964 data->assoc_reject.timed_out ? " timeout" : "",
5965 data->assoc_reject.timeout_reason ? "=" : "",
5966 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005967 data->assoc_reject.timeout_reason : "",
5968 data->assoc_reject.reason_code !=
5969 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5970 " qca_driver_reason=" : "",
5971 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005972 else
5973 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005974 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005975 data->assoc_reject.status_code,
5976 data->assoc_reject.timed_out ? " timeout" : "",
5977 data->assoc_reject.timeout_reason ? "=" : "",
5978 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005979 data->assoc_reject.timeout_reason : "",
5980 data->assoc_reject.reason_code !=
5981 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5982 " qca_driver_reason=" : "",
5983 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005984 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005985 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5986 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005987
5988#ifdef CONFIG_OWE
5989 if (data->assoc_reject.status_code ==
5990 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5991 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5992 wpa_s->current_ssid &&
5993 wpa_s->current_ssid->owe_group == 0 &&
5994 wpa_s->last_owe_group != 21) {
5995 struct wpa_ssid *ssid = wpa_s->current_ssid;
5996 struct wpa_bss *bss = wpa_s->current_bss;
5997
5998 if (!bss) {
5999 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
6000 if (!bss) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006001 wpas_connection_failed(wpa_s, bssid, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006002 wpa_supplicant_mark_disassoc(wpa_s);
6003 return;
6004 }
6005 }
6006 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
6007 wpas_connect_work_done(wpa_s);
6008 wpa_supplicant_mark_disassoc(wpa_s);
6009 wpa_supplicant_connect(wpa_s, bss, ssid);
6010 return;
6011 }
6012#endif /* CONFIG_OWE */
6013
Hai Shalomfdcde762020-04-02 11:19:20 -07006014#ifdef CONFIG_DPP2
6015 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
6016 * the status code defined in the DPP R2 tech spec.
6017 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
6018 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006019 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07006020 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
6021 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
6022 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07006023 wpa_s->current_ssid->dpp_pfs == 0 &&
6024 (data->assoc_reject.status_code ==
6025 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
6026 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
6027 struct wpa_ssid *ssid = wpa_s->current_ssid;
6028 struct wpa_bss *bss = wpa_s->current_bss;
6029
6030 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
6031 if (!bss)
6032 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
6033 if (!bss || wpa_s->dpp_pfs_fallback) {
6034 wpa_printf(MSG_DEBUG,
6035 "DPP: Updated PFS policy for next try");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006036 wpas_connection_failed(wpa_s, bssid, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07006037 wpa_supplicant_mark_disassoc(wpa_s);
6038 return;
6039 }
6040 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
6041 wpa_s->dpp_pfs_fallback = 1;
6042 wpas_connect_work_done(wpa_s);
6043 wpa_supplicant_mark_disassoc(wpa_s);
6044 wpa_supplicant_connect(wpa_s, bss, ssid);
6045 return;
6046 }
6047#endif /* CONFIG_DPP2 */
6048
Hai Shalom74f70d42019-02-11 14:42:39 -08006049#ifdef CONFIG_MBO
6050 if (data->assoc_reject.status_code ==
6051 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07006052 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08006053 const u8 *rssi_rej;
6054
6055 rssi_rej = mbo_get_attr_from_ies(
6056 data->assoc_reject.resp_ies,
6057 data->assoc_reject.resp_ies_len,
6058 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
6059 if (rssi_rej && rssi_rej[1] == 2) {
6060 wpa_printf(MSG_DEBUG,
6061 "OCE: RSSI-based association rejection from "
6062 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07006063 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08006064 rssi_rej[2], rssi_rej[3]);
6065 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07006066 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08006067 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07006068 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08006069 }
6070 }
6071#endif /* CONFIG_MBO */
6072
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006073 /* Check for other failed links in the response */
6074 os_memset(link_bssids, 0, sizeof(link_bssids));
6075 if (ieee802_11_parse_elems(data->assoc_reject.resp_ies,
6076 data->assoc_reject.resp_ies_len,
6077 &elems, 1) != ParseFailed) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006078 unsigned int n_links, i, idx;
6079
6080 idx = 0;
6081 n_links = wpas_ml_parse_assoc(wpa_s, &elems, ml_info);
6082
6083 for (i = 1; i < n_links; i++) {
6084 /* The status cannot be success here.
6085 * Add the link to the failed list if it is reporting
6086 * an error. The only valid "non-error" status is
6087 * TX_LINK_NOT_ACCEPTED as that means this link may
6088 * still accept an association from us.
6089 */
6090 if (ml_info[i].status !=
6091 WLAN_STATUS_DENIED_TX_LINK_NOT_ACCEPTED) {
6092 link_bssids[idx] = ml_info[i].bssid;
6093 idx++;
6094 }
6095 }
6096 }
6097
Roshan Pius3a1667e2018-07-03 15:17:14 -07006098 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006099 sme_event_assoc_reject(wpa_s, data, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006100 return;
6101 }
6102
6103 /* Driver-based SME cases */
6104
6105#ifdef CONFIG_SAE
6106 if (wpa_s->current_ssid &&
6107 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
6108 !data->assoc_reject.timed_out) {
6109 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
6110 wpa_sm_aborted_cached(wpa_s->wpa);
6111 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
6112 }
6113#endif /* CONFIG_SAE */
6114
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006115#ifdef CONFIG_DPP
6116 if (wpa_s->current_ssid &&
6117 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
6118 !data->assoc_reject.timed_out) {
6119 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
6120 wpa_sm_aborted_cached(wpa_s->wpa);
6121 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
6122 }
6123#endif /* CONFIG_DPP */
6124
Roshan Pius3a1667e2018-07-03 15:17:14 -07006125#ifdef CONFIG_FILS
6126 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07006127 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006128 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006129 eapol_sm_update_erp_next_seq_num(
6130 wpa_s->eapol,
6131 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07006132 fils_connection_failure(wpa_s);
6133 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006134#endif /* CONFIG_FILS */
6135
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006136 wpas_connection_failed(wpa_s, bssid, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006137 wpa_supplicant_mark_disassoc(wpa_s);
6138}
6139
6140
Hai Shalomfdcde762020-04-02 11:19:20 -07006141static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
6142 struct unprot_beacon *data)
6143{
6144 struct wpabuf *buf;
6145 int res;
6146
6147 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006148 !ether_addr_equal(data->sa, wpa_s->bssid))
Hai Shalomfdcde762020-04-02 11:19:20 -07006149 return;
6150 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
6151 MAC2STR(data->sa));
6152
6153 buf = wpabuf_alloc(4);
6154 if (!buf)
6155 return;
6156
6157 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
6158 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
6159 wpabuf_put_u8(buf, 1); /* Dialog Token */
6160 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
6161
6162 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
6163 wpa_s->own_addr, wpa_s->bssid,
6164 wpabuf_head(buf), wpabuf_len(buf), 0);
6165 if (res < 0)
6166 wpa_printf(MSG_DEBUG,
6167 "Failed to send WNM-Notification Request frame");
6168
6169 wpabuf_free(buf);
6170}
6171
6172
Sunil Ravi640215c2023-06-28 23:08:09 +00006173static const char * bitmap_to_str(u8 value, char *buf)
6174{
6175 char *pos = buf;
6176 int i, k = 0;
6177
6178 for (i = 7; i >= 0; i--)
6179 pos[k++] = (value & BIT(i)) ? '1' : '0';
6180
6181 pos[8] = '\0';
6182 return pos;
6183}
6184
6185
6186static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
6187 struct tid_link_map_info *info)
6188{
6189 char map_info[1000], *pos, *end;
6190 int res, i;
6191
6192 pos = map_info;
6193 end = pos + sizeof(map_info);
6194 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
6195 info->default_map);
6196 if (os_snprintf_error(end - pos, res))
6197 return;
6198 pos += res;
6199
6200 if (!info->default_map) {
Sunil Ravi99c035e2024-07-12 01:42:03 +00006201 for_each_link(info->valid_links, i) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006202 char uplink_map_str[9];
6203 char downlink_map_str[9];
6204
Sunil Ravi640215c2023-06-28 23:08:09 +00006205 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
6206 bitmap_to_str(info->t2lmap[i].downlink,
6207 downlink_map_str);
6208
6209 res = os_snprintf(pos, end - pos,
6210 " link_id=%d up_link=%s down_link=%s",
6211 i, uplink_map_str,
6212 downlink_map_str);
6213 if (os_snprintf_error(end - pos, res))
6214 return;
6215 pos += res;
6216 }
6217 }
6218
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306219 wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP);
Sunil Ravi640215c2023-06-28 23:08:09 +00006220 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
6221}
6222
6223
6224static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
6225{
6226 u8 bssid[ETH_ALEN];
6227
6228 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
6229 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
6230 wpa_supplicant_deauthenticate(wpa_s,
6231 WLAN_REASON_DEAUTH_LEAVING);
6232 return;
6233 }
6234
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006235 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006236 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
6237 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
6238 wpas_notify_bssid_changed(wpa_s);
6239 }
6240
6241 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
6242 wpa_printf(MSG_ERROR,
6243 "LINK_RECONFIG: Failed to get MLO connection info");
6244 wpa_supplicant_deauthenticate(wpa_s,
6245 WLAN_REASON_DEAUTH_LEAVING);
6246 return;
6247 }
6248
6249 if (wpa_sm_set_ml_info(wpa_s)) {
6250 wpa_printf(MSG_ERROR,
6251 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
6252 wpa_supplicant_deauthenticate(wpa_s,
6253 WLAN_REASON_DEAUTH_LEAVING);
6254 return;
6255 }
6256
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306257 wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL);
Sunil Ravi640215c2023-06-28 23:08:09 +00006258 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
6259 wpa_s->valid_links);
6260}
6261
Matthew Wangb820c2b2024-10-03 13:02:07 +00006262#ifdef MAINLINE_SUPPLICANT
6263static bool is_event_allowlisted(enum wpa_event_type event) {
Matthew Wangc8ea6132024-10-23 11:19:52 +00006264 return event == EVENT_SCAN_STARTED ||
6265 event == EVENT_SCAN_RESULTS ||
6266 event == EVENT_RX_MGMT ||
Matthew Wangb820c2b2024-10-03 13:02:07 +00006267 event == EVENT_REMAIN_ON_CHANNEL ||
6268 event == EVENT_CANCEL_REMAIN_ON_CHANNEL ||
6269 event == EVENT_TX_WAIT_EXPIRE;
6270}
6271#endif /* MAINLINE_SUPPLICANT */
6272
Sunil Ravi640215c2023-06-28 23:08:09 +00006273
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006274void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
6275 union wpa_event_data *data)
6276{
6277 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006278 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07006279 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08006280#ifndef CONFIG_NO_STDOUT_DEBUG
6281 int level = MSG_DEBUG;
6282#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006283
Matthew Wangb820c2b2024-10-03 13:02:07 +00006284#ifdef MAINLINE_SUPPLICANT
6285 if (!is_event_allowlisted(event)) {
6286 wpa_dbg(wpa_s, MSG_DEBUG,
6287 "Ignore event %s (%d) which is not allowlisted",
6288 event_to_string(event), event);
6289 return;
6290 }
6291#endif /* MAINLINE_SUPPLICANT */
6292
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006293 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
6294 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006295 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006296 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006297 event != EVENT_SCHED_SCAN_STOPPED) {
6298 wpa_dbg(wpa_s, MSG_DEBUG,
6299 "Ignore event %s (%d) while interface is disabled",
6300 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006301 return;
6302 }
6303
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006304#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07006305 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006306 const struct ieee80211_hdr *hdr;
6307 u16 fc;
6308 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
6309 fc = le_to_host16(hdr->frame_control);
6310 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
6311 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
6312 level = MSG_EXCESSIVE;
6313 }
6314
6315 wpa_dbg(wpa_s, level, "Event %s (%d) received",
6316 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006317#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006318
6319 switch (event) {
6320 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006321#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08006322 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
6323 data->auth.ies_len))
6324 wpa_printf(MSG_DEBUG,
6325 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006326#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006327 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006328 wpa_s->auth_status_code = data->auth.status_code;
6329 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006330 break;
6331 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006332#ifdef CONFIG_TESTING_OPTIONS
6333 if (wpa_s->ignore_auth_resp) {
6334 wpa_printf(MSG_INFO,
6335 "EVENT_ASSOC - ignore_auth_resp active!");
6336 break;
6337 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006338 if (wpa_s->testing_resend_assoc) {
6339 wpa_printf(MSG_INFO,
6340 "EVENT_DEAUTH - testing_resend_assoc");
6341 break;
6342 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006343#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05306344 if (wpa_s->disconnected) {
6345 wpa_printf(MSG_INFO,
6346 "Ignore unexpected EVENT_ASSOC in disconnected state");
6347 break;
6348 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006349 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006350 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006351 if (data &&
6352 (data->assoc_info.authorized ||
6353 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6354 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006355 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006356 if (data) {
6357 wpa_msg(wpa_s, MSG_INFO,
6358 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
6359 data->assoc_info.subnet_status);
6360 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006361 break;
6362 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006363 wpas_event_disassoc(wpa_s,
6364 data ? &data->disassoc_info : NULL);
6365 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006366 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006367#ifdef CONFIG_TESTING_OPTIONS
6368 if (wpa_s->ignore_auth_resp) {
6369 wpa_printf(MSG_INFO,
6370 "EVENT_DEAUTH - ignore_auth_resp active!");
6371 break;
6372 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006373 if (wpa_s->testing_resend_assoc) {
6374 wpa_printf(MSG_INFO,
6375 "EVENT_DEAUTH - testing_resend_assoc");
6376 break;
6377 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006378#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006379 wpas_event_deauth(wpa_s,
6380 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006381 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00006382 case EVENT_LINK_RECONFIG:
6383 wpas_link_reconfig(wpa_s);
6384 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006385 case EVENT_MICHAEL_MIC_FAILURE:
6386 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
6387 break;
6388#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006389 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006390 if (wpa_s->own_scan_requested ||
6391 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006392 struct os_reltime diff;
6393
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006394 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006395 os_reltime_sub(&wpa_s->scan_start_time,
6396 &wpa_s->scan_trigger_time, &diff);
6397 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
6398 diff.sec, diff.usec);
6399 wpa_s->own_scan_requested = 0;
6400 wpa_s->own_scan_running = 1;
6401 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
6402 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006403 wpa_msg_ctrl(wpa_s, MSG_INFO,
6404 WPA_EVENT_SCAN_STARTED "id=%u",
6405 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006406 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006407 wpa_msg_ctrl(wpa_s, MSG_INFO,
6408 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006409 }
6410 } else {
6411 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08006412 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006413 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006414 }
6415 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006416 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006417 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6418 wpa_s->scan_res_handler = NULL;
6419 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08006420 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006421 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
6422 break;
6423 }
6424
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006425 if (!(data && data->scan_info.external_scan) &&
6426 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006427 struct os_reltime now, diff;
6428 os_get_reltime(&now);
6429 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
6430 wpa_s->scan_start_time.sec = 0;
6431 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00006432 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006433 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
6434 diff.sec, diff.usec);
6435 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006436 if (wpa_supplicant_event_scan_results(wpa_s, data))
6437 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006438 if (!(data && data->scan_info.external_scan))
6439 wpa_s->own_scan_running = 0;
6440 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08006441 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006442 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006443 break;
6444#endif /* CONFIG_NO_SCAN_PROCESSING */
6445 case EVENT_ASSOCINFO:
6446 wpa_supplicant_event_associnfo(wpa_s, data);
6447 break;
6448 case EVENT_INTERFACE_STATUS:
6449 wpa_supplicant_event_interface_status(wpa_s, data);
6450 break;
6451 case EVENT_PMKID_CANDIDATE:
6452 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
6453 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006454#ifdef CONFIG_TDLS
6455 case EVENT_TDLS:
6456 wpa_supplicant_event_tdls(wpa_s, data);
6457 break;
6458#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006459#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006460 case EVENT_WNM:
6461 wpa_supplicant_event_wnm(wpa_s, data);
6462 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006463#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006464#ifdef CONFIG_IEEE80211R
6465 case EVENT_FT_RESPONSE:
6466 wpa_supplicant_event_ft_response(wpa_s, data);
6467 break;
6468#endif /* CONFIG_IEEE80211R */
6469#ifdef CONFIG_IBSS_RSN
6470 case EVENT_IBSS_RSN_START:
6471 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
6472 break;
6473#endif /* CONFIG_IBSS_RSN */
6474 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07006475 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006476 break;
6477 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006478 /* It is possible to get this event from earlier connection */
6479 if (wpa_s->current_ssid &&
6480 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6481 wpa_dbg(wpa_s, MSG_DEBUG,
6482 "Ignore AUTH_TIMED_OUT in mesh configuration");
6483 break;
6484 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006485 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6486 sme_event_auth_timed_out(wpa_s, data);
6487 break;
6488 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006489 /* It is possible to get this event from earlier connection */
6490 if (wpa_s->current_ssid &&
6491 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6492 wpa_dbg(wpa_s, MSG_DEBUG,
6493 "Ignore ASSOC_TIMED_OUT in mesh configuration");
6494 break;
6495 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006496 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6497 sme_event_assoc_timed_out(wpa_s, data);
6498 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006499 case EVENT_TX_STATUS:
6500 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
6501 " type=%d stype=%d",
6502 MAC2STR(data->tx_status.dst),
6503 data->tx_status.type, data->tx_status.stype);
Sunil Ravi99c035e2024-07-12 01:42:03 +00006504#ifdef CONFIG_WNM
6505 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6506 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
6507 wnm_btm_resp_tx_status(wpa_s, data->tx_status.data,
6508 data->tx_status.data_len) == 0)
6509 break;
6510#endif /* CONFIG_WNM */
Hai Shalom60840252021-02-19 19:02:11 -08006511#ifdef CONFIG_PASN
6512 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6513 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6514 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
6515 data->tx_status.data_len,
6516 data->tx_status.ack) == 0)
6517 break;
6518#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006519#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006520 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006521#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006522 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6523 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006524 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006525 wpa_s, data->tx_status.dst,
6526 data->tx_status.data,
6527 data->tx_status.data_len,
6528 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006529 OFFCHANNEL_SEND_ACTION_SUCCESS :
6530 OFFCHANNEL_SEND_ACTION_NO_ACK);
6531#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006532 break;
6533 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006534#endif /* CONFIG_AP */
6535#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006536 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006537 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006538 /*
6539 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006540 * interface in GO mode, or via standalone AP interface.
6541 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
6542 * except when the primary interface is used as a GO interface
6543 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006544 */
6545 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6546 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006547 ether_addr_equal(wpa_s->p2pdev->pending_action_dst,
6548 data->tx_status.dst)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006549 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006550 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006551 data->tx_status.data,
6552 data->tx_status.data_len,
6553 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006554 OFFCHANNEL_SEND_ACTION_SUCCESS :
6555 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006556 break;
6557 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006558#endif /* CONFIG_OFFCHANNEL */
6559#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006560 switch (data->tx_status.type) {
6561 case WLAN_FC_TYPE_MGMT:
6562 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
6563 data->tx_status.data_len,
6564 data->tx_status.stype,
6565 data->tx_status.ack);
6566 break;
6567 case WLAN_FC_TYPE_DATA:
6568 ap_tx_status(wpa_s, data->tx_status.dst,
6569 data->tx_status.data,
6570 data->tx_status.data_len,
6571 data->tx_status.ack);
6572 break;
6573 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006574#endif /* CONFIG_AP */
6575 break;
6576#ifdef CONFIG_AP
6577 case EVENT_EAPOL_TX_STATUS:
6578 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
6579 data->eapol_tx_status.data,
6580 data->eapol_tx_status.data_len,
6581 data->eapol_tx_status.ack);
6582 break;
6583 case EVENT_DRIVER_CLIENT_POLL_OK:
6584 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006585 break;
6586 case EVENT_RX_FROM_UNKNOWN:
6587 if (wpa_s->ap_iface == NULL)
6588 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006589 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
6590 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006591 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006592#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07006593
Sunil Ravi89eba102022-09-13 21:04:37 -07006594 case EVENT_LINK_CH_SWITCH_STARTED:
6595 case EVENT_LINK_CH_SWITCH:
6596 if (!data || !wpa_s->current_ssid ||
6597 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6598 break;
6599
6600 wpa_msg(wpa_s, MSG_INFO,
6601 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6602 event == EVENT_LINK_CH_SWITCH ?
6603 WPA_EVENT_LINK_CHANNEL_SWITCH :
6604 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6605 data->ch_switch.freq,
6606 data->ch_switch.link_id,
6607 data->ch_switch.ht_enabled,
6608 data->ch_switch.ch_offset,
6609 channel_width_to_string(data->ch_switch.ch_width),
6610 data->ch_switch.cf1,
6611 data->ch_switch.cf2);
6612 if (event == EVENT_LINK_CH_SWITCH_STARTED)
6613 break;
6614
6615 wpa_s->links[data->ch_switch.link_id].freq =
6616 data->ch_switch.freq;
6617 if (wpa_s->links[data->ch_switch.link_id].bss &&
6618 wpa_s->links[data->ch_switch.link_id].bss->freq !=
6619 data->ch_switch.freq) {
6620 wpa_s->links[data->ch_switch.link_id].bss->freq =
6621 data->ch_switch.freq;
6622 notify_bss_changes(
6623 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6624 wpa_s->links[data->ch_switch.link_id].bss);
Shuibing Dai0db6bb12023-09-28 17:53:17 -07006625 if (data->ch_switch.freq)
6626 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
Sunil Ravi89eba102022-09-13 21:04:37 -07006627 }
6628 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07006629 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07006630 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006631 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006632 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006633
Hai Shalom81f62d82019-07-22 12:10:00 -07006634 wpa_msg(wpa_s, MSG_INFO,
6635 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6636 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6637 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006638 data->ch_switch.freq,
6639 data->ch_switch.ht_enabled,
6640 data->ch_switch.ch_offset,
6641 channel_width_to_string(data->ch_switch.ch_width),
6642 data->ch_switch.cf1,
6643 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07006644 if (event == EVENT_CH_SWITCH_STARTED)
6645 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006646
Sunil Ravi65a724b2022-05-24 11:06:09 -07006647 if (wpa_s->assoc_freq && data->ch_switch.freq &&
6648 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
6649 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
6650 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006651 wpa_s->assoc_freq = data->ch_switch.freq;
6652 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08006653 if (wpa_s->current_bss &&
6654 wpa_s->current_bss->freq != data->ch_switch.freq) {
6655 wpa_s->current_bss->freq = data->ch_switch.freq;
6656 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6657 wpa_s->current_bss);
6658 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006659
Hai Shalomfdcde762020-04-02 11:19:20 -07006660#ifdef CONFIG_SME
6661 switch (data->ch_switch.ch_offset) {
6662 case 1:
6663 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6664 break;
6665 case -1:
6666 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6667 break;
6668 default:
6669 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6670 break;
6671 }
6672#endif /* CONFIG_SME */
6673
Roshan Pius3a1667e2018-07-03 15:17:14 -07006674#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006675 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6676 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08006677 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006678 wpa_s->current_ssid->mode ==
6679 WPAS_MODE_P2P_GROUP_FORMATION) {
6680 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6681 data->ch_switch.ht_enabled,
6682 data->ch_switch.ch_offset,
6683 data->ch_switch.ch_width,
6684 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006685 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07006686 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07006687 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006688 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006689#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006690
Hai Shalom899fcc72020-10-19 14:38:18 -07006691 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6692 sme_event_ch_switch(wpa_s);
6693
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006694 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006695 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006696 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006697#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006698#ifdef NEED_AP_MLME
6699 case EVENT_DFS_RADAR_DETECTED:
6700 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07006701 wpas_ap_event_dfs_radar_detected(wpa_s,
6702 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006703 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006704 case EVENT_DFS_NOP_FINISHED:
6705 if (data)
6706 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
6707 &data->dfs_event);
6708 break;
6709#endif /* NEED_AP_MLME */
6710#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006711 case EVENT_DFS_CAC_STARTED:
6712 if (data)
6713 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
6714 break;
6715 case EVENT_DFS_CAC_FINISHED:
6716 if (data)
6717 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
6718 break;
6719 case EVENT_DFS_CAC_ABORTED:
6720 if (data)
6721 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
6722 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006723 case EVENT_RX_MGMT: {
6724 u16 fc, stype;
6725 const struct ieee80211_mgmt *mgmt;
6726
Dmitry Shmidt818ea482014-03-10 13:15:21 -07006727#ifdef CONFIG_TESTING_OPTIONS
6728 if (wpa_s->ext_mgmt_frame_handling) {
6729 struct rx_mgmt *rx = &data->rx_mgmt;
6730 size_t hex_len = 2 * rx->frame_len + 1;
6731 char *hex = os_malloc(hex_len);
6732 if (hex) {
6733 wpa_snprintf_hex(hex, hex_len,
6734 rx->frame, rx->frame_len);
6735 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
6736 rx->freq, rx->datarate, rx->ssi_signal,
6737 hex);
6738 os_free(hex);
6739 }
6740 break;
6741 }
6742#endif /* CONFIG_TESTING_OPTIONS */
6743
Dmitry Shmidt04949592012-07-19 12:16:46 -07006744 mgmt = (const struct ieee80211_mgmt *)
6745 data->rx_mgmt.frame;
6746 fc = le_to_host16(mgmt->frame_control);
6747 stype = WLAN_FC_GET_STYPE(fc);
6748
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006749#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006750 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006751#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006752#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006753 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006754 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006755 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07006756 const u8 *ie;
6757 size_t ie_len;
6758
6759 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6760 ie_len = data->rx_mgmt.frame_len -
6761 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006762 wpas_p2p_probe_req_rx(
6763 wpa_s, src, mgmt->da,
6764 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006765 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006766 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006767 break;
6768 }
6769#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006770#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006771 if (wpa_s->current_ssid &&
6772 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
6773 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006774 data->rx_mgmt.frame_len >= 30) {
6775 wpa_supplicant_event_ibss_auth(wpa_s, data);
6776 break;
6777 }
6778#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006779
6780 if (stype == WLAN_FC_STYPE_ACTION) {
6781 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07006782 wpa_s, data->rx_mgmt.frame,
6783 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006784 data->rx_mgmt.freq,
6785 data->rx_mgmt.ssi_signal);
6786 break;
6787 }
6788
6789 if (wpa_s->ifmsh) {
6790 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006791 break;
6792 }
Hai Shalom60840252021-02-19 19:02:11 -08006793#ifdef CONFIG_PASN
6794 if (stype == WLAN_FC_STYPE_AUTH &&
6795 wpas_pasn_auth_rx(wpa_s, mgmt,
6796 data->rx_mgmt.frame_len) != -2)
6797 break;
6798#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006799
Roshan Pius3a1667e2018-07-03 15:17:14 -07006800#ifdef CONFIG_SAE
6801 if (stype == WLAN_FC_STYPE_AUTH &&
6802 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6803 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6804 sme_external_auth_mgmt_rx(
6805 wpa_s, data->rx_mgmt.frame,
6806 data->rx_mgmt.frame_len);
6807 break;
6808 }
6809#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006810 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6811 "management frame in non-AP mode");
6812 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006813#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006814 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006815
6816 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006817 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6818 const u8 *ie;
6819 size_t ie_len;
6820
6821 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6822 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006823
6824 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6825 mgmt->bssid, ie, ie_len,
6826 data->rx_mgmt.ssi_signal);
6827 }
6828
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006829 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006830#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006831 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006832 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006833 case EVENT_RX_PROBE_REQ:
6834 if (data->rx_probe_req.sa == NULL ||
6835 data->rx_probe_req.ie == NULL)
6836 break;
6837#ifdef CONFIG_AP
6838 if (wpa_s->ap_iface) {
6839 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6840 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006841 data->rx_probe_req.da,
6842 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006843 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006844 data->rx_probe_req.ie_len,
6845 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006846 break;
6847 }
6848#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006849 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006850 data->rx_probe_req.da,
6851 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006852 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006853 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006854 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006855 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006856 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006857 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006858#ifdef CONFIG_OFFCHANNEL
6859 offchannel_remain_on_channel_cb(
6860 wpa_s, data->remain_on_channel.freq,
6861 data->remain_on_channel.duration);
6862#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006863 wpas_p2p_remain_on_channel_cb(
6864 wpa_s, data->remain_on_channel.freq,
6865 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006866#ifdef CONFIG_DPP
6867 wpas_dpp_remain_on_channel_cb(
6868 wpa_s, data->remain_on_channel.freq,
6869 data->remain_on_channel.duration);
6870#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006871#ifdef CONFIG_NAN_USD
6872 wpas_nan_usd_remain_on_channel_cb(
6873 wpa_s, data->remain_on_channel.freq,
6874 data->remain_on_channel.duration);
6875#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006876 break;
6877 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006878#ifdef CONFIG_OFFCHANNEL
6879 offchannel_cancel_remain_on_channel_cb(
6880 wpa_s, data->remain_on_channel.freq);
6881#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006882 wpas_p2p_cancel_remain_on_channel_cb(
6883 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006884#ifdef CONFIG_DPP
6885 wpas_dpp_cancel_remain_on_channel_cb(
6886 wpa_s, data->remain_on_channel.freq);
6887#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006888#ifdef CONFIG_NAN_USD
6889 wpas_nan_usd_cancel_remain_on_channel_cb(
6890 wpa_s, data->remain_on_channel.freq);
6891#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006892 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006893 case EVENT_EAPOL_RX:
6894 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6895 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00006896 data->eapol_rx.data_len,
6897 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006898 break;
6899 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006900 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00006901 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006902 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006903 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006904 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006905 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006906 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006907 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006908 bgscan_notify_signal_change(
6909 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006910 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006911 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006912 data->signal_change.data.current_tx_rate);
6913 os_memcpy(&wpa_s->last_signal_info, data,
6914 sizeof(struct wpa_signal_info));
6915 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006916 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006917 case EVENT_INTERFACE_MAC_CHANGED:
6918 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006919 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006920 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006921 case EVENT_INTERFACE_ENABLED:
6922 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6923 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006924 u8 addr[ETH_ALEN];
6925
Hai Shalomfdcde762020-04-02 11:19:20 -07006926 eloop_cancel_timeout(wpas_clear_disabled_interface,
6927 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08006928 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006929 wpa_supplicant_update_mac_addr(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006930 if (!ether_addr_equal(addr, wpa_s->own_addr))
Hai Shalomc1a21442022-02-04 13:43:00 -08006931 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6932 else
6933 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07006934 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006935 if (wpa_s->p2p_mgmt) {
6936 wpa_supplicant_set_state(wpa_s,
6937 WPA_DISCONNECTED);
6938 break;
6939 }
6940
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006941#ifdef CONFIG_AP
6942 if (!wpa_s->ap_iface) {
6943 wpa_supplicant_set_state(wpa_s,
6944 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006945 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006946 wpa_supplicant_req_scan(wpa_s, 0, 0);
6947 } else
6948 wpa_supplicant_set_state(wpa_s,
6949 WPA_COMPLETED);
6950#else /* CONFIG_AP */
6951 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6952 wpa_supplicant_req_scan(wpa_s, 0, 0);
6953#endif /* CONFIG_AP */
6954 }
6955 break;
6956 case EVENT_INTERFACE_DISABLED:
6957 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006958#ifdef CONFIG_P2P
6959 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6960 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6961 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6962 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006963 * Mark interface disabled if this happens to end up not
6964 * being removed as a separate P2P group interface.
6965 */
6966 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6967 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006968 * The interface was externally disabled. Remove
6969 * it assuming an external entity will start a
6970 * new session if needed.
6971 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006972 if (wpa_s->current_ssid &&
6973 wpa_s->current_ssid->p2p_group)
6974 wpas_p2p_interface_unavailable(wpa_s);
6975 else
6976 wpas_p2p_disconnect(wpa_s);
6977 /*
6978 * wpa_s instance may have been freed, so must not use
6979 * it here anymore.
6980 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006981 break;
6982 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006983 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6984 p2p_in_progress(wpa_s->global->p2p) > 1) {
6985 /* This radio work will be cancelled, so clear P2P
6986 * state as well.
6987 */
6988 p2p_stop_find(wpa_s->global->p2p);
6989 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006990#endif /* CONFIG_P2P */
6991
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006992 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6993 /*
6994 * Indicate disconnection to keep ctrl_iface events
6995 * consistent.
6996 */
6997 wpa_supplicant_event_disassoc(
6998 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6999 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007000 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07007001 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08007002 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
7003 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07007004 clear_at.usec = 0;
7005 } else {
7006 struct os_reltime tmp;
7007
Hai Shalom60840252021-02-19 19:02:11 -08007008 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07007009 tmp.usec = 0;
7010 os_reltime_sub(&tmp, &age, &clear_at);
7011 }
7012 eloop_register_timeout(clear_at.sec, clear_at.usec,
7013 wpas_clear_disabled_interface,
7014 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08007015 radio_remove_works(wpa_s, NULL, 0);
7016
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007017 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
7018 break;
7019 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07007020 wpa_supplicant_update_channel_list(
7021 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007022 break;
7023 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007024 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007025 break;
7026 case EVENT_BEST_CHANNEL:
7027 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
7028 "(%d %d %d)",
7029 data->best_chan.freq_24, data->best_chan.freq_5,
7030 data->best_chan.freq_overall);
7031 wpa_s->best_24_freq = data->best_chan.freq_24;
7032 wpa_s->best_5_freq = data->best_chan.freq_5;
7033 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007034 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
7035 data->best_chan.freq_5,
7036 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007037 break;
7038 case EVENT_UNPROT_DEAUTH:
7039 wpa_supplicant_event_unprot_deauth(wpa_s,
7040 &data->unprot_deauth);
7041 break;
7042 case EVENT_UNPROT_DISASSOC:
7043 wpa_supplicant_event_unprot_disassoc(wpa_s,
7044 &data->unprot_disassoc);
7045 break;
7046 case EVENT_STATION_LOW_ACK:
7047#ifdef CONFIG_AP
7048 if (wpa_s->ap_iface && data)
7049 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
7050 data->low_ack.addr);
7051#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007052#ifdef CONFIG_TDLS
7053 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007054 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
7055 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007056#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007057 break;
7058 case EVENT_IBSS_PEER_LOST:
7059#ifdef CONFIG_IBSS_RSN
7060 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
7061#endif /* CONFIG_IBSS_RSN */
7062 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007063 case EVENT_DRIVER_GTK_REKEY:
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007064 if (!ether_addr_equal(data->driver_gtk_rekey.bssid,
7065 wpa_s->bssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007066 break;
7067 if (!wpa_s->wpa)
7068 break;
7069 wpa_sm_update_replay_ctr(wpa_s->wpa,
7070 data->driver_gtk_rekey.replay_ctr);
7071 break;
7072 case EVENT_SCHED_SCAN_STOPPED:
7073 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007074 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007075 wpa_supplicant_notify_scanning(wpa_s, 0);
7076
7077 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7078 break;
7079
7080 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007081 * If the driver stopped scanning without being requested to,
7082 * request a new scan to continue scanning for networks.
7083 */
7084 if (!wpa_s->sched_scan_stop_req &&
7085 wpa_s->wpa_state == WPA_SCANNING) {
7086 wpa_dbg(wpa_s, MSG_DEBUG,
7087 "Restart scanning after unexpected sched_scan stop event");
7088 wpa_supplicant_req_scan(wpa_s, 1, 0);
7089 break;
7090 }
7091
7092 wpa_s->sched_scan_stop_req = 0;
7093
7094 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08007095 * Start a new sched scan to continue searching for more SSIDs
7096 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007097 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07007098 if (wpa_s->sched_scan_timed_out) {
7099 wpa_supplicant_req_sched_scan(wpa_s);
7100 } else if (wpa_s->pno_sched_pending) {
7101 wpa_s->pno_sched_pending = 0;
7102 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07007103 } else if (resched) {
7104 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08007105 }
7106
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007107 break;
7108 case EVENT_WPS_BUTTON_PUSHED:
7109#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07007110 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007111#endif /* CONFIG_WPS */
7112 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007113 case EVENT_AVOID_FREQUENCIES:
7114 wpa_supplicant_notify_avoid_freq(wpa_s, data);
7115 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08007116 case EVENT_CONNECT_FAILED_REASON:
7117#ifdef CONFIG_AP
7118 if (!wpa_s->ap_iface || !data)
7119 break;
7120 hostapd_event_connect_failed_reason(
7121 wpa_s->ap_iface->bss[0],
7122 data->connect_failed_reason.addr,
7123 data->connect_failed_reason.code);
7124#endif /* CONFIG_AP */
7125 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007126 case EVENT_NEW_PEER_CANDIDATE:
7127#ifdef CONFIG_MESH
7128 if (!wpa_s->ifmsh || !data)
7129 break;
7130 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
7131 data->mesh_peer.ies,
7132 data->mesh_peer.ie_len);
7133#endif /* CONFIG_MESH */
7134 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007135 case EVENT_SURVEY:
7136#ifdef CONFIG_AP
7137 if (!wpa_s->ap_iface)
7138 break;
7139 hostapd_event_get_survey(wpa_s->ap_iface,
7140 &data->survey_results);
7141#endif /* CONFIG_AP */
7142 break;
7143 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08007144#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007145#ifdef CONFIG_ACS
7146 if (!wpa_s->ap_iface)
7147 break;
7148 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
7149 &data->acs_selected_channels);
7150#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08007151#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007152 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007153 case EVENT_P2P_LO_STOP:
7154#ifdef CONFIG_P2P
7155 wpa_s->p2p_lo_started = 0;
7156 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
7157 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
7158 data->p2p_lo_stop.reason_code);
7159#endif /* CONFIG_P2P */
7160 break;
Paul Stewart092955c2017-02-06 09:13:09 -08007161 case EVENT_BEACON_LOSS:
7162 if (!wpa_s->current_bss || !wpa_s->current_ssid)
7163 break;
7164 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
7165 bgscan_notify_beacon_loss(wpa_s);
7166 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007167 case EVENT_EXTERNAL_AUTH:
7168#ifdef CONFIG_SAE
7169 if (!wpa_s->current_ssid) {
7170 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
7171 break;
7172 }
7173 sme_external_auth_trigger(wpa_s, data);
7174#endif /* CONFIG_SAE */
7175 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07007176#ifdef CONFIG_PASN
7177 case EVENT_PASN_AUTH:
7178 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
7179 break;
7180#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007181 case EVENT_PORT_AUTHORIZED:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007182#ifdef CONFIG_AP
7183 if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
7184 struct sta_info *sta;
7185
7186 sta = ap_get_sta(wpa_s->ap_iface->bss[0],
7187 data->port_authorized.sta_addr);
7188 if (sta)
7189 ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
7190 sta, 1);
7191 else
7192 wpa_printf(MSG_DEBUG,
7193 "No STA info matching port authorized event found");
7194 break;
7195 }
7196#endif /* CONFIG_AP */
Sunil Ravi77d572f2023-01-17 23:58:31 +00007197#ifndef CONFIG_NO_WPA
7198 if (data->port_authorized.td_bitmap_len) {
7199 wpa_printf(MSG_DEBUG,
7200 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
7201 data->port_authorized.td_bitmap[0]);
7202 wpas_transition_disable(
7203 wpa_s, data->port_authorized.td_bitmap[0]);
7204 }
7205#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007206 wpa_supplicant_event_port_authorized(wpa_s);
7207 break;
7208 case EVENT_STATION_OPMODE_CHANGED:
7209#ifdef CONFIG_AP
7210 if (!wpa_s->ap_iface || !data)
7211 break;
7212
7213 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
7214 data->sta_opmode.addr,
7215 data->sta_opmode.smps_mode,
7216 data->sta_opmode.chan_width,
7217 data->sta_opmode.rx_nss);
7218#endif /* CONFIG_AP */
7219 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07007220 case EVENT_UNPROT_BEACON:
7221 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
7222 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08007223 case EVENT_TX_WAIT_EXPIRE:
7224#ifdef CONFIG_DPP
7225 wpas_dpp_tx_wait_expire(wpa_s);
7226#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007227#ifdef CONFIG_NAN_USD
7228 wpas_nan_usd_tx_wait_expire(wpa_s);
7229#endif /* CONFIG_NAN_USD */
Hai Shalomc1a21442022-02-04 13:43:00 -08007230 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00007231 case EVENT_TID_LINK_MAP:
7232 if (data)
7233 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
7234 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007235 default:
7236 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
7237 break;
7238 }
7239}
Dmitry Shmidte4663042016-04-04 10:07:49 -07007240
7241
7242void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
7243 union wpa_event_data *data)
7244{
7245 struct wpa_supplicant *wpa_s;
7246
7247 if (event != EVENT_INTERFACE_STATUS)
7248 return;
7249
7250 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
7251 if (wpa_s && wpa_s->driver->get_ifindex) {
7252 unsigned int ifindex;
7253
7254 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
7255 if (ifindex != data->interface_status.ifindex) {
7256 wpa_dbg(wpa_s, MSG_DEBUG,
7257 "interface status ifindex %d mismatch (%d)",
7258 ifindex, data->interface_status.ifindex);
7259 return;
7260 }
7261 }
7262#ifdef CONFIG_MATCH_IFACE
7263 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
7264 struct wpa_interface *wpa_i;
7265
7266 wpa_i = wpa_supplicant_match_iface(
7267 ctx, data->interface_status.ifname);
7268 if (!wpa_i)
7269 return;
7270 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
7271 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07007272 }
7273#endif /* CONFIG_MATCH_IFACE */
7274
7275 if (wpa_s)
7276 wpa_supplicant_event(wpa_s, event, data);
7277}