blob: 30176a0c4771cd721b77e9ca53755820d5132f48 [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;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000440
441 wpabuf_free(wpa_s->pending_eapol_rx);
442 wpa_s->pending_eapol_rx = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700443}
444
445
Sunil Ravi036cec52023-03-29 11:35:17 -0700446static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447{
448 struct wpa_ie_data ie;
449 int pmksa_set = -1;
450 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800451 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700452
Hai Shalomc1a21442022-02-04 13:43:00 -0800453 /* Start with assumption of no PMKSA cache entry match for cases other
454 * than SAE. In particular, this is needed to generate the PMKSA cache
455 * entries for Suite B cases with driver-based roaming indication. */
456 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
457 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
458 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700459
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700460 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
461 ie.pmkid == NULL)
462 return;
463
464 for (i = 0; i < ie.num_pmkid; i++) {
465 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
466 ie.pmkid + i * PMKID_LEN,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000467 NULL, NULL, 0, NULL, 0,
468 true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700469 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800470 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Sunil Ravi036cec52023-03-29 11:35:17 -0700471 if (authorized)
472 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 break;
474 }
475 }
476
477 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
478 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
479}
480
481
482static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
483 union wpa_event_data *data)
484{
485 if (data == NULL) {
486 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
487 "event");
488 return;
489 }
490 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
491 " index=%d preauth=%d",
492 MAC2STR(data->pmkid_candidate.bssid),
493 data->pmkid_candidate.index,
494 data->pmkid_candidate.preauth);
495
496 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
497 data->pmkid_candidate.index,
498 data->pmkid_candidate.preauth);
499}
500
501
502static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
503{
504 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
505 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
506 return 0;
507
508#ifdef IEEE8021X_EAPOL
509 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
510 wpa_s->current_ssid &&
511 !(wpa_s->current_ssid->eapol_flags &
512 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
513 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
514 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
515 * plaintext or static WEP keys). */
516 return 0;
517 }
518#endif /* IEEE8021X_EAPOL */
519
520 return 1;
521}
522
523
524/**
525 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
526 * @wpa_s: pointer to wpa_supplicant data
527 * @ssid: Configuration data for the network
528 * Returns: 0 on success, -1 on failure
529 *
530 * This function is called when starting authentication with a network that is
531 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
532 */
533int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
534 struct wpa_ssid *ssid)
535{
536#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800537#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700538 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700540 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
541 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542 return 0;
543
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700544 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545 sim = 1;
546 aka = 1;
547 } else {
548 struct eap_method_type *eap = ssid->eap.eap_methods;
549 while (eap->vendor != EAP_VENDOR_IETF ||
550 eap->method != EAP_TYPE_NONE) {
551 if (eap->vendor == EAP_VENDOR_IETF) {
552 if (eap->method == EAP_TYPE_SIM)
553 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700554 else if (eap->method == EAP_TYPE_AKA ||
555 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556 aka = 1;
557 }
558 eap++;
559 }
560 }
561
562 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
563 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700564 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
565 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
566 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567 aka = 0;
568
569 if (!sim && !aka) {
570 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
571 "use SIM, but neither EAP-SIM nor EAP-AKA are "
572 "enabled");
573 return 0;
574 }
575
576 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
577 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700578
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700579 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580 if (wpa_s->scard == NULL) {
581 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
582 "(pcsc-lite)");
583 return -1;
584 }
585 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
586 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800587#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700588#endif /* IEEE8021X_EAPOL */
589
590 return 0;
591}
592
593
594#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700595
Hai Shalomfdcde762020-04-02 11:19:20 -0700596#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700597static int has_wep_key(struct wpa_ssid *ssid)
598{
599 int i;
600
601 for (i = 0; i < NUM_WEP_KEYS; i++) {
602 if (ssid->wep_key_len[i])
603 return 1;
604 }
605
606 return 0;
607}
Hai Shalomfdcde762020-04-02 11:19:20 -0700608#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700609
610
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700611static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700612 struct wpa_ssid *ssid)
613{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700614 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700615
616 if (ssid->mixed_cell)
617 return 1;
618
619#ifdef CONFIG_WPS
620 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
621 return 1;
622#endif /* CONFIG_WPS */
623
Roshan Pius3a1667e2018-07-03 15:17:14 -0700624#ifdef CONFIG_OWE
625 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
626 return 1;
627#endif /* CONFIG_OWE */
628
Hai Shalomfdcde762020-04-02 11:19:20 -0700629#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700630 if (has_wep_key(ssid))
631 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700632#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700633
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700634#ifdef IEEE8021X_EAPOL
635 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
636 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
637 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
638 privacy = 1;
639#endif /* IEEE8021X_EAPOL */
640
Jouni Malinen75ecf522011-06-27 15:19:46 -0700641 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
642 privacy = 1;
643
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800644 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
645 privacy = 1;
646
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647 if (bss->caps & IEEE80211_CAP_PRIVACY)
648 return privacy;
649 return !privacy;
650}
651
652
653static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
654 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800655 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656{
657 struct wpa_ie_data ie;
658 int proto_match = 0;
659 const u8 *rsn_ie, *wpa_ie;
660 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700661#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700663#endif /* CONFIG_WEP */
Sunil Ravi640215c2023-06-28 23:08:09 +0000664 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665
666 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
667 if (ret >= 0)
668 return ret;
669
Hai Shalomfdcde762020-04-02 11:19:20 -0700670#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
672 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
673 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
674 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
675 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700676#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677
Sunil Ravi7f769292024-07-23 22:21:32 +0000678 rsn_ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
Sunil Ravi640215c2023-06-28 23:08:09 +0000679 if (is_6ghz_bss && !rsn_ie) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700680 if (debug_print)
681 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000682 " skip - 6 GHz BSS without RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700683 return 0;
684 }
685
Roshan Pius3a1667e2018-07-03 15:17:14 -0700686 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700687 proto_match++;
688
689 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800690 if (debug_print)
691 wpa_dbg(wpa_s, MSG_DEBUG,
692 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693 break;
694 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700695 if (!ie.has_pairwise)
696 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
697 if (!ie.has_group)
698 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700699
Sunil Ravi640215c2023-06-28 23:08:09 +0000700 if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
701 /* WEP and TKIP are not allowed on 6 GHz/MLD */
Sunil Ravia04bd252022-05-02 22:54:18 -0700702 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
703 WPA_CIPHER_WEP104 |
704 WPA_CIPHER_TKIP);
705 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
706 WPA_CIPHER_WEP104 |
707 WPA_CIPHER_TKIP);
708 }
709
Hai Shalomfdcde762020-04-02 11:19:20 -0700710#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700711 if (wep_ok &&
712 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
713 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800714 if (debug_print)
715 wpa_dbg(wpa_s, MSG_DEBUG,
716 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 return 1;
718 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700719#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720
Roshan Pius3a1667e2018-07-03 15:17:14 -0700721 if (!(ie.proto & ssid->proto) &&
722 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800723 if (debug_print)
724 wpa_dbg(wpa_s, MSG_DEBUG,
725 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700726 break;
727 }
728
729 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800730 if (debug_print)
731 wpa_dbg(wpa_s, MSG_DEBUG,
732 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 break;
734 }
735
736 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800737 if (debug_print)
738 wpa_dbg(wpa_s, MSG_DEBUG,
739 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740 break;
741 }
742
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700743 if (ssid->group_mgmt_cipher &&
744 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
745 if (debug_print)
746 wpa_dbg(wpa_s, MSG_DEBUG,
747 " skip RSN IE - group mgmt cipher mismatch");
748 break;
749 }
750
Sunil Ravi640215c2023-06-28 23:08:09 +0000751 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700752 /* MFPC must be supported on 6 GHz */
753 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
754 if (debug_print)
755 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000756 " skip RSNE - 6 GHz without MFPC");
Sunil Ravia04bd252022-05-02 22:54:18 -0700757 break;
758 }
759
760 /* WPA PSK is not allowed on the 6 GHz band */
761 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
762 WPA_KEY_MGMT_FT_PSK |
763 WPA_KEY_MGMT_PSK_SHA256);
764 }
765
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800767 if (debug_print)
768 wpa_dbg(wpa_s, MSG_DEBUG,
769 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 break;
771 }
772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800774 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800775 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800776 if (debug_print)
777 wpa_dbg(wpa_s, MSG_DEBUG,
778 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779 break;
780 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800781 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
782 wpas_get_ssid_pmf(wpa_s, ssid) ==
783 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800784 if (debug_print)
785 wpa_dbg(wpa_s, MSG_DEBUG,
786 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800787 break;
788 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800790 if (debug_print)
791 wpa_dbg(wpa_s, MSG_DEBUG,
792 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700793 return 1;
794 }
795
Sunil Ravi640215c2023-06-28 23:08:09 +0000796 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700797 if (debug_print)
798 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000799 " skip - 6 GHz BSS without matching RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700800 return 0;
801 }
802
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000803 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
804
Roshan Pius3a1667e2018-07-03 15:17:14 -0700805 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
806 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000807#ifdef CONFIG_OWE
808 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && ssid->owe_only &&
809 !wpa_ie && !rsn_ie &&
810 wpa_s->owe_transition_select &&
811 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
812 ssid->owe_transition_bss_select_count + 1 <=
813 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
814 ssid->owe_transition_bss_select_count++;
815 if (debug_print)
816 wpa_dbg(wpa_s, MSG_DEBUG,
817 " skip OWE open BSS (selection count %d does not exceed %d)",
818 ssid->owe_transition_bss_select_count,
819 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
820 wpa_s->owe_transition_search = 1;
821 return 0;
822 }
823#endif /* CONFIG_OWE */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800824 if (debug_print)
825 wpa_dbg(wpa_s, MSG_DEBUG,
826 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700827 return 0;
828 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700829
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700830 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
831 proto_match++;
832
833 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800834 if (debug_print)
835 wpa_dbg(wpa_s, MSG_DEBUG,
836 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837 break;
838 }
839
Hai Shalomfdcde762020-04-02 11:19:20 -0700840#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841 if (wep_ok &&
842 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
843 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800844 if (debug_print)
845 wpa_dbg(wpa_s, MSG_DEBUG,
846 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847 return 1;
848 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700849#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850
851 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800852 if (debug_print)
853 wpa_dbg(wpa_s, MSG_DEBUG,
854 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700855 break;
856 }
857
858 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800859 if (debug_print)
860 wpa_dbg(wpa_s, MSG_DEBUG,
861 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862 break;
863 }
864
865 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800866 if (debug_print)
867 wpa_dbg(wpa_s, MSG_DEBUG,
868 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869 break;
870 }
871
872 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800873 if (debug_print)
874 wpa_dbg(wpa_s, MSG_DEBUG,
875 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700876 break;
877 }
878
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800879 if (debug_print)
880 wpa_dbg(wpa_s, MSG_DEBUG,
881 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882 return 1;
883 }
884
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700885 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
886 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800887 if (debug_print)
888 wpa_dbg(wpa_s, MSG_DEBUG,
889 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700890 return 1;
891 }
892
Roshan Pius3a1667e2018-07-03 15:17:14 -0700893#ifdef CONFIG_OWE
894 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
895 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800896 if (wpa_s->owe_transition_select &&
897 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
898 ssid->owe_transition_bss_select_count + 1 <=
899 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
900 ssid->owe_transition_bss_select_count++;
901 if (debug_print)
902 wpa_dbg(wpa_s, MSG_DEBUG,
903 " skip OWE transition BSS (selection count %d does not exceed %d)",
904 ssid->owe_transition_bss_select_count,
905 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
906 wpa_s->owe_transition_search = 1;
907 return 0;
908 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700909 if (debug_print)
910 wpa_dbg(wpa_s, MSG_DEBUG,
911 " allow in OWE transition mode");
912 return 1;
913 }
914#endif /* CONFIG_OWE */
915
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
917 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800918 if (debug_print)
919 wpa_dbg(wpa_s, MSG_DEBUG,
920 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700921 return 0;
922 }
923
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800924 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
925 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800926 if (debug_print)
927 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800928 return 1;
929 }
930
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800932 if (debug_print)
933 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934 return 1;
935 }
936
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800937 if (debug_print)
938 wpa_dbg(wpa_s, MSG_DEBUG,
939 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700940
941 return 0;
942}
943
944
945static int freq_allowed(int *freqs, int freq)
946{
947 int i;
948
949 if (freqs == NULL)
950 return 1;
951
952 for (i = 0; freqs[i]; i++)
953 if (freqs[i] == freq)
954 return 1;
955 return 0;
956}
957
958
Hai Shalomfdcde762020-04-02 11:19:20 -0700959static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
960 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800961{
962 const struct hostapd_hw_modes *mode = NULL, *modes;
963 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
964 const u8 *rate_ie;
965 int i, j, k;
966
967 if (bss->freq == 0)
968 return 1; /* Cannot do matching without knowing band */
969
970 modes = wpa_s->hw.modes;
971 if (modes == NULL) {
972 /*
973 * The driver does not provide any additional information
974 * about the utilized hardware, so allow the connection attempt
975 * to continue.
976 */
977 return 1;
978 }
979
980 for (i = 0; i < wpa_s->hw.num_modes; i++) {
981 for (j = 0; j < modes[i].num_channels; j++) {
982 int freq = modes[i].channels[j].freq;
983 if (freq == bss->freq) {
984 if (mode &&
985 mode->mode == HOSTAPD_MODE_IEEE80211G)
986 break; /* do not allow 802.11b replace
987 * 802.11g */
988 mode = &modes[i];
989 break;
990 }
991 }
992 }
993
994 if (mode == NULL)
995 return 0;
996
997 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700998 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800999 if (rate_ie == NULL)
1000 continue;
1001
1002 for (j = 2; j < rate_ie[1] + 2; j++) {
1003 int flagged = !!(rate_ie[j] & 0x80);
1004 int r = (rate_ie[j] & 0x7f) * 5;
1005
1006 /*
1007 * IEEE Std 802.11n-2009 7.3.2.2:
1008 * The new BSS Membership selector value is encoded
1009 * like a legacy basic rate, but it is not a rate and
1010 * only indicates if the BSS members are required to
1011 * support the mandatory features of Clause 20 [HT PHY]
1012 * in order to join the BSS.
1013 */
1014 if (flagged && ((rate_ie[j] & 0x7f) ==
1015 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
1016 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001017 if (debug_print)
1018 wpa_dbg(wpa_s, MSG_DEBUG,
1019 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001020 return 0;
1021 }
1022 continue;
1023 }
1024
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001025 /* There's also a VHT selector for 802.11ac */
1026 if (flagged && ((rate_ie[j] & 0x7f) ==
1027 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
1028 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001029 if (debug_print)
1030 wpa_dbg(wpa_s, MSG_DEBUG,
1031 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001032 return 0;
1033 }
1034 continue;
1035 }
1036
Sunil Ravi77d572f2023-01-17 23:58:31 +00001037 if (flagged && ((rate_ie[j] & 0x7f) ==
1038 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
1039 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
1040 if (debug_print)
1041 wpa_dbg(wpa_s, MSG_DEBUG,
1042 " hardware does not support HE PHY");
1043 return 0;
1044 }
1045 continue;
1046 }
1047
Hai Shalomc3565922019-10-28 11:58:20 -07001048#ifdef CONFIG_SAE
1049 if (flagged && ((rate_ie[j] & 0x7f) ==
1050 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001051 if (wpas_get_ssid_sae_pwe(wpa_s, ssid) ==
Sunil Ravi77d572f2023-01-17 23:58:31 +00001052 SAE_PWE_HUNT_AND_PECK &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001053 !ssid->sae_password_id &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001054 !is_6ghz_freq(bss->freq) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001055 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -07001056 if (debug_print)
1057 wpa_dbg(wpa_s, MSG_DEBUG,
1058 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001059#ifdef CONFIG_TESTING_OPTIONS
1060 if (wpa_s->ignore_sae_h2e_only) {
1061 wpa_dbg(wpa_s, MSG_DEBUG,
1062 "TESTING: Ignore SAE H2E requirement mismatch");
1063 continue;
1064 }
1065#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -07001066 return 0;
1067 }
1068 continue;
1069 }
1070#endif /* CONFIG_SAE */
1071
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001072 if (!flagged)
1073 continue;
1074
1075 /* check for legacy basic rates */
1076 for (k = 0; k < mode->num_rates; k++) {
1077 if (mode->rates[k] == r)
1078 break;
1079 }
1080 if (k == mode->num_rates) {
1081 /*
1082 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1083 * order to join a BSS all required rates
1084 * have to be supported by the hardware.
1085 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001086 if (debug_print)
1087 wpa_dbg(wpa_s, MSG_DEBUG,
1088 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1089 r / 10, r % 10,
1090 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001091 return 0;
1092 }
1093 }
1094 }
1095
1096 return 1;
1097}
1098
1099
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001100/*
1101 * Test whether BSS is in an ESS.
1102 * This is done differently in DMG (60 GHz) and non-DMG bands
1103 */
1104static int bss_is_ess(struct wpa_bss *bss)
1105{
1106 if (bss_is_dmg(bss)) {
1107 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1108 IEEE80211_CAP_DMG_AP;
1109 }
1110
1111 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1112 IEEE80211_CAP_ESS);
1113}
1114
1115
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001116static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1117{
1118 size_t i;
1119
1120 for (i = 0; i < ETH_ALEN; i++) {
1121 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1122 return 0;
1123 }
1124 return 1;
1125}
1126
1127
1128static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1129{
1130 size_t i;
1131
1132 for (i = 0; i < num; i++) {
1133 const u8 *a = list + i * ETH_ALEN * 2;
1134 const u8 *m = a + ETH_ALEN;
1135
1136 if (match_mac_mask(a, addr, m))
1137 return 1;
1138 }
1139 return 0;
1140}
1141
1142
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001143static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1144 const u8 **ret_ssid, size_t *ret_ssid_len)
1145{
1146#ifdef CONFIG_OWE
Sunil Ravic0f5d412024-09-11 22:12:49 +00001147 const u8 *owe, *bssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001148
1149 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
Sunil Ravi7f769292024-07-23 22:21:32 +00001150 if (!owe || !wpa_bss_get_rsne(wpa_s, bss, NULL, false))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001151 return;
1152
Sunil Ravic0f5d412024-09-11 22:12:49 +00001153 if (wpas_get_owe_trans_network(owe, &bssid, ret_ssid, ret_ssid_len))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001154 return;
1155
1156 /* Match the profile SSID against the OWE transition mode SSID on the
1157 * open network. */
1158 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
Sunil Ravic0f5d412024-09-11 22:12:49 +00001159 " SSID: %s", MAC2STR(bssid),
1160 wpa_ssid_txt(*ret_ssid, *ret_ssid_len));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001161
Hai Shalomfdcde762020-04-02 11:19:20 -07001162 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1163 struct wpa_ssid *ssid;
1164
1165 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1166 if (wpas_network_disabled(wpa_s, ssid))
1167 continue;
Sunil Ravic0f5d412024-09-11 22:12:49 +00001168 if (ssid->ssid_len == *ret_ssid_len &&
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001169 os_memcmp(ssid->ssid, *ret_ssid, *ret_ssid_len) ==
1170 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001171 /* OWE BSS in transition mode for a currently
1172 * enabled OWE network. */
1173 wpa_dbg(wpa_s, MSG_DEBUG,
1174 "OWE: transition mode OWE SSID for active OWE profile");
1175 bss->flags |= WPA_BSS_OWE_TRANSITION;
1176 break;
1177 }
1178 }
1179 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001180#endif /* CONFIG_OWE */
1181}
1182
1183
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001184static bool wpas_valid_ml_bss(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001185{
1186 u16 removed_links;
1187
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001188 if (wpa_bss_parse_basic_ml_element(wpa_s, bss, NULL, NULL, NULL, NULL))
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001189 return true;
1190
Sunil Ravi99c035e2024-07-12 01:42:03 +00001191 if (!bss->valid_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001192 return true;
1193
1194 /* Check if the current BSS is going to be removed */
1195 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss);
Sunil Ravi99c035e2024-07-12 01:42:03 +00001196 if (BIT(bss->mld_link_id) & removed_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001197 return false;
1198
1199 return true;
1200}
1201
1202
Sunil Ravi26978f32021-04-30 15:19:18 -07001203int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001204{
1205 int i, j;
1206
1207 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1208 return 0;
1209
1210 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1211 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1212
1213 for (i = 0; i < mode->num_channels; i++) {
1214 struct hostapd_channel_data *chan = &mode->channels[i];
1215
1216 if (chan->freq == freq)
1217 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1218 }
1219 }
1220
1221 return 1;
1222}
1223
1224
Hai Shalom899fcc72020-10-19 14:38:18 -07001225static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1226 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001227 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001228 bool debug_print);
1229
1230
1231#ifdef CONFIG_SAE_PK
1232static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1233 struct wpa_bss *orig_bss,
1234 struct wpa_ssid *ssid,
1235 const u8 *match_ssid,
1236 size_t match_ssid_len)
1237{
1238 struct wpa_bss *bss;
1239
1240 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1241 int count;
1242 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001243
1244 if (bss == orig_bss)
1245 continue;
Sunil Ravi7f769292024-07-23 22:21:32 +00001246 ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
Hai Shalomc1a21442022-02-04 13:43:00 -08001247 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001248 continue;
1249
1250 /* TODO: Could be more thorough in checking what kind of
1251 * signal strength or throughput estimate would be acceptable
1252 * compared to the originally selected BSS. */
1253 if (bss->est_throughput < 2000)
1254 return false;
1255
Hai Shalom60840252021-02-19 19:02:11 -08001256 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001257 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1258 bss, count, 0))
1259 return true;
1260 }
1261
1262 return false;
1263}
1264#endif /* CONFIG_SAE_PK */
1265
1266
1267static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1268 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001269 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001270 bool debug_print)
1271{
1272 int res;
1273 bool wpa, check_ssid, osen, rsn_osen = false;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001274#ifndef CONFIG_NO_WPA
Hai Shalom899fcc72020-10-19 14:38:18 -07001275 struct wpa_ie_data data;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001276#endif /* CONFIG_NO_WPA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001277#ifdef CONFIG_MBO
1278 const u8 *assoc_disallow;
1279#endif /* CONFIG_MBO */
1280#ifdef CONFIG_SAE
1281 u8 rsnxe_capa = 0;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001282 enum sae_pwe sae_pwe;
Hai Shalom899fcc72020-10-19 14:38:18 -07001283#endif /* CONFIG_SAE */
1284 const u8 *ie;
1285
1286 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1287 wpa = ie && ie[1];
Sunil Ravi7f769292024-07-23 22:21:32 +00001288 ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
Hai Shalom899fcc72020-10-19 14:38:18 -07001289 wpa |= ie && ie[1];
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001290#ifndef CONFIG_NO_WPA
Hai Shalom899fcc72020-10-19 14:38:18 -07001291 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1292 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1293 rsn_osen = true;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001294#endif /* CONFIG_NO_WPA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001295 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1296 osen = ie != NULL;
1297
1298#ifdef CONFIG_SAE
Sunil Ravi7f769292024-07-23 22:21:32 +00001299 ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
1300 if (ie && ie[0] == WLAN_EID_VENDOR_SPECIFIC && ie[1] >= 4 + 1)
1301 rsnxe_capa = ie[4 + 2];
1302 else if (ie && ie[1] >= 1)
Hai Shalom899fcc72020-10-19 14:38:18 -07001303 rsnxe_capa = ie[2];
1304#endif /* CONFIG_SAE */
1305
1306 check_ssid = wpa || ssid->ssid_len > 0;
1307
1308 if (wpas_network_disabled(wpa_s, ssid)) {
1309 if (debug_print)
1310 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1311 return false;
1312 }
1313
1314 res = wpas_temp_disabled(wpa_s, ssid);
1315 if (res > 0) {
1316 if (debug_print)
1317 wpa_dbg(wpa_s, MSG_DEBUG,
1318 " skip - disabled temporarily for %d second(s)",
1319 res);
1320 return false;
1321 }
1322
1323#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001324 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001325 if (debug_print)
1326 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001327 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001328 return false;
1329 }
1330
1331 if (wpa && ssid->ssid_len == 0 &&
1332 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1333 check_ssid = false;
1334
1335 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1336 /* Only allow wildcard SSID match if an AP advertises active
1337 * WPS operation that matches our mode. */
1338 check_ssid = ssid->ssid_len > 0 ||
1339 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1340 }
1341#endif /* CONFIG_WPS */
1342
1343 if (ssid->bssid_set && ssid->ssid_len == 0 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001344 ether_addr_equal(bss->bssid, ssid->bssid))
Hai Shalom899fcc72020-10-19 14:38:18 -07001345 check_ssid = false;
1346
1347 if (check_ssid &&
1348 (match_ssid_len != ssid->ssid_len ||
1349 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1350 if (debug_print)
1351 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1352 return false;
1353 }
1354
1355 if (ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001356 !ether_addr_equal(bss->bssid, ssid->bssid)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001357 if (debug_print)
1358 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1359 return false;
1360 }
1361
Hai Shalom60840252021-02-19 19:02:11 -08001362 /* check the list of BSSIDs to ignore */
1363 if (ssid->num_bssid_ignore &&
1364 addr_in_list(bss->bssid, ssid->bssid_ignore,
1365 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001366 if (debug_print)
1367 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001368 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001369 return false;
1370 }
1371
Hai Shalom60840252021-02-19 19:02:11 -08001372 /* if there is a list of accepted BSSIDs, only accept those APs */
1373 if (ssid->num_bssid_accept &&
1374 !addr_in_list(bss->bssid, ssid->bssid_accept,
1375 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001376 if (debug_print)
1377 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001378 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001379 return false;
1380 }
1381
1382 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1383 return false;
1384
1385 if (!osen && !wpa &&
1386 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1387 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1388 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1389 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1390 if (debug_print)
1391 wpa_dbg(wpa_s, MSG_DEBUG,
1392 " skip - non-WPA network not allowed");
1393 return false;
1394 }
1395
1396#ifdef CONFIG_WEP
1397 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1398 if (debug_print)
1399 wpa_dbg(wpa_s, MSG_DEBUG,
1400 " skip - ignore WPA/WPA2 AP for WEP network block");
1401 return false;
1402 }
1403#endif /* CONFIG_WEP */
1404
1405 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1406 if (debug_print)
1407 wpa_dbg(wpa_s, MSG_DEBUG,
1408 " skip - non-OSEN network not allowed");
1409 return false;
1410 }
1411
1412 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1413 if (debug_print)
1414 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1415 return false;
1416 }
1417
1418 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1419 !bss_is_pbss(bss)) {
1420 if (debug_print)
1421 wpa_dbg(wpa_s, MSG_DEBUG,
1422 " skip - not ESS, PBSS, or MBSS");
1423 return false;
1424 }
1425
1426 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1427 if (debug_print)
1428 wpa_dbg(wpa_s, MSG_DEBUG,
1429 " skip - PBSS mismatch (ssid %d bss %d)",
1430 ssid->pbss, bss_is_pbss(bss));
1431 return false;
1432 }
1433
1434 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1435 if (debug_print)
1436 wpa_dbg(wpa_s, MSG_DEBUG,
1437 " skip - frequency not allowed");
1438 return false;
1439 }
1440
1441#ifdef CONFIG_MESH
1442 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1443 ssid->frequency != bss->freq) {
1444 if (debug_print)
1445 wpa_dbg(wpa_s, MSG_DEBUG,
1446 " skip - frequency not allowed (mesh)");
1447 return false;
1448 }
1449#endif /* CONFIG_MESH */
1450
1451 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1452 if (debug_print)
1453 wpa_dbg(wpa_s, MSG_DEBUG,
1454 " skip - rate sets do not match");
1455 return false;
1456 }
1457
1458#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001459 /* When using SAE Password Identifier and when operationg on the 6 GHz
1460 * band, only H2E is allowed. */
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001461 sae_pwe = wpas_get_ssid_sae_pwe(wpa_s, ssid);
1462 if ((sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00001463 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001464 sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001465 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001466#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301467 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001468#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001469 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1470 if (debug_print)
1471 wpa_dbg(wpa_s, MSG_DEBUG,
1472 " skip - SAE H2E required, but not supported by the AP");
1473 return false;
1474 }
1475#endif /* CONFIG_SAE */
1476
1477#ifdef CONFIG_SAE_PK
1478 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1479 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1480 if (debug_print)
1481 wpa_dbg(wpa_s, MSG_DEBUG,
1482 " skip - SAE-PK required, but not supported by the AP");
1483 return false;
1484 }
1485#endif /* CONFIG_SAE_PK */
1486
1487#ifndef CONFIG_IBSS_RSN
1488 if (ssid->mode == WPAS_MODE_IBSS &&
1489 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1490 if (debug_print)
1491 wpa_dbg(wpa_s, MSG_DEBUG,
1492 " skip - IBSS RSN not supported in the build");
1493 return false;
1494 }
1495#endif /* !CONFIG_IBSS_RSN */
1496
1497#ifdef CONFIG_P2P
1498 if (ssid->p2p_group &&
1499 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1500 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1501 if (debug_print)
1502 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1503 return false;
1504 }
1505
1506 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1507 struct wpabuf *p2p_ie;
1508 u8 dev_addr[ETH_ALEN];
1509
1510 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1511 if (!ie) {
1512 if (debug_print)
1513 wpa_dbg(wpa_s, MSG_DEBUG,
1514 " skip - no P2P element");
1515 return false;
1516 }
1517 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1518 if (!p2p_ie) {
1519 if (debug_print)
1520 wpa_dbg(wpa_s, MSG_DEBUG,
1521 " skip - could not fetch P2P element");
1522 return false;
1523 }
1524
1525 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001526 !ether_addr_equal(dev_addr, ssid->go_p2p_dev_addr)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001527 if (debug_print)
1528 wpa_dbg(wpa_s, MSG_DEBUG,
1529 " skip - no matching GO P2P Device Address in P2P element");
1530 wpabuf_free(p2p_ie);
1531 return false;
1532 }
1533 wpabuf_free(p2p_ie);
1534 }
1535
1536 /*
1537 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1538 * P2P Group Capability Bitmap and we are not in Group Formation with
1539 * that device.
1540 */
1541#endif /* CONFIG_P2P */
1542
1543 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1544 struct os_reltime diff;
1545
1546 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1547 if (debug_print)
1548 wpa_dbg(wpa_s, MSG_DEBUG,
1549 " skip - scan result not recent enough (%u.%06u seconds too old)",
1550 (unsigned int) diff.sec,
1551 (unsigned int) diff.usec);
1552 return false;
1553 }
1554#ifdef CONFIG_MBO
1555#ifdef CONFIG_TESTING_OPTIONS
1556 if (wpa_s->ignore_assoc_disallow)
1557 goto skip_assoc_disallow;
1558#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001559 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001560 if (assoc_disallow && assoc_disallow[1] >= 1) {
1561 if (debug_print)
1562 wpa_dbg(wpa_s, MSG_DEBUG,
1563 " skip - MBO association disallowed (reason %u)",
1564 assoc_disallow[2]);
1565 return false;
1566 }
1567
1568 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1569 if (debug_print)
1570 wpa_dbg(wpa_s, MSG_DEBUG,
1571 " skip - AP temporarily disallowed");
1572 return false;
1573 }
1574#ifdef CONFIG_TESTING_OPTIONS
1575skip_assoc_disallow:
1576#endif /* CONFIG_TESTING_OPTIONS */
1577#endif /* CONFIG_MBO */
1578
1579#ifdef CONFIG_DPP
1580 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001581 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1582 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001583 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1584 !ssid->dpp_csign)) {
1585 if (debug_print)
1586 wpa_dbg(wpa_s, MSG_DEBUG,
1587 " skip - no PMKSA entry for DPP");
1588 return false;
1589 }
1590#endif /* CONFIG_DPP */
1591
1592#ifdef CONFIG_SAE_PK
1593 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1594 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1595 ((ssid->sae_password &&
1596 sae_pk_valid_password(ssid->sae_password)) ||
1597 (!ssid->sae_password && ssid->passphrase &&
1598 sae_pk_valid_password(ssid->passphrase))) &&
1599 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1600 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1601 match_ssid_len)) {
1602 if (debug_print)
1603 wpa_dbg(wpa_s, MSG_DEBUG,
1604 " skip - another acceptable BSS with SAE-PK in the same ESS");
1605 return false;
1606 }
1607#endif /* CONFIG_SAE_PK */
1608
1609 if (bss->ssid_len == 0) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001610#ifdef CONFIG_OWE
1611 const u8 *owe_ssid = NULL;
1612 size_t owe_ssid_len = 0;
1613
1614 owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len);
1615 if (owe_ssid && owe_ssid_len &&
1616 owe_ssid_len == ssid->ssid_len &&
1617 os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) {
1618 if (debug_print)
1619 wpa_dbg(wpa_s, MSG_DEBUG,
1620 " skip - no SSID in BSS entry for a possible OWE transition mode BSS");
1621 int_array_add_unique(&wpa_s->owe_trans_scan_freq,
1622 bss->freq);
1623 return false;
1624 }
1625#endif /* CONFIG_OWE */
Hai Shalom899fcc72020-10-19 14:38:18 -07001626 if (debug_print)
1627 wpa_dbg(wpa_s, MSG_DEBUG,
1628 " skip - no SSID known for the BSS");
1629 return false;
1630 }
1631
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001632 if (!wpas_valid_ml_bss(wpa_s, bss)) {
1633 if (debug_print)
1634 wpa_dbg(wpa_s, MSG_DEBUG,
1635 " skip - ML BSS going to be removed");
1636 return false;
1637 }
1638
Hai Shalom899fcc72020-10-19 14:38:18 -07001639 /* Matching configuration found */
1640 return true;
1641}
1642
1643
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001644struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1645 int i, struct wpa_bss *bss,
1646 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001647 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001648{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001649 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001650 const u8 *ie;
1651 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001652 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001653 const u8 *match_ssid;
1654 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001655 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001656
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001657 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001658 wpa_ie_len = ie ? ie[1] : 0;
1659
Sunil Ravi7f769292024-07-23 22:21:32 +00001660 ie = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001661 rsn_ie_len = ie ? ie[1] : 0;
1662
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001663 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1664 osen = ie != NULL;
1665
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001666 if (debug_print) {
1667 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1668 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1669 i, MAC2STR(bss->bssid),
1670 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1671 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1672 bss->freq,
1673 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1674 " wps" : "",
1675 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1676 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1677 ? " p2p" : "",
1678 osen ? " osen=1" : "");
1679 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680
Hai Shalom60840252021-02-19 19:02:11 -08001681 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1682 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001683 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001684 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001685 /*
1686 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001687 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001688 * should not be done with multiple enabled networks to
1689 * avoid getting forced to move into a worse ESS on
1690 * single error if there are no other BSSes of the
1691 * current ESS.
1692 */
1693 limit = 0;
1694 }
Hai Shalom60840252021-02-19 19:02:11 -08001695 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001696 if (debug_print) {
1697 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001698 " skip - BSSID ignored (count=%d limit=%d)",
1699 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001700 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001701 return NULL;
1702 }
1703 }
1704
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001705 match_ssid = bss->ssid;
1706 match_ssid_len = bss->ssid_len;
1707 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1708
1709 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001710 if (debug_print)
1711 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001712 return NULL;
1713 }
1714
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001715 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001716 if (debug_print)
1717 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001718 return NULL;
1719 }
1720
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001721 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001722 if (debug_print)
1723 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001724 return NULL;
1725 }
1726
Hai Shalomfdcde762020-04-02 11:19:20 -07001727 if (disabled_freq(wpa_s, bss->freq)) {
1728 if (debug_print)
1729 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1730 return NULL;
1731 }
1732
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001733 if (wnm_is_bss_excluded(wpa_s, bss)) {
1734 if (debug_print)
1735 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID excluded");
1736 return NULL;
1737 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001738
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001739 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001740 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001741 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001742 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743 }
1744
1745 /* No matching configuration found */
1746 return NULL;
1747}
1748
1749
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001750struct wpa_bss *
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001751wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001752 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001753 struct wpa_ssid **selected_ssid,
1754 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001755{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001756 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001758 if (wpa_s->current_ssid) {
1759 struct wpa_ssid *ssid;
1760
1761 wpa_dbg(wpa_s, MSG_DEBUG,
1762 "Scan results matching the currently selected network");
1763 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1764 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1765
1766 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1767 only_first_ssid, 0);
1768 if (ssid != wpa_s->current_ssid)
1769 continue;
1770 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1771 " freq=%d level=%d snr=%d est_throughput=%u",
1772 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1773 bss->snr, bss->est_throughput);
1774 }
1775 }
1776
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001777 if (only_first_ssid)
1778 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1779 group->id);
1780 else
1781 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1782 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001783
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001784 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1785 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001786
1787 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001788 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001789 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001790 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001791 if (!*selected_ssid)
1792 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001793 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001794 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001795 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001796 MAC2STR(bss->bssid),
1797 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1798 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001799 }
1800
1801 return NULL;
1802}
1803
1804
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001805struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1806 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001807{
1808 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001809 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001810 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001811 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001812
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001813 if (wpa_s->last_scan_res == NULL ||
1814 wpa_s->last_scan_res_used == 0)
1815 return NULL; /* no scan results from last update */
1816
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001817 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001818 /* check that next_ssid is still valid */
1819 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1820 if (ssid == wpa_s->next_ssid)
1821 break;
1822 }
1823 next_ssid = ssid;
1824 wpa_s->next_ssid = NULL;
1825 }
1826
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001828 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1829 if (next_ssid && next_ssid->priority ==
1830 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001831 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001832 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001833 if (selected)
1834 break;
1835 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001836 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001837 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001838 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001839 if (selected)
1840 break;
1841 }
1842
Sunil Ravi99c035e2024-07-12 01:42:03 +00001843 if (!selected &&
1844 (wpa_s->bssid_ignore || wnm_active_bss_trans_mgmt(wpa_s)) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001845 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001846 wpa_dbg(wpa_s, MSG_DEBUG,
1847 "No APs found - clear BSSID ignore list and try again");
Sunil Ravi99c035e2024-07-12 01:42:03 +00001848 wnm_btm_reset(wpa_s);
Hai Shalom60840252021-02-19 19:02:11 -08001849 wpa_bssid_ignore_clear(wpa_s);
1850 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001851 } else if (selected == NULL)
1852 break;
1853 }
1854
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001855 ssid = *selected_ssid;
1856 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1857 !ssid->passphrase && !ssid->ext_psk) {
1858 const char *field_name, *txt = NULL;
1859
1860 wpa_dbg(wpa_s, MSG_DEBUG,
1861 "PSK/passphrase not yet available for the selected network");
1862
1863 wpas_notify_network_request(wpa_s, ssid,
1864 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1865
1866 field_name = wpa_supplicant_ctrl_req_to_string(
1867 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1868 if (field_name == NULL)
1869 return NULL;
1870
1871 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1872
1873 selected = NULL;
1874 }
1875
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001876 return selected;
1877}
1878
1879
1880static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1881 int timeout_sec, int timeout_usec)
1882{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001883 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001884 /*
1885 * No networks are enabled; short-circuit request so
1886 * we don't wait timeout seconds before transitioning
1887 * to INACTIVE state.
1888 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001889 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1890 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001891 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1892 return;
1893 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001894
1895 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001896 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1897}
1898
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001899
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001900static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s)
1901{
1902 if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss)
1903 return false;
1904
1905 wpa_msg(wpa_s, MSG_DEBUG,
1906 "Request association with " MACSTR " after ML probe",
1907 MAC2STR(wpa_s->ml_connect_probe_bss->bssid));
1908
1909 wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss,
1910 wpa_s->ml_connect_probe_ssid);
1911
1912 wpa_s->ml_connect_probe_ssid = NULL;
1913 wpa_s->ml_connect_probe_bss = NULL;
1914
1915 return true;
1916}
1917
1918
1919static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s,
1920 struct wpa_bss *selected,
1921 struct wpa_ssid *ssid)
1922{
1923 int *freqs;
1924 u16 missing_links = 0, removed_links;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001925 u8 ap_mld_id;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001926
1927 if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
1928 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)))
1929 return 0;
1930
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001931 if (wpa_bss_parse_basic_ml_element(wpa_s, selected, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001932 &missing_links, ssid,
1933 &ap_mld_id) ||
1934 !missing_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001935 return 0;
1936
1937 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected);
1938 missing_links &= ~removed_links;
1939
1940 if (!missing_links)
1941 return 0;
1942
1943 wpa_dbg(wpa_s, MSG_DEBUG,
1944 "MLD: Doing an ML probe for missing links 0x%04x",
1945 missing_links);
1946
1947 freqs = os_malloc(sizeof(int) * 2);
1948 if (!freqs)
1949 return 0;
1950
1951 wpa_s->ml_connect_probe_ssid = ssid;
1952 wpa_s->ml_connect_probe_bss = selected;
1953
1954 freqs[0] = selected->freq;
1955 freqs[1] = 0;
1956
1957 wpa_s->manual_scan_passive = 0;
1958 wpa_s->manual_scan_use_id = 0;
1959 wpa_s->manual_scan_only_new = 0;
1960 wpa_s->scan_id_count = 0;
1961 os_free(wpa_s->manual_scan_freqs);
1962 wpa_s->manual_scan_freqs = freqs;
1963
1964 os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001965
1966 /*
1967 * In case the ML probe request is intended to retrieve information from
1968 * the transmitted BSS, the AP MLD ID should be included and should be
1969 * set to zero.
1970 * In case the ML probe requested is intended to retrieve information
1971 * from a non-transmitted BSS, the AP MLD ID should not be included.
1972 */
1973 if (ap_mld_id)
1974 wpa_s->ml_probe_mld_id = -1;
1975 else
1976 wpa_s->ml_probe_mld_id = 0;
1977
1978 if (ssid && ssid->ssid_len) {
1979 os_free(wpa_s->ssids_from_scan_req);
1980 wpa_s->num_ssids_from_scan_req = 0;
1981
1982 wpa_s->ssids_from_scan_req =
1983 os_zalloc(sizeof(struct wpa_ssid_value));
1984 if (wpa_s->ssids_from_scan_req) {
1985 wpa_printf(MSG_DEBUG,
1986 "MLD: ML probe: With direct SSID");
1987
1988 wpa_s->num_ssids_from_scan_req = 1;
1989 wpa_s->ssids_from_scan_req[0].ssid_len = ssid->ssid_len;
1990 os_memcpy(wpa_s->ssids_from_scan_req[0].ssid,
1991 ssid->ssid, ssid->ssid_len);
1992 }
1993 }
1994
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001995 wpa_s->ml_probe_links = missing_links;
1996
1997 wpa_s->normal_scans = 0;
1998 wpa_s->scan_req = MANUAL_SCAN_REQ;
1999 wpa_s->after_wps = 0;
2000 wpa_s->known_wps_freq = 0;
2001 wpa_supplicant_req_scan(wpa_s, 0, 0);
2002
2003 return 1;
2004}
2005
2006
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002007int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002008 struct wpa_bss *selected,
2009 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002010{
Sunil Ravi640215c2023-06-28 23:08:09 +00002011#ifdef IEEE8021X_EAPOL
Sunil Ravi036cec52023-03-29 11:35:17 -07002012 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
2013 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00002014 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002015 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
2016 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07002017 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002018 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002019#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002020 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
2021 wpa_s->p2p_in_provisioning) {
2022 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
2023 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002024 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002025 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002026#endif /* CONFIG_P2P */
2027
2028#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002029 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002030 wpas_wps_cancel(wpa_s);
2031#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002032 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002033 }
Sunil Ravi640215c2023-06-28 23:08:09 +00002034#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002035
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002036 wpa_msg(wpa_s, MSG_DEBUG,
2037 "Considering connect request: reassociate: %d selected: "
2038 MACSTR " bssid: " MACSTR " pending: " MACSTR
2039 " wpa_state: %s ssid=%p current_ssid=%p",
2040 wpa_s->reassociate, MAC2STR(selected->bssid),
2041 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
2042 wpa_supplicant_state_txt(wpa_s->wpa_state),
2043 ssid, wpa_s->current_ssid);
2044
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002045 /*
2046 * Do not trigger new association unless the BSSID has changed or if
2047 * reassociation is requested. If we are in process of associating with
2048 * the selected BSSID, do not trigger new attempt.
2049 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002050 if (wpa_s->reassociate ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002051 (!ether_addr_equal(selected->bssid, wpa_s->bssid) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002052 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
2053 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002054 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002055 !ether_addr_equal(selected->bssid, wpa_s->pending_bssid)) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002056 (is_zero_ether_addr(wpa_s->pending_bssid) &&
2057 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002058 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
2059 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002060 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002061 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002062
2063 if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid))
2064 return 0;
2065
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002066 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
2067 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002068 wpa_supplicant_associate(wpa_s, selected, ssid);
2069 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002070 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
2071 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002072 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002073
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002074 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075}
2076
2077
2078static struct wpa_ssid *
2079wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
2080{
Hai Shalomfdcde762020-04-02 11:19:20 -07002081 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082 struct wpa_ssid *ssid;
2083
2084 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
2085 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
2086 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002087 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002089#ifndef CONFIG_IBSS_RSN
2090 if (ssid->mode == WPAS_MODE_IBSS &&
2091 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
2092 WPA_KEY_MGMT_WPA_NONE))) {
2093 wpa_msg(wpa_s, MSG_INFO,
2094 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
2095 wpa_ssid_txt(ssid->ssid,
2096 ssid->ssid_len));
2097 continue;
2098 }
2099#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07002100 if (ssid->mode == WPAS_MODE_IBSS ||
2101 ssid->mode == WPAS_MODE_AP ||
2102 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002103 return ssid;
2104 }
2105 }
2106 return NULL;
2107}
2108
2109
2110/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
2111 * on BSS added and BSS changed events */
2112static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03002113 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002114{
Jouni Malinen87fd2792011-05-16 18:35:42 +03002115 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002116
2117 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
2118 return;
2119
Jouni Malinen87fd2792011-05-16 18:35:42 +03002120 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002121 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002122
Jouni Malinen87fd2792011-05-16 18:35:42 +03002123 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002124 if (ssid == NULL)
2125 continue;
2126
Sunil Ravi7f769292024-07-23 22:21:32 +00002127 rsn = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002128 if (rsn == NULL)
2129 continue;
2130
Jouni Malinen87fd2792011-05-16 18:35:42 +03002131 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132 }
2133
2134}
2135
2136
Hai Shalomfdcde762020-04-02 11:19:20 -07002137#ifndef CONFIG_NO_ROAMING
2138
2139static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
2140{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002141 if (noise == WPA_INVALID_NOISE) {
2142 if (IS_5GHZ(frequency)) {
2143 noise = DEFAULT_NOISE_FLOOR_5GHZ;
2144 } else if (is_6ghz_freq(frequency)) {
2145 noise = DEFAULT_NOISE_FLOOR_6GHZ;
2146 } else {
2147 noise = DEFAULT_NOISE_FLOOR_2GHZ;
2148 }
2149 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002150 return avg_signal - noise;
2151}
2152
2153
2154static unsigned int
2155wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
2156 const struct wpa_bss *bss, int snr)
2157{
2158 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08002159 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07002160 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002161 enum chan_width max_cw = CHAN_WIDTH_UNKNOWN;
Hai Shalomfdcde762020-04-02 11:19:20 -07002162
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002163 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq,
2164 &max_cw);
Hai Shalomfdcde762020-04-02 11:19:20 -07002165}
2166
Hai Shalomfdcde762020-04-02 11:19:20 -07002167
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002168static int wpas_evaluate_band_score(int frequency)
2169{
2170 if (is_6ghz_freq(frequency))
2171 return 2;
2172 if (IS_5GHZ(frequency))
2173 return 1;
2174 return 0;
2175}
2176
2177
Hai Shalom899fcc72020-10-19 14:38:18 -07002178int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
2179 struct wpa_bss *current_bss,
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002180 struct wpa_bss *selected,
2181 bool poll_current)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002182{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002183 int min_diff, diff;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002184 int cur_band_score, sel_band_score;
Sunil Ravi036cec52023-03-29 11:35:17 -07002185 int to_5ghz, to_6ghz;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002186 int cur_level, sel_level;
Hai Shalomfdcde762020-04-02 11:19:20 -07002187 unsigned int cur_est, sel_est;
2188 struct wpa_signal_info si;
2189 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07002190 int ret = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002191 const u8 *cur_ies = wpa_bss_ie_ptr(current_bss);
2192 const u8 *sel_ies = wpa_bss_ie_ptr(selected);
2193 size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len :
2194 current_bss->beacon_ie_len;
2195 size_t sel_ie_len = selected->ie_len ? selected->ie_len :
2196 selected->beacon_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002198 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002199 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002200 " freq=%d level=%d snr=%d est_throughput=%u",
2201 MAC2STR(current_bss->bssid),
2202 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002203 current_bss->snr, current_bss->est_throughput);
2204 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002205 " freq=%d level=%d snr=%d est_throughput=%u",
2206 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002207 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002208
Sunil Ravi7f769292024-07-23 22:21:32 +00002209 if (wpas_ap_link_address(wpa_s, selected->bssid)) {
2210 wpa_dbg(wpa_s, MSG_DEBUG, "MLD: associated to selected BSS");
2211 return 0;
2212 }
2213
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002214 if (wpa_s->current_ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002215 ether_addr_equal(selected->bssid, wpa_s->current_ssid->bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002216 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2217 "has preferred BSSID");
2218 return 1;
2219 }
2220
Hai Shalomfdcde762020-04-02 11:19:20 -07002221 /*
2222 * Try to poll the signal from the driver since this will allow to get
2223 * more accurate values. In some cases, there can be big differences
2224 * between the RSSI of the Probe Response frames of the AP we are
2225 * associated with and the Beacon frames we hear from the same AP after
2226 * association. This can happen, e.g., when there are two antennas that
2227 * hear the AP very differently. If the driver chooses to hear the
2228 * Probe Response frames during the scan on the "bad" antenna because
2229 * it wants to save power, but knows to choose the other antenna after
2230 * association, we will hear our AP with a low RSSI as part of the
2231 * scan even when we can hear it decently on the other antenna. To cope
2232 * with this, ask the driver to teach us how it hears the AP. Also, the
2233 * scan results may be a bit old, since we can very quickly get fresh
2234 * information about our currently associated AP.
2235 */
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002236 if (poll_current && wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002237 (si.data.avg_beacon_signal || si.data.avg_signal)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002238 /*
2239 * Normalize avg_signal to the RSSI over 20 MHz, as the
2240 * throughput is estimated based on the RSSI over 20 MHz
2241 */
Sunil Ravi77d572f2023-01-17 23:58:31 +00002242 cur_level = si.data.avg_beacon_signal ?
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002243 si.data.avg_beacon_signal :
2244 (si.data.avg_signal -
2245 wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2246 si.chanwidth));
Hai Shalomfdcde762020-04-02 11:19:20 -07002247 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2248 si.current_noise);
2249
2250 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2251 current_bss,
2252 cur_snr);
2253 wpa_dbg(wpa_s, MSG_DEBUG,
2254 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2255 cur_level, cur_snr, cur_est);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002256 } else {
2257 /* Level and SNR are measured over 20 MHz channel */
2258 cur_level = current_bss->level;
2259 cur_snr = current_bss->snr;
2260 cur_est = current_bss->est_throughput;
Hai Shalomfdcde762020-04-02 11:19:20 -07002261 }
2262
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002263 /* Adjust the SNR of BSSes based on the channel width. */
2264 cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2265 current_bss->max_cw);
2266 cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len,
2267 current_bss->max_cw, cur_snr);
2268
2269 sel_est = selected->est_throughput;
2270 sel_level = selected->level +
2271 wpas_channel_width_rssi_bump(sel_ies, sel_ie_len,
2272 selected->max_cw);
2273
Hai Shalomfdcde762020-04-02 11:19:20 -07002274 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002275 wpa_dbg(wpa_s, MSG_DEBUG,
2276 "Allow reassociation - selected BSS has better estimated throughput");
2277 return 1;
2278 }
2279
Dmitry Shmidte4663042016-04-04 10:07:49 -07002280 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
Sunil Ravi036cec52023-03-29 11:35:17 -07002281 to_6ghz = is_6ghz_freq(selected->freq) &&
2282 !is_6ghz_freq(current_bss->freq);
Dmitry Shmidte4663042016-04-04 10:07:49 -07002283
Sunil Ravi036cec52023-03-29 11:35:17 -07002284 if (cur_level < 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002285 cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002286 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002287 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2288 "signal level");
2289 return 0;
2290 }
2291
Hai Shalomfdcde762020-04-02 11:19:20 -07002292 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002293 wpa_dbg(wpa_s, MSG_DEBUG,
2294 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002295 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002296 }
2297
Hai Shalomfdcde762020-04-02 11:19:20 -07002298 if (cur_snr > GREAT_SNR) {
2299 wpa_dbg(wpa_s, MSG_DEBUG,
2300 "Skip roam - Current BSS has good SNR (%u > %u)",
2301 cur_snr, GREAT_SNR);
2302 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002303 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002304
Hai Shalomfdcde762020-04-02 11:19:20 -07002305 if (cur_level < -85) /* ..-86 dBm */
2306 min_diff = 1;
2307 else if (cur_level < -80) /* -85..-81 dBm */
2308 min_diff = 2;
2309 else if (cur_level < -75) /* -80..-76 dBm */
2310 min_diff = 3;
2311 else if (cur_level < -70) /* -75..-71 dBm */
2312 min_diff = 4;
2313 else if (cur_level < 0) /* -70..-1 dBm */
2314 min_diff = 5;
2315 else /* unspecified units (not in dBm) */
2316 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002317
Hai Shalomfdcde762020-04-02 11:19:20 -07002318 if (cur_est > sel_est * 1.5)
2319 min_diff += 10;
2320 else if (cur_est > sel_est * 1.2)
2321 min_diff += 5;
2322 else if (cur_est > sel_est * 1.1)
2323 min_diff += 2;
2324 else if (cur_est > sel_est)
2325 min_diff++;
2326 else if (sel_est > cur_est * 1.5)
2327 min_diff -= 10;
2328 else if (sel_est > cur_est * 1.2)
2329 min_diff -= 5;
2330 else if (sel_est > cur_est * 1.1)
2331 min_diff -= 2;
2332 else if (sel_est > cur_est)
2333 min_diff--;
2334
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002335 cur_band_score = wpas_evaluate_band_score(current_bss->freq);
2336 sel_band_score = wpas_evaluate_band_score(selected->freq);
2337 min_diff += (cur_band_score - sel_band_score) * 2;
2338 if (wpa_s->signal_threshold && cur_level <= wpa_s->signal_threshold &&
2339 sel_level > wpa_s->signal_threshold)
Sunil Ravi036cec52023-03-29 11:35:17 -07002340 min_diff -= 2;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002341 diff = sel_level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002342 if (diff < min_diff) {
2343 wpa_dbg(wpa_s, MSG_DEBUG,
2344 "Skip roam - too small difference in signal level (%d < %d)",
2345 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002346 ret = 0;
2347 } else {
2348 wpa_dbg(wpa_s, MSG_DEBUG,
2349 "Allow reassociation due to difference in signal level (%d >= %d)",
2350 diff, min_diff);
2351 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002352 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002353 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2354 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2355 " sel_freq=%d sel_level=%d sel_est=%d",
2356 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2357 MAC2STR(current_bss->bssid),
2358 current_bss->freq, cur_level, cur_est,
2359 MAC2STR(selected->bssid),
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002360 selected->freq, sel_level, sel_est);
Hai Shalom899fcc72020-10-19 14:38:18 -07002361 return ret;
2362}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002363
Hai Shalom899fcc72020-10-19 14:38:18 -07002364#endif /* CONFIG_NO_ROAMING */
2365
2366
2367static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2368 struct wpa_bss *selected,
2369 struct wpa_ssid *ssid)
2370{
2371 struct wpa_bss *current_bss = NULL;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002372 const u8 *bssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07002373
2374 if (wpa_s->reassociate)
2375 return 1; /* explicit request to reassociate */
2376 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2377 return 1; /* we are not associated; continue */
2378 if (wpa_s->current_ssid == NULL)
2379 return 1; /* unknown current SSID */
2380 if (wpa_s->current_ssid != ssid)
2381 return 1; /* different network block */
2382
2383 if (wpas_driver_bss_selection(wpa_s))
2384 return 0; /* Driver-based roaming */
2385
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002386 if (wpa_s->valid_links)
2387 bssid = wpa_s->links[wpa_s->mlo_assoc_link_id].bssid;
2388 else
2389 bssid = wpa_s->bssid;
2390
Hai Shalom899fcc72020-10-19 14:38:18 -07002391 if (wpa_s->current_ssid->ssid)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002392 current_bss = wpa_bss_get(wpa_s, bssid,
Hai Shalom899fcc72020-10-19 14:38:18 -07002393 wpa_s->current_ssid->ssid,
2394 wpa_s->current_ssid->ssid_len);
2395 if (!current_bss)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002396 current_bss = wpa_bss_get_bssid(wpa_s, bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07002397
2398 if (!current_bss)
2399 return 1; /* current BSS not seen in scan results */
2400
2401 if (current_bss == selected)
2402 return 0;
2403
2404 if (selected->last_update_idx > current_bss->last_update_idx)
2405 return 1; /* current BSS not seen in the last scan */
2406
2407#ifndef CONFIG_NO_ROAMING
2408 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002409 selected, true);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002410#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002411 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002412#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002413}
2414
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002415
Sunil Ravic0f5d412024-09-11 22:12:49 +00002416static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s,
2417 union wpa_event_data *data)
2418{
2419 struct wpa_driver_scan_params params;
2420 unsigned int j;
2421
2422 wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan");
2423 os_memset(&params, 0, sizeof(params));
2424 params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz;
2425 for (j = 0; j < data->scan_info.num_ssids; j++)
2426 params.ssids[j] = data->scan_info.ssids[j];
2427 params.num_ssids = data->scan_info.num_ssids;
2428 wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
2429 true, false, false);
2430 if (!wpa_supplicant_trigger_scan(wpa_s, &params, true, true)) {
2431 wpa_s->scan_in_progress_6ghz = true;
2432 wpas_notify_scan_in_progress_6ghz(wpa_s);
2433 os_free(params.freqs);
2434 return 1;
2435 }
2436 wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan");
2437 os_free(params.freqs);
2438 return 0;
2439}
2440
2441
2442static bool wpas_short_ssid_match(struct wpa_supplicant *wpa_s,
2443 struct wpa_scan_results *scan_res)
2444{
2445 size_t i;
2446 struct wpa_ssid *ssid = wpa_s->current_ssid;
2447 u32 current_ssid_short = ieee80211_crc32(ssid->ssid, ssid->ssid_len);
2448
2449 for (i = 0; i < scan_res->num; i++) {
2450 struct wpa_scan_res *res = scan_res->res[i];
2451 const u8 *rnr_ie, *ie_end;
2452 const struct ieee80211_neighbor_ap_info *info;
2453 size_t left;
2454
2455 rnr_ie = wpa_scan_get_ie(res, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
2456 if (!rnr_ie)
2457 continue;
2458
2459 ie_end = rnr_ie + 2 + rnr_ie[1];
2460 rnr_ie += 2;
2461
2462 left = ie_end - rnr_ie;
2463 if (left < sizeof(struct ieee80211_neighbor_ap_info))
2464 continue;
2465
2466 info = (const struct ieee80211_neighbor_ap_info *) rnr_ie;
2467 if (info->tbtt_info_len < 11)
2468 continue; /* short SSID not included */
2469 left -= sizeof(struct ieee80211_neighbor_ap_info);
2470 rnr_ie += sizeof(struct ieee80211_neighbor_ap_info);
2471
2472 while (left >= info->tbtt_info_len && rnr_ie + 11 <= ie_end) {
2473 /* Skip TBTT offset and BSSID */
2474 u32 short_ssid = WPA_GET_LE32(rnr_ie + 1 + ETH_ALEN);
2475
2476 if (short_ssid == current_ssid_short)
2477 return true;
2478
2479 left -= info->tbtt_info_len;
2480 rnr_ie += info->tbtt_info_len;
2481 }
2482 }
2483
2484 return false;
2485}
2486
2487
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002488/*
2489 * Return a negative value if no scan results could be fetched or if scan
2490 * results should not be shared with other virtual interfaces.
2491 * Return 0 if scan results were fetched and may be shared with other
2492 * interfaces.
2493 * Return 1 if scan results may be shared with other virtual interfaces but may
2494 * not trigger any operations.
2495 * Return 2 if the interface was removed and cannot be used.
2496 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002497static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002498 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002499 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002500{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002501 struct wpa_scan_results *scan_res = NULL;
2502 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002503 int ap = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002504 bool trigger_6ghz_scan;
Sunil Ravic0f5d412024-09-11 22:12:49 +00002505 bool short_ssid_match_found = false;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002506#ifndef CONFIG_NO_RANDOM_POOL
2507 size_t i, num;
2508#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002509
2510#ifdef CONFIG_AP
2511 if (wpa_s->ap_iface)
2512 ap = 1;
2513#endif /* CONFIG_AP */
2514
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002515 trigger_6ghz_scan = wpa_s->crossed_6ghz_dom &&
2516 wpa_s->last_scan_all_chan;
2517 wpa_s->crossed_6ghz_dom = false;
2518 wpa_s->last_scan_all_chan = false;
2519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002520 wpa_supplicant_notify_scanning(wpa_s, 0);
2521
2522 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2523 data ? &data->scan_info :
Sunil Ravi99c035e2024-07-12 01:42:03 +00002524 NULL, 1, NULL);
Sunil Ravic0f5d412024-09-11 22:12:49 +00002525
2526 if (wpa_s->scan_in_progress_6ghz) {
2527 wpa_s->scan_in_progress_6ghz = false;
2528 wpas_notify_scan_in_progress_6ghz(wpa_s);
2529 }
2530
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002531 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002532 if (wpa_s->conf->ap_scan == 2 || ap ||
2533 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002534 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002535 if (!own_request)
2536 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002537 if (data && data->scan_info.external_scan)
2538 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002539 if (wpa_s->scan_res_fail_handler) {
2540 void (*handler)(struct wpa_supplicant *wpa_s);
2541
2542 handler = wpa_s->scan_res_fail_handler;
2543 wpa_s->scan_res_fail_handler = NULL;
2544 handler(wpa_s);
2545 } else {
2546 wpa_dbg(wpa_s, MSG_DEBUG,
2547 "Failed to get scan results - try scanning again");
2548 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2549 }
2550
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002551 ret = -1;
2552 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002553 }
2554
2555#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002556 num = scan_res->num;
2557 if (num > 10)
2558 num = 10;
2559 for (i = 0; i < num; i++) {
2560 u8 buf[5];
2561 struct wpa_scan_res *res = scan_res->res[i];
2562 buf[0] = res->bssid[5];
2563 buf[1] = res->qual & 0xff;
2564 buf[2] = res->noise & 0xff;
2565 buf[3] = res->level & 0xff;
2566 buf[4] = res->tsf & 0xff;
2567 random_add_randomness(buf, sizeof(buf));
2568 }
2569#endif /* CONFIG_NO_RANDOM_POOL */
2570
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002571 if (data) {
2572 size_t idx;
2573
2574 wpa_s->last_scan_external = data->scan_info.external_scan;
2575 wpa_s->last_scan_num_ssids = data->scan_info.num_ssids;
2576 for (idx = 0; idx < wpa_s->last_scan_num_ssids; idx++) {
2577 /* Copy the SSID and its length */
2578 if (idx >= WPAS_MAX_SCAN_SSIDS ||
2579 data->scan_info.ssids[idx].ssid_len > SSID_MAX_LEN)
2580 continue;
2581
2582 os_memcpy(wpa_s->last_scan_ssids[idx].ssid,
2583 data->scan_info.ssids[idx].ssid,
2584 data->scan_info.ssids[idx].ssid_len);
2585 wpa_s->last_scan_ssids[idx].ssid_len =
2586 data->scan_info.ssids[idx].ssid_len;
2587 }
2588 } else {
2589 wpa_s->last_scan_external = false;
2590 wpa_s->last_scan_num_ssids = 0;
2591 }
Sunil Ravi7f769292024-07-23 22:21:32 +00002592
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002593 if (update_only) {
2594 ret = 1;
2595 goto scan_work_done;
2596 }
2597
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002598 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002599 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002600 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2601 struct wpa_scan_results *scan_res);
2602
2603 scan_res_handler = wpa_s->scan_res_handler;
2604 wpa_s->scan_res_handler = NULL;
2605 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002606 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002607 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002608 }
2609
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002610 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002611 wpa_s->own_scan_running,
2612 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002613 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002614 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2615 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002616 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2617 wpa_s->manual_scan_id);
2618 wpa_s->manual_scan_use_id = 0;
2619 } else {
2620 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2621 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002622 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002623
2624 wpas_notify_scan_done(wpa_s, 1);
2625
Hai Shalomfdcde762020-04-02 11:19:20 -07002626 if (ap) {
2627 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2628#ifdef CONFIG_AP
2629 if (wpa_s->ap_iface->scan_cb)
2630 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2631#endif /* CONFIG_AP */
2632 goto scan_work_done;
2633 }
2634
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002635 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002636 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 -07002637 wpa_scan_results_free(scan_res);
2638 return 0;
2639 }
2640
Hai Shalomc1a21442022-02-04 13:43:00 -08002641 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002642 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002643
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002644#ifndef CONFIG_NO_RRM
Hai Shalom021b0b52019-04-10 11:17:58 -07002645 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002646 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2647 goto scan_work_done;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002648#endif /* CONFIG_NO_RRM */
Dmitry Shmidt29333592017-01-09 12:27:11 -08002649
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002650 if (ml_link_probe_scan(wpa_s))
2651 goto scan_work_done;
2652
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002653 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2654 goto scan_work_done;
2655
2656 if (autoscan_notify_scan(wpa_s, scan_res))
2657 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002658
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002659 if (wpa_s->disconnected) {
2660 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002661 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002662 }
2663
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002664 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002665 bgscan_notify_scan(wpa_s, scan_res) == 1)
2666 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002667
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002668 wpas_wps_update_ap_info(wpa_s, scan_res);
2669
Sunil Ravic0f5d412024-09-11 22:12:49 +00002670 if (wnm_scan_process(wpa_s, false) > 0)
2671 goto scan_work_done;
2672
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002673 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2674 wpa_s->wpa_state < WPA_COMPLETED)
2675 goto scan_work_done;
2676
Sunil Ravic0f5d412024-09-11 22:12:49 +00002677 if (wpa_s->current_ssid && trigger_6ghz_scan && own_request && data &&
2678 wpas_short_ssid_match(wpa_s, scan_res)) {
2679 wpa_dbg(wpa_s, MSG_INFO, "Short SSID match in scan results");
2680 short_ssid_match_found = true;
2681 }
2682
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002683 wpa_scan_results_free(scan_res);
2684
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002685 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002686 struct wpa_radio_work *work = wpa_s->scan_work;
2687 wpa_s->scan_work = NULL;
2688 radio_work_done(work);
2689 }
2690
Hai Shalomc3565922019-10-28 11:58:20 -07002691 os_free(wpa_s->last_scan_freqs);
2692 wpa_s->last_scan_freqs = NULL;
2693 wpa_s->num_last_scan_freqs = 0;
2694 if (own_request && data &&
2695 data->scan_info.freqs && data->scan_info.num_freqs) {
2696 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2697 data->scan_info.num_freqs);
2698 if (wpa_s->last_scan_freqs) {
2699 os_memcpy(wpa_s->last_scan_freqs,
2700 data->scan_info.freqs,
2701 sizeof(int) * data->scan_info.num_freqs);
2702 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2703 }
2704 }
2705
Sunil Ravi77d572f2023-01-17 23:58:31 +00002706 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2707 return ret;
2708
Sunil Ravic0f5d412024-09-11 22:12:49 +00002709 if (short_ssid_match_found && wpas_trigger_6ghz_scan(wpa_s, data) > 0)
2710 return 1;
2711
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002712 return wpas_select_network_from_last_scan(wpa_s, 1, own_request,
2713 trigger_6ghz_scan, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002714
2715scan_work_done:
2716 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002717 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002718 struct wpa_radio_work *work = wpa_s->scan_work;
2719 wpa_s->scan_work = NULL;
2720 radio_work_done(work);
2721 }
2722 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002723}
2724
2725
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002726/**
2727 * Select a network from the last scan
2728 * @wpa_s: Pointer to wpa_supplicant data
2729 * @new_scan: Whether this function was called right after a scan has finished
2730 * @own_request: Whether the scan was requested by this interface
2731 * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable
2732 * @data: Scan data from scan that finished if applicable
2733 *
2734 * See _wpa_supplicant_event_scan_results() for return values.
2735 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002736static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002737 int new_scan, int own_request,
2738 bool trigger_6ghz_scan,
2739 union wpa_event_data *data)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002740{
2741 struct wpa_bss *selected;
2742 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002743 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2744
2745 if (time_to_reenable > 0) {
2746 wpa_dbg(wpa_s, MSG_DEBUG,
2747 "Postpone network selection by %d seconds since all networks are disabled",
2748 time_to_reenable);
2749 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2750 eloop_register_timeout(time_to_reenable, 0,
2751 wpas_network_reenabled, wpa_s, NULL);
2752 return 0;
2753 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002754
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002755 if (wpa_s->p2p_mgmt)
2756 return 0; /* no normal connection on p2p_mgmt interface */
2757
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002758 wpa_s->owe_transition_search = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002759#ifdef CONFIG_OWE
2760 os_free(wpa_s->owe_trans_scan_freq);
2761 wpa_s->owe_trans_scan_freq = NULL;
2762#endif /* CONFIG_OWE */
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002763 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002764
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002765#ifdef CONFIG_MESH
2766 if (wpa_s->ifmsh) {
2767 wpa_msg(wpa_s, MSG_INFO,
2768 "Avoiding join because we already joined a mesh group");
2769 return 0;
2770 }
2771#endif /* CONFIG_MESH */
2772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002773 if (selected) {
2774 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002775 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002776 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002777 if (new_scan)
2778 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002779 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002780 }
2781
Hai Shalomc3565922019-10-28 11:58:20 -07002782 wpa_s->suitable_network++;
2783
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002784 if (ssid != wpa_s->current_ssid &&
2785 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2786 wpa_s->own_disconnect_req = 1;
2787 wpa_supplicant_deauthenticate(
2788 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2789 }
2790
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002791 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002792 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002793 return -1;
2794 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002795 wpa_s->supp_pbc_active = false;
2796
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002797 if (new_scan)
2798 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002799 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002800 * Do not allow other virtual radios to trigger operations based
2801 * on these scan results since we do not want them to start
2802 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002803 */
2804 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002805 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002806 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002807 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2808 ssid = wpa_supplicant_pick_new_network(wpa_s);
2809 if (ssid) {
2810 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2811 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002812 if (new_scan)
2813 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002814 } else if (own_request) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002815 if (wpa_s->support_6ghz && trigger_6ghz_scan && data &&
Sunil Ravic0f5d412024-09-11 22:12:49 +00002816 wpas_trigger_6ghz_scan(wpa_s, data) > 0)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002817 return 1;
2818
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002819 /*
2820 * No SSID found. If SCAN results are as a result of
2821 * own scan request and not due to a scan request on
2822 * another shared interface, try another scan.
2823 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002824 int timeout_sec = wpa_s->scan_interval;
2825 int timeout_usec = 0;
2826#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002827 int res;
2828
2829 res = wpas_p2p_scan_no_go_seen(wpa_s);
2830 if (res == 2)
2831 return 2;
2832 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002833 return 0;
2834
Sunil Ravi77d572f2023-01-17 23:58:31 +00002835 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002836 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002837
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002838 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002839 wpa_s->show_group_started ||
2840 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002841 /*
2842 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002843 * state and during P2P join-a-group operation
2844 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002845 */
2846 timeout_sec = 0;
2847 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002848 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2849 timeout_usec);
2850 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002851 }
2852#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002853#ifdef CONFIG_INTERWORKING
2854 if (wpa_s->conf->auto_interworking &&
2855 wpa_s->conf->interworking &&
2856 wpa_s->conf->cred) {
2857 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2858 "start ANQP fetch since no matching "
2859 "networks found");
2860 wpa_s->network_select = 1;
2861 wpa_s->auto_network_select = 1;
2862 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002863 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002864 }
2865#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002866#ifdef CONFIG_WPS
2867 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2868 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2869 timeout_sec = 0;
2870 timeout_usec = 500000;
2871 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2872 timeout_usec);
2873 return 0;
2874 }
2875#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002876#ifdef CONFIG_OWE
2877 if (wpa_s->owe_transition_search) {
2878 wpa_dbg(wpa_s, MSG_DEBUG,
2879 "OWE: Use shorter wait during transition mode search");
2880 timeout_sec = 0;
2881 timeout_usec = 500000;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002882 if (wpa_s->owe_trans_scan_freq) {
2883 os_free(wpa_s->next_scan_freqs);
2884 wpa_s->next_scan_freqs =
2885 wpa_s->owe_trans_scan_freq;
2886 wpa_s->owe_trans_scan_freq = NULL;
2887 timeout_usec = 100000;
2888 }
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002889 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2890 timeout_usec);
2891 return 0;
2892 }
2893#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002894 if (wpa_supplicant_req_sched_scan(wpa_s))
2895 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2896 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002897
2898 wpa_msg_ctrl(wpa_s, MSG_INFO,
2899 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002900 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002901 }
2902 }
2903 return 0;
2904}
2905
2906
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002907static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2908 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002909{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002910 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002911 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002912
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002913 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002914 if (res == 2) {
2915 /*
2916 * Interface may have been removed, so must not dereference
2917 * wpa_s after this.
2918 */
2919 return 1;
2920 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002921
2922 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002923 /*
2924 * If no scan results could be fetched, then no need to
2925 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002926 * this scan. Similarly, if scan results started a new operation on this
2927 * interface, do not notify other interfaces to avoid concurrent
2928 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002929 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002930 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002931 }
2932
2933 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002934 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002935 * so, they get updated with this same scan info.
2936 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002937 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2938 radio_list) {
2939 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002940 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2941 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002942 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2943 res > 0);
2944 if (res < 0)
2945 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002946 }
2947 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002948
2949 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002950}
2951
2952#endif /* CONFIG_NO_SCAN_PROCESSING */
2953
2954
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002955int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2956{
2957#ifdef CONFIG_NO_SCAN_PROCESSING
2958 return -1;
2959#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002960 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002961
Dmitry Shmidt29333592017-01-09 12:27:11 -08002962 wpa_s->ignore_post_flush_scan_res = 0;
2963
Dmitry Shmidt41712582015-06-29 11:02:15 -07002964 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002965 return -1;
2966
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002967 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002968 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002969 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002970 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2971 return -1;
Sunil Ravi7f769292024-07-23 22:21:32 +00002972 } else if (wpa_s->crossed_6ghz_dom) {
2973 wpa_printf(MSG_DEBUG, "Fast associate: Crossed 6 GHz domain");
2974 return -1;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002975 }
2976
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002977 return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002978#endif /* CONFIG_NO_SCAN_PROCESSING */
2979}
2980
Sunil Ravi77d572f2023-01-17 23:58:31 +00002981
2982int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2983{
2984#ifdef CONFIG_NO_SCAN_PROCESSING
2985 return -1;
2986#else /* CONFIG_NO_SCAN_PROCESSING */
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002987 return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002988#endif /* CONFIG_NO_SCAN_PROCESSING */
2989}
2990
2991
Dmitry Shmidt04949592012-07-19 12:16:46 -07002992#ifdef CONFIG_WNM
2993
2994static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2995{
2996 struct wpa_supplicant *wpa_s = eloop_ctx;
2997
2998 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2999 return;
3000
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003001 if (!wpa_s->no_keep_alive) {
3002 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
3003 MAC2STR(wpa_s->bssid));
3004 /* TODO: could skip this if normal data traffic has been sent */
3005 /* TODO: Consider using some more appropriate data frame for
3006 * this */
3007 if (wpa_s->l2)
3008 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
3009 (u8 *) "", 0);
3010 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003011
3012#ifdef CONFIG_SME
3013 if (wpa_s->sme.bss_max_idle_period) {
3014 unsigned int msec;
3015 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
3016 if (msec > 100)
3017 msec -= 100;
3018 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
3019 wnm_bss_keep_alive, wpa_s, NULL);
3020 }
3021#endif /* CONFIG_SME */
3022}
3023
3024
3025static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
3026 const u8 *ies, size_t ies_len)
3027{
3028 struct ieee802_11_elems elems;
3029
3030 if (ies == NULL)
3031 return;
3032
3033 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
3034 return;
3035
3036#ifdef CONFIG_SME
3037 if (elems.bss_max_idle_period) {
3038 unsigned int msec;
3039 wpa_s->sme.bss_max_idle_period =
3040 WPA_GET_LE16(elems.bss_max_idle_period);
3041 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
3042 "TU)%s", wpa_s->sme.bss_max_idle_period,
3043 (elems.bss_max_idle_period[2] & 0x01) ?
3044 " (protected keep-live required)" : "");
3045 if (wpa_s->sme.bss_max_idle_period == 0)
3046 wpa_s->sme.bss_max_idle_period = 1;
3047 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
3048 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
3049 /* msec times 1000 */
3050 msec = wpa_s->sme.bss_max_idle_period * 1024;
3051 if (msec > 100)
3052 msec -= 100;
3053 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
3054 wnm_bss_keep_alive, wpa_s,
3055 NULL);
3056 }
Sunil Ravi7f769292024-07-23 22:21:32 +00003057 } else {
3058 wpa_s->sme.bss_max_idle_period = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003059 }
3060#endif /* CONFIG_SME */
3061}
3062
3063#endif /* CONFIG_WNM */
3064
3065
3066void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
3067{
3068#ifdef CONFIG_WNM
3069 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
3070#endif /* CONFIG_WNM */
3071}
3072
3073
Dmitry Shmidt051af732013-10-22 13:52:46 -07003074static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
3075 size_t len)
3076{
3077 int res;
3078
3079 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
3080 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
3081 if (res) {
3082 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
3083 }
3084
3085 return res;
3086}
3087
3088
3089static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
3090 const u8 *ies, size_t ies_len)
3091{
3092 struct ieee802_11_elems elems;
3093
3094 if (ies == NULL)
3095 return;
3096
3097 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
3098 return;
3099
3100 if (elems.qos_map_set) {
3101 wpas_qos_map_set(wpa_s, elems.qos_map_set,
3102 elems.qos_map_set_len);
3103 }
3104}
3105
Dmitry Shmidt051af732013-10-22 13:52:46 -07003106
Sunil Ravi036cec52023-03-29 11:35:17 -07003107static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
3108{
3109 if (wpa_s->enabled_4addr_mode) {
3110 wpa_printf(MSG_DEBUG, "4addr mode already set");
3111 return;
3112 }
3113
3114 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
3115 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
3116 goto fail;
3117 }
3118 wpa_s->enabled_4addr_mode = 1;
3119 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
3120 return;
3121
3122fail:
3123 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3124}
3125
3126
Hai Shalom74f70d42019-02-11 14:42:39 -08003127static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
3128 const u8 *ies, size_t ies_len)
3129{
3130 struct ieee802_11_elems elems;
Sunil Ravi99c035e2024-07-12 01:42:03 +00003131 struct multi_ap_params multi_ap;
3132 u16 status;
Hai Shalom74f70d42019-02-11 14:42:39 -08003133
Hai Shalomfdcde762020-04-02 11:19:20 -07003134 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08003135
Hai Shalomfdcde762020-04-02 11:19:20 -07003136 if (!ies ||
3137 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
Sunil Ravi99c035e2024-07-12 01:42:03 +00003138 !elems.multi_ap)
Hai Shalomfdcde762020-04-02 11:19:20 -07003139 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08003140
Sunil Ravi99c035e2024-07-12 01:42:03 +00003141 status = check_multi_ap_ie(elems.multi_ap + 4, elems.multi_ap_len - 4,
3142 &multi_ap);
3143 if (status != WLAN_STATUS_SUCCESS)
Hai Shalomfdcde762020-04-02 11:19:20 -07003144 return;
3145
Sunil Ravi99c035e2024-07-12 01:42:03 +00003146 wpa_s->multi_ap_backhaul = !!(multi_ap.capability &
3147 MULTI_AP_BACKHAUL_BSS);
3148 wpa_s->multi_ap_fronthaul = !!(multi_ap.capability &
Hai Shalomfdcde762020-04-02 11:19:20 -07003149 MULTI_AP_FRONTHAUL_BSS);
3150 wpa_s->multi_ap_ie = 1;
3151}
3152
3153
3154static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
3155{
3156 if (!wpa_s->current_ssid ||
3157 !wpa_s->current_ssid->multi_ap_backhaul_sta)
3158 return;
3159
3160 if (!wpa_s->multi_ap_ie) {
3161 wpa_printf(MSG_INFO,
3162 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08003163 goto fail;
3164 }
3165
Hai Shalomfdcde762020-04-02 11:19:20 -07003166 if (!wpa_s->multi_ap_backhaul) {
3167 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07003168 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
3169 wpa_printf(MSG_INFO,
3170 "WPS active, accepting fronthaul-only BSS");
3171 /* Don't set 4addr mode in this case, so just return */
3172 return;
3173 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003174 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
3175 goto fail;
3176 }
3177
Sunil Ravi036cec52023-03-29 11:35:17 -07003178 wpa_supplicant_set_4addr_mode(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08003179 return;
3180
3181fail:
3182 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3183}
3184
3185
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003186#ifdef CONFIG_FST
3187static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
3188 const u8 *ie, size_t ie_len)
3189{
3190 struct mb_ies_info mb_ies;
3191
3192 if (!ie || !ie_len || !wpa_s->fst)
3193 return -ENOENT;
3194
3195 os_memset(&mb_ies, 0, sizeof(mb_ies));
3196
3197 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
3198 size_t len;
3199
3200 len = 2 + ie[1];
3201 if (len > ie_len) {
3202 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
3203 ie, ie_len);
3204 break;
3205 }
3206
3207 if (ie[0] == WLAN_EID_MULTI_BAND) {
3208 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
3209 (unsigned int) len);
3210 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
3211 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
3212 mb_ies.nof_ies++;
3213 }
3214
3215 ie_len -= len;
3216 ie += len;
3217 }
3218
3219 if (mb_ies.nof_ies > 0) {
3220 wpabuf_free(wpa_s->received_mb_ies);
3221 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
3222 return 0;
3223 }
3224
3225 return -ENOENT;
3226}
3227#endif /* CONFIG_FST */
3228
3229
Hai Shalomc1a21442022-02-04 13:43:00 -08003230static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
3231 union wpa_event_data *data)
3232{
3233 int sel;
3234 const u8 *p;
3235 int l, len;
3236 bool found = false;
3237 struct wpa_ie_data ie;
3238 struct wpa_ssid *ssid = wpa_s->current_ssid;
3239 struct wpa_bss *bss = wpa_s->current_bss;
3240 int pmf;
3241
3242 if (!ssid)
3243 return 0;
3244
3245 p = data->assoc_info.req_ies;
3246 l = data->assoc_info.req_ies_len;
3247
3248 while (p && l >= 2) {
3249 len = p[1] + 2;
3250 if (len > l) {
3251 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3252 p, l);
3253 break;
3254 }
3255 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3256 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3257 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3258 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3259 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3260 found = true;
3261 break;
3262 }
3263 l -= len;
3264 p += len;
3265 }
3266
Sunil Ravi036cec52023-03-29 11:35:17 -07003267 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
3268 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
Hai Shalomc1a21442022-02-04 13:43:00 -08003269 return 0;
Sunil Ravi036cec52023-03-29 11:35:17 -07003270 }
Hai Shalomc1a21442022-02-04 13:43:00 -08003271
3272 wpa_hexdump(MSG_DEBUG,
3273 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
3274 p, l);
3275
3276 /* Update proto from (Re)Association Request frame info */
3277 wpa_s->wpa_proto = ie.proto;
3278 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
3279 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
3280 !!(wpa_s->wpa_proto &
3281 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
3282
3283 /* Update AKMP suite from (Re)Association Request frame info */
3284 sel = ie.key_mgmt;
3285 if (ssid->key_mgmt)
3286 sel &= ssid->key_mgmt;
3287
3288 wpa_dbg(wpa_s, MSG_DEBUG,
3289 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
3290 ie.key_mgmt, ssid->key_mgmt, sel);
3291 if (ie.key_mgmt && !sel) {
3292 wpa_supplicant_deauthenticate(
3293 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
3294 return -1;
3295 }
3296
Sunil Ravi036cec52023-03-29 11:35:17 -07003297#ifdef CONFIG_OCV
3298 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
3299 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
3300 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
3301 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
3302#endif /* CONFIG_OCV */
3303
Sunil Ravi89eba102022-09-13 21:04:37 -07003304 /*
3305 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
3306 * different AKM.
3307 */
3308 if (wpa_s->key_mgmt != ie.key_mgmt &&
3309 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
3310 if (!ssid->psk_set) {
3311 wpa_dbg(wpa_s, MSG_INFO,
3312 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00003313 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07003314 return -1;
3315 }
3316
3317 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
3318 if (wpa_s->conf->key_mgmt_offload &&
3319 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003320 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
3321 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07003322 wpa_dbg(wpa_s, MSG_ERROR,
3323 "WPA: Cannot set PMK for key management offload");
3324 }
3325
Hai Shalomc1a21442022-02-04 13:43:00 -08003326 wpa_s->key_mgmt = ie.key_mgmt;
3327 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3328 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
3329 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
3330 wpa_s->wpa_proto);
3331
3332 /* Update pairwise cipher from (Re)Association Request frame info */
3333 sel = ie.pairwise_cipher;
3334 if (ssid->pairwise_cipher)
3335 sel &= ssid->pairwise_cipher;
3336
3337 wpa_dbg(wpa_s, MSG_DEBUG,
3338 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
3339 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
3340 if (ie.pairwise_cipher && !sel) {
3341 wpa_supplicant_deauthenticate(
3342 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
3343 return -1;
3344 }
3345
3346 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3347 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3348 wpa_s->pairwise_cipher);
3349 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
3350 wpa_cipher_txt(wpa_s->pairwise_cipher));
3351
3352 /* Update other parameters based on AP's WPA IE/RSNE, if available */
3353 if (!bss) {
3354 wpa_dbg(wpa_s, MSG_DEBUG,
3355 "WPA: current_bss == NULL - skip AP IE check");
3356 return 0;
3357 }
3358
3359 /* Update GTK and IGTK from AP's RSNE */
3360 found = false;
3361
3362 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
3363 const u8 *bss_rsn;
3364
Sunil Ravi7f769292024-07-23 22:21:32 +00003365 bss_rsn = wpa_bss_get_rsne(wpa_s, bss, ssid,
3366 wpa_s->valid_links);
Hai Shalomc1a21442022-02-04 13:43:00 -08003367 if (bss_rsn) {
3368 p = bss_rsn;
3369 len = 2 + bss_rsn[1];
3370 found = true;
3371 }
3372 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
3373 const u8 *bss_wpa;
3374
3375 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3376 if (bss_wpa) {
3377 p = bss_wpa;
3378 len = 2 + bss_wpa[1];
3379 found = true;
3380 }
3381 }
3382
3383 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
3384 return 0;
3385
3386 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
3387 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3388 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3389 /* AP does not support MFP, local configuration requires it */
3390 wpa_supplicant_deauthenticate(
3391 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3392 return -1;
3393 }
3394 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3395 pmf == NO_MGMT_FRAME_PROTECTION) {
3396 /* AP requires MFP, local configuration disables it */
3397 wpa_supplicant_deauthenticate(
3398 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3399 return -1;
3400 }
3401
3402 /* Update PMF from local configuration now that MFP validation was done
3403 * above */
3404 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3405
3406 /* Update GTK from AP's RSNE */
3407 sel = ie.group_cipher;
3408 if (ssid->group_cipher)
3409 sel &= ssid->group_cipher;
3410
3411 wpa_dbg(wpa_s, MSG_DEBUG,
3412 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3413 ie.group_cipher, ssid->group_cipher, sel);
3414 if (ie.group_cipher && !sel) {
3415 wpa_supplicant_deauthenticate(
3416 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3417 return -1;
3418 }
3419
3420 wpa_s->group_cipher = ie.group_cipher;
3421 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3422 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3423 wpa_cipher_txt(wpa_s->group_cipher));
3424
3425 /* Update IGTK from AP RSN IE */
3426 sel = ie.mgmt_group_cipher;
3427 if (ssid->group_mgmt_cipher)
3428 sel &= ssid->group_mgmt_cipher;
3429
3430 wpa_dbg(wpa_s, MSG_DEBUG,
3431 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3432 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3433
3434 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3435 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3436 wpa_dbg(wpa_s, MSG_DEBUG,
3437 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3438 ie.capabilities);
3439 ie.mgmt_group_cipher = 0;
3440 }
3441
3442 if (ie.mgmt_group_cipher && !sel) {
3443 wpa_supplicant_deauthenticate(
3444 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3445 return -1;
3446 }
3447
3448 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3449 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3450 wpa_s->mgmt_group_cipher);
3451 if (wpa_s->mgmt_group_cipher)
3452 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3453 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3454 else
3455 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3456
3457 return 0;
3458}
3459
3460
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003461static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3462 union wpa_event_data *data)
3463{
Matthew Wang9ed1c792024-12-02 14:05:18 +00003464 int l, len, found = 0, wpa_found, rsn_found;
3465#ifndef CONFIG_NO_WPA
3466 int found_x = 0;
3467#endif /* CONFIG_NO_WPA */
Sunil Ravic0f5d412024-09-11 22:12:49 +00003468 const u8 *p, *ie;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003469 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003470 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003471#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Sunil Ravic0f5d412024-09-11 22:12:49 +00003472 struct wpa_ie_data wpa_ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003473#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Sunil Ravic0f5d412024-09-11 22:12:49 +00003474 enum wpa_rsn_override rsn_override;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003475
3476 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Sunil Ravi7f769292024-07-23 22:21:32 +00003477 wpa_s->ssid_verified = false;
3478 wpa_s->bigtk_set = false;
3479#ifdef CONFIG_SAE
3480#ifdef CONFIG_SME
3481 /* SAE H2E binds the SSID into PT and that verifies the SSID
3482 * implicitly. */
3483 if (wpa_s->sme.sae.state == SAE_ACCEPTED && wpa_s->sme.sae.h2e)
3484 wpa_s->ssid_verified = true;
3485#endif /* CONFIG_SME */
3486#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -07003487 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003488 if (data->assoc_info.req_ies)
3489 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3490 data->assoc_info.req_ies_len);
3491 if (data->assoc_info.resp_ies) {
3492 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3493 data->assoc_info.resp_ies_len);
3494#ifdef CONFIG_TDLS
3495 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3496 data->assoc_info.resp_ies_len);
3497#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003498#ifdef CONFIG_WNM
3499 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3500 data->assoc_info.resp_ies_len);
3501#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003502 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3503 data->assoc_info.resp_ies_len);
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00003504 if ((wpa_s->hw_capab & BIT(CAPAB_VHT)) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07003505 get_ie(data->assoc_info.resp_ies,
3506 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3507 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003508
3509 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3510 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003511 }
3512 if (data->assoc_info.beacon_ies)
3513 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3514 data->assoc_info.beacon_ies,
3515 data->assoc_info.beacon_ies_len);
3516 if (data->assoc_info.freq)
3517 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3518 data->assoc_info.freq);
3519
Hai Shalom021b0b52019-04-10 11:17:58 -07003520 wpa_s->connection_set = 0;
3521 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3522 struct ieee802_11_elems req_elems, resp_elems;
3523
3524 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3525 data->assoc_info.req_ies_len,
3526 &req_elems, 0) != ParseFailed &&
3527 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3528 data->assoc_info.resp_ies_len,
3529 &resp_elems, 0) != ParseFailed) {
3530 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003531 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3532 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003533 wpa_s->connection_ht = req_elems.ht_capabilities &&
3534 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003535 /* Do not include subset of VHT on 2.4 GHz vendor
3536 * extension in consideration for reporting VHT
3537 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003538 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003539 resp_elems.vht_capabilities &&
3540 (!data->assoc_info.freq ||
3541 wpas_freq_to_band(data->assoc_info.freq) !=
3542 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003543 wpa_s->connection_he = req_elems.he_capabilities &&
3544 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003545 wpa_s->connection_eht = req_elems.eht_capabilities &&
3546 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003547
3548 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3549 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3550 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3551 max_nss_rx_req : max_nss_rx_resp;
3552 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3553 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3554 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3555 max_nss_tx_req : max_nss_tx_resp;
3556
3557 struct supported_chan_width sta_supported_chan_width =
3558 get_supported_channel_width(&req_elems);
3559 enum chan_width ap_operation_chan_width =
3560 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303561 if (wpa_s->connection_vht || wpa_s->connection_he ||
3562 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003563 wpa_s->connection_channel_bandwidth =
3564 get_sta_operation_chan_width(ap_operation_chan_width,
3565 sta_supported_chan_width);
3566 } else if (wpa_s->connection_ht) {
3567 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3568 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3569 } else {
3570 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3571 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003572 if (req_elems.rrm_enabled)
3573 wpa_s->rrm.rrm_used = 1;
Ainy Kumari322d4fd2024-02-14 13:05:40 +05303574 wpa_s->ap_t2lm_negotiation_support =
3575 is_ap_t2lm_negotiation_supported(resp_elems.basic_mle,
3576 resp_elems.basic_mle_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07003577 }
3578 }
3579
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003580 p = data->assoc_info.req_ies;
3581 l = data->assoc_info.req_ies_len;
3582
3583 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3584 while (p && l >= 2) {
3585 len = p[1] + 2;
3586 if (len > l) {
3587 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3588 p, l);
3589 break;
3590 }
Hai Shalomc3565922019-10-28 11:58:20 -07003591 if (!found &&
3592 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3593 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3594 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3595 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3596 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003597 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3598 break;
3599 found = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07003600 wpa_find_assoc_pmkid(wpa_s,
3601 data->assoc_info.authorized);
Hai Shalomc3565922019-10-28 11:58:20 -07003602 }
Matthew Wang9ed1c792024-12-02 14:05:18 +00003603#ifndef CONFIG_NO_WPA
Hai Shalomc3565922019-10-28 11:58:20 -07003604 if (!found_x && p[0] == WLAN_EID_RSNX) {
3605 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3606 break;
3607 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003608 }
Matthew Wang9ed1c792024-12-02 14:05:18 +00003609#endif /* CONFIG_NO_WPA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003610 l -= len;
3611 p += len;
3612 }
3613 if (!found && data->assoc_info.req_ies)
3614 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Matthew Wang9ed1c792024-12-02 14:05:18 +00003615#ifndef CONFIG_NO_WPA
Hai Shalomc3565922019-10-28 11:58:20 -07003616 if (!found_x && data->assoc_info.req_ies)
3617 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Matthew Wang9ed1c792024-12-02 14:05:18 +00003618#endif /* CONFIG_NO_WPA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003619
Winnie Chen4138eec2022-11-10 16:32:53 +08003620#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303621 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3622 * to a different security type, update the current supplicant configuration to use the AKM
3623 * and pairwise suites from the assoc IE passed by the driver.
3624 */
3625 if (wpas_driver_bss_selection(wpa_s)) {
Sunil Ravic0f5d412024-09-11 22:12:49 +00003626 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &wpa_ie) < 0)) {
Vinayak Yadawad14709082022-03-17 14:25:11 +05303627 /* Check if firmware has roamed to a different security network */
Sunil Ravic0f5d412024-09-11 22:12:49 +00003628 if(wpa_s->key_mgmt != wpa_ie.key_mgmt) {
Vinayak Yadawad14709082022-03-17 14:25:11 +05303629 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
Sunil Ravic0f5d412024-09-11 22:12:49 +00003630 wpa_ie.key_mgmt);
3631 wpa_s->key_mgmt = wpa_ie.key_mgmt;
Vinayak Yadawad14709082022-03-17 14:25:11 +05303632 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3633
3634 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3635 /* Restore PMK as it can get overwritten if the previous
3636 * association was to 802.1X.
3637 */
3638 if ((!(wpa_s->drv_flags &
3639 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3640 (wpa_s->current_ssid) &&
3641 (wpa_s->current_ssid->psk_set)) {
3642 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3643 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3644 "BSSID");
3645 wpa_supplicant_deauthenticate(
3646 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3647 return -1;
3648 }
3649 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3650 PMK_LEN, NULL, bssid);
3651 }
3652 }
3653 }
Sunil Ravic0f5d412024-09-11 22:12:49 +00003654 if(wpa_s->pairwise_cipher != wpa_ie.pairwise_cipher) {
Vinayak Yadawad14709082022-03-17 14:25:11 +05303655 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
Sunil Ravic0f5d412024-09-11 22:12:49 +00003656 "from Assoc IE", wpa_ie.pairwise_cipher);
3657 wpa_s->pairwise_cipher = wpa_ie.pairwise_cipher;
Vinayak Yadawad14709082022-03-17 14:25:11 +05303658 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3659 wpa_s->pairwise_cipher);
3660 }
3661 // TODO: Notify the framework about security type change b/230766005
3662 }
3663 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003664#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303665
Sunil Ravic0f5d412024-09-11 22:12:49 +00003666 rsn_override = RSN_OVERRIDE_NOT_USED;
3667 ie = get_vendor_ie(data->assoc_info.req_ies,
3668 data->assoc_info.req_ies_len,
3669 RSN_SELECTION_IE_VENDOR_TYPE);
3670 if (ie && ie[1] >= 4 + 1) {
3671 switch (ie[2 + 4]) {
3672 case RSN_SELECTION_RSNE:
3673 rsn_override = RSN_OVERRIDE_RSNE;
3674 break;
3675 case RSN_SELECTION_RSNE_OVERRIDE:
3676 rsn_override = RSN_OVERRIDE_RSNE_OVERRIDE;
3677 break;
3678 case RSN_SELECTION_RSNE_OVERRIDE_2:
3679 rsn_override = RSN_OVERRIDE_RSNE_OVERRIDE_2;
3680 break;
3681 }
3682 }
3683 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_OVERRIDE, rsn_override);
3684
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003685#ifdef CONFIG_FILS
3686#ifdef CONFIG_SME
Sunil Ravi7f769292024-07-23 22:21:32 +00003687 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3688 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) {
3689 if (!data->assoc_info.resp_frame ||
3690 fils_process_assoc_resp(wpa_s->wpa,
3691 data->assoc_info.resp_frame,
3692 data->assoc_info.resp_frame_len) <
3693 0) {
3694 wpa_supplicant_deauthenticate(wpa_s,
3695 WLAN_REASON_UNSPECIFIED);
3696 return -1;
3697 }
3698
3699 /* FILS use of an AEAD cipher include the SSID element in
3700 * (Re)Association Request frame in the AAD and since the AP
3701 * accepted that, the SSID was verified. */
3702 wpa_s->ssid_verified = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003703 }
3704#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003705
3706 /* Additional processing for FILS when SME is in driver */
3707 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3708 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3709 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003710#endif /* CONFIG_FILS */
3711
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003712#ifdef CONFIG_OWE
3713 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003714 !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003715 (!bssid_known ||
Sunil Ravi036cec52023-03-29 11:35:17 -07003716 owe_process_assoc_resp(wpa_s->wpa,
3717 wpa_s->valid_links ?
3718 wpa_s->ap_mld_addr : bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003719 data->assoc_info.resp_ies,
3720 data->assoc_info.resp_ies_len) < 0)) {
3721 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3722 return -1;
3723 }
3724#endif /* CONFIG_OWE */
3725
Hai Shalom021b0b52019-04-10 11:17:58 -07003726#ifdef CONFIG_DPP2
3727 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003728 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3729 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003730 struct ieee802_11_elems elems;
3731
3732 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3733 data->assoc_info.resp_ies_len,
3734 &elems, 0) == ParseFailed ||
3735 !elems.owe_dh)
3736 goto no_pfs;
3737 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3738 elems.owe_dh_len) < 0) {
3739 wpa_supplicant_deauthenticate(wpa_s,
3740 WLAN_REASON_UNSPECIFIED);
3741 return -1;
3742 }
3743
3744 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3745 }
3746no_pfs:
3747#endif /* CONFIG_DPP2 */
3748
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003749#ifdef CONFIG_IEEE80211R
3750#ifdef CONFIG_SME
3751 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003752 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003753 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3754 data->assoc_info.resp_ies,
3755 data->assoc_info.resp_ies_len,
3756 bssid) < 0) {
3757 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3758 "Reassociation Response failed");
3759 wpa_supplicant_deauthenticate(
3760 wpa_s, WLAN_REASON_INVALID_IE);
3761 return -1;
3762 }
Sunil Ravi7f769292024-07-23 22:21:32 +00003763 /* SSID is included in PMK-R0 derivation, so it is verified
3764 * implicitly. */
3765 wpa_s->ssid_verified = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003766 }
3767
3768 p = data->assoc_info.resp_ies;
3769 l = data->assoc_info.resp_ies_len;
3770
3771#ifdef CONFIG_WPS_STRICT
3772 if (p && wpa_s->current_ssid &&
3773 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3774 struct wpabuf *wps;
3775 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3776 if (wps == NULL) {
3777 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3778 "include WPS IE in (Re)Association Response");
3779 return -1;
3780 }
3781
3782 if (wps_validate_assoc_resp(wps) < 0) {
3783 wpabuf_free(wps);
3784 wpa_supplicant_deauthenticate(
3785 wpa_s, WLAN_REASON_INVALID_IE);
3786 return -1;
3787 }
3788 wpabuf_free(wps);
3789 }
3790#endif /* CONFIG_WPS_STRICT */
3791
3792 /* Go through the IEs and make a copy of the MDIE, if present. */
3793 while (p && l >= 2) {
3794 len = p[1] + 2;
3795 if (len > l) {
3796 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3797 p, l);
3798 break;
3799 }
3800 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3801 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3802 wpa_s->sme.ft_used = 1;
3803 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3804 MOBILITY_DOMAIN_ID_LEN);
3805 break;
3806 }
3807 l -= len;
3808 p += len;
3809 }
3810#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003811#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303812 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3813 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3814 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
Vinayak Yadawadf473bef2024-04-04 15:33:29 +05303815 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) ||
3816 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303817 wpa_ft_is_completed(wpa_s->wpa)) {
3818 return 0;
3819 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003820#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003821
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003822 /* Process FT when SME is in the driver */
3823 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3824 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003825 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003826 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3827 data->assoc_info.resp_ies,
3828 data->assoc_info.resp_ies_len,
3829 bssid) < 0) {
3830 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3831 "Reassociation Response failed");
3832 wpa_supplicant_deauthenticate(
3833 wpa_s, WLAN_REASON_INVALID_IE);
3834 return -1;
3835 }
3836 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
Sunil Ravi7f769292024-07-23 22:21:32 +00003837 /* SSID is included in PMK-R0 derivation, so it is verified
3838 * implicitly. */
3839 wpa_s->ssid_verified = true;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003840 }
3841
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003842 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3843 data->assoc_info.resp_ies_len);
3844#endif /* CONFIG_IEEE80211R */
3845
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003846#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07003847 if (bssid_known)
3848 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3849 data->assoc_info.resp_ies,
3850 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003851#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -07003852
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003853 /* WPA/RSN IE from Beacon/ProbeResp */
3854 p = data->assoc_info.beacon_ies;
3855 l = data->assoc_info.beacon_ies_len;
3856
3857 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3858 */
3859 wpa_found = rsn_found = 0;
3860 while (p && l >= 2) {
3861 len = p[1] + 2;
3862 if (len > l) {
3863 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3864 p, l);
3865 break;
3866 }
3867 if (!wpa_found &&
3868 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3869 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3870 wpa_found = 1;
3871 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3872 }
3873
3874 if (!rsn_found &&
3875 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3876 rsn_found = 1;
3877 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3878 }
3879
Sunil Ravic0f5d412024-09-11 22:12:49 +00003880 if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3881 WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_2_IE_VENDOR_TYPE)
3882 wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, p, len);
Sunil Ravi7f769292024-07-23 22:21:32 +00003883
Sunil Ravic0f5d412024-09-11 22:12:49 +00003884 if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3885 WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_IE_VENDOR_TYPE)
3886 wpa_sm_set_ap_rsne_override(wpa_s->wpa, p, len);
Sunil Ravi7f769292024-07-23 22:21:32 +00003887
Hai Shalomc3565922019-10-28 11:58:20 -07003888 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3889 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3890
Sunil Ravic0f5d412024-09-11 22:12:49 +00003891 if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
Sunil Ravi7f769292024-07-23 22:21:32 +00003892 WPA_GET_BE32(&p[2]) == RSNXE_OVERRIDE_IE_VENDOR_TYPE)
Sunil Ravic0f5d412024-09-11 22:12:49 +00003893 wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, p, len);
Sunil Ravi7f769292024-07-23 22:21:32 +00003894
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003895 l -= len;
3896 p += len;
3897 }
3898
3899 if (!wpa_found && data->assoc_info.beacon_ies)
3900 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003901 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003902 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003903 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
Sunil Ravic0f5d412024-09-11 22:12:49 +00003904 wpa_sm_set_ap_rsne_override(wpa_s->wpa, NULL, 0);
3905 wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, NULL, 0);
3906 wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003907 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003908 if (wpa_found || rsn_found)
3909 wpa_s->ap_ies_from_associnfo = 1;
3910
Sunil Ravi99c035e2024-07-12 01:42:03 +00003911 if (wpa_s->assoc_freq && data->assoc_info.freq) {
3912 struct wpa_bss *bss;
3913 unsigned int freq = 0;
3914
3915 if (bssid_known) {
3916 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
3917 if (bss)
3918 freq = bss->freq;
3919 }
3920 if (freq != data->assoc_info.freq) {
3921 wpa_printf(MSG_DEBUG,
3922 "Operating frequency changed from %u to %u MHz",
3923 wpa_s->assoc_freq, data->assoc_info.freq);
3924 wpa_supplicant_update_scan_results(wpa_s, bssid);
3925 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03003926 }
3927
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003928 wpa_s->assoc_freq = data->assoc_info.freq;
3929
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003930#ifndef CONFIG_NO_ROBUST_AV
Hai Shalomc1a21442022-02-04 13:43:00 -08003931 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3932 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003933#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08003934
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003935 return 0;
3936}
3937
3938
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003939static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3940{
Hai Shalomc3565922019-10-28 11:58:20 -07003941 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Sunil Ravic0f5d412024-09-11 22:12:49 +00003942 const u8 *rsnoe, *rsno2e, *rsnxoe;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003943
3944 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3945 return -1;
3946
3947 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3948 return 0;
3949
3950 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3951 WPA_IE_VENDOR_TYPE);
Sunil Ravic0f5d412024-09-11 22:12:49 +00003952 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
3953 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
3954 rsnoe = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3955 RSNE_OVERRIDE_IE_VENDOR_TYPE);
3956 rsno2e = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3957 RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
3958 rsnxoe = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3959 RSNXE_OVERRIDE_IE_VENDOR_TYPE);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003960
3961 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3962 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3963 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003964 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3965 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
Sunil Ravic0f5d412024-09-11 22:12:49 +00003966 bss_rsnx ? 2 + bss_rsnx[1] : 0) ||
3967 wpa_sm_set_ap_rsne_override(wpa_s->wpa, rsnoe,
3968 rsnoe ? 2 + rsnoe[1] : 0) ||
3969 wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, rsno2e,
3970 rsno2e ? 2 + rsno2e[1] : 0) ||
3971 wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, rsnxoe,
3972 rsnxoe ? 2 + rsnxoe[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003973 return -1;
3974
3975 return 0;
3976}
3977
3978
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003979static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3980 union wpa_event_data *data)
3981{
3982#ifdef CONFIG_FST
3983 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3984 struct wpa_bss *bss = wpa_s->current_bss;
3985 const u8 *ieprb, *iebcn;
3986
3987 wpabuf_free(wpa_s->received_mb_ies);
3988 wpa_s->received_mb_ies = NULL;
3989
3990 if (ai &&
3991 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3992 wpa_printf(MSG_DEBUG,
3993 "FST: MB IEs updated from Association Response frame");
3994 return;
3995 }
3996
3997 if (ai &&
3998 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3999 wpa_printf(MSG_DEBUG,
4000 "FST: MB IEs updated from association event Beacon IEs");
4001 return;
4002 }
4003
4004 if (!bss)
4005 return;
4006
Hai Shalom60840252021-02-19 19:02:11 -08004007 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004008 iebcn = ieprb + bss->ie_len;
4009
4010 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
4011 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
4012 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
4013 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
4014#endif /* CONFIG_FST */
4015}
4016
4017
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004018static unsigned int wpas_ml_parse_assoc(struct wpa_supplicant *wpa_s,
4019 struct ieee802_11_elems *elems,
4020 struct ml_sta_link_info *ml_info)
4021{
4022 struct wpabuf *mlbuf;
4023 struct ieee80211_eht_ml *ml;
4024 size_t ml_len;
4025 struct eht_ml_basic_common_info *common_info;
4026 const u8 *pos;
4027 u16 eml_capa = 0, mld_capa = 0;
4028 const u16 control =
4029 host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC |
4030 BASIC_MULTI_LINK_CTRL_PRES_LINK_ID |
4031 BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT);
4032 u8 expected_common_info_len = 9;
4033 unsigned int i = 0;
4034 u16 ml_control;
4035
4036 if (!wpa_s->valid_links || !elems->basic_mle || !elems->basic_mle_len)
4037 return 0;
4038
4039 mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
4040 if (!mlbuf)
4041 return 0;
4042
4043 ml = (struct ieee80211_eht_ml *) wpabuf_head(mlbuf);
4044 ml_len = wpabuf_len(mlbuf);
4045 if (ml_len < sizeof(*ml))
4046 goto out;
4047
4048 os_memset(ml_info, 0, sizeof(*ml_info) * MAX_NUM_MLD_LINKS);
4049
4050 ml_control = le_to_host16(ml->ml_control);
4051
4052 if ((ml_control & control) != control) {
4053 wpa_printf(MSG_DEBUG, "MLD: Invalid presence BM=0x%x",
4054 ml_control);
4055 goto out;
4056 }
4057
4058 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
4059 wpa_printf(MSG_DEBUG, "MLD: EML capabilities included");
4060 expected_common_info_len += 2;
4061 }
4062
4063 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
4064 wpa_printf(MSG_DEBUG, "MLD: MLD capabilities included");
4065 expected_common_info_len += 2;
4066 }
4067
4068 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
4069 wpa_printf(MSG_DEBUG,
4070 "MLD: Unexpected: medium sync delay info present");
4071 expected_common_info_len += 2;
4072 }
4073
4074 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
4075 wpa_printf(MSG_DEBUG,
4076 "MLD: Unexpected: MLD ID present");
4077 expected_common_info_len++;
4078 }
4079
4080 if (sizeof(*ml) + expected_common_info_len > ml_len) {
4081 wpa_printf(MSG_DEBUG,
4082 "MLD: Not enough bytes for common info. ml_len=%zu",
4083 ml_len);
4084 goto out;
4085 }
4086
4087 common_info = (struct eht_ml_basic_common_info *) ml->variable;
4088 if (common_info->len != expected_common_info_len) {
4089 wpa_printf(MSG_DEBUG,
4090 "MLD: Invalid common info len=%u. expected=%u",
4091 common_info->len, expected_common_info_len);
4092 goto out;
4093 }
4094
4095 wpa_printf(MSG_DEBUG, "MLD: address: " MACSTR,
4096 MAC2STR(common_info->mld_addr));
4097
4098 if (!ether_addr_equal(wpa_s->ap_mld_addr, common_info->mld_addr)) {
4099 wpa_printf(MSG_DEBUG, "MLD: Mismatching MLD address (expected "
4100 MACSTR ")", MAC2STR(wpa_s->ap_mld_addr));
4101 goto out;
4102 }
4103
4104 pos = common_info->variable;
4105
4106 /* Store the information for the association link */
4107 ml_info[i].link_id = *pos;
4108 pos++;
4109
4110 /* Skip the BSS Parameters Change Count */
4111 pos++;
4112
4113 /* Skip the Medium Synchronization Delay Information if present */
4114 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO)
4115 pos += 2;
4116
4117 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
4118 eml_capa = WPA_GET_LE16(pos);
4119 pos += 2;
4120 }
4121
4122 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
4123 mld_capa = WPA_GET_LE16(pos);
4124 pos += 2;
4125 }
4126
4127 wpa_printf(MSG_DEBUG,
4128 "MLD: link_id=%u, eml=0x%x, mld=0x%x",
4129 ml_info[i].link_id, eml_capa, mld_capa);
4130
4131 i++;
4132
4133 pos = ((u8 *) common_info) + common_info->len;
4134 ml_len -= sizeof(*ml) + common_info->len;
4135 while (ml_len > 2 && i < MAX_NUM_MLD_LINKS) {
4136 u8 sub_elem_len = pos[1];
4137 u8 sta_info_len;
4138 u8 nstr_bitmap_len = 0;
4139 u16 ctrl;
4140 const u8 *end;
4141
4142 wpa_printf(MSG_DEBUG, "MLD: Subelement len=%u", sub_elem_len);
4143
4144 if (sub_elem_len > ml_len - 2) {
4145 wpa_printf(MSG_DEBUG,
4146 "MLD: Invalid link info len: %u > %zu",
4147 2 + sub_elem_len, ml_len);
4148 goto out;
4149 }
4150
4151 switch (*pos) {
4152 case EHT_ML_SUB_ELEM_PER_STA_PROFILE:
4153 break;
4154 case EHT_ML_SUB_ELEM_FRAGMENT:
4155 case EHT_ML_SUB_ELEM_VENDOR:
4156 wpa_printf(MSG_DEBUG,
4157 "MLD: Skip subelement id=%u, len=%u",
4158 *pos, sub_elem_len);
4159 pos += 2 + sub_elem_len;
4160 ml_len -= 2 + sub_elem_len;
4161 continue;
4162 default:
4163 wpa_printf(MSG_DEBUG, "MLD: Unknown subelement ID=%u",
4164 *pos);
4165 goto out;
4166 }
4167
4168 end = pos + 2 + sub_elem_len;
4169
4170 /* Skip the subelement ID and the length */
4171 pos += 2;
4172 ml_len -= 2;
4173
4174 if (end - pos < 2)
4175 goto out;
4176
4177 /* Get the station control field */
4178 ctrl = WPA_GET_LE16(pos);
4179
4180 pos += 2;
4181 ml_len -= 2;
4182
4183 if (!(ctrl & EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK)) {
4184 wpa_printf(MSG_DEBUG,
4185 "MLD: Per STA complete profile expected");
4186 goto out;
4187 }
4188
4189 if (!(ctrl & EHT_PER_STA_CTRL_MAC_ADDR_PRESENT_MSK)) {
4190 wpa_printf(MSG_DEBUG,
4191 "MLD: Per STA MAC address not present");
4192 goto out;
4193 }
4194
4195 if (!(ctrl & EHT_PER_STA_CTRL_TSF_OFFSET_PRESENT_MSK)) {
4196 wpa_printf(MSG_DEBUG,
4197 "MLD: Per STA TSF offset not present");
4198 goto out;
4199 }
4200
4201 if (!(ctrl & EHT_PER_STA_CTRL_BEACON_INTERVAL_PRESENT_MSK)) {
4202 wpa_printf(MSG_DEBUG,
4203 "MLD: Beacon interval not present");
4204 goto out;
4205 }
4206
4207 if (!(ctrl & EHT_PER_STA_CTRL_DTIM_INFO_PRESENT_MSK)) {
4208 wpa_printf(MSG_DEBUG,
4209 "MLD: DTIM information not present");
4210 goto out;
4211 }
4212
4213 if (ctrl & EHT_PER_STA_CTRL_NSTR_LINK_PAIR_PRESENT_MSK) {
4214 if (ctrl & EHT_PER_STA_CTRL_NSTR_BM_SIZE_MSK)
4215 nstr_bitmap_len = 2;
4216 else
4217 nstr_bitmap_len = 1;
4218 }
4219
4220 if (!(ctrl & EHT_PER_STA_CTRL_BSS_PARAM_CNT_PRESENT_MSK)) {
4221 wpa_printf(MSG_DEBUG,
4222 "MLD: BSS params change count not present");
4223 goto out;
4224 }
4225
4226 sta_info_len = 1 + ETH_ALEN + 8 + 2 + 2 + 1 + nstr_bitmap_len;
4227 if (sta_info_len > ml_len || sta_info_len > end - pos ||
4228 sta_info_len + 2 > sub_elem_len ||
4229 sta_info_len != *pos) {
4230 wpa_printf(MSG_DEBUG,
4231 "MLD: Invalid STA info len=%u, len=%u",
4232 sta_info_len, *pos);
4233 goto out;
4234 }
4235
4236 /* Get the link address */
4237 wpa_printf(MSG_DEBUG,
4238 "MLD: link addr: " MACSTR " nstr BM len=%u",
4239 MAC2STR(pos + 1), nstr_bitmap_len);
4240
4241 ml_info[i].link_id = ctrl & EHT_PER_STA_CTRL_LINK_ID_MSK;
4242 os_memcpy(ml_info[i].bssid, pos + 1, ETH_ALEN);
4243
4244 pos += sta_info_len;
4245 ml_len -= sta_info_len;
4246
4247 wpa_printf(MSG_DEBUG, "MLD: sub_elem_len=%u, sta_info_len=%u",
4248 sub_elem_len, sta_info_len);
4249
4250 sub_elem_len -= sta_info_len + 2;
4251 if (sub_elem_len < 4) {
4252 wpa_printf(MSG_DEBUG, "MLD: Per STA profile too short");
4253 goto out;
4254 }
4255
4256 wpa_hexdump(MSG_MSGDUMP, "MLD: STA profile", pos, sub_elem_len);
4257 ml_info[i].status = WPA_GET_LE16(pos + 2);
4258
4259 pos += sub_elem_len;
4260 ml_len -= sub_elem_len;
4261
4262 i++;
4263 }
4264
4265 wpabuf_free(mlbuf);
4266 return i;
4267out:
4268 wpabuf_free(mlbuf);
4269 return 0;
4270}
4271
4272
Sunil Ravi89eba102022-09-13 21:04:37 -07004273static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
4274{
4275 struct driver_sta_mlo_info mlo;
4276 int i;
4277
Sunil Ravi77d572f2023-01-17 23:58:31 +00004278 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07004279 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
4280 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
4281 wpa_supplicant_deauthenticate(wpa_s,
4282 WLAN_REASON_DEAUTH_LEAVING);
4283 return -1;
4284 }
4285
4286 if (wpa_s->valid_links == mlo.valid_links) {
4287 bool match = true;
4288
4289 if (!mlo.valid_links)
4290 return 0;
4291
Sunil Ravi99c035e2024-07-12 01:42:03 +00004292 for_each_link(mlo.valid_links, i) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004293 if (!ether_addr_equal(wpa_s->links[i].addr,
4294 mlo.links[i].addr) ||
4295 !ether_addr_equal(wpa_s->links[i].bssid,
4296 mlo.links[i].bssid)) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004297 match = false;
4298 break;
4299 }
4300 }
4301
Sunil Ravi77d572f2023-01-17 23:58:31 +00004302 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004303 ether_addr_equal(wpa_s->ap_mld_addr, mlo.ap_mld_addr))
Sunil Ravi89eba102022-09-13 21:04:37 -07004304 return 0;
4305 }
4306
4307 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004308 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07004309 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
Sunil Ravi99c035e2024-07-12 01:42:03 +00004310 for_each_link(wpa_s->valid_links, i) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004311 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
4312 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
4313 wpa_s->links[i].freq = mlo.links[i].freq;
4314 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
4315 }
4316
4317 return 0;
4318}
4319
4320
Sunil Ravi77d572f2023-01-17 23:58:31 +00004321static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
4322{
4323 struct driver_sta_mlo_info drv_mlo;
4324 struct wpa_sm_mlo wpa_mlo;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004325 int i;
4326
4327 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
4328 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
4329 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
4330 return -1;
4331 }
4332
4333 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
4334 if (!drv_mlo.valid_links)
4335 goto out;
4336
4337 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
4338 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
4339 wpa_mlo.valid_links = drv_mlo.valid_links;
4340 wpa_mlo.req_links = drv_mlo.req_links;
4341
Sunil Ravi99c035e2024-07-12 01:42:03 +00004342 for_each_link(drv_mlo.req_links, i) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004343 struct wpa_bss *bss;
Sunil Ravic0f5d412024-09-11 22:12:49 +00004344 const u8 *rsne, *rsnxe, *rsnoe, *rsno2e, *rsnxoe;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004345
Sunil Ravi77d572f2023-01-17 23:58:31 +00004346 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
4347 if (!bss) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004348 wpa_dbg(wpa_s, MSG_INFO,
4349 "Failed to get MLO link %d BSS", i);
4350 return -1;
4351 }
4352
Sunil Ravic0f5d412024-09-11 22:12:49 +00004353 rsne = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4354 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
4355 rsnoe = wpa_bss_get_vendor_ie(bss,
4356 RSNE_OVERRIDE_IE_VENDOR_TYPE);
4357 rsno2e = wpa_bss_get_vendor_ie(bss,
4358 RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
4359 rsnxoe = wpa_bss_get_vendor_ie(bss,
4360 RSNXE_OVERRIDE_IE_VENDOR_TYPE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004361
Sunil Ravic0f5d412024-09-11 22:12:49 +00004362 wpa_mlo.links[i].ap_rsne = rsne ? (u8 *) rsne : NULL;
4363 wpa_mlo.links[i].ap_rsne_len = rsne ? 2 + rsne[1] : 0;
4364 wpa_mlo.links[i].ap_rsnxe = rsnxe ? (u8 *) rsnxe : NULL;
4365 wpa_mlo.links[i].ap_rsnxe_len = rsnxe ? 2 + rsnxe[1] : 0;
4366 wpa_mlo.links[i].ap_rsnoe = rsnoe ? (u8 *) rsnoe : NULL;
4367 wpa_mlo.links[i].ap_rsnoe_len = rsnoe ? 2 + rsnoe[1] : 0;
4368 wpa_mlo.links[i].ap_rsno2e = rsno2e ? (u8 *) rsno2e : NULL;
4369 wpa_mlo.links[i].ap_rsno2e_len = rsno2e ? 2 + rsno2e[1] : 0;
4370 wpa_mlo.links[i].ap_rsnxoe = rsnxoe ? (u8 *) rsnxoe : NULL;
4371 wpa_mlo.links[i].ap_rsnxoe_len = rsnxoe ? 2 + rsnxoe[1] : 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004372
4373 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
4374 ETH_ALEN);
4375 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
4376 ETH_ALEN);
4377 }
4378
4379out:
4380 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
4381}
4382
4383
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004384static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
4385 union wpa_event_data *data)
4386{
4387 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004388 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004389 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07004390#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4391 struct wpa_bss *bss;
4392#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08004393#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304394 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08004395#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004396
4397#ifdef CONFIG_AP
4398 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004399 if (!data)
4400 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004401 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
4402 data->assoc_info.addr,
4403 data->assoc_info.req_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004404 data->assoc_info.req_ies_len, NULL, 0,
4405 NULL, data->assoc_info.reassoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004406 return;
4407 }
4408#endif /* CONFIG_AP */
4409
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004410 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07004411 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004412
Andy Kuoaba17c12022-04-14 16:05:31 +08004413#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304414 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
4415 struct wpa_ft_ies parse;
4416 /* Check for FT reassociation is done by the driver */
4417#ifdef CONFIG_IEEE80211R
4418 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05304419 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05304420 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004421 data->assoc_info.resp_ies_len, &parse, use_sha384, false) < 0) {
Mir Ali677e7482020-11-12 19:49:02 +05304422 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
4423 return;
4424 }
4425 if (parse.rsn_pmkid != NULL) {
4426 wpa_set_ft_completed(wpa_s->wpa);
4427 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
4428 }
4429 }
4430#endif /* CONFIG_IEEE80211R */
4431 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004432#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05304433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004434 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07004435
4436 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4437 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
4438 wpa_supplicant_deauthenticate(
4439 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4440 return;
4441 }
4442
Sunil Ravi89eba102022-09-13 21:04:37 -07004443 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
4444 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
4445 wpa_supplicant_deauthenticate(wpa_s,
4446 WLAN_REASON_DEAUTH_LEAVING);
4447 return;
4448 }
4449
Sunil Ravia04bd252022-05-02 22:54:18 -07004450 if (ft_completed &&
4451 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
4452 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
4453 MAC2STR(bssid));
4454 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
4455 wpa_printf(MSG_ERROR,
4456 "Can't find target AP's information!");
4457 return;
4458 }
4459 wpa_supplicant_assoc_update_ie(wpa_s);
4460 }
4461
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004462 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
4463 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004464 /*
4465 * FILS authentication can share the same mechanism to mark the
4466 * connection fully authenticated, so set ft_completed also based on
4467 * FILS result.
4468 */
4469 if (!ft_completed)
4470 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004471
Andy Kuoaba17c12022-04-14 16:05:31 +08004472#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304473 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
4474 /*
4475 * For driver based roaming, insert PSK during
4476 * the initial association
4477 */
4478 if (is_zero_ether_addr(wpa_s->bssid) &&
4479 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
4480 /*
4481 * In case the driver wants to handle re-assocs,
4482 * pass it down the PMK.
4483 */
4484 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
4485 wpa_sm_install_pmk(wpa_s->wpa);
4486 }
Mir Ali677e7482020-11-12 19:49:02 +05304487 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304488#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08004489
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004490 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004491 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004492 if (os_reltime_initialized(&wpa_s->session_start)) {
4493 os_reltime_age(&wpa_s->session_start,
4494 &wpa_s->session_length);
4495 wpa_s->session_start.sec = 0;
4496 wpa_s->session_start.usec = 0;
4497 wpas_notify_session_length(wpa_s);
4498 } else {
4499 wpas_notify_auth_changed(wpa_s);
4500 os_get_reltime(&wpa_s->session_start);
4501 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004502 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
4503 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004504 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004505 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004506 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4507 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004508 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004509
4510 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
4511 wpa_clear_keys(wpa_s, bssid);
4512 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00004513 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004514 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004515 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4516 return;
4517 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004518 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004519
Hai Shalomc1a21442022-02-04 13:43:00 -08004520 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4521 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
4522 return;
4523
Hai Shalomfdcde762020-04-02 11:19:20 -07004524 multi_ap_set_4addr_mode(wpa_s);
4525
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004526 if (wpa_s->conf->ap_scan == 1 &&
4527 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004528 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
4529 wpa_msg(wpa_s, MSG_WARNING,
4530 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004531 }
4532
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004533 wpas_fst_update_mb_assoc(wpa_s, data);
4534
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004535#ifdef CONFIG_SME
Sunil Ravi640215c2023-06-28 23:08:09 +00004536 /*
4537 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
4538 * (for MLO connection) as the previous BSSID for subsequent
4539 * reassociation requests handled by SME-in-wpa_supplicant.
4540 */
4541 os_memcpy(wpa_s->sme.prev_bssid,
4542 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004543 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07004544 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004545#endif /* CONFIG_SME */
4546
4547 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
4548 if (wpa_s->current_ssid) {
4549 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
4550 * initialized before association, but for other modes,
4551 * initialize PC/SC here, if the current configuration needs
4552 * smartcard or SIM/USIM. */
4553 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
4554 }
4555 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004556
4557 if (wpa_sm_set_ml_info(wpa_s)) {
4558 wpa_dbg(wpa_s, MSG_INFO,
4559 "Failed to set MLO connection info to wpa_sm");
4560 wpa_supplicant_deauthenticate(wpa_s,
4561 WLAN_REASON_DEAUTH_LEAVING);
4562 return;
4563 }
4564
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004565 if (wpa_s->l2)
4566 l2_packet_notify_auth_start(wpa_s->l2);
4567
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004568 already_authorized = data && data->assoc_info.authorized;
4569
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004570 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07004571 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004572 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
4573 * state machine may transit to AUTHENTICATING state based on obsolete
4574 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
4575 * AUTHENTICATED without ever giving chance to EAP state machine to
4576 * reset the state.
4577 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004578 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07004579 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4580 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004581 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004582 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4583 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
4584 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07004585 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07004586 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004587 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07004588 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004589 wpa_s->eapol_received = 0;
4590 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4591 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4592 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004593 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004594 if (wpa_s->current_ssid &&
4595 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004596 (wpa_s->drv_flags &
4597 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4598 /*
4599 * Set the key after having received joined-IBSS event
4600 * from the driver.
4601 */
4602 wpa_supplicant_set_wpa_none_key(wpa_s,
4603 wpa_s->current_ssid);
4604 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004605 wpa_supplicant_cancel_auth_timeout(wpa_s);
4606 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4607 } else if (!ft_completed) {
4608 /* Timeout for receiving the first EAPOL packet */
4609 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
4610 }
4611 wpa_supplicant_cancel_scan(wpa_s);
4612
Hai Shalom5f92bc92019-04-18 11:54:11 -07004613 if (ft_completed) {
4614 /*
4615 * FT protocol completed - make sure EAPOL state machine ends
4616 * up in authenticated.
4617 */
4618 wpa_supplicant_cancel_auth_timeout(wpa_s);
4619 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004620 eapol_sm_notify_portValid(wpa_s->eapol, true);
4621 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07004622 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4623 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304624 if (already_authorized) {
4625 /*
4626 * We are done; the driver will take care of RSN 4-way
4627 * handshake.
4628 */
4629 wpa_supplicant_cancel_auth_timeout(wpa_s);
4630 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4631 eapol_sm_notify_portValid(wpa_s->eapol, true);
4632 eapol_sm_notify_eap_success(wpa_s->eapol, true);
4633 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004634 /* Update port, WPA_COMPLETED state from the
4635 * EVENT_PORT_AUTHORIZED handler when the driver is done
4636 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304637 */
Sunil Ravi167279a2023-05-31 01:12:34 +00004638 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004639 wpa_msg(wpa_s, MSG_INFO,
4640 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304641 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004642 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004643 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4644 /*
4645 * The driver will take care of RSN 4-way handshake, so we need
4646 * to allow EAPOL supplicant to complete its work without
4647 * waiting for WPA supplicant.
4648 */
Hai Shalome21d4e82020-04-29 16:34:06 -07004649 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004650 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004651#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05304652 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
4653 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4654 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
4655 wpa_s->key_mgmt);
4656 wpa_supplicant_deauthenticate(
4657 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4658 return;
4659 }
4660 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4661 wpa_s->assoc_freq = data->assoc_info.freq;
4662 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
4663 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004664#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
4665
Jouni Malinena05074c2012-12-21 21:35:35 +02004666 wpa_s->last_eapol_matches_bssid = 0;
4667
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004668#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07004669 if (wpa_s->rsne_override_eapol) {
4670 wpa_printf(MSG_DEBUG,
4671 "TESTING: RSNE EAPOL-Key msg 2/4 override");
4672 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4673 wpabuf_head(wpa_s->rsne_override_eapol),
4674 wpabuf_len(wpa_s->rsne_override_eapol));
4675 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004676 if (wpa_s->rsnxe_override_eapol) {
4677 wpa_printf(MSG_DEBUG,
4678 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4679 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4680 wpabuf_head(wpa_s->rsnxe_override_eapol),
4681 wpabuf_len(wpa_s->rsnxe_override_eapol));
4682 }
4683#endif /* CONFIG_TESTING_OPTIONS */
4684
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004685 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004686 struct os_reltime now, age;
4687 os_get_reltime(&now);
4688 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08004689 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004690 ether_addr_equal(wpa_s->pending_eapol_rx_src,
4691 wpa_s->valid_links ? wpa_s->ap_mld_addr :
4692 bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004693 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4694 "frame that was received just before "
4695 "association notification");
4696 wpa_supplicant_rx_eapol(
4697 wpa_s, wpa_s->pending_eapol_rx_src,
4698 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00004699 wpabuf_len(wpa_s->pending_eapol_rx),
4700 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004701 }
4702 wpabuf_free(wpa_s->pending_eapol_rx);
4703 wpa_s->pending_eapol_rx = NULL;
4704 }
4705
Hai Shalomfdcde762020-04-02 11:19:20 -07004706#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004707 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4708 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004709 wpa_s->current_ssid &&
4710 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004711 /* Set static WEP keys again */
4712 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4713 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004714#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004715
4716#ifdef CONFIG_IBSS_RSN
4717 if (wpa_s->current_ssid &&
4718 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4719 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4720 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4721 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004722 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004723 if (!wpa_s->ibss_rsn) {
4724 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4725 wpa_supplicant_deauthenticate(
4726 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4727 return;
4728 }
4729
4730 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4731 }
4732#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004733
4734 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004735
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004736#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004737 if (data) {
4738 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4739 data->assoc_info.resp_ies_len,
4740 &data->assoc_info.wmm_params);
4741
4742 if (wpa_s->reassoc_same_bss)
4743 wmm_ac_restore_tspecs(wpa_s);
4744 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004745#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004746
Hai Shalomc3565922019-10-28 11:58:20 -07004747#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4748 bss = wpa_bss_get_bssid(wpa_s, bssid);
4749#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004750#ifdef CONFIG_FILS
4751 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004752 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4753
4754 if (fils_cache_id)
4755 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4756 }
4757#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004758
4759#ifdef CONFIG_MBO
4760 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4761#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004762
4763#ifdef CONFIG_DPP2
4764 wpa_s->dpp_pfs_fallback = 0;
4765#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004766
4767 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4768 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004769}
4770
4771
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004772static int disconnect_reason_recoverable(u16 reason_code)
4773{
4774 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4775 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4776 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4777}
4778
4779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004780static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004781 u16 reason_code,
4782 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004783{
4784 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004785
4786 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4787 /*
4788 * At least Host AP driver and a Prism3 card seemed to be
4789 * generating streams of disconnected events when configuring
4790 * IBSS for WPA-None. Ignore them for now.
4791 */
4792 return;
4793 }
4794
4795 bssid = wpa_s->bssid;
4796 if (is_zero_ether_addr(bssid))
4797 bssid = wpa_s->pending_bssid;
4798
4799 if (!is_zero_ether_addr(bssid) ||
4800 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4801 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4802 " reason=%d%s",
4803 MAC2STR(bssid), reason_code,
4804 locally_generated ? " locally_generated=1" : "");
4805 }
4806}
4807
4808
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004809static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4810 int locally_generated)
4811{
4812 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004813 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004814 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4815 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004816 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004817
4818 /*
4819 * It looks like connection was lost while trying to go through PSK
4820 * 4-way handshake. Filter out known disconnection cases that are caused
4821 * by something else than PSK mismatch to avoid confusing reports.
4822 */
4823
4824 if (locally_generated) {
4825 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4826 return 0;
4827 }
4828
4829 return 1;
4830}
4831
4832
Jouni Malinen2b89da82012-08-31 22:04:41 +03004833static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4834 u16 reason_code,
4835 int locally_generated)
4836{
4837 const u8 *bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004838 struct wpa_bss *fast_reconnect = NULL;
4839 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004840 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004841
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004842 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4843 /*
4844 * At least Host AP driver and a Prism3 card seemed to be
4845 * generating streams of disconnected events when configuring
4846 * IBSS for WPA-None. Ignore them for now.
4847 */
4848 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4849 "IBSS/WPA-None mode");
4850 return;
4851 }
4852
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004853 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4854 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4855 locally_generated)
4856 /*
4857 * Remove the inactive AP (which is probably out of range) from
4858 * the BSS list after marking disassociation. In particular
4859 * mac80211-based drivers use the
4860 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4861 * locally generated disconnection events for cases where the
4862 * AP does not reply anymore.
4863 */
4864 curr = wpa_s->current_bss;
4865
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004866 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004867 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4868 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004869 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4870 return; /* P2P group removed */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004871 wpas_auth_failed(wpa_s, "WRONG_KEY", wpa_s->pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004872 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004873#ifdef CONFIG_DPP2
4874 wpas_dpp_send_conn_status_result(wpa_s,
4875 DPP_STATUS_AUTH_FAILURE);
4876#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004877 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004878 if (!wpa_s->disconnected &&
4879 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004880 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004881 wpas_wps_searching(wpa_s) ||
4882 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004883 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004884 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004885 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004886 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004887 wpa_s->wpa_state);
4888 if (wpa_s->wpa_state == WPA_COMPLETED &&
4889 wpa_s->current_ssid &&
4890 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004891 (wpa_s->own_reconnect_req ||
4892 (!locally_generated &&
4893 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004894 /*
4895 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004896 * us, but could allow us to get back in. This is also
4897 * triggered for cases where local reconnection request
4898 * is used to force reassociation with the same BSS.
4899 * Try to reconnect to the same BSS without a full scan
4900 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004901 */
4902 fast_reconnect = wpa_s->current_bss;
4903 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004904 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004905 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004906 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004907 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4908 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004909 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004910 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004911 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004912 "try to re-connect");
4913 wpa_s->reassociate = 0;
4914 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004915 if (!wpa_s->pno)
4916 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004917 }
4918 bssid = wpa_s->bssid;
4919 if (is_zero_ether_addr(bssid))
4920 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004921 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004922 wpas_connection_failed(wpa_s, bssid, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004923 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004924 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4925
Dmitry Shmidt04949592012-07-19 12:16:46 -07004926 if (locally_generated)
4927 wpa_s->disconnect_reason = -reason_code;
4928 else
4929 wpa_s->disconnect_reason = reason_code;
4930 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004931 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4932 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004933 wpa_clear_keys(wpa_s, wpa_s->bssid);
4934 }
4935 wpa_supplicant_mark_disassoc(wpa_s);
4936
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004937 if (curr)
4938 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4939
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004940 if (fast_reconnect &&
4941 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4942 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4943 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4944 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004945 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004946 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004947#ifndef CONFIG_NO_SCAN_PROCESSING
4948 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4949 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4950 fast_reconnect_ssid) < 0) {
4951 /* Recover through full scan */
4952 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4953 }
4954#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004955 } else if (fast_reconnect) {
4956 /*
4957 * Could not reconnect to the same BSS due to network being
4958 * disabled. Use a new scan to match the alternative behavior
4959 * above, i.e., to continue automatic reconnection attempt in a
4960 * way that enforces disabled network rules.
4961 */
4962 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004963 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004964}
4965
4966
4967#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004968void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004969{
4970 struct wpa_supplicant *wpa_s = eloop_ctx;
4971
4972 if (!wpa_s->pending_mic_error_report)
4973 return;
4974
4975 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4976 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4977 wpa_s->pending_mic_error_report = 0;
4978}
4979#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4980
4981
4982static void
4983wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4984 union wpa_event_data *data)
4985{
4986 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004987 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004988
4989 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4990 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004991 os_get_reltime(&t);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004992 if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004993 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004994 wpa_s->pending_mic_error_report) {
4995 if (wpa_s->pending_mic_error_report) {
4996 /*
4997 * Send the pending MIC error report immediately since
4998 * we are going to start countermeasures and AP better
4999 * do the same.
5000 */
5001 wpa_sm_key_request(wpa_s->wpa, 1,
5002 wpa_s->pending_mic_error_pairwise);
5003 }
5004
5005 /* Send the new MIC error report immediately since we are going
5006 * to start countermeasures and AP better do the same.
5007 */
5008 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
5009
5010 /* initialize countermeasures */
5011 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005012
Hai Shalom60840252021-02-19 19:02:11 -08005013 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005014
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005015 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
5016
5017 /*
5018 * Need to wait for completion of request frame. We do not get
5019 * any callback for the message completion, so just wait a
5020 * short while and hope for the best. */
5021 os_sleep(0, 10000);
5022
5023 wpa_drv_set_countermeasures(wpa_s, 1);
5024 wpa_supplicant_deauthenticate(wpa_s,
5025 WLAN_REASON_MICHAEL_MIC_FAILURE);
5026 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
5027 wpa_s, NULL);
5028 eloop_register_timeout(60, 0,
5029 wpa_supplicant_stop_countermeasures,
5030 wpa_s, NULL);
5031 /* TODO: mark the AP rejected for 60 second. STA is
5032 * allowed to associate with another AP.. */
5033 } else {
5034#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
5035 if (wpa_s->mic_errors_seen) {
5036 /*
5037 * Reduce the effectiveness of Michael MIC error
5038 * reports as a means for attacking against TKIP if
5039 * more than one MIC failure is noticed with the same
5040 * PTK. We delay the transmission of the reports by a
5041 * random time between 0 and 60 seconds in order to
5042 * force the attacker wait 60 seconds before getting
5043 * the information on whether a frame resulted in a MIC
5044 * failure.
5045 */
5046 u8 rval[4];
5047 int sec;
5048
5049 if (os_get_random(rval, sizeof(rval)) < 0)
5050 sec = os_random() % 60;
5051 else
5052 sec = WPA_GET_BE32(rval) % 60;
5053 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
5054 "report %d seconds", sec);
5055 wpa_s->pending_mic_error_report = 1;
5056 wpa_s->pending_mic_error_pairwise = pairwise;
5057 eloop_cancel_timeout(
5058 wpa_supplicant_delayed_mic_error_report,
5059 wpa_s, NULL);
5060 eloop_register_timeout(
5061 sec, os_random() % 1000000,
5062 wpa_supplicant_delayed_mic_error_report,
5063 wpa_s, NULL);
5064 } else {
5065 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
5066 }
5067#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
5068 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
5069#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
5070 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005071 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005072 wpa_s->mic_errors_seen++;
5073}
5074
5075
5076#ifdef CONFIG_TERMINATE_ONLASTIF
5077static int any_interfaces(struct wpa_supplicant *head)
5078{
5079 struct wpa_supplicant *wpa_s;
5080
5081 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
5082 if (!wpa_s->interface_removed)
5083 return 1;
5084 return 0;
5085}
5086#endif /* CONFIG_TERMINATE_ONLASTIF */
5087
5088
5089static void
5090wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
5091 union wpa_event_data *data)
5092{
5093 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
5094 return;
5095
5096 switch (data->interface_status.ievent) {
5097 case EVENT_INTERFACE_ADDED:
5098 if (!wpa_s->interface_removed)
5099 break;
5100 wpa_s->interface_removed = 0;
5101 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
5102 if (wpa_supplicant_driver_init(wpa_s) < 0) {
5103 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
5104 "driver after interface was added");
5105 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005106
5107#ifdef CONFIG_P2P
5108 if (!wpa_s->global->p2p &&
5109 !wpa_s->global->p2p_disabled &&
5110 !wpa_s->conf->p2p_disabled &&
5111 (wpa_s->drv_flags &
5112 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
5113 wpas_p2p_add_p2pdev_interface(
5114 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
5115 wpa_printf(MSG_INFO,
5116 "P2P: Failed to enable P2P Device interface");
5117 /* Try to continue without. P2P will be disabled. */
5118 }
5119#endif /* CONFIG_P2P */
5120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005121 break;
5122 case EVENT_INTERFACE_REMOVED:
5123 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
5124 wpa_s->interface_removed = 1;
5125 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005126 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005127 l2_packet_deinit(wpa_s->l2);
5128 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005129
5130#ifdef CONFIG_P2P
5131 if (wpa_s->global->p2p &&
5132 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
5133 (wpa_s->drv_flags &
5134 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
5135 wpa_dbg(wpa_s, MSG_DEBUG,
5136 "Removing P2P Device interface");
5137 wpa_supplicant_remove_iface(
5138 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
5139 0);
5140 wpa_s->global->p2p_init_wpa_s = NULL;
5141 }
5142#endif /* CONFIG_P2P */
5143
Dmitry Shmidte4663042016-04-04 10:07:49 -07005144#ifdef CONFIG_MATCH_IFACE
5145 if (wpa_s->matched) {
5146 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
5147 break;
5148 }
5149#endif /* CONFIG_MATCH_IFACE */
5150
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005151#ifdef CONFIG_TERMINATE_ONLASTIF
5152 /* check if last interface */
5153 if (!any_interfaces(wpa_s->global->ifaces))
5154 eloop_terminate();
5155#endif /* CONFIG_TERMINATE_ONLASTIF */
5156 break;
5157 }
5158}
5159
5160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005161#ifdef CONFIG_TDLS
5162static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
5163 union wpa_event_data *data)
5164{
5165 if (data == NULL)
5166 return;
5167 switch (data->tdls.oper) {
5168 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005169 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
5170 if (wpa_tdls_is_external_setup(wpa_s->wpa))
5171 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
5172 else
5173 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005174 break;
5175 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03005176 if (wpa_tdls_is_external_setup(wpa_s->wpa))
5177 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
5178 data->tdls.reason_code);
5179 else
5180 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
5181 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005182 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07005183 case TDLS_REQUEST_DISCOVER:
5184 wpa_tdls_send_discovery_request(wpa_s->wpa,
5185 data->tdls.peer);
5186 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005187 }
5188}
5189#endif /* CONFIG_TDLS */
5190
5191
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005192#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005193static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
5194 union wpa_event_data *data)
5195{
5196 if (data == NULL)
5197 return;
5198 switch (data->wnm.oper) {
5199 case WNM_OPER_SLEEP:
5200 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
5201 "(action=%d, intval=%d)",
5202 data->wnm.sleep_action, data->wnm.sleep_intval);
5203 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005204 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005205 break;
5206 }
5207}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005208#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005209
5210
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005211#ifdef CONFIG_IEEE80211R
5212static void
5213wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
5214 union wpa_event_data *data)
5215{
5216 if (data == NULL)
5217 return;
5218
5219 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
5220 data->ft_ies.ies_len,
5221 data->ft_ies.ft_action,
5222 data->ft_ies.target_ap,
5223 data->ft_ies.ric_ies,
5224 data->ft_ies.ric_ies_len) < 0) {
5225 /* TODO: prevent MLME/driver from trying to associate? */
5226 }
5227}
5228#endif /* CONFIG_IEEE80211R */
5229
5230
5231#ifdef CONFIG_IBSS_RSN
5232static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
5233 union wpa_event_data *data)
5234{
5235 struct wpa_ssid *ssid;
5236 if (wpa_s->wpa_state < WPA_ASSOCIATED)
5237 return;
5238 if (data == NULL)
5239 return;
5240 ssid = wpa_s->current_ssid;
5241 if (ssid == NULL)
5242 return;
5243 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5244 return;
5245
5246 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
5247}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005248
5249
5250static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
5251 union wpa_event_data *data)
5252{
5253 struct wpa_ssid *ssid = wpa_s->current_ssid;
5254
5255 if (ssid == NULL)
5256 return;
5257
5258 /* check if the ssid is correctly configured as IBSS/RSN */
5259 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5260 return;
5261
5262 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
5263 data->rx_mgmt.frame_len);
5264}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005265#endif /* CONFIG_IBSS_RSN */
5266
5267
5268#ifdef CONFIG_IEEE80211R
5269static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
5270 size_t len)
5271{
5272 const u8 *sta_addr, *target_ap_addr;
5273 u16 status;
5274
5275 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
5276 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
5277 return; /* only SME case supported for now */
5278 if (len < 1 + 2 * ETH_ALEN + 2)
5279 return;
5280 if (data[0] != 2)
5281 return; /* Only FT Action Response is supported for now */
5282 sta_addr = data + 1;
5283 target_ap_addr = data + 1 + ETH_ALEN;
5284 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
5285 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
5286 MACSTR " TargetAP " MACSTR " status %u",
5287 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
5288
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005289 if (!ether_addr_equal(sta_addr, wpa_s->own_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005290 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
5291 " in FT Action Response", MAC2STR(sta_addr));
5292 return;
5293 }
5294
5295 if (status) {
5296 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
5297 "failure (status code %d)", status);
5298 /* TODO: report error to FT code(?) */
5299 return;
5300 }
5301
5302 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
5303 len - (1 + 2 * ETH_ALEN + 2), 1,
5304 target_ap_addr, NULL, 0) < 0)
5305 return;
5306
5307#ifdef CONFIG_SME
5308 {
5309 struct wpa_bss *bss;
5310 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
5311 if (bss)
5312 wpa_s->sme.freq = bss->freq;
5313 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
5314 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
5315 WLAN_AUTH_FT);
5316 }
5317#endif /* CONFIG_SME */
5318}
5319#endif /* CONFIG_IEEE80211R */
5320
5321
5322static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
5323 struct unprot_deauth *e)
5324{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005325 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
5326 "dropped: " MACSTR " -> " MACSTR
5327 " (reason code %u)",
5328 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5329 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005330}
5331
5332
5333static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
5334 struct unprot_disassoc *e)
5335{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005336 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
5337 "dropped: " MACSTR " -> " MACSTR
5338 " (reason code %u)",
5339 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5340 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005341}
5342
5343
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005344static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
5345 u16 reason_code, int locally_generated,
5346 const u8 *ie, size_t ie_len, int deauth)
5347{
5348#ifdef CONFIG_AP
5349 if (wpa_s->ap_iface && addr) {
5350 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
5351 return;
5352 }
5353
5354 if (wpa_s->ap_iface) {
5355 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
5356 return;
5357 }
5358#endif /* CONFIG_AP */
5359
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005360 if (!locally_generated)
5361 wpa_s->own_disconnect_req = 0;
5362
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005363 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
5364
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005365 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
5366 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
5367 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
5368 eapol_sm_failed(wpa_s->eapol))) &&
5369 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00005370 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005371
5372#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07005373 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005374 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
5375 locally_generated) > 0) {
5376 /*
5377 * The interface was removed, so cannot continue
5378 * processing any additional operations after this.
5379 */
5380 return;
5381 }
5382 }
5383#endif /* CONFIG_P2P */
5384
5385 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
5386 locally_generated);
5387}
5388
5389
5390static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
5391 struct disassoc_info *info)
5392{
5393 u16 reason_code = 0;
5394 int locally_generated = 0;
5395 const u8 *addr = NULL;
5396 const u8 *ie = NULL;
5397 size_t ie_len = 0;
5398
5399 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
5400
5401 if (info) {
5402 addr = info->addr;
5403 ie = info->ie;
5404 ie_len = info->ie_len;
5405 reason_code = info->reason_code;
5406 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005407 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
5408 reason2str(reason_code),
5409 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005410 if (addr)
5411 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5412 MAC2STR(addr));
5413 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
5414 ie, ie_len);
5415 }
5416
5417#ifdef CONFIG_AP
5418 if (wpa_s->ap_iface && info && info->addr) {
5419 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
5420 return;
5421 }
5422
5423 if (wpa_s->ap_iface) {
5424 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
5425 return;
5426 }
5427#endif /* CONFIG_AP */
5428
5429#ifdef CONFIG_P2P
5430 if (info) {
5431 wpas_p2p_disassoc_notif(
5432 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
5433 locally_generated);
5434 }
5435#endif /* CONFIG_P2P */
5436
5437 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5438 sme_event_disassoc(wpa_s, info);
5439
5440 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
5441 ie, ie_len, 0);
5442}
5443
5444
5445static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
5446 struct deauth_info *info)
5447{
5448 u16 reason_code = 0;
5449 int locally_generated = 0;
5450 const u8 *addr = NULL;
5451 const u8 *ie = NULL;
5452 size_t ie_len = 0;
5453
5454 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
5455
5456 if (info) {
5457 addr = info->addr;
5458 ie = info->ie;
5459 ie_len = info->ie_len;
5460 reason_code = info->reason_code;
5461 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005462 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
5463 reason_code, reason2str(reason_code),
5464 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005465 if (addr) {
5466 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5467 MAC2STR(addr));
5468 }
5469 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
5470 ie, ie_len);
5471 }
5472
5473 wpa_reset_ft_completed(wpa_s->wpa);
5474
5475 wpas_event_disconnect(wpa_s, addr, reason_code,
5476 locally_generated, ie, ie_len, 1);
5477}
5478
5479
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005480static const char * reg_init_str(enum reg_change_initiator init)
5481{
5482 switch (init) {
5483 case REGDOM_SET_BY_CORE:
5484 return "CORE";
5485 case REGDOM_SET_BY_USER:
5486 return "USER";
5487 case REGDOM_SET_BY_DRIVER:
5488 return "DRIVER";
5489 case REGDOM_SET_BY_COUNTRY_IE:
5490 return "COUNTRY_IE";
5491 case REGDOM_BEACON_HINT:
5492 return "BEACON_HINT";
5493 }
5494 return "?";
5495}
5496
5497
5498static const char * reg_type_str(enum reg_type type)
5499{
5500 switch (type) {
5501 case REGDOM_TYPE_UNKNOWN:
5502 return "UNKNOWN";
5503 case REGDOM_TYPE_COUNTRY:
5504 return "COUNTRY";
5505 case REGDOM_TYPE_WORLD:
5506 return "WORLD";
5507 case REGDOM_TYPE_CUSTOM_WORLD:
5508 return "CUSTOM_WORLD";
5509 case REGDOM_TYPE_INTERSECTION:
5510 return "INTERSECTION";
5511 }
5512 return "?";
5513}
5514
5515
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005516static void wpas_beacon_hint(struct wpa_supplicant *wpa_s, const char *title,
5517 struct frequency_attrs *attrs)
5518{
5519 if (!attrs->freq)
5520 return;
5521 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_BEACON_HINT
5522 "%s freq=%u max_tx_power=%u%s%s%s",
5523 title, attrs->freq, attrs->max_tx_power,
5524 attrs->disabled ? " disabled=1" : "",
5525 attrs->no_ir ? " no_ir=1" : "",
5526 attrs->radar ? " radar=1" : "");
5527}
5528
5529
Hai Shalom74f70d42019-02-11 14:42:39 -08005530void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
5531 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005532{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005533 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005534 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005535
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005536 /*
5537 * To allow backwards compatibility with higher level layers that
5538 * assumed the REGDOM_CHANGE event is sent over the initially added
5539 * interface. Find the highest parent of this interface and use it to
5540 * send the event.
5541 */
5542 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
5543 ;
5544
Hai Shalom74f70d42019-02-11 14:42:39 -08005545 if (info) {
5546 wpa_msg(ifs, MSG_INFO,
5547 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
5548 reg_init_str(info->initiator), reg_type_str(info->type),
5549 info->alpha2[0] ? " alpha2=" : "",
5550 info->alpha2[0] ? info->alpha2 : "");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005551
5552 if (info->initiator == REGDOM_BEACON_HINT) {
5553 wpas_beacon_hint(ifs, "before",
5554 &info->beacon_hint_before);
5555 wpas_beacon_hint(ifs, "after",
5556 &info->beacon_hint_after);
5557 }
Hai Shalom74f70d42019-02-11 14:42:39 -08005558 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005559
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005560 if (wpa_s->drv_priv == NULL)
5561 return; /* Ignore event during drv initialization */
5562
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005563 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
5564 radio_list) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005565 bool was_6ghz_enabled;
5566
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005567 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
5568 ifs->ifname);
5569 free_hw_features(ifs);
5570 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005571 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005572
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005573 was_6ghz_enabled = ifs->is_6ghz_enabled;
5574 ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5575
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005576 /* Restart PNO/sched_scan with updated channel list */
5577 if (ifs->pno) {
5578 wpas_stop_pno(ifs);
5579 wpas_start_pno(ifs);
5580 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
5581 wpa_dbg(ifs, MSG_DEBUG,
5582 "Channel list changed - restart sched_scan");
5583 wpas_scan_restart_sched_scan(ifs);
Sunil Ravi7f769292024-07-23 22:21:32 +00005584 } else if (!was_6ghz_enabled && ifs->is_6ghz_enabled) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005585 wpa_dbg(ifs, MSG_INFO,
Sunil Ravi7f769292024-07-23 22:21:32 +00005586 "Channel list changed: 6 GHz was enabled");
5587
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005588 ifs->crossed_6ghz_dom = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005589 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005590 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005591
5592 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005593}
5594
5595
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005596static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005597 const u8 *frame, size_t len, int freq,
5598 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005599{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005600 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005601 const u8 *payload;
5602 size_t plen;
5603 u8 category;
5604
5605 if (len < IEEE80211_HDRLEN + 2)
5606 return;
5607
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005608 mgmt = (const struct ieee80211_mgmt *) frame;
5609 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005610 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005611 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005612
5613 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
5614 " Category=%u DataLen=%d freq=%d MHz",
5615 MAC2STR(mgmt->sa), category, (int) plen, freq);
5616
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005617#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005618 if (category == WLAN_ACTION_WMM) {
5619 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5620 return;
5621 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005622#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005623
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005624#ifdef CONFIG_IEEE80211R
5625 if (category == WLAN_ACTION_FT) {
5626 ft_rx_action(wpa_s, payload, plen);
5627 return;
5628 }
5629#endif /* CONFIG_IEEE80211R */
5630
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005631#ifdef CONFIG_SME
5632 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005633 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005634 return;
5635 }
5636#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005637
5638#ifdef CONFIG_WNM
5639 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
5640 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
5641 return;
5642 }
5643#endif /* CONFIG_WNM */
5644
5645#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08005646 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5647 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005648 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08005649 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005650 payload, plen, freq) == 0)
5651 return;
5652#endif /* CONFIG_GAS */
5653
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005654#ifdef CONFIG_GAS_SERVER
5655 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5656 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
5657 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
5658 mgmt->u.action.category,
5659 payload, plen, freq) == 0)
5660 return;
5661#endif /* CONFIG_GAS_SERVER */
5662
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005663#ifdef CONFIG_TDLS
5664 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
5665 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
5666 wpa_dbg(wpa_s, MSG_DEBUG,
5667 "TDLS: Received Discovery Response from " MACSTR,
5668 MAC2STR(mgmt->sa));
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005669 if (wpa_s->valid_links &&
5670 wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa,
5671 &payload[1], plen - 1))
5672 wpa_dbg(wpa_s, MSG_ERROR,
5673 "TDLS: Discovery Response process failed for "
5674 MACSTR, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005675 return;
5676 }
5677#endif /* CONFIG_TDLS */
5678
5679#ifdef CONFIG_INTERWORKING
5680 if (category == WLAN_ACTION_QOS && plen >= 1 &&
5681 payload[0] == QOS_QOS_MAP_CONFIG) {
5682 const u8 *pos = payload + 1;
5683 size_t qlen = plen - 1;
5684 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
5685 MACSTR, MAC2STR(mgmt->sa));
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005686 if (ether_addr_equal(mgmt->sa, wpa_s->bssid) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005687 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
5688 pos[1] <= qlen - 2 && pos[1] >= 16)
5689 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
5690 return;
5691 }
5692#endif /* CONFIG_INTERWORKING */
5693
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005694#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005695 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005696 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5697 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005698 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005699 payload + 1,
5700 plen - 1);
5701 return;
5702 }
5703
5704 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005705 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
5706 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
5707 return;
5708 }
5709
5710 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5711 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
5712 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
5713 payload + 1, plen - 1,
5714 rssi);
5715 return;
5716 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005717#endif /* CONFIG_NO_RRM */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005718
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005719#ifdef CONFIG_FST
5720 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
5721 fst_rx_action(wpa_s->fst, mgmt, len);
5722 return;
5723 }
5724#endif /* CONFIG_FST */
5725
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005726#ifdef CONFIG_NAN_USD
5727 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5728 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5729 WPA_GET_BE32(&payload[1]) == NAN_SDF_VENDOR_TYPE) {
5730 payload += 5;
5731 plen -= 5;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00005732 wpas_nan_usd_rx_sdf(wpa_s, mgmt->sa, mgmt->bssid, freq,
5733 payload, plen);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005734 return;
5735 }
5736#endif /* CONFIG_NAN_USD */
5737
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005738#ifdef CONFIG_DPP
5739 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5740 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5741 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
5742 payload[4] == DPP_OUI_TYPE) {
5743 payload++;
5744 plen--;
5745 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
5746 return;
5747 }
5748#endif /* CONFIG_DPP */
5749
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005750#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07005751 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08005752 payload[0] == ROBUST_AV_SCS_RESP) {
5753 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
5754 payload + 1, plen - 1);
5755 return;
5756 }
5757
5758 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005759 payload[0] == ROBUST_AV_MSCS_RESP) {
5760 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5761 payload + 1, plen - 1);
5762 return;
5763 }
5764
Hai Shalomc1a21442022-02-04 13:43:00 -08005765 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
5766 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
5767 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
5768 payload + 4, plen - 4);
5769 return;
5770 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005771#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08005772
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005773 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5774 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005775 if (wpa_s->ifmsh)
5776 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005777}
5778
5779
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005780static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5781 union wpa_event_data *event)
5782{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005783 struct wpa_freq_range_list *list;
5784 char *str = NULL;
5785
5786 list = &event->freq_range;
5787
5788 if (list->num)
5789 str = freq_range_list_str(list);
5790 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5791 str ? str : "");
5792
5793#ifdef CONFIG_P2P
5794 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5795 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5796 __func__);
5797 } else {
5798 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005799
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005800 /*
5801 * The update channel flow will also take care of moving a GO
5802 * from the unsafe frequency if needed.
5803 */
5804 wpas_p2p_update_channel_list(wpa_s,
5805 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005806 }
5807#endif /* CONFIG_P2P */
5808
5809 os_free(str);
5810}
5811
5812
Roshan Pius3a1667e2018-07-03 15:17:14 -07005813static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005814{
Sunil Ravi167279a2023-05-31 01:12:34 +00005815 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005816 wpa_supplicant_cancel_auth_timeout(wpa_s);
5817 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005818 eapol_sm_notify_portValid(wpa_s->eapol, true);
5819 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005820 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005821 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005822}
5823
5824
5825static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5826 int freq)
5827{
5828 size_t i;
5829 int j;
5830
5831 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5832 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5833
5834 for (j = 0; j < mode->num_channels; j++) {
5835 const struct hostapd_channel_data *chan;
5836
5837 chan = &mode->channels[j];
5838 if (chan->freq == freq)
5839 return chan->dfs_cac_ms;
5840 }
5841 }
5842
5843 return 0;
5844}
5845
5846
5847static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5848 struct dfs_event *radar)
5849{
5850#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005851 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005852 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5853 } else
5854#endif /* NEED_AP_MLME && CONFIG_AP */
5855 {
5856 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5857
5858 cac_time /= 1000; /* convert from ms to sec */
5859 if (!cac_time)
5860 cac_time = 10 * 60; /* max timeout: 10 minutes */
5861
5862 /* Restart auth timeout: CAC time added to initial timeout */
5863 wpas_auth_timeout_restart(wpa_s, cac_time);
5864 }
5865}
5866
5867
5868static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5869 struct dfs_event *radar)
5870{
5871#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005872 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005873 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5874 } else
5875#endif /* NEED_AP_MLME && CONFIG_AP */
5876 {
5877 /* Restart auth timeout with original value after CAC is
5878 * finished */
5879 wpas_auth_timeout_restart(wpa_s, 0);
5880 }
5881}
5882
5883
5884static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5885 struct dfs_event *radar)
5886{
5887#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005888 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005889 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5890 } else
5891#endif /* NEED_AP_MLME && CONFIG_AP */
5892 {
5893 /* Restart auth timeout with original value after CAC is
5894 * aborted */
5895 wpas_auth_timeout_restart(wpa_s, 0);
5896 }
5897}
5898
5899
5900static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5901 union wpa_event_data *data)
5902{
5903 wpa_dbg(wpa_s, MSG_DEBUG,
5904 "Connection authorized by device, previous state %d",
5905 wpa_s->wpa_state);
5906
5907 wpa_supplicant_event_port_authorized(wpa_s);
5908
Hai Shalomc1a21442022-02-04 13:43:00 -08005909 wpa_s->last_eapol_matches_bssid = 1;
5910
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005911 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5912 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005913 data->assoc_info.ptk_kck_len,
5914 data->assoc_info.ptk_kek,
5915 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005916#ifdef CONFIG_FILS
5917 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5918 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5919 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5920
5921 /* Update ERP next sequence number */
5922 eapol_sm_update_erp_next_seq_num(
5923 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5924
5925 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5926 /* Add the new PMK and PMKID to the PMKSA cache */
5927 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5928 data->assoc_info.fils_pmk,
5929 data->assoc_info.fils_pmk_len,
5930 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005931 wpa_s->valid_links ?
5932 wpa_s->ap_mld_addr :
5933 wpa_s->bssid,
5934 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005935 } else if (data->assoc_info.fils_pmkid) {
5936 /* Update the current PMKSA used for this connection */
5937 pmksa_cache_set_current(wpa_s->wpa,
5938 data->assoc_info.fils_pmkid,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005939 NULL, NULL, 0, NULL, 0, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005940 }
5941 }
5942#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005943}
5944
5945
Hai Shalom60840252021-02-19 19:02:11 -08005946static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5947{
5948 switch (code) {
5949 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5950 return "";
5951 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5952 return "no_bss_found";
5953 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5954 return "auth_tx_fail";
5955 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5956 return "auth_no_ack_received";
5957 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5958 return "auth_no_resp_received";
5959 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5960 return "assoc_req_tx_fail";
5961 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5962 return "assoc_no_ack_received";
5963 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5964 return "assoc_no_resp_received";
5965 default:
5966 return "unknown_reason";
5967 }
5968}
5969
5970
Roshan Pius3a1667e2018-07-03 15:17:14 -07005971static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5972 union wpa_event_data *data)
5973{
5974 const u8 *bssid = data->assoc_reject.bssid;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005975 struct ieee802_11_elems elems;
Sunil Ravi7f769292024-07-23 22:21:32 +00005976 struct ml_sta_link_info ml_info[MAX_NUM_MLD_LINKS];
5977 const u8 *link_bssids[MAX_NUM_MLD_LINKS + 1];
Hai Shalom81f62d82019-07-22 12:10:00 -07005978#ifdef CONFIG_MBO
5979 struct wpa_bss *reject_bss;
5980#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005981
5982 if (!bssid || is_zero_ether_addr(bssid))
5983 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005984#ifdef CONFIG_MBO
5985 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5986 reject_bss = wpa_s->current_bss;
5987 else
5988 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5989#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005990
5991 if (data->assoc_reject.bssid)
5992 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005993 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005994 MAC2STR(data->assoc_reject.bssid),
5995 data->assoc_reject.status_code,
5996 data->assoc_reject.timed_out ? " timeout" : "",
5997 data->assoc_reject.timeout_reason ? "=" : "",
5998 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005999 data->assoc_reject.timeout_reason : "",
6000 data->assoc_reject.reason_code !=
6001 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
6002 " qca_driver_reason=" : "",
6003 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07006004 else
6005 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08006006 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07006007 data->assoc_reject.status_code,
6008 data->assoc_reject.timed_out ? " timeout" : "",
6009 data->assoc_reject.timeout_reason ? "=" : "",
6010 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08006011 data->assoc_reject.timeout_reason : "",
6012 data->assoc_reject.reason_code !=
6013 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
6014 " qca_driver_reason=" : "",
6015 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07006016 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08006017 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
6018 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006019
6020#ifdef CONFIG_OWE
6021 if (data->assoc_reject.status_code ==
6022 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
6023 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
6024 wpa_s->current_ssid &&
6025 wpa_s->current_ssid->owe_group == 0 &&
6026 wpa_s->last_owe_group != 21) {
6027 struct wpa_ssid *ssid = wpa_s->current_ssid;
6028 struct wpa_bss *bss = wpa_s->current_bss;
6029
6030 if (!bss) {
6031 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
6032 if (!bss) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006033 wpas_connection_failed(wpa_s, bssid, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006034 wpa_supplicant_mark_disassoc(wpa_s);
6035 return;
6036 }
6037 }
6038 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
6039 wpas_connect_work_done(wpa_s);
6040 wpa_supplicant_mark_disassoc(wpa_s);
6041 wpa_supplicant_connect(wpa_s, bss, ssid);
6042 return;
6043 }
6044#endif /* CONFIG_OWE */
6045
Hai Shalomfdcde762020-04-02 11:19:20 -07006046#ifdef CONFIG_DPP2
6047 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
6048 * the status code defined in the DPP R2 tech spec.
6049 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
6050 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006051 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07006052 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
6053 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
6054 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07006055 wpa_s->current_ssid->dpp_pfs == 0 &&
6056 (data->assoc_reject.status_code ==
6057 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
6058 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
6059 struct wpa_ssid *ssid = wpa_s->current_ssid;
6060 struct wpa_bss *bss = wpa_s->current_bss;
6061
6062 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
6063 if (!bss)
6064 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
6065 if (!bss || wpa_s->dpp_pfs_fallback) {
6066 wpa_printf(MSG_DEBUG,
6067 "DPP: Updated PFS policy for next try");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006068 wpas_connection_failed(wpa_s, bssid, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07006069 wpa_supplicant_mark_disassoc(wpa_s);
6070 return;
6071 }
6072 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
6073 wpa_s->dpp_pfs_fallback = 1;
6074 wpas_connect_work_done(wpa_s);
6075 wpa_supplicant_mark_disassoc(wpa_s);
6076 wpa_supplicant_connect(wpa_s, bss, ssid);
6077 return;
6078 }
6079#endif /* CONFIG_DPP2 */
6080
Hai Shalom74f70d42019-02-11 14:42:39 -08006081#ifdef CONFIG_MBO
6082 if (data->assoc_reject.status_code ==
6083 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07006084 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08006085 const u8 *rssi_rej;
6086
6087 rssi_rej = mbo_get_attr_from_ies(
6088 data->assoc_reject.resp_ies,
6089 data->assoc_reject.resp_ies_len,
6090 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
6091 if (rssi_rej && rssi_rej[1] == 2) {
6092 wpa_printf(MSG_DEBUG,
6093 "OCE: RSSI-based association rejection from "
6094 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07006095 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08006096 rssi_rej[2], rssi_rej[3]);
6097 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07006098 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08006099 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07006100 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08006101 }
6102 }
6103#endif /* CONFIG_MBO */
6104
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006105 /* Check for other failed links in the response */
6106 os_memset(link_bssids, 0, sizeof(link_bssids));
6107 if (ieee802_11_parse_elems(data->assoc_reject.resp_ies,
6108 data->assoc_reject.resp_ies_len,
6109 &elems, 1) != ParseFailed) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006110 unsigned int n_links, i, idx;
6111
6112 idx = 0;
6113 n_links = wpas_ml_parse_assoc(wpa_s, &elems, ml_info);
6114
6115 for (i = 1; i < n_links; i++) {
6116 /* The status cannot be success here.
6117 * Add the link to the failed list if it is reporting
6118 * an error. The only valid "non-error" status is
6119 * TX_LINK_NOT_ACCEPTED as that means this link may
6120 * still accept an association from us.
6121 */
6122 if (ml_info[i].status !=
6123 WLAN_STATUS_DENIED_TX_LINK_NOT_ACCEPTED) {
6124 link_bssids[idx] = ml_info[i].bssid;
6125 idx++;
6126 }
6127 }
6128 }
6129
Roshan Pius3a1667e2018-07-03 15:17:14 -07006130 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006131 sme_event_assoc_reject(wpa_s, data, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006132 return;
6133 }
6134
6135 /* Driver-based SME cases */
6136
6137#ifdef CONFIG_SAE
6138 if (wpa_s->current_ssid &&
6139 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
6140 !data->assoc_reject.timed_out) {
6141 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
6142 wpa_sm_aborted_cached(wpa_s->wpa);
6143 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
6144 }
6145#endif /* CONFIG_SAE */
6146
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006147#ifdef CONFIG_DPP
6148 if (wpa_s->current_ssid &&
6149 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
6150 !data->assoc_reject.timed_out) {
6151 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
6152 wpa_sm_aborted_cached(wpa_s->wpa);
6153 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
6154 }
6155#endif /* CONFIG_DPP */
6156
Roshan Pius3a1667e2018-07-03 15:17:14 -07006157#ifdef CONFIG_FILS
6158 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07006159 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006160 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006161 eapol_sm_update_erp_next_seq_num(
6162 wpa_s->eapol,
6163 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07006164 fils_connection_failure(wpa_s);
6165 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006166#endif /* CONFIG_FILS */
6167
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006168 wpas_connection_failed(wpa_s, bssid, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006169 wpa_supplicant_mark_disassoc(wpa_s);
6170}
6171
6172
Hai Shalomfdcde762020-04-02 11:19:20 -07006173static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
6174 struct unprot_beacon *data)
6175{
6176 struct wpabuf *buf;
6177 int res;
6178
6179 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006180 !ether_addr_equal(data->sa, wpa_s->bssid))
Hai Shalomfdcde762020-04-02 11:19:20 -07006181 return;
6182 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
6183 MAC2STR(data->sa));
6184
6185 buf = wpabuf_alloc(4);
6186 if (!buf)
6187 return;
6188
6189 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
6190 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
6191 wpabuf_put_u8(buf, 1); /* Dialog Token */
6192 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
6193
6194 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
6195 wpa_s->own_addr, wpa_s->bssid,
6196 wpabuf_head(buf), wpabuf_len(buf), 0);
6197 if (res < 0)
6198 wpa_printf(MSG_DEBUG,
6199 "Failed to send WNM-Notification Request frame");
6200
6201 wpabuf_free(buf);
6202}
6203
6204
Sunil Ravi640215c2023-06-28 23:08:09 +00006205static const char * bitmap_to_str(u8 value, char *buf)
6206{
6207 char *pos = buf;
6208 int i, k = 0;
6209
6210 for (i = 7; i >= 0; i--)
6211 pos[k++] = (value & BIT(i)) ? '1' : '0';
6212
6213 pos[8] = '\0';
6214 return pos;
6215}
6216
6217
6218static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
6219 struct tid_link_map_info *info)
6220{
6221 char map_info[1000], *pos, *end;
6222 int res, i;
6223
6224 pos = map_info;
6225 end = pos + sizeof(map_info);
6226 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
6227 info->default_map);
6228 if (os_snprintf_error(end - pos, res))
6229 return;
6230 pos += res;
6231
6232 if (!info->default_map) {
Sunil Ravi99c035e2024-07-12 01:42:03 +00006233 for_each_link(info->valid_links, i) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006234 char uplink_map_str[9];
6235 char downlink_map_str[9];
6236
Sunil Ravi640215c2023-06-28 23:08:09 +00006237 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
6238 bitmap_to_str(info->t2lmap[i].downlink,
6239 downlink_map_str);
6240
6241 res = os_snprintf(pos, end - pos,
6242 " link_id=%d up_link=%s down_link=%s",
6243 i, uplink_map_str,
6244 downlink_map_str);
6245 if (os_snprintf_error(end - pos, res))
6246 return;
6247 pos += res;
6248 }
6249 }
6250
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306251 wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP);
Sunil Ravi640215c2023-06-28 23:08:09 +00006252 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
6253}
6254
6255
6256static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
6257{
6258 u8 bssid[ETH_ALEN];
6259
6260 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
6261 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
6262 wpa_supplicant_deauthenticate(wpa_s,
6263 WLAN_REASON_DEAUTH_LEAVING);
6264 return;
6265 }
6266
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006267 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006268 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
6269 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
6270 wpas_notify_bssid_changed(wpa_s);
6271 }
6272
6273 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
6274 wpa_printf(MSG_ERROR,
6275 "LINK_RECONFIG: Failed to get MLO connection info");
6276 wpa_supplicant_deauthenticate(wpa_s,
6277 WLAN_REASON_DEAUTH_LEAVING);
6278 return;
6279 }
6280
6281 if (wpa_sm_set_ml_info(wpa_s)) {
6282 wpa_printf(MSG_ERROR,
6283 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
6284 wpa_supplicant_deauthenticate(wpa_s,
6285 WLAN_REASON_DEAUTH_LEAVING);
6286 return;
6287 }
6288
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306289 wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL);
Sunil Ravi640215c2023-06-28 23:08:09 +00006290 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
6291 wpa_s->valid_links);
6292}
6293
Matthew Wangb820c2b2024-10-03 13:02:07 +00006294#ifdef MAINLINE_SUPPLICANT
6295static bool is_event_allowlisted(enum wpa_event_type event) {
Matthew Wangc8ea6132024-10-23 11:19:52 +00006296 return event == EVENT_SCAN_STARTED ||
6297 event == EVENT_SCAN_RESULTS ||
6298 event == EVENT_RX_MGMT ||
Matthew Wangb820c2b2024-10-03 13:02:07 +00006299 event == EVENT_REMAIN_ON_CHANNEL ||
6300 event == EVENT_CANCEL_REMAIN_ON_CHANNEL ||
6301 event == EVENT_TX_WAIT_EXPIRE;
6302}
6303#endif /* MAINLINE_SUPPLICANT */
6304
Sunil Ravi640215c2023-06-28 23:08:09 +00006305
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00006306#ifdef CONFIG_PASN
6307static int wpas_pasn_auth(struct wpa_supplicant *wpa_s,
6308 const struct ieee80211_mgmt *mgmt, size_t len,
6309 int freq)
6310{
6311#ifdef CONFIG_P2P
6312 struct ieee802_11_elems elems;
6313
6314 if (len < 24) {
6315 wpa_printf(MSG_DEBUG, "nl80211: Too short Management frame");
6316 return -2;
6317 }
6318
6319 if (ieee802_11_parse_elems(mgmt->u.auth.variable,
6320 len - offsetof(struct ieee80211_mgmt,
6321 u.auth.variable),
6322 &elems, 1) == ParseFailed) {
6323 wpa_printf(MSG_DEBUG,
6324 "PASN: Failed parsing Authentication frame");
6325 return -2;
6326 }
6327
6328 if (elems.p2p2_ie && elems.p2p2_ie_len)
6329 return wpas_p2p_pasn_auth_rx(wpa_s, mgmt, len, freq);
6330#endif /* CONFIG_P2P */
6331
6332 return wpas_pasn_auth_rx(wpa_s, mgmt, len);
6333}
6334#endif /* CONFIG_PASN */
6335
6336
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006337void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
6338 union wpa_event_data *data)
6339{
6340 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006341 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07006342 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08006343#ifndef CONFIG_NO_STDOUT_DEBUG
6344 int level = MSG_DEBUG;
6345#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006346
Matthew Wangb820c2b2024-10-03 13:02:07 +00006347#ifdef MAINLINE_SUPPLICANT
6348 if (!is_event_allowlisted(event)) {
6349 wpa_dbg(wpa_s, MSG_DEBUG,
6350 "Ignore event %s (%d) which is not allowlisted",
6351 event_to_string(event), event);
6352 return;
6353 }
6354#endif /* MAINLINE_SUPPLICANT */
6355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006356 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
6357 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006358 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006359 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006360 event != EVENT_SCHED_SCAN_STOPPED) {
6361 wpa_dbg(wpa_s, MSG_DEBUG,
6362 "Ignore event %s (%d) while interface is disabled",
6363 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006364 return;
6365 }
6366
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006367#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07006368 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006369 const struct ieee80211_hdr *hdr;
6370 u16 fc;
6371 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
6372 fc = le_to_host16(hdr->frame_control);
6373 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
6374 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
6375 level = MSG_EXCESSIVE;
6376 }
6377
6378 wpa_dbg(wpa_s, level, "Event %s (%d) received",
6379 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006380#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006381
6382 switch (event) {
6383 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006384#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08006385 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
6386 data->auth.ies_len))
6387 wpa_printf(MSG_DEBUG,
6388 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006389#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006390 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006391 wpa_s->auth_status_code = data->auth.status_code;
6392 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006393 break;
6394 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006395#ifdef CONFIG_TESTING_OPTIONS
6396 if (wpa_s->ignore_auth_resp) {
6397 wpa_printf(MSG_INFO,
6398 "EVENT_ASSOC - ignore_auth_resp active!");
6399 break;
6400 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006401 if (wpa_s->testing_resend_assoc) {
6402 wpa_printf(MSG_INFO,
6403 "EVENT_DEAUTH - testing_resend_assoc");
6404 break;
6405 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006406#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05306407 if (wpa_s->disconnected) {
6408 wpa_printf(MSG_INFO,
6409 "Ignore unexpected EVENT_ASSOC in disconnected state");
6410 break;
6411 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006412 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006413 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006414 if (data &&
6415 (data->assoc_info.authorized ||
6416 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6417 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006418 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006419 if (data) {
6420 wpa_msg(wpa_s, MSG_INFO,
6421 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
6422 data->assoc_info.subnet_status);
6423 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006424 break;
6425 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006426 wpas_event_disassoc(wpa_s,
6427 data ? &data->disassoc_info : NULL);
6428 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006429 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006430#ifdef CONFIG_TESTING_OPTIONS
6431 if (wpa_s->ignore_auth_resp) {
6432 wpa_printf(MSG_INFO,
6433 "EVENT_DEAUTH - ignore_auth_resp active!");
6434 break;
6435 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006436 if (wpa_s->testing_resend_assoc) {
6437 wpa_printf(MSG_INFO,
6438 "EVENT_DEAUTH - testing_resend_assoc");
6439 break;
6440 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006441#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006442 wpas_event_deauth(wpa_s,
6443 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006444 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00006445 case EVENT_LINK_RECONFIG:
6446 wpas_link_reconfig(wpa_s);
6447 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006448 case EVENT_MICHAEL_MIC_FAILURE:
6449 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
6450 break;
6451#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006452 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006453 if (wpa_s->own_scan_requested ||
6454 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006455 struct os_reltime diff;
6456
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006457 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006458 os_reltime_sub(&wpa_s->scan_start_time,
6459 &wpa_s->scan_trigger_time, &diff);
6460 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
6461 diff.sec, diff.usec);
6462 wpa_s->own_scan_requested = 0;
6463 wpa_s->own_scan_running = 1;
6464 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
6465 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006466 wpa_msg_ctrl(wpa_s, MSG_INFO,
6467 WPA_EVENT_SCAN_STARTED "id=%u",
6468 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006469 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006470 wpa_msg_ctrl(wpa_s, MSG_INFO,
6471 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006472 }
6473 } else {
6474 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08006475 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006476 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006477 }
6478 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006479 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006480 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6481 wpa_s->scan_res_handler = NULL;
6482 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08006483 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006484 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
6485 break;
6486 }
6487
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006488 if (!(data && data->scan_info.external_scan) &&
6489 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006490 struct os_reltime now, diff;
6491 os_get_reltime(&now);
6492 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
6493 wpa_s->scan_start_time.sec = 0;
6494 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00006495 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006496 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
6497 diff.sec, diff.usec);
6498 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006499 if (wpa_supplicant_event_scan_results(wpa_s, data))
6500 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006501 if (!(data && data->scan_info.external_scan))
6502 wpa_s->own_scan_running = 0;
6503 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08006504 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006505 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006506 break;
6507#endif /* CONFIG_NO_SCAN_PROCESSING */
6508 case EVENT_ASSOCINFO:
6509 wpa_supplicant_event_associnfo(wpa_s, data);
6510 break;
6511 case EVENT_INTERFACE_STATUS:
6512 wpa_supplicant_event_interface_status(wpa_s, data);
6513 break;
6514 case EVENT_PMKID_CANDIDATE:
6515 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
6516 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006517#ifdef CONFIG_TDLS
6518 case EVENT_TDLS:
6519 wpa_supplicant_event_tdls(wpa_s, data);
6520 break;
6521#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006522#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006523 case EVENT_WNM:
6524 wpa_supplicant_event_wnm(wpa_s, data);
6525 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006526#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006527#ifdef CONFIG_IEEE80211R
6528 case EVENT_FT_RESPONSE:
6529 wpa_supplicant_event_ft_response(wpa_s, data);
6530 break;
6531#endif /* CONFIG_IEEE80211R */
6532#ifdef CONFIG_IBSS_RSN
6533 case EVENT_IBSS_RSN_START:
6534 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
6535 break;
6536#endif /* CONFIG_IBSS_RSN */
6537 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07006538 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006539 break;
6540 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006541 /* It is possible to get this event from earlier connection */
6542 if (wpa_s->current_ssid &&
6543 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6544 wpa_dbg(wpa_s, MSG_DEBUG,
6545 "Ignore AUTH_TIMED_OUT in mesh configuration");
6546 break;
6547 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006548 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6549 sme_event_auth_timed_out(wpa_s, data);
6550 break;
6551 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006552 /* It is possible to get this event from earlier connection */
6553 if (wpa_s->current_ssid &&
6554 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6555 wpa_dbg(wpa_s, MSG_DEBUG,
6556 "Ignore ASSOC_TIMED_OUT in mesh configuration");
6557 break;
6558 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006559 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6560 sme_event_assoc_timed_out(wpa_s, data);
6561 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006562 case EVENT_TX_STATUS:
6563 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
6564 " type=%d stype=%d",
6565 MAC2STR(data->tx_status.dst),
6566 data->tx_status.type, data->tx_status.stype);
Sunil Ravi99c035e2024-07-12 01:42:03 +00006567#ifdef CONFIG_WNM
6568 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6569 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
6570 wnm_btm_resp_tx_status(wpa_s, data->tx_status.data,
6571 data->tx_status.data_len) == 0)
6572 break;
6573#endif /* CONFIG_WNM */
Hai Shalom60840252021-02-19 19:02:11 -08006574#ifdef CONFIG_PASN
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00006575#ifdef CONFIG_P2P
6576 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6577 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6578 !wpa_s->pasn_auth_work &&
6579 wpa_s->p2p_pasn_auth_work &&
6580 wpas_p2p_pasn_auth_tx_status(wpa_s,
6581 data->tx_status.data,
6582 data->tx_status.data_len,
6583 data->tx_status.ack) == 0)
6584 break;
6585#endif /* CONFIG_P2P */
Hai Shalom60840252021-02-19 19:02:11 -08006586 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6587 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6588 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
6589 data->tx_status.data_len,
6590 data->tx_status.ack) == 0)
6591 break;
6592#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006593#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006594 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006595#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006596 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6597 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006598 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006599 wpa_s, data->tx_status.dst,
6600 data->tx_status.data,
6601 data->tx_status.data_len,
6602 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006603 OFFCHANNEL_SEND_ACTION_SUCCESS :
6604 OFFCHANNEL_SEND_ACTION_NO_ACK);
6605#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006606 break;
6607 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006608#endif /* CONFIG_AP */
6609#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006610 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006611 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006612 /*
6613 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006614 * interface in GO mode, or via standalone AP interface.
6615 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
6616 * except when the primary interface is used as a GO interface
6617 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006618 */
6619 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6620 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006621 ether_addr_equal(wpa_s->p2pdev->pending_action_dst,
6622 data->tx_status.dst)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006623 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006624 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006625 data->tx_status.data,
6626 data->tx_status.data_len,
6627 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006628 OFFCHANNEL_SEND_ACTION_SUCCESS :
6629 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006630 break;
6631 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006632#endif /* CONFIG_OFFCHANNEL */
6633#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006634 switch (data->tx_status.type) {
6635 case WLAN_FC_TYPE_MGMT:
6636 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
6637 data->tx_status.data_len,
6638 data->tx_status.stype,
6639 data->tx_status.ack);
6640 break;
6641 case WLAN_FC_TYPE_DATA:
6642 ap_tx_status(wpa_s, data->tx_status.dst,
6643 data->tx_status.data,
6644 data->tx_status.data_len,
6645 data->tx_status.ack);
6646 break;
6647 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006648#endif /* CONFIG_AP */
6649 break;
6650#ifdef CONFIG_AP
6651 case EVENT_EAPOL_TX_STATUS:
6652 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
6653 data->eapol_tx_status.data,
6654 data->eapol_tx_status.data_len,
6655 data->eapol_tx_status.ack);
6656 break;
6657 case EVENT_DRIVER_CLIENT_POLL_OK:
6658 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006659 break;
6660 case EVENT_RX_FROM_UNKNOWN:
6661 if (wpa_s->ap_iface == NULL)
6662 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006663 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
6664 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006665 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006666#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07006667
Sunil Ravi89eba102022-09-13 21:04:37 -07006668 case EVENT_LINK_CH_SWITCH_STARTED:
6669 case EVENT_LINK_CH_SWITCH:
6670 if (!data || !wpa_s->current_ssid ||
6671 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6672 break;
6673
6674 wpa_msg(wpa_s, MSG_INFO,
6675 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6676 event == EVENT_LINK_CH_SWITCH ?
6677 WPA_EVENT_LINK_CHANNEL_SWITCH :
6678 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6679 data->ch_switch.freq,
6680 data->ch_switch.link_id,
6681 data->ch_switch.ht_enabled,
6682 data->ch_switch.ch_offset,
6683 channel_width_to_string(data->ch_switch.ch_width),
6684 data->ch_switch.cf1,
6685 data->ch_switch.cf2);
6686 if (event == EVENT_LINK_CH_SWITCH_STARTED)
6687 break;
6688
6689 wpa_s->links[data->ch_switch.link_id].freq =
6690 data->ch_switch.freq;
6691 if (wpa_s->links[data->ch_switch.link_id].bss &&
6692 wpa_s->links[data->ch_switch.link_id].bss->freq !=
6693 data->ch_switch.freq) {
6694 wpa_s->links[data->ch_switch.link_id].bss->freq =
6695 data->ch_switch.freq;
6696 notify_bss_changes(
6697 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6698 wpa_s->links[data->ch_switch.link_id].bss);
Shuibing Dai0db6bb12023-09-28 17:53:17 -07006699 if (data->ch_switch.freq)
6700 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
Sunil Ravi89eba102022-09-13 21:04:37 -07006701 }
6702 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07006703 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07006704 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006705 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006706 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006707
Hai Shalom81f62d82019-07-22 12:10:00 -07006708 wpa_msg(wpa_s, MSG_INFO,
6709 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6710 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6711 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006712 data->ch_switch.freq,
6713 data->ch_switch.ht_enabled,
6714 data->ch_switch.ch_offset,
6715 channel_width_to_string(data->ch_switch.ch_width),
6716 data->ch_switch.cf1,
6717 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07006718 if (event == EVENT_CH_SWITCH_STARTED)
6719 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006720
Sunil Ravi65a724b2022-05-24 11:06:09 -07006721 if (wpa_s->assoc_freq && data->ch_switch.freq &&
6722 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
6723 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
6724 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006725 wpa_s->assoc_freq = data->ch_switch.freq;
6726 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08006727 if (wpa_s->current_bss &&
6728 wpa_s->current_bss->freq != data->ch_switch.freq) {
6729 wpa_s->current_bss->freq = data->ch_switch.freq;
6730 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6731 wpa_s->current_bss);
6732 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006733
Hai Shalomfdcde762020-04-02 11:19:20 -07006734#ifdef CONFIG_SME
6735 switch (data->ch_switch.ch_offset) {
6736 case 1:
6737 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6738 break;
6739 case -1:
6740 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6741 break;
6742 default:
6743 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6744 break;
6745 }
6746#endif /* CONFIG_SME */
6747
Roshan Pius3a1667e2018-07-03 15:17:14 -07006748#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006749 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6750 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08006751 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006752 wpa_s->current_ssid->mode ==
6753 WPAS_MODE_P2P_GROUP_FORMATION) {
6754 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6755 data->ch_switch.ht_enabled,
6756 data->ch_switch.ch_offset,
6757 data->ch_switch.ch_width,
6758 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006759 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07006760 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07006761 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006762 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006763#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006764
Hai Shalom899fcc72020-10-19 14:38:18 -07006765 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6766 sme_event_ch_switch(wpa_s);
6767
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006768 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006769 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006770 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006771#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006772#ifdef NEED_AP_MLME
6773 case EVENT_DFS_RADAR_DETECTED:
6774 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07006775 wpas_ap_event_dfs_radar_detected(wpa_s,
6776 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006777 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006778 case EVENT_DFS_NOP_FINISHED:
6779 if (data)
6780 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
6781 &data->dfs_event);
6782 break;
6783#endif /* NEED_AP_MLME */
6784#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006785 case EVENT_DFS_CAC_STARTED:
6786 if (data)
6787 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
6788 break;
6789 case EVENT_DFS_CAC_FINISHED:
6790 if (data)
6791 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
6792 break;
6793 case EVENT_DFS_CAC_ABORTED:
6794 if (data)
6795 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
6796 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006797 case EVENT_RX_MGMT: {
6798 u16 fc, stype;
6799 const struct ieee80211_mgmt *mgmt;
6800
Dmitry Shmidt818ea482014-03-10 13:15:21 -07006801#ifdef CONFIG_TESTING_OPTIONS
6802 if (wpa_s->ext_mgmt_frame_handling) {
6803 struct rx_mgmt *rx = &data->rx_mgmt;
6804 size_t hex_len = 2 * rx->frame_len + 1;
6805 char *hex = os_malloc(hex_len);
6806 if (hex) {
6807 wpa_snprintf_hex(hex, hex_len,
6808 rx->frame, rx->frame_len);
6809 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
6810 rx->freq, rx->datarate, rx->ssi_signal,
6811 hex);
6812 os_free(hex);
6813 }
6814 break;
6815 }
6816#endif /* CONFIG_TESTING_OPTIONS */
6817
Dmitry Shmidt04949592012-07-19 12:16:46 -07006818 mgmt = (const struct ieee80211_mgmt *)
6819 data->rx_mgmt.frame;
6820 fc = le_to_host16(mgmt->frame_control);
6821 stype = WLAN_FC_GET_STYPE(fc);
6822
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006823#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006824 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006825#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006826#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006827 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006828 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006829 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07006830 const u8 *ie;
6831 size_t ie_len;
6832
6833 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6834 ie_len = data->rx_mgmt.frame_len -
6835 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006836 wpas_p2p_probe_req_rx(
6837 wpa_s, src, mgmt->da,
6838 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006839 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006840 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006841 break;
6842 }
6843#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006844#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006845 if (wpa_s->current_ssid &&
6846 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
6847 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006848 data->rx_mgmt.frame_len >= 30) {
6849 wpa_supplicant_event_ibss_auth(wpa_s, data);
6850 break;
6851 }
6852#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006853
6854 if (stype == WLAN_FC_STYPE_ACTION) {
6855 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07006856 wpa_s, data->rx_mgmt.frame,
6857 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006858 data->rx_mgmt.freq,
6859 data->rx_mgmt.ssi_signal);
6860 break;
6861 }
6862
6863 if (wpa_s->ifmsh) {
6864 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006865 break;
6866 }
Hai Shalom60840252021-02-19 19:02:11 -08006867#ifdef CONFIG_PASN
6868 if (stype == WLAN_FC_STYPE_AUTH &&
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00006869 wpas_pasn_auth(wpa_s, mgmt, data->rx_mgmt.frame_len,
6870 data->rx_mgmt.freq) != -2)
Hai Shalom60840252021-02-19 19:02:11 -08006871 break;
6872#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006873
Roshan Pius3a1667e2018-07-03 15:17:14 -07006874#ifdef CONFIG_SAE
6875 if (stype == WLAN_FC_STYPE_AUTH &&
6876 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6877 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6878 sme_external_auth_mgmt_rx(
6879 wpa_s, data->rx_mgmt.frame,
6880 data->rx_mgmt.frame_len);
6881 break;
6882 }
6883#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006884 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6885 "management frame in non-AP mode");
6886 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006887#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006888 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006889
6890 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006891 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6892 const u8 *ie;
6893 size_t ie_len;
6894
6895 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6896 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006897
6898 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6899 mgmt->bssid, ie, ie_len,
6900 data->rx_mgmt.ssi_signal);
6901 }
6902
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006903 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006904#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006905 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006906 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006907 case EVENT_RX_PROBE_REQ:
6908 if (data->rx_probe_req.sa == NULL ||
6909 data->rx_probe_req.ie == NULL)
6910 break;
6911#ifdef CONFIG_AP
6912 if (wpa_s->ap_iface) {
6913 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6914 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006915 data->rx_probe_req.da,
6916 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006917 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006918 data->rx_probe_req.ie_len,
6919 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006920 break;
6921 }
6922#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006923 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006924 data->rx_probe_req.da,
6925 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006926 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006927 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006928 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006929 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006930 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006931 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006932#ifdef CONFIG_OFFCHANNEL
6933 offchannel_remain_on_channel_cb(
6934 wpa_s, data->remain_on_channel.freq,
6935 data->remain_on_channel.duration);
6936#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006937 wpas_p2p_remain_on_channel_cb(
6938 wpa_s, data->remain_on_channel.freq,
6939 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006940#ifdef CONFIG_DPP
6941 wpas_dpp_remain_on_channel_cb(
6942 wpa_s, data->remain_on_channel.freq,
6943 data->remain_on_channel.duration);
6944#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006945#ifdef CONFIG_NAN_USD
6946 wpas_nan_usd_remain_on_channel_cb(
6947 wpa_s, data->remain_on_channel.freq,
6948 data->remain_on_channel.duration);
6949#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006950 break;
6951 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006952#ifdef CONFIG_OFFCHANNEL
6953 offchannel_cancel_remain_on_channel_cb(
6954 wpa_s, data->remain_on_channel.freq);
6955#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006956 wpas_p2p_cancel_remain_on_channel_cb(
6957 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006958#ifdef CONFIG_DPP
6959 wpas_dpp_cancel_remain_on_channel_cb(
6960 wpa_s, data->remain_on_channel.freq);
6961#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006962#ifdef CONFIG_NAN_USD
6963 wpas_nan_usd_cancel_remain_on_channel_cb(
6964 wpa_s, data->remain_on_channel.freq);
6965#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006966 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006967 case EVENT_EAPOL_RX:
6968 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6969 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00006970 data->eapol_rx.data_len,
6971 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006972 break;
6973 case EVENT_SIGNAL_CHANGE:
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00006974 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
6975 "above=%d signal=%d noise=%d txrate=%lu",
6976 data->signal_change.above_threshold,
6977 data->signal_change.data.signal,
6978 data->signal_change.current_noise,
6979 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006980 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006981 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006982 bgscan_notify_signal_change(
6983 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006984 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006985 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006986 data->signal_change.data.current_tx_rate);
6987 os_memcpy(&wpa_s->last_signal_info, data,
6988 sizeof(struct wpa_signal_info));
6989 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006990 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006991 case EVENT_INTERFACE_MAC_CHANGED:
6992 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006993 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006994 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006995 case EVENT_INTERFACE_ENABLED:
6996 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6997 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006998 u8 addr[ETH_ALEN];
6999
Hai Shalomfdcde762020-04-02 11:19:20 -07007000 eloop_cancel_timeout(wpas_clear_disabled_interface,
7001 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08007002 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007003 wpa_supplicant_update_mac_addr(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007004 if (!ether_addr_equal(addr, wpa_s->own_addr))
Hai Shalomc1a21442022-02-04 13:43:00 -08007005 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
7006 else
7007 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07007008 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007009 if (wpa_s->p2p_mgmt) {
7010 wpa_supplicant_set_state(wpa_s,
7011 WPA_DISCONNECTED);
7012 break;
7013 }
7014
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007015#ifdef CONFIG_AP
7016 if (!wpa_s->ap_iface) {
7017 wpa_supplicant_set_state(wpa_s,
7018 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007019 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007020 wpa_supplicant_req_scan(wpa_s, 0, 0);
7021 } else
7022 wpa_supplicant_set_state(wpa_s,
7023 WPA_COMPLETED);
7024#else /* CONFIG_AP */
7025 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
7026 wpa_supplicant_req_scan(wpa_s, 0, 0);
7027#endif /* CONFIG_AP */
7028 }
7029 break;
7030 case EVENT_INTERFACE_DISABLED:
7031 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08007032#ifdef CONFIG_P2P
7033 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
7034 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
7035 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
7036 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007037 * Mark interface disabled if this happens to end up not
7038 * being removed as a separate P2P group interface.
7039 */
7040 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
7041 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08007042 * The interface was externally disabled. Remove
7043 * it assuming an external entity will start a
7044 * new session if needed.
7045 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007046 if (wpa_s->current_ssid &&
7047 wpa_s->current_ssid->p2p_group)
7048 wpas_p2p_interface_unavailable(wpa_s);
7049 else
7050 wpas_p2p_disconnect(wpa_s);
7051 /*
7052 * wpa_s instance may have been freed, so must not use
7053 * it here anymore.
7054 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08007055 break;
7056 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07007057 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
7058 p2p_in_progress(wpa_s->global->p2p) > 1) {
7059 /* This radio work will be cancelled, so clear P2P
7060 * state as well.
7061 */
7062 p2p_stop_find(wpa_s->global->p2p);
7063 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08007064#endif /* CONFIG_P2P */
7065
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07007066 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
7067 /*
7068 * Indicate disconnection to keep ctrl_iface events
7069 * consistent.
7070 */
7071 wpa_supplicant_event_disassoc(
7072 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
7073 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007074 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07007075 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08007076 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
7077 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07007078 clear_at.usec = 0;
7079 } else {
7080 struct os_reltime tmp;
7081
Hai Shalom60840252021-02-19 19:02:11 -08007082 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07007083 tmp.usec = 0;
7084 os_reltime_sub(&tmp, &age, &clear_at);
7085 }
7086 eloop_register_timeout(clear_at.sec, clear_at.usec,
7087 wpas_clear_disabled_interface,
7088 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08007089 radio_remove_works(wpa_s, NULL, 0);
7090
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007091 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
7092 break;
7093 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07007094 wpa_supplicant_update_channel_list(
7095 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007096 break;
7097 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007098 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007099 break;
7100 case EVENT_BEST_CHANNEL:
7101 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
7102 "(%d %d %d)",
7103 data->best_chan.freq_24, data->best_chan.freq_5,
7104 data->best_chan.freq_overall);
7105 wpa_s->best_24_freq = data->best_chan.freq_24;
7106 wpa_s->best_5_freq = data->best_chan.freq_5;
7107 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007108 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
7109 data->best_chan.freq_5,
7110 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007111 break;
7112 case EVENT_UNPROT_DEAUTH:
7113 wpa_supplicant_event_unprot_deauth(wpa_s,
7114 &data->unprot_deauth);
7115 break;
7116 case EVENT_UNPROT_DISASSOC:
7117 wpa_supplicant_event_unprot_disassoc(wpa_s,
7118 &data->unprot_disassoc);
7119 break;
7120 case EVENT_STATION_LOW_ACK:
7121#ifdef CONFIG_AP
7122 if (wpa_s->ap_iface && data)
7123 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
7124 data->low_ack.addr);
7125#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007126#ifdef CONFIG_TDLS
7127 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007128 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
7129 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007130#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007131 break;
7132 case EVENT_IBSS_PEER_LOST:
7133#ifdef CONFIG_IBSS_RSN
7134 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
7135#endif /* CONFIG_IBSS_RSN */
7136 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007137 case EVENT_DRIVER_GTK_REKEY:
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007138 if (!ether_addr_equal(data->driver_gtk_rekey.bssid,
7139 wpa_s->bssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007140 break;
7141 if (!wpa_s->wpa)
7142 break;
7143 wpa_sm_update_replay_ctr(wpa_s->wpa,
7144 data->driver_gtk_rekey.replay_ctr);
7145 break;
7146 case EVENT_SCHED_SCAN_STOPPED:
7147 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007148 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007149 wpa_supplicant_notify_scanning(wpa_s, 0);
7150
7151 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7152 break;
7153
7154 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007155 * If the driver stopped scanning without being requested to,
7156 * request a new scan to continue scanning for networks.
7157 */
7158 if (!wpa_s->sched_scan_stop_req &&
7159 wpa_s->wpa_state == WPA_SCANNING) {
7160 wpa_dbg(wpa_s, MSG_DEBUG,
7161 "Restart scanning after unexpected sched_scan stop event");
7162 wpa_supplicant_req_scan(wpa_s, 1, 0);
7163 break;
7164 }
7165
7166 wpa_s->sched_scan_stop_req = 0;
7167
7168 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08007169 * Start a new sched scan to continue searching for more SSIDs
7170 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007171 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07007172 if (wpa_s->sched_scan_timed_out) {
7173 wpa_supplicant_req_sched_scan(wpa_s);
7174 } else if (wpa_s->pno_sched_pending) {
7175 wpa_s->pno_sched_pending = 0;
7176 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07007177 } else if (resched) {
7178 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08007179 }
7180
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007181 break;
7182 case EVENT_WPS_BUTTON_PUSHED:
7183#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07007184 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007185#endif /* CONFIG_WPS */
7186 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007187 case EVENT_AVOID_FREQUENCIES:
7188 wpa_supplicant_notify_avoid_freq(wpa_s, data);
7189 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08007190 case EVENT_CONNECT_FAILED_REASON:
7191#ifdef CONFIG_AP
7192 if (!wpa_s->ap_iface || !data)
7193 break;
7194 hostapd_event_connect_failed_reason(
7195 wpa_s->ap_iface->bss[0],
7196 data->connect_failed_reason.addr,
7197 data->connect_failed_reason.code);
7198#endif /* CONFIG_AP */
7199 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007200 case EVENT_NEW_PEER_CANDIDATE:
7201#ifdef CONFIG_MESH
7202 if (!wpa_s->ifmsh || !data)
7203 break;
7204 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
7205 data->mesh_peer.ies,
7206 data->mesh_peer.ie_len);
7207#endif /* CONFIG_MESH */
7208 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007209 case EVENT_SURVEY:
7210#ifdef CONFIG_AP
7211 if (!wpa_s->ap_iface)
7212 break;
7213 hostapd_event_get_survey(wpa_s->ap_iface,
7214 &data->survey_results);
7215#endif /* CONFIG_AP */
7216 break;
7217 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08007218#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007219#ifdef CONFIG_ACS
7220 if (!wpa_s->ap_iface)
7221 break;
7222 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
7223 &data->acs_selected_channels);
7224#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08007225#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007226 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007227 case EVENT_P2P_LO_STOP:
7228#ifdef CONFIG_P2P
7229 wpa_s->p2p_lo_started = 0;
7230 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
7231 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
7232 data->p2p_lo_stop.reason_code);
7233#endif /* CONFIG_P2P */
7234 break;
Paul Stewart092955c2017-02-06 09:13:09 -08007235 case EVENT_BEACON_LOSS:
7236 if (!wpa_s->current_bss || !wpa_s->current_ssid)
7237 break;
7238 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
7239 bgscan_notify_beacon_loss(wpa_s);
7240 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007241 case EVENT_EXTERNAL_AUTH:
7242#ifdef CONFIG_SAE
7243 if (!wpa_s->current_ssid) {
7244 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
7245 break;
7246 }
7247 sme_external_auth_trigger(wpa_s, data);
7248#endif /* CONFIG_SAE */
7249 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07007250#ifdef CONFIG_PASN
7251 case EVENT_PASN_AUTH:
7252 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
7253 break;
7254#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007255 case EVENT_PORT_AUTHORIZED:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007256#ifdef CONFIG_AP
7257 if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
7258 struct sta_info *sta;
7259
7260 sta = ap_get_sta(wpa_s->ap_iface->bss[0],
7261 data->port_authorized.sta_addr);
7262 if (sta)
7263 ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
7264 sta, 1);
7265 else
7266 wpa_printf(MSG_DEBUG,
7267 "No STA info matching port authorized event found");
7268 break;
7269 }
7270#endif /* CONFIG_AP */
Sunil Ravi77d572f2023-01-17 23:58:31 +00007271#ifndef CONFIG_NO_WPA
7272 if (data->port_authorized.td_bitmap_len) {
7273 wpa_printf(MSG_DEBUG,
7274 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
7275 data->port_authorized.td_bitmap[0]);
7276 wpas_transition_disable(
7277 wpa_s, data->port_authorized.td_bitmap[0]);
7278 }
7279#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007280 wpa_supplicant_event_port_authorized(wpa_s);
7281 break;
7282 case EVENT_STATION_OPMODE_CHANGED:
7283#ifdef CONFIG_AP
7284 if (!wpa_s->ap_iface || !data)
7285 break;
7286
7287 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
7288 data->sta_opmode.addr,
7289 data->sta_opmode.smps_mode,
7290 data->sta_opmode.chan_width,
7291 data->sta_opmode.rx_nss);
7292#endif /* CONFIG_AP */
7293 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07007294 case EVENT_UNPROT_BEACON:
7295 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
7296 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08007297 case EVENT_TX_WAIT_EXPIRE:
7298#ifdef CONFIG_DPP
7299 wpas_dpp_tx_wait_expire(wpa_s);
7300#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007301#ifdef CONFIG_NAN_USD
7302 wpas_nan_usd_tx_wait_expire(wpa_s);
7303#endif /* CONFIG_NAN_USD */
Hai Shalomc1a21442022-02-04 13:43:00 -08007304 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00007305 case EVENT_TID_LINK_MAP:
7306 if (data)
7307 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
7308 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007309 default:
7310 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
7311 break;
7312 }
7313}
Dmitry Shmidte4663042016-04-04 10:07:49 -07007314
7315
7316void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
7317 union wpa_event_data *data)
7318{
7319 struct wpa_supplicant *wpa_s;
7320
7321 if (event != EVENT_INTERFACE_STATUS)
7322 return;
7323
7324 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
7325 if (wpa_s && wpa_s->driver->get_ifindex) {
7326 unsigned int ifindex;
7327
7328 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
7329 if (ifindex != data->interface_status.ifindex) {
7330 wpa_dbg(wpa_s, MSG_DEBUG,
7331 "interface status ifindex %d mismatch (%d)",
7332 ifindex, data->interface_status.ifindex);
7333 return;
7334 }
7335 }
7336#ifdef CONFIG_MATCH_IFACE
7337 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
7338 struct wpa_interface *wpa_i;
7339
7340 wpa_i = wpa_supplicant_match_iface(
7341 ctx, data->interface_status.ifname);
7342 if (!wpa_i)
7343 return;
7344 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
7345 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07007346 }
7347#endif /* CONFIG_MATCH_IFACE */
7348
7349 if (wpa_s)
7350 wpa_supplicant_event(wpa_s, event, data);
7351}