blob: e83d877217871da7b0736c3a104dbe694d4bd24d [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"
25#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "notify.h"
29#include "common/ieee802_11_defs.h"
30#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070031#include "common/gas_server.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070032#include "common/dpp.h"
Hai Shalom60840252021-02-19 19:02:11 -080033#include "common/ptksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "crypto/random.h"
Hai Shalom60840252021-02-19 19:02:11 -080035#include "bssid_ignore.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "wpas_glue.h"
37#include "wps_supplicant.h"
38#include "ibss_rsn.h"
39#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080040#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "p2p_supplicant.h"
42#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070043#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044#include "ap.h"
45#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080047#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080049#include "mesh.h"
50#include "mesh_mpm.h"
51#include "wmm_ac.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070052#include "dpp_supplicant.h"
Mir Ali677e7482020-11-12 19:49:02 +053053#include "rsn_supp/wpa_i.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070054
55
Hai Shalom39ba6fc2019-01-22 12:40:38 -080056#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
57
58
Dmitry Shmidt34af3062013-07-11 10:46:32 -070059#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070060static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080061 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070062#endif /* CONFIG_NO_SCAN_PROCESSING */
Sunil Ravi640215c2023-06-28 23:08:09 +000063#ifdef CONFIG_OWE
64static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
65 const u8 **ret_ssid, size_t *ret_ssid_len);
66#endif /* CONFIG_OWE */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080067
68
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070069int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070070{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080071 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070072
73 if (ssid == NULL || ssid->disabled_until.sec == 0)
74 return 0;
75
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080076 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070077 if (ssid->disabled_until.sec > now.sec)
78 return ssid->disabled_until.sec - now.sec;
79
80 wpas_clear_temp_disabled(wpa_s, ssid, 0);
81
82 return 0;
83}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084
85
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080086#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070087/**
88 * wpas_reenabled_network_time - Time until first network is re-enabled
89 * @wpa_s: Pointer to wpa_supplicant data
90 * Returns: If all enabled networks are temporarily disabled, returns the time
91 * (in sec) until the first network is re-enabled. Otherwise returns 0.
92 *
93 * This function is used in case all enabled networks are temporarily disabled,
94 * in which case it returns the time (in sec) that the first network will be
95 * re-enabled. The function assumes that at least one network is enabled.
96 */
97static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
98{
99 struct wpa_ssid *ssid;
100 int disabled_for, res = 0;
101
102#ifdef CONFIG_INTERWORKING
103 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
104 wpa_s->conf->cred)
105 return 0;
106#endif /* CONFIG_INTERWORKING */
107
108 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
109 if (ssid->disabled)
110 continue;
111
112 disabled_for = wpas_temp_disabled(wpa_s, ssid);
113 if (!disabled_for)
114 return 0;
115
116 if (!res || disabled_for < res)
117 res = disabled_for;
118 }
119
120 return res;
121}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800122#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700123
124
125void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
126{
127 struct wpa_supplicant *wpa_s = eloop_ctx;
128
129 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
130 return;
131
132 wpa_dbg(wpa_s, MSG_DEBUG,
133 "Try to associate due to network getting re-enabled");
134 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
135 wpa_supplicant_cancel_sched_scan(wpa_s);
136 wpa_supplicant_req_scan(wpa_s, 0, 0);
137 }
138}
139
140
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800141static struct wpa_bss * wpa_supplicant_get_new_bss(
142 struct wpa_supplicant *wpa_s, const u8 *bssid)
143{
144 struct wpa_bss *bss = NULL;
145 struct wpa_ssid *ssid = wpa_s->current_ssid;
146
Sunil Ravi77d572f2023-01-17 23:58:31 +0000147 if (ssid && ssid->ssid_len > 0)
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800148 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
149 if (!bss)
150 bss = wpa_bss_get_bssid(wpa_s, bssid);
151
152 return bss;
153}
154
155
Sunil Ravia04bd252022-05-02 22:54:18 -0700156static struct wpa_bss *
157wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700158{
Sunil Ravia04bd252022-05-02 22:54:18 -0700159 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700160
161 if (!bss) {
162 wpa_supplicant_update_scan_results(wpa_s);
163
164 /* Get the BSS from the new scan results */
Sunil Ravia04bd252022-05-02 22:54:18 -0700165 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700166 }
167
168 if (bss)
169 wpa_s->current_bss = bss;
Sunil Ravia04bd252022-05-02 22:54:18 -0700170
171 return bss;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700172}
173
174
Sunil Ravi89eba102022-09-13 21:04:37 -0700175static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
176 u8 link_id, const u8 *bssid)
177{
178 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
179
180 if (!bss) {
181 wpa_supplicant_update_scan_results(wpa_s);
182 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
183 }
184
185 if (bss)
186 wpa_s->links[link_id].bss = bss;
187}
188
189
Sunil Ravi77d572f2023-01-17 23:58:31 +0000190static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
191 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192{
193 struct wpa_ssid *ssid, *old_ssid;
Sunil Ravi640215c2023-06-28 23:08:09 +0000194 struct wpa_bss *bss;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700195 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700196 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700197 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700199 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700200 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700201
202 if (wpa_s->current_ssid->ssid_len == 0)
203 return 0; /* current profile still in use */
204 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
205 if (res < 0) {
206 wpa_msg(wpa_s, MSG_INFO,
207 "Failed to read SSID from driver");
208 return 0; /* try to use current profile */
209 }
210 drv_ssid_len = res;
211
212 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
213 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
214 drv_ssid_len) == 0)
215 return 0; /* current profile still in use */
216
Hai Shalomfdcde762020-04-02 11:19:20 -0700217#ifdef CONFIG_OWE
Sunil Ravi640215c2023-06-28 23:08:09 +0000218 if (wpa_s->current_bss &&
219 !(wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION)) {
220 const u8 *match_ssid;
221 size_t match_ssid_len;
222
223 owe_trans_ssid(wpa_s, wpa_s->current_bss,
224 &match_ssid, &match_ssid_len);
225 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700226 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
227 wpa_s->current_bss &&
228 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
229 drv_ssid_len == wpa_s->current_bss->ssid_len &&
230 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
231 drv_ssid_len) == 0)
232 return 0; /* current profile still in use */
233#endif /* CONFIG_OWE */
234
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700235 wpa_msg(wpa_s, MSG_DEBUG,
236 "Driver-initiated BSS selection changed the SSID to %s",
237 wpa_ssid_txt(drv_ssid, drv_ssid_len));
238 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700239 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240
241 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
242 "information");
243 ssid = wpa_supplicant_get_ssid(wpa_s);
244 if (ssid == NULL) {
245 wpa_msg(wpa_s, MSG_INFO,
246 "No network configuration found for the current AP");
247 return -1;
248 }
249
Dmitry Shmidt04949592012-07-19 12:16:46 -0700250 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700251 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
252 return -1;
253 }
254
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800255 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
256 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
257 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
258 return -1;
259 }
260
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700261 res = wpas_temp_disabled(wpa_s, ssid);
262 if (res > 0) {
263 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
264 "disabled for %d second(s)", res);
265 return -1;
266 }
267
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
269 "current AP");
Sunil Ravi640215c2023-06-28 23:08:09 +0000270 bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800271 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272 u8 wpa_ie[80];
273 size_t wpa_ie_len = sizeof(wpa_ie);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000274 bool skip_default_rsne;
275
276 /* Do not override RSNE/RSNXE with the default values if the
277 * driver indicated the actual values used in the
278 * (Re)Association Request frame. */
279 skip_default_rsne = data && data->assoc_info.req_ies;
Sunil Ravi640215c2023-06-28 23:08:09 +0000280 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000281 wpa_ie, &wpa_ie_len,
282 skip_default_rsne) < 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800283 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700284 } else {
285 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
286 }
287
288 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
289 eapol_sm_invalidate_cached_session(wpa_s->eapol);
290 old_ssid = wpa_s->current_ssid;
291 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800292
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700293 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
294 wpa_supplicant_initiate_eapol(wpa_s);
295 if (old_ssid != wpa_s->current_ssid)
296 wpas_notify_network_changed(wpa_s);
297
298 return 0;
299}
300
301
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800302void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303{
304 struct wpa_supplicant *wpa_s = eloop_ctx;
305
306 if (wpa_s->countermeasures) {
307 wpa_s->countermeasures = 0;
308 wpa_drv_set_countermeasures(wpa_s, 0);
309 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800310
311 /*
312 * It is possible that the device is sched scanning, which means
313 * that a connection attempt will be done only when we receive
314 * scan results. However, in this case, it would be preferable
315 * to scan and connect immediately, so cancel the sched_scan and
316 * issue a regular scan flow.
317 */
318 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 wpa_supplicant_req_scan(wpa_s, 0, 0);
320 }
321}
322
323
Sunil Ravi77d572f2023-01-17 23:58:31 +0000324void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
Sunil Ravi89eba102022-09-13 21:04:37 -0700325{
Sunil Ravi89eba102022-09-13 21:04:37 -0700326 if (!wpa_s->valid_links)
327 return;
328
329 wpa_s->valid_links = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000330 wpa_s->mlo_assoc_link_id = 0;
331 os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN);
332 os_memset(wpa_s->links, 0, sizeof(wpa_s->links));
Sunil Ravi89eba102022-09-13 21:04:37 -0700333}
334
335
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
337{
338 int bssid_changed;
339
Dmitry Shmidt04949592012-07-19 12:16:46 -0700340 wnm_bss_keep_alive_deinit(wpa_s);
341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342#ifdef CONFIG_IBSS_RSN
343 ibss_rsn_deinit(wpa_s->ibss_rsn);
344 wpa_s->ibss_rsn = NULL;
345#endif /* CONFIG_IBSS_RSN */
346
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700347#ifdef CONFIG_AP
348 wpa_supplicant_ap_deinit(wpa_s);
349#endif /* CONFIG_AP */
350
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700351#ifdef CONFIG_HS20
352 /* Clear possibly configured frame filters */
353 wpa_drv_configure_frame_filters(wpa_s, 0);
354#endif /* CONFIG_HS20 */
355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700356 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
357 return;
358
Hai Shalom74f70d42019-02-11 14:42:39 -0800359 if (os_reltime_initialized(&wpa_s->session_start)) {
360 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
361 wpa_s->session_start.sec = 0;
362 wpa_s->session_start.usec = 0;
363 wpas_notify_session_length(wpa_s);
364 }
365
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700366 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
367 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
368 os_memset(wpa_s->bssid, 0, ETH_ALEN);
369 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800370 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700371 wpa_s->current_bss = NULL;
372 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700373
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700374 if (bssid_changed)
375 wpas_notify_bssid_changed(wpa_s);
376
Hai Shalome21d4e82020-04-29 16:34:06 -0700377 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
378 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700379 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
380 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700381 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700382 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700383 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700384 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700385 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700386 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700387 wpa_s->key_mgmt = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700388 wpa_s->allowed_key_mgmts = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800389
390 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800391 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800392 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700393 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700394
395#ifdef CONFIG_TESTING_OPTIONS
396 wpa_s->last_tk_alg = WPA_ALG_NONE;
397 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
398#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700399 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800400
401 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
402 wpa_s->enabled_4addr_mode = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700403
Sunil Ravi77d572f2023-01-17 23:58:31 +0000404 wpa_s->wps_scan_done = false;
Sunil Ravi89eba102022-09-13 21:04:37 -0700405 wpas_reset_mlo_info(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700406}
407
408
Sunil Ravi036cec52023-03-29 11:35:17 -0700409static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700410{
411 struct wpa_ie_data ie;
412 int pmksa_set = -1;
413 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800414 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415
Hai Shalomc1a21442022-02-04 13:43:00 -0800416 /* Start with assumption of no PMKSA cache entry match for cases other
417 * than SAE. In particular, this is needed to generate the PMKSA cache
418 * entries for Suite B cases with driver-based roaming indication. */
419 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
420 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
421 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700422
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700423 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
424 ie.pmkid == NULL)
425 return;
426
427 for (i = 0; i < ie.num_pmkid; i++) {
428 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
429 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700430 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800432 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Sunil Ravi036cec52023-03-29 11:35:17 -0700433 if (authorized)
434 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700435 break;
436 }
437 }
438
439 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
440 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
441}
442
443
444static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
445 union wpa_event_data *data)
446{
447 if (data == NULL) {
448 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
449 "event");
450 return;
451 }
452 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
453 " index=%d preauth=%d",
454 MAC2STR(data->pmkid_candidate.bssid),
455 data->pmkid_candidate.index,
456 data->pmkid_candidate.preauth);
457
458 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
459 data->pmkid_candidate.index,
460 data->pmkid_candidate.preauth);
461}
462
463
464static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
465{
466 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
467 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
468 return 0;
469
470#ifdef IEEE8021X_EAPOL
471 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
472 wpa_s->current_ssid &&
473 !(wpa_s->current_ssid->eapol_flags &
474 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
475 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
476 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
477 * plaintext or static WEP keys). */
478 return 0;
479 }
480#endif /* IEEE8021X_EAPOL */
481
482 return 1;
483}
484
485
486/**
487 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
488 * @wpa_s: pointer to wpa_supplicant data
489 * @ssid: Configuration data for the network
490 * Returns: 0 on success, -1 on failure
491 *
492 * This function is called when starting authentication with a network that is
493 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
494 */
495int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
496 struct wpa_ssid *ssid)
497{
498#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800499#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700500 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700502 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
503 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504 return 0;
505
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700506 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 sim = 1;
508 aka = 1;
509 } else {
510 struct eap_method_type *eap = ssid->eap.eap_methods;
511 while (eap->vendor != EAP_VENDOR_IETF ||
512 eap->method != EAP_TYPE_NONE) {
513 if (eap->vendor == EAP_VENDOR_IETF) {
514 if (eap->method == EAP_TYPE_SIM)
515 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700516 else if (eap->method == EAP_TYPE_AKA ||
517 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 aka = 1;
519 }
520 eap++;
521 }
522 }
523
524 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
525 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700526 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
527 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
528 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 aka = 0;
530
531 if (!sim && !aka) {
532 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
533 "use SIM, but neither EAP-SIM nor EAP-AKA are "
534 "enabled");
535 return 0;
536 }
537
538 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
539 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700540
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700541 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542 if (wpa_s->scard == NULL) {
543 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
544 "(pcsc-lite)");
545 return -1;
546 }
547 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
548 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800549#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700550#endif /* IEEE8021X_EAPOL */
551
552 return 0;
553}
554
555
556#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700557
Hai Shalomfdcde762020-04-02 11:19:20 -0700558#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700559static int has_wep_key(struct wpa_ssid *ssid)
560{
561 int i;
562
563 for (i = 0; i < NUM_WEP_KEYS; i++) {
564 if (ssid->wep_key_len[i])
565 return 1;
566 }
567
568 return 0;
569}
Hai Shalomfdcde762020-04-02 11:19:20 -0700570#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700571
572
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700573static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574 struct wpa_ssid *ssid)
575{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700576 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577
578 if (ssid->mixed_cell)
579 return 1;
580
581#ifdef CONFIG_WPS
582 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
583 return 1;
584#endif /* CONFIG_WPS */
585
Roshan Pius3a1667e2018-07-03 15:17:14 -0700586#ifdef CONFIG_OWE
587 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
588 return 1;
589#endif /* CONFIG_OWE */
590
Hai Shalomfdcde762020-04-02 11:19:20 -0700591#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700592 if (has_wep_key(ssid))
593 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700594#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700595
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596#ifdef IEEE8021X_EAPOL
597 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
598 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
599 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
600 privacy = 1;
601#endif /* IEEE8021X_EAPOL */
602
Jouni Malinen75ecf522011-06-27 15:19:46 -0700603 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
604 privacy = 1;
605
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800606 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
607 privacy = 1;
608
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 if (bss->caps & IEEE80211_CAP_PRIVACY)
610 return privacy;
611 return !privacy;
612}
613
614
615static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
616 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800617 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700618{
619 struct wpa_ie_data ie;
620 int proto_match = 0;
621 const u8 *rsn_ie, *wpa_ie;
622 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700623#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700624 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700625#endif /* CONFIG_WEP */
Sunil Ravi640215c2023-06-28 23:08:09 +0000626 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627
628 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
629 if (ret >= 0)
630 return ret;
631
Hai Shalomfdcde762020-04-02 11:19:20 -0700632#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
634 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
635 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
636 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
637 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700638#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700640 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Sunil Ravi640215c2023-06-28 23:08:09 +0000641 if (is_6ghz_bss && !rsn_ie) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700642 if (debug_print)
643 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000644 " skip - 6 GHz BSS without RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700645 return 0;
646 }
647
Roshan Pius3a1667e2018-07-03 15:17:14 -0700648 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 proto_match++;
650
651 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800652 if (debug_print)
653 wpa_dbg(wpa_s, MSG_DEBUG,
654 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700655 break;
656 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700657 if (!ie.has_pairwise)
658 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
659 if (!ie.has_group)
660 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661
Sunil Ravi640215c2023-06-28 23:08:09 +0000662 if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
663 /* WEP and TKIP are not allowed on 6 GHz/MLD */
Sunil Ravia04bd252022-05-02 22:54:18 -0700664 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
665 WPA_CIPHER_WEP104 |
666 WPA_CIPHER_TKIP);
667 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
668 WPA_CIPHER_WEP104 |
669 WPA_CIPHER_TKIP);
670 }
671
Hai Shalomfdcde762020-04-02 11:19:20 -0700672#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673 if (wep_ok &&
674 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
675 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800676 if (debug_print)
677 wpa_dbg(wpa_s, MSG_DEBUG,
678 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679 return 1;
680 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700681#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682
Roshan Pius3a1667e2018-07-03 15:17:14 -0700683 if (!(ie.proto & ssid->proto) &&
684 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800685 if (debug_print)
686 wpa_dbg(wpa_s, MSG_DEBUG,
687 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700688 break;
689 }
690
691 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800692 if (debug_print)
693 wpa_dbg(wpa_s, MSG_DEBUG,
694 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695 break;
696 }
697
698 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800699 if (debug_print)
700 wpa_dbg(wpa_s, MSG_DEBUG,
701 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700702 break;
703 }
704
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700705 if (ssid->group_mgmt_cipher &&
706 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
707 if (debug_print)
708 wpa_dbg(wpa_s, MSG_DEBUG,
709 " skip RSN IE - group mgmt cipher mismatch");
710 break;
711 }
712
Sunil Ravi640215c2023-06-28 23:08:09 +0000713 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700714 /* MFPC must be supported on 6 GHz */
715 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
716 if (debug_print)
717 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000718 " skip RSNE - 6 GHz without MFPC");
Sunil Ravia04bd252022-05-02 22:54:18 -0700719 break;
720 }
721
722 /* WPA PSK is not allowed on the 6 GHz band */
723 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
724 WPA_KEY_MGMT_FT_PSK |
725 WPA_KEY_MGMT_PSK_SHA256);
726 }
727
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800729 if (debug_print)
730 wpa_dbg(wpa_s, MSG_DEBUG,
731 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700732 break;
733 }
734
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700735 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800736 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800737 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800738 if (debug_print)
739 wpa_dbg(wpa_s, MSG_DEBUG,
740 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700741 break;
742 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800743 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
744 wpas_get_ssid_pmf(wpa_s, ssid) ==
745 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800746 if (debug_print)
747 wpa_dbg(wpa_s, MSG_DEBUG,
748 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800749 break;
750 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700751
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800752 if (debug_print)
753 wpa_dbg(wpa_s, MSG_DEBUG,
754 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700755 return 1;
756 }
757
Sunil Ravi640215c2023-06-28 23:08:09 +0000758 if (is_6ghz_bss) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700759 if (debug_print)
760 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi640215c2023-06-28 23:08:09 +0000761 " skip - 6 GHz BSS without matching RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700762 return 0;
763 }
764
Roshan Pius3a1667e2018-07-03 15:17:14 -0700765 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
766 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800767 if (debug_print)
768 wpa_dbg(wpa_s, MSG_DEBUG,
769 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700770 return 0;
771 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700772
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700773 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
775 proto_match++;
776
777 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800778 if (debug_print)
779 wpa_dbg(wpa_s, MSG_DEBUG,
780 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781 break;
782 }
783
Hai Shalomfdcde762020-04-02 11:19:20 -0700784#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 if (wep_ok &&
786 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
787 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800788 if (debug_print)
789 wpa_dbg(wpa_s, MSG_DEBUG,
790 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700791 return 1;
792 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700793#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794
795 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800796 if (debug_print)
797 wpa_dbg(wpa_s, MSG_DEBUG,
798 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700799 break;
800 }
801
802 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800803 if (debug_print)
804 wpa_dbg(wpa_s, MSG_DEBUG,
805 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 break;
807 }
808
809 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800810 if (debug_print)
811 wpa_dbg(wpa_s, MSG_DEBUG,
812 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813 break;
814 }
815
816 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800817 if (debug_print)
818 wpa_dbg(wpa_s, MSG_DEBUG,
819 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820 break;
821 }
822
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800823 if (debug_print)
824 wpa_dbg(wpa_s, MSG_DEBUG,
825 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700826 return 1;
827 }
828
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700829 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
830 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800831 if (debug_print)
832 wpa_dbg(wpa_s, MSG_DEBUG,
833 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700834 return 1;
835 }
836
Roshan Pius3a1667e2018-07-03 15:17:14 -0700837#ifdef CONFIG_OWE
838 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
839 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800840 if (wpa_s->owe_transition_select &&
841 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
842 ssid->owe_transition_bss_select_count + 1 <=
843 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
844 ssid->owe_transition_bss_select_count++;
845 if (debug_print)
846 wpa_dbg(wpa_s, MSG_DEBUG,
847 " skip OWE transition BSS (selection count %d does not exceed %d)",
848 ssid->owe_transition_bss_select_count,
849 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
850 wpa_s->owe_transition_search = 1;
851 return 0;
852 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700853 if (debug_print)
854 wpa_dbg(wpa_s, MSG_DEBUG,
855 " allow in OWE transition mode");
856 return 1;
857 }
858#endif /* CONFIG_OWE */
859
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700860 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
861 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800862 if (debug_print)
863 wpa_dbg(wpa_s, MSG_DEBUG,
864 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700865 return 0;
866 }
867
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800868 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
869 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800870 if (debug_print)
871 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800872 return 1;
873 }
874
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700875 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800876 if (debug_print)
877 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700878 return 1;
879 }
880
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800881 if (debug_print)
882 wpa_dbg(wpa_s, MSG_DEBUG,
883 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700884
885 return 0;
886}
887
888
889static int freq_allowed(int *freqs, int freq)
890{
891 int i;
892
893 if (freqs == NULL)
894 return 1;
895
896 for (i = 0; freqs[i]; i++)
897 if (freqs[i] == freq)
898 return 1;
899 return 0;
900}
901
902
Hai Shalomfdcde762020-04-02 11:19:20 -0700903static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
904 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800905{
906 const struct hostapd_hw_modes *mode = NULL, *modes;
907 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
908 const u8 *rate_ie;
909 int i, j, k;
910
911 if (bss->freq == 0)
912 return 1; /* Cannot do matching without knowing band */
913
914 modes = wpa_s->hw.modes;
915 if (modes == NULL) {
916 /*
917 * The driver does not provide any additional information
918 * about the utilized hardware, so allow the connection attempt
919 * to continue.
920 */
921 return 1;
922 }
923
924 for (i = 0; i < wpa_s->hw.num_modes; i++) {
925 for (j = 0; j < modes[i].num_channels; j++) {
926 int freq = modes[i].channels[j].freq;
927 if (freq == bss->freq) {
928 if (mode &&
929 mode->mode == HOSTAPD_MODE_IEEE80211G)
930 break; /* do not allow 802.11b replace
931 * 802.11g */
932 mode = &modes[i];
933 break;
934 }
935 }
936 }
937
938 if (mode == NULL)
939 return 0;
940
941 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700942 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800943 if (rate_ie == NULL)
944 continue;
945
946 for (j = 2; j < rate_ie[1] + 2; j++) {
947 int flagged = !!(rate_ie[j] & 0x80);
948 int r = (rate_ie[j] & 0x7f) * 5;
949
950 /*
951 * IEEE Std 802.11n-2009 7.3.2.2:
952 * The new BSS Membership selector value is encoded
953 * like a legacy basic rate, but it is not a rate and
954 * only indicates if the BSS members are required to
955 * support the mandatory features of Clause 20 [HT PHY]
956 * in order to join the BSS.
957 */
958 if (flagged && ((rate_ie[j] & 0x7f) ==
959 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
960 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800961 if (debug_print)
962 wpa_dbg(wpa_s, MSG_DEBUG,
963 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800964 return 0;
965 }
966 continue;
967 }
968
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700969 /* There's also a VHT selector for 802.11ac */
970 if (flagged && ((rate_ie[j] & 0x7f) ==
971 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
972 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800973 if (debug_print)
974 wpa_dbg(wpa_s, MSG_DEBUG,
975 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700976 return 0;
977 }
978 continue;
979 }
980
Sunil Ravi77d572f2023-01-17 23:58:31 +0000981 if (flagged && ((rate_ie[j] & 0x7f) ==
982 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
983 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
984 if (debug_print)
985 wpa_dbg(wpa_s, MSG_DEBUG,
986 " hardware does not support HE PHY");
987 return 0;
988 }
989 continue;
990 }
991
Hai Shalomc3565922019-10-28 11:58:20 -0700992#ifdef CONFIG_SAE
993 if (flagged && ((rate_ie[j] & 0x7f) ==
994 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Sunil Ravi77d572f2023-01-17 23:58:31 +0000995 if (wpa_s->conf->sae_pwe ==
996 SAE_PWE_HUNT_AND_PECK &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700997 !ssid->sae_password_id &&
Sunil Ravi036cec52023-03-29 11:35:17 -0700998 !is_6ghz_freq(bss->freq) &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700999 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -07001000 if (debug_print)
1001 wpa_dbg(wpa_s, MSG_DEBUG,
1002 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001003#ifdef CONFIG_TESTING_OPTIONS
1004 if (wpa_s->ignore_sae_h2e_only) {
1005 wpa_dbg(wpa_s, MSG_DEBUG,
1006 "TESTING: Ignore SAE H2E requirement mismatch");
1007 continue;
1008 }
1009#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -07001010 return 0;
1011 }
1012 continue;
1013 }
1014#endif /* CONFIG_SAE */
1015
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001016 if (!flagged)
1017 continue;
1018
1019 /* check for legacy basic rates */
1020 for (k = 0; k < mode->num_rates; k++) {
1021 if (mode->rates[k] == r)
1022 break;
1023 }
1024 if (k == mode->num_rates) {
1025 /*
1026 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1027 * order to join a BSS all required rates
1028 * have to be supported by the hardware.
1029 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001030 if (debug_print)
1031 wpa_dbg(wpa_s, MSG_DEBUG,
1032 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1033 r / 10, r % 10,
1034 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001035 return 0;
1036 }
1037 }
1038 }
1039
1040 return 1;
1041}
1042
1043
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001044/*
1045 * Test whether BSS is in an ESS.
1046 * This is done differently in DMG (60 GHz) and non-DMG bands
1047 */
1048static int bss_is_ess(struct wpa_bss *bss)
1049{
1050 if (bss_is_dmg(bss)) {
1051 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1052 IEEE80211_CAP_DMG_AP;
1053 }
1054
1055 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1056 IEEE80211_CAP_ESS);
1057}
1058
1059
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001060static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1061{
1062 size_t i;
1063
1064 for (i = 0; i < ETH_ALEN; i++) {
1065 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1066 return 0;
1067 }
1068 return 1;
1069}
1070
1071
1072static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1073{
1074 size_t i;
1075
1076 for (i = 0; i < num; i++) {
1077 const u8 *a = list + i * ETH_ALEN * 2;
1078 const u8 *m = a + ETH_ALEN;
1079
1080 if (match_mac_mask(a, addr, m))
1081 return 1;
1082 }
1083 return 0;
1084}
1085
1086
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001087static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1088 const u8 **ret_ssid, size_t *ret_ssid_len)
1089{
1090#ifdef CONFIG_OWE
1091 const u8 *owe, *pos, *end, *bssid;
1092 u8 ssid_len;
1093 struct wpa_bss *open_bss;
1094
1095 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1096 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
1097 return;
1098
1099 pos = owe + 6;
1100 end = owe + 2 + owe[1];
1101
1102 if (end - pos < ETH_ALEN + 1)
1103 return;
1104 bssid = pos;
1105 pos += ETH_ALEN;
1106 ssid_len = *pos++;
1107 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1108 return;
1109
1110 /* Match the profile SSID against the OWE transition mode SSID on the
1111 * open network. */
1112 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1113 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1114 *ret_ssid = pos;
1115 *ret_ssid_len = ssid_len;
1116
Hai Shalomfdcde762020-04-02 11:19:20 -07001117 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1118 struct wpa_ssid *ssid;
1119
1120 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1121 if (wpas_network_disabled(wpa_s, ssid))
1122 continue;
1123 if (ssid->ssid_len == ssid_len &&
1124 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1125 /* OWE BSS in transition mode for a currently
1126 * enabled OWE network. */
1127 wpa_dbg(wpa_s, MSG_DEBUG,
1128 "OWE: transition mode OWE SSID for active OWE profile");
1129 bss->flags |= WPA_BSS_OWE_TRANSITION;
1130 break;
1131 }
1132 }
1133 }
1134
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001135 if (bss->ssid_len > 0)
1136 return;
1137
1138 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1139 if (!open_bss)
1140 return;
1141 if (ssid_len != open_bss->ssid_len ||
1142 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1143 wpa_dbg(wpa_s, MSG_DEBUG,
1144 "OWE: transition mode SSID mismatch: %s",
1145 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1146 return;
1147 }
1148
1149 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1150 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1151 wpa_dbg(wpa_s, MSG_DEBUG,
1152 "OWE: transition mode open BSS unexpected info");
1153 return;
1154 }
1155
1156 pos = owe + 6;
1157 end = owe + 2 + owe[1];
1158
1159 if (end - pos < ETH_ALEN + 1)
1160 return;
1161 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1162 wpa_dbg(wpa_s, MSG_DEBUG,
1163 "OWE: transition mode BSSID mismatch: " MACSTR,
1164 MAC2STR(pos));
1165 return;
1166 }
1167 pos += ETH_ALEN;
1168 ssid_len = *pos++;
1169 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1170 return;
1171 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1172 wpa_ssid_txt(pos, ssid_len));
1173 os_memcpy(bss->ssid, pos, ssid_len);
1174 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001175 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001176#endif /* CONFIG_OWE */
1177}
1178
1179
Sunil Ravi26978f32021-04-30 15:19:18 -07001180int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001181{
1182 int i, j;
1183
1184 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1185 return 0;
1186
1187 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1188 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1189
1190 for (i = 0; i < mode->num_channels; i++) {
1191 struct hostapd_channel_data *chan = &mode->channels[i];
1192
1193 if (chan->freq == freq)
1194 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1195 }
1196 }
1197
1198 return 1;
1199}
1200
1201
Hai Shalom899fcc72020-10-19 14:38:18 -07001202static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1203 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001204 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001205 bool debug_print);
1206
1207
1208#ifdef CONFIG_SAE_PK
1209static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1210 struct wpa_bss *orig_bss,
1211 struct wpa_ssid *ssid,
1212 const u8 *match_ssid,
1213 size_t match_ssid_len)
1214{
1215 struct wpa_bss *bss;
1216
1217 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1218 int count;
1219 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001220
1221 if (bss == orig_bss)
1222 continue;
1223 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001224 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001225 continue;
1226
1227 /* TODO: Could be more thorough in checking what kind of
1228 * signal strength or throughput estimate would be acceptable
1229 * compared to the originally selected BSS. */
1230 if (bss->est_throughput < 2000)
1231 return false;
1232
Hai Shalom60840252021-02-19 19:02:11 -08001233 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001234 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1235 bss, count, 0))
1236 return true;
1237 }
1238
1239 return false;
1240}
1241#endif /* CONFIG_SAE_PK */
1242
1243
1244static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1245 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001246 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001247 bool debug_print)
1248{
1249 int res;
1250 bool wpa, check_ssid, osen, rsn_osen = false;
1251 struct wpa_ie_data data;
1252#ifdef CONFIG_MBO
1253 const u8 *assoc_disallow;
1254#endif /* CONFIG_MBO */
1255#ifdef CONFIG_SAE
1256 u8 rsnxe_capa = 0;
1257#endif /* CONFIG_SAE */
1258 const u8 *ie;
1259
1260 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1261 wpa = ie && ie[1];
1262 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1263 wpa |= ie && ie[1];
1264 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1265 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1266 rsn_osen = true;
1267 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1268 osen = ie != NULL;
1269
1270#ifdef CONFIG_SAE
1271 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1272 if (ie && ie[1] >= 1)
1273 rsnxe_capa = ie[2];
1274#endif /* CONFIG_SAE */
1275
1276 check_ssid = wpa || ssid->ssid_len > 0;
1277
1278 if (wpas_network_disabled(wpa_s, ssid)) {
1279 if (debug_print)
1280 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1281 return false;
1282 }
1283
1284 res = wpas_temp_disabled(wpa_s, ssid);
1285 if (res > 0) {
1286 if (debug_print)
1287 wpa_dbg(wpa_s, MSG_DEBUG,
1288 " skip - disabled temporarily for %d second(s)",
1289 res);
1290 return false;
1291 }
1292
1293#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001294 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001295 if (debug_print)
1296 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001297 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001298 return false;
1299 }
1300
1301 if (wpa && ssid->ssid_len == 0 &&
1302 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1303 check_ssid = false;
1304
1305 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1306 /* Only allow wildcard SSID match if an AP advertises active
1307 * WPS operation that matches our mode. */
1308 check_ssid = ssid->ssid_len > 0 ||
1309 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1310 }
1311#endif /* CONFIG_WPS */
1312
1313 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1314 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1315 check_ssid = false;
1316
1317 if (check_ssid &&
1318 (match_ssid_len != ssid->ssid_len ||
1319 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1320 if (debug_print)
1321 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1322 return false;
1323 }
1324
1325 if (ssid->bssid_set &&
1326 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1327 if (debug_print)
1328 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1329 return false;
1330 }
1331
Hai Shalom60840252021-02-19 19:02:11 -08001332 /* check the list of BSSIDs to ignore */
1333 if (ssid->num_bssid_ignore &&
1334 addr_in_list(bss->bssid, ssid->bssid_ignore,
1335 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001336 if (debug_print)
1337 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001338 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001339 return false;
1340 }
1341
Hai Shalom60840252021-02-19 19:02:11 -08001342 /* if there is a list of accepted BSSIDs, only accept those APs */
1343 if (ssid->num_bssid_accept &&
1344 !addr_in_list(bss->bssid, ssid->bssid_accept,
1345 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001346 if (debug_print)
1347 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001348 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001349 return false;
1350 }
1351
1352 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1353 return false;
1354
1355 if (!osen && !wpa &&
1356 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1357 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1358 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1359 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1360 if (debug_print)
1361 wpa_dbg(wpa_s, MSG_DEBUG,
1362 " skip - non-WPA network not allowed");
1363 return false;
1364 }
1365
1366#ifdef CONFIG_WEP
1367 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1368 if (debug_print)
1369 wpa_dbg(wpa_s, MSG_DEBUG,
1370 " skip - ignore WPA/WPA2 AP for WEP network block");
1371 return false;
1372 }
1373#endif /* CONFIG_WEP */
1374
1375 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1376 if (debug_print)
1377 wpa_dbg(wpa_s, MSG_DEBUG,
1378 " skip - non-OSEN network not allowed");
1379 return false;
1380 }
1381
1382 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1383 if (debug_print)
1384 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1385 return false;
1386 }
1387
1388 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1389 !bss_is_pbss(bss)) {
1390 if (debug_print)
1391 wpa_dbg(wpa_s, MSG_DEBUG,
1392 " skip - not ESS, PBSS, or MBSS");
1393 return false;
1394 }
1395
1396 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1397 if (debug_print)
1398 wpa_dbg(wpa_s, MSG_DEBUG,
1399 " skip - PBSS mismatch (ssid %d bss %d)",
1400 ssid->pbss, bss_is_pbss(bss));
1401 return false;
1402 }
1403
1404 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1405 if (debug_print)
1406 wpa_dbg(wpa_s, MSG_DEBUG,
1407 " skip - frequency not allowed");
1408 return false;
1409 }
1410
1411#ifdef CONFIG_MESH
1412 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1413 ssid->frequency != bss->freq) {
1414 if (debug_print)
1415 wpa_dbg(wpa_s, MSG_DEBUG,
1416 " skip - frequency not allowed (mesh)");
1417 return false;
1418 }
1419#endif /* CONFIG_MESH */
1420
1421 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1422 if (debug_print)
1423 wpa_dbg(wpa_s, MSG_DEBUG,
1424 " skip - rate sets do not match");
1425 return false;
1426 }
1427
1428#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001429 /* When using SAE Password Identifier and when operationg on the 6 GHz
1430 * band, only H2E is allowed. */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001431 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1432 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1433 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1434 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001435#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301436 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001437#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001438 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1439 if (debug_print)
1440 wpa_dbg(wpa_s, MSG_DEBUG,
1441 " skip - SAE H2E required, but not supported by the AP");
1442 return false;
1443 }
1444#endif /* CONFIG_SAE */
1445
1446#ifdef CONFIG_SAE_PK
1447 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1448 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1449 if (debug_print)
1450 wpa_dbg(wpa_s, MSG_DEBUG,
1451 " skip - SAE-PK required, but not supported by the AP");
1452 return false;
1453 }
1454#endif /* CONFIG_SAE_PK */
1455
1456#ifndef CONFIG_IBSS_RSN
1457 if (ssid->mode == WPAS_MODE_IBSS &&
1458 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1459 if (debug_print)
1460 wpa_dbg(wpa_s, MSG_DEBUG,
1461 " skip - IBSS RSN not supported in the build");
1462 return false;
1463 }
1464#endif /* !CONFIG_IBSS_RSN */
1465
1466#ifdef CONFIG_P2P
1467 if (ssid->p2p_group &&
1468 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1469 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1470 if (debug_print)
1471 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1472 return false;
1473 }
1474
1475 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1476 struct wpabuf *p2p_ie;
1477 u8 dev_addr[ETH_ALEN];
1478
1479 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1480 if (!ie) {
1481 if (debug_print)
1482 wpa_dbg(wpa_s, MSG_DEBUG,
1483 " skip - no P2P element");
1484 return false;
1485 }
1486 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1487 if (!p2p_ie) {
1488 if (debug_print)
1489 wpa_dbg(wpa_s, MSG_DEBUG,
1490 " skip - could not fetch P2P element");
1491 return false;
1492 }
1493
1494 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1495 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1496 if (debug_print)
1497 wpa_dbg(wpa_s, MSG_DEBUG,
1498 " skip - no matching GO P2P Device Address in P2P element");
1499 wpabuf_free(p2p_ie);
1500 return false;
1501 }
1502 wpabuf_free(p2p_ie);
1503 }
1504
1505 /*
1506 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1507 * P2P Group Capability Bitmap and we are not in Group Formation with
1508 * that device.
1509 */
1510#endif /* CONFIG_P2P */
1511
1512 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1513 struct os_reltime diff;
1514
1515 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1516 if (debug_print)
1517 wpa_dbg(wpa_s, MSG_DEBUG,
1518 " skip - scan result not recent enough (%u.%06u seconds too old)",
1519 (unsigned int) diff.sec,
1520 (unsigned int) diff.usec);
1521 return false;
1522 }
1523#ifdef CONFIG_MBO
1524#ifdef CONFIG_TESTING_OPTIONS
1525 if (wpa_s->ignore_assoc_disallow)
1526 goto skip_assoc_disallow;
1527#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001528 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001529 if (assoc_disallow && assoc_disallow[1] >= 1) {
1530 if (debug_print)
1531 wpa_dbg(wpa_s, MSG_DEBUG,
1532 " skip - MBO association disallowed (reason %u)",
1533 assoc_disallow[2]);
1534 return false;
1535 }
1536
1537 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1538 if (debug_print)
1539 wpa_dbg(wpa_s, MSG_DEBUG,
1540 " skip - AP temporarily disallowed");
1541 return false;
1542 }
1543#ifdef CONFIG_TESTING_OPTIONS
1544skip_assoc_disallow:
1545#endif /* CONFIG_TESTING_OPTIONS */
1546#endif /* CONFIG_MBO */
1547
1548#ifdef CONFIG_DPP
1549 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001550 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1551 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001552 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1553 !ssid->dpp_csign)) {
1554 if (debug_print)
1555 wpa_dbg(wpa_s, MSG_DEBUG,
1556 " skip - no PMKSA entry for DPP");
1557 return false;
1558 }
1559#endif /* CONFIG_DPP */
1560
1561#ifdef CONFIG_SAE_PK
1562 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1563 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1564 ((ssid->sae_password &&
1565 sae_pk_valid_password(ssid->sae_password)) ||
1566 (!ssid->sae_password && ssid->passphrase &&
1567 sae_pk_valid_password(ssid->passphrase))) &&
1568 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1569 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1570 match_ssid_len)) {
1571 if (debug_print)
1572 wpa_dbg(wpa_s, MSG_DEBUG,
1573 " skip - another acceptable BSS with SAE-PK in the same ESS");
1574 return false;
1575 }
1576#endif /* CONFIG_SAE_PK */
1577
1578 if (bss->ssid_len == 0) {
1579 if (debug_print)
1580 wpa_dbg(wpa_s, MSG_DEBUG,
1581 " skip - no SSID known for the BSS");
1582 return false;
1583 }
1584
1585 /* Matching configuration found */
1586 return true;
1587}
1588
1589
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001590struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1591 int i, struct wpa_bss *bss,
1592 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001593 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001594{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001595 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001596 const u8 *ie;
1597 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001598 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001599 const u8 *match_ssid;
1600 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001601 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001602
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001603 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001604 wpa_ie_len = ie ? ie[1] : 0;
1605
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001606 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001607 rsn_ie_len = ie ? ie[1] : 0;
1608
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001609 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1610 osen = ie != NULL;
1611
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001612 if (debug_print) {
1613 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1614 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1615 i, MAC2STR(bss->bssid),
1616 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1617 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1618 bss->freq,
1619 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1620 " wps" : "",
1621 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1622 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1623 ? " p2p" : "",
1624 osen ? " osen=1" : "");
1625 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001626
Hai Shalom60840252021-02-19 19:02:11 -08001627 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1628 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001629 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001630 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001631 /*
1632 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001633 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001634 * should not be done with multiple enabled networks to
1635 * avoid getting forced to move into a worse ESS on
1636 * single error if there are no other BSSes of the
1637 * current ESS.
1638 */
1639 limit = 0;
1640 }
Hai Shalom60840252021-02-19 19:02:11 -08001641 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001642 if (debug_print) {
1643 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001644 " skip - BSSID ignored (count=%d limit=%d)",
1645 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001646 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647 return NULL;
1648 }
1649 }
1650
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001651 match_ssid = bss->ssid;
1652 match_ssid_len = bss->ssid_len;
1653 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1654
1655 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001656 if (debug_print)
1657 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001658 return NULL;
1659 }
1660
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001661 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001662 if (debug_print)
1663 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001664 return NULL;
1665 }
1666
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001667 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001668 if (debug_print)
1669 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001670 return NULL;
1671 }
1672
Hai Shalomfdcde762020-04-02 11:19:20 -07001673 if (disabled_freq(wpa_s, bss->freq)) {
1674 if (debug_print)
1675 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1676 return NULL;
1677 }
1678
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001679 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001680 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001681 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001682 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001683 }
1684
1685 /* No matching configuration found */
1686 return NULL;
1687}
1688
1689
1690static struct wpa_bss *
1691wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001692 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001693 struct wpa_ssid **selected_ssid,
1694 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001695{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001696 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001698 if (wpa_s->current_ssid) {
1699 struct wpa_ssid *ssid;
1700
1701 wpa_dbg(wpa_s, MSG_DEBUG,
1702 "Scan results matching the currently selected network");
1703 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1704 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1705
1706 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1707 only_first_ssid, 0);
1708 if (ssid != wpa_s->current_ssid)
1709 continue;
1710 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1711 " freq=%d level=%d snr=%d est_throughput=%u",
1712 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1713 bss->snr, bss->est_throughput);
1714 }
1715 }
1716
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001717 if (only_first_ssid)
1718 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1719 group->id);
1720 else
1721 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1722 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001723
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001724 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1725 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001726
1727 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001728 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001729 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001730 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001731 if (!*selected_ssid)
1732 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001733 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001734 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001735 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001736 MAC2STR(bss->bssid),
1737 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1738 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001739 }
1740
1741 return NULL;
1742}
1743
1744
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001745struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1746 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001747{
1748 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001749 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001750 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001751 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001752
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001753 if (wpa_s->last_scan_res == NULL ||
1754 wpa_s->last_scan_res_used == 0)
1755 return NULL; /* no scan results from last update */
1756
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001757 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001758 /* check that next_ssid is still valid */
1759 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1760 if (ssid == wpa_s->next_ssid)
1761 break;
1762 }
1763 next_ssid = ssid;
1764 wpa_s->next_ssid = NULL;
1765 }
1766
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001767 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001768 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1769 if (next_ssid && next_ssid->priority ==
1770 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001771 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001772 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001773 if (selected)
1774 break;
1775 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001776 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001777 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001778 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001779 if (selected)
1780 break;
1781 }
1782
Hai Shalom60840252021-02-19 19:02:11 -08001783 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001784 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001785 wpa_dbg(wpa_s, MSG_DEBUG,
1786 "No APs found - clear BSSID ignore list and try again");
1787 wpa_bssid_ignore_clear(wpa_s);
1788 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001789 } else if (selected == NULL)
1790 break;
1791 }
1792
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001793 ssid = *selected_ssid;
1794 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1795 !ssid->passphrase && !ssid->ext_psk) {
1796 const char *field_name, *txt = NULL;
1797
1798 wpa_dbg(wpa_s, MSG_DEBUG,
1799 "PSK/passphrase not yet available for the selected network");
1800
1801 wpas_notify_network_request(wpa_s, ssid,
1802 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1803
1804 field_name = wpa_supplicant_ctrl_req_to_string(
1805 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1806 if (field_name == NULL)
1807 return NULL;
1808
1809 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1810
1811 selected = NULL;
1812 }
1813
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001814 return selected;
1815}
1816
1817
1818static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1819 int timeout_sec, int timeout_usec)
1820{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001821 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001822 /*
1823 * No networks are enabled; short-circuit request so
1824 * we don't wait timeout seconds before transitioning
1825 * to INACTIVE state.
1826 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001827 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1828 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001829 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1830 return;
1831 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001832
1833 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1835}
1836
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001837
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001838int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001839 struct wpa_bss *selected,
1840 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841{
Sunil Ravi640215c2023-06-28 23:08:09 +00001842#ifdef IEEE8021X_EAPOL
Sunil Ravi036cec52023-03-29 11:35:17 -07001843 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
1844 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00001845 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001846 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1847 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001848 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001849 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001851 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1852 wpa_s->p2p_in_provisioning) {
1853 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1854 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001855 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001856 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001857#endif /* CONFIG_P2P */
1858
1859#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001860 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001861 wpas_wps_cancel(wpa_s);
1862#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001863 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001864 }
Sunil Ravi640215c2023-06-28 23:08:09 +00001865#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001866
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001867 wpa_msg(wpa_s, MSG_DEBUG,
1868 "Considering connect request: reassociate: %d selected: "
1869 MACSTR " bssid: " MACSTR " pending: " MACSTR
1870 " wpa_state: %s ssid=%p current_ssid=%p",
1871 wpa_s->reassociate, MAC2STR(selected->bssid),
1872 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1873 wpa_supplicant_state_txt(wpa_s->wpa_state),
1874 ssid, wpa_s->current_ssid);
1875
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001876 /*
1877 * Do not trigger new association unless the BSSID has changed or if
1878 * reassociation is requested. If we are in process of associating with
1879 * the selected BSSID, do not trigger new attempt.
1880 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001881 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001882 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1883 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1884 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001885 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1886 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1887 0) ||
1888 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1889 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001890 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1891 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001892 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001893 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001894 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1895 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001896 wpa_supplicant_associate(wpa_s, selected, ssid);
1897 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001898 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1899 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001900 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001901
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001902 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001903}
1904
1905
1906static struct wpa_ssid *
1907wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1908{
Hai Shalomfdcde762020-04-02 11:19:20 -07001909 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001910 struct wpa_ssid *ssid;
1911
1912 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1913 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1914 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001915 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001916 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001917#ifndef CONFIG_IBSS_RSN
1918 if (ssid->mode == WPAS_MODE_IBSS &&
1919 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1920 WPA_KEY_MGMT_WPA_NONE))) {
1921 wpa_msg(wpa_s, MSG_INFO,
1922 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1923 wpa_ssid_txt(ssid->ssid,
1924 ssid->ssid_len));
1925 continue;
1926 }
1927#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001928 if (ssid->mode == WPAS_MODE_IBSS ||
1929 ssid->mode == WPAS_MODE_AP ||
1930 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001931 return ssid;
1932 }
1933 }
1934 return NULL;
1935}
1936
1937
1938/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1939 * on BSS added and BSS changed events */
1940static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001941 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001942{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001943 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001944
1945 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1946 return;
1947
Jouni Malinen87fd2792011-05-16 18:35:42 +03001948 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001949 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001950
Jouni Malinen87fd2792011-05-16 18:35:42 +03001951 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001952 if (ssid == NULL)
1953 continue;
1954
Jouni Malinen87fd2792011-05-16 18:35:42 +03001955 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001956 if (rsn == NULL)
1957 continue;
1958
Jouni Malinen87fd2792011-05-16 18:35:42 +03001959 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001960 }
1961
1962}
1963
1964
Hai Shalomfdcde762020-04-02 11:19:20 -07001965#ifndef CONFIG_NO_ROAMING
1966
1967static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1968{
1969 if (noise == WPA_INVALID_NOISE)
1970 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1971 DEFAULT_NOISE_FLOOR_2GHZ;
1972 return avg_signal - noise;
1973}
1974
1975
1976static unsigned int
1977wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1978 const struct wpa_bss *bss, int snr)
1979{
1980 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001981 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001982 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1983
Hai Shalomc1a21442022-02-04 13:43:00 -08001984 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07001985}
1986
Hai Shalomfdcde762020-04-02 11:19:20 -07001987
Hai Shalom899fcc72020-10-19 14:38:18 -07001988int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1989 struct wpa_bss *current_bss,
1990 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001991{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001992 int min_diff, diff;
Sunil Ravi036cec52023-03-29 11:35:17 -07001993 int to_5ghz, to_6ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001994 int cur_level;
1995 unsigned int cur_est, sel_est;
1996 struct wpa_signal_info si;
1997 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001998 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001999
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002000 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002001 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002002 " freq=%d level=%d snr=%d est_throughput=%u",
2003 MAC2STR(current_bss->bssid),
2004 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002005 current_bss->snr, current_bss->est_throughput);
2006 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002007 " freq=%d level=%d snr=%d est_throughput=%u",
2008 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002009 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002010
2011 if (wpa_s->current_ssid->bssid_set &&
2012 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
2013 0) {
2014 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2015 "has preferred BSSID");
2016 return 1;
2017 }
2018
Hai Shalomfdcde762020-04-02 11:19:20 -07002019 cur_level = current_bss->level;
2020 cur_est = current_bss->est_throughput;
2021 sel_est = selected->est_throughput;
2022
2023 /*
2024 * Try to poll the signal from the driver since this will allow to get
2025 * more accurate values. In some cases, there can be big differences
2026 * between the RSSI of the Probe Response frames of the AP we are
2027 * associated with and the Beacon frames we hear from the same AP after
2028 * association. This can happen, e.g., when there are two antennas that
2029 * hear the AP very differently. If the driver chooses to hear the
2030 * Probe Response frames during the scan on the "bad" antenna because
2031 * it wants to save power, but knows to choose the other antenna after
2032 * association, we will hear our AP with a low RSSI as part of the
2033 * scan even when we can hear it decently on the other antenna. To cope
2034 * with this, ask the driver to teach us how it hears the AP. Also, the
2035 * scan results may be a bit old, since we can very quickly get fresh
2036 * information about our currently associated AP.
2037 */
2038 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002039 (si.data.avg_beacon_signal || si.data.avg_signal)) {
2040 cur_level = si.data.avg_beacon_signal ?
2041 si.data.avg_beacon_signal : si.data.avg_signal;
Hai Shalomfdcde762020-04-02 11:19:20 -07002042 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2043 si.current_noise);
2044
2045 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2046 current_bss,
2047 cur_snr);
2048 wpa_dbg(wpa_s, MSG_DEBUG,
2049 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2050 cur_level, cur_snr, cur_est);
2051 }
2052
2053 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002054 wpa_dbg(wpa_s, MSG_DEBUG,
2055 "Allow reassociation - selected BSS has better estimated throughput");
2056 return 1;
2057 }
2058
Dmitry Shmidte4663042016-04-04 10:07:49 -07002059 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
Sunil Ravi036cec52023-03-29 11:35:17 -07002060 to_6ghz = is_6ghz_freq(selected->freq) &&
2061 !is_6ghz_freq(current_bss->freq);
Dmitry Shmidte4663042016-04-04 10:07:49 -07002062
Sunil Ravi036cec52023-03-29 11:35:17 -07002063 if (cur_level < 0 &&
2064 cur_level > selected->level + to_5ghz * 2 + to_6ghz * 2 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002065 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002066 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2067 "signal level");
2068 return 0;
2069 }
2070
Hai Shalomfdcde762020-04-02 11:19:20 -07002071 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002072 wpa_dbg(wpa_s, MSG_DEBUG,
2073 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002074 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002075 }
2076
Hai Shalomfdcde762020-04-02 11:19:20 -07002077 if (cur_snr > GREAT_SNR) {
2078 wpa_dbg(wpa_s, MSG_DEBUG,
2079 "Skip roam - Current BSS has good SNR (%u > %u)",
2080 cur_snr, GREAT_SNR);
2081 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002083
Hai Shalomfdcde762020-04-02 11:19:20 -07002084 if (cur_level < -85) /* ..-86 dBm */
2085 min_diff = 1;
2086 else if (cur_level < -80) /* -85..-81 dBm */
2087 min_diff = 2;
2088 else if (cur_level < -75) /* -80..-76 dBm */
2089 min_diff = 3;
2090 else if (cur_level < -70) /* -75..-71 dBm */
2091 min_diff = 4;
2092 else if (cur_level < 0) /* -70..-1 dBm */
2093 min_diff = 5;
2094 else /* unspecified units (not in dBm) */
2095 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002096
Hai Shalomfdcde762020-04-02 11:19:20 -07002097 if (cur_est > sel_est * 1.5)
2098 min_diff += 10;
2099 else if (cur_est > sel_est * 1.2)
2100 min_diff += 5;
2101 else if (cur_est > sel_est * 1.1)
2102 min_diff += 2;
2103 else if (cur_est > sel_est)
2104 min_diff++;
2105 else if (sel_est > cur_est * 1.5)
2106 min_diff -= 10;
2107 else if (sel_est > cur_est * 1.2)
2108 min_diff -= 5;
2109 else if (sel_est > cur_est * 1.1)
2110 min_diff -= 2;
2111 else if (sel_est > cur_est)
2112 min_diff--;
2113
2114 if (to_5ghz)
2115 min_diff -= 2;
Sunil Ravi036cec52023-03-29 11:35:17 -07002116 if (to_6ghz)
2117 min_diff -= 2;
Hai Shalomfdcde762020-04-02 11:19:20 -07002118 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002119 if (diff < min_diff) {
2120 wpa_dbg(wpa_s, MSG_DEBUG,
2121 "Skip roam - too small difference in signal level (%d < %d)",
2122 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002123 ret = 0;
2124 } else {
2125 wpa_dbg(wpa_s, MSG_DEBUG,
2126 "Allow reassociation due to difference in signal level (%d >= %d)",
2127 diff, min_diff);
2128 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002129 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002130 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2131 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2132 " sel_freq=%d sel_level=%d sel_est=%d",
2133 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2134 MAC2STR(current_bss->bssid),
2135 current_bss->freq, cur_level, cur_est,
2136 MAC2STR(selected->bssid),
2137 selected->freq, selected->level, sel_est);
2138 return ret;
2139}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002140
Hai Shalom899fcc72020-10-19 14:38:18 -07002141#endif /* CONFIG_NO_ROAMING */
2142
2143
2144static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2145 struct wpa_bss *selected,
2146 struct wpa_ssid *ssid)
2147{
2148 struct wpa_bss *current_bss = NULL;
2149
2150 if (wpa_s->reassociate)
2151 return 1; /* explicit request to reassociate */
2152 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2153 return 1; /* we are not associated; continue */
2154 if (wpa_s->current_ssid == NULL)
2155 return 1; /* unknown current SSID */
2156 if (wpa_s->current_ssid != ssid)
2157 return 1; /* different network block */
2158
2159 if (wpas_driver_bss_selection(wpa_s))
2160 return 0; /* Driver-based roaming */
2161
2162 if (wpa_s->current_ssid->ssid)
2163 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2164 wpa_s->current_ssid->ssid,
2165 wpa_s->current_ssid->ssid_len);
2166 if (!current_bss)
2167 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2168
2169 if (!current_bss)
2170 return 1; /* current BSS not seen in scan results */
2171
2172 if (current_bss == selected)
2173 return 0;
2174
2175 if (selected->last_update_idx > current_bss->last_update_idx)
2176 return 1; /* current BSS not seen in the last scan */
2177
2178#ifndef CONFIG_NO_ROAMING
2179 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2180 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002181#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002182 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002183#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002184}
2185
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002186
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002187/*
2188 * Return a negative value if no scan results could be fetched or if scan
2189 * results should not be shared with other virtual interfaces.
2190 * Return 0 if scan results were fetched and may be shared with other
2191 * interfaces.
2192 * Return 1 if scan results may be shared with other virtual interfaces but may
2193 * not trigger any operations.
2194 * Return 2 if the interface was removed and cannot be used.
2195 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002196static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002197 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002198 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002199{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002200 struct wpa_scan_results *scan_res = NULL;
2201 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002202 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002203#ifndef CONFIG_NO_RANDOM_POOL
2204 size_t i, num;
2205#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002206
2207#ifdef CONFIG_AP
2208 if (wpa_s->ap_iface)
2209 ap = 1;
2210#endif /* CONFIG_AP */
2211
2212 wpa_supplicant_notify_scanning(wpa_s, 0);
2213
2214 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2215 data ? &data->scan_info :
2216 NULL, 1);
2217 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002218 if (wpa_s->conf->ap_scan == 2 || ap ||
2219 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002220 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002221 if (!own_request)
2222 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002223 if (data && data->scan_info.external_scan)
2224 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002225 if (wpa_s->scan_res_fail_handler) {
2226 void (*handler)(struct wpa_supplicant *wpa_s);
2227
2228 handler = wpa_s->scan_res_fail_handler;
2229 wpa_s->scan_res_fail_handler = NULL;
2230 handler(wpa_s);
2231 } else {
2232 wpa_dbg(wpa_s, MSG_DEBUG,
2233 "Failed to get scan results - try scanning again");
2234 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2235 }
2236
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002237 ret = -1;
2238 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239 }
2240
2241#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242 num = scan_res->num;
2243 if (num > 10)
2244 num = 10;
2245 for (i = 0; i < num; i++) {
2246 u8 buf[5];
2247 struct wpa_scan_res *res = scan_res->res[i];
2248 buf[0] = res->bssid[5];
2249 buf[1] = res->qual & 0xff;
2250 buf[2] = res->noise & 0xff;
2251 buf[3] = res->level & 0xff;
2252 buf[4] = res->tsf & 0xff;
2253 random_add_randomness(buf, sizeof(buf));
2254 }
2255#endif /* CONFIG_NO_RANDOM_POOL */
2256
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002257 if (update_only) {
2258 ret = 1;
2259 goto scan_work_done;
2260 }
2261
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002262 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002263 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002264 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2265 struct wpa_scan_results *scan_res);
2266
2267 scan_res_handler = wpa_s->scan_res_handler;
2268 wpa_s->scan_res_handler = NULL;
2269 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002270 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002271 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002272 }
2273
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002274 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002275 wpa_s->own_scan_running,
2276 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002277 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002278 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2279 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002280 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2281 wpa_s->manual_scan_id);
2282 wpa_s->manual_scan_use_id = 0;
2283 } else {
2284 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2285 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002286 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002287
2288 wpas_notify_scan_done(wpa_s, 1);
2289
Hai Shalomfdcde762020-04-02 11:19:20 -07002290 if (ap) {
2291 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2292#ifdef CONFIG_AP
2293 if (wpa_s->ap_iface->scan_cb)
2294 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2295#endif /* CONFIG_AP */
2296 goto scan_work_done;
2297 }
2298
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002299 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002300 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 -07002301 wpa_scan_results_free(scan_res);
2302 return 0;
2303 }
2304
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002305 if (wnm_scan_process(wpa_s, 1) > 0)
2306 goto scan_work_done;
2307
Hai Shalomc1a21442022-02-04 13:43:00 -08002308 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002309 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002310
Hai Shalom021b0b52019-04-10 11:17:58 -07002311 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002312 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2313 goto scan_work_done;
2314
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002315 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2316 goto scan_work_done;
2317
2318 if (autoscan_notify_scan(wpa_s, scan_res))
2319 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002320
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002321 if (wpa_s->disconnected) {
2322 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002323 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002324 }
2325
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002326 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002327 bgscan_notify_scan(wpa_s, scan_res) == 1)
2328 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002329
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002330 wpas_wps_update_ap_info(wpa_s, scan_res);
2331
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002332 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2333 wpa_s->wpa_state < WPA_COMPLETED)
2334 goto scan_work_done;
2335
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002336 wpa_scan_results_free(scan_res);
2337
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002338 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002339 struct wpa_radio_work *work = wpa_s->scan_work;
2340 wpa_s->scan_work = NULL;
2341 radio_work_done(work);
2342 }
2343
Hai Shalomc3565922019-10-28 11:58:20 -07002344 os_free(wpa_s->last_scan_freqs);
2345 wpa_s->last_scan_freqs = NULL;
2346 wpa_s->num_last_scan_freqs = 0;
2347 if (own_request && data &&
2348 data->scan_info.freqs && data->scan_info.num_freqs) {
2349 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2350 data->scan_info.num_freqs);
2351 if (wpa_s->last_scan_freqs) {
2352 os_memcpy(wpa_s->last_scan_freqs,
2353 data->scan_info.freqs,
2354 sizeof(int) * data->scan_info.num_freqs);
2355 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2356 }
2357 }
2358
Sunil Ravi77d572f2023-01-17 23:58:31 +00002359 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2360 return ret;
2361
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002362 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002363
2364scan_work_done:
2365 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002366 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002367 struct wpa_radio_work *work = wpa_s->scan_work;
2368 wpa_s->scan_work = NULL;
2369 radio_work_done(work);
2370 }
2371 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002372}
2373
2374
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002375static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002376 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002377{
2378 struct wpa_bss *selected;
2379 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002380 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2381
2382 if (time_to_reenable > 0) {
2383 wpa_dbg(wpa_s, MSG_DEBUG,
2384 "Postpone network selection by %d seconds since all networks are disabled",
2385 time_to_reenable);
2386 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2387 eloop_register_timeout(time_to_reenable, 0,
2388 wpas_network_reenabled, wpa_s, NULL);
2389 return 0;
2390 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002391
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002392 if (wpa_s->p2p_mgmt)
2393 return 0; /* no normal connection on p2p_mgmt interface */
2394
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002395 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002396 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002397
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002398#ifdef CONFIG_MESH
2399 if (wpa_s->ifmsh) {
2400 wpa_msg(wpa_s, MSG_INFO,
2401 "Avoiding join because we already joined a mesh group");
2402 return 0;
2403 }
2404#endif /* CONFIG_MESH */
2405
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002406 if (selected) {
2407 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002408 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002409 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002410 if (new_scan)
2411 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002412 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002413 }
2414
Hai Shalomc3565922019-10-28 11:58:20 -07002415 wpa_s->suitable_network++;
2416
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002417 if (ssid != wpa_s->current_ssid &&
2418 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2419 wpa_s->own_disconnect_req = 1;
2420 wpa_supplicant_deauthenticate(
2421 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2422 }
2423
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002424 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002425 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002426 return -1;
2427 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002428 wpa_s->supp_pbc_active = false;
2429
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002430 if (new_scan)
2431 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002432 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002433 * Do not allow other virtual radios to trigger operations based
2434 * on these scan results since we do not want them to start
2435 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002436 */
2437 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002438 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002439 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002440 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2441 ssid = wpa_supplicant_pick_new_network(wpa_s);
2442 if (ssid) {
2443 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2444 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002445 if (new_scan)
2446 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002447 } else if (own_request) {
2448 /*
2449 * No SSID found. If SCAN results are as a result of
2450 * own scan request and not due to a scan request on
2451 * another shared interface, try another scan.
2452 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002453 int timeout_sec = wpa_s->scan_interval;
2454 int timeout_usec = 0;
2455#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002456 int res;
2457
2458 res = wpas_p2p_scan_no_go_seen(wpa_s);
2459 if (res == 2)
2460 return 2;
2461 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002462 return 0;
2463
Sunil Ravi77d572f2023-01-17 23:58:31 +00002464 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002465 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002466
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002467 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002468 wpa_s->show_group_started ||
2469 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002470 /*
2471 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002472 * state and during P2P join-a-group operation
2473 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002474 */
2475 timeout_sec = 0;
2476 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002477 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2478 timeout_usec);
2479 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002480 }
2481#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002482#ifdef CONFIG_INTERWORKING
2483 if (wpa_s->conf->auto_interworking &&
2484 wpa_s->conf->interworking &&
2485 wpa_s->conf->cred) {
2486 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2487 "start ANQP fetch since no matching "
2488 "networks found");
2489 wpa_s->network_select = 1;
2490 wpa_s->auto_network_select = 1;
2491 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002492 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002493 }
2494#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002495#ifdef CONFIG_WPS
2496 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2497 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2498 timeout_sec = 0;
2499 timeout_usec = 500000;
2500 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2501 timeout_usec);
2502 return 0;
2503 }
2504#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002505#ifdef CONFIG_OWE
2506 if (wpa_s->owe_transition_search) {
2507 wpa_dbg(wpa_s, MSG_DEBUG,
2508 "OWE: Use shorter wait during transition mode search");
2509 timeout_sec = 0;
2510 timeout_usec = 500000;
2511 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2512 timeout_usec);
2513 return 0;
2514 }
2515#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002516 if (wpa_supplicant_req_sched_scan(wpa_s))
2517 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2518 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002519
2520 wpa_msg_ctrl(wpa_s, MSG_INFO,
2521 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002522 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002523 }
2524 }
2525 return 0;
2526}
2527
2528
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002529static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2530 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002531{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002532 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002533 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002534
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002535 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002536 if (res == 2) {
2537 /*
2538 * Interface may have been removed, so must not dereference
2539 * wpa_s after this.
2540 */
2541 return 1;
2542 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002543
2544 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002545 /*
2546 * If no scan results could be fetched, then no need to
2547 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002548 * this scan. Similarly, if scan results started a new operation on this
2549 * interface, do not notify other interfaces to avoid concurrent
2550 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002551 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002552 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002553 }
2554
2555 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002556 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002557 * so, they get updated with this same scan info.
2558 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002559 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2560 radio_list) {
2561 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002562 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2563 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002564 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2565 res > 0);
2566 if (res < 0)
2567 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002568 }
2569 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002570
2571 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002572}
2573
2574#endif /* CONFIG_NO_SCAN_PROCESSING */
2575
2576
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002577int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2578{
2579#ifdef CONFIG_NO_SCAN_PROCESSING
2580 return -1;
2581#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002582 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002583
Dmitry Shmidt29333592017-01-09 12:27:11 -08002584 wpa_s->ignore_post_flush_scan_res = 0;
2585
Dmitry Shmidt41712582015-06-29 11:02:15 -07002586 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002587 return -1;
2588
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002589 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002590 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002591 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002592 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2593 return -1;
2594 }
2595
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002596 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002597#endif /* CONFIG_NO_SCAN_PROCESSING */
2598}
2599
Sunil Ravi77d572f2023-01-17 23:58:31 +00002600
2601int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2602{
2603#ifdef CONFIG_NO_SCAN_PROCESSING
2604 return -1;
2605#else /* CONFIG_NO_SCAN_PROCESSING */
2606 return wpas_select_network_from_last_scan(wpa_s, 1, 1);
2607#endif /* CONFIG_NO_SCAN_PROCESSING */
2608}
2609
2610
Dmitry Shmidt04949592012-07-19 12:16:46 -07002611#ifdef CONFIG_WNM
2612
2613static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2614{
2615 struct wpa_supplicant *wpa_s = eloop_ctx;
2616
2617 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2618 return;
2619
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002620 if (!wpa_s->no_keep_alive) {
2621 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2622 MAC2STR(wpa_s->bssid));
2623 /* TODO: could skip this if normal data traffic has been sent */
2624 /* TODO: Consider using some more appropriate data frame for
2625 * this */
2626 if (wpa_s->l2)
2627 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2628 (u8 *) "", 0);
2629 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002630
2631#ifdef CONFIG_SME
2632 if (wpa_s->sme.bss_max_idle_period) {
2633 unsigned int msec;
2634 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2635 if (msec > 100)
2636 msec -= 100;
2637 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2638 wnm_bss_keep_alive, wpa_s, NULL);
2639 }
2640#endif /* CONFIG_SME */
2641}
2642
2643
2644static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2645 const u8 *ies, size_t ies_len)
2646{
2647 struct ieee802_11_elems elems;
2648
2649 if (ies == NULL)
2650 return;
2651
2652 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2653 return;
2654
2655#ifdef CONFIG_SME
2656 if (elems.bss_max_idle_period) {
2657 unsigned int msec;
2658 wpa_s->sme.bss_max_idle_period =
2659 WPA_GET_LE16(elems.bss_max_idle_period);
2660 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2661 "TU)%s", wpa_s->sme.bss_max_idle_period,
2662 (elems.bss_max_idle_period[2] & 0x01) ?
2663 " (protected keep-live required)" : "");
2664 if (wpa_s->sme.bss_max_idle_period == 0)
2665 wpa_s->sme.bss_max_idle_period = 1;
2666 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2667 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2668 /* msec times 1000 */
2669 msec = wpa_s->sme.bss_max_idle_period * 1024;
2670 if (msec > 100)
2671 msec -= 100;
2672 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2673 wnm_bss_keep_alive, wpa_s,
2674 NULL);
2675 }
2676 }
2677#endif /* CONFIG_SME */
2678}
2679
2680#endif /* CONFIG_WNM */
2681
2682
2683void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2684{
2685#ifdef CONFIG_WNM
2686 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2687#endif /* CONFIG_WNM */
2688}
2689
2690
Dmitry Shmidt051af732013-10-22 13:52:46 -07002691#ifdef CONFIG_INTERWORKING
2692
2693static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2694 size_t len)
2695{
2696 int res;
2697
2698 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2699 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2700 if (res) {
2701 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2702 }
2703
2704 return res;
2705}
2706
2707
2708static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2709 const u8 *ies, size_t ies_len)
2710{
2711 struct ieee802_11_elems elems;
2712
2713 if (ies == NULL)
2714 return;
2715
2716 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2717 return;
2718
2719 if (elems.qos_map_set) {
2720 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2721 elems.qos_map_set_len);
2722 }
2723}
2724
2725#endif /* CONFIG_INTERWORKING */
2726
2727
Sunil Ravi036cec52023-03-29 11:35:17 -07002728static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
2729{
2730 if (wpa_s->enabled_4addr_mode) {
2731 wpa_printf(MSG_DEBUG, "4addr mode already set");
2732 return;
2733 }
2734
2735 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2736 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
2737 goto fail;
2738 }
2739 wpa_s->enabled_4addr_mode = 1;
2740 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
2741 return;
2742
2743fail:
2744 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2745}
2746
2747
Hai Shalom74f70d42019-02-11 14:42:39 -08002748static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2749 const u8 *ies, size_t ies_len)
2750{
2751 struct ieee802_11_elems elems;
2752 const u8 *map_sub_elem, *pos;
2753 size_t len;
2754
Hai Shalomfdcde762020-04-02 11:19:20 -07002755 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002756
Hai Shalomfdcde762020-04-02 11:19:20 -07002757 if (!ies ||
2758 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2759 !elems.multi_ap || elems.multi_ap_len < 7)
2760 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002761
2762 pos = elems.multi_ap + 4;
2763 len = elems.multi_ap_len - 4;
2764
2765 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002766 if (!map_sub_elem || map_sub_elem[1] < 1)
2767 return;
2768
2769 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2770 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2771 MULTI_AP_FRONTHAUL_BSS);
2772 wpa_s->multi_ap_ie = 1;
2773}
2774
2775
2776static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2777{
2778 if (!wpa_s->current_ssid ||
2779 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2780 return;
2781
2782 if (!wpa_s->multi_ap_ie) {
2783 wpa_printf(MSG_INFO,
2784 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002785 goto fail;
2786 }
2787
Hai Shalomfdcde762020-04-02 11:19:20 -07002788 if (!wpa_s->multi_ap_backhaul) {
2789 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002790 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2791 wpa_printf(MSG_INFO,
2792 "WPS active, accepting fronthaul-only BSS");
2793 /* Don't set 4addr mode in this case, so just return */
2794 return;
2795 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002796 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2797 goto fail;
2798 }
2799
Sunil Ravi036cec52023-03-29 11:35:17 -07002800 wpa_supplicant_set_4addr_mode(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08002801 return;
2802
2803fail:
2804 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2805}
2806
2807
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002808#ifdef CONFIG_FST
2809static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2810 const u8 *ie, size_t ie_len)
2811{
2812 struct mb_ies_info mb_ies;
2813
2814 if (!ie || !ie_len || !wpa_s->fst)
2815 return -ENOENT;
2816
2817 os_memset(&mb_ies, 0, sizeof(mb_ies));
2818
2819 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2820 size_t len;
2821
2822 len = 2 + ie[1];
2823 if (len > ie_len) {
2824 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2825 ie, ie_len);
2826 break;
2827 }
2828
2829 if (ie[0] == WLAN_EID_MULTI_BAND) {
2830 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2831 (unsigned int) len);
2832 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2833 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2834 mb_ies.nof_ies++;
2835 }
2836
2837 ie_len -= len;
2838 ie += len;
2839 }
2840
2841 if (mb_ies.nof_ies > 0) {
2842 wpabuf_free(wpa_s->received_mb_ies);
2843 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2844 return 0;
2845 }
2846
2847 return -ENOENT;
2848}
2849#endif /* CONFIG_FST */
2850
2851
Hai Shalomc1a21442022-02-04 13:43:00 -08002852static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2853 union wpa_event_data *data)
2854{
2855 int sel;
2856 const u8 *p;
2857 int l, len;
2858 bool found = false;
2859 struct wpa_ie_data ie;
2860 struct wpa_ssid *ssid = wpa_s->current_ssid;
2861 struct wpa_bss *bss = wpa_s->current_bss;
2862 int pmf;
2863
2864 if (!ssid)
2865 return 0;
2866
2867 p = data->assoc_info.req_ies;
2868 l = data->assoc_info.req_ies_len;
2869
2870 while (p && l >= 2) {
2871 len = p[1] + 2;
2872 if (len > l) {
2873 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2874 p, l);
2875 break;
2876 }
2877 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2878 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2879 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2880 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2881 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2882 found = true;
2883 break;
2884 }
2885 l -= len;
2886 p += len;
2887 }
2888
Sunil Ravi036cec52023-03-29 11:35:17 -07002889 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
2890 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
Hai Shalomc1a21442022-02-04 13:43:00 -08002891 return 0;
Sunil Ravi036cec52023-03-29 11:35:17 -07002892 }
Hai Shalomc1a21442022-02-04 13:43:00 -08002893
2894 wpa_hexdump(MSG_DEBUG,
2895 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2896 p, l);
2897
2898 /* Update proto from (Re)Association Request frame info */
2899 wpa_s->wpa_proto = ie.proto;
2900 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2901 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2902 !!(wpa_s->wpa_proto &
2903 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2904
2905 /* Update AKMP suite from (Re)Association Request frame info */
2906 sel = ie.key_mgmt;
2907 if (ssid->key_mgmt)
2908 sel &= ssid->key_mgmt;
2909
2910 wpa_dbg(wpa_s, MSG_DEBUG,
2911 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2912 ie.key_mgmt, ssid->key_mgmt, sel);
2913 if (ie.key_mgmt && !sel) {
2914 wpa_supplicant_deauthenticate(
2915 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2916 return -1;
2917 }
2918
Sunil Ravi036cec52023-03-29 11:35:17 -07002919#ifdef CONFIG_OCV
2920 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
2921 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
2922 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
2923 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
2924#endif /* CONFIG_OCV */
2925
Sunil Ravi89eba102022-09-13 21:04:37 -07002926 /*
2927 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
2928 * different AKM.
2929 */
2930 if (wpa_s->key_mgmt != ie.key_mgmt &&
2931 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
2932 if (!ssid->psk_set) {
2933 wpa_dbg(wpa_s, MSG_INFO,
2934 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00002935 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07002936 return -1;
2937 }
2938
2939 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
2940 if (wpa_s->conf->key_mgmt_offload &&
2941 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002942 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
2943 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07002944 wpa_dbg(wpa_s, MSG_ERROR,
2945 "WPA: Cannot set PMK for key management offload");
2946 }
2947
Hai Shalomc1a21442022-02-04 13:43:00 -08002948 wpa_s->key_mgmt = ie.key_mgmt;
2949 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2950 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2951 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2952 wpa_s->wpa_proto);
2953
2954 /* Update pairwise cipher from (Re)Association Request frame info */
2955 sel = ie.pairwise_cipher;
2956 if (ssid->pairwise_cipher)
2957 sel &= ssid->pairwise_cipher;
2958
2959 wpa_dbg(wpa_s, MSG_DEBUG,
2960 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2961 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2962 if (ie.pairwise_cipher && !sel) {
2963 wpa_supplicant_deauthenticate(
2964 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2965 return -1;
2966 }
2967
2968 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2969 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2970 wpa_s->pairwise_cipher);
2971 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2972 wpa_cipher_txt(wpa_s->pairwise_cipher));
2973
2974 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2975 if (!bss) {
2976 wpa_dbg(wpa_s, MSG_DEBUG,
2977 "WPA: current_bss == NULL - skip AP IE check");
2978 return 0;
2979 }
2980
2981 /* Update GTK and IGTK from AP's RSNE */
2982 found = false;
2983
2984 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2985 const u8 *bss_rsn;
2986
2987 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2988 if (bss_rsn) {
2989 p = bss_rsn;
2990 len = 2 + bss_rsn[1];
2991 found = true;
2992 }
2993 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2994 const u8 *bss_wpa;
2995
2996 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2997 if (bss_wpa) {
2998 p = bss_wpa;
2999 len = 2 + bss_wpa[1];
3000 found = true;
3001 }
3002 }
3003
3004 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
3005 return 0;
3006
3007 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
3008 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3009 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3010 /* AP does not support MFP, local configuration requires it */
3011 wpa_supplicant_deauthenticate(
3012 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3013 return -1;
3014 }
3015 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3016 pmf == NO_MGMT_FRAME_PROTECTION) {
3017 /* AP requires MFP, local configuration disables it */
3018 wpa_supplicant_deauthenticate(
3019 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3020 return -1;
3021 }
3022
3023 /* Update PMF from local configuration now that MFP validation was done
3024 * above */
3025 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3026
3027 /* Update GTK from AP's RSNE */
3028 sel = ie.group_cipher;
3029 if (ssid->group_cipher)
3030 sel &= ssid->group_cipher;
3031
3032 wpa_dbg(wpa_s, MSG_DEBUG,
3033 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3034 ie.group_cipher, ssid->group_cipher, sel);
3035 if (ie.group_cipher && !sel) {
3036 wpa_supplicant_deauthenticate(
3037 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3038 return -1;
3039 }
3040
3041 wpa_s->group_cipher = ie.group_cipher;
3042 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3043 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3044 wpa_cipher_txt(wpa_s->group_cipher));
3045
3046 /* Update IGTK from AP RSN IE */
3047 sel = ie.mgmt_group_cipher;
3048 if (ssid->group_mgmt_cipher)
3049 sel &= ssid->group_mgmt_cipher;
3050
3051 wpa_dbg(wpa_s, MSG_DEBUG,
3052 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3053 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3054
3055 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3056 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3057 wpa_dbg(wpa_s, MSG_DEBUG,
3058 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3059 ie.capabilities);
3060 ie.mgmt_group_cipher = 0;
3061 }
3062
3063 if (ie.mgmt_group_cipher && !sel) {
3064 wpa_supplicant_deauthenticate(
3065 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3066 return -1;
3067 }
3068
3069 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3070 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3071 wpa_s->mgmt_group_cipher);
3072 if (wpa_s->mgmt_group_cipher)
3073 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3074 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3075 else
3076 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3077
3078 return 0;
3079}
3080
3081
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003082static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3083 union wpa_event_data *data)
3084{
Hai Shalomc3565922019-10-28 11:58:20 -07003085 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003086 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003087 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003088 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003089#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303090 struct wpa_ie_data ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003091#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003092
3093 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07003094 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003095 if (data->assoc_info.req_ies)
3096 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3097 data->assoc_info.req_ies_len);
3098 if (data->assoc_info.resp_ies) {
3099 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3100 data->assoc_info.resp_ies_len);
3101#ifdef CONFIG_TDLS
3102 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3103 data->assoc_info.resp_ies_len);
3104#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003105#ifdef CONFIG_WNM
3106 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3107 data->assoc_info.resp_ies_len);
3108#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003109#ifdef CONFIG_INTERWORKING
3110 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3111 data->assoc_info.resp_ies_len);
3112#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003113 if (wpa_s->hw_capab == CAPAB_VHT &&
3114 get_ie(data->assoc_info.resp_ies,
3115 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3116 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003117
3118 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3119 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003120 }
3121 if (data->assoc_info.beacon_ies)
3122 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3123 data->assoc_info.beacon_ies,
3124 data->assoc_info.beacon_ies_len);
3125 if (data->assoc_info.freq)
3126 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3127 data->assoc_info.freq);
3128
Hai Shalom021b0b52019-04-10 11:17:58 -07003129 wpa_s->connection_set = 0;
3130 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3131 struct ieee802_11_elems req_elems, resp_elems;
3132
3133 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3134 data->assoc_info.req_ies_len,
3135 &req_elems, 0) != ParseFailed &&
3136 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3137 data->assoc_info.resp_ies_len,
3138 &resp_elems, 0) != ParseFailed) {
3139 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003140 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3141 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003142 wpa_s->connection_ht = req_elems.ht_capabilities &&
3143 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003144 /* Do not include subset of VHT on 2.4 GHz vendor
3145 * extension in consideration for reporting VHT
3146 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003147 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003148 resp_elems.vht_capabilities &&
3149 (!data->assoc_info.freq ||
3150 wpas_freq_to_band(data->assoc_info.freq) !=
3151 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003152 wpa_s->connection_he = req_elems.he_capabilities &&
3153 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003154 wpa_s->connection_eht = req_elems.eht_capabilities &&
3155 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003156
3157 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3158 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3159 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3160 max_nss_rx_req : max_nss_rx_resp;
3161 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3162 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3163 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3164 max_nss_tx_req : max_nss_tx_resp;
3165
3166 struct supported_chan_width sta_supported_chan_width =
3167 get_supported_channel_width(&req_elems);
3168 enum chan_width ap_operation_chan_width =
3169 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303170 if (wpa_s->connection_vht || wpa_s->connection_he ||
3171 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003172 wpa_s->connection_channel_bandwidth =
3173 get_sta_operation_chan_width(ap_operation_chan_width,
3174 sta_supported_chan_width);
3175 } else if (wpa_s->connection_ht) {
3176 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3177 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3178 } else {
3179 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3180 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003181 }
3182 }
3183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003184 p = data->assoc_info.req_ies;
3185 l = data->assoc_info.req_ies_len;
3186
3187 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3188 while (p && l >= 2) {
3189 len = p[1] + 2;
3190 if (len > l) {
3191 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3192 p, l);
3193 break;
3194 }
Hai Shalomc3565922019-10-28 11:58:20 -07003195 if (!found &&
3196 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3197 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3198 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3199 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3200 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003201 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3202 break;
3203 found = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07003204 wpa_find_assoc_pmkid(wpa_s,
3205 data->assoc_info.authorized);
Hai Shalomc3565922019-10-28 11:58:20 -07003206 }
3207 if (!found_x && p[0] == WLAN_EID_RSNX) {
3208 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3209 break;
3210 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003211 }
3212 l -= len;
3213 p += len;
3214 }
3215 if (!found && data->assoc_info.req_ies)
3216 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003217 if (!found_x && data->assoc_info.req_ies)
3218 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003219
Winnie Chen4138eec2022-11-10 16:32:53 +08003220#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303221 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3222 * to a different security type, update the current supplicant configuration to use the AKM
3223 * and pairwise suites from the assoc IE passed by the driver.
3224 */
3225 if (wpas_driver_bss_selection(wpa_s)) {
3226 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3227 /* Check if firmware has roamed to a different security network */
3228 if(wpa_s->key_mgmt != ie.key_mgmt) {
3229 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3230 ie.key_mgmt);
3231 wpa_s->key_mgmt = ie.key_mgmt;
3232 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3233
3234 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3235 /* Restore PMK as it can get overwritten if the previous
3236 * association was to 802.1X.
3237 */
3238 if ((!(wpa_s->drv_flags &
3239 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3240 (wpa_s->current_ssid) &&
3241 (wpa_s->current_ssid->psk_set)) {
3242 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3243 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3244 "BSSID");
3245 wpa_supplicant_deauthenticate(
3246 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3247 return -1;
3248 }
3249 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3250 PMK_LEN, NULL, bssid);
3251 }
3252 }
3253 }
3254 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3255 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3256 "from Assoc IE", ie.pairwise_cipher);
3257 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3258 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3259 wpa_s->pairwise_cipher);
3260 }
3261 // TODO: Notify the framework about security type change b/230766005
3262 }
3263 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003264#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303265
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003266#ifdef CONFIG_FILS
3267#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003268 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3269 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003270 (!data->assoc_info.resp_frame ||
3271 fils_process_assoc_resp(wpa_s->wpa,
3272 data->assoc_info.resp_frame,
3273 data->assoc_info.resp_frame_len) < 0)) {
3274 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3275 return -1;
3276 }
3277#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003278
3279 /* Additional processing for FILS when SME is in driver */
3280 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3281 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3282 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003283#endif /* CONFIG_FILS */
3284
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003285#ifdef CONFIG_OWE
3286 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003287 (!bssid_known ||
Sunil Ravi036cec52023-03-29 11:35:17 -07003288 owe_process_assoc_resp(wpa_s->wpa,
3289 wpa_s->valid_links ?
3290 wpa_s->ap_mld_addr : bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003291 data->assoc_info.resp_ies,
3292 data->assoc_info.resp_ies_len) < 0)) {
3293 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3294 return -1;
3295 }
3296#endif /* CONFIG_OWE */
3297
Hai Shalom021b0b52019-04-10 11:17:58 -07003298#ifdef CONFIG_DPP2
3299 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003300 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3301 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003302 struct ieee802_11_elems elems;
3303
3304 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3305 data->assoc_info.resp_ies_len,
3306 &elems, 0) == ParseFailed ||
3307 !elems.owe_dh)
3308 goto no_pfs;
3309 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3310 elems.owe_dh_len) < 0) {
3311 wpa_supplicant_deauthenticate(wpa_s,
3312 WLAN_REASON_UNSPECIFIED);
3313 return -1;
3314 }
3315
3316 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3317 }
3318no_pfs:
3319#endif /* CONFIG_DPP2 */
3320
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003321#ifdef CONFIG_IEEE80211R
3322#ifdef CONFIG_SME
3323 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003324 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003325 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3326 data->assoc_info.resp_ies,
3327 data->assoc_info.resp_ies_len,
3328 bssid) < 0) {
3329 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3330 "Reassociation Response failed");
3331 wpa_supplicant_deauthenticate(
3332 wpa_s, WLAN_REASON_INVALID_IE);
3333 return -1;
3334 }
3335 }
3336
3337 p = data->assoc_info.resp_ies;
3338 l = data->assoc_info.resp_ies_len;
3339
3340#ifdef CONFIG_WPS_STRICT
3341 if (p && wpa_s->current_ssid &&
3342 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3343 struct wpabuf *wps;
3344 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3345 if (wps == NULL) {
3346 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3347 "include WPS IE in (Re)Association Response");
3348 return -1;
3349 }
3350
3351 if (wps_validate_assoc_resp(wps) < 0) {
3352 wpabuf_free(wps);
3353 wpa_supplicant_deauthenticate(
3354 wpa_s, WLAN_REASON_INVALID_IE);
3355 return -1;
3356 }
3357 wpabuf_free(wps);
3358 }
3359#endif /* CONFIG_WPS_STRICT */
3360
3361 /* Go through the IEs and make a copy of the MDIE, if present. */
3362 while (p && l >= 2) {
3363 len = p[1] + 2;
3364 if (len > l) {
3365 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3366 p, l);
3367 break;
3368 }
3369 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3370 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3371 wpa_s->sme.ft_used = 1;
3372 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3373 MOBILITY_DOMAIN_ID_LEN);
3374 break;
3375 }
3376 l -= len;
3377 p += len;
3378 }
3379#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003380#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303381 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3382 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3383 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3384 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303385 wpa_ft_is_completed(wpa_s->wpa)) {
3386 return 0;
3387 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003388#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003389
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003390 /* Process FT when SME is in the driver */
3391 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3392 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003393 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003394 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3395 data->assoc_info.resp_ies,
3396 data->assoc_info.resp_ies_len,
3397 bssid) < 0) {
3398 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3399 "Reassociation Response failed");
3400 wpa_supplicant_deauthenticate(
3401 wpa_s, WLAN_REASON_INVALID_IE);
3402 return -1;
3403 }
3404 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3405 }
3406
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003407 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3408 data->assoc_info.resp_ies_len);
3409#endif /* CONFIG_IEEE80211R */
3410
Hai Shalom899fcc72020-10-19 14:38:18 -07003411 if (bssid_known)
3412 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3413 data->assoc_info.resp_ies,
3414 data->assoc_info.resp_ies_len);
3415
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003416 /* WPA/RSN IE from Beacon/ProbeResp */
3417 p = data->assoc_info.beacon_ies;
3418 l = data->assoc_info.beacon_ies_len;
3419
3420 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3421 */
3422 wpa_found = rsn_found = 0;
3423 while (p && l >= 2) {
3424 len = p[1] + 2;
3425 if (len > l) {
3426 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3427 p, l);
3428 break;
3429 }
3430 if (!wpa_found &&
3431 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3432 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3433 wpa_found = 1;
3434 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3435 }
3436
3437 if (!rsn_found &&
3438 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3439 rsn_found = 1;
3440 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3441 }
3442
Hai Shalomc3565922019-10-28 11:58:20 -07003443 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3444 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3445
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003446 l -= len;
3447 p += len;
3448 }
3449
3450 if (!wpa_found && data->assoc_info.beacon_ies)
3451 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003452 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003453 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003454 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3455 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003456 if (wpa_found || rsn_found)
3457 wpa_s->ap_ies_from_associnfo = 1;
3458
Jouni Malinen87fd2792011-05-16 18:35:42 +03003459 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3460 wpa_s->assoc_freq != data->assoc_info.freq) {
3461 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3462 "%u to %u MHz",
3463 wpa_s->assoc_freq, data->assoc_info.freq);
3464 wpa_supplicant_update_scan_results(wpa_s);
3465 }
3466
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003467 wpa_s->assoc_freq = data->assoc_info.freq;
3468
Hai Shalomc1a21442022-02-04 13:43:00 -08003469 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3470 data->assoc_info.resp_ies_len);
3471
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003472 return 0;
3473}
3474
3475
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003476static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3477{
Hai Shalomc3565922019-10-28 11:58:20 -07003478 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003479
3480 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3481 return -1;
3482
3483 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3484 return 0;
3485
3486 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3487 WPA_IE_VENDOR_TYPE);
3488 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003489 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003490
3491 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3492 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3493 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003494 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3495 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3496 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003497 return -1;
3498
3499 return 0;
3500}
3501
3502
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003503static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3504 union wpa_event_data *data)
3505{
3506#ifdef CONFIG_FST
3507 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3508 struct wpa_bss *bss = wpa_s->current_bss;
3509 const u8 *ieprb, *iebcn;
3510
3511 wpabuf_free(wpa_s->received_mb_ies);
3512 wpa_s->received_mb_ies = NULL;
3513
3514 if (ai &&
3515 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3516 wpa_printf(MSG_DEBUG,
3517 "FST: MB IEs updated from Association Response frame");
3518 return;
3519 }
3520
3521 if (ai &&
3522 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3523 wpa_printf(MSG_DEBUG,
3524 "FST: MB IEs updated from association event Beacon IEs");
3525 return;
3526 }
3527
3528 if (!bss)
3529 return;
3530
Hai Shalom60840252021-02-19 19:02:11 -08003531 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003532 iebcn = ieprb + bss->ie_len;
3533
3534 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3535 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3536 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3537 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3538#endif /* CONFIG_FST */
3539}
3540
3541
Sunil Ravi89eba102022-09-13 21:04:37 -07003542static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3543{
3544 struct driver_sta_mlo_info mlo;
3545 int i;
3546
Sunil Ravi77d572f2023-01-17 23:58:31 +00003547 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07003548 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3549 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3550 wpa_supplicant_deauthenticate(wpa_s,
3551 WLAN_REASON_DEAUTH_LEAVING);
3552 return -1;
3553 }
3554
3555 if (wpa_s->valid_links == mlo.valid_links) {
3556 bool match = true;
3557
3558 if (!mlo.valid_links)
3559 return 0;
3560
3561 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3562 if (!(mlo.valid_links & BIT(i)))
3563 continue;
3564
3565 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3566 ETH_ALEN) != 0 ||
3567 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3568 ETH_ALEN) != 0) {
3569 match = false;
3570 break;
3571 }
3572 }
3573
Sunil Ravi77d572f2023-01-17 23:58:31 +00003574 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravi89eba102022-09-13 21:04:37 -07003575 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3576 ETH_ALEN) == 0)
3577 return 0;
3578 }
3579
3580 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00003581 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07003582 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3583 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3584 if (!(wpa_s->valid_links & BIT(i)))
3585 continue;
3586
3587 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3588 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3589 wpa_s->links[i].freq = mlo.links[i].freq;
3590 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3591 }
3592
3593 return 0;
3594}
3595
3596
Sunil Ravi77d572f2023-01-17 23:58:31 +00003597static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
3598{
3599 struct driver_sta_mlo_info drv_mlo;
3600 struct wpa_sm_mlo wpa_mlo;
3601 const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
3602 int i;
3603
3604 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
3605 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
3606 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
3607 return -1;
3608 }
3609
3610 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
3611 if (!drv_mlo.valid_links)
3612 goto out;
3613
3614 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
3615 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
3616 wpa_mlo.valid_links = drv_mlo.valid_links;
3617 wpa_mlo.req_links = drv_mlo.req_links;
3618
3619 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3620 struct wpa_bss *bss;
3621
3622 if (!(drv_mlo.req_links & BIT(i)))
3623 continue;
3624
3625 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
3626 if (!bss) {
3627 wpa_supplicant_update_scan_results(wpa_s);
3628 bss = wpa_supplicant_get_new_bss(
3629 wpa_s, drv_mlo.links[i].bssid);
3630 }
3631
3632 if (!bss) {
3633 wpa_dbg(wpa_s, MSG_INFO,
3634 "Failed to get MLO link %d BSS", i);
3635 return -1;
3636 }
3637
3638 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3639 bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
3640
3641 wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
3642 wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
3643 wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
3644 wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
3645
3646 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
3647 ETH_ALEN);
3648 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
3649 ETH_ALEN);
3650 }
3651
3652out:
3653 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
3654}
3655
3656
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003657static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3658 union wpa_event_data *data)
3659{
3660 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003661 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003662 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003663#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3664 struct wpa_bss *bss;
3665#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003666#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303667 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003668#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003669
3670#ifdef CONFIG_AP
3671 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003672 if (!data)
3673 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003674 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3675 data->assoc_info.addr,
3676 data->assoc_info.req_ies,
3677 data->assoc_info.req_ies_len,
3678 data->assoc_info.reassoc);
3679 return;
3680 }
3681#endif /* CONFIG_AP */
3682
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003683 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003684 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003685
Andy Kuoaba17c12022-04-14 16:05:31 +08003686#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303687 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3688 struct wpa_ft_ies parse;
3689 /* Check for FT reassociation is done by the driver */
3690#ifdef CONFIG_IEEE80211R
3691 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303692 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303693 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3694 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3695 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3696 return;
3697 }
3698 if (parse.rsn_pmkid != NULL) {
3699 wpa_set_ft_completed(wpa_s->wpa);
3700 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3701 }
3702 }
3703#endif /* CONFIG_IEEE80211R */
3704 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003705#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303706
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003707 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003708
3709 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3710 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3711 wpa_supplicant_deauthenticate(
3712 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3713 return;
3714 }
3715
Sunil Ravi89eba102022-09-13 21:04:37 -07003716 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3717 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3718 wpa_supplicant_deauthenticate(wpa_s,
3719 WLAN_REASON_DEAUTH_LEAVING);
3720 return;
3721 }
3722
Sunil Ravia04bd252022-05-02 22:54:18 -07003723 if (ft_completed &&
3724 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3725 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3726 MAC2STR(bssid));
3727 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3728 wpa_printf(MSG_ERROR,
3729 "Can't find target AP's information!");
3730 return;
3731 }
3732 wpa_supplicant_assoc_update_ie(wpa_s);
3733 }
3734
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003735 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3736 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003737 /*
3738 * FILS authentication can share the same mechanism to mark the
3739 * connection fully authenticated, so set ft_completed also based on
3740 * FILS result.
3741 */
3742 if (!ft_completed)
3743 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003744
Andy Kuoaba17c12022-04-14 16:05:31 +08003745#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303746 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3747 /*
3748 * For driver based roaming, insert PSK during
3749 * the initial association
3750 */
3751 if (is_zero_ether_addr(wpa_s->bssid) &&
3752 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3753 /*
3754 * In case the driver wants to handle re-assocs,
3755 * pass it down the PMK.
3756 */
3757 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3758 wpa_sm_install_pmk(wpa_s->wpa);
3759 }
Mir Ali677e7482020-11-12 19:49:02 +05303760 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303761#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003763 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003764 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003765 if (os_reltime_initialized(&wpa_s->session_start)) {
3766 os_reltime_age(&wpa_s->session_start,
3767 &wpa_s->session_length);
3768 wpa_s->session_start.sec = 0;
3769 wpa_s->session_start.usec = 0;
3770 wpas_notify_session_length(wpa_s);
3771 } else {
3772 wpas_notify_auth_changed(wpa_s);
3773 os_get_reltime(&wpa_s->session_start);
3774 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003775 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3776 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003777 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003778 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003779 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3780 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003781 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003782
3783 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3784 wpa_clear_keys(wpa_s, bssid);
3785 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00003786 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003787 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003788 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3789 return;
3790 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003791 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003792
Hai Shalomc1a21442022-02-04 13:43:00 -08003793 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3794 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3795 return;
3796
Hai Shalomfdcde762020-04-02 11:19:20 -07003797 multi_ap_set_4addr_mode(wpa_s);
3798
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003799 if (wpa_s->conf->ap_scan == 1 &&
3800 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003801 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3802 wpa_msg(wpa_s, MSG_WARNING,
3803 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003804 }
3805
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003806 wpas_fst_update_mb_assoc(wpa_s, data);
3807
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003808#ifdef CONFIG_SME
Sunil Ravi640215c2023-06-28 23:08:09 +00003809 /*
3810 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
3811 * (for MLO connection) as the previous BSSID for subsequent
3812 * reassociation requests handled by SME-in-wpa_supplicant.
3813 */
3814 os_memcpy(wpa_s->sme.prev_bssid,
3815 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003816 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003817 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003818#endif /* CONFIG_SME */
3819
3820 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3821 if (wpa_s->current_ssid) {
3822 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3823 * initialized before association, but for other modes,
3824 * initialize PC/SC here, if the current configuration needs
3825 * smartcard or SIM/USIM. */
3826 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3827 }
3828 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00003829
3830 if (wpa_sm_set_ml_info(wpa_s)) {
3831 wpa_dbg(wpa_s, MSG_INFO,
3832 "Failed to set MLO connection info to wpa_sm");
3833 wpa_supplicant_deauthenticate(wpa_s,
3834 WLAN_REASON_DEAUTH_LEAVING);
3835 return;
3836 }
3837
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003838 if (wpa_s->l2)
3839 l2_packet_notify_auth_start(wpa_s->l2);
3840
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003841 already_authorized = data && data->assoc_info.authorized;
3842
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003843 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003844 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003845 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3846 * state machine may transit to AUTHENTICATING state based on obsolete
3847 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3848 * AUTHENTICATED without ever giving chance to EAP state machine to
3849 * reset the state.
3850 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003851 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003852 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3853 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003854 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003855 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3856 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3857 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003858 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003859 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003860 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003861 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003862 wpa_s->eapol_received = 0;
3863 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3864 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3865 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003866 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003867 if (wpa_s->current_ssid &&
3868 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003869 (wpa_s->drv_flags &
3870 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3871 /*
3872 * Set the key after having received joined-IBSS event
3873 * from the driver.
3874 */
3875 wpa_supplicant_set_wpa_none_key(wpa_s,
3876 wpa_s->current_ssid);
3877 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003878 wpa_supplicant_cancel_auth_timeout(wpa_s);
3879 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3880 } else if (!ft_completed) {
3881 /* Timeout for receiving the first EAPOL packet */
3882 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3883 }
3884 wpa_supplicant_cancel_scan(wpa_s);
3885
Hai Shalom5f92bc92019-04-18 11:54:11 -07003886 if (ft_completed) {
3887 /*
3888 * FT protocol completed - make sure EAPOL state machine ends
3889 * up in authenticated.
3890 */
3891 wpa_supplicant_cancel_auth_timeout(wpa_s);
3892 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003893 eapol_sm_notify_portValid(wpa_s->eapol, true);
3894 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003895 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3896 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303897 if (already_authorized) {
3898 /*
3899 * We are done; the driver will take care of RSN 4-way
3900 * handshake.
3901 */
3902 wpa_supplicant_cancel_auth_timeout(wpa_s);
3903 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3904 eapol_sm_notify_portValid(wpa_s->eapol, true);
3905 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3906 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00003907 /* Update port, WPA_COMPLETED state from the
3908 * EVENT_PORT_AUTHORIZED handler when the driver is done
3909 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303910 */
Sunil Ravi167279a2023-05-31 01:12:34 +00003911 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00003912 wpa_msg(wpa_s, MSG_INFO,
3913 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303914 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003915 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003916 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3917 /*
3918 * The driver will take care of RSN 4-way handshake, so we need
3919 * to allow EAPOL supplicant to complete its work without
3920 * waiting for WPA supplicant.
3921 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003922 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003923 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003924#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303925 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3926 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3927 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3928 wpa_s->key_mgmt);
3929 wpa_supplicant_deauthenticate(
3930 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3931 return;
3932 }
3933 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3934 wpa_s->assoc_freq = data->assoc_info.freq;
3935 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3936 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003937#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3938
Jouni Malinena05074c2012-12-21 21:35:35 +02003939 wpa_s->last_eapol_matches_bssid = 0;
3940
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003941#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003942 if (wpa_s->rsne_override_eapol) {
3943 wpa_printf(MSG_DEBUG,
3944 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3945 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3946 wpabuf_head(wpa_s->rsne_override_eapol),
3947 wpabuf_len(wpa_s->rsne_override_eapol));
3948 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003949 if (wpa_s->rsnxe_override_eapol) {
3950 wpa_printf(MSG_DEBUG,
3951 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3952 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3953 wpabuf_head(wpa_s->rsnxe_override_eapol),
3954 wpabuf_len(wpa_s->rsnxe_override_eapol));
3955 }
3956#endif /* CONFIG_TESTING_OPTIONS */
3957
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003958 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003959 struct os_reltime now, age;
3960 os_get_reltime(&now);
3961 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003962 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003963 os_memcmp(wpa_s->pending_eapol_rx_src,
3964 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid,
3965 ETH_ALEN) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003966 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3967 "frame that was received just before "
3968 "association notification");
3969 wpa_supplicant_rx_eapol(
3970 wpa_s, wpa_s->pending_eapol_rx_src,
3971 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00003972 wpabuf_len(wpa_s->pending_eapol_rx),
3973 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003974 }
3975 wpabuf_free(wpa_s->pending_eapol_rx);
3976 wpa_s->pending_eapol_rx = NULL;
3977 }
3978
Hai Shalomfdcde762020-04-02 11:19:20 -07003979#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003980 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3981 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003982 wpa_s->current_ssid &&
3983 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003984 /* Set static WEP keys again */
3985 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3986 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003987#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003988
3989#ifdef CONFIG_IBSS_RSN
3990 if (wpa_s->current_ssid &&
3991 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3992 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3993 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3994 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003995 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003996 if (!wpa_s->ibss_rsn) {
3997 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3998 wpa_supplicant_deauthenticate(
3999 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4000 return;
4001 }
4002
4003 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4004 }
4005#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004006
4007 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004008
4009 if (data) {
4010 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4011 data->assoc_info.resp_ies_len,
4012 &data->assoc_info.wmm_params);
4013
4014 if (wpa_s->reassoc_same_bss)
4015 wmm_ac_restore_tspecs(wpa_s);
4016 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004017
Hai Shalomc3565922019-10-28 11:58:20 -07004018#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4019 bss = wpa_bss_get_bssid(wpa_s, bssid);
4020#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004021#ifdef CONFIG_FILS
4022 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004023 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4024
4025 if (fils_cache_id)
4026 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4027 }
4028#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004029
4030#ifdef CONFIG_MBO
4031 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4032#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004033
4034#ifdef CONFIG_DPP2
4035 wpa_s->dpp_pfs_fallback = 0;
4036#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004037
4038 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4039 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004040}
4041
4042
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004043static int disconnect_reason_recoverable(u16 reason_code)
4044{
4045 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4046 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4047 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4048}
4049
4050
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004051static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004052 u16 reason_code,
4053 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004054{
4055 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004056
4057 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4058 /*
4059 * At least Host AP driver and a Prism3 card seemed to be
4060 * generating streams of disconnected events when configuring
4061 * IBSS for WPA-None. Ignore them for now.
4062 */
4063 return;
4064 }
4065
4066 bssid = wpa_s->bssid;
4067 if (is_zero_ether_addr(bssid))
4068 bssid = wpa_s->pending_bssid;
4069
4070 if (!is_zero_ether_addr(bssid) ||
4071 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4072 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4073 " reason=%d%s",
4074 MAC2STR(bssid), reason_code,
4075 locally_generated ? " locally_generated=1" : "");
4076 }
4077}
4078
4079
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004080static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4081 int locally_generated)
4082{
4083 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004084 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004085 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4086 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004087 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004088
4089 /*
4090 * It looks like connection was lost while trying to go through PSK
4091 * 4-way handshake. Filter out known disconnection cases that are caused
4092 * by something else than PSK mismatch to avoid confusing reports.
4093 */
4094
4095 if (locally_generated) {
4096 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4097 return 0;
4098 }
4099
4100 return 1;
4101}
4102
4103
Jouni Malinen2b89da82012-08-31 22:04:41 +03004104static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4105 u16 reason_code,
4106 int locally_generated)
4107{
4108 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004109 int authenticating;
4110 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004111 struct wpa_bss *fast_reconnect = NULL;
4112 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004113 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004114 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004115
4116 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
4117 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
4118
4119 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4120 /*
4121 * At least Host AP driver and a Prism3 card seemed to be
4122 * generating streams of disconnected events when configuring
4123 * IBSS for WPA-None. Ignore them for now.
4124 */
4125 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4126 "IBSS/WPA-None mode");
4127 return;
4128 }
4129
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004130 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4131 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4132 locally_generated)
4133 /*
4134 * Remove the inactive AP (which is probably out of range) from
4135 * the BSS list after marking disassociation. In particular
4136 * mac80211-based drivers use the
4137 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4138 * locally generated disconnection events for cases where the
4139 * AP does not reply anymore.
4140 */
4141 curr = wpa_s->current_bss;
4142
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004143 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004144 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4145 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004146 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4147 return; /* P2P group removed */
Sunil Ravi77d572f2023-01-17 23:58:31 +00004148 wpas_auth_failed(wpa_s, "WRONG_KEY", prev_pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004149 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004150#ifdef CONFIG_DPP2
4151 wpas_dpp_send_conn_status_result(wpa_s,
4152 DPP_STATUS_AUTH_FAILURE);
4153#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004154 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004155 if (!wpa_s->disconnected &&
4156 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004157 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004158 wpas_wps_searching(wpa_s) ||
4159 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004160 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004161 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004162 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004163 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004164 wpa_s->wpa_state);
4165 if (wpa_s->wpa_state == WPA_COMPLETED &&
4166 wpa_s->current_ssid &&
4167 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004168 (wpa_s->own_reconnect_req ||
4169 (!locally_generated &&
4170 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004171 /*
4172 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004173 * us, but could allow us to get back in. This is also
4174 * triggered for cases where local reconnection request
4175 * is used to force reassociation with the same BSS.
4176 * Try to reconnect to the same BSS without a full scan
4177 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004178 */
4179 fast_reconnect = wpa_s->current_bss;
4180 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004181 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004182 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004183 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004184 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4185 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004186 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004187 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004188 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004189 "try to re-connect");
4190 wpa_s->reassociate = 0;
4191 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004192 if (!wpa_s->pno)
4193 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004194 }
4195 bssid = wpa_s->bssid;
4196 if (is_zero_ether_addr(bssid))
4197 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004198 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4199 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004200 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004201 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4202
Dmitry Shmidt04949592012-07-19 12:16:46 -07004203 if (locally_generated)
4204 wpa_s->disconnect_reason = -reason_code;
4205 else
4206 wpa_s->disconnect_reason = reason_code;
4207 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004208 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4209 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004210 wpa_clear_keys(wpa_s, wpa_s->bssid);
4211 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004212 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004213 wpa_supplicant_mark_disassoc(wpa_s);
4214
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004215 if (curr)
4216 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4217
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004218 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004219 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004220 wpa_s->current_ssid = last_ssid;
4221 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004222
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004223 if (fast_reconnect &&
4224 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4225 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4226 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4227 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004228 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004229 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004230#ifndef CONFIG_NO_SCAN_PROCESSING
4231 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4232 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4233 fast_reconnect_ssid) < 0) {
4234 /* Recover through full scan */
4235 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4236 }
4237#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004238 } else if (fast_reconnect) {
4239 /*
4240 * Could not reconnect to the same BSS due to network being
4241 * disabled. Use a new scan to match the alternative behavior
4242 * above, i.e., to continue automatic reconnection attempt in a
4243 * way that enforces disabled network rules.
4244 */
4245 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004246 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004247}
4248
4249
4250#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004251void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252{
4253 struct wpa_supplicant *wpa_s = eloop_ctx;
4254
4255 if (!wpa_s->pending_mic_error_report)
4256 return;
4257
4258 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4259 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4260 wpa_s->pending_mic_error_report = 0;
4261}
4262#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4263
4264
4265static void
4266wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4267 union wpa_event_data *data)
4268{
4269 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004270 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004271
4272 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4273 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004274 os_get_reltime(&t);
4275 if ((wpa_s->last_michael_mic_error.sec &&
4276 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004277 wpa_s->pending_mic_error_report) {
4278 if (wpa_s->pending_mic_error_report) {
4279 /*
4280 * Send the pending MIC error report immediately since
4281 * we are going to start countermeasures and AP better
4282 * do the same.
4283 */
4284 wpa_sm_key_request(wpa_s->wpa, 1,
4285 wpa_s->pending_mic_error_pairwise);
4286 }
4287
4288 /* Send the new MIC error report immediately since we are going
4289 * to start countermeasures and AP better do the same.
4290 */
4291 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4292
4293 /* initialize countermeasures */
4294 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004295
Hai Shalom60840252021-02-19 19:02:11 -08004296 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004298 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4299
4300 /*
4301 * Need to wait for completion of request frame. We do not get
4302 * any callback for the message completion, so just wait a
4303 * short while and hope for the best. */
4304 os_sleep(0, 10000);
4305
4306 wpa_drv_set_countermeasures(wpa_s, 1);
4307 wpa_supplicant_deauthenticate(wpa_s,
4308 WLAN_REASON_MICHAEL_MIC_FAILURE);
4309 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4310 wpa_s, NULL);
4311 eloop_register_timeout(60, 0,
4312 wpa_supplicant_stop_countermeasures,
4313 wpa_s, NULL);
4314 /* TODO: mark the AP rejected for 60 second. STA is
4315 * allowed to associate with another AP.. */
4316 } else {
4317#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4318 if (wpa_s->mic_errors_seen) {
4319 /*
4320 * Reduce the effectiveness of Michael MIC error
4321 * reports as a means for attacking against TKIP if
4322 * more than one MIC failure is noticed with the same
4323 * PTK. We delay the transmission of the reports by a
4324 * random time between 0 and 60 seconds in order to
4325 * force the attacker wait 60 seconds before getting
4326 * the information on whether a frame resulted in a MIC
4327 * failure.
4328 */
4329 u8 rval[4];
4330 int sec;
4331
4332 if (os_get_random(rval, sizeof(rval)) < 0)
4333 sec = os_random() % 60;
4334 else
4335 sec = WPA_GET_BE32(rval) % 60;
4336 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4337 "report %d seconds", sec);
4338 wpa_s->pending_mic_error_report = 1;
4339 wpa_s->pending_mic_error_pairwise = pairwise;
4340 eloop_cancel_timeout(
4341 wpa_supplicant_delayed_mic_error_report,
4342 wpa_s, NULL);
4343 eloop_register_timeout(
4344 sec, os_random() % 1000000,
4345 wpa_supplicant_delayed_mic_error_report,
4346 wpa_s, NULL);
4347 } else {
4348 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4349 }
4350#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4351 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4352#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4353 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004354 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004355 wpa_s->mic_errors_seen++;
4356}
4357
4358
4359#ifdef CONFIG_TERMINATE_ONLASTIF
4360static int any_interfaces(struct wpa_supplicant *head)
4361{
4362 struct wpa_supplicant *wpa_s;
4363
4364 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4365 if (!wpa_s->interface_removed)
4366 return 1;
4367 return 0;
4368}
4369#endif /* CONFIG_TERMINATE_ONLASTIF */
4370
4371
4372static void
4373wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4374 union wpa_event_data *data)
4375{
4376 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4377 return;
4378
4379 switch (data->interface_status.ievent) {
4380 case EVENT_INTERFACE_ADDED:
4381 if (!wpa_s->interface_removed)
4382 break;
4383 wpa_s->interface_removed = 0;
4384 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4385 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4386 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4387 "driver after interface was added");
4388 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004389
4390#ifdef CONFIG_P2P
4391 if (!wpa_s->global->p2p &&
4392 !wpa_s->global->p2p_disabled &&
4393 !wpa_s->conf->p2p_disabled &&
4394 (wpa_s->drv_flags &
4395 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4396 wpas_p2p_add_p2pdev_interface(
4397 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4398 wpa_printf(MSG_INFO,
4399 "P2P: Failed to enable P2P Device interface");
4400 /* Try to continue without. P2P will be disabled. */
4401 }
4402#endif /* CONFIG_P2P */
4403
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004404 break;
4405 case EVENT_INTERFACE_REMOVED:
4406 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4407 wpa_s->interface_removed = 1;
4408 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004409 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004410 l2_packet_deinit(wpa_s->l2);
4411 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004412
4413#ifdef CONFIG_P2P
4414 if (wpa_s->global->p2p &&
4415 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4416 (wpa_s->drv_flags &
4417 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4418 wpa_dbg(wpa_s, MSG_DEBUG,
4419 "Removing P2P Device interface");
4420 wpa_supplicant_remove_iface(
4421 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4422 0);
4423 wpa_s->global->p2p_init_wpa_s = NULL;
4424 }
4425#endif /* CONFIG_P2P */
4426
Dmitry Shmidte4663042016-04-04 10:07:49 -07004427#ifdef CONFIG_MATCH_IFACE
4428 if (wpa_s->matched) {
4429 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4430 break;
4431 }
4432#endif /* CONFIG_MATCH_IFACE */
4433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004434#ifdef CONFIG_TERMINATE_ONLASTIF
4435 /* check if last interface */
4436 if (!any_interfaces(wpa_s->global->ifaces))
4437 eloop_terminate();
4438#endif /* CONFIG_TERMINATE_ONLASTIF */
4439 break;
4440 }
4441}
4442
4443
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004444#ifdef CONFIG_TDLS
4445static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4446 union wpa_event_data *data)
4447{
4448 if (data == NULL)
4449 return;
4450 switch (data->tdls.oper) {
4451 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004452 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4453 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4454 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4455 else
4456 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004457 break;
4458 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004459 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4460 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4461 data->tdls.reason_code);
4462 else
4463 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4464 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004465 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004466 case TDLS_REQUEST_DISCOVER:
4467 wpa_tdls_send_discovery_request(wpa_s->wpa,
4468 data->tdls.peer);
4469 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004470 }
4471}
4472#endif /* CONFIG_TDLS */
4473
4474
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004475#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004476static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4477 union wpa_event_data *data)
4478{
4479 if (data == NULL)
4480 return;
4481 switch (data->wnm.oper) {
4482 case WNM_OPER_SLEEP:
4483 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4484 "(action=%d, intval=%d)",
4485 data->wnm.sleep_action, data->wnm.sleep_intval);
4486 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004487 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004488 break;
4489 }
4490}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004491#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004492
4493
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004494#ifdef CONFIG_IEEE80211R
4495static void
4496wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4497 union wpa_event_data *data)
4498{
4499 if (data == NULL)
4500 return;
4501
4502 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4503 data->ft_ies.ies_len,
4504 data->ft_ies.ft_action,
4505 data->ft_ies.target_ap,
4506 data->ft_ies.ric_ies,
4507 data->ft_ies.ric_ies_len) < 0) {
4508 /* TODO: prevent MLME/driver from trying to associate? */
4509 }
4510}
4511#endif /* CONFIG_IEEE80211R */
4512
4513
4514#ifdef CONFIG_IBSS_RSN
4515static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4516 union wpa_event_data *data)
4517{
4518 struct wpa_ssid *ssid;
4519 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4520 return;
4521 if (data == NULL)
4522 return;
4523 ssid = wpa_s->current_ssid;
4524 if (ssid == NULL)
4525 return;
4526 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4527 return;
4528
4529 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4530}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004531
4532
4533static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4534 union wpa_event_data *data)
4535{
4536 struct wpa_ssid *ssid = wpa_s->current_ssid;
4537
4538 if (ssid == NULL)
4539 return;
4540
4541 /* check if the ssid is correctly configured as IBSS/RSN */
4542 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4543 return;
4544
4545 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4546 data->rx_mgmt.frame_len);
4547}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004548#endif /* CONFIG_IBSS_RSN */
4549
4550
4551#ifdef CONFIG_IEEE80211R
4552static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4553 size_t len)
4554{
4555 const u8 *sta_addr, *target_ap_addr;
4556 u16 status;
4557
4558 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4559 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4560 return; /* only SME case supported for now */
4561 if (len < 1 + 2 * ETH_ALEN + 2)
4562 return;
4563 if (data[0] != 2)
4564 return; /* Only FT Action Response is supported for now */
4565 sta_addr = data + 1;
4566 target_ap_addr = data + 1 + ETH_ALEN;
4567 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4568 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4569 MACSTR " TargetAP " MACSTR " status %u",
4570 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4571
4572 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4573 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4574 " in FT Action Response", MAC2STR(sta_addr));
4575 return;
4576 }
4577
4578 if (status) {
4579 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4580 "failure (status code %d)", status);
4581 /* TODO: report error to FT code(?) */
4582 return;
4583 }
4584
4585 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4586 len - (1 + 2 * ETH_ALEN + 2), 1,
4587 target_ap_addr, NULL, 0) < 0)
4588 return;
4589
4590#ifdef CONFIG_SME
4591 {
4592 struct wpa_bss *bss;
4593 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4594 if (bss)
4595 wpa_s->sme.freq = bss->freq;
4596 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4597 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4598 WLAN_AUTH_FT);
4599 }
4600#endif /* CONFIG_SME */
4601}
4602#endif /* CONFIG_IEEE80211R */
4603
4604
4605static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4606 struct unprot_deauth *e)
4607{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004608 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4609 "dropped: " MACSTR " -> " MACSTR
4610 " (reason code %u)",
4611 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4612 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004613}
4614
4615
4616static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4617 struct unprot_disassoc *e)
4618{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004619 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4620 "dropped: " MACSTR " -> " MACSTR
4621 " (reason code %u)",
4622 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4623 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004624}
4625
4626
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004627static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4628 u16 reason_code, int locally_generated,
4629 const u8 *ie, size_t ie_len, int deauth)
4630{
4631#ifdef CONFIG_AP
4632 if (wpa_s->ap_iface && addr) {
4633 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4634 return;
4635 }
4636
4637 if (wpa_s->ap_iface) {
4638 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4639 return;
4640 }
4641#endif /* CONFIG_AP */
4642
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004643 if (!locally_generated)
4644 wpa_s->own_disconnect_req = 0;
4645
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004646 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4647
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004648 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4649 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4650 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4651 eapol_sm_failed(wpa_s->eapol))) &&
4652 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00004653 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004654
4655#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004656 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004657 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4658 locally_generated) > 0) {
4659 /*
4660 * The interface was removed, so cannot continue
4661 * processing any additional operations after this.
4662 */
4663 return;
4664 }
4665 }
4666#endif /* CONFIG_P2P */
4667
4668 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4669 locally_generated);
4670}
4671
4672
4673static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4674 struct disassoc_info *info)
4675{
4676 u16 reason_code = 0;
4677 int locally_generated = 0;
4678 const u8 *addr = NULL;
4679 const u8 *ie = NULL;
4680 size_t ie_len = 0;
4681
4682 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4683
4684 if (info) {
4685 addr = info->addr;
4686 ie = info->ie;
4687 ie_len = info->ie_len;
4688 reason_code = info->reason_code;
4689 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004690 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4691 reason2str(reason_code),
4692 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004693 if (addr)
4694 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4695 MAC2STR(addr));
4696 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4697 ie, ie_len);
4698 }
4699
4700#ifdef CONFIG_AP
4701 if (wpa_s->ap_iface && info && info->addr) {
4702 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4703 return;
4704 }
4705
4706 if (wpa_s->ap_iface) {
4707 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4708 return;
4709 }
4710#endif /* CONFIG_AP */
4711
4712#ifdef CONFIG_P2P
4713 if (info) {
4714 wpas_p2p_disassoc_notif(
4715 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4716 locally_generated);
4717 }
4718#endif /* CONFIG_P2P */
4719
4720 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4721 sme_event_disassoc(wpa_s, info);
4722
4723 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4724 ie, ie_len, 0);
4725}
4726
4727
4728static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4729 struct deauth_info *info)
4730{
4731 u16 reason_code = 0;
4732 int locally_generated = 0;
4733 const u8 *addr = NULL;
4734 const u8 *ie = NULL;
4735 size_t ie_len = 0;
4736
4737 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4738
4739 if (info) {
4740 addr = info->addr;
4741 ie = info->ie;
4742 ie_len = info->ie_len;
4743 reason_code = info->reason_code;
4744 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004745 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4746 reason_code, reason2str(reason_code),
4747 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004748 if (addr) {
4749 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4750 MAC2STR(addr));
4751 }
4752 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4753 ie, ie_len);
4754 }
4755
4756 wpa_reset_ft_completed(wpa_s->wpa);
4757
4758 wpas_event_disconnect(wpa_s, addr, reason_code,
4759 locally_generated, ie, ie_len, 1);
4760}
4761
4762
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004763static const char * reg_init_str(enum reg_change_initiator init)
4764{
4765 switch (init) {
4766 case REGDOM_SET_BY_CORE:
4767 return "CORE";
4768 case REGDOM_SET_BY_USER:
4769 return "USER";
4770 case REGDOM_SET_BY_DRIVER:
4771 return "DRIVER";
4772 case REGDOM_SET_BY_COUNTRY_IE:
4773 return "COUNTRY_IE";
4774 case REGDOM_BEACON_HINT:
4775 return "BEACON_HINT";
4776 }
4777 return "?";
4778}
4779
4780
4781static const char * reg_type_str(enum reg_type type)
4782{
4783 switch (type) {
4784 case REGDOM_TYPE_UNKNOWN:
4785 return "UNKNOWN";
4786 case REGDOM_TYPE_COUNTRY:
4787 return "COUNTRY";
4788 case REGDOM_TYPE_WORLD:
4789 return "WORLD";
4790 case REGDOM_TYPE_CUSTOM_WORLD:
4791 return "CUSTOM_WORLD";
4792 case REGDOM_TYPE_INTERSECTION:
4793 return "INTERSECTION";
4794 }
4795 return "?";
4796}
4797
4798
Hai Shalom74f70d42019-02-11 14:42:39 -08004799void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4800 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004801{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004802 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004803 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004804
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004805 /*
4806 * To allow backwards compatibility with higher level layers that
4807 * assumed the REGDOM_CHANGE event is sent over the initially added
4808 * interface. Find the highest parent of this interface and use it to
4809 * send the event.
4810 */
4811 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4812 ;
4813
Hai Shalom74f70d42019-02-11 14:42:39 -08004814 if (info) {
4815 wpa_msg(ifs, MSG_INFO,
4816 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4817 reg_init_str(info->initiator), reg_type_str(info->type),
4818 info->alpha2[0] ? " alpha2=" : "",
4819 info->alpha2[0] ? info->alpha2 : "");
4820 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004821
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004822 if (wpa_s->drv_priv == NULL)
4823 return; /* Ignore event during drv initialization */
4824
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004825 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4826 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004827 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4828 ifs->ifname);
4829 free_hw_features(ifs);
4830 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004831 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004832
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004833 /* Restart PNO/sched_scan with updated channel list */
4834 if (ifs->pno) {
4835 wpas_stop_pno(ifs);
4836 wpas_start_pno(ifs);
4837 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4838 wpa_dbg(ifs, MSG_DEBUG,
4839 "Channel list changed - restart sched_scan");
4840 wpas_scan_restart_sched_scan(ifs);
4841 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004842 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004843
4844 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004845}
4846
4847
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004848static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004849 const u8 *frame, size_t len, int freq,
4850 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004851{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004852 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004853 const u8 *payload;
4854 size_t plen;
4855 u8 category;
4856
4857 if (len < IEEE80211_HDRLEN + 2)
4858 return;
4859
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004860 mgmt = (const struct ieee80211_mgmt *) frame;
4861 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004862 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004863 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004864
4865 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4866 " Category=%u DataLen=%d freq=%d MHz",
4867 MAC2STR(mgmt->sa), category, (int) plen, freq);
4868
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004869 if (category == WLAN_ACTION_WMM) {
4870 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4871 return;
4872 }
4873
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004874#ifdef CONFIG_IEEE80211R
4875 if (category == WLAN_ACTION_FT) {
4876 ft_rx_action(wpa_s, payload, plen);
4877 return;
4878 }
4879#endif /* CONFIG_IEEE80211R */
4880
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004881#ifdef CONFIG_SME
4882 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004883 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004884 return;
4885 }
4886#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004887
4888#ifdef CONFIG_WNM
4889 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4890 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4891 return;
4892 }
4893#endif /* CONFIG_WNM */
4894
4895#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004896 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4897 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004898 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004899 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004900 payload, plen, freq) == 0)
4901 return;
4902#endif /* CONFIG_GAS */
4903
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004904#ifdef CONFIG_GAS_SERVER
4905 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4906 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4907 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4908 mgmt->u.action.category,
4909 payload, plen, freq) == 0)
4910 return;
4911#endif /* CONFIG_GAS_SERVER */
4912
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004913#ifdef CONFIG_TDLS
4914 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4915 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4916 wpa_dbg(wpa_s, MSG_DEBUG,
4917 "TDLS: Received Discovery Response from " MACSTR,
4918 MAC2STR(mgmt->sa));
4919 return;
4920 }
4921#endif /* CONFIG_TDLS */
4922
4923#ifdef CONFIG_INTERWORKING
4924 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4925 payload[0] == QOS_QOS_MAP_CONFIG) {
4926 const u8 *pos = payload + 1;
4927 size_t qlen = plen - 1;
4928 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4929 MACSTR, MAC2STR(mgmt->sa));
4930 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4931 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4932 pos[1] <= qlen - 2 && pos[1] >= 16)
4933 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4934 return;
4935 }
4936#endif /* CONFIG_INTERWORKING */
4937
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004938 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004939 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4940 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004941 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004942 payload + 1,
4943 plen - 1);
4944 return;
4945 }
4946
4947 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004948 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4949 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4950 return;
4951 }
4952
4953 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4954 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4955 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4956 payload + 1, plen - 1,
4957 rssi);
4958 return;
4959 }
4960
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004961#ifdef CONFIG_FST
4962 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4963 fst_rx_action(wpa_s->fst, mgmt, len);
4964 return;
4965 }
4966#endif /* CONFIG_FST */
4967
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004968#ifdef CONFIG_DPP
4969 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4970 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4971 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4972 payload[4] == DPP_OUI_TYPE) {
4973 payload++;
4974 plen--;
4975 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4976 return;
4977 }
4978#endif /* CONFIG_DPP */
4979
Hai Shalom899fcc72020-10-19 14:38:18 -07004980 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004981 payload[0] == ROBUST_AV_SCS_RESP) {
4982 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4983 payload + 1, plen - 1);
4984 return;
4985 }
4986
4987 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004988 payload[0] == ROBUST_AV_MSCS_RESP) {
4989 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4990 payload + 1, plen - 1);
4991 return;
4992 }
4993
Hai Shalomc1a21442022-02-04 13:43:00 -08004994 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4995 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4996 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4997 payload + 4, plen - 4);
4998 return;
4999 }
5000
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005001 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5002 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005003 if (wpa_s->ifmsh)
5004 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005005}
5006
5007
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005008static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5009 union wpa_event_data *event)
5010{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005011 struct wpa_freq_range_list *list;
5012 char *str = NULL;
5013
5014 list = &event->freq_range;
5015
5016 if (list->num)
5017 str = freq_range_list_str(list);
5018 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5019 str ? str : "");
5020
5021#ifdef CONFIG_P2P
5022 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5023 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5024 __func__);
5025 } else {
5026 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005027
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005028 /*
5029 * The update channel flow will also take care of moving a GO
5030 * from the unsafe frequency if needed.
5031 */
5032 wpas_p2p_update_channel_list(wpa_s,
5033 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005034 }
5035#endif /* CONFIG_P2P */
5036
5037 os_free(str);
5038}
5039
5040
Roshan Pius3a1667e2018-07-03 15:17:14 -07005041static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005042{
Sunil Ravi167279a2023-05-31 01:12:34 +00005043 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005044 wpa_supplicant_cancel_auth_timeout(wpa_s);
5045 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005046 eapol_sm_notify_portValid(wpa_s->eapol, true);
5047 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005048 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005049 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005050}
5051
5052
5053static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5054 int freq)
5055{
5056 size_t i;
5057 int j;
5058
5059 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5060 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5061
5062 for (j = 0; j < mode->num_channels; j++) {
5063 const struct hostapd_channel_data *chan;
5064
5065 chan = &mode->channels[j];
5066 if (chan->freq == freq)
5067 return chan->dfs_cac_ms;
5068 }
5069 }
5070
5071 return 0;
5072}
5073
5074
5075static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5076 struct dfs_event *radar)
5077{
5078#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005079 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005080 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5081 } else
5082#endif /* NEED_AP_MLME && CONFIG_AP */
5083 {
5084 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5085
5086 cac_time /= 1000; /* convert from ms to sec */
5087 if (!cac_time)
5088 cac_time = 10 * 60; /* max timeout: 10 minutes */
5089
5090 /* Restart auth timeout: CAC time added to initial timeout */
5091 wpas_auth_timeout_restart(wpa_s, cac_time);
5092 }
5093}
5094
5095
5096static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5097 struct dfs_event *radar)
5098{
5099#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005100 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005101 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5102 } else
5103#endif /* NEED_AP_MLME && CONFIG_AP */
5104 {
5105 /* Restart auth timeout with original value after CAC is
5106 * finished */
5107 wpas_auth_timeout_restart(wpa_s, 0);
5108 }
5109}
5110
5111
5112static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5113 struct dfs_event *radar)
5114{
5115#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005116 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005117 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5118 } else
5119#endif /* NEED_AP_MLME && CONFIG_AP */
5120 {
5121 /* Restart auth timeout with original value after CAC is
5122 * aborted */
5123 wpas_auth_timeout_restart(wpa_s, 0);
5124 }
5125}
5126
5127
5128static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5129 union wpa_event_data *data)
5130{
5131 wpa_dbg(wpa_s, MSG_DEBUG,
5132 "Connection authorized by device, previous state %d",
5133 wpa_s->wpa_state);
5134
5135 wpa_supplicant_event_port_authorized(wpa_s);
5136
Hai Shalomc1a21442022-02-04 13:43:00 -08005137 wpa_s->last_eapol_matches_bssid = 1;
5138
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005139 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5140 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005141 data->assoc_info.ptk_kck_len,
5142 data->assoc_info.ptk_kek,
5143 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005144#ifdef CONFIG_FILS
5145 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5146 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5147 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5148
5149 /* Update ERP next sequence number */
5150 eapol_sm_update_erp_next_seq_num(
5151 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5152
5153 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5154 /* Add the new PMK and PMKID to the PMKSA cache */
5155 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5156 data->assoc_info.fils_pmk,
5157 data->assoc_info.fils_pmk_len,
5158 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005159 wpa_s->valid_links ?
5160 wpa_s->ap_mld_addr :
5161 wpa_s->bssid,
5162 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005163 } else if (data->assoc_info.fils_pmkid) {
5164 /* Update the current PMKSA used for this connection */
5165 pmksa_cache_set_current(wpa_s->wpa,
5166 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005167 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005168 }
5169 }
5170#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005171}
5172
5173
Hai Shalom60840252021-02-19 19:02:11 -08005174static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5175{
5176 switch (code) {
5177 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5178 return "";
5179 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5180 return "no_bss_found";
5181 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5182 return "auth_tx_fail";
5183 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5184 return "auth_no_ack_received";
5185 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5186 return "auth_no_resp_received";
5187 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5188 return "assoc_req_tx_fail";
5189 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5190 return "assoc_no_ack_received";
5191 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5192 return "assoc_no_resp_received";
5193 default:
5194 return "unknown_reason";
5195 }
5196}
5197
5198
Roshan Pius3a1667e2018-07-03 15:17:14 -07005199static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5200 union wpa_event_data *data)
5201{
5202 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005203#ifdef CONFIG_MBO
5204 struct wpa_bss *reject_bss;
5205#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005206
5207 if (!bssid || is_zero_ether_addr(bssid))
5208 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005209#ifdef CONFIG_MBO
5210 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5211 reject_bss = wpa_s->current_bss;
5212 else
5213 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5214#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005215
5216 if (data->assoc_reject.bssid)
5217 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005218 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005219 MAC2STR(data->assoc_reject.bssid),
5220 data->assoc_reject.status_code,
5221 data->assoc_reject.timed_out ? " timeout" : "",
5222 data->assoc_reject.timeout_reason ? "=" : "",
5223 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005224 data->assoc_reject.timeout_reason : "",
5225 data->assoc_reject.reason_code !=
5226 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5227 " qca_driver_reason=" : "",
5228 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005229 else
5230 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005231 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005232 data->assoc_reject.status_code,
5233 data->assoc_reject.timed_out ? " timeout" : "",
5234 data->assoc_reject.timeout_reason ? "=" : "",
5235 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005236 data->assoc_reject.timeout_reason : "",
5237 data->assoc_reject.reason_code !=
5238 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5239 " qca_driver_reason=" : "",
5240 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005241 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005242 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5243 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005244
5245#ifdef CONFIG_OWE
5246 if (data->assoc_reject.status_code ==
5247 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5248 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5249 wpa_s->current_ssid &&
5250 wpa_s->current_ssid->owe_group == 0 &&
5251 wpa_s->last_owe_group != 21) {
5252 struct wpa_ssid *ssid = wpa_s->current_ssid;
5253 struct wpa_bss *bss = wpa_s->current_bss;
5254
5255 if (!bss) {
5256 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5257 if (!bss) {
5258 wpas_connection_failed(wpa_s, bssid);
5259 wpa_supplicant_mark_disassoc(wpa_s);
5260 return;
5261 }
5262 }
5263 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5264 wpas_connect_work_done(wpa_s);
5265 wpa_supplicant_mark_disassoc(wpa_s);
5266 wpa_supplicant_connect(wpa_s, bss, ssid);
5267 return;
5268 }
5269#endif /* CONFIG_OWE */
5270
Hai Shalomfdcde762020-04-02 11:19:20 -07005271#ifdef CONFIG_DPP2
5272 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5273 * the status code defined in the DPP R2 tech spec.
5274 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5275 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005276 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005277 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5278 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5279 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005280 wpa_s->current_ssid->dpp_pfs == 0 &&
5281 (data->assoc_reject.status_code ==
5282 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5283 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5284 struct wpa_ssid *ssid = wpa_s->current_ssid;
5285 struct wpa_bss *bss = wpa_s->current_bss;
5286
5287 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5288 if (!bss)
5289 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5290 if (!bss || wpa_s->dpp_pfs_fallback) {
5291 wpa_printf(MSG_DEBUG,
5292 "DPP: Updated PFS policy for next try");
5293 wpas_connection_failed(wpa_s, bssid);
5294 wpa_supplicant_mark_disassoc(wpa_s);
5295 return;
5296 }
5297 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5298 wpa_s->dpp_pfs_fallback = 1;
5299 wpas_connect_work_done(wpa_s);
5300 wpa_supplicant_mark_disassoc(wpa_s);
5301 wpa_supplicant_connect(wpa_s, bss, ssid);
5302 return;
5303 }
5304#endif /* CONFIG_DPP2 */
5305
Hai Shalom74f70d42019-02-11 14:42:39 -08005306#ifdef CONFIG_MBO
5307 if (data->assoc_reject.status_code ==
5308 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005309 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005310 const u8 *rssi_rej;
5311
5312 rssi_rej = mbo_get_attr_from_ies(
5313 data->assoc_reject.resp_ies,
5314 data->assoc_reject.resp_ies_len,
5315 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5316 if (rssi_rej && rssi_rej[1] == 2) {
5317 wpa_printf(MSG_DEBUG,
5318 "OCE: RSSI-based association rejection from "
5319 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005320 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005321 rssi_rej[2], rssi_rej[3]);
5322 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005323 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005324 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005325 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005326 }
5327 }
5328#endif /* CONFIG_MBO */
5329
Roshan Pius3a1667e2018-07-03 15:17:14 -07005330 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5331 sme_event_assoc_reject(wpa_s, data);
5332 return;
5333 }
5334
5335 /* Driver-based SME cases */
5336
5337#ifdef CONFIG_SAE
5338 if (wpa_s->current_ssid &&
5339 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5340 !data->assoc_reject.timed_out) {
5341 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5342 wpa_sm_aborted_cached(wpa_s->wpa);
5343 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5344 }
5345#endif /* CONFIG_SAE */
5346
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005347#ifdef CONFIG_DPP
5348 if (wpa_s->current_ssid &&
5349 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5350 !data->assoc_reject.timed_out) {
5351 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5352 wpa_sm_aborted_cached(wpa_s->wpa);
5353 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5354 }
5355#endif /* CONFIG_DPP */
5356
Roshan Pius3a1667e2018-07-03 15:17:14 -07005357#ifdef CONFIG_FILS
5358 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005359 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005360 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005361 eapol_sm_update_erp_next_seq_num(
5362 wpa_s->eapol,
5363 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005364 fils_connection_failure(wpa_s);
5365 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005366#endif /* CONFIG_FILS */
5367
5368 wpas_connection_failed(wpa_s, bssid);
5369 wpa_supplicant_mark_disassoc(wpa_s);
5370}
5371
5372
Hai Shalomfdcde762020-04-02 11:19:20 -07005373static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5374 struct unprot_beacon *data)
5375{
5376 struct wpabuf *buf;
5377 int res;
5378
5379 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5380 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5381 return;
5382 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5383 MAC2STR(data->sa));
5384
5385 buf = wpabuf_alloc(4);
5386 if (!buf)
5387 return;
5388
5389 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5390 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5391 wpabuf_put_u8(buf, 1); /* Dialog Token */
5392 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5393
5394 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5395 wpa_s->own_addr, wpa_s->bssid,
5396 wpabuf_head(buf), wpabuf_len(buf), 0);
5397 if (res < 0)
5398 wpa_printf(MSG_DEBUG,
5399 "Failed to send WNM-Notification Request frame");
5400
5401 wpabuf_free(buf);
5402}
5403
5404
Sunil Ravi640215c2023-06-28 23:08:09 +00005405static const char * bitmap_to_str(u8 value, char *buf)
5406{
5407 char *pos = buf;
5408 int i, k = 0;
5409
5410 for (i = 7; i >= 0; i--)
5411 pos[k++] = (value & BIT(i)) ? '1' : '0';
5412
5413 pos[8] = '\0';
5414 return pos;
5415}
5416
5417
5418static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
5419 struct tid_link_map_info *info)
5420{
5421 char map_info[1000], *pos, *end;
5422 int res, i;
5423
5424 pos = map_info;
5425 end = pos + sizeof(map_info);
5426 res = os_snprintf(map_info, sizeof(map_info), "default=%d",
5427 info->default_map);
5428 if (os_snprintf_error(end - pos, res))
5429 return;
5430 pos += res;
5431
5432 if (!info->default_map) {
5433 for (i = 0; i < MAX_NUM_MLD_LINKS && end > pos; i++) {
5434 char uplink_map_str[9];
5435 char downlink_map_str[9];
5436
5437 if (!(info->valid_links & BIT(i)))
5438 continue;
5439
5440 bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
5441 bitmap_to_str(info->t2lmap[i].downlink,
5442 downlink_map_str);
5443
5444 res = os_snprintf(pos, end - pos,
5445 " link_id=%d up_link=%s down_link=%s",
5446 i, uplink_map_str,
5447 downlink_map_str);
5448 if (os_snprintf_error(end - pos, res))
5449 return;
5450 pos += res;
5451 }
5452 }
5453
5454 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
5455}
5456
5457
5458static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
5459{
5460 u8 bssid[ETH_ALEN];
5461
5462 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
5463 wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
5464 wpa_supplicant_deauthenticate(wpa_s,
5465 WLAN_REASON_DEAUTH_LEAVING);
5466 return;
5467 }
5468
5469 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
5470 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
5471 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
5472 wpas_notify_bssid_changed(wpa_s);
5473 }
5474
5475 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
5476 wpa_printf(MSG_ERROR,
5477 "LINK_RECONFIG: Failed to get MLO connection info");
5478 wpa_supplicant_deauthenticate(wpa_s,
5479 WLAN_REASON_DEAUTH_LEAVING);
5480 return;
5481 }
5482
5483 if (wpa_sm_set_ml_info(wpa_s)) {
5484 wpa_printf(MSG_ERROR,
5485 "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
5486 wpa_supplicant_deauthenticate(wpa_s,
5487 WLAN_REASON_DEAUTH_LEAVING);
5488 return;
5489 }
5490
5491 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
5492 wpa_s->valid_links);
5493}
5494
5495
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005496void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5497 union wpa_event_data *data)
5498{
5499 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005500 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005501 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005502#ifndef CONFIG_NO_STDOUT_DEBUG
5503 int level = MSG_DEBUG;
5504#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005505
5506 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5507 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005508 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005509 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005510 event != EVENT_SCHED_SCAN_STOPPED) {
5511 wpa_dbg(wpa_s, MSG_DEBUG,
5512 "Ignore event %s (%d) while interface is disabled",
5513 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005514 return;
5515 }
5516
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005517#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005518 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005519 const struct ieee80211_hdr *hdr;
5520 u16 fc;
5521 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5522 fc = le_to_host16(hdr->frame_control);
5523 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5524 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5525 level = MSG_EXCESSIVE;
5526 }
5527
5528 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5529 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005530#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005531
5532 switch (event) {
5533 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005534#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005535 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5536 data->auth.ies_len))
5537 wpa_printf(MSG_DEBUG,
5538 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005539#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005540 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005541 wpa_s->auth_status_code = data->auth.status_code;
5542 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005543 break;
5544 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005545#ifdef CONFIG_TESTING_OPTIONS
5546 if (wpa_s->ignore_auth_resp) {
5547 wpa_printf(MSG_INFO,
5548 "EVENT_ASSOC - ignore_auth_resp active!");
5549 break;
5550 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005551 if (wpa_s->testing_resend_assoc) {
5552 wpa_printf(MSG_INFO,
5553 "EVENT_DEAUTH - testing_resend_assoc");
5554 break;
5555 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005556#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305557 if (wpa_s->disconnected) {
5558 wpa_printf(MSG_INFO,
5559 "Ignore unexpected EVENT_ASSOC in disconnected state");
5560 break;
5561 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005562 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005563 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005564 if (data &&
5565 (data->assoc_info.authorized ||
5566 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5567 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005568 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005569 if (data) {
5570 wpa_msg(wpa_s, MSG_INFO,
5571 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5572 data->assoc_info.subnet_status);
5573 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005574 break;
5575 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005576 wpas_event_disassoc(wpa_s,
5577 data ? &data->disassoc_info : NULL);
5578 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005579 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005580#ifdef CONFIG_TESTING_OPTIONS
5581 if (wpa_s->ignore_auth_resp) {
5582 wpa_printf(MSG_INFO,
5583 "EVENT_DEAUTH - ignore_auth_resp active!");
5584 break;
5585 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005586 if (wpa_s->testing_resend_assoc) {
5587 wpa_printf(MSG_INFO,
5588 "EVENT_DEAUTH - testing_resend_assoc");
5589 break;
5590 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005591#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005592 wpas_event_deauth(wpa_s,
5593 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005594 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00005595 case EVENT_LINK_RECONFIG:
5596 wpas_link_reconfig(wpa_s);
5597 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005598 case EVENT_MICHAEL_MIC_FAILURE:
5599 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5600 break;
5601#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005602 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005603 if (wpa_s->own_scan_requested ||
5604 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005605 struct os_reltime diff;
5606
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005607 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005608 os_reltime_sub(&wpa_s->scan_start_time,
5609 &wpa_s->scan_trigger_time, &diff);
5610 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5611 diff.sec, diff.usec);
5612 wpa_s->own_scan_requested = 0;
5613 wpa_s->own_scan_running = 1;
5614 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5615 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005616 wpa_msg_ctrl(wpa_s, MSG_INFO,
5617 WPA_EVENT_SCAN_STARTED "id=%u",
5618 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005619 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005620 wpa_msg_ctrl(wpa_s, MSG_INFO,
5621 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005622 }
5623 } else {
5624 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005625 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005626 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005627 }
5628 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005629 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005630 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5631 wpa_s->scan_res_handler = NULL;
5632 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005633 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005634 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5635 break;
5636 }
5637
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005638 if (!(data && data->scan_info.external_scan) &&
5639 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005640 struct os_reltime now, diff;
5641 os_get_reltime(&now);
5642 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5643 wpa_s->scan_start_time.sec = 0;
5644 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00005645 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005646 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5647 diff.sec, diff.usec);
5648 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005649 if (wpa_supplicant_event_scan_results(wpa_s, data))
5650 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005651 if (!(data && data->scan_info.external_scan))
5652 wpa_s->own_scan_running = 0;
5653 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005654 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005655 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005656 break;
5657#endif /* CONFIG_NO_SCAN_PROCESSING */
5658 case EVENT_ASSOCINFO:
5659 wpa_supplicant_event_associnfo(wpa_s, data);
5660 break;
5661 case EVENT_INTERFACE_STATUS:
5662 wpa_supplicant_event_interface_status(wpa_s, data);
5663 break;
5664 case EVENT_PMKID_CANDIDATE:
5665 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5666 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005667#ifdef CONFIG_TDLS
5668 case EVENT_TDLS:
5669 wpa_supplicant_event_tdls(wpa_s, data);
5670 break;
5671#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005672#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005673 case EVENT_WNM:
5674 wpa_supplicant_event_wnm(wpa_s, data);
5675 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005676#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005677#ifdef CONFIG_IEEE80211R
5678 case EVENT_FT_RESPONSE:
5679 wpa_supplicant_event_ft_response(wpa_s, data);
5680 break;
5681#endif /* CONFIG_IEEE80211R */
5682#ifdef CONFIG_IBSS_RSN
5683 case EVENT_IBSS_RSN_START:
5684 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5685 break;
5686#endif /* CONFIG_IBSS_RSN */
5687 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005688 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005689 break;
5690 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005691 /* It is possible to get this event from earlier connection */
5692 if (wpa_s->current_ssid &&
5693 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5694 wpa_dbg(wpa_s, MSG_DEBUG,
5695 "Ignore AUTH_TIMED_OUT in mesh configuration");
5696 break;
5697 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005698 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5699 sme_event_auth_timed_out(wpa_s, data);
5700 break;
5701 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005702 /* It is possible to get this event from earlier connection */
5703 if (wpa_s->current_ssid &&
5704 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5705 wpa_dbg(wpa_s, MSG_DEBUG,
5706 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5707 break;
5708 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005709 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5710 sme_event_assoc_timed_out(wpa_s, data);
5711 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005712 case EVENT_TX_STATUS:
5713 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5714 " type=%d stype=%d",
5715 MAC2STR(data->tx_status.dst),
5716 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005717#ifdef CONFIG_PASN
5718 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5719 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5720 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5721 data->tx_status.data_len,
5722 data->tx_status.ack) == 0)
5723 break;
5724#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005725#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005726 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005727#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005728 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5729 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005730 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005731 wpa_s, data->tx_status.dst,
5732 data->tx_status.data,
5733 data->tx_status.data_len,
5734 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005735 OFFCHANNEL_SEND_ACTION_SUCCESS :
5736 OFFCHANNEL_SEND_ACTION_NO_ACK);
5737#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005738 break;
5739 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005740#endif /* CONFIG_AP */
5741#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005742 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005743 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005744 /*
5745 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005746 * interface in GO mode, or via standalone AP interface.
5747 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5748 * except when the primary interface is used as a GO interface
5749 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005750 */
5751 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5752 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005753 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005754 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005755 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005756 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005757 data->tx_status.data,
5758 data->tx_status.data_len,
5759 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005760 OFFCHANNEL_SEND_ACTION_SUCCESS :
5761 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005762 break;
5763 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005764#endif /* CONFIG_OFFCHANNEL */
5765#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005766 switch (data->tx_status.type) {
5767 case WLAN_FC_TYPE_MGMT:
5768 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5769 data->tx_status.data_len,
5770 data->tx_status.stype,
5771 data->tx_status.ack);
5772 break;
5773 case WLAN_FC_TYPE_DATA:
5774 ap_tx_status(wpa_s, data->tx_status.dst,
5775 data->tx_status.data,
5776 data->tx_status.data_len,
5777 data->tx_status.ack);
5778 break;
5779 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005780#endif /* CONFIG_AP */
5781 break;
5782#ifdef CONFIG_AP
5783 case EVENT_EAPOL_TX_STATUS:
5784 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5785 data->eapol_tx_status.data,
5786 data->eapol_tx_status.data_len,
5787 data->eapol_tx_status.ack);
5788 break;
5789 case EVENT_DRIVER_CLIENT_POLL_OK:
5790 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005791 break;
5792 case EVENT_RX_FROM_UNKNOWN:
5793 if (wpa_s->ap_iface == NULL)
5794 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005795 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5796 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005797 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005798#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005799
Sunil Ravi89eba102022-09-13 21:04:37 -07005800 case EVENT_LINK_CH_SWITCH_STARTED:
5801 case EVENT_LINK_CH_SWITCH:
5802 if (!data || !wpa_s->current_ssid ||
5803 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
5804 break;
5805
5806 wpa_msg(wpa_s, MSG_INFO,
5807 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5808 event == EVENT_LINK_CH_SWITCH ?
5809 WPA_EVENT_LINK_CHANNEL_SWITCH :
5810 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
5811 data->ch_switch.freq,
5812 data->ch_switch.link_id,
5813 data->ch_switch.ht_enabled,
5814 data->ch_switch.ch_offset,
5815 channel_width_to_string(data->ch_switch.ch_width),
5816 data->ch_switch.cf1,
5817 data->ch_switch.cf2);
5818 if (event == EVENT_LINK_CH_SWITCH_STARTED)
5819 break;
5820
5821 wpa_s->links[data->ch_switch.link_id].freq =
5822 data->ch_switch.freq;
5823 if (wpa_s->links[data->ch_switch.link_id].bss &&
5824 wpa_s->links[data->ch_switch.link_id].bss->freq !=
5825 data->ch_switch.freq) {
5826 wpa_s->links[data->ch_switch.link_id].bss->freq =
5827 data->ch_switch.freq;
5828 notify_bss_changes(
5829 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5830 wpa_s->links[data->ch_switch.link_id].bss);
5831 }
5832 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07005833 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005834 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005835 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005836 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005837
Hai Shalom81f62d82019-07-22 12:10:00 -07005838 wpa_msg(wpa_s, MSG_INFO,
5839 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5840 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5841 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005842 data->ch_switch.freq,
5843 data->ch_switch.ht_enabled,
5844 data->ch_switch.ch_offset,
5845 channel_width_to_string(data->ch_switch.ch_width),
5846 data->ch_switch.cf1,
5847 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005848 if (event == EVENT_CH_SWITCH_STARTED)
5849 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005850
Sunil Ravi65a724b2022-05-24 11:06:09 -07005851 if (wpa_s->assoc_freq && data->ch_switch.freq &&
5852 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
5853 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
5854 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005855 wpa_s->assoc_freq = data->ch_switch.freq;
5856 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005857 if (wpa_s->current_bss &&
5858 wpa_s->current_bss->freq != data->ch_switch.freq) {
5859 wpa_s->current_bss->freq = data->ch_switch.freq;
5860 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5861 wpa_s->current_bss);
5862 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005863
Hai Shalomfdcde762020-04-02 11:19:20 -07005864#ifdef CONFIG_SME
5865 switch (data->ch_switch.ch_offset) {
5866 case 1:
5867 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5868 break;
5869 case -1:
5870 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5871 break;
5872 default:
5873 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5874 break;
5875 }
5876#endif /* CONFIG_SME */
5877
Roshan Pius3a1667e2018-07-03 15:17:14 -07005878#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005879 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5880 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005881 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005882 wpa_s->current_ssid->mode ==
5883 WPAS_MODE_P2P_GROUP_FORMATION) {
5884 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5885 data->ch_switch.ht_enabled,
5886 data->ch_switch.ch_offset,
5887 data->ch_switch.ch_width,
5888 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005889 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07005890 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07005891 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005892 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005893#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005894
Hai Shalom899fcc72020-10-19 14:38:18 -07005895 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5896 sme_event_ch_switch(wpa_s);
5897
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005898 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005899 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005900 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005901#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005902#ifdef NEED_AP_MLME
5903 case EVENT_DFS_RADAR_DETECTED:
5904 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005905 wpas_ap_event_dfs_radar_detected(wpa_s,
5906 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005907 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005908 case EVENT_DFS_NOP_FINISHED:
5909 if (data)
5910 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5911 &data->dfs_event);
5912 break;
5913#endif /* NEED_AP_MLME */
5914#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005915 case EVENT_DFS_CAC_STARTED:
5916 if (data)
5917 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5918 break;
5919 case EVENT_DFS_CAC_FINISHED:
5920 if (data)
5921 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5922 break;
5923 case EVENT_DFS_CAC_ABORTED:
5924 if (data)
5925 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5926 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005927 case EVENT_RX_MGMT: {
5928 u16 fc, stype;
5929 const struct ieee80211_mgmt *mgmt;
5930
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005931#ifdef CONFIG_TESTING_OPTIONS
5932 if (wpa_s->ext_mgmt_frame_handling) {
5933 struct rx_mgmt *rx = &data->rx_mgmt;
5934 size_t hex_len = 2 * rx->frame_len + 1;
5935 char *hex = os_malloc(hex_len);
5936 if (hex) {
5937 wpa_snprintf_hex(hex, hex_len,
5938 rx->frame, rx->frame_len);
5939 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5940 rx->freq, rx->datarate, rx->ssi_signal,
5941 hex);
5942 os_free(hex);
5943 }
5944 break;
5945 }
5946#endif /* CONFIG_TESTING_OPTIONS */
5947
Dmitry Shmidt04949592012-07-19 12:16:46 -07005948 mgmt = (const struct ieee80211_mgmt *)
5949 data->rx_mgmt.frame;
5950 fc = le_to_host16(mgmt->frame_control);
5951 stype = WLAN_FC_GET_STYPE(fc);
5952
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005953#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005954 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005955#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005956#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005957 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005958 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005959 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005960 const u8 *ie;
5961 size_t ie_len;
5962
5963 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5964 ie_len = data->rx_mgmt.frame_len -
5965 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005966 wpas_p2p_probe_req_rx(
5967 wpa_s, src, mgmt->da,
5968 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005969 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005970 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005971 break;
5972 }
5973#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005974#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005975 if (wpa_s->current_ssid &&
5976 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5977 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005978 data->rx_mgmt.frame_len >= 30) {
5979 wpa_supplicant_event_ibss_auth(wpa_s, data);
5980 break;
5981 }
5982#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005983
5984 if (stype == WLAN_FC_STYPE_ACTION) {
5985 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005986 wpa_s, data->rx_mgmt.frame,
5987 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005988 data->rx_mgmt.freq,
5989 data->rx_mgmt.ssi_signal);
5990 break;
5991 }
5992
5993 if (wpa_s->ifmsh) {
5994 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005995 break;
5996 }
Hai Shalom60840252021-02-19 19:02:11 -08005997#ifdef CONFIG_PASN
5998 if (stype == WLAN_FC_STYPE_AUTH &&
5999 wpas_pasn_auth_rx(wpa_s, mgmt,
6000 data->rx_mgmt.frame_len) != -2)
6001 break;
6002#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006003
Roshan Pius3a1667e2018-07-03 15:17:14 -07006004#ifdef CONFIG_SAE
6005 if (stype == WLAN_FC_STYPE_AUTH &&
6006 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6007 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6008 sme_external_auth_mgmt_rx(
6009 wpa_s, data->rx_mgmt.frame,
6010 data->rx_mgmt.frame_len);
6011 break;
6012 }
6013#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006014 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6015 "management frame in non-AP mode");
6016 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006017#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006018 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006019
6020 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07006021 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6022 const u8 *ie;
6023 size_t ie_len;
6024
6025 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6026 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006027
6028 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6029 mgmt->bssid, ie, ie_len,
6030 data->rx_mgmt.ssi_signal);
6031 }
6032
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006033 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006034#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006035 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006036 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006037 case EVENT_RX_PROBE_REQ:
6038 if (data->rx_probe_req.sa == NULL ||
6039 data->rx_probe_req.ie == NULL)
6040 break;
6041#ifdef CONFIG_AP
6042 if (wpa_s->ap_iface) {
6043 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6044 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006045 data->rx_probe_req.da,
6046 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006047 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006048 data->rx_probe_req.ie_len,
6049 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006050 break;
6051 }
6052#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006053 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006054 data->rx_probe_req.da,
6055 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006056 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006057 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006058 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006059 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006060 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006061 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006062#ifdef CONFIG_OFFCHANNEL
6063 offchannel_remain_on_channel_cb(
6064 wpa_s, data->remain_on_channel.freq,
6065 data->remain_on_channel.duration);
6066#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006067 wpas_p2p_remain_on_channel_cb(
6068 wpa_s, data->remain_on_channel.freq,
6069 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07006070#ifdef CONFIG_DPP
6071 wpas_dpp_remain_on_channel_cb(
6072 wpa_s, data->remain_on_channel.freq,
6073 data->remain_on_channel.duration);
6074#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006075 break;
6076 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006077#ifdef CONFIG_OFFCHANNEL
6078 offchannel_cancel_remain_on_channel_cb(
6079 wpa_s, data->remain_on_channel.freq);
6080#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006081 wpas_p2p_cancel_remain_on_channel_cb(
6082 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006083#ifdef CONFIG_DPP
6084 wpas_dpp_cancel_remain_on_channel_cb(
6085 wpa_s, data->remain_on_channel.freq);
6086#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006087 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006088 case EVENT_EAPOL_RX:
6089 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6090 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00006091 data->eapol_rx.data_len,
6092 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006093 break;
6094 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006095 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00006096 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006097 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006098 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006099 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006100 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006101 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006102 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006103 bgscan_notify_signal_change(
6104 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006105 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006106 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00006107 data->signal_change.data.current_tx_rate);
6108 os_memcpy(&wpa_s->last_signal_info, data,
6109 sizeof(struct wpa_signal_info));
6110 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006111 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006112 case EVENT_INTERFACE_MAC_CHANGED:
6113 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006114 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006115 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006116 case EVENT_INTERFACE_ENABLED:
6117 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6118 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006119 u8 addr[ETH_ALEN];
6120
Hai Shalomfdcde762020-04-02 11:19:20 -07006121 eloop_cancel_timeout(wpas_clear_disabled_interface,
6122 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08006123 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006124 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006125 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
6126 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6127 else
6128 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07006129 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006130 if (wpa_s->p2p_mgmt) {
6131 wpa_supplicant_set_state(wpa_s,
6132 WPA_DISCONNECTED);
6133 break;
6134 }
6135
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006136#ifdef CONFIG_AP
6137 if (!wpa_s->ap_iface) {
6138 wpa_supplicant_set_state(wpa_s,
6139 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006140 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006141 wpa_supplicant_req_scan(wpa_s, 0, 0);
6142 } else
6143 wpa_supplicant_set_state(wpa_s,
6144 WPA_COMPLETED);
6145#else /* CONFIG_AP */
6146 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6147 wpa_supplicant_req_scan(wpa_s, 0, 0);
6148#endif /* CONFIG_AP */
6149 }
6150 break;
6151 case EVENT_INTERFACE_DISABLED:
6152 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006153#ifdef CONFIG_P2P
6154 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6155 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6156 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6157 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006158 * Mark interface disabled if this happens to end up not
6159 * being removed as a separate P2P group interface.
6160 */
6161 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6162 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006163 * The interface was externally disabled. Remove
6164 * it assuming an external entity will start a
6165 * new session if needed.
6166 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006167 if (wpa_s->current_ssid &&
6168 wpa_s->current_ssid->p2p_group)
6169 wpas_p2p_interface_unavailable(wpa_s);
6170 else
6171 wpas_p2p_disconnect(wpa_s);
6172 /*
6173 * wpa_s instance may have been freed, so must not use
6174 * it here anymore.
6175 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006176 break;
6177 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006178 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6179 p2p_in_progress(wpa_s->global->p2p) > 1) {
6180 /* This radio work will be cancelled, so clear P2P
6181 * state as well.
6182 */
6183 p2p_stop_find(wpa_s->global->p2p);
6184 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006185#endif /* CONFIG_P2P */
6186
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006187 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6188 /*
6189 * Indicate disconnection to keep ctrl_iface events
6190 * consistent.
6191 */
6192 wpa_supplicant_event_disassoc(
6193 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6194 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006195 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07006196 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08006197 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6198 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006199 clear_at.usec = 0;
6200 } else {
6201 struct os_reltime tmp;
6202
Hai Shalom60840252021-02-19 19:02:11 -08006203 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006204 tmp.usec = 0;
6205 os_reltime_sub(&tmp, &age, &clear_at);
6206 }
6207 eloop_register_timeout(clear_at.sec, clear_at.usec,
6208 wpas_clear_disabled_interface,
6209 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08006210 radio_remove_works(wpa_s, NULL, 0);
6211
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006212 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6213 break;
6214 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006215 wpa_supplicant_update_channel_list(
6216 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006217 break;
6218 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006219 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006220 break;
6221 case EVENT_BEST_CHANNEL:
6222 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6223 "(%d %d %d)",
6224 data->best_chan.freq_24, data->best_chan.freq_5,
6225 data->best_chan.freq_overall);
6226 wpa_s->best_24_freq = data->best_chan.freq_24;
6227 wpa_s->best_5_freq = data->best_chan.freq_5;
6228 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006229 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6230 data->best_chan.freq_5,
6231 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006232 break;
6233 case EVENT_UNPROT_DEAUTH:
6234 wpa_supplicant_event_unprot_deauth(wpa_s,
6235 &data->unprot_deauth);
6236 break;
6237 case EVENT_UNPROT_DISASSOC:
6238 wpa_supplicant_event_unprot_disassoc(wpa_s,
6239 &data->unprot_disassoc);
6240 break;
6241 case EVENT_STATION_LOW_ACK:
6242#ifdef CONFIG_AP
6243 if (wpa_s->ap_iface && data)
6244 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6245 data->low_ack.addr);
6246#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006247#ifdef CONFIG_TDLS
6248 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07006249 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
6250 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006251#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006252 break;
6253 case EVENT_IBSS_PEER_LOST:
6254#ifdef CONFIG_IBSS_RSN
6255 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6256#endif /* CONFIG_IBSS_RSN */
6257 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006258 case EVENT_DRIVER_GTK_REKEY:
6259 if (os_memcmp(data->driver_gtk_rekey.bssid,
6260 wpa_s->bssid, ETH_ALEN))
6261 break;
6262 if (!wpa_s->wpa)
6263 break;
6264 wpa_sm_update_replay_ctr(wpa_s->wpa,
6265 data->driver_gtk_rekey.replay_ctr);
6266 break;
6267 case EVENT_SCHED_SCAN_STOPPED:
6268 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006269 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006270 wpa_supplicant_notify_scanning(wpa_s, 0);
6271
6272 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6273 break;
6274
6275 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006276 * If the driver stopped scanning without being requested to,
6277 * request a new scan to continue scanning for networks.
6278 */
6279 if (!wpa_s->sched_scan_stop_req &&
6280 wpa_s->wpa_state == WPA_SCANNING) {
6281 wpa_dbg(wpa_s, MSG_DEBUG,
6282 "Restart scanning after unexpected sched_scan stop event");
6283 wpa_supplicant_req_scan(wpa_s, 1, 0);
6284 break;
6285 }
6286
6287 wpa_s->sched_scan_stop_req = 0;
6288
6289 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006290 * Start a new sched scan to continue searching for more SSIDs
6291 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006292 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006293 if (wpa_s->sched_scan_timed_out) {
6294 wpa_supplicant_req_sched_scan(wpa_s);
6295 } else if (wpa_s->pno_sched_pending) {
6296 wpa_s->pno_sched_pending = 0;
6297 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006298 } else if (resched) {
6299 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006300 }
6301
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006302 break;
6303 case EVENT_WPS_BUTTON_PUSHED:
6304#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006305 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006306#endif /* CONFIG_WPS */
6307 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006308 case EVENT_AVOID_FREQUENCIES:
6309 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6310 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006311 case EVENT_CONNECT_FAILED_REASON:
6312#ifdef CONFIG_AP
6313 if (!wpa_s->ap_iface || !data)
6314 break;
6315 hostapd_event_connect_failed_reason(
6316 wpa_s->ap_iface->bss[0],
6317 data->connect_failed_reason.addr,
6318 data->connect_failed_reason.code);
6319#endif /* CONFIG_AP */
6320 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006321 case EVENT_NEW_PEER_CANDIDATE:
6322#ifdef CONFIG_MESH
6323 if (!wpa_s->ifmsh || !data)
6324 break;
6325 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6326 data->mesh_peer.ies,
6327 data->mesh_peer.ie_len);
6328#endif /* CONFIG_MESH */
6329 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006330 case EVENT_SURVEY:
6331#ifdef CONFIG_AP
6332 if (!wpa_s->ap_iface)
6333 break;
6334 hostapd_event_get_survey(wpa_s->ap_iface,
6335 &data->survey_results);
6336#endif /* CONFIG_AP */
6337 break;
6338 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006339#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006340#ifdef CONFIG_ACS
6341 if (!wpa_s->ap_iface)
6342 break;
6343 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6344 &data->acs_selected_channels);
6345#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006346#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006347 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006348 case EVENT_P2P_LO_STOP:
6349#ifdef CONFIG_P2P
6350 wpa_s->p2p_lo_started = 0;
6351 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6352 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6353 data->p2p_lo_stop.reason_code);
6354#endif /* CONFIG_P2P */
6355 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006356 case EVENT_BEACON_LOSS:
6357 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6358 break;
6359 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6360 bgscan_notify_beacon_loss(wpa_s);
6361 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006362 case EVENT_EXTERNAL_AUTH:
6363#ifdef CONFIG_SAE
6364 if (!wpa_s->current_ssid) {
6365 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6366 break;
6367 }
6368 sme_external_auth_trigger(wpa_s, data);
6369#endif /* CONFIG_SAE */
6370 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006371#ifdef CONFIG_PASN
6372 case EVENT_PASN_AUTH:
6373 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6374 break;
6375#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006376 case EVENT_PORT_AUTHORIZED:
Sunil Ravi77d572f2023-01-17 23:58:31 +00006377#ifndef CONFIG_NO_WPA
6378 if (data->port_authorized.td_bitmap_len) {
6379 wpa_printf(MSG_DEBUG,
6380 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
6381 data->port_authorized.td_bitmap[0]);
6382 wpas_transition_disable(
6383 wpa_s, data->port_authorized.td_bitmap[0]);
6384 }
6385#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006386 wpa_supplicant_event_port_authorized(wpa_s);
6387 break;
6388 case EVENT_STATION_OPMODE_CHANGED:
6389#ifdef CONFIG_AP
6390 if (!wpa_s->ap_iface || !data)
6391 break;
6392
6393 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6394 data->sta_opmode.addr,
6395 data->sta_opmode.smps_mode,
6396 data->sta_opmode.chan_width,
6397 data->sta_opmode.rx_nss);
6398#endif /* CONFIG_AP */
6399 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07006400 case EVENT_UNPROT_BEACON:
6401 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6402 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08006403 case EVENT_TX_WAIT_EXPIRE:
6404#ifdef CONFIG_DPP
6405 wpas_dpp_tx_wait_expire(wpa_s);
6406#endif /* CONFIG_DPP */
6407 break;
Sunil Ravi640215c2023-06-28 23:08:09 +00006408 case EVENT_TID_LINK_MAP:
6409 if (data)
6410 wpas_tid_link_map(wpa_s, &data->t2l_map_info);
6411 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006412 default:
6413 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6414 break;
6415 }
6416}
Dmitry Shmidte4663042016-04-04 10:07:49 -07006417
6418
6419void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6420 union wpa_event_data *data)
6421{
6422 struct wpa_supplicant *wpa_s;
6423
6424 if (event != EVENT_INTERFACE_STATUS)
6425 return;
6426
6427 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6428 if (wpa_s && wpa_s->driver->get_ifindex) {
6429 unsigned int ifindex;
6430
6431 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6432 if (ifindex != data->interface_status.ifindex) {
6433 wpa_dbg(wpa_s, MSG_DEBUG,
6434 "interface status ifindex %d mismatch (%d)",
6435 ifindex, data->interface_status.ifindex);
6436 return;
6437 }
6438 }
6439#ifdef CONFIG_MATCH_IFACE
6440 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6441 struct wpa_interface *wpa_i;
6442
6443 wpa_i = wpa_supplicant_match_iface(
6444 ctx, data->interface_status.ifname);
6445 if (!wpa_i)
6446 return;
6447 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6448 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006449 }
6450#endif /* CONFIG_MATCH_IFACE */
6451
6452 if (wpa_s)
6453 wpa_supplicant_event(wpa_s, event, data);
6454}