blob: 3e6f88d69d053d45ebb60fc87475b6510f18423a [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Hai Shalom021b0b52019-04-10 11:17:58 -07003 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
Sunil Ravic0f5d412024-09-11 22:12:49 +000012#include "utils/crc32.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013#include "eapol_supp/eapol_supp_sm.h"
14#include "rsn_supp/wpa.h"
15#include "eloop.h"
16#include "config.h"
17#include "l2_packet/l2_packet.h"
18#include "wpa_supplicant_i.h"
19#include "driver_i.h"
20#include "pcsc_funcs.h"
21#include "rsn_supp/preauth.h"
22#include "rsn_supp/pmksa_cache.h"
23#include "common/wpa_ctrl.h"
24#include "eap_peer/eap.h"
25#include "ap/hostapd.h"
Sunil Ravi2a14cf12023-11-21 00:54:38 +000026#include "ap/sta_info.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080028#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070029#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "notify.h"
31#include "common/ieee802_11_defs.h"
32#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070033#include "common/gas_server.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070034#include "common/dpp.h"
Hai Shalom60840252021-02-19 19:02:11 -080035#include "common/ptksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "crypto/random.h"
Hai Shalom60840252021-02-19 19:02:11 -080037#include "bssid_ignore.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#include "wpas_glue.h"
39#include "wps_supplicant.h"
40#include "ibss_rsn.h"
41#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080042#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "p2p_supplicant.h"
44#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070045#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#include "ap.h"
47#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080049#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070050#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080051#include "mesh.h"
52#include "mesh_mpm.h"
53#include "wmm_ac.h"
Sunil Ravib0ac25f2024-07-12 01:42:03 +000054#include "nan_usd.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070055#include "dpp_supplicant.h"
Mir Ali677e7482020-11-12 19:49:02 +053056#include "rsn_supp/wpa_i.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070057
58
Hai Shalom39ba6fc2019-01-22 12:40:38 -080059#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
60
61
Dmitry Shmidt34af3062013-07-11 10:46:32 -070062#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070063static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000064 int new_scan, int own_request,
65 bool trigger_6ghz_scan,
66 union wpa_event_data *data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070067#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080068
69
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070070int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070071{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080072 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070073
74 if (ssid == NULL || ssid->disabled_until.sec == 0)
75 return 0;
76
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080077 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070078 if (ssid->disabled_until.sec > now.sec)
79 return ssid->disabled_until.sec - now.sec;
80
81 wpas_clear_temp_disabled(wpa_s, ssid, 0);
82
83 return 0;
84}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070085
86
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080087#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070088/**
89 * wpas_reenabled_network_time - Time until first network is re-enabled
90 * @wpa_s: Pointer to wpa_supplicant data
91 * Returns: If all enabled networks are temporarily disabled, returns the time
92 * (in sec) until the first network is re-enabled. Otherwise returns 0.
93 *
94 * This function is used in case all enabled networks are temporarily disabled,
95 * in which case it returns the time (in sec) that the first network will be
96 * re-enabled. The function assumes that at least one network is enabled.
97 */
98static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
99{
100 struct wpa_ssid *ssid;
101 int disabled_for, res = 0;
102
103#ifdef CONFIG_INTERWORKING
104 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
105 wpa_s->conf->cred)
106 return 0;
107#endif /* CONFIG_INTERWORKING */
108
109 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
110 if (ssid->disabled)
111 continue;
112
113 disabled_for = wpas_temp_disabled(wpa_s, ssid);
114 if (!disabled_for)
115 return 0;
116
117 if (!res || disabled_for < res)
118 res = disabled_for;
119 }
120
121 return res;
122}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800123#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700124
125
126void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
127{
128 struct wpa_supplicant *wpa_s = eloop_ctx;
129
130 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
131 return;
132
133 wpa_dbg(wpa_s, MSG_DEBUG,
134 "Try to associate due to network getting re-enabled");
135 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
136 wpa_supplicant_cancel_sched_scan(wpa_s);
137 wpa_supplicant_req_scan(wpa_s, 0, 0);
138 }
139}
140
141
Sunil Ravi7f769292024-07-23 22:21:32 +0000142static struct wpa_bss * __wpa_supplicant_get_new_bss(
143 struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *ssid,
144 size_t ssid_len)
145{
146 if (ssid && ssid_len > 0)
147 return wpa_bss_get(wpa_s, bssid, ssid, ssid_len);
148 else
149 return wpa_bss_get_bssid(wpa_s, bssid);
150}
151
152
153static struct wpa_bss * _wpa_supplicant_get_new_bss(
154 struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *ssid,
155 size_t ssid_len, bool try_update_scan_results)
156{
157 struct wpa_bss *bss = __wpa_supplicant_get_new_bss(wpa_s, bssid, ssid,
158 ssid_len);
159
160 if (bss || !try_update_scan_results)
161 return bss;
162
163 wpa_supplicant_update_scan_results(wpa_s, bssid);
164
165 return __wpa_supplicant_get_new_bss(wpa_s, bssid, ssid, ssid_len);
166}
167
168
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800169static struct wpa_bss * wpa_supplicant_get_new_bss(
170 struct wpa_supplicant *wpa_s, const u8 *bssid)
171{
172 struct wpa_bss *bss = NULL;
173 struct wpa_ssid *ssid = wpa_s->current_ssid;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000174 u8 drv_ssid[SSID_MAX_LEN];
175 int res;
Sunil Ravi7f769292024-07-23 22:21:32 +0000176 bool try_update_scan_results = true;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800177
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000178 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
Sunil Ravi7f769292024-07-23 22:21:32 +0000179 if (res > 0) {
180 bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, drv_ssid, res,
181 try_update_scan_results);
182 try_update_scan_results = false;
183 }
184 if (!bss && ssid && ssid->ssid_len > 0) {
185 bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, ssid->ssid,
186 ssid->ssid_len,
187 try_update_scan_results);
188 try_update_scan_results = false;
189 }
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800190 if (!bss)
Sunil Ravi7f769292024-07-23 22:21:32 +0000191 bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, NULL, 0,
192 try_update_scan_results);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800193
194 return bss;
195}
196
197
Sunil Ravia04bd252022-05-02 22:54:18 -0700198static struct wpa_bss *
199wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700200{
Sunil Ravia04bd252022-05-02 22:54:18 -0700201 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700202
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700203 if (bss)
204 wpa_s->current_bss = bss;
Sunil Ravia04bd252022-05-02 22:54:18 -0700205
206 return bss;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700207}
208
209
Sunil Ravi89eba102022-09-13 21:04:37 -0700210static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
211 u8 link_id, const u8 *bssid)
212{
213 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
214
Sunil Ravi89eba102022-09-13 21:04:37 -0700215 if (bss)
216 wpa_s->links[link_id].bss = bss;
217}
218
219
Sunil Ravi77d572f2023-01-17 23:58:31 +0000220static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
221 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222{
223 struct wpa_ssid *ssid, *old_ssid;
Sunil Ravi640215c2023-06-28 23:08:09 +0000224 struct wpa_bss *bss;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700225 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700226 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700227 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700229 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700230 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700231
232 if (wpa_s->current_ssid->ssid_len == 0)
233 return 0; /* current profile still in use */
234 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
235 if (res < 0) {
236 wpa_msg(wpa_s, MSG_INFO,
237 "Failed to read SSID from driver");
238 return 0; /* try to use current profile */
239 }
240 drv_ssid_len = res;
241
242 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
243 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
244 drv_ssid_len) == 0)
245 return 0; /* current profile still in use */
246
Hai Shalomfdcde762020-04-02 11:19:20 -0700247#ifdef CONFIG_OWE
248 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
249 wpa_s->current_bss &&
250 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
251 drv_ssid_len == wpa_s->current_bss->ssid_len &&
252 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
253 drv_ssid_len) == 0)
254 return 0; /* current profile still in use */
255#endif /* CONFIG_OWE */
256
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700257 wpa_msg(wpa_s, MSG_DEBUG,
258 "Driver-initiated BSS selection changed the SSID to %s",
259 wpa_ssid_txt(drv_ssid, drv_ssid_len));
260 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700261 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262
263 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
264 "information");
265 ssid = wpa_supplicant_get_ssid(wpa_s);
266 if (ssid == NULL) {
267 wpa_msg(wpa_s, MSG_INFO,
268 "No network configuration found for the current AP");
269 return -1;
270 }
271
Dmitry Shmidt04949592012-07-19 12:16:46 -0700272 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
274 return -1;
275 }
276
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800277 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
278 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
279 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
280 return -1;
281 }
282
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700283 res = wpas_temp_disabled(wpa_s, ssid);
284 if (res > 0) {
285 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
286 "disabled for %d second(s)", res);
287 return -1;
288 }
289
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700290 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
291 "current AP");
Sunil Ravi640215c2023-06-28 23:08:09 +0000292 bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800293 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 u8 wpa_ie[80];
295 size_t wpa_ie_len = sizeof(wpa_ie);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000296 bool skip_default_rsne;
297
298 /* Do not override RSNE/RSNXE with the default values if the
299 * driver indicated the actual values used in the
300 * (Re)Association Request frame. */
301 skip_default_rsne = data && data->assoc_info.req_ies;
Sunil Ravi640215c2023-06-28 23:08:09 +0000302 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000303 wpa_ie, &wpa_ie_len,
304 skip_default_rsne) < 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800305 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700306 } else {
307 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
308 }
309
310 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
311 eapol_sm_invalidate_cached_session(wpa_s->eapol);
312 old_ssid = wpa_s->current_ssid;
313 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800314
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
316 wpa_supplicant_initiate_eapol(wpa_s);
317 if (old_ssid != wpa_s->current_ssid)
318 wpas_notify_network_changed(wpa_s);
319
320 return 0;
321}
322
323
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800324void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325{
326 struct wpa_supplicant *wpa_s = eloop_ctx;
327
328 if (wpa_s->countermeasures) {
329 wpa_s->countermeasures = 0;
330 wpa_drv_set_countermeasures(wpa_s, 0);
331 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800332
333 /*
334 * It is possible that the device is sched scanning, which means
335 * that a connection attempt will be done only when we receive
336 * scan results. However, in this case, it would be preferable
337 * to scan and connect immediately, so cancel the sched_scan and
338 * issue a regular scan flow.
339 */
340 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700341 wpa_supplicant_req_scan(wpa_s, 0, 0);
342 }
343}
344
345
Sunil Ravi77d572f2023-01-17 23:58:31 +0000346void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
Sunil Ravi89eba102022-09-13 21:04:37 -0700347{
Sunil Ravi89eba102022-09-13 21:04:37 -0700348 if (!wpa_s->valid_links)
349 return;
350
351 wpa_s->valid_links = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000352 wpa_s->mlo_assoc_link_id = 0;
353 os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN);
354 os_memset(wpa_s->links, 0, sizeof(wpa_s->links));
Sunil Ravi89eba102022-09-13 21:04:37 -0700355}
356
357
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700358void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
359{
360 int bssid_changed;
361
Dmitry Shmidt04949592012-07-19 12:16:46 -0700362 wnm_bss_keep_alive_deinit(wpa_s);
363
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364#ifdef CONFIG_IBSS_RSN
365 ibss_rsn_deinit(wpa_s->ibss_rsn);
366 wpa_s->ibss_rsn = NULL;
367#endif /* CONFIG_IBSS_RSN */
368
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700369#ifdef CONFIG_AP
370 wpa_supplicant_ap_deinit(wpa_s);
371#endif /* CONFIG_AP */
372
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700373#ifdef CONFIG_HS20
374 /* Clear possibly configured frame filters */
375 wpa_drv_configure_frame_filters(wpa_s, 0);
376#endif /* CONFIG_HS20 */
377
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700378 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
379 return;
380
Hai Shalom74f70d42019-02-11 14:42:39 -0800381 if (os_reltime_initialized(&wpa_s->session_start)) {
382 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
383 wpa_s->session_start.sec = 0;
384 wpa_s->session_start.usec = 0;
385 wpas_notify_session_length(wpa_s);
386 }
387
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
389 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
390 os_memset(wpa_s->bssid, 0, ETH_ALEN);
391 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800392 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700393 wpa_s->current_bss = NULL;
394 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 if (bssid_changed)
397 wpas_notify_bssid_changed(wpa_s);
398
Hai Shalome21d4e82020-04-29 16:34:06 -0700399 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
400 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700401 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
402 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700403 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700404 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700405 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700406 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700407 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700408 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700409 wpa_s->key_mgmt = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700410 wpa_s->allowed_key_mgmts = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800411
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000412#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800413 wpas_rrm_reset(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000414#endif /* CONFIG_NO_RRM */
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800415 wpa_s->wnmsleep_used = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000416#ifdef CONFIG_WNM
417 wpa_s->wnm_mode = 0;
418#endif /* CONFIG_WNM */
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800419 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700420 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700421
422#ifdef CONFIG_TESTING_OPTIONS
423 wpa_s->last_tk_alg = WPA_ALG_NONE;
424 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
425#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700426 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800427
428 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
429 wpa_s->enabled_4addr_mode = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700430
Sunil Ravi77d572f2023-01-17 23:58:31 +0000431 wpa_s->wps_scan_done = false;
Sunil Ravi89eba102022-09-13 21:04:37 -0700432 wpas_reset_mlo_info(wpa_s);
Sunil Ravi7f769292024-07-23 22:21:32 +0000433
434#ifdef CONFIG_SME
435 wpa_s->sme.bss_max_idle_period = 0;
436#endif /* CONFIG_SME */
437
438 wpa_s->ssid_verified = false;
439 wpa_s->bigtk_set = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440}
441
442
Sunil Ravi036cec52023-03-29 11:35:17 -0700443static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444{
445 struct wpa_ie_data ie;
446 int pmksa_set = -1;
447 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800448 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700449
Hai Shalomc1a21442022-02-04 13:43:00 -0800450 /* Start with assumption of no PMKSA cache entry match for cases other
451 * than SAE. In particular, this is needed to generate the PMKSA cache
452 * entries for Suite B cases with driver-based roaming indication. */
453 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
454 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
455 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700456
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
458 ie.pmkid == NULL)
459 return;
460
461 for (i = 0; i < ie.num_pmkid; i++) {
462 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
463 ie.pmkid + i * PMKID_LEN,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000464 NULL, NULL, 0, NULL, 0,
465 true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800467 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Sunil Ravi036cec52023-03-29 11:35:17 -0700468 if (authorized)
469 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470 break;
471 }
472 }
473
474 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
475 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
476}
477
478
479static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
480 union wpa_event_data *data)
481{
482 if (data == NULL) {
483 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
484 "event");
485 return;
486 }
487 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
488 " index=%d preauth=%d",
489 MAC2STR(data->pmkid_candidate.bssid),
490 data->pmkid_candidate.index,
491 data->pmkid_candidate.preauth);
492
493 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
494 data->pmkid_candidate.index,
495 data->pmkid_candidate.preauth);
496}
497
498
499static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
500{
501 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
502 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
503 return 0;
504
505#ifdef IEEE8021X_EAPOL
506 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
507 wpa_s->current_ssid &&
508 !(wpa_s->current_ssid->eapol_flags &
509 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
510 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
511 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
512 * plaintext or static WEP keys). */
513 return 0;
514 }
515#endif /* IEEE8021X_EAPOL */
516
517 return 1;
518}
519
520
521/**
522 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
523 * @wpa_s: pointer to wpa_supplicant data
524 * @ssid: Configuration data for the network
525 * Returns: 0 on success, -1 on failure
526 *
527 * This function is called when starting authentication with a network that is
528 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
529 */
530int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
531 struct wpa_ssid *ssid)
532{
533#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800534#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700535 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700537 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
538 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539 return 0;
540
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700541 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542 sim = 1;
543 aka = 1;
544 } else {
545 struct eap_method_type *eap = ssid->eap.eap_methods;
546 while (eap->vendor != EAP_VENDOR_IETF ||
547 eap->method != EAP_TYPE_NONE) {
548 if (eap->vendor == EAP_VENDOR_IETF) {
549 if (eap->method == EAP_TYPE_SIM)
550 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700551 else if (eap->method == EAP_TYPE_AKA ||
552 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553 aka = 1;
554 }
555 eap++;
556 }
557 }
558
559 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
560 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700561 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
562 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
563 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 aka = 0;
565
566 if (!sim && !aka) {
567 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
568 "use SIM, but neither EAP-SIM nor EAP-AKA are "
569 "enabled");
570 return 0;
571 }
572
573 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
574 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700576 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577 if (wpa_s->scard == NULL) {
578 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
579 "(pcsc-lite)");
580 return -1;
581 }
582 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
583 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800584#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585#endif /* IEEE8021X_EAPOL */
586
587 return 0;
588}
589
590
591#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700592
Hai Shalomfdcde762020-04-02 11:19:20 -0700593#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700594static int has_wep_key(struct wpa_ssid *ssid)
595{
596 int i;
597
598 for (i = 0; i < NUM_WEP_KEYS; i++) {
599 if (ssid->wep_key_len[i])
600 return 1;
601 }
602
603 return 0;
604}
Hai Shalomfdcde762020-04-02 11:19:20 -0700605#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700606
607
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700608static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 struct wpa_ssid *ssid)
610{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700611 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700612
613 if (ssid->mixed_cell)
614 return 1;
615
616#ifdef CONFIG_WPS
617 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
618 return 1;
619#endif /* CONFIG_WPS */
620
Roshan Pius3a1667e2018-07-03 15:17:14 -0700621#ifdef CONFIG_OWE
622 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
623 return 1;
624#endif /* CONFIG_OWE */
625
Hai Shalomfdcde762020-04-02 11:19:20 -0700626#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700627 if (has_wep_key(ssid))
628 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700629#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700630
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631#ifdef IEEE8021X_EAPOL
632 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
633 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
634 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
635 privacy = 1;
636#endif /* IEEE8021X_EAPOL */
637
Jouni Malinen75ecf522011-06-27 15:19:46 -0700638 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
639 privacy = 1;
640
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800641 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
642 privacy = 1;
643
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 if (bss->caps & IEEE80211_CAP_PRIVACY)
645 return privacy;
646 return !privacy;
647}
648
649
650static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
651 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800652 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700653{
654 struct wpa_ie_data ie;
655 int proto_match = 0;
656 const u8 *rsn_ie, *wpa_ie;
657 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700658#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700659 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700660#endif /* CONFIG_WEP */
Sunil Ravi640215c2023-06-28 23:08:09 +0000661 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662
663 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
664 if (ret >= 0)
665 return ret;
666
Hai Shalomfdcde762020-04-02 11:19:20 -0700667#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
669 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
670 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
671 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
672 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700673#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674
Sunil Ravi7f769292024-07-23 22:21:32 +0000675 rsn_ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
Sunil Ravi640215c2023-06-28 23:08:09 +0000676 if (is_6ghz_bss && !rsn_ie) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700677 if (debug_print)
678 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000679 " skip - 6 GHz BSS without RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700680 return 0;
681 }
682
Roshan Pius3a1667e2018-07-03 15:17:14 -0700683 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 proto_match++;
685
686 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800687 if (debug_print)
688 wpa_dbg(wpa_s, MSG_DEBUG,
689 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690 break;
691 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700692 if (!ie.has_pairwise)
693 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
694 if (!ie.has_group)
695 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696
Sunil Ravi640215c2023-06-28 23:08:09 +0000697 if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
698 /* WEP and TKIP are not allowed on 6 GHz/MLD */
Sunil Ravia04bd252022-05-02 22:54:18 -0700699 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
700 WPA_CIPHER_WEP104 |
701 WPA_CIPHER_TKIP);
702 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
703 WPA_CIPHER_WEP104 |
704 WPA_CIPHER_TKIP);
705 }
706
Hai Shalomfdcde762020-04-02 11:19:20 -0700707#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700708 if (wep_ok &&
709 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
710 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800711 if (debug_print)
712 wpa_dbg(wpa_s, MSG_DEBUG,
713 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700714 return 1;
715 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700716#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717
Roshan Pius3a1667e2018-07-03 15:17:14 -0700718 if (!(ie.proto & ssid->proto) &&
719 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800720 if (debug_print)
721 wpa_dbg(wpa_s, MSG_DEBUG,
722 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723 break;
724 }
725
726 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800727 if (debug_print)
728 wpa_dbg(wpa_s, MSG_DEBUG,
729 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 break;
731 }
732
733 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800734 if (debug_print)
735 wpa_dbg(wpa_s, MSG_DEBUG,
736 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737 break;
738 }
739
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700740 if (ssid->group_mgmt_cipher &&
741 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
742 if (debug_print)
743 wpa_dbg(wpa_s, MSG_DEBUG,
744 " skip RSN IE - group mgmt cipher mismatch");
745 break;
746 }
747
Sunil Ravi640215c2023-06-28 23:08:09 +0000748 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700749 /* MFPC must be supported on 6 GHz */
750 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
751 if (debug_print)
752 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000753 " skip RSNE - 6 GHz without MFPC");
Sunil Ravia04bd252022-05-02 22:54:18 -0700754 break;
755 }
756
757 /* WPA PSK is not allowed on the 6 GHz band */
758 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
759 WPA_KEY_MGMT_FT_PSK |
760 WPA_KEY_MGMT_PSK_SHA256);
761 }
762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800764 if (debug_print)
765 wpa_dbg(wpa_s, MSG_DEBUG,
766 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767 break;
768 }
769
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800771 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800772 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800773 if (debug_print)
774 wpa_dbg(wpa_s, MSG_DEBUG,
775 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776 break;
777 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800778 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
779 wpas_get_ssid_pmf(wpa_s, ssid) ==
780 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800781 if (debug_print)
782 wpa_dbg(wpa_s, MSG_DEBUG,
783 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800784 break;
785 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700786
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800787 if (debug_print)
788 wpa_dbg(wpa_s, MSG_DEBUG,
789 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790 return 1;
791 }
792
Sunil Ravi640215c2023-06-28 23:08:09 +0000793 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700794 if (debug_print)
795 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000796 " skip - 6 GHz BSS without matching RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700797 return 0;
798 }
799
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000800 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
801
Roshan Pius3a1667e2018-07-03 15:17:14 -0700802 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
803 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000804#ifdef CONFIG_OWE
805 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && ssid->owe_only &&
806 !wpa_ie && !rsn_ie &&
807 wpa_s->owe_transition_select &&
808 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
809 ssid->owe_transition_bss_select_count + 1 <=
810 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
811 ssid->owe_transition_bss_select_count++;
812 if (debug_print)
813 wpa_dbg(wpa_s, MSG_DEBUG,
814 " skip OWE open BSS (selection count %d does not exceed %d)",
815 ssid->owe_transition_bss_select_count,
816 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
817 wpa_s->owe_transition_search = 1;
818 return 0;
819 }
820#endif /* CONFIG_OWE */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800821 if (debug_print)
822 wpa_dbg(wpa_s, MSG_DEBUG,
823 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700824 return 0;
825 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700826
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
828 proto_match++;
829
830 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800831 if (debug_print)
832 wpa_dbg(wpa_s, MSG_DEBUG,
833 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700834 break;
835 }
836
Hai Shalomfdcde762020-04-02 11:19:20 -0700837#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 if (wep_ok &&
839 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
840 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800841 if (debug_print)
842 wpa_dbg(wpa_s, MSG_DEBUG,
843 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844 return 1;
845 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700846#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847
848 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800849 if (debug_print)
850 wpa_dbg(wpa_s, MSG_DEBUG,
851 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700852 break;
853 }
854
855 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800856 if (debug_print)
857 wpa_dbg(wpa_s, MSG_DEBUG,
858 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700859 break;
860 }
861
862 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800863 if (debug_print)
864 wpa_dbg(wpa_s, MSG_DEBUG,
865 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866 break;
867 }
868
869 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800870 if (debug_print)
871 wpa_dbg(wpa_s, MSG_DEBUG,
872 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700873 break;
874 }
875
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800876 if (debug_print)
877 wpa_dbg(wpa_s, MSG_DEBUG,
878 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879 return 1;
880 }
881
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700882 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
883 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800884 if (debug_print)
885 wpa_dbg(wpa_s, MSG_DEBUG,
886 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700887 return 1;
888 }
889
Roshan Pius3a1667e2018-07-03 15:17:14 -0700890#ifdef CONFIG_OWE
891 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
892 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800893 if (wpa_s->owe_transition_select &&
894 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
895 ssid->owe_transition_bss_select_count + 1 <=
896 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
897 ssid->owe_transition_bss_select_count++;
898 if (debug_print)
899 wpa_dbg(wpa_s, MSG_DEBUG,
900 " skip OWE transition BSS (selection count %d does not exceed %d)",
901 ssid->owe_transition_bss_select_count,
902 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
903 wpa_s->owe_transition_search = 1;
904 return 0;
905 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700906 if (debug_print)
907 wpa_dbg(wpa_s, MSG_DEBUG,
908 " allow in OWE transition mode");
909 return 1;
910 }
911#endif /* CONFIG_OWE */
912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
914 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800915 if (debug_print)
916 wpa_dbg(wpa_s, MSG_DEBUG,
917 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918 return 0;
919 }
920
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800921 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
922 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800923 if (debug_print)
924 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800925 return 1;
926 }
927
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800929 if (debug_print)
930 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 return 1;
932 }
933
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800934 if (debug_print)
935 wpa_dbg(wpa_s, MSG_DEBUG,
936 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700937
938 return 0;
939}
940
941
942static int freq_allowed(int *freqs, int freq)
943{
944 int i;
945
946 if (freqs == NULL)
947 return 1;
948
949 for (i = 0; freqs[i]; i++)
950 if (freqs[i] == freq)
951 return 1;
952 return 0;
953}
954
955
Hai Shalomfdcde762020-04-02 11:19:20 -0700956static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
957 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800958{
959 const struct hostapd_hw_modes *mode = NULL, *modes;
960 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
961 const u8 *rate_ie;
962 int i, j, k;
963
964 if (bss->freq == 0)
965 return 1; /* Cannot do matching without knowing band */
966
967 modes = wpa_s->hw.modes;
968 if (modes == NULL) {
969 /*
970 * The driver does not provide any additional information
971 * about the utilized hardware, so allow the connection attempt
972 * to continue.
973 */
974 return 1;
975 }
976
977 for (i = 0; i < wpa_s->hw.num_modes; i++) {
978 for (j = 0; j < modes[i].num_channels; j++) {
979 int freq = modes[i].channels[j].freq;
980 if (freq == bss->freq) {
981 if (mode &&
982 mode->mode == HOSTAPD_MODE_IEEE80211G)
983 break; /* do not allow 802.11b replace
984 * 802.11g */
985 mode = &modes[i];
986 break;
987 }
988 }
989 }
990
991 if (mode == NULL)
992 return 0;
993
994 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700995 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800996 if (rate_ie == NULL)
997 continue;
998
999 for (j = 2; j < rate_ie[1] + 2; j++) {
1000 int flagged = !!(rate_ie[j] & 0x80);
1001 int r = (rate_ie[j] & 0x7f) * 5;
1002
1003 /*
1004 * IEEE Std 802.11n-2009 7.3.2.2:
1005 * The new BSS Membership selector value is encoded
1006 * like a legacy basic rate, but it is not a rate and
1007 * only indicates if the BSS members are required to
1008 * support the mandatory features of Clause 20 [HT PHY]
1009 * in order to join the BSS.
1010 */
1011 if (flagged && ((rate_ie[j] & 0x7f) ==
1012 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
1013 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001014 if (debug_print)
1015 wpa_dbg(wpa_s, MSG_DEBUG,
1016 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001017 return 0;
1018 }
1019 continue;
1020 }
1021
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001022 /* There's also a VHT selector for 802.11ac */
1023 if (flagged && ((rate_ie[j] & 0x7f) ==
1024 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
1025 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001026 if (debug_print)
1027 wpa_dbg(wpa_s, MSG_DEBUG,
1028 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001029 return 0;
1030 }
1031 continue;
1032 }
1033
Sunil Ravi77d572f2023-01-17 23:58:31 +00001034 if (flagged && ((rate_ie[j] & 0x7f) ==
1035 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
1036 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
1037 if (debug_print)
1038 wpa_dbg(wpa_s, MSG_DEBUG,
1039 " hardware does not support HE PHY");
1040 return 0;
1041 }
1042 continue;
1043 }
1044
Hai Shalomc3565922019-10-28 11:58:20 -07001045#ifdef CONFIG_SAE
1046 if (flagged && ((rate_ie[j] & 0x7f) ==
1047 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001048 if (wpa_s->conf->sae_pwe ==
1049 SAE_PWE_HUNT_AND_PECK &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001050 !ssid->sae_password_id &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001051 !is_6ghz_freq(bss->freq) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001052 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -07001053 if (debug_print)
1054 wpa_dbg(wpa_s, MSG_DEBUG,
1055 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001056#ifdef CONFIG_TESTING_OPTIONS
1057 if (wpa_s->ignore_sae_h2e_only) {
1058 wpa_dbg(wpa_s, MSG_DEBUG,
1059 "TESTING: Ignore SAE H2E requirement mismatch");
1060 continue;
1061 }
1062#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -07001063 return 0;
1064 }
1065 continue;
1066 }
1067#endif /* CONFIG_SAE */
1068
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001069 if (!flagged)
1070 continue;
1071
1072 /* check for legacy basic rates */
1073 for (k = 0; k < mode->num_rates; k++) {
1074 if (mode->rates[k] == r)
1075 break;
1076 }
1077 if (k == mode->num_rates) {
1078 /*
1079 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1080 * order to join a BSS all required rates
1081 * have to be supported by the hardware.
1082 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001083 if (debug_print)
1084 wpa_dbg(wpa_s, MSG_DEBUG,
1085 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1086 r / 10, r % 10,
1087 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001088 return 0;
1089 }
1090 }
1091 }
1092
1093 return 1;
1094}
1095
1096
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001097/*
1098 * Test whether BSS is in an ESS.
1099 * This is done differently in DMG (60 GHz) and non-DMG bands
1100 */
1101static int bss_is_ess(struct wpa_bss *bss)
1102{
1103 if (bss_is_dmg(bss)) {
1104 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1105 IEEE80211_CAP_DMG_AP;
1106 }
1107
1108 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1109 IEEE80211_CAP_ESS);
1110}
1111
1112
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001113static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1114{
1115 size_t i;
1116
1117 for (i = 0; i < ETH_ALEN; i++) {
1118 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1119 return 0;
1120 }
1121 return 1;
1122}
1123
1124
1125static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1126{
1127 size_t i;
1128
1129 for (i = 0; i < num; i++) {
1130 const u8 *a = list + i * ETH_ALEN * 2;
1131 const u8 *m = a + ETH_ALEN;
1132
1133 if (match_mac_mask(a, addr, m))
1134 return 1;
1135 }
1136 return 0;
1137}
1138
1139
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001140static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1141 const u8 **ret_ssid, size_t *ret_ssid_len)
1142{
1143#ifdef CONFIG_OWE
Sunil Ravic0f5d412024-09-11 22:12:49 +00001144 const u8 *owe, *bssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001145
1146 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
Sunil Ravi7f769292024-07-23 22:21:32 +00001147 if (!owe || !wpa_bss_get_rsne(wpa_s, bss, NULL, false))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001148 return;
1149
Sunil Ravic0f5d412024-09-11 22:12:49 +00001150 if (wpas_get_owe_trans_network(owe, &bssid, ret_ssid, ret_ssid_len))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001151 return;
1152
1153 /* Match the profile SSID against the OWE transition mode SSID on the
1154 * open network. */
1155 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
Sunil Ravic0f5d412024-09-11 22:12:49 +00001156 " SSID: %s", MAC2STR(bssid),
1157 wpa_ssid_txt(*ret_ssid, *ret_ssid_len));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001158
Hai Shalomfdcde762020-04-02 11:19:20 -07001159 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1160 struct wpa_ssid *ssid;
1161
1162 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1163 if (wpas_network_disabled(wpa_s, ssid))
1164 continue;
Sunil Ravic0f5d412024-09-11 22:12:49 +00001165 if (ssid->ssid_len == *ret_ssid_len &&
1166 os_memcmp(ssid->ssid, ret_ssid, *ret_ssid_len) == 0) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001167 /* OWE BSS in transition mode for a currently
1168 * enabled OWE network. */
1169 wpa_dbg(wpa_s, MSG_DEBUG,
1170 "OWE: transition mode OWE SSID for active OWE profile");
1171 bss->flags |= WPA_BSS_OWE_TRANSITION;
1172 break;
1173 }
1174 }
1175 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001176#endif /* CONFIG_OWE */
1177}
1178
1179
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001180static bool wpas_valid_ml_bss(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001181{
1182 u16 removed_links;
1183
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001184 if (wpa_bss_parse_basic_ml_element(wpa_s, bss, NULL, NULL, NULL, NULL))
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001185 return true;
1186
Sunil Ravi99c035e2024-07-12 01:42:03 +00001187 if (!bss->valid_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001188 return true;
1189
1190 /* Check if the current BSS is going to be removed */
1191 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss);
Sunil Ravi99c035e2024-07-12 01:42:03 +00001192 if (BIT(bss->mld_link_id) & removed_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001193 return false;
1194
1195 return true;
1196}
1197
1198
Sunil Ravi26978f32021-04-30 15:19:18 -07001199int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001200{
1201 int i, j;
1202
1203 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1204 return 0;
1205
1206 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1207 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1208
1209 for (i = 0; i < mode->num_channels; i++) {
1210 struct hostapd_channel_data *chan = &mode->channels[i];
1211
1212 if (chan->freq == freq)
1213 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1214 }
1215 }
1216
1217 return 1;
1218}
1219
1220
Hai Shalom899fcc72020-10-19 14:38:18 -07001221static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1222 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001223 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001224 bool debug_print);
1225
1226
1227#ifdef CONFIG_SAE_PK
1228static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1229 struct wpa_bss *orig_bss,
1230 struct wpa_ssid *ssid,
1231 const u8 *match_ssid,
1232 size_t match_ssid_len)
1233{
1234 struct wpa_bss *bss;
1235
1236 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1237 int count;
1238 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001239
1240 if (bss == orig_bss)
1241 continue;
Sunil Ravi7f769292024-07-23 22:21:32 +00001242 ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
Hai Shalomc1a21442022-02-04 13:43:00 -08001243 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001244 continue;
1245
1246 /* TODO: Could be more thorough in checking what kind of
1247 * signal strength or throughput estimate would be acceptable
1248 * compared to the originally selected BSS. */
1249 if (bss->est_throughput < 2000)
1250 return false;
1251
Hai Shalom60840252021-02-19 19:02:11 -08001252 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001253 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1254 bss, count, 0))
1255 return true;
1256 }
1257
1258 return false;
1259}
1260#endif /* CONFIG_SAE_PK */
1261
1262
1263static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1264 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001265 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001266 bool debug_print)
1267{
1268 int res;
1269 bool wpa, check_ssid, osen, rsn_osen = false;
1270 struct wpa_ie_data data;
1271#ifdef CONFIG_MBO
1272 const u8 *assoc_disallow;
1273#endif /* CONFIG_MBO */
1274#ifdef CONFIG_SAE
1275 u8 rsnxe_capa = 0;
1276#endif /* CONFIG_SAE */
1277 const u8 *ie;
1278
1279 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1280 wpa = ie && ie[1];
Sunil Ravi7f769292024-07-23 22:21:32 +00001281 ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
Hai Shalom899fcc72020-10-19 14:38:18 -07001282 wpa |= ie && ie[1];
1283 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1284 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1285 rsn_osen = true;
1286 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1287 osen = ie != NULL;
1288
1289#ifdef CONFIG_SAE
Sunil Ravi7f769292024-07-23 22:21:32 +00001290 ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
1291 if (ie && ie[0] == WLAN_EID_VENDOR_SPECIFIC && ie[1] >= 4 + 1)
1292 rsnxe_capa = ie[4 + 2];
1293 else if (ie && ie[1] >= 1)
Hai Shalom899fcc72020-10-19 14:38:18 -07001294 rsnxe_capa = ie[2];
1295#endif /* CONFIG_SAE */
1296
1297 check_ssid = wpa || ssid->ssid_len > 0;
1298
1299 if (wpas_network_disabled(wpa_s, ssid)) {
1300 if (debug_print)
1301 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1302 return false;
1303 }
1304
1305 res = wpas_temp_disabled(wpa_s, ssid);
1306 if (res > 0) {
1307 if (debug_print)
1308 wpa_dbg(wpa_s, MSG_DEBUG,
1309 " skip - disabled temporarily for %d second(s)",
1310 res);
1311 return false;
1312 }
1313
1314#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001315 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001316 if (debug_print)
1317 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001318 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001319 return false;
1320 }
1321
1322 if (wpa && ssid->ssid_len == 0 &&
1323 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1324 check_ssid = false;
1325
1326 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1327 /* Only allow wildcard SSID match if an AP advertises active
1328 * WPS operation that matches our mode. */
1329 check_ssid = ssid->ssid_len > 0 ||
1330 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1331 }
1332#endif /* CONFIG_WPS */
1333
1334 if (ssid->bssid_set && ssid->ssid_len == 0 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001335 ether_addr_equal(bss->bssid, ssid->bssid))
Hai Shalom899fcc72020-10-19 14:38:18 -07001336 check_ssid = false;
1337
1338 if (check_ssid &&
1339 (match_ssid_len != ssid->ssid_len ||
1340 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1341 if (debug_print)
1342 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1343 return false;
1344 }
1345
1346 if (ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001347 !ether_addr_equal(bss->bssid, ssid->bssid)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001348 if (debug_print)
1349 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1350 return false;
1351 }
1352
Hai Shalom60840252021-02-19 19:02:11 -08001353 /* check the list of BSSIDs to ignore */
1354 if (ssid->num_bssid_ignore &&
1355 addr_in_list(bss->bssid, ssid->bssid_ignore,
1356 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001357 if (debug_print)
1358 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001359 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001360 return false;
1361 }
1362
Hai Shalom60840252021-02-19 19:02:11 -08001363 /* if there is a list of accepted BSSIDs, only accept those APs */
1364 if (ssid->num_bssid_accept &&
1365 !addr_in_list(bss->bssid, ssid->bssid_accept,
1366 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001367 if (debug_print)
1368 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001369 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001370 return false;
1371 }
1372
1373 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1374 return false;
1375
1376 if (!osen && !wpa &&
1377 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1378 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1379 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1380 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1381 if (debug_print)
1382 wpa_dbg(wpa_s, MSG_DEBUG,
1383 " skip - non-WPA network not allowed");
1384 return false;
1385 }
1386
1387#ifdef CONFIG_WEP
1388 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1389 if (debug_print)
1390 wpa_dbg(wpa_s, MSG_DEBUG,
1391 " skip - ignore WPA/WPA2 AP for WEP network block");
1392 return false;
1393 }
1394#endif /* CONFIG_WEP */
1395
1396 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1397 if (debug_print)
1398 wpa_dbg(wpa_s, MSG_DEBUG,
1399 " skip - non-OSEN network not allowed");
1400 return false;
1401 }
1402
1403 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1404 if (debug_print)
1405 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1406 return false;
1407 }
1408
1409 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1410 !bss_is_pbss(bss)) {
1411 if (debug_print)
1412 wpa_dbg(wpa_s, MSG_DEBUG,
1413 " skip - not ESS, PBSS, or MBSS");
1414 return false;
1415 }
1416
1417 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1418 if (debug_print)
1419 wpa_dbg(wpa_s, MSG_DEBUG,
1420 " skip - PBSS mismatch (ssid %d bss %d)",
1421 ssid->pbss, bss_is_pbss(bss));
1422 return false;
1423 }
1424
1425 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1426 if (debug_print)
1427 wpa_dbg(wpa_s, MSG_DEBUG,
1428 " skip - frequency not allowed");
1429 return false;
1430 }
1431
1432#ifdef CONFIG_MESH
1433 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1434 ssid->frequency != bss->freq) {
1435 if (debug_print)
1436 wpa_dbg(wpa_s, MSG_DEBUG,
1437 " skip - frequency not allowed (mesh)");
1438 return false;
1439 }
1440#endif /* CONFIG_MESH */
1441
1442 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1443 if (debug_print)
1444 wpa_dbg(wpa_s, MSG_DEBUG,
1445 " skip - rate sets do not match");
1446 return false;
1447 }
1448
1449#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001450 /* When using SAE Password Identifier and when operationg on the 6 GHz
1451 * band, only H2E is allowed. */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001452 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1453 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1454 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1455 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001456#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301457 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001458#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001459 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1460 if (debug_print)
1461 wpa_dbg(wpa_s, MSG_DEBUG,
1462 " skip - SAE H2E required, but not supported by the AP");
1463 return false;
1464 }
1465#endif /* CONFIG_SAE */
1466
1467#ifdef CONFIG_SAE_PK
1468 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1469 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1470 if (debug_print)
1471 wpa_dbg(wpa_s, MSG_DEBUG,
1472 " skip - SAE-PK required, but not supported by the AP");
1473 return false;
1474 }
1475#endif /* CONFIG_SAE_PK */
1476
1477#ifndef CONFIG_IBSS_RSN
1478 if (ssid->mode == WPAS_MODE_IBSS &&
1479 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1480 if (debug_print)
1481 wpa_dbg(wpa_s, MSG_DEBUG,
1482 " skip - IBSS RSN not supported in the build");
1483 return false;
1484 }
1485#endif /* !CONFIG_IBSS_RSN */
1486
1487#ifdef CONFIG_P2P
1488 if (ssid->p2p_group &&
1489 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1490 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1491 if (debug_print)
1492 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1493 return false;
1494 }
1495
1496 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1497 struct wpabuf *p2p_ie;
1498 u8 dev_addr[ETH_ALEN];
1499
1500 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1501 if (!ie) {
1502 if (debug_print)
1503 wpa_dbg(wpa_s, MSG_DEBUG,
1504 " skip - no P2P element");
1505 return false;
1506 }
1507 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1508 if (!p2p_ie) {
1509 if (debug_print)
1510 wpa_dbg(wpa_s, MSG_DEBUG,
1511 " skip - could not fetch P2P element");
1512 return false;
1513 }
1514
1515 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001516 !ether_addr_equal(dev_addr, ssid->go_p2p_dev_addr)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001517 if (debug_print)
1518 wpa_dbg(wpa_s, MSG_DEBUG,
1519 " skip - no matching GO P2P Device Address in P2P element");
1520 wpabuf_free(p2p_ie);
1521 return false;
1522 }
1523 wpabuf_free(p2p_ie);
1524 }
1525
1526 /*
1527 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1528 * P2P Group Capability Bitmap and we are not in Group Formation with
1529 * that device.
1530 */
1531#endif /* CONFIG_P2P */
1532
1533 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1534 struct os_reltime diff;
1535
1536 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1537 if (debug_print)
1538 wpa_dbg(wpa_s, MSG_DEBUG,
1539 " skip - scan result not recent enough (%u.%06u seconds too old)",
1540 (unsigned int) diff.sec,
1541 (unsigned int) diff.usec);
1542 return false;
1543 }
1544#ifdef CONFIG_MBO
1545#ifdef CONFIG_TESTING_OPTIONS
1546 if (wpa_s->ignore_assoc_disallow)
1547 goto skip_assoc_disallow;
1548#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001549 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001550 if (assoc_disallow && assoc_disallow[1] >= 1) {
1551 if (debug_print)
1552 wpa_dbg(wpa_s, MSG_DEBUG,
1553 " skip - MBO association disallowed (reason %u)",
1554 assoc_disallow[2]);
1555 return false;
1556 }
1557
1558 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1559 if (debug_print)
1560 wpa_dbg(wpa_s, MSG_DEBUG,
1561 " skip - AP temporarily disallowed");
1562 return false;
1563 }
1564#ifdef CONFIG_TESTING_OPTIONS
1565skip_assoc_disallow:
1566#endif /* CONFIG_TESTING_OPTIONS */
1567#endif /* CONFIG_MBO */
1568
1569#ifdef CONFIG_DPP
1570 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001571 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1572 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001573 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1574 !ssid->dpp_csign)) {
1575 if (debug_print)
1576 wpa_dbg(wpa_s, MSG_DEBUG,
1577 " skip - no PMKSA entry for DPP");
1578 return false;
1579 }
1580#endif /* CONFIG_DPP */
1581
1582#ifdef CONFIG_SAE_PK
1583 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1584 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1585 ((ssid->sae_password &&
1586 sae_pk_valid_password(ssid->sae_password)) ||
1587 (!ssid->sae_password && ssid->passphrase &&
1588 sae_pk_valid_password(ssid->passphrase))) &&
1589 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1590 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1591 match_ssid_len)) {
1592 if (debug_print)
1593 wpa_dbg(wpa_s, MSG_DEBUG,
1594 " skip - another acceptable BSS with SAE-PK in the same ESS");
1595 return false;
1596 }
1597#endif /* CONFIG_SAE_PK */
1598
1599 if (bss->ssid_len == 0) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001600#ifdef CONFIG_OWE
1601 const u8 *owe_ssid = NULL;
1602 size_t owe_ssid_len = 0;
1603
1604 owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len);
1605 if (owe_ssid && owe_ssid_len &&
1606 owe_ssid_len == ssid->ssid_len &&
1607 os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) {
1608 if (debug_print)
1609 wpa_dbg(wpa_s, MSG_DEBUG,
1610 " skip - no SSID in BSS entry for a possible OWE transition mode BSS");
1611 int_array_add_unique(&wpa_s->owe_trans_scan_freq,
1612 bss->freq);
1613 return false;
1614 }
1615#endif /* CONFIG_OWE */
Hai Shalom899fcc72020-10-19 14:38:18 -07001616 if (debug_print)
1617 wpa_dbg(wpa_s, MSG_DEBUG,
1618 " skip - no SSID known for the BSS");
1619 return false;
1620 }
1621
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001622 if (!wpas_valid_ml_bss(wpa_s, bss)) {
1623 if (debug_print)
1624 wpa_dbg(wpa_s, MSG_DEBUG,
1625 " skip - ML BSS going to be removed");
1626 return false;
1627 }
1628
Hai Shalom899fcc72020-10-19 14:38:18 -07001629 /* Matching configuration found */
1630 return true;
1631}
1632
1633
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001634struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1635 int i, struct wpa_bss *bss,
1636 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001637 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001638{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001639 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001640 const u8 *ie;
1641 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001642 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001643 const u8 *match_ssid;
1644 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001645 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001646
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001647 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001648 wpa_ie_len = ie ? ie[1] : 0;
1649
Sunil Ravi7f769292024-07-23 22:21:32 +00001650 ie = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001651 rsn_ie_len = ie ? ie[1] : 0;
1652
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001653 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1654 osen = ie != NULL;
1655
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001656 if (debug_print) {
1657 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1658 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1659 i, MAC2STR(bss->bssid),
1660 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1661 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1662 bss->freq,
1663 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1664 " wps" : "",
1665 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1666 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1667 ? " p2p" : "",
1668 osen ? " osen=1" : "");
1669 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001670
Hai Shalom60840252021-02-19 19:02:11 -08001671 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1672 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001673 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001674 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675 /*
1676 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001677 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001678 * should not be done with multiple enabled networks to
1679 * avoid getting forced to move into a worse ESS on
1680 * single error if there are no other BSSes of the
1681 * current ESS.
1682 */
1683 limit = 0;
1684 }
Hai Shalom60840252021-02-19 19:02:11 -08001685 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001686 if (debug_print) {
1687 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001688 " skip - BSSID ignored (count=%d limit=%d)",
1689 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001690 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001691 return NULL;
1692 }
1693 }
1694
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001695 match_ssid = bss->ssid;
1696 match_ssid_len = bss->ssid_len;
1697 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1698
1699 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001700 if (debug_print)
1701 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001702 return NULL;
1703 }
1704
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001705 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001706 if (debug_print)
1707 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001708 return NULL;
1709 }
1710
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001711 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001712 if (debug_print)
1713 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001714 return NULL;
1715 }
1716
Hai Shalomfdcde762020-04-02 11:19:20 -07001717 if (disabled_freq(wpa_s, bss->freq)) {
1718 if (debug_print)
1719 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1720 return NULL;
1721 }
1722
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001723 if (wnm_is_bss_excluded(wpa_s, bss)) {
1724 if (debug_print)
1725 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID excluded");
1726 return NULL;
1727 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001728
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001729 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001730 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001731 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001732 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001733 }
1734
1735 /* No matching configuration found */
1736 return NULL;
1737}
1738
1739
1740static struct wpa_bss *
1741wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001742 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001743 struct wpa_ssid **selected_ssid,
1744 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001745{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001746 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001747
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001748 if (wpa_s->current_ssid) {
1749 struct wpa_ssid *ssid;
1750
1751 wpa_dbg(wpa_s, MSG_DEBUG,
1752 "Scan results matching the currently selected network");
1753 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1754 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1755
1756 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1757 only_first_ssid, 0);
1758 if (ssid != wpa_s->current_ssid)
1759 continue;
1760 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1761 " freq=%d level=%d snr=%d est_throughput=%u",
1762 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1763 bss->snr, bss->est_throughput);
1764 }
1765 }
1766
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001767 if (only_first_ssid)
1768 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1769 group->id);
1770 else
1771 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1772 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001773
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001774 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1775 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001776
1777 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001778 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001779 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001780 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001781 if (!*selected_ssid)
1782 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001783 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001784 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001785 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001786 MAC2STR(bss->bssid),
1787 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1788 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001789 }
1790
1791 return NULL;
1792}
1793
1794
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001795struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1796 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797{
1798 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001799 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001800 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001801 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001802
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001803 if (wpa_s->last_scan_res == NULL ||
1804 wpa_s->last_scan_res_used == 0)
1805 return NULL; /* no scan results from last update */
1806
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001807 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001808 /* check that next_ssid is still valid */
1809 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1810 if (ssid == wpa_s->next_ssid)
1811 break;
1812 }
1813 next_ssid = ssid;
1814 wpa_s->next_ssid = NULL;
1815 }
1816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001818 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1819 if (next_ssid && next_ssid->priority ==
1820 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001821 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001822 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001823 if (selected)
1824 break;
1825 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001826 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001827 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001828 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001829 if (selected)
1830 break;
1831 }
1832
Sunil Ravi99c035e2024-07-12 01:42:03 +00001833 if (!selected &&
1834 (wpa_s->bssid_ignore || wnm_active_bss_trans_mgmt(wpa_s)) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001835 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001836 wpa_dbg(wpa_s, MSG_DEBUG,
1837 "No APs found - clear BSSID ignore list and try again");
Sunil Ravi99c035e2024-07-12 01:42:03 +00001838 wnm_btm_reset(wpa_s);
Hai Shalom60840252021-02-19 19:02:11 -08001839 wpa_bssid_ignore_clear(wpa_s);
1840 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 } else if (selected == NULL)
1842 break;
1843 }
1844
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001845 ssid = *selected_ssid;
1846 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1847 !ssid->passphrase && !ssid->ext_psk) {
1848 const char *field_name, *txt = NULL;
1849
1850 wpa_dbg(wpa_s, MSG_DEBUG,
1851 "PSK/passphrase not yet available for the selected network");
1852
1853 wpas_notify_network_request(wpa_s, ssid,
1854 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1855
1856 field_name = wpa_supplicant_ctrl_req_to_string(
1857 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1858 if (field_name == NULL)
1859 return NULL;
1860
1861 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1862
1863 selected = NULL;
1864 }
1865
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001866 return selected;
1867}
1868
1869
1870static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1871 int timeout_sec, int timeout_usec)
1872{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001873 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874 /*
1875 * No networks are enabled; short-circuit request so
1876 * we don't wait timeout seconds before transitioning
1877 * to INACTIVE state.
1878 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001879 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1880 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001881 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1882 return;
1883 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001884
1885 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001886 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1887}
1888
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001889
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001890static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s)
1891{
1892 if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss)
1893 return false;
1894
1895 wpa_msg(wpa_s, MSG_DEBUG,
1896 "Request association with " MACSTR " after ML probe",
1897 MAC2STR(wpa_s->ml_connect_probe_bss->bssid));
1898
1899 wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss,
1900 wpa_s->ml_connect_probe_ssid);
1901
1902 wpa_s->ml_connect_probe_ssid = NULL;
1903 wpa_s->ml_connect_probe_bss = NULL;
1904
1905 return true;
1906}
1907
1908
1909static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s,
1910 struct wpa_bss *selected,
1911 struct wpa_ssid *ssid)
1912{
1913 int *freqs;
1914 u16 missing_links = 0, removed_links;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001915 u8 ap_mld_id;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001916
1917 if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
1918 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)))
1919 return 0;
1920
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001921 if (wpa_bss_parse_basic_ml_element(wpa_s, selected, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001922 &missing_links, ssid,
1923 &ap_mld_id) ||
1924 !missing_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001925 return 0;
1926
1927 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected);
1928 missing_links &= ~removed_links;
1929
1930 if (!missing_links)
1931 return 0;
1932
1933 wpa_dbg(wpa_s, MSG_DEBUG,
1934 "MLD: Doing an ML probe for missing links 0x%04x",
1935 missing_links);
1936
1937 freqs = os_malloc(sizeof(int) * 2);
1938 if (!freqs)
1939 return 0;
1940
1941 wpa_s->ml_connect_probe_ssid = ssid;
1942 wpa_s->ml_connect_probe_bss = selected;
1943
1944 freqs[0] = selected->freq;
1945 freqs[1] = 0;
1946
1947 wpa_s->manual_scan_passive = 0;
1948 wpa_s->manual_scan_use_id = 0;
1949 wpa_s->manual_scan_only_new = 0;
1950 wpa_s->scan_id_count = 0;
1951 os_free(wpa_s->manual_scan_freqs);
1952 wpa_s->manual_scan_freqs = freqs;
1953
1954 os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001955
1956 /*
1957 * In case the ML probe request is intended to retrieve information from
1958 * the transmitted BSS, the AP MLD ID should be included and should be
1959 * set to zero.
1960 * In case the ML probe requested is intended to retrieve information
1961 * from a non-transmitted BSS, the AP MLD ID should not be included.
1962 */
1963 if (ap_mld_id)
1964 wpa_s->ml_probe_mld_id = -1;
1965 else
1966 wpa_s->ml_probe_mld_id = 0;
1967
1968 if (ssid && ssid->ssid_len) {
1969 os_free(wpa_s->ssids_from_scan_req);
1970 wpa_s->num_ssids_from_scan_req = 0;
1971
1972 wpa_s->ssids_from_scan_req =
1973 os_zalloc(sizeof(struct wpa_ssid_value));
1974 if (wpa_s->ssids_from_scan_req) {
1975 wpa_printf(MSG_DEBUG,
1976 "MLD: ML probe: With direct SSID");
1977
1978 wpa_s->num_ssids_from_scan_req = 1;
1979 wpa_s->ssids_from_scan_req[0].ssid_len = ssid->ssid_len;
1980 os_memcpy(wpa_s->ssids_from_scan_req[0].ssid,
1981 ssid->ssid, ssid->ssid_len);
1982 }
1983 }
1984
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001985 wpa_s->ml_probe_links = missing_links;
1986
1987 wpa_s->normal_scans = 0;
1988 wpa_s->scan_req = MANUAL_SCAN_REQ;
1989 wpa_s->after_wps = 0;
1990 wpa_s->known_wps_freq = 0;
1991 wpa_supplicant_req_scan(wpa_s, 0, 0);
1992
1993 return 1;
1994}
1995
1996
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001997int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001998 struct wpa_bss *selected,
1999 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002000{
Sunil Ravi640215c2023-06-28 23:08:09 +00002001#ifdef IEEE8021X_EAPOL
Sunil Ravi036cec52023-03-29 11:35:17 -07002002 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
2003 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00002004 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002005 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
2006 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07002007 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002008 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002009#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002010 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
2011 wpa_s->p2p_in_provisioning) {
2012 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
2013 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002014 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002015 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002016#endif /* CONFIG_P2P */
2017
2018#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002019 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002020 wpas_wps_cancel(wpa_s);
2021#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002022 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002023 }
Sunil Ravi640215c2023-06-28 23:08:09 +00002024#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002026 wpa_msg(wpa_s, MSG_DEBUG,
2027 "Considering connect request: reassociate: %d selected: "
2028 MACSTR " bssid: " MACSTR " pending: " MACSTR
2029 " wpa_state: %s ssid=%p current_ssid=%p",
2030 wpa_s->reassociate, MAC2STR(selected->bssid),
2031 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
2032 wpa_supplicant_state_txt(wpa_s->wpa_state),
2033 ssid, wpa_s->current_ssid);
2034
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002035 /*
2036 * Do not trigger new association unless the BSSID has changed or if
2037 * reassociation is requested. If we are in process of associating with
2038 * the selected BSSID, do not trigger new attempt.
2039 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002040 if (wpa_s->reassociate ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002041 (!ether_addr_equal(selected->bssid, wpa_s->bssid) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002042 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
2043 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002044 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002045 !ether_addr_equal(selected->bssid, wpa_s->pending_bssid)) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002046 (is_zero_ether_addr(wpa_s->pending_bssid) &&
2047 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002048 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
2049 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002050 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002051 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002052
2053 if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid))
2054 return 0;
2055
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002056 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
2057 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002058 wpa_supplicant_associate(wpa_s, selected, ssid);
2059 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002060 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
2061 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002062 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002063
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002064 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002065}
2066
2067
2068static struct wpa_ssid *
2069wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
2070{
Hai Shalomfdcde762020-04-02 11:19:20 -07002071 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002072 struct wpa_ssid *ssid;
2073
2074 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
2075 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
2076 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002077 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002078 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002079#ifndef CONFIG_IBSS_RSN
2080 if (ssid->mode == WPAS_MODE_IBSS &&
2081 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
2082 WPA_KEY_MGMT_WPA_NONE))) {
2083 wpa_msg(wpa_s, MSG_INFO,
2084 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
2085 wpa_ssid_txt(ssid->ssid,
2086 ssid->ssid_len));
2087 continue;
2088 }
2089#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07002090 if (ssid->mode == WPAS_MODE_IBSS ||
2091 ssid->mode == WPAS_MODE_AP ||
2092 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002093 return ssid;
2094 }
2095 }
2096 return NULL;
2097}
2098
2099
2100/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
2101 * on BSS added and BSS changed events */
2102static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03002103 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002104{
Jouni Malinen87fd2792011-05-16 18:35:42 +03002105 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002106
2107 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
2108 return;
2109
Jouni Malinen87fd2792011-05-16 18:35:42 +03002110 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002111 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002112
Jouni Malinen87fd2792011-05-16 18:35:42 +03002113 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002114 if (ssid == NULL)
2115 continue;
2116
Sunil Ravi7f769292024-07-23 22:21:32 +00002117 rsn = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002118 if (rsn == NULL)
2119 continue;
2120
Jouni Malinen87fd2792011-05-16 18:35:42 +03002121 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002122 }
2123
2124}
2125
2126
Hai Shalomfdcde762020-04-02 11:19:20 -07002127#ifndef CONFIG_NO_ROAMING
2128
2129static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
2130{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002131 if (noise == WPA_INVALID_NOISE) {
2132 if (IS_5GHZ(frequency)) {
2133 noise = DEFAULT_NOISE_FLOOR_5GHZ;
2134 } else if (is_6ghz_freq(frequency)) {
2135 noise = DEFAULT_NOISE_FLOOR_6GHZ;
2136 } else {
2137 noise = DEFAULT_NOISE_FLOOR_2GHZ;
2138 }
2139 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002140 return avg_signal - noise;
2141}
2142
2143
2144static unsigned int
2145wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
2146 const struct wpa_bss *bss, int snr)
2147{
2148 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08002149 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07002150 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002151 enum chan_width max_cw = CHAN_WIDTH_UNKNOWN;
Hai Shalomfdcde762020-04-02 11:19:20 -07002152
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002153 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq,
2154 &max_cw);
Hai Shalomfdcde762020-04-02 11:19:20 -07002155}
2156
Hai Shalomfdcde762020-04-02 11:19:20 -07002157
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002158static int wpas_evaluate_band_score(int frequency)
2159{
2160 if (is_6ghz_freq(frequency))
2161 return 2;
2162 if (IS_5GHZ(frequency))
2163 return 1;
2164 return 0;
2165}
2166
2167
Hai Shalom899fcc72020-10-19 14:38:18 -07002168int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
2169 struct wpa_bss *current_bss,
2170 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002171{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002172 int min_diff, diff;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002173 int cur_band_score, sel_band_score;
Sunil Ravi036cec52023-03-29 11:35:17 -07002174 int to_5ghz, to_6ghz;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002175 int cur_level, sel_level;
Hai Shalomfdcde762020-04-02 11:19:20 -07002176 unsigned int cur_est, sel_est;
2177 struct wpa_signal_info si;
2178 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07002179 int ret = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002180 const u8 *cur_ies = wpa_bss_ie_ptr(current_bss);
2181 const u8 *sel_ies = wpa_bss_ie_ptr(selected);
2182 size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len :
2183 current_bss->beacon_ie_len;
2184 size_t sel_ie_len = selected->ie_len ? selected->ie_len :
2185 selected->beacon_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002187 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002188 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002189 " freq=%d level=%d snr=%d est_throughput=%u",
2190 MAC2STR(current_bss->bssid),
2191 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002192 current_bss->snr, current_bss->est_throughput);
2193 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002194 " freq=%d level=%d snr=%d est_throughput=%u",
2195 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002196 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002197
Sunil Ravi7f769292024-07-23 22:21:32 +00002198 if (wpas_ap_link_address(wpa_s, selected->bssid)) {
2199 wpa_dbg(wpa_s, MSG_DEBUG, "MLD: associated to selected BSS");
2200 return 0;
2201 }
2202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002203 if (wpa_s->current_ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002204 ether_addr_equal(selected->bssid, wpa_s->current_ssid->bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002205 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2206 "has preferred BSSID");
2207 return 1;
2208 }
2209
Hai Shalomfdcde762020-04-02 11:19:20 -07002210 /*
2211 * Try to poll the signal from the driver since this will allow to get
2212 * more accurate values. In some cases, there can be big differences
2213 * between the RSSI of the Probe Response frames of the AP we are
2214 * associated with and the Beacon frames we hear from the same AP after
2215 * association. This can happen, e.g., when there are two antennas that
2216 * hear the AP very differently. If the driver chooses to hear the
2217 * Probe Response frames during the scan on the "bad" antenna because
2218 * it wants to save power, but knows to choose the other antenna after
2219 * association, we will hear our AP with a low RSSI as part of the
2220 * scan even when we can hear it decently on the other antenna. To cope
2221 * with this, ask the driver to teach us how it hears the AP. Also, the
2222 * scan results may be a bit old, since we can very quickly get fresh
2223 * information about our currently associated AP.
2224 */
2225 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002226 (si.data.avg_beacon_signal || si.data.avg_signal)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002227 /*
2228 * Normalize avg_signal to the RSSI over 20 MHz, as the
2229 * throughput is estimated based on the RSSI over 20 MHz
2230 */
Sunil Ravi77d572f2023-01-17 23:58:31 +00002231 cur_level = si.data.avg_beacon_signal ?
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002232 si.data.avg_beacon_signal :
2233 (si.data.avg_signal -
2234 wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2235 si.chanwidth));
Hai Shalomfdcde762020-04-02 11:19:20 -07002236 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2237 si.current_noise);
2238
2239 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2240 current_bss,
2241 cur_snr);
2242 wpa_dbg(wpa_s, MSG_DEBUG,
2243 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2244 cur_level, cur_snr, cur_est);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002245 } else {
2246 /* Level and SNR are measured over 20 MHz channel */
2247 cur_level = current_bss->level;
2248 cur_snr = current_bss->snr;
2249 cur_est = current_bss->est_throughput;
Hai Shalomfdcde762020-04-02 11:19:20 -07002250 }
2251
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002252 /* Adjust the SNR of BSSes based on the channel width. */
2253 cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2254 current_bss->max_cw);
2255 cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len,
2256 current_bss->max_cw, cur_snr);
2257
2258 sel_est = selected->est_throughput;
2259 sel_level = selected->level +
2260 wpas_channel_width_rssi_bump(sel_ies, sel_ie_len,
2261 selected->max_cw);
2262
Hai Shalomfdcde762020-04-02 11:19:20 -07002263 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002264 wpa_dbg(wpa_s, MSG_DEBUG,
2265 "Allow reassociation - selected BSS has better estimated throughput");
2266 return 1;
2267 }
2268
Dmitry Shmidte4663042016-04-04 10:07:49 -07002269 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
Sunil Ravi036cec52023-03-29 11:35:17 -07002270 to_6ghz = is_6ghz_freq(selected->freq) &&
2271 !is_6ghz_freq(current_bss->freq);
Dmitry Shmidte4663042016-04-04 10:07:49 -07002272
Sunil Ravi036cec52023-03-29 11:35:17 -07002273 if (cur_level < 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002274 cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002275 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002276 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2277 "signal level");
2278 return 0;
2279 }
2280
Hai Shalomfdcde762020-04-02 11:19:20 -07002281 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002282 wpa_dbg(wpa_s, MSG_DEBUG,
2283 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002284 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002285 }
2286
Hai Shalomfdcde762020-04-02 11:19:20 -07002287 if (cur_snr > GREAT_SNR) {
2288 wpa_dbg(wpa_s, MSG_DEBUG,
2289 "Skip roam - Current BSS has good SNR (%u > %u)",
2290 cur_snr, GREAT_SNR);
2291 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002292 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002293
Hai Shalomfdcde762020-04-02 11:19:20 -07002294 if (cur_level < -85) /* ..-86 dBm */
2295 min_diff = 1;
2296 else if (cur_level < -80) /* -85..-81 dBm */
2297 min_diff = 2;
2298 else if (cur_level < -75) /* -80..-76 dBm */
2299 min_diff = 3;
2300 else if (cur_level < -70) /* -75..-71 dBm */
2301 min_diff = 4;
2302 else if (cur_level < 0) /* -70..-1 dBm */
2303 min_diff = 5;
2304 else /* unspecified units (not in dBm) */
2305 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002306
Hai Shalomfdcde762020-04-02 11:19:20 -07002307 if (cur_est > sel_est * 1.5)
2308 min_diff += 10;
2309 else if (cur_est > sel_est * 1.2)
2310 min_diff += 5;
2311 else if (cur_est > sel_est * 1.1)
2312 min_diff += 2;
2313 else if (cur_est > sel_est)
2314 min_diff++;
2315 else if (sel_est > cur_est * 1.5)
2316 min_diff -= 10;
2317 else if (sel_est > cur_est * 1.2)
2318 min_diff -= 5;
2319 else if (sel_est > cur_est * 1.1)
2320 min_diff -= 2;
2321 else if (sel_est > cur_est)
2322 min_diff--;
2323
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002324 cur_band_score = wpas_evaluate_band_score(current_bss->freq);
2325 sel_band_score = wpas_evaluate_band_score(selected->freq);
2326 min_diff += (cur_band_score - sel_band_score) * 2;
2327 if (wpa_s->signal_threshold && cur_level <= wpa_s->signal_threshold &&
2328 sel_level > wpa_s->signal_threshold)
Sunil Ravi036cec52023-03-29 11:35:17 -07002329 min_diff -= 2;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002330 diff = sel_level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002331 if (diff < min_diff) {
2332 wpa_dbg(wpa_s, MSG_DEBUG,
2333 "Skip roam - too small difference in signal level (%d < %d)",
2334 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002335 ret = 0;
2336 } else {
2337 wpa_dbg(wpa_s, MSG_DEBUG,
2338 "Allow reassociation due to difference in signal level (%d >= %d)",
2339 diff, min_diff);
2340 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002341 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002342 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2343 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2344 " sel_freq=%d sel_level=%d sel_est=%d",
2345 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2346 MAC2STR(current_bss->bssid),
2347 current_bss->freq, cur_level, cur_est,
2348 MAC2STR(selected->bssid),
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002349 selected->freq, sel_level, sel_est);
Hai Shalom899fcc72020-10-19 14:38:18 -07002350 return ret;
2351}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002352
Hai Shalom899fcc72020-10-19 14:38:18 -07002353#endif /* CONFIG_NO_ROAMING */
2354
2355
2356static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2357 struct wpa_bss *selected,
2358 struct wpa_ssid *ssid)
2359{
2360 struct wpa_bss *current_bss = NULL;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002361 const u8 *bssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07002362
2363 if (wpa_s->reassociate)
2364 return 1; /* explicit request to reassociate */
2365 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2366 return 1; /* we are not associated; continue */
2367 if (wpa_s->current_ssid == NULL)
2368 return 1; /* unknown current SSID */
2369 if (wpa_s->current_ssid != ssid)
2370 return 1; /* different network block */
2371
2372 if (wpas_driver_bss_selection(wpa_s))
2373 return 0; /* Driver-based roaming */
2374
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002375 if (wpa_s->valid_links)
2376 bssid = wpa_s->links[wpa_s->mlo_assoc_link_id].bssid;
2377 else
2378 bssid = wpa_s->bssid;
2379
Hai Shalom899fcc72020-10-19 14:38:18 -07002380 if (wpa_s->current_ssid->ssid)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002381 current_bss = wpa_bss_get(wpa_s, bssid,
Hai Shalom899fcc72020-10-19 14:38:18 -07002382 wpa_s->current_ssid->ssid,
2383 wpa_s->current_ssid->ssid_len);
2384 if (!current_bss)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002385 current_bss = wpa_bss_get_bssid(wpa_s, bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07002386
2387 if (!current_bss)
2388 return 1; /* current BSS not seen in scan results */
2389
2390 if (current_bss == selected)
2391 return 0;
2392
2393 if (selected->last_update_idx > current_bss->last_update_idx)
2394 return 1; /* current BSS not seen in the last scan */
2395
2396#ifndef CONFIG_NO_ROAMING
2397 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2398 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002399#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002400 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002401#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002402}
2403
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002404
Sunil Ravic0f5d412024-09-11 22:12:49 +00002405static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s,
2406 union wpa_event_data *data)
2407{
2408 struct wpa_driver_scan_params params;
2409 unsigned int j;
2410
2411 wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan");
2412 os_memset(&params, 0, sizeof(params));
2413 params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz;
2414 for (j = 0; j < data->scan_info.num_ssids; j++)
2415 params.ssids[j] = data->scan_info.ssids[j];
2416 params.num_ssids = data->scan_info.num_ssids;
2417 wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
2418 true, false, false);
2419 if (!wpa_supplicant_trigger_scan(wpa_s, &params, true, true)) {
2420 wpa_s->scan_in_progress_6ghz = true;
2421 wpas_notify_scan_in_progress_6ghz(wpa_s);
2422 os_free(params.freqs);
2423 return 1;
2424 }
2425 wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan");
2426 os_free(params.freqs);
2427 return 0;
2428}
2429
2430
2431static bool wpas_short_ssid_match(struct wpa_supplicant *wpa_s,
2432 struct wpa_scan_results *scan_res)
2433{
2434 size_t i;
2435 struct wpa_ssid *ssid = wpa_s->current_ssid;
2436 u32 current_ssid_short = ieee80211_crc32(ssid->ssid, ssid->ssid_len);
2437
2438 for (i = 0; i < scan_res->num; i++) {
2439 struct wpa_scan_res *res = scan_res->res[i];
2440 const u8 *rnr_ie, *ie_end;
2441 const struct ieee80211_neighbor_ap_info *info;
2442 size_t left;
2443
2444 rnr_ie = wpa_scan_get_ie(res, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
2445 if (!rnr_ie)
2446 continue;
2447
2448 ie_end = rnr_ie + 2 + rnr_ie[1];
2449 rnr_ie += 2;
2450
2451 left = ie_end - rnr_ie;
2452 if (left < sizeof(struct ieee80211_neighbor_ap_info))
2453 continue;
2454
2455 info = (const struct ieee80211_neighbor_ap_info *) rnr_ie;
2456 if (info->tbtt_info_len < 11)
2457 continue; /* short SSID not included */
2458 left -= sizeof(struct ieee80211_neighbor_ap_info);
2459 rnr_ie += sizeof(struct ieee80211_neighbor_ap_info);
2460
2461 while (left >= info->tbtt_info_len && rnr_ie + 11 <= ie_end) {
2462 /* Skip TBTT offset and BSSID */
2463 u32 short_ssid = WPA_GET_LE32(rnr_ie + 1 + ETH_ALEN);
2464
2465 if (short_ssid == current_ssid_short)
2466 return true;
2467
2468 left -= info->tbtt_info_len;
2469 rnr_ie += info->tbtt_info_len;
2470 }
2471 }
2472
2473 return false;
2474}
2475
2476
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002477/*
2478 * Return a negative value if no scan results could be fetched or if scan
2479 * results should not be shared with other virtual interfaces.
2480 * Return 0 if scan results were fetched and may be shared with other
2481 * interfaces.
2482 * Return 1 if scan results may be shared with other virtual interfaces but may
2483 * not trigger any operations.
2484 * Return 2 if the interface was removed and cannot be used.
2485 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002486static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002487 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002488 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002489{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002490 struct wpa_scan_results *scan_res = NULL;
2491 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002492 int ap = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002493 bool trigger_6ghz_scan;
Sunil Ravic0f5d412024-09-11 22:12:49 +00002494 bool short_ssid_match_found = false;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002495#ifndef CONFIG_NO_RANDOM_POOL
2496 size_t i, num;
2497#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002498
2499#ifdef CONFIG_AP
2500 if (wpa_s->ap_iface)
2501 ap = 1;
2502#endif /* CONFIG_AP */
2503
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002504 trigger_6ghz_scan = wpa_s->crossed_6ghz_dom &&
2505 wpa_s->last_scan_all_chan;
2506 wpa_s->crossed_6ghz_dom = false;
2507 wpa_s->last_scan_all_chan = false;
2508
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002509 wpa_supplicant_notify_scanning(wpa_s, 0);
2510
2511 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2512 data ? &data->scan_info :
Sunil Ravi99c035e2024-07-12 01:42:03 +00002513 NULL, 1, NULL);
Sunil Ravic0f5d412024-09-11 22:12:49 +00002514
2515 if (wpa_s->scan_in_progress_6ghz) {
2516 wpa_s->scan_in_progress_6ghz = false;
2517 wpas_notify_scan_in_progress_6ghz(wpa_s);
2518 }
2519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002520 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002521 if (wpa_s->conf->ap_scan == 2 || ap ||
2522 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002523 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002524 if (!own_request)
2525 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002526 if (data && data->scan_info.external_scan)
2527 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002528 if (wpa_s->scan_res_fail_handler) {
2529 void (*handler)(struct wpa_supplicant *wpa_s);
2530
2531 handler = wpa_s->scan_res_fail_handler;
2532 wpa_s->scan_res_fail_handler = NULL;
2533 handler(wpa_s);
2534 } else {
2535 wpa_dbg(wpa_s, MSG_DEBUG,
2536 "Failed to get scan results - try scanning again");
2537 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2538 }
2539
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002540 ret = -1;
2541 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002542 }
2543
2544#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002545 num = scan_res->num;
2546 if (num > 10)
2547 num = 10;
2548 for (i = 0; i < num; i++) {
2549 u8 buf[5];
2550 struct wpa_scan_res *res = scan_res->res[i];
2551 buf[0] = res->bssid[5];
2552 buf[1] = res->qual & 0xff;
2553 buf[2] = res->noise & 0xff;
2554 buf[3] = res->level & 0xff;
2555 buf[4] = res->tsf & 0xff;
2556 random_add_randomness(buf, sizeof(buf));
2557 }
2558#endif /* CONFIG_NO_RANDOM_POOL */
2559
Sunil Ravi7f769292024-07-23 22:21:32 +00002560 wpa_s->last_scan_external = data && data->scan_info.external_scan;
2561
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002562 if (update_only) {
2563 ret = 1;
2564 goto scan_work_done;
2565 }
2566
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002567 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002568 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002569 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2570 struct wpa_scan_results *scan_res);
2571
2572 scan_res_handler = wpa_s->scan_res_handler;
2573 wpa_s->scan_res_handler = NULL;
2574 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002575 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002576 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002577 }
2578
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002579 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002580 wpa_s->own_scan_running,
2581 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002582 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002583 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2584 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002585 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2586 wpa_s->manual_scan_id);
2587 wpa_s->manual_scan_use_id = 0;
2588 } else {
2589 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2590 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002591 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002592
2593 wpas_notify_scan_done(wpa_s, 1);
2594
Hai Shalomfdcde762020-04-02 11:19:20 -07002595 if (ap) {
2596 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2597#ifdef CONFIG_AP
2598 if (wpa_s->ap_iface->scan_cb)
2599 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2600#endif /* CONFIG_AP */
2601 goto scan_work_done;
2602 }
2603
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002604 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002605 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
Dmitry Shmidt04949592012-07-19 12:16:46 -07002606 wpa_scan_results_free(scan_res);
2607 return 0;
2608 }
2609
Hai Shalomc1a21442022-02-04 13:43:00 -08002610 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002611 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002612
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002613#ifndef CONFIG_NO_RRM
Hai Shalom021b0b52019-04-10 11:17:58 -07002614 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002615 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2616 goto scan_work_done;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002617#endif /* CONFIG_NO_RRM */
Dmitry Shmidt29333592017-01-09 12:27:11 -08002618
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002619 if (ml_link_probe_scan(wpa_s))
2620 goto scan_work_done;
2621
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002622 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2623 goto scan_work_done;
2624
2625 if (autoscan_notify_scan(wpa_s, scan_res))
2626 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002627
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002628 if (wpa_s->disconnected) {
2629 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002630 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002631 }
2632
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002633 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002634 bgscan_notify_scan(wpa_s, scan_res) == 1)
2635 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002636
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002637 wpas_wps_update_ap_info(wpa_s, scan_res);
2638
Sunil Ravic0f5d412024-09-11 22:12:49 +00002639 if (wnm_scan_process(wpa_s, false) > 0)
2640 goto scan_work_done;
2641
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002642 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2643 wpa_s->wpa_state < WPA_COMPLETED)
2644 goto scan_work_done;
2645
Sunil Ravic0f5d412024-09-11 22:12:49 +00002646 if (wpa_s->current_ssid && trigger_6ghz_scan && own_request && data &&
2647 wpas_short_ssid_match(wpa_s, scan_res)) {
2648 wpa_dbg(wpa_s, MSG_INFO, "Short SSID match in scan results");
2649 short_ssid_match_found = true;
2650 }
2651
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002652 wpa_scan_results_free(scan_res);
2653
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002654 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002655 struct wpa_radio_work *work = wpa_s->scan_work;
2656 wpa_s->scan_work = NULL;
2657 radio_work_done(work);
2658 }
2659
Hai Shalomc3565922019-10-28 11:58:20 -07002660 os_free(wpa_s->last_scan_freqs);
2661 wpa_s->last_scan_freqs = NULL;
2662 wpa_s->num_last_scan_freqs = 0;
2663 if (own_request && data &&
2664 data->scan_info.freqs && data->scan_info.num_freqs) {
2665 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2666 data->scan_info.num_freqs);
2667 if (wpa_s->last_scan_freqs) {
2668 os_memcpy(wpa_s->last_scan_freqs,
2669 data->scan_info.freqs,
2670 sizeof(int) * data->scan_info.num_freqs);
2671 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2672 }
2673 }
2674
Sunil Ravi77d572f2023-01-17 23:58:31 +00002675 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2676 return ret;
2677
Sunil Ravic0f5d412024-09-11 22:12:49 +00002678 if (short_ssid_match_found && wpas_trigger_6ghz_scan(wpa_s, data) > 0)
2679 return 1;
2680
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002681 return wpas_select_network_from_last_scan(wpa_s, 1, own_request,
2682 trigger_6ghz_scan, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002683
2684scan_work_done:
2685 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002686 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002687 struct wpa_radio_work *work = wpa_s->scan_work;
2688 wpa_s->scan_work = NULL;
2689 radio_work_done(work);
2690 }
2691 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002692}
2693
2694
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002695/**
2696 * Select a network from the last scan
2697 * @wpa_s: Pointer to wpa_supplicant data
2698 * @new_scan: Whether this function was called right after a scan has finished
2699 * @own_request: Whether the scan was requested by this interface
2700 * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable
2701 * @data: Scan data from scan that finished if applicable
2702 *
2703 * See _wpa_supplicant_event_scan_results() for return values.
2704 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002705static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002706 int new_scan, int own_request,
2707 bool trigger_6ghz_scan,
2708 union wpa_event_data *data)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002709{
2710 struct wpa_bss *selected;
2711 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002712 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2713
2714 if (time_to_reenable > 0) {
2715 wpa_dbg(wpa_s, MSG_DEBUG,
2716 "Postpone network selection by %d seconds since all networks are disabled",
2717 time_to_reenable);
2718 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2719 eloop_register_timeout(time_to_reenable, 0,
2720 wpas_network_reenabled, wpa_s, NULL);
2721 return 0;
2722 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002723
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002724 if (wpa_s->p2p_mgmt)
2725 return 0; /* no normal connection on p2p_mgmt interface */
2726
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002727 wpa_s->owe_transition_search = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002728#ifdef CONFIG_OWE
2729 os_free(wpa_s->owe_trans_scan_freq);
2730 wpa_s->owe_trans_scan_freq = NULL;
2731#endif /* CONFIG_OWE */
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002732 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002734#ifdef CONFIG_MESH
2735 if (wpa_s->ifmsh) {
2736 wpa_msg(wpa_s, MSG_INFO,
2737 "Avoiding join because we already joined a mesh group");
2738 return 0;
2739 }
2740#endif /* CONFIG_MESH */
2741
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002742 if (selected) {
2743 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002744 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002745 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002746 if (new_scan)
2747 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002749 }
2750
Hai Shalomc3565922019-10-28 11:58:20 -07002751 wpa_s->suitable_network++;
2752
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002753 if (ssid != wpa_s->current_ssid &&
2754 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2755 wpa_s->own_disconnect_req = 1;
2756 wpa_supplicant_deauthenticate(
2757 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2758 }
2759
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002760 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002761 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002762 return -1;
2763 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002764 wpa_s->supp_pbc_active = false;
2765
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002766 if (new_scan)
2767 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002768 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002769 * Do not allow other virtual radios to trigger operations based
2770 * on these scan results since we do not want them to start
2771 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002772 */
2773 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002774 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002775 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2777 ssid = wpa_supplicant_pick_new_network(wpa_s);
2778 if (ssid) {
2779 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2780 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002781 if (new_scan)
2782 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002783 } else if (own_request) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002784 if (wpa_s->support_6ghz && trigger_6ghz_scan && data &&
Sunil Ravic0f5d412024-09-11 22:12:49 +00002785 wpas_trigger_6ghz_scan(wpa_s, data) > 0)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002786 return 1;
2787
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002788 /*
2789 * No SSID found. If SCAN results are as a result of
2790 * own scan request and not due to a scan request on
2791 * another shared interface, try another scan.
2792 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002793 int timeout_sec = wpa_s->scan_interval;
2794 int timeout_usec = 0;
2795#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002796 int res;
2797
2798 res = wpas_p2p_scan_no_go_seen(wpa_s);
2799 if (res == 2)
2800 return 2;
2801 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002802 return 0;
2803
Sunil Ravi77d572f2023-01-17 23:58:31 +00002804 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002805 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002806
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002807 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002808 wpa_s->show_group_started ||
2809 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002810 /*
2811 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002812 * state and during P2P join-a-group operation
2813 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002814 */
2815 timeout_sec = 0;
2816 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002817 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2818 timeout_usec);
2819 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002820 }
2821#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002822#ifdef CONFIG_INTERWORKING
2823 if (wpa_s->conf->auto_interworking &&
2824 wpa_s->conf->interworking &&
2825 wpa_s->conf->cred) {
2826 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2827 "start ANQP fetch since no matching "
2828 "networks found");
2829 wpa_s->network_select = 1;
2830 wpa_s->auto_network_select = 1;
2831 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002832 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002833 }
2834#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002835#ifdef CONFIG_WPS
2836 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2837 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2838 timeout_sec = 0;
2839 timeout_usec = 500000;
2840 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2841 timeout_usec);
2842 return 0;
2843 }
2844#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002845#ifdef CONFIG_OWE
2846 if (wpa_s->owe_transition_search) {
2847 wpa_dbg(wpa_s, MSG_DEBUG,
2848 "OWE: Use shorter wait during transition mode search");
2849 timeout_sec = 0;
2850 timeout_usec = 500000;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002851 if (wpa_s->owe_trans_scan_freq) {
2852 os_free(wpa_s->next_scan_freqs);
2853 wpa_s->next_scan_freqs =
2854 wpa_s->owe_trans_scan_freq;
2855 wpa_s->owe_trans_scan_freq = NULL;
2856 timeout_usec = 100000;
2857 }
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002858 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2859 timeout_usec);
2860 return 0;
2861 }
2862#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002863 if (wpa_supplicant_req_sched_scan(wpa_s))
2864 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2865 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002866
2867 wpa_msg_ctrl(wpa_s, MSG_INFO,
2868 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002869 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002870 }
2871 }
2872 return 0;
2873}
2874
2875
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002876static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2877 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002879 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002880 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002881
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002882 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002883 if (res == 2) {
2884 /*
2885 * Interface may have been removed, so must not dereference
2886 * wpa_s after this.
2887 */
2888 return 1;
2889 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002890
2891 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002892 /*
2893 * If no scan results could be fetched, then no need to
2894 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002895 * this scan. Similarly, if scan results started a new operation on this
2896 * interface, do not notify other interfaces to avoid concurrent
2897 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002898 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002899 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002900 }
2901
2902 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002903 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904 * so, they get updated with this same scan info.
2905 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002906 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2907 radio_list) {
2908 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002909 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2910 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002911 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2912 res > 0);
2913 if (res < 0)
2914 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002915 }
2916 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002917
2918 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002919}
2920
2921#endif /* CONFIG_NO_SCAN_PROCESSING */
2922
2923
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002924int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2925{
2926#ifdef CONFIG_NO_SCAN_PROCESSING
2927 return -1;
2928#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002929 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002930
Dmitry Shmidt29333592017-01-09 12:27:11 -08002931 wpa_s->ignore_post_flush_scan_res = 0;
2932
Dmitry Shmidt41712582015-06-29 11:02:15 -07002933 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002934 return -1;
2935
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002936 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002937 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002938 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002939 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2940 return -1;
Sunil Ravi7f769292024-07-23 22:21:32 +00002941 } else if (wpa_s->crossed_6ghz_dom) {
2942 wpa_printf(MSG_DEBUG, "Fast associate: Crossed 6 GHz domain");
2943 return -1;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002944 }
2945
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002946 return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002947#endif /* CONFIG_NO_SCAN_PROCESSING */
2948}
2949
Sunil Ravi77d572f2023-01-17 23:58:31 +00002950
2951int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2952{
2953#ifdef CONFIG_NO_SCAN_PROCESSING
2954 return -1;
2955#else /* CONFIG_NO_SCAN_PROCESSING */
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002956 return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002957#endif /* CONFIG_NO_SCAN_PROCESSING */
2958}
2959
2960
Dmitry Shmidt04949592012-07-19 12:16:46 -07002961#ifdef CONFIG_WNM
2962
2963static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2964{
2965 struct wpa_supplicant *wpa_s = eloop_ctx;
2966
2967 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2968 return;
2969
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002970 if (!wpa_s->no_keep_alive) {
2971 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2972 MAC2STR(wpa_s->bssid));
2973 /* TODO: could skip this if normal data traffic has been sent */
2974 /* TODO: Consider using some more appropriate data frame for
2975 * this */
2976 if (wpa_s->l2)
2977 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2978 (u8 *) "", 0);
2979 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002980
2981#ifdef CONFIG_SME
2982 if (wpa_s->sme.bss_max_idle_period) {
2983 unsigned int msec;
2984 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2985 if (msec > 100)
2986 msec -= 100;
2987 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2988 wnm_bss_keep_alive, wpa_s, NULL);
2989 }
2990#endif /* CONFIG_SME */
2991}
2992
2993
2994static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2995 const u8 *ies, size_t ies_len)
2996{
2997 struct ieee802_11_elems elems;
2998
2999 if (ies == NULL)
3000 return;
3001
3002 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
3003 return;
3004
3005#ifdef CONFIG_SME
3006 if (elems.bss_max_idle_period) {
3007 unsigned int msec;
3008 wpa_s->sme.bss_max_idle_period =
3009 WPA_GET_LE16(elems.bss_max_idle_period);
3010 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
3011 "TU)%s", wpa_s->sme.bss_max_idle_period,
3012 (elems.bss_max_idle_period[2] & 0x01) ?
3013 " (protected keep-live required)" : "");
3014 if (wpa_s->sme.bss_max_idle_period == 0)
3015 wpa_s->sme.bss_max_idle_period = 1;
3016 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
3017 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
3018 /* msec times 1000 */
3019 msec = wpa_s->sme.bss_max_idle_period * 1024;
3020 if (msec > 100)
3021 msec -= 100;
3022 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
3023 wnm_bss_keep_alive, wpa_s,
3024 NULL);
3025 }
Sunil Ravi7f769292024-07-23 22:21:32 +00003026 } else {
3027 wpa_s->sme.bss_max_idle_period = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003028 }
3029#endif /* CONFIG_SME */
3030}
3031
3032#endif /* CONFIG_WNM */
3033
3034
3035void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
3036{
3037#ifdef CONFIG_WNM
3038 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
3039#endif /* CONFIG_WNM */
3040}
3041
3042
Dmitry Shmidt051af732013-10-22 13:52:46 -07003043static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
3044 size_t len)
3045{
3046 int res;
3047
3048 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
3049 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
3050 if (res) {
3051 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
3052 }
3053
3054 return res;
3055}
3056
3057
3058static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
3059 const u8 *ies, size_t ies_len)
3060{
3061 struct ieee802_11_elems elems;
3062
3063 if (ies == NULL)
3064 return;
3065
3066 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
3067 return;
3068
3069 if (elems.qos_map_set) {
3070 wpas_qos_map_set(wpa_s, elems.qos_map_set,
3071 elems.qos_map_set_len);
3072 }
3073}
3074
Dmitry Shmidt051af732013-10-22 13:52:46 -07003075
Sunil Ravi036cec52023-03-29 11:35:17 -07003076static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
3077{
3078 if (wpa_s->enabled_4addr_mode) {
3079 wpa_printf(MSG_DEBUG, "4addr mode already set");
3080 return;
3081 }
3082
3083 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
3084 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
3085 goto fail;
3086 }
3087 wpa_s->enabled_4addr_mode = 1;
3088 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
3089 return;
3090
3091fail:
3092 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3093}
3094
3095
Hai Shalom74f70d42019-02-11 14:42:39 -08003096static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
3097 const u8 *ies, size_t ies_len)
3098{
3099 struct ieee802_11_elems elems;
Sunil Ravi99c035e2024-07-12 01:42:03 +00003100 struct multi_ap_params multi_ap;
3101 u16 status;
Hai Shalom74f70d42019-02-11 14:42:39 -08003102
Hai Shalomfdcde762020-04-02 11:19:20 -07003103 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08003104
Hai Shalomfdcde762020-04-02 11:19:20 -07003105 if (!ies ||
3106 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
Sunil Ravi99c035e2024-07-12 01:42:03 +00003107 !elems.multi_ap)
Hai Shalomfdcde762020-04-02 11:19:20 -07003108 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08003109
Sunil Ravi99c035e2024-07-12 01:42:03 +00003110 status = check_multi_ap_ie(elems.multi_ap + 4, elems.multi_ap_len - 4,
3111 &multi_ap);
3112 if (status != WLAN_STATUS_SUCCESS)
Hai Shalomfdcde762020-04-02 11:19:20 -07003113 return;
3114
Sunil Ravi99c035e2024-07-12 01:42:03 +00003115 wpa_s->multi_ap_backhaul = !!(multi_ap.capability &
3116 MULTI_AP_BACKHAUL_BSS);
3117 wpa_s->multi_ap_fronthaul = !!(multi_ap.capability &
Hai Shalomfdcde762020-04-02 11:19:20 -07003118 MULTI_AP_FRONTHAUL_BSS);
3119 wpa_s->multi_ap_ie = 1;
3120}
3121
3122
3123static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
3124{
3125 if (!wpa_s->current_ssid ||
3126 !wpa_s->current_ssid->multi_ap_backhaul_sta)
3127 return;
3128
3129 if (!wpa_s->multi_ap_ie) {
3130 wpa_printf(MSG_INFO,
3131 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08003132 goto fail;
3133 }
3134
Hai Shalomfdcde762020-04-02 11:19:20 -07003135 if (!wpa_s->multi_ap_backhaul) {
3136 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07003137 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
3138 wpa_printf(MSG_INFO,
3139 "WPS active, accepting fronthaul-only BSS");
3140 /* Don't set 4addr mode in this case, so just return */
3141 return;
3142 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003143 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
3144 goto fail;
3145 }
3146
Sunil Ravi036cec52023-03-29 11:35:17 -07003147 wpa_supplicant_set_4addr_mode(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08003148 return;
3149
3150fail:
3151 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3152}
3153
3154
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003155#ifdef CONFIG_FST
3156static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
3157 const u8 *ie, size_t ie_len)
3158{
3159 struct mb_ies_info mb_ies;
3160
3161 if (!ie || !ie_len || !wpa_s->fst)
3162 return -ENOENT;
3163
3164 os_memset(&mb_ies, 0, sizeof(mb_ies));
3165
3166 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
3167 size_t len;
3168
3169 len = 2 + ie[1];
3170 if (len > ie_len) {
3171 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
3172 ie, ie_len);
3173 break;
3174 }
3175
3176 if (ie[0] == WLAN_EID_MULTI_BAND) {
3177 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
3178 (unsigned int) len);
3179 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
3180 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
3181 mb_ies.nof_ies++;
3182 }
3183
3184 ie_len -= len;
3185 ie += len;
3186 }
3187
3188 if (mb_ies.nof_ies > 0) {
3189 wpabuf_free(wpa_s->received_mb_ies);
3190 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
3191 return 0;
3192 }
3193
3194 return -ENOENT;
3195}
3196#endif /* CONFIG_FST */
3197
3198
Hai Shalomc1a21442022-02-04 13:43:00 -08003199static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
3200 union wpa_event_data *data)
3201{
3202 int sel;
3203 const u8 *p;
3204 int l, len;
3205 bool found = false;
3206 struct wpa_ie_data ie;
3207 struct wpa_ssid *ssid = wpa_s->current_ssid;
3208 struct wpa_bss *bss = wpa_s->current_bss;
3209 int pmf;
3210
3211 if (!ssid)
3212 return 0;
3213
3214 p = data->assoc_info.req_ies;
3215 l = data->assoc_info.req_ies_len;
3216
3217 while (p && l >= 2) {
3218 len = p[1] + 2;
3219 if (len > l) {
3220 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3221 p, l);
3222 break;
3223 }
3224 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3225 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3226 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3227 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3228 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3229 found = true;
3230 break;
3231 }
3232 l -= len;
3233 p += len;
3234 }
3235
Sunil Ravi036cec52023-03-29 11:35:17 -07003236 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
3237 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
Hai Shalomc1a21442022-02-04 13:43:00 -08003238 return 0;
Sunil Ravi036cec52023-03-29 11:35:17 -07003239 }
Hai Shalomc1a21442022-02-04 13:43:00 -08003240
3241 wpa_hexdump(MSG_DEBUG,
3242 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
3243 p, l);
3244
3245 /* Update proto from (Re)Association Request frame info */
3246 wpa_s->wpa_proto = ie.proto;
3247 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
3248 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
3249 !!(wpa_s->wpa_proto &
3250 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
3251
3252 /* Update AKMP suite from (Re)Association Request frame info */
3253 sel = ie.key_mgmt;
3254 if (ssid->key_mgmt)
3255 sel &= ssid->key_mgmt;
3256
3257 wpa_dbg(wpa_s, MSG_DEBUG,
3258 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
3259 ie.key_mgmt, ssid->key_mgmt, sel);
3260 if (ie.key_mgmt && !sel) {
3261 wpa_supplicant_deauthenticate(
3262 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
3263 return -1;
3264 }
3265
Sunil Ravi036cec52023-03-29 11:35:17 -07003266#ifdef CONFIG_OCV
3267 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
3268 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
3269 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
3270 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
3271#endif /* CONFIG_OCV */
3272
Sunil Ravi89eba102022-09-13 21:04:37 -07003273 /*
3274 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
3275 * different AKM.
3276 */
3277 if (wpa_s->key_mgmt != ie.key_mgmt &&
3278 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
3279 if (!ssid->psk_set) {
3280 wpa_dbg(wpa_s, MSG_INFO,
3281 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00003282 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07003283 return -1;
3284 }
3285
3286 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
3287 if (wpa_s->conf->key_mgmt_offload &&
3288 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003289 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
3290 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07003291 wpa_dbg(wpa_s, MSG_ERROR,
3292 "WPA: Cannot set PMK for key management offload");
3293 }
3294
Hai Shalomc1a21442022-02-04 13:43:00 -08003295 wpa_s->key_mgmt = ie.key_mgmt;
3296 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3297 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
3298 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
3299 wpa_s->wpa_proto);
3300
3301 /* Update pairwise cipher from (Re)Association Request frame info */
3302 sel = ie.pairwise_cipher;
3303 if (ssid->pairwise_cipher)
3304 sel &= ssid->pairwise_cipher;
3305
3306 wpa_dbg(wpa_s, MSG_DEBUG,
3307 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
3308 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
3309 if (ie.pairwise_cipher && !sel) {
3310 wpa_supplicant_deauthenticate(
3311 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
3312 return -1;
3313 }
3314
3315 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3316 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3317 wpa_s->pairwise_cipher);
3318 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
3319 wpa_cipher_txt(wpa_s->pairwise_cipher));
3320
3321 /* Update other parameters based on AP's WPA IE/RSNE, if available */
3322 if (!bss) {
3323 wpa_dbg(wpa_s, MSG_DEBUG,
3324 "WPA: current_bss == NULL - skip AP IE check");
3325 return 0;
3326 }
3327
3328 /* Update GTK and IGTK from AP's RSNE */
3329 found = false;
3330
3331 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
3332 const u8 *bss_rsn;
3333
Sunil Ravi7f769292024-07-23 22:21:32 +00003334 bss_rsn = wpa_bss_get_rsne(wpa_s, bss, ssid,
3335 wpa_s->valid_links);
Hai Shalomc1a21442022-02-04 13:43:00 -08003336 if (bss_rsn) {
3337 p = bss_rsn;
3338 len = 2 + bss_rsn[1];
3339 found = true;
3340 }
3341 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
3342 const u8 *bss_wpa;
3343
3344 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3345 if (bss_wpa) {
3346 p = bss_wpa;
3347 len = 2 + bss_wpa[1];
3348 found = true;
3349 }
3350 }
3351
3352 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
3353 return 0;
3354
3355 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
3356 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3357 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3358 /* AP does not support MFP, local configuration requires it */
3359 wpa_supplicant_deauthenticate(
3360 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3361 return -1;
3362 }
3363 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3364 pmf == NO_MGMT_FRAME_PROTECTION) {
3365 /* AP requires MFP, local configuration disables it */
3366 wpa_supplicant_deauthenticate(
3367 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3368 return -1;
3369 }
3370
3371 /* Update PMF from local configuration now that MFP validation was done
3372 * above */
3373 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3374
3375 /* Update GTK from AP's RSNE */
3376 sel = ie.group_cipher;
3377 if (ssid->group_cipher)
3378 sel &= ssid->group_cipher;
3379
3380 wpa_dbg(wpa_s, MSG_DEBUG,
3381 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3382 ie.group_cipher, ssid->group_cipher, sel);
3383 if (ie.group_cipher && !sel) {
3384 wpa_supplicant_deauthenticate(
3385 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3386 return -1;
3387 }
3388
3389 wpa_s->group_cipher = ie.group_cipher;
3390 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3391 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3392 wpa_cipher_txt(wpa_s->group_cipher));
3393
3394 /* Update IGTK from AP RSN IE */
3395 sel = ie.mgmt_group_cipher;
3396 if (ssid->group_mgmt_cipher)
3397 sel &= ssid->group_mgmt_cipher;
3398
3399 wpa_dbg(wpa_s, MSG_DEBUG,
3400 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3401 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3402
3403 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3404 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3405 wpa_dbg(wpa_s, MSG_DEBUG,
3406 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3407 ie.capabilities);
3408 ie.mgmt_group_cipher = 0;
3409 }
3410
3411 if (ie.mgmt_group_cipher && !sel) {
3412 wpa_supplicant_deauthenticate(
3413 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3414 return -1;
3415 }
3416
3417 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3418 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3419 wpa_s->mgmt_group_cipher);
3420 if (wpa_s->mgmt_group_cipher)
3421 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3422 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3423 else
3424 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3425
3426 return 0;
3427}
3428
3429
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003430static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3431 union wpa_event_data *data)
3432{
Hai Shalomc3565922019-10-28 11:58:20 -07003433 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Sunil Ravic0f5d412024-09-11 22:12:49 +00003434 const u8 *p, *ie;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003435 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003436 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003437#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Sunil Ravic0f5d412024-09-11 22:12:49 +00003438 struct wpa_ie_data wpa_ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003439#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Sunil Ravic0f5d412024-09-11 22:12:49 +00003440 enum wpa_rsn_override rsn_override;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003441
3442 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Sunil Ravi7f769292024-07-23 22:21:32 +00003443 wpa_s->ssid_verified = false;
3444 wpa_s->bigtk_set = false;
3445#ifdef CONFIG_SAE
3446#ifdef CONFIG_SME
3447 /* SAE H2E binds the SSID into PT and that verifies the SSID
3448 * implicitly. */
3449 if (wpa_s->sme.sae.state == SAE_ACCEPTED && wpa_s->sme.sae.h2e)
3450 wpa_s->ssid_verified = true;
3451#endif /* CONFIG_SME */
3452#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -07003453 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003454 if (data->assoc_info.req_ies)
3455 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3456 data->assoc_info.req_ies_len);
3457 if (data->assoc_info.resp_ies) {
3458 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3459 data->assoc_info.resp_ies_len);
3460#ifdef CONFIG_TDLS
3461 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3462 data->assoc_info.resp_ies_len);
3463#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003464#ifdef CONFIG_WNM
3465 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3466 data->assoc_info.resp_ies_len);
3467#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003468 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3469 data->assoc_info.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003470 if (wpa_s->hw_capab == CAPAB_VHT &&
3471 get_ie(data->assoc_info.resp_ies,
3472 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3473 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003474
3475 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3476 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003477 }
3478 if (data->assoc_info.beacon_ies)
3479 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3480 data->assoc_info.beacon_ies,
3481 data->assoc_info.beacon_ies_len);
3482 if (data->assoc_info.freq)
3483 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3484 data->assoc_info.freq);
3485
Hai Shalom021b0b52019-04-10 11:17:58 -07003486 wpa_s->connection_set = 0;
3487 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3488 struct ieee802_11_elems req_elems, resp_elems;
3489
3490 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3491 data->assoc_info.req_ies_len,
3492 &req_elems, 0) != ParseFailed &&
3493 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3494 data->assoc_info.resp_ies_len,
3495 &resp_elems, 0) != ParseFailed) {
3496 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003497 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3498 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003499 wpa_s->connection_ht = req_elems.ht_capabilities &&
3500 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003501 /* Do not include subset of VHT on 2.4 GHz vendor
3502 * extension in consideration for reporting VHT
3503 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003504 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003505 resp_elems.vht_capabilities &&
3506 (!data->assoc_info.freq ||
3507 wpas_freq_to_band(data->assoc_info.freq) !=
3508 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003509 wpa_s->connection_he = req_elems.he_capabilities &&
3510 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003511 wpa_s->connection_eht = req_elems.eht_capabilities &&
3512 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003513
3514 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3515 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3516 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3517 max_nss_rx_req : max_nss_rx_resp;
3518 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3519 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3520 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3521 max_nss_tx_req : max_nss_tx_resp;
3522
3523 struct supported_chan_width sta_supported_chan_width =
3524 get_supported_channel_width(&req_elems);
3525 enum chan_width ap_operation_chan_width =
3526 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303527 if (wpa_s->connection_vht || wpa_s->connection_he ||
3528 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003529 wpa_s->connection_channel_bandwidth =
3530 get_sta_operation_chan_width(ap_operation_chan_width,
3531 sta_supported_chan_width);
3532 } else if (wpa_s->connection_ht) {
3533 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3534 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3535 } else {
3536 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3537 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003538 if (req_elems.rrm_enabled)
3539 wpa_s->rrm.rrm_used = 1;
Ainy Kumari322d4fd2024-02-14 13:05:40 +05303540 wpa_s->ap_t2lm_negotiation_support =
3541 is_ap_t2lm_negotiation_supported(resp_elems.basic_mle,
3542 resp_elems.basic_mle_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07003543 }
3544 }
3545
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003546 p = data->assoc_info.req_ies;
3547 l = data->assoc_info.req_ies_len;
3548
3549 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3550 while (p && l >= 2) {
3551 len = p[1] + 2;
3552 if (len > l) {
3553 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3554 p, l);
3555 break;
3556 }
Hai Shalomc3565922019-10-28 11:58:20 -07003557 if (!found &&
3558 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3559 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3560 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3561 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3562 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003563 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3564 break;
3565 found = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07003566 wpa_find_assoc_pmkid(wpa_s,
3567 data->assoc_info.authorized);
Hai Shalomc3565922019-10-28 11:58:20 -07003568 }
3569 if (!found_x && p[0] == WLAN_EID_RSNX) {
3570 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3571 break;
3572 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003573 }
3574 l -= len;
3575 p += len;
3576 }
3577 if (!found && data->assoc_info.req_ies)
3578 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003579 if (!found_x && data->assoc_info.req_ies)
3580 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003581
Winnie Chen4138eec2022-11-10 16:32:53 +08003582#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303583 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3584 * to a different security type, update the current supplicant configuration to use the AKM
3585 * and pairwise suites from the assoc IE passed by the driver.
3586 */
3587 if (wpas_driver_bss_selection(wpa_s)) {
Sunil Ravic0f5d412024-09-11 22:12:49 +00003588 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &wpa_ie) < 0)) {
Vinayak Yadawad14709082022-03-17 14:25:11 +05303589 /* Check if firmware has roamed to a different security network */
Sunil Ravic0f5d412024-09-11 22:12:49 +00003590 if(wpa_s->key_mgmt != wpa_ie.key_mgmt) {
Vinayak Yadawad14709082022-03-17 14:25:11 +05303591 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
Sunil Ravic0f5d412024-09-11 22:12:49 +00003592 wpa_ie.key_mgmt);
3593 wpa_s->key_mgmt = wpa_ie.key_mgmt;
Vinayak Yadawad14709082022-03-17 14:25:11 +05303594 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3595
3596 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3597 /* Restore PMK as it can get overwritten if the previous
3598 * association was to 802.1X.
3599 */
3600 if ((!(wpa_s->drv_flags &
3601 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3602 (wpa_s->current_ssid) &&
3603 (wpa_s->current_ssid->psk_set)) {
3604 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3605 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3606 "BSSID");
3607 wpa_supplicant_deauthenticate(
3608 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3609 return -1;
3610 }
3611 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3612 PMK_LEN, NULL, bssid);
3613 }
3614 }
3615 }
Sunil Ravic0f5d412024-09-11 22:12:49 +00003616 if(wpa_s->pairwise_cipher != wpa_ie.pairwise_cipher) {
Vinayak Yadawad14709082022-03-17 14:25:11 +05303617 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
Sunil Ravic0f5d412024-09-11 22:12:49 +00003618 "from Assoc IE", wpa_ie.pairwise_cipher);
3619 wpa_s->pairwise_cipher = wpa_ie.pairwise_cipher;
Vinayak Yadawad14709082022-03-17 14:25:11 +05303620 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3621 wpa_s->pairwise_cipher);
3622 }
3623 // TODO: Notify the framework about security type change b/230766005
3624 }
3625 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003626#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303627
Sunil Ravic0f5d412024-09-11 22:12:49 +00003628 rsn_override = RSN_OVERRIDE_NOT_USED;
3629 ie = get_vendor_ie(data->assoc_info.req_ies,
3630 data->assoc_info.req_ies_len,
3631 RSN_SELECTION_IE_VENDOR_TYPE);
3632 if (ie && ie[1] >= 4 + 1) {
3633 switch (ie[2 + 4]) {
3634 case RSN_SELECTION_RSNE:
3635 rsn_override = RSN_OVERRIDE_RSNE;
3636 break;
3637 case RSN_SELECTION_RSNE_OVERRIDE:
3638 rsn_override = RSN_OVERRIDE_RSNE_OVERRIDE;
3639 break;
3640 case RSN_SELECTION_RSNE_OVERRIDE_2:
3641 rsn_override = RSN_OVERRIDE_RSNE_OVERRIDE_2;
3642 break;
3643 }
3644 }
3645 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_OVERRIDE, rsn_override);
3646
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003647#ifdef CONFIG_FILS
3648#ifdef CONFIG_SME
Sunil Ravi7f769292024-07-23 22:21:32 +00003649 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3650 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) {
3651 if (!data->assoc_info.resp_frame ||
3652 fils_process_assoc_resp(wpa_s->wpa,
3653 data->assoc_info.resp_frame,
3654 data->assoc_info.resp_frame_len) <
3655 0) {
3656 wpa_supplicant_deauthenticate(wpa_s,
3657 WLAN_REASON_UNSPECIFIED);
3658 return -1;
3659 }
3660
3661 /* FILS use of an AEAD cipher include the SSID element in
3662 * (Re)Association Request frame in the AAD and since the AP
3663 * accepted that, the SSID was verified. */
3664 wpa_s->ssid_verified = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003665 }
3666#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003667
3668 /* Additional processing for FILS when SME is in driver */
3669 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3670 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3671 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003672#endif /* CONFIG_FILS */
3673
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003674#ifdef CONFIG_OWE
3675 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003676 !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003677 (!bssid_known ||
Sunil Ravi036cec52023-03-29 11:35:17 -07003678 owe_process_assoc_resp(wpa_s->wpa,
3679 wpa_s->valid_links ?
3680 wpa_s->ap_mld_addr : bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003681 data->assoc_info.resp_ies,
3682 data->assoc_info.resp_ies_len) < 0)) {
3683 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3684 return -1;
3685 }
3686#endif /* CONFIG_OWE */
3687
Hai Shalom021b0b52019-04-10 11:17:58 -07003688#ifdef CONFIG_DPP2
3689 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003690 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3691 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003692 struct ieee802_11_elems elems;
3693
3694 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3695 data->assoc_info.resp_ies_len,
3696 &elems, 0) == ParseFailed ||
3697 !elems.owe_dh)
3698 goto no_pfs;
3699 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3700 elems.owe_dh_len) < 0) {
3701 wpa_supplicant_deauthenticate(wpa_s,
3702 WLAN_REASON_UNSPECIFIED);
3703 return -1;
3704 }
3705
3706 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3707 }
3708no_pfs:
3709#endif /* CONFIG_DPP2 */
3710
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003711#ifdef CONFIG_IEEE80211R
3712#ifdef CONFIG_SME
3713 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003714 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003715 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3716 data->assoc_info.resp_ies,
3717 data->assoc_info.resp_ies_len,
3718 bssid) < 0) {
3719 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3720 "Reassociation Response failed");
3721 wpa_supplicant_deauthenticate(
3722 wpa_s, WLAN_REASON_INVALID_IE);
3723 return -1;
3724 }
Sunil Ravi7f769292024-07-23 22:21:32 +00003725 /* SSID is included in PMK-R0 derivation, so it is verified
3726 * implicitly. */
3727 wpa_s->ssid_verified = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003728 }
3729
3730 p = data->assoc_info.resp_ies;
3731 l = data->assoc_info.resp_ies_len;
3732
3733#ifdef CONFIG_WPS_STRICT
3734 if (p && wpa_s->current_ssid &&
3735 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3736 struct wpabuf *wps;
3737 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3738 if (wps == NULL) {
3739 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3740 "include WPS IE in (Re)Association Response");
3741 return -1;
3742 }
3743
3744 if (wps_validate_assoc_resp(wps) < 0) {
3745 wpabuf_free(wps);
3746 wpa_supplicant_deauthenticate(
3747 wpa_s, WLAN_REASON_INVALID_IE);
3748 return -1;
3749 }
3750 wpabuf_free(wps);
3751 }
3752#endif /* CONFIG_WPS_STRICT */
3753
3754 /* Go through the IEs and make a copy of the MDIE, if present. */
3755 while (p && l >= 2) {
3756 len = p[1] + 2;
3757 if (len > l) {
3758 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3759 p, l);
3760 break;
3761 }
3762 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3763 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3764 wpa_s->sme.ft_used = 1;
3765 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3766 MOBILITY_DOMAIN_ID_LEN);
3767 break;
3768 }
3769 l -= len;
3770 p += len;
3771 }
3772#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003773#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303774 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3775 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3776 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
Vinayak Yadawadf473bef2024-04-04 15:33:29 +05303777 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) ||
3778 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303779 wpa_ft_is_completed(wpa_s->wpa)) {
3780 return 0;
3781 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003782#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003783
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003784 /* Process FT when SME is in the driver */
3785 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3786 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003787 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003788 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3789 data->assoc_info.resp_ies,
3790 data->assoc_info.resp_ies_len,
3791 bssid) < 0) {
3792 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3793 "Reassociation Response failed");
3794 wpa_supplicant_deauthenticate(
3795 wpa_s, WLAN_REASON_INVALID_IE);
3796 return -1;
3797 }
3798 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
Sunil Ravi7f769292024-07-23 22:21:32 +00003799 /* SSID is included in PMK-R0 derivation, so it is verified
3800 * implicitly. */
3801 wpa_s->ssid_verified = true;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003802 }
3803
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003804 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3805 data->assoc_info.resp_ies_len);
3806#endif /* CONFIG_IEEE80211R */
3807
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003808#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07003809 if (bssid_known)
3810 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3811 data->assoc_info.resp_ies,
3812 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003813#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -07003814
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003815 /* WPA/RSN IE from Beacon/ProbeResp */
3816 p = data->assoc_info.beacon_ies;
3817 l = data->assoc_info.beacon_ies_len;
3818
3819 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3820 */
3821 wpa_found = rsn_found = 0;
3822 while (p && l >= 2) {
3823 len = p[1] + 2;
3824 if (len > l) {
3825 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3826 p, l);
3827 break;
3828 }
3829 if (!wpa_found &&
3830 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3831 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3832 wpa_found = 1;
3833 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3834 }
3835
3836 if (!rsn_found &&
3837 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3838 rsn_found = 1;
3839 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3840 }
3841
Sunil Ravic0f5d412024-09-11 22:12:49 +00003842 if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3843 WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_2_IE_VENDOR_TYPE)
3844 wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, p, len);
Sunil Ravi7f769292024-07-23 22:21:32 +00003845
Sunil Ravic0f5d412024-09-11 22:12:49 +00003846 if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3847 WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_IE_VENDOR_TYPE)
3848 wpa_sm_set_ap_rsne_override(wpa_s->wpa, p, len);
Sunil Ravi7f769292024-07-23 22:21:32 +00003849
Hai Shalomc3565922019-10-28 11:58:20 -07003850 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3851 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3852
Sunil Ravic0f5d412024-09-11 22:12:49 +00003853 if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
Sunil Ravi7f769292024-07-23 22:21:32 +00003854 WPA_GET_BE32(&p[2]) == RSNXE_OVERRIDE_IE_VENDOR_TYPE)
Sunil Ravic0f5d412024-09-11 22:12:49 +00003855 wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, p, len);
Sunil Ravi7f769292024-07-23 22:21:32 +00003856
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003857 l -= len;
3858 p += len;
3859 }
3860
3861 if (!wpa_found && data->assoc_info.beacon_ies)
3862 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003863 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003864 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003865 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
Sunil Ravic0f5d412024-09-11 22:12:49 +00003866 wpa_sm_set_ap_rsne_override(wpa_s->wpa, NULL, 0);
3867 wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, NULL, 0);
3868 wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003869 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003870 if (wpa_found || rsn_found)
3871 wpa_s->ap_ies_from_associnfo = 1;
3872
Sunil Ravi99c035e2024-07-12 01:42:03 +00003873 if (wpa_s->assoc_freq && data->assoc_info.freq) {
3874 struct wpa_bss *bss;
3875 unsigned int freq = 0;
3876
3877 if (bssid_known) {
3878 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
3879 if (bss)
3880 freq = bss->freq;
3881 }
3882 if (freq != data->assoc_info.freq) {
3883 wpa_printf(MSG_DEBUG,
3884 "Operating frequency changed from %u to %u MHz",
3885 wpa_s->assoc_freq, data->assoc_info.freq);
3886 wpa_supplicant_update_scan_results(wpa_s, bssid);
3887 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03003888 }
3889
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003890 wpa_s->assoc_freq = data->assoc_info.freq;
3891
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003892#ifndef CONFIG_NO_ROBUST_AV
Hai Shalomc1a21442022-02-04 13:43:00 -08003893 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3894 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003895#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08003896
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003897 return 0;
3898}
3899
3900
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003901static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3902{
Hai Shalomc3565922019-10-28 11:58:20 -07003903 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Sunil Ravic0f5d412024-09-11 22:12:49 +00003904 const u8 *rsnoe, *rsno2e, *rsnxoe;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003905
3906 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3907 return -1;
3908
3909 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3910 return 0;
3911
3912 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3913 WPA_IE_VENDOR_TYPE);
Sunil Ravic0f5d412024-09-11 22:12:49 +00003914 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
3915 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
3916 rsnoe = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3917 RSNE_OVERRIDE_IE_VENDOR_TYPE);
3918 rsno2e = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3919 RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
3920 rsnxoe = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3921 RSNXE_OVERRIDE_IE_VENDOR_TYPE);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003922
3923 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3924 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3925 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003926 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3927 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
Sunil Ravic0f5d412024-09-11 22:12:49 +00003928 bss_rsnx ? 2 + bss_rsnx[1] : 0) ||
3929 wpa_sm_set_ap_rsne_override(wpa_s->wpa, rsnoe,
3930 rsnoe ? 2 + rsnoe[1] : 0) ||
3931 wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, rsno2e,
3932 rsno2e ? 2 + rsno2e[1] : 0) ||
3933 wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, rsnxoe,
3934 rsnxoe ? 2 + rsnxoe[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003935 return -1;
3936
3937 return 0;
3938}
3939
3940
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003941static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3942 union wpa_event_data *data)
3943{
3944#ifdef CONFIG_FST
3945 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3946 struct wpa_bss *bss = wpa_s->current_bss;
3947 const u8 *ieprb, *iebcn;
3948
3949 wpabuf_free(wpa_s->received_mb_ies);
3950 wpa_s->received_mb_ies = NULL;
3951
3952 if (ai &&
3953 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3954 wpa_printf(MSG_DEBUG,
3955 "FST: MB IEs updated from Association Response frame");
3956 return;
3957 }
3958
3959 if (ai &&
3960 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3961 wpa_printf(MSG_DEBUG,
3962 "FST: MB IEs updated from association event Beacon IEs");
3963 return;
3964 }
3965
3966 if (!bss)
3967 return;
3968
Hai Shalom60840252021-02-19 19:02:11 -08003969 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003970 iebcn = ieprb + bss->ie_len;
3971
3972 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3973 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3974 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3975 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3976#endif /* CONFIG_FST */
3977}
3978
3979
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003980static unsigned int wpas_ml_parse_assoc(struct wpa_supplicant *wpa_s,
3981 struct ieee802_11_elems *elems,
3982 struct ml_sta_link_info *ml_info)
3983{
3984 struct wpabuf *mlbuf;
3985 struct ieee80211_eht_ml *ml;
3986 size_t ml_len;
3987 struct eht_ml_basic_common_info *common_info;
3988 const u8 *pos;
3989 u16 eml_capa = 0, mld_capa = 0;
3990 const u16 control =
3991 host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC |
3992 BASIC_MULTI_LINK_CTRL_PRES_LINK_ID |
3993 BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT);
3994 u8 expected_common_info_len = 9;
3995 unsigned int i = 0;
3996 u16 ml_control;
3997
3998 if (!wpa_s->valid_links || !elems->basic_mle || !elems->basic_mle_len)
3999 return 0;
4000
4001 mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
4002 if (!mlbuf)
4003 return 0;
4004
4005 ml = (struct ieee80211_eht_ml *) wpabuf_head(mlbuf);
4006 ml_len = wpabuf_len(mlbuf);
4007 if (ml_len < sizeof(*ml))
4008 goto out;
4009
4010 os_memset(ml_info, 0, sizeof(*ml_info) * MAX_NUM_MLD_LINKS);
4011
4012 ml_control = le_to_host16(ml->ml_control);
4013
4014 if ((ml_control & control) != control) {
4015 wpa_printf(MSG_DEBUG, "MLD: Invalid presence BM=0x%x",
4016 ml_control);
4017 goto out;
4018 }
4019
4020 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
4021 wpa_printf(MSG_DEBUG, "MLD: EML capabilities included");
4022 expected_common_info_len += 2;
4023 }
4024
4025 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
4026 wpa_printf(MSG_DEBUG, "MLD: MLD capabilities included");
4027 expected_common_info_len += 2;
4028 }
4029
4030 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
4031 wpa_printf(MSG_DEBUG,
4032 "MLD: Unexpected: medium sync delay info present");
4033 expected_common_info_len += 2;
4034 }
4035
4036 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
4037 wpa_printf(MSG_DEBUG,
4038 "MLD: Unexpected: MLD ID present");
4039 expected_common_info_len++;
4040 }
4041
4042 if (sizeof(*ml) + expected_common_info_len > ml_len) {
4043 wpa_printf(MSG_DEBUG,
4044 "MLD: Not enough bytes for common info. ml_len=%zu",
4045 ml_len);
4046 goto out;
4047 }
4048
4049 common_info = (struct eht_ml_basic_common_info *) ml->variable;
4050 if (common_info->len != expected_common_info_len) {
4051 wpa_printf(MSG_DEBUG,
4052 "MLD: Invalid common info len=%u. expected=%u",
4053 common_info->len, expected_common_info_len);
4054 goto out;
4055 }
4056
4057 wpa_printf(MSG_DEBUG, "MLD: address: " MACSTR,
4058 MAC2STR(common_info->mld_addr));
4059
4060 if (!ether_addr_equal(wpa_s->ap_mld_addr, common_info->mld_addr)) {
4061 wpa_printf(MSG_DEBUG, "MLD: Mismatching MLD address (expected "
4062 MACSTR ")", MAC2STR(wpa_s->ap_mld_addr));
4063 goto out;
4064 }
4065
4066 pos = common_info->variable;
4067
4068 /* Store the information for the association link */
4069 ml_info[i].link_id = *pos;
4070 pos++;
4071
4072 /* Skip the BSS Parameters Change Count */
4073 pos++;
4074
4075 /* Skip the Medium Synchronization Delay Information if present */
4076 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO)
4077 pos += 2;
4078
4079 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
4080 eml_capa = WPA_GET_LE16(pos);
4081 pos += 2;
4082 }
4083
4084 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
4085 mld_capa = WPA_GET_LE16(pos);
4086 pos += 2;
4087 }
4088
4089 wpa_printf(MSG_DEBUG,
4090 "MLD: link_id=%u, eml=0x%x, mld=0x%x",
4091 ml_info[i].link_id, eml_capa, mld_capa);
4092
4093 i++;
4094
4095 pos = ((u8 *) common_info) + common_info->len;
4096 ml_len -= sizeof(*ml) + common_info->len;
4097 while (ml_len > 2 && i < MAX_NUM_MLD_LINKS) {
4098 u8 sub_elem_len = pos[1];
4099 u8 sta_info_len;
4100 u8 nstr_bitmap_len = 0;
4101 u16 ctrl;
4102 const u8 *end;
4103
4104 wpa_printf(MSG_DEBUG, "MLD: Subelement len=%u", sub_elem_len);
4105
4106 if (sub_elem_len > ml_len - 2) {
4107 wpa_printf(MSG_DEBUG,
4108 "MLD: Invalid link info len: %u > %zu",
4109 2 + sub_elem_len, ml_len);
4110 goto out;
4111 }
4112
4113 switch (*pos) {
4114 case EHT_ML_SUB_ELEM_PER_STA_PROFILE:
4115 break;
4116 case EHT_ML_SUB_ELEM_FRAGMENT:
4117 case EHT_ML_SUB_ELEM_VENDOR:
4118 wpa_printf(MSG_DEBUG,
4119 "MLD: Skip subelement id=%u, len=%u",
4120 *pos, sub_elem_len);
4121 pos += 2 + sub_elem_len;
4122 ml_len -= 2 + sub_elem_len;
4123 continue;
4124 default:
4125 wpa_printf(MSG_DEBUG, "MLD: Unknown subelement ID=%u",
4126 *pos);
4127 goto out;
4128 }
4129
4130 end = pos + 2 + sub_elem_len;
4131
4132 /* Skip the subelement ID and the length */
4133 pos += 2;
4134 ml_len -= 2;
4135
4136 if (end - pos < 2)
4137 goto out;
4138
4139 /* Get the station control field */
4140 ctrl = WPA_GET_LE16(pos);
4141
4142 pos += 2;
4143 ml_len -= 2;
4144
4145 if (!(ctrl & EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK)) {
4146 wpa_printf(MSG_DEBUG,
4147 "MLD: Per STA complete profile expected");
4148 goto out;
4149 }
4150
4151 if (!(ctrl & EHT_PER_STA_CTRL_MAC_ADDR_PRESENT_MSK)) {
4152 wpa_printf(MSG_DEBUG,
4153 "MLD: Per STA MAC address not present");
4154 goto out;
4155 }
4156
4157 if (!(ctrl & EHT_PER_STA_CTRL_TSF_OFFSET_PRESENT_MSK)) {
4158 wpa_printf(MSG_DEBUG,
4159 "MLD: Per STA TSF offset not present");
4160 goto out;
4161 }
4162
4163 if (!(ctrl & EHT_PER_STA_CTRL_BEACON_INTERVAL_PRESENT_MSK)) {
4164 wpa_printf(MSG_DEBUG,
4165 "MLD: Beacon interval not present");
4166 goto out;
4167 }
4168
4169 if (!(ctrl & EHT_PER_STA_CTRL_DTIM_INFO_PRESENT_MSK)) {
4170 wpa_printf(MSG_DEBUG,
4171 "MLD: DTIM information not present");
4172 goto out;
4173 }
4174
4175 if (ctrl & EHT_PER_STA_CTRL_NSTR_LINK_PAIR_PRESENT_MSK) {
4176 if (ctrl & EHT_PER_STA_CTRL_NSTR_BM_SIZE_MSK)
4177 nstr_bitmap_len = 2;
4178 else
4179 nstr_bitmap_len = 1;
4180 }
4181
4182 if (!(ctrl & EHT_PER_STA_CTRL_BSS_PARAM_CNT_PRESENT_MSK)) {
4183 wpa_printf(MSG_DEBUG,
4184 "MLD: BSS params change count not present");
4185 goto out;
4186 }
4187
4188 sta_info_len = 1 + ETH_ALEN + 8 + 2 + 2 + 1 + nstr_bitmap_len;
4189 if (sta_info_len > ml_len || sta_info_len > end - pos ||
4190 sta_info_len + 2 > sub_elem_len ||
4191 sta_info_len != *pos) {
4192 wpa_printf(MSG_DEBUG,
4193 "MLD: Invalid STA info len=%u, len=%u",
4194 sta_info_len, *pos);
4195 goto out;
4196 }
4197
4198 /* Get the link address */
4199 wpa_printf(MSG_DEBUG,
4200 "MLD: link addr: " MACSTR " nstr BM len=%u",
4201 MAC2STR(pos + 1), nstr_bitmap_len);
4202
4203 ml_info[i].link_id = ctrl & EHT_PER_STA_CTRL_LINK_ID_MSK;
4204 os_memcpy(ml_info[i].bssid, pos + 1, ETH_ALEN);
4205
4206 pos += sta_info_len;
4207 ml_len -= sta_info_len;
4208
4209 wpa_printf(MSG_DEBUG, "MLD: sub_elem_len=%u, sta_info_len=%u",
4210 sub_elem_len, sta_info_len);
4211
4212 sub_elem_len -= sta_info_len + 2;
4213 if (sub_elem_len < 4) {
4214 wpa_printf(MSG_DEBUG, "MLD: Per STA profile too short");
4215 goto out;
4216 }
4217
4218 wpa_hexdump(MSG_MSGDUMP, "MLD: STA profile", pos, sub_elem_len);
4219 ml_info[i].status = WPA_GET_LE16(pos + 2);
4220
4221 pos += sub_elem_len;
4222 ml_len -= sub_elem_len;
4223
4224 i++;
4225 }
4226
4227 wpabuf_free(mlbuf);
4228 return i;
4229out:
4230 wpabuf_free(mlbuf);
4231 return 0;
4232}
4233
4234
Sunil Ravi89eba102022-09-13 21:04:37 -07004235static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
4236{
4237 struct driver_sta_mlo_info mlo;
4238 int i;
4239
Sunil Ravi77d572f2023-01-17 23:58:31 +00004240 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07004241 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
4242 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
4243 wpa_supplicant_deauthenticate(wpa_s,
4244 WLAN_REASON_DEAUTH_LEAVING);
4245 return -1;
4246 }
4247
4248 if (wpa_s->valid_links == mlo.valid_links) {
4249 bool match = true;
4250
4251 if (!mlo.valid_links)
4252 return 0;
4253
Sunil Ravi99c035e2024-07-12 01:42:03 +00004254 for_each_link(mlo.valid_links, i) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004255 if (!ether_addr_equal(wpa_s->links[i].addr,
4256 mlo.links[i].addr) ||
4257 !ether_addr_equal(wpa_s->links[i].bssid,
4258 mlo.links[i].bssid)) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004259 match = false;
4260 break;
4261 }
4262 }
4263
Sunil Ravi77d572f2023-01-17 23:58:31 +00004264 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004265 ether_addr_equal(wpa_s->ap_mld_addr, mlo.ap_mld_addr))
Sunil Ravi89eba102022-09-13 21:04:37 -07004266 return 0;
4267 }
4268
4269 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004270 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07004271 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
Sunil Ravi99c035e2024-07-12 01:42:03 +00004272 for_each_link(wpa_s->valid_links, i) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004273 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
4274 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
4275 wpa_s->links[i].freq = mlo.links[i].freq;
4276 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
4277 }
4278
4279 return 0;
4280}
4281
4282
Sunil Ravi77d572f2023-01-17 23:58:31 +00004283static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
4284{
4285 struct driver_sta_mlo_info drv_mlo;
4286 struct wpa_sm_mlo wpa_mlo;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004287 int i;
4288
4289 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
4290 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
4291 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
4292 return -1;
4293 }
4294
4295 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
4296 if (!drv_mlo.valid_links)
4297 goto out;
4298
4299 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
4300 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
4301 wpa_mlo.valid_links = drv_mlo.valid_links;
4302 wpa_mlo.req_links = drv_mlo.req_links;
4303
Sunil Ravi99c035e2024-07-12 01:42:03 +00004304 for_each_link(drv_mlo.req_links, i) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004305 struct wpa_bss *bss;
Sunil Ravic0f5d412024-09-11 22:12:49 +00004306 const u8 *rsne, *rsnxe, *rsnoe, *rsno2e, *rsnxoe;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004307
Sunil Ravi77d572f2023-01-17 23:58:31 +00004308 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
4309 if (!bss) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004310 wpa_dbg(wpa_s, MSG_INFO,
4311 "Failed to get MLO link %d BSS", i);
4312 return -1;
4313 }
4314
Sunil Ravic0f5d412024-09-11 22:12:49 +00004315 rsne = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4316 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
4317 rsnoe = wpa_bss_get_vendor_ie(bss,
4318 RSNE_OVERRIDE_IE_VENDOR_TYPE);
4319 rsno2e = wpa_bss_get_vendor_ie(bss,
4320 RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
4321 rsnxoe = wpa_bss_get_vendor_ie(bss,
4322 RSNXE_OVERRIDE_IE_VENDOR_TYPE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004323
Sunil Ravic0f5d412024-09-11 22:12:49 +00004324 wpa_mlo.links[i].ap_rsne = rsne ? (u8 *) rsne : NULL;
4325 wpa_mlo.links[i].ap_rsne_len = rsne ? 2 + rsne[1] : 0;
4326 wpa_mlo.links[i].ap_rsnxe = rsnxe ? (u8 *) rsnxe : NULL;
4327 wpa_mlo.links[i].ap_rsnxe_len = rsnxe ? 2 + rsnxe[1] : 0;
4328 wpa_mlo.links[i].ap_rsnoe = rsnoe ? (u8 *) rsnoe : NULL;
4329 wpa_mlo.links[i].ap_rsnoe_len = rsnoe ? 2 + rsnoe[1] : 0;
4330 wpa_mlo.links[i].ap_rsno2e = rsno2e ? (u8 *) rsno2e : NULL;
4331 wpa_mlo.links[i].ap_rsno2e_len = rsno2e ? 2 + rsno2e[1] : 0;
4332 wpa_mlo.links[i].ap_rsnxoe = rsnxoe ? (u8 *) rsnxoe : NULL;
4333 wpa_mlo.links[i].ap_rsnxoe_len = rsnxoe ? 2 + rsnxoe[1] : 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004334
4335 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
4336 ETH_ALEN);
4337 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
4338 ETH_ALEN);
4339 }
4340
4341out:
4342 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
4343}
4344
4345
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004346static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
4347 union wpa_event_data *data)
4348{
4349 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004350 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004351 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07004352#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4353 struct wpa_bss *bss;
4354#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08004355#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304356 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08004357#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004358
4359#ifdef CONFIG_AP
4360 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004361 if (!data)
4362 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004363 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
4364 data->assoc_info.addr,
4365 data->assoc_info.req_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004366 data->assoc_info.req_ies_len, NULL, 0,
4367 NULL, data->assoc_info.reassoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004368 return;
4369 }
4370#endif /* CONFIG_AP */
4371
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004372 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07004373 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004374
Andy Kuoaba17c12022-04-14 16:05:31 +08004375#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304376 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
4377 struct wpa_ft_ies parse;
4378 /* Check for FT reassociation is done by the driver */
4379#ifdef CONFIG_IEEE80211R
4380 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05304381 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05304382 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004383 data->assoc_info.resp_ies_len, &parse, use_sha384, false) < 0) {
Mir Ali677e7482020-11-12 19:49:02 +05304384 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
4385 return;
4386 }
4387 if (parse.rsn_pmkid != NULL) {
4388 wpa_set_ft_completed(wpa_s->wpa);
4389 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
4390 }
4391 }
4392#endif /* CONFIG_IEEE80211R */
4393 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004394#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05304395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004396 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07004397
4398 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4399 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
4400 wpa_supplicant_deauthenticate(
4401 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4402 return;
4403 }
4404
Sunil Ravi89eba102022-09-13 21:04:37 -07004405 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
4406 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
4407 wpa_supplicant_deauthenticate(wpa_s,
4408 WLAN_REASON_DEAUTH_LEAVING);
4409 return;
4410 }
4411
Sunil Ravia04bd252022-05-02 22:54:18 -07004412 if (ft_completed &&
4413 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
4414 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
4415 MAC2STR(bssid));
4416 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
4417 wpa_printf(MSG_ERROR,
4418 "Can't find target AP's information!");
4419 return;
4420 }
4421 wpa_supplicant_assoc_update_ie(wpa_s);
4422 }
4423
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004424 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
4425 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004426 /*
4427 * FILS authentication can share the same mechanism to mark the
4428 * connection fully authenticated, so set ft_completed also based on
4429 * FILS result.
4430 */
4431 if (!ft_completed)
4432 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004433
Andy Kuoaba17c12022-04-14 16:05:31 +08004434#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304435 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
4436 /*
4437 * For driver based roaming, insert PSK during
4438 * the initial association
4439 */
4440 if (is_zero_ether_addr(wpa_s->bssid) &&
4441 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
4442 /*
4443 * In case the driver wants to handle re-assocs,
4444 * pass it down the PMK.
4445 */
4446 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
4447 wpa_sm_install_pmk(wpa_s->wpa);
4448 }
Mir Ali677e7482020-11-12 19:49:02 +05304449 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304450#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08004451
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004452 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004453 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004454 if (os_reltime_initialized(&wpa_s->session_start)) {
4455 os_reltime_age(&wpa_s->session_start,
4456 &wpa_s->session_length);
4457 wpa_s->session_start.sec = 0;
4458 wpa_s->session_start.usec = 0;
4459 wpas_notify_session_length(wpa_s);
4460 } else {
4461 wpas_notify_auth_changed(wpa_s);
4462 os_get_reltime(&wpa_s->session_start);
4463 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004464 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
4465 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004466 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004467 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004468 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4469 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004470 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004471
4472 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
4473 wpa_clear_keys(wpa_s, bssid);
4474 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00004475 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004476 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004477 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4478 return;
4479 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004480 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004481
Hai Shalomc1a21442022-02-04 13:43:00 -08004482 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4483 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
4484 return;
4485
Hai Shalomfdcde762020-04-02 11:19:20 -07004486 multi_ap_set_4addr_mode(wpa_s);
4487
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004488 if (wpa_s->conf->ap_scan == 1 &&
4489 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004490 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
4491 wpa_msg(wpa_s, MSG_WARNING,
4492 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004493 }
4494
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004495 wpas_fst_update_mb_assoc(wpa_s, data);
4496
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004497#ifdef CONFIG_SME
Sunil Ravi640215c2023-06-28 23:08:09 +00004498 /*
4499 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
4500 * (for MLO connection) as the previous BSSID for subsequent
4501 * reassociation requests handled by SME-in-wpa_supplicant.
4502 */
4503 os_memcpy(wpa_s->sme.prev_bssid,
4504 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004505 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07004506 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004507#endif /* CONFIG_SME */
4508
4509 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
4510 if (wpa_s->current_ssid) {
4511 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
4512 * initialized before association, but for other modes,
4513 * initialize PC/SC here, if the current configuration needs
4514 * smartcard or SIM/USIM. */
4515 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
4516 }
4517 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004518
4519 if (wpa_sm_set_ml_info(wpa_s)) {
4520 wpa_dbg(wpa_s, MSG_INFO,
4521 "Failed to set MLO connection info to wpa_sm");
4522 wpa_supplicant_deauthenticate(wpa_s,
4523 WLAN_REASON_DEAUTH_LEAVING);
4524 return;
4525 }
4526
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004527 if (wpa_s->l2)
4528 l2_packet_notify_auth_start(wpa_s->l2);
4529
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004530 already_authorized = data && data->assoc_info.authorized;
4531
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004532 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07004533 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004534 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
4535 * state machine may transit to AUTHENTICATING state based on obsolete
4536 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
4537 * AUTHENTICATED without ever giving chance to EAP state machine to
4538 * reset the state.
4539 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004540 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07004541 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4542 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004543 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004544 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4545 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
4546 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07004547 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07004548 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004549 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07004550 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004551 wpa_s->eapol_received = 0;
4552 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4553 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4554 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004555 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004556 if (wpa_s->current_ssid &&
4557 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004558 (wpa_s->drv_flags &
4559 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4560 /*
4561 * Set the key after having received joined-IBSS event
4562 * from the driver.
4563 */
4564 wpa_supplicant_set_wpa_none_key(wpa_s,
4565 wpa_s->current_ssid);
4566 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004567 wpa_supplicant_cancel_auth_timeout(wpa_s);
4568 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4569 } else if (!ft_completed) {
4570 /* Timeout for receiving the first EAPOL packet */
4571 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
4572 }
4573 wpa_supplicant_cancel_scan(wpa_s);
4574
Hai Shalom5f92bc92019-04-18 11:54:11 -07004575 if (ft_completed) {
4576 /*
4577 * FT protocol completed - make sure EAPOL state machine ends
4578 * up in authenticated.
4579 */
4580 wpa_supplicant_cancel_auth_timeout(wpa_s);
4581 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004582 eapol_sm_notify_portValid(wpa_s->eapol, true);
4583 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07004584 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4585 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304586 if (already_authorized) {
4587 /*
4588 * We are done; the driver will take care of RSN 4-way
4589 * handshake.
4590 */
4591 wpa_supplicant_cancel_auth_timeout(wpa_s);
4592 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4593 eapol_sm_notify_portValid(wpa_s->eapol, true);
4594 eapol_sm_notify_eap_success(wpa_s->eapol, true);
4595 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004596 /* Update port, WPA_COMPLETED state from the
4597 * EVENT_PORT_AUTHORIZED handler when the driver is done
4598 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304599 */
Sunil Ravi167279a2023-05-31 01:12:34 +00004600 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004601 wpa_msg(wpa_s, MSG_INFO,
4602 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304603 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004604 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004605 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4606 /*
4607 * The driver will take care of RSN 4-way handshake, so we need
4608 * to allow EAPOL supplicant to complete its work without
4609 * waiting for WPA supplicant.
4610 */
Hai Shalome21d4e82020-04-29 16:34:06 -07004611 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004612 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004613#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05304614 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
4615 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4616 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
4617 wpa_s->key_mgmt);
4618 wpa_supplicant_deauthenticate(
4619 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4620 return;
4621 }
4622 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4623 wpa_s->assoc_freq = data->assoc_info.freq;
4624 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
4625 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004626#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
4627
Jouni Malinena05074c2012-12-21 21:35:35 +02004628 wpa_s->last_eapol_matches_bssid = 0;
4629
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004630#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07004631 if (wpa_s->rsne_override_eapol) {
4632 wpa_printf(MSG_DEBUG,
4633 "TESTING: RSNE EAPOL-Key msg 2/4 override");
4634 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4635 wpabuf_head(wpa_s->rsne_override_eapol),
4636 wpabuf_len(wpa_s->rsne_override_eapol));
4637 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004638 if (wpa_s->rsnxe_override_eapol) {
4639 wpa_printf(MSG_DEBUG,
4640 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4641 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4642 wpabuf_head(wpa_s->rsnxe_override_eapol),
4643 wpabuf_len(wpa_s->rsnxe_override_eapol));
4644 }
4645#endif /* CONFIG_TESTING_OPTIONS */
4646
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004647 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004648 struct os_reltime now, age;
4649 os_get_reltime(&now);
4650 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08004651 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004652 ether_addr_equal(wpa_s->pending_eapol_rx_src,
4653 wpa_s->valid_links ? wpa_s->ap_mld_addr :
4654 bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004655 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4656 "frame that was received just before "
4657 "association notification");
4658 wpa_supplicant_rx_eapol(
4659 wpa_s, wpa_s->pending_eapol_rx_src,
4660 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00004661 wpabuf_len(wpa_s->pending_eapol_rx),
4662 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004663 }
4664 wpabuf_free(wpa_s->pending_eapol_rx);
4665 wpa_s->pending_eapol_rx = NULL;
4666 }
4667
Hai Shalomfdcde762020-04-02 11:19:20 -07004668#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004669 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4670 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004671 wpa_s->current_ssid &&
4672 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004673 /* Set static WEP keys again */
4674 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4675 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004676#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004677
4678#ifdef CONFIG_IBSS_RSN
4679 if (wpa_s->current_ssid &&
4680 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4681 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4682 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4683 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004684 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004685 if (!wpa_s->ibss_rsn) {
4686 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4687 wpa_supplicant_deauthenticate(
4688 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4689 return;
4690 }
4691
4692 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4693 }
4694#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004695
4696 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004697
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004698#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004699 if (data) {
4700 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4701 data->assoc_info.resp_ies_len,
4702 &data->assoc_info.wmm_params);
4703
4704 if (wpa_s->reassoc_same_bss)
4705 wmm_ac_restore_tspecs(wpa_s);
4706 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004707#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004708
Hai Shalomc3565922019-10-28 11:58:20 -07004709#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4710 bss = wpa_bss_get_bssid(wpa_s, bssid);
4711#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004712#ifdef CONFIG_FILS
4713 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004714 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4715
4716 if (fils_cache_id)
4717 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4718 }
4719#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004720
4721#ifdef CONFIG_MBO
4722 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4723#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004724
4725#ifdef CONFIG_DPP2
4726 wpa_s->dpp_pfs_fallback = 0;
4727#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004728
4729 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4730 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004731}
4732
4733
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004734static int disconnect_reason_recoverable(u16 reason_code)
4735{
4736 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4737 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4738 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4739}
4740
4741
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004742static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004743 u16 reason_code,
4744 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004745{
4746 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004747
4748 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4749 /*
4750 * At least Host AP driver and a Prism3 card seemed to be
4751 * generating streams of disconnected events when configuring
4752 * IBSS for WPA-None. Ignore them for now.
4753 */
4754 return;
4755 }
4756
4757 bssid = wpa_s->bssid;
4758 if (is_zero_ether_addr(bssid))
4759 bssid = wpa_s->pending_bssid;
4760
4761 if (!is_zero_ether_addr(bssid) ||
4762 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4763 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4764 " reason=%d%s",
4765 MAC2STR(bssid), reason_code,
4766 locally_generated ? " locally_generated=1" : "");
4767 }
4768}
4769
4770
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004771static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4772 int locally_generated)
4773{
4774 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004775 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004776 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4777 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004778 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004779
4780 /*
4781 * It looks like connection was lost while trying to go through PSK
4782 * 4-way handshake. Filter out known disconnection cases that are caused
4783 * by something else than PSK mismatch to avoid confusing reports.
4784 */
4785
4786 if (locally_generated) {
4787 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4788 return 0;
4789 }
4790
4791 return 1;
4792}
4793
4794
Jouni Malinen2b89da82012-08-31 22:04:41 +03004795static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4796 u16 reason_code,
4797 int locally_generated)
4798{
4799 const u8 *bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004800 struct wpa_bss *fast_reconnect = NULL;
4801 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004802 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004803
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004804 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4805 /*
4806 * At least Host AP driver and a Prism3 card seemed to be
4807 * generating streams of disconnected events when configuring
4808 * IBSS for WPA-None. Ignore them for now.
4809 */
4810 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4811 "IBSS/WPA-None mode");
4812 return;
4813 }
4814
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004815 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4816 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4817 locally_generated)
4818 /*
4819 * Remove the inactive AP (which is probably out of range) from
4820 * the BSS list after marking disassociation. In particular
4821 * mac80211-based drivers use the
4822 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4823 * locally generated disconnection events for cases where the
4824 * AP does not reply anymore.
4825 */
4826 curr = wpa_s->current_bss;
4827
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004828 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004829 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4830 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004831 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4832 return; /* P2P group removed */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004833 wpas_auth_failed(wpa_s, "WRONG_KEY", wpa_s->pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004834 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004835#ifdef CONFIG_DPP2
4836 wpas_dpp_send_conn_status_result(wpa_s,
4837 DPP_STATUS_AUTH_FAILURE);
4838#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004839 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004840 if (!wpa_s->disconnected &&
4841 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004842 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004843 wpas_wps_searching(wpa_s) ||
4844 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004845 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004846 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004847 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004848 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004849 wpa_s->wpa_state);
4850 if (wpa_s->wpa_state == WPA_COMPLETED &&
4851 wpa_s->current_ssid &&
4852 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004853 (wpa_s->own_reconnect_req ||
4854 (!locally_generated &&
4855 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004856 /*
4857 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004858 * us, but could allow us to get back in. This is also
4859 * triggered for cases where local reconnection request
4860 * is used to force reassociation with the same BSS.
4861 * Try to reconnect to the same BSS without a full scan
4862 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004863 */
4864 fast_reconnect = wpa_s->current_bss;
4865 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004866 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004867 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004868 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004869 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4870 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004871 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004872 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004873 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004874 "try to re-connect");
4875 wpa_s->reassociate = 0;
4876 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004877 if (!wpa_s->pno)
4878 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004879 }
4880 bssid = wpa_s->bssid;
4881 if (is_zero_ether_addr(bssid))
4882 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004883 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004884 wpas_connection_failed(wpa_s, bssid, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004885 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004886 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4887
Dmitry Shmidt04949592012-07-19 12:16:46 -07004888 if (locally_generated)
4889 wpa_s->disconnect_reason = -reason_code;
4890 else
4891 wpa_s->disconnect_reason = reason_code;
4892 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004893 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4894 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004895 wpa_clear_keys(wpa_s, wpa_s->bssid);
4896 }
4897 wpa_supplicant_mark_disassoc(wpa_s);
4898
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004899 if (curr)
4900 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4901
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004902 if (fast_reconnect &&
4903 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4904 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4905 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4906 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004907 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004908 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004909#ifndef CONFIG_NO_SCAN_PROCESSING
4910 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4911 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4912 fast_reconnect_ssid) < 0) {
4913 /* Recover through full scan */
4914 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4915 }
4916#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004917 } else if (fast_reconnect) {
4918 /*
4919 * Could not reconnect to the same BSS due to network being
4920 * disabled. Use a new scan to match the alternative behavior
4921 * above, i.e., to continue automatic reconnection attempt in a
4922 * way that enforces disabled network rules.
4923 */
4924 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004925 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004926}
4927
4928
4929#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004930void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004931{
4932 struct wpa_supplicant *wpa_s = eloop_ctx;
4933
4934 if (!wpa_s->pending_mic_error_report)
4935 return;
4936
4937 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4938 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4939 wpa_s->pending_mic_error_report = 0;
4940}
4941#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4942
4943
4944static void
4945wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4946 union wpa_event_data *data)
4947{
4948 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004949 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004950
4951 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4952 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004953 os_get_reltime(&t);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004954 if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004955 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004956 wpa_s->pending_mic_error_report) {
4957 if (wpa_s->pending_mic_error_report) {
4958 /*
4959 * Send the pending MIC error report immediately since
4960 * we are going to start countermeasures and AP better
4961 * do the same.
4962 */
4963 wpa_sm_key_request(wpa_s->wpa, 1,
4964 wpa_s->pending_mic_error_pairwise);
4965 }
4966
4967 /* Send the new MIC error report immediately since we are going
4968 * to start countermeasures and AP better do the same.
4969 */
4970 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4971
4972 /* initialize countermeasures */
4973 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004974
Hai Shalom60840252021-02-19 19:02:11 -08004975 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004976
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004977 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4978
4979 /*
4980 * Need to wait for completion of request frame. We do not get
4981 * any callback for the message completion, so just wait a
4982 * short while and hope for the best. */
4983 os_sleep(0, 10000);
4984
4985 wpa_drv_set_countermeasures(wpa_s, 1);
4986 wpa_supplicant_deauthenticate(wpa_s,
4987 WLAN_REASON_MICHAEL_MIC_FAILURE);
4988 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4989 wpa_s, NULL);
4990 eloop_register_timeout(60, 0,
4991 wpa_supplicant_stop_countermeasures,
4992 wpa_s, NULL);
4993 /* TODO: mark the AP rejected for 60 second. STA is
4994 * allowed to associate with another AP.. */
4995 } else {
4996#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4997 if (wpa_s->mic_errors_seen) {
4998 /*
4999 * Reduce the effectiveness of Michael MIC error
5000 * reports as a means for attacking against TKIP if
5001 * more than one MIC failure is noticed with the same
5002 * PTK. We delay the transmission of the reports by a
5003 * random time between 0 and 60 seconds in order to
5004 * force the attacker wait 60 seconds before getting
5005 * the information on whether a frame resulted in a MIC
5006 * failure.
5007 */
5008 u8 rval[4];
5009 int sec;
5010
5011 if (os_get_random(rval, sizeof(rval)) < 0)
5012 sec = os_random() % 60;
5013 else
5014 sec = WPA_GET_BE32(rval) % 60;
5015 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
5016 "report %d seconds", sec);
5017 wpa_s->pending_mic_error_report = 1;
5018 wpa_s->pending_mic_error_pairwise = pairwise;
5019 eloop_cancel_timeout(
5020 wpa_supplicant_delayed_mic_error_report,
5021 wpa_s, NULL);
5022 eloop_register_timeout(
5023 sec, os_random() % 1000000,
5024 wpa_supplicant_delayed_mic_error_report,
5025 wpa_s, NULL);
5026 } else {
5027 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
5028 }
5029#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
5030 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
5031#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
5032 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005033 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005034 wpa_s->mic_errors_seen++;
5035}
5036
5037
5038#ifdef CONFIG_TERMINATE_ONLASTIF
5039static int any_interfaces(struct wpa_supplicant *head)
5040{
5041 struct wpa_supplicant *wpa_s;
5042
5043 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
5044 if (!wpa_s->interface_removed)
5045 return 1;
5046 return 0;
5047}
5048#endif /* CONFIG_TERMINATE_ONLASTIF */
5049
5050
5051static void
5052wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
5053 union wpa_event_data *data)
5054{
5055 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
5056 return;
5057
5058 switch (data->interface_status.ievent) {
5059 case EVENT_INTERFACE_ADDED:
5060 if (!wpa_s->interface_removed)
5061 break;
5062 wpa_s->interface_removed = 0;
5063 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
5064 if (wpa_supplicant_driver_init(wpa_s) < 0) {
5065 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
5066 "driver after interface was added");
5067 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005068
5069#ifdef CONFIG_P2P
5070 if (!wpa_s->global->p2p &&
5071 !wpa_s->global->p2p_disabled &&
5072 !wpa_s->conf->p2p_disabled &&
5073 (wpa_s->drv_flags &
5074 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
5075 wpas_p2p_add_p2pdev_interface(
5076 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
5077 wpa_printf(MSG_INFO,
5078 "P2P: Failed to enable P2P Device interface");
5079 /* Try to continue without. P2P will be disabled. */
5080 }
5081#endif /* CONFIG_P2P */
5082
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005083 break;
5084 case EVENT_INTERFACE_REMOVED:
5085 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
5086 wpa_s->interface_removed = 1;
5087 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005088 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005089 l2_packet_deinit(wpa_s->l2);
5090 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005091
5092#ifdef CONFIG_P2P
5093 if (wpa_s->global->p2p &&
5094 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
5095 (wpa_s->drv_flags &
5096 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
5097 wpa_dbg(wpa_s, MSG_DEBUG,
5098 "Removing P2P Device interface");
5099 wpa_supplicant_remove_iface(
5100 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
5101 0);
5102 wpa_s->global->p2p_init_wpa_s = NULL;
5103 }
5104#endif /* CONFIG_P2P */
5105
Dmitry Shmidte4663042016-04-04 10:07:49 -07005106#ifdef CONFIG_MATCH_IFACE
5107 if (wpa_s->matched) {
5108 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
5109 break;
5110 }
5111#endif /* CONFIG_MATCH_IFACE */
5112
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005113#ifdef CONFIG_TERMINATE_ONLASTIF
5114 /* check if last interface */
5115 if (!any_interfaces(wpa_s->global->ifaces))
5116 eloop_terminate();
5117#endif /* CONFIG_TERMINATE_ONLASTIF */
5118 break;
5119 }
5120}
5121
5122
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005123#ifdef CONFIG_TDLS
5124static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
5125 union wpa_event_data *data)
5126{
5127 if (data == NULL)
5128 return;
5129 switch (data->tdls.oper) {
5130 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005131 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
5132 if (wpa_tdls_is_external_setup(wpa_s->wpa))
5133 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
5134 else
5135 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005136 break;
5137 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03005138 if (wpa_tdls_is_external_setup(wpa_s->wpa))
5139 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
5140 data->tdls.reason_code);
5141 else
5142 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
5143 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005144 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07005145 case TDLS_REQUEST_DISCOVER:
5146 wpa_tdls_send_discovery_request(wpa_s->wpa,
5147 data->tdls.peer);
5148 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005149 }
5150}
5151#endif /* CONFIG_TDLS */
5152
5153
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005154#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005155static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
5156 union wpa_event_data *data)
5157{
5158 if (data == NULL)
5159 return;
5160 switch (data->wnm.oper) {
5161 case WNM_OPER_SLEEP:
5162 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
5163 "(action=%d, intval=%d)",
5164 data->wnm.sleep_action, data->wnm.sleep_intval);
5165 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005166 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005167 break;
5168 }
5169}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005170#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005171
5172
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005173#ifdef CONFIG_IEEE80211R
5174static void
5175wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
5176 union wpa_event_data *data)
5177{
5178 if (data == NULL)
5179 return;
5180
5181 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
5182 data->ft_ies.ies_len,
5183 data->ft_ies.ft_action,
5184 data->ft_ies.target_ap,
5185 data->ft_ies.ric_ies,
5186 data->ft_ies.ric_ies_len) < 0) {
5187 /* TODO: prevent MLME/driver from trying to associate? */
5188 }
5189}
5190#endif /* CONFIG_IEEE80211R */
5191
5192
5193#ifdef CONFIG_IBSS_RSN
5194static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
5195 union wpa_event_data *data)
5196{
5197 struct wpa_ssid *ssid;
5198 if (wpa_s->wpa_state < WPA_ASSOCIATED)
5199 return;
5200 if (data == NULL)
5201 return;
5202 ssid = wpa_s->current_ssid;
5203 if (ssid == NULL)
5204 return;
5205 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5206 return;
5207
5208 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
5209}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005210
5211
5212static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
5213 union wpa_event_data *data)
5214{
5215 struct wpa_ssid *ssid = wpa_s->current_ssid;
5216
5217 if (ssid == NULL)
5218 return;
5219
5220 /* check if the ssid is correctly configured as IBSS/RSN */
5221 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5222 return;
5223
5224 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
5225 data->rx_mgmt.frame_len);
5226}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005227#endif /* CONFIG_IBSS_RSN */
5228
5229
5230#ifdef CONFIG_IEEE80211R
5231static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
5232 size_t len)
5233{
5234 const u8 *sta_addr, *target_ap_addr;
5235 u16 status;
5236
5237 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
5238 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
5239 return; /* only SME case supported for now */
5240 if (len < 1 + 2 * ETH_ALEN + 2)
5241 return;
5242 if (data[0] != 2)
5243 return; /* Only FT Action Response is supported for now */
5244 sta_addr = data + 1;
5245 target_ap_addr = data + 1 + ETH_ALEN;
5246 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
5247 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
5248 MACSTR " TargetAP " MACSTR " status %u",
5249 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
5250
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005251 if (!ether_addr_equal(sta_addr, wpa_s->own_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005252 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
5253 " in FT Action Response", MAC2STR(sta_addr));
5254 return;
5255 }
5256
5257 if (status) {
5258 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
5259 "failure (status code %d)", status);
5260 /* TODO: report error to FT code(?) */
5261 return;
5262 }
5263
5264 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
5265 len - (1 + 2 * ETH_ALEN + 2), 1,
5266 target_ap_addr, NULL, 0) < 0)
5267 return;
5268
5269#ifdef CONFIG_SME
5270 {
5271 struct wpa_bss *bss;
5272 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
5273 if (bss)
5274 wpa_s->sme.freq = bss->freq;
5275 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
5276 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
5277 WLAN_AUTH_FT);
5278 }
5279#endif /* CONFIG_SME */
5280}
5281#endif /* CONFIG_IEEE80211R */
5282
5283
5284static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
5285 struct unprot_deauth *e)
5286{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005287 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
5288 "dropped: " MACSTR " -> " MACSTR
5289 " (reason code %u)",
5290 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5291 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005292}
5293
5294
5295static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
5296 struct unprot_disassoc *e)
5297{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005298 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
5299 "dropped: " MACSTR " -> " MACSTR
5300 " (reason code %u)",
5301 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5302 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005303}
5304
5305
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005306static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
5307 u16 reason_code, int locally_generated,
5308 const u8 *ie, size_t ie_len, int deauth)
5309{
5310#ifdef CONFIG_AP
5311 if (wpa_s->ap_iface && addr) {
5312 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
5313 return;
5314 }
5315
5316 if (wpa_s->ap_iface) {
5317 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
5318 return;
5319 }
5320#endif /* CONFIG_AP */
5321
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005322 if (!locally_generated)
5323 wpa_s->own_disconnect_req = 0;
5324
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005325 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
5326
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005327 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
5328 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
5329 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
5330 eapol_sm_failed(wpa_s->eapol))) &&
5331 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00005332 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005333
5334#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07005335 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005336 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
5337 locally_generated) > 0) {
5338 /*
5339 * The interface was removed, so cannot continue
5340 * processing any additional operations after this.
5341 */
5342 return;
5343 }
5344 }
5345#endif /* CONFIG_P2P */
5346
5347 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
5348 locally_generated);
5349}
5350
5351
5352static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
5353 struct disassoc_info *info)
5354{
5355 u16 reason_code = 0;
5356 int locally_generated = 0;
5357 const u8 *addr = NULL;
5358 const u8 *ie = NULL;
5359 size_t ie_len = 0;
5360
5361 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
5362
5363 if (info) {
5364 addr = info->addr;
5365 ie = info->ie;
5366 ie_len = info->ie_len;
5367 reason_code = info->reason_code;
5368 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005369 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
5370 reason2str(reason_code),
5371 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005372 if (addr)
5373 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5374 MAC2STR(addr));
5375 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
5376 ie, ie_len);
5377 }
5378
5379#ifdef CONFIG_AP
5380 if (wpa_s->ap_iface && info && info->addr) {
5381 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
5382 return;
5383 }
5384
5385 if (wpa_s->ap_iface) {
5386 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
5387 return;
5388 }
5389#endif /* CONFIG_AP */
5390
5391#ifdef CONFIG_P2P
5392 if (info) {
5393 wpas_p2p_disassoc_notif(
5394 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
5395 locally_generated);
5396 }
5397#endif /* CONFIG_P2P */
5398
5399 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5400 sme_event_disassoc(wpa_s, info);
5401
5402 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
5403 ie, ie_len, 0);
5404}
5405
5406
5407static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
5408 struct deauth_info *info)
5409{
5410 u16 reason_code = 0;
5411 int locally_generated = 0;
5412 const u8 *addr = NULL;
5413 const u8 *ie = NULL;
5414 size_t ie_len = 0;
5415
5416 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
5417
5418 if (info) {
5419 addr = info->addr;
5420 ie = info->ie;
5421 ie_len = info->ie_len;
5422 reason_code = info->reason_code;
5423 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005424 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
5425 reason_code, reason2str(reason_code),
5426 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005427 if (addr) {
5428 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5429 MAC2STR(addr));
5430 }
5431 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
5432 ie, ie_len);
5433 }
5434
5435 wpa_reset_ft_completed(wpa_s->wpa);
5436
5437 wpas_event_disconnect(wpa_s, addr, reason_code,
5438 locally_generated, ie, ie_len, 1);
5439}
5440
5441
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005442static const char * reg_init_str(enum reg_change_initiator init)
5443{
5444 switch (init) {
5445 case REGDOM_SET_BY_CORE:
5446 return "CORE";
5447 case REGDOM_SET_BY_USER:
5448 return "USER";
5449 case REGDOM_SET_BY_DRIVER:
5450 return "DRIVER";
5451 case REGDOM_SET_BY_COUNTRY_IE:
5452 return "COUNTRY_IE";
5453 case REGDOM_BEACON_HINT:
5454 return "BEACON_HINT";
5455 }
5456 return "?";
5457}
5458
5459
5460static const char * reg_type_str(enum reg_type type)
5461{
5462 switch (type) {
5463 case REGDOM_TYPE_UNKNOWN:
5464 return "UNKNOWN";
5465 case REGDOM_TYPE_COUNTRY:
5466 return "COUNTRY";
5467 case REGDOM_TYPE_WORLD:
5468 return "WORLD";
5469 case REGDOM_TYPE_CUSTOM_WORLD:
5470 return "CUSTOM_WORLD";
5471 case REGDOM_TYPE_INTERSECTION:
5472 return "INTERSECTION";
5473 }
5474 return "?";
5475}
5476
5477
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005478static void wpas_beacon_hint(struct wpa_supplicant *wpa_s, const char *title,
5479 struct frequency_attrs *attrs)
5480{
5481 if (!attrs->freq)
5482 return;
5483 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_BEACON_HINT
5484 "%s freq=%u max_tx_power=%u%s%s%s",
5485 title, attrs->freq, attrs->max_tx_power,
5486 attrs->disabled ? " disabled=1" : "",
5487 attrs->no_ir ? " no_ir=1" : "",
5488 attrs->radar ? " radar=1" : "");
5489}
5490
5491
Hai Shalom74f70d42019-02-11 14:42:39 -08005492void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
5493 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005494{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005495 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005496 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005497
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005498 /*
5499 * To allow backwards compatibility with higher level layers that
5500 * assumed the REGDOM_CHANGE event is sent over the initially added
5501 * interface. Find the highest parent of this interface and use it to
5502 * send the event.
5503 */
5504 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
5505 ;
5506
Hai Shalom74f70d42019-02-11 14:42:39 -08005507 if (info) {
5508 wpa_msg(ifs, MSG_INFO,
5509 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
5510 reg_init_str(info->initiator), reg_type_str(info->type),
5511 info->alpha2[0] ? " alpha2=" : "",
5512 info->alpha2[0] ? info->alpha2 : "");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005513
5514 if (info->initiator == REGDOM_BEACON_HINT) {
5515 wpas_beacon_hint(ifs, "before",
5516 &info->beacon_hint_before);
5517 wpas_beacon_hint(ifs, "after",
5518 &info->beacon_hint_after);
5519 }
Hai Shalom74f70d42019-02-11 14:42:39 -08005520 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005521
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005522 if (wpa_s->drv_priv == NULL)
5523 return; /* Ignore event during drv initialization */
5524
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005525 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
5526 radio_list) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005527 bool was_6ghz_enabled;
5528
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005529 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
5530 ifs->ifname);
5531 free_hw_features(ifs);
5532 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005533 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005534
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005535 was_6ghz_enabled = ifs->is_6ghz_enabled;
5536 ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5537
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005538 /* Restart PNO/sched_scan with updated channel list */
5539 if (ifs->pno) {
5540 wpas_stop_pno(ifs);
5541 wpas_start_pno(ifs);
5542 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
5543 wpa_dbg(ifs, MSG_DEBUG,
5544 "Channel list changed - restart sched_scan");
5545 wpas_scan_restart_sched_scan(ifs);
Sunil Ravi7f769292024-07-23 22:21:32 +00005546 } else if (!was_6ghz_enabled && ifs->is_6ghz_enabled) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005547 wpa_dbg(ifs, MSG_INFO,
Sunil Ravi7f769292024-07-23 22:21:32 +00005548 "Channel list changed: 6 GHz was enabled");
5549
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005550 ifs->crossed_6ghz_dom = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005551 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005552 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005553
5554 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005555}
5556
5557
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005558static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005559 const u8 *frame, size_t len, int freq,
5560 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005561{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005562 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005563 const u8 *payload;
5564 size_t plen;
5565 u8 category;
5566
5567 if (len < IEEE80211_HDRLEN + 2)
5568 return;
5569
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005570 mgmt = (const struct ieee80211_mgmt *) frame;
5571 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005572 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005573 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005574
5575 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
5576 " Category=%u DataLen=%d freq=%d MHz",
5577 MAC2STR(mgmt->sa), category, (int) plen, freq);
5578
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005579#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005580 if (category == WLAN_ACTION_WMM) {
5581 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5582 return;
5583 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005584#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005585
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005586#ifdef CONFIG_IEEE80211R
5587 if (category == WLAN_ACTION_FT) {
5588 ft_rx_action(wpa_s, payload, plen);
5589 return;
5590 }
5591#endif /* CONFIG_IEEE80211R */
5592
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005593#ifdef CONFIG_SME
5594 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005595 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005596 return;
5597 }
5598#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005599
5600#ifdef CONFIG_WNM
5601 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
5602 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
5603 return;
5604 }
5605#endif /* CONFIG_WNM */
5606
5607#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08005608 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5609 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005610 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08005611 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005612 payload, plen, freq) == 0)
5613 return;
5614#endif /* CONFIG_GAS */
5615
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005616#ifdef CONFIG_GAS_SERVER
5617 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5618 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
5619 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
5620 mgmt->u.action.category,
5621 payload, plen, freq) == 0)
5622 return;
5623#endif /* CONFIG_GAS_SERVER */
5624
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005625#ifdef CONFIG_TDLS
5626 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
5627 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
5628 wpa_dbg(wpa_s, MSG_DEBUG,
5629 "TDLS: Received Discovery Response from " MACSTR,
5630 MAC2STR(mgmt->sa));
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005631 if (wpa_s->valid_links &&
5632 wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa,
5633 &payload[1], plen - 1))
5634 wpa_dbg(wpa_s, MSG_ERROR,
5635 "TDLS: Discovery Response process failed for "
5636 MACSTR, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005637 return;
5638 }
5639#endif /* CONFIG_TDLS */
5640
5641#ifdef CONFIG_INTERWORKING
5642 if (category == WLAN_ACTION_QOS && plen >= 1 &&
5643 payload[0] == QOS_QOS_MAP_CONFIG) {
5644 const u8 *pos = payload + 1;
5645 size_t qlen = plen - 1;
5646 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
5647 MACSTR, MAC2STR(mgmt->sa));
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005648 if (ether_addr_equal(mgmt->sa, wpa_s->bssid) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005649 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
5650 pos[1] <= qlen - 2 && pos[1] >= 16)
5651 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
5652 return;
5653 }
5654#endif /* CONFIG_INTERWORKING */
5655
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005656#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005657 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005658 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5659 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005660 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005661 payload + 1,
5662 plen - 1);
5663 return;
5664 }
5665
5666 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005667 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
5668 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
5669 return;
5670 }
5671
5672 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5673 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
5674 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
5675 payload + 1, plen - 1,
5676 rssi);
5677 return;
5678 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005679#endif /* CONFIG_NO_RRM */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005680
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005681#ifdef CONFIG_FST
5682 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
5683 fst_rx_action(wpa_s->fst, mgmt, len);
5684 return;
5685 }
5686#endif /* CONFIG_FST */
5687
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005688#ifdef CONFIG_NAN_USD
5689 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5690 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5691 WPA_GET_BE32(&payload[1]) == NAN_SDF_VENDOR_TYPE) {
5692 payload += 5;
5693 plen -= 5;
5694 wpas_nan_usd_rx_sdf(wpa_s, mgmt->sa, freq, payload, plen);
5695 return;
5696 }
5697#endif /* CONFIG_NAN_USD */
5698
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005699#ifdef CONFIG_DPP
5700 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5701 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5702 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
5703 payload[4] == DPP_OUI_TYPE) {
5704 payload++;
5705 plen--;
5706 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
5707 return;
5708 }
5709#endif /* CONFIG_DPP */
5710
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005711#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07005712 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08005713 payload[0] == ROBUST_AV_SCS_RESP) {
5714 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
5715 payload + 1, plen - 1);
5716 return;
5717 }
5718
5719 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005720 payload[0] == ROBUST_AV_MSCS_RESP) {
5721 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5722 payload + 1, plen - 1);
5723 return;
5724 }
5725
Hai Shalomc1a21442022-02-04 13:43:00 -08005726 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
5727 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
5728 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
5729 payload + 4, plen - 4);
5730 return;
5731 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005732#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08005733
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005734 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5735 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005736 if (wpa_s->ifmsh)
5737 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005738}
5739
5740
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005741static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5742 union wpa_event_data *event)
5743{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005744 struct wpa_freq_range_list *list;
5745 char *str = NULL;
5746
5747 list = &event->freq_range;
5748
5749 if (list->num)
5750 str = freq_range_list_str(list);
5751 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5752 str ? str : "");
5753
5754#ifdef CONFIG_P2P
5755 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5756 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5757 __func__);
5758 } else {
5759 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005760
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005761 /*
5762 * The update channel flow will also take care of moving a GO
5763 * from the unsafe frequency if needed.
5764 */
5765 wpas_p2p_update_channel_list(wpa_s,
5766 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005767 }
5768#endif /* CONFIG_P2P */
5769
5770 os_free(str);
5771}
5772
5773
Roshan Pius3a1667e2018-07-03 15:17:14 -07005774static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005775{
Sunil Ravi167279a2023-05-31 01:12:34 +00005776 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005777 wpa_supplicant_cancel_auth_timeout(wpa_s);
5778 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005779 eapol_sm_notify_portValid(wpa_s->eapol, true);
5780 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005781 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005782 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005783}
5784
5785
5786static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5787 int freq)
5788{
5789 size_t i;
5790 int j;
5791
5792 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5793 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5794
5795 for (j = 0; j < mode->num_channels; j++) {
5796 const struct hostapd_channel_data *chan;
5797
5798 chan = &mode->channels[j];
5799 if (chan->freq == freq)
5800 return chan->dfs_cac_ms;
5801 }
5802 }
5803
5804 return 0;
5805}
5806
5807
5808static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5809 struct dfs_event *radar)
5810{
5811#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005812 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005813 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5814 } else
5815#endif /* NEED_AP_MLME && CONFIG_AP */
5816 {
5817 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5818
5819 cac_time /= 1000; /* convert from ms to sec */
5820 if (!cac_time)
5821 cac_time = 10 * 60; /* max timeout: 10 minutes */
5822
5823 /* Restart auth timeout: CAC time added to initial timeout */
5824 wpas_auth_timeout_restart(wpa_s, cac_time);
5825 }
5826}
5827
5828
5829static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5830 struct dfs_event *radar)
5831{
5832#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005833 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005834 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5835 } else
5836#endif /* NEED_AP_MLME && CONFIG_AP */
5837 {
5838 /* Restart auth timeout with original value after CAC is
5839 * finished */
5840 wpas_auth_timeout_restart(wpa_s, 0);
5841 }
5842}
5843
5844
5845static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5846 struct dfs_event *radar)
5847{
5848#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005849 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005850 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5851 } else
5852#endif /* NEED_AP_MLME && CONFIG_AP */
5853 {
5854 /* Restart auth timeout with original value after CAC is
5855 * aborted */
5856 wpas_auth_timeout_restart(wpa_s, 0);
5857 }
5858}
5859
5860
5861static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5862 union wpa_event_data *data)
5863{
5864 wpa_dbg(wpa_s, MSG_DEBUG,
5865 "Connection authorized by device, previous state %d",
5866 wpa_s->wpa_state);
5867
5868 wpa_supplicant_event_port_authorized(wpa_s);
5869
Hai Shalomc1a21442022-02-04 13:43:00 -08005870 wpa_s->last_eapol_matches_bssid = 1;
5871
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005872 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5873 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005874 data->assoc_info.ptk_kck_len,
5875 data->assoc_info.ptk_kek,
5876 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005877#ifdef CONFIG_FILS
5878 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5879 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5880 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5881
5882 /* Update ERP next sequence number */
5883 eapol_sm_update_erp_next_seq_num(
5884 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5885
5886 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5887 /* Add the new PMK and PMKID to the PMKSA cache */
5888 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5889 data->assoc_info.fils_pmk,
5890 data->assoc_info.fils_pmk_len,
5891 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005892 wpa_s->valid_links ?
5893 wpa_s->ap_mld_addr :
5894 wpa_s->bssid,
5895 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005896 } else if (data->assoc_info.fils_pmkid) {
5897 /* Update the current PMKSA used for this connection */
5898 pmksa_cache_set_current(wpa_s->wpa,
5899 data->assoc_info.fils_pmkid,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005900 NULL, NULL, 0, NULL, 0, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005901 }
5902 }
5903#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005904}
5905
5906
Hai Shalom60840252021-02-19 19:02:11 -08005907static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5908{
5909 switch (code) {
5910 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5911 return "";
5912 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5913 return "no_bss_found";
5914 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5915 return "auth_tx_fail";
5916 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5917 return "auth_no_ack_received";
5918 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5919 return "auth_no_resp_received";
5920 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5921 return "assoc_req_tx_fail";
5922 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5923 return "assoc_no_ack_received";
5924 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5925 return "assoc_no_resp_received";
5926 default:
5927 return "unknown_reason";
5928 }
5929}
5930
5931
Roshan Pius3a1667e2018-07-03 15:17:14 -07005932static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5933 union wpa_event_data *data)
5934{
5935 const u8 *bssid = data->assoc_reject.bssid;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005936 struct ieee802_11_elems elems;
Sunil Ravi7f769292024-07-23 22:21:32 +00005937 struct ml_sta_link_info ml_info[MAX_NUM_MLD_LINKS];
5938 const u8 *link_bssids[MAX_NUM_MLD_LINKS + 1];
Hai Shalom81f62d82019-07-22 12:10:00 -07005939#ifdef CONFIG_MBO
5940 struct wpa_bss *reject_bss;
5941#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005942
5943 if (!bssid || is_zero_ether_addr(bssid))
5944 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005945#ifdef CONFIG_MBO
5946 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5947 reject_bss = wpa_s->current_bss;
5948 else
5949 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5950#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005951
5952 if (data->assoc_reject.bssid)
5953 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005954 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005955 MAC2STR(data->assoc_reject.bssid),
5956 data->assoc_reject.status_code,
5957 data->assoc_reject.timed_out ? " timeout" : "",
5958 data->assoc_reject.timeout_reason ? "=" : "",
5959 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005960 data->assoc_reject.timeout_reason : "",
5961 data->assoc_reject.reason_code !=
5962 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5963 " qca_driver_reason=" : "",
5964 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005965 else
5966 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005967 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005968 data->assoc_reject.status_code,
5969 data->assoc_reject.timed_out ? " timeout" : "",
5970 data->assoc_reject.timeout_reason ? "=" : "",
5971 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005972 data->assoc_reject.timeout_reason : "",
5973 data->assoc_reject.reason_code !=
5974 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5975 " qca_driver_reason=" : "",
5976 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005977 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005978 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5979 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005980
5981#ifdef CONFIG_OWE
5982 if (data->assoc_reject.status_code ==
5983 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5984 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5985 wpa_s->current_ssid &&
5986 wpa_s->current_ssid->owe_group == 0 &&
5987 wpa_s->last_owe_group != 21) {
5988 struct wpa_ssid *ssid = wpa_s->current_ssid;
5989 struct wpa_bss *bss = wpa_s->current_bss;
5990
5991 if (!bss) {
5992 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5993 if (!bss) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005994 wpas_connection_failed(wpa_s, bssid, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005995 wpa_supplicant_mark_disassoc(wpa_s);
5996 return;
5997 }
5998 }
5999 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
6000 wpas_connect_work_done(wpa_s);
6001 wpa_supplicant_mark_disassoc(wpa_s);
6002 wpa_supplicant_connect(wpa_s, bss, ssid);
6003 return;
6004 }
6005#endif /* CONFIG_OWE */
6006
Hai Shalomfdcde762020-04-02 11:19:20 -07006007#ifdef CONFIG_DPP2
6008 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
6009 * the status code defined in the DPP R2 tech spec.
6010 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
6011 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006012 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07006013 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
6014 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
6015 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07006016 wpa_s->current_ssid->dpp_pfs == 0 &&
6017 (data->assoc_reject.status_code ==
6018 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
6019 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
6020 struct wpa_ssid *ssid = wpa_s->current_ssid;
6021 struct wpa_bss *bss = wpa_s->current_bss;
6022
6023 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
6024 if (!bss)
6025 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
6026 if (!bss || wpa_s->dpp_pfs_fallback) {
6027 wpa_printf(MSG_DEBUG,
6028 "DPP: Updated PFS policy for next try");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006029 wpas_connection_failed(wpa_s, bssid, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07006030 wpa_supplicant_mark_disassoc(wpa_s);
6031 return;
6032 }
6033 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
6034 wpa_s->dpp_pfs_fallback = 1;
6035 wpas_connect_work_done(wpa_s);
6036 wpa_supplicant_mark_disassoc(wpa_s);
6037 wpa_supplicant_connect(wpa_s, bss, ssid);
6038 return;
6039 }
6040#endif /* CONFIG_DPP2 */
6041
Hai Shalom74f70d42019-02-11 14:42:39 -08006042#ifdef CONFIG_MBO
6043 if (data->assoc_reject.status_code ==
6044 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07006045 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08006046 const u8 *rssi_rej;
6047
6048 rssi_rej = mbo_get_attr_from_ies(
6049 data->assoc_reject.resp_ies,
6050 data->assoc_reject.resp_ies_len,
6051 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
6052 if (rssi_rej && rssi_rej[1] == 2) {
6053 wpa_printf(MSG_DEBUG,
6054 "OCE: RSSI-based association rejection from "
6055 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07006056 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08006057 rssi_rej[2], rssi_rej[3]);
6058 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07006059 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08006060 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07006061 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08006062 }
6063 }
6064#endif /* CONFIG_MBO */
6065
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006066 /* Check for other failed links in the response */
6067 os_memset(link_bssids, 0, sizeof(link_bssids));
6068 if (ieee802_11_parse_elems(data->assoc_reject.resp_ies,
6069 data->assoc_reject.resp_ies_len,
6070 &elems, 1) != ParseFailed) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006071 unsigned int n_links, i, idx;
6072
6073 idx = 0;
6074 n_links = wpas_ml_parse_assoc(wpa_s, &elems, ml_info);
6075
6076 for (i = 1; i < n_links; i++) {
6077 /* The status cannot be success here.
6078 * Add the link to the failed list if it is reporting
6079 * an error. The only valid "non-error" status is
6080 * TX_LINK_NOT_ACCEPTED as that means this link may
6081 * still accept an association from us.
6082 */
6083 if (ml_info[i].status !=
6084 WLAN_STATUS_DENIED_TX_LINK_NOT_ACCEPTED) {
6085 link_bssids[idx] = ml_info[i].bssid;
6086 idx++;
6087 }
6088 }
6089 }
6090
Roshan Pius3a1667e2018-07-03 15:17:14 -07006091 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006092 sme_event_assoc_reject(wpa_s, data, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006093 return;
6094 }
6095
6096 /* Driver-based SME cases */
6097
6098#ifdef CONFIG_SAE
6099 if (wpa_s->current_ssid &&
6100 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
6101 !data->assoc_reject.timed_out) {
6102 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
6103 wpa_sm_aborted_cached(wpa_s->wpa);
6104 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
6105 }
6106#endif /* CONFIG_SAE */
6107
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006108#ifdef CONFIG_DPP
6109 if (wpa_s->current_ssid &&
6110 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
6111 !data->assoc_reject.timed_out) {
6112 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
6113 wpa_sm_aborted_cached(wpa_s->wpa);
6114 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
6115 }
6116#endif /* CONFIG_DPP */
6117
Roshan Pius3a1667e2018-07-03 15:17:14 -07006118#ifdef CONFIG_FILS
6119 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07006120 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006121 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006122 eapol_sm_update_erp_next_seq_num(
6123 wpa_s->eapol,
6124 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07006125 fils_connection_failure(wpa_s);
6126 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006127#endif /* CONFIG_FILS */
6128
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006129 wpas_connection_failed(wpa_s, bssid, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006130 wpa_supplicant_mark_disassoc(wpa_s);
6131}
6132
6133
Hai Shalomfdcde762020-04-02 11:19:20 -07006134static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
6135 struct unprot_beacon *data)
6136{
6137 struct wpabuf *buf;
6138 int res;
6139
6140 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006141 !ether_addr_equal(data->sa, wpa_s->bssid))
Hai Shalomfdcde762020-04-02 11:19:20 -07006142 return;
6143 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
6144 MAC2STR(data->sa));
6145
6146 buf = wpabuf_alloc(4);
6147 if (!buf)
6148 return;
6149
6150 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
6151 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
6152 wpabuf_put_u8(buf, 1); /* Dialog Token */
6153 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
6154
6155 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
6156 wpa_s->own_addr, wpa_s->bssid,
6157 wpabuf_head(buf), wpabuf_len(buf), 0);
6158 if (res < 0)
6159 wpa_printf(MSG_DEBUG,
6160 "Failed to send WNM-Notification Request frame");
6161
6162 wpabuf_free(buf);
6163}
6164
6165
Sunil Ravi640215c2023-06-28 23:08:09 +00006166static const char * bitmap_to_str(u8 value, char *buf)
6167{
6168 char *pos = buf;
6169 int i, k = 0;
6170
6171 for (i = 7; i >= 0; i--)
6172 pos[k++] = (value & BIT(i)) ? '1' : '0';
6173
6174 pos[8] = '\0';
6175 return pos;
6176}
6177
6178
6179static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
6180 struct tid_link_map_info *info)
6181{
6182 char map_info[1000], *pos, *end;
6183 int res, i;
6184
6185 pos = map_info;
6186 end = pos + sizeof(map_info);
6187 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
6188 info->default_map);
6189 if (os_snprintf_error(end - pos, res))
6190 return;
6191 pos += res;
6192
6193 if (!info->default_map) {
Sunil Ravi99c035e2024-07-12 01:42:03 +00006194 for_each_link(info->valid_links, i) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006195 char uplink_map_str[9];
6196 char downlink_map_str[9];
6197
Sunil Ravi640215c2023-06-28 23:08:09 +00006198 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
6199 bitmap_to_str(info->t2lmap[i].downlink,
6200 downlink_map_str);
6201
6202 res = os_snprintf(pos, end - pos,
6203 " link_id=%d up_link=%s down_link=%s",
6204 i, uplink_map_str,
6205 downlink_map_str);
6206 if (os_snprintf_error(end - pos, res))
6207 return;
6208 pos += res;
6209 }
6210 }
6211
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306212 wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP);
Sunil Ravi640215c2023-06-28 23:08:09 +00006213 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
6214}
6215
6216
6217static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
6218{
6219 u8 bssid[ETH_ALEN];
6220
6221 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
6222 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
6223 wpa_supplicant_deauthenticate(wpa_s,
6224 WLAN_REASON_DEAUTH_LEAVING);
6225 return;
6226 }
6227
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006228 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006229 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
6230 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
6231 wpas_notify_bssid_changed(wpa_s);
6232 }
6233
6234 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
6235 wpa_printf(MSG_ERROR,
6236 "LINK_RECONFIG: Failed to get MLO connection info");
6237 wpa_supplicant_deauthenticate(wpa_s,
6238 WLAN_REASON_DEAUTH_LEAVING);
6239 return;
6240 }
6241
6242 if (wpa_sm_set_ml_info(wpa_s)) {
6243 wpa_printf(MSG_ERROR,
6244 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
6245 wpa_supplicant_deauthenticate(wpa_s,
6246 WLAN_REASON_DEAUTH_LEAVING);
6247 return;
6248 }
6249
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306250 wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL);
Sunil Ravi640215c2023-06-28 23:08:09 +00006251 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
6252 wpa_s->valid_links);
6253}
6254
Matthew Wangb820c2b2024-10-03 13:02:07 +00006255#ifdef MAINLINE_SUPPLICANT
6256static bool is_event_allowlisted(enum wpa_event_type event) {
Matthew Wangc8ea6132024-10-23 11:19:52 +00006257 return event == EVENT_SCAN_STARTED ||
6258 event == EVENT_SCAN_RESULTS ||
6259 event == EVENT_RX_MGMT ||
Matthew Wangb820c2b2024-10-03 13:02:07 +00006260 event == EVENT_REMAIN_ON_CHANNEL ||
6261 event == EVENT_CANCEL_REMAIN_ON_CHANNEL ||
6262 event == EVENT_TX_WAIT_EXPIRE;
6263}
6264#endif /* MAINLINE_SUPPLICANT */
6265
Sunil Ravi640215c2023-06-28 23:08:09 +00006266
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006267void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
6268 union wpa_event_data *data)
6269{
6270 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006271 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07006272 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08006273#ifndef CONFIG_NO_STDOUT_DEBUG
6274 int level = MSG_DEBUG;
6275#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006276
Matthew Wangb820c2b2024-10-03 13:02:07 +00006277#ifdef MAINLINE_SUPPLICANT
6278 if (!is_event_allowlisted(event)) {
6279 wpa_dbg(wpa_s, MSG_DEBUG,
6280 "Ignore event %s (%d) which is not allowlisted",
6281 event_to_string(event), event);
6282 return;
6283 }
6284#endif /* MAINLINE_SUPPLICANT */
6285
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006286 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
6287 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006288 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006289 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006290 event != EVENT_SCHED_SCAN_STOPPED) {
6291 wpa_dbg(wpa_s, MSG_DEBUG,
6292 "Ignore event %s (%d) while interface is disabled",
6293 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006294 return;
6295 }
6296
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006297#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07006298 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006299 const struct ieee80211_hdr *hdr;
6300 u16 fc;
6301 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
6302 fc = le_to_host16(hdr->frame_control);
6303 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
6304 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
6305 level = MSG_EXCESSIVE;
6306 }
6307
6308 wpa_dbg(wpa_s, level, "Event %s (%d) received",
6309 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006310#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006311
6312 switch (event) {
6313 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006314#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08006315 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
6316 data->auth.ies_len))
6317 wpa_printf(MSG_DEBUG,
6318 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006319#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006320 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006321 wpa_s->auth_status_code = data->auth.status_code;
6322 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006323 break;
6324 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006325#ifdef CONFIG_TESTING_OPTIONS
6326 if (wpa_s->ignore_auth_resp) {
6327 wpa_printf(MSG_INFO,
6328 "EVENT_ASSOC - ignore_auth_resp active!");
6329 break;
6330 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006331 if (wpa_s->testing_resend_assoc) {
6332 wpa_printf(MSG_INFO,
6333 "EVENT_DEAUTH - testing_resend_assoc");
6334 break;
6335 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006336#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05306337 if (wpa_s->disconnected) {
6338 wpa_printf(MSG_INFO,
6339 "Ignore unexpected EVENT_ASSOC in disconnected state");
6340 break;
6341 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006342 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006343 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006344 if (data &&
6345 (data->assoc_info.authorized ||
6346 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6347 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006348 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006349 if (data) {
6350 wpa_msg(wpa_s, MSG_INFO,
6351 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
6352 data->assoc_info.subnet_status);
6353 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006354 break;
6355 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006356 wpas_event_disassoc(wpa_s,
6357 data ? &data->disassoc_info : NULL);
6358 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006359 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006360#ifdef CONFIG_TESTING_OPTIONS
6361 if (wpa_s->ignore_auth_resp) {
6362 wpa_printf(MSG_INFO,
6363 "EVENT_DEAUTH - ignore_auth_resp active!");
6364 break;
6365 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006366 if (wpa_s->testing_resend_assoc) {
6367 wpa_printf(MSG_INFO,
6368 "EVENT_DEAUTH - testing_resend_assoc");
6369 break;
6370 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006371#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006372 wpas_event_deauth(wpa_s,
6373 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006374 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00006375 case EVENT_LINK_RECONFIG:
6376 wpas_link_reconfig(wpa_s);
6377 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006378 case EVENT_MICHAEL_MIC_FAILURE:
6379 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
6380 break;
6381#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006382 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006383 if (wpa_s->own_scan_requested ||
6384 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006385 struct os_reltime diff;
6386
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006387 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006388 os_reltime_sub(&wpa_s->scan_start_time,
6389 &wpa_s->scan_trigger_time, &diff);
6390 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
6391 diff.sec, diff.usec);
6392 wpa_s->own_scan_requested = 0;
6393 wpa_s->own_scan_running = 1;
6394 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
6395 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006396 wpa_msg_ctrl(wpa_s, MSG_INFO,
6397 WPA_EVENT_SCAN_STARTED "id=%u",
6398 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006399 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006400 wpa_msg_ctrl(wpa_s, MSG_INFO,
6401 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006402 }
6403 } else {
6404 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08006405 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006406 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006407 }
6408 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006409 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006410 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6411 wpa_s->scan_res_handler = NULL;
6412 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08006413 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006414 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
6415 break;
6416 }
6417
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006418 if (!(data && data->scan_info.external_scan) &&
6419 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006420 struct os_reltime now, diff;
6421 os_get_reltime(&now);
6422 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
6423 wpa_s->scan_start_time.sec = 0;
6424 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00006425 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006426 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
6427 diff.sec, diff.usec);
6428 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006429 if (wpa_supplicant_event_scan_results(wpa_s, data))
6430 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006431 if (!(data && data->scan_info.external_scan))
6432 wpa_s->own_scan_running = 0;
6433 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08006434 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006435 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006436 break;
6437#endif /* CONFIG_NO_SCAN_PROCESSING */
6438 case EVENT_ASSOCINFO:
6439 wpa_supplicant_event_associnfo(wpa_s, data);
6440 break;
6441 case EVENT_INTERFACE_STATUS:
6442 wpa_supplicant_event_interface_status(wpa_s, data);
6443 break;
6444 case EVENT_PMKID_CANDIDATE:
6445 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
6446 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006447#ifdef CONFIG_TDLS
6448 case EVENT_TDLS:
6449 wpa_supplicant_event_tdls(wpa_s, data);
6450 break;
6451#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006452#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006453 case EVENT_WNM:
6454 wpa_supplicant_event_wnm(wpa_s, data);
6455 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006456#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006457#ifdef CONFIG_IEEE80211R
6458 case EVENT_FT_RESPONSE:
6459 wpa_supplicant_event_ft_response(wpa_s, data);
6460 break;
6461#endif /* CONFIG_IEEE80211R */
6462#ifdef CONFIG_IBSS_RSN
6463 case EVENT_IBSS_RSN_START:
6464 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
6465 break;
6466#endif /* CONFIG_IBSS_RSN */
6467 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07006468 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006469 break;
6470 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006471 /* It is possible to get this event from earlier connection */
6472 if (wpa_s->current_ssid &&
6473 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6474 wpa_dbg(wpa_s, MSG_DEBUG,
6475 "Ignore AUTH_TIMED_OUT in mesh configuration");
6476 break;
6477 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006478 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6479 sme_event_auth_timed_out(wpa_s, data);
6480 break;
6481 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006482 /* It is possible to get this event from earlier connection */
6483 if (wpa_s->current_ssid &&
6484 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6485 wpa_dbg(wpa_s, MSG_DEBUG,
6486 "Ignore ASSOC_TIMED_OUT in mesh configuration");
6487 break;
6488 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006489 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6490 sme_event_assoc_timed_out(wpa_s, data);
6491 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006492 case EVENT_TX_STATUS:
6493 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
6494 " type=%d stype=%d",
6495 MAC2STR(data->tx_status.dst),
6496 data->tx_status.type, data->tx_status.stype);
Sunil Ravi99c035e2024-07-12 01:42:03 +00006497#ifdef CONFIG_WNM
6498 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6499 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
6500 wnm_btm_resp_tx_status(wpa_s, data->tx_status.data,
6501 data->tx_status.data_len) == 0)
6502 break;
6503#endif /* CONFIG_WNM */
Hai Shalom60840252021-02-19 19:02:11 -08006504#ifdef CONFIG_PASN
6505 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6506 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6507 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
6508 data->tx_status.data_len,
6509 data->tx_status.ack) == 0)
6510 break;
6511#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006512#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006513 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006514#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006515 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6516 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006517 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006518 wpa_s, data->tx_status.dst,
6519 data->tx_status.data,
6520 data->tx_status.data_len,
6521 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006522 OFFCHANNEL_SEND_ACTION_SUCCESS :
6523 OFFCHANNEL_SEND_ACTION_NO_ACK);
6524#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006525 break;
6526 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006527#endif /* CONFIG_AP */
6528#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006529 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006530 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006531 /*
6532 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006533 * interface in GO mode, or via standalone AP interface.
6534 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
6535 * except when the primary interface is used as a GO interface
6536 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006537 */
6538 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6539 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006540 ether_addr_equal(wpa_s->p2pdev->pending_action_dst,
6541 data->tx_status.dst)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006542 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006543 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006544 data->tx_status.data,
6545 data->tx_status.data_len,
6546 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006547 OFFCHANNEL_SEND_ACTION_SUCCESS :
6548 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006549 break;
6550 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006551#endif /* CONFIG_OFFCHANNEL */
6552#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006553 switch (data->tx_status.type) {
6554 case WLAN_FC_TYPE_MGMT:
6555 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
6556 data->tx_status.data_len,
6557 data->tx_status.stype,
6558 data->tx_status.ack);
6559 break;
6560 case WLAN_FC_TYPE_DATA:
6561 ap_tx_status(wpa_s, data->tx_status.dst,
6562 data->tx_status.data,
6563 data->tx_status.data_len,
6564 data->tx_status.ack);
6565 break;
6566 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006567#endif /* CONFIG_AP */
6568 break;
6569#ifdef CONFIG_AP
6570 case EVENT_EAPOL_TX_STATUS:
6571 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
6572 data->eapol_tx_status.data,
6573 data->eapol_tx_status.data_len,
6574 data->eapol_tx_status.ack);
6575 break;
6576 case EVENT_DRIVER_CLIENT_POLL_OK:
6577 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006578 break;
6579 case EVENT_RX_FROM_UNKNOWN:
6580 if (wpa_s->ap_iface == NULL)
6581 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006582 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
6583 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006584 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006585#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07006586
Sunil Ravi89eba102022-09-13 21:04:37 -07006587 case EVENT_LINK_CH_SWITCH_STARTED:
6588 case EVENT_LINK_CH_SWITCH:
6589 if (!data || !wpa_s->current_ssid ||
6590 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6591 break;
6592
6593 wpa_msg(wpa_s, MSG_INFO,
6594 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6595 event == EVENT_LINK_CH_SWITCH ?
6596 WPA_EVENT_LINK_CHANNEL_SWITCH :
6597 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6598 data->ch_switch.freq,
6599 data->ch_switch.link_id,
6600 data->ch_switch.ht_enabled,
6601 data->ch_switch.ch_offset,
6602 channel_width_to_string(data->ch_switch.ch_width),
6603 data->ch_switch.cf1,
6604 data->ch_switch.cf2);
6605 if (event == EVENT_LINK_CH_SWITCH_STARTED)
6606 break;
6607
6608 wpa_s->links[data->ch_switch.link_id].freq =
6609 data->ch_switch.freq;
6610 if (wpa_s->links[data->ch_switch.link_id].bss &&
6611 wpa_s->links[data->ch_switch.link_id].bss->freq !=
6612 data->ch_switch.freq) {
6613 wpa_s->links[data->ch_switch.link_id].bss->freq =
6614 data->ch_switch.freq;
6615 notify_bss_changes(
6616 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6617 wpa_s->links[data->ch_switch.link_id].bss);
Shuibing Dai0db6bb12023-09-28 17:53:17 -07006618 if (data->ch_switch.freq)
6619 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
Sunil Ravi89eba102022-09-13 21:04:37 -07006620 }
6621 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07006622 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07006623 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006624 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006625 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006626
Hai Shalom81f62d82019-07-22 12:10:00 -07006627 wpa_msg(wpa_s, MSG_INFO,
6628 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6629 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6630 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006631 data->ch_switch.freq,
6632 data->ch_switch.ht_enabled,
6633 data->ch_switch.ch_offset,
6634 channel_width_to_string(data->ch_switch.ch_width),
6635 data->ch_switch.cf1,
6636 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07006637 if (event == EVENT_CH_SWITCH_STARTED)
6638 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006639
Sunil Ravi65a724b2022-05-24 11:06:09 -07006640 if (wpa_s->assoc_freq && data->ch_switch.freq &&
6641 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
6642 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
6643 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006644 wpa_s->assoc_freq = data->ch_switch.freq;
6645 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08006646 if (wpa_s->current_bss &&
6647 wpa_s->current_bss->freq != data->ch_switch.freq) {
6648 wpa_s->current_bss->freq = data->ch_switch.freq;
6649 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6650 wpa_s->current_bss);
6651 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006652
Hai Shalomfdcde762020-04-02 11:19:20 -07006653#ifdef CONFIG_SME
6654 switch (data->ch_switch.ch_offset) {
6655 case 1:
6656 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6657 break;
6658 case -1:
6659 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6660 break;
6661 default:
6662 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6663 break;
6664 }
6665#endif /* CONFIG_SME */
6666
Roshan Pius3a1667e2018-07-03 15:17:14 -07006667#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006668 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6669 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08006670 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006671 wpa_s->current_ssid->mode ==
6672 WPAS_MODE_P2P_GROUP_FORMATION) {
6673 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6674 data->ch_switch.ht_enabled,
6675 data->ch_switch.ch_offset,
6676 data->ch_switch.ch_width,
6677 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006678 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07006679 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07006680 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006681 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006682#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006683
Hai Shalom899fcc72020-10-19 14:38:18 -07006684 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6685 sme_event_ch_switch(wpa_s);
6686
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006687 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006688 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006689 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006690#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006691#ifdef NEED_AP_MLME
6692 case EVENT_DFS_RADAR_DETECTED:
6693 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07006694 wpas_ap_event_dfs_radar_detected(wpa_s,
6695 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006696 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006697 case EVENT_DFS_NOP_FINISHED:
6698 if (data)
6699 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
6700 &data->dfs_event);
6701 break;
6702#endif /* NEED_AP_MLME */
6703#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006704 case EVENT_DFS_CAC_STARTED:
6705 if (data)
6706 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
6707 break;
6708 case EVENT_DFS_CAC_FINISHED:
6709 if (data)
6710 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
6711 break;
6712 case EVENT_DFS_CAC_ABORTED:
6713 if (data)
6714 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
6715 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006716 case EVENT_RX_MGMT: {
6717 u16 fc, stype;
6718 const struct ieee80211_mgmt *mgmt;
6719
Dmitry Shmidt818ea482014-03-10 13:15:21 -07006720#ifdef CONFIG_TESTING_OPTIONS
6721 if (wpa_s->ext_mgmt_frame_handling) {
6722 struct rx_mgmt *rx = &data->rx_mgmt;
6723 size_t hex_len = 2 * rx->frame_len + 1;
6724 char *hex = os_malloc(hex_len);
6725 if (hex) {
6726 wpa_snprintf_hex(hex, hex_len,
6727 rx->frame, rx->frame_len);
6728 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
6729 rx->freq, rx->datarate, rx->ssi_signal,
6730 hex);
6731 os_free(hex);
6732 }
6733 break;
6734 }
6735#endif /* CONFIG_TESTING_OPTIONS */
6736
Dmitry Shmidt04949592012-07-19 12:16:46 -07006737 mgmt = (const struct ieee80211_mgmt *)
6738 data->rx_mgmt.frame;
6739 fc = le_to_host16(mgmt->frame_control);
6740 stype = WLAN_FC_GET_STYPE(fc);
6741
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006742#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006743 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006744#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006745#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006746 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006747 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006748 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07006749 const u8 *ie;
6750 size_t ie_len;
6751
6752 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6753 ie_len = data->rx_mgmt.frame_len -
6754 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006755 wpas_p2p_probe_req_rx(
6756 wpa_s, src, mgmt->da,
6757 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006758 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006759 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006760 break;
6761 }
6762#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006763#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006764 if (wpa_s->current_ssid &&
6765 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
6766 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006767 data->rx_mgmt.frame_len >= 30) {
6768 wpa_supplicant_event_ibss_auth(wpa_s, data);
6769 break;
6770 }
6771#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006772
6773 if (stype == WLAN_FC_STYPE_ACTION) {
6774 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07006775 wpa_s, data->rx_mgmt.frame,
6776 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006777 data->rx_mgmt.freq,
6778 data->rx_mgmt.ssi_signal);
6779 break;
6780 }
6781
6782 if (wpa_s->ifmsh) {
6783 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006784 break;
6785 }
Hai Shalom60840252021-02-19 19:02:11 -08006786#ifdef CONFIG_PASN
6787 if (stype == WLAN_FC_STYPE_AUTH &&
6788 wpas_pasn_auth_rx(wpa_s, mgmt,
6789 data->rx_mgmt.frame_len) != -2)
6790 break;
6791#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006792
Roshan Pius3a1667e2018-07-03 15:17:14 -07006793#ifdef CONFIG_SAE
6794 if (stype == WLAN_FC_STYPE_AUTH &&
6795 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6796 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6797 sme_external_auth_mgmt_rx(
6798 wpa_s, data->rx_mgmt.frame,
6799 data->rx_mgmt.frame_len);
6800 break;
6801 }
6802#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006803 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6804 "management frame in non-AP mode");
6805 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006806#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006807 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006808
6809 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006810 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6811 const u8 *ie;
6812 size_t ie_len;
6813
6814 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6815 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006816
6817 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6818 mgmt->bssid, ie, ie_len,
6819 data->rx_mgmt.ssi_signal);
6820 }
6821
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006822 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006823#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006824 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006825 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006826 case EVENT_RX_PROBE_REQ:
6827 if (data->rx_probe_req.sa == NULL ||
6828 data->rx_probe_req.ie == NULL)
6829 break;
6830#ifdef CONFIG_AP
6831 if (wpa_s->ap_iface) {
6832 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6833 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006834 data->rx_probe_req.da,
6835 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006836 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006837 data->rx_probe_req.ie_len,
6838 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006839 break;
6840 }
6841#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006842 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006843 data->rx_probe_req.da,
6844 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006845 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006846 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006847 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006848 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006849 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006850 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006851#ifdef CONFIG_OFFCHANNEL
6852 offchannel_remain_on_channel_cb(
6853 wpa_s, data->remain_on_channel.freq,
6854 data->remain_on_channel.duration);
6855#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006856 wpas_p2p_remain_on_channel_cb(
6857 wpa_s, data->remain_on_channel.freq,
6858 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006859#ifdef CONFIG_DPP
6860 wpas_dpp_remain_on_channel_cb(
6861 wpa_s, data->remain_on_channel.freq,
6862 data->remain_on_channel.duration);
6863#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006864#ifdef CONFIG_NAN_USD
6865 wpas_nan_usd_remain_on_channel_cb(
6866 wpa_s, data->remain_on_channel.freq,
6867 data->remain_on_channel.duration);
6868#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006869 break;
6870 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006871#ifdef CONFIG_OFFCHANNEL
6872 offchannel_cancel_remain_on_channel_cb(
6873 wpa_s, data->remain_on_channel.freq);
6874#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006875 wpas_p2p_cancel_remain_on_channel_cb(
6876 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006877#ifdef CONFIG_DPP
6878 wpas_dpp_cancel_remain_on_channel_cb(
6879 wpa_s, data->remain_on_channel.freq);
6880#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006881#ifdef CONFIG_NAN_USD
6882 wpas_nan_usd_cancel_remain_on_channel_cb(
6883 wpa_s, data->remain_on_channel.freq);
6884#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006885 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006886 case EVENT_EAPOL_RX:
6887 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6888 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00006889 data->eapol_rx.data_len,
6890 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006891 break;
6892 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006893 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00006894 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006895 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006896 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006897 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006898 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006899 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006900 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006901 bgscan_notify_signal_change(
6902 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006903 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006904 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006905 data->signal_change.data.current_tx_rate);
6906 os_memcpy(&wpa_s->last_signal_info, data,
6907 sizeof(struct wpa_signal_info));
6908 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006909 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006910 case EVENT_INTERFACE_MAC_CHANGED:
6911 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006912 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006913 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006914 case EVENT_INTERFACE_ENABLED:
6915 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6916 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006917 u8 addr[ETH_ALEN];
6918
Hai Shalomfdcde762020-04-02 11:19:20 -07006919 eloop_cancel_timeout(wpas_clear_disabled_interface,
6920 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08006921 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006922 wpa_supplicant_update_mac_addr(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006923 if (!ether_addr_equal(addr, wpa_s->own_addr))
Hai Shalomc1a21442022-02-04 13:43:00 -08006924 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6925 else
6926 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07006927 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006928 if (wpa_s->p2p_mgmt) {
6929 wpa_supplicant_set_state(wpa_s,
6930 WPA_DISCONNECTED);
6931 break;
6932 }
6933
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006934#ifdef CONFIG_AP
6935 if (!wpa_s->ap_iface) {
6936 wpa_supplicant_set_state(wpa_s,
6937 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006938 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006939 wpa_supplicant_req_scan(wpa_s, 0, 0);
6940 } else
6941 wpa_supplicant_set_state(wpa_s,
6942 WPA_COMPLETED);
6943#else /* CONFIG_AP */
6944 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6945 wpa_supplicant_req_scan(wpa_s, 0, 0);
6946#endif /* CONFIG_AP */
6947 }
6948 break;
6949 case EVENT_INTERFACE_DISABLED:
6950 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006951#ifdef CONFIG_P2P
6952 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6953 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6954 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6955 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006956 * Mark interface disabled if this happens to end up not
6957 * being removed as a separate P2P group interface.
6958 */
6959 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6960 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006961 * The interface was externally disabled. Remove
6962 * it assuming an external entity will start a
6963 * new session if needed.
6964 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006965 if (wpa_s->current_ssid &&
6966 wpa_s->current_ssid->p2p_group)
6967 wpas_p2p_interface_unavailable(wpa_s);
6968 else
6969 wpas_p2p_disconnect(wpa_s);
6970 /*
6971 * wpa_s instance may have been freed, so must not use
6972 * it here anymore.
6973 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006974 break;
6975 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006976 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6977 p2p_in_progress(wpa_s->global->p2p) > 1) {
6978 /* This radio work will be cancelled, so clear P2P
6979 * state as well.
6980 */
6981 p2p_stop_find(wpa_s->global->p2p);
6982 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006983#endif /* CONFIG_P2P */
6984
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006985 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6986 /*
6987 * Indicate disconnection to keep ctrl_iface events
6988 * consistent.
6989 */
6990 wpa_supplicant_event_disassoc(
6991 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6992 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006993 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07006994 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08006995 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6996 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006997 clear_at.usec = 0;
6998 } else {
6999 struct os_reltime tmp;
7000
Hai Shalom60840252021-02-19 19:02:11 -08007001 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07007002 tmp.usec = 0;
7003 os_reltime_sub(&tmp, &age, &clear_at);
7004 }
7005 eloop_register_timeout(clear_at.sec, clear_at.usec,
7006 wpas_clear_disabled_interface,
7007 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08007008 radio_remove_works(wpa_s, NULL, 0);
7009
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007010 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
7011 break;
7012 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07007013 wpa_supplicant_update_channel_list(
7014 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007015 break;
7016 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007017 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007018 break;
7019 case EVENT_BEST_CHANNEL:
7020 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
7021 "(%d %d %d)",
7022 data->best_chan.freq_24, data->best_chan.freq_5,
7023 data->best_chan.freq_overall);
7024 wpa_s->best_24_freq = data->best_chan.freq_24;
7025 wpa_s->best_5_freq = data->best_chan.freq_5;
7026 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007027 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
7028 data->best_chan.freq_5,
7029 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007030 break;
7031 case EVENT_UNPROT_DEAUTH:
7032 wpa_supplicant_event_unprot_deauth(wpa_s,
7033 &data->unprot_deauth);
7034 break;
7035 case EVENT_UNPROT_DISASSOC:
7036 wpa_supplicant_event_unprot_disassoc(wpa_s,
7037 &data->unprot_disassoc);
7038 break;
7039 case EVENT_STATION_LOW_ACK:
7040#ifdef CONFIG_AP
7041 if (wpa_s->ap_iface && data)
7042 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
7043 data->low_ack.addr);
7044#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007045#ifdef CONFIG_TDLS
7046 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007047 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
7048 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007049#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007050 break;
7051 case EVENT_IBSS_PEER_LOST:
7052#ifdef CONFIG_IBSS_RSN
7053 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
7054#endif /* CONFIG_IBSS_RSN */
7055 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007056 case EVENT_DRIVER_GTK_REKEY:
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007057 if (!ether_addr_equal(data->driver_gtk_rekey.bssid,
7058 wpa_s->bssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007059 break;
7060 if (!wpa_s->wpa)
7061 break;
7062 wpa_sm_update_replay_ctr(wpa_s->wpa,
7063 data->driver_gtk_rekey.replay_ctr);
7064 break;
7065 case EVENT_SCHED_SCAN_STOPPED:
7066 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007067 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007068 wpa_supplicant_notify_scanning(wpa_s, 0);
7069
7070 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7071 break;
7072
7073 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007074 * If the driver stopped scanning without being requested to,
7075 * request a new scan to continue scanning for networks.
7076 */
7077 if (!wpa_s->sched_scan_stop_req &&
7078 wpa_s->wpa_state == WPA_SCANNING) {
7079 wpa_dbg(wpa_s, MSG_DEBUG,
7080 "Restart scanning after unexpected sched_scan stop event");
7081 wpa_supplicant_req_scan(wpa_s, 1, 0);
7082 break;
7083 }
7084
7085 wpa_s->sched_scan_stop_req = 0;
7086
7087 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08007088 * Start a new sched scan to continue searching for more SSIDs
7089 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007090 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07007091 if (wpa_s->sched_scan_timed_out) {
7092 wpa_supplicant_req_sched_scan(wpa_s);
7093 } else if (wpa_s->pno_sched_pending) {
7094 wpa_s->pno_sched_pending = 0;
7095 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07007096 } else if (resched) {
7097 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08007098 }
7099
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007100 break;
7101 case EVENT_WPS_BUTTON_PUSHED:
7102#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07007103 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007104#endif /* CONFIG_WPS */
7105 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007106 case EVENT_AVOID_FREQUENCIES:
7107 wpa_supplicant_notify_avoid_freq(wpa_s, data);
7108 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08007109 case EVENT_CONNECT_FAILED_REASON:
7110#ifdef CONFIG_AP
7111 if (!wpa_s->ap_iface || !data)
7112 break;
7113 hostapd_event_connect_failed_reason(
7114 wpa_s->ap_iface->bss[0],
7115 data->connect_failed_reason.addr,
7116 data->connect_failed_reason.code);
7117#endif /* CONFIG_AP */
7118 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007119 case EVENT_NEW_PEER_CANDIDATE:
7120#ifdef CONFIG_MESH
7121 if (!wpa_s->ifmsh || !data)
7122 break;
7123 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
7124 data->mesh_peer.ies,
7125 data->mesh_peer.ie_len);
7126#endif /* CONFIG_MESH */
7127 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007128 case EVENT_SURVEY:
7129#ifdef CONFIG_AP
7130 if (!wpa_s->ap_iface)
7131 break;
7132 hostapd_event_get_survey(wpa_s->ap_iface,
7133 &data->survey_results);
7134#endif /* CONFIG_AP */
7135 break;
7136 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08007137#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007138#ifdef CONFIG_ACS
7139 if (!wpa_s->ap_iface)
7140 break;
7141 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
7142 &data->acs_selected_channels);
7143#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08007144#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007145 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007146 case EVENT_P2P_LO_STOP:
7147#ifdef CONFIG_P2P
7148 wpa_s->p2p_lo_started = 0;
7149 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
7150 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
7151 data->p2p_lo_stop.reason_code);
7152#endif /* CONFIG_P2P */
7153 break;
Paul Stewart092955c2017-02-06 09:13:09 -08007154 case EVENT_BEACON_LOSS:
7155 if (!wpa_s->current_bss || !wpa_s->current_ssid)
7156 break;
7157 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
7158 bgscan_notify_beacon_loss(wpa_s);
7159 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007160 case EVENT_EXTERNAL_AUTH:
7161#ifdef CONFIG_SAE
7162 if (!wpa_s->current_ssid) {
7163 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
7164 break;
7165 }
7166 sme_external_auth_trigger(wpa_s, data);
7167#endif /* CONFIG_SAE */
7168 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07007169#ifdef CONFIG_PASN
7170 case EVENT_PASN_AUTH:
7171 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
7172 break;
7173#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007174 case EVENT_PORT_AUTHORIZED:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007175#ifdef CONFIG_AP
7176 if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
7177 struct sta_info *sta;
7178
7179 sta = ap_get_sta(wpa_s->ap_iface->bss[0],
7180 data->port_authorized.sta_addr);
7181 if (sta)
7182 ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
7183 sta, 1);
7184 else
7185 wpa_printf(MSG_DEBUG,
7186 "No STA info matching port authorized event found");
7187 break;
7188 }
7189#endif /* CONFIG_AP */
Sunil Ravi77d572f2023-01-17 23:58:31 +00007190#ifndef CONFIG_NO_WPA
7191 if (data->port_authorized.td_bitmap_len) {
7192 wpa_printf(MSG_DEBUG,
7193 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
7194 data->port_authorized.td_bitmap[0]);
7195 wpas_transition_disable(
7196 wpa_s, data->port_authorized.td_bitmap[0]);
7197 }
7198#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007199 wpa_supplicant_event_port_authorized(wpa_s);
7200 break;
7201 case EVENT_STATION_OPMODE_CHANGED:
7202#ifdef CONFIG_AP
7203 if (!wpa_s->ap_iface || !data)
7204 break;
7205
7206 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
7207 data->sta_opmode.addr,
7208 data->sta_opmode.smps_mode,
7209 data->sta_opmode.chan_width,
7210 data->sta_opmode.rx_nss);
7211#endif /* CONFIG_AP */
7212 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07007213 case EVENT_UNPROT_BEACON:
7214 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
7215 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08007216 case EVENT_TX_WAIT_EXPIRE:
7217#ifdef CONFIG_DPP
7218 wpas_dpp_tx_wait_expire(wpa_s);
7219#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007220#ifdef CONFIG_NAN_USD
7221 wpas_nan_usd_tx_wait_expire(wpa_s);
7222#endif /* CONFIG_NAN_USD */
Hai Shalomc1a21442022-02-04 13:43:00 -08007223 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00007224 case EVENT_TID_LINK_MAP:
7225 if (data)
7226 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
7227 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007228 default:
7229 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
7230 break;
7231 }
7232}
Dmitry Shmidte4663042016-04-04 10:07:49 -07007233
7234
7235void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
7236 union wpa_event_data *data)
7237{
7238 struct wpa_supplicant *wpa_s;
7239
7240 if (event != EVENT_INTERFACE_STATUS)
7241 return;
7242
7243 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
7244 if (wpa_s && wpa_s->driver->get_ifindex) {
7245 unsigned int ifindex;
7246
7247 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
7248 if (ifindex != data->interface_status.ifindex) {
7249 wpa_dbg(wpa_s, MSG_DEBUG,
7250 "interface status ifindex %d mismatch (%d)",
7251 ifindex, data->interface_status.ifindex);
7252 return;
7253 }
7254 }
7255#ifdef CONFIG_MATCH_IFACE
7256 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
7257 struct wpa_interface *wpa_i;
7258
7259 wpa_i = wpa_supplicant_match_iface(
7260 ctx, data->interface_status.ifname);
7261 if (!wpa_i)
7262 return;
7263 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
7264 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07007265 }
7266#endif /* CONFIG_MATCH_IFACE */
7267
7268 if (wpa_s)
7269 wpa_supplicant_event(wpa_s, event, data);
7270}