blob: bc45579bb115609e095800fa041881f266d4fdda [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 Ravib0ac25f2024-07-12 01:42:03 +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 Ravi88611412024-06-28 17:34:56 +0000167 wpa_supplicant_update_scan_results(wpa_s);
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 Ravi88611412024-06-28 17:34:56 +0000186 wpa_supplicant_update_scan_results(wpa_s);
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 Ravib0ac25f2024-07-12 01:42:03 +0000387#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800388 wpas_rrm_reset(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000389#endif /* CONFIG_NO_RRM */
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800390 wpa_s->wnmsleep_used = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +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 Ravib0ac25f2024-07-12 01:42:03 +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 Ravib0ac25f2024-07-12 01:42:03 +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 Ravi88611412024-06-28 17:34:56 +00001159
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001160{
1161 u16 removed_links;
1162
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001163 if (wpa_bss_parse_basic_ml_element(wpa_s, bss, NULL, NULL, NULL, NULL))
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001164 return true;
1165
Sunil Ravi88611412024-06-28 17:34:56 +00001166 if (bss->n_mld_links == 0)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001167 return true;
1168
1169 /* Check if the current BSS is going to be removed */
1170 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss);
Sunil Ravi88611412024-06-28 17:34:56 +00001171 if (BIT(bss->mld_links[0].link_id) & removed_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001172 return false;
1173
1174 return true;
1175}
1176
1177
Sunil Ravi26978f32021-04-30 15:19:18 -07001178int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001179{
1180 int i, j;
1181
1182 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1183 return 0;
1184
1185 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1186 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1187
1188 for (i = 0; i < mode->num_channels; i++) {
1189 struct hostapd_channel_data *chan = &mode->channels[i];
1190
1191 if (chan->freq == freq)
1192 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1193 }
1194 }
1195
1196 return 1;
1197}
1198
1199
Hai Shalom899fcc72020-10-19 14:38:18 -07001200static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1201 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001202 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001203 bool debug_print);
1204
1205
1206#ifdef CONFIG_SAE_PK
1207static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1208 struct wpa_bss *orig_bss,
1209 struct wpa_ssid *ssid,
1210 const u8 *match_ssid,
1211 size_t match_ssid_len)
1212{
1213 struct wpa_bss *bss;
1214
1215 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1216 int count;
1217 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001218
1219 if (bss == orig_bss)
1220 continue;
1221 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001222 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001223 continue;
1224
1225 /* TODO: Could be more thorough in checking what kind of
1226 * signal strength or throughput estimate would be acceptable
1227 * compared to the originally selected BSS. */
1228 if (bss->est_throughput < 2000)
1229 return false;
1230
Hai Shalom60840252021-02-19 19:02:11 -08001231 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001232 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1233 bss, count, 0))
1234 return true;
1235 }
1236
1237 return false;
1238}
1239#endif /* CONFIG_SAE_PK */
1240
1241
1242static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1243 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001244 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001245 bool debug_print)
1246{
1247 int res;
1248 bool wpa, check_ssid, osen, rsn_osen = false;
1249 struct wpa_ie_data data;
1250#ifdef CONFIG_MBO
1251 const u8 *assoc_disallow;
1252#endif /* CONFIG_MBO */
1253#ifdef CONFIG_SAE
1254 u8 rsnxe_capa = 0;
1255#endif /* CONFIG_SAE */
1256 const u8 *ie;
1257
1258 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1259 wpa = ie && ie[1];
1260 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1261 wpa |= ie && ie[1];
1262 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1263 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1264 rsn_osen = true;
1265 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1266 osen = ie != NULL;
1267
1268#ifdef CONFIG_SAE
1269 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1270 if (ie && ie[1] >= 1)
1271 rsnxe_capa = ie[2];
1272#endif /* CONFIG_SAE */
1273
1274 check_ssid = wpa || ssid->ssid_len > 0;
1275
1276 if (wpas_network_disabled(wpa_s, ssid)) {
1277 if (debug_print)
1278 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1279 return false;
1280 }
1281
1282 res = wpas_temp_disabled(wpa_s, ssid);
1283 if (res > 0) {
1284 if (debug_print)
1285 wpa_dbg(wpa_s, MSG_DEBUG,
1286 " skip - disabled temporarily for %d second(s)",
1287 res);
1288 return false;
1289 }
1290
1291#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001292 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001293 if (debug_print)
1294 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001295 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001296 return false;
1297 }
1298
1299 if (wpa && ssid->ssid_len == 0 &&
1300 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1301 check_ssid = false;
1302
1303 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1304 /* Only allow wildcard SSID match if an AP advertises active
1305 * WPS operation that matches our mode. */
1306 check_ssid = ssid->ssid_len > 0 ||
1307 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1308 }
1309#endif /* CONFIG_WPS */
1310
1311 if (ssid->bssid_set && ssid->ssid_len == 0 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001312 ether_addr_equal(bss->bssid, ssid->bssid))
Hai Shalom899fcc72020-10-19 14:38:18 -07001313 check_ssid = false;
1314
1315 if (check_ssid &&
1316 (match_ssid_len != ssid->ssid_len ||
1317 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1318 if (debug_print)
1319 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1320 return false;
1321 }
1322
1323 if (ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001324 !ether_addr_equal(bss->bssid, ssid->bssid)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001325 if (debug_print)
1326 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1327 return false;
1328 }
1329
Hai Shalom60840252021-02-19 19:02:11 -08001330 /* check the list of BSSIDs to ignore */
1331 if (ssid->num_bssid_ignore &&
1332 addr_in_list(bss->bssid, ssid->bssid_ignore,
1333 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001334 if (debug_print)
1335 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001336 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001337 return false;
1338 }
1339
Hai Shalom60840252021-02-19 19:02:11 -08001340 /* if there is a list of accepted BSSIDs, only accept those APs */
1341 if (ssid->num_bssid_accept &&
1342 !addr_in_list(bss->bssid, ssid->bssid_accept,
1343 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001344 if (debug_print)
1345 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001346 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001347 return false;
1348 }
1349
1350 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1351 return false;
1352
1353 if (!osen && !wpa &&
1354 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1355 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1356 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1357 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1358 if (debug_print)
1359 wpa_dbg(wpa_s, MSG_DEBUG,
1360 " skip - non-WPA network not allowed");
1361 return false;
1362 }
1363
1364#ifdef CONFIG_WEP
1365 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1366 if (debug_print)
1367 wpa_dbg(wpa_s, MSG_DEBUG,
1368 " skip - ignore WPA/WPA2 AP for WEP network block");
1369 return false;
1370 }
1371#endif /* CONFIG_WEP */
1372
1373 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1374 if (debug_print)
1375 wpa_dbg(wpa_s, MSG_DEBUG,
1376 " skip - non-OSEN network not allowed");
1377 return false;
1378 }
1379
1380 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1381 if (debug_print)
1382 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1383 return false;
1384 }
1385
1386 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1387 !bss_is_pbss(bss)) {
1388 if (debug_print)
1389 wpa_dbg(wpa_s, MSG_DEBUG,
1390 " skip - not ESS, PBSS, or MBSS");
1391 return false;
1392 }
1393
1394 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1395 if (debug_print)
1396 wpa_dbg(wpa_s, MSG_DEBUG,
1397 " skip - PBSS mismatch (ssid %d bss %d)",
1398 ssid->pbss, bss_is_pbss(bss));
1399 return false;
1400 }
1401
1402 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1403 if (debug_print)
1404 wpa_dbg(wpa_s, MSG_DEBUG,
1405 " skip - frequency not allowed");
1406 return false;
1407 }
1408
1409#ifdef CONFIG_MESH
1410 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1411 ssid->frequency != bss->freq) {
1412 if (debug_print)
1413 wpa_dbg(wpa_s, MSG_DEBUG,
1414 " skip - frequency not allowed (mesh)");
1415 return false;
1416 }
1417#endif /* CONFIG_MESH */
1418
1419 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1420 if (debug_print)
1421 wpa_dbg(wpa_s, MSG_DEBUG,
1422 " skip - rate sets do not match");
1423 return false;
1424 }
1425
1426#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001427 /* When using SAE Password Identifier and when operationg on the 6 GHz
1428 * band, only H2E is allowed. */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001429 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1430 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1431 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1432 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001433#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301434 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001435#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001436 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1437 if (debug_print)
1438 wpa_dbg(wpa_s, MSG_DEBUG,
1439 " skip - SAE H2E required, but not supported by the AP");
1440 return false;
1441 }
1442#endif /* CONFIG_SAE */
1443
1444#ifdef CONFIG_SAE_PK
1445 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1446 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1447 if (debug_print)
1448 wpa_dbg(wpa_s, MSG_DEBUG,
1449 " skip - SAE-PK required, but not supported by the AP");
1450 return false;
1451 }
1452#endif /* CONFIG_SAE_PK */
1453
1454#ifndef CONFIG_IBSS_RSN
1455 if (ssid->mode == WPAS_MODE_IBSS &&
1456 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1457 if (debug_print)
1458 wpa_dbg(wpa_s, MSG_DEBUG,
1459 " skip - IBSS RSN not supported in the build");
1460 return false;
1461 }
1462#endif /* !CONFIG_IBSS_RSN */
1463
1464#ifdef CONFIG_P2P
1465 if (ssid->p2p_group &&
1466 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1467 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1468 if (debug_print)
1469 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1470 return false;
1471 }
1472
1473 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1474 struct wpabuf *p2p_ie;
1475 u8 dev_addr[ETH_ALEN];
1476
1477 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1478 if (!ie) {
1479 if (debug_print)
1480 wpa_dbg(wpa_s, MSG_DEBUG,
1481 " skip - no P2P element");
1482 return false;
1483 }
1484 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1485 if (!p2p_ie) {
1486 if (debug_print)
1487 wpa_dbg(wpa_s, MSG_DEBUG,
1488 " skip - could not fetch P2P element");
1489 return false;
1490 }
1491
1492 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001493 !ether_addr_equal(dev_addr, ssid->go_p2p_dev_addr)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001494 if (debug_print)
1495 wpa_dbg(wpa_s, MSG_DEBUG,
1496 " skip - no matching GO P2P Device Address in P2P element");
1497 wpabuf_free(p2p_ie);
1498 return false;
1499 }
1500 wpabuf_free(p2p_ie);
1501 }
1502
1503 /*
1504 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1505 * P2P Group Capability Bitmap and we are not in Group Formation with
1506 * that device.
1507 */
1508#endif /* CONFIG_P2P */
1509
1510 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1511 struct os_reltime diff;
1512
1513 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1514 if (debug_print)
1515 wpa_dbg(wpa_s, MSG_DEBUG,
1516 " skip - scan result not recent enough (%u.%06u seconds too old)",
1517 (unsigned int) diff.sec,
1518 (unsigned int) diff.usec);
1519 return false;
1520 }
1521#ifdef CONFIG_MBO
1522#ifdef CONFIG_TESTING_OPTIONS
1523 if (wpa_s->ignore_assoc_disallow)
1524 goto skip_assoc_disallow;
1525#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001526 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001527 if (assoc_disallow && assoc_disallow[1] >= 1) {
1528 if (debug_print)
1529 wpa_dbg(wpa_s, MSG_DEBUG,
1530 " skip - MBO association disallowed (reason %u)",
1531 assoc_disallow[2]);
1532 return false;
1533 }
1534
1535 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1536 if (debug_print)
1537 wpa_dbg(wpa_s, MSG_DEBUG,
1538 " skip - AP temporarily disallowed");
1539 return false;
1540 }
1541#ifdef CONFIG_TESTING_OPTIONS
1542skip_assoc_disallow:
1543#endif /* CONFIG_TESTING_OPTIONS */
1544#endif /* CONFIG_MBO */
1545
1546#ifdef CONFIG_DPP
1547 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001548 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1549 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001550 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1551 !ssid->dpp_csign)) {
1552 if (debug_print)
1553 wpa_dbg(wpa_s, MSG_DEBUG,
1554 " skip - no PMKSA entry for DPP");
1555 return false;
1556 }
1557#endif /* CONFIG_DPP */
1558
1559#ifdef CONFIG_SAE_PK
1560 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1561 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1562 ((ssid->sae_password &&
1563 sae_pk_valid_password(ssid->sae_password)) ||
1564 (!ssid->sae_password && ssid->passphrase &&
1565 sae_pk_valid_password(ssid->passphrase))) &&
1566 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1567 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1568 match_ssid_len)) {
1569 if (debug_print)
1570 wpa_dbg(wpa_s, MSG_DEBUG,
1571 " skip - another acceptable BSS with SAE-PK in the same ESS");
1572 return false;
1573 }
1574#endif /* CONFIG_SAE_PK */
1575
1576 if (bss->ssid_len == 0) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001577#ifdef CONFIG_OWE
1578 const u8 *owe_ssid = NULL;
1579 size_t owe_ssid_len = 0;
1580
1581 owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len);
1582 if (owe_ssid && owe_ssid_len &&
1583 owe_ssid_len == ssid->ssid_len &&
1584 os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) {
1585 if (debug_print)
1586 wpa_dbg(wpa_s, MSG_DEBUG,
1587 " skip - no SSID in BSS entry for a possible OWE transition mode BSS");
1588 int_array_add_unique(&wpa_s->owe_trans_scan_freq,
1589 bss->freq);
1590 return false;
1591 }
1592#endif /* CONFIG_OWE */
Hai Shalom899fcc72020-10-19 14:38:18 -07001593 if (debug_print)
1594 wpa_dbg(wpa_s, MSG_DEBUG,
1595 " skip - no SSID known for the BSS");
1596 return false;
1597 }
1598
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001599 if (!wpas_valid_ml_bss(wpa_s, bss)) {
1600 if (debug_print)
1601 wpa_dbg(wpa_s, MSG_DEBUG,
1602 " skip - ML BSS going to be removed");
1603 return false;
1604 }
1605
Hai Shalom899fcc72020-10-19 14:38:18 -07001606 /* Matching configuration found */
1607 return true;
1608}
1609
1610
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001611struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1612 int i, struct wpa_bss *bss,
1613 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001614 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001615{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001616 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001617 const u8 *ie;
1618 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001619 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001620 const u8 *match_ssid;
1621 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001622 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001624 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001625 wpa_ie_len = ie ? ie[1] : 0;
1626
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001627 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001628 rsn_ie_len = ie ? ie[1] : 0;
1629
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001630 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1631 osen = ie != NULL;
1632
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001633 if (debug_print) {
1634 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1635 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1636 i, MAC2STR(bss->bssid),
1637 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1638 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1639 bss->freq,
1640 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1641 " wps" : "",
1642 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1643 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1644 ? " p2p" : "",
1645 osen ? " osen=1" : "");
1646 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647
Hai Shalom60840252021-02-19 19:02:11 -08001648 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1649 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001650 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001651 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001652 /*
1653 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001654 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655 * should not be done with multiple enabled networks to
1656 * avoid getting forced to move into a worse ESS on
1657 * single error if there are no other BSSes of the
1658 * current ESS.
1659 */
1660 limit = 0;
1661 }
Hai Shalom60840252021-02-19 19:02:11 -08001662 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001663 if (debug_print) {
1664 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001665 " skip - BSSID ignored (count=%d limit=%d)",
1666 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001667 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001668 return NULL;
1669 }
1670 }
1671
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001672 match_ssid = bss->ssid;
1673 match_ssid_len = bss->ssid_len;
1674 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1675
1676 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001677 if (debug_print)
1678 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679 return NULL;
1680 }
1681
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001682 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001683 if (debug_print)
1684 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001685 return NULL;
1686 }
1687
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001688 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001689 if (debug_print)
1690 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001691 return NULL;
1692 }
1693
Hai Shalomfdcde762020-04-02 11:19:20 -07001694 if (disabled_freq(wpa_s, bss->freq)) {
1695 if (debug_print)
1696 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1697 return NULL;
1698 }
1699
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001700#ifdef CONFIG_WNM
1701 if (wnm_is_bss_excluded(wpa_s, bss)) {
1702 if (debug_print)
1703 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID excluded");
1704 return NULL;
1705 }
1706#endif /* CONFIG_WNM */
1707
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001708 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001709 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001710 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001711 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001712 }
1713
1714 /* No matching configuration found */
1715 return NULL;
1716}
1717
1718
1719static struct wpa_bss *
1720wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001721 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001722 struct wpa_ssid **selected_ssid,
1723 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001724{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001725 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001726
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001727 if (wpa_s->current_ssid) {
1728 struct wpa_ssid *ssid;
1729
1730 wpa_dbg(wpa_s, MSG_DEBUG,
1731 "Scan results matching the currently selected network");
1732 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1733 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1734
1735 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1736 only_first_ssid, 0);
1737 if (ssid != wpa_s->current_ssid)
1738 continue;
1739 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1740 " freq=%d level=%d snr=%d est_throughput=%u",
1741 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1742 bss->snr, bss->est_throughput);
1743 }
1744 }
1745
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001746 if (only_first_ssid)
1747 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1748 group->id);
1749 else
1750 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1751 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001752
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001753 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1754 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001755
1756 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001757 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001758 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001759 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001760 if (!*selected_ssid)
1761 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001762 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001764 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001765 MAC2STR(bss->bssid),
1766 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1767 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001768 }
1769
1770 return NULL;
1771}
1772
1773
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001774struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1775 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001776{
1777 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001778 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001779 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001780 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001781
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001782 if (wpa_s->last_scan_res == NULL ||
1783 wpa_s->last_scan_res_used == 0)
1784 return NULL; /* no scan results from last update */
1785
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001786 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001787 /* check that next_ssid is still valid */
1788 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1789 if (ssid == wpa_s->next_ssid)
1790 break;
1791 }
1792 next_ssid = ssid;
1793 wpa_s->next_ssid = NULL;
1794 }
1795
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001796 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001797 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1798 if (next_ssid && next_ssid->priority ==
1799 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001800 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001801 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001802 if (selected)
1803 break;
1804 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001806 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001807 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001808 if (selected)
1809 break;
1810 }
1811
Sunil Ravi88611412024-06-28 17:34:56 +00001812 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001813 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001814 wpa_dbg(wpa_s, MSG_DEBUG,
1815 "No APs found - clear BSSID ignore list and try again");
1816 wpa_bssid_ignore_clear(wpa_s);
1817 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001818 } else if (selected == NULL)
1819 break;
1820 }
1821
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001822 ssid = *selected_ssid;
1823 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1824 !ssid->passphrase && !ssid->ext_psk) {
1825 const char *field_name, *txt = NULL;
1826
1827 wpa_dbg(wpa_s, MSG_DEBUG,
1828 "PSK/passphrase not yet available for the selected network");
1829
1830 wpas_notify_network_request(wpa_s, ssid,
1831 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1832
1833 field_name = wpa_supplicant_ctrl_req_to_string(
1834 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1835 if (field_name == NULL)
1836 return NULL;
1837
1838 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1839
1840 selected = NULL;
1841 }
1842
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001843 return selected;
1844}
1845
1846
1847static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1848 int timeout_sec, int timeout_usec)
1849{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001850 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001851 /*
1852 * No networks are enabled; short-circuit request so
1853 * we don't wait timeout seconds before transitioning
1854 * to INACTIVE state.
1855 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001856 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1857 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1859 return;
1860 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001861
1862 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001863 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1864}
1865
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001866
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001867static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s)
1868{
1869 if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss)
1870 return false;
1871
1872 wpa_msg(wpa_s, MSG_DEBUG,
1873 "Request association with " MACSTR " after ML probe",
1874 MAC2STR(wpa_s->ml_connect_probe_bss->bssid));
1875
1876 wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss,
1877 wpa_s->ml_connect_probe_ssid);
1878
1879 wpa_s->ml_connect_probe_ssid = NULL;
1880 wpa_s->ml_connect_probe_bss = NULL;
1881
1882 return true;
1883}
1884
1885
1886static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s,
1887 struct wpa_bss *selected,
1888 struct wpa_ssid *ssid)
1889{
1890 int *freqs;
1891 u16 missing_links = 0, removed_links;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001892 u8 ap_mld_id;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001893
1894 if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
1895 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)))
1896 return 0;
1897
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001898 if (wpa_bss_parse_basic_ml_element(wpa_s, selected, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001899 &missing_links, ssid,
1900 &ap_mld_id) ||
1901 !missing_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001902 return 0;
1903
1904 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected);
1905 missing_links &= ~removed_links;
1906
1907 if (!missing_links)
1908 return 0;
1909
1910 wpa_dbg(wpa_s, MSG_DEBUG,
1911 "MLD: Doing an ML probe for missing links 0x%04x",
1912 missing_links);
1913
1914 freqs = os_malloc(sizeof(int) * 2);
1915 if (!freqs)
1916 return 0;
1917
1918 wpa_s->ml_connect_probe_ssid = ssid;
1919 wpa_s->ml_connect_probe_bss = selected;
1920
1921 freqs[0] = selected->freq;
1922 freqs[1] = 0;
1923
1924 wpa_s->manual_scan_passive = 0;
1925 wpa_s->manual_scan_use_id = 0;
1926 wpa_s->manual_scan_only_new = 0;
1927 wpa_s->scan_id_count = 0;
1928 os_free(wpa_s->manual_scan_freqs);
1929 wpa_s->manual_scan_freqs = freqs;
1930
1931 os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001932
1933 /*
1934 * In case the ML probe request is intended to retrieve information from
1935 * the transmitted BSS, the AP MLD ID should be included and should be
1936 * set to zero.
1937 * In case the ML probe requested is intended to retrieve information
1938 * from a non-transmitted BSS, the AP MLD ID should not be included.
1939 */
1940 if (ap_mld_id)
1941 wpa_s->ml_probe_mld_id = -1;
1942 else
1943 wpa_s->ml_probe_mld_id = 0;
1944
1945 if (ssid && ssid->ssid_len) {
1946 os_free(wpa_s->ssids_from_scan_req);
1947 wpa_s->num_ssids_from_scan_req = 0;
1948
1949 wpa_s->ssids_from_scan_req =
1950 os_zalloc(sizeof(struct wpa_ssid_value));
1951 if (wpa_s->ssids_from_scan_req) {
1952 wpa_printf(MSG_DEBUG,
1953 "MLD: ML probe: With direct SSID");
1954
1955 wpa_s->num_ssids_from_scan_req = 1;
1956 wpa_s->ssids_from_scan_req[0].ssid_len = ssid->ssid_len;
1957 os_memcpy(wpa_s->ssids_from_scan_req[0].ssid,
1958 ssid->ssid, ssid->ssid_len);
1959 }
1960 }
1961
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001962 wpa_s->ml_probe_links = missing_links;
1963
1964 wpa_s->normal_scans = 0;
1965 wpa_s->scan_req = MANUAL_SCAN_REQ;
1966 wpa_s->after_wps = 0;
1967 wpa_s->known_wps_freq = 0;
1968 wpa_supplicant_req_scan(wpa_s, 0, 0);
1969
1970 return 1;
1971}
1972
1973
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001974int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001975 struct wpa_bss *selected,
1976 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001977{
Sunil Ravi640215c2023-06-28 23:08:09 +00001978#ifdef IEEE8021X_EAPOL
Sunil Ravi036cec52023-03-29 11:35:17 -07001979 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
1980 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00001981 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001982 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1983 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001984 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001985 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001986#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001987 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1988 wpa_s->p2p_in_provisioning) {
1989 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1990 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001991 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001992 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001993#endif /* CONFIG_P2P */
1994
1995#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001996 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001997 wpas_wps_cancel(wpa_s);
1998#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001999 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002000 }
Sunil Ravi640215c2023-06-28 23:08:09 +00002001#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002002
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002003 wpa_msg(wpa_s, MSG_DEBUG,
2004 "Considering connect request: reassociate: %d selected: "
2005 MACSTR " bssid: " MACSTR " pending: " MACSTR
2006 " wpa_state: %s ssid=%p current_ssid=%p",
2007 wpa_s->reassociate, MAC2STR(selected->bssid),
2008 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
2009 wpa_supplicant_state_txt(wpa_s->wpa_state),
2010 ssid, wpa_s->current_ssid);
2011
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002012 /*
2013 * Do not trigger new association unless the BSSID has changed or if
2014 * reassociation is requested. If we are in process of associating with
2015 * the selected BSSID, do not trigger new attempt.
2016 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002017 if (wpa_s->reassociate ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002018 (!ether_addr_equal(selected->bssid, wpa_s->bssid) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002019 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
2020 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002021 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002022 !ether_addr_equal(selected->bssid, wpa_s->pending_bssid)) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002023 (is_zero_ether_addr(wpa_s->pending_bssid) &&
2024 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
2026 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002027 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002028 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002029
2030 if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid))
2031 return 0;
2032
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002033 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
2034 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002035 wpa_supplicant_associate(wpa_s, selected, ssid);
2036 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002037 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
2038 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002039 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002040
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002041 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002042}
2043
2044
2045static struct wpa_ssid *
2046wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
2047{
Hai Shalomfdcde762020-04-02 11:19:20 -07002048 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002049 struct wpa_ssid *ssid;
2050
2051 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
2052 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
2053 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002054 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002055 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002056#ifndef CONFIG_IBSS_RSN
2057 if (ssid->mode == WPAS_MODE_IBSS &&
2058 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
2059 WPA_KEY_MGMT_WPA_NONE))) {
2060 wpa_msg(wpa_s, MSG_INFO,
2061 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
2062 wpa_ssid_txt(ssid->ssid,
2063 ssid->ssid_len));
2064 continue;
2065 }
2066#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07002067 if (ssid->mode == WPAS_MODE_IBSS ||
2068 ssid->mode == WPAS_MODE_AP ||
2069 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002070 return ssid;
2071 }
2072 }
2073 return NULL;
2074}
2075
2076
2077/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
2078 * on BSS added and BSS changed events */
2079static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03002080 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002081{
Jouni Malinen87fd2792011-05-16 18:35:42 +03002082 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002083
2084 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
2085 return;
2086
Jouni Malinen87fd2792011-05-16 18:35:42 +03002087 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002089
Jouni Malinen87fd2792011-05-16 18:35:42 +03002090 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002091 if (ssid == NULL)
2092 continue;
2093
Jouni Malinen87fd2792011-05-16 18:35:42 +03002094 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002095 if (rsn == NULL)
2096 continue;
2097
Jouni Malinen87fd2792011-05-16 18:35:42 +03002098 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002099 }
2100
2101}
2102
2103
Hai Shalomfdcde762020-04-02 11:19:20 -07002104#ifndef CONFIG_NO_ROAMING
2105
2106static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
2107{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002108 if (noise == WPA_INVALID_NOISE) {
2109 if (IS_5GHZ(frequency)) {
2110 noise = DEFAULT_NOISE_FLOOR_5GHZ;
2111 } else if (is_6ghz_freq(frequency)) {
2112 noise = DEFAULT_NOISE_FLOOR_6GHZ;
2113 } else {
2114 noise = DEFAULT_NOISE_FLOOR_2GHZ;
2115 }
2116 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002117 return avg_signal - noise;
2118}
2119
2120
2121static unsigned int
2122wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
2123 const struct wpa_bss *bss, int snr)
2124{
2125 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08002126 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07002127 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002128 enum chan_width max_cw = CHAN_WIDTH_UNKNOWN;
Hai Shalomfdcde762020-04-02 11:19:20 -07002129
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002130 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq,
2131 &max_cw);
Hai Shalomfdcde762020-04-02 11:19:20 -07002132}
2133
Hai Shalomfdcde762020-04-02 11:19:20 -07002134
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002135static int wpas_evaluate_band_score(int frequency)
2136{
2137 if (is_6ghz_freq(frequency))
2138 return 2;
2139 if (IS_5GHZ(frequency))
2140 return 1;
2141 return 0;
2142}
2143
2144
Hai Shalom899fcc72020-10-19 14:38:18 -07002145int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
2146 struct wpa_bss *current_bss,
2147 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002148{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002149 int min_diff, diff;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002150 int cur_band_score, sel_band_score;
Sunil Ravi036cec52023-03-29 11:35:17 -07002151 int to_5ghz, to_6ghz;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002152 int cur_level, sel_level;
Hai Shalomfdcde762020-04-02 11:19:20 -07002153 unsigned int cur_est, sel_est;
2154 struct wpa_signal_info si;
2155 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07002156 int ret = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002157 const u8 *cur_ies = wpa_bss_ie_ptr(current_bss);
2158 const u8 *sel_ies = wpa_bss_ie_ptr(selected);
2159 size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len :
2160 current_bss->beacon_ie_len;
2161 size_t sel_ie_len = selected->ie_len ? selected->ie_len :
2162 selected->beacon_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002163
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002165 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002166 " freq=%d level=%d snr=%d est_throughput=%u",
2167 MAC2STR(current_bss->bssid),
2168 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002169 current_bss->snr, current_bss->est_throughput);
2170 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002171 " freq=%d level=%d snr=%d est_throughput=%u",
2172 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002173 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002174
2175 if (wpa_s->current_ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002176 ether_addr_equal(selected->bssid, wpa_s->current_ssid->bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002177 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2178 "has preferred BSSID");
2179 return 1;
2180 }
2181
Hai Shalomfdcde762020-04-02 11:19:20 -07002182 /*
2183 * Try to poll the signal from the driver since this will allow to get
2184 * more accurate values. In some cases, there can be big differences
2185 * between the RSSI of the Probe Response frames of the AP we are
2186 * associated with and the Beacon frames we hear from the same AP after
2187 * association. This can happen, e.g., when there are two antennas that
2188 * hear the AP very differently. If the driver chooses to hear the
2189 * Probe Response frames during the scan on the "bad" antenna because
2190 * it wants to save power, but knows to choose the other antenna after
2191 * association, we will hear our AP with a low RSSI as part of the
2192 * scan even when we can hear it decently on the other antenna. To cope
2193 * with this, ask the driver to teach us how it hears the AP. Also, the
2194 * scan results may be a bit old, since we can very quickly get fresh
2195 * information about our currently associated AP.
2196 */
2197 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002198 (si.data.avg_beacon_signal || si.data.avg_signal)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002199 /*
2200 * Normalize avg_signal to the RSSI over 20 MHz, as the
2201 * throughput is estimated based on the RSSI over 20 MHz
2202 */
Sunil Ravi77d572f2023-01-17 23:58:31 +00002203 cur_level = si.data.avg_beacon_signal ?
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002204 si.data.avg_beacon_signal :
2205 (si.data.avg_signal -
2206 wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2207 si.chanwidth));
Hai Shalomfdcde762020-04-02 11:19:20 -07002208 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2209 si.current_noise);
2210
2211 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2212 current_bss,
2213 cur_snr);
2214 wpa_dbg(wpa_s, MSG_DEBUG,
2215 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2216 cur_level, cur_snr, cur_est);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002217 } else {
2218 /* Level and SNR are measured over 20 MHz channel */
2219 cur_level = current_bss->level;
2220 cur_snr = current_bss->snr;
2221 cur_est = current_bss->est_throughput;
Hai Shalomfdcde762020-04-02 11:19:20 -07002222 }
2223
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002224 /* Adjust the SNR of BSSes based on the channel width. */
2225 cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2226 current_bss->max_cw);
2227 cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len,
2228 current_bss->max_cw, cur_snr);
2229
2230 sel_est = selected->est_throughput;
2231 sel_level = selected->level +
2232 wpas_channel_width_rssi_bump(sel_ies, sel_ie_len,
2233 selected->max_cw);
2234
Hai Shalomfdcde762020-04-02 11:19:20 -07002235 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002236 wpa_dbg(wpa_s, MSG_DEBUG,
2237 "Allow reassociation - selected BSS has better estimated throughput");
2238 return 1;
2239 }
2240
Dmitry Shmidte4663042016-04-04 10:07:49 -07002241 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
Sunil Ravi036cec52023-03-29 11:35:17 -07002242 to_6ghz = is_6ghz_freq(selected->freq) &&
2243 !is_6ghz_freq(current_bss->freq);
Dmitry Shmidte4663042016-04-04 10:07:49 -07002244
Sunil Ravi036cec52023-03-29 11:35:17 -07002245 if (cur_level < 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002246 cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002247 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002248 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2249 "signal level");
2250 return 0;
2251 }
2252
Hai Shalomfdcde762020-04-02 11:19:20 -07002253 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002254 wpa_dbg(wpa_s, MSG_DEBUG,
2255 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002256 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002257 }
2258
Hai Shalomfdcde762020-04-02 11:19:20 -07002259 if (cur_snr > GREAT_SNR) {
2260 wpa_dbg(wpa_s, MSG_DEBUG,
2261 "Skip roam - Current BSS has good SNR (%u > %u)",
2262 cur_snr, GREAT_SNR);
2263 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002264 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002265
Hai Shalomfdcde762020-04-02 11:19:20 -07002266 if (cur_level < -85) /* ..-86 dBm */
2267 min_diff = 1;
2268 else if (cur_level < -80) /* -85..-81 dBm */
2269 min_diff = 2;
2270 else if (cur_level < -75) /* -80..-76 dBm */
2271 min_diff = 3;
2272 else if (cur_level < -70) /* -75..-71 dBm */
2273 min_diff = 4;
2274 else if (cur_level < 0) /* -70..-1 dBm */
2275 min_diff = 5;
2276 else /* unspecified units (not in dBm) */
2277 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002278
Hai Shalomfdcde762020-04-02 11:19:20 -07002279 if (cur_est > sel_est * 1.5)
2280 min_diff += 10;
2281 else if (cur_est > sel_est * 1.2)
2282 min_diff += 5;
2283 else if (cur_est > sel_est * 1.1)
2284 min_diff += 2;
2285 else if (cur_est > sel_est)
2286 min_diff++;
2287 else if (sel_est > cur_est * 1.5)
2288 min_diff -= 10;
2289 else if (sel_est > cur_est * 1.2)
2290 min_diff -= 5;
2291 else if (sel_est > cur_est * 1.1)
2292 min_diff -= 2;
2293 else if (sel_est > cur_est)
2294 min_diff--;
2295
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002296 cur_band_score = wpas_evaluate_band_score(current_bss->freq);
2297 sel_band_score = wpas_evaluate_band_score(selected->freq);
2298 min_diff += (cur_band_score - sel_band_score) * 2;
2299 if (wpa_s->signal_threshold && cur_level <= wpa_s->signal_threshold &&
2300 sel_level > wpa_s->signal_threshold)
Sunil Ravi036cec52023-03-29 11:35:17 -07002301 min_diff -= 2;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002302 diff = sel_level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002303 if (diff < min_diff) {
2304 wpa_dbg(wpa_s, MSG_DEBUG,
2305 "Skip roam - too small difference in signal level (%d < %d)",
2306 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002307 ret = 0;
2308 } else {
2309 wpa_dbg(wpa_s, MSG_DEBUG,
2310 "Allow reassociation due to difference in signal level (%d >= %d)",
2311 diff, min_diff);
2312 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002313 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002314 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2315 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2316 " sel_freq=%d sel_level=%d sel_est=%d",
2317 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2318 MAC2STR(current_bss->bssid),
2319 current_bss->freq, cur_level, cur_est,
2320 MAC2STR(selected->bssid),
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002321 selected->freq, sel_level, sel_est);
Hai Shalom899fcc72020-10-19 14:38:18 -07002322 return ret;
2323}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002324
Hai Shalom899fcc72020-10-19 14:38:18 -07002325#endif /* CONFIG_NO_ROAMING */
2326
2327
2328static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2329 struct wpa_bss *selected,
2330 struct wpa_ssid *ssid)
2331{
2332 struct wpa_bss *current_bss = NULL;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002333 const u8 *bssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07002334
2335 if (wpa_s->reassociate)
2336 return 1; /* explicit request to reassociate */
2337 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2338 return 1; /* we are not associated; continue */
2339 if (wpa_s->current_ssid == NULL)
2340 return 1; /* unknown current SSID */
2341 if (wpa_s->current_ssid != ssid)
2342 return 1; /* different network block */
2343
2344 if (wpas_driver_bss_selection(wpa_s))
2345 return 0; /* Driver-based roaming */
2346
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002347 if (wpa_s->valid_links)
2348 bssid = wpa_s->links[wpa_s->mlo_assoc_link_id].bssid;
2349 else
2350 bssid = wpa_s->bssid;
2351
Hai Shalom899fcc72020-10-19 14:38:18 -07002352 if (wpa_s->current_ssid->ssid)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002353 current_bss = wpa_bss_get(wpa_s, bssid,
Hai Shalom899fcc72020-10-19 14:38:18 -07002354 wpa_s->current_ssid->ssid,
2355 wpa_s->current_ssid->ssid_len);
2356 if (!current_bss)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002357 current_bss = wpa_bss_get_bssid(wpa_s, bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07002358
2359 if (!current_bss)
2360 return 1; /* current BSS not seen in scan results */
2361
2362 if (current_bss == selected)
2363 return 0;
2364
2365 if (selected->last_update_idx > current_bss->last_update_idx)
2366 return 1; /* current BSS not seen in the last scan */
2367
2368#ifndef CONFIG_NO_ROAMING
2369 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2370 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002371#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002372 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002373#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002374}
2375
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002376
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002377/*
2378 * Return a negative value if no scan results could be fetched or if scan
2379 * results should not be shared with other virtual interfaces.
2380 * Return 0 if scan results were fetched and may be shared with other
2381 * interfaces.
2382 * Return 1 if scan results may be shared with other virtual interfaces but may
2383 * not trigger any operations.
2384 * Return 2 if the interface was removed and cannot be used.
2385 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002386static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002387 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002388 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002389{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002390 struct wpa_scan_results *scan_res = NULL;
2391 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002392 int ap = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002393 bool trigger_6ghz_scan;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002394#ifndef CONFIG_NO_RANDOM_POOL
2395 size_t i, num;
2396#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002397
2398#ifdef CONFIG_AP
2399 if (wpa_s->ap_iface)
2400 ap = 1;
2401#endif /* CONFIG_AP */
2402
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002403 trigger_6ghz_scan = wpa_s->crossed_6ghz_dom &&
2404 wpa_s->last_scan_all_chan;
2405 wpa_s->crossed_6ghz_dom = false;
2406 wpa_s->last_scan_all_chan = false;
2407
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002408 wpa_supplicant_notify_scanning(wpa_s, 0);
2409
2410 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2411 data ? &data->scan_info :
Sunil Ravi88611412024-06-28 17:34:56 +00002412 NULL, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002413 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002414 if (wpa_s->conf->ap_scan == 2 || ap ||
2415 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002416 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002417 if (!own_request)
2418 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002419 if (data && data->scan_info.external_scan)
2420 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002421 if (wpa_s->scan_res_fail_handler) {
2422 void (*handler)(struct wpa_supplicant *wpa_s);
2423
2424 handler = wpa_s->scan_res_fail_handler;
2425 wpa_s->scan_res_fail_handler = NULL;
2426 handler(wpa_s);
2427 } else {
2428 wpa_dbg(wpa_s, MSG_DEBUG,
2429 "Failed to get scan results - try scanning again");
2430 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2431 }
2432
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002433 ret = -1;
2434 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002435 }
2436
2437#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002438 num = scan_res->num;
2439 if (num > 10)
2440 num = 10;
2441 for (i = 0; i < num; i++) {
2442 u8 buf[5];
2443 struct wpa_scan_res *res = scan_res->res[i];
2444 buf[0] = res->bssid[5];
2445 buf[1] = res->qual & 0xff;
2446 buf[2] = res->noise & 0xff;
2447 buf[3] = res->level & 0xff;
2448 buf[4] = res->tsf & 0xff;
2449 random_add_randomness(buf, sizeof(buf));
2450 }
2451#endif /* CONFIG_NO_RANDOM_POOL */
2452
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002453 if (update_only) {
2454 ret = 1;
2455 goto scan_work_done;
2456 }
2457
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002458 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002459 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002460 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2461 struct wpa_scan_results *scan_res);
2462
2463 scan_res_handler = wpa_s->scan_res_handler;
2464 wpa_s->scan_res_handler = NULL;
2465 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002466 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002467 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002468 }
2469
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002470 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002471 wpa_s->own_scan_running,
2472 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002473 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002474 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2475 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002476 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2477 wpa_s->manual_scan_id);
2478 wpa_s->manual_scan_use_id = 0;
2479 } else {
2480 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2481 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002482 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002483
2484 wpas_notify_scan_done(wpa_s, 1);
2485
Hai Shalomfdcde762020-04-02 11:19:20 -07002486 if (ap) {
2487 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2488#ifdef CONFIG_AP
2489 if (wpa_s->ap_iface->scan_cb)
2490 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2491#endif /* CONFIG_AP */
2492 goto scan_work_done;
2493 }
2494
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002495 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002496 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 -07002497 wpa_scan_results_free(scan_res);
2498 return 0;
2499 }
2500
Sunil Ravi88611412024-06-28 17:34:56 +00002501 if (wnm_scan_process(wpa_s, 1) > 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002502 goto scan_work_done;
2503
Hai Shalomc1a21442022-02-04 13:43:00 -08002504 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002505 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002506
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002507#ifndef CONFIG_NO_RRM
Hai Shalom021b0b52019-04-10 11:17:58 -07002508 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002509 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2510 goto scan_work_done;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002511#endif /* CONFIG_NO_RRM */
Dmitry Shmidt29333592017-01-09 12:27:11 -08002512
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002513 if (ml_link_probe_scan(wpa_s))
2514 goto scan_work_done;
2515
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002516 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2517 goto scan_work_done;
2518
2519 if (autoscan_notify_scan(wpa_s, scan_res))
2520 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002521
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002522 if (wpa_s->disconnected) {
2523 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002524 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002525 }
2526
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002527 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002528 bgscan_notify_scan(wpa_s, scan_res) == 1)
2529 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002530
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002531 wpas_wps_update_ap_info(wpa_s, scan_res);
2532
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002533 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2534 wpa_s->wpa_state < WPA_COMPLETED)
2535 goto scan_work_done;
2536
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002537 wpa_scan_results_free(scan_res);
2538
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002539 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002540 struct wpa_radio_work *work = wpa_s->scan_work;
2541 wpa_s->scan_work = NULL;
2542 radio_work_done(work);
2543 }
2544
Hai Shalomc3565922019-10-28 11:58:20 -07002545 os_free(wpa_s->last_scan_freqs);
2546 wpa_s->last_scan_freqs = NULL;
2547 wpa_s->num_last_scan_freqs = 0;
2548 if (own_request && data &&
2549 data->scan_info.freqs && data->scan_info.num_freqs) {
2550 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2551 data->scan_info.num_freqs);
2552 if (wpa_s->last_scan_freqs) {
2553 os_memcpy(wpa_s->last_scan_freqs,
2554 data->scan_info.freqs,
2555 sizeof(int) * data->scan_info.num_freqs);
2556 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2557 }
2558 }
2559
Sunil Ravi77d572f2023-01-17 23:58:31 +00002560 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2561 return ret;
2562
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002563 return wpas_select_network_from_last_scan(wpa_s, 1, own_request,
2564 trigger_6ghz_scan, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002565
2566scan_work_done:
2567 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002568 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002569 struct wpa_radio_work *work = wpa_s->scan_work;
2570 wpa_s->scan_work = NULL;
2571 radio_work_done(work);
2572 }
2573 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002574}
2575
2576
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002577static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s,
2578 union wpa_event_data *data)
2579{
2580 struct wpa_driver_scan_params params;
2581 unsigned int j;
2582
2583 wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan");
2584 os_memset(&params, 0, sizeof(params));
2585 params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz;
2586 for (j = 0; j < data->scan_info.num_ssids; j++)
2587 params.ssids[j] = data->scan_info.ssids[j];
2588 params.num_ssids = data->scan_info.num_ssids;
2589 wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
2590 true, !wpa_s->last_scan_non_coloc_6ghz, false);
2591 if (!wpa_supplicant_trigger_scan(wpa_s, &params, true, true)) {
2592 os_free(params.freqs);
2593 return 1;
2594 }
2595 wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan");
2596 os_free(params.freqs);
2597 return 0;
2598}
2599
2600
2601/**
2602 * Select a network from the last scan
2603 * @wpa_s: Pointer to wpa_supplicant data
2604 * @new_scan: Whether this function was called right after a scan has finished
2605 * @own_request: Whether the scan was requested by this interface
2606 * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable
2607 * @data: Scan data from scan that finished if applicable
2608 *
2609 * See _wpa_supplicant_event_scan_results() for return values.
2610 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002611static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002612 int new_scan, int own_request,
2613 bool trigger_6ghz_scan,
2614 union wpa_event_data *data)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002615{
2616 struct wpa_bss *selected;
2617 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002618 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2619
2620 if (time_to_reenable > 0) {
2621 wpa_dbg(wpa_s, MSG_DEBUG,
2622 "Postpone network selection by %d seconds since all networks are disabled",
2623 time_to_reenable);
2624 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2625 eloop_register_timeout(time_to_reenable, 0,
2626 wpas_network_reenabled, wpa_s, NULL);
2627 return 0;
2628 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002629
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002630 if (wpa_s->p2p_mgmt)
2631 return 0; /* no normal connection on p2p_mgmt interface */
2632
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002633 wpa_s->owe_transition_search = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002634#ifdef CONFIG_OWE
2635 os_free(wpa_s->owe_trans_scan_freq);
2636 wpa_s->owe_trans_scan_freq = NULL;
2637#endif /* CONFIG_OWE */
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002638 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002639
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002640#ifdef CONFIG_MESH
2641 if (wpa_s->ifmsh) {
2642 wpa_msg(wpa_s, MSG_INFO,
2643 "Avoiding join because we already joined a mesh group");
2644 return 0;
2645 }
2646#endif /* CONFIG_MESH */
2647
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002648 if (selected) {
2649 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002650 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002651 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002652 if (new_scan)
2653 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002654 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002655 }
2656
Hai Shalomc3565922019-10-28 11:58:20 -07002657 wpa_s->suitable_network++;
2658
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002659 if (ssid != wpa_s->current_ssid &&
2660 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2661 wpa_s->own_disconnect_req = 1;
2662 wpa_supplicant_deauthenticate(
2663 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2664 }
2665
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002666 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002667 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002668 return -1;
2669 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002670 wpa_s->supp_pbc_active = false;
2671
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002672 if (new_scan)
2673 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002674 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002675 * Do not allow other virtual radios to trigger operations based
2676 * on these scan results since we do not want them to start
2677 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002678 */
2679 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002680 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002681 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002682 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2683 ssid = wpa_supplicant_pick_new_network(wpa_s);
2684 if (ssid) {
2685 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2686 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002687 if (new_scan)
2688 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002689 } else if (own_request) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002690 if (wpa_s->support_6ghz && trigger_6ghz_scan && data &&
2691 wpas_trigger_6ghz_scan(wpa_s, data) < 0)
2692 return 1;
2693
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002694 /*
2695 * No SSID found. If SCAN results are as a result of
2696 * own scan request and not due to a scan request on
2697 * another shared interface, try another scan.
2698 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699 int timeout_sec = wpa_s->scan_interval;
2700 int timeout_usec = 0;
2701#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002702 int res;
2703
2704 res = wpas_p2p_scan_no_go_seen(wpa_s);
2705 if (res == 2)
2706 return 2;
2707 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002708 return 0;
2709
Sunil Ravi77d572f2023-01-17 23:58:31 +00002710 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002711 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002712
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002713 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002714 wpa_s->show_group_started ||
2715 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002716 /*
2717 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002718 * state and during P2P join-a-group operation
2719 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002720 */
2721 timeout_sec = 0;
2722 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002723 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2724 timeout_usec);
2725 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002726 }
2727#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002728#ifdef CONFIG_INTERWORKING
2729 if (wpa_s->conf->auto_interworking &&
2730 wpa_s->conf->interworking &&
2731 wpa_s->conf->cred) {
2732 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2733 "start ANQP fetch since no matching "
2734 "networks found");
2735 wpa_s->network_select = 1;
2736 wpa_s->auto_network_select = 1;
2737 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002738 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002739 }
2740#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002741#ifdef CONFIG_WPS
2742 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2743 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2744 timeout_sec = 0;
2745 timeout_usec = 500000;
2746 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2747 timeout_usec);
2748 return 0;
2749 }
2750#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002751#ifdef CONFIG_OWE
2752 if (wpa_s->owe_transition_search) {
2753 wpa_dbg(wpa_s, MSG_DEBUG,
2754 "OWE: Use shorter wait during transition mode search");
2755 timeout_sec = 0;
2756 timeout_usec = 500000;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002757 if (wpa_s->owe_trans_scan_freq) {
2758 os_free(wpa_s->next_scan_freqs);
2759 wpa_s->next_scan_freqs =
2760 wpa_s->owe_trans_scan_freq;
2761 wpa_s->owe_trans_scan_freq = NULL;
2762 timeout_usec = 100000;
2763 }
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002764 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2765 timeout_usec);
2766 return 0;
2767 }
2768#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002769 if (wpa_supplicant_req_sched_scan(wpa_s))
2770 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2771 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002772
2773 wpa_msg_ctrl(wpa_s, MSG_INFO,
2774 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002775 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776 }
2777 }
2778 return 0;
2779}
2780
2781
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002782static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2783 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002784{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002785 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002786 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002787
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002788 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002789 if (res == 2) {
2790 /*
2791 * Interface may have been removed, so must not dereference
2792 * wpa_s after this.
2793 */
2794 return 1;
2795 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002796
2797 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002798 /*
2799 * If no scan results could be fetched, then no need to
2800 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002801 * this scan. Similarly, if scan results started a new operation on this
2802 * interface, do not notify other interfaces to avoid concurrent
2803 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002804 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002805 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002806 }
2807
2808 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002809 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002810 * so, they get updated with this same scan info.
2811 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002812 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2813 radio_list) {
2814 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002815 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2816 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002817 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2818 res > 0);
2819 if (res < 0)
2820 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002821 }
2822 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002823
2824 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002825}
2826
2827#endif /* CONFIG_NO_SCAN_PROCESSING */
2828
2829
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002830int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2831{
2832#ifdef CONFIG_NO_SCAN_PROCESSING
2833 return -1;
2834#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002835 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002836
Dmitry Shmidt29333592017-01-09 12:27:11 -08002837 wpa_s->ignore_post_flush_scan_res = 0;
2838
Dmitry Shmidt41712582015-06-29 11:02:15 -07002839 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002840 return -1;
2841
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002842 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002843 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002844 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002845 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2846 return -1;
2847 }
2848
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002849 return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002850#endif /* CONFIG_NO_SCAN_PROCESSING */
2851}
2852
Sunil Ravi77d572f2023-01-17 23:58:31 +00002853
2854int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2855{
2856#ifdef CONFIG_NO_SCAN_PROCESSING
2857 return -1;
2858#else /* CONFIG_NO_SCAN_PROCESSING */
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002859 return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002860#endif /* CONFIG_NO_SCAN_PROCESSING */
2861}
2862
2863
Dmitry Shmidt04949592012-07-19 12:16:46 -07002864#ifdef CONFIG_WNM
2865
2866static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2867{
2868 struct wpa_supplicant *wpa_s = eloop_ctx;
2869
2870 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2871 return;
2872
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002873 if (!wpa_s->no_keep_alive) {
2874 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2875 MAC2STR(wpa_s->bssid));
2876 /* TODO: could skip this if normal data traffic has been sent */
2877 /* TODO: Consider using some more appropriate data frame for
2878 * this */
2879 if (wpa_s->l2)
2880 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2881 (u8 *) "", 0);
2882 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002883
2884#ifdef CONFIG_SME
2885 if (wpa_s->sme.bss_max_idle_period) {
2886 unsigned int msec;
2887 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2888 if (msec > 100)
2889 msec -= 100;
2890 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2891 wnm_bss_keep_alive, wpa_s, NULL);
2892 }
2893#endif /* CONFIG_SME */
2894}
2895
2896
2897static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2898 const u8 *ies, size_t ies_len)
2899{
2900 struct ieee802_11_elems elems;
2901
2902 if (ies == NULL)
2903 return;
2904
2905 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2906 return;
2907
2908#ifdef CONFIG_SME
2909 if (elems.bss_max_idle_period) {
2910 unsigned int msec;
2911 wpa_s->sme.bss_max_idle_period =
2912 WPA_GET_LE16(elems.bss_max_idle_period);
2913 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2914 "TU)%s", wpa_s->sme.bss_max_idle_period,
2915 (elems.bss_max_idle_period[2] & 0x01) ?
2916 " (protected keep-live required)" : "");
2917 if (wpa_s->sme.bss_max_idle_period == 0)
2918 wpa_s->sme.bss_max_idle_period = 1;
2919 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2920 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2921 /* msec times 1000 */
2922 msec = wpa_s->sme.bss_max_idle_period * 1024;
2923 if (msec > 100)
2924 msec -= 100;
2925 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2926 wnm_bss_keep_alive, wpa_s,
2927 NULL);
2928 }
2929 }
2930#endif /* CONFIG_SME */
2931}
2932
2933#endif /* CONFIG_WNM */
2934
2935
2936void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2937{
2938#ifdef CONFIG_WNM
2939 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2940#endif /* CONFIG_WNM */
2941}
2942
2943
Sunil Ravi88611412024-06-28 17:34:56 +00002944#ifdef CONFIG_INTERWORKING
2945
Dmitry Shmidt051af732013-10-22 13:52:46 -07002946static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2947 size_t len)
2948{
2949 int res;
2950
2951 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2952 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2953 if (res) {
2954 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2955 }
2956
2957 return res;
2958}
2959
2960
2961static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2962 const u8 *ies, size_t ies_len)
2963{
2964 struct ieee802_11_elems elems;
2965
2966 if (ies == NULL)
2967 return;
2968
2969 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2970 return;
2971
2972 if (elems.qos_map_set) {
2973 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2974 elems.qos_map_set_len);
2975 }
2976}
2977
Sunil Ravi88611412024-06-28 17:34:56 +00002978#endif /* CONFIG_INTERWORKING */
2979
Dmitry Shmidt051af732013-10-22 13:52:46 -07002980
Sunil Ravi036cec52023-03-29 11:35:17 -07002981static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
2982{
2983 if (wpa_s->enabled_4addr_mode) {
2984 wpa_printf(MSG_DEBUG, "4addr mode already set");
2985 return;
2986 }
2987
2988 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2989 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
2990 goto fail;
2991 }
2992 wpa_s->enabled_4addr_mode = 1;
2993 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
2994 return;
2995
2996fail:
2997 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2998}
2999
3000
Hai Shalom74f70d42019-02-11 14:42:39 -08003001static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
3002 const u8 *ies, size_t ies_len)
3003{
3004 struct ieee802_11_elems elems;
Sunil Ravi88611412024-06-28 17:34:56 +00003005 const u8 *map_sub_elem, *pos;
3006 size_t len;
Hai Shalom74f70d42019-02-11 14:42:39 -08003007
Hai Shalomfdcde762020-04-02 11:19:20 -07003008 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08003009
Hai Shalomfdcde762020-04-02 11:19:20 -07003010 if (!ies ||
3011 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
Sunil Ravi88611412024-06-28 17:34:56 +00003012 !elems.multi_ap || elems.multi_ap_len < 7)
Hai Shalomfdcde762020-04-02 11:19:20 -07003013 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08003014
Sunil Ravi88611412024-06-28 17:34:56 +00003015 pos = elems.multi_ap + 4;
3016 len = elems.multi_ap_len - 4;
3017
3018 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
3019 if (!map_sub_elem || map_sub_elem[1] < 1)
Hai Shalomfdcde762020-04-02 11:19:20 -07003020 return;
3021
Sunil Ravi88611412024-06-28 17:34:56 +00003022 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
3023 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
Hai Shalomfdcde762020-04-02 11:19:20 -07003024 MULTI_AP_FRONTHAUL_BSS);
3025 wpa_s->multi_ap_ie = 1;
3026}
3027
3028
3029static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
3030{
3031 if (!wpa_s->current_ssid ||
3032 !wpa_s->current_ssid->multi_ap_backhaul_sta)
3033 return;
3034
3035 if (!wpa_s->multi_ap_ie) {
3036 wpa_printf(MSG_INFO,
3037 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08003038 goto fail;
3039 }
3040
Hai Shalomfdcde762020-04-02 11:19:20 -07003041 if (!wpa_s->multi_ap_backhaul) {
3042 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07003043 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
3044 wpa_printf(MSG_INFO,
3045 "WPS active, accepting fronthaul-only BSS");
3046 /* Don't set 4addr mode in this case, so just return */
3047 return;
3048 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003049 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
3050 goto fail;
3051 }
3052
Sunil Ravi036cec52023-03-29 11:35:17 -07003053 wpa_supplicant_set_4addr_mode(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08003054 return;
3055
3056fail:
3057 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3058}
3059
3060
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003061#ifdef CONFIG_FST
3062static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
3063 const u8 *ie, size_t ie_len)
3064{
3065 struct mb_ies_info mb_ies;
3066
3067 if (!ie || !ie_len || !wpa_s->fst)
3068 return -ENOENT;
3069
3070 os_memset(&mb_ies, 0, sizeof(mb_ies));
3071
3072 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
3073 size_t len;
3074
3075 len = 2 + ie[1];
3076 if (len > ie_len) {
3077 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
3078 ie, ie_len);
3079 break;
3080 }
3081
3082 if (ie[0] == WLAN_EID_MULTI_BAND) {
3083 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
3084 (unsigned int) len);
3085 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
3086 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
3087 mb_ies.nof_ies++;
3088 }
3089
3090 ie_len -= len;
3091 ie += len;
3092 }
3093
3094 if (mb_ies.nof_ies > 0) {
3095 wpabuf_free(wpa_s->received_mb_ies);
3096 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
3097 return 0;
3098 }
3099
3100 return -ENOENT;
3101}
3102#endif /* CONFIG_FST */
3103
3104
Hai Shalomc1a21442022-02-04 13:43:00 -08003105static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
3106 union wpa_event_data *data)
3107{
3108 int sel;
3109 const u8 *p;
3110 int l, len;
3111 bool found = false;
3112 struct wpa_ie_data ie;
3113 struct wpa_ssid *ssid = wpa_s->current_ssid;
3114 struct wpa_bss *bss = wpa_s->current_bss;
3115 int pmf;
3116
3117 if (!ssid)
3118 return 0;
3119
3120 p = data->assoc_info.req_ies;
3121 l = data->assoc_info.req_ies_len;
3122
3123 while (p && l >= 2) {
3124 len = p[1] + 2;
3125 if (len > l) {
3126 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3127 p, l);
3128 break;
3129 }
3130 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3131 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3132 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3133 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3134 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3135 found = true;
3136 break;
3137 }
3138 l -= len;
3139 p += len;
3140 }
3141
Sunil Ravi036cec52023-03-29 11:35:17 -07003142 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
3143 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
Hai Shalomc1a21442022-02-04 13:43:00 -08003144 return 0;
Sunil Ravi036cec52023-03-29 11:35:17 -07003145 }
Hai Shalomc1a21442022-02-04 13:43:00 -08003146
3147 wpa_hexdump(MSG_DEBUG,
3148 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
3149 p, l);
3150
3151 /* Update proto from (Re)Association Request frame info */
3152 wpa_s->wpa_proto = ie.proto;
3153 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
3154 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
3155 !!(wpa_s->wpa_proto &
3156 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
3157
3158 /* Update AKMP suite from (Re)Association Request frame info */
3159 sel = ie.key_mgmt;
3160 if (ssid->key_mgmt)
3161 sel &= ssid->key_mgmt;
3162
3163 wpa_dbg(wpa_s, MSG_DEBUG,
3164 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
3165 ie.key_mgmt, ssid->key_mgmt, sel);
3166 if (ie.key_mgmt && !sel) {
3167 wpa_supplicant_deauthenticate(
3168 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
3169 return -1;
3170 }
3171
Sunil Ravi036cec52023-03-29 11:35:17 -07003172#ifdef CONFIG_OCV
3173 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
3174 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
3175 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
3176 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
3177#endif /* CONFIG_OCV */
3178
Sunil Ravi89eba102022-09-13 21:04:37 -07003179 /*
3180 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
3181 * different AKM.
3182 */
3183 if (wpa_s->key_mgmt != ie.key_mgmt &&
3184 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
3185 if (!ssid->psk_set) {
3186 wpa_dbg(wpa_s, MSG_INFO,
3187 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00003188 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07003189 return -1;
3190 }
3191
3192 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
3193 if (wpa_s->conf->key_mgmt_offload &&
3194 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003195 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
3196 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07003197 wpa_dbg(wpa_s, MSG_ERROR,
3198 "WPA: Cannot set PMK for key management offload");
3199 }
3200
Hai Shalomc1a21442022-02-04 13:43:00 -08003201 wpa_s->key_mgmt = ie.key_mgmt;
3202 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3203 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
3204 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
3205 wpa_s->wpa_proto);
3206
3207 /* Update pairwise cipher from (Re)Association Request frame info */
3208 sel = ie.pairwise_cipher;
3209 if (ssid->pairwise_cipher)
3210 sel &= ssid->pairwise_cipher;
3211
3212 wpa_dbg(wpa_s, MSG_DEBUG,
3213 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
3214 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
3215 if (ie.pairwise_cipher && !sel) {
3216 wpa_supplicant_deauthenticate(
3217 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
3218 return -1;
3219 }
3220
3221 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3222 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3223 wpa_s->pairwise_cipher);
3224 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
3225 wpa_cipher_txt(wpa_s->pairwise_cipher));
3226
3227 /* Update other parameters based on AP's WPA IE/RSNE, if available */
3228 if (!bss) {
3229 wpa_dbg(wpa_s, MSG_DEBUG,
3230 "WPA: current_bss == NULL - skip AP IE check");
3231 return 0;
3232 }
3233
3234 /* Update GTK and IGTK from AP's RSNE */
3235 found = false;
3236
3237 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
3238 const u8 *bss_rsn;
3239
3240 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3241 if (bss_rsn) {
3242 p = bss_rsn;
3243 len = 2 + bss_rsn[1];
3244 found = true;
3245 }
3246 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
3247 const u8 *bss_wpa;
3248
3249 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3250 if (bss_wpa) {
3251 p = bss_wpa;
3252 len = 2 + bss_wpa[1];
3253 found = true;
3254 }
3255 }
3256
3257 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
3258 return 0;
3259
3260 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
3261 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3262 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3263 /* AP does not support MFP, local configuration requires it */
3264 wpa_supplicant_deauthenticate(
3265 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3266 return -1;
3267 }
3268 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3269 pmf == NO_MGMT_FRAME_PROTECTION) {
3270 /* AP requires MFP, local configuration disables it */
3271 wpa_supplicant_deauthenticate(
3272 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3273 return -1;
3274 }
3275
3276 /* Update PMF from local configuration now that MFP validation was done
3277 * above */
3278 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3279
3280 /* Update GTK from AP's RSNE */
3281 sel = ie.group_cipher;
3282 if (ssid->group_cipher)
3283 sel &= ssid->group_cipher;
3284
3285 wpa_dbg(wpa_s, MSG_DEBUG,
3286 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3287 ie.group_cipher, ssid->group_cipher, sel);
3288 if (ie.group_cipher && !sel) {
3289 wpa_supplicant_deauthenticate(
3290 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3291 return -1;
3292 }
3293
3294 wpa_s->group_cipher = ie.group_cipher;
3295 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3296 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3297 wpa_cipher_txt(wpa_s->group_cipher));
3298
3299 /* Update IGTK from AP RSN IE */
3300 sel = ie.mgmt_group_cipher;
3301 if (ssid->group_mgmt_cipher)
3302 sel &= ssid->group_mgmt_cipher;
3303
3304 wpa_dbg(wpa_s, MSG_DEBUG,
3305 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3306 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3307
3308 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3309 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3310 wpa_dbg(wpa_s, MSG_DEBUG,
3311 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3312 ie.capabilities);
3313 ie.mgmt_group_cipher = 0;
3314 }
3315
3316 if (ie.mgmt_group_cipher && !sel) {
3317 wpa_supplicant_deauthenticate(
3318 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3319 return -1;
3320 }
3321
3322 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3323 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3324 wpa_s->mgmt_group_cipher);
3325 if (wpa_s->mgmt_group_cipher)
3326 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3327 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3328 else
3329 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3330
3331 return 0;
3332}
3333
3334
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003335static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3336 union wpa_event_data *data)
3337{
Hai Shalomc3565922019-10-28 11:58:20 -07003338 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003339 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003340 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003341 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003342#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303343 struct wpa_ie_data ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003344#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003345
3346 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07003347 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003348 if (data->assoc_info.req_ies)
3349 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3350 data->assoc_info.req_ies_len);
3351 if (data->assoc_info.resp_ies) {
3352 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3353 data->assoc_info.resp_ies_len);
3354#ifdef CONFIG_TDLS
3355 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3356 data->assoc_info.resp_ies_len);
3357#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003358#ifdef CONFIG_WNM
3359 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3360 data->assoc_info.resp_ies_len);
3361#endif /* CONFIG_WNM */
Sunil Ravi88611412024-06-28 17:34:56 +00003362#ifdef CONFIG_INTERWORKING
Dmitry Shmidt051af732013-10-22 13:52:46 -07003363 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3364 data->assoc_info.resp_ies_len);
Sunil Ravi88611412024-06-28 17:34:56 +00003365#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003366 if (wpa_s->hw_capab == CAPAB_VHT &&
3367 get_ie(data->assoc_info.resp_ies,
3368 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3369 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003370
3371 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3372 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003373 }
3374 if (data->assoc_info.beacon_ies)
3375 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3376 data->assoc_info.beacon_ies,
3377 data->assoc_info.beacon_ies_len);
3378 if (data->assoc_info.freq)
3379 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3380 data->assoc_info.freq);
3381
Hai Shalom021b0b52019-04-10 11:17:58 -07003382 wpa_s->connection_set = 0;
3383 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3384 struct ieee802_11_elems req_elems, resp_elems;
3385
3386 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3387 data->assoc_info.req_ies_len,
3388 &req_elems, 0) != ParseFailed &&
3389 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3390 data->assoc_info.resp_ies_len,
3391 &resp_elems, 0) != ParseFailed) {
3392 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003393 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3394 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003395 wpa_s->connection_ht = req_elems.ht_capabilities &&
3396 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003397 /* Do not include subset of VHT on 2.4 GHz vendor
3398 * extension in consideration for reporting VHT
3399 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003400 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003401 resp_elems.vht_capabilities &&
3402 (!data->assoc_info.freq ||
3403 wpas_freq_to_band(data->assoc_info.freq) !=
3404 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003405 wpa_s->connection_he = req_elems.he_capabilities &&
3406 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003407 wpa_s->connection_eht = req_elems.eht_capabilities &&
3408 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003409
3410 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3411 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3412 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3413 max_nss_rx_req : max_nss_rx_resp;
3414 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3415 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3416 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3417 max_nss_tx_req : max_nss_tx_resp;
3418
3419 struct supported_chan_width sta_supported_chan_width =
3420 get_supported_channel_width(&req_elems);
3421 enum chan_width ap_operation_chan_width =
3422 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303423 if (wpa_s->connection_vht || wpa_s->connection_he ||
3424 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003425 wpa_s->connection_channel_bandwidth =
3426 get_sta_operation_chan_width(ap_operation_chan_width,
3427 sta_supported_chan_width);
3428 } else if (wpa_s->connection_ht) {
3429 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3430 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3431 } else {
3432 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3433 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003434 if (req_elems.rrm_enabled)
3435 wpa_s->rrm.rrm_used = 1;
Ainy Kumari322d4fd2024-02-14 13:05:40 +05303436 wpa_s->ap_t2lm_negotiation_support =
3437 is_ap_t2lm_negotiation_supported(resp_elems.basic_mle,
3438 resp_elems.basic_mle_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07003439 }
3440 }
3441
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003442 p = data->assoc_info.req_ies;
3443 l = data->assoc_info.req_ies_len;
3444
3445 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3446 while (p && l >= 2) {
3447 len = p[1] + 2;
3448 if (len > l) {
3449 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3450 p, l);
3451 break;
3452 }
Hai Shalomc3565922019-10-28 11:58:20 -07003453 if (!found &&
3454 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3455 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3456 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3457 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3458 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003459 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3460 break;
3461 found = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07003462 wpa_find_assoc_pmkid(wpa_s,
3463 data->assoc_info.authorized);
Hai Shalomc3565922019-10-28 11:58:20 -07003464 }
3465 if (!found_x && p[0] == WLAN_EID_RSNX) {
3466 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3467 break;
3468 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003469 }
3470 l -= len;
3471 p += len;
3472 }
3473 if (!found && data->assoc_info.req_ies)
3474 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003475 if (!found_x && data->assoc_info.req_ies)
3476 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003477
Winnie Chen4138eec2022-11-10 16:32:53 +08003478#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303479 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3480 * to a different security type, update the current supplicant configuration to use the AKM
3481 * and pairwise suites from the assoc IE passed by the driver.
3482 */
3483 if (wpas_driver_bss_selection(wpa_s)) {
3484 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3485 /* Check if firmware has roamed to a different security network */
3486 if(wpa_s->key_mgmt != ie.key_mgmt) {
3487 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3488 ie.key_mgmt);
3489 wpa_s->key_mgmt = ie.key_mgmt;
3490 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3491
3492 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3493 /* Restore PMK as it can get overwritten if the previous
3494 * association was to 802.1X.
3495 */
3496 if ((!(wpa_s->drv_flags &
3497 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3498 (wpa_s->current_ssid) &&
3499 (wpa_s->current_ssid->psk_set)) {
3500 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3501 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3502 "BSSID");
3503 wpa_supplicant_deauthenticate(
3504 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3505 return -1;
3506 }
3507 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3508 PMK_LEN, NULL, bssid);
3509 }
3510 }
3511 }
3512 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3513 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3514 "from Assoc IE", ie.pairwise_cipher);
3515 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3516 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3517 wpa_s->pairwise_cipher);
3518 }
3519 // TODO: Notify the framework about security type change b/230766005
3520 }
3521 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003522#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303523
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003524#ifdef CONFIG_FILS
3525#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003526 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3527 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003528 (!data->assoc_info.resp_frame ||
3529 fils_process_assoc_resp(wpa_s->wpa,
3530 data->assoc_info.resp_frame,
3531 data->assoc_info.resp_frame_len) < 0)) {
3532 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3533 return -1;
3534 }
3535#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003536
3537 /* Additional processing for FILS when SME is in driver */
3538 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3539 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3540 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003541#endif /* CONFIG_FILS */
3542
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003543#ifdef CONFIG_OWE
3544 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003545 !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003546 (!bssid_known ||
Sunil Ravi036cec52023-03-29 11:35:17 -07003547 owe_process_assoc_resp(wpa_s->wpa,
3548 wpa_s->valid_links ?
3549 wpa_s->ap_mld_addr : bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003550 data->assoc_info.resp_ies,
3551 data->assoc_info.resp_ies_len) < 0)) {
3552 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3553 return -1;
3554 }
3555#endif /* CONFIG_OWE */
3556
Hai Shalom021b0b52019-04-10 11:17:58 -07003557#ifdef CONFIG_DPP2
3558 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003559 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3560 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003561 struct ieee802_11_elems elems;
3562
3563 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3564 data->assoc_info.resp_ies_len,
3565 &elems, 0) == ParseFailed ||
3566 !elems.owe_dh)
3567 goto no_pfs;
3568 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3569 elems.owe_dh_len) < 0) {
3570 wpa_supplicant_deauthenticate(wpa_s,
3571 WLAN_REASON_UNSPECIFIED);
3572 return -1;
3573 }
3574
3575 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3576 }
3577no_pfs:
3578#endif /* CONFIG_DPP2 */
3579
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003580#ifdef CONFIG_IEEE80211R
3581#ifdef CONFIG_SME
3582 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003583 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003584 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3585 data->assoc_info.resp_ies,
3586 data->assoc_info.resp_ies_len,
3587 bssid) < 0) {
3588 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3589 "Reassociation Response failed");
3590 wpa_supplicant_deauthenticate(
3591 wpa_s, WLAN_REASON_INVALID_IE);
3592 return -1;
3593 }
3594 }
3595
3596 p = data->assoc_info.resp_ies;
3597 l = data->assoc_info.resp_ies_len;
3598
3599#ifdef CONFIG_WPS_STRICT
3600 if (p && wpa_s->current_ssid &&
3601 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3602 struct wpabuf *wps;
3603 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3604 if (wps == NULL) {
3605 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3606 "include WPS IE in (Re)Association Response");
3607 return -1;
3608 }
3609
3610 if (wps_validate_assoc_resp(wps) < 0) {
3611 wpabuf_free(wps);
3612 wpa_supplicant_deauthenticate(
3613 wpa_s, WLAN_REASON_INVALID_IE);
3614 return -1;
3615 }
3616 wpabuf_free(wps);
3617 }
3618#endif /* CONFIG_WPS_STRICT */
3619
3620 /* Go through the IEs and make a copy of the MDIE, if present. */
3621 while (p && l >= 2) {
3622 len = p[1] + 2;
3623 if (len > l) {
3624 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3625 p, l);
3626 break;
3627 }
3628 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3629 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3630 wpa_s->sme.ft_used = 1;
3631 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3632 MOBILITY_DOMAIN_ID_LEN);
3633 break;
3634 }
3635 l -= len;
3636 p += len;
3637 }
3638#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003639#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303640 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3641 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3642 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
Vinayak Yadawadf473bef2024-04-04 15:33:29 +05303643 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) ||
3644 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303645 wpa_ft_is_completed(wpa_s->wpa)) {
3646 return 0;
3647 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003648#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003649
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003650 /* Process FT when SME is in the driver */
3651 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3652 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003653 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003654 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3655 data->assoc_info.resp_ies,
3656 data->assoc_info.resp_ies_len,
3657 bssid) < 0) {
3658 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3659 "Reassociation Response failed");
3660 wpa_supplicant_deauthenticate(
3661 wpa_s, WLAN_REASON_INVALID_IE);
3662 return -1;
3663 }
3664 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3665 }
3666
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003667 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3668 data->assoc_info.resp_ies_len);
3669#endif /* CONFIG_IEEE80211R */
3670
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003671#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07003672 if (bssid_known)
3673 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3674 data->assoc_info.resp_ies,
3675 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003676#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -07003677
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003678 /* WPA/RSN IE from Beacon/ProbeResp */
3679 p = data->assoc_info.beacon_ies;
3680 l = data->assoc_info.beacon_ies_len;
3681
3682 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3683 */
3684 wpa_found = rsn_found = 0;
3685 while (p && l >= 2) {
3686 len = p[1] + 2;
3687 if (len > l) {
3688 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3689 p, l);
3690 break;
3691 }
3692 if (!wpa_found &&
3693 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3694 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3695 wpa_found = 1;
3696 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3697 }
3698
3699 if (!rsn_found &&
3700 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3701 rsn_found = 1;
3702 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3703 }
3704
Hai Shalomc3565922019-10-28 11:58:20 -07003705 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3706 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3707
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003708 l -= len;
3709 p += len;
3710 }
3711
3712 if (!wpa_found && data->assoc_info.beacon_ies)
3713 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003714 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003715 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003716 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3717 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003718 if (wpa_found || rsn_found)
3719 wpa_s->ap_ies_from_associnfo = 1;
3720
Sunil Ravi88611412024-06-28 17:34:56 +00003721 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3722 wpa_s->assoc_freq != data->assoc_info.freq) {
3723 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3724 "%u to %u MHz",
3725 wpa_s->assoc_freq, data->assoc_info.freq);
3726 wpa_supplicant_update_scan_results(wpa_s);
Jouni Malinen87fd2792011-05-16 18:35:42 +03003727 }
3728
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003729 wpa_s->assoc_freq = data->assoc_info.freq;
3730
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003731#ifndef CONFIG_NO_ROBUST_AV
Hai Shalomc1a21442022-02-04 13:43:00 -08003732 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3733 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003734#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08003735
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003736 return 0;
3737}
3738
3739
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003740static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3741{
Hai Shalomc3565922019-10-28 11:58:20 -07003742 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003743
3744 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3745 return -1;
3746
3747 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3748 return 0;
3749
3750 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3751 WPA_IE_VENDOR_TYPE);
3752 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003753 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003754
3755 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3756 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3757 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003758 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3759 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3760 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003761 return -1;
3762
3763 return 0;
3764}
3765
3766
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003767static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3768 union wpa_event_data *data)
3769{
3770#ifdef CONFIG_FST
3771 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3772 struct wpa_bss *bss = wpa_s->current_bss;
3773 const u8 *ieprb, *iebcn;
3774
3775 wpabuf_free(wpa_s->received_mb_ies);
3776 wpa_s->received_mb_ies = NULL;
3777
3778 if (ai &&
3779 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3780 wpa_printf(MSG_DEBUG,
3781 "FST: MB IEs updated from Association Response frame");
3782 return;
3783 }
3784
3785 if (ai &&
3786 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3787 wpa_printf(MSG_DEBUG,
3788 "FST: MB IEs updated from association event Beacon IEs");
3789 return;
3790 }
3791
3792 if (!bss)
3793 return;
3794
Hai Shalom60840252021-02-19 19:02:11 -08003795 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003796 iebcn = ieprb + bss->ie_len;
3797
3798 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3799 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3800 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3801 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3802#endif /* CONFIG_FST */
3803}
3804
3805
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003806static unsigned int wpas_ml_parse_assoc(struct wpa_supplicant *wpa_s,
3807 struct ieee802_11_elems *elems,
3808 struct ml_sta_link_info *ml_info)
3809{
3810 struct wpabuf *mlbuf;
3811 struct ieee80211_eht_ml *ml;
3812 size_t ml_len;
3813 struct eht_ml_basic_common_info *common_info;
3814 const u8 *pos;
3815 u16 eml_capa = 0, mld_capa = 0;
3816 const u16 control =
3817 host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC |
3818 BASIC_MULTI_LINK_CTRL_PRES_LINK_ID |
3819 BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT);
3820 u8 expected_common_info_len = 9;
3821 unsigned int i = 0;
3822 u16 ml_control;
3823
3824 if (!wpa_s->valid_links || !elems->basic_mle || !elems->basic_mle_len)
3825 return 0;
3826
3827 mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
3828 if (!mlbuf)
3829 return 0;
3830
3831 ml = (struct ieee80211_eht_ml *) wpabuf_head(mlbuf);
3832 ml_len = wpabuf_len(mlbuf);
3833 if (ml_len < sizeof(*ml))
3834 goto out;
3835
3836 os_memset(ml_info, 0, sizeof(*ml_info) * MAX_NUM_MLD_LINKS);
3837
3838 ml_control = le_to_host16(ml->ml_control);
3839
3840 if ((ml_control & control) != control) {
3841 wpa_printf(MSG_DEBUG, "MLD: Invalid presence BM=0x%x",
3842 ml_control);
3843 goto out;
3844 }
3845
3846 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
3847 wpa_printf(MSG_DEBUG, "MLD: EML capabilities included");
3848 expected_common_info_len += 2;
3849 }
3850
3851 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
3852 wpa_printf(MSG_DEBUG, "MLD: MLD capabilities included");
3853 expected_common_info_len += 2;
3854 }
3855
3856 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
3857 wpa_printf(MSG_DEBUG,
3858 "MLD: Unexpected: medium sync delay info present");
3859 expected_common_info_len += 2;
3860 }
3861
3862 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
3863 wpa_printf(MSG_DEBUG,
3864 "MLD: Unexpected: MLD ID present");
3865 expected_common_info_len++;
3866 }
3867
3868 if (sizeof(*ml) + expected_common_info_len > ml_len) {
3869 wpa_printf(MSG_DEBUG,
3870 "MLD: Not enough bytes for common info. ml_len=%zu",
3871 ml_len);
3872 goto out;
3873 }
3874
3875 common_info = (struct eht_ml_basic_common_info *) ml->variable;
3876 if (common_info->len != expected_common_info_len) {
3877 wpa_printf(MSG_DEBUG,
3878 "MLD: Invalid common info len=%u. expected=%u",
3879 common_info->len, expected_common_info_len);
3880 goto out;
3881 }
3882
3883 wpa_printf(MSG_DEBUG, "MLD: address: " MACSTR,
3884 MAC2STR(common_info->mld_addr));
3885
3886 if (!ether_addr_equal(wpa_s->ap_mld_addr, common_info->mld_addr)) {
3887 wpa_printf(MSG_DEBUG, "MLD: Mismatching MLD address (expected "
3888 MACSTR ")", MAC2STR(wpa_s->ap_mld_addr));
3889 goto out;
3890 }
3891
3892 pos = common_info->variable;
3893
3894 /* Store the information for the association link */
3895 ml_info[i].link_id = *pos;
3896 pos++;
3897
3898 /* Skip the BSS Parameters Change Count */
3899 pos++;
3900
3901 /* Skip the Medium Synchronization Delay Information if present */
3902 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO)
3903 pos += 2;
3904
3905 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
3906 eml_capa = WPA_GET_LE16(pos);
3907 pos += 2;
3908 }
3909
3910 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
3911 mld_capa = WPA_GET_LE16(pos);
3912 pos += 2;
3913 }
3914
3915 wpa_printf(MSG_DEBUG,
3916 "MLD: link_id=%u, eml=0x%x, mld=0x%x",
3917 ml_info[i].link_id, eml_capa, mld_capa);
3918
3919 i++;
3920
3921 pos = ((u8 *) common_info) + common_info->len;
3922 ml_len -= sizeof(*ml) + common_info->len;
3923 while (ml_len > 2 && i < MAX_NUM_MLD_LINKS) {
3924 u8 sub_elem_len = pos[1];
3925 u8 sta_info_len;
3926 u8 nstr_bitmap_len = 0;
3927 u16 ctrl;
3928 const u8 *end;
3929
3930 wpa_printf(MSG_DEBUG, "MLD: Subelement len=%u", sub_elem_len);
3931
3932 if (sub_elem_len > ml_len - 2) {
3933 wpa_printf(MSG_DEBUG,
3934 "MLD: Invalid link info len: %u > %zu",
3935 2 + sub_elem_len, ml_len);
3936 goto out;
3937 }
3938
3939 switch (*pos) {
3940 case EHT_ML_SUB_ELEM_PER_STA_PROFILE:
3941 break;
3942 case EHT_ML_SUB_ELEM_FRAGMENT:
3943 case EHT_ML_SUB_ELEM_VENDOR:
3944 wpa_printf(MSG_DEBUG,
3945 "MLD: Skip subelement id=%u, len=%u",
3946 *pos, sub_elem_len);
3947 pos += 2 + sub_elem_len;
3948 ml_len -= 2 + sub_elem_len;
3949 continue;
3950 default:
3951 wpa_printf(MSG_DEBUG, "MLD: Unknown subelement ID=%u",
3952 *pos);
3953 goto out;
3954 }
3955
3956 end = pos + 2 + sub_elem_len;
3957
3958 /* Skip the subelement ID and the length */
3959 pos += 2;
3960 ml_len -= 2;
3961
3962 if (end - pos < 2)
3963 goto out;
3964
3965 /* Get the station control field */
3966 ctrl = WPA_GET_LE16(pos);
3967
3968 pos += 2;
3969 ml_len -= 2;
3970
3971 if (!(ctrl & EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK)) {
3972 wpa_printf(MSG_DEBUG,
3973 "MLD: Per STA complete profile expected");
3974 goto out;
3975 }
3976
3977 if (!(ctrl & EHT_PER_STA_CTRL_MAC_ADDR_PRESENT_MSK)) {
3978 wpa_printf(MSG_DEBUG,
3979 "MLD: Per STA MAC address not present");
3980 goto out;
3981 }
3982
3983 if (!(ctrl & EHT_PER_STA_CTRL_TSF_OFFSET_PRESENT_MSK)) {
3984 wpa_printf(MSG_DEBUG,
3985 "MLD: Per STA TSF offset not present");
3986 goto out;
3987 }
3988
3989 if (!(ctrl & EHT_PER_STA_CTRL_BEACON_INTERVAL_PRESENT_MSK)) {
3990 wpa_printf(MSG_DEBUG,
3991 "MLD: Beacon interval not present");
3992 goto out;
3993 }
3994
3995 if (!(ctrl & EHT_PER_STA_CTRL_DTIM_INFO_PRESENT_MSK)) {
3996 wpa_printf(MSG_DEBUG,
3997 "MLD: DTIM information not present");
3998 goto out;
3999 }
4000
4001 if (ctrl & EHT_PER_STA_CTRL_NSTR_LINK_PAIR_PRESENT_MSK) {
4002 if (ctrl & EHT_PER_STA_CTRL_NSTR_BM_SIZE_MSK)
4003 nstr_bitmap_len = 2;
4004 else
4005 nstr_bitmap_len = 1;
4006 }
4007
4008 if (!(ctrl & EHT_PER_STA_CTRL_BSS_PARAM_CNT_PRESENT_MSK)) {
4009 wpa_printf(MSG_DEBUG,
4010 "MLD: BSS params change count not present");
4011 goto out;
4012 }
4013
4014 sta_info_len = 1 + ETH_ALEN + 8 + 2 + 2 + 1 + nstr_bitmap_len;
4015 if (sta_info_len > ml_len || sta_info_len > end - pos ||
4016 sta_info_len + 2 > sub_elem_len ||
4017 sta_info_len != *pos) {
4018 wpa_printf(MSG_DEBUG,
4019 "MLD: Invalid STA info len=%u, len=%u",
4020 sta_info_len, *pos);
4021 goto out;
4022 }
4023
4024 /* Get the link address */
4025 wpa_printf(MSG_DEBUG,
4026 "MLD: link addr: " MACSTR " nstr BM len=%u",
4027 MAC2STR(pos + 1), nstr_bitmap_len);
4028
4029 ml_info[i].link_id = ctrl & EHT_PER_STA_CTRL_LINK_ID_MSK;
4030 os_memcpy(ml_info[i].bssid, pos + 1, ETH_ALEN);
4031
4032 pos += sta_info_len;
4033 ml_len -= sta_info_len;
4034
4035 wpa_printf(MSG_DEBUG, "MLD: sub_elem_len=%u, sta_info_len=%u",
4036 sub_elem_len, sta_info_len);
4037
4038 sub_elem_len -= sta_info_len + 2;
4039 if (sub_elem_len < 4) {
4040 wpa_printf(MSG_DEBUG, "MLD: Per STA profile too short");
4041 goto out;
4042 }
4043
4044 wpa_hexdump(MSG_MSGDUMP, "MLD: STA profile", pos, sub_elem_len);
4045 ml_info[i].status = WPA_GET_LE16(pos + 2);
4046
4047 pos += sub_elem_len;
4048 ml_len -= sub_elem_len;
4049
4050 i++;
4051 }
4052
4053 wpabuf_free(mlbuf);
4054 return i;
4055out:
4056 wpabuf_free(mlbuf);
4057 return 0;
4058}
4059
4060
Sunil Ravi89eba102022-09-13 21:04:37 -07004061static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
4062{
4063 struct driver_sta_mlo_info mlo;
4064 int i;
4065
Sunil Ravi77d572f2023-01-17 23:58:31 +00004066 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07004067 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
4068 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
4069 wpa_supplicant_deauthenticate(wpa_s,
4070 WLAN_REASON_DEAUTH_LEAVING);
4071 return -1;
4072 }
4073
4074 if (wpa_s->valid_links == mlo.valid_links) {
4075 bool match = true;
4076
4077 if (!mlo.valid_links)
4078 return 0;
4079
Sunil Ravi88611412024-06-28 17:34:56 +00004080 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
4081 if (!(mlo.valid_links & BIT(i)))
4082 continue;
4083
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004084 if (!ether_addr_equal(wpa_s->links[i].addr,
4085 mlo.links[i].addr) ||
4086 !ether_addr_equal(wpa_s->links[i].bssid,
4087 mlo.links[i].bssid)) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004088 match = false;
4089 break;
4090 }
4091 }
4092
Sunil Ravi77d572f2023-01-17 23:58:31 +00004093 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004094 ether_addr_equal(wpa_s->ap_mld_addr, mlo.ap_mld_addr))
Sunil Ravi89eba102022-09-13 21:04:37 -07004095 return 0;
4096 }
4097
4098 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004099 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07004100 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
Sunil Ravi88611412024-06-28 17:34:56 +00004101 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
4102 if (!(wpa_s->valid_links & BIT(i)))
4103 continue;
4104
Sunil Ravi89eba102022-09-13 21:04:37 -07004105 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
4106 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
4107 wpa_s->links[i].freq = mlo.links[i].freq;
4108 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
4109 }
4110
4111 return 0;
4112}
4113
4114
Sunil Ravi77d572f2023-01-17 23:58:31 +00004115static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
4116{
4117 struct driver_sta_mlo_info drv_mlo;
4118 struct wpa_sm_mlo wpa_mlo;
4119 const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
4120 int i;
4121
4122 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
4123 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
4124 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
4125 return -1;
4126 }
4127
4128 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
4129 if (!drv_mlo.valid_links)
4130 goto out;
4131
4132 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
4133 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
4134 wpa_mlo.valid_links = drv_mlo.valid_links;
4135 wpa_mlo.req_links = drv_mlo.req_links;
4136
Sunil Ravi88611412024-06-28 17:34:56 +00004137 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004138 struct wpa_bss *bss;
4139
Sunil Ravi88611412024-06-28 17:34:56 +00004140 if (!(drv_mlo.req_links & BIT(i)))
4141 continue;
4142
Sunil Ravi77d572f2023-01-17 23:58:31 +00004143 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
4144 if (!bss) {
Sunil Ravi88611412024-06-28 17:34:56 +00004145 wpa_supplicant_update_scan_results(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004146 bss = wpa_supplicant_get_new_bss(
4147 wpa_s, drv_mlo.links[i].bssid);
4148 }
4149
4150 if (!bss) {
4151 wpa_dbg(wpa_s, MSG_INFO,
4152 "Failed to get MLO link %d BSS", i);
4153 return -1;
4154 }
4155
4156 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4157 bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
4158
4159 wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
4160 wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
4161 wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
4162 wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
4163
4164 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
4165 ETH_ALEN);
4166 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
4167 ETH_ALEN);
4168 }
4169
4170out:
4171 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
4172}
4173
4174
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004175static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
4176 union wpa_event_data *data)
4177{
4178 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004179 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004180 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07004181#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4182 struct wpa_bss *bss;
4183#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08004184#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304185 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08004186#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004187
4188#ifdef CONFIG_AP
4189 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004190 if (!data)
4191 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004192 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
4193 data->assoc_info.addr,
4194 data->assoc_info.req_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004195 data->assoc_info.req_ies_len, NULL, 0,
4196 NULL, data->assoc_info.reassoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004197 return;
4198 }
4199#endif /* CONFIG_AP */
4200
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004201 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07004202 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004203
Andy Kuoaba17c12022-04-14 16:05:31 +08004204#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304205 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
4206 struct wpa_ft_ies parse;
4207 /* Check for FT reassociation is done by the driver */
4208#ifdef CONFIG_IEEE80211R
4209 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05304210 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05304211 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004212 data->assoc_info.resp_ies_len, &parse, use_sha384, false) < 0) {
Mir Ali677e7482020-11-12 19:49:02 +05304213 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
4214 return;
4215 }
4216 if (parse.rsn_pmkid != NULL) {
4217 wpa_set_ft_completed(wpa_s->wpa);
4218 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
4219 }
4220 }
4221#endif /* CONFIG_IEEE80211R */
4222 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004223#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05304224
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004225 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07004226
4227 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4228 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
4229 wpa_supplicant_deauthenticate(
4230 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4231 return;
4232 }
4233
Sunil Ravi89eba102022-09-13 21:04:37 -07004234 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
4235 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
4236 wpa_supplicant_deauthenticate(wpa_s,
4237 WLAN_REASON_DEAUTH_LEAVING);
4238 return;
4239 }
4240
Sunil Ravia04bd252022-05-02 22:54:18 -07004241 if (ft_completed &&
4242 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
4243 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
4244 MAC2STR(bssid));
4245 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
4246 wpa_printf(MSG_ERROR,
4247 "Can't find target AP's information!");
4248 return;
4249 }
4250 wpa_supplicant_assoc_update_ie(wpa_s);
4251 }
4252
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004253 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
4254 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004255 /*
4256 * FILS authentication can share the same mechanism to mark the
4257 * connection fully authenticated, so set ft_completed also based on
4258 * FILS result.
4259 */
4260 if (!ft_completed)
4261 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004262
Andy Kuoaba17c12022-04-14 16:05:31 +08004263#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304264 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
4265 /*
4266 * For driver based roaming, insert PSK during
4267 * the initial association
4268 */
4269 if (is_zero_ether_addr(wpa_s->bssid) &&
4270 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
4271 /*
4272 * In case the driver wants to handle re-assocs,
4273 * pass it down the PMK.
4274 */
4275 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
4276 wpa_sm_install_pmk(wpa_s->wpa);
4277 }
Mir Ali677e7482020-11-12 19:49:02 +05304278 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304279#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08004280
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004281 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004282 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004283 if (os_reltime_initialized(&wpa_s->session_start)) {
4284 os_reltime_age(&wpa_s->session_start,
4285 &wpa_s->session_length);
4286 wpa_s->session_start.sec = 0;
4287 wpa_s->session_start.usec = 0;
4288 wpas_notify_session_length(wpa_s);
4289 } else {
4290 wpas_notify_auth_changed(wpa_s);
4291 os_get_reltime(&wpa_s->session_start);
4292 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004293 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
4294 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004295 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004296 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004297 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4298 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004299 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004300
4301 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
4302 wpa_clear_keys(wpa_s, bssid);
4303 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00004304 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004305 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004306 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4307 return;
4308 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004309 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004310
Hai Shalomc1a21442022-02-04 13:43:00 -08004311 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4312 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
4313 return;
4314
Hai Shalomfdcde762020-04-02 11:19:20 -07004315 multi_ap_set_4addr_mode(wpa_s);
4316
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004317 if (wpa_s->conf->ap_scan == 1 &&
4318 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004319 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
4320 wpa_msg(wpa_s, MSG_WARNING,
4321 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004322 }
4323
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004324 wpas_fst_update_mb_assoc(wpa_s, data);
4325
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004326#ifdef CONFIG_SME
Sunil Ravi640215c2023-06-28 23:08:09 +00004327 /*
4328 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
4329 * (for MLO connection) as the previous BSSID for subsequent
4330 * reassociation requests handled by SME-in-wpa_supplicant.
4331 */
4332 os_memcpy(wpa_s->sme.prev_bssid,
4333 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004334 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07004335 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004336#endif /* CONFIG_SME */
4337
4338 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
4339 if (wpa_s->current_ssid) {
4340 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
4341 * initialized before association, but for other modes,
4342 * initialize PC/SC here, if the current configuration needs
4343 * smartcard or SIM/USIM. */
4344 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
4345 }
4346 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004347
4348 if (wpa_sm_set_ml_info(wpa_s)) {
4349 wpa_dbg(wpa_s, MSG_INFO,
4350 "Failed to set MLO connection info to wpa_sm");
4351 wpa_supplicant_deauthenticate(wpa_s,
4352 WLAN_REASON_DEAUTH_LEAVING);
4353 return;
4354 }
4355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004356 if (wpa_s->l2)
4357 l2_packet_notify_auth_start(wpa_s->l2);
4358
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004359 already_authorized = data && data->assoc_info.authorized;
4360
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004361 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07004362 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004363 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
4364 * state machine may transit to AUTHENTICATING state based on obsolete
4365 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
4366 * AUTHENTICATED without ever giving chance to EAP state machine to
4367 * reset the state.
4368 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004369 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07004370 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4371 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004372 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004373 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4374 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
4375 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07004376 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07004377 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004378 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07004379 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004380 wpa_s->eapol_received = 0;
4381 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4382 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4383 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004384 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004385 if (wpa_s->current_ssid &&
4386 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004387 (wpa_s->drv_flags &
4388 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4389 /*
4390 * Set the key after having received joined-IBSS event
4391 * from the driver.
4392 */
4393 wpa_supplicant_set_wpa_none_key(wpa_s,
4394 wpa_s->current_ssid);
4395 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004396 wpa_supplicant_cancel_auth_timeout(wpa_s);
4397 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4398 } else if (!ft_completed) {
4399 /* Timeout for receiving the first EAPOL packet */
4400 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
4401 }
4402 wpa_supplicant_cancel_scan(wpa_s);
4403
Hai Shalom5f92bc92019-04-18 11:54:11 -07004404 if (ft_completed) {
4405 /*
4406 * FT protocol completed - make sure EAPOL state machine ends
4407 * up in authenticated.
4408 */
4409 wpa_supplicant_cancel_auth_timeout(wpa_s);
4410 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004411 eapol_sm_notify_portValid(wpa_s->eapol, true);
4412 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07004413 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4414 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304415 if (already_authorized) {
4416 /*
4417 * We are done; the driver will take care of RSN 4-way
4418 * handshake.
4419 */
4420 wpa_supplicant_cancel_auth_timeout(wpa_s);
4421 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4422 eapol_sm_notify_portValid(wpa_s->eapol, true);
4423 eapol_sm_notify_eap_success(wpa_s->eapol, true);
4424 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004425 /* Update port, WPA_COMPLETED state from the
4426 * EVENT_PORT_AUTHORIZED handler when the driver is done
4427 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304428 */
Sunil Ravi167279a2023-05-31 01:12:34 +00004429 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004430 wpa_msg(wpa_s, MSG_INFO,
4431 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304432 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004433 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004434 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4435 /*
4436 * The driver will take care of RSN 4-way handshake, so we need
4437 * to allow EAPOL supplicant to complete its work without
4438 * waiting for WPA supplicant.
4439 */
Hai Shalome21d4e82020-04-29 16:34:06 -07004440 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004441 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004442#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05304443 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
4444 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4445 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
4446 wpa_s->key_mgmt);
4447 wpa_supplicant_deauthenticate(
4448 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4449 return;
4450 }
4451 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4452 wpa_s->assoc_freq = data->assoc_info.freq;
4453 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
4454 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004455#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
4456
Jouni Malinena05074c2012-12-21 21:35:35 +02004457 wpa_s->last_eapol_matches_bssid = 0;
4458
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004459#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07004460 if (wpa_s->rsne_override_eapol) {
4461 wpa_printf(MSG_DEBUG,
4462 "TESTING: RSNE EAPOL-Key msg 2/4 override");
4463 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4464 wpabuf_head(wpa_s->rsne_override_eapol),
4465 wpabuf_len(wpa_s->rsne_override_eapol));
4466 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004467 if (wpa_s->rsnxe_override_eapol) {
4468 wpa_printf(MSG_DEBUG,
4469 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4470 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4471 wpabuf_head(wpa_s->rsnxe_override_eapol),
4472 wpabuf_len(wpa_s->rsnxe_override_eapol));
4473 }
4474#endif /* CONFIG_TESTING_OPTIONS */
4475
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004476 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004477 struct os_reltime now, age;
4478 os_get_reltime(&now);
4479 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08004480 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004481 ether_addr_equal(wpa_s->pending_eapol_rx_src,
4482 wpa_s->valid_links ? wpa_s->ap_mld_addr :
4483 bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004484 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4485 "frame that was received just before "
4486 "association notification");
4487 wpa_supplicant_rx_eapol(
4488 wpa_s, wpa_s->pending_eapol_rx_src,
4489 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00004490 wpabuf_len(wpa_s->pending_eapol_rx),
4491 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004492 }
4493 wpabuf_free(wpa_s->pending_eapol_rx);
4494 wpa_s->pending_eapol_rx = NULL;
4495 }
4496
Hai Shalomfdcde762020-04-02 11:19:20 -07004497#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004498 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4499 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004500 wpa_s->current_ssid &&
4501 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004502 /* Set static WEP keys again */
4503 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4504 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004505#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004506
4507#ifdef CONFIG_IBSS_RSN
4508 if (wpa_s->current_ssid &&
4509 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4510 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4511 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4512 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004513 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004514 if (!wpa_s->ibss_rsn) {
4515 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4516 wpa_supplicant_deauthenticate(
4517 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4518 return;
4519 }
4520
4521 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4522 }
4523#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004524
4525 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004526
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004527#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004528 if (data) {
4529 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4530 data->assoc_info.resp_ies_len,
4531 &data->assoc_info.wmm_params);
4532
4533 if (wpa_s->reassoc_same_bss)
4534 wmm_ac_restore_tspecs(wpa_s);
4535 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004536#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004537
Hai Shalomc3565922019-10-28 11:58:20 -07004538#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4539 bss = wpa_bss_get_bssid(wpa_s, bssid);
4540#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004541#ifdef CONFIG_FILS
4542 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004543 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4544
4545 if (fils_cache_id)
4546 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4547 }
4548#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004549
4550#ifdef CONFIG_MBO
4551 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4552#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004553
4554#ifdef CONFIG_DPP2
4555 wpa_s->dpp_pfs_fallback = 0;
4556#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004557
4558 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4559 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004560}
4561
4562
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004563static int disconnect_reason_recoverable(u16 reason_code)
4564{
4565 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4566 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4567 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4568}
4569
4570
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004571static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004572 u16 reason_code,
4573 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004574{
4575 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004576
4577 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4578 /*
4579 * At least Host AP driver and a Prism3 card seemed to be
4580 * generating streams of disconnected events when configuring
4581 * IBSS for WPA-None. Ignore them for now.
4582 */
4583 return;
4584 }
4585
4586 bssid = wpa_s->bssid;
4587 if (is_zero_ether_addr(bssid))
4588 bssid = wpa_s->pending_bssid;
4589
4590 if (!is_zero_ether_addr(bssid) ||
4591 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4592 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4593 " reason=%d%s",
4594 MAC2STR(bssid), reason_code,
4595 locally_generated ? " locally_generated=1" : "");
4596 }
4597}
4598
4599
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004600static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4601 int locally_generated)
4602{
4603 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004604 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004605 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4606 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004607 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004608
4609 /*
4610 * It looks like connection was lost while trying to go through PSK
4611 * 4-way handshake. Filter out known disconnection cases that are caused
4612 * by something else than PSK mismatch to avoid confusing reports.
4613 */
4614
4615 if (locally_generated) {
4616 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4617 return 0;
4618 }
4619
4620 return 1;
4621}
4622
4623
Jouni Malinen2b89da82012-08-31 22:04:41 +03004624static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4625 u16 reason_code,
4626 int locally_generated)
4627{
4628 const u8 *bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004629 struct wpa_bss *fast_reconnect = NULL;
4630 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004631 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004632
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004633 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4634 /*
4635 * At least Host AP driver and a Prism3 card seemed to be
4636 * generating streams of disconnected events when configuring
4637 * IBSS for WPA-None. Ignore them for now.
4638 */
4639 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4640 "IBSS/WPA-None mode");
4641 return;
4642 }
4643
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004644 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4645 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4646 locally_generated)
4647 /*
4648 * Remove the inactive AP (which is probably out of range) from
4649 * the BSS list after marking disassociation. In particular
4650 * mac80211-based drivers use the
4651 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4652 * locally generated disconnection events for cases where the
4653 * AP does not reply anymore.
4654 */
4655 curr = wpa_s->current_bss;
4656
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004657 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004658 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4659 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004660 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4661 return; /* P2P group removed */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004662 wpas_auth_failed(wpa_s, "WRONG_KEY", wpa_s->pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004663 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004664#ifdef CONFIG_DPP2
4665 wpas_dpp_send_conn_status_result(wpa_s,
4666 DPP_STATUS_AUTH_FAILURE);
4667#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004668 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004669 if (!wpa_s->disconnected &&
4670 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004671 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004672 wpas_wps_searching(wpa_s) ||
4673 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004674 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004675 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004676 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004677 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004678 wpa_s->wpa_state);
4679 if (wpa_s->wpa_state == WPA_COMPLETED &&
4680 wpa_s->current_ssid &&
4681 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004682 (wpa_s->own_reconnect_req ||
4683 (!locally_generated &&
4684 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004685 /*
4686 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004687 * us, but could allow us to get back in. This is also
4688 * triggered for cases where local reconnection request
4689 * is used to force reassociation with the same BSS.
4690 * Try to reconnect to the same BSS without a full scan
4691 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004692 */
4693 fast_reconnect = wpa_s->current_bss;
4694 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004695 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004696 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004697 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004698 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4699 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004700 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004701 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004702 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004703 "try to re-connect");
4704 wpa_s->reassociate = 0;
4705 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004706 if (!wpa_s->pno)
4707 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004708 }
4709 bssid = wpa_s->bssid;
4710 if (is_zero_ether_addr(bssid))
4711 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004712 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004713 wpas_connection_failed(wpa_s, bssid, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004714 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004715 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4716
Dmitry Shmidt04949592012-07-19 12:16:46 -07004717 if (locally_generated)
4718 wpa_s->disconnect_reason = -reason_code;
4719 else
4720 wpa_s->disconnect_reason = reason_code;
4721 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004722 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4723 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004724 wpa_clear_keys(wpa_s, wpa_s->bssid);
4725 }
4726 wpa_supplicant_mark_disassoc(wpa_s);
4727
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004728 if (curr)
4729 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4730
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004731 if (fast_reconnect &&
4732 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4733 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4734 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4735 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004736 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004737 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004738#ifndef CONFIG_NO_SCAN_PROCESSING
4739 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4740 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4741 fast_reconnect_ssid) < 0) {
4742 /* Recover through full scan */
4743 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4744 }
4745#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004746 } else if (fast_reconnect) {
4747 /*
4748 * Could not reconnect to the same BSS due to network being
4749 * disabled. Use a new scan to match the alternative behavior
4750 * above, i.e., to continue automatic reconnection attempt in a
4751 * way that enforces disabled network rules.
4752 */
4753 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004754 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004755}
4756
4757
4758#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004759void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004760{
4761 struct wpa_supplicant *wpa_s = eloop_ctx;
4762
4763 if (!wpa_s->pending_mic_error_report)
4764 return;
4765
4766 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4767 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4768 wpa_s->pending_mic_error_report = 0;
4769}
4770#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4771
4772
4773static void
4774wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4775 union wpa_event_data *data)
4776{
4777 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004778 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004779
4780 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4781 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004782 os_get_reltime(&t);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004783 if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004784 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004785 wpa_s->pending_mic_error_report) {
4786 if (wpa_s->pending_mic_error_report) {
4787 /*
4788 * Send the pending MIC error report immediately since
4789 * we are going to start countermeasures and AP better
4790 * do the same.
4791 */
4792 wpa_sm_key_request(wpa_s->wpa, 1,
4793 wpa_s->pending_mic_error_pairwise);
4794 }
4795
4796 /* Send the new MIC error report immediately since we are going
4797 * to start countermeasures and AP better do the same.
4798 */
4799 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4800
4801 /* initialize countermeasures */
4802 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004803
Hai Shalom60840252021-02-19 19:02:11 -08004804 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004805
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004806 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4807
4808 /*
4809 * Need to wait for completion of request frame. We do not get
4810 * any callback for the message completion, so just wait a
4811 * short while and hope for the best. */
4812 os_sleep(0, 10000);
4813
4814 wpa_drv_set_countermeasures(wpa_s, 1);
4815 wpa_supplicant_deauthenticate(wpa_s,
4816 WLAN_REASON_MICHAEL_MIC_FAILURE);
4817 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4818 wpa_s, NULL);
4819 eloop_register_timeout(60, 0,
4820 wpa_supplicant_stop_countermeasures,
4821 wpa_s, NULL);
4822 /* TODO: mark the AP rejected for 60 second. STA is
4823 * allowed to associate with another AP.. */
4824 } else {
4825#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4826 if (wpa_s->mic_errors_seen) {
4827 /*
4828 * Reduce the effectiveness of Michael MIC error
4829 * reports as a means for attacking against TKIP if
4830 * more than one MIC failure is noticed with the same
4831 * PTK. We delay the transmission of the reports by a
4832 * random time between 0 and 60 seconds in order to
4833 * force the attacker wait 60 seconds before getting
4834 * the information on whether a frame resulted in a MIC
4835 * failure.
4836 */
4837 u8 rval[4];
4838 int sec;
4839
4840 if (os_get_random(rval, sizeof(rval)) < 0)
4841 sec = os_random() % 60;
4842 else
4843 sec = WPA_GET_BE32(rval) % 60;
4844 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4845 "report %d seconds", sec);
4846 wpa_s->pending_mic_error_report = 1;
4847 wpa_s->pending_mic_error_pairwise = pairwise;
4848 eloop_cancel_timeout(
4849 wpa_supplicant_delayed_mic_error_report,
4850 wpa_s, NULL);
4851 eloop_register_timeout(
4852 sec, os_random() % 1000000,
4853 wpa_supplicant_delayed_mic_error_report,
4854 wpa_s, NULL);
4855 } else {
4856 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4857 }
4858#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4859 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4860#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4861 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004862 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004863 wpa_s->mic_errors_seen++;
4864}
4865
4866
4867#ifdef CONFIG_TERMINATE_ONLASTIF
4868static int any_interfaces(struct wpa_supplicant *head)
4869{
4870 struct wpa_supplicant *wpa_s;
4871
4872 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4873 if (!wpa_s->interface_removed)
4874 return 1;
4875 return 0;
4876}
4877#endif /* CONFIG_TERMINATE_ONLASTIF */
4878
4879
4880static void
4881wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4882 union wpa_event_data *data)
4883{
4884 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4885 return;
4886
4887 switch (data->interface_status.ievent) {
4888 case EVENT_INTERFACE_ADDED:
4889 if (!wpa_s->interface_removed)
4890 break;
4891 wpa_s->interface_removed = 0;
4892 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4893 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4894 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4895 "driver after interface was added");
4896 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004897
4898#ifdef CONFIG_P2P
4899 if (!wpa_s->global->p2p &&
4900 !wpa_s->global->p2p_disabled &&
4901 !wpa_s->conf->p2p_disabled &&
4902 (wpa_s->drv_flags &
4903 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4904 wpas_p2p_add_p2pdev_interface(
4905 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4906 wpa_printf(MSG_INFO,
4907 "P2P: Failed to enable P2P Device interface");
4908 /* Try to continue without. P2P will be disabled. */
4909 }
4910#endif /* CONFIG_P2P */
4911
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004912 break;
4913 case EVENT_INTERFACE_REMOVED:
4914 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4915 wpa_s->interface_removed = 1;
4916 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004917 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004918 l2_packet_deinit(wpa_s->l2);
4919 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004920
4921#ifdef CONFIG_P2P
4922 if (wpa_s->global->p2p &&
4923 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4924 (wpa_s->drv_flags &
4925 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4926 wpa_dbg(wpa_s, MSG_DEBUG,
4927 "Removing P2P Device interface");
4928 wpa_supplicant_remove_iface(
4929 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4930 0);
4931 wpa_s->global->p2p_init_wpa_s = NULL;
4932 }
4933#endif /* CONFIG_P2P */
4934
Dmitry Shmidte4663042016-04-04 10:07:49 -07004935#ifdef CONFIG_MATCH_IFACE
4936 if (wpa_s->matched) {
4937 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4938 break;
4939 }
4940#endif /* CONFIG_MATCH_IFACE */
4941
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004942#ifdef CONFIG_TERMINATE_ONLASTIF
4943 /* check if last interface */
4944 if (!any_interfaces(wpa_s->global->ifaces))
4945 eloop_terminate();
4946#endif /* CONFIG_TERMINATE_ONLASTIF */
4947 break;
4948 }
4949}
4950
4951
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004952#ifdef CONFIG_TDLS
4953static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4954 union wpa_event_data *data)
4955{
4956 if (data == NULL)
4957 return;
4958 switch (data->tdls.oper) {
4959 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004960 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4961 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4962 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4963 else
4964 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004965 break;
4966 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004967 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4968 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4969 data->tdls.reason_code);
4970 else
4971 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4972 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004973 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004974 case TDLS_REQUEST_DISCOVER:
4975 wpa_tdls_send_discovery_request(wpa_s->wpa,
4976 data->tdls.peer);
4977 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004978 }
4979}
4980#endif /* CONFIG_TDLS */
4981
4982
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004983#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004984static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4985 union wpa_event_data *data)
4986{
4987 if (data == NULL)
4988 return;
4989 switch (data->wnm.oper) {
4990 case WNM_OPER_SLEEP:
4991 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4992 "(action=%d, intval=%d)",
4993 data->wnm.sleep_action, data->wnm.sleep_intval);
4994 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004995 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004996 break;
4997 }
4998}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004999#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005000
5001
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005002#ifdef CONFIG_IEEE80211R
5003static void
5004wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
5005 union wpa_event_data *data)
5006{
5007 if (data == NULL)
5008 return;
5009
5010 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
5011 data->ft_ies.ies_len,
5012 data->ft_ies.ft_action,
5013 data->ft_ies.target_ap,
5014 data->ft_ies.ric_ies,
5015 data->ft_ies.ric_ies_len) < 0) {
5016 /* TODO: prevent MLME/driver from trying to associate? */
5017 }
5018}
5019#endif /* CONFIG_IEEE80211R */
5020
5021
5022#ifdef CONFIG_IBSS_RSN
5023static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
5024 union wpa_event_data *data)
5025{
5026 struct wpa_ssid *ssid;
5027 if (wpa_s->wpa_state < WPA_ASSOCIATED)
5028 return;
5029 if (data == NULL)
5030 return;
5031 ssid = wpa_s->current_ssid;
5032 if (ssid == NULL)
5033 return;
5034 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5035 return;
5036
5037 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
5038}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005039
5040
5041static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
5042 union wpa_event_data *data)
5043{
5044 struct wpa_ssid *ssid = wpa_s->current_ssid;
5045
5046 if (ssid == NULL)
5047 return;
5048
5049 /* check if the ssid is correctly configured as IBSS/RSN */
5050 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5051 return;
5052
5053 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
5054 data->rx_mgmt.frame_len);
5055}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005056#endif /* CONFIG_IBSS_RSN */
5057
5058
5059#ifdef CONFIG_IEEE80211R
5060static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
5061 size_t len)
5062{
5063 const u8 *sta_addr, *target_ap_addr;
5064 u16 status;
5065
5066 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
5067 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
5068 return; /* only SME case supported for now */
5069 if (len < 1 + 2 * ETH_ALEN + 2)
5070 return;
5071 if (data[0] != 2)
5072 return; /* Only FT Action Response is supported for now */
5073 sta_addr = data + 1;
5074 target_ap_addr = data + 1 + ETH_ALEN;
5075 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
5076 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
5077 MACSTR " TargetAP " MACSTR " status %u",
5078 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
5079
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005080 if (!ether_addr_equal(sta_addr, wpa_s->own_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005081 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
5082 " in FT Action Response", MAC2STR(sta_addr));
5083 return;
5084 }
5085
5086 if (status) {
5087 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
5088 "failure (status code %d)", status);
5089 /* TODO: report error to FT code(?) */
5090 return;
5091 }
5092
5093 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
5094 len - (1 + 2 * ETH_ALEN + 2), 1,
5095 target_ap_addr, NULL, 0) < 0)
5096 return;
5097
5098#ifdef CONFIG_SME
5099 {
5100 struct wpa_bss *bss;
5101 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
5102 if (bss)
5103 wpa_s->sme.freq = bss->freq;
5104 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
5105 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
5106 WLAN_AUTH_FT);
5107 }
5108#endif /* CONFIG_SME */
5109}
5110#endif /* CONFIG_IEEE80211R */
5111
5112
5113static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
5114 struct unprot_deauth *e)
5115{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005116 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
5117 "dropped: " MACSTR " -> " MACSTR
5118 " (reason code %u)",
5119 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5120 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005121}
5122
5123
5124static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
5125 struct unprot_disassoc *e)
5126{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005127 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
5128 "dropped: " MACSTR " -> " MACSTR
5129 " (reason code %u)",
5130 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5131 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005132}
5133
5134
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005135static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
5136 u16 reason_code, int locally_generated,
5137 const u8 *ie, size_t ie_len, int deauth)
5138{
5139#ifdef CONFIG_AP
5140 if (wpa_s->ap_iface && addr) {
5141 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
5142 return;
5143 }
5144
5145 if (wpa_s->ap_iface) {
5146 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
5147 return;
5148 }
5149#endif /* CONFIG_AP */
5150
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005151 if (!locally_generated)
5152 wpa_s->own_disconnect_req = 0;
5153
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005154 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
5155
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005156 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
5157 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
5158 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
5159 eapol_sm_failed(wpa_s->eapol))) &&
5160 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00005161 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005162
5163#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07005164 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005165 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
5166 locally_generated) > 0) {
5167 /*
5168 * The interface was removed, so cannot continue
5169 * processing any additional operations after this.
5170 */
5171 return;
5172 }
5173 }
5174#endif /* CONFIG_P2P */
5175
5176 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
5177 locally_generated);
5178}
5179
5180
5181static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
5182 struct disassoc_info *info)
5183{
5184 u16 reason_code = 0;
5185 int locally_generated = 0;
5186 const u8 *addr = NULL;
5187 const u8 *ie = NULL;
5188 size_t ie_len = 0;
5189
5190 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
5191
5192 if (info) {
5193 addr = info->addr;
5194 ie = info->ie;
5195 ie_len = info->ie_len;
5196 reason_code = info->reason_code;
5197 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005198 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
5199 reason2str(reason_code),
5200 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005201 if (addr)
5202 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5203 MAC2STR(addr));
5204 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
5205 ie, ie_len);
5206 }
5207
5208#ifdef CONFIG_AP
5209 if (wpa_s->ap_iface && info && info->addr) {
5210 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
5211 return;
5212 }
5213
5214 if (wpa_s->ap_iface) {
5215 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
5216 return;
5217 }
5218#endif /* CONFIG_AP */
5219
5220#ifdef CONFIG_P2P
5221 if (info) {
5222 wpas_p2p_disassoc_notif(
5223 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
5224 locally_generated);
5225 }
5226#endif /* CONFIG_P2P */
5227
5228 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5229 sme_event_disassoc(wpa_s, info);
5230
5231 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
5232 ie, ie_len, 0);
5233}
5234
5235
5236static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
5237 struct deauth_info *info)
5238{
5239 u16 reason_code = 0;
5240 int locally_generated = 0;
5241 const u8 *addr = NULL;
5242 const u8 *ie = NULL;
5243 size_t ie_len = 0;
5244
5245 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
5246
5247 if (info) {
5248 addr = info->addr;
5249 ie = info->ie;
5250 ie_len = info->ie_len;
5251 reason_code = info->reason_code;
5252 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005253 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
5254 reason_code, reason2str(reason_code),
5255 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005256 if (addr) {
5257 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5258 MAC2STR(addr));
5259 }
5260 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
5261 ie, ie_len);
5262 }
5263
5264 wpa_reset_ft_completed(wpa_s->wpa);
5265
5266 wpas_event_disconnect(wpa_s, addr, reason_code,
5267 locally_generated, ie, ie_len, 1);
5268}
5269
5270
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005271static const char * reg_init_str(enum reg_change_initiator init)
5272{
5273 switch (init) {
5274 case REGDOM_SET_BY_CORE:
5275 return "CORE";
5276 case REGDOM_SET_BY_USER:
5277 return "USER";
5278 case REGDOM_SET_BY_DRIVER:
5279 return "DRIVER";
5280 case REGDOM_SET_BY_COUNTRY_IE:
5281 return "COUNTRY_IE";
5282 case REGDOM_BEACON_HINT:
5283 return "BEACON_HINT";
5284 }
5285 return "?";
5286}
5287
5288
5289static const char * reg_type_str(enum reg_type type)
5290{
5291 switch (type) {
5292 case REGDOM_TYPE_UNKNOWN:
5293 return "UNKNOWN";
5294 case REGDOM_TYPE_COUNTRY:
5295 return "COUNTRY";
5296 case REGDOM_TYPE_WORLD:
5297 return "WORLD";
5298 case REGDOM_TYPE_CUSTOM_WORLD:
5299 return "CUSTOM_WORLD";
5300 case REGDOM_TYPE_INTERSECTION:
5301 return "INTERSECTION";
5302 }
5303 return "?";
5304}
5305
5306
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005307static void wpas_beacon_hint(struct wpa_supplicant *wpa_s, const char *title,
5308 struct frequency_attrs *attrs)
5309{
5310 if (!attrs->freq)
5311 return;
5312 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_BEACON_HINT
5313 "%s freq=%u max_tx_power=%u%s%s%s",
5314 title, attrs->freq, attrs->max_tx_power,
5315 attrs->disabled ? " disabled=1" : "",
5316 attrs->no_ir ? " no_ir=1" : "",
5317 attrs->radar ? " radar=1" : "");
5318}
5319
5320
Hai Shalom74f70d42019-02-11 14:42:39 -08005321void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
5322 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005323{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005324 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005325 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005326
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005327 /*
5328 * To allow backwards compatibility with higher level layers that
5329 * assumed the REGDOM_CHANGE event is sent over the initially added
5330 * interface. Find the highest parent of this interface and use it to
5331 * send the event.
5332 */
5333 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
5334 ;
5335
Hai Shalom74f70d42019-02-11 14:42:39 -08005336 if (info) {
5337 wpa_msg(ifs, MSG_INFO,
5338 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
5339 reg_init_str(info->initiator), reg_type_str(info->type),
5340 info->alpha2[0] ? " alpha2=" : "",
5341 info->alpha2[0] ? info->alpha2 : "");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005342
5343 if (info->initiator == REGDOM_BEACON_HINT) {
5344 wpas_beacon_hint(ifs, "before",
5345 &info->beacon_hint_before);
5346 wpas_beacon_hint(ifs, "after",
5347 &info->beacon_hint_after);
5348 }
Hai Shalom74f70d42019-02-11 14:42:39 -08005349 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005350
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005351 if (wpa_s->drv_priv == NULL)
5352 return; /* Ignore event during drv initialization */
5353
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005354 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
5355 radio_list) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005356 bool was_6ghz_enabled;
5357
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005358 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
5359 ifs->ifname);
5360 free_hw_features(ifs);
5361 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005362 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005363
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005364 was_6ghz_enabled = ifs->is_6ghz_enabled;
5365 ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5366
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005367 /* Restart PNO/sched_scan with updated channel list */
5368 if (ifs->pno) {
5369 wpas_stop_pno(ifs);
5370 wpas_start_pno(ifs);
5371 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
5372 wpa_dbg(ifs, MSG_DEBUG,
5373 "Channel list changed - restart sched_scan");
5374 wpas_scan_restart_sched_scan(ifs);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005375 } else if (ifs->scanning && !was_6ghz_enabled &&
5376 ifs->is_6ghz_enabled) {
5377 /* Look for APs in the 6 GHz band */
5378 wpa_dbg(ifs, MSG_INFO,
5379 "Channel list changed - trigger 6 GHz-only scan");
5380 ifs->crossed_6ghz_dom = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005381 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005382 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005383
5384 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005385}
5386
5387
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005388static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005389 const u8 *frame, size_t len, int freq,
5390 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005391{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005392 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005393 const u8 *payload;
5394 size_t plen;
5395 u8 category;
5396
5397 if (len < IEEE80211_HDRLEN + 2)
5398 return;
5399
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005400 mgmt = (const struct ieee80211_mgmt *) frame;
5401 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005402 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005403 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005404
5405 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
5406 " Category=%u DataLen=%d freq=%d MHz",
5407 MAC2STR(mgmt->sa), category, (int) plen, freq);
5408
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005409#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005410 if (category == WLAN_ACTION_WMM) {
5411 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5412 return;
5413 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005414#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005415
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005416#ifdef CONFIG_IEEE80211R
5417 if (category == WLAN_ACTION_FT) {
5418 ft_rx_action(wpa_s, payload, plen);
5419 return;
5420 }
5421#endif /* CONFIG_IEEE80211R */
5422
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005423#ifdef CONFIG_SME
5424 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005425 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005426 return;
5427 }
5428#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005429
5430#ifdef CONFIG_WNM
5431 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
5432 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
5433 return;
5434 }
5435#endif /* CONFIG_WNM */
5436
5437#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08005438 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5439 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005440 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08005441 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005442 payload, plen, freq) == 0)
5443 return;
5444#endif /* CONFIG_GAS */
5445
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005446#ifdef CONFIG_GAS_SERVER
5447 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5448 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
5449 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
5450 mgmt->u.action.category,
5451 payload, plen, freq) == 0)
5452 return;
5453#endif /* CONFIG_GAS_SERVER */
5454
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005455#ifdef CONFIG_TDLS
5456 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
5457 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
5458 wpa_dbg(wpa_s, MSG_DEBUG,
5459 "TDLS: Received Discovery Response from " MACSTR,
5460 MAC2STR(mgmt->sa));
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005461 if (wpa_s->valid_links &&
5462 wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa,
5463 &payload[1], plen - 1))
5464 wpa_dbg(wpa_s, MSG_ERROR,
5465 "TDLS: Discovery Response process failed for "
5466 MACSTR, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005467 return;
5468 }
5469#endif /* CONFIG_TDLS */
5470
5471#ifdef CONFIG_INTERWORKING
5472 if (category == WLAN_ACTION_QOS && plen >= 1 &&
5473 payload[0] == QOS_QOS_MAP_CONFIG) {
5474 const u8 *pos = payload + 1;
5475 size_t qlen = plen - 1;
5476 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
5477 MACSTR, MAC2STR(mgmt->sa));
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005478 if (ether_addr_equal(mgmt->sa, wpa_s->bssid) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005479 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
5480 pos[1] <= qlen - 2 && pos[1] >= 16)
5481 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
5482 return;
5483 }
5484#endif /* CONFIG_INTERWORKING */
5485
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005486#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005487 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005488 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5489 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005490 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005491 payload + 1,
5492 plen - 1);
5493 return;
5494 }
5495
5496 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005497 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
5498 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
5499 return;
5500 }
5501
5502 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5503 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
5504 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
5505 payload + 1, plen - 1,
5506 rssi);
5507 return;
5508 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005509#endif /* CONFIG_NO_RRM */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005510
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005511#ifdef CONFIG_FST
5512 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
5513 fst_rx_action(wpa_s->fst, mgmt, len);
5514 return;
5515 }
5516#endif /* CONFIG_FST */
5517
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005518#ifdef CONFIG_NAN_USD
5519 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5520 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5521 WPA_GET_BE32(&payload[1]) == NAN_SDF_VENDOR_TYPE) {
5522 payload += 5;
5523 plen -= 5;
5524 wpas_nan_usd_rx_sdf(wpa_s, mgmt->sa, freq, payload, plen);
5525 return;
5526 }
5527#endif /* CONFIG_NAN_USD */
5528
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005529#ifdef CONFIG_DPP
5530 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5531 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5532 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
5533 payload[4] == DPP_OUI_TYPE) {
5534 payload++;
5535 plen--;
5536 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
5537 return;
5538 }
5539#endif /* CONFIG_DPP */
5540
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005541#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07005542 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08005543 payload[0] == ROBUST_AV_SCS_RESP) {
5544 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
5545 payload + 1, plen - 1);
5546 return;
5547 }
5548
5549 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005550 payload[0] == ROBUST_AV_MSCS_RESP) {
5551 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5552 payload + 1, plen - 1);
5553 return;
5554 }
5555
Hai Shalomc1a21442022-02-04 13:43:00 -08005556 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
5557 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
5558 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
5559 payload + 4, plen - 4);
5560 return;
5561 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005562#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08005563
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005564 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5565 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005566 if (wpa_s->ifmsh)
5567 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005568}
5569
5570
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005571static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5572 union wpa_event_data *event)
5573{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005574 struct wpa_freq_range_list *list;
5575 char *str = NULL;
5576
5577 list = &event->freq_range;
5578
5579 if (list->num)
5580 str = freq_range_list_str(list);
5581 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5582 str ? str : "");
5583
5584#ifdef CONFIG_P2P
5585 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5586 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5587 __func__);
5588 } else {
5589 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005590
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005591 /*
5592 * The update channel flow will also take care of moving a GO
5593 * from the unsafe frequency if needed.
5594 */
5595 wpas_p2p_update_channel_list(wpa_s,
5596 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005597 }
5598#endif /* CONFIG_P2P */
5599
5600 os_free(str);
5601}
5602
5603
Roshan Pius3a1667e2018-07-03 15:17:14 -07005604static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005605{
Sunil Ravi167279a2023-05-31 01:12:34 +00005606 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005607 wpa_supplicant_cancel_auth_timeout(wpa_s);
5608 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005609 eapol_sm_notify_portValid(wpa_s->eapol, true);
5610 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005611 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005612 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005613}
5614
5615
5616static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5617 int freq)
5618{
5619 size_t i;
5620 int j;
5621
5622 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5623 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5624
5625 for (j = 0; j < mode->num_channels; j++) {
5626 const struct hostapd_channel_data *chan;
5627
5628 chan = &mode->channels[j];
5629 if (chan->freq == freq)
5630 return chan->dfs_cac_ms;
5631 }
5632 }
5633
5634 return 0;
5635}
5636
5637
5638static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5639 struct dfs_event *radar)
5640{
5641#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005642 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005643 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5644 } else
5645#endif /* NEED_AP_MLME && CONFIG_AP */
5646 {
5647 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5648
5649 cac_time /= 1000; /* convert from ms to sec */
5650 if (!cac_time)
5651 cac_time = 10 * 60; /* max timeout: 10 minutes */
5652
5653 /* Restart auth timeout: CAC time added to initial timeout */
5654 wpas_auth_timeout_restart(wpa_s, cac_time);
5655 }
5656}
5657
5658
5659static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5660 struct dfs_event *radar)
5661{
5662#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005663 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005664 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5665 } else
5666#endif /* NEED_AP_MLME && CONFIG_AP */
5667 {
5668 /* Restart auth timeout with original value after CAC is
5669 * finished */
5670 wpas_auth_timeout_restart(wpa_s, 0);
5671 }
5672}
5673
5674
5675static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5676 struct dfs_event *radar)
5677{
5678#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005679 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005680 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5681 } else
5682#endif /* NEED_AP_MLME && CONFIG_AP */
5683 {
5684 /* Restart auth timeout with original value after CAC is
5685 * aborted */
5686 wpas_auth_timeout_restart(wpa_s, 0);
5687 }
5688}
5689
5690
5691static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5692 union wpa_event_data *data)
5693{
5694 wpa_dbg(wpa_s, MSG_DEBUG,
5695 "Connection authorized by device, previous state %d",
5696 wpa_s->wpa_state);
5697
5698 wpa_supplicant_event_port_authorized(wpa_s);
5699
Hai Shalomc1a21442022-02-04 13:43:00 -08005700 wpa_s->last_eapol_matches_bssid = 1;
5701
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005702 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5703 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005704 data->assoc_info.ptk_kck_len,
5705 data->assoc_info.ptk_kek,
5706 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005707#ifdef CONFIG_FILS
5708 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5709 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5710 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5711
5712 /* Update ERP next sequence number */
5713 eapol_sm_update_erp_next_seq_num(
5714 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5715
5716 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5717 /* Add the new PMK and PMKID to the PMKSA cache */
5718 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5719 data->assoc_info.fils_pmk,
5720 data->assoc_info.fils_pmk_len,
5721 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005722 wpa_s->valid_links ?
5723 wpa_s->ap_mld_addr :
5724 wpa_s->bssid,
5725 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005726 } else if (data->assoc_info.fils_pmkid) {
5727 /* Update the current PMKSA used for this connection */
5728 pmksa_cache_set_current(wpa_s->wpa,
5729 data->assoc_info.fils_pmkid,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005730 NULL, NULL, 0, NULL, 0, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005731 }
5732 }
5733#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005734}
5735
5736
Hai Shalom60840252021-02-19 19:02:11 -08005737static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5738{
5739 switch (code) {
5740 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5741 return "";
5742 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5743 return "no_bss_found";
5744 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5745 return "auth_tx_fail";
5746 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5747 return "auth_no_ack_received";
5748 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5749 return "auth_no_resp_received";
5750 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5751 return "assoc_req_tx_fail";
5752 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5753 return "assoc_no_ack_received";
5754 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5755 return "assoc_no_resp_received";
5756 default:
5757 return "unknown_reason";
5758 }
5759}
5760
5761
Roshan Pius3a1667e2018-07-03 15:17:14 -07005762static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5763 union wpa_event_data *data)
5764{
5765 const u8 *bssid = data->assoc_reject.bssid;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005766 struct ieee802_11_elems elems;
5767 const u8 *link_bssids[MAX_NUM_MLD_LINKS];
Hai Shalom81f62d82019-07-22 12:10:00 -07005768#ifdef CONFIG_MBO
5769 struct wpa_bss *reject_bss;
5770#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005771
5772 if (!bssid || is_zero_ether_addr(bssid))
5773 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005774#ifdef CONFIG_MBO
5775 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5776 reject_bss = wpa_s->current_bss;
5777 else
5778 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5779#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005780
5781 if (data->assoc_reject.bssid)
5782 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005783 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005784 MAC2STR(data->assoc_reject.bssid),
5785 data->assoc_reject.status_code,
5786 data->assoc_reject.timed_out ? " timeout" : "",
5787 data->assoc_reject.timeout_reason ? "=" : "",
5788 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005789 data->assoc_reject.timeout_reason : "",
5790 data->assoc_reject.reason_code !=
5791 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5792 " qca_driver_reason=" : "",
5793 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005794 else
5795 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005796 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005797 data->assoc_reject.status_code,
5798 data->assoc_reject.timed_out ? " timeout" : "",
5799 data->assoc_reject.timeout_reason ? "=" : "",
5800 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005801 data->assoc_reject.timeout_reason : "",
5802 data->assoc_reject.reason_code !=
5803 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5804 " qca_driver_reason=" : "",
5805 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005806 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005807 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5808 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005809
5810#ifdef CONFIG_OWE
5811 if (data->assoc_reject.status_code ==
5812 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5813 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5814 wpa_s->current_ssid &&
5815 wpa_s->current_ssid->owe_group == 0 &&
5816 wpa_s->last_owe_group != 21) {
5817 struct wpa_ssid *ssid = wpa_s->current_ssid;
5818 struct wpa_bss *bss = wpa_s->current_bss;
5819
5820 if (!bss) {
5821 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5822 if (!bss) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005823 wpas_connection_failed(wpa_s, bssid, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005824 wpa_supplicant_mark_disassoc(wpa_s);
5825 return;
5826 }
5827 }
5828 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5829 wpas_connect_work_done(wpa_s);
5830 wpa_supplicant_mark_disassoc(wpa_s);
5831 wpa_supplicant_connect(wpa_s, bss, ssid);
5832 return;
5833 }
5834#endif /* CONFIG_OWE */
5835
Hai Shalomfdcde762020-04-02 11:19:20 -07005836#ifdef CONFIG_DPP2
5837 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5838 * the status code defined in the DPP R2 tech spec.
5839 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5840 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005841 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005842 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5843 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5844 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005845 wpa_s->current_ssid->dpp_pfs == 0 &&
5846 (data->assoc_reject.status_code ==
5847 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5848 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5849 struct wpa_ssid *ssid = wpa_s->current_ssid;
5850 struct wpa_bss *bss = wpa_s->current_bss;
5851
5852 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5853 if (!bss)
5854 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5855 if (!bss || wpa_s->dpp_pfs_fallback) {
5856 wpa_printf(MSG_DEBUG,
5857 "DPP: Updated PFS policy for next try");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005858 wpas_connection_failed(wpa_s, bssid, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07005859 wpa_supplicant_mark_disassoc(wpa_s);
5860 return;
5861 }
5862 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5863 wpa_s->dpp_pfs_fallback = 1;
5864 wpas_connect_work_done(wpa_s);
5865 wpa_supplicant_mark_disassoc(wpa_s);
5866 wpa_supplicant_connect(wpa_s, bss, ssid);
5867 return;
5868 }
5869#endif /* CONFIG_DPP2 */
5870
Hai Shalom74f70d42019-02-11 14:42:39 -08005871#ifdef CONFIG_MBO
5872 if (data->assoc_reject.status_code ==
5873 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005874 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005875 const u8 *rssi_rej;
5876
5877 rssi_rej = mbo_get_attr_from_ies(
5878 data->assoc_reject.resp_ies,
5879 data->assoc_reject.resp_ies_len,
5880 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5881 if (rssi_rej && rssi_rej[1] == 2) {
5882 wpa_printf(MSG_DEBUG,
5883 "OCE: RSSI-based association rejection from "
5884 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005885 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005886 rssi_rej[2], rssi_rej[3]);
5887 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005888 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005889 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005890 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005891 }
5892 }
5893#endif /* CONFIG_MBO */
5894
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005895 /* Check for other failed links in the response */
5896 os_memset(link_bssids, 0, sizeof(link_bssids));
5897 if (ieee802_11_parse_elems(data->assoc_reject.resp_ies,
5898 data->assoc_reject.resp_ies_len,
5899 &elems, 1) != ParseFailed) {
5900 struct ml_sta_link_info ml_info[MAX_NUM_MLD_LINKS];
5901 unsigned int n_links, i, idx;
5902
5903 idx = 0;
5904 n_links = wpas_ml_parse_assoc(wpa_s, &elems, ml_info);
5905
5906 for (i = 1; i < n_links; i++) {
5907 /* The status cannot be success here.
5908 * Add the link to the failed list if it is reporting
5909 * an error. The only valid "non-error" status is
5910 * TX_LINK_NOT_ACCEPTED as that means this link may
5911 * still accept an association from us.
5912 */
5913 if (ml_info[i].status !=
5914 WLAN_STATUS_DENIED_TX_LINK_NOT_ACCEPTED) {
5915 link_bssids[idx] = ml_info[i].bssid;
5916 idx++;
5917 }
5918 }
5919 }
5920
Roshan Pius3a1667e2018-07-03 15:17:14 -07005921 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005922 sme_event_assoc_reject(wpa_s, data, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005923 return;
5924 }
5925
5926 /* Driver-based SME cases */
5927
5928#ifdef CONFIG_SAE
5929 if (wpa_s->current_ssid &&
5930 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5931 !data->assoc_reject.timed_out) {
5932 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5933 wpa_sm_aborted_cached(wpa_s->wpa);
5934 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5935 }
5936#endif /* CONFIG_SAE */
5937
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005938#ifdef CONFIG_DPP
5939 if (wpa_s->current_ssid &&
5940 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5941 !data->assoc_reject.timed_out) {
5942 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5943 wpa_sm_aborted_cached(wpa_s->wpa);
5944 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5945 }
5946#endif /* CONFIG_DPP */
5947
Roshan Pius3a1667e2018-07-03 15:17:14 -07005948#ifdef CONFIG_FILS
5949 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005950 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005951 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005952 eapol_sm_update_erp_next_seq_num(
5953 wpa_s->eapol,
5954 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005955 fils_connection_failure(wpa_s);
5956 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005957#endif /* CONFIG_FILS */
5958
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005959 wpas_connection_failed(wpa_s, bssid, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005960 wpa_supplicant_mark_disassoc(wpa_s);
5961}
5962
5963
Hai Shalomfdcde762020-04-02 11:19:20 -07005964static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5965 struct unprot_beacon *data)
5966{
5967 struct wpabuf *buf;
5968 int res;
5969
5970 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005971 !ether_addr_equal(data->sa, wpa_s->bssid))
Hai Shalomfdcde762020-04-02 11:19:20 -07005972 return;
5973 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5974 MAC2STR(data->sa));
5975
5976 buf = wpabuf_alloc(4);
5977 if (!buf)
5978 return;
5979
5980 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5981 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5982 wpabuf_put_u8(buf, 1); /* Dialog Token */
5983 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5984
5985 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5986 wpa_s->own_addr, wpa_s->bssid,
5987 wpabuf_head(buf), wpabuf_len(buf), 0);
5988 if (res < 0)
5989 wpa_printf(MSG_DEBUG,
5990 "Failed to send WNM-Notification Request frame");
5991
5992 wpabuf_free(buf);
5993}
5994
5995
Sunil Ravi640215c2023-06-28 23:08:09 +00005996static const char * bitmap_to_str(u8 value, char *buf)
5997{
5998 char *pos = buf;
5999 int i, k = 0;
6000
6001 for (i = 7; i >= 0; i--)
6002 pos[k++] = (value & BIT(i)) ? '1' : '0';
6003
6004 pos[8] = '\0';
6005 return pos;
6006}
6007
6008
6009static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
6010 struct tid_link_map_info *info)
6011{
6012 char map_info[1000], *pos, *end;
6013 int res, i;
6014
6015 pos = map_info;
6016 end = pos + sizeof(map_info);
6017 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
6018 info->default_map);
6019 if (os_snprintf_error(end - pos, res))
6020 return;
6021 pos += res;
6022
6023 if (!info->default_map) {
Sunil Ravi88611412024-06-28 17:34:56 +00006024 for (i = 0; i < MAX_NUM_MLD_LINKS && end > pos; i++) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006025 char uplink_map_str[9];
6026 char downlink_map_str[9];
6027
Sunil Ravi88611412024-06-28 17:34:56 +00006028 if (!(info->valid_links & BIT(i)))
6029 continue;
6030
Sunil Ravi640215c2023-06-28 23:08:09 +00006031 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
6032 bitmap_to_str(info->t2lmap[i].downlink,
6033 downlink_map_str);
6034
6035 res = os_snprintf(pos, end - pos,
6036 " link_id=%d up_link=%s down_link=%s",
6037 i, uplink_map_str,
6038 downlink_map_str);
6039 if (os_snprintf_error(end - pos, res))
6040 return;
6041 pos += res;
6042 }
6043 }
6044
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306045 wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP);
Sunil Ravi640215c2023-06-28 23:08:09 +00006046 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
6047}
6048
6049
6050static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
6051{
6052 u8 bssid[ETH_ALEN];
6053
6054 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
6055 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
6056 wpa_supplicant_deauthenticate(wpa_s,
6057 WLAN_REASON_DEAUTH_LEAVING);
6058 return;
6059 }
6060
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006061 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006062 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
6063 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
6064 wpas_notify_bssid_changed(wpa_s);
6065 }
6066
6067 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
6068 wpa_printf(MSG_ERROR,
6069 "LINK_RECONFIG: Failed to get MLO connection info");
6070 wpa_supplicant_deauthenticate(wpa_s,
6071 WLAN_REASON_DEAUTH_LEAVING);
6072 return;
6073 }
6074
6075 if (wpa_sm_set_ml_info(wpa_s)) {
6076 wpa_printf(MSG_ERROR,
6077 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
6078 wpa_supplicant_deauthenticate(wpa_s,
6079 WLAN_REASON_DEAUTH_LEAVING);
6080 return;
6081 }
6082
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306083 wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL);
Sunil Ravi640215c2023-06-28 23:08:09 +00006084 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
6085 wpa_s->valid_links);
6086}
6087
6088
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006089void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
6090 union wpa_event_data *data)
6091{
6092 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006093 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07006094 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08006095#ifndef CONFIG_NO_STDOUT_DEBUG
6096 int level = MSG_DEBUG;
6097#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006098
6099 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
6100 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006101 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006102 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006103 event != EVENT_SCHED_SCAN_STOPPED) {
6104 wpa_dbg(wpa_s, MSG_DEBUG,
6105 "Ignore event %s (%d) while interface is disabled",
6106 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006107 return;
6108 }
6109
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006110#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07006111 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006112 const struct ieee80211_hdr *hdr;
6113 u16 fc;
6114 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
6115 fc = le_to_host16(hdr->frame_control);
6116 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
6117 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
6118 level = MSG_EXCESSIVE;
6119 }
6120
6121 wpa_dbg(wpa_s, level, "Event %s (%d) received",
6122 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006123#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006124
6125 switch (event) {
6126 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006127#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08006128 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
6129 data->auth.ies_len))
6130 wpa_printf(MSG_DEBUG,
6131 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006132#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006133 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006134 wpa_s->auth_status_code = data->auth.status_code;
6135 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006136 break;
6137 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006138#ifdef CONFIG_TESTING_OPTIONS
6139 if (wpa_s->ignore_auth_resp) {
6140 wpa_printf(MSG_INFO,
6141 "EVENT_ASSOC - ignore_auth_resp active!");
6142 break;
6143 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006144 if (wpa_s->testing_resend_assoc) {
6145 wpa_printf(MSG_INFO,
6146 "EVENT_DEAUTH - testing_resend_assoc");
6147 break;
6148 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006149#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05306150 if (wpa_s->disconnected) {
6151 wpa_printf(MSG_INFO,
6152 "Ignore unexpected EVENT_ASSOC in disconnected state");
6153 break;
6154 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006155 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006156 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006157 if (data &&
6158 (data->assoc_info.authorized ||
6159 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6160 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006161 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006162 if (data) {
6163 wpa_msg(wpa_s, MSG_INFO,
6164 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
6165 data->assoc_info.subnet_status);
6166 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006167 break;
6168 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006169 wpas_event_disassoc(wpa_s,
6170 data ? &data->disassoc_info : NULL);
6171 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006172 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006173#ifdef CONFIG_TESTING_OPTIONS
6174 if (wpa_s->ignore_auth_resp) {
6175 wpa_printf(MSG_INFO,
6176 "EVENT_DEAUTH - ignore_auth_resp active!");
6177 break;
6178 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006179 if (wpa_s->testing_resend_assoc) {
6180 wpa_printf(MSG_INFO,
6181 "EVENT_DEAUTH - testing_resend_assoc");
6182 break;
6183 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006184#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006185 wpas_event_deauth(wpa_s,
6186 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006187 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00006188 case EVENT_LINK_RECONFIG:
6189 wpas_link_reconfig(wpa_s);
6190 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006191 case EVENT_MICHAEL_MIC_FAILURE:
6192 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
6193 break;
6194#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006195 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006196 if (wpa_s->own_scan_requested ||
6197 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006198 struct os_reltime diff;
6199
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006200 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006201 os_reltime_sub(&wpa_s->scan_start_time,
6202 &wpa_s->scan_trigger_time, &diff);
6203 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
6204 diff.sec, diff.usec);
6205 wpa_s->own_scan_requested = 0;
6206 wpa_s->own_scan_running = 1;
6207 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
6208 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006209 wpa_msg_ctrl(wpa_s, MSG_INFO,
6210 WPA_EVENT_SCAN_STARTED "id=%u",
6211 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006212 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006213 wpa_msg_ctrl(wpa_s, MSG_INFO,
6214 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006215 }
6216 } else {
6217 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08006218 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006219 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006220 }
6221 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006222 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006223 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6224 wpa_s->scan_res_handler = NULL;
6225 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08006226 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006227 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
6228 break;
6229 }
6230
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006231 if (!(data && data->scan_info.external_scan) &&
6232 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006233 struct os_reltime now, diff;
6234 os_get_reltime(&now);
6235 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
6236 wpa_s->scan_start_time.sec = 0;
6237 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00006238 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006239 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
6240 diff.sec, diff.usec);
6241 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006242 if (wpa_supplicant_event_scan_results(wpa_s, data))
6243 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006244 if (!(data && data->scan_info.external_scan))
6245 wpa_s->own_scan_running = 0;
6246 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08006247 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006248 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006249 break;
6250#endif /* CONFIG_NO_SCAN_PROCESSING */
6251 case EVENT_ASSOCINFO:
6252 wpa_supplicant_event_associnfo(wpa_s, data);
6253 break;
6254 case EVENT_INTERFACE_STATUS:
6255 wpa_supplicant_event_interface_status(wpa_s, data);
6256 break;
6257 case EVENT_PMKID_CANDIDATE:
6258 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
6259 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006260#ifdef CONFIG_TDLS
6261 case EVENT_TDLS:
6262 wpa_supplicant_event_tdls(wpa_s, data);
6263 break;
6264#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006265#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006266 case EVENT_WNM:
6267 wpa_supplicant_event_wnm(wpa_s, data);
6268 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006269#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006270#ifdef CONFIG_IEEE80211R
6271 case EVENT_FT_RESPONSE:
6272 wpa_supplicant_event_ft_response(wpa_s, data);
6273 break;
6274#endif /* CONFIG_IEEE80211R */
6275#ifdef CONFIG_IBSS_RSN
6276 case EVENT_IBSS_RSN_START:
6277 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
6278 break;
6279#endif /* CONFIG_IBSS_RSN */
6280 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07006281 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006282 break;
6283 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006284 /* It is possible to get this event from earlier connection */
6285 if (wpa_s->current_ssid &&
6286 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6287 wpa_dbg(wpa_s, MSG_DEBUG,
6288 "Ignore AUTH_TIMED_OUT in mesh configuration");
6289 break;
6290 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006291 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6292 sme_event_auth_timed_out(wpa_s, data);
6293 break;
6294 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006295 /* It is possible to get this event from earlier connection */
6296 if (wpa_s->current_ssid &&
6297 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6298 wpa_dbg(wpa_s, MSG_DEBUG,
6299 "Ignore ASSOC_TIMED_OUT in mesh configuration");
6300 break;
6301 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006302 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6303 sme_event_assoc_timed_out(wpa_s, data);
6304 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006305 case EVENT_TX_STATUS:
6306 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
6307 " type=%d stype=%d",
6308 MAC2STR(data->tx_status.dst),
6309 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08006310#ifdef CONFIG_PASN
6311 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6312 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6313 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
6314 data->tx_status.data_len,
6315 data->tx_status.ack) == 0)
6316 break;
6317#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006318#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006319 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006320#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006321 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6322 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006323 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006324 wpa_s, data->tx_status.dst,
6325 data->tx_status.data,
6326 data->tx_status.data_len,
6327 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006328 OFFCHANNEL_SEND_ACTION_SUCCESS :
6329 OFFCHANNEL_SEND_ACTION_NO_ACK);
6330#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006331 break;
6332 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006333#endif /* CONFIG_AP */
6334#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006335 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006336 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006337 /*
6338 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006339 * interface in GO mode, or via standalone AP interface.
6340 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
6341 * except when the primary interface is used as a GO interface
6342 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006343 */
6344 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6345 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006346 ether_addr_equal(wpa_s->p2pdev->pending_action_dst,
6347 data->tx_status.dst)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006348 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006349 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006350 data->tx_status.data,
6351 data->tx_status.data_len,
6352 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006353 OFFCHANNEL_SEND_ACTION_SUCCESS :
6354 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006355 break;
6356 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006357#endif /* CONFIG_OFFCHANNEL */
6358#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006359 switch (data->tx_status.type) {
6360 case WLAN_FC_TYPE_MGMT:
6361 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
6362 data->tx_status.data_len,
6363 data->tx_status.stype,
6364 data->tx_status.ack);
6365 break;
6366 case WLAN_FC_TYPE_DATA:
6367 ap_tx_status(wpa_s, data->tx_status.dst,
6368 data->tx_status.data,
6369 data->tx_status.data_len,
6370 data->tx_status.ack);
6371 break;
6372 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006373#endif /* CONFIG_AP */
6374 break;
6375#ifdef CONFIG_AP
6376 case EVENT_EAPOL_TX_STATUS:
6377 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
6378 data->eapol_tx_status.data,
6379 data->eapol_tx_status.data_len,
6380 data->eapol_tx_status.ack);
6381 break;
6382 case EVENT_DRIVER_CLIENT_POLL_OK:
6383 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006384 break;
6385 case EVENT_RX_FROM_UNKNOWN:
6386 if (wpa_s->ap_iface == NULL)
6387 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006388 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
6389 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006390 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006391#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07006392
Sunil Ravi89eba102022-09-13 21:04:37 -07006393 case EVENT_LINK_CH_SWITCH_STARTED:
6394 case EVENT_LINK_CH_SWITCH:
6395 if (!data || !wpa_s->current_ssid ||
6396 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6397 break;
6398
6399 wpa_msg(wpa_s, MSG_INFO,
6400 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6401 event == EVENT_LINK_CH_SWITCH ?
6402 WPA_EVENT_LINK_CHANNEL_SWITCH :
6403 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6404 data->ch_switch.freq,
6405 data->ch_switch.link_id,
6406 data->ch_switch.ht_enabled,
6407 data->ch_switch.ch_offset,
6408 channel_width_to_string(data->ch_switch.ch_width),
6409 data->ch_switch.cf1,
6410 data->ch_switch.cf2);
6411 if (event == EVENT_LINK_CH_SWITCH_STARTED)
6412 break;
6413
6414 wpa_s->links[data->ch_switch.link_id].freq =
6415 data->ch_switch.freq;
6416 if (wpa_s->links[data->ch_switch.link_id].bss &&
6417 wpa_s->links[data->ch_switch.link_id].bss->freq !=
6418 data->ch_switch.freq) {
6419 wpa_s->links[data->ch_switch.link_id].bss->freq =
6420 data->ch_switch.freq;
6421 notify_bss_changes(
6422 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6423 wpa_s->links[data->ch_switch.link_id].bss);
Shuibing Dai0db6bb12023-09-28 17:53:17 -07006424 if (data->ch_switch.freq)
6425 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
Sunil Ravi89eba102022-09-13 21:04:37 -07006426 }
6427 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07006428 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07006429 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006430 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006431 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006432
Hai Shalom81f62d82019-07-22 12:10:00 -07006433 wpa_msg(wpa_s, MSG_INFO,
6434 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6435 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6436 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006437 data->ch_switch.freq,
6438 data->ch_switch.ht_enabled,
6439 data->ch_switch.ch_offset,
6440 channel_width_to_string(data->ch_switch.ch_width),
6441 data->ch_switch.cf1,
6442 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07006443 if (event == EVENT_CH_SWITCH_STARTED)
6444 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006445
Sunil Ravi65a724b2022-05-24 11:06:09 -07006446 if (wpa_s->assoc_freq && data->ch_switch.freq &&
6447 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
6448 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
6449 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006450 wpa_s->assoc_freq = data->ch_switch.freq;
6451 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08006452 if (wpa_s->current_bss &&
6453 wpa_s->current_bss->freq != data->ch_switch.freq) {
6454 wpa_s->current_bss->freq = data->ch_switch.freq;
6455 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6456 wpa_s->current_bss);
6457 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006458
Hai Shalomfdcde762020-04-02 11:19:20 -07006459#ifdef CONFIG_SME
6460 switch (data->ch_switch.ch_offset) {
6461 case 1:
6462 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6463 break;
6464 case -1:
6465 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6466 break;
6467 default:
6468 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6469 break;
6470 }
6471#endif /* CONFIG_SME */
6472
Roshan Pius3a1667e2018-07-03 15:17:14 -07006473#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006474 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6475 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08006476 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006477 wpa_s->current_ssid->mode ==
6478 WPAS_MODE_P2P_GROUP_FORMATION) {
6479 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6480 data->ch_switch.ht_enabled,
6481 data->ch_switch.ch_offset,
6482 data->ch_switch.ch_width,
6483 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006484 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07006485 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07006486 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006487 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006488#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006489
Hai Shalom899fcc72020-10-19 14:38:18 -07006490 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6491 sme_event_ch_switch(wpa_s);
6492
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006493 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006494 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006495 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006496#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006497#ifdef NEED_AP_MLME
6498 case EVENT_DFS_RADAR_DETECTED:
6499 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07006500 wpas_ap_event_dfs_radar_detected(wpa_s,
6501 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006502 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006503 case EVENT_DFS_NOP_FINISHED:
6504 if (data)
6505 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
6506 &data->dfs_event);
6507 break;
6508#endif /* NEED_AP_MLME */
6509#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006510 case EVENT_DFS_CAC_STARTED:
6511 if (data)
6512 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
6513 break;
6514 case EVENT_DFS_CAC_FINISHED:
6515 if (data)
6516 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
6517 break;
6518 case EVENT_DFS_CAC_ABORTED:
6519 if (data)
6520 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
6521 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006522 case EVENT_RX_MGMT: {
6523 u16 fc, stype;
6524 const struct ieee80211_mgmt *mgmt;
6525
Dmitry Shmidt818ea482014-03-10 13:15:21 -07006526#ifdef CONFIG_TESTING_OPTIONS
6527 if (wpa_s->ext_mgmt_frame_handling) {
6528 struct rx_mgmt *rx = &data->rx_mgmt;
6529 size_t hex_len = 2 * rx->frame_len + 1;
6530 char *hex = os_malloc(hex_len);
6531 if (hex) {
6532 wpa_snprintf_hex(hex, hex_len,
6533 rx->frame, rx->frame_len);
6534 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
6535 rx->freq, rx->datarate, rx->ssi_signal,
6536 hex);
6537 os_free(hex);
6538 }
6539 break;
6540 }
6541#endif /* CONFIG_TESTING_OPTIONS */
6542
Dmitry Shmidt04949592012-07-19 12:16:46 -07006543 mgmt = (const struct ieee80211_mgmt *)
6544 data->rx_mgmt.frame;
6545 fc = le_to_host16(mgmt->frame_control);
6546 stype = WLAN_FC_GET_STYPE(fc);
6547
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006548#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006549 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006550#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006551#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006552 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006553 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006554 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07006555 const u8 *ie;
6556 size_t ie_len;
6557
6558 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6559 ie_len = data->rx_mgmt.frame_len -
6560 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006561 wpas_p2p_probe_req_rx(
6562 wpa_s, src, mgmt->da,
6563 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006564 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006565 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006566 break;
6567 }
6568#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006569#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006570 if (wpa_s->current_ssid &&
6571 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
6572 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006573 data->rx_mgmt.frame_len >= 30) {
6574 wpa_supplicant_event_ibss_auth(wpa_s, data);
6575 break;
6576 }
6577#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006578
6579 if (stype == WLAN_FC_STYPE_ACTION) {
6580 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07006581 wpa_s, data->rx_mgmt.frame,
6582 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006583 data->rx_mgmt.freq,
6584 data->rx_mgmt.ssi_signal);
6585 break;
6586 }
6587
6588 if (wpa_s->ifmsh) {
6589 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006590 break;
6591 }
Hai Shalom60840252021-02-19 19:02:11 -08006592#ifdef CONFIG_PASN
6593 if (stype == WLAN_FC_STYPE_AUTH &&
6594 wpas_pasn_auth_rx(wpa_s, mgmt,
6595 data->rx_mgmt.frame_len) != -2)
6596 break;
6597#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006598
Roshan Pius3a1667e2018-07-03 15:17:14 -07006599#ifdef CONFIG_SAE
6600 if (stype == WLAN_FC_STYPE_AUTH &&
6601 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6602 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6603 sme_external_auth_mgmt_rx(
6604 wpa_s, data->rx_mgmt.frame,
6605 data->rx_mgmt.frame_len);
6606 break;
6607 }
6608#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006609 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6610 "management frame in non-AP mode");
6611 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006612#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006613 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006614
6615 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006616 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6617 const u8 *ie;
6618 size_t ie_len;
6619
6620 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6621 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006622
6623 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6624 mgmt->bssid, ie, ie_len,
6625 data->rx_mgmt.ssi_signal);
6626 }
6627
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006628 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006629#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006630 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006631 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006632 case EVENT_RX_PROBE_REQ:
6633 if (data->rx_probe_req.sa == NULL ||
6634 data->rx_probe_req.ie == NULL)
6635 break;
6636#ifdef CONFIG_AP
6637 if (wpa_s->ap_iface) {
6638 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6639 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006640 data->rx_probe_req.da,
6641 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006642 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006643 data->rx_probe_req.ie_len,
6644 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006645 break;
6646 }
6647#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006648 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006649 data->rx_probe_req.da,
6650 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006651 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006652 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006653 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006654 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006655 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006656 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006657#ifdef CONFIG_OFFCHANNEL
6658 offchannel_remain_on_channel_cb(
6659 wpa_s, data->remain_on_channel.freq,
6660 data->remain_on_channel.duration);
6661#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006662 wpas_p2p_remain_on_channel_cb(
6663 wpa_s, data->remain_on_channel.freq,
6664 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006665#ifdef CONFIG_DPP
6666 wpas_dpp_remain_on_channel_cb(
6667 wpa_s, data->remain_on_channel.freq,
6668 data->remain_on_channel.duration);
6669#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006670#ifdef CONFIG_NAN_USD
6671 wpas_nan_usd_remain_on_channel_cb(
6672 wpa_s, data->remain_on_channel.freq,
6673 data->remain_on_channel.duration);
6674#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006675 break;
6676 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006677#ifdef CONFIG_OFFCHANNEL
6678 offchannel_cancel_remain_on_channel_cb(
6679 wpa_s, data->remain_on_channel.freq);
6680#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006681 wpas_p2p_cancel_remain_on_channel_cb(
6682 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006683#ifdef CONFIG_DPP
6684 wpas_dpp_cancel_remain_on_channel_cb(
6685 wpa_s, data->remain_on_channel.freq);
6686#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006687#ifdef CONFIG_NAN_USD
6688 wpas_nan_usd_cancel_remain_on_channel_cb(
6689 wpa_s, data->remain_on_channel.freq);
6690#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006691 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006692 case EVENT_EAPOL_RX:
6693 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6694 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00006695 data->eapol_rx.data_len,
6696 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006697 break;
6698 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006699 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00006700 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006701 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006702 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006703 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006704 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006705 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006706 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006707 bgscan_notify_signal_change(
6708 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006709 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006710 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006711 data->signal_change.data.current_tx_rate);
6712 os_memcpy(&wpa_s->last_signal_info, data,
6713 sizeof(struct wpa_signal_info));
6714 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006715 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006716 case EVENT_INTERFACE_MAC_CHANGED:
6717 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006718 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006719 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006720 case EVENT_INTERFACE_ENABLED:
6721 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6722 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006723 u8 addr[ETH_ALEN];
6724
Hai Shalomfdcde762020-04-02 11:19:20 -07006725 eloop_cancel_timeout(wpas_clear_disabled_interface,
6726 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08006727 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006728 wpa_supplicant_update_mac_addr(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006729 if (!ether_addr_equal(addr, wpa_s->own_addr))
Hai Shalomc1a21442022-02-04 13:43:00 -08006730 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6731 else
6732 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07006733 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006734 if (wpa_s->p2p_mgmt) {
6735 wpa_supplicant_set_state(wpa_s,
6736 WPA_DISCONNECTED);
6737 break;
6738 }
6739
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006740#ifdef CONFIG_AP
6741 if (!wpa_s->ap_iface) {
6742 wpa_supplicant_set_state(wpa_s,
6743 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006744 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006745 wpa_supplicant_req_scan(wpa_s, 0, 0);
6746 } else
6747 wpa_supplicant_set_state(wpa_s,
6748 WPA_COMPLETED);
6749#else /* CONFIG_AP */
6750 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6751 wpa_supplicant_req_scan(wpa_s, 0, 0);
6752#endif /* CONFIG_AP */
6753 }
6754 break;
6755 case EVENT_INTERFACE_DISABLED:
6756 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006757#ifdef CONFIG_P2P
6758 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6759 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6760 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6761 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006762 * Mark interface disabled if this happens to end up not
6763 * being removed as a separate P2P group interface.
6764 */
6765 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6766 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006767 * The interface was externally disabled. Remove
6768 * it assuming an external entity will start a
6769 * new session if needed.
6770 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006771 if (wpa_s->current_ssid &&
6772 wpa_s->current_ssid->p2p_group)
6773 wpas_p2p_interface_unavailable(wpa_s);
6774 else
6775 wpas_p2p_disconnect(wpa_s);
6776 /*
6777 * wpa_s instance may have been freed, so must not use
6778 * it here anymore.
6779 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006780 break;
6781 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006782 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6783 p2p_in_progress(wpa_s->global->p2p) > 1) {
6784 /* This radio work will be cancelled, so clear P2P
6785 * state as well.
6786 */
6787 p2p_stop_find(wpa_s->global->p2p);
6788 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006789#endif /* CONFIG_P2P */
6790
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006791 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6792 /*
6793 * Indicate disconnection to keep ctrl_iface events
6794 * consistent.
6795 */
6796 wpa_supplicant_event_disassoc(
6797 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6798 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006799 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07006800 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08006801 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6802 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006803 clear_at.usec = 0;
6804 } else {
6805 struct os_reltime tmp;
6806
Hai Shalom60840252021-02-19 19:02:11 -08006807 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006808 tmp.usec = 0;
6809 os_reltime_sub(&tmp, &age, &clear_at);
6810 }
6811 eloop_register_timeout(clear_at.sec, clear_at.usec,
6812 wpas_clear_disabled_interface,
6813 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08006814 radio_remove_works(wpa_s, NULL, 0);
6815
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006816 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6817 break;
6818 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006819 wpa_supplicant_update_channel_list(
6820 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006821 break;
6822 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006823 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006824 break;
6825 case EVENT_BEST_CHANNEL:
6826 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6827 "(%d %d %d)",
6828 data->best_chan.freq_24, data->best_chan.freq_5,
6829 data->best_chan.freq_overall);
6830 wpa_s->best_24_freq = data->best_chan.freq_24;
6831 wpa_s->best_5_freq = data->best_chan.freq_5;
6832 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006833 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6834 data->best_chan.freq_5,
6835 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006836 break;
6837 case EVENT_UNPROT_DEAUTH:
6838 wpa_supplicant_event_unprot_deauth(wpa_s,
6839 &data->unprot_deauth);
6840 break;
6841 case EVENT_UNPROT_DISASSOC:
6842 wpa_supplicant_event_unprot_disassoc(wpa_s,
6843 &data->unprot_disassoc);
6844 break;
6845 case EVENT_STATION_LOW_ACK:
6846#ifdef CONFIG_AP
6847 if (wpa_s->ap_iface && data)
6848 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6849 data->low_ack.addr);
6850#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006851#ifdef CONFIG_TDLS
6852 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07006853 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
6854 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006855#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006856 break;
6857 case EVENT_IBSS_PEER_LOST:
6858#ifdef CONFIG_IBSS_RSN
6859 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6860#endif /* CONFIG_IBSS_RSN */
6861 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006862 case EVENT_DRIVER_GTK_REKEY:
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006863 if (!ether_addr_equal(data->driver_gtk_rekey.bssid,
6864 wpa_s->bssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006865 break;
6866 if (!wpa_s->wpa)
6867 break;
6868 wpa_sm_update_replay_ctr(wpa_s->wpa,
6869 data->driver_gtk_rekey.replay_ctr);
6870 break;
6871 case EVENT_SCHED_SCAN_STOPPED:
6872 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006873 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006874 wpa_supplicant_notify_scanning(wpa_s, 0);
6875
6876 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6877 break;
6878
6879 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006880 * If the driver stopped scanning without being requested to,
6881 * request a new scan to continue scanning for networks.
6882 */
6883 if (!wpa_s->sched_scan_stop_req &&
6884 wpa_s->wpa_state == WPA_SCANNING) {
6885 wpa_dbg(wpa_s, MSG_DEBUG,
6886 "Restart scanning after unexpected sched_scan stop event");
6887 wpa_supplicant_req_scan(wpa_s, 1, 0);
6888 break;
6889 }
6890
6891 wpa_s->sched_scan_stop_req = 0;
6892
6893 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006894 * Start a new sched scan to continue searching for more SSIDs
6895 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006896 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006897 if (wpa_s->sched_scan_timed_out) {
6898 wpa_supplicant_req_sched_scan(wpa_s);
6899 } else if (wpa_s->pno_sched_pending) {
6900 wpa_s->pno_sched_pending = 0;
6901 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006902 } else if (resched) {
6903 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006904 }
6905
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006906 break;
6907 case EVENT_WPS_BUTTON_PUSHED:
6908#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006909 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006910#endif /* CONFIG_WPS */
6911 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006912 case EVENT_AVOID_FREQUENCIES:
6913 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6914 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006915 case EVENT_CONNECT_FAILED_REASON:
6916#ifdef CONFIG_AP
6917 if (!wpa_s->ap_iface || !data)
6918 break;
6919 hostapd_event_connect_failed_reason(
6920 wpa_s->ap_iface->bss[0],
6921 data->connect_failed_reason.addr,
6922 data->connect_failed_reason.code);
6923#endif /* CONFIG_AP */
6924 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006925 case EVENT_NEW_PEER_CANDIDATE:
6926#ifdef CONFIG_MESH
6927 if (!wpa_s->ifmsh || !data)
6928 break;
6929 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6930 data->mesh_peer.ies,
6931 data->mesh_peer.ie_len);
6932#endif /* CONFIG_MESH */
6933 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006934 case EVENT_SURVEY:
6935#ifdef CONFIG_AP
6936 if (!wpa_s->ap_iface)
6937 break;
6938 hostapd_event_get_survey(wpa_s->ap_iface,
6939 &data->survey_results);
6940#endif /* CONFIG_AP */
6941 break;
6942 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006943#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006944#ifdef CONFIG_ACS
6945 if (!wpa_s->ap_iface)
6946 break;
6947 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6948 &data->acs_selected_channels);
6949#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006950#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006951 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006952 case EVENT_P2P_LO_STOP:
6953#ifdef CONFIG_P2P
6954 wpa_s->p2p_lo_started = 0;
6955 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6956 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6957 data->p2p_lo_stop.reason_code);
6958#endif /* CONFIG_P2P */
6959 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006960 case EVENT_BEACON_LOSS:
6961 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6962 break;
6963 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6964 bgscan_notify_beacon_loss(wpa_s);
6965 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006966 case EVENT_EXTERNAL_AUTH:
6967#ifdef CONFIG_SAE
6968 if (!wpa_s->current_ssid) {
6969 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6970 break;
6971 }
6972 sme_external_auth_trigger(wpa_s, data);
6973#endif /* CONFIG_SAE */
6974 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006975#ifdef CONFIG_PASN
6976 case EVENT_PASN_AUTH:
6977 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6978 break;
6979#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006980 case EVENT_PORT_AUTHORIZED:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006981#ifdef CONFIG_AP
6982 if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
6983 struct sta_info *sta;
6984
6985 sta = ap_get_sta(wpa_s->ap_iface->bss[0],
6986 data->port_authorized.sta_addr);
6987 if (sta)
6988 ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
6989 sta, 1);
6990 else
6991 wpa_printf(MSG_DEBUG,
6992 "No STA info matching port authorized event found");
6993 break;
6994 }
6995#endif /* CONFIG_AP */
Sunil Ravi77d572f2023-01-17 23:58:31 +00006996#ifndef CONFIG_NO_WPA
6997 if (data->port_authorized.td_bitmap_len) {
6998 wpa_printf(MSG_DEBUG,
6999 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
7000 data->port_authorized.td_bitmap[0]);
7001 wpas_transition_disable(
7002 wpa_s, data->port_authorized.td_bitmap[0]);
7003 }
7004#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007005 wpa_supplicant_event_port_authorized(wpa_s);
7006 break;
7007 case EVENT_STATION_OPMODE_CHANGED:
7008#ifdef CONFIG_AP
7009 if (!wpa_s->ap_iface || !data)
7010 break;
7011
7012 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
7013 data->sta_opmode.addr,
7014 data->sta_opmode.smps_mode,
7015 data->sta_opmode.chan_width,
7016 data->sta_opmode.rx_nss);
7017#endif /* CONFIG_AP */
7018 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07007019 case EVENT_UNPROT_BEACON:
7020 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
7021 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08007022 case EVENT_TX_WAIT_EXPIRE:
7023#ifdef CONFIG_DPP
7024 wpas_dpp_tx_wait_expire(wpa_s);
7025#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007026#ifdef CONFIG_NAN_USD
7027 wpas_nan_usd_tx_wait_expire(wpa_s);
7028#endif /* CONFIG_NAN_USD */
Hai Shalomc1a21442022-02-04 13:43:00 -08007029 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00007030 case EVENT_TID_LINK_MAP:
7031 if (data)
7032 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
7033 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007034 default:
7035 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
7036 break;
7037 }
7038}
Dmitry Shmidte4663042016-04-04 10:07:49 -07007039
7040
7041void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
7042 union wpa_event_data *data)
7043{
7044 struct wpa_supplicant *wpa_s;
7045
7046 if (event != EVENT_INTERFACE_STATUS)
7047 return;
7048
7049 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
7050 if (wpa_s && wpa_s->driver->get_ifindex) {
7051 unsigned int ifindex;
7052
7053 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
7054 if (ifindex != data->interface_status.ifindex) {
7055 wpa_dbg(wpa_s, MSG_DEBUG,
7056 "interface status ifindex %d mismatch (%d)",
7057 ifindex, data->interface_status.ifindex);
7058 return;
7059 }
7060 }
7061#ifdef CONFIG_MATCH_IFACE
7062 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
7063 struct wpa_interface *wpa_i;
7064
7065 wpa_i = wpa_supplicant_match_iface(
7066 ctx, data->interface_status.ifname);
7067 if (!wpa_i)
7068 return;
7069 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
7070 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07007071 }
7072#endif /* CONFIG_MATCH_IFACE */
7073
7074 if (wpa_s)
7075 wpa_supplicant_event(wpa_s, event, data);
7076}