blob: 09a2bbb5f2a557828df76c4fca270175a909c80d [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
Sunil Ravi7f769292024-07-23 22:21:32 +0000141static struct wpa_bss * __wpa_supplicant_get_new_bss(
142 struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *ssid,
143 size_t ssid_len)
144{
145 if (ssid && ssid_len > 0)
146 return wpa_bss_get(wpa_s, bssid, ssid, ssid_len);
147 else
148 return wpa_bss_get_bssid(wpa_s, bssid);
149}
150
151
152static struct wpa_bss * _wpa_supplicant_get_new_bss(
153 struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *ssid,
154 size_t ssid_len, bool try_update_scan_results)
155{
156 struct wpa_bss *bss = __wpa_supplicant_get_new_bss(wpa_s, bssid, ssid,
157 ssid_len);
158
159 if (bss || !try_update_scan_results)
160 return bss;
161
162 wpa_supplicant_update_scan_results(wpa_s, bssid);
163
164 return __wpa_supplicant_get_new_bss(wpa_s, bssid, ssid, ssid_len);
165}
166
167
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800168static struct wpa_bss * wpa_supplicant_get_new_bss(
169 struct wpa_supplicant *wpa_s, const u8 *bssid)
170{
171 struct wpa_bss *bss = NULL;
172 struct wpa_ssid *ssid = wpa_s->current_ssid;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000173 u8 drv_ssid[SSID_MAX_LEN];
174 int res;
Sunil Ravi7f769292024-07-23 22:21:32 +0000175 bool try_update_scan_results = true;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800176
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000177 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
Sunil Ravi7f769292024-07-23 22:21:32 +0000178 if (res > 0) {
179 bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, drv_ssid, res,
180 try_update_scan_results);
181 try_update_scan_results = false;
182 }
183 if (!bss && ssid && ssid->ssid_len > 0) {
184 bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, ssid->ssid,
185 ssid->ssid_len,
186 try_update_scan_results);
187 try_update_scan_results = false;
188 }
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800189 if (!bss)
Sunil Ravi7f769292024-07-23 22:21:32 +0000190 bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, NULL, 0,
191 try_update_scan_results);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800192
193 return bss;
194}
195
196
Sunil Ravia04bd252022-05-02 22:54:18 -0700197static struct wpa_bss *
198wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700199{
Sunil Ravia04bd252022-05-02 22:54:18 -0700200 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700201
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700202 if (bss)
203 wpa_s->current_bss = bss;
Sunil Ravia04bd252022-05-02 22:54:18 -0700204
205 return bss;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700206}
207
208
Sunil Ravi89eba102022-09-13 21:04:37 -0700209static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
210 u8 link_id, const u8 *bssid)
211{
212 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
213
Sunil Ravi89eba102022-09-13 21:04:37 -0700214 if (bss)
215 wpa_s->links[link_id].bss = bss;
216}
217
218
Sunil Ravi77d572f2023-01-17 23:58:31 +0000219static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
220 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221{
222 struct wpa_ssid *ssid, *old_ssid;
Sunil Ravi640215c2023-06-28 23:08:09 +0000223 struct wpa_bss *bss;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700224 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700225 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700226 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700228 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700229 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700230
231 if (wpa_s->current_ssid->ssid_len == 0)
232 return 0; /* current profile still in use */
233 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
234 if (res < 0) {
235 wpa_msg(wpa_s, MSG_INFO,
236 "Failed to read SSID from driver");
237 return 0; /* try to use current profile */
238 }
239 drv_ssid_len = res;
240
241 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
242 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
243 drv_ssid_len) == 0)
244 return 0; /* current profile still in use */
245
Hai Shalomfdcde762020-04-02 11:19:20 -0700246#ifdef CONFIG_OWE
247 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
248 wpa_s->current_bss &&
249 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
250 drv_ssid_len == wpa_s->current_bss->ssid_len &&
251 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
252 drv_ssid_len) == 0)
253 return 0; /* current profile still in use */
254#endif /* CONFIG_OWE */
255
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700256 wpa_msg(wpa_s, MSG_DEBUG,
257 "Driver-initiated BSS selection changed the SSID to %s",
258 wpa_ssid_txt(drv_ssid, drv_ssid_len));
259 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700260 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700261
262 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
263 "information");
264 ssid = wpa_supplicant_get_ssid(wpa_s);
265 if (ssid == NULL) {
266 wpa_msg(wpa_s, MSG_INFO,
267 "No network configuration found for the current AP");
268 return -1;
269 }
270
Dmitry Shmidt04949592012-07-19 12:16:46 -0700271 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
273 return -1;
274 }
275
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800276 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
277 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
278 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
279 return -1;
280 }
281
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700282 res = wpas_temp_disabled(wpa_s, ssid);
283 if (res > 0) {
284 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
285 "disabled for %d second(s)", res);
286 return -1;
287 }
288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
290 "current AP");
Sunil Ravi640215c2023-06-28 23:08:09 +0000291 bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800292 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700293 u8 wpa_ie[80];
294 size_t wpa_ie_len = sizeof(wpa_ie);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000295 bool skip_default_rsne;
296
297 /* Do not override RSNE/RSNXE with the default values if the
298 * driver indicated the actual values used in the
299 * (Re)Association Request frame. */
300 skip_default_rsne = data && data->assoc_info.req_ies;
Sunil Ravi640215c2023-06-28 23:08:09 +0000301 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000302 wpa_ie, &wpa_ie_len,
303 skip_default_rsne) < 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800304 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 } else {
306 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
307 }
308
309 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
310 eapol_sm_invalidate_cached_session(wpa_s->eapol);
311 old_ssid = wpa_s->current_ssid;
312 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800313
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
315 wpa_supplicant_initiate_eapol(wpa_s);
316 if (old_ssid != wpa_s->current_ssid)
317 wpas_notify_network_changed(wpa_s);
318
319 return 0;
320}
321
322
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800323void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324{
325 struct wpa_supplicant *wpa_s = eloop_ctx;
326
327 if (wpa_s->countermeasures) {
328 wpa_s->countermeasures = 0;
329 wpa_drv_set_countermeasures(wpa_s, 0);
330 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800331
332 /*
333 * It is possible that the device is sched scanning, which means
334 * that a connection attempt will be done only when we receive
335 * scan results. However, in this case, it would be preferable
336 * to scan and connect immediately, so cancel the sched_scan and
337 * issue a regular scan flow.
338 */
339 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340 wpa_supplicant_req_scan(wpa_s, 0, 0);
341 }
342}
343
344
Sunil Ravi77d572f2023-01-17 23:58:31 +0000345void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
Sunil Ravi89eba102022-09-13 21:04:37 -0700346{
Sunil Ravi89eba102022-09-13 21:04:37 -0700347 if (!wpa_s->valid_links)
348 return;
349
350 wpa_s->valid_links = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000351 wpa_s->mlo_assoc_link_id = 0;
352 os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN);
353 os_memset(wpa_s->links, 0, sizeof(wpa_s->links));
Sunil Ravi89eba102022-09-13 21:04:37 -0700354}
355
356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
358{
359 int bssid_changed;
360
Dmitry Shmidt04949592012-07-19 12:16:46 -0700361 wnm_bss_keep_alive_deinit(wpa_s);
362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363#ifdef CONFIG_IBSS_RSN
364 ibss_rsn_deinit(wpa_s->ibss_rsn);
365 wpa_s->ibss_rsn = NULL;
366#endif /* CONFIG_IBSS_RSN */
367
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700368#ifdef CONFIG_AP
369 wpa_supplicant_ap_deinit(wpa_s);
370#endif /* CONFIG_AP */
371
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700372#ifdef CONFIG_HS20
373 /* Clear possibly configured frame filters */
374 wpa_drv_configure_frame_filters(wpa_s, 0);
375#endif /* CONFIG_HS20 */
376
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
378 return;
379
Hai Shalom74f70d42019-02-11 14:42:39 -0800380 if (os_reltime_initialized(&wpa_s->session_start)) {
381 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
382 wpa_s->session_start.sec = 0;
383 wpa_s->session_start.usec = 0;
384 wpas_notify_session_length(wpa_s);
385 }
386
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700387 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
388 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
389 os_memset(wpa_s->bssid, 0, ETH_ALEN);
390 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800391 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392 wpa_s->current_bss = NULL;
393 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700394
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700395 if (bssid_changed)
396 wpas_notify_bssid_changed(wpa_s);
397
Hai Shalome21d4e82020-04-29 16:34:06 -0700398 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
399 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700400 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
401 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700402 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700403 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700404 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700406 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700407 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700408 wpa_s->key_mgmt = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700409 wpa_s->allowed_key_mgmts = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800410
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000411#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800412 wpas_rrm_reset(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000413#endif /* CONFIG_NO_RRM */
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800414 wpa_s->wnmsleep_used = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000415#ifdef CONFIG_WNM
416 wpa_s->wnm_mode = 0;
417#endif /* CONFIG_WNM */
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800418 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700419 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700420
421#ifdef CONFIG_TESTING_OPTIONS
422 wpa_s->last_tk_alg = WPA_ALG_NONE;
423 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
424#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700425 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800426
427 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
428 wpa_s->enabled_4addr_mode = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700429
Sunil Ravi77d572f2023-01-17 23:58:31 +0000430 wpa_s->wps_scan_done = false;
Sunil Ravi89eba102022-09-13 21:04:37 -0700431 wpas_reset_mlo_info(wpa_s);
Sunil Ravi7f769292024-07-23 22:21:32 +0000432
433#ifdef CONFIG_SME
434 wpa_s->sme.bss_max_idle_period = 0;
435#endif /* CONFIG_SME */
436
437 wpa_s->ssid_verified = false;
438 wpa_s->bigtk_set = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700439}
440
441
Sunil Ravi036cec52023-03-29 11:35:17 -0700442static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700443{
444 struct wpa_ie_data ie;
445 int pmksa_set = -1;
446 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800447 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700448
Hai Shalomc1a21442022-02-04 13:43:00 -0800449 /* Start with assumption of no PMKSA cache entry match for cases other
450 * than SAE. In particular, this is needed to generate the PMKSA cache
451 * entries for Suite B cases with driver-based roaming indication. */
452 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
453 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
454 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700455
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700456 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
457 ie.pmkid == NULL)
458 return;
459
460 for (i = 0; i < ie.num_pmkid; i++) {
461 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
462 ie.pmkid + i * PMKID_LEN,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000463 NULL, NULL, 0, NULL, 0,
464 true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700465 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800466 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Sunil Ravi036cec52023-03-29 11:35:17 -0700467 if (authorized)
468 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700469 break;
470 }
471 }
472
473 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
474 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
475}
476
477
478static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
479 union wpa_event_data *data)
480{
481 if (data == NULL) {
482 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
483 "event");
484 return;
485 }
486 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
487 " index=%d preauth=%d",
488 MAC2STR(data->pmkid_candidate.bssid),
489 data->pmkid_candidate.index,
490 data->pmkid_candidate.preauth);
491
492 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
493 data->pmkid_candidate.index,
494 data->pmkid_candidate.preauth);
495}
496
497
498static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
499{
500 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
501 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
502 return 0;
503
504#ifdef IEEE8021X_EAPOL
505 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
506 wpa_s->current_ssid &&
507 !(wpa_s->current_ssid->eapol_flags &
508 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
509 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
510 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
511 * plaintext or static WEP keys). */
512 return 0;
513 }
514#endif /* IEEE8021X_EAPOL */
515
516 return 1;
517}
518
519
520/**
521 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
522 * @wpa_s: pointer to wpa_supplicant data
523 * @ssid: Configuration data for the network
524 * Returns: 0 on success, -1 on failure
525 *
526 * This function is called when starting authentication with a network that is
527 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
528 */
529int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
530 struct wpa_ssid *ssid)
531{
532#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700534 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700536 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
537 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538 return 0;
539
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700540 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541 sim = 1;
542 aka = 1;
543 } else {
544 struct eap_method_type *eap = ssid->eap.eap_methods;
545 while (eap->vendor != EAP_VENDOR_IETF ||
546 eap->method != EAP_TYPE_NONE) {
547 if (eap->vendor == EAP_VENDOR_IETF) {
548 if (eap->method == EAP_TYPE_SIM)
549 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700550 else if (eap->method == EAP_TYPE_AKA ||
551 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552 aka = 1;
553 }
554 eap++;
555 }
556 }
557
558 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
559 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700560 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
561 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
562 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563 aka = 0;
564
565 if (!sim && !aka) {
566 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
567 "use SIM, but neither EAP-SIM nor EAP-AKA are "
568 "enabled");
569 return 0;
570 }
571
572 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
573 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700575 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576 if (wpa_s->scard == NULL) {
577 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
578 "(pcsc-lite)");
579 return -1;
580 }
581 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
582 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800583#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584#endif /* IEEE8021X_EAPOL */
585
586 return 0;
587}
588
589
590#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700591
Hai Shalomfdcde762020-04-02 11:19:20 -0700592#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700593static int has_wep_key(struct wpa_ssid *ssid)
594{
595 int i;
596
597 for (i = 0; i < NUM_WEP_KEYS; i++) {
598 if (ssid->wep_key_len[i])
599 return 1;
600 }
601
602 return 0;
603}
Hai Shalomfdcde762020-04-02 11:19:20 -0700604#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700605
606
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700607static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700608 struct wpa_ssid *ssid)
609{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700610 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700611
612 if (ssid->mixed_cell)
613 return 1;
614
615#ifdef CONFIG_WPS
616 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
617 return 1;
618#endif /* CONFIG_WPS */
619
Roshan Pius3a1667e2018-07-03 15:17:14 -0700620#ifdef CONFIG_OWE
621 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
622 return 1;
623#endif /* CONFIG_OWE */
624
Hai Shalomfdcde762020-04-02 11:19:20 -0700625#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700626 if (has_wep_key(ssid))
627 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700628#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700629
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700630#ifdef IEEE8021X_EAPOL
631 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
632 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
633 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
634 privacy = 1;
635#endif /* IEEE8021X_EAPOL */
636
Jouni Malinen75ecf522011-06-27 15:19:46 -0700637 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
638 privacy = 1;
639
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800640 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
641 privacy = 1;
642
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643 if (bss->caps & IEEE80211_CAP_PRIVACY)
644 return privacy;
645 return !privacy;
646}
647
648
649static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
650 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800651 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652{
653 struct wpa_ie_data ie;
654 int proto_match = 0;
655 const u8 *rsn_ie, *wpa_ie;
656 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700657#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700659#endif /* CONFIG_WEP */
Sunil Ravi640215c2023-06-28 23:08:09 +0000660 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661
662 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
663 if (ret >= 0)
664 return ret;
665
Hai Shalomfdcde762020-04-02 11:19:20 -0700666#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
668 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
669 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
670 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
671 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700672#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673
Sunil Ravi7f769292024-07-23 22:21:32 +0000674 rsn_ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
Sunil Ravi640215c2023-06-28 23:08:09 +0000675 if (is_6ghz_bss && !rsn_ie) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700676 if (debug_print)
677 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000678 " skip - 6 GHz BSS without RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700679 return 0;
680 }
681
Roshan Pius3a1667e2018-07-03 15:17:14 -0700682 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683 proto_match++;
684
685 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800686 if (debug_print)
687 wpa_dbg(wpa_s, MSG_DEBUG,
688 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689 break;
690 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700691 if (!ie.has_pairwise)
692 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
693 if (!ie.has_group)
694 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695
Sunil Ravi640215c2023-06-28 23:08:09 +0000696 if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
697 /* WEP and TKIP are not allowed on 6 GHz/MLD */
Sunil Ravia04bd252022-05-02 22:54:18 -0700698 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
699 WPA_CIPHER_WEP104 |
700 WPA_CIPHER_TKIP);
701 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
702 WPA_CIPHER_WEP104 |
703 WPA_CIPHER_TKIP);
704 }
705
Hai Shalomfdcde762020-04-02 11:19:20 -0700706#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707 if (wep_ok &&
708 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
709 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800710 if (debug_print)
711 wpa_dbg(wpa_s, MSG_DEBUG,
712 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700713 return 1;
714 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700715#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700716
Roshan Pius3a1667e2018-07-03 15:17:14 -0700717 if (!(ie.proto & ssid->proto) &&
718 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800719 if (debug_print)
720 wpa_dbg(wpa_s, MSG_DEBUG,
721 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722 break;
723 }
724
725 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800726 if (debug_print)
727 wpa_dbg(wpa_s, MSG_DEBUG,
728 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729 break;
730 }
731
732 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800733 if (debug_print)
734 wpa_dbg(wpa_s, MSG_DEBUG,
735 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700736 break;
737 }
738
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700739 if (ssid->group_mgmt_cipher &&
740 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
741 if (debug_print)
742 wpa_dbg(wpa_s, MSG_DEBUG,
743 " skip RSN IE - group mgmt cipher mismatch");
744 break;
745 }
746
Sunil Ravi640215c2023-06-28 23:08:09 +0000747 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700748 /* MFPC must be supported on 6 GHz */
749 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
750 if (debug_print)
751 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000752 " skip RSNE - 6 GHz without MFPC");
Sunil Ravia04bd252022-05-02 22:54:18 -0700753 break;
754 }
755
756 /* WPA PSK is not allowed on the 6 GHz band */
757 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
758 WPA_KEY_MGMT_FT_PSK |
759 WPA_KEY_MGMT_PSK_SHA256);
760 }
761
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800763 if (debug_print)
764 wpa_dbg(wpa_s, MSG_DEBUG,
765 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 break;
767 }
768
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800770 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800771 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800772 if (debug_print)
773 wpa_dbg(wpa_s, MSG_DEBUG,
774 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775 break;
776 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800777 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
778 wpas_get_ssid_pmf(wpa_s, ssid) ==
779 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800780 if (debug_print)
781 wpa_dbg(wpa_s, MSG_DEBUG,
782 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800783 break;
784 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800786 if (debug_print)
787 wpa_dbg(wpa_s, MSG_DEBUG,
788 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789 return 1;
790 }
791
Sunil Ravi640215c2023-06-28 23:08:09 +0000792 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700793 if (debug_print)
794 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000795 " skip - 6 GHz BSS without matching RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700796 return 0;
797 }
798
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000799 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
800
Roshan Pius3a1667e2018-07-03 15:17:14 -0700801 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
802 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000803#ifdef CONFIG_OWE
804 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && ssid->owe_only &&
805 !wpa_ie && !rsn_ie &&
806 wpa_s->owe_transition_select &&
807 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
808 ssid->owe_transition_bss_select_count + 1 <=
809 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
810 ssid->owe_transition_bss_select_count++;
811 if (debug_print)
812 wpa_dbg(wpa_s, MSG_DEBUG,
813 " skip OWE open BSS (selection count %d does not exceed %d)",
814 ssid->owe_transition_bss_select_count,
815 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
816 wpa_s->owe_transition_search = 1;
817 return 0;
818 }
819#endif /* CONFIG_OWE */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800820 if (debug_print)
821 wpa_dbg(wpa_s, MSG_DEBUG,
822 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700823 return 0;
824 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700825
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700826 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
827 proto_match++;
828
829 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800830 if (debug_print)
831 wpa_dbg(wpa_s, MSG_DEBUG,
832 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833 break;
834 }
835
Hai Shalomfdcde762020-04-02 11:19:20 -0700836#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837 if (wep_ok &&
838 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
839 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800840 if (debug_print)
841 wpa_dbg(wpa_s, MSG_DEBUG,
842 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843 return 1;
844 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700845#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846
847 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800848 if (debug_print)
849 wpa_dbg(wpa_s, MSG_DEBUG,
850 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851 break;
852 }
853
854 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800855 if (debug_print)
856 wpa_dbg(wpa_s, MSG_DEBUG,
857 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858 break;
859 }
860
861 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800862 if (debug_print)
863 wpa_dbg(wpa_s, MSG_DEBUG,
864 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700865 break;
866 }
867
868 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800869 if (debug_print)
870 wpa_dbg(wpa_s, MSG_DEBUG,
871 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 break;
873 }
874
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800875 if (debug_print)
876 wpa_dbg(wpa_s, MSG_DEBUG,
877 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700878 return 1;
879 }
880
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700881 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
882 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800883 if (debug_print)
884 wpa_dbg(wpa_s, MSG_DEBUG,
885 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700886 return 1;
887 }
888
Roshan Pius3a1667e2018-07-03 15:17:14 -0700889#ifdef CONFIG_OWE
890 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
891 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800892 if (wpa_s->owe_transition_select &&
893 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
894 ssid->owe_transition_bss_select_count + 1 <=
895 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
896 ssid->owe_transition_bss_select_count++;
897 if (debug_print)
898 wpa_dbg(wpa_s, MSG_DEBUG,
899 " skip OWE transition BSS (selection count %d does not exceed %d)",
900 ssid->owe_transition_bss_select_count,
901 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
902 wpa_s->owe_transition_search = 1;
903 return 0;
904 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700905 if (debug_print)
906 wpa_dbg(wpa_s, MSG_DEBUG,
907 " allow in OWE transition mode");
908 return 1;
909 }
910#endif /* CONFIG_OWE */
911
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
913 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800914 if (debug_print)
915 wpa_dbg(wpa_s, MSG_DEBUG,
916 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917 return 0;
918 }
919
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800920 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
921 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800922 if (debug_print)
923 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800924 return 1;
925 }
926
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700927 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800928 if (debug_print)
929 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700930 return 1;
931 }
932
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800933 if (debug_print)
934 wpa_dbg(wpa_s, MSG_DEBUG,
935 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936
937 return 0;
938}
939
940
941static int freq_allowed(int *freqs, int freq)
942{
943 int i;
944
945 if (freqs == NULL)
946 return 1;
947
948 for (i = 0; freqs[i]; i++)
949 if (freqs[i] == freq)
950 return 1;
951 return 0;
952}
953
954
Hai Shalomfdcde762020-04-02 11:19:20 -0700955static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
956 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800957{
958 const struct hostapd_hw_modes *mode = NULL, *modes;
959 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
960 const u8 *rate_ie;
961 int i, j, k;
962
963 if (bss->freq == 0)
964 return 1; /* Cannot do matching without knowing band */
965
966 modes = wpa_s->hw.modes;
967 if (modes == NULL) {
968 /*
969 * The driver does not provide any additional information
970 * about the utilized hardware, so allow the connection attempt
971 * to continue.
972 */
973 return 1;
974 }
975
976 for (i = 0; i < wpa_s->hw.num_modes; i++) {
977 for (j = 0; j < modes[i].num_channels; j++) {
978 int freq = modes[i].channels[j].freq;
979 if (freq == bss->freq) {
980 if (mode &&
981 mode->mode == HOSTAPD_MODE_IEEE80211G)
982 break; /* do not allow 802.11b replace
983 * 802.11g */
984 mode = &modes[i];
985 break;
986 }
987 }
988 }
989
990 if (mode == NULL)
991 return 0;
992
993 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700994 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800995 if (rate_ie == NULL)
996 continue;
997
998 for (j = 2; j < rate_ie[1] + 2; j++) {
999 int flagged = !!(rate_ie[j] & 0x80);
1000 int r = (rate_ie[j] & 0x7f) * 5;
1001
1002 /*
1003 * IEEE Std 802.11n-2009 7.3.2.2:
1004 * The new BSS Membership selector value is encoded
1005 * like a legacy basic rate, but it is not a rate and
1006 * only indicates if the BSS members are required to
1007 * support the mandatory features of Clause 20 [HT PHY]
1008 * in order to join the BSS.
1009 */
1010 if (flagged && ((rate_ie[j] & 0x7f) ==
1011 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
1012 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001013 if (debug_print)
1014 wpa_dbg(wpa_s, MSG_DEBUG,
1015 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001016 return 0;
1017 }
1018 continue;
1019 }
1020
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001021 /* There's also a VHT selector for 802.11ac */
1022 if (flagged && ((rate_ie[j] & 0x7f) ==
1023 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
1024 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001025 if (debug_print)
1026 wpa_dbg(wpa_s, MSG_DEBUG,
1027 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001028 return 0;
1029 }
1030 continue;
1031 }
1032
Sunil Ravi77d572f2023-01-17 23:58:31 +00001033 if (flagged && ((rate_ie[j] & 0x7f) ==
1034 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
1035 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
1036 if (debug_print)
1037 wpa_dbg(wpa_s, MSG_DEBUG,
1038 " hardware does not support HE PHY");
1039 return 0;
1040 }
1041 continue;
1042 }
1043
Hai Shalomc3565922019-10-28 11:58:20 -07001044#ifdef CONFIG_SAE
1045 if (flagged && ((rate_ie[j] & 0x7f) ==
1046 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001047 if (wpa_s->conf->sae_pwe ==
1048 SAE_PWE_HUNT_AND_PECK &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001049 !ssid->sae_password_id &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001050 !is_6ghz_freq(bss->freq) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001051 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -07001052 if (debug_print)
1053 wpa_dbg(wpa_s, MSG_DEBUG,
1054 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001055#ifdef CONFIG_TESTING_OPTIONS
1056 if (wpa_s->ignore_sae_h2e_only) {
1057 wpa_dbg(wpa_s, MSG_DEBUG,
1058 "TESTING: Ignore SAE H2E requirement mismatch");
1059 continue;
1060 }
1061#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -07001062 return 0;
1063 }
1064 continue;
1065 }
1066#endif /* CONFIG_SAE */
1067
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001068 if (!flagged)
1069 continue;
1070
1071 /* check for legacy basic rates */
1072 for (k = 0; k < mode->num_rates; k++) {
1073 if (mode->rates[k] == r)
1074 break;
1075 }
1076 if (k == mode->num_rates) {
1077 /*
1078 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1079 * order to join a BSS all required rates
1080 * have to be supported by the hardware.
1081 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001082 if (debug_print)
1083 wpa_dbg(wpa_s, MSG_DEBUG,
1084 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1085 r / 10, r % 10,
1086 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001087 return 0;
1088 }
1089 }
1090 }
1091
1092 return 1;
1093}
1094
1095
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001096/*
1097 * Test whether BSS is in an ESS.
1098 * This is done differently in DMG (60 GHz) and non-DMG bands
1099 */
1100static int bss_is_ess(struct wpa_bss *bss)
1101{
1102 if (bss_is_dmg(bss)) {
1103 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1104 IEEE80211_CAP_DMG_AP;
1105 }
1106
1107 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1108 IEEE80211_CAP_ESS);
1109}
1110
1111
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001112static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1113{
1114 size_t i;
1115
1116 for (i = 0; i < ETH_ALEN; i++) {
1117 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1118 return 0;
1119 }
1120 return 1;
1121}
1122
1123
1124static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1125{
1126 size_t i;
1127
1128 for (i = 0; i < num; i++) {
1129 const u8 *a = list + i * ETH_ALEN * 2;
1130 const u8 *m = a + ETH_ALEN;
1131
1132 if (match_mac_mask(a, addr, m))
1133 return 1;
1134 }
1135 return 0;
1136}
1137
1138
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001139static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1140 const u8 **ret_ssid, size_t *ret_ssid_len)
1141{
1142#ifdef CONFIG_OWE
1143 const u8 *owe, *pos, *end, *bssid;
1144 u8 ssid_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001145
1146 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
Sunil Ravi7f769292024-07-23 22:21:32 +00001147 if (!owe || !wpa_bss_get_rsne(wpa_s, bss, NULL, false))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001148 return;
1149
1150 pos = owe + 6;
1151 end = owe + 2 + owe[1];
1152
1153 if (end - pos < ETH_ALEN + 1)
1154 return;
1155 bssid = pos;
1156 pos += ETH_ALEN;
1157 ssid_len = *pos++;
1158 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1159 return;
1160
1161 /* Match the profile SSID against the OWE transition mode SSID on the
1162 * open network. */
1163 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1164 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1165 *ret_ssid = pos;
1166 *ret_ssid_len = ssid_len;
1167
Hai Shalomfdcde762020-04-02 11:19:20 -07001168 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1169 struct wpa_ssid *ssid;
1170
1171 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1172 if (wpas_network_disabled(wpa_s, ssid))
1173 continue;
1174 if (ssid->ssid_len == ssid_len &&
1175 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1176 /* OWE BSS in transition mode for a currently
1177 * enabled OWE network. */
1178 wpa_dbg(wpa_s, MSG_DEBUG,
1179 "OWE: transition mode OWE SSID for active OWE profile");
1180 bss->flags |= WPA_BSS_OWE_TRANSITION;
1181 break;
1182 }
1183 }
1184 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001185#endif /* CONFIG_OWE */
1186}
1187
1188
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001189static bool wpas_valid_ml_bss(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001190{
1191 u16 removed_links;
1192
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001193 if (wpa_bss_parse_basic_ml_element(wpa_s, bss, NULL, NULL, NULL, NULL))
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001194 return true;
1195
Sunil Ravi99c035e2024-07-12 01:42:03 +00001196 if (!bss->valid_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001197 return true;
1198
1199 /* Check if the current BSS is going to be removed */
1200 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss);
Sunil Ravi99c035e2024-07-12 01:42:03 +00001201 if (BIT(bss->mld_link_id) & removed_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001202 return false;
1203
1204 return true;
1205}
1206
1207
Sunil Ravi26978f32021-04-30 15:19:18 -07001208int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001209{
1210 int i, j;
1211
1212 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1213 return 0;
1214
1215 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1216 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1217
1218 for (i = 0; i < mode->num_channels; i++) {
1219 struct hostapd_channel_data *chan = &mode->channels[i];
1220
1221 if (chan->freq == freq)
1222 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1223 }
1224 }
1225
1226 return 1;
1227}
1228
1229
Hai Shalom899fcc72020-10-19 14:38:18 -07001230static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1231 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001232 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001233 bool debug_print);
1234
1235
1236#ifdef CONFIG_SAE_PK
1237static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1238 struct wpa_bss *orig_bss,
1239 struct wpa_ssid *ssid,
1240 const u8 *match_ssid,
1241 size_t match_ssid_len)
1242{
1243 struct wpa_bss *bss;
1244
1245 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1246 int count;
1247 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001248
1249 if (bss == orig_bss)
1250 continue;
Sunil Ravi7f769292024-07-23 22:21:32 +00001251 ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
Hai Shalomc1a21442022-02-04 13:43:00 -08001252 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001253 continue;
1254
1255 /* TODO: Could be more thorough in checking what kind of
1256 * signal strength or throughput estimate would be acceptable
1257 * compared to the originally selected BSS. */
1258 if (bss->est_throughput < 2000)
1259 return false;
1260
Hai Shalom60840252021-02-19 19:02:11 -08001261 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001262 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1263 bss, count, 0))
1264 return true;
1265 }
1266
1267 return false;
1268}
1269#endif /* CONFIG_SAE_PK */
1270
1271
1272static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1273 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001274 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001275 bool debug_print)
1276{
1277 int res;
1278 bool wpa, check_ssid, osen, rsn_osen = false;
1279 struct wpa_ie_data data;
1280#ifdef CONFIG_MBO
1281 const u8 *assoc_disallow;
1282#endif /* CONFIG_MBO */
1283#ifdef CONFIG_SAE
1284 u8 rsnxe_capa = 0;
1285#endif /* CONFIG_SAE */
1286 const u8 *ie;
1287
1288 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1289 wpa = ie && ie[1];
Sunil Ravi7f769292024-07-23 22:21:32 +00001290 ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
Hai Shalom899fcc72020-10-19 14:38:18 -07001291 wpa |= ie && ie[1];
1292 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1293 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1294 rsn_osen = true;
1295 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1296 osen = ie != NULL;
1297
1298#ifdef CONFIG_SAE
Sunil Ravi7f769292024-07-23 22:21:32 +00001299 ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
1300 if (ie && ie[0] == WLAN_EID_VENDOR_SPECIFIC && ie[1] >= 4 + 1)
1301 rsnxe_capa = ie[4 + 2];
1302 else if (ie && ie[1] >= 1)
Hai Shalom899fcc72020-10-19 14:38:18 -07001303 rsnxe_capa = ie[2];
1304#endif /* CONFIG_SAE */
1305
1306 check_ssid = wpa || ssid->ssid_len > 0;
1307
1308 if (wpas_network_disabled(wpa_s, ssid)) {
1309 if (debug_print)
1310 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1311 return false;
1312 }
1313
1314 res = wpas_temp_disabled(wpa_s, ssid);
1315 if (res > 0) {
1316 if (debug_print)
1317 wpa_dbg(wpa_s, MSG_DEBUG,
1318 " skip - disabled temporarily for %d second(s)",
1319 res);
1320 return false;
1321 }
1322
1323#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001324 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001325 if (debug_print)
1326 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001327 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001328 return false;
1329 }
1330
1331 if (wpa && ssid->ssid_len == 0 &&
1332 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1333 check_ssid = false;
1334
1335 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1336 /* Only allow wildcard SSID match if an AP advertises active
1337 * WPS operation that matches our mode. */
1338 check_ssid = ssid->ssid_len > 0 ||
1339 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1340 }
1341#endif /* CONFIG_WPS */
1342
1343 if (ssid->bssid_set && ssid->ssid_len == 0 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001344 ether_addr_equal(bss->bssid, ssid->bssid))
Hai Shalom899fcc72020-10-19 14:38:18 -07001345 check_ssid = false;
1346
1347 if (check_ssid &&
1348 (match_ssid_len != ssid->ssid_len ||
1349 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1350 if (debug_print)
1351 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1352 return false;
1353 }
1354
1355 if (ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001356 !ether_addr_equal(bss->bssid, ssid->bssid)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001357 if (debug_print)
1358 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1359 return false;
1360 }
1361
Hai Shalom60840252021-02-19 19:02:11 -08001362 /* check the list of BSSIDs to ignore */
1363 if (ssid->num_bssid_ignore &&
1364 addr_in_list(bss->bssid, ssid->bssid_ignore,
1365 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001366 if (debug_print)
1367 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001368 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001369 return false;
1370 }
1371
Hai Shalom60840252021-02-19 19:02:11 -08001372 /* if there is a list of accepted BSSIDs, only accept those APs */
1373 if (ssid->num_bssid_accept &&
1374 !addr_in_list(bss->bssid, ssid->bssid_accept,
1375 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001376 if (debug_print)
1377 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001378 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001379 return false;
1380 }
1381
1382 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1383 return false;
1384
1385 if (!osen && !wpa &&
1386 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1387 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1388 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1389 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1390 if (debug_print)
1391 wpa_dbg(wpa_s, MSG_DEBUG,
1392 " skip - non-WPA network not allowed");
1393 return false;
1394 }
1395
1396#ifdef CONFIG_WEP
1397 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1398 if (debug_print)
1399 wpa_dbg(wpa_s, MSG_DEBUG,
1400 " skip - ignore WPA/WPA2 AP for WEP network block");
1401 return false;
1402 }
1403#endif /* CONFIG_WEP */
1404
1405 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1406 if (debug_print)
1407 wpa_dbg(wpa_s, MSG_DEBUG,
1408 " skip - non-OSEN network not allowed");
1409 return false;
1410 }
1411
1412 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1413 if (debug_print)
1414 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1415 return false;
1416 }
1417
1418 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1419 !bss_is_pbss(bss)) {
1420 if (debug_print)
1421 wpa_dbg(wpa_s, MSG_DEBUG,
1422 " skip - not ESS, PBSS, or MBSS");
1423 return false;
1424 }
1425
1426 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1427 if (debug_print)
1428 wpa_dbg(wpa_s, MSG_DEBUG,
1429 " skip - PBSS mismatch (ssid %d bss %d)",
1430 ssid->pbss, bss_is_pbss(bss));
1431 return false;
1432 }
1433
1434 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1435 if (debug_print)
1436 wpa_dbg(wpa_s, MSG_DEBUG,
1437 " skip - frequency not allowed");
1438 return false;
1439 }
1440
1441#ifdef CONFIG_MESH
1442 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1443 ssid->frequency != bss->freq) {
1444 if (debug_print)
1445 wpa_dbg(wpa_s, MSG_DEBUG,
1446 " skip - frequency not allowed (mesh)");
1447 return false;
1448 }
1449#endif /* CONFIG_MESH */
1450
1451 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1452 if (debug_print)
1453 wpa_dbg(wpa_s, MSG_DEBUG,
1454 " skip - rate sets do not match");
1455 return false;
1456 }
1457
1458#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001459 /* When using SAE Password Identifier and when operationg on the 6 GHz
1460 * band, only H2E is allowed. */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001461 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1462 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1463 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1464 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001465#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301466 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001467#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001468 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1469 if (debug_print)
1470 wpa_dbg(wpa_s, MSG_DEBUG,
1471 " skip - SAE H2E required, but not supported by the AP");
1472 return false;
1473 }
1474#endif /* CONFIG_SAE */
1475
1476#ifdef CONFIG_SAE_PK
1477 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1478 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1479 if (debug_print)
1480 wpa_dbg(wpa_s, MSG_DEBUG,
1481 " skip - SAE-PK required, but not supported by the AP");
1482 return false;
1483 }
1484#endif /* CONFIG_SAE_PK */
1485
1486#ifndef CONFIG_IBSS_RSN
1487 if (ssid->mode == WPAS_MODE_IBSS &&
1488 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1489 if (debug_print)
1490 wpa_dbg(wpa_s, MSG_DEBUG,
1491 " skip - IBSS RSN not supported in the build");
1492 return false;
1493 }
1494#endif /* !CONFIG_IBSS_RSN */
1495
1496#ifdef CONFIG_P2P
1497 if (ssid->p2p_group &&
1498 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1499 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1500 if (debug_print)
1501 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1502 return false;
1503 }
1504
1505 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1506 struct wpabuf *p2p_ie;
1507 u8 dev_addr[ETH_ALEN];
1508
1509 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1510 if (!ie) {
1511 if (debug_print)
1512 wpa_dbg(wpa_s, MSG_DEBUG,
1513 " skip - no P2P element");
1514 return false;
1515 }
1516 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1517 if (!p2p_ie) {
1518 if (debug_print)
1519 wpa_dbg(wpa_s, MSG_DEBUG,
1520 " skip - could not fetch P2P element");
1521 return false;
1522 }
1523
1524 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001525 !ether_addr_equal(dev_addr, ssid->go_p2p_dev_addr)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001526 if (debug_print)
1527 wpa_dbg(wpa_s, MSG_DEBUG,
1528 " skip - no matching GO P2P Device Address in P2P element");
1529 wpabuf_free(p2p_ie);
1530 return false;
1531 }
1532 wpabuf_free(p2p_ie);
1533 }
1534
1535 /*
1536 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1537 * P2P Group Capability Bitmap and we are not in Group Formation with
1538 * that device.
1539 */
1540#endif /* CONFIG_P2P */
1541
1542 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1543 struct os_reltime diff;
1544
1545 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1546 if (debug_print)
1547 wpa_dbg(wpa_s, MSG_DEBUG,
1548 " skip - scan result not recent enough (%u.%06u seconds too old)",
1549 (unsigned int) diff.sec,
1550 (unsigned int) diff.usec);
1551 return false;
1552 }
1553#ifdef CONFIG_MBO
1554#ifdef CONFIG_TESTING_OPTIONS
1555 if (wpa_s->ignore_assoc_disallow)
1556 goto skip_assoc_disallow;
1557#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001558 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001559 if (assoc_disallow && assoc_disallow[1] >= 1) {
1560 if (debug_print)
1561 wpa_dbg(wpa_s, MSG_DEBUG,
1562 " skip - MBO association disallowed (reason %u)",
1563 assoc_disallow[2]);
1564 return false;
1565 }
1566
1567 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1568 if (debug_print)
1569 wpa_dbg(wpa_s, MSG_DEBUG,
1570 " skip - AP temporarily disallowed");
1571 return false;
1572 }
1573#ifdef CONFIG_TESTING_OPTIONS
1574skip_assoc_disallow:
1575#endif /* CONFIG_TESTING_OPTIONS */
1576#endif /* CONFIG_MBO */
1577
1578#ifdef CONFIG_DPP
1579 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001580 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1581 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001582 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1583 !ssid->dpp_csign)) {
1584 if (debug_print)
1585 wpa_dbg(wpa_s, MSG_DEBUG,
1586 " skip - no PMKSA entry for DPP");
1587 return false;
1588 }
1589#endif /* CONFIG_DPP */
1590
1591#ifdef CONFIG_SAE_PK
1592 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1593 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1594 ((ssid->sae_password &&
1595 sae_pk_valid_password(ssid->sae_password)) ||
1596 (!ssid->sae_password && ssid->passphrase &&
1597 sae_pk_valid_password(ssid->passphrase))) &&
1598 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1599 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1600 match_ssid_len)) {
1601 if (debug_print)
1602 wpa_dbg(wpa_s, MSG_DEBUG,
1603 " skip - another acceptable BSS with SAE-PK in the same ESS");
1604 return false;
1605 }
1606#endif /* CONFIG_SAE_PK */
1607
1608 if (bss->ssid_len == 0) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001609#ifdef CONFIG_OWE
1610 const u8 *owe_ssid = NULL;
1611 size_t owe_ssid_len = 0;
1612
1613 owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len);
1614 if (owe_ssid && owe_ssid_len &&
1615 owe_ssid_len == ssid->ssid_len &&
1616 os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) {
1617 if (debug_print)
1618 wpa_dbg(wpa_s, MSG_DEBUG,
1619 " skip - no SSID in BSS entry for a possible OWE transition mode BSS");
1620 int_array_add_unique(&wpa_s->owe_trans_scan_freq,
1621 bss->freq);
1622 return false;
1623 }
1624#endif /* CONFIG_OWE */
Hai Shalom899fcc72020-10-19 14:38:18 -07001625 if (debug_print)
1626 wpa_dbg(wpa_s, MSG_DEBUG,
1627 " skip - no SSID known for the BSS");
1628 return false;
1629 }
1630
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001631 if (!wpas_valid_ml_bss(wpa_s, bss)) {
1632 if (debug_print)
1633 wpa_dbg(wpa_s, MSG_DEBUG,
1634 " skip - ML BSS going to be removed");
1635 return false;
1636 }
1637
Hai Shalom899fcc72020-10-19 14:38:18 -07001638 /* Matching configuration found */
1639 return true;
1640}
1641
1642
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001643struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1644 int i, struct wpa_bss *bss,
1645 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001646 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001648 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001649 const u8 *ie;
1650 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001651 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001652 const u8 *match_ssid;
1653 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001654 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001656 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001657 wpa_ie_len = ie ? ie[1] : 0;
1658
Sunil Ravi7f769292024-07-23 22:21:32 +00001659 ie = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660 rsn_ie_len = ie ? ie[1] : 0;
1661
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001662 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1663 osen = ie != NULL;
1664
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001665 if (debug_print) {
1666 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1667 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1668 i, MAC2STR(bss->bssid),
1669 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1670 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1671 bss->freq,
1672 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1673 " wps" : "",
1674 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1675 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1676 ? " p2p" : "",
1677 osen ? " osen=1" : "");
1678 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679
Hai Shalom60840252021-02-19 19:02:11 -08001680 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1681 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001682 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001683 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001684 /*
1685 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001686 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001687 * should not be done with multiple enabled networks to
1688 * avoid getting forced to move into a worse ESS on
1689 * single error if there are no other BSSes of the
1690 * current ESS.
1691 */
1692 limit = 0;
1693 }
Hai Shalom60840252021-02-19 19:02:11 -08001694 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001695 if (debug_print) {
1696 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001697 " skip - BSSID ignored (count=%d limit=%d)",
1698 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001699 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001700 return NULL;
1701 }
1702 }
1703
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001704 match_ssid = bss->ssid;
1705 match_ssid_len = bss->ssid_len;
1706 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1707
1708 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001709 if (debug_print)
1710 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001711 return NULL;
1712 }
1713
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001714 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001715 if (debug_print)
1716 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001717 return NULL;
1718 }
1719
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001720 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001721 if (debug_print)
1722 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001723 return NULL;
1724 }
1725
Hai Shalomfdcde762020-04-02 11:19:20 -07001726 if (disabled_freq(wpa_s, bss->freq)) {
1727 if (debug_print)
1728 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1729 return NULL;
1730 }
1731
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001732 if (wnm_is_bss_excluded(wpa_s, bss)) {
1733 if (debug_print)
1734 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID excluded");
1735 return NULL;
1736 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001737
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001738 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001739 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001740 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001741 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001742 }
1743
1744 /* No matching configuration found */
1745 return NULL;
1746}
1747
1748
1749static struct wpa_bss *
1750wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001751 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001752 struct wpa_ssid **selected_ssid,
1753 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001754{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001755 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001757 if (wpa_s->current_ssid) {
1758 struct wpa_ssid *ssid;
1759
1760 wpa_dbg(wpa_s, MSG_DEBUG,
1761 "Scan results matching the currently selected network");
1762 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1763 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1764
1765 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1766 only_first_ssid, 0);
1767 if (ssid != wpa_s->current_ssid)
1768 continue;
1769 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1770 " freq=%d level=%d snr=%d est_throughput=%u",
1771 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1772 bss->snr, bss->est_throughput);
1773 }
1774 }
1775
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001776 if (only_first_ssid)
1777 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1778 group->id);
1779 else
1780 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1781 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001782
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001783 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1784 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001785
1786 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001787 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001788 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001789 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001790 if (!*selected_ssid)
1791 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001792 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001793 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001794 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001795 MAC2STR(bss->bssid),
1796 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1797 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001798 }
1799
1800 return NULL;
1801}
1802
1803
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001804struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1805 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001806{
1807 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001808 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001809 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001810 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001811
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001812 if (wpa_s->last_scan_res == NULL ||
1813 wpa_s->last_scan_res_used == 0)
1814 return NULL; /* no scan results from last update */
1815
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001816 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001817 /* check that next_ssid is still valid */
1818 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1819 if (ssid == wpa_s->next_ssid)
1820 break;
1821 }
1822 next_ssid = ssid;
1823 wpa_s->next_ssid = NULL;
1824 }
1825
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001826 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001827 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1828 if (next_ssid && next_ssid->priority ==
1829 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001830 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001831 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001832 if (selected)
1833 break;
1834 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001836 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001837 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 if (selected)
1839 break;
1840 }
1841
Sunil Ravi99c035e2024-07-12 01:42:03 +00001842 if (!selected &&
1843 (wpa_s->bssid_ignore || wnm_active_bss_trans_mgmt(wpa_s)) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001844 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001845 wpa_dbg(wpa_s, MSG_DEBUG,
1846 "No APs found - clear BSSID ignore list and try again");
Sunil Ravi99c035e2024-07-12 01:42:03 +00001847 wnm_btm_reset(wpa_s);
Hai Shalom60840252021-02-19 19:02:11 -08001848 wpa_bssid_ignore_clear(wpa_s);
1849 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850 } else if (selected == NULL)
1851 break;
1852 }
1853
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001854 ssid = *selected_ssid;
1855 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1856 !ssid->passphrase && !ssid->ext_psk) {
1857 const char *field_name, *txt = NULL;
1858
1859 wpa_dbg(wpa_s, MSG_DEBUG,
1860 "PSK/passphrase not yet available for the selected network");
1861
1862 wpas_notify_network_request(wpa_s, ssid,
1863 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1864
1865 field_name = wpa_supplicant_ctrl_req_to_string(
1866 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1867 if (field_name == NULL)
1868 return NULL;
1869
1870 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1871
1872 selected = NULL;
1873 }
1874
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001875 return selected;
1876}
1877
1878
1879static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1880 int timeout_sec, int timeout_usec)
1881{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001882 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001883 /*
1884 * No networks are enabled; short-circuit request so
1885 * we don't wait timeout seconds before transitioning
1886 * to INACTIVE state.
1887 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001888 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1889 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001890 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1891 return;
1892 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001893
1894 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001895 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1896}
1897
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001898
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001899static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s)
1900{
1901 if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss)
1902 return false;
1903
1904 wpa_msg(wpa_s, MSG_DEBUG,
1905 "Request association with " MACSTR " after ML probe",
1906 MAC2STR(wpa_s->ml_connect_probe_bss->bssid));
1907
1908 wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss,
1909 wpa_s->ml_connect_probe_ssid);
1910
1911 wpa_s->ml_connect_probe_ssid = NULL;
1912 wpa_s->ml_connect_probe_bss = NULL;
1913
1914 return true;
1915}
1916
1917
1918static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s,
1919 struct wpa_bss *selected,
1920 struct wpa_ssid *ssid)
1921{
1922 int *freqs;
1923 u16 missing_links = 0, removed_links;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001924 u8 ap_mld_id;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001925
1926 if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
1927 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)))
1928 return 0;
1929
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001930 if (wpa_bss_parse_basic_ml_element(wpa_s, selected, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001931 &missing_links, ssid,
1932 &ap_mld_id) ||
1933 !missing_links)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001934 return 0;
1935
1936 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected);
1937 missing_links &= ~removed_links;
1938
1939 if (!missing_links)
1940 return 0;
1941
1942 wpa_dbg(wpa_s, MSG_DEBUG,
1943 "MLD: Doing an ML probe for missing links 0x%04x",
1944 missing_links);
1945
1946 freqs = os_malloc(sizeof(int) * 2);
1947 if (!freqs)
1948 return 0;
1949
1950 wpa_s->ml_connect_probe_ssid = ssid;
1951 wpa_s->ml_connect_probe_bss = selected;
1952
1953 freqs[0] = selected->freq;
1954 freqs[1] = 0;
1955
1956 wpa_s->manual_scan_passive = 0;
1957 wpa_s->manual_scan_use_id = 0;
1958 wpa_s->manual_scan_only_new = 0;
1959 wpa_s->scan_id_count = 0;
1960 os_free(wpa_s->manual_scan_freqs);
1961 wpa_s->manual_scan_freqs = freqs;
1962
1963 os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001964
1965 /*
1966 * In case the ML probe request is intended to retrieve information from
1967 * the transmitted BSS, the AP MLD ID should be included and should be
1968 * set to zero.
1969 * In case the ML probe requested is intended to retrieve information
1970 * from a non-transmitted BSS, the AP MLD ID should not be included.
1971 */
1972 if (ap_mld_id)
1973 wpa_s->ml_probe_mld_id = -1;
1974 else
1975 wpa_s->ml_probe_mld_id = 0;
1976
1977 if (ssid && ssid->ssid_len) {
1978 os_free(wpa_s->ssids_from_scan_req);
1979 wpa_s->num_ssids_from_scan_req = 0;
1980
1981 wpa_s->ssids_from_scan_req =
1982 os_zalloc(sizeof(struct wpa_ssid_value));
1983 if (wpa_s->ssids_from_scan_req) {
1984 wpa_printf(MSG_DEBUG,
1985 "MLD: ML probe: With direct SSID");
1986
1987 wpa_s->num_ssids_from_scan_req = 1;
1988 wpa_s->ssids_from_scan_req[0].ssid_len = ssid->ssid_len;
1989 os_memcpy(wpa_s->ssids_from_scan_req[0].ssid,
1990 ssid->ssid, ssid->ssid_len);
1991 }
1992 }
1993
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001994 wpa_s->ml_probe_links = missing_links;
1995
1996 wpa_s->normal_scans = 0;
1997 wpa_s->scan_req = MANUAL_SCAN_REQ;
1998 wpa_s->after_wps = 0;
1999 wpa_s->known_wps_freq = 0;
2000 wpa_supplicant_req_scan(wpa_s, 0, 0);
2001
2002 return 1;
2003}
2004
2005
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002006int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002007 struct wpa_bss *selected,
2008 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002009{
Sunil Ravi640215c2023-06-28 23:08:09 +00002010#ifdef IEEE8021X_EAPOL
Sunil Ravi036cec52023-03-29 11:35:17 -07002011 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
2012 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00002013 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002014 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
2015 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07002016 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002017 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002018#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002019 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
2020 wpa_s->p2p_in_provisioning) {
2021 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
2022 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002023 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002024 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025#endif /* CONFIG_P2P */
2026
2027#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002028 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002029 wpas_wps_cancel(wpa_s);
2030#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002031 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002032 }
Sunil Ravi640215c2023-06-28 23:08:09 +00002033#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002034
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002035 wpa_msg(wpa_s, MSG_DEBUG,
2036 "Considering connect request: reassociate: %d selected: "
2037 MACSTR " bssid: " MACSTR " pending: " MACSTR
2038 " wpa_state: %s ssid=%p current_ssid=%p",
2039 wpa_s->reassociate, MAC2STR(selected->bssid),
2040 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
2041 wpa_supplicant_state_txt(wpa_s->wpa_state),
2042 ssid, wpa_s->current_ssid);
2043
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002044 /*
2045 * Do not trigger new association unless the BSSID has changed or if
2046 * reassociation is requested. If we are in process of associating with
2047 * the selected BSSID, do not trigger new attempt.
2048 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002049 if (wpa_s->reassociate ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002050 (!ether_addr_equal(selected->bssid, wpa_s->bssid) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002051 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
2052 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002053 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002054 !ether_addr_equal(selected->bssid, wpa_s->pending_bssid)) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002055 (is_zero_ether_addr(wpa_s->pending_bssid) &&
2056 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002057 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
2058 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002059 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002060 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002061
2062 if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid))
2063 return 0;
2064
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002065 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
2066 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002067 wpa_supplicant_associate(wpa_s, selected, ssid);
2068 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07002069 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
2070 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002071 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002072
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002073 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002074}
2075
2076
2077static struct wpa_ssid *
2078wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
2079{
Hai Shalomfdcde762020-04-02 11:19:20 -07002080 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002081 struct wpa_ssid *ssid;
2082
2083 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
2084 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
2085 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002086 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002087 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002088#ifndef CONFIG_IBSS_RSN
2089 if (ssid->mode == WPAS_MODE_IBSS &&
2090 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
2091 WPA_KEY_MGMT_WPA_NONE))) {
2092 wpa_msg(wpa_s, MSG_INFO,
2093 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
2094 wpa_ssid_txt(ssid->ssid,
2095 ssid->ssid_len));
2096 continue;
2097 }
2098#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07002099 if (ssid->mode == WPAS_MODE_IBSS ||
2100 ssid->mode == WPAS_MODE_AP ||
2101 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002102 return ssid;
2103 }
2104 }
2105 return NULL;
2106}
2107
2108
2109/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
2110 * on BSS added and BSS changed events */
2111static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03002112 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002113{
Jouni Malinen87fd2792011-05-16 18:35:42 +03002114 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002115
2116 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
2117 return;
2118
Jouni Malinen87fd2792011-05-16 18:35:42 +03002119 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002120 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002121
Jouni Malinen87fd2792011-05-16 18:35:42 +03002122 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002123 if (ssid == NULL)
2124 continue;
2125
Sunil Ravi7f769292024-07-23 22:21:32 +00002126 rsn = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002127 if (rsn == NULL)
2128 continue;
2129
Jouni Malinen87fd2792011-05-16 18:35:42 +03002130 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002131 }
2132
2133}
2134
2135
Hai Shalomfdcde762020-04-02 11:19:20 -07002136#ifndef CONFIG_NO_ROAMING
2137
2138static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
2139{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002140 if (noise == WPA_INVALID_NOISE) {
2141 if (IS_5GHZ(frequency)) {
2142 noise = DEFAULT_NOISE_FLOOR_5GHZ;
2143 } else if (is_6ghz_freq(frequency)) {
2144 noise = DEFAULT_NOISE_FLOOR_6GHZ;
2145 } else {
2146 noise = DEFAULT_NOISE_FLOOR_2GHZ;
2147 }
2148 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002149 return avg_signal - noise;
2150}
2151
2152
2153static unsigned int
2154wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
2155 const struct wpa_bss *bss, int snr)
2156{
2157 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08002158 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07002159 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002160 enum chan_width max_cw = CHAN_WIDTH_UNKNOWN;
Hai Shalomfdcde762020-04-02 11:19:20 -07002161
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002162 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq,
2163 &max_cw);
Hai Shalomfdcde762020-04-02 11:19:20 -07002164}
2165
Hai Shalomfdcde762020-04-02 11:19:20 -07002166
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002167static int wpas_evaluate_band_score(int frequency)
2168{
2169 if (is_6ghz_freq(frequency))
2170 return 2;
2171 if (IS_5GHZ(frequency))
2172 return 1;
2173 return 0;
2174}
2175
2176
Hai Shalom899fcc72020-10-19 14:38:18 -07002177int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
2178 struct wpa_bss *current_bss,
2179 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002180{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002181 int min_diff, diff;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002182 int cur_band_score, sel_band_score;
Sunil Ravi036cec52023-03-29 11:35:17 -07002183 int to_5ghz, to_6ghz;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002184 int cur_level, sel_level;
Hai Shalomfdcde762020-04-02 11:19:20 -07002185 unsigned int cur_est, sel_est;
2186 struct wpa_signal_info si;
2187 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07002188 int ret = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002189 const u8 *cur_ies = wpa_bss_ie_ptr(current_bss);
2190 const u8 *sel_ies = wpa_bss_ie_ptr(selected);
2191 size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len :
2192 current_bss->beacon_ie_len;
2193 size_t sel_ie_len = selected->ie_len ? selected->ie_len :
2194 selected->beacon_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002195
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002196 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002197 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002198 " freq=%d level=%d snr=%d est_throughput=%u",
2199 MAC2STR(current_bss->bssid),
2200 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002201 current_bss->snr, current_bss->est_throughput);
2202 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002203 " freq=%d level=%d snr=%d est_throughput=%u",
2204 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002205 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002206
Sunil Ravi7f769292024-07-23 22:21:32 +00002207 if (wpas_ap_link_address(wpa_s, selected->bssid)) {
2208 wpa_dbg(wpa_s, MSG_DEBUG, "MLD: associated to selected BSS");
2209 return 0;
2210 }
2211
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002212 if (wpa_s->current_ssid->bssid_set &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002213 ether_addr_equal(selected->bssid, wpa_s->current_ssid->bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002214 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2215 "has preferred BSSID");
2216 return 1;
2217 }
2218
Hai Shalomfdcde762020-04-02 11:19:20 -07002219 /*
2220 * Try to poll the signal from the driver since this will allow to get
2221 * more accurate values. In some cases, there can be big differences
2222 * between the RSSI of the Probe Response frames of the AP we are
2223 * associated with and the Beacon frames we hear from the same AP after
2224 * association. This can happen, e.g., when there are two antennas that
2225 * hear the AP very differently. If the driver chooses to hear the
2226 * Probe Response frames during the scan on the "bad" antenna because
2227 * it wants to save power, but knows to choose the other antenna after
2228 * association, we will hear our AP with a low RSSI as part of the
2229 * scan even when we can hear it decently on the other antenna. To cope
2230 * with this, ask the driver to teach us how it hears the AP. Also, the
2231 * scan results may be a bit old, since we can very quickly get fresh
2232 * information about our currently associated AP.
2233 */
2234 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002235 (si.data.avg_beacon_signal || si.data.avg_signal)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002236 /*
2237 * Normalize avg_signal to the RSSI over 20 MHz, as the
2238 * throughput is estimated based on the RSSI over 20 MHz
2239 */
Sunil Ravi77d572f2023-01-17 23:58:31 +00002240 cur_level = si.data.avg_beacon_signal ?
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002241 si.data.avg_beacon_signal :
2242 (si.data.avg_signal -
2243 wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2244 si.chanwidth));
Hai Shalomfdcde762020-04-02 11:19:20 -07002245 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2246 si.current_noise);
2247
2248 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2249 current_bss,
2250 cur_snr);
2251 wpa_dbg(wpa_s, MSG_DEBUG,
2252 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2253 cur_level, cur_snr, cur_est);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002254 } else {
2255 /* Level and SNR are measured over 20 MHz channel */
2256 cur_level = current_bss->level;
2257 cur_snr = current_bss->snr;
2258 cur_est = current_bss->est_throughput;
Hai Shalomfdcde762020-04-02 11:19:20 -07002259 }
2260
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002261 /* Adjust the SNR of BSSes based on the channel width. */
2262 cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2263 current_bss->max_cw);
2264 cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len,
2265 current_bss->max_cw, cur_snr);
2266
2267 sel_est = selected->est_throughput;
2268 sel_level = selected->level +
2269 wpas_channel_width_rssi_bump(sel_ies, sel_ie_len,
2270 selected->max_cw);
2271
Hai Shalomfdcde762020-04-02 11:19:20 -07002272 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002273 wpa_dbg(wpa_s, MSG_DEBUG,
2274 "Allow reassociation - selected BSS has better estimated throughput");
2275 return 1;
2276 }
2277
Dmitry Shmidte4663042016-04-04 10:07:49 -07002278 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
Sunil Ravi036cec52023-03-29 11:35:17 -07002279 to_6ghz = is_6ghz_freq(selected->freq) &&
2280 !is_6ghz_freq(current_bss->freq);
Dmitry Shmidte4663042016-04-04 10:07:49 -07002281
Sunil Ravi036cec52023-03-29 11:35:17 -07002282 if (cur_level < 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002283 cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002284 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002285 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2286 "signal level");
2287 return 0;
2288 }
2289
Hai Shalomfdcde762020-04-02 11:19:20 -07002290 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002291 wpa_dbg(wpa_s, MSG_DEBUG,
2292 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002293 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002294 }
2295
Hai Shalomfdcde762020-04-02 11:19:20 -07002296 if (cur_snr > GREAT_SNR) {
2297 wpa_dbg(wpa_s, MSG_DEBUG,
2298 "Skip roam - Current BSS has good SNR (%u > %u)",
2299 cur_snr, GREAT_SNR);
2300 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002301 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002302
Hai Shalomfdcde762020-04-02 11:19:20 -07002303 if (cur_level < -85) /* ..-86 dBm */
2304 min_diff = 1;
2305 else if (cur_level < -80) /* -85..-81 dBm */
2306 min_diff = 2;
2307 else if (cur_level < -75) /* -80..-76 dBm */
2308 min_diff = 3;
2309 else if (cur_level < -70) /* -75..-71 dBm */
2310 min_diff = 4;
2311 else if (cur_level < 0) /* -70..-1 dBm */
2312 min_diff = 5;
2313 else /* unspecified units (not in dBm) */
2314 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002315
Hai Shalomfdcde762020-04-02 11:19:20 -07002316 if (cur_est > sel_est * 1.5)
2317 min_diff += 10;
2318 else if (cur_est > sel_est * 1.2)
2319 min_diff += 5;
2320 else if (cur_est > sel_est * 1.1)
2321 min_diff += 2;
2322 else if (cur_est > sel_est)
2323 min_diff++;
2324 else if (sel_est > cur_est * 1.5)
2325 min_diff -= 10;
2326 else if (sel_est > cur_est * 1.2)
2327 min_diff -= 5;
2328 else if (sel_est > cur_est * 1.1)
2329 min_diff -= 2;
2330 else if (sel_est > cur_est)
2331 min_diff--;
2332
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002333 cur_band_score = wpas_evaluate_band_score(current_bss->freq);
2334 sel_band_score = wpas_evaluate_band_score(selected->freq);
2335 min_diff += (cur_band_score - sel_band_score) * 2;
2336 if (wpa_s->signal_threshold && cur_level <= wpa_s->signal_threshold &&
2337 sel_level > wpa_s->signal_threshold)
Sunil Ravi036cec52023-03-29 11:35:17 -07002338 min_diff -= 2;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002339 diff = sel_level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002340 if (diff < min_diff) {
2341 wpa_dbg(wpa_s, MSG_DEBUG,
2342 "Skip roam - too small difference in signal level (%d < %d)",
2343 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002344 ret = 0;
2345 } else {
2346 wpa_dbg(wpa_s, MSG_DEBUG,
2347 "Allow reassociation due to difference in signal level (%d >= %d)",
2348 diff, min_diff);
2349 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002350 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002351 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2352 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2353 " sel_freq=%d sel_level=%d sel_est=%d",
2354 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2355 MAC2STR(current_bss->bssid),
2356 current_bss->freq, cur_level, cur_est,
2357 MAC2STR(selected->bssid),
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002358 selected->freq, sel_level, sel_est);
Hai Shalom899fcc72020-10-19 14:38:18 -07002359 return ret;
2360}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002361
Hai Shalom899fcc72020-10-19 14:38:18 -07002362#endif /* CONFIG_NO_ROAMING */
2363
2364
2365static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2366 struct wpa_bss *selected,
2367 struct wpa_ssid *ssid)
2368{
2369 struct wpa_bss *current_bss = NULL;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002370 const u8 *bssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07002371
2372 if (wpa_s->reassociate)
2373 return 1; /* explicit request to reassociate */
2374 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2375 return 1; /* we are not associated; continue */
2376 if (wpa_s->current_ssid == NULL)
2377 return 1; /* unknown current SSID */
2378 if (wpa_s->current_ssid != ssid)
2379 return 1; /* different network block */
2380
2381 if (wpas_driver_bss_selection(wpa_s))
2382 return 0; /* Driver-based roaming */
2383
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002384 if (wpa_s->valid_links)
2385 bssid = wpa_s->links[wpa_s->mlo_assoc_link_id].bssid;
2386 else
2387 bssid = wpa_s->bssid;
2388
Hai Shalom899fcc72020-10-19 14:38:18 -07002389 if (wpa_s->current_ssid->ssid)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002390 current_bss = wpa_bss_get(wpa_s, bssid,
Hai Shalom899fcc72020-10-19 14:38:18 -07002391 wpa_s->current_ssid->ssid,
2392 wpa_s->current_ssid->ssid_len);
2393 if (!current_bss)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002394 current_bss = wpa_bss_get_bssid(wpa_s, bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07002395
2396 if (!current_bss)
2397 return 1; /* current BSS not seen in scan results */
2398
2399 if (current_bss == selected)
2400 return 0;
2401
2402 if (selected->last_update_idx > current_bss->last_update_idx)
2403 return 1; /* current BSS not seen in the last scan */
2404
2405#ifndef CONFIG_NO_ROAMING
2406 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2407 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002408#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002409 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002410#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002411}
2412
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002413
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002414/*
2415 * Return a negative value if no scan results could be fetched or if scan
2416 * results should not be shared with other virtual interfaces.
2417 * Return 0 if scan results were fetched and may be shared with other
2418 * interfaces.
2419 * Return 1 if scan results may be shared with other virtual interfaces but may
2420 * not trigger any operations.
2421 * Return 2 if the interface was removed and cannot be used.
2422 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002423static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002424 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002425 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002426{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002427 struct wpa_scan_results *scan_res = NULL;
2428 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002429 int ap = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002430 bool trigger_6ghz_scan;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002431#ifndef CONFIG_NO_RANDOM_POOL
2432 size_t i, num;
2433#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002434
2435#ifdef CONFIG_AP
2436 if (wpa_s->ap_iface)
2437 ap = 1;
2438#endif /* CONFIG_AP */
2439
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002440 trigger_6ghz_scan = wpa_s->crossed_6ghz_dom &&
2441 wpa_s->last_scan_all_chan;
2442 wpa_s->crossed_6ghz_dom = false;
2443 wpa_s->last_scan_all_chan = false;
2444
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002445 wpa_supplicant_notify_scanning(wpa_s, 0);
2446
2447 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2448 data ? &data->scan_info :
Sunil Ravi99c035e2024-07-12 01:42:03 +00002449 NULL, 1, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002450 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002451 if (wpa_s->conf->ap_scan == 2 || ap ||
2452 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002453 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002454 if (!own_request)
2455 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002456 if (data && data->scan_info.external_scan)
2457 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002458 if (wpa_s->scan_res_fail_handler) {
2459 void (*handler)(struct wpa_supplicant *wpa_s);
2460
2461 handler = wpa_s->scan_res_fail_handler;
2462 wpa_s->scan_res_fail_handler = NULL;
2463 handler(wpa_s);
2464 } else {
2465 wpa_dbg(wpa_s, MSG_DEBUG,
2466 "Failed to get scan results - try scanning again");
2467 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2468 }
2469
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002470 ret = -1;
2471 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002472 }
2473
2474#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002475 num = scan_res->num;
2476 if (num > 10)
2477 num = 10;
2478 for (i = 0; i < num; i++) {
2479 u8 buf[5];
2480 struct wpa_scan_res *res = scan_res->res[i];
2481 buf[0] = res->bssid[5];
2482 buf[1] = res->qual & 0xff;
2483 buf[2] = res->noise & 0xff;
2484 buf[3] = res->level & 0xff;
2485 buf[4] = res->tsf & 0xff;
2486 random_add_randomness(buf, sizeof(buf));
2487 }
2488#endif /* CONFIG_NO_RANDOM_POOL */
2489
Sunil Ravi7f769292024-07-23 22:21:32 +00002490 wpa_s->last_scan_external = data && data->scan_info.external_scan;
2491
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002492 if (update_only) {
2493 ret = 1;
2494 goto scan_work_done;
2495 }
2496
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002497 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002498 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002499 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2500 struct wpa_scan_results *scan_res);
2501
2502 scan_res_handler = wpa_s->scan_res_handler;
2503 wpa_s->scan_res_handler = NULL;
2504 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002505 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002506 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002507 }
2508
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002509 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002510 wpa_s->own_scan_running,
2511 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002512 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002513 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2514 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002515 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2516 wpa_s->manual_scan_id);
2517 wpa_s->manual_scan_use_id = 0;
2518 } else {
2519 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2520 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002521 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002522
2523 wpas_notify_scan_done(wpa_s, 1);
2524
Hai Shalomfdcde762020-04-02 11:19:20 -07002525 if (ap) {
2526 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2527#ifdef CONFIG_AP
2528 if (wpa_s->ap_iface->scan_cb)
2529 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2530#endif /* CONFIG_AP */
2531 goto scan_work_done;
2532 }
2533
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002534 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002535 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 -07002536 wpa_scan_results_free(scan_res);
2537 return 0;
2538 }
2539
Sunil Ravi99c035e2024-07-12 01:42:03 +00002540 if (wnm_scan_process(wpa_s, false) > 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002541 goto scan_work_done;
2542
Hai Shalomc1a21442022-02-04 13:43:00 -08002543 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002544 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002545
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002546#ifndef CONFIG_NO_RRM
Hai Shalom021b0b52019-04-10 11:17:58 -07002547 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002548 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2549 goto scan_work_done;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002550#endif /* CONFIG_NO_RRM */
Dmitry Shmidt29333592017-01-09 12:27:11 -08002551
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002552 if (ml_link_probe_scan(wpa_s))
2553 goto scan_work_done;
2554
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002555 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2556 goto scan_work_done;
2557
2558 if (autoscan_notify_scan(wpa_s, scan_res))
2559 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002560
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002561 if (wpa_s->disconnected) {
2562 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002563 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002564 }
2565
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002566 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002567 bgscan_notify_scan(wpa_s, scan_res) == 1)
2568 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002569
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002570 wpas_wps_update_ap_info(wpa_s, scan_res);
2571
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002572 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2573 wpa_s->wpa_state < WPA_COMPLETED)
2574 goto scan_work_done;
2575
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002576 wpa_scan_results_free(scan_res);
2577
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002578 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002579 struct wpa_radio_work *work = wpa_s->scan_work;
2580 wpa_s->scan_work = NULL;
2581 radio_work_done(work);
2582 }
2583
Hai Shalomc3565922019-10-28 11:58:20 -07002584 os_free(wpa_s->last_scan_freqs);
2585 wpa_s->last_scan_freqs = NULL;
2586 wpa_s->num_last_scan_freqs = 0;
2587 if (own_request && data &&
2588 data->scan_info.freqs && data->scan_info.num_freqs) {
2589 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2590 data->scan_info.num_freqs);
2591 if (wpa_s->last_scan_freqs) {
2592 os_memcpy(wpa_s->last_scan_freqs,
2593 data->scan_info.freqs,
2594 sizeof(int) * data->scan_info.num_freqs);
2595 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2596 }
2597 }
2598
Sunil Ravi77d572f2023-01-17 23:58:31 +00002599 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2600 return ret;
2601
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002602 return wpas_select_network_from_last_scan(wpa_s, 1, own_request,
2603 trigger_6ghz_scan, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002604
2605scan_work_done:
2606 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002607 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002608 struct wpa_radio_work *work = wpa_s->scan_work;
2609 wpa_s->scan_work = NULL;
2610 radio_work_done(work);
2611 }
2612 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002613}
2614
2615
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002616static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s,
2617 union wpa_event_data *data)
2618{
2619 struct wpa_driver_scan_params params;
2620 unsigned int j;
2621
2622 wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan");
2623 os_memset(&params, 0, sizeof(params));
2624 params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz;
2625 for (j = 0; j < data->scan_info.num_ssids; j++)
2626 params.ssids[j] = data->scan_info.ssids[j];
2627 params.num_ssids = data->scan_info.num_ssids;
2628 wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
2629 true, !wpa_s->last_scan_non_coloc_6ghz, false);
2630 if (!wpa_supplicant_trigger_scan(wpa_s, &params, true, true)) {
2631 os_free(params.freqs);
2632 return 1;
2633 }
2634 wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan");
2635 os_free(params.freqs);
2636 return 0;
2637}
2638
2639
2640/**
2641 * Select a network from the last scan
2642 * @wpa_s: Pointer to wpa_supplicant data
2643 * @new_scan: Whether this function was called right after a scan has finished
2644 * @own_request: Whether the scan was requested by this interface
2645 * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable
2646 * @data: Scan data from scan that finished if applicable
2647 *
2648 * See _wpa_supplicant_event_scan_results() for return values.
2649 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002650static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002651 int new_scan, int own_request,
2652 bool trigger_6ghz_scan,
2653 union wpa_event_data *data)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002654{
2655 struct wpa_bss *selected;
2656 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002657 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2658
2659 if (time_to_reenable > 0) {
2660 wpa_dbg(wpa_s, MSG_DEBUG,
2661 "Postpone network selection by %d seconds since all networks are disabled",
2662 time_to_reenable);
2663 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2664 eloop_register_timeout(time_to_reenable, 0,
2665 wpas_network_reenabled, wpa_s, NULL);
2666 return 0;
2667 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002668
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002669 if (wpa_s->p2p_mgmt)
2670 return 0; /* no normal connection on p2p_mgmt interface */
2671
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002672 wpa_s->owe_transition_search = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002673#ifdef CONFIG_OWE
2674 os_free(wpa_s->owe_trans_scan_freq);
2675 wpa_s->owe_trans_scan_freq = NULL;
2676#endif /* CONFIG_OWE */
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002677 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002678
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002679#ifdef CONFIG_MESH
2680 if (wpa_s->ifmsh) {
2681 wpa_msg(wpa_s, MSG_INFO,
2682 "Avoiding join because we already joined a mesh group");
2683 return 0;
2684 }
2685#endif /* CONFIG_MESH */
2686
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002687 if (selected) {
2688 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002689 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002690 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002691 if (new_scan)
2692 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002693 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002694 }
2695
Hai Shalomc3565922019-10-28 11:58:20 -07002696 wpa_s->suitable_network++;
2697
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002698 if (ssid != wpa_s->current_ssid &&
2699 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2700 wpa_s->own_disconnect_req = 1;
2701 wpa_supplicant_deauthenticate(
2702 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2703 }
2704
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002705 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002706 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002707 return -1;
2708 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002709 wpa_s->supp_pbc_active = false;
2710
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002711 if (new_scan)
2712 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002713 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002714 * Do not allow other virtual radios to trigger operations based
2715 * on these scan results since we do not want them to start
2716 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002717 */
2718 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002719 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002720 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002721 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2722 ssid = wpa_supplicant_pick_new_network(wpa_s);
2723 if (ssid) {
2724 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2725 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002726 if (new_scan)
2727 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002728 } else if (own_request) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002729 if (wpa_s->support_6ghz && trigger_6ghz_scan && data &&
2730 wpas_trigger_6ghz_scan(wpa_s, data) < 0)
2731 return 1;
2732
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002733 /*
2734 * No SSID found. If SCAN results are as a result of
2735 * own scan request and not due to a scan request on
2736 * another shared interface, try another scan.
2737 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002738 int timeout_sec = wpa_s->scan_interval;
2739 int timeout_usec = 0;
2740#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002741 int res;
2742
2743 res = wpas_p2p_scan_no_go_seen(wpa_s);
2744 if (res == 2)
2745 return 2;
2746 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002747 return 0;
2748
Sunil Ravi77d572f2023-01-17 23:58:31 +00002749 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002750 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002751
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002752 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002753 wpa_s->show_group_started ||
2754 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002755 /*
2756 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002757 * state and during P2P join-a-group operation
2758 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002759 */
2760 timeout_sec = 0;
2761 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002762 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2763 timeout_usec);
2764 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002765 }
2766#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002767#ifdef CONFIG_INTERWORKING
2768 if (wpa_s->conf->auto_interworking &&
2769 wpa_s->conf->interworking &&
2770 wpa_s->conf->cred) {
2771 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2772 "start ANQP fetch since no matching "
2773 "networks found");
2774 wpa_s->network_select = 1;
2775 wpa_s->auto_network_select = 1;
2776 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002777 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002778 }
2779#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002780#ifdef CONFIG_WPS
2781 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2782 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2783 timeout_sec = 0;
2784 timeout_usec = 500000;
2785 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2786 timeout_usec);
2787 return 0;
2788 }
2789#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002790#ifdef CONFIG_OWE
2791 if (wpa_s->owe_transition_search) {
2792 wpa_dbg(wpa_s, MSG_DEBUG,
2793 "OWE: Use shorter wait during transition mode search");
2794 timeout_sec = 0;
2795 timeout_usec = 500000;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002796 if (wpa_s->owe_trans_scan_freq) {
2797 os_free(wpa_s->next_scan_freqs);
2798 wpa_s->next_scan_freqs =
2799 wpa_s->owe_trans_scan_freq;
2800 wpa_s->owe_trans_scan_freq = NULL;
2801 timeout_usec = 100000;
2802 }
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002803 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2804 timeout_usec);
2805 return 0;
2806 }
2807#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002808 if (wpa_supplicant_req_sched_scan(wpa_s))
2809 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2810 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002811
2812 wpa_msg_ctrl(wpa_s, MSG_INFO,
2813 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002814 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002815 }
2816 }
2817 return 0;
2818}
2819
2820
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002821static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2822 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002823{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002824 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002825 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002826
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002827 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002828 if (res == 2) {
2829 /*
2830 * Interface may have been removed, so must not dereference
2831 * wpa_s after this.
2832 */
2833 return 1;
2834 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002835
2836 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002837 /*
2838 * If no scan results could be fetched, then no need to
2839 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002840 * this scan. Similarly, if scan results started a new operation on this
2841 * interface, do not notify other interfaces to avoid concurrent
2842 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002843 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002844 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002845 }
2846
2847 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002848 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002849 * so, they get updated with this same scan info.
2850 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002851 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2852 radio_list) {
2853 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002854 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2855 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002856 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2857 res > 0);
2858 if (res < 0)
2859 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002860 }
2861 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002862
2863 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002864}
2865
2866#endif /* CONFIG_NO_SCAN_PROCESSING */
2867
2868
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002869int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2870{
2871#ifdef CONFIG_NO_SCAN_PROCESSING
2872 return -1;
2873#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002874 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002875
Dmitry Shmidt29333592017-01-09 12:27:11 -08002876 wpa_s->ignore_post_flush_scan_res = 0;
2877
Dmitry Shmidt41712582015-06-29 11:02:15 -07002878 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002879 return -1;
2880
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002881 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002882 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002883 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002884 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2885 return -1;
Sunil Ravi7f769292024-07-23 22:21:32 +00002886 } else if (wpa_s->crossed_6ghz_dom) {
2887 wpa_printf(MSG_DEBUG, "Fast associate: Crossed 6 GHz domain");
2888 return -1;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002889 }
2890
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002891 return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002892#endif /* CONFIG_NO_SCAN_PROCESSING */
2893}
2894
Sunil Ravi77d572f2023-01-17 23:58:31 +00002895
2896int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2897{
2898#ifdef CONFIG_NO_SCAN_PROCESSING
2899 return -1;
2900#else /* CONFIG_NO_SCAN_PROCESSING */
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002901 return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002902#endif /* CONFIG_NO_SCAN_PROCESSING */
2903}
2904
2905
Dmitry Shmidt04949592012-07-19 12:16:46 -07002906#ifdef CONFIG_WNM
2907
2908static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2909{
2910 struct wpa_supplicant *wpa_s = eloop_ctx;
2911
2912 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2913 return;
2914
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002915 if (!wpa_s->no_keep_alive) {
2916 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2917 MAC2STR(wpa_s->bssid));
2918 /* TODO: could skip this if normal data traffic has been sent */
2919 /* TODO: Consider using some more appropriate data frame for
2920 * this */
2921 if (wpa_s->l2)
2922 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2923 (u8 *) "", 0);
2924 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002925
2926#ifdef CONFIG_SME
2927 if (wpa_s->sme.bss_max_idle_period) {
2928 unsigned int msec;
2929 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2930 if (msec > 100)
2931 msec -= 100;
2932 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2933 wnm_bss_keep_alive, wpa_s, NULL);
2934 }
2935#endif /* CONFIG_SME */
2936}
2937
2938
2939static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2940 const u8 *ies, size_t ies_len)
2941{
2942 struct ieee802_11_elems elems;
2943
2944 if (ies == NULL)
2945 return;
2946
2947 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2948 return;
2949
2950#ifdef CONFIG_SME
2951 if (elems.bss_max_idle_period) {
2952 unsigned int msec;
2953 wpa_s->sme.bss_max_idle_period =
2954 WPA_GET_LE16(elems.bss_max_idle_period);
2955 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2956 "TU)%s", wpa_s->sme.bss_max_idle_period,
2957 (elems.bss_max_idle_period[2] & 0x01) ?
2958 " (protected keep-live required)" : "");
2959 if (wpa_s->sme.bss_max_idle_period == 0)
2960 wpa_s->sme.bss_max_idle_period = 1;
2961 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2962 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2963 /* msec times 1000 */
2964 msec = wpa_s->sme.bss_max_idle_period * 1024;
2965 if (msec > 100)
2966 msec -= 100;
2967 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2968 wnm_bss_keep_alive, wpa_s,
2969 NULL);
2970 }
Sunil Ravi7f769292024-07-23 22:21:32 +00002971 } else {
2972 wpa_s->sme.bss_max_idle_period = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002973 }
2974#endif /* CONFIG_SME */
2975}
2976
2977#endif /* CONFIG_WNM */
2978
2979
2980void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2981{
2982#ifdef CONFIG_WNM
2983 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2984#endif /* CONFIG_WNM */
2985}
2986
2987
Dmitry Shmidt051af732013-10-22 13:52:46 -07002988static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2989 size_t len)
2990{
2991 int res;
2992
2993 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2994 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2995 if (res) {
2996 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2997 }
2998
2999 return res;
3000}
3001
3002
3003static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
3004 const u8 *ies, size_t ies_len)
3005{
3006 struct ieee802_11_elems elems;
3007
3008 if (ies == NULL)
3009 return;
3010
3011 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
3012 return;
3013
3014 if (elems.qos_map_set) {
3015 wpas_qos_map_set(wpa_s, elems.qos_map_set,
3016 elems.qos_map_set_len);
3017 }
3018}
3019
Dmitry Shmidt051af732013-10-22 13:52:46 -07003020
Sunil Ravi036cec52023-03-29 11:35:17 -07003021static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
3022{
3023 if (wpa_s->enabled_4addr_mode) {
3024 wpa_printf(MSG_DEBUG, "4addr mode already set");
3025 return;
3026 }
3027
3028 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
3029 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
3030 goto fail;
3031 }
3032 wpa_s->enabled_4addr_mode = 1;
3033 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
3034 return;
3035
3036fail:
3037 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3038}
3039
3040
Hai Shalom74f70d42019-02-11 14:42:39 -08003041static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
3042 const u8 *ies, size_t ies_len)
3043{
3044 struct ieee802_11_elems elems;
Sunil Ravi99c035e2024-07-12 01:42:03 +00003045 struct multi_ap_params multi_ap;
3046 u16 status;
Hai Shalom74f70d42019-02-11 14:42:39 -08003047
Hai Shalomfdcde762020-04-02 11:19:20 -07003048 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08003049
Hai Shalomfdcde762020-04-02 11:19:20 -07003050 if (!ies ||
3051 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
Sunil Ravi99c035e2024-07-12 01:42:03 +00003052 !elems.multi_ap)
Hai Shalomfdcde762020-04-02 11:19:20 -07003053 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08003054
Sunil Ravi99c035e2024-07-12 01:42:03 +00003055 status = check_multi_ap_ie(elems.multi_ap + 4, elems.multi_ap_len - 4,
3056 &multi_ap);
3057 if (status != WLAN_STATUS_SUCCESS)
Hai Shalomfdcde762020-04-02 11:19:20 -07003058 return;
3059
Sunil Ravi99c035e2024-07-12 01:42:03 +00003060 wpa_s->multi_ap_backhaul = !!(multi_ap.capability &
3061 MULTI_AP_BACKHAUL_BSS);
3062 wpa_s->multi_ap_fronthaul = !!(multi_ap.capability &
Hai Shalomfdcde762020-04-02 11:19:20 -07003063 MULTI_AP_FRONTHAUL_BSS);
3064 wpa_s->multi_ap_ie = 1;
3065}
3066
3067
3068static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
3069{
3070 if (!wpa_s->current_ssid ||
3071 !wpa_s->current_ssid->multi_ap_backhaul_sta)
3072 return;
3073
3074 if (!wpa_s->multi_ap_ie) {
3075 wpa_printf(MSG_INFO,
3076 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08003077 goto fail;
3078 }
3079
Hai Shalomfdcde762020-04-02 11:19:20 -07003080 if (!wpa_s->multi_ap_backhaul) {
3081 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07003082 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
3083 wpa_printf(MSG_INFO,
3084 "WPS active, accepting fronthaul-only BSS");
3085 /* Don't set 4addr mode in this case, so just return */
3086 return;
3087 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003088 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
3089 goto fail;
3090 }
3091
Sunil Ravi036cec52023-03-29 11:35:17 -07003092 wpa_supplicant_set_4addr_mode(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08003093 return;
3094
3095fail:
3096 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3097}
3098
3099
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003100#ifdef CONFIG_FST
3101static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
3102 const u8 *ie, size_t ie_len)
3103{
3104 struct mb_ies_info mb_ies;
3105
3106 if (!ie || !ie_len || !wpa_s->fst)
3107 return -ENOENT;
3108
3109 os_memset(&mb_ies, 0, sizeof(mb_ies));
3110
3111 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
3112 size_t len;
3113
3114 len = 2 + ie[1];
3115 if (len > ie_len) {
3116 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
3117 ie, ie_len);
3118 break;
3119 }
3120
3121 if (ie[0] == WLAN_EID_MULTI_BAND) {
3122 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
3123 (unsigned int) len);
3124 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
3125 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
3126 mb_ies.nof_ies++;
3127 }
3128
3129 ie_len -= len;
3130 ie += len;
3131 }
3132
3133 if (mb_ies.nof_ies > 0) {
3134 wpabuf_free(wpa_s->received_mb_ies);
3135 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
3136 return 0;
3137 }
3138
3139 return -ENOENT;
3140}
3141#endif /* CONFIG_FST */
3142
3143
Hai Shalomc1a21442022-02-04 13:43:00 -08003144static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
3145 union wpa_event_data *data)
3146{
3147 int sel;
3148 const u8 *p;
3149 int l, len;
3150 bool found = false;
3151 struct wpa_ie_data ie;
3152 struct wpa_ssid *ssid = wpa_s->current_ssid;
3153 struct wpa_bss *bss = wpa_s->current_bss;
3154 int pmf;
3155
3156 if (!ssid)
3157 return 0;
3158
3159 p = data->assoc_info.req_ies;
3160 l = data->assoc_info.req_ies_len;
3161
3162 while (p && l >= 2) {
3163 len = p[1] + 2;
3164 if (len > l) {
3165 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3166 p, l);
3167 break;
3168 }
3169 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3170 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3171 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3172 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3173 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3174 found = true;
3175 break;
3176 }
3177 l -= len;
3178 p += len;
3179 }
3180
Sunil Ravi036cec52023-03-29 11:35:17 -07003181 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
3182 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
Hai Shalomc1a21442022-02-04 13:43:00 -08003183 return 0;
Sunil Ravi036cec52023-03-29 11:35:17 -07003184 }
Hai Shalomc1a21442022-02-04 13:43:00 -08003185
3186 wpa_hexdump(MSG_DEBUG,
3187 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
3188 p, l);
3189
3190 /* Update proto from (Re)Association Request frame info */
3191 wpa_s->wpa_proto = ie.proto;
3192 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
3193 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
3194 !!(wpa_s->wpa_proto &
3195 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
3196
3197 /* Update AKMP suite from (Re)Association Request frame info */
3198 sel = ie.key_mgmt;
3199 if (ssid->key_mgmt)
3200 sel &= ssid->key_mgmt;
3201
3202 wpa_dbg(wpa_s, MSG_DEBUG,
3203 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
3204 ie.key_mgmt, ssid->key_mgmt, sel);
3205 if (ie.key_mgmt && !sel) {
3206 wpa_supplicant_deauthenticate(
3207 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
3208 return -1;
3209 }
3210
Sunil Ravi036cec52023-03-29 11:35:17 -07003211#ifdef CONFIG_OCV
3212 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
3213 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
3214 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
3215 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
3216#endif /* CONFIG_OCV */
3217
Sunil Ravi89eba102022-09-13 21:04:37 -07003218 /*
3219 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
3220 * different AKM.
3221 */
3222 if (wpa_s->key_mgmt != ie.key_mgmt &&
3223 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
3224 if (!ssid->psk_set) {
3225 wpa_dbg(wpa_s, MSG_INFO,
3226 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00003227 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07003228 return -1;
3229 }
3230
3231 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
3232 if (wpa_s->conf->key_mgmt_offload &&
3233 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003234 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
3235 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07003236 wpa_dbg(wpa_s, MSG_ERROR,
3237 "WPA: Cannot set PMK for key management offload");
3238 }
3239
Hai Shalomc1a21442022-02-04 13:43:00 -08003240 wpa_s->key_mgmt = ie.key_mgmt;
3241 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3242 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
3243 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
3244 wpa_s->wpa_proto);
3245
3246 /* Update pairwise cipher from (Re)Association Request frame info */
3247 sel = ie.pairwise_cipher;
3248 if (ssid->pairwise_cipher)
3249 sel &= ssid->pairwise_cipher;
3250
3251 wpa_dbg(wpa_s, MSG_DEBUG,
3252 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
3253 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
3254 if (ie.pairwise_cipher && !sel) {
3255 wpa_supplicant_deauthenticate(
3256 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
3257 return -1;
3258 }
3259
3260 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3261 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3262 wpa_s->pairwise_cipher);
3263 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
3264 wpa_cipher_txt(wpa_s->pairwise_cipher));
3265
3266 /* Update other parameters based on AP's WPA IE/RSNE, if available */
3267 if (!bss) {
3268 wpa_dbg(wpa_s, MSG_DEBUG,
3269 "WPA: current_bss == NULL - skip AP IE check");
3270 return 0;
3271 }
3272
3273 /* Update GTK and IGTK from AP's RSNE */
3274 found = false;
3275
3276 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
3277 const u8 *bss_rsn;
3278
Sunil Ravi7f769292024-07-23 22:21:32 +00003279 bss_rsn = wpa_bss_get_rsne(wpa_s, bss, ssid,
3280 wpa_s->valid_links);
Hai Shalomc1a21442022-02-04 13:43:00 -08003281 if (bss_rsn) {
3282 p = bss_rsn;
3283 len = 2 + bss_rsn[1];
3284 found = true;
3285 }
3286 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
3287 const u8 *bss_wpa;
3288
3289 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3290 if (bss_wpa) {
3291 p = bss_wpa;
3292 len = 2 + bss_wpa[1];
3293 found = true;
3294 }
3295 }
3296
3297 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
3298 return 0;
3299
3300 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
3301 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3302 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3303 /* AP does not support MFP, local configuration requires it */
3304 wpa_supplicant_deauthenticate(
3305 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3306 return -1;
3307 }
3308 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3309 pmf == NO_MGMT_FRAME_PROTECTION) {
3310 /* AP requires MFP, local configuration disables it */
3311 wpa_supplicant_deauthenticate(
3312 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3313 return -1;
3314 }
3315
3316 /* Update PMF from local configuration now that MFP validation was done
3317 * above */
3318 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3319
3320 /* Update GTK from AP's RSNE */
3321 sel = ie.group_cipher;
3322 if (ssid->group_cipher)
3323 sel &= ssid->group_cipher;
3324
3325 wpa_dbg(wpa_s, MSG_DEBUG,
3326 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3327 ie.group_cipher, ssid->group_cipher, sel);
3328 if (ie.group_cipher && !sel) {
3329 wpa_supplicant_deauthenticate(
3330 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3331 return -1;
3332 }
3333
3334 wpa_s->group_cipher = ie.group_cipher;
3335 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3336 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3337 wpa_cipher_txt(wpa_s->group_cipher));
3338
3339 /* Update IGTK from AP RSN IE */
3340 sel = ie.mgmt_group_cipher;
3341 if (ssid->group_mgmt_cipher)
3342 sel &= ssid->group_mgmt_cipher;
3343
3344 wpa_dbg(wpa_s, MSG_DEBUG,
3345 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3346 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3347
3348 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3349 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3350 wpa_dbg(wpa_s, MSG_DEBUG,
3351 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3352 ie.capabilities);
3353 ie.mgmt_group_cipher = 0;
3354 }
3355
3356 if (ie.mgmt_group_cipher && !sel) {
3357 wpa_supplicant_deauthenticate(
3358 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3359 return -1;
3360 }
3361
3362 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3363 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3364 wpa_s->mgmt_group_cipher);
3365 if (wpa_s->mgmt_group_cipher)
3366 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3367 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3368 else
3369 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3370
3371 return 0;
3372}
3373
3374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003375static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3376 union wpa_event_data *data)
3377{
Hai Shalomc3565922019-10-28 11:58:20 -07003378 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003379 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003380 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003381 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003382#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303383 struct wpa_ie_data ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003384#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003385
3386 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Sunil Ravi7f769292024-07-23 22:21:32 +00003387 wpa_s->ssid_verified = false;
3388 wpa_s->bigtk_set = false;
3389#ifdef CONFIG_SAE
3390#ifdef CONFIG_SME
3391 /* SAE H2E binds the SSID into PT and that verifies the SSID
3392 * implicitly. */
3393 if (wpa_s->sme.sae.state == SAE_ACCEPTED && wpa_s->sme.sae.h2e)
3394 wpa_s->ssid_verified = true;
3395#endif /* CONFIG_SME */
3396#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -07003397 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003398 if (data->assoc_info.req_ies)
3399 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3400 data->assoc_info.req_ies_len);
3401 if (data->assoc_info.resp_ies) {
3402 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3403 data->assoc_info.resp_ies_len);
3404#ifdef CONFIG_TDLS
3405 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3406 data->assoc_info.resp_ies_len);
3407#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003408#ifdef CONFIG_WNM
3409 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3410 data->assoc_info.resp_ies_len);
3411#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003412 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3413 data->assoc_info.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003414 if (wpa_s->hw_capab == CAPAB_VHT &&
3415 get_ie(data->assoc_info.resp_ies,
3416 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3417 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003418
3419 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3420 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003421 }
3422 if (data->assoc_info.beacon_ies)
3423 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3424 data->assoc_info.beacon_ies,
3425 data->assoc_info.beacon_ies_len);
3426 if (data->assoc_info.freq)
3427 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3428 data->assoc_info.freq);
3429
Hai Shalom021b0b52019-04-10 11:17:58 -07003430 wpa_s->connection_set = 0;
3431 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3432 struct ieee802_11_elems req_elems, resp_elems;
3433
3434 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3435 data->assoc_info.req_ies_len,
3436 &req_elems, 0) != ParseFailed &&
3437 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3438 data->assoc_info.resp_ies_len,
3439 &resp_elems, 0) != ParseFailed) {
3440 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003441 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3442 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003443 wpa_s->connection_ht = req_elems.ht_capabilities &&
3444 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003445 /* Do not include subset of VHT on 2.4 GHz vendor
3446 * extension in consideration for reporting VHT
3447 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003448 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003449 resp_elems.vht_capabilities &&
3450 (!data->assoc_info.freq ||
3451 wpas_freq_to_band(data->assoc_info.freq) !=
3452 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003453 wpa_s->connection_he = req_elems.he_capabilities &&
3454 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003455 wpa_s->connection_eht = req_elems.eht_capabilities &&
3456 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003457
3458 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3459 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3460 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3461 max_nss_rx_req : max_nss_rx_resp;
3462 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3463 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3464 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3465 max_nss_tx_req : max_nss_tx_resp;
3466
3467 struct supported_chan_width sta_supported_chan_width =
3468 get_supported_channel_width(&req_elems);
3469 enum chan_width ap_operation_chan_width =
3470 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303471 if (wpa_s->connection_vht || wpa_s->connection_he ||
3472 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003473 wpa_s->connection_channel_bandwidth =
3474 get_sta_operation_chan_width(ap_operation_chan_width,
3475 sta_supported_chan_width);
3476 } else if (wpa_s->connection_ht) {
3477 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3478 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3479 } else {
3480 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3481 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003482 if (req_elems.rrm_enabled)
3483 wpa_s->rrm.rrm_used = 1;
Ainy Kumari322d4fd2024-02-14 13:05:40 +05303484 wpa_s->ap_t2lm_negotiation_support =
3485 is_ap_t2lm_negotiation_supported(resp_elems.basic_mle,
3486 resp_elems.basic_mle_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07003487 }
3488 }
3489
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003490 p = data->assoc_info.req_ies;
3491 l = data->assoc_info.req_ies_len;
3492
3493 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3494 while (p && l >= 2) {
3495 len = p[1] + 2;
3496 if (len > l) {
3497 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3498 p, l);
3499 break;
3500 }
Hai Shalomc3565922019-10-28 11:58:20 -07003501 if (!found &&
3502 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3503 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3504 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3505 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3506 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003507 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3508 break;
3509 found = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07003510 wpa_find_assoc_pmkid(wpa_s,
3511 data->assoc_info.authorized);
Hai Shalomc3565922019-10-28 11:58:20 -07003512 }
3513 if (!found_x && p[0] == WLAN_EID_RSNX) {
3514 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3515 break;
3516 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003517 }
3518 l -= len;
3519 p += len;
3520 }
3521 if (!found && data->assoc_info.req_ies)
3522 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003523 if (!found_x && data->assoc_info.req_ies)
3524 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003525
Winnie Chen4138eec2022-11-10 16:32:53 +08003526#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303527 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3528 * to a different security type, update the current supplicant configuration to use the AKM
3529 * and pairwise suites from the assoc IE passed by the driver.
3530 */
3531 if (wpas_driver_bss_selection(wpa_s)) {
3532 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3533 /* Check if firmware has roamed to a different security network */
3534 if(wpa_s->key_mgmt != ie.key_mgmt) {
3535 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3536 ie.key_mgmt);
3537 wpa_s->key_mgmt = ie.key_mgmt;
3538 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3539
3540 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3541 /* Restore PMK as it can get overwritten if the previous
3542 * association was to 802.1X.
3543 */
3544 if ((!(wpa_s->drv_flags &
3545 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3546 (wpa_s->current_ssid) &&
3547 (wpa_s->current_ssid->psk_set)) {
3548 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3549 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3550 "BSSID");
3551 wpa_supplicant_deauthenticate(
3552 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3553 return -1;
3554 }
3555 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3556 PMK_LEN, NULL, bssid);
3557 }
3558 }
3559 }
3560 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3561 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3562 "from Assoc IE", ie.pairwise_cipher);
3563 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3564 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3565 wpa_s->pairwise_cipher);
3566 }
3567 // TODO: Notify the framework about security type change b/230766005
3568 }
3569 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003570#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303571
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003572#ifdef CONFIG_FILS
3573#ifdef CONFIG_SME
Sunil Ravi7f769292024-07-23 22:21:32 +00003574 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3575 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) {
3576 if (!data->assoc_info.resp_frame ||
3577 fils_process_assoc_resp(wpa_s->wpa,
3578 data->assoc_info.resp_frame,
3579 data->assoc_info.resp_frame_len) <
3580 0) {
3581 wpa_supplicant_deauthenticate(wpa_s,
3582 WLAN_REASON_UNSPECIFIED);
3583 return -1;
3584 }
3585
3586 /* FILS use of an AEAD cipher include the SSID element in
3587 * (Re)Association Request frame in the AAD and since the AP
3588 * accepted that, the SSID was verified. */
3589 wpa_s->ssid_verified = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003590 }
3591#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003592
3593 /* Additional processing for FILS when SME is in driver */
3594 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3595 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3596 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003597#endif /* CONFIG_FILS */
3598
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003599#ifdef CONFIG_OWE
3600 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003601 !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003602 (!bssid_known ||
Sunil Ravi036cec52023-03-29 11:35:17 -07003603 owe_process_assoc_resp(wpa_s->wpa,
3604 wpa_s->valid_links ?
3605 wpa_s->ap_mld_addr : bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003606 data->assoc_info.resp_ies,
3607 data->assoc_info.resp_ies_len) < 0)) {
3608 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3609 return -1;
3610 }
3611#endif /* CONFIG_OWE */
3612
Hai Shalom021b0b52019-04-10 11:17:58 -07003613#ifdef CONFIG_DPP2
3614 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003615 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3616 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003617 struct ieee802_11_elems elems;
3618
3619 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3620 data->assoc_info.resp_ies_len,
3621 &elems, 0) == ParseFailed ||
3622 !elems.owe_dh)
3623 goto no_pfs;
3624 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3625 elems.owe_dh_len) < 0) {
3626 wpa_supplicant_deauthenticate(wpa_s,
3627 WLAN_REASON_UNSPECIFIED);
3628 return -1;
3629 }
3630
3631 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3632 }
3633no_pfs:
3634#endif /* CONFIG_DPP2 */
3635
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003636#ifdef CONFIG_IEEE80211R
3637#ifdef CONFIG_SME
3638 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003639 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003640 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3641 data->assoc_info.resp_ies,
3642 data->assoc_info.resp_ies_len,
3643 bssid) < 0) {
3644 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3645 "Reassociation Response failed");
3646 wpa_supplicant_deauthenticate(
3647 wpa_s, WLAN_REASON_INVALID_IE);
3648 return -1;
3649 }
Sunil Ravi7f769292024-07-23 22:21:32 +00003650 /* SSID is included in PMK-R0 derivation, so it is verified
3651 * implicitly. */
3652 wpa_s->ssid_verified = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003653 }
3654
3655 p = data->assoc_info.resp_ies;
3656 l = data->assoc_info.resp_ies_len;
3657
3658#ifdef CONFIG_WPS_STRICT
3659 if (p && wpa_s->current_ssid &&
3660 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3661 struct wpabuf *wps;
3662 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3663 if (wps == NULL) {
3664 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3665 "include WPS IE in (Re)Association Response");
3666 return -1;
3667 }
3668
3669 if (wps_validate_assoc_resp(wps) < 0) {
3670 wpabuf_free(wps);
3671 wpa_supplicant_deauthenticate(
3672 wpa_s, WLAN_REASON_INVALID_IE);
3673 return -1;
3674 }
3675 wpabuf_free(wps);
3676 }
3677#endif /* CONFIG_WPS_STRICT */
3678
3679 /* Go through the IEs and make a copy of the MDIE, if present. */
3680 while (p && l >= 2) {
3681 len = p[1] + 2;
3682 if (len > l) {
3683 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3684 p, l);
3685 break;
3686 }
3687 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3688 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3689 wpa_s->sme.ft_used = 1;
3690 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3691 MOBILITY_DOMAIN_ID_LEN);
3692 break;
3693 }
3694 l -= len;
3695 p += len;
3696 }
3697#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003698#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303699 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3700 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3701 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
Vinayak Yadawadf473bef2024-04-04 15:33:29 +05303702 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) ||
3703 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303704 wpa_ft_is_completed(wpa_s->wpa)) {
3705 return 0;
3706 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003707#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003708
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003709 /* Process FT when SME is in the driver */
3710 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3711 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003712 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003713 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3714 data->assoc_info.resp_ies,
3715 data->assoc_info.resp_ies_len,
3716 bssid) < 0) {
3717 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3718 "Reassociation Response failed");
3719 wpa_supplicant_deauthenticate(
3720 wpa_s, WLAN_REASON_INVALID_IE);
3721 return -1;
3722 }
3723 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
Sunil Ravi7f769292024-07-23 22:21:32 +00003724 /* SSID is included in PMK-R0 derivation, so it is verified
3725 * implicitly. */
3726 wpa_s->ssid_verified = true;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003727 }
3728
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003729 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3730 data->assoc_info.resp_ies_len);
3731#endif /* CONFIG_IEEE80211R */
3732
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003733#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07003734 if (bssid_known)
3735 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3736 data->assoc_info.resp_ies,
3737 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003738#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -07003739
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003740 /* WPA/RSN IE from Beacon/ProbeResp */
3741 p = data->assoc_info.beacon_ies;
3742 l = data->assoc_info.beacon_ies_len;
3743
3744 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3745 */
3746 wpa_found = rsn_found = 0;
3747 while (p && l >= 2) {
3748 len = p[1] + 2;
3749 if (len > l) {
3750 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3751 p, l);
3752 break;
3753 }
3754 if (!wpa_found &&
3755 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3756 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3757 wpa_found = 1;
3758 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3759 }
3760
3761 if (!rsn_found &&
3762 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3763 rsn_found = 1;
3764 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3765 }
3766
Sunil Ravi7f769292024-07-23 22:21:32 +00003767 if (wpas_rsn_overriding(wpa_s) &&
3768 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3769 WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_2_IE_VENDOR_TYPE) {
3770 rsn_found = 1;
3771 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3772 }
3773
3774 if (!rsn_found &&
3775 wpas_rsn_overriding(wpa_s) &&
3776 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3777 WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_IE_VENDOR_TYPE) {
3778 rsn_found = 1;
3779 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3780 }
3781
Hai Shalomc3565922019-10-28 11:58:20 -07003782 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3783 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3784
Sunil Ravi7f769292024-07-23 22:21:32 +00003785 if (wpas_rsn_overriding(wpa_s) &&
3786 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3787 WPA_GET_BE32(&p[2]) == RSNXE_OVERRIDE_IE_VENDOR_TYPE)
3788 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3789
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003790 l -= len;
3791 p += len;
3792 }
3793
3794 if (!wpa_found && data->assoc_info.beacon_ies)
3795 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003796 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003797 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003798 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3799 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003800 if (wpa_found || rsn_found)
3801 wpa_s->ap_ies_from_associnfo = 1;
3802
Sunil Ravi99c035e2024-07-12 01:42:03 +00003803 if (wpa_s->assoc_freq && data->assoc_info.freq) {
3804 struct wpa_bss *bss;
3805 unsigned int freq = 0;
3806
3807 if (bssid_known) {
3808 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
3809 if (bss)
3810 freq = bss->freq;
3811 }
3812 if (freq != data->assoc_info.freq) {
3813 wpa_printf(MSG_DEBUG,
3814 "Operating frequency changed from %u to %u MHz",
3815 wpa_s->assoc_freq, data->assoc_info.freq);
3816 wpa_supplicant_update_scan_results(wpa_s, bssid);
3817 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03003818 }
3819
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003820 wpa_s->assoc_freq = data->assoc_info.freq;
3821
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003822#ifndef CONFIG_NO_ROBUST_AV
Hai Shalomc1a21442022-02-04 13:43:00 -08003823 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3824 data->assoc_info.resp_ies_len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003825#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08003826
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003827 return 0;
3828}
3829
3830
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003831static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3832{
Hai Shalomc3565922019-10-28 11:58:20 -07003833 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003834
3835 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3836 return -1;
3837
3838 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3839 return 0;
3840
3841 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3842 WPA_IE_VENDOR_TYPE);
Sunil Ravi7f769292024-07-23 22:21:32 +00003843 bss_rsn = wpa_bss_get_rsne(wpa_s, wpa_s->current_bss, NULL,
3844 wpa_s->valid_links);
3845 bss_rsnx = wpa_bss_get_rsnxe(wpa_s, wpa_s->current_bss, NULL,
3846 wpa_s->valid_links);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003847
3848 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3849 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3850 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003851 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3852 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3853 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003854 return -1;
3855
3856 return 0;
3857}
3858
3859
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003860static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3861 union wpa_event_data *data)
3862{
3863#ifdef CONFIG_FST
3864 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3865 struct wpa_bss *bss = wpa_s->current_bss;
3866 const u8 *ieprb, *iebcn;
3867
3868 wpabuf_free(wpa_s->received_mb_ies);
3869 wpa_s->received_mb_ies = NULL;
3870
3871 if (ai &&
3872 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3873 wpa_printf(MSG_DEBUG,
3874 "FST: MB IEs updated from Association Response frame");
3875 return;
3876 }
3877
3878 if (ai &&
3879 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3880 wpa_printf(MSG_DEBUG,
3881 "FST: MB IEs updated from association event Beacon IEs");
3882 return;
3883 }
3884
3885 if (!bss)
3886 return;
3887
Hai Shalom60840252021-02-19 19:02:11 -08003888 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003889 iebcn = ieprb + bss->ie_len;
3890
3891 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3892 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3893 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3894 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3895#endif /* CONFIG_FST */
3896}
3897
3898
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003899static unsigned int wpas_ml_parse_assoc(struct wpa_supplicant *wpa_s,
3900 struct ieee802_11_elems *elems,
3901 struct ml_sta_link_info *ml_info)
3902{
3903 struct wpabuf *mlbuf;
3904 struct ieee80211_eht_ml *ml;
3905 size_t ml_len;
3906 struct eht_ml_basic_common_info *common_info;
3907 const u8 *pos;
3908 u16 eml_capa = 0, mld_capa = 0;
3909 const u16 control =
3910 host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC |
3911 BASIC_MULTI_LINK_CTRL_PRES_LINK_ID |
3912 BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT);
3913 u8 expected_common_info_len = 9;
3914 unsigned int i = 0;
3915 u16 ml_control;
3916
3917 if (!wpa_s->valid_links || !elems->basic_mle || !elems->basic_mle_len)
3918 return 0;
3919
3920 mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
3921 if (!mlbuf)
3922 return 0;
3923
3924 ml = (struct ieee80211_eht_ml *) wpabuf_head(mlbuf);
3925 ml_len = wpabuf_len(mlbuf);
3926 if (ml_len < sizeof(*ml))
3927 goto out;
3928
3929 os_memset(ml_info, 0, sizeof(*ml_info) * MAX_NUM_MLD_LINKS);
3930
3931 ml_control = le_to_host16(ml->ml_control);
3932
3933 if ((ml_control & control) != control) {
3934 wpa_printf(MSG_DEBUG, "MLD: Invalid presence BM=0x%x",
3935 ml_control);
3936 goto out;
3937 }
3938
3939 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
3940 wpa_printf(MSG_DEBUG, "MLD: EML capabilities included");
3941 expected_common_info_len += 2;
3942 }
3943
3944 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
3945 wpa_printf(MSG_DEBUG, "MLD: MLD capabilities included");
3946 expected_common_info_len += 2;
3947 }
3948
3949 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
3950 wpa_printf(MSG_DEBUG,
3951 "MLD: Unexpected: medium sync delay info present");
3952 expected_common_info_len += 2;
3953 }
3954
3955 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
3956 wpa_printf(MSG_DEBUG,
3957 "MLD: Unexpected: MLD ID present");
3958 expected_common_info_len++;
3959 }
3960
3961 if (sizeof(*ml) + expected_common_info_len > ml_len) {
3962 wpa_printf(MSG_DEBUG,
3963 "MLD: Not enough bytes for common info. ml_len=%zu",
3964 ml_len);
3965 goto out;
3966 }
3967
3968 common_info = (struct eht_ml_basic_common_info *) ml->variable;
3969 if (common_info->len != expected_common_info_len) {
3970 wpa_printf(MSG_DEBUG,
3971 "MLD: Invalid common info len=%u. expected=%u",
3972 common_info->len, expected_common_info_len);
3973 goto out;
3974 }
3975
3976 wpa_printf(MSG_DEBUG, "MLD: address: " MACSTR,
3977 MAC2STR(common_info->mld_addr));
3978
3979 if (!ether_addr_equal(wpa_s->ap_mld_addr, common_info->mld_addr)) {
3980 wpa_printf(MSG_DEBUG, "MLD: Mismatching MLD address (expected "
3981 MACSTR ")", MAC2STR(wpa_s->ap_mld_addr));
3982 goto out;
3983 }
3984
3985 pos = common_info->variable;
3986
3987 /* Store the information for the association link */
3988 ml_info[i].link_id = *pos;
3989 pos++;
3990
3991 /* Skip the BSS Parameters Change Count */
3992 pos++;
3993
3994 /* Skip the Medium Synchronization Delay Information if present */
3995 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO)
3996 pos += 2;
3997
3998 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
3999 eml_capa = WPA_GET_LE16(pos);
4000 pos += 2;
4001 }
4002
4003 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
4004 mld_capa = WPA_GET_LE16(pos);
4005 pos += 2;
4006 }
4007
4008 wpa_printf(MSG_DEBUG,
4009 "MLD: link_id=%u, eml=0x%x, mld=0x%x",
4010 ml_info[i].link_id, eml_capa, mld_capa);
4011
4012 i++;
4013
4014 pos = ((u8 *) common_info) + common_info->len;
4015 ml_len -= sizeof(*ml) + common_info->len;
4016 while (ml_len > 2 && i < MAX_NUM_MLD_LINKS) {
4017 u8 sub_elem_len = pos[1];
4018 u8 sta_info_len;
4019 u8 nstr_bitmap_len = 0;
4020 u16 ctrl;
4021 const u8 *end;
4022
4023 wpa_printf(MSG_DEBUG, "MLD: Subelement len=%u", sub_elem_len);
4024
4025 if (sub_elem_len > ml_len - 2) {
4026 wpa_printf(MSG_DEBUG,
4027 "MLD: Invalid link info len: %u > %zu",
4028 2 + sub_elem_len, ml_len);
4029 goto out;
4030 }
4031
4032 switch (*pos) {
4033 case EHT_ML_SUB_ELEM_PER_STA_PROFILE:
4034 break;
4035 case EHT_ML_SUB_ELEM_FRAGMENT:
4036 case EHT_ML_SUB_ELEM_VENDOR:
4037 wpa_printf(MSG_DEBUG,
4038 "MLD: Skip subelement id=%u, len=%u",
4039 *pos, sub_elem_len);
4040 pos += 2 + sub_elem_len;
4041 ml_len -= 2 + sub_elem_len;
4042 continue;
4043 default:
4044 wpa_printf(MSG_DEBUG, "MLD: Unknown subelement ID=%u",
4045 *pos);
4046 goto out;
4047 }
4048
4049 end = pos + 2 + sub_elem_len;
4050
4051 /* Skip the subelement ID and the length */
4052 pos += 2;
4053 ml_len -= 2;
4054
4055 if (end - pos < 2)
4056 goto out;
4057
4058 /* Get the station control field */
4059 ctrl = WPA_GET_LE16(pos);
4060
4061 pos += 2;
4062 ml_len -= 2;
4063
4064 if (!(ctrl & EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK)) {
4065 wpa_printf(MSG_DEBUG,
4066 "MLD: Per STA complete profile expected");
4067 goto out;
4068 }
4069
4070 if (!(ctrl & EHT_PER_STA_CTRL_MAC_ADDR_PRESENT_MSK)) {
4071 wpa_printf(MSG_DEBUG,
4072 "MLD: Per STA MAC address not present");
4073 goto out;
4074 }
4075
4076 if (!(ctrl & EHT_PER_STA_CTRL_TSF_OFFSET_PRESENT_MSK)) {
4077 wpa_printf(MSG_DEBUG,
4078 "MLD: Per STA TSF offset not present");
4079 goto out;
4080 }
4081
4082 if (!(ctrl & EHT_PER_STA_CTRL_BEACON_INTERVAL_PRESENT_MSK)) {
4083 wpa_printf(MSG_DEBUG,
4084 "MLD: Beacon interval not present");
4085 goto out;
4086 }
4087
4088 if (!(ctrl & EHT_PER_STA_CTRL_DTIM_INFO_PRESENT_MSK)) {
4089 wpa_printf(MSG_DEBUG,
4090 "MLD: DTIM information not present");
4091 goto out;
4092 }
4093
4094 if (ctrl & EHT_PER_STA_CTRL_NSTR_LINK_PAIR_PRESENT_MSK) {
4095 if (ctrl & EHT_PER_STA_CTRL_NSTR_BM_SIZE_MSK)
4096 nstr_bitmap_len = 2;
4097 else
4098 nstr_bitmap_len = 1;
4099 }
4100
4101 if (!(ctrl & EHT_PER_STA_CTRL_BSS_PARAM_CNT_PRESENT_MSK)) {
4102 wpa_printf(MSG_DEBUG,
4103 "MLD: BSS params change count not present");
4104 goto out;
4105 }
4106
4107 sta_info_len = 1 + ETH_ALEN + 8 + 2 + 2 + 1 + nstr_bitmap_len;
4108 if (sta_info_len > ml_len || sta_info_len > end - pos ||
4109 sta_info_len + 2 > sub_elem_len ||
4110 sta_info_len != *pos) {
4111 wpa_printf(MSG_DEBUG,
4112 "MLD: Invalid STA info len=%u, len=%u",
4113 sta_info_len, *pos);
4114 goto out;
4115 }
4116
4117 /* Get the link address */
4118 wpa_printf(MSG_DEBUG,
4119 "MLD: link addr: " MACSTR " nstr BM len=%u",
4120 MAC2STR(pos + 1), nstr_bitmap_len);
4121
4122 ml_info[i].link_id = ctrl & EHT_PER_STA_CTRL_LINK_ID_MSK;
4123 os_memcpy(ml_info[i].bssid, pos + 1, ETH_ALEN);
4124
4125 pos += sta_info_len;
4126 ml_len -= sta_info_len;
4127
4128 wpa_printf(MSG_DEBUG, "MLD: sub_elem_len=%u, sta_info_len=%u",
4129 sub_elem_len, sta_info_len);
4130
4131 sub_elem_len -= sta_info_len + 2;
4132 if (sub_elem_len < 4) {
4133 wpa_printf(MSG_DEBUG, "MLD: Per STA profile too short");
4134 goto out;
4135 }
4136
4137 wpa_hexdump(MSG_MSGDUMP, "MLD: STA profile", pos, sub_elem_len);
4138 ml_info[i].status = WPA_GET_LE16(pos + 2);
4139
4140 pos += sub_elem_len;
4141 ml_len -= sub_elem_len;
4142
4143 i++;
4144 }
4145
4146 wpabuf_free(mlbuf);
4147 return i;
4148out:
4149 wpabuf_free(mlbuf);
4150 return 0;
4151}
4152
4153
Sunil Ravi89eba102022-09-13 21:04:37 -07004154static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
4155{
4156 struct driver_sta_mlo_info mlo;
4157 int i;
4158
Sunil Ravi77d572f2023-01-17 23:58:31 +00004159 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07004160 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
4161 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
4162 wpa_supplicant_deauthenticate(wpa_s,
4163 WLAN_REASON_DEAUTH_LEAVING);
4164 return -1;
4165 }
4166
4167 if (wpa_s->valid_links == mlo.valid_links) {
4168 bool match = true;
4169
4170 if (!mlo.valid_links)
4171 return 0;
4172
Sunil Ravi99c035e2024-07-12 01:42:03 +00004173 for_each_link(mlo.valid_links, i) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004174 if (!ether_addr_equal(wpa_s->links[i].addr,
4175 mlo.links[i].addr) ||
4176 !ether_addr_equal(wpa_s->links[i].bssid,
4177 mlo.links[i].bssid)) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004178 match = false;
4179 break;
4180 }
4181 }
4182
Sunil Ravi77d572f2023-01-17 23:58:31 +00004183 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004184 ether_addr_equal(wpa_s->ap_mld_addr, mlo.ap_mld_addr))
Sunil Ravi89eba102022-09-13 21:04:37 -07004185 return 0;
4186 }
4187
4188 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00004189 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07004190 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
Sunil Ravi99c035e2024-07-12 01:42:03 +00004191 for_each_link(wpa_s->valid_links, i) {
Sunil Ravi89eba102022-09-13 21:04:37 -07004192 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
4193 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
4194 wpa_s->links[i].freq = mlo.links[i].freq;
4195 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
4196 }
4197
4198 return 0;
4199}
4200
4201
Sunil Ravi77d572f2023-01-17 23:58:31 +00004202static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
4203{
4204 struct driver_sta_mlo_info drv_mlo;
4205 struct wpa_sm_mlo wpa_mlo;
4206 const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
4207 int i;
4208
4209 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
4210 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
4211 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
4212 return -1;
4213 }
4214
4215 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
4216 if (!drv_mlo.valid_links)
4217 goto out;
4218
4219 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
4220 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
4221 wpa_mlo.valid_links = drv_mlo.valid_links;
4222 wpa_mlo.req_links = drv_mlo.req_links;
4223
Sunil Ravi99c035e2024-07-12 01:42:03 +00004224 for_each_link(drv_mlo.req_links, i) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004225 struct wpa_bss *bss;
4226
Sunil Ravi77d572f2023-01-17 23:58:31 +00004227 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
4228 if (!bss) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004229 wpa_dbg(wpa_s, MSG_INFO,
4230 "Failed to get MLO link %d BSS", i);
4231 return -1;
4232 }
4233
Sunil Ravi7f769292024-07-23 22:21:32 +00004234 bss_rsn = wpa_bss_get_rsne(wpa_s, bss, NULL, true);
4235 bss_rsnx = wpa_bss_get_rsnxe(wpa_s, bss, NULL, true);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004236
4237 wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
4238 wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
4239 wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
4240 wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
4241
4242 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
4243 ETH_ALEN);
4244 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
4245 ETH_ALEN);
4246 }
4247
4248out:
4249 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
4250}
4251
4252
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004253static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
4254 union wpa_event_data *data)
4255{
4256 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004257 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004258 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07004259#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4260 struct wpa_bss *bss;
4261#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08004262#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304263 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08004264#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004265
4266#ifdef CONFIG_AP
4267 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004268 if (!data)
4269 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004270 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
4271 data->assoc_info.addr,
4272 data->assoc_info.req_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004273 data->assoc_info.req_ies_len, NULL, 0,
4274 NULL, data->assoc_info.reassoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004275 return;
4276 }
4277#endif /* CONFIG_AP */
4278
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004279 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07004280 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004281
Andy Kuoaba17c12022-04-14 16:05:31 +08004282#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05304283 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
4284 struct wpa_ft_ies parse;
4285 /* Check for FT reassociation is done by the driver */
4286#ifdef CONFIG_IEEE80211R
4287 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05304288 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05304289 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004290 data->assoc_info.resp_ies_len, &parse, use_sha384, false) < 0) {
Mir Ali677e7482020-11-12 19:49:02 +05304291 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
4292 return;
4293 }
4294 if (parse.rsn_pmkid != NULL) {
4295 wpa_set_ft_completed(wpa_s->wpa);
4296 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
4297 }
4298 }
4299#endif /* CONFIG_IEEE80211R */
4300 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004301#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05304302
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004303 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07004304
4305 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4306 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
4307 wpa_supplicant_deauthenticate(
4308 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4309 return;
4310 }
4311
Sunil Ravi89eba102022-09-13 21:04:37 -07004312 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
4313 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
4314 wpa_supplicant_deauthenticate(wpa_s,
4315 WLAN_REASON_DEAUTH_LEAVING);
4316 return;
4317 }
4318
Sunil Ravia04bd252022-05-02 22:54:18 -07004319 if (ft_completed &&
4320 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
4321 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
4322 MAC2STR(bssid));
4323 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
4324 wpa_printf(MSG_ERROR,
4325 "Can't find target AP's information!");
4326 return;
4327 }
4328 wpa_supplicant_assoc_update_ie(wpa_s);
4329 }
4330
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004331 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
4332 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004333 /*
4334 * FILS authentication can share the same mechanism to mark the
4335 * connection fully authenticated, so set ft_completed also based on
4336 * FILS result.
4337 */
4338 if (!ft_completed)
4339 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004340
Andy Kuoaba17c12022-04-14 16:05:31 +08004341#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304342 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
4343 /*
4344 * For driver based roaming, insert PSK during
4345 * the initial association
4346 */
4347 if (is_zero_ether_addr(wpa_s->bssid) &&
4348 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
4349 /*
4350 * In case the driver wants to handle re-assocs,
4351 * pass it down the PMK.
4352 */
4353 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
4354 wpa_sm_install_pmk(wpa_s->wpa);
4355 }
Mir Ali677e7482020-11-12 19:49:02 +05304356 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304357#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08004358
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004359 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004360 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004361 if (os_reltime_initialized(&wpa_s->session_start)) {
4362 os_reltime_age(&wpa_s->session_start,
4363 &wpa_s->session_length);
4364 wpa_s->session_start.sec = 0;
4365 wpa_s->session_start.usec = 0;
4366 wpas_notify_session_length(wpa_s);
4367 } else {
4368 wpas_notify_auth_changed(wpa_s);
4369 os_get_reltime(&wpa_s->session_start);
4370 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004371 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
4372 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004373 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004374 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004375 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4376 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004377 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004378
4379 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
4380 wpa_clear_keys(wpa_s, bssid);
4381 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00004382 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004383 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004384 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4385 return;
4386 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004387 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004388
Hai Shalomc1a21442022-02-04 13:43:00 -08004389 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4390 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
4391 return;
4392
Hai Shalomfdcde762020-04-02 11:19:20 -07004393 multi_ap_set_4addr_mode(wpa_s);
4394
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004395 if (wpa_s->conf->ap_scan == 1 &&
4396 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07004397 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
4398 wpa_msg(wpa_s, MSG_WARNING,
4399 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004400 }
4401
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004402 wpas_fst_update_mb_assoc(wpa_s, data);
4403
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004404#ifdef CONFIG_SME
Sunil Ravi640215c2023-06-28 23:08:09 +00004405 /*
4406 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
4407 * (for MLO connection) as the previous BSSID for subsequent
4408 * reassociation requests handled by SME-in-wpa_supplicant.
4409 */
4410 os_memcpy(wpa_s->sme.prev_bssid,
4411 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004412 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07004413 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004414#endif /* CONFIG_SME */
4415
4416 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
4417 if (wpa_s->current_ssid) {
4418 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
4419 * initialized before association, but for other modes,
4420 * initialize PC/SC here, if the current configuration needs
4421 * smartcard or SIM/USIM. */
4422 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
4423 }
4424 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004425
4426 if (wpa_sm_set_ml_info(wpa_s)) {
4427 wpa_dbg(wpa_s, MSG_INFO,
4428 "Failed to set MLO connection info to wpa_sm");
4429 wpa_supplicant_deauthenticate(wpa_s,
4430 WLAN_REASON_DEAUTH_LEAVING);
4431 return;
4432 }
4433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004434 if (wpa_s->l2)
4435 l2_packet_notify_auth_start(wpa_s->l2);
4436
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004437 already_authorized = data && data->assoc_info.authorized;
4438
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004439 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07004440 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004441 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
4442 * state machine may transit to AUTHENTICATING state based on obsolete
4443 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
4444 * AUTHENTICATED without ever giving chance to EAP state machine to
4445 * reset the state.
4446 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004447 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07004448 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4449 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004450 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004451 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4452 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
4453 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07004454 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07004455 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004456 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07004457 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004458 wpa_s->eapol_received = 0;
4459 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4460 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4461 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004462 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004463 if (wpa_s->current_ssid &&
4464 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004465 (wpa_s->drv_flags &
4466 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4467 /*
4468 * Set the key after having received joined-IBSS event
4469 * from the driver.
4470 */
4471 wpa_supplicant_set_wpa_none_key(wpa_s,
4472 wpa_s->current_ssid);
4473 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004474 wpa_supplicant_cancel_auth_timeout(wpa_s);
4475 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4476 } else if (!ft_completed) {
4477 /* Timeout for receiving the first EAPOL packet */
4478 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
4479 }
4480 wpa_supplicant_cancel_scan(wpa_s);
4481
Hai Shalom5f92bc92019-04-18 11:54:11 -07004482 if (ft_completed) {
4483 /*
4484 * FT protocol completed - make sure EAPOL state machine ends
4485 * up in authenticated.
4486 */
4487 wpa_supplicant_cancel_auth_timeout(wpa_s);
4488 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004489 eapol_sm_notify_portValid(wpa_s->eapol, true);
4490 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07004491 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4492 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304493 if (already_authorized) {
4494 /*
4495 * We are done; the driver will take care of RSN 4-way
4496 * handshake.
4497 */
4498 wpa_supplicant_cancel_auth_timeout(wpa_s);
4499 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4500 eapol_sm_notify_portValid(wpa_s->eapol, true);
4501 eapol_sm_notify_eap_success(wpa_s->eapol, true);
4502 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004503 /* Update port, WPA_COMPLETED state from the
4504 * EVENT_PORT_AUTHORIZED handler when the driver is done
4505 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304506 */
Sunil Ravi167279a2023-05-31 01:12:34 +00004507 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004508 wpa_msg(wpa_s, MSG_INFO,
4509 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304510 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004511 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004512 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4513 /*
4514 * The driver will take care of RSN 4-way handshake, so we need
4515 * to allow EAPOL supplicant to complete its work without
4516 * waiting for WPA supplicant.
4517 */
Hai Shalome21d4e82020-04-29 16:34:06 -07004518 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004519 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004520#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05304521 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
4522 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4523 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
4524 wpa_s->key_mgmt);
4525 wpa_supplicant_deauthenticate(
4526 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4527 return;
4528 }
4529 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4530 wpa_s->assoc_freq = data->assoc_info.freq;
4531 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
4532 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004533#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
4534
Jouni Malinena05074c2012-12-21 21:35:35 +02004535 wpa_s->last_eapol_matches_bssid = 0;
4536
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004537#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07004538 if (wpa_s->rsne_override_eapol) {
4539 wpa_printf(MSG_DEBUG,
4540 "TESTING: RSNE EAPOL-Key msg 2/4 override");
4541 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4542 wpabuf_head(wpa_s->rsne_override_eapol),
4543 wpabuf_len(wpa_s->rsne_override_eapol));
4544 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004545 if (wpa_s->rsnxe_override_eapol) {
4546 wpa_printf(MSG_DEBUG,
4547 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4548 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4549 wpabuf_head(wpa_s->rsnxe_override_eapol),
4550 wpabuf_len(wpa_s->rsnxe_override_eapol));
4551 }
4552#endif /* CONFIG_TESTING_OPTIONS */
4553
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004554 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004555 struct os_reltime now, age;
4556 os_get_reltime(&now);
4557 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08004558 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004559 ether_addr_equal(wpa_s->pending_eapol_rx_src,
4560 wpa_s->valid_links ? wpa_s->ap_mld_addr :
4561 bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004562 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4563 "frame that was received just before "
4564 "association notification");
4565 wpa_supplicant_rx_eapol(
4566 wpa_s, wpa_s->pending_eapol_rx_src,
4567 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00004568 wpabuf_len(wpa_s->pending_eapol_rx),
4569 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004570 }
4571 wpabuf_free(wpa_s->pending_eapol_rx);
4572 wpa_s->pending_eapol_rx = NULL;
4573 }
4574
Hai Shalomfdcde762020-04-02 11:19:20 -07004575#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004576 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4577 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004578 wpa_s->current_ssid &&
4579 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004580 /* Set static WEP keys again */
4581 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4582 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004583#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004584
4585#ifdef CONFIG_IBSS_RSN
4586 if (wpa_s->current_ssid &&
4587 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4588 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4589 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4590 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004591 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004592 if (!wpa_s->ibss_rsn) {
4593 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4594 wpa_supplicant_deauthenticate(
4595 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4596 return;
4597 }
4598
4599 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4600 }
4601#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004602
4603 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004604
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004605#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004606 if (data) {
4607 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4608 data->assoc_info.resp_ies_len,
4609 &data->assoc_info.wmm_params);
4610
4611 if (wpa_s->reassoc_same_bss)
4612 wmm_ac_restore_tspecs(wpa_s);
4613 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004614#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004615
Hai Shalomc3565922019-10-28 11:58:20 -07004616#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4617 bss = wpa_bss_get_bssid(wpa_s, bssid);
4618#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004619#ifdef CONFIG_FILS
4620 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004621 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4622
4623 if (fils_cache_id)
4624 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4625 }
4626#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004627
4628#ifdef CONFIG_MBO
4629 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4630#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004631
4632#ifdef CONFIG_DPP2
4633 wpa_s->dpp_pfs_fallback = 0;
4634#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004635
4636 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4637 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004638}
4639
4640
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004641static int disconnect_reason_recoverable(u16 reason_code)
4642{
4643 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4644 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4645 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4646}
4647
4648
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004649static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004650 u16 reason_code,
4651 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004652{
4653 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004654
4655 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4656 /*
4657 * At least Host AP driver and a Prism3 card seemed to be
4658 * generating streams of disconnected events when configuring
4659 * IBSS for WPA-None. Ignore them for now.
4660 */
4661 return;
4662 }
4663
4664 bssid = wpa_s->bssid;
4665 if (is_zero_ether_addr(bssid))
4666 bssid = wpa_s->pending_bssid;
4667
4668 if (!is_zero_ether_addr(bssid) ||
4669 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4670 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4671 " reason=%d%s",
4672 MAC2STR(bssid), reason_code,
4673 locally_generated ? " locally_generated=1" : "");
4674 }
4675}
4676
4677
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004678static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4679 int locally_generated)
4680{
4681 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004682 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004683 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4684 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004685 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004686
4687 /*
4688 * It looks like connection was lost while trying to go through PSK
4689 * 4-way handshake. Filter out known disconnection cases that are caused
4690 * by something else than PSK mismatch to avoid confusing reports.
4691 */
4692
4693 if (locally_generated) {
4694 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4695 return 0;
4696 }
4697
4698 return 1;
4699}
4700
4701
Jouni Malinen2b89da82012-08-31 22:04:41 +03004702static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4703 u16 reason_code,
4704 int locally_generated)
4705{
4706 const u8 *bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004707 struct wpa_bss *fast_reconnect = NULL;
4708 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004709 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004710
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004711 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4712 /*
4713 * At least Host AP driver and a Prism3 card seemed to be
4714 * generating streams of disconnected events when configuring
4715 * IBSS for WPA-None. Ignore them for now.
4716 */
4717 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4718 "IBSS/WPA-None mode");
4719 return;
4720 }
4721
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004722 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4723 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4724 locally_generated)
4725 /*
4726 * Remove the inactive AP (which is probably out of range) from
4727 * the BSS list after marking disassociation. In particular
4728 * mac80211-based drivers use the
4729 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4730 * locally generated disconnection events for cases where the
4731 * AP does not reply anymore.
4732 */
4733 curr = wpa_s->current_bss;
4734
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004735 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004736 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4737 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004738 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4739 return; /* P2P group removed */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004740 wpas_auth_failed(wpa_s, "WRONG_KEY", wpa_s->pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004741 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004742#ifdef CONFIG_DPP2
4743 wpas_dpp_send_conn_status_result(wpa_s,
4744 DPP_STATUS_AUTH_FAILURE);
4745#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004746 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004747 if (!wpa_s->disconnected &&
4748 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004749 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004750 wpas_wps_searching(wpa_s) ||
4751 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004752 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004753 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004754 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004755 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004756 wpa_s->wpa_state);
4757 if (wpa_s->wpa_state == WPA_COMPLETED &&
4758 wpa_s->current_ssid &&
4759 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004760 (wpa_s->own_reconnect_req ||
4761 (!locally_generated &&
4762 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004763 /*
4764 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004765 * us, but could allow us to get back in. This is also
4766 * triggered for cases where local reconnection request
4767 * is used to force reassociation with the same BSS.
4768 * Try to reconnect to the same BSS without a full scan
4769 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004770 */
4771 fast_reconnect = wpa_s->current_bss;
4772 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004773 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004774 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004775 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004776 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4777 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004778 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004779 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004780 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004781 "try to re-connect");
4782 wpa_s->reassociate = 0;
4783 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004784 if (!wpa_s->pno)
4785 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004786 }
4787 bssid = wpa_s->bssid;
4788 if (is_zero_ether_addr(bssid))
4789 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004790 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004791 wpas_connection_failed(wpa_s, bssid, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004792 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004793 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4794
Dmitry Shmidt04949592012-07-19 12:16:46 -07004795 if (locally_generated)
4796 wpa_s->disconnect_reason = -reason_code;
4797 else
4798 wpa_s->disconnect_reason = reason_code;
4799 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004800 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4801 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004802 wpa_clear_keys(wpa_s, wpa_s->bssid);
4803 }
4804 wpa_supplicant_mark_disassoc(wpa_s);
4805
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004806 if (curr)
4807 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4808
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004809 if (fast_reconnect &&
4810 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4811 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4812 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4813 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004814 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004815 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004816#ifndef CONFIG_NO_SCAN_PROCESSING
4817 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4818 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4819 fast_reconnect_ssid) < 0) {
4820 /* Recover through full scan */
4821 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4822 }
4823#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004824 } else if (fast_reconnect) {
4825 /*
4826 * Could not reconnect to the same BSS due to network being
4827 * disabled. Use a new scan to match the alternative behavior
4828 * above, i.e., to continue automatic reconnection attempt in a
4829 * way that enforces disabled network rules.
4830 */
4831 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004832 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004833}
4834
4835
4836#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004837void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004838{
4839 struct wpa_supplicant *wpa_s = eloop_ctx;
4840
4841 if (!wpa_s->pending_mic_error_report)
4842 return;
4843
4844 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4845 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4846 wpa_s->pending_mic_error_report = 0;
4847}
4848#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4849
4850
4851static void
4852wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4853 union wpa_event_data *data)
4854{
4855 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004856 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004857
4858 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4859 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004860 os_get_reltime(&t);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004861 if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004862 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004863 wpa_s->pending_mic_error_report) {
4864 if (wpa_s->pending_mic_error_report) {
4865 /*
4866 * Send the pending MIC error report immediately since
4867 * we are going to start countermeasures and AP better
4868 * do the same.
4869 */
4870 wpa_sm_key_request(wpa_s->wpa, 1,
4871 wpa_s->pending_mic_error_pairwise);
4872 }
4873
4874 /* Send the new MIC error report immediately since we are going
4875 * to start countermeasures and AP better do the same.
4876 */
4877 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4878
4879 /* initialize countermeasures */
4880 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004881
Hai Shalom60840252021-02-19 19:02:11 -08004882 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004883
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004884 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4885
4886 /*
4887 * Need to wait for completion of request frame. We do not get
4888 * any callback for the message completion, so just wait a
4889 * short while and hope for the best. */
4890 os_sleep(0, 10000);
4891
4892 wpa_drv_set_countermeasures(wpa_s, 1);
4893 wpa_supplicant_deauthenticate(wpa_s,
4894 WLAN_REASON_MICHAEL_MIC_FAILURE);
4895 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4896 wpa_s, NULL);
4897 eloop_register_timeout(60, 0,
4898 wpa_supplicant_stop_countermeasures,
4899 wpa_s, NULL);
4900 /* TODO: mark the AP rejected for 60 second. STA is
4901 * allowed to associate with another AP.. */
4902 } else {
4903#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4904 if (wpa_s->mic_errors_seen) {
4905 /*
4906 * Reduce the effectiveness of Michael MIC error
4907 * reports as a means for attacking against TKIP if
4908 * more than one MIC failure is noticed with the same
4909 * PTK. We delay the transmission of the reports by a
4910 * random time between 0 and 60 seconds in order to
4911 * force the attacker wait 60 seconds before getting
4912 * the information on whether a frame resulted in a MIC
4913 * failure.
4914 */
4915 u8 rval[4];
4916 int sec;
4917
4918 if (os_get_random(rval, sizeof(rval)) < 0)
4919 sec = os_random() % 60;
4920 else
4921 sec = WPA_GET_BE32(rval) % 60;
4922 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4923 "report %d seconds", sec);
4924 wpa_s->pending_mic_error_report = 1;
4925 wpa_s->pending_mic_error_pairwise = pairwise;
4926 eloop_cancel_timeout(
4927 wpa_supplicant_delayed_mic_error_report,
4928 wpa_s, NULL);
4929 eloop_register_timeout(
4930 sec, os_random() % 1000000,
4931 wpa_supplicant_delayed_mic_error_report,
4932 wpa_s, NULL);
4933 } else {
4934 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4935 }
4936#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4937 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4938#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4939 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004940 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004941 wpa_s->mic_errors_seen++;
4942}
4943
4944
4945#ifdef CONFIG_TERMINATE_ONLASTIF
4946static int any_interfaces(struct wpa_supplicant *head)
4947{
4948 struct wpa_supplicant *wpa_s;
4949
4950 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4951 if (!wpa_s->interface_removed)
4952 return 1;
4953 return 0;
4954}
4955#endif /* CONFIG_TERMINATE_ONLASTIF */
4956
4957
4958static void
4959wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4960 union wpa_event_data *data)
4961{
4962 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4963 return;
4964
4965 switch (data->interface_status.ievent) {
4966 case EVENT_INTERFACE_ADDED:
4967 if (!wpa_s->interface_removed)
4968 break;
4969 wpa_s->interface_removed = 0;
4970 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4971 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4972 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4973 "driver after interface was added");
4974 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004975
4976#ifdef CONFIG_P2P
4977 if (!wpa_s->global->p2p &&
4978 !wpa_s->global->p2p_disabled &&
4979 !wpa_s->conf->p2p_disabled &&
4980 (wpa_s->drv_flags &
4981 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4982 wpas_p2p_add_p2pdev_interface(
4983 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4984 wpa_printf(MSG_INFO,
4985 "P2P: Failed to enable P2P Device interface");
4986 /* Try to continue without. P2P will be disabled. */
4987 }
4988#endif /* CONFIG_P2P */
4989
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004990 break;
4991 case EVENT_INTERFACE_REMOVED:
4992 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4993 wpa_s->interface_removed = 1;
4994 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004995 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004996 l2_packet_deinit(wpa_s->l2);
4997 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004998
4999#ifdef CONFIG_P2P
5000 if (wpa_s->global->p2p &&
5001 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
5002 (wpa_s->drv_flags &
5003 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
5004 wpa_dbg(wpa_s, MSG_DEBUG,
5005 "Removing P2P Device interface");
5006 wpa_supplicant_remove_iface(
5007 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
5008 0);
5009 wpa_s->global->p2p_init_wpa_s = NULL;
5010 }
5011#endif /* CONFIG_P2P */
5012
Dmitry Shmidte4663042016-04-04 10:07:49 -07005013#ifdef CONFIG_MATCH_IFACE
5014 if (wpa_s->matched) {
5015 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
5016 break;
5017 }
5018#endif /* CONFIG_MATCH_IFACE */
5019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005020#ifdef CONFIG_TERMINATE_ONLASTIF
5021 /* check if last interface */
5022 if (!any_interfaces(wpa_s->global->ifaces))
5023 eloop_terminate();
5024#endif /* CONFIG_TERMINATE_ONLASTIF */
5025 break;
5026 }
5027}
5028
5029
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005030#ifdef CONFIG_TDLS
5031static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
5032 union wpa_event_data *data)
5033{
5034 if (data == NULL)
5035 return;
5036 switch (data->tdls.oper) {
5037 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005038 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
5039 if (wpa_tdls_is_external_setup(wpa_s->wpa))
5040 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
5041 else
5042 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005043 break;
5044 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03005045 if (wpa_tdls_is_external_setup(wpa_s->wpa))
5046 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
5047 data->tdls.reason_code);
5048 else
5049 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
5050 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005051 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07005052 case TDLS_REQUEST_DISCOVER:
5053 wpa_tdls_send_discovery_request(wpa_s->wpa,
5054 data->tdls.peer);
5055 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005056 }
5057}
5058#endif /* CONFIG_TDLS */
5059
5060
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005061#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005062static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
5063 union wpa_event_data *data)
5064{
5065 if (data == NULL)
5066 return;
5067 switch (data->wnm.oper) {
5068 case WNM_OPER_SLEEP:
5069 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
5070 "(action=%d, intval=%d)",
5071 data->wnm.sleep_action, data->wnm.sleep_intval);
5072 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005073 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005074 break;
5075 }
5076}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005077#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005078
5079
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005080#ifdef CONFIG_IEEE80211R
5081static void
5082wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
5083 union wpa_event_data *data)
5084{
5085 if (data == NULL)
5086 return;
5087
5088 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
5089 data->ft_ies.ies_len,
5090 data->ft_ies.ft_action,
5091 data->ft_ies.target_ap,
5092 data->ft_ies.ric_ies,
5093 data->ft_ies.ric_ies_len) < 0) {
5094 /* TODO: prevent MLME/driver from trying to associate? */
5095 }
5096}
5097#endif /* CONFIG_IEEE80211R */
5098
5099
5100#ifdef CONFIG_IBSS_RSN
5101static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
5102 union wpa_event_data *data)
5103{
5104 struct wpa_ssid *ssid;
5105 if (wpa_s->wpa_state < WPA_ASSOCIATED)
5106 return;
5107 if (data == NULL)
5108 return;
5109 ssid = wpa_s->current_ssid;
5110 if (ssid == NULL)
5111 return;
5112 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5113 return;
5114
5115 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
5116}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005117
5118
5119static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
5120 union wpa_event_data *data)
5121{
5122 struct wpa_ssid *ssid = wpa_s->current_ssid;
5123
5124 if (ssid == NULL)
5125 return;
5126
5127 /* check if the ssid is correctly configured as IBSS/RSN */
5128 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5129 return;
5130
5131 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
5132 data->rx_mgmt.frame_len);
5133}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005134#endif /* CONFIG_IBSS_RSN */
5135
5136
5137#ifdef CONFIG_IEEE80211R
5138static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
5139 size_t len)
5140{
5141 const u8 *sta_addr, *target_ap_addr;
5142 u16 status;
5143
5144 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
5145 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
5146 return; /* only SME case supported for now */
5147 if (len < 1 + 2 * ETH_ALEN + 2)
5148 return;
5149 if (data[0] != 2)
5150 return; /* Only FT Action Response is supported for now */
5151 sta_addr = data + 1;
5152 target_ap_addr = data + 1 + ETH_ALEN;
5153 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
5154 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
5155 MACSTR " TargetAP " MACSTR " status %u",
5156 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
5157
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005158 if (!ether_addr_equal(sta_addr, wpa_s->own_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005159 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
5160 " in FT Action Response", MAC2STR(sta_addr));
5161 return;
5162 }
5163
5164 if (status) {
5165 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
5166 "failure (status code %d)", status);
5167 /* TODO: report error to FT code(?) */
5168 return;
5169 }
5170
5171 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
5172 len - (1 + 2 * ETH_ALEN + 2), 1,
5173 target_ap_addr, NULL, 0) < 0)
5174 return;
5175
5176#ifdef CONFIG_SME
5177 {
5178 struct wpa_bss *bss;
5179 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
5180 if (bss)
5181 wpa_s->sme.freq = bss->freq;
5182 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
5183 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
5184 WLAN_AUTH_FT);
5185 }
5186#endif /* CONFIG_SME */
5187}
5188#endif /* CONFIG_IEEE80211R */
5189
5190
5191static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
5192 struct unprot_deauth *e)
5193{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005194 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
5195 "dropped: " MACSTR " -> " MACSTR
5196 " (reason code %u)",
5197 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5198 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005199}
5200
5201
5202static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
5203 struct unprot_disassoc *e)
5204{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005205 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
5206 "dropped: " MACSTR " -> " MACSTR
5207 " (reason code %u)",
5208 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5209 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005210}
5211
5212
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005213static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
5214 u16 reason_code, int locally_generated,
5215 const u8 *ie, size_t ie_len, int deauth)
5216{
5217#ifdef CONFIG_AP
5218 if (wpa_s->ap_iface && addr) {
5219 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
5220 return;
5221 }
5222
5223 if (wpa_s->ap_iface) {
5224 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
5225 return;
5226 }
5227#endif /* CONFIG_AP */
5228
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005229 if (!locally_generated)
5230 wpa_s->own_disconnect_req = 0;
5231
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005232 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
5233
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005234 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
5235 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
5236 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
5237 eapol_sm_failed(wpa_s->eapol))) &&
5238 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00005239 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005240
5241#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07005242 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005243 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
5244 locally_generated) > 0) {
5245 /*
5246 * The interface was removed, so cannot continue
5247 * processing any additional operations after this.
5248 */
5249 return;
5250 }
5251 }
5252#endif /* CONFIG_P2P */
5253
5254 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
5255 locally_generated);
5256}
5257
5258
5259static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
5260 struct disassoc_info *info)
5261{
5262 u16 reason_code = 0;
5263 int locally_generated = 0;
5264 const u8 *addr = NULL;
5265 const u8 *ie = NULL;
5266 size_t ie_len = 0;
5267
5268 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
5269
5270 if (info) {
5271 addr = info->addr;
5272 ie = info->ie;
5273 ie_len = info->ie_len;
5274 reason_code = info->reason_code;
5275 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005276 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
5277 reason2str(reason_code),
5278 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005279 if (addr)
5280 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5281 MAC2STR(addr));
5282 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
5283 ie, ie_len);
5284 }
5285
5286#ifdef CONFIG_AP
5287 if (wpa_s->ap_iface && info && info->addr) {
5288 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
5289 return;
5290 }
5291
5292 if (wpa_s->ap_iface) {
5293 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
5294 return;
5295 }
5296#endif /* CONFIG_AP */
5297
5298#ifdef CONFIG_P2P
5299 if (info) {
5300 wpas_p2p_disassoc_notif(
5301 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
5302 locally_generated);
5303 }
5304#endif /* CONFIG_P2P */
5305
5306 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5307 sme_event_disassoc(wpa_s, info);
5308
5309 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
5310 ie, ie_len, 0);
5311}
5312
5313
5314static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
5315 struct deauth_info *info)
5316{
5317 u16 reason_code = 0;
5318 int locally_generated = 0;
5319 const u8 *addr = NULL;
5320 const u8 *ie = NULL;
5321 size_t ie_len = 0;
5322
5323 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
5324
5325 if (info) {
5326 addr = info->addr;
5327 ie = info->ie;
5328 ie_len = info->ie_len;
5329 reason_code = info->reason_code;
5330 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07005331 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
5332 reason_code, reason2str(reason_code),
5333 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005334 if (addr) {
5335 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5336 MAC2STR(addr));
5337 }
5338 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
5339 ie, ie_len);
5340 }
5341
5342 wpa_reset_ft_completed(wpa_s->wpa);
5343
5344 wpas_event_disconnect(wpa_s, addr, reason_code,
5345 locally_generated, ie, ie_len, 1);
5346}
5347
5348
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005349static const char * reg_init_str(enum reg_change_initiator init)
5350{
5351 switch (init) {
5352 case REGDOM_SET_BY_CORE:
5353 return "CORE";
5354 case REGDOM_SET_BY_USER:
5355 return "USER";
5356 case REGDOM_SET_BY_DRIVER:
5357 return "DRIVER";
5358 case REGDOM_SET_BY_COUNTRY_IE:
5359 return "COUNTRY_IE";
5360 case REGDOM_BEACON_HINT:
5361 return "BEACON_HINT";
5362 }
5363 return "?";
5364}
5365
5366
5367static const char * reg_type_str(enum reg_type type)
5368{
5369 switch (type) {
5370 case REGDOM_TYPE_UNKNOWN:
5371 return "UNKNOWN";
5372 case REGDOM_TYPE_COUNTRY:
5373 return "COUNTRY";
5374 case REGDOM_TYPE_WORLD:
5375 return "WORLD";
5376 case REGDOM_TYPE_CUSTOM_WORLD:
5377 return "CUSTOM_WORLD";
5378 case REGDOM_TYPE_INTERSECTION:
5379 return "INTERSECTION";
5380 }
5381 return "?";
5382}
5383
5384
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005385static void wpas_beacon_hint(struct wpa_supplicant *wpa_s, const char *title,
5386 struct frequency_attrs *attrs)
5387{
5388 if (!attrs->freq)
5389 return;
5390 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_BEACON_HINT
5391 "%s freq=%u max_tx_power=%u%s%s%s",
5392 title, attrs->freq, attrs->max_tx_power,
5393 attrs->disabled ? " disabled=1" : "",
5394 attrs->no_ir ? " no_ir=1" : "",
5395 attrs->radar ? " radar=1" : "");
5396}
5397
5398
Hai Shalom74f70d42019-02-11 14:42:39 -08005399void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
5400 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005401{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005402 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005403 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005404
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005405 /*
5406 * To allow backwards compatibility with higher level layers that
5407 * assumed the REGDOM_CHANGE event is sent over the initially added
5408 * interface. Find the highest parent of this interface and use it to
5409 * send the event.
5410 */
5411 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
5412 ;
5413
Hai Shalom74f70d42019-02-11 14:42:39 -08005414 if (info) {
5415 wpa_msg(ifs, MSG_INFO,
5416 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
5417 reg_init_str(info->initiator), reg_type_str(info->type),
5418 info->alpha2[0] ? " alpha2=" : "",
5419 info->alpha2[0] ? info->alpha2 : "");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005420
5421 if (info->initiator == REGDOM_BEACON_HINT) {
5422 wpas_beacon_hint(ifs, "before",
5423 &info->beacon_hint_before);
5424 wpas_beacon_hint(ifs, "after",
5425 &info->beacon_hint_after);
5426 }
Hai Shalom74f70d42019-02-11 14:42:39 -08005427 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005428
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005429 if (wpa_s->drv_priv == NULL)
5430 return; /* Ignore event during drv initialization */
5431
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005432 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
5433 radio_list) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005434 bool was_6ghz_enabled;
5435
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005436 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
5437 ifs->ifname);
5438 free_hw_features(ifs);
5439 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005440 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005441
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005442 was_6ghz_enabled = ifs->is_6ghz_enabled;
5443 ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5444
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005445 /* Restart PNO/sched_scan with updated channel list */
5446 if (ifs->pno) {
5447 wpas_stop_pno(ifs);
5448 wpas_start_pno(ifs);
5449 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
5450 wpa_dbg(ifs, MSG_DEBUG,
5451 "Channel list changed - restart sched_scan");
5452 wpas_scan_restart_sched_scan(ifs);
Sunil Ravi7f769292024-07-23 22:21:32 +00005453 } else if (!was_6ghz_enabled && ifs->is_6ghz_enabled) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005454 wpa_dbg(ifs, MSG_INFO,
Sunil Ravi7f769292024-07-23 22:21:32 +00005455 "Channel list changed: 6 GHz was enabled");
5456
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005457 ifs->crossed_6ghz_dom = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005458 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005459 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005460
5461 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005462}
5463
5464
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005465static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005466 const u8 *frame, size_t len, int freq,
5467 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005468{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005469 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005470 const u8 *payload;
5471 size_t plen;
5472 u8 category;
5473
5474 if (len < IEEE80211_HDRLEN + 2)
5475 return;
5476
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005477 mgmt = (const struct ieee80211_mgmt *) frame;
5478 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005479 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005480 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005481
5482 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
5483 " Category=%u DataLen=%d freq=%d MHz",
5484 MAC2STR(mgmt->sa), category, (int) plen, freq);
5485
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005486#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005487 if (category == WLAN_ACTION_WMM) {
5488 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5489 return;
5490 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005491#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005492
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005493#ifdef CONFIG_IEEE80211R
5494 if (category == WLAN_ACTION_FT) {
5495 ft_rx_action(wpa_s, payload, plen);
5496 return;
5497 }
5498#endif /* CONFIG_IEEE80211R */
5499
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005500#ifdef CONFIG_SME
5501 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005502 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005503 return;
5504 }
5505#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005506
5507#ifdef CONFIG_WNM
5508 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
5509 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
5510 return;
5511 }
5512#endif /* CONFIG_WNM */
5513
5514#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08005515 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5516 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005517 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08005518 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005519 payload, plen, freq) == 0)
5520 return;
5521#endif /* CONFIG_GAS */
5522
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005523#ifdef CONFIG_GAS_SERVER
5524 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5525 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
5526 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
5527 mgmt->u.action.category,
5528 payload, plen, freq) == 0)
5529 return;
5530#endif /* CONFIG_GAS_SERVER */
5531
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005532#ifdef CONFIG_TDLS
5533 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
5534 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
5535 wpa_dbg(wpa_s, MSG_DEBUG,
5536 "TDLS: Received Discovery Response from " MACSTR,
5537 MAC2STR(mgmt->sa));
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005538 if (wpa_s->valid_links &&
5539 wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa,
5540 &payload[1], plen - 1))
5541 wpa_dbg(wpa_s, MSG_ERROR,
5542 "TDLS: Discovery Response process failed for "
5543 MACSTR, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005544 return;
5545 }
5546#endif /* CONFIG_TDLS */
5547
5548#ifdef CONFIG_INTERWORKING
5549 if (category == WLAN_ACTION_QOS && plen >= 1 &&
5550 payload[0] == QOS_QOS_MAP_CONFIG) {
5551 const u8 *pos = payload + 1;
5552 size_t qlen = plen - 1;
5553 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
5554 MACSTR, MAC2STR(mgmt->sa));
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005555 if (ether_addr_equal(mgmt->sa, wpa_s->bssid) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005556 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
5557 pos[1] <= qlen - 2 && pos[1] >= 16)
5558 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
5559 return;
5560 }
5561#endif /* CONFIG_INTERWORKING */
5562
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005563#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005564 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005565 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5566 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005567 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005568 payload + 1,
5569 plen - 1);
5570 return;
5571 }
5572
5573 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005574 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
5575 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
5576 return;
5577 }
5578
5579 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5580 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
5581 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
5582 payload + 1, plen - 1,
5583 rssi);
5584 return;
5585 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005586#endif /* CONFIG_NO_RRM */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005587
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005588#ifdef CONFIG_FST
5589 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
5590 fst_rx_action(wpa_s->fst, mgmt, len);
5591 return;
5592 }
5593#endif /* CONFIG_FST */
5594
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005595#ifdef CONFIG_NAN_USD
5596 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5597 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5598 WPA_GET_BE32(&payload[1]) == NAN_SDF_VENDOR_TYPE) {
5599 payload += 5;
5600 plen -= 5;
5601 wpas_nan_usd_rx_sdf(wpa_s, mgmt->sa, freq, payload, plen);
5602 return;
5603 }
5604#endif /* CONFIG_NAN_USD */
5605
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005606#ifdef CONFIG_DPP
5607 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5608 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5609 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
5610 payload[4] == DPP_OUI_TYPE) {
5611 payload++;
5612 plen--;
5613 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
5614 return;
5615 }
5616#endif /* CONFIG_DPP */
5617
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005618#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07005619 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08005620 payload[0] == ROBUST_AV_SCS_RESP) {
5621 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
5622 payload + 1, plen - 1);
5623 return;
5624 }
5625
5626 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005627 payload[0] == ROBUST_AV_MSCS_RESP) {
5628 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5629 payload + 1, plen - 1);
5630 return;
5631 }
5632
Hai Shalomc1a21442022-02-04 13:43:00 -08005633 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
5634 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
5635 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
5636 payload + 4, plen - 4);
5637 return;
5638 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005639#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalomc1a21442022-02-04 13:43:00 -08005640
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005641 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5642 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005643 if (wpa_s->ifmsh)
5644 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005645}
5646
5647
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005648static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5649 union wpa_event_data *event)
5650{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005651 struct wpa_freq_range_list *list;
5652 char *str = NULL;
5653
5654 list = &event->freq_range;
5655
5656 if (list->num)
5657 str = freq_range_list_str(list);
5658 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5659 str ? str : "");
5660
5661#ifdef CONFIG_P2P
5662 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5663 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5664 __func__);
5665 } else {
5666 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005667
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005668 /*
5669 * The update channel flow will also take care of moving a GO
5670 * from the unsafe frequency if needed.
5671 */
5672 wpas_p2p_update_channel_list(wpa_s,
5673 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005674 }
5675#endif /* CONFIG_P2P */
5676
5677 os_free(str);
5678}
5679
5680
Roshan Pius3a1667e2018-07-03 15:17:14 -07005681static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005682{
Sunil Ravi167279a2023-05-31 01:12:34 +00005683 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005684 wpa_supplicant_cancel_auth_timeout(wpa_s);
5685 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005686 eapol_sm_notify_portValid(wpa_s->eapol, true);
5687 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005688 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005689 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005690}
5691
5692
5693static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5694 int freq)
5695{
5696 size_t i;
5697 int j;
5698
5699 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5700 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5701
5702 for (j = 0; j < mode->num_channels; j++) {
5703 const struct hostapd_channel_data *chan;
5704
5705 chan = &mode->channels[j];
5706 if (chan->freq == freq)
5707 return chan->dfs_cac_ms;
5708 }
5709 }
5710
5711 return 0;
5712}
5713
5714
5715static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5716 struct dfs_event *radar)
5717{
5718#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005719 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005720 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5721 } else
5722#endif /* NEED_AP_MLME && CONFIG_AP */
5723 {
5724 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5725
5726 cac_time /= 1000; /* convert from ms to sec */
5727 if (!cac_time)
5728 cac_time = 10 * 60; /* max timeout: 10 minutes */
5729
5730 /* Restart auth timeout: CAC time added to initial timeout */
5731 wpas_auth_timeout_restart(wpa_s, cac_time);
5732 }
5733}
5734
5735
5736static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5737 struct dfs_event *radar)
5738{
5739#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005740 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005741 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5742 } else
5743#endif /* NEED_AP_MLME && CONFIG_AP */
5744 {
5745 /* Restart auth timeout with original value after CAC is
5746 * finished */
5747 wpas_auth_timeout_restart(wpa_s, 0);
5748 }
5749}
5750
5751
5752static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5753 struct dfs_event *radar)
5754{
5755#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005756 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005757 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5758 } else
5759#endif /* NEED_AP_MLME && CONFIG_AP */
5760 {
5761 /* Restart auth timeout with original value after CAC is
5762 * aborted */
5763 wpas_auth_timeout_restart(wpa_s, 0);
5764 }
5765}
5766
5767
5768static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5769 union wpa_event_data *data)
5770{
5771 wpa_dbg(wpa_s, MSG_DEBUG,
5772 "Connection authorized by device, previous state %d",
5773 wpa_s->wpa_state);
5774
5775 wpa_supplicant_event_port_authorized(wpa_s);
5776
Hai Shalomc1a21442022-02-04 13:43:00 -08005777 wpa_s->last_eapol_matches_bssid = 1;
5778
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005779 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5780 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005781 data->assoc_info.ptk_kck_len,
5782 data->assoc_info.ptk_kek,
5783 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005784#ifdef CONFIG_FILS
5785 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5786 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5787 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5788
5789 /* Update ERP next sequence number */
5790 eapol_sm_update_erp_next_seq_num(
5791 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5792
5793 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5794 /* Add the new PMK and PMKID to the PMKSA cache */
5795 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5796 data->assoc_info.fils_pmk,
5797 data->assoc_info.fils_pmk_len,
5798 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005799 wpa_s->valid_links ?
5800 wpa_s->ap_mld_addr :
5801 wpa_s->bssid,
5802 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005803 } else if (data->assoc_info.fils_pmkid) {
5804 /* Update the current PMKSA used for this connection */
5805 pmksa_cache_set_current(wpa_s->wpa,
5806 data->assoc_info.fils_pmkid,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005807 NULL, NULL, 0, NULL, 0, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005808 }
5809 }
5810#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005811}
5812
5813
Hai Shalom60840252021-02-19 19:02:11 -08005814static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5815{
5816 switch (code) {
5817 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5818 return "";
5819 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5820 return "no_bss_found";
5821 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5822 return "auth_tx_fail";
5823 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5824 return "auth_no_ack_received";
5825 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5826 return "auth_no_resp_received";
5827 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5828 return "assoc_req_tx_fail";
5829 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5830 return "assoc_no_ack_received";
5831 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5832 return "assoc_no_resp_received";
5833 default:
5834 return "unknown_reason";
5835 }
5836}
5837
5838
Roshan Pius3a1667e2018-07-03 15:17:14 -07005839static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5840 union wpa_event_data *data)
5841{
5842 const u8 *bssid = data->assoc_reject.bssid;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005843 struct ieee802_11_elems elems;
Sunil Ravi7f769292024-07-23 22:21:32 +00005844 struct ml_sta_link_info ml_info[MAX_NUM_MLD_LINKS];
5845 const u8 *link_bssids[MAX_NUM_MLD_LINKS + 1];
Hai Shalom81f62d82019-07-22 12:10:00 -07005846#ifdef CONFIG_MBO
5847 struct wpa_bss *reject_bss;
5848#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005849
5850 if (!bssid || is_zero_ether_addr(bssid))
5851 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005852#ifdef CONFIG_MBO
5853 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5854 reject_bss = wpa_s->current_bss;
5855 else
5856 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5857#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005858
5859 if (data->assoc_reject.bssid)
5860 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005861 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005862 MAC2STR(data->assoc_reject.bssid),
5863 data->assoc_reject.status_code,
5864 data->assoc_reject.timed_out ? " timeout" : "",
5865 data->assoc_reject.timeout_reason ? "=" : "",
5866 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005867 data->assoc_reject.timeout_reason : "",
5868 data->assoc_reject.reason_code !=
5869 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5870 " qca_driver_reason=" : "",
5871 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005872 else
5873 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005874 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005875 data->assoc_reject.status_code,
5876 data->assoc_reject.timed_out ? " timeout" : "",
5877 data->assoc_reject.timeout_reason ? "=" : "",
5878 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005879 data->assoc_reject.timeout_reason : "",
5880 data->assoc_reject.reason_code !=
5881 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5882 " qca_driver_reason=" : "",
5883 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005884 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005885 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5886 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005887
5888#ifdef CONFIG_OWE
5889 if (data->assoc_reject.status_code ==
5890 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5891 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5892 wpa_s->current_ssid &&
5893 wpa_s->current_ssid->owe_group == 0 &&
5894 wpa_s->last_owe_group != 21) {
5895 struct wpa_ssid *ssid = wpa_s->current_ssid;
5896 struct wpa_bss *bss = wpa_s->current_bss;
5897
5898 if (!bss) {
5899 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5900 if (!bss) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005901 wpas_connection_failed(wpa_s, bssid, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005902 wpa_supplicant_mark_disassoc(wpa_s);
5903 return;
5904 }
5905 }
5906 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5907 wpas_connect_work_done(wpa_s);
5908 wpa_supplicant_mark_disassoc(wpa_s);
5909 wpa_supplicant_connect(wpa_s, bss, ssid);
5910 return;
5911 }
5912#endif /* CONFIG_OWE */
5913
Hai Shalomfdcde762020-04-02 11:19:20 -07005914#ifdef CONFIG_DPP2
5915 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5916 * the status code defined in the DPP R2 tech spec.
5917 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5918 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005919 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005920 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5921 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5922 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005923 wpa_s->current_ssid->dpp_pfs == 0 &&
5924 (data->assoc_reject.status_code ==
5925 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5926 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5927 struct wpa_ssid *ssid = wpa_s->current_ssid;
5928 struct wpa_bss *bss = wpa_s->current_bss;
5929
5930 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5931 if (!bss)
5932 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5933 if (!bss || wpa_s->dpp_pfs_fallback) {
5934 wpa_printf(MSG_DEBUG,
5935 "DPP: Updated PFS policy for next try");
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005936 wpas_connection_failed(wpa_s, bssid, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07005937 wpa_supplicant_mark_disassoc(wpa_s);
5938 return;
5939 }
5940 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5941 wpa_s->dpp_pfs_fallback = 1;
5942 wpas_connect_work_done(wpa_s);
5943 wpa_supplicant_mark_disassoc(wpa_s);
5944 wpa_supplicant_connect(wpa_s, bss, ssid);
5945 return;
5946 }
5947#endif /* CONFIG_DPP2 */
5948
Hai Shalom74f70d42019-02-11 14:42:39 -08005949#ifdef CONFIG_MBO
5950 if (data->assoc_reject.status_code ==
5951 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005952 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005953 const u8 *rssi_rej;
5954
5955 rssi_rej = mbo_get_attr_from_ies(
5956 data->assoc_reject.resp_ies,
5957 data->assoc_reject.resp_ies_len,
5958 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5959 if (rssi_rej && rssi_rej[1] == 2) {
5960 wpa_printf(MSG_DEBUG,
5961 "OCE: RSSI-based association rejection from "
5962 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005963 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005964 rssi_rej[2], rssi_rej[3]);
5965 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005966 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005967 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005968 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005969 }
5970 }
5971#endif /* CONFIG_MBO */
5972
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005973 /* Check for other failed links in the response */
5974 os_memset(link_bssids, 0, sizeof(link_bssids));
5975 if (ieee802_11_parse_elems(data->assoc_reject.resp_ies,
5976 data->assoc_reject.resp_ies_len,
5977 &elems, 1) != ParseFailed) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005978 unsigned int n_links, i, idx;
5979
5980 idx = 0;
5981 n_links = wpas_ml_parse_assoc(wpa_s, &elems, ml_info);
5982
5983 for (i = 1; i < n_links; i++) {
5984 /* The status cannot be success here.
5985 * Add the link to the failed list if it is reporting
5986 * an error. The only valid "non-error" status is
5987 * TX_LINK_NOT_ACCEPTED as that means this link may
5988 * still accept an association from us.
5989 */
5990 if (ml_info[i].status !=
5991 WLAN_STATUS_DENIED_TX_LINK_NOT_ACCEPTED) {
5992 link_bssids[idx] = ml_info[i].bssid;
5993 idx++;
5994 }
5995 }
5996 }
5997
Roshan Pius3a1667e2018-07-03 15:17:14 -07005998 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005999 sme_event_assoc_reject(wpa_s, data, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006000 return;
6001 }
6002
6003 /* Driver-based SME cases */
6004
6005#ifdef CONFIG_SAE
6006 if (wpa_s->current_ssid &&
6007 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
6008 !data->assoc_reject.timed_out) {
6009 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
6010 wpa_sm_aborted_cached(wpa_s->wpa);
6011 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
6012 }
6013#endif /* CONFIG_SAE */
6014
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006015#ifdef CONFIG_DPP
6016 if (wpa_s->current_ssid &&
6017 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
6018 !data->assoc_reject.timed_out) {
6019 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
6020 wpa_sm_aborted_cached(wpa_s->wpa);
6021 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
6022 }
6023#endif /* CONFIG_DPP */
6024
Roshan Pius3a1667e2018-07-03 15:17:14 -07006025#ifdef CONFIG_FILS
6026 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07006027 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006028 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006029 eapol_sm_update_erp_next_seq_num(
6030 wpa_s->eapol,
6031 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07006032 fils_connection_failure(wpa_s);
6033 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006034#endif /* CONFIG_FILS */
6035
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006036 wpas_connection_failed(wpa_s, bssid, link_bssids);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006037 wpa_supplicant_mark_disassoc(wpa_s);
6038}
6039
6040
Hai Shalomfdcde762020-04-02 11:19:20 -07006041static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
6042 struct unprot_beacon *data)
6043{
6044 struct wpabuf *buf;
6045 int res;
6046
6047 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006048 !ether_addr_equal(data->sa, wpa_s->bssid))
Hai Shalomfdcde762020-04-02 11:19:20 -07006049 return;
6050 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
6051 MAC2STR(data->sa));
6052
6053 buf = wpabuf_alloc(4);
6054 if (!buf)
6055 return;
6056
6057 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
6058 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
6059 wpabuf_put_u8(buf, 1); /* Dialog Token */
6060 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
6061
6062 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
6063 wpa_s->own_addr, wpa_s->bssid,
6064 wpabuf_head(buf), wpabuf_len(buf), 0);
6065 if (res < 0)
6066 wpa_printf(MSG_DEBUG,
6067 "Failed to send WNM-Notification Request frame");
6068
6069 wpabuf_free(buf);
6070}
6071
6072
Sunil Ravi640215c2023-06-28 23:08:09 +00006073static const char * bitmap_to_str(u8 value, char *buf)
6074{
6075 char *pos = buf;
6076 int i, k = 0;
6077
6078 for (i = 7; i >= 0; i--)
6079 pos[k++] = (value & BIT(i)) ? '1' : '0';
6080
6081 pos[8] = '\0';
6082 return pos;
6083}
6084
6085
6086static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
6087 struct tid_link_map_info *info)
6088{
6089 char map_info[1000], *pos, *end;
6090 int res, i;
6091
6092 pos = map_info;
6093 end = pos + sizeof(map_info);
6094 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
6095 info->default_map);
6096 if (os_snprintf_error(end - pos, res))
6097 return;
6098 pos += res;
6099
6100 if (!info->default_map) {
Sunil Ravi99c035e2024-07-12 01:42:03 +00006101 for_each_link(info->valid_links, i) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006102 char uplink_map_str[9];
6103 char downlink_map_str[9];
6104
Sunil Ravi640215c2023-06-28 23:08:09 +00006105 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
6106 bitmap_to_str(info->t2lmap[i].downlink,
6107 downlink_map_str);
6108
6109 res = os_snprintf(pos, end - pos,
6110 " link_id=%d up_link=%s down_link=%s",
6111 i, uplink_map_str,
6112 downlink_map_str);
6113 if (os_snprintf_error(end - pos, res))
6114 return;
6115 pos += res;
6116 }
6117 }
6118
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306119 wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP);
Sunil Ravi640215c2023-06-28 23:08:09 +00006120 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
6121}
6122
6123
6124static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
6125{
6126 u8 bssid[ETH_ALEN];
6127
6128 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
6129 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
6130 wpa_supplicant_deauthenticate(wpa_s,
6131 WLAN_REASON_DEAUTH_LEAVING);
6132 return;
6133 }
6134
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006135 if (!ether_addr_equal(bssid, wpa_s->bssid)) {
Sunil Ravi640215c2023-06-28 23:08:09 +00006136 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
6137 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
6138 wpas_notify_bssid_changed(wpa_s);
6139 }
6140
6141 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
6142 wpa_printf(MSG_ERROR,
6143 "LINK_RECONFIG: Failed to get MLO connection info");
6144 wpa_supplicant_deauthenticate(wpa_s,
6145 WLAN_REASON_DEAUTH_LEAVING);
6146 return;
6147 }
6148
6149 if (wpa_sm_set_ml_info(wpa_s)) {
6150 wpa_printf(MSG_ERROR,
6151 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
6152 wpa_supplicant_deauthenticate(wpa_s,
6153 WLAN_REASON_DEAUTH_LEAVING);
6154 return;
6155 }
6156
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05306157 wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL);
Sunil Ravi640215c2023-06-28 23:08:09 +00006158 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
6159 wpa_s->valid_links);
6160}
6161
6162
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006163void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
6164 union wpa_event_data *data)
6165{
6166 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006167 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07006168 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08006169#ifndef CONFIG_NO_STDOUT_DEBUG
6170 int level = MSG_DEBUG;
6171#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006172
6173 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
6174 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006175 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006176 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006177 event != EVENT_SCHED_SCAN_STOPPED) {
6178 wpa_dbg(wpa_s, MSG_DEBUG,
6179 "Ignore event %s (%d) while interface is disabled",
6180 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006181 return;
6182 }
6183
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006184#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07006185 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006186 const struct ieee80211_hdr *hdr;
6187 u16 fc;
6188 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
6189 fc = le_to_host16(hdr->frame_control);
6190 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
6191 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
6192 level = MSG_EXCESSIVE;
6193 }
6194
6195 wpa_dbg(wpa_s, level, "Event %s (%d) received",
6196 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006197#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006198
6199 switch (event) {
6200 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006201#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08006202 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
6203 data->auth.ies_len))
6204 wpa_printf(MSG_DEBUG,
6205 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006206#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006207 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006208 wpa_s->auth_status_code = data->auth.status_code;
6209 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006210 break;
6211 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006212#ifdef CONFIG_TESTING_OPTIONS
6213 if (wpa_s->ignore_auth_resp) {
6214 wpa_printf(MSG_INFO,
6215 "EVENT_ASSOC - ignore_auth_resp active!");
6216 break;
6217 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006218 if (wpa_s->testing_resend_assoc) {
6219 wpa_printf(MSG_INFO,
6220 "EVENT_DEAUTH - testing_resend_assoc");
6221 break;
6222 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006223#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05306224 if (wpa_s->disconnected) {
6225 wpa_printf(MSG_INFO,
6226 "Ignore unexpected EVENT_ASSOC in disconnected state");
6227 break;
6228 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006229 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08006230 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006231 if (data &&
6232 (data->assoc_info.authorized ||
6233 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6234 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006235 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006236 if (data) {
6237 wpa_msg(wpa_s, MSG_INFO,
6238 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
6239 data->assoc_info.subnet_status);
6240 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006241 break;
6242 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006243 wpas_event_disassoc(wpa_s,
6244 data ? &data->disassoc_info : NULL);
6245 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006246 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006247#ifdef CONFIG_TESTING_OPTIONS
6248 if (wpa_s->ignore_auth_resp) {
6249 wpa_printf(MSG_INFO,
6250 "EVENT_DEAUTH - ignore_auth_resp active!");
6251 break;
6252 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006253 if (wpa_s->testing_resend_assoc) {
6254 wpa_printf(MSG_INFO,
6255 "EVENT_DEAUTH - testing_resend_assoc");
6256 break;
6257 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07006258#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006259 wpas_event_deauth(wpa_s,
6260 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006261 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00006262 case EVENT_LINK_RECONFIG:
6263 wpas_link_reconfig(wpa_s);
6264 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006265 case EVENT_MICHAEL_MIC_FAILURE:
6266 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
6267 break;
6268#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006269 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006270 if (wpa_s->own_scan_requested ||
6271 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006272 struct os_reltime diff;
6273
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006274 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006275 os_reltime_sub(&wpa_s->scan_start_time,
6276 &wpa_s->scan_trigger_time, &diff);
6277 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
6278 diff.sec, diff.usec);
6279 wpa_s->own_scan_requested = 0;
6280 wpa_s->own_scan_running = 1;
6281 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
6282 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006283 wpa_msg_ctrl(wpa_s, MSG_INFO,
6284 WPA_EVENT_SCAN_STARTED "id=%u",
6285 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006286 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006287 wpa_msg_ctrl(wpa_s, MSG_INFO,
6288 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006289 }
6290 } else {
6291 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08006292 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006293 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006294 }
6295 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006296 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006297 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6298 wpa_s->scan_res_handler = NULL;
6299 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08006300 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006301 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
6302 break;
6303 }
6304
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006305 if (!(data && data->scan_info.external_scan) &&
6306 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006307 struct os_reltime now, diff;
6308 os_get_reltime(&now);
6309 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
6310 wpa_s->scan_start_time.sec = 0;
6311 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00006312 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006313 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
6314 diff.sec, diff.usec);
6315 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006316 if (wpa_supplicant_event_scan_results(wpa_s, data))
6317 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006318 if (!(data && data->scan_info.external_scan))
6319 wpa_s->own_scan_running = 0;
6320 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08006321 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006322 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006323 break;
6324#endif /* CONFIG_NO_SCAN_PROCESSING */
6325 case EVENT_ASSOCINFO:
6326 wpa_supplicant_event_associnfo(wpa_s, data);
6327 break;
6328 case EVENT_INTERFACE_STATUS:
6329 wpa_supplicant_event_interface_status(wpa_s, data);
6330 break;
6331 case EVENT_PMKID_CANDIDATE:
6332 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
6333 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006334#ifdef CONFIG_TDLS
6335 case EVENT_TDLS:
6336 wpa_supplicant_event_tdls(wpa_s, data);
6337 break;
6338#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006339#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006340 case EVENT_WNM:
6341 wpa_supplicant_event_wnm(wpa_s, data);
6342 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006343#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006344#ifdef CONFIG_IEEE80211R
6345 case EVENT_FT_RESPONSE:
6346 wpa_supplicant_event_ft_response(wpa_s, data);
6347 break;
6348#endif /* CONFIG_IEEE80211R */
6349#ifdef CONFIG_IBSS_RSN
6350 case EVENT_IBSS_RSN_START:
6351 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
6352 break;
6353#endif /* CONFIG_IBSS_RSN */
6354 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07006355 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006356 break;
6357 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006358 /* It is possible to get this event from earlier connection */
6359 if (wpa_s->current_ssid &&
6360 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6361 wpa_dbg(wpa_s, MSG_DEBUG,
6362 "Ignore AUTH_TIMED_OUT in mesh configuration");
6363 break;
6364 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006365 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6366 sme_event_auth_timed_out(wpa_s, data);
6367 break;
6368 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006369 /* It is possible to get this event from earlier connection */
6370 if (wpa_s->current_ssid &&
6371 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6372 wpa_dbg(wpa_s, MSG_DEBUG,
6373 "Ignore ASSOC_TIMED_OUT in mesh configuration");
6374 break;
6375 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006376 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6377 sme_event_assoc_timed_out(wpa_s, data);
6378 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006379 case EVENT_TX_STATUS:
6380 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
6381 " type=%d stype=%d",
6382 MAC2STR(data->tx_status.dst),
6383 data->tx_status.type, data->tx_status.stype);
Sunil Ravi99c035e2024-07-12 01:42:03 +00006384#ifdef CONFIG_WNM
6385 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6386 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
6387 wnm_btm_resp_tx_status(wpa_s, data->tx_status.data,
6388 data->tx_status.data_len) == 0)
6389 break;
6390#endif /* CONFIG_WNM */
Hai Shalom60840252021-02-19 19:02:11 -08006391#ifdef CONFIG_PASN
6392 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6393 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6394 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
6395 data->tx_status.data_len,
6396 data->tx_status.ack) == 0)
6397 break;
6398#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006399#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006400 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006401#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006402 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6403 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006404 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006405 wpa_s, data->tx_status.dst,
6406 data->tx_status.data,
6407 data->tx_status.data_len,
6408 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006409 OFFCHANNEL_SEND_ACTION_SUCCESS :
6410 OFFCHANNEL_SEND_ACTION_NO_ACK);
6411#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006412 break;
6413 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006414#endif /* CONFIG_AP */
6415#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006416 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006417 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006418 /*
6419 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006420 * interface in GO mode, or via standalone AP interface.
6421 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
6422 * except when the primary interface is used as a GO interface
6423 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006424 */
6425 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6426 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006427 ether_addr_equal(wpa_s->p2pdev->pending_action_dst,
6428 data->tx_status.dst)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006429 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006430 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006431 data->tx_status.data,
6432 data->tx_status.data_len,
6433 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006434 OFFCHANNEL_SEND_ACTION_SUCCESS :
6435 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006436 break;
6437 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006438#endif /* CONFIG_OFFCHANNEL */
6439#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006440 switch (data->tx_status.type) {
6441 case WLAN_FC_TYPE_MGMT:
6442 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
6443 data->tx_status.data_len,
6444 data->tx_status.stype,
6445 data->tx_status.ack);
6446 break;
6447 case WLAN_FC_TYPE_DATA:
6448 ap_tx_status(wpa_s, data->tx_status.dst,
6449 data->tx_status.data,
6450 data->tx_status.data_len,
6451 data->tx_status.ack);
6452 break;
6453 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006454#endif /* CONFIG_AP */
6455 break;
6456#ifdef CONFIG_AP
6457 case EVENT_EAPOL_TX_STATUS:
6458 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
6459 data->eapol_tx_status.data,
6460 data->eapol_tx_status.data_len,
6461 data->eapol_tx_status.ack);
6462 break;
6463 case EVENT_DRIVER_CLIENT_POLL_OK:
6464 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006465 break;
6466 case EVENT_RX_FROM_UNKNOWN:
6467 if (wpa_s->ap_iface == NULL)
6468 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006469 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
6470 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006471 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006472#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07006473
Sunil Ravi89eba102022-09-13 21:04:37 -07006474 case EVENT_LINK_CH_SWITCH_STARTED:
6475 case EVENT_LINK_CH_SWITCH:
6476 if (!data || !wpa_s->current_ssid ||
6477 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6478 break;
6479
6480 wpa_msg(wpa_s, MSG_INFO,
6481 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6482 event == EVENT_LINK_CH_SWITCH ?
6483 WPA_EVENT_LINK_CHANNEL_SWITCH :
6484 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6485 data->ch_switch.freq,
6486 data->ch_switch.link_id,
6487 data->ch_switch.ht_enabled,
6488 data->ch_switch.ch_offset,
6489 channel_width_to_string(data->ch_switch.ch_width),
6490 data->ch_switch.cf1,
6491 data->ch_switch.cf2);
6492 if (event == EVENT_LINK_CH_SWITCH_STARTED)
6493 break;
6494
6495 wpa_s->links[data->ch_switch.link_id].freq =
6496 data->ch_switch.freq;
6497 if (wpa_s->links[data->ch_switch.link_id].bss &&
6498 wpa_s->links[data->ch_switch.link_id].bss->freq !=
6499 data->ch_switch.freq) {
6500 wpa_s->links[data->ch_switch.link_id].bss->freq =
6501 data->ch_switch.freq;
6502 notify_bss_changes(
6503 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6504 wpa_s->links[data->ch_switch.link_id].bss);
Shuibing Dai0db6bb12023-09-28 17:53:17 -07006505 if (data->ch_switch.freq)
6506 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
Sunil Ravi89eba102022-09-13 21:04:37 -07006507 }
6508 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07006509 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07006510 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006511 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006512 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006513
Hai Shalom81f62d82019-07-22 12:10:00 -07006514 wpa_msg(wpa_s, MSG_INFO,
6515 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6516 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6517 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006518 data->ch_switch.freq,
6519 data->ch_switch.ht_enabled,
6520 data->ch_switch.ch_offset,
6521 channel_width_to_string(data->ch_switch.ch_width),
6522 data->ch_switch.cf1,
6523 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07006524 if (event == EVENT_CH_SWITCH_STARTED)
6525 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006526
Sunil Ravi65a724b2022-05-24 11:06:09 -07006527 if (wpa_s->assoc_freq && data->ch_switch.freq &&
6528 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
6529 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
6530 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006531 wpa_s->assoc_freq = data->ch_switch.freq;
6532 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08006533 if (wpa_s->current_bss &&
6534 wpa_s->current_bss->freq != data->ch_switch.freq) {
6535 wpa_s->current_bss->freq = data->ch_switch.freq;
6536 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6537 wpa_s->current_bss);
6538 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006539
Hai Shalomfdcde762020-04-02 11:19:20 -07006540#ifdef CONFIG_SME
6541 switch (data->ch_switch.ch_offset) {
6542 case 1:
6543 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6544 break;
6545 case -1:
6546 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6547 break;
6548 default:
6549 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6550 break;
6551 }
6552#endif /* CONFIG_SME */
6553
Roshan Pius3a1667e2018-07-03 15:17:14 -07006554#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006555 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6556 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08006557 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006558 wpa_s->current_ssid->mode ==
6559 WPAS_MODE_P2P_GROUP_FORMATION) {
6560 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6561 data->ch_switch.ht_enabled,
6562 data->ch_switch.ch_offset,
6563 data->ch_switch.ch_width,
6564 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006565 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07006566 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07006567 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006568 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006569#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006570
Hai Shalom899fcc72020-10-19 14:38:18 -07006571 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6572 sme_event_ch_switch(wpa_s);
6573
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006574 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006575 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006576 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006577#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006578#ifdef NEED_AP_MLME
6579 case EVENT_DFS_RADAR_DETECTED:
6580 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07006581 wpas_ap_event_dfs_radar_detected(wpa_s,
6582 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006583 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006584 case EVENT_DFS_NOP_FINISHED:
6585 if (data)
6586 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
6587 &data->dfs_event);
6588 break;
6589#endif /* NEED_AP_MLME */
6590#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006591 case EVENT_DFS_CAC_STARTED:
6592 if (data)
6593 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
6594 break;
6595 case EVENT_DFS_CAC_FINISHED:
6596 if (data)
6597 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
6598 break;
6599 case EVENT_DFS_CAC_ABORTED:
6600 if (data)
6601 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
6602 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006603 case EVENT_RX_MGMT: {
6604 u16 fc, stype;
6605 const struct ieee80211_mgmt *mgmt;
6606
Dmitry Shmidt818ea482014-03-10 13:15:21 -07006607#ifdef CONFIG_TESTING_OPTIONS
6608 if (wpa_s->ext_mgmt_frame_handling) {
6609 struct rx_mgmt *rx = &data->rx_mgmt;
6610 size_t hex_len = 2 * rx->frame_len + 1;
6611 char *hex = os_malloc(hex_len);
6612 if (hex) {
6613 wpa_snprintf_hex(hex, hex_len,
6614 rx->frame, rx->frame_len);
6615 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
6616 rx->freq, rx->datarate, rx->ssi_signal,
6617 hex);
6618 os_free(hex);
6619 }
6620 break;
6621 }
6622#endif /* CONFIG_TESTING_OPTIONS */
6623
Dmitry Shmidt04949592012-07-19 12:16:46 -07006624 mgmt = (const struct ieee80211_mgmt *)
6625 data->rx_mgmt.frame;
6626 fc = le_to_host16(mgmt->frame_control);
6627 stype = WLAN_FC_GET_STYPE(fc);
6628
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006629#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006630 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006631#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006632#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006633 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006634 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006635 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07006636 const u8 *ie;
6637 size_t ie_len;
6638
6639 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6640 ie_len = data->rx_mgmt.frame_len -
6641 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006642 wpas_p2p_probe_req_rx(
6643 wpa_s, src, mgmt->da,
6644 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006645 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006646 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006647 break;
6648 }
6649#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006650#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006651 if (wpa_s->current_ssid &&
6652 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
6653 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006654 data->rx_mgmt.frame_len >= 30) {
6655 wpa_supplicant_event_ibss_auth(wpa_s, data);
6656 break;
6657 }
6658#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006659
6660 if (stype == WLAN_FC_STYPE_ACTION) {
6661 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07006662 wpa_s, data->rx_mgmt.frame,
6663 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006664 data->rx_mgmt.freq,
6665 data->rx_mgmt.ssi_signal);
6666 break;
6667 }
6668
6669 if (wpa_s->ifmsh) {
6670 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006671 break;
6672 }
Hai Shalom60840252021-02-19 19:02:11 -08006673#ifdef CONFIG_PASN
6674 if (stype == WLAN_FC_STYPE_AUTH &&
6675 wpas_pasn_auth_rx(wpa_s, mgmt,
6676 data->rx_mgmt.frame_len) != -2)
6677 break;
6678#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006679
Roshan Pius3a1667e2018-07-03 15:17:14 -07006680#ifdef CONFIG_SAE
6681 if (stype == WLAN_FC_STYPE_AUTH &&
6682 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6683 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6684 sme_external_auth_mgmt_rx(
6685 wpa_s, data->rx_mgmt.frame,
6686 data->rx_mgmt.frame_len);
6687 break;
6688 }
6689#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006690 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6691 "management frame in non-AP mode");
6692 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006693#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006694 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006695
6696 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006697 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6698 const u8 *ie;
6699 size_t ie_len;
6700
6701 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6702 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006703
6704 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6705 mgmt->bssid, ie, ie_len,
6706 data->rx_mgmt.ssi_signal);
6707 }
6708
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006709 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006710#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006711 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006712 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006713 case EVENT_RX_PROBE_REQ:
6714 if (data->rx_probe_req.sa == NULL ||
6715 data->rx_probe_req.ie == NULL)
6716 break;
6717#ifdef CONFIG_AP
6718 if (wpa_s->ap_iface) {
6719 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6720 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006721 data->rx_probe_req.da,
6722 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006723 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006724 data->rx_probe_req.ie_len,
6725 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006726 break;
6727 }
6728#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006729 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006730 data->rx_probe_req.da,
6731 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006732 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006733 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006734 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006735 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006736 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006737 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006738#ifdef CONFIG_OFFCHANNEL
6739 offchannel_remain_on_channel_cb(
6740 wpa_s, data->remain_on_channel.freq,
6741 data->remain_on_channel.duration);
6742#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006743 wpas_p2p_remain_on_channel_cb(
6744 wpa_s, data->remain_on_channel.freq,
6745 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006746#ifdef CONFIG_DPP
6747 wpas_dpp_remain_on_channel_cb(
6748 wpa_s, data->remain_on_channel.freq,
6749 data->remain_on_channel.duration);
6750#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006751#ifdef CONFIG_NAN_USD
6752 wpas_nan_usd_remain_on_channel_cb(
6753 wpa_s, data->remain_on_channel.freq,
6754 data->remain_on_channel.duration);
6755#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006756 break;
6757 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006758#ifdef CONFIG_OFFCHANNEL
6759 offchannel_cancel_remain_on_channel_cb(
6760 wpa_s, data->remain_on_channel.freq);
6761#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006762 wpas_p2p_cancel_remain_on_channel_cb(
6763 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006764#ifdef CONFIG_DPP
6765 wpas_dpp_cancel_remain_on_channel_cb(
6766 wpa_s, data->remain_on_channel.freq);
6767#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006768#ifdef CONFIG_NAN_USD
6769 wpas_nan_usd_cancel_remain_on_channel_cb(
6770 wpa_s, data->remain_on_channel.freq);
6771#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006772 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006773 case EVENT_EAPOL_RX:
6774 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6775 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00006776 data->eapol_rx.data_len,
6777 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006778 break;
6779 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006780 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00006781 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006782 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006783 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006784 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006785 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006786 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006787 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006788 bgscan_notify_signal_change(
6789 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006790 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006791 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006792 data->signal_change.data.current_tx_rate);
6793 os_memcpy(&wpa_s->last_signal_info, data,
6794 sizeof(struct wpa_signal_info));
6795 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006796 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006797 case EVENT_INTERFACE_MAC_CHANGED:
6798 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006799 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006800 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006801 case EVENT_INTERFACE_ENABLED:
6802 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6803 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006804 u8 addr[ETH_ALEN];
6805
Hai Shalomfdcde762020-04-02 11:19:20 -07006806 eloop_cancel_timeout(wpas_clear_disabled_interface,
6807 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08006808 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006809 wpa_supplicant_update_mac_addr(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006810 if (!ether_addr_equal(addr, wpa_s->own_addr))
Hai Shalomc1a21442022-02-04 13:43:00 -08006811 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6812 else
6813 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07006814 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006815 if (wpa_s->p2p_mgmt) {
6816 wpa_supplicant_set_state(wpa_s,
6817 WPA_DISCONNECTED);
6818 break;
6819 }
6820
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006821#ifdef CONFIG_AP
6822 if (!wpa_s->ap_iface) {
6823 wpa_supplicant_set_state(wpa_s,
6824 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006825 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006826 wpa_supplicant_req_scan(wpa_s, 0, 0);
6827 } else
6828 wpa_supplicant_set_state(wpa_s,
6829 WPA_COMPLETED);
6830#else /* CONFIG_AP */
6831 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6832 wpa_supplicant_req_scan(wpa_s, 0, 0);
6833#endif /* CONFIG_AP */
6834 }
6835 break;
6836 case EVENT_INTERFACE_DISABLED:
6837 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006838#ifdef CONFIG_P2P
6839 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6840 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6841 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6842 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006843 * Mark interface disabled if this happens to end up not
6844 * being removed as a separate P2P group interface.
6845 */
6846 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6847 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006848 * The interface was externally disabled. Remove
6849 * it assuming an external entity will start a
6850 * new session if needed.
6851 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006852 if (wpa_s->current_ssid &&
6853 wpa_s->current_ssid->p2p_group)
6854 wpas_p2p_interface_unavailable(wpa_s);
6855 else
6856 wpas_p2p_disconnect(wpa_s);
6857 /*
6858 * wpa_s instance may have been freed, so must not use
6859 * it here anymore.
6860 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006861 break;
6862 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006863 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6864 p2p_in_progress(wpa_s->global->p2p) > 1) {
6865 /* This radio work will be cancelled, so clear P2P
6866 * state as well.
6867 */
6868 p2p_stop_find(wpa_s->global->p2p);
6869 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006870#endif /* CONFIG_P2P */
6871
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006872 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6873 /*
6874 * Indicate disconnection to keep ctrl_iface events
6875 * consistent.
6876 */
6877 wpa_supplicant_event_disassoc(
6878 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6879 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006880 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07006881 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08006882 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6883 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006884 clear_at.usec = 0;
6885 } else {
6886 struct os_reltime tmp;
6887
Hai Shalom60840252021-02-19 19:02:11 -08006888 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006889 tmp.usec = 0;
6890 os_reltime_sub(&tmp, &age, &clear_at);
6891 }
6892 eloop_register_timeout(clear_at.sec, clear_at.usec,
6893 wpas_clear_disabled_interface,
6894 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08006895 radio_remove_works(wpa_s, NULL, 0);
6896
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006897 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6898 break;
6899 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006900 wpa_supplicant_update_channel_list(
6901 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006902 break;
6903 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006904 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006905 break;
6906 case EVENT_BEST_CHANNEL:
6907 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6908 "(%d %d %d)",
6909 data->best_chan.freq_24, data->best_chan.freq_5,
6910 data->best_chan.freq_overall);
6911 wpa_s->best_24_freq = data->best_chan.freq_24;
6912 wpa_s->best_5_freq = data->best_chan.freq_5;
6913 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006914 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6915 data->best_chan.freq_5,
6916 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006917 break;
6918 case EVENT_UNPROT_DEAUTH:
6919 wpa_supplicant_event_unprot_deauth(wpa_s,
6920 &data->unprot_deauth);
6921 break;
6922 case EVENT_UNPROT_DISASSOC:
6923 wpa_supplicant_event_unprot_disassoc(wpa_s,
6924 &data->unprot_disassoc);
6925 break;
6926 case EVENT_STATION_LOW_ACK:
6927#ifdef CONFIG_AP
6928 if (wpa_s->ap_iface && data)
6929 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6930 data->low_ack.addr);
6931#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006932#ifdef CONFIG_TDLS
6933 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07006934 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
6935 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006936#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006937 break;
6938 case EVENT_IBSS_PEER_LOST:
6939#ifdef CONFIG_IBSS_RSN
6940 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6941#endif /* CONFIG_IBSS_RSN */
6942 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006943 case EVENT_DRIVER_GTK_REKEY:
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006944 if (!ether_addr_equal(data->driver_gtk_rekey.bssid,
6945 wpa_s->bssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006946 break;
6947 if (!wpa_s->wpa)
6948 break;
6949 wpa_sm_update_replay_ctr(wpa_s->wpa,
6950 data->driver_gtk_rekey.replay_ctr);
6951 break;
6952 case EVENT_SCHED_SCAN_STOPPED:
6953 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006954 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006955 wpa_supplicant_notify_scanning(wpa_s, 0);
6956
6957 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6958 break;
6959
6960 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006961 * If the driver stopped scanning without being requested to,
6962 * request a new scan to continue scanning for networks.
6963 */
6964 if (!wpa_s->sched_scan_stop_req &&
6965 wpa_s->wpa_state == WPA_SCANNING) {
6966 wpa_dbg(wpa_s, MSG_DEBUG,
6967 "Restart scanning after unexpected sched_scan stop event");
6968 wpa_supplicant_req_scan(wpa_s, 1, 0);
6969 break;
6970 }
6971
6972 wpa_s->sched_scan_stop_req = 0;
6973
6974 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006975 * Start a new sched scan to continue searching for more SSIDs
6976 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006977 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006978 if (wpa_s->sched_scan_timed_out) {
6979 wpa_supplicant_req_sched_scan(wpa_s);
6980 } else if (wpa_s->pno_sched_pending) {
6981 wpa_s->pno_sched_pending = 0;
6982 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006983 } else if (resched) {
6984 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006985 }
6986
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006987 break;
6988 case EVENT_WPS_BUTTON_PUSHED:
6989#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006990 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006991#endif /* CONFIG_WPS */
6992 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006993 case EVENT_AVOID_FREQUENCIES:
6994 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6995 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006996 case EVENT_CONNECT_FAILED_REASON:
6997#ifdef CONFIG_AP
6998 if (!wpa_s->ap_iface || !data)
6999 break;
7000 hostapd_event_connect_failed_reason(
7001 wpa_s->ap_iface->bss[0],
7002 data->connect_failed_reason.addr,
7003 data->connect_failed_reason.code);
7004#endif /* CONFIG_AP */
7005 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007006 case EVENT_NEW_PEER_CANDIDATE:
7007#ifdef CONFIG_MESH
7008 if (!wpa_s->ifmsh || !data)
7009 break;
7010 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
7011 data->mesh_peer.ies,
7012 data->mesh_peer.ie_len);
7013#endif /* CONFIG_MESH */
7014 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007015 case EVENT_SURVEY:
7016#ifdef CONFIG_AP
7017 if (!wpa_s->ap_iface)
7018 break;
7019 hostapd_event_get_survey(wpa_s->ap_iface,
7020 &data->survey_results);
7021#endif /* CONFIG_AP */
7022 break;
7023 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08007024#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007025#ifdef CONFIG_ACS
7026 if (!wpa_s->ap_iface)
7027 break;
7028 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
7029 &data->acs_selected_channels);
7030#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08007031#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08007032 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007033 case EVENT_P2P_LO_STOP:
7034#ifdef CONFIG_P2P
7035 wpa_s->p2p_lo_started = 0;
7036 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
7037 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
7038 data->p2p_lo_stop.reason_code);
7039#endif /* CONFIG_P2P */
7040 break;
Paul Stewart092955c2017-02-06 09:13:09 -08007041 case EVENT_BEACON_LOSS:
7042 if (!wpa_s->current_bss || !wpa_s->current_ssid)
7043 break;
7044 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
7045 bgscan_notify_beacon_loss(wpa_s);
7046 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007047 case EVENT_EXTERNAL_AUTH:
7048#ifdef CONFIG_SAE
7049 if (!wpa_s->current_ssid) {
7050 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
7051 break;
7052 }
7053 sme_external_auth_trigger(wpa_s, data);
7054#endif /* CONFIG_SAE */
7055 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07007056#ifdef CONFIG_PASN
7057 case EVENT_PASN_AUTH:
7058 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
7059 break;
7060#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007061 case EVENT_PORT_AUTHORIZED:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00007062#ifdef CONFIG_AP
7063 if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
7064 struct sta_info *sta;
7065
7066 sta = ap_get_sta(wpa_s->ap_iface->bss[0],
7067 data->port_authorized.sta_addr);
7068 if (sta)
7069 ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
7070 sta, 1);
7071 else
7072 wpa_printf(MSG_DEBUG,
7073 "No STA info matching port authorized event found");
7074 break;
7075 }
7076#endif /* CONFIG_AP */
Sunil Ravi77d572f2023-01-17 23:58:31 +00007077#ifndef CONFIG_NO_WPA
7078 if (data->port_authorized.td_bitmap_len) {
7079 wpa_printf(MSG_DEBUG,
7080 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
7081 data->port_authorized.td_bitmap[0]);
7082 wpas_transition_disable(
7083 wpa_s, data->port_authorized.td_bitmap[0]);
7084 }
7085#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07007086 wpa_supplicant_event_port_authorized(wpa_s);
7087 break;
7088 case EVENT_STATION_OPMODE_CHANGED:
7089#ifdef CONFIG_AP
7090 if (!wpa_s->ap_iface || !data)
7091 break;
7092
7093 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
7094 data->sta_opmode.addr,
7095 data->sta_opmode.smps_mode,
7096 data->sta_opmode.chan_width,
7097 data->sta_opmode.rx_nss);
7098#endif /* CONFIG_AP */
7099 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07007100 case EVENT_UNPROT_BEACON:
7101 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
7102 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08007103 case EVENT_TX_WAIT_EXPIRE:
7104#ifdef CONFIG_DPP
7105 wpas_dpp_tx_wait_expire(wpa_s);
7106#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007107#ifdef CONFIG_NAN_USD
7108 wpas_nan_usd_tx_wait_expire(wpa_s);
7109#endif /* CONFIG_NAN_USD */
Hai Shalomc1a21442022-02-04 13:43:00 -08007110 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00007111 case EVENT_TID_LINK_MAP:
7112 if (data)
7113 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
7114 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007115 default:
7116 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
7117 break;
7118 }
7119}
Dmitry Shmidte4663042016-04-04 10:07:49 -07007120
7121
7122void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
7123 union wpa_event_data *data)
7124{
7125 struct wpa_supplicant *wpa_s;
7126
7127 if (event != EVENT_INTERFACE_STATUS)
7128 return;
7129
7130 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
7131 if (wpa_s && wpa_s->driver->get_ifindex) {
7132 unsigned int ifindex;
7133
7134 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
7135 if (ifindex != data->interface_status.ifindex) {
7136 wpa_dbg(wpa_s, MSG_DEBUG,
7137 "interface status ifindex %d mismatch (%d)",
7138 ifindex, data->interface_status.ifindex);
7139 return;
7140 }
7141 }
7142#ifdef CONFIG_MATCH_IFACE
7143 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
7144 struct wpa_interface *wpa_i;
7145
7146 wpa_i = wpa_supplicant_match_iface(
7147 ctx, data->interface_status.ifname);
7148 if (!wpa_i)
7149 return;
7150 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
7151 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07007152 }
7153#endif /* CONFIG_MATCH_IFACE */
7154
7155 if (wpa_s)
7156 wpa_supplicant_event(wpa_s, event, data);
7157}