blob: f38611945ee5baf3a2eba7b8899d29b83cd975e8 [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) ||
Vinayak Yadawadf473bef2024-04-04 15:33:29 +05303561 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) ||
3562 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303563 wpa_ft_is_completed(wpa_s->wpa)) {
3564 return 0;
3565 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003566#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003567
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003568 /* Process FT when SME is in the driver */
3569 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3570 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003571 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003572 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3573 data->assoc_info.resp_ies,
3574 data->assoc_info.resp_ies_len,
3575 bssid) < 0) {
3576 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3577 "Reassociation Response failed");
3578 wpa_supplicant_deauthenticate(
3579 wpa_s, WLAN_REASON_INVALID_IE);
3580 return -1;
3581 }
3582 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3583 }
3584
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003585 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3586 data->assoc_info.resp_ies_len);
3587#endif /* CONFIG_IEEE80211R */
3588
Hai Shalom899fcc72020-10-19 14:38:18 -07003589 if (bssid_known)
3590 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3591 data->assoc_info.resp_ies,
3592 data->assoc_info.resp_ies_len);
3593
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003594 /* WPA/RSN IE from Beacon/ProbeResp */
3595 p = data->assoc_info.beacon_ies;
3596 l = data->assoc_info.beacon_ies_len;
3597
3598 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3599 */
3600 wpa_found = rsn_found = 0;
3601 while (p && l >= 2) {
3602 len = p[1] + 2;
3603 if (len > l) {
3604 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3605 p, l);
3606 break;
3607 }
3608 if (!wpa_found &&
3609 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3610 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3611 wpa_found = 1;
3612 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3613 }
3614
3615 if (!rsn_found &&
3616 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3617 rsn_found = 1;
3618 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3619 }
3620
Hai Shalomc3565922019-10-28 11:58:20 -07003621 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3622 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3623
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003624 l -= len;
3625 p += len;
3626 }
3627
3628 if (!wpa_found && data->assoc_info.beacon_ies)
3629 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003630 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003631 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003632 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3633 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003634 if (wpa_found || rsn_found)
3635 wpa_s->ap_ies_from_associnfo = 1;
3636
Jouni Malinen87fd2792011-05-16 18:35:42 +03003637 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3638 wpa_s->assoc_freq != data->assoc_info.freq) {
3639 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3640 "%u to %u MHz",
3641 wpa_s->assoc_freq, data->assoc_info.freq);
3642 wpa_supplicant_update_scan_results(wpa_s);
3643 }
3644
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003645 wpa_s->assoc_freq = data->assoc_info.freq;
3646
Hai Shalomc1a21442022-02-04 13:43:00 -08003647 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3648 data->assoc_info.resp_ies_len);
3649
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003650 return 0;
3651}
3652
3653
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003654static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3655{
Hai Shalomc3565922019-10-28 11:58:20 -07003656 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003657
3658 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3659 return -1;
3660
3661 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3662 return 0;
3663
3664 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3665 WPA_IE_VENDOR_TYPE);
3666 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003667 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003668
3669 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3670 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3671 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003672 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3673 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3674 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003675 return -1;
3676
3677 return 0;
3678}
3679
3680
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003681static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3682 union wpa_event_data *data)
3683{
3684#ifdef CONFIG_FST
3685 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3686 struct wpa_bss *bss = wpa_s->current_bss;
3687 const u8 *ieprb, *iebcn;
3688
3689 wpabuf_free(wpa_s->received_mb_ies);
3690 wpa_s->received_mb_ies = NULL;
3691
3692 if (ai &&
3693 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3694 wpa_printf(MSG_DEBUG,
3695 "FST: MB IEs updated from Association Response frame");
3696 return;
3697 }
3698
3699 if (ai &&
3700 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3701 wpa_printf(MSG_DEBUG,
3702 "FST: MB IEs updated from association event Beacon IEs");
3703 return;
3704 }
3705
3706 if (!bss)
3707 return;
3708
Hai Shalom60840252021-02-19 19:02:11 -08003709 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003710 iebcn = ieprb + bss->ie_len;
3711
3712 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3713 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3714 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3715 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3716#endif /* CONFIG_FST */
3717}
3718
3719
Sunil Ravi89eba102022-09-13 21:04:37 -07003720static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3721{
3722 struct driver_sta_mlo_info mlo;
3723 int i;
3724
Sunil Ravi77d572f2023-01-17 23:58:31 +00003725 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07003726 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3727 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3728 wpa_supplicant_deauthenticate(wpa_s,
3729 WLAN_REASON_DEAUTH_LEAVING);
3730 return -1;
3731 }
3732
3733 if (wpa_s->valid_links == mlo.valid_links) {
3734 bool match = true;
3735
3736 if (!mlo.valid_links)
3737 return 0;
3738
3739 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3740 if (!(mlo.valid_links & BIT(i)))
3741 continue;
3742
3743 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3744 ETH_ALEN) != 0 ||
3745 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3746 ETH_ALEN) != 0) {
3747 match = false;
3748 break;
3749 }
3750 }
3751
Sunil Ravi77d572f2023-01-17 23:58:31 +00003752 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravi89eba102022-09-13 21:04:37 -07003753 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3754 ETH_ALEN) == 0)
3755 return 0;
3756 }
3757
3758 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00003759 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07003760 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3761 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3762 if (!(wpa_s->valid_links & BIT(i)))
3763 continue;
3764
3765 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3766 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3767 wpa_s->links[i].freq = mlo.links[i].freq;
3768 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3769 }
3770
3771 return 0;
3772}
3773
3774
Sunil Ravi77d572f2023-01-17 23:58:31 +00003775static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
3776{
3777 struct driver_sta_mlo_info drv_mlo;
3778 struct wpa_sm_mlo wpa_mlo;
3779 const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
3780 int i;
3781
3782 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
3783 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
3784 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
3785 return -1;
3786 }
3787
3788 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
3789 if (!drv_mlo.valid_links)
3790 goto out;
3791
3792 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
3793 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
3794 wpa_mlo.valid_links = drv_mlo.valid_links;
3795 wpa_mlo.req_links = drv_mlo.req_links;
3796
3797 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3798 struct wpa_bss *bss;
3799
3800 if (!(drv_mlo.req_links & BIT(i)))
3801 continue;
3802
3803 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
3804 if (!bss) {
3805 wpa_supplicant_update_scan_results(wpa_s);
3806 bss = wpa_supplicant_get_new_bss(
3807 wpa_s, drv_mlo.links[i].bssid);
3808 }
3809
3810 if (!bss) {
3811 wpa_dbg(wpa_s, MSG_INFO,
3812 "Failed to get MLO link %d BSS", i);
3813 return -1;
3814 }
3815
3816 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3817 bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
3818
3819 wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
3820 wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
3821 wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
3822 wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
3823
3824 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
3825 ETH_ALEN);
3826 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
3827 ETH_ALEN);
3828 }
3829
3830out:
3831 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
3832}
3833
3834
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003835static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3836 union wpa_event_data *data)
3837{
3838 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003839 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003840 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003841#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3842 struct wpa_bss *bss;
3843#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003844#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303845 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003846#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003847
3848#ifdef CONFIG_AP
3849 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003850 if (!data)
3851 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003852 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3853 data->assoc_info.addr,
3854 data->assoc_info.req_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003855 data->assoc_info.req_ies_len, NULL, 0,
3856 NULL, data->assoc_info.reassoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003857 return;
3858 }
3859#endif /* CONFIG_AP */
3860
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003861 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003862 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003863
Andy Kuoaba17c12022-04-14 16:05:31 +08003864#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303865 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3866 struct wpa_ft_ies parse;
3867 /* Check for FT reassociation is done by the driver */
3868#ifdef CONFIG_IEEE80211R
3869 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303870 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303871 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003872 data->assoc_info.resp_ies_len, &parse, use_sha384, false) < 0) {
Mir Ali677e7482020-11-12 19:49:02 +05303873 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3874 return;
3875 }
3876 if (parse.rsn_pmkid != NULL) {
3877 wpa_set_ft_completed(wpa_s->wpa);
3878 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3879 }
3880 }
3881#endif /* CONFIG_IEEE80211R */
3882 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003883#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303884
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003885 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003886
3887 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3888 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3889 wpa_supplicant_deauthenticate(
3890 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3891 return;
3892 }
3893
Sunil Ravi89eba102022-09-13 21:04:37 -07003894 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3895 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3896 wpa_supplicant_deauthenticate(wpa_s,
3897 WLAN_REASON_DEAUTH_LEAVING);
3898 return;
3899 }
3900
Sunil Ravia04bd252022-05-02 22:54:18 -07003901 if (ft_completed &&
3902 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3903 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3904 MAC2STR(bssid));
3905 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3906 wpa_printf(MSG_ERROR,
3907 "Can't find target AP's information!");
3908 return;
3909 }
3910 wpa_supplicant_assoc_update_ie(wpa_s);
3911 }
3912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003913 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3914 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003915 /*
3916 * FILS authentication can share the same mechanism to mark the
3917 * connection fully authenticated, so set ft_completed also based on
3918 * FILS result.
3919 */
3920 if (!ft_completed)
3921 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003922
Andy Kuoaba17c12022-04-14 16:05:31 +08003923#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303924 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3925 /*
3926 * For driver based roaming, insert PSK during
3927 * the initial association
3928 */
3929 if (is_zero_ether_addr(wpa_s->bssid) &&
3930 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3931 /*
3932 * In case the driver wants to handle re-assocs,
3933 * pass it down the PMK.
3934 */
3935 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3936 wpa_sm_install_pmk(wpa_s->wpa);
3937 }
Mir Ali677e7482020-11-12 19:49:02 +05303938 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303939#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003940
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003941 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003942 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003943 if (os_reltime_initialized(&wpa_s->session_start)) {
3944 os_reltime_age(&wpa_s->session_start,
3945 &wpa_s->session_length);
3946 wpa_s->session_start.sec = 0;
3947 wpa_s->session_start.usec = 0;
3948 wpas_notify_session_length(wpa_s);
3949 } else {
3950 wpas_notify_auth_changed(wpa_s);
3951 os_get_reltime(&wpa_s->session_start);
3952 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003953 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3954 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003955 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003956 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003957 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3958 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003959 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003960
3961 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3962 wpa_clear_keys(wpa_s, bssid);
3963 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00003964 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003965 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003966 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3967 return;
3968 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003969 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003970
Hai Shalomc1a21442022-02-04 13:43:00 -08003971 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3972 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3973 return;
3974
Hai Shalomfdcde762020-04-02 11:19:20 -07003975 multi_ap_set_4addr_mode(wpa_s);
3976
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003977 if (wpa_s->conf->ap_scan == 1 &&
3978 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003979 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3980 wpa_msg(wpa_s, MSG_WARNING,
3981 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003982 }
3983
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003984 wpas_fst_update_mb_assoc(wpa_s, data);
3985
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003986#ifdef CONFIG_SME
Sunil Ravi640215c2023-06-28 23:08:09 +00003987 /*
3988 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
3989 * (for MLO connection) as the previous BSSID for subsequent
3990 * reassociation requests handled by SME-in-wpa_supplicant.
3991 */
3992 os_memcpy(wpa_s->sme.prev_bssid,
3993 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003994 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003995 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003996#endif /* CONFIG_SME */
3997
3998 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3999 if (wpa_s->current_ssid) {
4000 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
4001 * initialized before association, but for other modes,
4002 * initialize PC/SC here, if the current configuration needs
4003 * smartcard or SIM/USIM. */
4004 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
4005 }
4006 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004007
4008 if (wpa_sm_set_ml_info(wpa_s)) {
4009 wpa_dbg(wpa_s, MSG_INFO,
4010 "Failed to set MLO connection info to wpa_sm");
4011 wpa_supplicant_deauthenticate(wpa_s,
4012 WLAN_REASON_DEAUTH_LEAVING);
4013 return;
4014 }
4015
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004016 if (wpa_s->l2)
4017 l2_packet_notify_auth_start(wpa_s->l2);
4018
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004019 already_authorized = data && data->assoc_info.authorized;
4020
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004021 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07004022 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004023 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
4024 * state machine may transit to AUTHENTICATING state based on obsolete
4025 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
4026 * AUTHENTICATED without ever giving chance to EAP state machine to
4027 * reset the state.
4028 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004029 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07004030 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4031 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004032 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004033 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4034 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
4035 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07004036 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07004037 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004038 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07004039 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004040 wpa_s->eapol_received = 0;
4041 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4042 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4043 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004044 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07004045 if (wpa_s->current_ssid &&
4046 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004047 (wpa_s->drv_flags &
4048 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4049 /*
4050 * Set the key after having received joined-IBSS event
4051 * from the driver.
4052 */
4053 wpa_supplicant_set_wpa_none_key(wpa_s,
4054 wpa_s->current_ssid);
4055 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004056 wpa_supplicant_cancel_auth_timeout(wpa_s);
4057 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4058 } else if (!ft_completed) {
4059 /* Timeout for receiving the first EAPOL packet */
4060 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
4061 }
4062 wpa_supplicant_cancel_scan(wpa_s);
4063
Hai Shalom5f92bc92019-04-18 11:54:11 -07004064 if (ft_completed) {
4065 /*
4066 * FT protocol completed - make sure EAPOL state machine ends
4067 * up in authenticated.
4068 */
4069 wpa_supplicant_cancel_auth_timeout(wpa_s);
4070 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004071 eapol_sm_notify_portValid(wpa_s->eapol, true);
4072 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07004073 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4074 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304075 if (already_authorized) {
4076 /*
4077 * We are done; the driver will take care of RSN 4-way
4078 * handshake.
4079 */
4080 wpa_supplicant_cancel_auth_timeout(wpa_s);
4081 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4082 eapol_sm_notify_portValid(wpa_s->eapol, true);
4083 eapol_sm_notify_eap_success(wpa_s->eapol, true);
4084 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00004085 /* Update port, WPA_COMPLETED state from the
4086 * EVENT_PORT_AUTHORIZED handler when the driver is done
4087 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304088 */
Sunil Ravi167279a2023-05-31 01:12:34 +00004089 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00004090 wpa_msg(wpa_s, MSG_INFO,
4091 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05304092 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004093 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004094 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4095 /*
4096 * The driver will take care of RSN 4-way handshake, so we need
4097 * to allow EAPOL supplicant to complete its work without
4098 * waiting for WPA supplicant.
4099 */
Hai Shalome21d4e82020-04-29 16:34:06 -07004100 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004101 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004102#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05304103 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
4104 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4105 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
4106 wpa_s->key_mgmt);
4107 wpa_supplicant_deauthenticate(
4108 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4109 return;
4110 }
4111 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4112 wpa_s->assoc_freq = data->assoc_info.freq;
4113 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
4114 }
Andy Kuoaba17c12022-04-14 16:05:31 +08004115#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
4116
Jouni Malinena05074c2012-12-21 21:35:35 +02004117 wpa_s->last_eapol_matches_bssid = 0;
4118
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004119#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07004120 if (wpa_s->rsne_override_eapol) {
4121 wpa_printf(MSG_DEBUG,
4122 "TESTING: RSNE EAPOL-Key msg 2/4 override");
4123 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4124 wpabuf_head(wpa_s->rsne_override_eapol),
4125 wpabuf_len(wpa_s->rsne_override_eapol));
4126 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004127 if (wpa_s->rsnxe_override_eapol) {
4128 wpa_printf(MSG_DEBUG,
4129 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4130 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4131 wpabuf_head(wpa_s->rsnxe_override_eapol),
4132 wpabuf_len(wpa_s->rsnxe_override_eapol));
4133 }
4134#endif /* CONFIG_TESTING_OPTIONS */
4135
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004136 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004137 struct os_reltime now, age;
4138 os_get_reltime(&now);
4139 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08004140 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00004141 os_memcmp(wpa_s->pending_eapol_rx_src,
4142 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid,
4143 ETH_ALEN) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004144 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4145 "frame that was received just before "
4146 "association notification");
4147 wpa_supplicant_rx_eapol(
4148 wpa_s, wpa_s->pending_eapol_rx_src,
4149 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00004150 wpabuf_len(wpa_s->pending_eapol_rx),
4151 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004152 }
4153 wpabuf_free(wpa_s->pending_eapol_rx);
4154 wpa_s->pending_eapol_rx = NULL;
4155 }
4156
Hai Shalomfdcde762020-04-02 11:19:20 -07004157#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004158 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4159 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07004160 wpa_s->current_ssid &&
4161 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004162 /* Set static WEP keys again */
4163 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4164 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004165#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004166
4167#ifdef CONFIG_IBSS_RSN
4168 if (wpa_s->current_ssid &&
4169 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4170 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4171 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4172 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004173 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004174 if (!wpa_s->ibss_rsn) {
4175 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4176 wpa_supplicant_deauthenticate(
4177 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4178 return;
4179 }
4180
4181 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4182 }
4183#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004184
4185 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004186
4187 if (data) {
4188 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4189 data->assoc_info.resp_ies_len,
4190 &data->assoc_info.wmm_params);
4191
4192 if (wpa_s->reassoc_same_bss)
4193 wmm_ac_restore_tspecs(wpa_s);
4194 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004195
Hai Shalomc3565922019-10-28 11:58:20 -07004196#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4197 bss = wpa_bss_get_bssid(wpa_s, bssid);
4198#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004199#ifdef CONFIG_FILS
4200 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004201 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4202
4203 if (fils_cache_id)
4204 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4205 }
4206#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004207
4208#ifdef CONFIG_MBO
4209 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4210#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004211
4212#ifdef CONFIG_DPP2
4213 wpa_s->dpp_pfs_fallback = 0;
4214#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004215
4216 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4217 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004218}
4219
4220
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004221static int disconnect_reason_recoverable(u16 reason_code)
4222{
4223 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4224 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4225 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4226}
4227
4228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004229static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004230 u16 reason_code,
4231 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004232{
4233 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004234
4235 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4236 /*
4237 * At least Host AP driver and a Prism3 card seemed to be
4238 * generating streams of disconnected events when configuring
4239 * IBSS for WPA-None. Ignore them for now.
4240 */
4241 return;
4242 }
4243
4244 bssid = wpa_s->bssid;
4245 if (is_zero_ether_addr(bssid))
4246 bssid = wpa_s->pending_bssid;
4247
4248 if (!is_zero_ether_addr(bssid) ||
4249 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4250 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4251 " reason=%d%s",
4252 MAC2STR(bssid), reason_code,
4253 locally_generated ? " locally_generated=1" : "");
4254 }
4255}
4256
4257
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004258static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4259 int locally_generated)
4260{
4261 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004262 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004263 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4264 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004265 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004266
4267 /*
4268 * It looks like connection was lost while trying to go through PSK
4269 * 4-way handshake. Filter out known disconnection cases that are caused
4270 * by something else than PSK mismatch to avoid confusing reports.
4271 */
4272
4273 if (locally_generated) {
4274 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4275 return 0;
4276 }
4277
4278 return 1;
4279}
4280
4281
Jouni Malinen2b89da82012-08-31 22:04:41 +03004282static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4283 u16 reason_code,
4284 int locally_generated)
4285{
4286 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004287 int authenticating;
4288 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004289 struct wpa_bss *fast_reconnect = NULL;
4290 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004291 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004292 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004293
4294 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
4295 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
4296
4297 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4298 /*
4299 * At least Host AP driver and a Prism3 card seemed to be
4300 * generating streams of disconnected events when configuring
4301 * IBSS for WPA-None. Ignore them for now.
4302 */
4303 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4304 "IBSS/WPA-None mode");
4305 return;
4306 }
4307
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004308 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4309 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4310 locally_generated)
4311 /*
4312 * Remove the inactive AP (which is probably out of range) from
4313 * the BSS list after marking disassociation. In particular
4314 * mac80211-based drivers use the
4315 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4316 * locally generated disconnection events for cases where the
4317 * AP does not reply anymore.
4318 */
4319 curr = wpa_s->current_bss;
4320
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004321 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004322 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4323 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004324 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4325 return; /* P2P group removed */
Sunil Ravi77d572f2023-01-17 23:58:31 +00004326 wpas_auth_failed(wpa_s, "WRONG_KEY", prev_pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004327 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004328#ifdef CONFIG_DPP2
4329 wpas_dpp_send_conn_status_result(wpa_s,
4330 DPP_STATUS_AUTH_FAILURE);
4331#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004332 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004333 if (!wpa_s->disconnected &&
4334 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004335 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004336 wpas_wps_searching(wpa_s) ||
4337 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004338 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004339 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004340 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004341 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004342 wpa_s->wpa_state);
4343 if (wpa_s->wpa_state == WPA_COMPLETED &&
4344 wpa_s->current_ssid &&
4345 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004346 (wpa_s->own_reconnect_req ||
4347 (!locally_generated &&
4348 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004349 /*
4350 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004351 * us, but could allow us to get back in. This is also
4352 * triggered for cases where local reconnection request
4353 * is used to force reassociation with the same BSS.
4354 * Try to reconnect to the same BSS without a full scan
4355 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004356 */
4357 fast_reconnect = wpa_s->current_bss;
4358 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004359 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004360 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004361 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004362 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4363 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004364 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004365 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004366 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004367 "try to re-connect");
4368 wpa_s->reassociate = 0;
4369 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004370 if (!wpa_s->pno)
4371 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004372 }
4373 bssid = wpa_s->bssid;
4374 if (is_zero_ether_addr(bssid))
4375 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004376 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4377 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004378 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004379 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4380
Dmitry Shmidt04949592012-07-19 12:16:46 -07004381 if (locally_generated)
4382 wpa_s->disconnect_reason = -reason_code;
4383 else
4384 wpa_s->disconnect_reason = reason_code;
4385 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004386 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4387 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004388 wpa_clear_keys(wpa_s, wpa_s->bssid);
4389 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004390 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004391 wpa_supplicant_mark_disassoc(wpa_s);
4392
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004393 if (curr)
4394 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4395
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004396 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004397 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004398 wpa_s->current_ssid = last_ssid;
4399 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004400
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004401 if (fast_reconnect &&
4402 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4403 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4404 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4405 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004406 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004407 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004408#ifndef CONFIG_NO_SCAN_PROCESSING
4409 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4410 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4411 fast_reconnect_ssid) < 0) {
4412 /* Recover through full scan */
4413 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4414 }
4415#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004416 } else if (fast_reconnect) {
4417 /*
4418 * Could not reconnect to the same BSS due to network being
4419 * disabled. Use a new scan to match the alternative behavior
4420 * above, i.e., to continue automatic reconnection attempt in a
4421 * way that enforces disabled network rules.
4422 */
4423 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004424 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004425}
4426
4427
4428#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004429void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004430{
4431 struct wpa_supplicant *wpa_s = eloop_ctx;
4432
4433 if (!wpa_s->pending_mic_error_report)
4434 return;
4435
4436 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4437 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4438 wpa_s->pending_mic_error_report = 0;
4439}
4440#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4441
4442
4443static void
4444wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4445 union wpa_event_data *data)
4446{
4447 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004448 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004449
4450 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4451 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004452 os_get_reltime(&t);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00004453 if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004454 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004455 wpa_s->pending_mic_error_report) {
4456 if (wpa_s->pending_mic_error_report) {
4457 /*
4458 * Send the pending MIC error report immediately since
4459 * we are going to start countermeasures and AP better
4460 * do the same.
4461 */
4462 wpa_sm_key_request(wpa_s->wpa, 1,
4463 wpa_s->pending_mic_error_pairwise);
4464 }
4465
4466 /* Send the new MIC error report immediately since we are going
4467 * to start countermeasures and AP better do the same.
4468 */
4469 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4470
4471 /* initialize countermeasures */
4472 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004473
Hai Shalom60840252021-02-19 19:02:11 -08004474 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004475
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004476 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4477
4478 /*
4479 * Need to wait for completion of request frame. We do not get
4480 * any callback for the message completion, so just wait a
4481 * short while and hope for the best. */
4482 os_sleep(0, 10000);
4483
4484 wpa_drv_set_countermeasures(wpa_s, 1);
4485 wpa_supplicant_deauthenticate(wpa_s,
4486 WLAN_REASON_MICHAEL_MIC_FAILURE);
4487 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4488 wpa_s, NULL);
4489 eloop_register_timeout(60, 0,
4490 wpa_supplicant_stop_countermeasures,
4491 wpa_s, NULL);
4492 /* TODO: mark the AP rejected for 60 second. STA is
4493 * allowed to associate with another AP.. */
4494 } else {
4495#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4496 if (wpa_s->mic_errors_seen) {
4497 /*
4498 * Reduce the effectiveness of Michael MIC error
4499 * reports as a means for attacking against TKIP if
4500 * more than one MIC failure is noticed with the same
4501 * PTK. We delay the transmission of the reports by a
4502 * random time between 0 and 60 seconds in order to
4503 * force the attacker wait 60 seconds before getting
4504 * the information on whether a frame resulted in a MIC
4505 * failure.
4506 */
4507 u8 rval[4];
4508 int sec;
4509
4510 if (os_get_random(rval, sizeof(rval)) < 0)
4511 sec = os_random() % 60;
4512 else
4513 sec = WPA_GET_BE32(rval) % 60;
4514 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4515 "report %d seconds", sec);
4516 wpa_s->pending_mic_error_report = 1;
4517 wpa_s->pending_mic_error_pairwise = pairwise;
4518 eloop_cancel_timeout(
4519 wpa_supplicant_delayed_mic_error_report,
4520 wpa_s, NULL);
4521 eloop_register_timeout(
4522 sec, os_random() % 1000000,
4523 wpa_supplicant_delayed_mic_error_report,
4524 wpa_s, NULL);
4525 } else {
4526 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4527 }
4528#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4529 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4530#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4531 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004532 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004533 wpa_s->mic_errors_seen++;
4534}
4535
4536
4537#ifdef CONFIG_TERMINATE_ONLASTIF
4538static int any_interfaces(struct wpa_supplicant *head)
4539{
4540 struct wpa_supplicant *wpa_s;
4541
4542 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4543 if (!wpa_s->interface_removed)
4544 return 1;
4545 return 0;
4546}
4547#endif /* CONFIG_TERMINATE_ONLASTIF */
4548
4549
4550static void
4551wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4552 union wpa_event_data *data)
4553{
4554 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4555 return;
4556
4557 switch (data->interface_status.ievent) {
4558 case EVENT_INTERFACE_ADDED:
4559 if (!wpa_s->interface_removed)
4560 break;
4561 wpa_s->interface_removed = 0;
4562 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4563 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4564 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4565 "driver after interface was added");
4566 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004567
4568#ifdef CONFIG_P2P
4569 if (!wpa_s->global->p2p &&
4570 !wpa_s->global->p2p_disabled &&
4571 !wpa_s->conf->p2p_disabled &&
4572 (wpa_s->drv_flags &
4573 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4574 wpas_p2p_add_p2pdev_interface(
4575 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4576 wpa_printf(MSG_INFO,
4577 "P2P: Failed to enable P2P Device interface");
4578 /* Try to continue without. P2P will be disabled. */
4579 }
4580#endif /* CONFIG_P2P */
4581
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004582 break;
4583 case EVENT_INTERFACE_REMOVED:
4584 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4585 wpa_s->interface_removed = 1;
4586 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004587 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004588 l2_packet_deinit(wpa_s->l2);
4589 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004590
4591#ifdef CONFIG_P2P
4592 if (wpa_s->global->p2p &&
4593 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4594 (wpa_s->drv_flags &
4595 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4596 wpa_dbg(wpa_s, MSG_DEBUG,
4597 "Removing P2P Device interface");
4598 wpa_supplicant_remove_iface(
4599 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4600 0);
4601 wpa_s->global->p2p_init_wpa_s = NULL;
4602 }
4603#endif /* CONFIG_P2P */
4604
Dmitry Shmidte4663042016-04-04 10:07:49 -07004605#ifdef CONFIG_MATCH_IFACE
4606 if (wpa_s->matched) {
4607 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4608 break;
4609 }
4610#endif /* CONFIG_MATCH_IFACE */
4611
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004612#ifdef CONFIG_TERMINATE_ONLASTIF
4613 /* check if last interface */
4614 if (!any_interfaces(wpa_s->global->ifaces))
4615 eloop_terminate();
4616#endif /* CONFIG_TERMINATE_ONLASTIF */
4617 break;
4618 }
4619}
4620
4621
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004622#ifdef CONFIG_TDLS
4623static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4624 union wpa_event_data *data)
4625{
4626 if (data == NULL)
4627 return;
4628 switch (data->tdls.oper) {
4629 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004630 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4631 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4632 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4633 else
4634 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004635 break;
4636 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004637 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4638 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4639 data->tdls.reason_code);
4640 else
4641 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4642 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004643 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004644 case TDLS_REQUEST_DISCOVER:
4645 wpa_tdls_send_discovery_request(wpa_s->wpa,
4646 data->tdls.peer);
4647 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004648 }
4649}
4650#endif /* CONFIG_TDLS */
4651
4652
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004653#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004654static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4655 union wpa_event_data *data)
4656{
4657 if (data == NULL)
4658 return;
4659 switch (data->wnm.oper) {
4660 case WNM_OPER_SLEEP:
4661 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4662 "(action=%d, intval=%d)",
4663 data->wnm.sleep_action, data->wnm.sleep_intval);
4664 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004665 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004666 break;
4667 }
4668}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004669#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004670
4671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004672#ifdef CONFIG_IEEE80211R
4673static void
4674wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4675 union wpa_event_data *data)
4676{
4677 if (data == NULL)
4678 return;
4679
4680 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4681 data->ft_ies.ies_len,
4682 data->ft_ies.ft_action,
4683 data->ft_ies.target_ap,
4684 data->ft_ies.ric_ies,
4685 data->ft_ies.ric_ies_len) < 0) {
4686 /* TODO: prevent MLME/driver from trying to associate? */
4687 }
4688}
4689#endif /* CONFIG_IEEE80211R */
4690
4691
4692#ifdef CONFIG_IBSS_RSN
4693static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4694 union wpa_event_data *data)
4695{
4696 struct wpa_ssid *ssid;
4697 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4698 return;
4699 if (data == NULL)
4700 return;
4701 ssid = wpa_s->current_ssid;
4702 if (ssid == NULL)
4703 return;
4704 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4705 return;
4706
4707 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4708}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004709
4710
4711static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4712 union wpa_event_data *data)
4713{
4714 struct wpa_ssid *ssid = wpa_s->current_ssid;
4715
4716 if (ssid == NULL)
4717 return;
4718
4719 /* check if the ssid is correctly configured as IBSS/RSN */
4720 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4721 return;
4722
4723 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4724 data->rx_mgmt.frame_len);
4725}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004726#endif /* CONFIG_IBSS_RSN */
4727
4728
4729#ifdef CONFIG_IEEE80211R
4730static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4731 size_t len)
4732{
4733 const u8 *sta_addr, *target_ap_addr;
4734 u16 status;
4735
4736 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4737 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4738 return; /* only SME case supported for now */
4739 if (len < 1 + 2 * ETH_ALEN + 2)
4740 return;
4741 if (data[0] != 2)
4742 return; /* Only FT Action Response is supported for now */
4743 sta_addr = data + 1;
4744 target_ap_addr = data + 1 + ETH_ALEN;
4745 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4746 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4747 MACSTR " TargetAP " MACSTR " status %u",
4748 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4749
4750 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4751 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4752 " in FT Action Response", MAC2STR(sta_addr));
4753 return;
4754 }
4755
4756 if (status) {
4757 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4758 "failure (status code %d)", status);
4759 /* TODO: report error to FT code(?) */
4760 return;
4761 }
4762
4763 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4764 len - (1 + 2 * ETH_ALEN + 2), 1,
4765 target_ap_addr, NULL, 0) < 0)
4766 return;
4767
4768#ifdef CONFIG_SME
4769 {
4770 struct wpa_bss *bss;
4771 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4772 if (bss)
4773 wpa_s->sme.freq = bss->freq;
4774 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4775 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4776 WLAN_AUTH_FT);
4777 }
4778#endif /* CONFIG_SME */
4779}
4780#endif /* CONFIG_IEEE80211R */
4781
4782
4783static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4784 struct unprot_deauth *e)
4785{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004786 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4787 "dropped: " MACSTR " -> " MACSTR
4788 " (reason code %u)",
4789 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4790 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004791}
4792
4793
4794static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4795 struct unprot_disassoc *e)
4796{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004797 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4798 "dropped: " MACSTR " -> " MACSTR
4799 " (reason code %u)",
4800 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4801 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004802}
4803
4804
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004805static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4806 u16 reason_code, int locally_generated,
4807 const u8 *ie, size_t ie_len, int deauth)
4808{
4809#ifdef CONFIG_AP
4810 if (wpa_s->ap_iface && addr) {
4811 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4812 return;
4813 }
4814
4815 if (wpa_s->ap_iface) {
4816 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4817 return;
4818 }
4819#endif /* CONFIG_AP */
4820
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004821 if (!locally_generated)
4822 wpa_s->own_disconnect_req = 0;
4823
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004824 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4825
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004826 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4827 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4828 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4829 eapol_sm_failed(wpa_s->eapol))) &&
4830 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00004831 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004832
4833#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004834 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004835 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4836 locally_generated) > 0) {
4837 /*
4838 * The interface was removed, so cannot continue
4839 * processing any additional operations after this.
4840 */
4841 return;
4842 }
4843 }
4844#endif /* CONFIG_P2P */
4845
4846 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4847 locally_generated);
4848}
4849
4850
4851static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4852 struct disassoc_info *info)
4853{
4854 u16 reason_code = 0;
4855 int locally_generated = 0;
4856 const u8 *addr = NULL;
4857 const u8 *ie = NULL;
4858 size_t ie_len = 0;
4859
4860 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4861
4862 if (info) {
4863 addr = info->addr;
4864 ie = info->ie;
4865 ie_len = info->ie_len;
4866 reason_code = info->reason_code;
4867 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004868 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4869 reason2str(reason_code),
4870 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004871 if (addr)
4872 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4873 MAC2STR(addr));
4874 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4875 ie, ie_len);
4876 }
4877
4878#ifdef CONFIG_AP
4879 if (wpa_s->ap_iface && info && info->addr) {
4880 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4881 return;
4882 }
4883
4884 if (wpa_s->ap_iface) {
4885 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4886 return;
4887 }
4888#endif /* CONFIG_AP */
4889
4890#ifdef CONFIG_P2P
4891 if (info) {
4892 wpas_p2p_disassoc_notif(
4893 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4894 locally_generated);
4895 }
4896#endif /* CONFIG_P2P */
4897
4898 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4899 sme_event_disassoc(wpa_s, info);
4900
4901 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4902 ie, ie_len, 0);
4903}
4904
4905
4906static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4907 struct deauth_info *info)
4908{
4909 u16 reason_code = 0;
4910 int locally_generated = 0;
4911 const u8 *addr = NULL;
4912 const u8 *ie = NULL;
4913 size_t ie_len = 0;
4914
4915 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4916
4917 if (info) {
4918 addr = info->addr;
4919 ie = info->ie;
4920 ie_len = info->ie_len;
4921 reason_code = info->reason_code;
4922 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004923 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4924 reason_code, reason2str(reason_code),
4925 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004926 if (addr) {
4927 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4928 MAC2STR(addr));
4929 }
4930 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4931 ie, ie_len);
4932 }
4933
4934 wpa_reset_ft_completed(wpa_s->wpa);
4935
4936 wpas_event_disconnect(wpa_s, addr, reason_code,
4937 locally_generated, ie, ie_len, 1);
4938}
4939
4940
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004941static const char * reg_init_str(enum reg_change_initiator init)
4942{
4943 switch (init) {
4944 case REGDOM_SET_BY_CORE:
4945 return "CORE";
4946 case REGDOM_SET_BY_USER:
4947 return "USER";
4948 case REGDOM_SET_BY_DRIVER:
4949 return "DRIVER";
4950 case REGDOM_SET_BY_COUNTRY_IE:
4951 return "COUNTRY_IE";
4952 case REGDOM_BEACON_HINT:
4953 return "BEACON_HINT";
4954 }
4955 return "?";
4956}
4957
4958
4959static const char * reg_type_str(enum reg_type type)
4960{
4961 switch (type) {
4962 case REGDOM_TYPE_UNKNOWN:
4963 return "UNKNOWN";
4964 case REGDOM_TYPE_COUNTRY:
4965 return "COUNTRY";
4966 case REGDOM_TYPE_WORLD:
4967 return "WORLD";
4968 case REGDOM_TYPE_CUSTOM_WORLD:
4969 return "CUSTOM_WORLD";
4970 case REGDOM_TYPE_INTERSECTION:
4971 return "INTERSECTION";
4972 }
4973 return "?";
4974}
4975
4976
Hai Shalom74f70d42019-02-11 14:42:39 -08004977void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4978 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004979{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004980 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004981 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004982
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004983 /*
4984 * To allow backwards compatibility with higher level layers that
4985 * assumed the REGDOM_CHANGE event is sent over the initially added
4986 * interface. Find the highest parent of this interface and use it to
4987 * send the event.
4988 */
4989 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4990 ;
4991
Hai Shalom74f70d42019-02-11 14:42:39 -08004992 if (info) {
4993 wpa_msg(ifs, MSG_INFO,
4994 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4995 reg_init_str(info->initiator), reg_type_str(info->type),
4996 info->alpha2[0] ? " alpha2=" : "",
4997 info->alpha2[0] ? info->alpha2 : "");
4998 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004999
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005000 if (wpa_s->drv_priv == NULL)
5001 return; /* Ignore event during drv initialization */
5002
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005003 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
5004 radio_list) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005005 bool was_6ghz_enabled;
5006
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005007 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
5008 ifs->ifname);
5009 free_hw_features(ifs);
5010 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005011 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005012
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005013 was_6ghz_enabled = ifs->is_6ghz_enabled;
5014 ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5015
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005016 /* Restart PNO/sched_scan with updated channel list */
5017 if (ifs->pno) {
5018 wpas_stop_pno(ifs);
5019 wpas_start_pno(ifs);
5020 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
5021 wpa_dbg(ifs, MSG_DEBUG,
5022 "Channel list changed - restart sched_scan");
5023 wpas_scan_restart_sched_scan(ifs);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005024 } else if (ifs->scanning && !was_6ghz_enabled &&
5025 ifs->is_6ghz_enabled) {
5026 /* Look for APs in the 6 GHz band */
5027 wpa_dbg(ifs, MSG_INFO,
5028 "Channel list changed - trigger 6 GHz-only scan");
5029 ifs->crossed_6ghz_dom = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005030 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07005031 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005032
5033 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005034}
5035
5036
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005037static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005038 const u8 *frame, size_t len, int freq,
5039 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005040{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005041 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005042 const u8 *payload;
5043 size_t plen;
5044 u8 category;
5045
5046 if (len < IEEE80211_HDRLEN + 2)
5047 return;
5048
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005049 mgmt = (const struct ieee80211_mgmt *) frame;
5050 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005051 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005052 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005053
5054 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
5055 " Category=%u DataLen=%d freq=%d MHz",
5056 MAC2STR(mgmt->sa), category, (int) plen, freq);
5057
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005058 if (category == WLAN_ACTION_WMM) {
5059 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5060 return;
5061 }
5062
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005063#ifdef CONFIG_IEEE80211R
5064 if (category == WLAN_ACTION_FT) {
5065 ft_rx_action(wpa_s, payload, plen);
5066 return;
5067 }
5068#endif /* CONFIG_IEEE80211R */
5069
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005070#ifdef CONFIG_SME
5071 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005072 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005073 return;
5074 }
5075#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005076
5077#ifdef CONFIG_WNM
5078 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
5079 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
5080 return;
5081 }
5082#endif /* CONFIG_WNM */
5083
5084#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08005085 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5086 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005087 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08005088 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005089 payload, plen, freq) == 0)
5090 return;
5091#endif /* CONFIG_GAS */
5092
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005093#ifdef CONFIG_GAS_SERVER
5094 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5095 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
5096 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
5097 mgmt->u.action.category,
5098 payload, plen, freq) == 0)
5099 return;
5100#endif /* CONFIG_GAS_SERVER */
5101
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005102#ifdef CONFIG_TDLS
5103 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
5104 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
5105 wpa_dbg(wpa_s, MSG_DEBUG,
5106 "TDLS: Received Discovery Response from " MACSTR,
5107 MAC2STR(mgmt->sa));
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005108 if (wpa_s->valid_links &&
5109 wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa,
5110 &payload[1], plen - 1))
5111 wpa_dbg(wpa_s, MSG_ERROR,
5112 "TDLS: Discovery Response process failed for "
5113 MACSTR, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005114 return;
5115 }
5116#endif /* CONFIG_TDLS */
5117
5118#ifdef CONFIG_INTERWORKING
5119 if (category == WLAN_ACTION_QOS && plen >= 1 &&
5120 payload[0] == QOS_QOS_MAP_CONFIG) {
5121 const u8 *pos = payload + 1;
5122 size_t qlen = plen - 1;
5123 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
5124 MACSTR, MAC2STR(mgmt->sa));
5125 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
5126 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
5127 pos[1] <= qlen - 2 && pos[1] >= 16)
5128 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
5129 return;
5130 }
5131#endif /* CONFIG_INTERWORKING */
5132
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005133 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005134 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5135 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005136 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005137 payload + 1,
5138 plen - 1);
5139 return;
5140 }
5141
5142 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005143 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
5144 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
5145 return;
5146 }
5147
5148 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5149 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
5150 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
5151 payload + 1, plen - 1,
5152 rssi);
5153 return;
5154 }
5155
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005156#ifdef CONFIG_FST
5157 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
5158 fst_rx_action(wpa_s->fst, mgmt, len);
5159 return;
5160 }
5161#endif /* CONFIG_FST */
5162
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005163#ifdef CONFIG_DPP
5164 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5165 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5166 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
5167 payload[4] == DPP_OUI_TYPE) {
5168 payload++;
5169 plen--;
5170 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
5171 return;
5172 }
5173#endif /* CONFIG_DPP */
5174
Hai Shalom899fcc72020-10-19 14:38:18 -07005175 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08005176 payload[0] == ROBUST_AV_SCS_RESP) {
5177 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
5178 payload + 1, plen - 1);
5179 return;
5180 }
5181
5182 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005183 payload[0] == ROBUST_AV_MSCS_RESP) {
5184 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5185 payload + 1, plen - 1);
5186 return;
5187 }
5188
Hai Shalomc1a21442022-02-04 13:43:00 -08005189 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
5190 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
5191 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
5192 payload + 4, plen - 4);
5193 return;
5194 }
5195
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005196 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5197 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005198 if (wpa_s->ifmsh)
5199 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005200}
5201
5202
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005203static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5204 union wpa_event_data *event)
5205{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005206 struct wpa_freq_range_list *list;
5207 char *str = NULL;
5208
5209 list = &event->freq_range;
5210
5211 if (list->num)
5212 str = freq_range_list_str(list);
5213 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5214 str ? str : "");
5215
5216#ifdef CONFIG_P2P
5217 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5218 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5219 __func__);
5220 } else {
5221 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005222
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005223 /*
5224 * The update channel flow will also take care of moving a GO
5225 * from the unsafe frequency if needed.
5226 */
5227 wpas_p2p_update_channel_list(wpa_s,
5228 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005229 }
5230#endif /* CONFIG_P2P */
5231
5232 os_free(str);
5233}
5234
5235
Roshan Pius3a1667e2018-07-03 15:17:14 -07005236static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005237{
Sunil Ravi167279a2023-05-31 01:12:34 +00005238 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005239 wpa_supplicant_cancel_auth_timeout(wpa_s);
5240 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005241 eapol_sm_notify_portValid(wpa_s->eapol, true);
5242 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005243 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005244 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005245}
5246
5247
5248static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5249 int freq)
5250{
5251 size_t i;
5252 int j;
5253
5254 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5255 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5256
5257 for (j = 0; j < mode->num_channels; j++) {
5258 const struct hostapd_channel_data *chan;
5259
5260 chan = &mode->channels[j];
5261 if (chan->freq == freq)
5262 return chan->dfs_cac_ms;
5263 }
5264 }
5265
5266 return 0;
5267}
5268
5269
5270static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5271 struct dfs_event *radar)
5272{
5273#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005274 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005275 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5276 } else
5277#endif /* NEED_AP_MLME && CONFIG_AP */
5278 {
5279 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5280
5281 cac_time /= 1000; /* convert from ms to sec */
5282 if (!cac_time)
5283 cac_time = 10 * 60; /* max timeout: 10 minutes */
5284
5285 /* Restart auth timeout: CAC time added to initial timeout */
5286 wpas_auth_timeout_restart(wpa_s, cac_time);
5287 }
5288}
5289
5290
5291static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5292 struct dfs_event *radar)
5293{
5294#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005295 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005296 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5297 } else
5298#endif /* NEED_AP_MLME && CONFIG_AP */
5299 {
5300 /* Restart auth timeout with original value after CAC is
5301 * finished */
5302 wpas_auth_timeout_restart(wpa_s, 0);
5303 }
5304}
5305
5306
5307static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5308 struct dfs_event *radar)
5309{
5310#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005311 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005312 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5313 } else
5314#endif /* NEED_AP_MLME && CONFIG_AP */
5315 {
5316 /* Restart auth timeout with original value after CAC is
5317 * aborted */
5318 wpas_auth_timeout_restart(wpa_s, 0);
5319 }
5320}
5321
5322
5323static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5324 union wpa_event_data *data)
5325{
5326 wpa_dbg(wpa_s, MSG_DEBUG,
5327 "Connection authorized by device, previous state %d",
5328 wpa_s->wpa_state);
5329
5330 wpa_supplicant_event_port_authorized(wpa_s);
5331
Hai Shalomc1a21442022-02-04 13:43:00 -08005332 wpa_s->last_eapol_matches_bssid = 1;
5333
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005334 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5335 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005336 data->assoc_info.ptk_kck_len,
5337 data->assoc_info.ptk_kek,
5338 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005339#ifdef CONFIG_FILS
5340 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5341 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5342 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5343
5344 /* Update ERP next sequence number */
5345 eapol_sm_update_erp_next_seq_num(
5346 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5347
5348 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5349 /* Add the new PMK and PMKID to the PMKSA cache */
5350 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5351 data->assoc_info.fils_pmk,
5352 data->assoc_info.fils_pmk_len,
5353 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005354 wpa_s->valid_links ?
5355 wpa_s->ap_mld_addr :
5356 wpa_s->bssid,
5357 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005358 } else if (data->assoc_info.fils_pmkid) {
5359 /* Update the current PMKSA used for this connection */
5360 pmksa_cache_set_current(wpa_s->wpa,
5361 data->assoc_info.fils_pmkid,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005362 NULL, NULL, 0, NULL, 0, true);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005363 }
5364 }
5365#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005366}
5367
5368
Hai Shalom60840252021-02-19 19:02:11 -08005369static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5370{
5371 switch (code) {
5372 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5373 return "";
5374 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5375 return "no_bss_found";
5376 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5377 return "auth_tx_fail";
5378 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5379 return "auth_no_ack_received";
5380 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5381 return "auth_no_resp_received";
5382 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5383 return "assoc_req_tx_fail";
5384 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5385 return "assoc_no_ack_received";
5386 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5387 return "assoc_no_resp_received";
5388 default:
5389 return "unknown_reason";
5390 }
5391}
5392
5393
Roshan Pius3a1667e2018-07-03 15:17:14 -07005394static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5395 union wpa_event_data *data)
5396{
5397 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005398#ifdef CONFIG_MBO
5399 struct wpa_bss *reject_bss;
5400#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005401
5402 if (!bssid || is_zero_ether_addr(bssid))
5403 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005404#ifdef CONFIG_MBO
5405 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5406 reject_bss = wpa_s->current_bss;
5407 else
5408 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5409#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005410
5411 if (data->assoc_reject.bssid)
5412 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005413 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005414 MAC2STR(data->assoc_reject.bssid),
5415 data->assoc_reject.status_code,
5416 data->assoc_reject.timed_out ? " timeout" : "",
5417 data->assoc_reject.timeout_reason ? "=" : "",
5418 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005419 data->assoc_reject.timeout_reason : "",
5420 data->assoc_reject.reason_code !=
5421 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5422 " qca_driver_reason=" : "",
5423 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005424 else
5425 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005426 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005427 data->assoc_reject.status_code,
5428 data->assoc_reject.timed_out ? " timeout" : "",
5429 data->assoc_reject.timeout_reason ? "=" : "",
5430 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005431 data->assoc_reject.timeout_reason : "",
5432 data->assoc_reject.reason_code !=
5433 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5434 " qca_driver_reason=" : "",
5435 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005436 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005437 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5438 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005439
5440#ifdef CONFIG_OWE
5441 if (data->assoc_reject.status_code ==
5442 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5443 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5444 wpa_s->current_ssid &&
5445 wpa_s->current_ssid->owe_group == 0 &&
5446 wpa_s->last_owe_group != 21) {
5447 struct wpa_ssid *ssid = wpa_s->current_ssid;
5448 struct wpa_bss *bss = wpa_s->current_bss;
5449
5450 if (!bss) {
5451 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5452 if (!bss) {
5453 wpas_connection_failed(wpa_s, bssid);
5454 wpa_supplicant_mark_disassoc(wpa_s);
5455 return;
5456 }
5457 }
5458 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5459 wpas_connect_work_done(wpa_s);
5460 wpa_supplicant_mark_disassoc(wpa_s);
5461 wpa_supplicant_connect(wpa_s, bss, ssid);
5462 return;
5463 }
5464#endif /* CONFIG_OWE */
5465
Hai Shalomfdcde762020-04-02 11:19:20 -07005466#ifdef CONFIG_DPP2
5467 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5468 * the status code defined in the DPP R2 tech spec.
5469 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5470 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005471 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005472 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5473 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5474 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005475 wpa_s->current_ssid->dpp_pfs == 0 &&
5476 (data->assoc_reject.status_code ==
5477 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5478 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5479 struct wpa_ssid *ssid = wpa_s->current_ssid;
5480 struct wpa_bss *bss = wpa_s->current_bss;
5481
5482 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5483 if (!bss)
5484 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5485 if (!bss || wpa_s->dpp_pfs_fallback) {
5486 wpa_printf(MSG_DEBUG,
5487 "DPP: Updated PFS policy for next try");
5488 wpas_connection_failed(wpa_s, bssid);
5489 wpa_supplicant_mark_disassoc(wpa_s);
5490 return;
5491 }
5492 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5493 wpa_s->dpp_pfs_fallback = 1;
5494 wpas_connect_work_done(wpa_s);
5495 wpa_supplicant_mark_disassoc(wpa_s);
5496 wpa_supplicant_connect(wpa_s, bss, ssid);
5497 return;
5498 }
5499#endif /* CONFIG_DPP2 */
5500
Hai Shalom74f70d42019-02-11 14:42:39 -08005501#ifdef CONFIG_MBO
5502 if (data->assoc_reject.status_code ==
5503 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005504 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005505 const u8 *rssi_rej;
5506
5507 rssi_rej = mbo_get_attr_from_ies(
5508 data->assoc_reject.resp_ies,
5509 data->assoc_reject.resp_ies_len,
5510 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5511 if (rssi_rej && rssi_rej[1] == 2) {
5512 wpa_printf(MSG_DEBUG,
5513 "OCE: RSSI-based association rejection from "
5514 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005515 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005516 rssi_rej[2], rssi_rej[3]);
5517 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005518 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005519 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005520 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005521 }
5522 }
5523#endif /* CONFIG_MBO */
5524
Roshan Pius3a1667e2018-07-03 15:17:14 -07005525 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5526 sme_event_assoc_reject(wpa_s, data);
5527 return;
5528 }
5529
5530 /* Driver-based SME cases */
5531
5532#ifdef CONFIG_SAE
5533 if (wpa_s->current_ssid &&
5534 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5535 !data->assoc_reject.timed_out) {
5536 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5537 wpa_sm_aborted_cached(wpa_s->wpa);
5538 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5539 }
5540#endif /* CONFIG_SAE */
5541
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005542#ifdef CONFIG_DPP
5543 if (wpa_s->current_ssid &&
5544 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5545 !data->assoc_reject.timed_out) {
5546 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5547 wpa_sm_aborted_cached(wpa_s->wpa);
5548 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5549 }
5550#endif /* CONFIG_DPP */
5551
Roshan Pius3a1667e2018-07-03 15:17:14 -07005552#ifdef CONFIG_FILS
5553 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005554 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005555 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005556 eapol_sm_update_erp_next_seq_num(
5557 wpa_s->eapol,
5558 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005559 fils_connection_failure(wpa_s);
5560 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005561#endif /* CONFIG_FILS */
5562
5563 wpas_connection_failed(wpa_s, bssid);
5564 wpa_supplicant_mark_disassoc(wpa_s);
5565}
5566
5567
Hai Shalomfdcde762020-04-02 11:19:20 -07005568static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5569 struct unprot_beacon *data)
5570{
5571 struct wpabuf *buf;
5572 int res;
5573
5574 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5575 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5576 return;
5577 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5578 MAC2STR(data->sa));
5579
5580 buf = wpabuf_alloc(4);
5581 if (!buf)
5582 return;
5583
5584 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5585 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5586 wpabuf_put_u8(buf, 1); /* Dialog Token */
5587 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5588
5589 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5590 wpa_s->own_addr, wpa_s->bssid,
5591 wpabuf_head(buf), wpabuf_len(buf), 0);
5592 if (res < 0)
5593 wpa_printf(MSG_DEBUG,
5594 "Failed to send WNM-Notification Request frame");
5595
5596 wpabuf_free(buf);
5597}
5598
5599
Sunil Ravi640215c2023-06-28 23:08:09 +00005600static const char * bitmap_to_str(u8 value, char *buf)
5601{
5602 char *pos = buf;
5603 int i, k = 0;
5604
5605 for (i = 7; i >= 0; i--)
5606 pos[k++] = (value & BIT(i)) ? '1' : '0';
5607
5608 pos[8] = '\0';
5609 return pos;
5610}
5611
5612
5613static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
5614 struct tid_link_map_info *info)
5615{
5616 char map_info[1000], *pos, *end;
5617 int res, i;
5618
5619 pos = map_info;
5620 end = pos + sizeof(map_info);
5621 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
5622 info->default_map);
5623 if (os_snprintf_error(end - pos, res))
5624 return;
5625 pos += res;
5626
5627 if (!info->default_map) {
5628 for (i = 0; i < MAX_NUM_MLD_LINKS && end > pos; i++) {
5629 char uplink_map_str[9];
5630 char downlink_map_str[9];
5631
5632 if (!(info->valid_links & BIT(i)))
5633 continue;
5634
5635 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
5636 bitmap_to_str(info->t2lmap[i].downlink,
5637 downlink_map_str);
5638
5639 res = os_snprintf(pos, end - pos,
5640 " link_id=%d up_link=%s down_link=%s",
5641 i, uplink_map_str,
5642 downlink_map_str);
5643 if (os_snprintf_error(end - pos, res))
5644 return;
5645 pos += res;
5646 }
5647 }
5648
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05305649 wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP);
Sunil Ravi640215c2023-06-28 23:08:09 +00005650 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
5651}
5652
5653
5654static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
5655{
5656 u8 bssid[ETH_ALEN];
5657
5658 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
5659 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
5660 wpa_supplicant_deauthenticate(wpa_s,
5661 WLAN_REASON_DEAUTH_LEAVING);
5662 return;
5663 }
5664
5665 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
5666 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
5667 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
5668 wpas_notify_bssid_changed(wpa_s);
5669 }
5670
5671 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
5672 wpa_printf(MSG_ERROR,
5673 "LINK_RECONFIG: Failed to get MLO connection info");
5674 wpa_supplicant_deauthenticate(wpa_s,
5675 WLAN_REASON_DEAUTH_LEAVING);
5676 return;
5677 }
5678
5679 if (wpa_sm_set_ml_info(wpa_s)) {
5680 wpa_printf(MSG_ERROR,
5681 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
5682 wpa_supplicant_deauthenticate(wpa_s,
5683 WLAN_REASON_DEAUTH_LEAVING);
5684 return;
5685 }
5686
Veerendranath Jakkambc2fa492023-05-25 01:26:50 +05305687 wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL);
Sunil Ravi640215c2023-06-28 23:08:09 +00005688 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
5689 wpa_s->valid_links);
5690}
5691
5692
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005693void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5694 union wpa_event_data *data)
5695{
5696 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005697 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005698 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005699#ifndef CONFIG_NO_STDOUT_DEBUG
5700 int level = MSG_DEBUG;
5701#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005702
5703 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5704 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005705 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005706 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005707 event != EVENT_SCHED_SCAN_STOPPED) {
5708 wpa_dbg(wpa_s, MSG_DEBUG,
5709 "Ignore event %s (%d) while interface is disabled",
5710 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005711 return;
5712 }
5713
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005714#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005715 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005716 const struct ieee80211_hdr *hdr;
5717 u16 fc;
5718 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5719 fc = le_to_host16(hdr->frame_control);
5720 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5721 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5722 level = MSG_EXCESSIVE;
5723 }
5724
5725 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5726 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005727#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005728
5729 switch (event) {
5730 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005731#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005732 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5733 data->auth.ies_len))
5734 wpa_printf(MSG_DEBUG,
5735 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005736#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005737 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005738 wpa_s->auth_status_code = data->auth.status_code;
5739 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005740 break;
5741 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005742#ifdef CONFIG_TESTING_OPTIONS
5743 if (wpa_s->ignore_auth_resp) {
5744 wpa_printf(MSG_INFO,
5745 "EVENT_ASSOC - ignore_auth_resp active!");
5746 break;
5747 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005748 if (wpa_s->testing_resend_assoc) {
5749 wpa_printf(MSG_INFO,
5750 "EVENT_DEAUTH - testing_resend_assoc");
5751 break;
5752 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005753#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305754 if (wpa_s->disconnected) {
5755 wpa_printf(MSG_INFO,
5756 "Ignore unexpected EVENT_ASSOC in disconnected state");
5757 break;
5758 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005759 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005760 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005761 if (data &&
5762 (data->assoc_info.authorized ||
5763 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5764 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005765 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005766 if (data) {
5767 wpa_msg(wpa_s, MSG_INFO,
5768 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5769 data->assoc_info.subnet_status);
5770 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005771 break;
5772 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005773 wpas_event_disassoc(wpa_s,
5774 data ? &data->disassoc_info : NULL);
5775 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005776 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005777#ifdef CONFIG_TESTING_OPTIONS
5778 if (wpa_s->ignore_auth_resp) {
5779 wpa_printf(MSG_INFO,
5780 "EVENT_DEAUTH - ignore_auth_resp active!");
5781 break;
5782 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005783 if (wpa_s->testing_resend_assoc) {
5784 wpa_printf(MSG_INFO,
5785 "EVENT_DEAUTH - testing_resend_assoc");
5786 break;
5787 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005788#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005789 wpas_event_deauth(wpa_s,
5790 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005791 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00005792 case EVENT_LINK_RECONFIG:
5793 wpas_link_reconfig(wpa_s);
5794 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005795 case EVENT_MICHAEL_MIC_FAILURE:
5796 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5797 break;
5798#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005799 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005800 if (wpa_s->own_scan_requested ||
5801 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005802 struct os_reltime diff;
5803
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005804 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005805 os_reltime_sub(&wpa_s->scan_start_time,
5806 &wpa_s->scan_trigger_time, &diff);
5807 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5808 diff.sec, diff.usec);
5809 wpa_s->own_scan_requested = 0;
5810 wpa_s->own_scan_running = 1;
5811 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5812 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005813 wpa_msg_ctrl(wpa_s, MSG_INFO,
5814 WPA_EVENT_SCAN_STARTED "id=%u",
5815 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005816 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005817 wpa_msg_ctrl(wpa_s, MSG_INFO,
5818 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005819 }
5820 } else {
5821 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005822 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005823 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005824 }
5825 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005826 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005827 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5828 wpa_s->scan_res_handler = NULL;
5829 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005830 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005831 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5832 break;
5833 }
5834
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005835 if (!(data && data->scan_info.external_scan) &&
5836 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005837 struct os_reltime now, diff;
5838 os_get_reltime(&now);
5839 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5840 wpa_s->scan_start_time.sec = 0;
5841 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00005842 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005843 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5844 diff.sec, diff.usec);
5845 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005846 if (wpa_supplicant_event_scan_results(wpa_s, data))
5847 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005848 if (!(data && data->scan_info.external_scan))
5849 wpa_s->own_scan_running = 0;
5850 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005851 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005852 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005853 break;
5854#endif /* CONFIG_NO_SCAN_PROCESSING */
5855 case EVENT_ASSOCINFO:
5856 wpa_supplicant_event_associnfo(wpa_s, data);
5857 break;
5858 case EVENT_INTERFACE_STATUS:
5859 wpa_supplicant_event_interface_status(wpa_s, data);
5860 break;
5861 case EVENT_PMKID_CANDIDATE:
5862 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5863 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005864#ifdef CONFIG_TDLS
5865 case EVENT_TDLS:
5866 wpa_supplicant_event_tdls(wpa_s, data);
5867 break;
5868#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005869#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005870 case EVENT_WNM:
5871 wpa_supplicant_event_wnm(wpa_s, data);
5872 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005873#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005874#ifdef CONFIG_IEEE80211R
5875 case EVENT_FT_RESPONSE:
5876 wpa_supplicant_event_ft_response(wpa_s, data);
5877 break;
5878#endif /* CONFIG_IEEE80211R */
5879#ifdef CONFIG_IBSS_RSN
5880 case EVENT_IBSS_RSN_START:
5881 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5882 break;
5883#endif /* CONFIG_IBSS_RSN */
5884 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005885 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005886 break;
5887 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005888 /* It is possible to get this event from earlier connection */
5889 if (wpa_s->current_ssid &&
5890 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5891 wpa_dbg(wpa_s, MSG_DEBUG,
5892 "Ignore AUTH_TIMED_OUT in mesh configuration");
5893 break;
5894 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005895 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5896 sme_event_auth_timed_out(wpa_s, data);
5897 break;
5898 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005899 /* It is possible to get this event from earlier connection */
5900 if (wpa_s->current_ssid &&
5901 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5902 wpa_dbg(wpa_s, MSG_DEBUG,
5903 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5904 break;
5905 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005906 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5907 sme_event_assoc_timed_out(wpa_s, data);
5908 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005909 case EVENT_TX_STATUS:
5910 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5911 " type=%d stype=%d",
5912 MAC2STR(data->tx_status.dst),
5913 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005914#ifdef CONFIG_PASN
5915 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5916 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5917 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5918 data->tx_status.data_len,
5919 data->tx_status.ack) == 0)
5920 break;
5921#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005922#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005923 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005924#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005925 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5926 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005927 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005928 wpa_s, data->tx_status.dst,
5929 data->tx_status.data,
5930 data->tx_status.data_len,
5931 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005932 OFFCHANNEL_SEND_ACTION_SUCCESS :
5933 OFFCHANNEL_SEND_ACTION_NO_ACK);
5934#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005935 break;
5936 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005937#endif /* CONFIG_AP */
5938#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005939 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005940 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005941 /*
5942 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005943 * interface in GO mode, or via standalone AP interface.
5944 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5945 * except when the primary interface is used as a GO interface
5946 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005947 */
5948 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5949 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005950 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005951 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005952 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005953 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005954 data->tx_status.data,
5955 data->tx_status.data_len,
5956 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005957 OFFCHANNEL_SEND_ACTION_SUCCESS :
5958 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005959 break;
5960 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005961#endif /* CONFIG_OFFCHANNEL */
5962#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005963 switch (data->tx_status.type) {
5964 case WLAN_FC_TYPE_MGMT:
5965 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5966 data->tx_status.data_len,
5967 data->tx_status.stype,
5968 data->tx_status.ack);
5969 break;
5970 case WLAN_FC_TYPE_DATA:
5971 ap_tx_status(wpa_s, data->tx_status.dst,
5972 data->tx_status.data,
5973 data->tx_status.data_len,
5974 data->tx_status.ack);
5975 break;
5976 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005977#endif /* CONFIG_AP */
5978 break;
5979#ifdef CONFIG_AP
5980 case EVENT_EAPOL_TX_STATUS:
5981 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5982 data->eapol_tx_status.data,
5983 data->eapol_tx_status.data_len,
5984 data->eapol_tx_status.ack);
5985 break;
5986 case EVENT_DRIVER_CLIENT_POLL_OK:
5987 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005988 break;
5989 case EVENT_RX_FROM_UNKNOWN:
5990 if (wpa_s->ap_iface == NULL)
5991 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005992 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5993 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005994 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005995#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005996
Sunil Ravi89eba102022-09-13 21:04:37 -07005997 case EVENT_LINK_CH_SWITCH_STARTED:
5998 case EVENT_LINK_CH_SWITCH:
5999 if (!data || !wpa_s->current_ssid ||
6000 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6001 break;
6002
6003 wpa_msg(wpa_s, MSG_INFO,
6004 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6005 event == EVENT_LINK_CH_SWITCH ?
6006 WPA_EVENT_LINK_CHANNEL_SWITCH :
6007 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6008 data->ch_switch.freq,
6009 data->ch_switch.link_id,
6010 data->ch_switch.ht_enabled,
6011 data->ch_switch.ch_offset,
6012 channel_width_to_string(data->ch_switch.ch_width),
6013 data->ch_switch.cf1,
6014 data->ch_switch.cf2);
6015 if (event == EVENT_LINK_CH_SWITCH_STARTED)
6016 break;
6017
6018 wpa_s->links[data->ch_switch.link_id].freq =
6019 data->ch_switch.freq;
6020 if (wpa_s->links[data->ch_switch.link_id].bss &&
6021 wpa_s->links[data->ch_switch.link_id].bss->freq !=
6022 data->ch_switch.freq) {
6023 wpa_s->links[data->ch_switch.link_id].bss->freq =
6024 data->ch_switch.freq;
6025 notify_bss_changes(
6026 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6027 wpa_s->links[data->ch_switch.link_id].bss);
Shuibing Dai0db6bb12023-09-28 17:53:17 -07006028 if (data->ch_switch.freq)
6029 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
Sunil Ravi89eba102022-09-13 21:04:37 -07006030 }
6031 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07006032 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07006033 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006034 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006035 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006036
Hai Shalom81f62d82019-07-22 12:10:00 -07006037 wpa_msg(wpa_s, MSG_INFO,
6038 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6039 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6040 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006041 data->ch_switch.freq,
6042 data->ch_switch.ht_enabled,
6043 data->ch_switch.ch_offset,
6044 channel_width_to_string(data->ch_switch.ch_width),
6045 data->ch_switch.cf1,
6046 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07006047 if (event == EVENT_CH_SWITCH_STARTED)
6048 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07006049
Sunil Ravi65a724b2022-05-24 11:06:09 -07006050 if (wpa_s->assoc_freq && data->ch_switch.freq &&
6051 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
6052 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
6053 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006054 wpa_s->assoc_freq = data->ch_switch.freq;
6055 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08006056 if (wpa_s->current_bss &&
6057 wpa_s->current_bss->freq != data->ch_switch.freq) {
6058 wpa_s->current_bss->freq = data->ch_switch.freq;
6059 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6060 wpa_s->current_bss);
6061 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006062
Hai Shalomfdcde762020-04-02 11:19:20 -07006063#ifdef CONFIG_SME
6064 switch (data->ch_switch.ch_offset) {
6065 case 1:
6066 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6067 break;
6068 case -1:
6069 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6070 break;
6071 default:
6072 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6073 break;
6074 }
6075#endif /* CONFIG_SME */
6076
Roshan Pius3a1667e2018-07-03 15:17:14 -07006077#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006078 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6079 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08006080 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006081 wpa_s->current_ssid->mode ==
6082 WPAS_MODE_P2P_GROUP_FORMATION) {
6083 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6084 data->ch_switch.ht_enabled,
6085 data->ch_switch.ch_offset,
6086 data->ch_switch.ch_width,
6087 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07006088 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07006089 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07006090 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006091 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07006092#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006093
Hai Shalom899fcc72020-10-19 14:38:18 -07006094 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6095 sme_event_ch_switch(wpa_s);
6096
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006097 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08006098 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006099 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006100#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006101#ifdef NEED_AP_MLME
6102 case EVENT_DFS_RADAR_DETECTED:
6103 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07006104 wpas_ap_event_dfs_radar_detected(wpa_s,
6105 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006106 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006107 case EVENT_DFS_NOP_FINISHED:
6108 if (data)
6109 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
6110 &data->dfs_event);
6111 break;
6112#endif /* NEED_AP_MLME */
6113#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006114 case EVENT_DFS_CAC_STARTED:
6115 if (data)
6116 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
6117 break;
6118 case EVENT_DFS_CAC_FINISHED:
6119 if (data)
6120 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
6121 break;
6122 case EVENT_DFS_CAC_ABORTED:
6123 if (data)
6124 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
6125 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006126 case EVENT_RX_MGMT: {
6127 u16 fc, stype;
6128 const struct ieee80211_mgmt *mgmt;
6129
Dmitry Shmidt818ea482014-03-10 13:15:21 -07006130#ifdef CONFIG_TESTING_OPTIONS
6131 if (wpa_s->ext_mgmt_frame_handling) {
6132 struct rx_mgmt *rx = &data->rx_mgmt;
6133 size_t hex_len = 2 * rx->frame_len + 1;
6134 char *hex = os_malloc(hex_len);
6135 if (hex) {
6136 wpa_snprintf_hex(hex, hex_len,
6137 rx->frame, rx->frame_len);
6138 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
6139 rx->freq, rx->datarate, rx->ssi_signal,
6140 hex);
6141 os_free(hex);
6142 }
6143 break;
6144 }
6145#endif /* CONFIG_TESTING_OPTIONS */
6146
Dmitry Shmidt04949592012-07-19 12:16:46 -07006147 mgmt = (const struct ieee80211_mgmt *)
6148 data->rx_mgmt.frame;
6149 fc = le_to_host16(mgmt->frame_control);
6150 stype = WLAN_FC_GET_STYPE(fc);
6151
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006152#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006153 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006154#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006155#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006156 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006157 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006158 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07006159 const u8 *ie;
6160 size_t ie_len;
6161
6162 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6163 ie_len = data->rx_mgmt.frame_len -
6164 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006165 wpas_p2p_probe_req_rx(
6166 wpa_s, src, mgmt->da,
6167 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006168 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006169 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006170 break;
6171 }
6172#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006173#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006174 if (wpa_s->current_ssid &&
6175 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
6176 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006177 data->rx_mgmt.frame_len >= 30) {
6178 wpa_supplicant_event_ibss_auth(wpa_s, data);
6179 break;
6180 }
6181#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006182
6183 if (stype == WLAN_FC_STYPE_ACTION) {
6184 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07006185 wpa_s, data->rx_mgmt.frame,
6186 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006187 data->rx_mgmt.freq,
6188 data->rx_mgmt.ssi_signal);
6189 break;
6190 }
6191
6192 if (wpa_s->ifmsh) {
6193 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006194 break;
6195 }
Hai Shalom60840252021-02-19 19:02:11 -08006196#ifdef CONFIG_PASN
6197 if (stype == WLAN_FC_STYPE_AUTH &&
6198 wpas_pasn_auth_rx(wpa_s, mgmt,
6199 data->rx_mgmt.frame_len) != -2)
6200 break;
6201#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006202
Roshan Pius3a1667e2018-07-03 15:17:14 -07006203#ifdef CONFIG_SAE
6204 if (stype == WLAN_FC_STYPE_AUTH &&
6205 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6206 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6207 sme_external_auth_mgmt_rx(
6208 wpa_s, data->rx_mgmt.frame,
6209 data->rx_mgmt.frame_len);
6210 break;
6211 }
6212#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006213 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6214 "management frame in non-AP mode");
6215 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006216#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006217 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006218
6219 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006220 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6221 const u8 *ie;
6222 size_t ie_len;
6223
6224 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6225 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006226
6227 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6228 mgmt->bssid, ie, ie_len,
6229 data->rx_mgmt.ssi_signal);
6230 }
6231
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006232 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006233#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006234 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006235 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006236 case EVENT_RX_PROBE_REQ:
6237 if (data->rx_probe_req.sa == NULL ||
6238 data->rx_probe_req.ie == NULL)
6239 break;
6240#ifdef CONFIG_AP
6241 if (wpa_s->ap_iface) {
6242 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6243 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006244 data->rx_probe_req.da,
6245 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006246 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006247 data->rx_probe_req.ie_len,
6248 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006249 break;
6250 }
6251#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006252 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006253 data->rx_probe_req.da,
6254 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006255 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006256 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006257 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006258 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006259 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006260 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006261#ifdef CONFIG_OFFCHANNEL
6262 offchannel_remain_on_channel_cb(
6263 wpa_s, data->remain_on_channel.freq,
6264 data->remain_on_channel.duration);
6265#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006266 wpas_p2p_remain_on_channel_cb(
6267 wpa_s, data->remain_on_channel.freq,
6268 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006269#ifdef CONFIG_DPP
6270 wpas_dpp_remain_on_channel_cb(
6271 wpa_s, data->remain_on_channel.freq,
6272 data->remain_on_channel.duration);
6273#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006274 break;
6275 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006276#ifdef CONFIG_OFFCHANNEL
6277 offchannel_cancel_remain_on_channel_cb(
6278 wpa_s, data->remain_on_channel.freq);
6279#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006280 wpas_p2p_cancel_remain_on_channel_cb(
6281 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006282#ifdef CONFIG_DPP
6283 wpas_dpp_cancel_remain_on_channel_cb(
6284 wpa_s, data->remain_on_channel.freq);
6285#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006286 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006287 case EVENT_EAPOL_RX:
6288 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6289 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00006290 data->eapol_rx.data_len,
6291 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006292 break;
6293 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006294 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00006295 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006296 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006297 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006298 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006299 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006300 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006301 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006302 bgscan_notify_signal_change(
6303 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006304 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006305 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006306 data->signal_change.data.current_tx_rate);
6307 os_memcpy(&wpa_s->last_signal_info, data,
6308 sizeof(struct wpa_signal_info));
6309 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006310 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006311 case EVENT_INTERFACE_MAC_CHANGED:
6312 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006313 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006314 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006315 case EVENT_INTERFACE_ENABLED:
6316 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6317 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006318 u8 addr[ETH_ALEN];
6319
Hai Shalomfdcde762020-04-02 11:19:20 -07006320 eloop_cancel_timeout(wpas_clear_disabled_interface,
6321 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08006322 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006323 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006324 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
6325 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6326 else
6327 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07006328 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006329 if (wpa_s->p2p_mgmt) {
6330 wpa_supplicant_set_state(wpa_s,
6331 WPA_DISCONNECTED);
6332 break;
6333 }
6334
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006335#ifdef CONFIG_AP
6336 if (!wpa_s->ap_iface) {
6337 wpa_supplicant_set_state(wpa_s,
6338 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006339 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006340 wpa_supplicant_req_scan(wpa_s, 0, 0);
6341 } else
6342 wpa_supplicant_set_state(wpa_s,
6343 WPA_COMPLETED);
6344#else /* CONFIG_AP */
6345 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6346 wpa_supplicant_req_scan(wpa_s, 0, 0);
6347#endif /* CONFIG_AP */
6348 }
6349 break;
6350 case EVENT_INTERFACE_DISABLED:
6351 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006352#ifdef CONFIG_P2P
6353 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6354 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6355 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6356 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006357 * Mark interface disabled if this happens to end up not
6358 * being removed as a separate P2P group interface.
6359 */
6360 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6361 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006362 * The interface was externally disabled. Remove
6363 * it assuming an external entity will start a
6364 * new session if needed.
6365 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006366 if (wpa_s->current_ssid &&
6367 wpa_s->current_ssid->p2p_group)
6368 wpas_p2p_interface_unavailable(wpa_s);
6369 else
6370 wpas_p2p_disconnect(wpa_s);
6371 /*
6372 * wpa_s instance may have been freed, so must not use
6373 * it here anymore.
6374 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006375 break;
6376 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006377 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6378 p2p_in_progress(wpa_s->global->p2p) > 1) {
6379 /* This radio work will be cancelled, so clear P2P
6380 * state as well.
6381 */
6382 p2p_stop_find(wpa_s->global->p2p);
6383 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006384#endif /* CONFIG_P2P */
6385
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006386 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6387 /*
6388 * Indicate disconnection to keep ctrl_iface events
6389 * consistent.
6390 */
6391 wpa_supplicant_event_disassoc(
6392 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6393 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006394 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07006395 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08006396 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6397 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006398 clear_at.usec = 0;
6399 } else {
6400 struct os_reltime tmp;
6401
Hai Shalom60840252021-02-19 19:02:11 -08006402 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006403 tmp.usec = 0;
6404 os_reltime_sub(&tmp, &age, &clear_at);
6405 }
6406 eloop_register_timeout(clear_at.sec, clear_at.usec,
6407 wpas_clear_disabled_interface,
6408 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08006409 radio_remove_works(wpa_s, NULL, 0);
6410
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006411 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6412 break;
6413 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006414 wpa_supplicant_update_channel_list(
6415 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006416 break;
6417 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006418 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006419 break;
6420 case EVENT_BEST_CHANNEL:
6421 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6422 "(%d %d %d)",
6423 data->best_chan.freq_24, data->best_chan.freq_5,
6424 data->best_chan.freq_overall);
6425 wpa_s->best_24_freq = data->best_chan.freq_24;
6426 wpa_s->best_5_freq = data->best_chan.freq_5;
6427 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006428 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6429 data->best_chan.freq_5,
6430 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006431 break;
6432 case EVENT_UNPROT_DEAUTH:
6433 wpa_supplicant_event_unprot_deauth(wpa_s,
6434 &data->unprot_deauth);
6435 break;
6436 case EVENT_UNPROT_DISASSOC:
6437 wpa_supplicant_event_unprot_disassoc(wpa_s,
6438 &data->unprot_disassoc);
6439 break;
6440 case EVENT_STATION_LOW_ACK:
6441#ifdef CONFIG_AP
6442 if (wpa_s->ap_iface && data)
6443 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6444 data->low_ack.addr);
6445#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006446#ifdef CONFIG_TDLS
6447 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07006448 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
6449 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006450#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006451 break;
6452 case EVENT_IBSS_PEER_LOST:
6453#ifdef CONFIG_IBSS_RSN
6454 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6455#endif /* CONFIG_IBSS_RSN */
6456 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006457 case EVENT_DRIVER_GTK_REKEY:
6458 if (os_memcmp(data->driver_gtk_rekey.bssid,
6459 wpa_s->bssid, ETH_ALEN))
6460 break;
6461 if (!wpa_s->wpa)
6462 break;
6463 wpa_sm_update_replay_ctr(wpa_s->wpa,
6464 data->driver_gtk_rekey.replay_ctr);
6465 break;
6466 case EVENT_SCHED_SCAN_STOPPED:
6467 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006468 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006469 wpa_supplicant_notify_scanning(wpa_s, 0);
6470
6471 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6472 break;
6473
6474 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006475 * If the driver stopped scanning without being requested to,
6476 * request a new scan to continue scanning for networks.
6477 */
6478 if (!wpa_s->sched_scan_stop_req &&
6479 wpa_s->wpa_state == WPA_SCANNING) {
6480 wpa_dbg(wpa_s, MSG_DEBUG,
6481 "Restart scanning after unexpected sched_scan stop event");
6482 wpa_supplicant_req_scan(wpa_s, 1, 0);
6483 break;
6484 }
6485
6486 wpa_s->sched_scan_stop_req = 0;
6487
6488 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006489 * Start a new sched scan to continue searching for more SSIDs
6490 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006491 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006492 if (wpa_s->sched_scan_timed_out) {
6493 wpa_supplicant_req_sched_scan(wpa_s);
6494 } else if (wpa_s->pno_sched_pending) {
6495 wpa_s->pno_sched_pending = 0;
6496 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006497 } else if (resched) {
6498 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006499 }
6500
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006501 break;
6502 case EVENT_WPS_BUTTON_PUSHED:
6503#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006504 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006505#endif /* CONFIG_WPS */
6506 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006507 case EVENT_AVOID_FREQUENCIES:
6508 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6509 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006510 case EVENT_CONNECT_FAILED_REASON:
6511#ifdef CONFIG_AP
6512 if (!wpa_s->ap_iface || !data)
6513 break;
6514 hostapd_event_connect_failed_reason(
6515 wpa_s->ap_iface->bss[0],
6516 data->connect_failed_reason.addr,
6517 data->connect_failed_reason.code);
6518#endif /* CONFIG_AP */
6519 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006520 case EVENT_NEW_PEER_CANDIDATE:
6521#ifdef CONFIG_MESH
6522 if (!wpa_s->ifmsh || !data)
6523 break;
6524 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6525 data->mesh_peer.ies,
6526 data->mesh_peer.ie_len);
6527#endif /* CONFIG_MESH */
6528 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006529 case EVENT_SURVEY:
6530#ifdef CONFIG_AP
6531 if (!wpa_s->ap_iface)
6532 break;
6533 hostapd_event_get_survey(wpa_s->ap_iface,
6534 &data->survey_results);
6535#endif /* CONFIG_AP */
6536 break;
6537 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006538#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006539#ifdef CONFIG_ACS
6540 if (!wpa_s->ap_iface)
6541 break;
6542 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6543 &data->acs_selected_channels);
6544#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006545#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006546 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006547 case EVENT_P2P_LO_STOP:
6548#ifdef CONFIG_P2P
6549 wpa_s->p2p_lo_started = 0;
6550 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6551 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6552 data->p2p_lo_stop.reason_code);
6553#endif /* CONFIG_P2P */
6554 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006555 case EVENT_BEACON_LOSS:
6556 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6557 break;
6558 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6559 bgscan_notify_beacon_loss(wpa_s);
6560 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006561 case EVENT_EXTERNAL_AUTH:
6562#ifdef CONFIG_SAE
6563 if (!wpa_s->current_ssid) {
6564 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6565 break;
6566 }
6567 sme_external_auth_trigger(wpa_s, data);
6568#endif /* CONFIG_SAE */
6569 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006570#ifdef CONFIG_PASN
6571 case EVENT_PASN_AUTH:
6572 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6573 break;
6574#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006575 case EVENT_PORT_AUTHORIZED:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00006576#ifdef CONFIG_AP
6577 if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
6578 struct sta_info *sta;
6579
6580 sta = ap_get_sta(wpa_s->ap_iface->bss[0],
6581 data->port_authorized.sta_addr);
6582 if (sta)
6583 ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
6584 sta, 1);
6585 else
6586 wpa_printf(MSG_DEBUG,
6587 "No STA info matching port authorized event found");
6588 break;
6589 }
6590#endif /* CONFIG_AP */
Sunil Ravi77d572f2023-01-17 23:58:31 +00006591#ifndef CONFIG_NO_WPA
6592 if (data->port_authorized.td_bitmap_len) {
6593 wpa_printf(MSG_DEBUG,
6594 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
6595 data->port_authorized.td_bitmap[0]);
6596 wpas_transition_disable(
6597 wpa_s, data->port_authorized.td_bitmap[0]);
6598 }
6599#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006600 wpa_supplicant_event_port_authorized(wpa_s);
6601 break;
6602 case EVENT_STATION_OPMODE_CHANGED:
6603#ifdef CONFIG_AP
6604 if (!wpa_s->ap_iface || !data)
6605 break;
6606
6607 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6608 data->sta_opmode.addr,
6609 data->sta_opmode.smps_mode,
6610 data->sta_opmode.chan_width,
6611 data->sta_opmode.rx_nss);
6612#endif /* CONFIG_AP */
6613 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07006614 case EVENT_UNPROT_BEACON:
6615 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6616 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08006617 case EVENT_TX_WAIT_EXPIRE:
6618#ifdef CONFIG_DPP
6619 wpas_dpp_tx_wait_expire(wpa_s);
6620#endif /* CONFIG_DPP */
6621 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00006622 case EVENT_TID_LINK_MAP:
6623 if (data)
6624 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
6625 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006626 default:
6627 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6628 break;
6629 }
6630}
Dmitry Shmidte4663042016-04-04 10:07:49 -07006631
6632
6633void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6634 union wpa_event_data *data)
6635{
6636 struct wpa_supplicant *wpa_s;
6637
6638 if (event != EVENT_INTERFACE_STATUS)
6639 return;
6640
6641 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6642 if (wpa_s && wpa_s->driver->get_ifindex) {
6643 unsigned int ifindex;
6644
6645 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6646 if (ifindex != data->interface_status.ifindex) {
6647 wpa_dbg(wpa_s, MSG_DEBUG,
6648 "interface status ifindex %d mismatch (%d)",
6649 ifindex, data->interface_status.ifindex);
6650 return;
6651 }
6652 }
6653#ifdef CONFIG_MATCH_IFACE
6654 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6655 struct wpa_interface *wpa_i;
6656
6657 wpa_i = wpa_supplicant_match_iface(
6658 ctx, data->interface_status.ifname);
6659 if (!wpa_i)
6660 return;
6661 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6662 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006663 }
6664#endif /* CONFIG_MATCH_IFACE */
6665
6666 if (wpa_s)
6667 wpa_supplicant_event(wpa_s, event, data);
6668}