blob: ff18543c07e959976d9d88d803f305a646b10542 [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"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
Sunil Ravi2a14cf12023-11-21 00:54:38 +000025#include "ap/sta_info.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080027#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070028#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029#include "notify.h"
30#include "common/ieee802_11_defs.h"
31#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070032#include "common/gas_server.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070033#include "common/dpp.h"
Hai Shalom60840252021-02-19 19:02:11 -080034#include "common/ptksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035#include "crypto/random.h"
Hai Shalom60840252021-02-19 19:02:11 -080036#include "bssid_ignore.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "wpas_glue.h"
38#include "wps_supplicant.h"
39#include "ibss_rsn.h"
40#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080041#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "p2p_supplicant.h"
43#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070044#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045#include "ap.h"
46#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070047#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080048#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070049#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080050#include "mesh.h"
51#include "mesh_mpm.h"
52#include "wmm_ac.h"
Sunil Ravi72e01222024-03-09 01:25:43 +000053#include "nan_usd.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070054#include "dpp_supplicant.h"
Mir Ali677e7482020-11-12 19:49:02 +053055#include "rsn_supp/wpa_i.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070056
57
Hai Shalom39ba6fc2019-01-22 12:40:38 -080058#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
59
60
Dmitry Shmidt34af3062013-07-11 10:46:32 -070061#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070062static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000063 int new_scan, int own_request,
64 bool trigger_6ghz_scan,
65 union wpa_event_data *data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070066#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080067
68
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070069int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070070{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080071 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070072
73 if (ssid == NULL || ssid->disabled_until.sec == 0)
74 return 0;
75
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080076 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070077 if (ssid->disabled_until.sec > now.sec)
78 return ssid->disabled_until.sec - now.sec;
79
80 wpas_clear_temp_disabled(wpa_s, ssid, 0);
81
82 return 0;
83}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084
85
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080086#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070087/**
88 * wpas_reenabled_network_time - Time until first network is re-enabled
89 * @wpa_s: Pointer to wpa_supplicant data
90 * Returns: If all enabled networks are temporarily disabled, returns the time
91 * (in sec) until the first network is re-enabled. Otherwise returns 0.
92 *
93 * This function is used in case all enabled networks are temporarily disabled,
94 * in which case it returns the time (in sec) that the first network will be
95 * re-enabled. The function assumes that at least one network is enabled.
96 */
97static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
98{
99 struct wpa_ssid *ssid;
100 int disabled_for, res = 0;
101
102#ifdef CONFIG_INTERWORKING
103 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
104 wpa_s->conf->cred)
105 return 0;
106#endif /* CONFIG_INTERWORKING */
107
108 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
109 if (ssid->disabled)
110 continue;
111
112 disabled_for = wpas_temp_disabled(wpa_s, ssid);
113 if (!disabled_for)
114 return 0;
115
116 if (!res || disabled_for < res)
117 res = disabled_for;
118 }
119
120 return res;
121}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800122#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700123
124
125void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
126{
127 struct wpa_supplicant *wpa_s = eloop_ctx;
128
129 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
130 return;
131
132 wpa_dbg(wpa_s, MSG_DEBUG,
133 "Try to associate due to network getting re-enabled");
134 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
135 wpa_supplicant_cancel_sched_scan(wpa_s);
136 wpa_supplicant_req_scan(wpa_s, 0, 0);
137 }
138}
139
140
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800141static struct wpa_bss * wpa_supplicant_get_new_bss(
142 struct wpa_supplicant *wpa_s, const u8 *bssid)
143{
144 struct wpa_bss *bss = NULL;
145 struct wpa_ssid *ssid = wpa_s->current_ssid;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000146 u8 drv_ssid[SSID_MAX_LEN];
147 int res;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800148
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000149 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
150 if (res > 0)
151 bss = wpa_bss_get(wpa_s, bssid, drv_ssid, res);
152 if (!bss && ssid && ssid->ssid_len > 0)
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800153 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
154 if (!bss)
155 bss = wpa_bss_get_bssid(wpa_s, bssid);
156
157 return bss;
158}
159
160
Sunil Ravia04bd252022-05-02 22:54:18 -0700161static struct wpa_bss *
162wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700163{
Sunil Ravia04bd252022-05-02 22:54:18 -0700164 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700165
166 if (!bss) {
Sunil Raviaf399a82024-05-05 20:56:55 +0000167 wpa_supplicant_update_scan_results(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700168
169 /* Get the BSS from the new scan results */
Sunil Ravia04bd252022-05-02 22:54:18 -0700170 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700171 }
172
173 if (bss)
174 wpa_s->current_bss = bss;
Sunil Ravia04bd252022-05-02 22:54:18 -0700175
176 return bss;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700177}
178
179
Sunil Ravi89eba102022-09-13 21:04:37 -0700180static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
181 u8 link_id, const u8 *bssid)
182{
183 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
184
185 if (!bss) {
Sunil Raviaf399a82024-05-05 20:56:55 +0000186 wpa_supplicant_update_scan_results(wpa_s, bssid);
Sunil Ravi89eba102022-09-13 21:04:37 -0700187 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
188 }
189
190 if (bss)
191 wpa_s->links[link_id].bss = bss;
192}
193
194
Sunil Ravi77d572f2023-01-17 23:58:31 +0000195static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
196 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700197{
198 struct wpa_ssid *ssid, *old_ssid;
Sunil Ravi640215c2023-06-28 23:08:09 +0000199 struct wpa_bss *bss;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700200 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700201 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700202 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700204 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700205 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700206
207 if (wpa_s->current_ssid->ssid_len == 0)
208 return 0; /* current profile still in use */
209 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
210 if (res < 0) {
211 wpa_msg(wpa_s, MSG_INFO,
212 "Failed to read SSID from driver");
213 return 0; /* try to use current profile */
214 }
215 drv_ssid_len = res;
216
217 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
218 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
219 drv_ssid_len) == 0)
220 return 0; /* current profile still in use */
221
Hai Shalomfdcde762020-04-02 11:19:20 -0700222#ifdef CONFIG_OWE
223 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
224 wpa_s->current_bss &&
225 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
226 drv_ssid_len == wpa_s->current_bss->ssid_len &&
227 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
228 drv_ssid_len) == 0)
229 return 0; /* current profile still in use */
230#endif /* CONFIG_OWE */
231
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700232 wpa_msg(wpa_s, MSG_DEBUG,
233 "Driver-initiated BSS selection changed the SSID to %s",
234 wpa_ssid_txt(drv_ssid, drv_ssid_len));
235 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700236 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237
238 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
239 "information");
240 ssid = wpa_supplicant_get_ssid(wpa_s);
241 if (ssid == NULL) {
242 wpa_msg(wpa_s, MSG_INFO,
243 "No network configuration found for the current AP");
244 return -1;
245 }
246
Dmitry Shmidt04949592012-07-19 12:16:46 -0700247 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
249 return -1;
250 }
251
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800252 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
253 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
254 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
255 return -1;
256 }
257
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700258 res = wpas_temp_disabled(wpa_s, ssid);
259 if (res > 0) {
260 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
261 "disabled for %d second(s)", res);
262 return -1;
263 }
264
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
266 "current AP");
Sunil Ravi640215c2023-06-28 23:08:09 +0000267 bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800268 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269 u8 wpa_ie[80];
270 size_t wpa_ie_len = sizeof(wpa_ie);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000271 bool skip_default_rsne;
272
273 /* Do not override RSNE/RSNXE with the default values if the
274 * driver indicated the actual values used in the
275 * (Re)Association Request frame. */
276 skip_default_rsne = data && data->assoc_info.req_ies;
Sunil Ravi640215c2023-06-28 23:08:09 +0000277 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000278 wpa_ie, &wpa_ie_len,
279 skip_default_rsne) < 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800280 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281 } else {
282 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
283 }
284
285 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
286 eapol_sm_invalidate_cached_session(wpa_s->eapol);
287 old_ssid = wpa_s->current_ssid;
288 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800289
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700290 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
291 wpa_supplicant_initiate_eapol(wpa_s);
292 if (old_ssid != wpa_s->current_ssid)
293 wpas_notify_network_changed(wpa_s);
294
295 return 0;
296}
297
298
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800299void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300{
301 struct wpa_supplicant *wpa_s = eloop_ctx;
302
303 if (wpa_s->countermeasures) {
304 wpa_s->countermeasures = 0;
305 wpa_drv_set_countermeasures(wpa_s, 0);
306 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800307
308 /*
309 * It is possible that the device is sched scanning, which means
310 * that a connection attempt will be done only when we receive
311 * scan results. However, in this case, it would be preferable
312 * to scan and connect immediately, so cancel the sched_scan and
313 * issue a regular scan flow.
314 */
315 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 wpa_supplicant_req_scan(wpa_s, 0, 0);
317 }
318}
319
320
Sunil Ravi77d572f2023-01-17 23:58:31 +0000321void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
Sunil Ravi89eba102022-09-13 21:04:37 -0700322{
Sunil Ravi89eba102022-09-13 21:04:37 -0700323 if (!wpa_s->valid_links)
324 return;
325
326 wpa_s->valid_links = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000327 wpa_s->mlo_assoc_link_id = 0;
328 os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN);
329 os_memset(wpa_s->links, 0, sizeof(wpa_s->links));
Sunil Ravi89eba102022-09-13 21:04:37 -0700330}
331
332
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
334{
335 int bssid_changed;
336
Dmitry Shmidt04949592012-07-19 12:16:46 -0700337 wnm_bss_keep_alive_deinit(wpa_s);
338
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700339#ifdef CONFIG_IBSS_RSN
340 ibss_rsn_deinit(wpa_s->ibss_rsn);
341 wpa_s->ibss_rsn = NULL;
342#endif /* CONFIG_IBSS_RSN */
343
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700344#ifdef CONFIG_AP
345 wpa_supplicant_ap_deinit(wpa_s);
346#endif /* CONFIG_AP */
347
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700348#ifdef CONFIG_HS20
349 /* Clear possibly configured frame filters */
350 wpa_drv_configure_frame_filters(wpa_s, 0);
351#endif /* CONFIG_HS20 */
352
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700353 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
354 return;
355
Hai Shalom74f70d42019-02-11 14:42:39 -0800356 if (os_reltime_initialized(&wpa_s->session_start)) {
357 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
358 wpa_s->session_start.sec = 0;
359 wpa_s->session_start.usec = 0;
360 wpas_notify_session_length(wpa_s);
361 }
362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
364 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
365 os_memset(wpa_s->bssid, 0, ETH_ALEN);
366 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800367 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700368 wpa_s->current_bss = NULL;
369 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700370
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700371 if (bssid_changed)
372 wpas_notify_bssid_changed(wpa_s);
373
Hai Shalome21d4e82020-04-29 16:34:06 -0700374 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
375 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700376 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
377 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700378 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700379 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700380 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700382 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700383 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700384 wpa_s->key_mgmt = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700385 wpa_s->allowed_key_mgmts = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800386
Sunil Ravi72e01222024-03-09 01:25:43 +0000387#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800388 wpas_rrm_reset(wpa_s);
Sunil Ravi72e01222024-03-09 01:25:43 +0000389#endif /* CONFIG_NO_RRM */
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800390 wpa_s->wnmsleep_used = 0;
Sunil Ravi72e01222024-03-09 01:25:43 +0000391#ifdef CONFIG_WNM
392 wpa_s->wnm_mode = 0;
393#endif /* CONFIG_WNM */
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800394 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700395 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700396
397#ifdef CONFIG_TESTING_OPTIONS
398 wpa_s->last_tk_alg = WPA_ALG_NONE;
399 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
400#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700401 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800402
403 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
404 wpa_s->enabled_4addr_mode = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700405
Sunil Ravi77d572f2023-01-17 23:58:31 +0000406 wpa_s->wps_scan_done = false;
Sunil Ravi89eba102022-09-13 21:04:37 -0700407 wpas_reset_mlo_info(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700408}
409
410
Sunil Ravi036cec52023-03-29 11:35:17 -0700411static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700412{
413 struct wpa_ie_data ie;
414 int pmksa_set = -1;
415 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800416 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700417
Hai Shalomc1a21442022-02-04 13:43:00 -0800418 /* Start with assumption of no PMKSA cache entry match for cases other
419 * than SAE. In particular, this is needed to generate the PMKSA cache
420 * entries for Suite B cases with driver-based roaming indication. */
421 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
422 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
423 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700424
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
426 ie.pmkid == NULL)
427 return;
428
429 for (i = 0; i < ie.num_pmkid; i++) {
430 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
431 ie.pmkid + i * PMKID_LEN,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000432 NULL, NULL, 0, NULL, 0,
433 true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700434 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800435 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Sunil Ravi036cec52023-03-29 11:35:17 -0700436 if (authorized)
437 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438 break;
439 }
440 }
441
442 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
443 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
444}
445
446
447static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
448 union wpa_event_data *data)
449{
450 if (data == NULL) {
451 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
452 "event");
453 return;
454 }
455 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
456 " index=%d preauth=%d",
457 MAC2STR(data->pmkid_candidate.bssid),
458 data->pmkid_candidate.index,
459 data->pmkid_candidate.preauth);
460
461 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
462 data->pmkid_candidate.index,
463 data->pmkid_candidate.preauth);
464}
465
466
467static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
468{
469 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
470 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
471 return 0;
472
473#ifdef IEEE8021X_EAPOL
474 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
475 wpa_s->current_ssid &&
476 !(wpa_s->current_ssid->eapol_flags &
477 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
478 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
479 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
480 * plaintext or static WEP keys). */
481 return 0;
482 }
483#endif /* IEEE8021X_EAPOL */
484
485 return 1;
486}
487
488
489/**
490 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
491 * @wpa_s: pointer to wpa_supplicant data
492 * @ssid: Configuration data for the network
493 * Returns: 0 on success, -1 on failure
494 *
495 * This function is called when starting authentication with a network that is
496 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
497 */
498int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
499 struct wpa_ssid *ssid)
500{
501#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800502#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700503 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700505 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
506 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 return 0;
508
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700509 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700510 sim = 1;
511 aka = 1;
512 } else {
513 struct eap_method_type *eap = ssid->eap.eap_methods;
514 while (eap->vendor != EAP_VENDOR_IETF ||
515 eap->method != EAP_TYPE_NONE) {
516 if (eap->vendor == EAP_VENDOR_IETF) {
517 if (eap->method == EAP_TYPE_SIM)
518 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700519 else if (eap->method == EAP_TYPE_AKA ||
520 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521 aka = 1;
522 }
523 eap++;
524 }
525 }
526
527 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
528 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700529 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
530 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
531 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700532 aka = 0;
533
534 if (!sim && !aka) {
535 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
536 "use SIM, but neither EAP-SIM nor EAP-AKA are "
537 "enabled");
538 return 0;
539 }
540
541 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
542 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700544 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545 if (wpa_s->scard == NULL) {
546 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
547 "(pcsc-lite)");
548 return -1;
549 }
550 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
551 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800552#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553#endif /* IEEE8021X_EAPOL */
554
555 return 0;
556}
557
558
559#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700560
Hai Shalomfdcde762020-04-02 11:19:20 -0700561#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700562static int has_wep_key(struct wpa_ssid *ssid)
563{
564 int i;
565
566 for (i = 0; i < NUM_WEP_KEYS; i++) {
567 if (ssid->wep_key_len[i])
568 return 1;
569 }
570
571 return 0;
572}
Hai Shalomfdcde762020-04-02 11:19:20 -0700573#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700574
575
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700576static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577 struct wpa_ssid *ssid)
578{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700579 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580
581 if (ssid->mixed_cell)
582 return 1;
583
584#ifdef CONFIG_WPS
585 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
586 return 1;
587#endif /* CONFIG_WPS */
588
Roshan Pius3a1667e2018-07-03 15:17:14 -0700589#ifdef CONFIG_OWE
590 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
591 return 1;
592#endif /* CONFIG_OWE */
593
Hai Shalomfdcde762020-04-02 11:19:20 -0700594#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700595 if (has_wep_key(ssid))
596 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700597#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700598
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700599#ifdef IEEE8021X_EAPOL
600 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
601 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
602 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
603 privacy = 1;
604#endif /* IEEE8021X_EAPOL */
605
Jouni Malinen75ecf522011-06-27 15:19:46 -0700606 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
607 privacy = 1;
608
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800609 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
610 privacy = 1;
611
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700612 if (bss->caps & IEEE80211_CAP_PRIVACY)
613 return privacy;
614 return !privacy;
615}
616
617
618static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
619 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800620 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621{
622 struct wpa_ie_data ie;
623 int proto_match = 0;
624 const u8 *rsn_ie, *wpa_ie;
625 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700626#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700628#endif /* CONFIG_WEP */
Sunil Ravi640215c2023-06-28 23:08:09 +0000629 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700630
631 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
632 if (ret >= 0)
633 return ret;
634
Hai Shalomfdcde762020-04-02 11:19:20 -0700635#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
637 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
638 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
639 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
640 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700641#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700643 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Sunil Ravi640215c2023-06-28 23:08:09 +0000644 if (is_6ghz_bss && !rsn_ie) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700645 if (debug_print)
646 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000647 " skip - 6 GHz BSS without RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700648 return 0;
649 }
650
Roshan Pius3a1667e2018-07-03 15:17:14 -0700651 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652 proto_match++;
653
654 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800655 if (debug_print)
656 wpa_dbg(wpa_s, MSG_DEBUG,
657 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658 break;
659 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700660 if (!ie.has_pairwise)
661 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
662 if (!ie.has_group)
663 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664
Sunil Ravi640215c2023-06-28 23:08:09 +0000665 if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
666 /* WEP and TKIP are not allowed on 6 GHz/MLD */
Sunil Ravia04bd252022-05-02 22:54:18 -0700667 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
668 WPA_CIPHER_WEP104 |
669 WPA_CIPHER_TKIP);
670 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
671 WPA_CIPHER_WEP104 |
672 WPA_CIPHER_TKIP);
673 }
674
Hai Shalomfdcde762020-04-02 11:19:20 -0700675#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700676 if (wep_ok &&
677 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
678 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800679 if (debug_print)
680 wpa_dbg(wpa_s, MSG_DEBUG,
681 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682 return 1;
683 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700684#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700685
Roshan Pius3a1667e2018-07-03 15:17:14 -0700686 if (!(ie.proto & ssid->proto) &&
687 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800688 if (debug_print)
689 wpa_dbg(wpa_s, MSG_DEBUG,
690 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691 break;
692 }
693
694 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800695 if (debug_print)
696 wpa_dbg(wpa_s, MSG_DEBUG,
697 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698 break;
699 }
700
701 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800702 if (debug_print)
703 wpa_dbg(wpa_s, MSG_DEBUG,
704 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700705 break;
706 }
707
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700708 if (ssid->group_mgmt_cipher &&
709 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
710 if (debug_print)
711 wpa_dbg(wpa_s, MSG_DEBUG,
712 " skip RSN IE - group mgmt cipher mismatch");
713 break;
714 }
715
Sunil Ravi640215c2023-06-28 23:08:09 +0000716 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700717 /* MFPC must be supported on 6 GHz */
718 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
719 if (debug_print)
720 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000721 " skip RSNE - 6 GHz without MFPC");
Sunil Ravia04bd252022-05-02 22:54:18 -0700722 break;
723 }
724
725 /* WPA PSK is not allowed on the 6 GHz band */
726 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
727 WPA_KEY_MGMT_FT_PSK |
728 WPA_KEY_MGMT_PSK_SHA256);
729 }
730
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700731 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800732 if (debug_print)
733 wpa_dbg(wpa_s, MSG_DEBUG,
734 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700735 break;
736 }
737
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700738 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800739 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800740 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800741 if (debug_print)
742 wpa_dbg(wpa_s, MSG_DEBUG,
743 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744 break;
745 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800746 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
747 wpas_get_ssid_pmf(wpa_s, ssid) ==
748 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800749 if (debug_print)
750 wpa_dbg(wpa_s, MSG_DEBUG,
751 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800752 break;
753 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800755 if (debug_print)
756 wpa_dbg(wpa_s, MSG_DEBUG,
757 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700758 return 1;
759 }
760
Sunil Ravi640215c2023-06-28 23:08:09 +0000761 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700762 if (debug_print)
763 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000764 " skip - 6 GHz BSS without matching RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700765 return 0;
766 }
767
Sunil Ravi72e01222024-03-09 01:25:43 +0000768 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
769
Roshan Pius3a1667e2018-07-03 15:17:14 -0700770 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
771 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Sunil Ravi72e01222024-03-09 01:25:43 +0000772#ifdef CONFIG_OWE
773 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && ssid->owe_only &&
774 !wpa_ie && !rsn_ie &&
775 wpa_s->owe_transition_select &&
776 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
777 ssid->owe_transition_bss_select_count + 1 <=
778 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
779 ssid->owe_transition_bss_select_count++;
780 if (debug_print)
781 wpa_dbg(wpa_s, MSG_DEBUG,
782 " skip OWE open BSS (selection count %d does not exceed %d)",
783 ssid->owe_transition_bss_select_count,
784 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
785 wpa_s->owe_transition_search = 1;
786 return 0;
787 }
788#endif /* CONFIG_OWE */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800789 if (debug_print)
790 wpa_dbg(wpa_s, MSG_DEBUG,
791 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700792 return 0;
793 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700794
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700795 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
796 proto_match++;
797
798 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800799 if (debug_print)
800 wpa_dbg(wpa_s, MSG_DEBUG,
801 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802 break;
803 }
804
Hai Shalomfdcde762020-04-02 11:19:20 -0700805#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 if (wep_ok &&
807 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
808 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800809 if (debug_print)
810 wpa_dbg(wpa_s, MSG_DEBUG,
811 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700812 return 1;
813 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700814#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815
816 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800817 if (debug_print)
818 wpa_dbg(wpa_s, MSG_DEBUG,
819 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820 break;
821 }
822
823 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800824 if (debug_print)
825 wpa_dbg(wpa_s, MSG_DEBUG,
826 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827 break;
828 }
829
830 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800831 if (debug_print)
832 wpa_dbg(wpa_s, MSG_DEBUG,
833 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700834 break;
835 }
836
837 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800838 if (debug_print)
839 wpa_dbg(wpa_s, MSG_DEBUG,
840 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841 break;
842 }
843
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800844 if (debug_print)
845 wpa_dbg(wpa_s, MSG_DEBUG,
846 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847 return 1;
848 }
849
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700850 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
851 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800852 if (debug_print)
853 wpa_dbg(wpa_s, MSG_DEBUG,
854 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700855 return 1;
856 }
857
Roshan Pius3a1667e2018-07-03 15:17:14 -0700858#ifdef CONFIG_OWE
859 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
860 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800861 if (wpa_s->owe_transition_select &&
862 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
863 ssid->owe_transition_bss_select_count + 1 <=
864 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
865 ssid->owe_transition_bss_select_count++;
866 if (debug_print)
867 wpa_dbg(wpa_s, MSG_DEBUG,
868 " skip OWE transition BSS (selection count %d does not exceed %d)",
869 ssid->owe_transition_bss_select_count,
870 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
871 wpa_s->owe_transition_search = 1;
872 return 0;
873 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700874 if (debug_print)
875 wpa_dbg(wpa_s, MSG_DEBUG,
876 " allow in OWE transition mode");
877 return 1;
878 }
879#endif /* CONFIG_OWE */
880
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
882 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800883 if (debug_print)
884 wpa_dbg(wpa_s, MSG_DEBUG,
885 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700886 return 0;
887 }
888
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800889 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
890 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800891 if (debug_print)
892 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800893 return 1;
894 }
895
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800897 if (debug_print)
898 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700899 return 1;
900 }
901
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800902 if (debug_print)
903 wpa_dbg(wpa_s, MSG_DEBUG,
904 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905
906 return 0;
907}
908
909
910static int freq_allowed(int *freqs, int freq)
911{
912 int i;
913
914 if (freqs == NULL)
915 return 1;
916
917 for (i = 0; freqs[i]; i++)
918 if (freqs[i] == freq)
919 return 1;
920 return 0;
921}
922
923
Hai Shalomfdcde762020-04-02 11:19:20 -0700924static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
925 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800926{
927 const struct hostapd_hw_modes *mode = NULL, *modes;
928 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
929 const u8 *rate_ie;
930 int i, j, k;
931
932 if (bss->freq == 0)
933 return 1; /* Cannot do matching without knowing band */
934
935 modes = wpa_s->hw.modes;
936 if (modes == NULL) {
937 /*
938 * The driver does not provide any additional information
939 * about the utilized hardware, so allow the connection attempt
940 * to continue.
941 */
942 return 1;
943 }
944
945 for (i = 0; i < wpa_s->hw.num_modes; i++) {
946 for (j = 0; j < modes[i].num_channels; j++) {
947 int freq = modes[i].channels[j].freq;
948 if (freq == bss->freq) {
949 if (mode &&
950 mode->mode == HOSTAPD_MODE_IEEE80211G)
951 break; /* do not allow 802.11b replace
952 * 802.11g */
953 mode = &modes[i];
954 break;
955 }
956 }
957 }
958
959 if (mode == NULL)
960 return 0;
961
962 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700963 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800964 if (rate_ie == NULL)
965 continue;
966
967 for (j = 2; j < rate_ie[1] + 2; j++) {
968 int flagged = !!(rate_ie[j] & 0x80);
969 int r = (rate_ie[j] & 0x7f) * 5;
970
971 /*
972 * IEEE Std 802.11n-2009 7.3.2.2:
973 * The new BSS Membership selector value is encoded
974 * like a legacy basic rate, but it is not a rate and
975 * only indicates if the BSS members are required to
976 * support the mandatory features of Clause 20 [HT PHY]
977 * in order to join the BSS.
978 */
979 if (flagged && ((rate_ie[j] & 0x7f) ==
980 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
981 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800982 if (debug_print)
983 wpa_dbg(wpa_s, MSG_DEBUG,
984 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800985 return 0;
986 }
987 continue;
988 }
989
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700990 /* There's also a VHT selector for 802.11ac */
991 if (flagged && ((rate_ie[j] & 0x7f) ==
992 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
993 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800994 if (debug_print)
995 wpa_dbg(wpa_s, MSG_DEBUG,
996 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700997 return 0;
998 }
999 continue;
1000 }
1001
Sunil Ravi77d572f2023-01-17 23:58:31 +00001002 if (flagged && ((rate_ie[j] & 0x7f) ==
1003 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
1004 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
1005 if (debug_print)
1006 wpa_dbg(wpa_s, MSG_DEBUG,
1007 " hardware does not support HE PHY");
1008 return 0;
1009 }
1010 continue;
1011 }
1012
Hai Shalomc3565922019-10-28 11:58:20 -07001013#ifdef CONFIG_SAE
1014 if (flagged && ((rate_ie[j] & 0x7f) ==
1015 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001016 if (wpa_s->conf->sae_pwe ==
1017 SAE_PWE_HUNT_AND_PECK &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001018 !ssid->sae_password_id &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001019 !is_6ghz_freq(bss->freq) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001020 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -07001021 if (debug_print)
1022 wpa_dbg(wpa_s, MSG_DEBUG,
1023 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001024#ifdef CONFIG_TESTING_OPTIONS
1025 if (wpa_s->ignore_sae_h2e_only) {
1026 wpa_dbg(wpa_s, MSG_DEBUG,
1027 "TESTING: Ignore SAE H2E requirement mismatch");
1028 continue;
1029 }
1030#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -07001031 return 0;
1032 }
1033 continue;
1034 }
1035#endif /* CONFIG_SAE */
1036
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001037 if (!flagged)
1038 continue;
1039
1040 /* check for legacy basic rates */
1041 for (k = 0; k < mode->num_rates; k++) {
1042 if (mode->rates[k] == r)
1043 break;
1044 }
1045 if (k == mode->num_rates) {
1046 /*
1047 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1048 * order to join a BSS all required rates
1049 * have to be supported by the hardware.
1050 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001051 if (debug_print)
1052 wpa_dbg(wpa_s, MSG_DEBUG,
1053 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1054 r / 10, r % 10,
1055 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001056 return 0;
1057 }
1058 }
1059 }
1060
1061 return 1;
1062}
1063
1064
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001065/*
1066 * Test whether BSS is in an ESS.
1067 * This is done differently in DMG (60 GHz) and non-DMG bands
1068 */
1069static int bss_is_ess(struct wpa_bss *bss)
1070{
1071 if (bss_is_dmg(bss)) {
1072 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1073 IEEE80211_CAP_DMG_AP;
1074 }
1075
1076 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1077 IEEE80211_CAP_ESS);
1078}
1079
1080
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001081static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1082{
1083 size_t i;
1084
1085 for (i = 0; i < ETH_ALEN; i++) {
1086 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1087 return 0;
1088 }
1089 return 1;
1090}
1091
1092
1093static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1094{
1095 size_t i;
1096
1097 for (i = 0; i < num; i++) {
1098 const u8 *a = list + i * ETH_ALEN * 2;
1099 const u8 *m = a + ETH_ALEN;
1100
1101 if (match_mac_mask(a, addr, m))
1102 return 1;
1103 }
1104 return 0;
1105}
1106
1107
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001108static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1109 const u8 **ret_ssid, size_t *ret_ssid_len)
1110{
1111#ifdef CONFIG_OWE
1112 const u8 *owe, *pos, *end, *bssid;
1113 u8 ssid_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001114
1115 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1116 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
1117 return;
1118
1119 pos = owe + 6;
1120 end = owe + 2 + owe[1];
1121
1122 if (end - pos < ETH_ALEN + 1)
1123 return;
1124 bssid = pos;
1125 pos += ETH_ALEN;
1126 ssid_len = *pos++;
1127 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1128 return;
1129
1130 /* Match the profile SSID against the OWE transition mode SSID on the
1131 * open network. */
1132 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1133 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1134 *ret_ssid = pos;
1135 *ret_ssid_len = ssid_len;
1136
Hai Shalomfdcde762020-04-02 11:19:20 -07001137 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1138 struct wpa_ssid *ssid;
1139
1140 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1141 if (wpas_network_disabled(wpa_s, ssid))
1142 continue;
1143 if (ssid->ssid_len == ssid_len &&
1144 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1145 /* OWE BSS in transition mode for a currently
1146 * enabled OWE network. */
1147 wpa_dbg(wpa_s, MSG_DEBUG,
1148 "OWE: transition mode OWE SSID for active OWE profile");
1149 bss->flags |= WPA_BSS_OWE_TRANSITION;
1150 break;
1151 }
1152 }
1153 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001154#endif /* CONFIG_OWE */
1155}
1156
1157
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001158static bool wpas_valid_ml_bss(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001159{
1160 u16 removed_links;
1161
Sunil Ravi72e01222024-03-09 01:25:43 +00001162 if (wpa_bss_parse_basic_ml_element(wpa_s, bss, NULL, NULL, NULL, NULL))
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001163 return true;
1164
Sunil Raviaf399a82024-05-05 20:56:55 +00001165 if (!bss->valid_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001166 return true;
1167
1168 /* Check if the current BSS is going to be removed */
1169 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss);
Sunil Raviaf399a82024-05-05 20:56:55 +00001170 if (BIT(bss->mld_link_id) & removed_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001171 return false;
1172
1173 return true;
1174}
1175
1176
Sunil Ravi26978f32021-04-30 15:19:18 -07001177int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001178{
1179 int i, j;
1180
1181 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1182 return 0;
1183
1184 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1185 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1186
1187 for (i = 0; i < mode->num_channels; i++) {
1188 struct hostapd_channel_data *chan = &mode->channels[i];
1189
1190 if (chan->freq == freq)
1191 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1192 }
1193 }
1194
1195 return 1;
1196}
1197
1198
Hai Shalom899fcc72020-10-19 14:38:18 -07001199static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1200 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001201 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001202 bool debug_print);
1203
1204
1205#ifdef CONFIG_SAE_PK
1206static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1207 struct wpa_bss *orig_bss,
1208 struct wpa_ssid *ssid,
1209 const u8 *match_ssid,
1210 size_t match_ssid_len)
1211{
1212 struct wpa_bss *bss;
1213
1214 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1215 int count;
1216 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001217
1218 if (bss == orig_bss)
1219 continue;
1220 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001221 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001222 continue;
1223
1224 /* TODO: Could be more thorough in checking what kind of
1225 * signal strength or throughput estimate would be acceptable
1226 * compared to the originally selected BSS. */
1227 if (bss->est_throughput < 2000)
1228 return false;
1229
Hai Shalom60840252021-02-19 19:02:11 -08001230 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001231 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1232 bss, count, 0))
1233 return true;
1234 }
1235
1236 return false;
1237}
1238#endif /* CONFIG_SAE_PK */
1239
1240
1241static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1242 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001243 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001244 bool debug_print)
1245{
1246 int res;
1247 bool wpa, check_ssid, osen, rsn_osen = false;
1248 struct wpa_ie_data data;
1249#ifdef CONFIG_MBO
1250 const u8 *assoc_disallow;
1251#endif /* CONFIG_MBO */
1252#ifdef CONFIG_SAE
1253 u8 rsnxe_capa = 0;
1254#endif /* CONFIG_SAE */
1255 const u8 *ie;
1256
1257 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1258 wpa = ie && ie[1];
1259 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1260 wpa |= ie && ie[1];
1261 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1262 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1263 rsn_osen = true;
1264 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1265 osen = ie != NULL;
1266
1267#ifdef CONFIG_SAE
1268 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1269 if (ie && ie[1] >= 1)
1270 rsnxe_capa = ie[2];
1271#endif /* CONFIG_SAE */
1272
1273 check_ssid = wpa || ssid->ssid_len > 0;
1274
1275 if (wpas_network_disabled(wpa_s, ssid)) {
1276 if (debug_print)
1277 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1278 return false;
1279 }
1280
1281 res = wpas_temp_disabled(wpa_s, ssid);
1282 if (res > 0) {
1283 if (debug_print)
1284 wpa_dbg(wpa_s, MSG_DEBUG,
1285 " skip - disabled temporarily for %d second(s)",
1286 res);
1287 return false;
1288 }
1289
1290#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001291 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001292 if (debug_print)
1293 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001294 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001295 return false;
1296 }
1297
1298 if (wpa && ssid->ssid_len == 0 &&
1299 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1300 check_ssid = false;
1301
1302 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1303 /* Only allow wildcard SSID match if an AP advertises active
1304 * WPS operation that matches our mode. */
1305 check_ssid = ssid->ssid_len > 0 ||
1306 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1307 }
1308#endif /* CONFIG_WPS */
1309
1310 if (ssid->bssid_set && ssid->ssid_len == 0 &&
Sunil Ravi72e01222024-03-09 01:25:43 +00001311 ether_addr_equal(bss->bssid, ssid->bssid))
Hai Shalom899fcc72020-10-19 14:38:18 -07001312 check_ssid = false;
1313
1314 if (check_ssid &&
1315 (match_ssid_len != ssid->ssid_len ||
1316 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1317 if (debug_print)
1318 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1319 return false;
1320 }
1321
1322 if (ssid->bssid_set &&
Sunil Ravi72e01222024-03-09 01:25:43 +00001323 !ether_addr_equal(bss->bssid, ssid->bssid)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001324 if (debug_print)
1325 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1326 return false;
1327 }
1328
Hai Shalom60840252021-02-19 19:02:11 -08001329 /* check the list of BSSIDs to ignore */
1330 if (ssid->num_bssid_ignore &&
1331 addr_in_list(bss->bssid, ssid->bssid_ignore,
1332 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001333 if (debug_print)
1334 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001335 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001336 return false;
1337 }
1338
Hai Shalom60840252021-02-19 19:02:11 -08001339 /* if there is a list of accepted BSSIDs, only accept those APs */
1340 if (ssid->num_bssid_accept &&
1341 !addr_in_list(bss->bssid, ssid->bssid_accept,
1342 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001343 if (debug_print)
1344 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001345 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001346 return false;
1347 }
1348
1349 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1350 return false;
1351
1352 if (!osen && !wpa &&
1353 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1354 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1355 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1356 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1357 if (debug_print)
1358 wpa_dbg(wpa_s, MSG_DEBUG,
1359 " skip - non-WPA network not allowed");
1360 return false;
1361 }
1362
1363#ifdef CONFIG_WEP
1364 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1365 if (debug_print)
1366 wpa_dbg(wpa_s, MSG_DEBUG,
1367 " skip - ignore WPA/WPA2 AP for WEP network block");
1368 return false;
1369 }
1370#endif /* CONFIG_WEP */
1371
1372 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1373 if (debug_print)
1374 wpa_dbg(wpa_s, MSG_DEBUG,
1375 " skip - non-OSEN network not allowed");
1376 return false;
1377 }
1378
1379 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1380 if (debug_print)
1381 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1382 return false;
1383 }
1384
1385 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1386 !bss_is_pbss(bss)) {
1387 if (debug_print)
1388 wpa_dbg(wpa_s, MSG_DEBUG,
1389 " skip - not ESS, PBSS, or MBSS");
1390 return false;
1391 }
1392
1393 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1394 if (debug_print)
1395 wpa_dbg(wpa_s, MSG_DEBUG,
1396 " skip - PBSS mismatch (ssid %d bss %d)",
1397 ssid->pbss, bss_is_pbss(bss));
1398 return false;
1399 }
1400
1401 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1402 if (debug_print)
1403 wpa_dbg(wpa_s, MSG_DEBUG,
1404 " skip - frequency not allowed");
1405 return false;
1406 }
1407
1408#ifdef CONFIG_MESH
1409 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1410 ssid->frequency != bss->freq) {
1411 if (debug_print)
1412 wpa_dbg(wpa_s, MSG_DEBUG,
1413 " skip - frequency not allowed (mesh)");
1414 return false;
1415 }
1416#endif /* CONFIG_MESH */
1417
1418 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1419 if (debug_print)
1420 wpa_dbg(wpa_s, MSG_DEBUG,
1421 " skip - rate sets do not match");
1422 return false;
1423 }
1424
1425#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001426 /* When using SAE Password Identifier and when operationg on the 6 GHz
1427 * band, only H2E is allowed. */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001428 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1429 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1430 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1431 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001432#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301433 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001434#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001435 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1436 if (debug_print)
1437 wpa_dbg(wpa_s, MSG_DEBUG,
1438 " skip - SAE H2E required, but not supported by the AP");
1439 return false;
1440 }
1441#endif /* CONFIG_SAE */
1442
1443#ifdef CONFIG_SAE_PK
1444 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1445 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1446 if (debug_print)
1447 wpa_dbg(wpa_s, MSG_DEBUG,
1448 " skip - SAE-PK required, but not supported by the AP");
1449 return false;
1450 }
1451#endif /* CONFIG_SAE_PK */
1452
1453#ifndef CONFIG_IBSS_RSN
1454 if (ssid->mode == WPAS_MODE_IBSS &&
1455 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1456 if (debug_print)
1457 wpa_dbg(wpa_s, MSG_DEBUG,
1458 " skip - IBSS RSN not supported in the build");
1459 return false;
1460 }
1461#endif /* !CONFIG_IBSS_RSN */
1462
1463#ifdef CONFIG_P2P
1464 if (ssid->p2p_group &&
1465 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1466 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1467 if (debug_print)
1468 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1469 return false;
1470 }
1471
1472 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1473 struct wpabuf *p2p_ie;
1474 u8 dev_addr[ETH_ALEN];
1475
1476 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1477 if (!ie) {
1478 if (debug_print)
1479 wpa_dbg(wpa_s, MSG_DEBUG,
1480 " skip - no P2P element");
1481 return false;
1482 }
1483 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1484 if (!p2p_ie) {
1485 if (debug_print)
1486 wpa_dbg(wpa_s, MSG_DEBUG,
1487 " skip - could not fetch P2P element");
1488 return false;
1489 }
1490
1491 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
Sunil Ravi72e01222024-03-09 01:25:43 +00001492 !ether_addr_equal(dev_addr, ssid->go_p2p_dev_addr)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001493 if (debug_print)
1494 wpa_dbg(wpa_s, MSG_DEBUG,
1495 " skip - no matching GO P2P Device Address in P2P element");
1496 wpabuf_free(p2p_ie);
1497 return false;
1498 }
1499 wpabuf_free(p2p_ie);
1500 }
1501
1502 /*
1503 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1504 * P2P Group Capability Bitmap and we are not in Group Formation with
1505 * that device.
1506 */
1507#endif /* CONFIG_P2P */
1508
1509 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1510 struct os_reltime diff;
1511
1512 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1513 if (debug_print)
1514 wpa_dbg(wpa_s, MSG_DEBUG,
1515 " skip - scan result not recent enough (%u.%06u seconds too old)",
1516 (unsigned int) diff.sec,
1517 (unsigned int) diff.usec);
1518 return false;
1519 }
1520#ifdef CONFIG_MBO
1521#ifdef CONFIG_TESTING_OPTIONS
1522 if (wpa_s->ignore_assoc_disallow)
1523 goto skip_assoc_disallow;
1524#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001525 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001526 if (assoc_disallow && assoc_disallow[1] >= 1) {
1527 if (debug_print)
1528 wpa_dbg(wpa_s, MSG_DEBUG,
1529 " skip - MBO association disallowed (reason %u)",
1530 assoc_disallow[2]);
1531 return false;
1532 }
1533
1534 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1535 if (debug_print)
1536 wpa_dbg(wpa_s, MSG_DEBUG,
1537 " skip - AP temporarily disallowed");
1538 return false;
1539 }
1540#ifdef CONFIG_TESTING_OPTIONS
1541skip_assoc_disallow:
1542#endif /* CONFIG_TESTING_OPTIONS */
1543#endif /* CONFIG_MBO */
1544
1545#ifdef CONFIG_DPP
1546 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001547 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1548 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001549 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1550 !ssid->dpp_csign)) {
1551 if (debug_print)
1552 wpa_dbg(wpa_s, MSG_DEBUG,
1553 " skip - no PMKSA entry for DPP");
1554 return false;
1555 }
1556#endif /* CONFIG_DPP */
1557
1558#ifdef CONFIG_SAE_PK
1559 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1560 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1561 ((ssid->sae_password &&
1562 sae_pk_valid_password(ssid->sae_password)) ||
1563 (!ssid->sae_password && ssid->passphrase &&
1564 sae_pk_valid_password(ssid->passphrase))) &&
1565 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1566 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1567 match_ssid_len)) {
1568 if (debug_print)
1569 wpa_dbg(wpa_s, MSG_DEBUG,
1570 " skip - another acceptable BSS with SAE-PK in the same ESS");
1571 return false;
1572 }
1573#endif /* CONFIG_SAE_PK */
1574
1575 if (bss->ssid_len == 0) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001576#ifdef CONFIG_OWE
1577 const u8 *owe_ssid = NULL;
1578 size_t owe_ssid_len = 0;
1579
1580 owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len);
1581 if (owe_ssid && owe_ssid_len &&
1582 owe_ssid_len == ssid->ssid_len &&
1583 os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) {
1584 if (debug_print)
1585 wpa_dbg(wpa_s, MSG_DEBUG,
1586 " skip - no SSID in BSS entry for a possible OWE transition mode BSS");
1587 int_array_add_unique(&wpa_s->owe_trans_scan_freq,
1588 bss->freq);
1589 return false;
1590 }
1591#endif /* CONFIG_OWE */
Hai Shalom899fcc72020-10-19 14:38:18 -07001592 if (debug_print)
1593 wpa_dbg(wpa_s, MSG_DEBUG,
1594 " skip - no SSID known for the BSS");
1595 return false;
1596 }
1597
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001598 if (!wpas_valid_ml_bss(wpa_s, bss)) {
1599 if (debug_print)
1600 wpa_dbg(wpa_s, MSG_DEBUG,
1601 " skip - ML BSS going to be removed");
1602 return false;
1603 }
1604
Hai Shalom899fcc72020-10-19 14:38:18 -07001605 /* Matching configuration found */
1606 return true;
1607}
1608
1609
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001610struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1611 int i, struct wpa_bss *bss,
1612 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001613 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001614{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001615 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001616 const u8 *ie;
1617 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001618 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001619 const u8 *match_ssid;
1620 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001621 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001622
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001623 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001624 wpa_ie_len = ie ? ie[1] : 0;
1625
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001626 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001627 rsn_ie_len = ie ? ie[1] : 0;
1628
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001629 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1630 osen = ie != NULL;
1631
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001632 if (debug_print) {
1633 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1634 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1635 i, MAC2STR(bss->bssid),
1636 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1637 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1638 bss->freq,
1639 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1640 " wps" : "",
1641 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1642 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1643 ? " p2p" : "",
1644 osen ? " osen=1" : "");
1645 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001646
Hai Shalom60840252021-02-19 19:02:11 -08001647 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1648 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001649 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001650 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001651 /*
1652 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001653 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001654 * should not be done with multiple enabled networks to
1655 * avoid getting forced to move into a worse ESS on
1656 * single error if there are no other BSSes of the
1657 * current ESS.
1658 */
1659 limit = 0;
1660 }
Hai Shalom60840252021-02-19 19:02:11 -08001661 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001662 if (debug_print) {
1663 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001664 " skip - BSSID ignored (count=%d limit=%d)",
1665 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001666 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001667 return NULL;
1668 }
1669 }
1670
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001671 match_ssid = bss->ssid;
1672 match_ssid_len = bss->ssid_len;
1673 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1674
1675 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001676 if (debug_print)
1677 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001678 return NULL;
1679 }
1680
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001681 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001682 if (debug_print)
1683 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001684 return NULL;
1685 }
1686
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001687 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001688 if (debug_print)
1689 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001690 return NULL;
1691 }
1692
Hai Shalomfdcde762020-04-02 11:19:20 -07001693 if (disabled_freq(wpa_s, bss->freq)) {
1694 if (debug_print)
1695 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1696 return NULL;
1697 }
1698
Sunil Ravi72e01222024-03-09 01:25:43 +00001699 if (wnm_is_bss_excluded(wpa_s, bss)) {
1700 if (debug_print)
1701 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID excluded");
1702 return NULL;
1703 }
Sunil Ravi72e01222024-03-09 01:25:43 +00001704
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001705 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001706 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001707 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001708 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001709 }
1710
1711 /* No matching configuration found */
1712 return NULL;
1713}
1714
1715
1716static struct wpa_bss *
1717wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001718 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001719 struct wpa_ssid **selected_ssid,
1720 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001721{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001722 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001723
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001724 if (wpa_s->current_ssid) {
1725 struct wpa_ssid *ssid;
1726
1727 wpa_dbg(wpa_s, MSG_DEBUG,
1728 "Scan results matching the currently selected network");
1729 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1730 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1731
1732 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1733 only_first_ssid, 0);
1734 if (ssid != wpa_s->current_ssid)
1735 continue;
1736 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1737 " freq=%d level=%d snr=%d est_throughput=%u",
1738 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1739 bss->snr, bss->est_throughput);
1740 }
1741 }
1742
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001743 if (only_first_ssid)
1744 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1745 group->id);
1746 else
1747 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1748 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001749
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001750 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1751 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001752
1753 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001754 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001755 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001756 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 if (!*selected_ssid)
1758 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001759 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001760 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001761 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001762 MAC2STR(bss->bssid),
1763 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1764 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001765 }
1766
1767 return NULL;
1768}
1769
1770
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001771struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1772 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001773{
1774 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001775 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001776 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001777 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001779 if (wpa_s->last_scan_res == NULL ||
1780 wpa_s->last_scan_res_used == 0)
1781 return NULL; /* no scan results from last update */
1782
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001783 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001784 /* check that next_ssid is still valid */
1785 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1786 if (ssid == wpa_s->next_ssid)
1787 break;
1788 }
1789 next_ssid = ssid;
1790 wpa_s->next_ssid = NULL;
1791 }
1792
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001793 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001794 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1795 if (next_ssid && next_ssid->priority ==
1796 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001797 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001798 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001799 if (selected)
1800 break;
1801 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001802 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001803 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001804 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805 if (selected)
1806 break;
1807 }
1808
Sunil Raviaf399a82024-05-05 20:56:55 +00001809 if (!selected &&
1810 (wpa_s->bssid_ignore || wnm_active_bss_trans_mgmt(wpa_s)) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001811 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001812 wpa_dbg(wpa_s, MSG_DEBUG,
1813 "No APs found - clear BSSID ignore list and try again");
Sunil Raviaf399a82024-05-05 20:56:55 +00001814 wnm_btm_reset(wpa_s);
Hai Shalom60840252021-02-19 19:02:11 -08001815 wpa_bssid_ignore_clear(wpa_s);
1816 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817 } else if (selected == NULL)
1818 break;
1819 }
1820
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001821 ssid = *selected_ssid;
1822 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1823 !ssid->passphrase && !ssid->ext_psk) {
1824 const char *field_name, *txt = NULL;
1825
1826 wpa_dbg(wpa_s, MSG_DEBUG,
1827 "PSK/passphrase not yet available for the selected network");
1828
1829 wpas_notify_network_request(wpa_s, ssid,
1830 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1831
1832 field_name = wpa_supplicant_ctrl_req_to_string(
1833 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1834 if (field_name == NULL)
1835 return NULL;
1836
1837 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1838
1839 selected = NULL;
1840 }
1841
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001842 return selected;
1843}
1844
1845
1846static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1847 int timeout_sec, int timeout_usec)
1848{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001849 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850 /*
1851 * No networks are enabled; short-circuit request so
1852 * we don't wait timeout seconds before transitioning
1853 * to INACTIVE state.
1854 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001855 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1856 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001857 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1858 return;
1859 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001860
1861 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001862 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1863}
1864
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001865
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001866static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s)
1867{
1868 if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss)
1869 return false;
1870
1871 wpa_msg(wpa_s, MSG_DEBUG,
1872 "Request association with " MACSTR " after ML probe",
1873 MAC2STR(wpa_s->ml_connect_probe_bss->bssid));
1874
1875 wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss,
1876 wpa_s->ml_connect_probe_ssid);
1877
1878 wpa_s->ml_connect_probe_ssid = NULL;
1879 wpa_s->ml_connect_probe_bss = NULL;
1880
1881 return true;
1882}
1883
1884
1885static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s,
1886 struct wpa_bss *selected,
1887 struct wpa_ssid *ssid)
1888{
1889 int *freqs;
1890 u16 missing_links = 0, removed_links;
Sunil Ravi72e01222024-03-09 01:25:43 +00001891 u8 ap_mld_id;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001892
1893 if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
1894 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)))
1895 return 0;
1896
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001897 if (wpa_bss_parse_basic_ml_element(wpa_s, selected, NULL,
Sunil Ravi72e01222024-03-09 01:25:43 +00001898 &missing_links, ssid,
1899 &ap_mld_id) ||
1900 !missing_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001901 return 0;
1902
1903 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected);
1904 missing_links &= ~removed_links;
1905
1906 if (!missing_links)
1907 return 0;
1908
1909 wpa_dbg(wpa_s, MSG_DEBUG,
1910 "MLD: Doing an ML probe for missing links 0x%04x",
1911 missing_links);
1912
1913 freqs = os_malloc(sizeof(int) * 2);
1914 if (!freqs)
1915 return 0;
1916
1917 wpa_s->ml_connect_probe_ssid = ssid;
1918 wpa_s->ml_connect_probe_bss = selected;
1919
1920 freqs[0] = selected->freq;
1921 freqs[1] = 0;
1922
1923 wpa_s->manual_scan_passive = 0;
1924 wpa_s->manual_scan_use_id = 0;
1925 wpa_s->manual_scan_only_new = 0;
1926 wpa_s->scan_id_count = 0;
1927 os_free(wpa_s->manual_scan_freqs);
1928 wpa_s->manual_scan_freqs = freqs;
1929
1930 os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN);
Sunil Ravi72e01222024-03-09 01:25:43 +00001931
1932 /*
1933 * In case the ML probe request is intended to retrieve information from
1934 * the transmitted BSS, the AP MLD ID should be included and should be
1935 * set to zero.
1936 * In case the ML probe requested is intended to retrieve information
1937 * from a non-transmitted BSS, the AP MLD ID should not be included.
1938 */
1939 if (ap_mld_id)
1940 wpa_s->ml_probe_mld_id = -1;
1941 else
1942 wpa_s->ml_probe_mld_id = 0;
1943
1944 if (ssid && ssid->ssid_len) {
1945 os_free(wpa_s->ssids_from_scan_req);
1946 wpa_s->num_ssids_from_scan_req = 0;
1947
1948 wpa_s->ssids_from_scan_req =
1949 os_zalloc(sizeof(struct wpa_ssid_value));
1950 if (wpa_s->ssids_from_scan_req) {
1951 wpa_printf(MSG_DEBUG,
1952 "MLD: ML probe: With direct SSID");
1953
1954 wpa_s->num_ssids_from_scan_req = 1;
1955 wpa_s->ssids_from_scan_req[0].ssid_len = ssid->ssid_len;
1956 os_memcpy(wpa_s->ssids_from_scan_req[0].ssid,
1957 ssid->ssid, ssid->ssid_len);
1958 }
1959 }
1960
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001961 wpa_s->ml_probe_links = missing_links;
1962
1963 wpa_s->normal_scans = 0;
1964 wpa_s->scan_req = MANUAL_SCAN_REQ;
1965 wpa_s->after_wps = 0;
1966 wpa_s->known_wps_freq = 0;
1967 wpa_supplicant_req_scan(wpa_s, 0, 0);
1968
1969 return 1;
1970}
1971
1972
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001973int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001974 struct wpa_bss *selected,
1975 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001976{
Sunil Ravi640215c2023-06-28 23:08:09 +00001977#ifdef IEEE8021X_EAPOL
Sunil Ravi036cec52023-03-29 11:35:17 -07001978 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
1979 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00001980 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001981 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1982 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001983 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001984 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001985#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001986 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1987 wpa_s->p2p_in_provisioning) {
1988 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1989 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001990 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001991 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001992#endif /* CONFIG_P2P */
1993
1994#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001995 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001996 wpas_wps_cancel(wpa_s);
1997#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001998 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001999 }
Sunil Ravi640215c2023-06-28 23:08:09 +00002000#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002001
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002002 wpa_msg(wpa_s, MSG_DEBUG,
2003 "Considering connect request: reassociate: %d selected: "
2004 MACSTR " bssid: " MACSTR " pending: " MACSTR
2005 " wpa_state: %s ssid=%p current_ssid=%p",
2006 wpa_s->reassociate, MAC2STR(selected->bssid),
2007 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
2008 wpa_supplicant_state_txt(wpa_s->wpa_state),
2009 ssid, wpa_s->current_ssid);
2010
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002011 /*
2012 * Do not trigger new association unless the BSSID has changed or if
2013 * reassociation is requested. If we are in process of associating with
2014 * the selected BSSID, do not trigger new attempt.
2015 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002016 if (wpa_s->reassociate ||
Sunil Ravi72e01222024-03-09 01:25:43 +00002017 (!ether_addr_equal(selected->bssid, wpa_s->bssid) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002018 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
2019 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002020 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
Sunil Ravi72e01222024-03-09 01:25:43 +00002021 !ether_addr_equal(selected->bssid, wpa_s->pending_bssid)) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002022 (is_zero_ether_addr(wpa_s->pending_bssid) &&
2023 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002024 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
2025 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002026 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002027 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002028
2029 if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid))
2030 return 0;
2031
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002032 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
2033 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002034 wpa_supplicant_associate(wpa_s, selected, ssid);
2035 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002036 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
2037 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002038 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002039
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002040 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002041}
2042
2043
2044static struct wpa_ssid *
2045wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
2046{
Hai Shalomfdcde762020-04-02 11:19:20 -07002047 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002048 struct wpa_ssid *ssid;
2049
2050 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
2051 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
2052 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002053 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002054 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002055#ifndef CONFIG_IBSS_RSN
2056 if (ssid->mode == WPAS_MODE_IBSS &&
2057 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
2058 WPA_KEY_MGMT_WPA_NONE))) {
2059 wpa_msg(wpa_s, MSG_INFO,
2060 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
2061 wpa_ssid_txt(ssid->ssid,
2062 ssid->ssid_len));
2063 continue;
2064 }
2065#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07002066 if (ssid->mode == WPAS_MODE_IBSS ||
2067 ssid->mode == WPAS_MODE_AP ||
2068 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002069 return ssid;
2070 }
2071 }
2072 return NULL;
2073}
2074
2075
2076/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
2077 * on BSS added and BSS changed events */
2078static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03002079 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002080{
Jouni Malinen87fd2792011-05-16 18:35:42 +03002081 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082
2083 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
2084 return;
2085
Jouni Malinen87fd2792011-05-16 18:35:42 +03002086 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002087 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088
Jouni Malinen87fd2792011-05-16 18:35:42 +03002089 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002090 if (ssid == NULL)
2091 continue;
2092
Jouni Malinen87fd2792011-05-16 18:35:42 +03002093 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002094 if (rsn == NULL)
2095 continue;
2096
Jouni Malinen87fd2792011-05-16 18:35:42 +03002097 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002098 }
2099
2100}
2101
2102
Hai Shalomfdcde762020-04-02 11:19:20 -07002103#ifndef CONFIG_NO_ROAMING
2104
2105static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
2106{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002107 if (noise == WPA_INVALID_NOISE) {
2108 if (IS_5GHZ(frequency)) {
2109 noise = DEFAULT_NOISE_FLOOR_5GHZ;
2110 } else if (is_6ghz_freq(frequency)) {
2111 noise = DEFAULT_NOISE_FLOOR_6GHZ;
2112 } else {
2113 noise = DEFAULT_NOISE_FLOOR_2GHZ;
2114 }
2115 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002116 return avg_signal - noise;
2117}
2118
2119
2120static unsigned int
2121wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
2122 const struct wpa_bss *bss, int snr)
2123{
2124 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08002125 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07002126 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002127 enum chan_width max_cw = CHAN_WIDTH_UNKNOWN;
Hai Shalomfdcde762020-04-02 11:19:20 -07002128
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002129 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq,
2130 &max_cw);
Hai Shalomfdcde762020-04-02 11:19:20 -07002131}
2132
Hai Shalomfdcde762020-04-02 11:19:20 -07002133
Sunil Ravi72e01222024-03-09 01:25:43 +00002134static int wpas_evaluate_band_score(int frequency)
2135{
2136 if (is_6ghz_freq(frequency))
2137 return 2;
2138 if (IS_5GHZ(frequency))
2139 return 1;
2140 return 0;
2141}
2142
2143
Hai Shalom899fcc72020-10-19 14:38:18 -07002144int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
2145 struct wpa_bss *current_bss,
2146 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002147{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002148 int min_diff, diff;
Sunil Ravi72e01222024-03-09 01:25:43 +00002149 int cur_band_score, sel_band_score;
Sunil Ravi036cec52023-03-29 11:35:17 -07002150 int to_5ghz, to_6ghz;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002151 int cur_level, sel_level;
Hai Shalomfdcde762020-04-02 11:19:20 -07002152 unsigned int cur_est, sel_est;
2153 struct wpa_signal_info si;
2154 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07002155 int ret = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002156 const u8 *cur_ies = wpa_bss_ie_ptr(current_bss);
2157 const u8 *sel_ies = wpa_bss_ie_ptr(selected);
2158 size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len :
2159 current_bss->beacon_ie_len;
2160 size_t sel_ie_len = selected->ie_len ? selected->ie_len :
2161 selected->beacon_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002163 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002164 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002165 " freq=%d level=%d snr=%d est_throughput=%u",
2166 MAC2STR(current_bss->bssid),
2167 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002168 current_bss->snr, current_bss->est_throughput);
2169 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002170 " freq=%d level=%d snr=%d est_throughput=%u",
2171 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002172 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002173
2174 if (wpa_s->current_ssid->bssid_set &&
Sunil Ravi72e01222024-03-09 01:25:43 +00002175 ether_addr_equal(selected->bssid, wpa_s->current_ssid->bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002176 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2177 "has preferred BSSID");
2178 return 1;
2179 }
2180
Hai Shalomfdcde762020-04-02 11:19:20 -07002181 /*
2182 * Try to poll the signal from the driver since this will allow to get
2183 * more accurate values. In some cases, there can be big differences
2184 * between the RSSI of the Probe Response frames of the AP we are
2185 * associated with and the Beacon frames we hear from the same AP after
2186 * association. This can happen, e.g., when there are two antennas that
2187 * hear the AP very differently. If the driver chooses to hear the
2188 * Probe Response frames during the scan on the "bad" antenna because
2189 * it wants to save power, but knows to choose the other antenna after
2190 * association, we will hear our AP with a low RSSI as part of the
2191 * scan even when we can hear it decently on the other antenna. To cope
2192 * with this, ask the driver to teach us how it hears the AP. Also, the
2193 * scan results may be a bit old, since we can very quickly get fresh
2194 * information about our currently associated AP.
2195 */
2196 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002197 (si.data.avg_beacon_signal || si.data.avg_signal)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002198 /*
2199 * Normalize avg_signal to the RSSI over 20 MHz, as the
2200 * throughput is estimated based on the RSSI over 20 MHz
2201 */
Sunil Ravi77d572f2023-01-17 23:58:31 +00002202 cur_level = si.data.avg_beacon_signal ?
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002203 si.data.avg_beacon_signal :
2204 (si.data.avg_signal -
2205 wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2206 si.chanwidth));
Hai Shalomfdcde762020-04-02 11:19:20 -07002207 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2208 si.current_noise);
2209
2210 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2211 current_bss,
2212 cur_snr);
2213 wpa_dbg(wpa_s, MSG_DEBUG,
2214 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2215 cur_level, cur_snr, cur_est);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002216 } else {
2217 /* Level and SNR are measured over 20 MHz channel */
2218 cur_level = current_bss->level;
2219 cur_snr = current_bss->snr;
2220 cur_est = current_bss->est_throughput;
Hai Shalomfdcde762020-04-02 11:19:20 -07002221 }
2222
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002223 /* Adjust the SNR of BSSes based on the channel width. */
2224 cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2225 current_bss->max_cw);
2226 cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len,
2227 current_bss->max_cw, cur_snr);
2228
2229 sel_est = selected->est_throughput;
2230 sel_level = selected->level +
2231 wpas_channel_width_rssi_bump(sel_ies, sel_ie_len,
2232 selected->max_cw);
2233
Hai Shalomfdcde762020-04-02 11:19:20 -07002234 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002235 wpa_dbg(wpa_s, MSG_DEBUG,
2236 "Allow reassociation - selected BSS has better estimated throughput");
2237 return 1;
2238 }
2239
Dmitry Shmidte4663042016-04-04 10:07:49 -07002240 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
Sunil Ravi036cec52023-03-29 11:35:17 -07002241 to_6ghz = is_6ghz_freq(selected->freq) &&
2242 !is_6ghz_freq(current_bss->freq);
Dmitry Shmidte4663042016-04-04 10:07:49 -07002243
Sunil Ravi036cec52023-03-29 11:35:17 -07002244 if (cur_level < 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002245 cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002246 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002247 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2248 "signal level");
2249 return 0;
2250 }
2251
Hai Shalomfdcde762020-04-02 11:19:20 -07002252 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002253 wpa_dbg(wpa_s, MSG_DEBUG,
2254 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002255 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002256 }
2257
Hai Shalomfdcde762020-04-02 11:19:20 -07002258 if (cur_snr > GREAT_SNR) {
2259 wpa_dbg(wpa_s, MSG_DEBUG,
2260 "Skip roam - Current BSS has good SNR (%u > %u)",
2261 cur_snr, GREAT_SNR);
2262 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002264
Hai Shalomfdcde762020-04-02 11:19:20 -07002265 if (cur_level < -85) /* ..-86 dBm */
2266 min_diff = 1;
2267 else if (cur_level < -80) /* -85..-81 dBm */
2268 min_diff = 2;
2269 else if (cur_level < -75) /* -80..-76 dBm */
2270 min_diff = 3;
2271 else if (cur_level < -70) /* -75..-71 dBm */
2272 min_diff = 4;
2273 else if (cur_level < 0) /* -70..-1 dBm */
2274 min_diff = 5;
2275 else /* unspecified units (not in dBm) */
2276 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002277
Hai Shalomfdcde762020-04-02 11:19:20 -07002278 if (cur_est > sel_est * 1.5)
2279 min_diff += 10;
2280 else if (cur_est > sel_est * 1.2)
2281 min_diff += 5;
2282 else if (cur_est > sel_est * 1.1)
2283 min_diff += 2;
2284 else if (cur_est > sel_est)
2285 min_diff++;
2286 else if (sel_est > cur_est * 1.5)
2287 min_diff -= 10;
2288 else if (sel_est > cur_est * 1.2)
2289 min_diff -= 5;
2290 else if (sel_est > cur_est * 1.1)
2291 min_diff -= 2;
2292 else if (sel_est > cur_est)
2293 min_diff--;
2294
Sunil Ravi72e01222024-03-09 01:25:43 +00002295 cur_band_score = wpas_evaluate_band_score(current_bss->freq);
2296 sel_band_score = wpas_evaluate_band_score(selected->freq);
2297 min_diff += (cur_band_score - sel_band_score) * 2;
2298 if (wpa_s->signal_threshold && cur_level <= wpa_s->signal_threshold &&
2299 sel_level > wpa_s->signal_threshold)
Sunil Ravi036cec52023-03-29 11:35:17 -07002300 min_diff -= 2;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002301 diff = sel_level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002302 if (diff < min_diff) {
2303 wpa_dbg(wpa_s, MSG_DEBUG,
2304 "Skip roam - too small difference in signal level (%d < %d)",
2305 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002306 ret = 0;
2307 } else {
2308 wpa_dbg(wpa_s, MSG_DEBUG,
2309 "Allow reassociation due to difference in signal level (%d >= %d)",
2310 diff, min_diff);
2311 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002312 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002313 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2314 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2315 " sel_freq=%d sel_level=%d sel_est=%d",
2316 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2317 MAC2STR(current_bss->bssid),
2318 current_bss->freq, cur_level, cur_est,
2319 MAC2STR(selected->bssid),
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002320 selected->freq, sel_level, sel_est);
Hai Shalom899fcc72020-10-19 14:38:18 -07002321 return ret;
2322}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002323
Hai Shalom899fcc72020-10-19 14:38:18 -07002324#endif /* CONFIG_NO_ROAMING */
2325
2326
2327static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2328 struct wpa_bss *selected,
2329 struct wpa_ssid *ssid)
2330{
2331 struct wpa_bss *current_bss = NULL;
Sunil Ravi72e01222024-03-09 01:25:43 +00002332 const u8 *bssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07002333
2334 if (wpa_s->reassociate)
2335 return 1; /* explicit request to reassociate */
2336 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2337 return 1; /* we are not associated; continue */
2338 if (wpa_s->current_ssid == NULL)
2339 return 1; /* unknown current SSID */
2340 if (wpa_s->current_ssid != ssid)
2341 return 1; /* different network block */
2342
2343 if (wpas_driver_bss_selection(wpa_s))
2344 return 0; /* Driver-based roaming */
2345
Sunil Ravi72e01222024-03-09 01:25:43 +00002346 if (wpa_s->valid_links)
2347 bssid = wpa_s->links[wpa_s->mlo_assoc_link_id].bssid;
2348 else
2349 bssid = wpa_s->bssid;
2350
Hai Shalom899fcc72020-10-19 14:38:18 -07002351 if (wpa_s->current_ssid->ssid)
Sunil Ravi72e01222024-03-09 01:25:43 +00002352 current_bss = wpa_bss_get(wpa_s, bssid,
Hai Shalom899fcc72020-10-19 14:38:18 -07002353 wpa_s->current_ssid->ssid,
2354 wpa_s->current_ssid->ssid_len);
2355 if (!current_bss)
Sunil Ravi72e01222024-03-09 01:25:43 +00002356 current_bss = wpa_bss_get_bssid(wpa_s, bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07002357
2358 if (!current_bss)
2359 return 1; /* current BSS not seen in scan results */
2360
2361 if (current_bss == selected)
2362 return 0;
2363
2364 if (selected->last_update_idx > current_bss->last_update_idx)
2365 return 1; /* current BSS not seen in the last scan */
2366
2367#ifndef CONFIG_NO_ROAMING
2368 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2369 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002370#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002371 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002372#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002373}
2374
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002375
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002376/*
2377 * Return a negative value if no scan results could be fetched or if scan
2378 * results should not be shared with other virtual interfaces.
2379 * Return 0 if scan results were fetched and may be shared with other
2380 * interfaces.
2381 * Return 1 if scan results may be shared with other virtual interfaces but may
2382 * not trigger any operations.
2383 * Return 2 if the interface was removed and cannot be used.
2384 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002385static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002386 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002387 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002388{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002389 struct wpa_scan_results *scan_res = NULL;
2390 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002391 int ap = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002392 bool trigger_6ghz_scan;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002393#ifndef CONFIG_NO_RANDOM_POOL
2394 size_t i, num;
2395#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002396
2397#ifdef CONFIG_AP
2398 if (wpa_s->ap_iface)
2399 ap = 1;
2400#endif /* CONFIG_AP */
2401
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002402 trigger_6ghz_scan = wpa_s->crossed_6ghz_dom &&
2403 wpa_s->last_scan_all_chan;
2404 wpa_s->crossed_6ghz_dom = false;
2405 wpa_s->last_scan_all_chan = false;
2406
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002407 wpa_supplicant_notify_scanning(wpa_s, 0);
2408
2409 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2410 data ? &data->scan_info :
Sunil Raviaf399a82024-05-05 20:56:55 +00002411 NULL, 1, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002412 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002413 if (wpa_s->conf->ap_scan == 2 || ap ||
2414 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002415 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002416 if (!own_request)
2417 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002418 if (data && data->scan_info.external_scan)
2419 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002420 if (wpa_s->scan_res_fail_handler) {
2421 void (*handler)(struct wpa_supplicant *wpa_s);
2422
2423 handler = wpa_s->scan_res_fail_handler;
2424 wpa_s->scan_res_fail_handler = NULL;
2425 handler(wpa_s);
2426 } else {
2427 wpa_dbg(wpa_s, MSG_DEBUG,
2428 "Failed to get scan results - try scanning again");
2429 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2430 }
2431
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002432 ret = -1;
2433 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002434 }
2435
2436#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002437 num = scan_res->num;
2438 if (num > 10)
2439 num = 10;
2440 for (i = 0; i < num; i++) {
2441 u8 buf[5];
2442 struct wpa_scan_res *res = scan_res->res[i];
2443 buf[0] = res->bssid[5];
2444 buf[1] = res->qual & 0xff;
2445 buf[2] = res->noise & 0xff;
2446 buf[3] = res->level & 0xff;
2447 buf[4] = res->tsf & 0xff;
2448 random_add_randomness(buf, sizeof(buf));
2449 }
2450#endif /* CONFIG_NO_RANDOM_POOL */
2451
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002452 if (update_only) {
2453 ret = 1;
2454 goto scan_work_done;
2455 }
2456
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002457 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002458 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002459 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2460 struct wpa_scan_results *scan_res);
2461
2462 scan_res_handler = wpa_s->scan_res_handler;
2463 wpa_s->scan_res_handler = NULL;
2464 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002465 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002466 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002467 }
2468
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002469 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002470 wpa_s->own_scan_running,
2471 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002472 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002473 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2474 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002475 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2476 wpa_s->manual_scan_id);
2477 wpa_s->manual_scan_use_id = 0;
2478 } else {
2479 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2480 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002481 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002482
2483 wpas_notify_scan_done(wpa_s, 1);
2484
Hai Shalomfdcde762020-04-02 11:19:20 -07002485 if (ap) {
2486 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2487#ifdef CONFIG_AP
2488 if (wpa_s->ap_iface->scan_cb)
2489 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2490#endif /* CONFIG_AP */
2491 goto scan_work_done;
2492 }
2493
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002494 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002495 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 -07002496 wpa_scan_results_free(scan_res);
2497 return 0;
2498 }
2499
Sunil Raviaf399a82024-05-05 20:56:55 +00002500 if (wnm_scan_process(wpa_s, false) > 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002501 goto scan_work_done;
2502
Hai Shalomc1a21442022-02-04 13:43:00 -08002503 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002504 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002505
Sunil Ravi72e01222024-03-09 01:25:43 +00002506#ifndef CONFIG_NO_RRM
Hai Shalom021b0b52019-04-10 11:17:58 -07002507 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002508 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2509 goto scan_work_done;
Sunil Ravi72e01222024-03-09 01:25:43 +00002510#endif /* CONFIG_NO_RRM */
Dmitry Shmidt29333592017-01-09 12:27:11 -08002511
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002512 if (ml_link_probe_scan(wpa_s))
2513 goto scan_work_done;
2514
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002515 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2516 goto scan_work_done;
2517
2518 if (autoscan_notify_scan(wpa_s, scan_res))
2519 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002520
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002521 if (wpa_s->disconnected) {
2522 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002523 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002524 }
2525
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002526 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002527 bgscan_notify_scan(wpa_s, scan_res) == 1)
2528 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002529
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002530 wpas_wps_update_ap_info(wpa_s, scan_res);
2531
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002532 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2533 wpa_s->wpa_state < WPA_COMPLETED)
2534 goto scan_work_done;
2535
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002536 wpa_scan_results_free(scan_res);
2537
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002538 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002539 struct wpa_radio_work *work = wpa_s->scan_work;
2540 wpa_s->scan_work = NULL;
2541 radio_work_done(work);
2542 }
2543
Hai Shalomc3565922019-10-28 11:58:20 -07002544 os_free(wpa_s->last_scan_freqs);
2545 wpa_s->last_scan_freqs = NULL;
2546 wpa_s->num_last_scan_freqs = 0;
2547 if (own_request && data &&
2548 data->scan_info.freqs && data->scan_info.num_freqs) {
2549 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2550 data->scan_info.num_freqs);
2551 if (wpa_s->last_scan_freqs) {
2552 os_memcpy(wpa_s->last_scan_freqs,
2553 data->scan_info.freqs,
2554 sizeof(int) * data->scan_info.num_freqs);
2555 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2556 }
2557 }
2558
Sunil Ravi77d572f2023-01-17 23:58:31 +00002559 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2560 return ret;
2561
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002562 return wpas_select_network_from_last_scan(wpa_s, 1, own_request,
2563 trigger_6ghz_scan, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002564
2565scan_work_done:
2566 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002567 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002568 struct wpa_radio_work *work = wpa_s->scan_work;
2569 wpa_s->scan_work = NULL;
2570 radio_work_done(work);
2571 }
2572 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002573}
2574
2575
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002576static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s,
2577 union wpa_event_data *data)
2578{
2579 struct wpa_driver_scan_params params;
2580 unsigned int j;
2581
2582 wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan");
2583 os_memset(&params, 0, sizeof(params));
2584 params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz;
2585 for (j = 0; j < data->scan_info.num_ssids; j++)
2586 params.ssids[j] = data->scan_info.ssids[j];
2587 params.num_ssids = data->scan_info.num_ssids;
2588 wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
2589 true, !wpa_s->last_scan_non_coloc_6ghz, false);
2590 if (!wpa_supplicant_trigger_scan(wpa_s, &params, true, true)) {
2591 os_free(params.freqs);
2592 return 1;
2593 }
2594 wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan");
2595 os_free(params.freqs);
2596 return 0;
2597}
2598
2599
2600/**
2601 * Select a network from the last scan
2602 * @wpa_s: Pointer to wpa_supplicant data
2603 * @new_scan: Whether this function was called right after a scan has finished
2604 * @own_request: Whether the scan was requested by this interface
2605 * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable
2606 * @data: Scan data from scan that finished if applicable
2607 *
2608 * See _wpa_supplicant_event_scan_results() for return values.
2609 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002610static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002611 int new_scan, int own_request,
2612 bool trigger_6ghz_scan,
2613 union wpa_event_data *data)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002614{
2615 struct wpa_bss *selected;
2616 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002617 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2618
2619 if (time_to_reenable > 0) {
2620 wpa_dbg(wpa_s, MSG_DEBUG,
2621 "Postpone network selection by %d seconds since all networks are disabled",
2622 time_to_reenable);
2623 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2624 eloop_register_timeout(time_to_reenable, 0,
2625 wpas_network_reenabled, wpa_s, NULL);
2626 return 0;
2627 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002628
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002629 if (wpa_s->p2p_mgmt)
2630 return 0; /* no normal connection on p2p_mgmt interface */
2631
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002632 wpa_s->owe_transition_search = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002633#ifdef CONFIG_OWE
2634 os_free(wpa_s->owe_trans_scan_freq);
2635 wpa_s->owe_trans_scan_freq = NULL;
2636#endif /* CONFIG_OWE */
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002637 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002638
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002639#ifdef CONFIG_MESH
2640 if (wpa_s->ifmsh) {
2641 wpa_msg(wpa_s, MSG_INFO,
2642 "Avoiding join because we already joined a mesh group");
2643 return 0;
2644 }
2645#endif /* CONFIG_MESH */
2646
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002647 if (selected) {
2648 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002649 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002650 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002651 if (new_scan)
2652 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002653 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002654 }
2655
Hai Shalomc3565922019-10-28 11:58:20 -07002656 wpa_s->suitable_network++;
2657
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002658 if (ssid != wpa_s->current_ssid &&
2659 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2660 wpa_s->own_disconnect_req = 1;
2661 wpa_supplicant_deauthenticate(
2662 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2663 }
2664
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002665 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002666 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002667 return -1;
2668 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002669 wpa_s->supp_pbc_active = false;
2670
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002671 if (new_scan)
2672 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002673 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002674 * Do not allow other virtual radios to trigger operations based
2675 * on these scan results since we do not want them to start
2676 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002677 */
2678 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002679 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002680 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002681 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2682 ssid = wpa_supplicant_pick_new_network(wpa_s);
2683 if (ssid) {
2684 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2685 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002686 if (new_scan)
2687 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002688 } else if (own_request) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002689 if (wpa_s->support_6ghz && trigger_6ghz_scan && data &&
2690 wpas_trigger_6ghz_scan(wpa_s, data) < 0)
2691 return 1;
2692
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002693 /*
2694 * No SSID found. If SCAN results are as a result of
2695 * own scan request and not due to a scan request on
2696 * another shared interface, try another scan.
2697 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002698 int timeout_sec = wpa_s->scan_interval;
2699 int timeout_usec = 0;
2700#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002701 int res;
2702
2703 res = wpas_p2p_scan_no_go_seen(wpa_s);
2704 if (res == 2)
2705 return 2;
2706 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002707 return 0;
2708
Sunil Ravi77d572f2023-01-17 23:58:31 +00002709 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002710 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002711
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002712 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002713 wpa_s->show_group_started ||
2714 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002715 /*
2716 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002717 * state and during P2P join-a-group operation
2718 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002719 */
2720 timeout_sec = 0;
2721 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002722 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2723 timeout_usec);
2724 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002725 }
2726#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002727#ifdef CONFIG_INTERWORKING
2728 if (wpa_s->conf->auto_interworking &&
2729 wpa_s->conf->interworking &&
2730 wpa_s->conf->cred) {
2731 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2732 "start ANQP fetch since no matching "
2733 "networks found");
2734 wpa_s->network_select = 1;
2735 wpa_s->auto_network_select = 1;
2736 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002737 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002738 }
2739#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002740#ifdef CONFIG_WPS
2741 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2742 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2743 timeout_sec = 0;
2744 timeout_usec = 500000;
2745 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2746 timeout_usec);
2747 return 0;
2748 }
2749#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002750#ifdef CONFIG_OWE
2751 if (wpa_s->owe_transition_search) {
2752 wpa_dbg(wpa_s, MSG_DEBUG,
2753 "OWE: Use shorter wait during transition mode search");
2754 timeout_sec = 0;
2755 timeout_usec = 500000;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002756 if (wpa_s->owe_trans_scan_freq) {
2757 os_free(wpa_s->next_scan_freqs);
2758 wpa_s->next_scan_freqs =
2759 wpa_s->owe_trans_scan_freq;
2760 wpa_s->owe_trans_scan_freq = NULL;
2761 timeout_usec = 100000;
2762 }
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002763 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2764 timeout_usec);
2765 return 0;
2766 }
2767#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002768 if (wpa_supplicant_req_sched_scan(wpa_s))
2769 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2770 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002771
2772 wpa_msg_ctrl(wpa_s, MSG_INFO,
2773 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002774 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002775 }
2776 }
2777 return 0;
2778}
2779
2780
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002781static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2782 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002783{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002784 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002785 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002786
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002787 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002788 if (res == 2) {
2789 /*
2790 * Interface may have been removed, so must not dereference
2791 * wpa_s after this.
2792 */
2793 return 1;
2794 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002795
2796 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002797 /*
2798 * If no scan results could be fetched, then no need to
2799 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002800 * this scan. Similarly, if scan results started a new operation on this
2801 * interface, do not notify other interfaces to avoid concurrent
2802 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002803 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002804 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002805 }
2806
2807 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002808 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002809 * so, they get updated with this same scan info.
2810 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002811 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2812 radio_list) {
2813 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002814 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2815 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002816 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2817 res > 0);
2818 if (res < 0)
2819 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002820 }
2821 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002822
2823 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002824}
2825
2826#endif /* CONFIG_NO_SCAN_PROCESSING */
2827
2828
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002829int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2830{
2831#ifdef CONFIG_NO_SCAN_PROCESSING
2832 return -1;
2833#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002834 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002835
Dmitry Shmidt29333592017-01-09 12:27:11 -08002836 wpa_s->ignore_post_flush_scan_res = 0;
2837
Dmitry Shmidt41712582015-06-29 11:02:15 -07002838 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002839 return -1;
2840
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002841 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002842 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002843 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002844 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2845 return -1;
2846 }
2847
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002848 return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002849#endif /* CONFIG_NO_SCAN_PROCESSING */
2850}
2851
Sunil Ravi77d572f2023-01-17 23:58:31 +00002852
2853int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2854{
2855#ifdef CONFIG_NO_SCAN_PROCESSING
2856 return -1;
2857#else /* CONFIG_NO_SCAN_PROCESSING */
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002858 return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002859#endif /* CONFIG_NO_SCAN_PROCESSING */
2860}
2861
2862
Dmitry Shmidt04949592012-07-19 12:16:46 -07002863#ifdef CONFIG_WNM
2864
2865static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2866{
2867 struct wpa_supplicant *wpa_s = eloop_ctx;
2868
2869 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2870 return;
2871
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002872 if (!wpa_s->no_keep_alive) {
2873 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2874 MAC2STR(wpa_s->bssid));
2875 /* TODO: could skip this if normal data traffic has been sent */
2876 /* TODO: Consider using some more appropriate data frame for
2877 * this */
2878 if (wpa_s->l2)
2879 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2880 (u8 *) "", 0);
2881 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002882
2883#ifdef CONFIG_SME
2884 if (wpa_s->sme.bss_max_idle_period) {
2885 unsigned int msec;
2886 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2887 if (msec > 100)
2888 msec -= 100;
2889 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2890 wnm_bss_keep_alive, wpa_s, NULL);
2891 }
2892#endif /* CONFIG_SME */
2893}
2894
2895
2896static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2897 const u8 *ies, size_t ies_len)
2898{
2899 struct ieee802_11_elems elems;
2900
2901 if (ies == NULL)
2902 return;
2903
2904 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2905 return;
2906
2907#ifdef CONFIG_SME
2908 if (elems.bss_max_idle_period) {
2909 unsigned int msec;
2910 wpa_s->sme.bss_max_idle_period =
2911 WPA_GET_LE16(elems.bss_max_idle_period);
2912 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2913 "TU)%s", wpa_s->sme.bss_max_idle_period,
2914 (elems.bss_max_idle_period[2] & 0x01) ?
2915 " (protected keep-live required)" : "");
2916 if (wpa_s->sme.bss_max_idle_period == 0)
2917 wpa_s->sme.bss_max_idle_period = 1;
2918 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2919 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2920 /* msec times 1000 */
2921 msec = wpa_s->sme.bss_max_idle_period * 1024;
2922 if (msec > 100)
2923 msec -= 100;
2924 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2925 wnm_bss_keep_alive, wpa_s,
2926 NULL);
2927 }
2928 }
2929#endif /* CONFIG_SME */
2930}
2931
2932#endif /* CONFIG_WNM */
2933
2934
2935void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2936{
2937#ifdef CONFIG_WNM
2938 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2939#endif /* CONFIG_WNM */
2940}
2941
2942
Dmitry Shmidt051af732013-10-22 13:52:46 -07002943static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2944 size_t len)
2945{
2946 int res;
2947
2948 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2949 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2950 if (res) {
2951 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2952 }
2953
2954 return res;
2955}
2956
2957
2958static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2959 const u8 *ies, size_t ies_len)
2960{
2961 struct ieee802_11_elems elems;
2962
2963 if (ies == NULL)
2964 return;
2965
2966 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2967 return;
2968
2969 if (elems.qos_map_set) {
2970 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2971 elems.qos_map_set_len);
2972 }
2973}
2974
Dmitry Shmidt051af732013-10-22 13:52:46 -07002975
Sunil Ravi036cec52023-03-29 11:35:17 -07002976static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
2977{
2978 if (wpa_s->enabled_4addr_mode) {
2979 wpa_printf(MSG_DEBUG, "4addr mode already set");
2980 return;
2981 }
2982
2983 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2984 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
2985 goto fail;
2986 }
2987 wpa_s->enabled_4addr_mode = 1;
2988 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
2989 return;
2990
2991fail:
2992 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2993}
2994
2995
Hai Shalom74f70d42019-02-11 14:42:39 -08002996static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2997 const u8 *ies, size_t ies_len)
2998{
2999 struct ieee802_11_elems elems;
Sunil Raviaf399a82024-05-05 20:56:55 +00003000 struct multi_ap_params multi_ap;
3001 u16 status;
Hai Shalom74f70d42019-02-11 14:42:39 -08003002
Hai Shalomfdcde762020-04-02 11:19:20 -07003003 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08003004
Hai Shalomfdcde762020-04-02 11:19:20 -07003005 if (!ies ||
3006 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
Sunil Raviaf399a82024-05-05 20:56:55 +00003007 !elems.multi_ap)
Hai Shalomfdcde762020-04-02 11:19:20 -07003008 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08003009
Sunil Raviaf399a82024-05-05 20:56:55 +00003010 status = check_multi_ap_ie(elems.multi_ap + 4, elems.multi_ap_len - 4,
3011 &multi_ap);
3012 if (status != WLAN_STATUS_SUCCESS)
Hai Shalomfdcde762020-04-02 11:19:20 -07003013 return;
3014
Sunil Raviaf399a82024-05-05 20:56:55 +00003015 wpa_s->multi_ap_backhaul = !!(multi_ap.capability &
3016 MULTI_AP_BACKHAUL_BSS);
3017 wpa_s->multi_ap_fronthaul = !!(multi_ap.capability &
Hai Shalomfdcde762020-04-02 11:19:20 -07003018 MULTI_AP_FRONTHAUL_BSS);
3019 wpa_s->multi_ap_ie = 1;
3020}
3021
3022
3023static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
3024{
3025 if (!wpa_s->current_ssid ||
3026 !wpa_s->current_ssid->multi_ap_backhaul_sta)
3027 return;
3028
3029 if (!wpa_s->multi_ap_ie) {
3030 wpa_printf(MSG_INFO,
3031 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08003032 goto fail;
3033 }
3034
Hai Shalomfdcde762020-04-02 11:19:20 -07003035 if (!wpa_s->multi_ap_backhaul) {
3036 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07003037 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
3038 wpa_printf(MSG_INFO,
3039 "WPS active, accepting fronthaul-only BSS");
3040 /* Don't set 4addr mode in this case, so just return */
3041 return;
3042 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003043 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
3044 goto fail;
3045 }
3046
Sunil Ravi036cec52023-03-29 11:35:17 -07003047 wpa_supplicant_set_4addr_mode(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08003048 return;
3049
3050fail:
3051 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3052}
3053
3054
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003055#ifdef CONFIG_FST
3056static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
3057 const u8 *ie, size_t ie_len)
3058{
3059 struct mb_ies_info mb_ies;
3060
3061 if (!ie || !ie_len || !wpa_s->fst)
3062 return -ENOENT;
3063
3064 os_memset(&mb_ies, 0, sizeof(mb_ies));
3065
3066 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
3067 size_t len;
3068
3069 len = 2 + ie[1];
3070 if (len > ie_len) {
3071 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
3072 ie, ie_len);
3073 break;
3074 }
3075
3076 if (ie[0] == WLAN_EID_MULTI_BAND) {
3077 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
3078 (unsigned int) len);
3079 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
3080 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
3081 mb_ies.nof_ies++;
3082 }
3083
3084 ie_len -= len;
3085 ie += len;
3086 }
3087
3088 if (mb_ies.nof_ies > 0) {
3089 wpabuf_free(wpa_s->received_mb_ies);
3090 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
3091 return 0;
3092 }
3093
3094 return -ENOENT;
3095}
3096#endif /* CONFIG_FST */
3097
3098
Hai Shalomc1a21442022-02-04 13:43:00 -08003099static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
3100 union wpa_event_data *data)
3101{
3102 int sel;
3103 const u8 *p;
3104 int l, len;
3105 bool found = false;
3106 struct wpa_ie_data ie;
3107 struct wpa_ssid *ssid = wpa_s->current_ssid;
3108 struct wpa_bss *bss = wpa_s->current_bss;
3109 int pmf;
3110
3111 if (!ssid)
3112 return 0;
3113
3114 p = data->assoc_info.req_ies;
3115 l = data->assoc_info.req_ies_len;
3116
3117 while (p && l >= 2) {
3118 len = p[1] + 2;
3119 if (len > l) {
3120 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3121 p, l);
3122 break;
3123 }
3124 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3125 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3126 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3127 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3128 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3129 found = true;
3130 break;
3131 }
3132 l -= len;
3133 p += len;
3134 }
3135
Sunil Ravi036cec52023-03-29 11:35:17 -07003136 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
3137 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
Hai Shalomc1a21442022-02-04 13:43:00 -08003138 return 0;
Sunil Ravi036cec52023-03-29 11:35:17 -07003139 }
Hai Shalomc1a21442022-02-04 13:43:00 -08003140
3141 wpa_hexdump(MSG_DEBUG,
3142 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
3143 p, l);
3144
3145 /* Update proto from (Re)Association Request frame info */
3146 wpa_s->wpa_proto = ie.proto;
3147 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
3148 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
3149 !!(wpa_s->wpa_proto &
3150 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
3151
3152 /* Update AKMP suite from (Re)Association Request frame info */
3153 sel = ie.key_mgmt;
3154 if (ssid->key_mgmt)
3155 sel &= ssid->key_mgmt;
3156
3157 wpa_dbg(wpa_s, MSG_DEBUG,
3158 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
3159 ie.key_mgmt, ssid->key_mgmt, sel);
3160 if (ie.key_mgmt && !sel) {
3161 wpa_supplicant_deauthenticate(
3162 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
3163 return -1;
3164 }
3165
Sunil Ravi036cec52023-03-29 11:35:17 -07003166#ifdef CONFIG_OCV
3167 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
3168 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
3169 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
3170 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
3171#endif /* CONFIG_OCV */
3172
Sunil Ravi89eba102022-09-13 21:04:37 -07003173 /*
3174 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
3175 * different AKM.
3176 */
3177 if (wpa_s->key_mgmt != ie.key_mgmt &&
3178 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
3179 if (!ssid->psk_set) {
3180 wpa_dbg(wpa_s, MSG_INFO,
3181 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00003182 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07003183 return -1;
3184 }
3185
3186 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
3187 if (wpa_s->conf->key_mgmt_offload &&
3188 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003189 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
3190 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07003191 wpa_dbg(wpa_s, MSG_ERROR,
3192 "WPA: Cannot set PMK for key management offload");
3193 }
3194
Hai Shalomc1a21442022-02-04 13:43:00 -08003195 wpa_s->key_mgmt = ie.key_mgmt;
3196 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3197 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
3198 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
3199 wpa_s->wpa_proto);
3200
3201 /* Update pairwise cipher from (Re)Association Request frame info */
3202 sel = ie.pairwise_cipher;
3203 if (ssid->pairwise_cipher)
3204 sel &= ssid->pairwise_cipher;
3205
3206 wpa_dbg(wpa_s, MSG_DEBUG,
3207 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
3208 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
3209 if (ie.pairwise_cipher && !sel) {
3210 wpa_supplicant_deauthenticate(
3211 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
3212 return -1;
3213 }
3214
3215 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3216 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3217 wpa_s->pairwise_cipher);
3218 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
3219 wpa_cipher_txt(wpa_s->pairwise_cipher));
3220
3221 /* Update other parameters based on AP's WPA IE/RSNE, if available */
3222 if (!bss) {
3223 wpa_dbg(wpa_s, MSG_DEBUG,
3224 "WPA: current_bss == NULL - skip AP IE check");
3225 return 0;
3226 }
3227
3228 /* Update GTK and IGTK from AP's RSNE */
3229 found = false;
3230
3231 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
3232 const u8 *bss_rsn;
3233
3234 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3235 if (bss_rsn) {
3236 p = bss_rsn;
3237 len = 2 + bss_rsn[1];
3238 found = true;
3239 }
3240 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
3241 const u8 *bss_wpa;
3242
3243 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3244 if (bss_wpa) {
3245 p = bss_wpa;
3246 len = 2 + bss_wpa[1];
3247 found = true;
3248 }
3249 }
3250
3251 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
3252 return 0;
3253
3254 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
3255 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3256 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3257 /* AP does not support MFP, local configuration requires it */
3258 wpa_supplicant_deauthenticate(
3259 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3260 return -1;
3261 }
3262 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3263 pmf == NO_MGMT_FRAME_PROTECTION) {
3264 /* AP requires MFP, local configuration disables it */
3265 wpa_supplicant_deauthenticate(
3266 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3267 return -1;
3268 }
3269
3270 /* Update PMF from local configuration now that MFP validation was done
3271 * above */
3272 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3273
3274 /* Update GTK from AP's RSNE */
3275 sel = ie.group_cipher;
3276 if (ssid->group_cipher)
3277 sel &= ssid->group_cipher;
3278
3279 wpa_dbg(wpa_s, MSG_DEBUG,
3280 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3281 ie.group_cipher, ssid->group_cipher, sel);
3282 if (ie.group_cipher && !sel) {
3283 wpa_supplicant_deauthenticate(
3284 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3285 return -1;
3286 }
3287
3288 wpa_s->group_cipher = ie.group_cipher;
3289 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3290 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3291 wpa_cipher_txt(wpa_s->group_cipher));
3292
3293 /* Update IGTK from AP RSN IE */
3294 sel = ie.mgmt_group_cipher;
3295 if (ssid->group_mgmt_cipher)
3296 sel &= ssid->group_mgmt_cipher;
3297
3298 wpa_dbg(wpa_s, MSG_DEBUG,
3299 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3300 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3301
3302 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3303 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3304 wpa_dbg(wpa_s, MSG_DEBUG,
3305 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3306 ie.capabilities);
3307 ie.mgmt_group_cipher = 0;
3308 }
3309
3310 if (ie.mgmt_group_cipher && !sel) {
3311 wpa_supplicant_deauthenticate(
3312 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3313 return -1;
3314 }
3315
3316 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3317 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3318 wpa_s->mgmt_group_cipher);
3319 if (wpa_s->mgmt_group_cipher)
3320 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3321 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3322 else
3323 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3324
3325 return 0;
3326}
3327
3328
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003329static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3330 union wpa_event_data *data)
3331{
Hai Shalomc3565922019-10-28 11:58:20 -07003332 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003333 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003334 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003335 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003336#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303337 struct wpa_ie_data ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003338#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003339
3340 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07003341 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003342 if (data->assoc_info.req_ies)
3343 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3344 data->assoc_info.req_ies_len);
3345 if (data->assoc_info.resp_ies) {
3346 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3347 data->assoc_info.resp_ies_len);
3348#ifdef CONFIG_TDLS
3349 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3350 data->assoc_info.resp_ies_len);
3351#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003352#ifdef CONFIG_WNM
3353 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3354 data->assoc_info.resp_ies_len);
3355#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003356 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3357 data->assoc_info.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003358 if (wpa_s->hw_capab == CAPAB_VHT &&
3359 get_ie(data->assoc_info.resp_ies,
3360 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3361 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003362
3363 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3364 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003365 }
3366 if (data->assoc_info.beacon_ies)
3367 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3368 data->assoc_info.beacon_ies,
3369 data->assoc_info.beacon_ies_len);
3370 if (data->assoc_info.freq)
3371 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3372 data->assoc_info.freq);
3373
Hai Shalom021b0b52019-04-10 11:17:58 -07003374 wpa_s->connection_set = 0;
3375 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3376 struct ieee802_11_elems req_elems, resp_elems;
3377
3378 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3379 data->assoc_info.req_ies_len,
3380 &req_elems, 0) != ParseFailed &&
3381 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3382 data->assoc_info.resp_ies_len,
3383 &resp_elems, 0) != ParseFailed) {
3384 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003385 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3386 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003387 wpa_s->connection_ht = req_elems.ht_capabilities &&
3388 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003389 /* Do not include subset of VHT on 2.4 GHz vendor
3390 * extension in consideration for reporting VHT
3391 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003392 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003393 resp_elems.vht_capabilities &&
3394 (!data->assoc_info.freq ||
3395 wpas_freq_to_band(data->assoc_info.freq) !=
3396 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003397 wpa_s->connection_he = req_elems.he_capabilities &&
3398 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003399 wpa_s->connection_eht = req_elems.eht_capabilities &&
3400 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003401
3402 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3403 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3404 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3405 max_nss_rx_req : max_nss_rx_resp;
3406 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3407 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3408 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3409 max_nss_tx_req : max_nss_tx_resp;
3410
3411 struct supported_chan_width sta_supported_chan_width =
3412 get_supported_channel_width(&req_elems);
3413 enum chan_width ap_operation_chan_width =
3414 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303415 if (wpa_s->connection_vht || wpa_s->connection_he ||
3416 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003417 wpa_s->connection_channel_bandwidth =
3418 get_sta_operation_chan_width(ap_operation_chan_width,
3419 sta_supported_chan_width);
3420 } else if (wpa_s->connection_ht) {
3421 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3422 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3423 } else {
3424 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3425 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003426 if (req_elems.rrm_enabled)
3427 wpa_s->rrm.rrm_used = 1;
Ainy Kumari322d4fd2024-02-14 13:05:40 +05303428 wpa_s->ap_t2lm_negotiation_support =
3429 is_ap_t2lm_negotiation_supported(resp_elems.basic_mle,
3430 resp_elems.basic_mle_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07003431 }
3432 }
3433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003434 p = data->assoc_info.req_ies;
3435 l = data->assoc_info.req_ies_len;
3436
3437 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3438 while (p && l >= 2) {
3439 len = p[1] + 2;
3440 if (len > l) {
3441 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3442 p, l);
3443 break;
3444 }
Hai Shalomc3565922019-10-28 11:58:20 -07003445 if (!found &&
3446 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3447 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3448 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3449 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3450 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003451 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3452 break;
3453 found = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07003454 wpa_find_assoc_pmkid(wpa_s,
3455 data->assoc_info.authorized);
Hai Shalomc3565922019-10-28 11:58:20 -07003456 }
3457 if (!found_x && p[0] == WLAN_EID_RSNX) {
3458 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3459 break;
3460 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003461 }
3462 l -= len;
3463 p += len;
3464 }
3465 if (!found && data->assoc_info.req_ies)
3466 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003467 if (!found_x && data->assoc_info.req_ies)
3468 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003469
Winnie Chen4138eec2022-11-10 16:32:53 +08003470#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303471 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3472 * to a different security type, update the current supplicant configuration to use the AKM
3473 * and pairwise suites from the assoc IE passed by the driver.
3474 */
3475 if (wpas_driver_bss_selection(wpa_s)) {
3476 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3477 /* Check if firmware has roamed to a different security network */
3478 if(wpa_s->key_mgmt != ie.key_mgmt) {
3479 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3480 ie.key_mgmt);
3481 wpa_s->key_mgmt = ie.key_mgmt;
3482 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3483
3484 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3485 /* Restore PMK as it can get overwritten if the previous
3486 * association was to 802.1X.
3487 */
3488 if ((!(wpa_s->drv_flags &
3489 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3490 (wpa_s->current_ssid) &&
3491 (wpa_s->current_ssid->psk_set)) {
3492 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3493 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3494 "BSSID");
3495 wpa_supplicant_deauthenticate(
3496 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3497 return -1;
3498 }
3499 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3500 PMK_LEN, NULL, bssid);
3501 }
3502 }
3503 }
3504 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3505 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3506 "from Assoc IE", ie.pairwise_cipher);
3507 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3508 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3509 wpa_s->pairwise_cipher);
3510 }
3511 // TODO: Notify the framework about security type change b/230766005
3512 }
3513 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003514#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303515
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003516#ifdef CONFIG_FILS
3517#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003518 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3519 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003520 (!data->assoc_info.resp_frame ||
3521 fils_process_assoc_resp(wpa_s->wpa,
3522 data->assoc_info.resp_frame,
3523 data->assoc_info.resp_frame_len) < 0)) {
3524 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3525 return -1;
3526 }
3527#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003528
3529 /* Additional processing for FILS when SME is in driver */
3530 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3531 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3532 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003533#endif /* CONFIG_FILS */
3534
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003535#ifdef CONFIG_OWE
3536 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003537 !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003538 (!bssid_known ||
Sunil Ravi036cec52023-03-29 11:35:17 -07003539 owe_process_assoc_resp(wpa_s->wpa,
3540 wpa_s->valid_links ?
3541 wpa_s->ap_mld_addr : bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003542 data->assoc_info.resp_ies,
3543 data->assoc_info.resp_ies_len) < 0)) {
3544 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3545 return -1;
3546 }
3547#endif /* CONFIG_OWE */
3548
Hai Shalom021b0b52019-04-10 11:17:58 -07003549#ifdef CONFIG_DPP2
3550 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003551 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3552 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003553 struct ieee802_11_elems elems;
3554
3555 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3556 data->assoc_info.resp_ies_len,
3557 &elems, 0) == ParseFailed ||
3558 !elems.owe_dh)
3559 goto no_pfs;
3560 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3561 elems.owe_dh_len) < 0) {
3562 wpa_supplicant_deauthenticate(wpa_s,
3563 WLAN_REASON_UNSPECIFIED);
3564 return -1;
3565 }
3566
3567 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3568 }
3569no_pfs:
3570#endif /* CONFIG_DPP2 */
3571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003572#ifdef CONFIG_IEEE80211R
3573#ifdef CONFIG_SME
3574 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003575 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003576 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3577 data->assoc_info.resp_ies,
3578 data->assoc_info.resp_ies_len,
3579 bssid) < 0) {
3580 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3581 "Reassociation Response failed");
3582 wpa_supplicant_deauthenticate(
3583 wpa_s, WLAN_REASON_INVALID_IE);
3584 return -1;
3585 }
3586 }
3587
3588 p = data->assoc_info.resp_ies;
3589 l = data->assoc_info.resp_ies_len;
3590
3591#ifdef CONFIG_WPS_STRICT
3592 if (p && wpa_s->current_ssid &&
3593 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3594 struct wpabuf *wps;
3595 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3596 if (wps == NULL) {
3597 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3598 "include WPS IE in (Re)Association Response");
3599 return -1;
3600 }
3601
3602 if (wps_validate_assoc_resp(wps) < 0) {
3603 wpabuf_free(wps);
3604 wpa_supplicant_deauthenticate(
3605 wpa_s, WLAN_REASON_INVALID_IE);
3606 return -1;
3607 }
3608 wpabuf_free(wps);
3609 }
3610#endif /* CONFIG_WPS_STRICT */
3611
3612 /* Go through the IEs and make a copy of the MDIE, if present. */
3613 while (p && l >= 2) {
3614 len = p[1] + 2;
3615 if (len > l) {
3616 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3617 p, l);
3618 break;
3619 }
3620 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3621 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3622 wpa_s->sme.ft_used = 1;
3623 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3624 MOBILITY_DOMAIN_ID_LEN);
3625 break;
3626 }
3627 l -= len;
3628 p += len;
3629 }
3630#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003631#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303632 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3633 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3634 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
Vinayak Yadawadf473bef2024-04-04 15:33:29 +05303635 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) ||
3636 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303637 wpa_ft_is_completed(wpa_s->wpa)) {
3638 return 0;
3639 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003640#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003641
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003642 /* Process FT when SME is in the driver */
3643 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3644 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003645 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003646 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3647 data->assoc_info.resp_ies,
3648 data->assoc_info.resp_ies_len,
3649 bssid) < 0) {
3650 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3651 "Reassociation Response failed");
3652 wpa_supplicant_deauthenticate(
3653 wpa_s, WLAN_REASON_INVALID_IE);
3654 return -1;
3655 }
3656 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3657 }
3658
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003659 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3660 data->assoc_info.resp_ies_len);
3661#endif /* CONFIG_IEEE80211R */
3662
Sunil Ravi72e01222024-03-09 01:25:43 +00003663#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07003664 if (bssid_known)
3665 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3666 data->assoc_info.resp_ies,
3667 data->assoc_info.resp_ies_len);
Sunil Ravi72e01222024-03-09 01:25:43 +00003668#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -07003669
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003670 /* WPA/RSN IE from Beacon/ProbeResp */
3671 p = data->assoc_info.beacon_ies;
3672 l = data->assoc_info.beacon_ies_len;
3673
3674 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3675 */
3676 wpa_found = rsn_found = 0;
3677 while (p && l >= 2) {
3678 len = p[1] + 2;
3679 if (len > l) {
3680 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3681 p, l);
3682 break;
3683 }
3684 if (!wpa_found &&
3685 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3686 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3687 wpa_found = 1;
3688 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3689 }
3690
3691 if (!rsn_found &&
3692 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3693 rsn_found = 1;
3694 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3695 }
3696
Hai Shalomc3565922019-10-28 11:58:20 -07003697 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3698 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003700 l -= len;
3701 p += len;
3702 }
3703
3704 if (!wpa_found && data->assoc_info.beacon_ies)
3705 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003706 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003707 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003708 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3709 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003710 if (wpa_found || rsn_found)
3711 wpa_s->ap_ies_from_associnfo = 1;
3712
Sunil Raviaf399a82024-05-05 20:56:55 +00003713 if (wpa_s->assoc_freq && data->assoc_info.freq) {
3714 struct wpa_bss *bss;
3715 unsigned int freq = 0;
3716
3717 if (bssid_known) {
3718 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
3719 if (bss)
3720 freq = bss->freq;
3721 }
3722 if (freq != data->assoc_info.freq) {
3723 wpa_printf(MSG_DEBUG,
3724 "Operating frequency changed from %u to %u MHz",
3725 wpa_s->assoc_freq, data->assoc_info.freq);
3726 wpa_supplicant_update_scan_results(wpa_s, bssid);
3727 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03003728 }
3729
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003730 wpa_s->assoc_freq = data->assoc_info.freq;
3731
Sunil Ravi72e01222024-03-09 01:25:43 +00003732#ifndef CONFIG_NO_ROBUST_AV
Hai Shalomc1a21442022-02-04 13:43:00 -08003733 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3734 data->assoc_info.resp_ies_len);
Sunil Ravi72e01222024-03-09 01:25:43 +00003735#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08003736
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003737 return 0;
3738}
3739
3740
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003741static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3742{
Hai Shalomc3565922019-10-28 11:58:20 -07003743 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003744
3745 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3746 return -1;
3747
3748 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3749 return 0;
3750
3751 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3752 WPA_IE_VENDOR_TYPE);
3753 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003754 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003755
3756 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3757 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3758 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003759 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3760 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3761 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003762 return -1;
3763
3764 return 0;
3765}
3766
3767
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003768static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3769 union wpa_event_data *data)
3770{
3771#ifdef CONFIG_FST
3772 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3773 struct wpa_bss *bss = wpa_s->current_bss;
3774 const u8 *ieprb, *iebcn;
3775
3776 wpabuf_free(wpa_s->received_mb_ies);
3777 wpa_s->received_mb_ies = NULL;
3778
3779 if (ai &&
3780 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3781 wpa_printf(MSG_DEBUG,
3782 "FST: MB IEs updated from Association Response frame");
3783 return;
3784 }
3785
3786 if (ai &&
3787 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3788 wpa_printf(MSG_DEBUG,
3789 "FST: MB IEs updated from association event Beacon IEs");
3790 return;
3791 }
3792
3793 if (!bss)
3794 return;
3795
Hai Shalom60840252021-02-19 19:02:11 -08003796 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003797 iebcn = ieprb + bss->ie_len;
3798
3799 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3800 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3801 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3802 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3803#endif /* CONFIG_FST */
3804}
3805
3806
Sunil Ravi72e01222024-03-09 01:25:43 +00003807static unsigned int wpas_ml_parse_assoc(struct wpa_supplicant *wpa_s,
3808 struct ieee802_11_elems *elems,
3809 struct ml_sta_link_info *ml_info)
3810{
3811 struct wpabuf *mlbuf;
3812 struct ieee80211_eht_ml *ml;
3813 size_t ml_len;
3814 struct eht_ml_basic_common_info *common_info;
3815 const u8 *pos;
3816 u16 eml_capa = 0, mld_capa = 0;
3817 const u16 control =
3818 host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC |
3819 BASIC_MULTI_LINK_CTRL_PRES_LINK_ID |
3820 BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT);
3821 u8 expected_common_info_len = 9;
3822 unsigned int i = 0;
3823 u16 ml_control;
3824
3825 if (!wpa_s->valid_links || !elems->basic_mle || !elems->basic_mle_len)
3826 return 0;
3827
3828 mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
3829 if (!mlbuf)
3830 return 0;
3831
3832 ml = (struct ieee80211_eht_ml *) wpabuf_head(mlbuf);
3833 ml_len = wpabuf_len(mlbuf);
3834 if (ml_len < sizeof(*ml))
3835 goto out;
3836
3837 os_memset(ml_info, 0, sizeof(*ml_info) * MAX_NUM_MLD_LINKS);
3838
3839 ml_control = le_to_host16(ml->ml_control);
3840
3841 if ((ml_control & control) != control) {
3842 wpa_printf(MSG_DEBUG, "MLD: Invalid presence BM=0x%x",
3843 ml_control);
3844 goto out;
3845 }
3846
3847 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
3848 wpa_printf(MSG_DEBUG, "MLD: EML capabilities included");
3849 expected_common_info_len += 2;
3850 }
3851
3852 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
3853 wpa_printf(MSG_DEBUG, "MLD: MLD capabilities included");
3854 expected_common_info_len += 2;
3855 }
3856
3857 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
3858 wpa_printf(MSG_DEBUG,
3859 "MLD: Unexpected: medium sync delay info present");
3860 expected_common_info_len += 2;
3861 }
3862
3863 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
3864 wpa_printf(MSG_DEBUG,
3865 "MLD: Unexpected: MLD ID present");
3866 expected_common_info_len++;
3867 }
3868
3869 if (sizeof(*ml) + expected_common_info_len > ml_len) {
3870 wpa_printf(MSG_DEBUG,
3871 "MLD: Not enough bytes for common info. ml_len=%zu",
3872 ml_len);
3873 goto out;
3874 }
3875
3876 common_info = (struct eht_ml_basic_common_info *) ml->variable;
3877 if (common_info->len != expected_common_info_len) {
3878 wpa_printf(MSG_DEBUG,
3879 "MLD: Invalid common info len=%u. expected=%u",
3880 common_info->len, expected_common_info_len);
3881 goto out;
3882 }
3883
3884 wpa_printf(MSG_DEBUG, "MLD: address: " MACSTR,
3885 MAC2STR(common_info->mld_addr));
3886
3887 if (!ether_addr_equal(wpa_s->ap_mld_addr, common_info->mld_addr)) {
3888 wpa_printf(MSG_DEBUG, "MLD: Mismatching MLD address (expected "
3889 MACSTR ")", MAC2STR(wpa_s->ap_mld_addr));
3890 goto out;
3891 }
3892
3893 pos = common_info->variable;
3894
3895 /* Store the information for the association link */
3896 ml_info[i].link_id = *pos;
3897 pos++;
3898
3899 /* Skip the BSS Parameters Change Count */
3900 pos++;
3901
3902 /* Skip the Medium Synchronization Delay Information if present */
3903 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO)
3904 pos += 2;
3905
3906 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
3907 eml_capa = WPA_GET_LE16(pos);
3908 pos += 2;
3909 }
3910
3911 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
3912 mld_capa = WPA_GET_LE16(pos);
3913 pos += 2;
3914 }
3915
3916 wpa_printf(MSG_DEBUG,
3917 "MLD: link_id=%u, eml=0x%x, mld=0x%x",
3918 ml_info[i].link_id, eml_capa, mld_capa);
3919
3920 i++;
3921
3922 pos = ((u8 *) common_info) + common_info->len;
3923 ml_len -= sizeof(*ml) + common_info->len;
3924 while (ml_len > 2 && i < MAX_NUM_MLD_LINKS) {
3925 u8 sub_elem_len = pos[1];
3926 u8 sta_info_len;
3927 u8 nstr_bitmap_len = 0;
3928 u16 ctrl;
3929 const u8 *end;
3930
3931 wpa_printf(MSG_DEBUG, "MLD: Subelement len=%u", sub_elem_len);
3932
3933 if (sub_elem_len > ml_len - 2) {
3934 wpa_printf(MSG_DEBUG,
3935 "MLD: Invalid link info len: %u > %zu",
3936 2 + sub_elem_len, ml_len);
3937 goto out;
3938 }
3939
3940 switch (*pos) {
3941 case EHT_ML_SUB_ELEM_PER_STA_PROFILE:
3942 break;
3943 case EHT_ML_SUB_ELEM_FRAGMENT:
3944 case EHT_ML_SUB_ELEM_VENDOR:
3945 wpa_printf(MSG_DEBUG,
3946 "MLD: Skip subelement id=%u, len=%u",
3947 *pos, sub_elem_len);
3948 pos += 2 + sub_elem_len;
3949 ml_len -= 2 + sub_elem_len;
3950 continue;
3951 default:
3952 wpa_printf(MSG_DEBUG, "MLD: Unknown subelement ID=%u",
3953 *pos);
3954 goto out;
3955 }
3956
3957 end = pos + 2 + sub_elem_len;
3958
3959 /* Skip the subelement ID and the length */
3960 pos += 2;
3961 ml_len -= 2;
3962
3963 if (end - pos < 2)
3964 goto out;
3965
3966 /* Get the station control field */
3967 ctrl = WPA_GET_LE16(pos);
3968
3969 pos += 2;
3970 ml_len -= 2;
3971
3972 if (!(ctrl & EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK)) {
3973 wpa_printf(MSG_DEBUG,
3974 "MLD: Per STA complete profile expected");
3975 goto out;
3976 }
3977
3978 if (!(ctrl & EHT_PER_STA_CTRL_MAC_ADDR_PRESENT_MSK)) {
3979 wpa_printf(MSG_DEBUG,
3980 "MLD: Per STA MAC address not present");
3981 goto out;
3982 }
3983
3984 if (!(ctrl & EHT_PER_STA_CTRL_TSF_OFFSET_PRESENT_MSK)) {
3985 wpa_printf(MSG_DEBUG,
3986 "MLD: Per STA TSF offset not present");
3987 goto out;
3988 }
3989
3990 if (!(ctrl & EHT_PER_STA_CTRL_BEACON_INTERVAL_PRESENT_MSK)) {
3991 wpa_printf(MSG_DEBUG,
3992 "MLD: Beacon interval not present");
3993 goto out;
3994 }
3995
3996 if (!(ctrl & EHT_PER_STA_CTRL_DTIM_INFO_PRESENT_MSK)) {
3997 wpa_printf(MSG_DEBUG,
3998 "MLD: DTIM information not present");
3999 goto out;
4000 }
4001
4002 if (ctrl & EHT_PER_STA_CTRL_NSTR_LINK_PAIR_PRESENT_MSK) {
4003 if (ctrl & EHT_PER_STA_CTRL_NSTR_BM_SIZE_MSK)
4004 nstr_bitmap_len = 2;
4005 else
4006 nstr_bitmap_len = 1;
4007 }
4008
4009 if (!(ctrl & EHT_PER_STA_CTRL_BSS_PARAM_CNT_PRESENT_MSK)) {
4010 wpa_printf(MSG_DEBUG,
4011 "MLD: BSS params change count not present");
4012 goto out;
4013 }
4014
4015 sta_info_len = 1 + ETH_ALEN + 8 + 2 + 2 + 1 + nstr_bitmap_len;
4016 if (sta_info_len > ml_len || sta_info_len > end - pos ||
4017 sta_info_len + 2 > sub_elem_len ||
4018 sta_info_len != *pos) {
4019 wpa_printf(MSG_DEBUG,
4020 "MLD: Invalid STA info len=%u, len=%u",
4021 sta_info_len, *pos);
4022 goto out;
4023 }
4024
4025 /* Get the link address */
4026 wpa_printf(MSG_DEBUG,
4027 "MLD: link addr: " MACSTR " nstr BM len=%u",
4028 MAC2STR(pos + 1), nstr_bitmap_len);
4029
4030 ml_info[i].link_id = ctrl & EHT_PER_STA_CTRL_LINK_ID_MSK;
4031 os_memcpy(ml_info[i].bssid, pos + 1, ETH_ALEN);
4032
4033 pos += sta_info_len;
4034 ml_len -= sta_info_len;
4035
4036 wpa_printf(MSG_DEBUG, "MLD: sub_elem_len=%u, sta_info_len=%u",
4037 sub_elem_len, sta_info_len);
4038
4039 sub_elem_len -= sta_info_len + 2;
4040 if (sub_elem_len < 4) {
4041 wpa_printf(MSG_DEBUG, "MLD: Per STA profile too short");
4042 goto out;
4043 }
4044
4045 wpa_hexdump(MSG_MSGDUMP, "MLD: STA profile", pos, sub_elem_len);
4046 ml_info[i].status = WPA_GET_LE16(pos + 2);
4047
4048 pos += sub_elem_len;
4049 ml_len -= sub_elem_len;
4050
4051 i++;
4052 }
4053
4054 wpabuf_free(mlbuf);
4055 return i;
4056out:
4057 wpabuf_free(mlbuf);
4058 return 0;
4059}
4060
4061
Sunil Ravi89eba102022-09-13 21:04:37 -07004062static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
4063{
4064 struct driver_sta_mlo_info mlo;
4065 int i;
4066
Sunil Ravi77d572f2023-01-17 23:58:31 +00004067 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07004068 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
4069 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
4070 wpa_supplicant_deauthenticate(wpa_s,
4071 WLAN_REASON_DEAUTH_LEAVING);
4072 return -1;
4073 }
4074
4075 if (wpa_s->valid_links == mlo.valid_links) {
4076 bool match = true;
4077
4078 if (!mlo.valid_links)
4079 return 0;
4080
Sunil Raviaf399a82024-05-05 20:56:55 +00004081 for_each_link(mlo.valid_links, i) {
Sunil Ravi72e01222024-03-09 01:25:43 +00004082 if (!ether_addr_equal(wpa_s->links[i].addr,
4083 mlo.links[i].addr) ||
4084 !ether_addr_equal(wpa_s->links[i].bssid,
4085 mlo.links[i].bssid)) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004086 match = false;
4087 break;
4088 }
4089 }
4090
Sunil Ravi77d572f2023-01-17 23:58:31 +00004091 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravi72e01222024-03-09 01:25:43 +00004092 ether_addr_equal(wpa_s->ap_mld_addr, mlo.ap_mld_addr))
Sunil Ravi89eba102022-09-13 21:04:37 -07004093 return 0;
4094 }
4095
4096 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004097 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07004098 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
Sunil Raviaf399a82024-05-05 20:56:55 +00004099 for_each_link(wpa_s->valid_links, i) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004100 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
4101 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
4102 wpa_s->links[i].freq = mlo.links[i].freq;
4103 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
4104 }
4105
4106 return 0;
4107}
4108
4109
Sunil Ravi77d572f2023-01-17 23:58:31 +00004110static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
4111{
4112 struct driver_sta_mlo_info drv_mlo;
4113 struct wpa_sm_mlo wpa_mlo;
4114 const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
4115 int i;
4116
4117 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
4118 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
4119 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
4120 return -1;
4121 }
4122
4123 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
4124 if (!drv_mlo.valid_links)
4125 goto out;
4126
4127 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
4128 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
4129 wpa_mlo.valid_links = drv_mlo.valid_links;
4130 wpa_mlo.req_links = drv_mlo.req_links;
4131
Sunil Raviaf399a82024-05-05 20:56:55 +00004132 for_each_link(drv_mlo.req_links, i) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004133 struct wpa_bss *bss;
4134
Sunil Ravi77d572f2023-01-17 23:58:31 +00004135 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
4136 if (!bss) {
Sunil Raviaf399a82024-05-05 20:56:55 +00004137 wpa_supplicant_update_scan_results(
4138 wpa_s, drv_mlo.links[i].bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004139 bss = wpa_supplicant_get_new_bss(
4140 wpa_s, drv_mlo.links[i].bssid);
4141 }
4142
4143 if (!bss) {
4144 wpa_dbg(wpa_s, MSG_INFO,
4145 "Failed to get MLO link %d BSS", i);
4146 return -1;
4147 }
4148
4149 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4150 bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
4151
4152 wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
4153 wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
4154 wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
4155 wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
4156
4157 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
4158 ETH_ALEN);
4159 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
4160 ETH_ALEN);
4161 }
4162
4163out:
4164 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
4165}
4166
4167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004168static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
4169 union wpa_event_data *data)
4170{
4171 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004172 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004173 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07004174#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4175 struct wpa_bss *bss;
4176#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08004177#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304178 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08004179#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004180
4181#ifdef CONFIG_AP
4182 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004183 if (!data)
4184 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004185 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
4186 data->assoc_info.addr,
4187 data->assoc_info.req_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004188 data->assoc_info.req_ies_len, NULL, 0,
4189 NULL, data->assoc_info.reassoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004190 return;
4191 }
4192#endif /* CONFIG_AP */
4193
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004194 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07004195 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004196
Andy Kuoaba17c12022-04-14 16:05:31 +08004197#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304198 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
4199 struct wpa_ft_ies parse;
4200 /* Check for FT reassociation is done by the driver */
4201#ifdef CONFIG_IEEE80211R
4202 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05304203 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05304204 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004205 data->assoc_info.resp_ies_len, &parse, use_sha384, false) < 0) {
Mir Ali677e7482020-11-12 19:49:02 +05304206 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
4207 return;
4208 }
4209 if (parse.rsn_pmkid != NULL) {
4210 wpa_set_ft_completed(wpa_s->wpa);
4211 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
4212 }
4213 }
4214#endif /* CONFIG_IEEE80211R */
4215 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004216#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05304217
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004218 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07004219
4220 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4221 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
4222 wpa_supplicant_deauthenticate(
4223 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4224 return;
4225 }
4226
Sunil Ravi89eba102022-09-13 21:04:37 -07004227 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
4228 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
4229 wpa_supplicant_deauthenticate(wpa_s,
4230 WLAN_REASON_DEAUTH_LEAVING);
4231 return;
4232 }
4233
Sunil Ravia04bd252022-05-02 22:54:18 -07004234 if (ft_completed &&
4235 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
4236 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
4237 MAC2STR(bssid));
4238 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
4239 wpa_printf(MSG_ERROR,
4240 "Can't find target AP's information!");
4241 return;
4242 }
4243 wpa_supplicant_assoc_update_ie(wpa_s);
4244 }
4245
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004246 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
4247 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004248 /*
4249 * FILS authentication can share the same mechanism to mark the
4250 * connection fully authenticated, so set ft_completed also based on
4251 * FILS result.
4252 */
4253 if (!ft_completed)
4254 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004255
Andy Kuoaba17c12022-04-14 16:05:31 +08004256#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304257 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
4258 /*
4259 * For driver based roaming, insert PSK during
4260 * the initial association
4261 */
4262 if (is_zero_ether_addr(wpa_s->bssid) &&
4263 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
4264 /*
4265 * In case the driver wants to handle re-assocs,
4266 * pass it down the PMK.
4267 */
4268 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
4269 wpa_sm_install_pmk(wpa_s->wpa);
4270 }
Mir Ali677e7482020-11-12 19:49:02 +05304271 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304272#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08004273
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004274 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Sunil Ravi72e01222024-03-09 01:25:43 +00004275 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004276 if (os_reltime_initialized(&wpa_s->session_start)) {
4277 os_reltime_age(&wpa_s->session_start,
4278 &wpa_s->session_length);
4279 wpa_s->session_start.sec = 0;
4280 wpa_s->session_start.usec = 0;
4281 wpas_notify_session_length(wpa_s);
4282 } else {
4283 wpas_notify_auth_changed(wpa_s);
4284 os_get_reltime(&wpa_s->session_start);
4285 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004286 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
4287 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004288 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004289 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004290 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4291 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004292 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004293
4294 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
4295 wpa_clear_keys(wpa_s, bssid);
4296 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00004297 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004298 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004299 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4300 return;
4301 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004302 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004303
Hai Shalomc1a21442022-02-04 13:43:00 -08004304 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4305 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
4306 return;
4307
Hai Shalomfdcde762020-04-02 11:19:20 -07004308 multi_ap_set_4addr_mode(wpa_s);
4309
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004310 if (wpa_s->conf->ap_scan == 1 &&
4311 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004312 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
4313 wpa_msg(wpa_s, MSG_WARNING,
4314 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004315 }
4316
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004317 wpas_fst_update_mb_assoc(wpa_s, data);
4318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004319#ifdef CONFIG_SME
Sunil Ravi640215c2023-06-28 23:08:09 +00004320 /*
4321 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
4322 * (for MLO connection) as the previous BSSID for subsequent
4323 * reassociation requests handled by SME-in-wpa_supplicant.
4324 */
4325 os_memcpy(wpa_s->sme.prev_bssid,
4326 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004327 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07004328 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004329#endif /* CONFIG_SME */
4330
4331 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
4332 if (wpa_s->current_ssid) {
4333 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
4334 * initialized before association, but for other modes,
4335 * initialize PC/SC here, if the current configuration needs
4336 * smartcard or SIM/USIM. */
4337 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
4338 }
4339 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004340
4341 if (wpa_sm_set_ml_info(wpa_s)) {
4342 wpa_dbg(wpa_s, MSG_INFO,
4343 "Failed to set MLO connection info to wpa_sm");
4344 wpa_supplicant_deauthenticate(wpa_s,
4345 WLAN_REASON_DEAUTH_LEAVING);
4346 return;
4347 }
4348
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004349 if (wpa_s->l2)
4350 l2_packet_notify_auth_start(wpa_s->l2);
4351
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004352 already_authorized = data && data->assoc_info.authorized;
4353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004354 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07004355 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004356 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
4357 * state machine may transit to AUTHENTICATING state based on obsolete
4358 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
4359 * AUTHENTICATED without ever giving chance to EAP state machine to
4360 * reset the state.
4361 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004362 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07004363 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4364 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004365 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004366 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4367 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
4368 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07004369 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07004370 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004371 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07004372 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004373 wpa_s->eapol_received = 0;
4374 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4375 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4376 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004377 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004378 if (wpa_s->current_ssid &&
4379 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004380 (wpa_s->drv_flags &
4381 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4382 /*
4383 * Set the key after having received joined-IBSS event
4384 * from the driver.
4385 */
4386 wpa_supplicant_set_wpa_none_key(wpa_s,
4387 wpa_s->current_ssid);
4388 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004389 wpa_supplicant_cancel_auth_timeout(wpa_s);
4390 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4391 } else if (!ft_completed) {
4392 /* Timeout for receiving the first EAPOL packet */
4393 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
4394 }
4395 wpa_supplicant_cancel_scan(wpa_s);
4396
Hai Shalom5f92bc92019-04-18 11:54:11 -07004397 if (ft_completed) {
4398 /*
4399 * FT protocol completed - make sure EAPOL state machine ends
4400 * up in authenticated.
4401 */
4402 wpa_supplicant_cancel_auth_timeout(wpa_s);
4403 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004404 eapol_sm_notify_portValid(wpa_s->eapol, true);
4405 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07004406 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4407 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304408 if (already_authorized) {
4409 /*
4410 * We are done; the driver will take care of RSN 4-way
4411 * handshake.
4412 */
4413 wpa_supplicant_cancel_auth_timeout(wpa_s);
4414 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4415 eapol_sm_notify_portValid(wpa_s->eapol, true);
4416 eapol_sm_notify_eap_success(wpa_s->eapol, true);
4417 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004418 /* Update port, WPA_COMPLETED state from the
4419 * EVENT_PORT_AUTHORIZED handler when the driver is done
4420 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304421 */
Sunil Ravi167279a2023-05-31 01:12:34 +00004422 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004423 wpa_msg(wpa_s, MSG_INFO,
4424 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304425 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004426 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004427 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4428 /*
4429 * The driver will take care of RSN 4-way handshake, so we need
4430 * to allow EAPOL supplicant to complete its work without
4431 * waiting for WPA supplicant.
4432 */
Hai Shalome21d4e82020-04-29 16:34:06 -07004433 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004434 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004435#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05304436 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
4437 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4438 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
4439 wpa_s->key_mgmt);
4440 wpa_supplicant_deauthenticate(
4441 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4442 return;
4443 }
4444 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4445 wpa_s->assoc_freq = data->assoc_info.freq;
4446 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
4447 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004448#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
4449
Jouni Malinena05074c2012-12-21 21:35:35 +02004450 wpa_s->last_eapol_matches_bssid = 0;
4451
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004452#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07004453 if (wpa_s->rsne_override_eapol) {
4454 wpa_printf(MSG_DEBUG,
4455 "TESTING: RSNE EAPOL-Key msg 2/4 override");
4456 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4457 wpabuf_head(wpa_s->rsne_override_eapol),
4458 wpabuf_len(wpa_s->rsne_override_eapol));
4459 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004460 if (wpa_s->rsnxe_override_eapol) {
4461 wpa_printf(MSG_DEBUG,
4462 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4463 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4464 wpabuf_head(wpa_s->rsnxe_override_eapol),
4465 wpabuf_len(wpa_s->rsnxe_override_eapol));
4466 }
4467#endif /* CONFIG_TESTING_OPTIONS */
4468
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004469 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004470 struct os_reltime now, age;
4471 os_get_reltime(&now);
4472 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08004473 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravi72e01222024-03-09 01:25:43 +00004474 ether_addr_equal(wpa_s->pending_eapol_rx_src,
4475 wpa_s->valid_links ? wpa_s->ap_mld_addr :
4476 bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004477 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4478 "frame that was received just before "
4479 "association notification");
4480 wpa_supplicant_rx_eapol(
4481 wpa_s, wpa_s->pending_eapol_rx_src,
4482 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00004483 wpabuf_len(wpa_s->pending_eapol_rx),
4484 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004485 }
4486 wpabuf_free(wpa_s->pending_eapol_rx);
4487 wpa_s->pending_eapol_rx = NULL;
4488 }
4489
Hai Shalomfdcde762020-04-02 11:19:20 -07004490#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004491 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4492 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004493 wpa_s->current_ssid &&
4494 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004495 /* Set static WEP keys again */
4496 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4497 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004498#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004499
4500#ifdef CONFIG_IBSS_RSN
4501 if (wpa_s->current_ssid &&
4502 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4503 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4504 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4505 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004506 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004507 if (!wpa_s->ibss_rsn) {
4508 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4509 wpa_supplicant_deauthenticate(
4510 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4511 return;
4512 }
4513
4514 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4515 }
4516#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004517
4518 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004519
Sunil Ravi72e01222024-03-09 01:25:43 +00004520#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004521 if (data) {
4522 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4523 data->assoc_info.resp_ies_len,
4524 &data->assoc_info.wmm_params);
4525
4526 if (wpa_s->reassoc_same_bss)
4527 wmm_ac_restore_tspecs(wpa_s);
4528 }
Sunil Ravi72e01222024-03-09 01:25:43 +00004529#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004530
Hai Shalomc3565922019-10-28 11:58:20 -07004531#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4532 bss = wpa_bss_get_bssid(wpa_s, bssid);
4533#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004534#ifdef CONFIG_FILS
4535 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004536 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4537
4538 if (fils_cache_id)
4539 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4540 }
4541#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004542
4543#ifdef CONFIG_MBO
4544 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4545#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004546
4547#ifdef CONFIG_DPP2
4548 wpa_s->dpp_pfs_fallback = 0;
4549#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004550
4551 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4552 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004553}
4554
4555
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004556static int disconnect_reason_recoverable(u16 reason_code)
4557{
4558 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4559 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4560 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4561}
4562
4563
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004564static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004565 u16 reason_code,
4566 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004567{
4568 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004569
4570 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4571 /*
4572 * At least Host AP driver and a Prism3 card seemed to be
4573 * generating streams of disconnected events when configuring
4574 * IBSS for WPA-None. Ignore them for now.
4575 */
4576 return;
4577 }
4578
4579 bssid = wpa_s->bssid;
4580 if (is_zero_ether_addr(bssid))
4581 bssid = wpa_s->pending_bssid;
4582
4583 if (!is_zero_ether_addr(bssid) ||
4584 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4585 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4586 " reason=%d%s",
4587 MAC2STR(bssid), reason_code,
4588 locally_generated ? " locally_generated=1" : "");
4589 }
4590}
4591
4592
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004593static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4594 int locally_generated)
4595{
4596 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004597 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004598 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4599 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004600 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004601
4602 /*
4603 * It looks like connection was lost while trying to go through PSK
4604 * 4-way handshake. Filter out known disconnection cases that are caused
4605 * by something else than PSK mismatch to avoid confusing reports.
4606 */
4607
4608 if (locally_generated) {
4609 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4610 return 0;
4611 }
4612
4613 return 1;
4614}
4615
4616
Jouni Malinen2b89da82012-08-31 22:04:41 +03004617static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4618 u16 reason_code,
4619 int locally_generated)
4620{
4621 const u8 *bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004622 struct wpa_bss *fast_reconnect = NULL;
4623 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004624 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004625
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004626 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4627 /*
4628 * At least Host AP driver and a Prism3 card seemed to be
4629 * generating streams of disconnected events when configuring
4630 * IBSS for WPA-None. Ignore them for now.
4631 */
4632 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4633 "IBSS/WPA-None mode");
4634 return;
4635 }
4636
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004637 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4638 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4639 locally_generated)
4640 /*
4641 * Remove the inactive AP (which is probably out of range) from
4642 * the BSS list after marking disassociation. In particular
4643 * mac80211-based drivers use the
4644 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4645 * locally generated disconnection events for cases where the
4646 * AP does not reply anymore.
4647 */
4648 curr = wpa_s->current_bss;
4649
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004650 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004651 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4652 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004653 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4654 return; /* P2P group removed */
Sunil Ravi72e01222024-03-09 01:25:43 +00004655 wpas_auth_failed(wpa_s, "WRONG_KEY", wpa_s->pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004656 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004657#ifdef CONFIG_DPP2
4658 wpas_dpp_send_conn_status_result(wpa_s,
4659 DPP_STATUS_AUTH_FAILURE);
4660#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004661 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004662 if (!wpa_s->disconnected &&
4663 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004664 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004665 wpas_wps_searching(wpa_s) ||
4666 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004667 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004668 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004669 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004670 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004671 wpa_s->wpa_state);
4672 if (wpa_s->wpa_state == WPA_COMPLETED &&
4673 wpa_s->current_ssid &&
4674 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004675 (wpa_s->own_reconnect_req ||
4676 (!locally_generated &&
4677 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004678 /*
4679 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004680 * us, but could allow us to get back in. This is also
4681 * triggered for cases where local reconnection request
4682 * is used to force reassociation with the same BSS.
4683 * Try to reconnect to the same BSS without a full scan
4684 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004685 */
4686 fast_reconnect = wpa_s->current_bss;
4687 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004688 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004689 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004690 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004691 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4692 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004693 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004694 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004695 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004696 "try to re-connect");
4697 wpa_s->reassociate = 0;
4698 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004699 if (!wpa_s->pno)
4700 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004701 }
4702 bssid = wpa_s->bssid;
4703 if (is_zero_ether_addr(bssid))
4704 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004705 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
Sunil Ravi72e01222024-03-09 01:25:43 +00004706 wpas_connection_failed(wpa_s, bssid, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004707 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004708 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4709
Dmitry Shmidt04949592012-07-19 12:16:46 -07004710 if (locally_generated)
4711 wpa_s->disconnect_reason = -reason_code;
4712 else
4713 wpa_s->disconnect_reason = reason_code;
4714 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004715 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4716 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004717 wpa_clear_keys(wpa_s, wpa_s->bssid);
4718 }
4719 wpa_supplicant_mark_disassoc(wpa_s);
4720
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004721 if (curr)
4722 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4723
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004724 if (fast_reconnect &&
4725 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4726 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4727 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4728 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004729 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004730 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004731#ifndef CONFIG_NO_SCAN_PROCESSING
4732 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4733 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4734 fast_reconnect_ssid) < 0) {
4735 /* Recover through full scan */
4736 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4737 }
4738#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004739 } else if (fast_reconnect) {
4740 /*
4741 * Could not reconnect to the same BSS due to network being
4742 * disabled. Use a new scan to match the alternative behavior
4743 * above, i.e., to continue automatic reconnection attempt in a
4744 * way that enforces disabled network rules.
4745 */
4746 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004747 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004748}
4749
4750
4751#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004752void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004753{
4754 struct wpa_supplicant *wpa_s = eloop_ctx;
4755
4756 if (!wpa_s->pending_mic_error_report)
4757 return;
4758
4759 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4760 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4761 wpa_s->pending_mic_error_report = 0;
4762}
4763#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4764
4765
4766static void
4767wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4768 union wpa_event_data *data)
4769{
4770 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004771 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004772
4773 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4774 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004775 os_get_reltime(&t);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004776 if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004777 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004778 wpa_s->pending_mic_error_report) {
4779 if (wpa_s->pending_mic_error_report) {
4780 /*
4781 * Send the pending MIC error report immediately since
4782 * we are going to start countermeasures and AP better
4783 * do the same.
4784 */
4785 wpa_sm_key_request(wpa_s->wpa, 1,
4786 wpa_s->pending_mic_error_pairwise);
4787 }
4788
4789 /* Send the new MIC error report immediately since we are going
4790 * to start countermeasures and AP better do the same.
4791 */
4792 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4793
4794 /* initialize countermeasures */
4795 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004796
Hai Shalom60840252021-02-19 19:02:11 -08004797 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004798
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004799 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4800
4801 /*
4802 * Need to wait for completion of request frame. We do not get
4803 * any callback for the message completion, so just wait a
4804 * short while and hope for the best. */
4805 os_sleep(0, 10000);
4806
4807 wpa_drv_set_countermeasures(wpa_s, 1);
4808 wpa_supplicant_deauthenticate(wpa_s,
4809 WLAN_REASON_MICHAEL_MIC_FAILURE);
4810 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4811 wpa_s, NULL);
4812 eloop_register_timeout(60, 0,
4813 wpa_supplicant_stop_countermeasures,
4814 wpa_s, NULL);
4815 /* TODO: mark the AP rejected for 60 second. STA is
4816 * allowed to associate with another AP.. */
4817 } else {
4818#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4819 if (wpa_s->mic_errors_seen) {
4820 /*
4821 * Reduce the effectiveness of Michael MIC error
4822 * reports as a means for attacking against TKIP if
4823 * more than one MIC failure is noticed with the same
4824 * PTK. We delay the transmission of the reports by a
4825 * random time between 0 and 60 seconds in order to
4826 * force the attacker wait 60 seconds before getting
4827 * the information on whether a frame resulted in a MIC
4828 * failure.
4829 */
4830 u8 rval[4];
4831 int sec;
4832
4833 if (os_get_random(rval, sizeof(rval)) < 0)
4834 sec = os_random() % 60;
4835 else
4836 sec = WPA_GET_BE32(rval) % 60;
4837 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4838 "report %d seconds", sec);
4839 wpa_s->pending_mic_error_report = 1;
4840 wpa_s->pending_mic_error_pairwise = pairwise;
4841 eloop_cancel_timeout(
4842 wpa_supplicant_delayed_mic_error_report,
4843 wpa_s, NULL);
4844 eloop_register_timeout(
4845 sec, os_random() % 1000000,
4846 wpa_supplicant_delayed_mic_error_report,
4847 wpa_s, NULL);
4848 } else {
4849 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4850 }
4851#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4852 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4853#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4854 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004855 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004856 wpa_s->mic_errors_seen++;
4857}
4858
4859
4860#ifdef CONFIG_TERMINATE_ONLASTIF
4861static int any_interfaces(struct wpa_supplicant *head)
4862{
4863 struct wpa_supplicant *wpa_s;
4864
4865 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4866 if (!wpa_s->interface_removed)
4867 return 1;
4868 return 0;
4869}
4870#endif /* CONFIG_TERMINATE_ONLASTIF */
4871
4872
4873static void
4874wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4875 union wpa_event_data *data)
4876{
4877 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4878 return;
4879
4880 switch (data->interface_status.ievent) {
4881 case EVENT_INTERFACE_ADDED:
4882 if (!wpa_s->interface_removed)
4883 break;
4884 wpa_s->interface_removed = 0;
4885 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4886 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4887 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4888 "driver after interface was added");
4889 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004890
4891#ifdef CONFIG_P2P
4892 if (!wpa_s->global->p2p &&
4893 !wpa_s->global->p2p_disabled &&
4894 !wpa_s->conf->p2p_disabled &&
4895 (wpa_s->drv_flags &
4896 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4897 wpas_p2p_add_p2pdev_interface(
4898 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4899 wpa_printf(MSG_INFO,
4900 "P2P: Failed to enable P2P Device interface");
4901 /* Try to continue without. P2P will be disabled. */
4902 }
4903#endif /* CONFIG_P2P */
4904
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004905 break;
4906 case EVENT_INTERFACE_REMOVED:
4907 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4908 wpa_s->interface_removed = 1;
4909 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004910 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004911 l2_packet_deinit(wpa_s->l2);
4912 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004913
4914#ifdef CONFIG_P2P
4915 if (wpa_s->global->p2p &&
4916 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4917 (wpa_s->drv_flags &
4918 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4919 wpa_dbg(wpa_s, MSG_DEBUG,
4920 "Removing P2P Device interface");
4921 wpa_supplicant_remove_iface(
4922 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4923 0);
4924 wpa_s->global->p2p_init_wpa_s = NULL;
4925 }
4926#endif /* CONFIG_P2P */
4927
Dmitry Shmidte4663042016-04-04 10:07:49 -07004928#ifdef CONFIG_MATCH_IFACE
4929 if (wpa_s->matched) {
4930 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4931 break;
4932 }
4933#endif /* CONFIG_MATCH_IFACE */
4934
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004935#ifdef CONFIG_TERMINATE_ONLASTIF
4936 /* check if last interface */
4937 if (!any_interfaces(wpa_s->global->ifaces))
4938 eloop_terminate();
4939#endif /* CONFIG_TERMINATE_ONLASTIF */
4940 break;
4941 }
4942}
4943
4944
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004945#ifdef CONFIG_TDLS
4946static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4947 union wpa_event_data *data)
4948{
4949 if (data == NULL)
4950 return;
4951 switch (data->tdls.oper) {
4952 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004953 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4954 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4955 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4956 else
4957 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004958 break;
4959 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004960 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4961 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4962 data->tdls.reason_code);
4963 else
4964 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4965 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004966 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004967 case TDLS_REQUEST_DISCOVER:
4968 wpa_tdls_send_discovery_request(wpa_s->wpa,
4969 data->tdls.peer);
4970 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004971 }
4972}
4973#endif /* CONFIG_TDLS */
4974
4975
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004976#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004977static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4978 union wpa_event_data *data)
4979{
4980 if (data == NULL)
4981 return;
4982 switch (data->wnm.oper) {
4983 case WNM_OPER_SLEEP:
4984 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4985 "(action=%d, intval=%d)",
4986 data->wnm.sleep_action, data->wnm.sleep_intval);
4987 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004988 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004989 break;
4990 }
4991}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004992#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004993
4994
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004995#ifdef CONFIG_IEEE80211R
4996static void
4997wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4998 union wpa_event_data *data)
4999{
5000 if (data == NULL)
5001 return;
5002
5003 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
5004 data->ft_ies.ies_len,
5005 data->ft_ies.ft_action,
5006 data->ft_ies.target_ap,
5007 data->ft_ies.ric_ies,
5008 data->ft_ies.ric_ies_len) < 0) {
5009 /* TODO: prevent MLME/driver from trying to associate? */
5010 }
5011}
5012#endif /* CONFIG_IEEE80211R */
5013
5014
5015#ifdef CONFIG_IBSS_RSN
5016static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
5017 union wpa_event_data *data)
5018{
5019 struct wpa_ssid *ssid;
5020 if (wpa_s->wpa_state < WPA_ASSOCIATED)
5021 return;
5022 if (data == NULL)
5023 return;
5024 ssid = wpa_s->current_ssid;
5025 if (ssid == NULL)
5026 return;
5027 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5028 return;
5029
5030 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
5031}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005032
5033
5034static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
5035 union wpa_event_data *data)
5036{
5037 struct wpa_ssid *ssid = wpa_s->current_ssid;
5038
5039 if (ssid == NULL)
5040 return;
5041
5042 /* check if the ssid is correctly configured as IBSS/RSN */
5043 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5044 return;
5045
5046 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
5047 data->rx_mgmt.frame_len);
5048}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005049#endif /* CONFIG_IBSS_RSN */
5050
5051
5052#ifdef CONFIG_IEEE80211R
5053static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
5054 size_t len)
5055{
5056 const u8 *sta_addr, *target_ap_addr;
5057 u16 status;
5058
5059 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
5060 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
5061 return; /* only SME case supported for now */
5062 if (len < 1 + 2 * ETH_ALEN + 2)
5063 return;
5064 if (data[0] != 2)
5065 return; /* Only FT Action Response is supported for now */
5066 sta_addr = data + 1;
5067 target_ap_addr = data + 1 + ETH_ALEN;
5068 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
5069 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
5070 MACSTR " TargetAP " MACSTR " status %u",
5071 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
5072
Sunil Ravi72e01222024-03-09 01:25:43 +00005073 if (!ether_addr_equal(sta_addr, wpa_s->own_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005074 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
5075 " in FT Action Response", MAC2STR(sta_addr));
5076 return;
5077 }
5078
5079 if (status) {
5080 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
5081 "failure (status code %d)", status);
5082 /* TODO: report error to FT code(?) */
5083 return;
5084 }
5085
5086 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
5087 len - (1 + 2 * ETH_ALEN + 2), 1,
5088 target_ap_addr, NULL, 0) < 0)
5089 return;
5090
5091#ifdef CONFIG_SME
5092 {
5093 struct wpa_bss *bss;
5094 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
5095 if (bss)
5096 wpa_s->sme.freq = bss->freq;
5097 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
5098 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
5099 WLAN_AUTH_FT);
5100 }
5101#endif /* CONFIG_SME */
5102}
5103#endif /* CONFIG_IEEE80211R */
5104
5105
5106static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
5107 struct unprot_deauth *e)
5108{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005109 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
5110 "dropped: " MACSTR " -> " MACSTR
5111 " (reason code %u)",
5112 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5113 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005114}
5115
5116
5117static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
5118 struct unprot_disassoc *e)
5119{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005120 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
5121 "dropped: " MACSTR " -> " MACSTR
5122 " (reason code %u)",
5123 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5124 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005125}
5126
5127
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005128static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
5129 u16 reason_code, int locally_generated,
5130 const u8 *ie, size_t ie_len, int deauth)
5131{
5132#ifdef CONFIG_AP
5133 if (wpa_s->ap_iface && addr) {
5134 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
5135 return;
5136 }
5137
5138 if (wpa_s->ap_iface) {
5139 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
5140 return;
5141 }
5142#endif /* CONFIG_AP */
5143
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005144 if (!locally_generated)
5145 wpa_s->own_disconnect_req = 0;
5146
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005147 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
5148
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005149 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
5150 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
5151 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
5152 eapol_sm_failed(wpa_s->eapol))) &&
5153 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00005154 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005155
5156#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07005157 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005158 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
5159 locally_generated) > 0) {
5160 /*
5161 * The interface was removed, so cannot continue
5162 * processing any additional operations after this.
5163 */
5164 return;
5165 }
5166 }
5167#endif /* CONFIG_P2P */
5168
5169 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
5170 locally_generated);
5171}
5172
5173
5174static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
5175 struct disassoc_info *info)
5176{
5177 u16 reason_code = 0;
5178 int locally_generated = 0;
5179 const u8 *addr = NULL;
5180 const u8 *ie = NULL;
5181 size_t ie_len = 0;
5182
5183 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
5184
5185 if (info) {
5186 addr = info->addr;
5187 ie = info->ie;
5188 ie_len = info->ie_len;
5189 reason_code = info->reason_code;
5190 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005191 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
5192 reason2str(reason_code),
5193 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005194 if (addr)
5195 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5196 MAC2STR(addr));
5197 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
5198 ie, ie_len);
5199 }
5200
5201#ifdef CONFIG_AP
5202 if (wpa_s->ap_iface && info && info->addr) {
5203 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
5204 return;
5205 }
5206
5207 if (wpa_s->ap_iface) {
5208 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
5209 return;
5210 }
5211#endif /* CONFIG_AP */
5212
5213#ifdef CONFIG_P2P
5214 if (info) {
5215 wpas_p2p_disassoc_notif(
5216 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
5217 locally_generated);
5218 }
5219#endif /* CONFIG_P2P */
5220
5221 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5222 sme_event_disassoc(wpa_s, info);
5223
5224 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
5225 ie, ie_len, 0);
5226}
5227
5228
5229static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
5230 struct deauth_info *info)
5231{
5232 u16 reason_code = 0;
5233 int locally_generated = 0;
5234 const u8 *addr = NULL;
5235 const u8 *ie = NULL;
5236 size_t ie_len = 0;
5237
5238 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
5239
5240 if (info) {
5241 addr = info->addr;
5242 ie = info->ie;
5243 ie_len = info->ie_len;
5244 reason_code = info->reason_code;
5245 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005246 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
5247 reason_code, reason2str(reason_code),
5248 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005249 if (addr) {
5250 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5251 MAC2STR(addr));
5252 }
5253 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
5254 ie, ie_len);
5255 }
5256
5257 wpa_reset_ft_completed(wpa_s->wpa);
5258
5259 wpas_event_disconnect(wpa_s, addr, reason_code,
5260 locally_generated, ie, ie_len, 1);
5261}
5262
5263
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005264static const char * reg_init_str(enum reg_change_initiator init)
5265{
5266 switch (init) {
5267 case REGDOM_SET_BY_CORE:
5268 return "CORE";
5269 case REGDOM_SET_BY_USER:
5270 return "USER";
5271 case REGDOM_SET_BY_DRIVER:
5272 return "DRIVER";
5273 case REGDOM_SET_BY_COUNTRY_IE:
5274 return "COUNTRY_IE";
5275 case REGDOM_BEACON_HINT:
5276 return "BEACON_HINT";
5277 }
5278 return "?";
5279}
5280
5281
5282static const char * reg_type_str(enum reg_type type)
5283{
5284 switch (type) {
5285 case REGDOM_TYPE_UNKNOWN:
5286 return "UNKNOWN";
5287 case REGDOM_TYPE_COUNTRY:
5288 return "COUNTRY";
5289 case REGDOM_TYPE_WORLD:
5290 return "WORLD";
5291 case REGDOM_TYPE_CUSTOM_WORLD:
5292 return "CUSTOM_WORLD";
5293 case REGDOM_TYPE_INTERSECTION:
5294 return "INTERSECTION";
5295 }
5296 return "?";
5297}
5298
5299
Sunil Ravi72e01222024-03-09 01:25:43 +00005300static void wpas_beacon_hint(struct wpa_supplicant *wpa_s, const char *title,
5301 struct frequency_attrs *attrs)
5302{
5303 if (!attrs->freq)
5304 return;
5305 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_BEACON_HINT
5306 "%s freq=%u max_tx_power=%u%s%s%s",
5307 title, attrs->freq, attrs->max_tx_power,
5308 attrs->disabled ? " disabled=1" : "",
5309 attrs->no_ir ? " no_ir=1" : "",
5310 attrs->radar ? " radar=1" : "");
5311}
5312
5313
Hai Shalom74f70d42019-02-11 14:42:39 -08005314void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
5315 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005316{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005317 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005318 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005319
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005320 /*
5321 * To allow backwards compatibility with higher level layers that
5322 * assumed the REGDOM_CHANGE event is sent over the initially added
5323 * interface. Find the highest parent of this interface and use it to
5324 * send the event.
5325 */
5326 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
5327 ;
5328
Hai Shalom74f70d42019-02-11 14:42:39 -08005329 if (info) {
5330 wpa_msg(ifs, MSG_INFO,
5331 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
5332 reg_init_str(info->initiator), reg_type_str(info->type),
5333 info->alpha2[0] ? " alpha2=" : "",
5334 info->alpha2[0] ? info->alpha2 : "");
Sunil Ravi72e01222024-03-09 01:25:43 +00005335
5336 if (info->initiator == REGDOM_BEACON_HINT) {
5337 wpas_beacon_hint(ifs, "before",
5338 &info->beacon_hint_before);
5339 wpas_beacon_hint(ifs, "after",
5340 &info->beacon_hint_after);
5341 }
Hai Shalom74f70d42019-02-11 14:42:39 -08005342 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005343
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005344 if (wpa_s->drv_priv == NULL)
5345 return; /* Ignore event during drv initialization */
5346
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005347 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
5348 radio_list) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005349 bool was_6ghz_enabled;
5350
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005351 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
5352 ifs->ifname);
5353 free_hw_features(ifs);
5354 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005355 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005356
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005357 was_6ghz_enabled = ifs->is_6ghz_enabled;
5358 ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5359
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005360 /* Restart PNO/sched_scan with updated channel list */
5361 if (ifs->pno) {
5362 wpas_stop_pno(ifs);
5363 wpas_start_pno(ifs);
5364 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
5365 wpa_dbg(ifs, MSG_DEBUG,
5366 "Channel list changed - restart sched_scan");
5367 wpas_scan_restart_sched_scan(ifs);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005368 } else if (ifs->scanning && !was_6ghz_enabled &&
5369 ifs->is_6ghz_enabled) {
5370 /* Look for APs in the 6 GHz band */
5371 wpa_dbg(ifs, MSG_INFO,
5372 "Channel list changed - trigger 6 GHz-only scan");
5373 ifs->crossed_6ghz_dom = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005374 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005375 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005376
5377 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005378}
5379
5380
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005381static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005382 const u8 *frame, size_t len, int freq,
5383 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005384{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005385 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005386 const u8 *payload;
5387 size_t plen;
5388 u8 category;
5389
5390 if (len < IEEE80211_HDRLEN + 2)
5391 return;
5392
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005393 mgmt = (const struct ieee80211_mgmt *) frame;
5394 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005395 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005396 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005397
5398 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
5399 " Category=%u DataLen=%d freq=%d MHz",
5400 MAC2STR(mgmt->sa), category, (int) plen, freq);
5401
Sunil Ravi72e01222024-03-09 01:25:43 +00005402#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005403 if (category == WLAN_ACTION_WMM) {
5404 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5405 return;
5406 }
Sunil Ravi72e01222024-03-09 01:25:43 +00005407#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005408
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005409#ifdef CONFIG_IEEE80211R
5410 if (category == WLAN_ACTION_FT) {
5411 ft_rx_action(wpa_s, payload, plen);
5412 return;
5413 }
5414#endif /* CONFIG_IEEE80211R */
5415
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005416#ifdef CONFIG_SME
5417 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005418 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005419 return;
5420 }
5421#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005422
5423#ifdef CONFIG_WNM
5424 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
5425 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
5426 return;
5427 }
5428#endif /* CONFIG_WNM */
5429
5430#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08005431 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5432 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005433 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08005434 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005435 payload, plen, freq) == 0)
5436 return;
5437#endif /* CONFIG_GAS */
5438
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005439#ifdef CONFIG_GAS_SERVER
5440 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5441 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
5442 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
5443 mgmt->u.action.category,
5444 payload, plen, freq) == 0)
5445 return;
5446#endif /* CONFIG_GAS_SERVER */
5447
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005448#ifdef CONFIG_TDLS
5449 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
5450 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
5451 wpa_dbg(wpa_s, MSG_DEBUG,
5452 "TDLS: Received Discovery Response from " MACSTR,
5453 MAC2STR(mgmt->sa));
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005454 if (wpa_s->valid_links &&
5455 wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa,
5456 &payload[1], plen - 1))
5457 wpa_dbg(wpa_s, MSG_ERROR,
5458 "TDLS: Discovery Response process failed for "
5459 MACSTR, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005460 return;
5461 }
5462#endif /* CONFIG_TDLS */
5463
5464#ifdef CONFIG_INTERWORKING
5465 if (category == WLAN_ACTION_QOS && plen >= 1 &&
5466 payload[0] == QOS_QOS_MAP_CONFIG) {
5467 const u8 *pos = payload + 1;
5468 size_t qlen = plen - 1;
5469 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
5470 MACSTR, MAC2STR(mgmt->sa));
Sunil Ravi72e01222024-03-09 01:25:43 +00005471 if (ether_addr_equal(mgmt->sa, wpa_s->bssid) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005472 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
5473 pos[1] <= qlen - 2 && pos[1] >= 16)
5474 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
5475 return;
5476 }
5477#endif /* CONFIG_INTERWORKING */
5478
Sunil Ravi72e01222024-03-09 01:25:43 +00005479#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005480 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005481 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5482 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005483 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005484 payload + 1,
5485 plen - 1);
5486 return;
5487 }
5488
5489 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005490 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
5491 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
5492 return;
5493 }
5494
5495 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5496 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
5497 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
5498 payload + 1, plen - 1,
5499 rssi);
5500 return;
5501 }
Sunil Ravi72e01222024-03-09 01:25:43 +00005502#endif /* CONFIG_NO_RRM */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005503
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005504#ifdef CONFIG_FST
5505 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
5506 fst_rx_action(wpa_s->fst, mgmt, len);
5507 return;
5508 }
5509#endif /* CONFIG_FST */
5510
Sunil Ravi72e01222024-03-09 01:25:43 +00005511#ifdef CONFIG_NAN_USD
5512 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5513 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5514 WPA_GET_BE32(&payload[1]) == NAN_SDF_VENDOR_TYPE) {
5515 payload += 5;
5516 plen -= 5;
5517 wpas_nan_usd_rx_sdf(wpa_s, mgmt->sa, freq, payload, plen);
5518 return;
5519 }
5520#endif /* CONFIG_NAN_USD */
5521
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005522#ifdef CONFIG_DPP
5523 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5524 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5525 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
5526 payload[4] == DPP_OUI_TYPE) {
5527 payload++;
5528 plen--;
5529 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
5530 return;
5531 }
5532#endif /* CONFIG_DPP */
5533
Sunil Ravi72e01222024-03-09 01:25:43 +00005534#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07005535 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08005536 payload[0] == ROBUST_AV_SCS_RESP) {
5537 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
5538 payload + 1, plen - 1);
5539 return;
5540 }
5541
5542 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005543 payload[0] == ROBUST_AV_MSCS_RESP) {
5544 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5545 payload + 1, plen - 1);
5546 return;
5547 }
5548
Hai Shalomc1a21442022-02-04 13:43:00 -08005549 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
5550 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
5551 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
5552 payload + 4, plen - 4);
5553 return;
5554 }
Sunil Ravi72e01222024-03-09 01:25:43 +00005555#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08005556
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005557 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5558 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005559 if (wpa_s->ifmsh)
5560 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005561}
5562
5563
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005564static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5565 union wpa_event_data *event)
5566{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005567 struct wpa_freq_range_list *list;
5568 char *str = NULL;
5569
5570 list = &event->freq_range;
5571
5572 if (list->num)
5573 str = freq_range_list_str(list);
5574 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5575 str ? str : "");
5576
5577#ifdef CONFIG_P2P
5578 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5579 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5580 __func__);
5581 } else {
5582 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005583
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005584 /*
5585 * The update channel flow will also take care of moving a GO
5586 * from the unsafe frequency if needed.
5587 */
5588 wpas_p2p_update_channel_list(wpa_s,
5589 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005590 }
5591#endif /* CONFIG_P2P */
5592
5593 os_free(str);
5594}
5595
5596
Roshan Pius3a1667e2018-07-03 15:17:14 -07005597static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005598{
Sunil Ravi167279a2023-05-31 01:12:34 +00005599 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005600 wpa_supplicant_cancel_auth_timeout(wpa_s);
5601 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005602 eapol_sm_notify_portValid(wpa_s->eapol, true);
5603 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005604 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005605 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005606}
5607
5608
5609static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5610 int freq)
5611{
5612 size_t i;
5613 int j;
5614
5615 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5616 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5617
5618 for (j = 0; j < mode->num_channels; j++) {
5619 const struct hostapd_channel_data *chan;
5620
5621 chan = &mode->channels[j];
5622 if (chan->freq == freq)
5623 return chan->dfs_cac_ms;
5624 }
5625 }
5626
5627 return 0;
5628}
5629
5630
5631static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5632 struct dfs_event *radar)
5633{
5634#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005635 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005636 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5637 } else
5638#endif /* NEED_AP_MLME && CONFIG_AP */
5639 {
5640 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5641
5642 cac_time /= 1000; /* convert from ms to sec */
5643 if (!cac_time)
5644 cac_time = 10 * 60; /* max timeout: 10 minutes */
5645
5646 /* Restart auth timeout: CAC time added to initial timeout */
5647 wpas_auth_timeout_restart(wpa_s, cac_time);
5648 }
5649}
5650
5651
5652static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5653 struct dfs_event *radar)
5654{
5655#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005656 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005657 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5658 } else
5659#endif /* NEED_AP_MLME && CONFIG_AP */
5660 {
5661 /* Restart auth timeout with original value after CAC is
5662 * finished */
5663 wpas_auth_timeout_restart(wpa_s, 0);
5664 }
5665}
5666
5667
5668static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5669 struct dfs_event *radar)
5670{
5671#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005672 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005673 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5674 } else
5675#endif /* NEED_AP_MLME && CONFIG_AP */
5676 {
5677 /* Restart auth timeout with original value after CAC is
5678 * aborted */
5679 wpas_auth_timeout_restart(wpa_s, 0);
5680 }
5681}
5682
5683
5684static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5685 union wpa_event_data *data)
5686{
5687 wpa_dbg(wpa_s, MSG_DEBUG,
5688 "Connection authorized by device, previous state %d",
5689 wpa_s->wpa_state);
5690
5691 wpa_supplicant_event_port_authorized(wpa_s);
5692
Hai Shalomc1a21442022-02-04 13:43:00 -08005693 wpa_s->last_eapol_matches_bssid = 1;
5694
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005695 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5696 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005697 data->assoc_info.ptk_kck_len,
5698 data->assoc_info.ptk_kek,
5699 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005700#ifdef CONFIG_FILS
5701 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5702 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5703 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5704
5705 /* Update ERP next sequence number */
5706 eapol_sm_update_erp_next_seq_num(
5707 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5708
5709 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5710 /* Add the new PMK and PMKID to the PMKSA cache */
5711 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5712 data->assoc_info.fils_pmk,
5713 data->assoc_info.fils_pmk_len,
5714 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005715 wpa_s->valid_links ?
5716 wpa_s->ap_mld_addr :
5717 wpa_s->bssid,
5718 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005719 } else if (data->assoc_info.fils_pmkid) {
5720 /* Update the current PMKSA used for this connection */
5721 pmksa_cache_set_current(wpa_s->wpa,
5722 data->assoc_info.fils_pmkid,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005723 NULL, NULL, 0, NULL, 0, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005724 }
5725 }
5726#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005727}
5728
5729
Hai Shalom60840252021-02-19 19:02:11 -08005730static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5731{
5732 switch (code) {
5733 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5734 return "";
5735 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5736 return "no_bss_found";
5737 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5738 return "auth_tx_fail";
5739 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5740 return "auth_no_ack_received";
5741 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5742 return "auth_no_resp_received";
5743 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5744 return "assoc_req_tx_fail";
5745 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5746 return "assoc_no_ack_received";
5747 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5748 return "assoc_no_resp_received";
5749 default:
5750 return "unknown_reason";
5751 }
5752}
5753
5754
Roshan Pius3a1667e2018-07-03 15:17:14 -07005755static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5756 union wpa_event_data *data)
5757{
5758 const u8 *bssid = data->assoc_reject.bssid;
Sunil Ravi72e01222024-03-09 01:25:43 +00005759 struct ieee802_11_elems elems;
5760 const u8 *link_bssids[MAX_NUM_MLD_LINKS];
Hai Shalom81f62d82019-07-22 12:10:00 -07005761#ifdef CONFIG_MBO
5762 struct wpa_bss *reject_bss;
5763#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005764
5765 if (!bssid || is_zero_ether_addr(bssid))
5766 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005767#ifdef CONFIG_MBO
5768 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5769 reject_bss = wpa_s->current_bss;
5770 else
5771 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5772#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005773
5774 if (data->assoc_reject.bssid)
5775 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005776 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005777 MAC2STR(data->assoc_reject.bssid),
5778 data->assoc_reject.status_code,
5779 data->assoc_reject.timed_out ? " timeout" : "",
5780 data->assoc_reject.timeout_reason ? "=" : "",
5781 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005782 data->assoc_reject.timeout_reason : "",
5783 data->assoc_reject.reason_code !=
5784 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5785 " qca_driver_reason=" : "",
5786 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005787 else
5788 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005789 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005790 data->assoc_reject.status_code,
5791 data->assoc_reject.timed_out ? " timeout" : "",
5792 data->assoc_reject.timeout_reason ? "=" : "",
5793 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005794 data->assoc_reject.timeout_reason : "",
5795 data->assoc_reject.reason_code !=
5796 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5797 " qca_driver_reason=" : "",
5798 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005799 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005800 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5801 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005802
5803#ifdef CONFIG_OWE
5804 if (data->assoc_reject.status_code ==
5805 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5806 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5807 wpa_s->current_ssid &&
5808 wpa_s->current_ssid->owe_group == 0 &&
5809 wpa_s->last_owe_group != 21) {
5810 struct wpa_ssid *ssid = wpa_s->current_ssid;
5811 struct wpa_bss *bss = wpa_s->current_bss;
5812
5813 if (!bss) {
5814 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5815 if (!bss) {
Sunil Ravi72e01222024-03-09 01:25:43 +00005816 wpas_connection_failed(wpa_s, bssid, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005817 wpa_supplicant_mark_disassoc(wpa_s);
5818 return;
5819 }
5820 }
5821 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5822 wpas_connect_work_done(wpa_s);
5823 wpa_supplicant_mark_disassoc(wpa_s);
5824 wpa_supplicant_connect(wpa_s, bss, ssid);
5825 return;
5826 }
5827#endif /* CONFIG_OWE */
5828
Hai Shalomfdcde762020-04-02 11:19:20 -07005829#ifdef CONFIG_DPP2
5830 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5831 * the status code defined in the DPP R2 tech spec.
5832 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5833 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005834 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005835 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5836 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5837 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005838 wpa_s->current_ssid->dpp_pfs == 0 &&
5839 (data->assoc_reject.status_code ==
5840 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5841 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5842 struct wpa_ssid *ssid = wpa_s->current_ssid;
5843 struct wpa_bss *bss = wpa_s->current_bss;
5844
5845 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5846 if (!bss)
5847 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5848 if (!bss || wpa_s->dpp_pfs_fallback) {
5849 wpa_printf(MSG_DEBUG,
5850 "DPP: Updated PFS policy for next try");
Sunil Ravi72e01222024-03-09 01:25:43 +00005851 wpas_connection_failed(wpa_s, bssid, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07005852 wpa_supplicant_mark_disassoc(wpa_s);
5853 return;
5854 }
5855 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5856 wpa_s->dpp_pfs_fallback = 1;
5857 wpas_connect_work_done(wpa_s);
5858 wpa_supplicant_mark_disassoc(wpa_s);
5859 wpa_supplicant_connect(wpa_s, bss, ssid);
5860 return;
5861 }
5862#endif /* CONFIG_DPP2 */
5863
Hai Shalom74f70d42019-02-11 14:42:39 -08005864#ifdef CONFIG_MBO
5865 if (data->assoc_reject.status_code ==
5866 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005867 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005868 const u8 *rssi_rej;
5869
5870 rssi_rej = mbo_get_attr_from_ies(
5871 data->assoc_reject.resp_ies,
5872 data->assoc_reject.resp_ies_len,
5873 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5874 if (rssi_rej && rssi_rej[1] == 2) {
5875 wpa_printf(MSG_DEBUG,
5876 "OCE: RSSI-based association rejection from "
5877 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005878 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005879 rssi_rej[2], rssi_rej[3]);
5880 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005881 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005882 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005883 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005884 }
5885 }
5886#endif /* CONFIG_MBO */
5887
Sunil Ravi72e01222024-03-09 01:25:43 +00005888 /* Check for other failed links in the response */
5889 os_memset(link_bssids, 0, sizeof(link_bssids));
5890 if (ieee802_11_parse_elems(data->assoc_reject.resp_ies,
5891 data->assoc_reject.resp_ies_len,
5892 &elems, 1) != ParseFailed) {
5893 struct ml_sta_link_info ml_info[MAX_NUM_MLD_LINKS];
5894 unsigned int n_links, i, idx;
5895
5896 idx = 0;
5897 n_links = wpas_ml_parse_assoc(wpa_s, &elems, ml_info);
5898
5899 for (i = 1; i < n_links; i++) {
5900 /* The status cannot be success here.
5901 * Add the link to the failed list if it is reporting
5902 * an error. The only valid "non-error" status is
5903 * TX_LINK_NOT_ACCEPTED as that means this link may
5904 * still accept an association from us.
5905 */
5906 if (ml_info[i].status !=
5907 WLAN_STATUS_DENIED_TX_LINK_NOT_ACCEPTED) {
5908 link_bssids[idx] = ml_info[i].bssid;
5909 idx++;
5910 }
5911 }
5912 }
5913
Roshan Pius3a1667e2018-07-03 15:17:14 -07005914 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
Sunil Ravi72e01222024-03-09 01:25:43 +00005915 sme_event_assoc_reject(wpa_s, data, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005916 return;
5917 }
5918
5919 /* Driver-based SME cases */
5920
5921#ifdef CONFIG_SAE
5922 if (wpa_s->current_ssid &&
5923 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5924 !data->assoc_reject.timed_out) {
5925 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5926 wpa_sm_aborted_cached(wpa_s->wpa);
5927 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5928 }
5929#endif /* CONFIG_SAE */
5930
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005931#ifdef CONFIG_DPP
5932 if (wpa_s->current_ssid &&
5933 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5934 !data->assoc_reject.timed_out) {
5935 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5936 wpa_sm_aborted_cached(wpa_s->wpa);
5937 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5938 }
5939#endif /* CONFIG_DPP */
5940
Roshan Pius3a1667e2018-07-03 15:17:14 -07005941#ifdef CONFIG_FILS
5942 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005943 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005944 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005945 eapol_sm_update_erp_next_seq_num(
5946 wpa_s->eapol,
5947 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005948 fils_connection_failure(wpa_s);
5949 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005950#endif /* CONFIG_FILS */
5951
Sunil Ravi72e01222024-03-09 01:25:43 +00005952 wpas_connection_failed(wpa_s, bssid, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005953 wpa_supplicant_mark_disassoc(wpa_s);
5954}
5955
5956
Hai Shalomfdcde762020-04-02 11:19:20 -07005957static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5958 struct unprot_beacon *data)
5959{
5960 struct wpabuf *buf;
5961 int res;
5962
5963 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
Sunil Ravi72e01222024-03-09 01:25:43 +00005964 !ether_addr_equal(data->sa, wpa_s->bssid))
Hai Shalomfdcde762020-04-02 11:19:20 -07005965 return;
5966 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5967 MAC2STR(data->sa));
5968
5969 buf = wpabuf_alloc(4);
5970 if (!buf)
5971 return;
5972
5973 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5974 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5975 wpabuf_put_u8(buf, 1); /* Dialog Token */
5976 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5977
5978 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5979 wpa_s->own_addr, wpa_s->bssid,
5980 wpabuf_head(buf), wpabuf_len(buf), 0);
5981 if (res < 0)
5982 wpa_printf(MSG_DEBUG,
5983 "Failed to send WNM-Notification Request frame");
5984
5985 wpabuf_free(buf);
5986}
5987
5988
Sunil Ravi640215c2023-06-28 23:08:09 +00005989static const char * bitmap_to_str(u8 value, char *buf)
5990{
5991 char *pos = buf;
5992 int i, k = 0;
5993
5994 for (i = 7; i >= 0; i--)
5995 pos[k++] = (value & BIT(i)) ? '1' : '0';
5996
5997 pos[8] = '\0';
5998 return pos;
5999}
6000
6001
6002static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
6003 struct tid_link_map_info *info)
6004{
6005 char map_info[1000], *pos, *end;
6006 int res, i;
6007
6008 pos = map_info;
6009 end = pos + sizeof(map_info);
6010 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
6011 info->default_map);
6012 if (os_snprintf_error(end - pos, res))
6013 return;
6014 pos += res;
6015
6016 if (!info->default_map) {
Sunil Raviaf399a82024-05-05 20:56:55 +00006017 for_each_link(info->valid_links, i) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006018 char uplink_map_str[9];
6019 char downlink_map_str[9];
6020
Sunil Ravi640215c2023-06-28 23:08:09 +00006021 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
6022 bitmap_to_str(info->t2lmap[i].downlink,
6023 downlink_map_str);
6024
6025 res = os_snprintf(pos, end - pos,
6026 " link_id=%d up_link=%s down_link=%s",
6027 i, uplink_map_str,
6028 downlink_map_str);
6029 if (os_snprintf_error(end - pos, res))
6030 return;
6031 pos += res;
6032 }
6033 }
6034
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306035 wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP);
Sunil Ravi640215c2023-06-28 23:08:09 +00006036 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
6037}
6038
6039
6040static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
6041{
6042 u8 bssid[ETH_ALEN];
6043
6044 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
6045 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
6046 wpa_supplicant_deauthenticate(wpa_s,
6047 WLAN_REASON_DEAUTH_LEAVING);
6048 return;
6049 }
6050
Sunil Ravi72e01222024-03-09 01:25:43 +00006051 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006052 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
6053 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
6054 wpas_notify_bssid_changed(wpa_s);
6055 }
6056
6057 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
6058 wpa_printf(MSG_ERROR,
6059 "LINK_RECONFIG: Failed to get MLO connection info");
6060 wpa_supplicant_deauthenticate(wpa_s,
6061 WLAN_REASON_DEAUTH_LEAVING);
6062 return;
6063 }
6064
6065 if (wpa_sm_set_ml_info(wpa_s)) {
6066 wpa_printf(MSG_ERROR,
6067 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
6068 wpa_supplicant_deauthenticate(wpa_s,
6069 WLAN_REASON_DEAUTH_LEAVING);
6070 return;
6071 }
6072
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306073 wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL);
Sunil Ravi640215c2023-06-28 23:08:09 +00006074 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
6075 wpa_s->valid_links);
6076}
6077
6078
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006079void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
6080 union wpa_event_data *data)
6081{
6082 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006083 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07006084 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08006085#ifndef CONFIG_NO_STDOUT_DEBUG
6086 int level = MSG_DEBUG;
6087#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006088
6089 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
6090 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006091 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006092 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006093 event != EVENT_SCHED_SCAN_STOPPED) {
6094 wpa_dbg(wpa_s, MSG_DEBUG,
6095 "Ignore event %s (%d) while interface is disabled",
6096 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006097 return;
6098 }
6099
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006100#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07006101 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006102 const struct ieee80211_hdr *hdr;
6103 u16 fc;
6104 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
6105 fc = le_to_host16(hdr->frame_control);
6106 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
6107 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
6108 level = MSG_EXCESSIVE;
6109 }
6110
6111 wpa_dbg(wpa_s, level, "Event %s (%d) received",
6112 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006113#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006114
6115 switch (event) {
6116 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006117#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08006118 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
6119 data->auth.ies_len))
6120 wpa_printf(MSG_DEBUG,
6121 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006122#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006123 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006124 wpa_s->auth_status_code = data->auth.status_code;
6125 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006126 break;
6127 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006128#ifdef CONFIG_TESTING_OPTIONS
6129 if (wpa_s->ignore_auth_resp) {
6130 wpa_printf(MSG_INFO,
6131 "EVENT_ASSOC - ignore_auth_resp active!");
6132 break;
6133 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006134 if (wpa_s->testing_resend_assoc) {
6135 wpa_printf(MSG_INFO,
6136 "EVENT_DEAUTH - testing_resend_assoc");
6137 break;
6138 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006139#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05306140 if (wpa_s->disconnected) {
6141 wpa_printf(MSG_INFO,
6142 "Ignore unexpected EVENT_ASSOC in disconnected state");
6143 break;
6144 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006145 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006146 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006147 if (data &&
6148 (data->assoc_info.authorized ||
6149 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6150 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006151 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006152 if (data) {
6153 wpa_msg(wpa_s, MSG_INFO,
6154 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
6155 data->assoc_info.subnet_status);
6156 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006157 break;
6158 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006159 wpas_event_disassoc(wpa_s,
6160 data ? &data->disassoc_info : NULL);
6161 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006162 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006163#ifdef CONFIG_TESTING_OPTIONS
6164 if (wpa_s->ignore_auth_resp) {
6165 wpa_printf(MSG_INFO,
6166 "EVENT_DEAUTH - ignore_auth_resp active!");
6167 break;
6168 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006169 if (wpa_s->testing_resend_assoc) {
6170 wpa_printf(MSG_INFO,
6171 "EVENT_DEAUTH - testing_resend_assoc");
6172 break;
6173 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006174#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006175 wpas_event_deauth(wpa_s,
6176 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006177 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00006178 case EVENT_LINK_RECONFIG:
6179 wpas_link_reconfig(wpa_s);
6180 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006181 case EVENT_MICHAEL_MIC_FAILURE:
6182 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
6183 break;
6184#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006185 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006186 if (wpa_s->own_scan_requested ||
6187 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006188 struct os_reltime diff;
6189
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006190 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006191 os_reltime_sub(&wpa_s->scan_start_time,
6192 &wpa_s->scan_trigger_time, &diff);
6193 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
6194 diff.sec, diff.usec);
6195 wpa_s->own_scan_requested = 0;
6196 wpa_s->own_scan_running = 1;
6197 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
6198 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006199 wpa_msg_ctrl(wpa_s, MSG_INFO,
6200 WPA_EVENT_SCAN_STARTED "id=%u",
6201 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006202 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006203 wpa_msg_ctrl(wpa_s, MSG_INFO,
6204 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006205 }
6206 } else {
6207 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08006208 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006209 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006210 }
6211 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006212 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006213 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6214 wpa_s->scan_res_handler = NULL;
6215 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08006216 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006217 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
6218 break;
6219 }
6220
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006221 if (!(data && data->scan_info.external_scan) &&
6222 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006223 struct os_reltime now, diff;
6224 os_get_reltime(&now);
6225 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
6226 wpa_s->scan_start_time.sec = 0;
6227 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00006228 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006229 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
6230 diff.sec, diff.usec);
6231 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006232 if (wpa_supplicant_event_scan_results(wpa_s, data))
6233 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006234 if (!(data && data->scan_info.external_scan))
6235 wpa_s->own_scan_running = 0;
6236 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08006237 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006238 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006239 break;
6240#endif /* CONFIG_NO_SCAN_PROCESSING */
6241 case EVENT_ASSOCINFO:
6242 wpa_supplicant_event_associnfo(wpa_s, data);
6243 break;
6244 case EVENT_INTERFACE_STATUS:
6245 wpa_supplicant_event_interface_status(wpa_s, data);
6246 break;
6247 case EVENT_PMKID_CANDIDATE:
6248 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
6249 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006250#ifdef CONFIG_TDLS
6251 case EVENT_TDLS:
6252 wpa_supplicant_event_tdls(wpa_s, data);
6253 break;
6254#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006255#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006256 case EVENT_WNM:
6257 wpa_supplicant_event_wnm(wpa_s, data);
6258 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006259#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006260#ifdef CONFIG_IEEE80211R
6261 case EVENT_FT_RESPONSE:
6262 wpa_supplicant_event_ft_response(wpa_s, data);
6263 break;
6264#endif /* CONFIG_IEEE80211R */
6265#ifdef CONFIG_IBSS_RSN
6266 case EVENT_IBSS_RSN_START:
6267 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
6268 break;
6269#endif /* CONFIG_IBSS_RSN */
6270 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07006271 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006272 break;
6273 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006274 /* It is possible to get this event from earlier connection */
6275 if (wpa_s->current_ssid &&
6276 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6277 wpa_dbg(wpa_s, MSG_DEBUG,
6278 "Ignore AUTH_TIMED_OUT in mesh configuration");
6279 break;
6280 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006281 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6282 sme_event_auth_timed_out(wpa_s, data);
6283 break;
6284 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006285 /* It is possible to get this event from earlier connection */
6286 if (wpa_s->current_ssid &&
6287 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6288 wpa_dbg(wpa_s, MSG_DEBUG,
6289 "Ignore ASSOC_TIMED_OUT in mesh configuration");
6290 break;
6291 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006292 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6293 sme_event_assoc_timed_out(wpa_s, data);
6294 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006295 case EVENT_TX_STATUS:
6296 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
6297 " type=%d stype=%d",
6298 MAC2STR(data->tx_status.dst),
6299 data->tx_status.type, data->tx_status.stype);
Sunil Raviaf399a82024-05-05 20:56:55 +00006300#ifdef CONFIG_WNM
6301 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6302 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
6303 wnm_btm_resp_tx_status(wpa_s, data->tx_status.data,
6304 data->tx_status.data_len) == 0)
6305 break;
6306#endif /* CONFIG_WNM */
Hai Shalom60840252021-02-19 19:02:11 -08006307#ifdef CONFIG_PASN
6308 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6309 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6310 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
6311 data->tx_status.data_len,
6312 data->tx_status.ack) == 0)
6313 break;
6314#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006315#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006316 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006317#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006318 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6319 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006320 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006321 wpa_s, data->tx_status.dst,
6322 data->tx_status.data,
6323 data->tx_status.data_len,
6324 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006325 OFFCHANNEL_SEND_ACTION_SUCCESS :
6326 OFFCHANNEL_SEND_ACTION_NO_ACK);
6327#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006328 break;
6329 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006330#endif /* CONFIG_AP */
6331#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006332 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006333 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006334 /*
6335 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006336 * interface in GO mode, or via standalone AP interface.
6337 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
6338 * except when the primary interface is used as a GO interface
6339 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006340 */
6341 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6342 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Sunil Ravi72e01222024-03-09 01:25:43 +00006343 ether_addr_equal(wpa_s->p2pdev->pending_action_dst,
6344 data->tx_status.dst)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006345 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006346 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006347 data->tx_status.data,
6348 data->tx_status.data_len,
6349 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006350 OFFCHANNEL_SEND_ACTION_SUCCESS :
6351 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006352 break;
6353 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006354#endif /* CONFIG_OFFCHANNEL */
6355#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006356 switch (data->tx_status.type) {
6357 case WLAN_FC_TYPE_MGMT:
6358 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
6359 data->tx_status.data_len,
6360 data->tx_status.stype,
6361 data->tx_status.ack);
6362 break;
6363 case WLAN_FC_TYPE_DATA:
6364 ap_tx_status(wpa_s, data->tx_status.dst,
6365 data->tx_status.data,
6366 data->tx_status.data_len,
6367 data->tx_status.ack);
6368 break;
6369 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006370#endif /* CONFIG_AP */
6371 break;
6372#ifdef CONFIG_AP
6373 case EVENT_EAPOL_TX_STATUS:
6374 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
6375 data->eapol_tx_status.data,
6376 data->eapol_tx_status.data_len,
6377 data->eapol_tx_status.ack);
6378 break;
6379 case EVENT_DRIVER_CLIENT_POLL_OK:
6380 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006381 break;
6382 case EVENT_RX_FROM_UNKNOWN:
6383 if (wpa_s->ap_iface == NULL)
6384 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006385 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
6386 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006387 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006388#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07006389
Sunil Ravi89eba102022-09-13 21:04:37 -07006390 case EVENT_LINK_CH_SWITCH_STARTED:
6391 case EVENT_LINK_CH_SWITCH:
6392 if (!data || !wpa_s->current_ssid ||
6393 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6394 break;
6395
6396 wpa_msg(wpa_s, MSG_INFO,
6397 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6398 event == EVENT_LINK_CH_SWITCH ?
6399 WPA_EVENT_LINK_CHANNEL_SWITCH :
6400 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6401 data->ch_switch.freq,
6402 data->ch_switch.link_id,
6403 data->ch_switch.ht_enabled,
6404 data->ch_switch.ch_offset,
6405 channel_width_to_string(data->ch_switch.ch_width),
6406 data->ch_switch.cf1,
6407 data->ch_switch.cf2);
6408 if (event == EVENT_LINK_CH_SWITCH_STARTED)
6409 break;
6410
6411 wpa_s->links[data->ch_switch.link_id].freq =
6412 data->ch_switch.freq;
6413 if (wpa_s->links[data->ch_switch.link_id].bss &&
6414 wpa_s->links[data->ch_switch.link_id].bss->freq !=
6415 data->ch_switch.freq) {
6416 wpa_s->links[data->ch_switch.link_id].bss->freq =
6417 data->ch_switch.freq;
6418 notify_bss_changes(
6419 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6420 wpa_s->links[data->ch_switch.link_id].bss);
Shuibing Dai0db6bb12023-09-28 17:53:17 -07006421 if (data->ch_switch.freq)
6422 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
Sunil Ravi89eba102022-09-13 21:04:37 -07006423 }
6424 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07006425 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07006426 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006427 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006428 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006429
Hai Shalom81f62d82019-07-22 12:10:00 -07006430 wpa_msg(wpa_s, MSG_INFO,
6431 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6432 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6433 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006434 data->ch_switch.freq,
6435 data->ch_switch.ht_enabled,
6436 data->ch_switch.ch_offset,
6437 channel_width_to_string(data->ch_switch.ch_width),
6438 data->ch_switch.cf1,
6439 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07006440 if (event == EVENT_CH_SWITCH_STARTED)
6441 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006442
Sunil Ravi65a724b2022-05-24 11:06:09 -07006443 if (wpa_s->assoc_freq && data->ch_switch.freq &&
6444 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
6445 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
6446 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006447 wpa_s->assoc_freq = data->ch_switch.freq;
6448 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08006449 if (wpa_s->current_bss &&
6450 wpa_s->current_bss->freq != data->ch_switch.freq) {
6451 wpa_s->current_bss->freq = data->ch_switch.freq;
6452 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6453 wpa_s->current_bss);
6454 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006455
Hai Shalomfdcde762020-04-02 11:19:20 -07006456#ifdef CONFIG_SME
6457 switch (data->ch_switch.ch_offset) {
6458 case 1:
6459 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6460 break;
6461 case -1:
6462 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6463 break;
6464 default:
6465 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6466 break;
6467 }
6468#endif /* CONFIG_SME */
6469
Roshan Pius3a1667e2018-07-03 15:17:14 -07006470#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006471 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6472 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08006473 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006474 wpa_s->current_ssid->mode ==
6475 WPAS_MODE_P2P_GROUP_FORMATION) {
6476 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6477 data->ch_switch.ht_enabled,
6478 data->ch_switch.ch_offset,
6479 data->ch_switch.ch_width,
6480 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006481 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07006482 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07006483 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006484 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006485#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006486
Hai Shalom899fcc72020-10-19 14:38:18 -07006487 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6488 sme_event_ch_switch(wpa_s);
6489
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006490 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006491 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006492 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006493#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006494#ifdef NEED_AP_MLME
6495 case EVENT_DFS_RADAR_DETECTED:
6496 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07006497 wpas_ap_event_dfs_radar_detected(wpa_s,
6498 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006499 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006500 case EVENT_DFS_NOP_FINISHED:
6501 if (data)
6502 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
6503 &data->dfs_event);
6504 break;
6505#endif /* NEED_AP_MLME */
6506#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006507 case EVENT_DFS_CAC_STARTED:
6508 if (data)
6509 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
6510 break;
6511 case EVENT_DFS_CAC_FINISHED:
6512 if (data)
6513 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
6514 break;
6515 case EVENT_DFS_CAC_ABORTED:
6516 if (data)
6517 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
6518 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006519 case EVENT_RX_MGMT: {
6520 u16 fc, stype;
6521 const struct ieee80211_mgmt *mgmt;
6522
Dmitry Shmidt818ea482014-03-10 13:15:21 -07006523#ifdef CONFIG_TESTING_OPTIONS
6524 if (wpa_s->ext_mgmt_frame_handling) {
6525 struct rx_mgmt *rx = &data->rx_mgmt;
6526 size_t hex_len = 2 * rx->frame_len + 1;
6527 char *hex = os_malloc(hex_len);
6528 if (hex) {
6529 wpa_snprintf_hex(hex, hex_len,
6530 rx->frame, rx->frame_len);
6531 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
6532 rx->freq, rx->datarate, rx->ssi_signal,
6533 hex);
6534 os_free(hex);
6535 }
6536 break;
6537 }
6538#endif /* CONFIG_TESTING_OPTIONS */
6539
Dmitry Shmidt04949592012-07-19 12:16:46 -07006540 mgmt = (const struct ieee80211_mgmt *)
6541 data->rx_mgmt.frame;
6542 fc = le_to_host16(mgmt->frame_control);
6543 stype = WLAN_FC_GET_STYPE(fc);
6544
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006545#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006546 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006547#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006548#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006549 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006550 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006551 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07006552 const u8 *ie;
6553 size_t ie_len;
6554
6555 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6556 ie_len = data->rx_mgmt.frame_len -
6557 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006558 wpas_p2p_probe_req_rx(
6559 wpa_s, src, mgmt->da,
6560 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006561 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006562 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006563 break;
6564 }
6565#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006566#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006567 if (wpa_s->current_ssid &&
6568 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
6569 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006570 data->rx_mgmt.frame_len >= 30) {
6571 wpa_supplicant_event_ibss_auth(wpa_s, data);
6572 break;
6573 }
6574#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006575
6576 if (stype == WLAN_FC_STYPE_ACTION) {
6577 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07006578 wpa_s, data->rx_mgmt.frame,
6579 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006580 data->rx_mgmt.freq,
6581 data->rx_mgmt.ssi_signal);
6582 break;
6583 }
6584
6585 if (wpa_s->ifmsh) {
6586 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006587 break;
6588 }
Hai Shalom60840252021-02-19 19:02:11 -08006589#ifdef CONFIG_PASN
6590 if (stype == WLAN_FC_STYPE_AUTH &&
6591 wpas_pasn_auth_rx(wpa_s, mgmt,
6592 data->rx_mgmt.frame_len) != -2)
6593 break;
6594#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006595
Roshan Pius3a1667e2018-07-03 15:17:14 -07006596#ifdef CONFIG_SAE
6597 if (stype == WLAN_FC_STYPE_AUTH &&
6598 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6599 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6600 sme_external_auth_mgmt_rx(
6601 wpa_s, data->rx_mgmt.frame,
6602 data->rx_mgmt.frame_len);
6603 break;
6604 }
6605#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006606 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6607 "management frame in non-AP mode");
6608 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006609#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006610 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006611
6612 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006613 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6614 const u8 *ie;
6615 size_t ie_len;
6616
6617 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6618 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006619
6620 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6621 mgmt->bssid, ie, ie_len,
6622 data->rx_mgmt.ssi_signal);
6623 }
6624
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006625 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006626#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006627 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006628 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006629 case EVENT_RX_PROBE_REQ:
6630 if (data->rx_probe_req.sa == NULL ||
6631 data->rx_probe_req.ie == NULL)
6632 break;
6633#ifdef CONFIG_AP
6634 if (wpa_s->ap_iface) {
6635 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6636 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006637 data->rx_probe_req.da,
6638 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006639 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006640 data->rx_probe_req.ie_len,
6641 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006642 break;
6643 }
6644#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006645 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006646 data->rx_probe_req.da,
6647 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006648 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006649 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006650 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006651 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006652 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006653 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006654#ifdef CONFIG_OFFCHANNEL
6655 offchannel_remain_on_channel_cb(
6656 wpa_s, data->remain_on_channel.freq,
6657 data->remain_on_channel.duration);
6658#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006659 wpas_p2p_remain_on_channel_cb(
6660 wpa_s, data->remain_on_channel.freq,
6661 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006662#ifdef CONFIG_DPP
6663 wpas_dpp_remain_on_channel_cb(
6664 wpa_s, data->remain_on_channel.freq,
6665 data->remain_on_channel.duration);
6666#endif /* CONFIG_DPP */
Sunil Ravi72e01222024-03-09 01:25:43 +00006667#ifdef CONFIG_NAN_USD
6668 wpas_nan_usd_remain_on_channel_cb(
6669 wpa_s, data->remain_on_channel.freq,
6670 data->remain_on_channel.duration);
6671#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006672 break;
6673 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006674#ifdef CONFIG_OFFCHANNEL
6675 offchannel_cancel_remain_on_channel_cb(
6676 wpa_s, data->remain_on_channel.freq);
6677#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006678 wpas_p2p_cancel_remain_on_channel_cb(
6679 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006680#ifdef CONFIG_DPP
6681 wpas_dpp_cancel_remain_on_channel_cb(
6682 wpa_s, data->remain_on_channel.freq);
6683#endif /* CONFIG_DPP */
Sunil Ravi72e01222024-03-09 01:25:43 +00006684#ifdef CONFIG_NAN_USD
6685 wpas_nan_usd_cancel_remain_on_channel_cb(
6686 wpa_s, data->remain_on_channel.freq);
6687#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006688 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006689 case EVENT_EAPOL_RX:
6690 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6691 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00006692 data->eapol_rx.data_len,
6693 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006694 break;
6695 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006696 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00006697 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006698 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006699 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006700 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006701 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006702 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006703 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006704 bgscan_notify_signal_change(
6705 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006706 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006707 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006708 data->signal_change.data.current_tx_rate);
6709 os_memcpy(&wpa_s->last_signal_info, data,
6710 sizeof(struct wpa_signal_info));
6711 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006712 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006713 case EVENT_INTERFACE_MAC_CHANGED:
6714 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006715 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006716 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006717 case EVENT_INTERFACE_ENABLED:
6718 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6719 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006720 u8 addr[ETH_ALEN];
6721
Hai Shalomfdcde762020-04-02 11:19:20 -07006722 eloop_cancel_timeout(wpas_clear_disabled_interface,
6723 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08006724 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006725 wpa_supplicant_update_mac_addr(wpa_s);
Sunil Ravi72e01222024-03-09 01:25:43 +00006726 if (!ether_addr_equal(addr, wpa_s->own_addr))
Hai Shalomc1a21442022-02-04 13:43:00 -08006727 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6728 else
6729 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07006730 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006731 if (wpa_s->p2p_mgmt) {
6732 wpa_supplicant_set_state(wpa_s,
6733 WPA_DISCONNECTED);
6734 break;
6735 }
6736
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006737#ifdef CONFIG_AP
6738 if (!wpa_s->ap_iface) {
6739 wpa_supplicant_set_state(wpa_s,
6740 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006741 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006742 wpa_supplicant_req_scan(wpa_s, 0, 0);
6743 } else
6744 wpa_supplicant_set_state(wpa_s,
6745 WPA_COMPLETED);
6746#else /* CONFIG_AP */
6747 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6748 wpa_supplicant_req_scan(wpa_s, 0, 0);
6749#endif /* CONFIG_AP */
6750 }
6751 break;
6752 case EVENT_INTERFACE_DISABLED:
6753 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006754#ifdef CONFIG_P2P
6755 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6756 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6757 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6758 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006759 * Mark interface disabled if this happens to end up not
6760 * being removed as a separate P2P group interface.
6761 */
6762 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6763 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006764 * The interface was externally disabled. Remove
6765 * it assuming an external entity will start a
6766 * new session if needed.
6767 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006768 if (wpa_s->current_ssid &&
6769 wpa_s->current_ssid->p2p_group)
6770 wpas_p2p_interface_unavailable(wpa_s);
6771 else
6772 wpas_p2p_disconnect(wpa_s);
6773 /*
6774 * wpa_s instance may have been freed, so must not use
6775 * it here anymore.
6776 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006777 break;
6778 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006779 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6780 p2p_in_progress(wpa_s->global->p2p) > 1) {
6781 /* This radio work will be cancelled, so clear P2P
6782 * state as well.
6783 */
6784 p2p_stop_find(wpa_s->global->p2p);
6785 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006786#endif /* CONFIG_P2P */
6787
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006788 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6789 /*
6790 * Indicate disconnection to keep ctrl_iface events
6791 * consistent.
6792 */
6793 wpa_supplicant_event_disassoc(
6794 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6795 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006796 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07006797 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08006798 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6799 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006800 clear_at.usec = 0;
6801 } else {
6802 struct os_reltime tmp;
6803
Hai Shalom60840252021-02-19 19:02:11 -08006804 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006805 tmp.usec = 0;
6806 os_reltime_sub(&tmp, &age, &clear_at);
6807 }
6808 eloop_register_timeout(clear_at.sec, clear_at.usec,
6809 wpas_clear_disabled_interface,
6810 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08006811 radio_remove_works(wpa_s, NULL, 0);
6812
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006813 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6814 break;
6815 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006816 wpa_supplicant_update_channel_list(
6817 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006818 break;
6819 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006820 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006821 break;
6822 case EVENT_BEST_CHANNEL:
6823 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6824 "(%d %d %d)",
6825 data->best_chan.freq_24, data->best_chan.freq_5,
6826 data->best_chan.freq_overall);
6827 wpa_s->best_24_freq = data->best_chan.freq_24;
6828 wpa_s->best_5_freq = data->best_chan.freq_5;
6829 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006830 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6831 data->best_chan.freq_5,
6832 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006833 break;
6834 case EVENT_UNPROT_DEAUTH:
6835 wpa_supplicant_event_unprot_deauth(wpa_s,
6836 &data->unprot_deauth);
6837 break;
6838 case EVENT_UNPROT_DISASSOC:
6839 wpa_supplicant_event_unprot_disassoc(wpa_s,
6840 &data->unprot_disassoc);
6841 break;
6842 case EVENT_STATION_LOW_ACK:
6843#ifdef CONFIG_AP
6844 if (wpa_s->ap_iface && data)
6845 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6846 data->low_ack.addr);
6847#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006848#ifdef CONFIG_TDLS
6849 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07006850 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
6851 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006852#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006853 break;
6854 case EVENT_IBSS_PEER_LOST:
6855#ifdef CONFIG_IBSS_RSN
6856 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6857#endif /* CONFIG_IBSS_RSN */
6858 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006859 case EVENT_DRIVER_GTK_REKEY:
Sunil Ravi72e01222024-03-09 01:25:43 +00006860 if (!ether_addr_equal(data->driver_gtk_rekey.bssid,
6861 wpa_s->bssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006862 break;
6863 if (!wpa_s->wpa)
6864 break;
6865 wpa_sm_update_replay_ctr(wpa_s->wpa,
6866 data->driver_gtk_rekey.replay_ctr);
6867 break;
6868 case EVENT_SCHED_SCAN_STOPPED:
6869 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006870 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006871 wpa_supplicant_notify_scanning(wpa_s, 0);
6872
6873 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6874 break;
6875
6876 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006877 * If the driver stopped scanning without being requested to,
6878 * request a new scan to continue scanning for networks.
6879 */
6880 if (!wpa_s->sched_scan_stop_req &&
6881 wpa_s->wpa_state == WPA_SCANNING) {
6882 wpa_dbg(wpa_s, MSG_DEBUG,
6883 "Restart scanning after unexpected sched_scan stop event");
6884 wpa_supplicant_req_scan(wpa_s, 1, 0);
6885 break;
6886 }
6887
6888 wpa_s->sched_scan_stop_req = 0;
6889
6890 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006891 * Start a new sched scan to continue searching for more SSIDs
6892 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006893 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006894 if (wpa_s->sched_scan_timed_out) {
6895 wpa_supplicant_req_sched_scan(wpa_s);
6896 } else if (wpa_s->pno_sched_pending) {
6897 wpa_s->pno_sched_pending = 0;
6898 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006899 } else if (resched) {
6900 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006901 }
6902
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006903 break;
6904 case EVENT_WPS_BUTTON_PUSHED:
6905#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006906 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006907#endif /* CONFIG_WPS */
6908 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006909 case EVENT_AVOID_FREQUENCIES:
6910 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6911 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006912 case EVENT_CONNECT_FAILED_REASON:
6913#ifdef CONFIG_AP
6914 if (!wpa_s->ap_iface || !data)
6915 break;
6916 hostapd_event_connect_failed_reason(
6917 wpa_s->ap_iface->bss[0],
6918 data->connect_failed_reason.addr,
6919 data->connect_failed_reason.code);
6920#endif /* CONFIG_AP */
6921 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006922 case EVENT_NEW_PEER_CANDIDATE:
6923#ifdef CONFIG_MESH
6924 if (!wpa_s->ifmsh || !data)
6925 break;
6926 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6927 data->mesh_peer.ies,
6928 data->mesh_peer.ie_len);
6929#endif /* CONFIG_MESH */
6930 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006931 case EVENT_SURVEY:
6932#ifdef CONFIG_AP
6933 if (!wpa_s->ap_iface)
6934 break;
6935 hostapd_event_get_survey(wpa_s->ap_iface,
6936 &data->survey_results);
6937#endif /* CONFIG_AP */
6938 break;
6939 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006940#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006941#ifdef CONFIG_ACS
6942 if (!wpa_s->ap_iface)
6943 break;
6944 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6945 &data->acs_selected_channels);
6946#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006947#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006948 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006949 case EVENT_P2P_LO_STOP:
6950#ifdef CONFIG_P2P
6951 wpa_s->p2p_lo_started = 0;
6952 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6953 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6954 data->p2p_lo_stop.reason_code);
6955#endif /* CONFIG_P2P */
6956 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006957 case EVENT_BEACON_LOSS:
6958 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6959 break;
6960 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6961 bgscan_notify_beacon_loss(wpa_s);
6962 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006963 case EVENT_EXTERNAL_AUTH:
6964#ifdef CONFIG_SAE
6965 if (!wpa_s->current_ssid) {
6966 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6967 break;
6968 }
6969 sme_external_auth_trigger(wpa_s, data);
6970#endif /* CONFIG_SAE */
6971 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006972#ifdef CONFIG_PASN
6973 case EVENT_PASN_AUTH:
6974 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6975 break;
6976#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006977 case EVENT_PORT_AUTHORIZED:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006978#ifdef CONFIG_AP
6979 if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
6980 struct sta_info *sta;
6981
6982 sta = ap_get_sta(wpa_s->ap_iface->bss[0],
6983 data->port_authorized.sta_addr);
6984 if (sta)
6985 ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
6986 sta, 1);
6987 else
6988 wpa_printf(MSG_DEBUG,
6989 "No STA info matching port authorized event found");
6990 break;
6991 }
6992#endif /* CONFIG_AP */
Sunil Ravi77d572f2023-01-17 23:58:31 +00006993#ifndef CONFIG_NO_WPA
6994 if (data->port_authorized.td_bitmap_len) {
6995 wpa_printf(MSG_DEBUG,
6996 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
6997 data->port_authorized.td_bitmap[0]);
6998 wpas_transition_disable(
6999 wpa_s, data->port_authorized.td_bitmap[0]);
7000 }
7001#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007002 wpa_supplicant_event_port_authorized(wpa_s);
7003 break;
7004 case EVENT_STATION_OPMODE_CHANGED:
7005#ifdef CONFIG_AP
7006 if (!wpa_s->ap_iface || !data)
7007 break;
7008
7009 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
7010 data->sta_opmode.addr,
7011 data->sta_opmode.smps_mode,
7012 data->sta_opmode.chan_width,
7013 data->sta_opmode.rx_nss);
7014#endif /* CONFIG_AP */
7015 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07007016 case EVENT_UNPROT_BEACON:
7017 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
7018 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08007019 case EVENT_TX_WAIT_EXPIRE:
7020#ifdef CONFIG_DPP
7021 wpas_dpp_tx_wait_expire(wpa_s);
7022#endif /* CONFIG_DPP */
Sunil Ravi72e01222024-03-09 01:25:43 +00007023#ifdef CONFIG_NAN_USD
7024 wpas_nan_usd_tx_wait_expire(wpa_s);
7025#endif /* CONFIG_NAN_USD */
Hai Shalomc1a21442022-02-04 13:43:00 -08007026 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00007027 case EVENT_TID_LINK_MAP:
7028 if (data)
7029 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
7030 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007031 default:
7032 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
7033 break;
7034 }
7035}
Dmitry Shmidte4663042016-04-04 10:07:49 -07007036
7037
7038void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
7039 union wpa_event_data *data)
7040{
7041 struct wpa_supplicant *wpa_s;
7042
7043 if (event != EVENT_INTERFACE_STATUS)
7044 return;
7045
7046 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
7047 if (wpa_s && wpa_s->driver->get_ifindex) {
7048 unsigned int ifindex;
7049
7050 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
7051 if (ifindex != data->interface_status.ifindex) {
7052 wpa_dbg(wpa_s, MSG_DEBUG,
7053 "interface status ifindex %d mismatch (%d)",
7054 ifindex, data->interface_status.ifindex);
7055 return;
7056 }
7057 }
7058#ifdef CONFIG_MATCH_IFACE
7059 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
7060 struct wpa_interface *wpa_i;
7061
7062 wpa_i = wpa_supplicant_match_iface(
7063 ctx, data->interface_status.ifname);
7064 if (!wpa_i)
7065 return;
7066 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
7067 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07007068 }
7069#endif /* CONFIG_MATCH_IFACE */
7070
7071 if (wpa_s)
7072 wpa_supplicant_event(wpa_s, event, data);
7073}