blob: fc93305c0af1927ac386345139670f079932897e [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"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070053#include "dpp_supplicant.h"
Mir Ali677e7482020-11-12 19:49:02 +053054#include "rsn_supp/wpa_i.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070055
56
Hai Shalom39ba6fc2019-01-22 12:40:38 -080057#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
58
59
Dmitry Shmidt34af3062013-07-11 10:46:32 -070060#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070061static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +000062 int new_scan, int own_request,
63 bool trigger_6ghz_scan,
64 union wpa_event_data *data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070065#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080066
67
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070068int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070069{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080070 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070071
72 if (ssid == NULL || ssid->disabled_until.sec == 0)
73 return 0;
74
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080075 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070076 if (ssid->disabled_until.sec > now.sec)
77 return ssid->disabled_until.sec - now.sec;
78
79 wpas_clear_temp_disabled(wpa_s, ssid, 0);
80
81 return 0;
82}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083
84
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080085#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070086/**
87 * wpas_reenabled_network_time - Time until first network is re-enabled
88 * @wpa_s: Pointer to wpa_supplicant data
89 * Returns: If all enabled networks are temporarily disabled, returns the time
90 * (in sec) until the first network is re-enabled. Otherwise returns 0.
91 *
92 * This function is used in case all enabled networks are temporarily disabled,
93 * in which case it returns the time (in sec) that the first network will be
94 * re-enabled. The function assumes that at least one network is enabled.
95 */
96static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
97{
98 struct wpa_ssid *ssid;
99 int disabled_for, res = 0;
100
101#ifdef CONFIG_INTERWORKING
102 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
103 wpa_s->conf->cred)
104 return 0;
105#endif /* CONFIG_INTERWORKING */
106
107 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
108 if (ssid->disabled)
109 continue;
110
111 disabled_for = wpas_temp_disabled(wpa_s, ssid);
112 if (!disabled_for)
113 return 0;
114
115 if (!res || disabled_for < res)
116 res = disabled_for;
117 }
118
119 return res;
120}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800121#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700122
123
124void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
125{
126 struct wpa_supplicant *wpa_s = eloop_ctx;
127
128 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
129 return;
130
131 wpa_dbg(wpa_s, MSG_DEBUG,
132 "Try to associate due to network getting re-enabled");
133 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
134 wpa_supplicant_cancel_sched_scan(wpa_s);
135 wpa_supplicant_req_scan(wpa_s, 0, 0);
136 }
137}
138
139
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800140static struct wpa_bss * wpa_supplicant_get_new_bss(
141 struct wpa_supplicant *wpa_s, const u8 *bssid)
142{
143 struct wpa_bss *bss = NULL;
144 struct wpa_ssid *ssid = wpa_s->current_ssid;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000145 u8 drv_ssid[SSID_MAX_LEN];
146 int res;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800147
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000148 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
149 if (res > 0)
150 bss = wpa_bss_get(wpa_s, bssid, drv_ssid, res);
151 if (!bss && ssid && ssid->ssid_len > 0)
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800152 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
153 if (!bss)
154 bss = wpa_bss_get_bssid(wpa_s, bssid);
155
156 return bss;
157}
158
159
Sunil Ravia04bd252022-05-02 22:54:18 -0700160static struct wpa_bss *
161wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700162{
Sunil Ravia04bd252022-05-02 22:54:18 -0700163 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700164
165 if (!bss) {
166 wpa_supplicant_update_scan_results(wpa_s);
167
168 /* Get the BSS from the new scan results */
Sunil Ravia04bd252022-05-02 22:54:18 -0700169 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700170 }
171
172 if (bss)
173 wpa_s->current_bss = bss;
Sunil Ravia04bd252022-05-02 22:54:18 -0700174
175 return bss;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700176}
177
178
Sunil Ravi89eba102022-09-13 21:04:37 -0700179static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
180 u8 link_id, const u8 *bssid)
181{
182 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
183
184 if (!bss) {
185 wpa_supplicant_update_scan_results(wpa_s);
186 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
187 }
188
189 if (bss)
190 wpa_s->links[link_id].bss = bss;
191}
192
193
Sunil Ravi77d572f2023-01-17 23:58:31 +0000194static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
195 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700196{
197 struct wpa_ssid *ssid, *old_ssid;
Sunil Ravi640215c2023-06-28 23:08:09 +0000198 struct wpa_bss *bss;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700199 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700200 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700201 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700203 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700204 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700205
206 if (wpa_s->current_ssid->ssid_len == 0)
207 return 0; /* current profile still in use */
208 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
209 if (res < 0) {
210 wpa_msg(wpa_s, MSG_INFO,
211 "Failed to read SSID from driver");
212 return 0; /* try to use current profile */
213 }
214 drv_ssid_len = res;
215
216 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
217 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
218 drv_ssid_len) == 0)
219 return 0; /* current profile still in use */
220
Hai Shalomfdcde762020-04-02 11:19:20 -0700221#ifdef CONFIG_OWE
222 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
223 wpa_s->current_bss &&
224 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
225 drv_ssid_len == wpa_s->current_bss->ssid_len &&
226 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
227 drv_ssid_len) == 0)
228 return 0; /* current profile still in use */
229#endif /* CONFIG_OWE */
230
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700231 wpa_msg(wpa_s, MSG_DEBUG,
232 "Driver-initiated BSS selection changed the SSID to %s",
233 wpa_ssid_txt(drv_ssid, drv_ssid_len));
234 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700235 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700236
237 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
238 "information");
239 ssid = wpa_supplicant_get_ssid(wpa_s);
240 if (ssid == NULL) {
241 wpa_msg(wpa_s, MSG_INFO,
242 "No network configuration found for the current AP");
243 return -1;
244 }
245
Dmitry Shmidt04949592012-07-19 12:16:46 -0700246 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700247 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
248 return -1;
249 }
250
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800251 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
252 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
253 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
254 return -1;
255 }
256
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700257 res = wpas_temp_disabled(wpa_s, ssid);
258 if (res > 0) {
259 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
260 "disabled for %d second(s)", res);
261 return -1;
262 }
263
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
265 "current AP");
Sunil Ravi640215c2023-06-28 23:08:09 +0000266 bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800267 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268 u8 wpa_ie[80];
269 size_t wpa_ie_len = sizeof(wpa_ie);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000270 bool skip_default_rsne;
271
272 /* Do not override RSNE/RSNXE with the default values if the
273 * driver indicated the actual values used in the
274 * (Re)Association Request frame. */
275 skip_default_rsne = data && data->assoc_info.req_ies;
Sunil Ravi640215c2023-06-28 23:08:09 +0000276 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000277 wpa_ie, &wpa_ie_len,
278 skip_default_rsne) < 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800279 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280 } else {
281 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
282 }
283
284 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
285 eapol_sm_invalidate_cached_session(wpa_s->eapol);
286 old_ssid = wpa_s->current_ssid;
287 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
290 wpa_supplicant_initiate_eapol(wpa_s);
291 if (old_ssid != wpa_s->current_ssid)
292 wpas_notify_network_changed(wpa_s);
293
294 return 0;
295}
296
297
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800298void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299{
300 struct wpa_supplicant *wpa_s = eloop_ctx;
301
302 if (wpa_s->countermeasures) {
303 wpa_s->countermeasures = 0;
304 wpa_drv_set_countermeasures(wpa_s, 0);
305 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800306
307 /*
308 * It is possible that the device is sched scanning, which means
309 * that a connection attempt will be done only when we receive
310 * scan results. However, in this case, it would be preferable
311 * to scan and connect immediately, so cancel the sched_scan and
312 * issue a regular scan flow.
313 */
314 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 wpa_supplicant_req_scan(wpa_s, 0, 0);
316 }
317}
318
319
Sunil Ravi77d572f2023-01-17 23:58:31 +0000320void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
Sunil Ravi89eba102022-09-13 21:04:37 -0700321{
Sunil Ravi89eba102022-09-13 21:04:37 -0700322 if (!wpa_s->valid_links)
323 return;
324
325 wpa_s->valid_links = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000326 wpa_s->mlo_assoc_link_id = 0;
327 os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN);
328 os_memset(wpa_s->links, 0, sizeof(wpa_s->links));
Sunil Ravi89eba102022-09-13 21:04:37 -0700329}
330
331
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
333{
334 int bssid_changed;
335
Dmitry Shmidt04949592012-07-19 12:16:46 -0700336 wnm_bss_keep_alive_deinit(wpa_s);
337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338#ifdef CONFIG_IBSS_RSN
339 ibss_rsn_deinit(wpa_s->ibss_rsn);
340 wpa_s->ibss_rsn = NULL;
341#endif /* CONFIG_IBSS_RSN */
342
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700343#ifdef CONFIG_AP
344 wpa_supplicant_ap_deinit(wpa_s);
345#endif /* CONFIG_AP */
346
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700347#ifdef CONFIG_HS20
348 /* Clear possibly configured frame filters */
349 wpa_drv_configure_frame_filters(wpa_s, 0);
350#endif /* CONFIG_HS20 */
351
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
353 return;
354
Hai Shalom74f70d42019-02-11 14:42:39 -0800355 if (os_reltime_initialized(&wpa_s->session_start)) {
356 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
357 wpa_s->session_start.sec = 0;
358 wpa_s->session_start.usec = 0;
359 wpas_notify_session_length(wpa_s);
360 }
361
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700362 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
363 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
364 os_memset(wpa_s->bssid, 0, ETH_ALEN);
365 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800366 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700367 wpa_s->current_bss = NULL;
368 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700369
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700370 if (bssid_changed)
371 wpas_notify_bssid_changed(wpa_s);
372
Hai Shalome21d4e82020-04-29 16:34:06 -0700373 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
374 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700375 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
376 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700377 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700378 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700379 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700381 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700382 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700383 wpa_s->key_mgmt = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700384 wpa_s->allowed_key_mgmts = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800385
386 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800387 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800388 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700389 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700390
391#ifdef CONFIG_TESTING_OPTIONS
392 wpa_s->last_tk_alg = WPA_ALG_NONE;
393 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
394#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700395 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800396
397 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
398 wpa_s->enabled_4addr_mode = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700399
Sunil Ravi77d572f2023-01-17 23:58:31 +0000400 wpa_s->wps_scan_done = false;
Sunil Ravi89eba102022-09-13 21:04:37 -0700401 wpas_reset_mlo_info(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700402}
403
404
Sunil Ravi036cec52023-03-29 11:35:17 -0700405static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700406{
407 struct wpa_ie_data ie;
408 int pmksa_set = -1;
409 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800410 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411
Hai Shalomc1a21442022-02-04 13:43:00 -0800412 /* Start with assumption of no PMKSA cache entry match for cases other
413 * than SAE. In particular, this is needed to generate the PMKSA cache
414 * entries for Suite B cases with driver-based roaming indication. */
415 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
416 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
417 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700418
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700419 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
420 ie.pmkid == NULL)
421 return;
422
423 for (i = 0; i < ie.num_pmkid; i++) {
424 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
425 ie.pmkid + i * PMKID_LEN,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000426 NULL, NULL, 0, NULL, 0,
427 true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700428 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800429 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Sunil Ravi036cec52023-03-29 11:35:17 -0700430 if (authorized)
431 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432 break;
433 }
434 }
435
436 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
437 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
438}
439
440
441static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
442 union wpa_event_data *data)
443{
444 if (data == NULL) {
445 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
446 "event");
447 return;
448 }
449 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
450 " index=%d preauth=%d",
451 MAC2STR(data->pmkid_candidate.bssid),
452 data->pmkid_candidate.index,
453 data->pmkid_candidate.preauth);
454
455 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
456 data->pmkid_candidate.index,
457 data->pmkid_candidate.preauth);
458}
459
460
461static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
462{
463 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
464 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
465 return 0;
466
467#ifdef IEEE8021X_EAPOL
468 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
469 wpa_s->current_ssid &&
470 !(wpa_s->current_ssid->eapol_flags &
471 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
472 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
473 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
474 * plaintext or static WEP keys). */
475 return 0;
476 }
477#endif /* IEEE8021X_EAPOL */
478
479 return 1;
480}
481
482
483/**
484 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
485 * @wpa_s: pointer to wpa_supplicant data
486 * @ssid: Configuration data for the network
487 * Returns: 0 on success, -1 on failure
488 *
489 * This function is called when starting authentication with a network that is
490 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
491 */
492int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
493 struct wpa_ssid *ssid)
494{
495#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800496#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700497 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700499 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
500 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 return 0;
502
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700503 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504 sim = 1;
505 aka = 1;
506 } else {
507 struct eap_method_type *eap = ssid->eap.eap_methods;
508 while (eap->vendor != EAP_VENDOR_IETF ||
509 eap->method != EAP_TYPE_NONE) {
510 if (eap->vendor == EAP_VENDOR_IETF) {
511 if (eap->method == EAP_TYPE_SIM)
512 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700513 else if (eap->method == EAP_TYPE_AKA ||
514 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515 aka = 1;
516 }
517 eap++;
518 }
519 }
520
521 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
522 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700523 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
524 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
525 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700526 aka = 0;
527
528 if (!sim && !aka) {
529 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
530 "use SIM, but neither EAP-SIM nor EAP-AKA are "
531 "enabled");
532 return 0;
533 }
534
535 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
536 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700537
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700538 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539 if (wpa_s->scard == NULL) {
540 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
541 "(pcsc-lite)");
542 return -1;
543 }
544 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
545 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800546#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700547#endif /* IEEE8021X_EAPOL */
548
549 return 0;
550}
551
552
553#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700554
Hai Shalomfdcde762020-04-02 11:19:20 -0700555#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700556static int has_wep_key(struct wpa_ssid *ssid)
557{
558 int i;
559
560 for (i = 0; i < NUM_WEP_KEYS; i++) {
561 if (ssid->wep_key_len[i])
562 return 1;
563 }
564
565 return 0;
566}
Hai Shalomfdcde762020-04-02 11:19:20 -0700567#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700568
569
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700570static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700571 struct wpa_ssid *ssid)
572{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700573 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574
575 if (ssid->mixed_cell)
576 return 1;
577
578#ifdef CONFIG_WPS
579 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
580 return 1;
581#endif /* CONFIG_WPS */
582
Roshan Pius3a1667e2018-07-03 15:17:14 -0700583#ifdef CONFIG_OWE
584 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
585 return 1;
586#endif /* CONFIG_OWE */
587
Hai Shalomfdcde762020-04-02 11:19:20 -0700588#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700589 if (has_wep_key(ssid))
590 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700591#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700592
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593#ifdef IEEE8021X_EAPOL
594 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
595 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
596 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
597 privacy = 1;
598#endif /* IEEE8021X_EAPOL */
599
Jouni Malinen75ecf522011-06-27 15:19:46 -0700600 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
601 privacy = 1;
602
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800603 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
604 privacy = 1;
605
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700606 if (bss->caps & IEEE80211_CAP_PRIVACY)
607 return privacy;
608 return !privacy;
609}
610
611
612static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
613 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800614 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700615{
616 struct wpa_ie_data ie;
617 int proto_match = 0;
618 const u8 *rsn_ie, *wpa_ie;
619 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700620#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700622#endif /* CONFIG_WEP */
Sunil Ravi640215c2023-06-28 23:08:09 +0000623 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700624
625 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
626 if (ret >= 0)
627 return ret;
628
Hai Shalomfdcde762020-04-02 11:19:20 -0700629#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700630 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
631 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
632 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
633 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
634 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700635#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700637 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Sunil Ravi640215c2023-06-28 23:08:09 +0000638 if (is_6ghz_bss && !rsn_ie) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700639 if (debug_print)
640 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000641 " skip - 6 GHz BSS without RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700642 return 0;
643 }
644
Roshan Pius3a1667e2018-07-03 15:17:14 -0700645 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646 proto_match++;
647
648 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800649 if (debug_print)
650 wpa_dbg(wpa_s, MSG_DEBUG,
651 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652 break;
653 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700654 if (!ie.has_pairwise)
655 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
656 if (!ie.has_group)
657 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658
Sunil Ravi640215c2023-06-28 23:08:09 +0000659 if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
660 /* WEP and TKIP are not allowed on 6 GHz/MLD */
Sunil Ravia04bd252022-05-02 22:54:18 -0700661 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
662 WPA_CIPHER_WEP104 |
663 WPA_CIPHER_TKIP);
664 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
665 WPA_CIPHER_WEP104 |
666 WPA_CIPHER_TKIP);
667 }
668
Hai Shalomfdcde762020-04-02 11:19:20 -0700669#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670 if (wep_ok &&
671 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
672 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800673 if (debug_print)
674 wpa_dbg(wpa_s, MSG_DEBUG,
675 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700676 return 1;
677 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700678#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679
Roshan Pius3a1667e2018-07-03 15:17:14 -0700680 if (!(ie.proto & ssid->proto) &&
681 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800682 if (debug_print)
683 wpa_dbg(wpa_s, MSG_DEBUG,
684 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700685 break;
686 }
687
688 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800689 if (debug_print)
690 wpa_dbg(wpa_s, MSG_DEBUG,
691 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700692 break;
693 }
694
695 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800696 if (debug_print)
697 wpa_dbg(wpa_s, MSG_DEBUG,
698 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700699 break;
700 }
701
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700702 if (ssid->group_mgmt_cipher &&
703 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
704 if (debug_print)
705 wpa_dbg(wpa_s, MSG_DEBUG,
706 " skip RSN IE - group mgmt cipher mismatch");
707 break;
708 }
709
Sunil Ravi640215c2023-06-28 23:08:09 +0000710 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700711 /* MFPC must be supported on 6 GHz */
712 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
713 if (debug_print)
714 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000715 " skip RSNE - 6 GHz without MFPC");
Sunil Ravia04bd252022-05-02 22:54:18 -0700716 break;
717 }
718
719 /* WPA PSK is not allowed on the 6 GHz band */
720 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
721 WPA_KEY_MGMT_FT_PSK |
722 WPA_KEY_MGMT_PSK_SHA256);
723 }
724
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800726 if (debug_print)
727 wpa_dbg(wpa_s, MSG_DEBUG,
728 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729 break;
730 }
731
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700732 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800733 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800734 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800735 if (debug_print)
736 wpa_dbg(wpa_s, MSG_DEBUG,
737 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700738 break;
739 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800740 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
741 wpas_get_ssid_pmf(wpa_s, ssid) ==
742 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800743 if (debug_print)
744 wpa_dbg(wpa_s, MSG_DEBUG,
745 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800746 break;
747 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800749 if (debug_print)
750 wpa_dbg(wpa_s, MSG_DEBUG,
751 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752 return 1;
753 }
754
Sunil Ravi640215c2023-06-28 23:08:09 +0000755 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700756 if (debug_print)
757 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000758 " skip - 6 GHz BSS without matching RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700759 return 0;
760 }
761
Roshan Pius3a1667e2018-07-03 15:17:14 -0700762 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
763 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800764 if (debug_print)
765 wpa_dbg(wpa_s, MSG_DEBUG,
766 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700767 return 0;
768 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700769
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700770 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
772 proto_match++;
773
774 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800775 if (debug_print)
776 wpa_dbg(wpa_s, MSG_DEBUG,
777 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778 break;
779 }
780
Hai Shalomfdcde762020-04-02 11:19:20 -0700781#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782 if (wep_ok &&
783 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
784 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800785 if (debug_print)
786 wpa_dbg(wpa_s, MSG_DEBUG,
787 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788 return 1;
789 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700790#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700791
792 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800793 if (debug_print)
794 wpa_dbg(wpa_s, MSG_DEBUG,
795 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796 break;
797 }
798
799 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800800 if (debug_print)
801 wpa_dbg(wpa_s, MSG_DEBUG,
802 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803 break;
804 }
805
806 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800807 if (debug_print)
808 wpa_dbg(wpa_s, MSG_DEBUG,
809 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 break;
811 }
812
813 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800814 if (debug_print)
815 wpa_dbg(wpa_s, MSG_DEBUG,
816 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 break;
818 }
819
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800820 if (debug_print)
821 wpa_dbg(wpa_s, MSG_DEBUG,
822 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823 return 1;
824 }
825
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700826 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
827 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800828 if (debug_print)
829 wpa_dbg(wpa_s, MSG_DEBUG,
830 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700831 return 1;
832 }
833
Roshan Pius3a1667e2018-07-03 15:17:14 -0700834#ifdef CONFIG_OWE
835 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
836 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800837 if (wpa_s->owe_transition_select &&
838 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
839 ssid->owe_transition_bss_select_count + 1 <=
840 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
841 ssid->owe_transition_bss_select_count++;
842 if (debug_print)
843 wpa_dbg(wpa_s, MSG_DEBUG,
844 " skip OWE transition BSS (selection count %d does not exceed %d)",
845 ssid->owe_transition_bss_select_count,
846 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
847 wpa_s->owe_transition_search = 1;
848 return 0;
849 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700850 if (debug_print)
851 wpa_dbg(wpa_s, MSG_DEBUG,
852 " allow in OWE transition mode");
853 return 1;
854 }
855#endif /* CONFIG_OWE */
856
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700857 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
858 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800859 if (debug_print)
860 wpa_dbg(wpa_s, MSG_DEBUG,
861 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862 return 0;
863 }
864
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800865 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
866 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800867 if (debug_print)
868 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800869 return 1;
870 }
871
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800873 if (debug_print)
874 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700875 return 1;
876 }
877
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800878 if (debug_print)
879 wpa_dbg(wpa_s, MSG_DEBUG,
880 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881
882 return 0;
883}
884
885
886static int freq_allowed(int *freqs, int freq)
887{
888 int i;
889
890 if (freqs == NULL)
891 return 1;
892
893 for (i = 0; freqs[i]; i++)
894 if (freqs[i] == freq)
895 return 1;
896 return 0;
897}
898
899
Hai Shalomfdcde762020-04-02 11:19:20 -0700900static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
901 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800902{
903 const struct hostapd_hw_modes *mode = NULL, *modes;
904 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
905 const u8 *rate_ie;
906 int i, j, k;
907
908 if (bss->freq == 0)
909 return 1; /* Cannot do matching without knowing band */
910
911 modes = wpa_s->hw.modes;
912 if (modes == NULL) {
913 /*
914 * The driver does not provide any additional information
915 * about the utilized hardware, so allow the connection attempt
916 * to continue.
917 */
918 return 1;
919 }
920
921 for (i = 0; i < wpa_s->hw.num_modes; i++) {
922 for (j = 0; j < modes[i].num_channels; j++) {
923 int freq = modes[i].channels[j].freq;
924 if (freq == bss->freq) {
925 if (mode &&
926 mode->mode == HOSTAPD_MODE_IEEE80211G)
927 break; /* do not allow 802.11b replace
928 * 802.11g */
929 mode = &modes[i];
930 break;
931 }
932 }
933 }
934
935 if (mode == NULL)
936 return 0;
937
938 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700939 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800940 if (rate_ie == NULL)
941 continue;
942
943 for (j = 2; j < rate_ie[1] + 2; j++) {
944 int flagged = !!(rate_ie[j] & 0x80);
945 int r = (rate_ie[j] & 0x7f) * 5;
946
947 /*
948 * IEEE Std 802.11n-2009 7.3.2.2:
949 * The new BSS Membership selector value is encoded
950 * like a legacy basic rate, but it is not a rate and
951 * only indicates if the BSS members are required to
952 * support the mandatory features of Clause 20 [HT PHY]
953 * in order to join the BSS.
954 */
955 if (flagged && ((rate_ie[j] & 0x7f) ==
956 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
957 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800958 if (debug_print)
959 wpa_dbg(wpa_s, MSG_DEBUG,
960 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800961 return 0;
962 }
963 continue;
964 }
965
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700966 /* There's also a VHT selector for 802.11ac */
967 if (flagged && ((rate_ie[j] & 0x7f) ==
968 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
969 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800970 if (debug_print)
971 wpa_dbg(wpa_s, MSG_DEBUG,
972 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700973 return 0;
974 }
975 continue;
976 }
977
Sunil Ravi77d572f2023-01-17 23:58:31 +0000978 if (flagged && ((rate_ie[j] & 0x7f) ==
979 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
980 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
981 if (debug_print)
982 wpa_dbg(wpa_s, MSG_DEBUG,
983 " hardware does not support HE PHY");
984 return 0;
985 }
986 continue;
987 }
988
Hai Shalomc3565922019-10-28 11:58:20 -0700989#ifdef CONFIG_SAE
990 if (flagged && ((rate_ie[j] & 0x7f) ==
991 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Sunil Ravi77d572f2023-01-17 23:58:31 +0000992 if (wpa_s->conf->sae_pwe ==
993 SAE_PWE_HUNT_AND_PECK &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700994 !ssid->sae_password_id &&
Sunil Ravi036cec52023-03-29 11:35:17 -0700995 !is_6ghz_freq(bss->freq) &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700996 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700997 if (debug_print)
998 wpa_dbg(wpa_s, MSG_DEBUG,
999 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001000#ifdef CONFIG_TESTING_OPTIONS
1001 if (wpa_s->ignore_sae_h2e_only) {
1002 wpa_dbg(wpa_s, MSG_DEBUG,
1003 "TESTING: Ignore SAE H2E requirement mismatch");
1004 continue;
1005 }
1006#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -07001007 return 0;
1008 }
1009 continue;
1010 }
1011#endif /* CONFIG_SAE */
1012
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001013 if (!flagged)
1014 continue;
1015
1016 /* check for legacy basic rates */
1017 for (k = 0; k < mode->num_rates; k++) {
1018 if (mode->rates[k] == r)
1019 break;
1020 }
1021 if (k == mode->num_rates) {
1022 /*
1023 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1024 * order to join a BSS all required rates
1025 * have to be supported by the hardware.
1026 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001027 if (debug_print)
1028 wpa_dbg(wpa_s, MSG_DEBUG,
1029 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1030 r / 10, r % 10,
1031 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001032 return 0;
1033 }
1034 }
1035 }
1036
1037 return 1;
1038}
1039
1040
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001041/*
1042 * Test whether BSS is in an ESS.
1043 * This is done differently in DMG (60 GHz) and non-DMG bands
1044 */
1045static int bss_is_ess(struct wpa_bss *bss)
1046{
1047 if (bss_is_dmg(bss)) {
1048 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1049 IEEE80211_CAP_DMG_AP;
1050 }
1051
1052 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1053 IEEE80211_CAP_ESS);
1054}
1055
1056
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001057static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1058{
1059 size_t i;
1060
1061 for (i = 0; i < ETH_ALEN; i++) {
1062 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1063 return 0;
1064 }
1065 return 1;
1066}
1067
1068
1069static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1070{
1071 size_t i;
1072
1073 for (i = 0; i < num; i++) {
1074 const u8 *a = list + i * ETH_ALEN * 2;
1075 const u8 *m = a + ETH_ALEN;
1076
1077 if (match_mac_mask(a, addr, m))
1078 return 1;
1079 }
1080 return 0;
1081}
1082
1083
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001084static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1085 const u8 **ret_ssid, size_t *ret_ssid_len)
1086{
1087#ifdef CONFIG_OWE
1088 const u8 *owe, *pos, *end, *bssid;
1089 u8 ssid_len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001090
1091 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1092 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
1093 return;
1094
1095 pos = owe + 6;
1096 end = owe + 2 + owe[1];
1097
1098 if (end - pos < ETH_ALEN + 1)
1099 return;
1100 bssid = pos;
1101 pos += ETH_ALEN;
1102 ssid_len = *pos++;
1103 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1104 return;
1105
1106 /* Match the profile SSID against the OWE transition mode SSID on the
1107 * open network. */
1108 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1109 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1110 *ret_ssid = pos;
1111 *ret_ssid_len = ssid_len;
1112
Hai Shalomfdcde762020-04-02 11:19:20 -07001113 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1114 struct wpa_ssid *ssid;
1115
1116 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1117 if (wpas_network_disabled(wpa_s, ssid))
1118 continue;
1119 if (ssid->ssid_len == ssid_len &&
1120 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1121 /* OWE BSS in transition mode for a currently
1122 * enabled OWE network. */
1123 wpa_dbg(wpa_s, MSG_DEBUG,
1124 "OWE: transition mode OWE SSID for active OWE profile");
1125 bss->flags |= WPA_BSS_OWE_TRANSITION;
1126 break;
1127 }
1128 }
1129 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001130#endif /* CONFIG_OWE */
1131}
1132
1133
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001134static bool wpas_valid_ml_bss(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
1135
1136{
1137 u16 removed_links;
1138
1139 if (wpa_bss_parse_basic_ml_element(wpa_s, bss, NULL, NULL))
1140 return true;
1141
1142 if (bss->n_mld_links == 0)
1143 return true;
1144
1145 /* Check if the current BSS is going to be removed */
1146 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss);
1147 if (BIT(bss->mld_links[0].link_id) & removed_links)
1148 return false;
1149
1150 return true;
1151}
1152
1153
Sunil Ravi26978f32021-04-30 15:19:18 -07001154int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001155{
1156 int i, j;
1157
1158 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1159 return 0;
1160
1161 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1162 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1163
1164 for (i = 0; i < mode->num_channels; i++) {
1165 struct hostapd_channel_data *chan = &mode->channels[i];
1166
1167 if (chan->freq == freq)
1168 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1169 }
1170 }
1171
1172 return 1;
1173}
1174
1175
Hai Shalom899fcc72020-10-19 14:38:18 -07001176static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1177 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001178 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001179 bool debug_print);
1180
1181
1182#ifdef CONFIG_SAE_PK
1183static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1184 struct wpa_bss *orig_bss,
1185 struct wpa_ssid *ssid,
1186 const u8 *match_ssid,
1187 size_t match_ssid_len)
1188{
1189 struct wpa_bss *bss;
1190
1191 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1192 int count;
1193 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001194
1195 if (bss == orig_bss)
1196 continue;
1197 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001198 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001199 continue;
1200
1201 /* TODO: Could be more thorough in checking what kind of
1202 * signal strength or throughput estimate would be acceptable
1203 * compared to the originally selected BSS. */
1204 if (bss->est_throughput < 2000)
1205 return false;
1206
Hai Shalom60840252021-02-19 19:02:11 -08001207 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001208 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1209 bss, count, 0))
1210 return true;
1211 }
1212
1213 return false;
1214}
1215#endif /* CONFIG_SAE_PK */
1216
1217
1218static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1219 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001220 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001221 bool debug_print)
1222{
1223 int res;
1224 bool wpa, check_ssid, osen, rsn_osen = false;
1225 struct wpa_ie_data data;
1226#ifdef CONFIG_MBO
1227 const u8 *assoc_disallow;
1228#endif /* CONFIG_MBO */
1229#ifdef CONFIG_SAE
1230 u8 rsnxe_capa = 0;
1231#endif /* CONFIG_SAE */
1232 const u8 *ie;
1233
1234 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1235 wpa = ie && ie[1];
1236 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1237 wpa |= ie && ie[1];
1238 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1239 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1240 rsn_osen = true;
1241 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1242 osen = ie != NULL;
1243
1244#ifdef CONFIG_SAE
1245 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1246 if (ie && ie[1] >= 1)
1247 rsnxe_capa = ie[2];
1248#endif /* CONFIG_SAE */
1249
1250 check_ssid = wpa || ssid->ssid_len > 0;
1251
1252 if (wpas_network_disabled(wpa_s, ssid)) {
1253 if (debug_print)
1254 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1255 return false;
1256 }
1257
1258 res = wpas_temp_disabled(wpa_s, ssid);
1259 if (res > 0) {
1260 if (debug_print)
1261 wpa_dbg(wpa_s, MSG_DEBUG,
1262 " skip - disabled temporarily for %d second(s)",
1263 res);
1264 return false;
1265 }
1266
1267#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001268 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001269 if (debug_print)
1270 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001271 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001272 return false;
1273 }
1274
1275 if (wpa && ssid->ssid_len == 0 &&
1276 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1277 check_ssid = false;
1278
1279 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1280 /* Only allow wildcard SSID match if an AP advertises active
1281 * WPS operation that matches our mode. */
1282 check_ssid = ssid->ssid_len > 0 ||
1283 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1284 }
1285#endif /* CONFIG_WPS */
1286
1287 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1288 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1289 check_ssid = false;
1290
1291 if (check_ssid &&
1292 (match_ssid_len != ssid->ssid_len ||
1293 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1294 if (debug_print)
1295 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1296 return false;
1297 }
1298
1299 if (ssid->bssid_set &&
1300 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1301 if (debug_print)
1302 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1303 return false;
1304 }
1305
Hai Shalom60840252021-02-19 19:02:11 -08001306 /* check the list of BSSIDs to ignore */
1307 if (ssid->num_bssid_ignore &&
1308 addr_in_list(bss->bssid, ssid->bssid_ignore,
1309 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001310 if (debug_print)
1311 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001312 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001313 return false;
1314 }
1315
Hai Shalom60840252021-02-19 19:02:11 -08001316 /* if there is a list of accepted BSSIDs, only accept those APs */
1317 if (ssid->num_bssid_accept &&
1318 !addr_in_list(bss->bssid, ssid->bssid_accept,
1319 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001320 if (debug_print)
1321 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001322 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001323 return false;
1324 }
1325
1326 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1327 return false;
1328
1329 if (!osen && !wpa &&
1330 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1331 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1332 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1333 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1334 if (debug_print)
1335 wpa_dbg(wpa_s, MSG_DEBUG,
1336 " skip - non-WPA network not allowed");
1337 return false;
1338 }
1339
1340#ifdef CONFIG_WEP
1341 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1342 if (debug_print)
1343 wpa_dbg(wpa_s, MSG_DEBUG,
1344 " skip - ignore WPA/WPA2 AP for WEP network block");
1345 return false;
1346 }
1347#endif /* CONFIG_WEP */
1348
1349 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1350 if (debug_print)
1351 wpa_dbg(wpa_s, MSG_DEBUG,
1352 " skip - non-OSEN network not allowed");
1353 return false;
1354 }
1355
1356 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1357 if (debug_print)
1358 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1359 return false;
1360 }
1361
1362 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1363 !bss_is_pbss(bss)) {
1364 if (debug_print)
1365 wpa_dbg(wpa_s, MSG_DEBUG,
1366 " skip - not ESS, PBSS, or MBSS");
1367 return false;
1368 }
1369
1370 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1371 if (debug_print)
1372 wpa_dbg(wpa_s, MSG_DEBUG,
1373 " skip - PBSS mismatch (ssid %d bss %d)",
1374 ssid->pbss, bss_is_pbss(bss));
1375 return false;
1376 }
1377
1378 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1379 if (debug_print)
1380 wpa_dbg(wpa_s, MSG_DEBUG,
1381 " skip - frequency not allowed");
1382 return false;
1383 }
1384
1385#ifdef CONFIG_MESH
1386 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1387 ssid->frequency != bss->freq) {
1388 if (debug_print)
1389 wpa_dbg(wpa_s, MSG_DEBUG,
1390 " skip - frequency not allowed (mesh)");
1391 return false;
1392 }
1393#endif /* CONFIG_MESH */
1394
1395 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1396 if (debug_print)
1397 wpa_dbg(wpa_s, MSG_DEBUG,
1398 " skip - rate sets do not match");
1399 return false;
1400 }
1401
1402#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001403 /* When using SAE Password Identifier and when operationg on the 6 GHz
1404 * band, only H2E is allowed. */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001405 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1406 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1407 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1408 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001409#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301410 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001411#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001412 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1413 if (debug_print)
1414 wpa_dbg(wpa_s, MSG_DEBUG,
1415 " skip - SAE H2E required, but not supported by the AP");
1416 return false;
1417 }
1418#endif /* CONFIG_SAE */
1419
1420#ifdef CONFIG_SAE_PK
1421 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1422 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1423 if (debug_print)
1424 wpa_dbg(wpa_s, MSG_DEBUG,
1425 " skip - SAE-PK required, but not supported by the AP");
1426 return false;
1427 }
1428#endif /* CONFIG_SAE_PK */
1429
1430#ifndef CONFIG_IBSS_RSN
1431 if (ssid->mode == WPAS_MODE_IBSS &&
1432 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1433 if (debug_print)
1434 wpa_dbg(wpa_s, MSG_DEBUG,
1435 " skip - IBSS RSN not supported in the build");
1436 return false;
1437 }
1438#endif /* !CONFIG_IBSS_RSN */
1439
1440#ifdef CONFIG_P2P
1441 if (ssid->p2p_group &&
1442 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1443 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1444 if (debug_print)
1445 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1446 return false;
1447 }
1448
1449 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1450 struct wpabuf *p2p_ie;
1451 u8 dev_addr[ETH_ALEN];
1452
1453 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1454 if (!ie) {
1455 if (debug_print)
1456 wpa_dbg(wpa_s, MSG_DEBUG,
1457 " skip - no P2P element");
1458 return false;
1459 }
1460 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1461 if (!p2p_ie) {
1462 if (debug_print)
1463 wpa_dbg(wpa_s, MSG_DEBUG,
1464 " skip - could not fetch P2P element");
1465 return false;
1466 }
1467
1468 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1469 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1470 if (debug_print)
1471 wpa_dbg(wpa_s, MSG_DEBUG,
1472 " skip - no matching GO P2P Device Address in P2P element");
1473 wpabuf_free(p2p_ie);
1474 return false;
1475 }
1476 wpabuf_free(p2p_ie);
1477 }
1478
1479 /*
1480 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1481 * P2P Group Capability Bitmap and we are not in Group Formation with
1482 * that device.
1483 */
1484#endif /* CONFIG_P2P */
1485
1486 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1487 struct os_reltime diff;
1488
1489 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1490 if (debug_print)
1491 wpa_dbg(wpa_s, MSG_DEBUG,
1492 " skip - scan result not recent enough (%u.%06u seconds too old)",
1493 (unsigned int) diff.sec,
1494 (unsigned int) diff.usec);
1495 return false;
1496 }
1497#ifdef CONFIG_MBO
1498#ifdef CONFIG_TESTING_OPTIONS
1499 if (wpa_s->ignore_assoc_disallow)
1500 goto skip_assoc_disallow;
1501#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001502 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001503 if (assoc_disallow && assoc_disallow[1] >= 1) {
1504 if (debug_print)
1505 wpa_dbg(wpa_s, MSG_DEBUG,
1506 " skip - MBO association disallowed (reason %u)",
1507 assoc_disallow[2]);
1508 return false;
1509 }
1510
1511 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1512 if (debug_print)
1513 wpa_dbg(wpa_s, MSG_DEBUG,
1514 " skip - AP temporarily disallowed");
1515 return false;
1516 }
1517#ifdef CONFIG_TESTING_OPTIONS
1518skip_assoc_disallow:
1519#endif /* CONFIG_TESTING_OPTIONS */
1520#endif /* CONFIG_MBO */
1521
1522#ifdef CONFIG_DPP
1523 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001524 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1525 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001526 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1527 !ssid->dpp_csign)) {
1528 if (debug_print)
1529 wpa_dbg(wpa_s, MSG_DEBUG,
1530 " skip - no PMKSA entry for DPP");
1531 return false;
1532 }
1533#endif /* CONFIG_DPP */
1534
1535#ifdef CONFIG_SAE_PK
1536 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1537 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1538 ((ssid->sae_password &&
1539 sae_pk_valid_password(ssid->sae_password)) ||
1540 (!ssid->sae_password && ssid->passphrase &&
1541 sae_pk_valid_password(ssid->passphrase))) &&
1542 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1543 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1544 match_ssid_len)) {
1545 if (debug_print)
1546 wpa_dbg(wpa_s, MSG_DEBUG,
1547 " skip - another acceptable BSS with SAE-PK in the same ESS");
1548 return false;
1549 }
1550#endif /* CONFIG_SAE_PK */
1551
1552 if (bss->ssid_len == 0) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001553#ifdef CONFIG_OWE
1554 const u8 *owe_ssid = NULL;
1555 size_t owe_ssid_len = 0;
1556
1557 owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len);
1558 if (owe_ssid && owe_ssid_len &&
1559 owe_ssid_len == ssid->ssid_len &&
1560 os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) {
1561 if (debug_print)
1562 wpa_dbg(wpa_s, MSG_DEBUG,
1563 " skip - no SSID in BSS entry for a possible OWE transition mode BSS");
1564 int_array_add_unique(&wpa_s->owe_trans_scan_freq,
1565 bss->freq);
1566 return false;
1567 }
1568#endif /* CONFIG_OWE */
Hai Shalom899fcc72020-10-19 14:38:18 -07001569 if (debug_print)
1570 wpa_dbg(wpa_s, MSG_DEBUG,
1571 " skip - no SSID known for the BSS");
1572 return false;
1573 }
1574
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001575 if (!wpas_valid_ml_bss(wpa_s, bss)) {
1576 if (debug_print)
1577 wpa_dbg(wpa_s, MSG_DEBUG,
1578 " skip - ML BSS going to be removed");
1579 return false;
1580 }
1581
Hai Shalom899fcc72020-10-19 14:38:18 -07001582 /* Matching configuration found */
1583 return true;
1584}
1585
1586
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001587struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1588 int i, struct wpa_bss *bss,
1589 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001590 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001591{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001592 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001593 const u8 *ie;
1594 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001595 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001596 const u8 *match_ssid;
1597 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001598 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001599
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001600 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001601 wpa_ie_len = ie ? ie[1] : 0;
1602
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001603 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001604 rsn_ie_len = ie ? ie[1] : 0;
1605
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001606 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1607 osen = ie != NULL;
1608
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001609 if (debug_print) {
1610 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1611 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1612 i, MAC2STR(bss->bssid),
1613 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1614 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1615 bss->freq,
1616 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1617 " wps" : "",
1618 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1619 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1620 ? " p2p" : "",
1621 osen ? " osen=1" : "");
1622 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623
Hai Shalom60840252021-02-19 19:02:11 -08001624 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1625 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001626 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001627 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001628 /*
1629 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001630 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001631 * should not be done with multiple enabled networks to
1632 * avoid getting forced to move into a worse ESS on
1633 * single error if there are no other BSSes of the
1634 * current ESS.
1635 */
1636 limit = 0;
1637 }
Hai Shalom60840252021-02-19 19:02:11 -08001638 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001639 if (debug_print) {
1640 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001641 " skip - BSSID ignored (count=%d limit=%d)",
1642 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001643 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001644 return NULL;
1645 }
1646 }
1647
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001648 match_ssid = bss->ssid;
1649 match_ssid_len = bss->ssid_len;
1650 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1651
1652 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001653 if (debug_print)
1654 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655 return NULL;
1656 }
1657
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001658 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001659 if (debug_print)
1660 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001661 return NULL;
1662 }
1663
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001664 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001665 if (debug_print)
1666 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001667 return NULL;
1668 }
1669
Hai Shalomfdcde762020-04-02 11:19:20 -07001670 if (disabled_freq(wpa_s, bss->freq)) {
1671 if (debug_print)
1672 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1673 return NULL;
1674 }
1675
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001676 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001677 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001678 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001679 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680 }
1681
1682 /* No matching configuration found */
1683 return NULL;
1684}
1685
1686
1687static struct wpa_bss *
1688wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001689 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001690 struct wpa_ssid **selected_ssid,
1691 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001692{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001693 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001694
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001695 if (wpa_s->current_ssid) {
1696 struct wpa_ssid *ssid;
1697
1698 wpa_dbg(wpa_s, MSG_DEBUG,
1699 "Scan results matching the currently selected network");
1700 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1701 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1702
1703 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1704 only_first_ssid, 0);
1705 if (ssid != wpa_s->current_ssid)
1706 continue;
1707 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1708 " freq=%d level=%d snr=%d est_throughput=%u",
1709 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1710 bss->snr, bss->est_throughput);
1711 }
1712 }
1713
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001714 if (only_first_ssid)
1715 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1716 group->id);
1717 else
1718 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1719 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001720
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001721 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1722 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001723
1724 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001725 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001726 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001727 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001728 if (!*selected_ssid)
1729 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001730 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001731 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001732 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001733 MAC2STR(bss->bssid),
1734 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1735 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001736 }
1737
1738 return NULL;
1739}
1740
1741
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001742struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1743 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001744{
1745 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001746 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001747 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001748 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001749
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001750 if (wpa_s->last_scan_res == NULL ||
1751 wpa_s->last_scan_res_used == 0)
1752 return NULL; /* no scan results from last update */
1753
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001754 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001755 /* check that next_ssid is still valid */
1756 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1757 if (ssid == wpa_s->next_ssid)
1758 break;
1759 }
1760 next_ssid = ssid;
1761 wpa_s->next_ssid = NULL;
1762 }
1763
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001765 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1766 if (next_ssid && next_ssid->priority ==
1767 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001768 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001769 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001770 if (selected)
1771 break;
1772 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001773 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001774 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001775 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001776 if (selected)
1777 break;
1778 }
1779
Hai Shalom60840252021-02-19 19:02:11 -08001780 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001781 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001782 wpa_dbg(wpa_s, MSG_DEBUG,
1783 "No APs found - clear BSSID ignore list and try again");
1784 wpa_bssid_ignore_clear(wpa_s);
1785 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001786 } else if (selected == NULL)
1787 break;
1788 }
1789
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001790 ssid = *selected_ssid;
1791 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1792 !ssid->passphrase && !ssid->ext_psk) {
1793 const char *field_name, *txt = NULL;
1794
1795 wpa_dbg(wpa_s, MSG_DEBUG,
1796 "PSK/passphrase not yet available for the selected network");
1797
1798 wpas_notify_network_request(wpa_s, ssid,
1799 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1800
1801 field_name = wpa_supplicant_ctrl_req_to_string(
1802 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1803 if (field_name == NULL)
1804 return NULL;
1805
1806 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1807
1808 selected = NULL;
1809 }
1810
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001811 return selected;
1812}
1813
1814
1815static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1816 int timeout_sec, int timeout_usec)
1817{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001818 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001819 /*
1820 * No networks are enabled; short-circuit request so
1821 * we don't wait timeout seconds before transitioning
1822 * to INACTIVE state.
1823 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001824 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1825 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001826 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1827 return;
1828 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001829
1830 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001831 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1832}
1833
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001834
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001835static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s)
1836{
1837 if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss)
1838 return false;
1839
1840 wpa_msg(wpa_s, MSG_DEBUG,
1841 "Request association with " MACSTR " after ML probe",
1842 MAC2STR(wpa_s->ml_connect_probe_bss->bssid));
1843
1844 wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss,
1845 wpa_s->ml_connect_probe_ssid);
1846
1847 wpa_s->ml_connect_probe_ssid = NULL;
1848 wpa_s->ml_connect_probe_bss = NULL;
1849
1850 return true;
1851}
1852
1853
1854static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s,
1855 struct wpa_bss *selected,
1856 struct wpa_ssid *ssid)
1857{
1858 int *freqs;
1859 u16 missing_links = 0, removed_links;
1860
1861 if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
1862 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)))
1863 return 0;
1864
1865 /* Try to resolve any missing link information */
1866 if (wpa_bss_parse_basic_ml_element(wpa_s, selected, NULL,
1867 &missing_links) || !missing_links)
1868 return 0;
1869
1870 removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected);
1871 missing_links &= ~removed_links;
1872
1873 if (!missing_links)
1874 return 0;
1875
1876 wpa_dbg(wpa_s, MSG_DEBUG,
1877 "MLD: Doing an ML probe for missing links 0x%04x",
1878 missing_links);
1879
1880 freqs = os_malloc(sizeof(int) * 2);
1881 if (!freqs)
1882 return 0;
1883
1884 wpa_s->ml_connect_probe_ssid = ssid;
1885 wpa_s->ml_connect_probe_bss = selected;
1886
1887 freqs[0] = selected->freq;
1888 freqs[1] = 0;
1889
1890 wpa_s->manual_scan_passive = 0;
1891 wpa_s->manual_scan_use_id = 0;
1892 wpa_s->manual_scan_only_new = 0;
1893 wpa_s->scan_id_count = 0;
1894 os_free(wpa_s->manual_scan_freqs);
1895 wpa_s->manual_scan_freqs = freqs;
1896
1897 os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN);
1898 wpa_s->ml_probe_mld_id = -1;
1899 wpa_s->ml_probe_links = missing_links;
1900
1901 wpa_s->normal_scans = 0;
1902 wpa_s->scan_req = MANUAL_SCAN_REQ;
1903 wpa_s->after_wps = 0;
1904 wpa_s->known_wps_freq = 0;
1905 wpa_supplicant_req_scan(wpa_s, 0, 0);
1906
1907 return 1;
1908}
1909
1910
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001911int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001912 struct wpa_bss *selected,
1913 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001914{
Sunil Ravi640215c2023-06-28 23:08:09 +00001915#ifdef IEEE8021X_EAPOL
Sunil Ravi036cec52023-03-29 11:35:17 -07001916 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
1917 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00001918 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001919 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1920 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001921 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001922 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001923#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001924 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1925 wpa_s->p2p_in_provisioning) {
1926 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1927 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001928 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001929 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001930#endif /* CONFIG_P2P */
1931
1932#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001933 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001934 wpas_wps_cancel(wpa_s);
1935#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001936 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001937 }
Sunil Ravi640215c2023-06-28 23:08:09 +00001938#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001939
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001940 wpa_msg(wpa_s, MSG_DEBUG,
1941 "Considering connect request: reassociate: %d selected: "
1942 MACSTR " bssid: " MACSTR " pending: " MACSTR
1943 " wpa_state: %s ssid=%p current_ssid=%p",
1944 wpa_s->reassociate, MAC2STR(selected->bssid),
1945 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1946 wpa_supplicant_state_txt(wpa_s->wpa_state),
1947 ssid, wpa_s->current_ssid);
1948
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001949 /*
1950 * Do not trigger new association unless the BSSID has changed or if
1951 * reassociation is requested. If we are in process of associating with
1952 * the selected BSSID, do not trigger new attempt.
1953 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001954 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001955 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1956 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1957 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001958 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1959 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1960 0) ||
1961 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1962 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001963 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1964 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001965 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001966 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001967
1968 if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid))
1969 return 0;
1970
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001971 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1972 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001973 wpa_supplicant_associate(wpa_s, selected, ssid);
1974 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001975 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1976 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001977 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001978
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001979 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001980}
1981
1982
1983static struct wpa_ssid *
1984wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1985{
Hai Shalomfdcde762020-04-02 11:19:20 -07001986 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001987 struct wpa_ssid *ssid;
1988
1989 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1990 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1991 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001992 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001993 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001994#ifndef CONFIG_IBSS_RSN
1995 if (ssid->mode == WPAS_MODE_IBSS &&
1996 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1997 WPA_KEY_MGMT_WPA_NONE))) {
1998 wpa_msg(wpa_s, MSG_INFO,
1999 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
2000 wpa_ssid_txt(ssid->ssid,
2001 ssid->ssid_len));
2002 continue;
2003 }
2004#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07002005 if (ssid->mode == WPAS_MODE_IBSS ||
2006 ssid->mode == WPAS_MODE_AP ||
2007 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002008 return ssid;
2009 }
2010 }
2011 return NULL;
2012}
2013
2014
2015/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
2016 * on BSS added and BSS changed events */
2017static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03002018 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002019{
Jouni Malinen87fd2792011-05-16 18:35:42 +03002020 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002021
2022 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
2023 return;
2024
Jouni Malinen87fd2792011-05-16 18:35:42 +03002025 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002026 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002027
Jouni Malinen87fd2792011-05-16 18:35:42 +03002028 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002029 if (ssid == NULL)
2030 continue;
2031
Jouni Malinen87fd2792011-05-16 18:35:42 +03002032 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002033 if (rsn == NULL)
2034 continue;
2035
Jouni Malinen87fd2792011-05-16 18:35:42 +03002036 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002037 }
2038
2039}
2040
2041
Hai Shalomfdcde762020-04-02 11:19:20 -07002042#ifndef CONFIG_NO_ROAMING
2043
2044static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
2045{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002046 if (noise == WPA_INVALID_NOISE) {
2047 if (IS_5GHZ(frequency)) {
2048 noise = DEFAULT_NOISE_FLOOR_5GHZ;
2049 } else if (is_6ghz_freq(frequency)) {
2050 noise = DEFAULT_NOISE_FLOOR_6GHZ;
2051 } else {
2052 noise = DEFAULT_NOISE_FLOOR_2GHZ;
2053 }
2054 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002055 return avg_signal - noise;
2056}
2057
2058
2059static unsigned int
2060wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
2061 const struct wpa_bss *bss, int snr)
2062{
2063 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08002064 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07002065 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002066 enum chan_width max_cw = CHAN_WIDTH_UNKNOWN;
Hai Shalomfdcde762020-04-02 11:19:20 -07002067
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002068 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq,
2069 &max_cw);
Hai Shalomfdcde762020-04-02 11:19:20 -07002070}
2071
Hai Shalomfdcde762020-04-02 11:19:20 -07002072
Hai Shalom899fcc72020-10-19 14:38:18 -07002073int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
2074 struct wpa_bss *current_bss,
2075 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002076{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002077 int min_diff, diff;
Sunil Ravi036cec52023-03-29 11:35:17 -07002078 int to_5ghz, to_6ghz;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002079 int cur_level, sel_level;
Hai Shalomfdcde762020-04-02 11:19:20 -07002080 unsigned int cur_est, sel_est;
2081 struct wpa_signal_info si;
2082 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07002083 int ret = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002084 const u8 *cur_ies = wpa_bss_ie_ptr(current_bss);
2085 const u8 *sel_ies = wpa_bss_ie_ptr(selected);
2086 size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len :
2087 current_bss->beacon_ie_len;
2088 size_t sel_ie_len = selected->ie_len ? selected->ie_len :
2089 selected->beacon_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002090
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002091 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002092 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002093 " freq=%d level=%d snr=%d est_throughput=%u",
2094 MAC2STR(current_bss->bssid),
2095 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002096 current_bss->snr, current_bss->est_throughput);
2097 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002098 " freq=%d level=%d snr=%d est_throughput=%u",
2099 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002100 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002101
2102 if (wpa_s->current_ssid->bssid_set &&
2103 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
2104 0) {
2105 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2106 "has preferred BSSID");
2107 return 1;
2108 }
2109
Hai Shalomfdcde762020-04-02 11:19:20 -07002110 /*
2111 * Try to poll the signal from the driver since this will allow to get
2112 * more accurate values. In some cases, there can be big differences
2113 * between the RSSI of the Probe Response frames of the AP we are
2114 * associated with and the Beacon frames we hear from the same AP after
2115 * association. This can happen, e.g., when there are two antennas that
2116 * hear the AP very differently. If the driver chooses to hear the
2117 * Probe Response frames during the scan on the "bad" antenna because
2118 * it wants to save power, but knows to choose the other antenna after
2119 * association, we will hear our AP with a low RSSI as part of the
2120 * scan even when we can hear it decently on the other antenna. To cope
2121 * with this, ask the driver to teach us how it hears the AP. Also, the
2122 * scan results may be a bit old, since we can very quickly get fresh
2123 * information about our currently associated AP.
2124 */
2125 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002126 (si.data.avg_beacon_signal || si.data.avg_signal)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002127 /*
2128 * Normalize avg_signal to the RSSI over 20 MHz, as the
2129 * throughput is estimated based on the RSSI over 20 MHz
2130 */
Sunil Ravi77d572f2023-01-17 23:58:31 +00002131 cur_level = si.data.avg_beacon_signal ?
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002132 si.data.avg_beacon_signal :
2133 (si.data.avg_signal -
2134 wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2135 si.chanwidth));
Hai Shalomfdcde762020-04-02 11:19:20 -07002136 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2137 si.current_noise);
2138
2139 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2140 current_bss,
2141 cur_snr);
2142 wpa_dbg(wpa_s, MSG_DEBUG,
2143 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2144 cur_level, cur_snr, cur_est);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002145 } else {
2146 /* Level and SNR are measured over 20 MHz channel */
2147 cur_level = current_bss->level;
2148 cur_snr = current_bss->snr;
2149 cur_est = current_bss->est_throughput;
Hai Shalomfdcde762020-04-02 11:19:20 -07002150 }
2151
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002152 /* Adjust the SNR of BSSes based on the channel width. */
2153 cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2154 current_bss->max_cw);
2155 cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len,
2156 current_bss->max_cw, cur_snr);
2157
2158 sel_est = selected->est_throughput;
2159 sel_level = selected->level +
2160 wpas_channel_width_rssi_bump(sel_ies, sel_ie_len,
2161 selected->max_cw);
2162
Hai Shalomfdcde762020-04-02 11:19:20 -07002163 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002164 wpa_dbg(wpa_s, MSG_DEBUG,
2165 "Allow reassociation - selected BSS has better estimated throughput");
2166 return 1;
2167 }
2168
Dmitry Shmidte4663042016-04-04 10:07:49 -07002169 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
Sunil Ravi036cec52023-03-29 11:35:17 -07002170 to_6ghz = is_6ghz_freq(selected->freq) &&
2171 !is_6ghz_freq(current_bss->freq);
Dmitry Shmidte4663042016-04-04 10:07:49 -07002172
Sunil Ravi036cec52023-03-29 11:35:17 -07002173 if (cur_level < 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002174 cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002175 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002176 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2177 "signal level");
2178 return 0;
2179 }
2180
Hai Shalomfdcde762020-04-02 11:19:20 -07002181 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002182 wpa_dbg(wpa_s, MSG_DEBUG,
2183 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002184 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002185 }
2186
Hai Shalomfdcde762020-04-02 11:19:20 -07002187 if (cur_snr > GREAT_SNR) {
2188 wpa_dbg(wpa_s, MSG_DEBUG,
2189 "Skip roam - Current BSS has good SNR (%u > %u)",
2190 cur_snr, GREAT_SNR);
2191 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002192 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002193
Hai Shalomfdcde762020-04-02 11:19:20 -07002194 if (cur_level < -85) /* ..-86 dBm */
2195 min_diff = 1;
2196 else if (cur_level < -80) /* -85..-81 dBm */
2197 min_diff = 2;
2198 else if (cur_level < -75) /* -80..-76 dBm */
2199 min_diff = 3;
2200 else if (cur_level < -70) /* -75..-71 dBm */
2201 min_diff = 4;
2202 else if (cur_level < 0) /* -70..-1 dBm */
2203 min_diff = 5;
2204 else /* unspecified units (not in dBm) */
2205 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002206
Hai Shalomfdcde762020-04-02 11:19:20 -07002207 if (cur_est > sel_est * 1.5)
2208 min_diff += 10;
2209 else if (cur_est > sel_est * 1.2)
2210 min_diff += 5;
2211 else if (cur_est > sel_est * 1.1)
2212 min_diff += 2;
2213 else if (cur_est > sel_est)
2214 min_diff++;
2215 else if (sel_est > cur_est * 1.5)
2216 min_diff -= 10;
2217 else if (sel_est > cur_est * 1.2)
2218 min_diff -= 5;
2219 else if (sel_est > cur_est * 1.1)
2220 min_diff -= 2;
2221 else if (sel_est > cur_est)
2222 min_diff--;
2223
2224 if (to_5ghz)
2225 min_diff -= 2;
Sunil Ravi036cec52023-03-29 11:35:17 -07002226 if (to_6ghz)
2227 min_diff -= 2;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002228 diff = sel_level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002229 if (diff < min_diff) {
2230 wpa_dbg(wpa_s, MSG_DEBUG,
2231 "Skip roam - too small difference in signal level (%d < %d)",
2232 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002233 ret = 0;
2234 } else {
2235 wpa_dbg(wpa_s, MSG_DEBUG,
2236 "Allow reassociation due to difference in signal level (%d >= %d)",
2237 diff, min_diff);
2238 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002240 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2241 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2242 " sel_freq=%d sel_level=%d sel_est=%d",
2243 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2244 MAC2STR(current_bss->bssid),
2245 current_bss->freq, cur_level, cur_est,
2246 MAC2STR(selected->bssid),
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002247 selected->freq, sel_level, sel_est);
Hai Shalom899fcc72020-10-19 14:38:18 -07002248 return ret;
2249}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002250
Hai Shalom899fcc72020-10-19 14:38:18 -07002251#endif /* CONFIG_NO_ROAMING */
2252
2253
2254static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2255 struct wpa_bss *selected,
2256 struct wpa_ssid *ssid)
2257{
2258 struct wpa_bss *current_bss = NULL;
2259
2260 if (wpa_s->reassociate)
2261 return 1; /* explicit request to reassociate */
2262 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2263 return 1; /* we are not associated; continue */
2264 if (wpa_s->current_ssid == NULL)
2265 return 1; /* unknown current SSID */
2266 if (wpa_s->current_ssid != ssid)
2267 return 1; /* different network block */
2268
2269 if (wpas_driver_bss_selection(wpa_s))
2270 return 0; /* Driver-based roaming */
2271
2272 if (wpa_s->current_ssid->ssid)
2273 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2274 wpa_s->current_ssid->ssid,
2275 wpa_s->current_ssid->ssid_len);
2276 if (!current_bss)
2277 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2278
2279 if (!current_bss)
2280 return 1; /* current BSS not seen in scan results */
2281
2282 if (current_bss == selected)
2283 return 0;
2284
2285 if (selected->last_update_idx > current_bss->last_update_idx)
2286 return 1; /* current BSS not seen in the last scan */
2287
2288#ifndef CONFIG_NO_ROAMING
2289 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2290 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002291#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002292 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002293#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002294}
2295
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002296
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002297/*
2298 * Return a negative value if no scan results could be fetched or if scan
2299 * results should not be shared with other virtual interfaces.
2300 * Return 0 if scan results were fetched and may be shared with other
2301 * interfaces.
2302 * Return 1 if scan results may be shared with other virtual interfaces but may
2303 * not trigger any operations.
2304 * Return 2 if the interface was removed and cannot be used.
2305 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002306static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002307 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002308 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002309{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002310 struct wpa_scan_results *scan_res = NULL;
2311 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002312 int ap = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002313 bool trigger_6ghz_scan;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002314#ifndef CONFIG_NO_RANDOM_POOL
2315 size_t i, num;
2316#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002317
2318#ifdef CONFIG_AP
2319 if (wpa_s->ap_iface)
2320 ap = 1;
2321#endif /* CONFIG_AP */
2322
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002323 trigger_6ghz_scan = wpa_s->crossed_6ghz_dom &&
2324 wpa_s->last_scan_all_chan;
2325 wpa_s->crossed_6ghz_dom = false;
2326 wpa_s->last_scan_all_chan = false;
2327
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002328 wpa_supplicant_notify_scanning(wpa_s, 0);
2329
2330 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2331 data ? &data->scan_info :
2332 NULL, 1);
2333 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002334 if (wpa_s->conf->ap_scan == 2 || ap ||
2335 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002336 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002337 if (!own_request)
2338 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002339 if (data && data->scan_info.external_scan)
2340 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002341 if (wpa_s->scan_res_fail_handler) {
2342 void (*handler)(struct wpa_supplicant *wpa_s);
2343
2344 handler = wpa_s->scan_res_fail_handler;
2345 wpa_s->scan_res_fail_handler = NULL;
2346 handler(wpa_s);
2347 } else {
2348 wpa_dbg(wpa_s, MSG_DEBUG,
2349 "Failed to get scan results - try scanning again");
2350 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2351 }
2352
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002353 ret = -1;
2354 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002355 }
2356
2357#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002358 num = scan_res->num;
2359 if (num > 10)
2360 num = 10;
2361 for (i = 0; i < num; i++) {
2362 u8 buf[5];
2363 struct wpa_scan_res *res = scan_res->res[i];
2364 buf[0] = res->bssid[5];
2365 buf[1] = res->qual & 0xff;
2366 buf[2] = res->noise & 0xff;
2367 buf[3] = res->level & 0xff;
2368 buf[4] = res->tsf & 0xff;
2369 random_add_randomness(buf, sizeof(buf));
2370 }
2371#endif /* CONFIG_NO_RANDOM_POOL */
2372
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002373 if (update_only) {
2374 ret = 1;
2375 goto scan_work_done;
2376 }
2377
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002378 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002379 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002380 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2381 struct wpa_scan_results *scan_res);
2382
2383 scan_res_handler = wpa_s->scan_res_handler;
2384 wpa_s->scan_res_handler = NULL;
2385 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002386 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002387 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002388 }
2389
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002390 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002391 wpa_s->own_scan_running,
2392 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002393 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002394 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2395 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002396 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2397 wpa_s->manual_scan_id);
2398 wpa_s->manual_scan_use_id = 0;
2399 } else {
2400 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2401 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002402 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002403
2404 wpas_notify_scan_done(wpa_s, 1);
2405
Hai Shalomfdcde762020-04-02 11:19:20 -07002406 if (ap) {
2407 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2408#ifdef CONFIG_AP
2409 if (wpa_s->ap_iface->scan_cb)
2410 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2411#endif /* CONFIG_AP */
2412 goto scan_work_done;
2413 }
2414
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002415 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002416 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 -07002417 wpa_scan_results_free(scan_res);
2418 return 0;
2419 }
2420
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002421 if (wnm_scan_process(wpa_s, 1) > 0)
2422 goto scan_work_done;
2423
Hai Shalomc1a21442022-02-04 13:43:00 -08002424 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002425 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002426
Hai Shalom021b0b52019-04-10 11:17:58 -07002427 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002428 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2429 goto scan_work_done;
2430
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002431 if (ml_link_probe_scan(wpa_s))
2432 goto scan_work_done;
2433
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002434 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2435 goto scan_work_done;
2436
2437 if (autoscan_notify_scan(wpa_s, scan_res))
2438 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002439
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002440 if (wpa_s->disconnected) {
2441 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002442 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002443 }
2444
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002445 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002446 bgscan_notify_scan(wpa_s, scan_res) == 1)
2447 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002448
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002449 wpas_wps_update_ap_info(wpa_s, scan_res);
2450
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002451 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2452 wpa_s->wpa_state < WPA_COMPLETED)
2453 goto scan_work_done;
2454
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002455 wpa_scan_results_free(scan_res);
2456
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002457 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002458 struct wpa_radio_work *work = wpa_s->scan_work;
2459 wpa_s->scan_work = NULL;
2460 radio_work_done(work);
2461 }
2462
Hai Shalomc3565922019-10-28 11:58:20 -07002463 os_free(wpa_s->last_scan_freqs);
2464 wpa_s->last_scan_freqs = NULL;
2465 wpa_s->num_last_scan_freqs = 0;
2466 if (own_request && data &&
2467 data->scan_info.freqs && data->scan_info.num_freqs) {
2468 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2469 data->scan_info.num_freqs);
2470 if (wpa_s->last_scan_freqs) {
2471 os_memcpy(wpa_s->last_scan_freqs,
2472 data->scan_info.freqs,
2473 sizeof(int) * data->scan_info.num_freqs);
2474 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2475 }
2476 }
2477
Sunil Ravi77d572f2023-01-17 23:58:31 +00002478 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2479 return ret;
2480
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002481 return wpas_select_network_from_last_scan(wpa_s, 1, own_request,
2482 trigger_6ghz_scan, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002483
2484scan_work_done:
2485 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002486 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002487 struct wpa_radio_work *work = wpa_s->scan_work;
2488 wpa_s->scan_work = NULL;
2489 radio_work_done(work);
2490 }
2491 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002492}
2493
2494
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002495static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s,
2496 union wpa_event_data *data)
2497{
2498 struct wpa_driver_scan_params params;
2499 unsigned int j;
2500
2501 wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan");
2502 os_memset(&params, 0, sizeof(params));
2503 params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz;
2504 for (j = 0; j < data->scan_info.num_ssids; j++)
2505 params.ssids[j] = data->scan_info.ssids[j];
2506 params.num_ssids = data->scan_info.num_ssids;
2507 wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
2508 true, !wpa_s->last_scan_non_coloc_6ghz, false);
2509 if (!wpa_supplicant_trigger_scan(wpa_s, &params, true, true)) {
2510 os_free(params.freqs);
2511 return 1;
2512 }
2513 wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan");
2514 os_free(params.freqs);
2515 return 0;
2516}
2517
2518
2519/**
2520 * Select a network from the last scan
2521 * @wpa_s: Pointer to wpa_supplicant data
2522 * @new_scan: Whether this function was called right after a scan has finished
2523 * @own_request: Whether the scan was requested by this interface
2524 * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable
2525 * @data: Scan data from scan that finished if applicable
2526 *
2527 * See _wpa_supplicant_event_scan_results() for return values.
2528 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002529static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002530 int new_scan, int own_request,
2531 bool trigger_6ghz_scan,
2532 union wpa_event_data *data)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002533{
2534 struct wpa_bss *selected;
2535 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002536 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2537
2538 if (time_to_reenable > 0) {
2539 wpa_dbg(wpa_s, MSG_DEBUG,
2540 "Postpone network selection by %d seconds since all networks are disabled",
2541 time_to_reenable);
2542 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2543 eloop_register_timeout(time_to_reenable, 0,
2544 wpas_network_reenabled, wpa_s, NULL);
2545 return 0;
2546 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002547
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002548 if (wpa_s->p2p_mgmt)
2549 return 0; /* no normal connection on p2p_mgmt interface */
2550
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002551 wpa_s->owe_transition_search = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002552#ifdef CONFIG_OWE
2553 os_free(wpa_s->owe_trans_scan_freq);
2554 wpa_s->owe_trans_scan_freq = NULL;
2555#endif /* CONFIG_OWE */
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002556 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002557
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002558#ifdef CONFIG_MESH
2559 if (wpa_s->ifmsh) {
2560 wpa_msg(wpa_s, MSG_INFO,
2561 "Avoiding join because we already joined a mesh group");
2562 return 0;
2563 }
2564#endif /* CONFIG_MESH */
2565
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002566 if (selected) {
2567 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002568 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002569 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002570 if (new_scan)
2571 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002572 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002573 }
2574
Hai Shalomc3565922019-10-28 11:58:20 -07002575 wpa_s->suitable_network++;
2576
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002577 if (ssid != wpa_s->current_ssid &&
2578 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2579 wpa_s->own_disconnect_req = 1;
2580 wpa_supplicant_deauthenticate(
2581 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2582 }
2583
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002584 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002585 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002586 return -1;
2587 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002588 wpa_s->supp_pbc_active = false;
2589
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002590 if (new_scan)
2591 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002592 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002593 * Do not allow other virtual radios to trigger operations based
2594 * on these scan results since we do not want them to start
2595 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002596 */
2597 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002598 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002599 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002600 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2601 ssid = wpa_supplicant_pick_new_network(wpa_s);
2602 if (ssid) {
2603 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2604 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002605 if (new_scan)
2606 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002607 } else if (own_request) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002608 if (wpa_s->support_6ghz && trigger_6ghz_scan && data &&
2609 wpas_trigger_6ghz_scan(wpa_s, data) < 0)
2610 return 1;
2611
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002612 /*
2613 * No SSID found. If SCAN results are as a result of
2614 * own scan request and not due to a scan request on
2615 * another shared interface, try another scan.
2616 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002617 int timeout_sec = wpa_s->scan_interval;
2618 int timeout_usec = 0;
2619#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002620 int res;
2621
2622 res = wpas_p2p_scan_no_go_seen(wpa_s);
2623 if (res == 2)
2624 return 2;
2625 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002626 return 0;
2627
Sunil Ravi77d572f2023-01-17 23:58:31 +00002628 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002629 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002630
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002631 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002632 wpa_s->show_group_started ||
2633 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002634 /*
2635 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002636 * state and during P2P join-a-group operation
2637 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002638 */
2639 timeout_sec = 0;
2640 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002641 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2642 timeout_usec);
2643 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002644 }
2645#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002646#ifdef CONFIG_INTERWORKING
2647 if (wpa_s->conf->auto_interworking &&
2648 wpa_s->conf->interworking &&
2649 wpa_s->conf->cred) {
2650 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2651 "start ANQP fetch since no matching "
2652 "networks found");
2653 wpa_s->network_select = 1;
2654 wpa_s->auto_network_select = 1;
2655 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002656 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002657 }
2658#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002659#ifdef CONFIG_WPS
2660 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2661 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2662 timeout_sec = 0;
2663 timeout_usec = 500000;
2664 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2665 timeout_usec);
2666 return 0;
2667 }
2668#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002669#ifdef CONFIG_OWE
2670 if (wpa_s->owe_transition_search) {
2671 wpa_dbg(wpa_s, MSG_DEBUG,
2672 "OWE: Use shorter wait during transition mode search");
2673 timeout_sec = 0;
2674 timeout_usec = 500000;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002675 if (wpa_s->owe_trans_scan_freq) {
2676 os_free(wpa_s->next_scan_freqs);
2677 wpa_s->next_scan_freqs =
2678 wpa_s->owe_trans_scan_freq;
2679 wpa_s->owe_trans_scan_freq = NULL;
2680 timeout_usec = 100000;
2681 }
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002682 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2683 timeout_usec);
2684 return 0;
2685 }
2686#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002687 if (wpa_supplicant_req_sched_scan(wpa_s))
2688 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2689 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002690
2691 wpa_msg_ctrl(wpa_s, MSG_INFO,
2692 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002693 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002694 }
2695 }
2696 return 0;
2697}
2698
2699
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002700static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2701 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002702{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002703 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002704 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002705
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002706 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002707 if (res == 2) {
2708 /*
2709 * Interface may have been removed, so must not dereference
2710 * wpa_s after this.
2711 */
2712 return 1;
2713 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002714
2715 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002716 /*
2717 * If no scan results could be fetched, then no need to
2718 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002719 * this scan. Similarly, if scan results started a new operation on this
2720 * interface, do not notify other interfaces to avoid concurrent
2721 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002722 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002723 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002724 }
2725
2726 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002727 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002728 * so, they get updated with this same scan info.
2729 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002730 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2731 radio_list) {
2732 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2734 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002735 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2736 res > 0);
2737 if (res < 0)
2738 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002739 }
2740 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002741
2742 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002743}
2744
2745#endif /* CONFIG_NO_SCAN_PROCESSING */
2746
2747
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002748int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2749{
2750#ifdef CONFIG_NO_SCAN_PROCESSING
2751 return -1;
2752#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002753 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002754
Dmitry Shmidt29333592017-01-09 12:27:11 -08002755 wpa_s->ignore_post_flush_scan_res = 0;
2756
Dmitry Shmidt41712582015-06-29 11:02:15 -07002757 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002758 return -1;
2759
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002760 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002761 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002762 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002763 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2764 return -1;
2765 }
2766
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002767 return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002768#endif /* CONFIG_NO_SCAN_PROCESSING */
2769}
2770
Sunil Ravi77d572f2023-01-17 23:58:31 +00002771
2772int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2773{
2774#ifdef CONFIG_NO_SCAN_PROCESSING
2775 return -1;
2776#else /* CONFIG_NO_SCAN_PROCESSING */
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002777 return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002778#endif /* CONFIG_NO_SCAN_PROCESSING */
2779}
2780
2781
Dmitry Shmidt04949592012-07-19 12:16:46 -07002782#ifdef CONFIG_WNM
2783
2784static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2785{
2786 struct wpa_supplicant *wpa_s = eloop_ctx;
2787
2788 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2789 return;
2790
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002791 if (!wpa_s->no_keep_alive) {
2792 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2793 MAC2STR(wpa_s->bssid));
2794 /* TODO: could skip this if normal data traffic has been sent */
2795 /* TODO: Consider using some more appropriate data frame for
2796 * this */
2797 if (wpa_s->l2)
2798 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2799 (u8 *) "", 0);
2800 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002801
2802#ifdef CONFIG_SME
2803 if (wpa_s->sme.bss_max_idle_period) {
2804 unsigned int msec;
2805 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2806 if (msec > 100)
2807 msec -= 100;
2808 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2809 wnm_bss_keep_alive, wpa_s, NULL);
2810 }
2811#endif /* CONFIG_SME */
2812}
2813
2814
2815static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2816 const u8 *ies, size_t ies_len)
2817{
2818 struct ieee802_11_elems elems;
2819
2820 if (ies == NULL)
2821 return;
2822
2823 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2824 return;
2825
2826#ifdef CONFIG_SME
2827 if (elems.bss_max_idle_period) {
2828 unsigned int msec;
2829 wpa_s->sme.bss_max_idle_period =
2830 WPA_GET_LE16(elems.bss_max_idle_period);
2831 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2832 "TU)%s", wpa_s->sme.bss_max_idle_period,
2833 (elems.bss_max_idle_period[2] & 0x01) ?
2834 " (protected keep-live required)" : "");
2835 if (wpa_s->sme.bss_max_idle_period == 0)
2836 wpa_s->sme.bss_max_idle_period = 1;
2837 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2838 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2839 /* msec times 1000 */
2840 msec = wpa_s->sme.bss_max_idle_period * 1024;
2841 if (msec > 100)
2842 msec -= 100;
2843 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2844 wnm_bss_keep_alive, wpa_s,
2845 NULL);
2846 }
2847 }
2848#endif /* CONFIG_SME */
2849}
2850
2851#endif /* CONFIG_WNM */
2852
2853
2854void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2855{
2856#ifdef CONFIG_WNM
2857 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2858#endif /* CONFIG_WNM */
2859}
2860
2861
Dmitry Shmidt051af732013-10-22 13:52:46 -07002862#ifdef CONFIG_INTERWORKING
2863
2864static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2865 size_t len)
2866{
2867 int res;
2868
2869 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2870 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2871 if (res) {
2872 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2873 }
2874
2875 return res;
2876}
2877
2878
2879static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2880 const u8 *ies, size_t ies_len)
2881{
2882 struct ieee802_11_elems elems;
2883
2884 if (ies == NULL)
2885 return;
2886
2887 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2888 return;
2889
2890 if (elems.qos_map_set) {
2891 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2892 elems.qos_map_set_len);
2893 }
2894}
2895
2896#endif /* CONFIG_INTERWORKING */
2897
2898
Sunil Ravi036cec52023-03-29 11:35:17 -07002899static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
2900{
2901 if (wpa_s->enabled_4addr_mode) {
2902 wpa_printf(MSG_DEBUG, "4addr mode already set");
2903 return;
2904 }
2905
2906 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2907 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
2908 goto fail;
2909 }
2910 wpa_s->enabled_4addr_mode = 1;
2911 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
2912 return;
2913
2914fail:
2915 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2916}
2917
2918
Hai Shalom74f70d42019-02-11 14:42:39 -08002919static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2920 const u8 *ies, size_t ies_len)
2921{
2922 struct ieee802_11_elems elems;
2923 const u8 *map_sub_elem, *pos;
2924 size_t len;
2925
Hai Shalomfdcde762020-04-02 11:19:20 -07002926 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002927
Hai Shalomfdcde762020-04-02 11:19:20 -07002928 if (!ies ||
2929 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2930 !elems.multi_ap || elems.multi_ap_len < 7)
2931 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002932
2933 pos = elems.multi_ap + 4;
2934 len = elems.multi_ap_len - 4;
2935
2936 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002937 if (!map_sub_elem || map_sub_elem[1] < 1)
2938 return;
2939
2940 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2941 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2942 MULTI_AP_FRONTHAUL_BSS);
2943 wpa_s->multi_ap_ie = 1;
2944}
2945
2946
2947static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2948{
2949 if (!wpa_s->current_ssid ||
2950 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2951 return;
2952
2953 if (!wpa_s->multi_ap_ie) {
2954 wpa_printf(MSG_INFO,
2955 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002956 goto fail;
2957 }
2958
Hai Shalomfdcde762020-04-02 11:19:20 -07002959 if (!wpa_s->multi_ap_backhaul) {
2960 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002961 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2962 wpa_printf(MSG_INFO,
2963 "WPS active, accepting fronthaul-only BSS");
2964 /* Don't set 4addr mode in this case, so just return */
2965 return;
2966 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002967 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2968 goto fail;
2969 }
2970
Sunil Ravi036cec52023-03-29 11:35:17 -07002971 wpa_supplicant_set_4addr_mode(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08002972 return;
2973
2974fail:
2975 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2976}
2977
2978
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002979#ifdef CONFIG_FST
2980static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2981 const u8 *ie, size_t ie_len)
2982{
2983 struct mb_ies_info mb_ies;
2984
2985 if (!ie || !ie_len || !wpa_s->fst)
2986 return -ENOENT;
2987
2988 os_memset(&mb_ies, 0, sizeof(mb_ies));
2989
2990 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2991 size_t len;
2992
2993 len = 2 + ie[1];
2994 if (len > ie_len) {
2995 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2996 ie, ie_len);
2997 break;
2998 }
2999
3000 if (ie[0] == WLAN_EID_MULTI_BAND) {
3001 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
3002 (unsigned int) len);
3003 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
3004 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
3005 mb_ies.nof_ies++;
3006 }
3007
3008 ie_len -= len;
3009 ie += len;
3010 }
3011
3012 if (mb_ies.nof_ies > 0) {
3013 wpabuf_free(wpa_s->received_mb_ies);
3014 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
3015 return 0;
3016 }
3017
3018 return -ENOENT;
3019}
3020#endif /* CONFIG_FST */
3021
3022
Hai Shalomc1a21442022-02-04 13:43:00 -08003023static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
3024 union wpa_event_data *data)
3025{
3026 int sel;
3027 const u8 *p;
3028 int l, len;
3029 bool found = false;
3030 struct wpa_ie_data ie;
3031 struct wpa_ssid *ssid = wpa_s->current_ssid;
3032 struct wpa_bss *bss = wpa_s->current_bss;
3033 int pmf;
3034
3035 if (!ssid)
3036 return 0;
3037
3038 p = data->assoc_info.req_ies;
3039 l = data->assoc_info.req_ies_len;
3040
3041 while (p && l >= 2) {
3042 len = p[1] + 2;
3043 if (len > l) {
3044 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3045 p, l);
3046 break;
3047 }
3048 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3049 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3050 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3051 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3052 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3053 found = true;
3054 break;
3055 }
3056 l -= len;
3057 p += len;
3058 }
3059
Sunil Ravi036cec52023-03-29 11:35:17 -07003060 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
3061 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
Hai Shalomc1a21442022-02-04 13:43:00 -08003062 return 0;
Sunil Ravi036cec52023-03-29 11:35:17 -07003063 }
Hai Shalomc1a21442022-02-04 13:43:00 -08003064
3065 wpa_hexdump(MSG_DEBUG,
3066 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
3067 p, l);
3068
3069 /* Update proto from (Re)Association Request frame info */
3070 wpa_s->wpa_proto = ie.proto;
3071 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
3072 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
3073 !!(wpa_s->wpa_proto &
3074 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
3075
3076 /* Update AKMP suite from (Re)Association Request frame info */
3077 sel = ie.key_mgmt;
3078 if (ssid->key_mgmt)
3079 sel &= ssid->key_mgmt;
3080
3081 wpa_dbg(wpa_s, MSG_DEBUG,
3082 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
3083 ie.key_mgmt, ssid->key_mgmt, sel);
3084 if (ie.key_mgmt && !sel) {
3085 wpa_supplicant_deauthenticate(
3086 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
3087 return -1;
3088 }
3089
Sunil Ravi036cec52023-03-29 11:35:17 -07003090#ifdef CONFIG_OCV
3091 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
3092 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
3093 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
3094 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
3095#endif /* CONFIG_OCV */
3096
Sunil Ravi89eba102022-09-13 21:04:37 -07003097 /*
3098 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
3099 * different AKM.
3100 */
3101 if (wpa_s->key_mgmt != ie.key_mgmt &&
3102 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
3103 if (!ssid->psk_set) {
3104 wpa_dbg(wpa_s, MSG_INFO,
3105 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00003106 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07003107 return -1;
3108 }
3109
3110 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
3111 if (wpa_s->conf->key_mgmt_offload &&
3112 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003113 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
3114 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07003115 wpa_dbg(wpa_s, MSG_ERROR,
3116 "WPA: Cannot set PMK for key management offload");
3117 }
3118
Hai Shalomc1a21442022-02-04 13:43:00 -08003119 wpa_s->key_mgmt = ie.key_mgmt;
3120 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3121 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
3122 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
3123 wpa_s->wpa_proto);
3124
3125 /* Update pairwise cipher from (Re)Association Request frame info */
3126 sel = ie.pairwise_cipher;
3127 if (ssid->pairwise_cipher)
3128 sel &= ssid->pairwise_cipher;
3129
3130 wpa_dbg(wpa_s, MSG_DEBUG,
3131 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
3132 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
3133 if (ie.pairwise_cipher && !sel) {
3134 wpa_supplicant_deauthenticate(
3135 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
3136 return -1;
3137 }
3138
3139 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3140 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3141 wpa_s->pairwise_cipher);
3142 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
3143 wpa_cipher_txt(wpa_s->pairwise_cipher));
3144
3145 /* Update other parameters based on AP's WPA IE/RSNE, if available */
3146 if (!bss) {
3147 wpa_dbg(wpa_s, MSG_DEBUG,
3148 "WPA: current_bss == NULL - skip AP IE check");
3149 return 0;
3150 }
3151
3152 /* Update GTK and IGTK from AP's RSNE */
3153 found = false;
3154
3155 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
3156 const u8 *bss_rsn;
3157
3158 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3159 if (bss_rsn) {
3160 p = bss_rsn;
3161 len = 2 + bss_rsn[1];
3162 found = true;
3163 }
3164 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
3165 const u8 *bss_wpa;
3166
3167 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3168 if (bss_wpa) {
3169 p = bss_wpa;
3170 len = 2 + bss_wpa[1];
3171 found = true;
3172 }
3173 }
3174
3175 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
3176 return 0;
3177
3178 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
3179 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3180 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3181 /* AP does not support MFP, local configuration requires it */
3182 wpa_supplicant_deauthenticate(
3183 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3184 return -1;
3185 }
3186 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3187 pmf == NO_MGMT_FRAME_PROTECTION) {
3188 /* AP requires MFP, local configuration disables it */
3189 wpa_supplicant_deauthenticate(
3190 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3191 return -1;
3192 }
3193
3194 /* Update PMF from local configuration now that MFP validation was done
3195 * above */
3196 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3197
3198 /* Update GTK from AP's RSNE */
3199 sel = ie.group_cipher;
3200 if (ssid->group_cipher)
3201 sel &= ssid->group_cipher;
3202
3203 wpa_dbg(wpa_s, MSG_DEBUG,
3204 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3205 ie.group_cipher, ssid->group_cipher, sel);
3206 if (ie.group_cipher && !sel) {
3207 wpa_supplicant_deauthenticate(
3208 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3209 return -1;
3210 }
3211
3212 wpa_s->group_cipher = ie.group_cipher;
3213 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3214 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3215 wpa_cipher_txt(wpa_s->group_cipher));
3216
3217 /* Update IGTK from AP RSN IE */
3218 sel = ie.mgmt_group_cipher;
3219 if (ssid->group_mgmt_cipher)
3220 sel &= ssid->group_mgmt_cipher;
3221
3222 wpa_dbg(wpa_s, MSG_DEBUG,
3223 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3224 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3225
3226 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3227 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3228 wpa_dbg(wpa_s, MSG_DEBUG,
3229 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3230 ie.capabilities);
3231 ie.mgmt_group_cipher = 0;
3232 }
3233
3234 if (ie.mgmt_group_cipher && !sel) {
3235 wpa_supplicant_deauthenticate(
3236 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3237 return -1;
3238 }
3239
3240 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3241 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3242 wpa_s->mgmt_group_cipher);
3243 if (wpa_s->mgmt_group_cipher)
3244 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3245 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3246 else
3247 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3248
3249 return 0;
3250}
3251
3252
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003253static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3254 union wpa_event_data *data)
3255{
Hai Shalomc3565922019-10-28 11:58:20 -07003256 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003257 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003258 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003259 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003260#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303261 struct wpa_ie_data ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003262#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003263
3264 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07003265 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003266 if (data->assoc_info.req_ies)
3267 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3268 data->assoc_info.req_ies_len);
3269 if (data->assoc_info.resp_ies) {
3270 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3271 data->assoc_info.resp_ies_len);
3272#ifdef CONFIG_TDLS
3273 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3274 data->assoc_info.resp_ies_len);
3275#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003276#ifdef CONFIG_WNM
3277 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3278 data->assoc_info.resp_ies_len);
3279#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003280#ifdef CONFIG_INTERWORKING
3281 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3282 data->assoc_info.resp_ies_len);
3283#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003284 if (wpa_s->hw_capab == CAPAB_VHT &&
3285 get_ie(data->assoc_info.resp_ies,
3286 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3287 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003288
3289 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3290 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003291 }
3292 if (data->assoc_info.beacon_ies)
3293 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3294 data->assoc_info.beacon_ies,
3295 data->assoc_info.beacon_ies_len);
3296 if (data->assoc_info.freq)
3297 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3298 data->assoc_info.freq);
3299
Hai Shalom021b0b52019-04-10 11:17:58 -07003300 wpa_s->connection_set = 0;
3301 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3302 struct ieee802_11_elems req_elems, resp_elems;
3303
3304 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3305 data->assoc_info.req_ies_len,
3306 &req_elems, 0) != ParseFailed &&
3307 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3308 data->assoc_info.resp_ies_len,
3309 &resp_elems, 0) != ParseFailed) {
3310 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003311 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3312 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003313 wpa_s->connection_ht = req_elems.ht_capabilities &&
3314 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003315 /* Do not include subset of VHT on 2.4 GHz vendor
3316 * extension in consideration for reporting VHT
3317 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003318 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003319 resp_elems.vht_capabilities &&
3320 (!data->assoc_info.freq ||
3321 wpas_freq_to_band(data->assoc_info.freq) !=
3322 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003323 wpa_s->connection_he = req_elems.he_capabilities &&
3324 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003325 wpa_s->connection_eht = req_elems.eht_capabilities &&
3326 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003327
3328 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3329 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3330 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3331 max_nss_rx_req : max_nss_rx_resp;
3332 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3333 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3334 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3335 max_nss_tx_req : max_nss_tx_resp;
3336
3337 struct supported_chan_width sta_supported_chan_width =
3338 get_supported_channel_width(&req_elems);
3339 enum chan_width ap_operation_chan_width =
3340 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303341 if (wpa_s->connection_vht || wpa_s->connection_he ||
3342 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003343 wpa_s->connection_channel_bandwidth =
3344 get_sta_operation_chan_width(ap_operation_chan_width,
3345 sta_supported_chan_width);
3346 } else if (wpa_s->connection_ht) {
3347 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3348 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3349 } else {
3350 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3351 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003352 if (req_elems.rrm_enabled)
3353 wpa_s->rrm.rrm_used = 1;
Ainy Kumari322d4fd2024-02-14 13:05:40 +05303354 wpa_s->ap_t2lm_negotiation_support =
3355 is_ap_t2lm_negotiation_supported(resp_elems.basic_mle,
3356 resp_elems.basic_mle_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07003357 }
3358 }
3359
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003360 p = data->assoc_info.req_ies;
3361 l = data->assoc_info.req_ies_len;
3362
3363 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3364 while (p && l >= 2) {
3365 len = p[1] + 2;
3366 if (len > l) {
3367 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3368 p, l);
3369 break;
3370 }
Hai Shalomc3565922019-10-28 11:58:20 -07003371 if (!found &&
3372 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3373 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3374 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3375 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3376 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003377 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3378 break;
3379 found = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07003380 wpa_find_assoc_pmkid(wpa_s,
3381 data->assoc_info.authorized);
Hai Shalomc3565922019-10-28 11:58:20 -07003382 }
3383 if (!found_x && p[0] == WLAN_EID_RSNX) {
3384 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3385 break;
3386 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003387 }
3388 l -= len;
3389 p += len;
3390 }
3391 if (!found && data->assoc_info.req_ies)
3392 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003393 if (!found_x && data->assoc_info.req_ies)
3394 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003395
Winnie Chen4138eec2022-11-10 16:32:53 +08003396#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303397 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3398 * to a different security type, update the current supplicant configuration to use the AKM
3399 * and pairwise suites from the assoc IE passed by the driver.
3400 */
3401 if (wpas_driver_bss_selection(wpa_s)) {
3402 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3403 /* Check if firmware has roamed to a different security network */
3404 if(wpa_s->key_mgmt != ie.key_mgmt) {
3405 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3406 ie.key_mgmt);
3407 wpa_s->key_mgmt = ie.key_mgmt;
3408 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3409
3410 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3411 /* Restore PMK as it can get overwritten if the previous
3412 * association was to 802.1X.
3413 */
3414 if ((!(wpa_s->drv_flags &
3415 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3416 (wpa_s->current_ssid) &&
3417 (wpa_s->current_ssid->psk_set)) {
3418 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3419 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3420 "BSSID");
3421 wpa_supplicant_deauthenticate(
3422 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3423 return -1;
3424 }
3425 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3426 PMK_LEN, NULL, bssid);
3427 }
3428 }
3429 }
3430 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3431 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3432 "from Assoc IE", ie.pairwise_cipher);
3433 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3434 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3435 wpa_s->pairwise_cipher);
3436 }
3437 // TODO: Notify the framework about security type change b/230766005
3438 }
3439 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003440#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303441
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003442#ifdef CONFIG_FILS
3443#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003444 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3445 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003446 (!data->assoc_info.resp_frame ||
3447 fils_process_assoc_resp(wpa_s->wpa,
3448 data->assoc_info.resp_frame,
3449 data->assoc_info.resp_frame_len) < 0)) {
3450 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3451 return -1;
3452 }
3453#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003454
3455 /* Additional processing for FILS when SME is in driver */
3456 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3457 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3458 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003459#endif /* CONFIG_FILS */
3460
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003461#ifdef CONFIG_OWE
3462 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003463 !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003464 (!bssid_known ||
Sunil Ravi036cec52023-03-29 11:35:17 -07003465 owe_process_assoc_resp(wpa_s->wpa,
3466 wpa_s->valid_links ?
3467 wpa_s->ap_mld_addr : bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003468 data->assoc_info.resp_ies,
3469 data->assoc_info.resp_ies_len) < 0)) {
3470 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3471 return -1;
3472 }
3473#endif /* CONFIG_OWE */
3474
Hai Shalom021b0b52019-04-10 11:17:58 -07003475#ifdef CONFIG_DPP2
3476 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003477 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3478 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003479 struct ieee802_11_elems elems;
3480
3481 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3482 data->assoc_info.resp_ies_len,
3483 &elems, 0) == ParseFailed ||
3484 !elems.owe_dh)
3485 goto no_pfs;
3486 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3487 elems.owe_dh_len) < 0) {
3488 wpa_supplicant_deauthenticate(wpa_s,
3489 WLAN_REASON_UNSPECIFIED);
3490 return -1;
3491 }
3492
3493 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3494 }
3495no_pfs:
3496#endif /* CONFIG_DPP2 */
3497
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003498#ifdef CONFIG_IEEE80211R
3499#ifdef CONFIG_SME
3500 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003501 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003502 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3503 data->assoc_info.resp_ies,
3504 data->assoc_info.resp_ies_len,
3505 bssid) < 0) {
3506 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3507 "Reassociation Response failed");
3508 wpa_supplicant_deauthenticate(
3509 wpa_s, WLAN_REASON_INVALID_IE);
3510 return -1;
3511 }
3512 }
3513
3514 p = data->assoc_info.resp_ies;
3515 l = data->assoc_info.resp_ies_len;
3516
3517#ifdef CONFIG_WPS_STRICT
3518 if (p && wpa_s->current_ssid &&
3519 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3520 struct wpabuf *wps;
3521 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3522 if (wps == NULL) {
3523 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3524 "include WPS IE in (Re)Association Response");
3525 return -1;
3526 }
3527
3528 if (wps_validate_assoc_resp(wps) < 0) {
3529 wpabuf_free(wps);
3530 wpa_supplicant_deauthenticate(
3531 wpa_s, WLAN_REASON_INVALID_IE);
3532 return -1;
3533 }
3534 wpabuf_free(wps);
3535 }
3536#endif /* CONFIG_WPS_STRICT */
3537
3538 /* Go through the IEs and make a copy of the MDIE, if present. */
3539 while (p && l >= 2) {
3540 len = p[1] + 2;
3541 if (len > l) {
3542 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3543 p, l);
3544 break;
3545 }
3546 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3547 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3548 wpa_s->sme.ft_used = 1;
3549 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3550 MOBILITY_DOMAIN_ID_LEN);
3551 break;
3552 }
3553 l -= len;
3554 p += len;
3555 }
3556#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003557#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303558 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3559 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3560 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3561 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303562 wpa_ft_is_completed(wpa_s->wpa)) {
3563 return 0;
3564 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003565#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003566
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003567 /* Process FT when SME is in the driver */
3568 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3569 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003570 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003571 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3572 data->assoc_info.resp_ies,
3573 data->assoc_info.resp_ies_len,
3574 bssid) < 0) {
3575 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3576 "Reassociation Response failed");
3577 wpa_supplicant_deauthenticate(
3578 wpa_s, WLAN_REASON_INVALID_IE);
3579 return -1;
3580 }
3581 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3582 }
3583
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003584 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3585 data->assoc_info.resp_ies_len);
3586#endif /* CONFIG_IEEE80211R */
3587
Hai Shalom899fcc72020-10-19 14:38:18 -07003588 if (bssid_known)
3589 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3590 data->assoc_info.resp_ies,
3591 data->assoc_info.resp_ies_len);
3592
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003593 /* WPA/RSN IE from Beacon/ProbeResp */
3594 p = data->assoc_info.beacon_ies;
3595 l = data->assoc_info.beacon_ies_len;
3596
3597 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3598 */
3599 wpa_found = rsn_found = 0;
3600 while (p && l >= 2) {
3601 len = p[1] + 2;
3602 if (len > l) {
3603 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3604 p, l);
3605 break;
3606 }
3607 if (!wpa_found &&
3608 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3609 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3610 wpa_found = 1;
3611 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3612 }
3613
3614 if (!rsn_found &&
3615 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3616 rsn_found = 1;
3617 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3618 }
3619
Hai Shalomc3565922019-10-28 11:58:20 -07003620 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3621 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3622
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003623 l -= len;
3624 p += len;
3625 }
3626
3627 if (!wpa_found && data->assoc_info.beacon_ies)
3628 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003629 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003630 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003631 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3632 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003633 if (wpa_found || rsn_found)
3634 wpa_s->ap_ies_from_associnfo = 1;
3635
Jouni Malinen87fd2792011-05-16 18:35:42 +03003636 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3637 wpa_s->assoc_freq != data->assoc_info.freq) {
3638 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3639 "%u to %u MHz",
3640 wpa_s->assoc_freq, data->assoc_info.freq);
3641 wpa_supplicant_update_scan_results(wpa_s);
3642 }
3643
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003644 wpa_s->assoc_freq = data->assoc_info.freq;
3645
Hai Shalomc1a21442022-02-04 13:43:00 -08003646 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3647 data->assoc_info.resp_ies_len);
3648
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003649 return 0;
3650}
3651
3652
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003653static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3654{
Hai Shalomc3565922019-10-28 11:58:20 -07003655 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003656
3657 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3658 return -1;
3659
3660 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3661 return 0;
3662
3663 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3664 WPA_IE_VENDOR_TYPE);
3665 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003666 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003667
3668 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3669 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3670 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003671 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3672 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3673 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003674 return -1;
3675
3676 return 0;
3677}
3678
3679
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003680static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3681 union wpa_event_data *data)
3682{
3683#ifdef CONFIG_FST
3684 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3685 struct wpa_bss *bss = wpa_s->current_bss;
3686 const u8 *ieprb, *iebcn;
3687
3688 wpabuf_free(wpa_s->received_mb_ies);
3689 wpa_s->received_mb_ies = NULL;
3690
3691 if (ai &&
3692 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3693 wpa_printf(MSG_DEBUG,
3694 "FST: MB IEs updated from Association Response frame");
3695 return;
3696 }
3697
3698 if (ai &&
3699 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3700 wpa_printf(MSG_DEBUG,
3701 "FST: MB IEs updated from association event Beacon IEs");
3702 return;
3703 }
3704
3705 if (!bss)
3706 return;
3707
Hai Shalom60840252021-02-19 19:02:11 -08003708 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003709 iebcn = ieprb + bss->ie_len;
3710
3711 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3712 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3713 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3714 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3715#endif /* CONFIG_FST */
3716}
3717
3718
Sunil Ravi89eba102022-09-13 21:04:37 -07003719static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3720{
3721 struct driver_sta_mlo_info mlo;
3722 int i;
3723
Sunil Ravi77d572f2023-01-17 23:58:31 +00003724 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07003725 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3726 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3727 wpa_supplicant_deauthenticate(wpa_s,
3728 WLAN_REASON_DEAUTH_LEAVING);
3729 return -1;
3730 }
3731
3732 if (wpa_s->valid_links == mlo.valid_links) {
3733 bool match = true;
3734
3735 if (!mlo.valid_links)
3736 return 0;
3737
3738 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3739 if (!(mlo.valid_links & BIT(i)))
3740 continue;
3741
3742 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3743 ETH_ALEN) != 0 ||
3744 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3745 ETH_ALEN) != 0) {
3746 match = false;
3747 break;
3748 }
3749 }
3750
Sunil Ravi77d572f2023-01-17 23:58:31 +00003751 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravi89eba102022-09-13 21:04:37 -07003752 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3753 ETH_ALEN) == 0)
3754 return 0;
3755 }
3756
3757 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00003758 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07003759 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3760 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3761 if (!(wpa_s->valid_links & BIT(i)))
3762 continue;
3763
3764 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3765 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3766 wpa_s->links[i].freq = mlo.links[i].freq;
3767 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3768 }
3769
3770 return 0;
3771}
3772
3773
Sunil Ravi77d572f2023-01-17 23:58:31 +00003774static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
3775{
3776 struct driver_sta_mlo_info drv_mlo;
3777 struct wpa_sm_mlo wpa_mlo;
3778 const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
3779 int i;
3780
3781 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
3782 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
3783 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
3784 return -1;
3785 }
3786
3787 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
3788 if (!drv_mlo.valid_links)
3789 goto out;
3790
3791 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
3792 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
3793 wpa_mlo.valid_links = drv_mlo.valid_links;
3794 wpa_mlo.req_links = drv_mlo.req_links;
3795
3796 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3797 struct wpa_bss *bss;
3798
3799 if (!(drv_mlo.req_links & BIT(i)))
3800 continue;
3801
3802 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
3803 if (!bss) {
3804 wpa_supplicant_update_scan_results(wpa_s);
3805 bss = wpa_supplicant_get_new_bss(
3806 wpa_s, drv_mlo.links[i].bssid);
3807 }
3808
3809 if (!bss) {
3810 wpa_dbg(wpa_s, MSG_INFO,
3811 "Failed to get MLO link %d BSS", i);
3812 return -1;
3813 }
3814
3815 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3816 bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
3817
3818 wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
3819 wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
3820 wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
3821 wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
3822
3823 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
3824 ETH_ALEN);
3825 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
3826 ETH_ALEN);
3827 }
3828
3829out:
3830 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
3831}
3832
3833
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003834static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3835 union wpa_event_data *data)
3836{
3837 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003838 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003839 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003840#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3841 struct wpa_bss *bss;
3842#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003843#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303844 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003845#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003846
3847#ifdef CONFIG_AP
3848 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003849 if (!data)
3850 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003851 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3852 data->assoc_info.addr,
3853 data->assoc_info.req_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003854 data->assoc_info.req_ies_len, NULL, 0,
3855 NULL, data->assoc_info.reassoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003856 return;
3857 }
3858#endif /* CONFIG_AP */
3859
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003860 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003861 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003862
Andy Kuoaba17c12022-04-14 16:05:31 +08003863#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303864 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3865 struct wpa_ft_ies parse;
3866 /* Check for FT reassociation is done by the driver */
3867#ifdef CONFIG_IEEE80211R
3868 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303869 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303870 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003871 data->assoc_info.resp_ies_len, &parse, use_sha384, false) < 0) {
Mir Ali677e7482020-11-12 19:49:02 +05303872 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3873 return;
3874 }
3875 if (parse.rsn_pmkid != NULL) {
3876 wpa_set_ft_completed(wpa_s->wpa);
3877 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3878 }
3879 }
3880#endif /* CONFIG_IEEE80211R */
3881 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003882#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303883
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003884 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003885
3886 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3887 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3888 wpa_supplicant_deauthenticate(
3889 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3890 return;
3891 }
3892
Sunil Ravi89eba102022-09-13 21:04:37 -07003893 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3894 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3895 wpa_supplicant_deauthenticate(wpa_s,
3896 WLAN_REASON_DEAUTH_LEAVING);
3897 return;
3898 }
3899
Sunil Ravia04bd252022-05-02 22:54:18 -07003900 if (ft_completed &&
3901 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3902 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3903 MAC2STR(bssid));
3904 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3905 wpa_printf(MSG_ERROR,
3906 "Can't find target AP's information!");
3907 return;
3908 }
3909 wpa_supplicant_assoc_update_ie(wpa_s);
3910 }
3911
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003912 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3913 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003914 /*
3915 * FILS authentication can share the same mechanism to mark the
3916 * connection fully authenticated, so set ft_completed also based on
3917 * FILS result.
3918 */
3919 if (!ft_completed)
3920 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003921
Andy Kuoaba17c12022-04-14 16:05:31 +08003922#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303923 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3924 /*
3925 * For driver based roaming, insert PSK during
3926 * the initial association
3927 */
3928 if (is_zero_ether_addr(wpa_s->bssid) &&
3929 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3930 /*
3931 * In case the driver wants to handle re-assocs,
3932 * pass it down the PMK.
3933 */
3934 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3935 wpa_sm_install_pmk(wpa_s->wpa);
3936 }
Mir Ali677e7482020-11-12 19:49:02 +05303937 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303938#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003939
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003940 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003941 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003942 if (os_reltime_initialized(&wpa_s->session_start)) {
3943 os_reltime_age(&wpa_s->session_start,
3944 &wpa_s->session_length);
3945 wpa_s->session_start.sec = 0;
3946 wpa_s->session_start.usec = 0;
3947 wpas_notify_session_length(wpa_s);
3948 } else {
3949 wpas_notify_auth_changed(wpa_s);
3950 os_get_reltime(&wpa_s->session_start);
3951 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003952 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3953 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003954 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003955 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003956 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3957 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003958 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003959
3960 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3961 wpa_clear_keys(wpa_s, bssid);
3962 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00003963 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003964 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003965 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3966 return;
3967 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003968 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003969
Hai Shalomc1a21442022-02-04 13:43:00 -08003970 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3971 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3972 return;
3973
Hai Shalomfdcde762020-04-02 11:19:20 -07003974 multi_ap_set_4addr_mode(wpa_s);
3975
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003976 if (wpa_s->conf->ap_scan == 1 &&
3977 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003978 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3979 wpa_msg(wpa_s, MSG_WARNING,
3980 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003981 }
3982
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003983 wpas_fst_update_mb_assoc(wpa_s, data);
3984
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003985#ifdef CONFIG_SME
Sunil Ravi640215c2023-06-28 23:08:09 +00003986 /*
3987 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
3988 * (for MLO connection) as the previous BSSID for subsequent
3989 * reassociation requests handled by SME-in-wpa_supplicant.
3990 */
3991 os_memcpy(wpa_s->sme.prev_bssid,
3992 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003993 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003994 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003995#endif /* CONFIG_SME */
3996
3997 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3998 if (wpa_s->current_ssid) {
3999 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
4000 * initialized before association, but for other modes,
4001 * initialize PC/SC here, if the current configuration needs
4002 * smartcard or SIM/USIM. */
4003 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
4004 }
4005 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004006
4007 if (wpa_sm_set_ml_info(wpa_s)) {
4008 wpa_dbg(wpa_s, MSG_INFO,
4009 "Failed to set MLO connection info to wpa_sm");
4010 wpa_supplicant_deauthenticate(wpa_s,
4011 WLAN_REASON_DEAUTH_LEAVING);
4012 return;
4013 }
4014
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004015 if (wpa_s->l2)
4016 l2_packet_notify_auth_start(wpa_s->l2);
4017
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004018 already_authorized = data && data->assoc_info.authorized;
4019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004020 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07004021 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004022 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
4023 * state machine may transit to AUTHENTICATING state based on obsolete
4024 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
4025 * AUTHENTICATED without ever giving chance to EAP state machine to
4026 * reset the state.
4027 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004028 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07004029 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4030 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004031 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004032 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4033 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
4034 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07004035 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07004036 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004037 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07004038 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004039 wpa_s->eapol_received = 0;
4040 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4041 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4042 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004043 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004044 if (wpa_s->current_ssid &&
4045 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004046 (wpa_s->drv_flags &
4047 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4048 /*
4049 * Set the key after having received joined-IBSS event
4050 * from the driver.
4051 */
4052 wpa_supplicant_set_wpa_none_key(wpa_s,
4053 wpa_s->current_ssid);
4054 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004055 wpa_supplicant_cancel_auth_timeout(wpa_s);
4056 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4057 } else if (!ft_completed) {
4058 /* Timeout for receiving the first EAPOL packet */
4059 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
4060 }
4061 wpa_supplicant_cancel_scan(wpa_s);
4062
Hai Shalom5f92bc92019-04-18 11:54:11 -07004063 if (ft_completed) {
4064 /*
4065 * FT protocol completed - make sure EAPOL state machine ends
4066 * up in authenticated.
4067 */
4068 wpa_supplicant_cancel_auth_timeout(wpa_s);
4069 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004070 eapol_sm_notify_portValid(wpa_s->eapol, true);
4071 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07004072 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4073 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304074 if (already_authorized) {
4075 /*
4076 * We are done; the driver will take care of RSN 4-way
4077 * handshake.
4078 */
4079 wpa_supplicant_cancel_auth_timeout(wpa_s);
4080 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4081 eapol_sm_notify_portValid(wpa_s->eapol, true);
4082 eapol_sm_notify_eap_success(wpa_s->eapol, true);
4083 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004084 /* Update port, WPA_COMPLETED state from the
4085 * EVENT_PORT_AUTHORIZED handler when the driver is done
4086 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304087 */
Sunil Ravi167279a2023-05-31 01:12:34 +00004088 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004089 wpa_msg(wpa_s, MSG_INFO,
4090 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304091 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004092 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004093 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4094 /*
4095 * The driver will take care of RSN 4-way handshake, so we need
4096 * to allow EAPOL supplicant to complete its work without
4097 * waiting for WPA supplicant.
4098 */
Hai Shalome21d4e82020-04-29 16:34:06 -07004099 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004100 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004101#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05304102 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
4103 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4104 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
4105 wpa_s->key_mgmt);
4106 wpa_supplicant_deauthenticate(
4107 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4108 return;
4109 }
4110 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4111 wpa_s->assoc_freq = data->assoc_info.freq;
4112 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
4113 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004114#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
4115
Jouni Malinena05074c2012-12-21 21:35:35 +02004116 wpa_s->last_eapol_matches_bssid = 0;
4117
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004118#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07004119 if (wpa_s->rsne_override_eapol) {
4120 wpa_printf(MSG_DEBUG,
4121 "TESTING: RSNE EAPOL-Key msg 2/4 override");
4122 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4123 wpabuf_head(wpa_s->rsne_override_eapol),
4124 wpabuf_len(wpa_s->rsne_override_eapol));
4125 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004126 if (wpa_s->rsnxe_override_eapol) {
4127 wpa_printf(MSG_DEBUG,
4128 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4129 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4130 wpabuf_head(wpa_s->rsnxe_override_eapol),
4131 wpabuf_len(wpa_s->rsnxe_override_eapol));
4132 }
4133#endif /* CONFIG_TESTING_OPTIONS */
4134
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004135 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004136 struct os_reltime now, age;
4137 os_get_reltime(&now);
4138 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08004139 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00004140 os_memcmp(wpa_s->pending_eapol_rx_src,
4141 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid,
4142 ETH_ALEN) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004143 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4144 "frame that was received just before "
4145 "association notification");
4146 wpa_supplicant_rx_eapol(
4147 wpa_s, wpa_s->pending_eapol_rx_src,
4148 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00004149 wpabuf_len(wpa_s->pending_eapol_rx),
4150 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004151 }
4152 wpabuf_free(wpa_s->pending_eapol_rx);
4153 wpa_s->pending_eapol_rx = NULL;
4154 }
4155
Hai Shalomfdcde762020-04-02 11:19:20 -07004156#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004157 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4158 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004159 wpa_s->current_ssid &&
4160 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004161 /* Set static WEP keys again */
4162 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4163 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004164#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004165
4166#ifdef CONFIG_IBSS_RSN
4167 if (wpa_s->current_ssid &&
4168 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4169 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4170 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4171 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004172 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004173 if (!wpa_s->ibss_rsn) {
4174 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4175 wpa_supplicant_deauthenticate(
4176 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4177 return;
4178 }
4179
4180 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4181 }
4182#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004183
4184 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004185
4186 if (data) {
4187 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4188 data->assoc_info.resp_ies_len,
4189 &data->assoc_info.wmm_params);
4190
4191 if (wpa_s->reassoc_same_bss)
4192 wmm_ac_restore_tspecs(wpa_s);
4193 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004194
Hai Shalomc3565922019-10-28 11:58:20 -07004195#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4196 bss = wpa_bss_get_bssid(wpa_s, bssid);
4197#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004198#ifdef CONFIG_FILS
4199 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004200 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4201
4202 if (fils_cache_id)
4203 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4204 }
4205#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004206
4207#ifdef CONFIG_MBO
4208 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4209#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004210
4211#ifdef CONFIG_DPP2
4212 wpa_s->dpp_pfs_fallback = 0;
4213#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004214
4215 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4216 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004217}
4218
4219
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004220static int disconnect_reason_recoverable(u16 reason_code)
4221{
4222 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4223 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4224 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4225}
4226
4227
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004228static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004229 u16 reason_code,
4230 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004231{
4232 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004233
4234 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4235 /*
4236 * At least Host AP driver and a Prism3 card seemed to be
4237 * generating streams of disconnected events when configuring
4238 * IBSS for WPA-None. Ignore them for now.
4239 */
4240 return;
4241 }
4242
4243 bssid = wpa_s->bssid;
4244 if (is_zero_ether_addr(bssid))
4245 bssid = wpa_s->pending_bssid;
4246
4247 if (!is_zero_ether_addr(bssid) ||
4248 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4249 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4250 " reason=%d%s",
4251 MAC2STR(bssid), reason_code,
4252 locally_generated ? " locally_generated=1" : "");
4253 }
4254}
4255
4256
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004257static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4258 int locally_generated)
4259{
4260 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004261 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004262 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4263 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004264 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004265
4266 /*
4267 * It looks like connection was lost while trying to go through PSK
4268 * 4-way handshake. Filter out known disconnection cases that are caused
4269 * by something else than PSK mismatch to avoid confusing reports.
4270 */
4271
4272 if (locally_generated) {
4273 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4274 return 0;
4275 }
4276
4277 return 1;
4278}
4279
4280
Jouni Malinen2b89da82012-08-31 22:04:41 +03004281static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4282 u16 reason_code,
4283 int locally_generated)
4284{
4285 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004286 int authenticating;
4287 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004288 struct wpa_bss *fast_reconnect = NULL;
4289 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004290 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004291 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004292
4293 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
4294 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
4295
4296 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4297 /*
4298 * At least Host AP driver and a Prism3 card seemed to be
4299 * generating streams of disconnected events when configuring
4300 * IBSS for WPA-None. Ignore them for now.
4301 */
4302 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4303 "IBSS/WPA-None mode");
4304 return;
4305 }
4306
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004307 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4308 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4309 locally_generated)
4310 /*
4311 * Remove the inactive AP (which is probably out of range) from
4312 * the BSS list after marking disassociation. In particular
4313 * mac80211-based drivers use the
4314 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4315 * locally generated disconnection events for cases where the
4316 * AP does not reply anymore.
4317 */
4318 curr = wpa_s->current_bss;
4319
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004320 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004321 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4322 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004323 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4324 return; /* P2P group removed */
Sunil Ravi77d572f2023-01-17 23:58:31 +00004325 wpas_auth_failed(wpa_s, "WRONG_KEY", prev_pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004326 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004327#ifdef CONFIG_DPP2
4328 wpas_dpp_send_conn_status_result(wpa_s,
4329 DPP_STATUS_AUTH_FAILURE);
4330#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004331 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004332 if (!wpa_s->disconnected &&
4333 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004334 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004335 wpas_wps_searching(wpa_s) ||
4336 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004337 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004338 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004339 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004340 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004341 wpa_s->wpa_state);
4342 if (wpa_s->wpa_state == WPA_COMPLETED &&
4343 wpa_s->current_ssid &&
4344 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004345 (wpa_s->own_reconnect_req ||
4346 (!locally_generated &&
4347 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004348 /*
4349 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004350 * us, but could allow us to get back in. This is also
4351 * triggered for cases where local reconnection request
4352 * is used to force reassociation with the same BSS.
4353 * Try to reconnect to the same BSS without a full scan
4354 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004355 */
4356 fast_reconnect = wpa_s->current_bss;
4357 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004358 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004359 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004360 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004361 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4362 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004363 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004364 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004365 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004366 "try to re-connect");
4367 wpa_s->reassociate = 0;
4368 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004369 if (!wpa_s->pno)
4370 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004371 }
4372 bssid = wpa_s->bssid;
4373 if (is_zero_ether_addr(bssid))
4374 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004375 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4376 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004377 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004378 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4379
Dmitry Shmidt04949592012-07-19 12:16:46 -07004380 if (locally_generated)
4381 wpa_s->disconnect_reason = -reason_code;
4382 else
4383 wpa_s->disconnect_reason = reason_code;
4384 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004385 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4386 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004387 wpa_clear_keys(wpa_s, wpa_s->bssid);
4388 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004389 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004390 wpa_supplicant_mark_disassoc(wpa_s);
4391
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004392 if (curr)
4393 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4394
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004395 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004396 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004397 wpa_s->current_ssid = last_ssid;
4398 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004399
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004400 if (fast_reconnect &&
4401 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4402 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4403 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4404 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004405 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004406 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004407#ifndef CONFIG_NO_SCAN_PROCESSING
4408 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4409 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4410 fast_reconnect_ssid) < 0) {
4411 /* Recover through full scan */
4412 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4413 }
4414#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004415 } else if (fast_reconnect) {
4416 /*
4417 * Could not reconnect to the same BSS due to network being
4418 * disabled. Use a new scan to match the alternative behavior
4419 * above, i.e., to continue automatic reconnection attempt in a
4420 * way that enforces disabled network rules.
4421 */
4422 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004423 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004424}
4425
4426
4427#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004428void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004429{
4430 struct wpa_supplicant *wpa_s = eloop_ctx;
4431
4432 if (!wpa_s->pending_mic_error_report)
4433 return;
4434
4435 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4436 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4437 wpa_s->pending_mic_error_report = 0;
4438}
4439#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4440
4441
4442static void
4443wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4444 union wpa_event_data *data)
4445{
4446 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004447 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004448
4449 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4450 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004451 os_get_reltime(&t);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004452 if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004453 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004454 wpa_s->pending_mic_error_report) {
4455 if (wpa_s->pending_mic_error_report) {
4456 /*
4457 * Send the pending MIC error report immediately since
4458 * we are going to start countermeasures and AP better
4459 * do the same.
4460 */
4461 wpa_sm_key_request(wpa_s->wpa, 1,
4462 wpa_s->pending_mic_error_pairwise);
4463 }
4464
4465 /* Send the new MIC error report immediately since we are going
4466 * to start countermeasures and AP better do the same.
4467 */
4468 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4469
4470 /* initialize countermeasures */
4471 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004472
Hai Shalom60840252021-02-19 19:02:11 -08004473 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004475 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4476
4477 /*
4478 * Need to wait for completion of request frame. We do not get
4479 * any callback for the message completion, so just wait a
4480 * short while and hope for the best. */
4481 os_sleep(0, 10000);
4482
4483 wpa_drv_set_countermeasures(wpa_s, 1);
4484 wpa_supplicant_deauthenticate(wpa_s,
4485 WLAN_REASON_MICHAEL_MIC_FAILURE);
4486 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4487 wpa_s, NULL);
4488 eloop_register_timeout(60, 0,
4489 wpa_supplicant_stop_countermeasures,
4490 wpa_s, NULL);
4491 /* TODO: mark the AP rejected for 60 second. STA is
4492 * allowed to associate with another AP.. */
4493 } else {
4494#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4495 if (wpa_s->mic_errors_seen) {
4496 /*
4497 * Reduce the effectiveness of Michael MIC error
4498 * reports as a means for attacking against TKIP if
4499 * more than one MIC failure is noticed with the same
4500 * PTK. We delay the transmission of the reports by a
4501 * random time between 0 and 60 seconds in order to
4502 * force the attacker wait 60 seconds before getting
4503 * the information on whether a frame resulted in a MIC
4504 * failure.
4505 */
4506 u8 rval[4];
4507 int sec;
4508
4509 if (os_get_random(rval, sizeof(rval)) < 0)
4510 sec = os_random() % 60;
4511 else
4512 sec = WPA_GET_BE32(rval) % 60;
4513 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4514 "report %d seconds", sec);
4515 wpa_s->pending_mic_error_report = 1;
4516 wpa_s->pending_mic_error_pairwise = pairwise;
4517 eloop_cancel_timeout(
4518 wpa_supplicant_delayed_mic_error_report,
4519 wpa_s, NULL);
4520 eloop_register_timeout(
4521 sec, os_random() % 1000000,
4522 wpa_supplicant_delayed_mic_error_report,
4523 wpa_s, NULL);
4524 } else {
4525 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4526 }
4527#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4528 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4529#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4530 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004531 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004532 wpa_s->mic_errors_seen++;
4533}
4534
4535
4536#ifdef CONFIG_TERMINATE_ONLASTIF
4537static int any_interfaces(struct wpa_supplicant *head)
4538{
4539 struct wpa_supplicant *wpa_s;
4540
4541 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4542 if (!wpa_s->interface_removed)
4543 return 1;
4544 return 0;
4545}
4546#endif /* CONFIG_TERMINATE_ONLASTIF */
4547
4548
4549static void
4550wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4551 union wpa_event_data *data)
4552{
4553 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4554 return;
4555
4556 switch (data->interface_status.ievent) {
4557 case EVENT_INTERFACE_ADDED:
4558 if (!wpa_s->interface_removed)
4559 break;
4560 wpa_s->interface_removed = 0;
4561 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4562 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4563 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4564 "driver after interface was added");
4565 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004566
4567#ifdef CONFIG_P2P
4568 if (!wpa_s->global->p2p &&
4569 !wpa_s->global->p2p_disabled &&
4570 !wpa_s->conf->p2p_disabled &&
4571 (wpa_s->drv_flags &
4572 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4573 wpas_p2p_add_p2pdev_interface(
4574 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4575 wpa_printf(MSG_INFO,
4576 "P2P: Failed to enable P2P Device interface");
4577 /* Try to continue without. P2P will be disabled. */
4578 }
4579#endif /* CONFIG_P2P */
4580
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004581 break;
4582 case EVENT_INTERFACE_REMOVED:
4583 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4584 wpa_s->interface_removed = 1;
4585 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004586 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004587 l2_packet_deinit(wpa_s->l2);
4588 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004589
4590#ifdef CONFIG_P2P
4591 if (wpa_s->global->p2p &&
4592 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4593 (wpa_s->drv_flags &
4594 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4595 wpa_dbg(wpa_s, MSG_DEBUG,
4596 "Removing P2P Device interface");
4597 wpa_supplicant_remove_iface(
4598 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4599 0);
4600 wpa_s->global->p2p_init_wpa_s = NULL;
4601 }
4602#endif /* CONFIG_P2P */
4603
Dmitry Shmidte4663042016-04-04 10:07:49 -07004604#ifdef CONFIG_MATCH_IFACE
4605 if (wpa_s->matched) {
4606 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4607 break;
4608 }
4609#endif /* CONFIG_MATCH_IFACE */
4610
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004611#ifdef CONFIG_TERMINATE_ONLASTIF
4612 /* check if last interface */
4613 if (!any_interfaces(wpa_s->global->ifaces))
4614 eloop_terminate();
4615#endif /* CONFIG_TERMINATE_ONLASTIF */
4616 break;
4617 }
4618}
4619
4620
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004621#ifdef CONFIG_TDLS
4622static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4623 union wpa_event_data *data)
4624{
4625 if (data == NULL)
4626 return;
4627 switch (data->tdls.oper) {
4628 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004629 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4630 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4631 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4632 else
4633 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004634 break;
4635 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004636 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4637 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4638 data->tdls.reason_code);
4639 else
4640 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4641 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004642 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004643 case TDLS_REQUEST_DISCOVER:
4644 wpa_tdls_send_discovery_request(wpa_s->wpa,
4645 data->tdls.peer);
4646 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004647 }
4648}
4649#endif /* CONFIG_TDLS */
4650
4651
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004652#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004653static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4654 union wpa_event_data *data)
4655{
4656 if (data == NULL)
4657 return;
4658 switch (data->wnm.oper) {
4659 case WNM_OPER_SLEEP:
4660 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4661 "(action=%d, intval=%d)",
4662 data->wnm.sleep_action, data->wnm.sleep_intval);
4663 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004664 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004665 break;
4666 }
4667}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004668#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004669
4670
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004671#ifdef CONFIG_IEEE80211R
4672static void
4673wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4674 union wpa_event_data *data)
4675{
4676 if (data == NULL)
4677 return;
4678
4679 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4680 data->ft_ies.ies_len,
4681 data->ft_ies.ft_action,
4682 data->ft_ies.target_ap,
4683 data->ft_ies.ric_ies,
4684 data->ft_ies.ric_ies_len) < 0) {
4685 /* TODO: prevent MLME/driver from trying to associate? */
4686 }
4687}
4688#endif /* CONFIG_IEEE80211R */
4689
4690
4691#ifdef CONFIG_IBSS_RSN
4692static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4693 union wpa_event_data *data)
4694{
4695 struct wpa_ssid *ssid;
4696 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4697 return;
4698 if (data == NULL)
4699 return;
4700 ssid = wpa_s->current_ssid;
4701 if (ssid == NULL)
4702 return;
4703 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4704 return;
4705
4706 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4707}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004708
4709
4710static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4711 union wpa_event_data *data)
4712{
4713 struct wpa_ssid *ssid = wpa_s->current_ssid;
4714
4715 if (ssid == NULL)
4716 return;
4717
4718 /* check if the ssid is correctly configured as IBSS/RSN */
4719 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4720 return;
4721
4722 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4723 data->rx_mgmt.frame_len);
4724}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004725#endif /* CONFIG_IBSS_RSN */
4726
4727
4728#ifdef CONFIG_IEEE80211R
4729static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4730 size_t len)
4731{
4732 const u8 *sta_addr, *target_ap_addr;
4733 u16 status;
4734
4735 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4736 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4737 return; /* only SME case supported for now */
4738 if (len < 1 + 2 * ETH_ALEN + 2)
4739 return;
4740 if (data[0] != 2)
4741 return; /* Only FT Action Response is supported for now */
4742 sta_addr = data + 1;
4743 target_ap_addr = data + 1 + ETH_ALEN;
4744 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4745 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4746 MACSTR " TargetAP " MACSTR " status %u",
4747 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4748
4749 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4750 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4751 " in FT Action Response", MAC2STR(sta_addr));
4752 return;
4753 }
4754
4755 if (status) {
4756 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4757 "failure (status code %d)", status);
4758 /* TODO: report error to FT code(?) */
4759 return;
4760 }
4761
4762 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4763 len - (1 + 2 * ETH_ALEN + 2), 1,
4764 target_ap_addr, NULL, 0) < 0)
4765 return;
4766
4767#ifdef CONFIG_SME
4768 {
4769 struct wpa_bss *bss;
4770 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4771 if (bss)
4772 wpa_s->sme.freq = bss->freq;
4773 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4774 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4775 WLAN_AUTH_FT);
4776 }
4777#endif /* CONFIG_SME */
4778}
4779#endif /* CONFIG_IEEE80211R */
4780
4781
4782static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4783 struct unprot_deauth *e)
4784{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004785 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4786 "dropped: " MACSTR " -> " MACSTR
4787 " (reason code %u)",
4788 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4789 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004790}
4791
4792
4793static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4794 struct unprot_disassoc *e)
4795{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004796 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4797 "dropped: " MACSTR " -> " MACSTR
4798 " (reason code %u)",
4799 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4800 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004801}
4802
4803
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004804static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4805 u16 reason_code, int locally_generated,
4806 const u8 *ie, size_t ie_len, int deauth)
4807{
4808#ifdef CONFIG_AP
4809 if (wpa_s->ap_iface && addr) {
4810 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4811 return;
4812 }
4813
4814 if (wpa_s->ap_iface) {
4815 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4816 return;
4817 }
4818#endif /* CONFIG_AP */
4819
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004820 if (!locally_generated)
4821 wpa_s->own_disconnect_req = 0;
4822
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004823 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4824
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004825 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4826 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4827 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4828 eapol_sm_failed(wpa_s->eapol))) &&
4829 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00004830 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004831
4832#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004833 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004834 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4835 locally_generated) > 0) {
4836 /*
4837 * The interface was removed, so cannot continue
4838 * processing any additional operations after this.
4839 */
4840 return;
4841 }
4842 }
4843#endif /* CONFIG_P2P */
4844
4845 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4846 locally_generated);
4847}
4848
4849
4850static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4851 struct disassoc_info *info)
4852{
4853 u16 reason_code = 0;
4854 int locally_generated = 0;
4855 const u8 *addr = NULL;
4856 const u8 *ie = NULL;
4857 size_t ie_len = 0;
4858
4859 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4860
4861 if (info) {
4862 addr = info->addr;
4863 ie = info->ie;
4864 ie_len = info->ie_len;
4865 reason_code = info->reason_code;
4866 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004867 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4868 reason2str(reason_code),
4869 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004870 if (addr)
4871 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4872 MAC2STR(addr));
4873 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4874 ie, ie_len);
4875 }
4876
4877#ifdef CONFIG_AP
4878 if (wpa_s->ap_iface && info && info->addr) {
4879 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4880 return;
4881 }
4882
4883 if (wpa_s->ap_iface) {
4884 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4885 return;
4886 }
4887#endif /* CONFIG_AP */
4888
4889#ifdef CONFIG_P2P
4890 if (info) {
4891 wpas_p2p_disassoc_notif(
4892 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4893 locally_generated);
4894 }
4895#endif /* CONFIG_P2P */
4896
4897 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4898 sme_event_disassoc(wpa_s, info);
4899
4900 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4901 ie, ie_len, 0);
4902}
4903
4904
4905static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4906 struct deauth_info *info)
4907{
4908 u16 reason_code = 0;
4909 int locally_generated = 0;
4910 const u8 *addr = NULL;
4911 const u8 *ie = NULL;
4912 size_t ie_len = 0;
4913
4914 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4915
4916 if (info) {
4917 addr = info->addr;
4918 ie = info->ie;
4919 ie_len = info->ie_len;
4920 reason_code = info->reason_code;
4921 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004922 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4923 reason_code, reason2str(reason_code),
4924 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004925 if (addr) {
4926 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4927 MAC2STR(addr));
4928 }
4929 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4930 ie, ie_len);
4931 }
4932
4933 wpa_reset_ft_completed(wpa_s->wpa);
4934
4935 wpas_event_disconnect(wpa_s, addr, reason_code,
4936 locally_generated, ie, ie_len, 1);
4937}
4938
4939
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004940static const char * reg_init_str(enum reg_change_initiator init)
4941{
4942 switch (init) {
4943 case REGDOM_SET_BY_CORE:
4944 return "CORE";
4945 case REGDOM_SET_BY_USER:
4946 return "USER";
4947 case REGDOM_SET_BY_DRIVER:
4948 return "DRIVER";
4949 case REGDOM_SET_BY_COUNTRY_IE:
4950 return "COUNTRY_IE";
4951 case REGDOM_BEACON_HINT:
4952 return "BEACON_HINT";
4953 }
4954 return "?";
4955}
4956
4957
4958static const char * reg_type_str(enum reg_type type)
4959{
4960 switch (type) {
4961 case REGDOM_TYPE_UNKNOWN:
4962 return "UNKNOWN";
4963 case REGDOM_TYPE_COUNTRY:
4964 return "COUNTRY";
4965 case REGDOM_TYPE_WORLD:
4966 return "WORLD";
4967 case REGDOM_TYPE_CUSTOM_WORLD:
4968 return "CUSTOM_WORLD";
4969 case REGDOM_TYPE_INTERSECTION:
4970 return "INTERSECTION";
4971 }
4972 return "?";
4973}
4974
4975
Hai Shalom74f70d42019-02-11 14:42:39 -08004976void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4977 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004978{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004979 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004980 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004981
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004982 /*
4983 * To allow backwards compatibility with higher level layers that
4984 * assumed the REGDOM_CHANGE event is sent over the initially added
4985 * interface. Find the highest parent of this interface and use it to
4986 * send the event.
4987 */
4988 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4989 ;
4990
Hai Shalom74f70d42019-02-11 14:42:39 -08004991 if (info) {
4992 wpa_msg(ifs, MSG_INFO,
4993 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4994 reg_init_str(info->initiator), reg_type_str(info->type),
4995 info->alpha2[0] ? " alpha2=" : "",
4996 info->alpha2[0] ? info->alpha2 : "");
4997 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004998
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004999 if (wpa_s->drv_priv == NULL)
5000 return; /* Ignore event during drv initialization */
5001
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005002 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
5003 radio_list) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005004 bool was_6ghz_enabled;
5005
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005006 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
5007 ifs->ifname);
5008 free_hw_features(ifs);
5009 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005010 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005011
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005012 was_6ghz_enabled = ifs->is_6ghz_enabled;
5013 ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5014
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005015 /* Restart PNO/sched_scan with updated channel list */
5016 if (ifs->pno) {
5017 wpas_stop_pno(ifs);
5018 wpas_start_pno(ifs);
5019 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
5020 wpa_dbg(ifs, MSG_DEBUG,
5021 "Channel list changed - restart sched_scan");
5022 wpas_scan_restart_sched_scan(ifs);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005023 } else if (ifs->scanning && !was_6ghz_enabled &&
5024 ifs->is_6ghz_enabled) {
5025 /* Look for APs in the 6 GHz band */
5026 wpa_dbg(ifs, MSG_INFO,
5027 "Channel list changed - trigger 6 GHz-only scan");
5028 ifs->crossed_6ghz_dom = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005029 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005030 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005031
5032 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005033}
5034
5035
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005036static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005037 const u8 *frame, size_t len, int freq,
5038 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005039{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005040 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005041 const u8 *payload;
5042 size_t plen;
5043 u8 category;
5044
5045 if (len < IEEE80211_HDRLEN + 2)
5046 return;
5047
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005048 mgmt = (const struct ieee80211_mgmt *) frame;
5049 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005050 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005051 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005052
5053 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
5054 " Category=%u DataLen=%d freq=%d MHz",
5055 MAC2STR(mgmt->sa), category, (int) plen, freq);
5056
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005057 if (category == WLAN_ACTION_WMM) {
5058 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5059 return;
5060 }
5061
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005062#ifdef CONFIG_IEEE80211R
5063 if (category == WLAN_ACTION_FT) {
5064 ft_rx_action(wpa_s, payload, plen);
5065 return;
5066 }
5067#endif /* CONFIG_IEEE80211R */
5068
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005069#ifdef CONFIG_SME
5070 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005071 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005072 return;
5073 }
5074#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005075
5076#ifdef CONFIG_WNM
5077 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
5078 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
5079 return;
5080 }
5081#endif /* CONFIG_WNM */
5082
5083#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08005084 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5085 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005086 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08005087 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005088 payload, plen, freq) == 0)
5089 return;
5090#endif /* CONFIG_GAS */
5091
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005092#ifdef CONFIG_GAS_SERVER
5093 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5094 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
5095 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
5096 mgmt->u.action.category,
5097 payload, plen, freq) == 0)
5098 return;
5099#endif /* CONFIG_GAS_SERVER */
5100
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005101#ifdef CONFIG_TDLS
5102 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
5103 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
5104 wpa_dbg(wpa_s, MSG_DEBUG,
5105 "TDLS: Received Discovery Response from " MACSTR,
5106 MAC2STR(mgmt->sa));
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005107 if (wpa_s->valid_links &&
5108 wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa,
5109 &payload[1], plen - 1))
5110 wpa_dbg(wpa_s, MSG_ERROR,
5111 "TDLS: Discovery Response process failed for "
5112 MACSTR, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005113 return;
5114 }
5115#endif /* CONFIG_TDLS */
5116
5117#ifdef CONFIG_INTERWORKING
5118 if (category == WLAN_ACTION_QOS && plen >= 1 &&
5119 payload[0] == QOS_QOS_MAP_CONFIG) {
5120 const u8 *pos = payload + 1;
5121 size_t qlen = plen - 1;
5122 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
5123 MACSTR, MAC2STR(mgmt->sa));
5124 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
5125 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
5126 pos[1] <= qlen - 2 && pos[1] >= 16)
5127 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
5128 return;
5129 }
5130#endif /* CONFIG_INTERWORKING */
5131
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005132 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005133 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5134 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005135 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005136 payload + 1,
5137 plen - 1);
5138 return;
5139 }
5140
5141 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005142 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
5143 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
5144 return;
5145 }
5146
5147 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5148 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
5149 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
5150 payload + 1, plen - 1,
5151 rssi);
5152 return;
5153 }
5154
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005155#ifdef CONFIG_FST
5156 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
5157 fst_rx_action(wpa_s->fst, mgmt, len);
5158 return;
5159 }
5160#endif /* CONFIG_FST */
5161
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005162#ifdef CONFIG_DPP
5163 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5164 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5165 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
5166 payload[4] == DPP_OUI_TYPE) {
5167 payload++;
5168 plen--;
5169 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
5170 return;
5171 }
5172#endif /* CONFIG_DPP */
5173
Hai Shalom899fcc72020-10-19 14:38:18 -07005174 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08005175 payload[0] == ROBUST_AV_SCS_RESP) {
5176 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
5177 payload + 1, plen - 1);
5178 return;
5179 }
5180
5181 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005182 payload[0] == ROBUST_AV_MSCS_RESP) {
5183 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5184 payload + 1, plen - 1);
5185 return;
5186 }
5187
Hai Shalomc1a21442022-02-04 13:43:00 -08005188 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
5189 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
5190 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
5191 payload + 4, plen - 4);
5192 return;
5193 }
5194
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005195 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5196 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005197 if (wpa_s->ifmsh)
5198 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005199}
5200
5201
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005202static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5203 union wpa_event_data *event)
5204{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005205 struct wpa_freq_range_list *list;
5206 char *str = NULL;
5207
5208 list = &event->freq_range;
5209
5210 if (list->num)
5211 str = freq_range_list_str(list);
5212 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5213 str ? str : "");
5214
5215#ifdef CONFIG_P2P
5216 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5217 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5218 __func__);
5219 } else {
5220 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005221
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005222 /*
5223 * The update channel flow will also take care of moving a GO
5224 * from the unsafe frequency if needed.
5225 */
5226 wpas_p2p_update_channel_list(wpa_s,
5227 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005228 }
5229#endif /* CONFIG_P2P */
5230
5231 os_free(str);
5232}
5233
5234
Roshan Pius3a1667e2018-07-03 15:17:14 -07005235static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005236{
Sunil Ravi167279a2023-05-31 01:12:34 +00005237 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005238 wpa_supplicant_cancel_auth_timeout(wpa_s);
5239 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005240 eapol_sm_notify_portValid(wpa_s->eapol, true);
5241 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005242 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005243 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005244}
5245
5246
5247static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5248 int freq)
5249{
5250 size_t i;
5251 int j;
5252
5253 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5254 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5255
5256 for (j = 0; j < mode->num_channels; j++) {
5257 const struct hostapd_channel_data *chan;
5258
5259 chan = &mode->channels[j];
5260 if (chan->freq == freq)
5261 return chan->dfs_cac_ms;
5262 }
5263 }
5264
5265 return 0;
5266}
5267
5268
5269static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5270 struct dfs_event *radar)
5271{
5272#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005273 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005274 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5275 } else
5276#endif /* NEED_AP_MLME && CONFIG_AP */
5277 {
5278 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5279
5280 cac_time /= 1000; /* convert from ms to sec */
5281 if (!cac_time)
5282 cac_time = 10 * 60; /* max timeout: 10 minutes */
5283
5284 /* Restart auth timeout: CAC time added to initial timeout */
5285 wpas_auth_timeout_restart(wpa_s, cac_time);
5286 }
5287}
5288
5289
5290static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5291 struct dfs_event *radar)
5292{
5293#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005294 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005295 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5296 } else
5297#endif /* NEED_AP_MLME && CONFIG_AP */
5298 {
5299 /* Restart auth timeout with original value after CAC is
5300 * finished */
5301 wpas_auth_timeout_restart(wpa_s, 0);
5302 }
5303}
5304
5305
5306static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5307 struct dfs_event *radar)
5308{
5309#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005310 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005311 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5312 } else
5313#endif /* NEED_AP_MLME && CONFIG_AP */
5314 {
5315 /* Restart auth timeout with original value after CAC is
5316 * aborted */
5317 wpas_auth_timeout_restart(wpa_s, 0);
5318 }
5319}
5320
5321
5322static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5323 union wpa_event_data *data)
5324{
5325 wpa_dbg(wpa_s, MSG_DEBUG,
5326 "Connection authorized by device, previous state %d",
5327 wpa_s->wpa_state);
5328
5329 wpa_supplicant_event_port_authorized(wpa_s);
5330
Hai Shalomc1a21442022-02-04 13:43:00 -08005331 wpa_s->last_eapol_matches_bssid = 1;
5332
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005333 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5334 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005335 data->assoc_info.ptk_kck_len,
5336 data->assoc_info.ptk_kek,
5337 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005338#ifdef CONFIG_FILS
5339 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5340 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5341 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5342
5343 /* Update ERP next sequence number */
5344 eapol_sm_update_erp_next_seq_num(
5345 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5346
5347 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5348 /* Add the new PMK and PMKID to the PMKSA cache */
5349 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5350 data->assoc_info.fils_pmk,
5351 data->assoc_info.fils_pmk_len,
5352 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005353 wpa_s->valid_links ?
5354 wpa_s->ap_mld_addr :
5355 wpa_s->bssid,
5356 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005357 } else if (data->assoc_info.fils_pmkid) {
5358 /* Update the current PMKSA used for this connection */
5359 pmksa_cache_set_current(wpa_s->wpa,
5360 data->assoc_info.fils_pmkid,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005361 NULL, NULL, 0, NULL, 0, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005362 }
5363 }
5364#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005365}
5366
5367
Hai Shalom60840252021-02-19 19:02:11 -08005368static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5369{
5370 switch (code) {
5371 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5372 return "";
5373 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5374 return "no_bss_found";
5375 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5376 return "auth_tx_fail";
5377 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5378 return "auth_no_ack_received";
5379 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5380 return "auth_no_resp_received";
5381 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5382 return "assoc_req_tx_fail";
5383 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5384 return "assoc_no_ack_received";
5385 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5386 return "assoc_no_resp_received";
5387 default:
5388 return "unknown_reason";
5389 }
5390}
5391
5392
Roshan Pius3a1667e2018-07-03 15:17:14 -07005393static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5394 union wpa_event_data *data)
5395{
5396 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005397#ifdef CONFIG_MBO
5398 struct wpa_bss *reject_bss;
5399#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005400
5401 if (!bssid || is_zero_ether_addr(bssid))
5402 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005403#ifdef CONFIG_MBO
5404 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5405 reject_bss = wpa_s->current_bss;
5406 else
5407 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5408#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005409
5410 if (data->assoc_reject.bssid)
5411 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005412 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005413 MAC2STR(data->assoc_reject.bssid),
5414 data->assoc_reject.status_code,
5415 data->assoc_reject.timed_out ? " timeout" : "",
5416 data->assoc_reject.timeout_reason ? "=" : "",
5417 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005418 data->assoc_reject.timeout_reason : "",
5419 data->assoc_reject.reason_code !=
5420 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5421 " qca_driver_reason=" : "",
5422 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005423 else
5424 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005425 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005426 data->assoc_reject.status_code,
5427 data->assoc_reject.timed_out ? " timeout" : "",
5428 data->assoc_reject.timeout_reason ? "=" : "",
5429 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005430 data->assoc_reject.timeout_reason : "",
5431 data->assoc_reject.reason_code !=
5432 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5433 " qca_driver_reason=" : "",
5434 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005435 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005436 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5437 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005438
5439#ifdef CONFIG_OWE
5440 if (data->assoc_reject.status_code ==
5441 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5442 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5443 wpa_s->current_ssid &&
5444 wpa_s->current_ssid->owe_group == 0 &&
5445 wpa_s->last_owe_group != 21) {
5446 struct wpa_ssid *ssid = wpa_s->current_ssid;
5447 struct wpa_bss *bss = wpa_s->current_bss;
5448
5449 if (!bss) {
5450 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5451 if (!bss) {
5452 wpas_connection_failed(wpa_s, bssid);
5453 wpa_supplicant_mark_disassoc(wpa_s);
5454 return;
5455 }
5456 }
5457 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5458 wpas_connect_work_done(wpa_s);
5459 wpa_supplicant_mark_disassoc(wpa_s);
5460 wpa_supplicant_connect(wpa_s, bss, ssid);
5461 return;
5462 }
5463#endif /* CONFIG_OWE */
5464
Hai Shalomfdcde762020-04-02 11:19:20 -07005465#ifdef CONFIG_DPP2
5466 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5467 * the status code defined in the DPP R2 tech spec.
5468 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5469 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005470 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005471 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5472 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5473 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005474 wpa_s->current_ssid->dpp_pfs == 0 &&
5475 (data->assoc_reject.status_code ==
5476 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5477 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5478 struct wpa_ssid *ssid = wpa_s->current_ssid;
5479 struct wpa_bss *bss = wpa_s->current_bss;
5480
5481 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5482 if (!bss)
5483 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5484 if (!bss || wpa_s->dpp_pfs_fallback) {
5485 wpa_printf(MSG_DEBUG,
5486 "DPP: Updated PFS policy for next try");
5487 wpas_connection_failed(wpa_s, bssid);
5488 wpa_supplicant_mark_disassoc(wpa_s);
5489 return;
5490 }
5491 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5492 wpa_s->dpp_pfs_fallback = 1;
5493 wpas_connect_work_done(wpa_s);
5494 wpa_supplicant_mark_disassoc(wpa_s);
5495 wpa_supplicant_connect(wpa_s, bss, ssid);
5496 return;
5497 }
5498#endif /* CONFIG_DPP2 */
5499
Hai Shalom74f70d42019-02-11 14:42:39 -08005500#ifdef CONFIG_MBO
5501 if (data->assoc_reject.status_code ==
5502 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005503 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005504 const u8 *rssi_rej;
5505
5506 rssi_rej = mbo_get_attr_from_ies(
5507 data->assoc_reject.resp_ies,
5508 data->assoc_reject.resp_ies_len,
5509 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5510 if (rssi_rej && rssi_rej[1] == 2) {
5511 wpa_printf(MSG_DEBUG,
5512 "OCE: RSSI-based association rejection from "
5513 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005514 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005515 rssi_rej[2], rssi_rej[3]);
5516 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005517 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005518 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005519 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005520 }
5521 }
5522#endif /* CONFIG_MBO */
5523
Roshan Pius3a1667e2018-07-03 15:17:14 -07005524 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5525 sme_event_assoc_reject(wpa_s, data);
5526 return;
5527 }
5528
5529 /* Driver-based SME cases */
5530
5531#ifdef CONFIG_SAE
5532 if (wpa_s->current_ssid &&
5533 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5534 !data->assoc_reject.timed_out) {
5535 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5536 wpa_sm_aborted_cached(wpa_s->wpa);
5537 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5538 }
5539#endif /* CONFIG_SAE */
5540
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005541#ifdef CONFIG_DPP
5542 if (wpa_s->current_ssid &&
5543 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5544 !data->assoc_reject.timed_out) {
5545 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5546 wpa_sm_aborted_cached(wpa_s->wpa);
5547 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5548 }
5549#endif /* CONFIG_DPP */
5550
Roshan Pius3a1667e2018-07-03 15:17:14 -07005551#ifdef CONFIG_FILS
5552 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005553 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005554 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005555 eapol_sm_update_erp_next_seq_num(
5556 wpa_s->eapol,
5557 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005558 fils_connection_failure(wpa_s);
5559 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005560#endif /* CONFIG_FILS */
5561
5562 wpas_connection_failed(wpa_s, bssid);
5563 wpa_supplicant_mark_disassoc(wpa_s);
5564}
5565
5566
Hai Shalomfdcde762020-04-02 11:19:20 -07005567static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5568 struct unprot_beacon *data)
5569{
5570 struct wpabuf *buf;
5571 int res;
5572
5573 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5574 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5575 return;
5576 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5577 MAC2STR(data->sa));
5578
5579 buf = wpabuf_alloc(4);
5580 if (!buf)
5581 return;
5582
5583 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5584 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5585 wpabuf_put_u8(buf, 1); /* Dialog Token */
5586 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5587
5588 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5589 wpa_s->own_addr, wpa_s->bssid,
5590 wpabuf_head(buf), wpabuf_len(buf), 0);
5591 if (res < 0)
5592 wpa_printf(MSG_DEBUG,
5593 "Failed to send WNM-Notification Request frame");
5594
5595 wpabuf_free(buf);
5596}
5597
5598
Sunil Ravi640215c2023-06-28 23:08:09 +00005599static const char * bitmap_to_str(u8 value, char *buf)
5600{
5601 char *pos = buf;
5602 int i, k = 0;
5603
5604 for (i = 7; i >= 0; i--)
5605 pos[k++] = (value & BIT(i)) ? '1' : '0';
5606
5607 pos[8] = '\0';
5608 return pos;
5609}
5610
5611
5612static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
5613 struct tid_link_map_info *info)
5614{
5615 char map_info[1000], *pos, *end;
5616 int res, i;
5617
5618 pos = map_info;
5619 end = pos + sizeof(map_info);
5620 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
5621 info->default_map);
5622 if (os_snprintf_error(end - pos, res))
5623 return;
5624 pos += res;
5625
5626 if (!info->default_map) {
5627 for (i = 0; i < MAX_NUM_MLD_LINKS && end > pos; i++) {
5628 char uplink_map_str[9];
5629 char downlink_map_str[9];
5630
5631 if (!(info->valid_links & BIT(i)))
5632 continue;
5633
5634 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
5635 bitmap_to_str(info->t2lmap[i].downlink,
5636 downlink_map_str);
5637
5638 res = os_snprintf(pos, end - pos,
5639 " link_id=%d up_link=%s down_link=%s",
5640 i, uplink_map_str,
5641 downlink_map_str);
5642 if (os_snprintf_error(end - pos, res))
5643 return;
5644 pos += res;
5645 }
5646 }
5647
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05305648 wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP);
Sunil Ravi640215c2023-06-28 23:08:09 +00005649 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
5650}
5651
5652
5653static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
5654{
5655 u8 bssid[ETH_ALEN];
5656
5657 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
5658 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
5659 wpa_supplicant_deauthenticate(wpa_s,
5660 WLAN_REASON_DEAUTH_LEAVING);
5661 return;
5662 }
5663
5664 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
5665 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
5666 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
5667 wpas_notify_bssid_changed(wpa_s);
5668 }
5669
5670 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
5671 wpa_printf(MSG_ERROR,
5672 "LINK_RECONFIG: Failed to get MLO connection info");
5673 wpa_supplicant_deauthenticate(wpa_s,
5674 WLAN_REASON_DEAUTH_LEAVING);
5675 return;
5676 }
5677
5678 if (wpa_sm_set_ml_info(wpa_s)) {
5679 wpa_printf(MSG_ERROR,
5680 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
5681 wpa_supplicant_deauthenticate(wpa_s,
5682 WLAN_REASON_DEAUTH_LEAVING);
5683 return;
5684 }
5685
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05305686 wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL);
Sunil Ravi640215c2023-06-28 23:08:09 +00005687 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
5688 wpa_s->valid_links);
5689}
5690
5691
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005692void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5693 union wpa_event_data *data)
5694{
5695 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005696 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005697 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005698#ifndef CONFIG_NO_STDOUT_DEBUG
5699 int level = MSG_DEBUG;
5700#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005701
5702 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5703 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005704 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005705 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005706 event != EVENT_SCHED_SCAN_STOPPED) {
5707 wpa_dbg(wpa_s, MSG_DEBUG,
5708 "Ignore event %s (%d) while interface is disabled",
5709 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005710 return;
5711 }
5712
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005713#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005714 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005715 const struct ieee80211_hdr *hdr;
5716 u16 fc;
5717 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5718 fc = le_to_host16(hdr->frame_control);
5719 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5720 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5721 level = MSG_EXCESSIVE;
5722 }
5723
5724 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5725 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005726#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005727
5728 switch (event) {
5729 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005730#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005731 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5732 data->auth.ies_len))
5733 wpa_printf(MSG_DEBUG,
5734 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005735#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005736 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005737 wpa_s->auth_status_code = data->auth.status_code;
5738 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005739 break;
5740 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005741#ifdef CONFIG_TESTING_OPTIONS
5742 if (wpa_s->ignore_auth_resp) {
5743 wpa_printf(MSG_INFO,
5744 "EVENT_ASSOC - ignore_auth_resp active!");
5745 break;
5746 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005747 if (wpa_s->testing_resend_assoc) {
5748 wpa_printf(MSG_INFO,
5749 "EVENT_DEAUTH - testing_resend_assoc");
5750 break;
5751 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005752#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305753 if (wpa_s->disconnected) {
5754 wpa_printf(MSG_INFO,
5755 "Ignore unexpected EVENT_ASSOC in disconnected state");
5756 break;
5757 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005758 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005759 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005760 if (data &&
5761 (data->assoc_info.authorized ||
5762 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5763 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005764 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005765 if (data) {
5766 wpa_msg(wpa_s, MSG_INFO,
5767 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5768 data->assoc_info.subnet_status);
5769 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005770 break;
5771 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005772 wpas_event_disassoc(wpa_s,
5773 data ? &data->disassoc_info : NULL);
5774 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005775 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005776#ifdef CONFIG_TESTING_OPTIONS
5777 if (wpa_s->ignore_auth_resp) {
5778 wpa_printf(MSG_INFO,
5779 "EVENT_DEAUTH - ignore_auth_resp active!");
5780 break;
5781 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005782 if (wpa_s->testing_resend_assoc) {
5783 wpa_printf(MSG_INFO,
5784 "EVENT_DEAUTH - testing_resend_assoc");
5785 break;
5786 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005787#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005788 wpas_event_deauth(wpa_s,
5789 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005790 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00005791 case EVENT_LINK_RECONFIG:
5792 wpas_link_reconfig(wpa_s);
5793 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005794 case EVENT_MICHAEL_MIC_FAILURE:
5795 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5796 break;
5797#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005798 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005799 if (wpa_s->own_scan_requested ||
5800 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005801 struct os_reltime diff;
5802
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005803 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005804 os_reltime_sub(&wpa_s->scan_start_time,
5805 &wpa_s->scan_trigger_time, &diff);
5806 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5807 diff.sec, diff.usec);
5808 wpa_s->own_scan_requested = 0;
5809 wpa_s->own_scan_running = 1;
5810 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5811 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005812 wpa_msg_ctrl(wpa_s, MSG_INFO,
5813 WPA_EVENT_SCAN_STARTED "id=%u",
5814 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005815 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005816 wpa_msg_ctrl(wpa_s, MSG_INFO,
5817 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005818 }
5819 } else {
5820 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005821 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005822 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005823 }
5824 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005825 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005826 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5827 wpa_s->scan_res_handler = NULL;
5828 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005829 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005830 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5831 break;
5832 }
5833
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005834 if (!(data && data->scan_info.external_scan) &&
5835 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005836 struct os_reltime now, diff;
5837 os_get_reltime(&now);
5838 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5839 wpa_s->scan_start_time.sec = 0;
5840 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00005841 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005842 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5843 diff.sec, diff.usec);
5844 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005845 if (wpa_supplicant_event_scan_results(wpa_s, data))
5846 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005847 if (!(data && data->scan_info.external_scan))
5848 wpa_s->own_scan_running = 0;
5849 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005850 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005851 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005852 break;
5853#endif /* CONFIG_NO_SCAN_PROCESSING */
5854 case EVENT_ASSOCINFO:
5855 wpa_supplicant_event_associnfo(wpa_s, data);
5856 break;
5857 case EVENT_INTERFACE_STATUS:
5858 wpa_supplicant_event_interface_status(wpa_s, data);
5859 break;
5860 case EVENT_PMKID_CANDIDATE:
5861 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5862 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005863#ifdef CONFIG_TDLS
5864 case EVENT_TDLS:
5865 wpa_supplicant_event_tdls(wpa_s, data);
5866 break;
5867#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005868#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005869 case EVENT_WNM:
5870 wpa_supplicant_event_wnm(wpa_s, data);
5871 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005872#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005873#ifdef CONFIG_IEEE80211R
5874 case EVENT_FT_RESPONSE:
5875 wpa_supplicant_event_ft_response(wpa_s, data);
5876 break;
5877#endif /* CONFIG_IEEE80211R */
5878#ifdef CONFIG_IBSS_RSN
5879 case EVENT_IBSS_RSN_START:
5880 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5881 break;
5882#endif /* CONFIG_IBSS_RSN */
5883 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005884 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005885 break;
5886 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005887 /* It is possible to get this event from earlier connection */
5888 if (wpa_s->current_ssid &&
5889 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5890 wpa_dbg(wpa_s, MSG_DEBUG,
5891 "Ignore AUTH_TIMED_OUT in mesh configuration");
5892 break;
5893 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005894 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5895 sme_event_auth_timed_out(wpa_s, data);
5896 break;
5897 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005898 /* It is possible to get this event from earlier connection */
5899 if (wpa_s->current_ssid &&
5900 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5901 wpa_dbg(wpa_s, MSG_DEBUG,
5902 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5903 break;
5904 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005905 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5906 sme_event_assoc_timed_out(wpa_s, data);
5907 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005908 case EVENT_TX_STATUS:
5909 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5910 " type=%d stype=%d",
5911 MAC2STR(data->tx_status.dst),
5912 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005913#ifdef CONFIG_PASN
5914 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5915 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5916 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5917 data->tx_status.data_len,
5918 data->tx_status.ack) == 0)
5919 break;
5920#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005921#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005922 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005923#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005924 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5925 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005926 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005927 wpa_s, data->tx_status.dst,
5928 data->tx_status.data,
5929 data->tx_status.data_len,
5930 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005931 OFFCHANNEL_SEND_ACTION_SUCCESS :
5932 OFFCHANNEL_SEND_ACTION_NO_ACK);
5933#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005934 break;
5935 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005936#endif /* CONFIG_AP */
5937#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005938 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005939 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005940 /*
5941 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005942 * interface in GO mode, or via standalone AP interface.
5943 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5944 * except when the primary interface is used as a GO interface
5945 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005946 */
5947 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5948 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005949 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005950 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005951 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005952 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005953 data->tx_status.data,
5954 data->tx_status.data_len,
5955 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005956 OFFCHANNEL_SEND_ACTION_SUCCESS :
5957 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005958 break;
5959 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005960#endif /* CONFIG_OFFCHANNEL */
5961#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005962 switch (data->tx_status.type) {
5963 case WLAN_FC_TYPE_MGMT:
5964 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5965 data->tx_status.data_len,
5966 data->tx_status.stype,
5967 data->tx_status.ack);
5968 break;
5969 case WLAN_FC_TYPE_DATA:
5970 ap_tx_status(wpa_s, data->tx_status.dst,
5971 data->tx_status.data,
5972 data->tx_status.data_len,
5973 data->tx_status.ack);
5974 break;
5975 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005976#endif /* CONFIG_AP */
5977 break;
5978#ifdef CONFIG_AP
5979 case EVENT_EAPOL_TX_STATUS:
5980 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5981 data->eapol_tx_status.data,
5982 data->eapol_tx_status.data_len,
5983 data->eapol_tx_status.ack);
5984 break;
5985 case EVENT_DRIVER_CLIENT_POLL_OK:
5986 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005987 break;
5988 case EVENT_RX_FROM_UNKNOWN:
5989 if (wpa_s->ap_iface == NULL)
5990 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005991 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5992 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005993 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005994#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005995
Sunil Ravi89eba102022-09-13 21:04:37 -07005996 case EVENT_LINK_CH_SWITCH_STARTED:
5997 case EVENT_LINK_CH_SWITCH:
5998 if (!data || !wpa_s->current_ssid ||
5999 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6000 break;
6001
6002 wpa_msg(wpa_s, MSG_INFO,
6003 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6004 event == EVENT_LINK_CH_SWITCH ?
6005 WPA_EVENT_LINK_CHANNEL_SWITCH :
6006 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6007 data->ch_switch.freq,
6008 data->ch_switch.link_id,
6009 data->ch_switch.ht_enabled,
6010 data->ch_switch.ch_offset,
6011 channel_width_to_string(data->ch_switch.ch_width),
6012 data->ch_switch.cf1,
6013 data->ch_switch.cf2);
6014 if (event == EVENT_LINK_CH_SWITCH_STARTED)
6015 break;
6016
6017 wpa_s->links[data->ch_switch.link_id].freq =
6018 data->ch_switch.freq;
6019 if (wpa_s->links[data->ch_switch.link_id].bss &&
6020 wpa_s->links[data->ch_switch.link_id].bss->freq !=
6021 data->ch_switch.freq) {
6022 wpa_s->links[data->ch_switch.link_id].bss->freq =
6023 data->ch_switch.freq;
6024 notify_bss_changes(
6025 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6026 wpa_s->links[data->ch_switch.link_id].bss);
Shuibing Dai0db6bb12023-09-28 17:53:17 -07006027 if (data->ch_switch.freq)
6028 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
Sunil Ravi89eba102022-09-13 21:04:37 -07006029 }
6030 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07006031 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07006032 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006033 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006034 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006035
Hai Shalom81f62d82019-07-22 12:10:00 -07006036 wpa_msg(wpa_s, MSG_INFO,
6037 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6038 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6039 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006040 data->ch_switch.freq,
6041 data->ch_switch.ht_enabled,
6042 data->ch_switch.ch_offset,
6043 channel_width_to_string(data->ch_switch.ch_width),
6044 data->ch_switch.cf1,
6045 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07006046 if (event == EVENT_CH_SWITCH_STARTED)
6047 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006048
Sunil Ravi65a724b2022-05-24 11:06:09 -07006049 if (wpa_s->assoc_freq && data->ch_switch.freq &&
6050 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
6051 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
6052 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006053 wpa_s->assoc_freq = data->ch_switch.freq;
6054 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08006055 if (wpa_s->current_bss &&
6056 wpa_s->current_bss->freq != data->ch_switch.freq) {
6057 wpa_s->current_bss->freq = data->ch_switch.freq;
6058 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6059 wpa_s->current_bss);
6060 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006061
Hai Shalomfdcde762020-04-02 11:19:20 -07006062#ifdef CONFIG_SME
6063 switch (data->ch_switch.ch_offset) {
6064 case 1:
6065 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6066 break;
6067 case -1:
6068 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6069 break;
6070 default:
6071 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6072 break;
6073 }
6074#endif /* CONFIG_SME */
6075
Roshan Pius3a1667e2018-07-03 15:17:14 -07006076#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006077 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6078 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08006079 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006080 wpa_s->current_ssid->mode ==
6081 WPAS_MODE_P2P_GROUP_FORMATION) {
6082 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6083 data->ch_switch.ht_enabled,
6084 data->ch_switch.ch_offset,
6085 data->ch_switch.ch_width,
6086 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006087 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07006088 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07006089 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006090 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006091#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006092
Hai Shalom899fcc72020-10-19 14:38:18 -07006093 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6094 sme_event_ch_switch(wpa_s);
6095
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006096 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006097 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006098 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006099#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006100#ifdef NEED_AP_MLME
6101 case EVENT_DFS_RADAR_DETECTED:
6102 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07006103 wpas_ap_event_dfs_radar_detected(wpa_s,
6104 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006105 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006106 case EVENT_DFS_NOP_FINISHED:
6107 if (data)
6108 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
6109 &data->dfs_event);
6110 break;
6111#endif /* NEED_AP_MLME */
6112#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006113 case EVENT_DFS_CAC_STARTED:
6114 if (data)
6115 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
6116 break;
6117 case EVENT_DFS_CAC_FINISHED:
6118 if (data)
6119 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
6120 break;
6121 case EVENT_DFS_CAC_ABORTED:
6122 if (data)
6123 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
6124 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006125 case EVENT_RX_MGMT: {
6126 u16 fc, stype;
6127 const struct ieee80211_mgmt *mgmt;
6128
Dmitry Shmidt818ea482014-03-10 13:15:21 -07006129#ifdef CONFIG_TESTING_OPTIONS
6130 if (wpa_s->ext_mgmt_frame_handling) {
6131 struct rx_mgmt *rx = &data->rx_mgmt;
6132 size_t hex_len = 2 * rx->frame_len + 1;
6133 char *hex = os_malloc(hex_len);
6134 if (hex) {
6135 wpa_snprintf_hex(hex, hex_len,
6136 rx->frame, rx->frame_len);
6137 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
6138 rx->freq, rx->datarate, rx->ssi_signal,
6139 hex);
6140 os_free(hex);
6141 }
6142 break;
6143 }
6144#endif /* CONFIG_TESTING_OPTIONS */
6145
Dmitry Shmidt04949592012-07-19 12:16:46 -07006146 mgmt = (const struct ieee80211_mgmt *)
6147 data->rx_mgmt.frame;
6148 fc = le_to_host16(mgmt->frame_control);
6149 stype = WLAN_FC_GET_STYPE(fc);
6150
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006151#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006152 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006153#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006154#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006155 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006156 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006157 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07006158 const u8 *ie;
6159 size_t ie_len;
6160
6161 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6162 ie_len = data->rx_mgmt.frame_len -
6163 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006164 wpas_p2p_probe_req_rx(
6165 wpa_s, src, mgmt->da,
6166 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006167 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006168 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006169 break;
6170 }
6171#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006172#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006173 if (wpa_s->current_ssid &&
6174 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
6175 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006176 data->rx_mgmt.frame_len >= 30) {
6177 wpa_supplicant_event_ibss_auth(wpa_s, data);
6178 break;
6179 }
6180#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006181
6182 if (stype == WLAN_FC_STYPE_ACTION) {
6183 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07006184 wpa_s, data->rx_mgmt.frame,
6185 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006186 data->rx_mgmt.freq,
6187 data->rx_mgmt.ssi_signal);
6188 break;
6189 }
6190
6191 if (wpa_s->ifmsh) {
6192 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006193 break;
6194 }
Hai Shalom60840252021-02-19 19:02:11 -08006195#ifdef CONFIG_PASN
6196 if (stype == WLAN_FC_STYPE_AUTH &&
6197 wpas_pasn_auth_rx(wpa_s, mgmt,
6198 data->rx_mgmt.frame_len) != -2)
6199 break;
6200#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006201
Roshan Pius3a1667e2018-07-03 15:17:14 -07006202#ifdef CONFIG_SAE
6203 if (stype == WLAN_FC_STYPE_AUTH &&
6204 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6205 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6206 sme_external_auth_mgmt_rx(
6207 wpa_s, data->rx_mgmt.frame,
6208 data->rx_mgmt.frame_len);
6209 break;
6210 }
6211#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006212 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6213 "management frame in non-AP mode");
6214 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006215#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006216 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006217
6218 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006219 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6220 const u8 *ie;
6221 size_t ie_len;
6222
6223 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6224 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006225
6226 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6227 mgmt->bssid, ie, ie_len,
6228 data->rx_mgmt.ssi_signal);
6229 }
6230
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006231 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006232#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006233 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006234 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006235 case EVENT_RX_PROBE_REQ:
6236 if (data->rx_probe_req.sa == NULL ||
6237 data->rx_probe_req.ie == NULL)
6238 break;
6239#ifdef CONFIG_AP
6240 if (wpa_s->ap_iface) {
6241 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6242 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006243 data->rx_probe_req.da,
6244 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006245 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006246 data->rx_probe_req.ie_len,
6247 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006248 break;
6249 }
6250#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006251 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006252 data->rx_probe_req.da,
6253 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006254 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006255 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006256 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006257 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006258 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006259 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006260#ifdef CONFIG_OFFCHANNEL
6261 offchannel_remain_on_channel_cb(
6262 wpa_s, data->remain_on_channel.freq,
6263 data->remain_on_channel.duration);
6264#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006265 wpas_p2p_remain_on_channel_cb(
6266 wpa_s, data->remain_on_channel.freq,
6267 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006268#ifdef CONFIG_DPP
6269 wpas_dpp_remain_on_channel_cb(
6270 wpa_s, data->remain_on_channel.freq,
6271 data->remain_on_channel.duration);
6272#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006273 break;
6274 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006275#ifdef CONFIG_OFFCHANNEL
6276 offchannel_cancel_remain_on_channel_cb(
6277 wpa_s, data->remain_on_channel.freq);
6278#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006279 wpas_p2p_cancel_remain_on_channel_cb(
6280 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006281#ifdef CONFIG_DPP
6282 wpas_dpp_cancel_remain_on_channel_cb(
6283 wpa_s, data->remain_on_channel.freq);
6284#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006285 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006286 case EVENT_EAPOL_RX:
6287 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6288 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00006289 data->eapol_rx.data_len,
6290 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006291 break;
6292 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006293 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00006294 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006295 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006296 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006297 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006298 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006299 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006300 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006301 bgscan_notify_signal_change(
6302 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006303 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006304 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006305 data->signal_change.data.current_tx_rate);
6306 os_memcpy(&wpa_s->last_signal_info, data,
6307 sizeof(struct wpa_signal_info));
6308 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006309 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006310 case EVENT_INTERFACE_MAC_CHANGED:
6311 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006312 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006313 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006314 case EVENT_INTERFACE_ENABLED:
6315 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6316 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006317 u8 addr[ETH_ALEN];
6318
Hai Shalomfdcde762020-04-02 11:19:20 -07006319 eloop_cancel_timeout(wpas_clear_disabled_interface,
6320 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08006321 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006322 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006323 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
6324 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6325 else
6326 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07006327 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006328 if (wpa_s->p2p_mgmt) {
6329 wpa_supplicant_set_state(wpa_s,
6330 WPA_DISCONNECTED);
6331 break;
6332 }
6333
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006334#ifdef CONFIG_AP
6335 if (!wpa_s->ap_iface) {
6336 wpa_supplicant_set_state(wpa_s,
6337 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006338 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006339 wpa_supplicant_req_scan(wpa_s, 0, 0);
6340 } else
6341 wpa_supplicant_set_state(wpa_s,
6342 WPA_COMPLETED);
6343#else /* CONFIG_AP */
6344 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6345 wpa_supplicant_req_scan(wpa_s, 0, 0);
6346#endif /* CONFIG_AP */
6347 }
6348 break;
6349 case EVENT_INTERFACE_DISABLED:
6350 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006351#ifdef CONFIG_P2P
6352 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6353 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6354 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6355 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006356 * Mark interface disabled if this happens to end up not
6357 * being removed as a separate P2P group interface.
6358 */
6359 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6360 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006361 * The interface was externally disabled. Remove
6362 * it assuming an external entity will start a
6363 * new session if needed.
6364 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006365 if (wpa_s->current_ssid &&
6366 wpa_s->current_ssid->p2p_group)
6367 wpas_p2p_interface_unavailable(wpa_s);
6368 else
6369 wpas_p2p_disconnect(wpa_s);
6370 /*
6371 * wpa_s instance may have been freed, so must not use
6372 * it here anymore.
6373 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006374 break;
6375 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006376 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6377 p2p_in_progress(wpa_s->global->p2p) > 1) {
6378 /* This radio work will be cancelled, so clear P2P
6379 * state as well.
6380 */
6381 p2p_stop_find(wpa_s->global->p2p);
6382 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006383#endif /* CONFIG_P2P */
6384
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006385 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6386 /*
6387 * Indicate disconnection to keep ctrl_iface events
6388 * consistent.
6389 */
6390 wpa_supplicant_event_disassoc(
6391 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6392 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006393 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07006394 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08006395 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6396 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006397 clear_at.usec = 0;
6398 } else {
6399 struct os_reltime tmp;
6400
Hai Shalom60840252021-02-19 19:02:11 -08006401 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006402 tmp.usec = 0;
6403 os_reltime_sub(&tmp, &age, &clear_at);
6404 }
6405 eloop_register_timeout(clear_at.sec, clear_at.usec,
6406 wpas_clear_disabled_interface,
6407 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08006408 radio_remove_works(wpa_s, NULL, 0);
6409
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006410 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6411 break;
6412 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006413 wpa_supplicant_update_channel_list(
6414 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006415 break;
6416 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006417 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006418 break;
6419 case EVENT_BEST_CHANNEL:
6420 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6421 "(%d %d %d)",
6422 data->best_chan.freq_24, data->best_chan.freq_5,
6423 data->best_chan.freq_overall);
6424 wpa_s->best_24_freq = data->best_chan.freq_24;
6425 wpa_s->best_5_freq = data->best_chan.freq_5;
6426 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006427 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6428 data->best_chan.freq_5,
6429 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006430 break;
6431 case EVENT_UNPROT_DEAUTH:
6432 wpa_supplicant_event_unprot_deauth(wpa_s,
6433 &data->unprot_deauth);
6434 break;
6435 case EVENT_UNPROT_DISASSOC:
6436 wpa_supplicant_event_unprot_disassoc(wpa_s,
6437 &data->unprot_disassoc);
6438 break;
6439 case EVENT_STATION_LOW_ACK:
6440#ifdef CONFIG_AP
6441 if (wpa_s->ap_iface && data)
6442 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6443 data->low_ack.addr);
6444#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006445#ifdef CONFIG_TDLS
6446 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07006447 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
6448 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006449#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006450 break;
6451 case EVENT_IBSS_PEER_LOST:
6452#ifdef CONFIG_IBSS_RSN
6453 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6454#endif /* CONFIG_IBSS_RSN */
6455 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006456 case EVENT_DRIVER_GTK_REKEY:
6457 if (os_memcmp(data->driver_gtk_rekey.bssid,
6458 wpa_s->bssid, ETH_ALEN))
6459 break;
6460 if (!wpa_s->wpa)
6461 break;
6462 wpa_sm_update_replay_ctr(wpa_s->wpa,
6463 data->driver_gtk_rekey.replay_ctr);
6464 break;
6465 case EVENT_SCHED_SCAN_STOPPED:
6466 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006467 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006468 wpa_supplicant_notify_scanning(wpa_s, 0);
6469
6470 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6471 break;
6472
6473 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006474 * If the driver stopped scanning without being requested to,
6475 * request a new scan to continue scanning for networks.
6476 */
6477 if (!wpa_s->sched_scan_stop_req &&
6478 wpa_s->wpa_state == WPA_SCANNING) {
6479 wpa_dbg(wpa_s, MSG_DEBUG,
6480 "Restart scanning after unexpected sched_scan stop event");
6481 wpa_supplicant_req_scan(wpa_s, 1, 0);
6482 break;
6483 }
6484
6485 wpa_s->sched_scan_stop_req = 0;
6486
6487 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006488 * Start a new sched scan to continue searching for more SSIDs
6489 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006490 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006491 if (wpa_s->sched_scan_timed_out) {
6492 wpa_supplicant_req_sched_scan(wpa_s);
6493 } else if (wpa_s->pno_sched_pending) {
6494 wpa_s->pno_sched_pending = 0;
6495 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006496 } else if (resched) {
6497 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006498 }
6499
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006500 break;
6501 case EVENT_WPS_BUTTON_PUSHED:
6502#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006503 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006504#endif /* CONFIG_WPS */
6505 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006506 case EVENT_AVOID_FREQUENCIES:
6507 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6508 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006509 case EVENT_CONNECT_FAILED_REASON:
6510#ifdef CONFIG_AP
6511 if (!wpa_s->ap_iface || !data)
6512 break;
6513 hostapd_event_connect_failed_reason(
6514 wpa_s->ap_iface->bss[0],
6515 data->connect_failed_reason.addr,
6516 data->connect_failed_reason.code);
6517#endif /* CONFIG_AP */
6518 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006519 case EVENT_NEW_PEER_CANDIDATE:
6520#ifdef CONFIG_MESH
6521 if (!wpa_s->ifmsh || !data)
6522 break;
6523 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6524 data->mesh_peer.ies,
6525 data->mesh_peer.ie_len);
6526#endif /* CONFIG_MESH */
6527 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006528 case EVENT_SURVEY:
6529#ifdef CONFIG_AP
6530 if (!wpa_s->ap_iface)
6531 break;
6532 hostapd_event_get_survey(wpa_s->ap_iface,
6533 &data->survey_results);
6534#endif /* CONFIG_AP */
6535 break;
6536 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006537#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006538#ifdef CONFIG_ACS
6539 if (!wpa_s->ap_iface)
6540 break;
6541 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6542 &data->acs_selected_channels);
6543#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006544#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006545 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006546 case EVENT_P2P_LO_STOP:
6547#ifdef CONFIG_P2P
6548 wpa_s->p2p_lo_started = 0;
6549 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6550 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6551 data->p2p_lo_stop.reason_code);
6552#endif /* CONFIG_P2P */
6553 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006554 case EVENT_BEACON_LOSS:
6555 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6556 break;
6557 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6558 bgscan_notify_beacon_loss(wpa_s);
6559 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006560 case EVENT_EXTERNAL_AUTH:
6561#ifdef CONFIG_SAE
6562 if (!wpa_s->current_ssid) {
6563 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6564 break;
6565 }
6566 sme_external_auth_trigger(wpa_s, data);
6567#endif /* CONFIG_SAE */
6568 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006569#ifdef CONFIG_PASN
6570 case EVENT_PASN_AUTH:
6571 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6572 break;
6573#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006574 case EVENT_PORT_AUTHORIZED:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006575#ifdef CONFIG_AP
6576 if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
6577 struct sta_info *sta;
6578
6579 sta = ap_get_sta(wpa_s->ap_iface->bss[0],
6580 data->port_authorized.sta_addr);
6581 if (sta)
6582 ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
6583 sta, 1);
6584 else
6585 wpa_printf(MSG_DEBUG,
6586 "No STA info matching port authorized event found");
6587 break;
6588 }
6589#endif /* CONFIG_AP */
Sunil Ravi77d572f2023-01-17 23:58:31 +00006590#ifndef CONFIG_NO_WPA
6591 if (data->port_authorized.td_bitmap_len) {
6592 wpa_printf(MSG_DEBUG,
6593 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
6594 data->port_authorized.td_bitmap[0]);
6595 wpas_transition_disable(
6596 wpa_s, data->port_authorized.td_bitmap[0]);
6597 }
6598#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006599 wpa_supplicant_event_port_authorized(wpa_s);
6600 break;
6601 case EVENT_STATION_OPMODE_CHANGED:
6602#ifdef CONFIG_AP
6603 if (!wpa_s->ap_iface || !data)
6604 break;
6605
6606 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6607 data->sta_opmode.addr,
6608 data->sta_opmode.smps_mode,
6609 data->sta_opmode.chan_width,
6610 data->sta_opmode.rx_nss);
6611#endif /* CONFIG_AP */
6612 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07006613 case EVENT_UNPROT_BEACON:
6614 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6615 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08006616 case EVENT_TX_WAIT_EXPIRE:
6617#ifdef CONFIG_DPP
6618 wpas_dpp_tx_wait_expire(wpa_s);
6619#endif /* CONFIG_DPP */
6620 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00006621 case EVENT_TID_LINK_MAP:
6622 if (data)
6623 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
6624 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006625 default:
6626 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6627 break;
6628 }
6629}
Dmitry Shmidte4663042016-04-04 10:07:49 -07006630
6631
6632void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6633 union wpa_event_data *data)
6634{
6635 struct wpa_supplicant *wpa_s;
6636
6637 if (event != EVENT_INTERFACE_STATUS)
6638 return;
6639
6640 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6641 if (wpa_s && wpa_s->driver->get_ifindex) {
6642 unsigned int ifindex;
6643
6644 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6645 if (ifindex != data->interface_status.ifindex) {
6646 wpa_dbg(wpa_s, MSG_DEBUG,
6647 "interface status ifindex %d mismatch (%d)",
6648 ifindex, data->interface_status.ifindex);
6649 return;
6650 }
6651 }
6652#ifdef CONFIG_MATCH_IFACE
6653 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6654 struct wpa_interface *wpa_i;
6655
6656 wpa_i = wpa_supplicant_match_iface(
6657 ctx, data->interface_status.ifname);
6658 if (!wpa_i)
6659 return;
6660 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6661 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006662 }
6663#endif /* CONFIG_MATCH_IFACE */
6664
6665 if (wpa_s)
6666 wpa_supplicant_event(wpa_s, event, data);
6667}