blob: 0909961342281011efe2f3017557ca990ccba0ef [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 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080063
64
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070065int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080067 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070068
69 if (ssid == NULL || ssid->disabled_until.sec == 0)
70 return 0;
71
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080072 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070073 if (ssid->disabled_until.sec > now.sec)
74 return ssid->disabled_until.sec - now.sec;
75
76 wpas_clear_temp_disabled(wpa_s, ssid, 0);
77
78 return 0;
79}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080
81
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080082#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070083/**
84 * wpas_reenabled_network_time - Time until first network is re-enabled
85 * @wpa_s: Pointer to wpa_supplicant data
86 * Returns: If all enabled networks are temporarily disabled, returns the time
87 * (in sec) until the first network is re-enabled. Otherwise returns 0.
88 *
89 * This function is used in case all enabled networks are temporarily disabled,
90 * in which case it returns the time (in sec) that the first network will be
91 * re-enabled. The function assumes that at least one network is enabled.
92 */
93static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
94{
95 struct wpa_ssid *ssid;
96 int disabled_for, res = 0;
97
98#ifdef CONFIG_INTERWORKING
99 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
100 wpa_s->conf->cred)
101 return 0;
102#endif /* CONFIG_INTERWORKING */
103
104 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
105 if (ssid->disabled)
106 continue;
107
108 disabled_for = wpas_temp_disabled(wpa_s, ssid);
109 if (!disabled_for)
110 return 0;
111
112 if (!res || disabled_for < res)
113 res = disabled_for;
114 }
115
116 return res;
117}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800118#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700119
120
121void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
122{
123 struct wpa_supplicant *wpa_s = eloop_ctx;
124
125 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
126 return;
127
128 wpa_dbg(wpa_s, MSG_DEBUG,
129 "Try to associate due to network getting re-enabled");
130 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
131 wpa_supplicant_cancel_sched_scan(wpa_s);
132 wpa_supplicant_req_scan(wpa_s, 0, 0);
133 }
134}
135
136
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800137static struct wpa_bss * wpa_supplicant_get_new_bss(
138 struct wpa_supplicant *wpa_s, const u8 *bssid)
139{
140 struct wpa_bss *bss = NULL;
141 struct wpa_ssid *ssid = wpa_s->current_ssid;
142
Sunil Ravi77d572f2023-01-17 23:58:31 +0000143 if (ssid && ssid->ssid_len > 0)
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800144 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
145 if (!bss)
146 bss = wpa_bss_get_bssid(wpa_s, bssid);
147
148 return bss;
149}
150
151
Sunil Ravia04bd252022-05-02 22:54:18 -0700152static struct wpa_bss *
153wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700154{
Sunil Ravia04bd252022-05-02 22:54:18 -0700155 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700156
157 if (!bss) {
158 wpa_supplicant_update_scan_results(wpa_s);
159
160 /* Get the BSS from the new scan results */
Sunil Ravia04bd252022-05-02 22:54:18 -0700161 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700162 }
163
164 if (bss)
165 wpa_s->current_bss = bss;
Sunil Ravia04bd252022-05-02 22:54:18 -0700166
167 return bss;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700168}
169
170
Sunil Ravi89eba102022-09-13 21:04:37 -0700171static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
172 u8 link_id, const u8 *bssid)
173{
174 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
175
176 if (!bss) {
177 wpa_supplicant_update_scan_results(wpa_s);
178 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
179 }
180
181 if (bss)
182 wpa_s->links[link_id].bss = bss;
183}
184
185
Sunil Ravi77d572f2023-01-17 23:58:31 +0000186static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
187 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700188{
189 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700190 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700191 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700192 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700193
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700194 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700195 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700196
197 if (wpa_s->current_ssid->ssid_len == 0)
198 return 0; /* current profile still in use */
199 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
200 if (res < 0) {
201 wpa_msg(wpa_s, MSG_INFO,
202 "Failed to read SSID from driver");
203 return 0; /* try to use current profile */
204 }
205 drv_ssid_len = res;
206
207 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
208 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
209 drv_ssid_len) == 0)
210 return 0; /* current profile still in use */
211
Hai Shalomfdcde762020-04-02 11:19:20 -0700212#ifdef CONFIG_OWE
213 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
214 wpa_s->current_bss &&
215 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
216 drv_ssid_len == wpa_s->current_bss->ssid_len &&
217 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
218 drv_ssid_len) == 0)
219 return 0; /* current profile still in use */
220#endif /* CONFIG_OWE */
221
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700222 wpa_msg(wpa_s, MSG_DEBUG,
223 "Driver-initiated BSS selection changed the SSID to %s",
224 wpa_ssid_txt(drv_ssid, drv_ssid_len));
225 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700226 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227
228 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
229 "information");
230 ssid = wpa_supplicant_get_ssid(wpa_s);
231 if (ssid == NULL) {
232 wpa_msg(wpa_s, MSG_INFO,
233 "No network configuration found for the current AP");
234 return -1;
235 }
236
Dmitry Shmidt04949592012-07-19 12:16:46 -0700237 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
239 return -1;
240 }
241
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800242 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
243 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
244 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
245 return -1;
246 }
247
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700248 res = wpas_temp_disabled(wpa_s, ssid);
249 if (res > 0) {
250 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
251 "disabled for %d second(s)", res);
252 return -1;
253 }
254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700255 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
256 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800257 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258 u8 wpa_ie[80];
259 size_t wpa_ie_len = sizeof(wpa_ie);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000260 bool skip_default_rsne;
261
262 /* Do not override RSNE/RSNXE with the default values if the
263 * driver indicated the actual values used in the
264 * (Re)Association Request frame. */
265 skip_default_rsne = data && data->assoc_info.req_ies;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800266 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000267 wpa_ie, &wpa_ie_len,
268 skip_default_rsne) < 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800269 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700270 } else {
271 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
272 }
273
274 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
275 eapol_sm_invalidate_cached_session(wpa_s->eapol);
276 old_ssid = wpa_s->current_ssid;
277 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800278
Sunil Ravia04bd252022-05-02 22:54:18 -0700279 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800280
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
282 wpa_supplicant_initiate_eapol(wpa_s);
283 if (old_ssid != wpa_s->current_ssid)
284 wpas_notify_network_changed(wpa_s);
285
286 return 0;
287}
288
289
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800290void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291{
292 struct wpa_supplicant *wpa_s = eloop_ctx;
293
294 if (wpa_s->countermeasures) {
295 wpa_s->countermeasures = 0;
296 wpa_drv_set_countermeasures(wpa_s, 0);
297 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800298
299 /*
300 * It is possible that the device is sched scanning, which means
301 * that a connection attempt will be done only when we receive
302 * scan results. However, in this case, it would be preferable
303 * to scan and connect immediately, so cancel the sched_scan and
304 * issue a regular scan flow.
305 */
306 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307 wpa_supplicant_req_scan(wpa_s, 0, 0);
308 }
309}
310
311
Sunil Ravi77d572f2023-01-17 23:58:31 +0000312void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
Sunil Ravi89eba102022-09-13 21:04:37 -0700313{
Sunil Ravi89eba102022-09-13 21:04:37 -0700314 if (!wpa_s->valid_links)
315 return;
316
317 wpa_s->valid_links = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000318 wpa_s->mlo_assoc_link_id = 0;
319 os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN);
320 os_memset(wpa_s->links, 0, sizeof(wpa_s->links));
Sunil Ravi89eba102022-09-13 21:04:37 -0700321}
322
323
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
325{
326 int bssid_changed;
327
Dmitry Shmidt04949592012-07-19 12:16:46 -0700328 wnm_bss_keep_alive_deinit(wpa_s);
329
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330#ifdef CONFIG_IBSS_RSN
331 ibss_rsn_deinit(wpa_s->ibss_rsn);
332 wpa_s->ibss_rsn = NULL;
333#endif /* CONFIG_IBSS_RSN */
334
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700335#ifdef CONFIG_AP
336 wpa_supplicant_ap_deinit(wpa_s);
337#endif /* CONFIG_AP */
338
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700339#ifdef CONFIG_HS20
340 /* Clear possibly configured frame filters */
341 wpa_drv_configure_frame_filters(wpa_s, 0);
342#endif /* CONFIG_HS20 */
343
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
345 return;
346
Hai Shalom74f70d42019-02-11 14:42:39 -0800347 if (os_reltime_initialized(&wpa_s->session_start)) {
348 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
349 wpa_s->session_start.sec = 0;
350 wpa_s->session_start.usec = 0;
351 wpas_notify_session_length(wpa_s);
352 }
353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
355 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
356 os_memset(wpa_s->bssid, 0, ETH_ALEN);
357 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800358 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359 wpa_s->current_bss = NULL;
360 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700361
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700362 if (bssid_changed)
363 wpas_notify_bssid_changed(wpa_s);
364
Hai Shalome21d4e82020-04-29 16:34:06 -0700365 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
366 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700367 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
368 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700369 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700370 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700371 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700372 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700373 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700374 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700375 wpa_s->key_mgmt = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700376 wpa_s->allowed_key_mgmts = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800377
378 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800379 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800380 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700381 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700382
383#ifdef CONFIG_TESTING_OPTIONS
384 wpa_s->last_tk_alg = WPA_ALG_NONE;
385 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
386#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700387 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800388
389 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
390 wpa_s->enabled_4addr_mode = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700391
Sunil Ravi77d572f2023-01-17 23:58:31 +0000392 wpa_s->wps_scan_done = false;
Sunil Ravi89eba102022-09-13 21:04:37 -0700393 wpas_reset_mlo_info(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394}
395
396
Sunil Ravi036cec52023-03-29 11:35:17 -0700397static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398{
399 struct wpa_ie_data ie;
400 int pmksa_set = -1;
401 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800402 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403
Hai Shalomc1a21442022-02-04 13:43:00 -0800404 /* Start with assumption of no PMKSA cache entry match for cases other
405 * than SAE. In particular, this is needed to generate the PMKSA cache
406 * entries for Suite B cases with driver-based roaming indication. */
407 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
408 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
409 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700410
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
412 ie.pmkid == NULL)
413 return;
414
415 for (i = 0; i < ie.num_pmkid; i++) {
416 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
417 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700418 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700419 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800420 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Sunil Ravi036cec52023-03-29 11:35:17 -0700421 if (authorized)
422 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700423 break;
424 }
425 }
426
427 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
428 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
429}
430
431
432static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
433 union wpa_event_data *data)
434{
435 if (data == NULL) {
436 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
437 "event");
438 return;
439 }
440 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
441 " index=%d preauth=%d",
442 MAC2STR(data->pmkid_candidate.bssid),
443 data->pmkid_candidate.index,
444 data->pmkid_candidate.preauth);
445
446 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
447 data->pmkid_candidate.index,
448 data->pmkid_candidate.preauth);
449}
450
451
452static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
453{
454 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
455 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
456 return 0;
457
458#ifdef IEEE8021X_EAPOL
459 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
460 wpa_s->current_ssid &&
461 !(wpa_s->current_ssid->eapol_flags &
462 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
463 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
464 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
465 * plaintext or static WEP keys). */
466 return 0;
467 }
468#endif /* IEEE8021X_EAPOL */
469
470 return 1;
471}
472
473
474/**
475 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
476 * @wpa_s: pointer to wpa_supplicant data
477 * @ssid: Configuration data for the network
478 * Returns: 0 on success, -1 on failure
479 *
480 * This function is called when starting authentication with a network that is
481 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
482 */
483int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
484 struct wpa_ssid *ssid)
485{
486#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800487#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700488 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700489
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700490 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
491 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700492 return 0;
493
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700494 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700495 sim = 1;
496 aka = 1;
497 } else {
498 struct eap_method_type *eap = ssid->eap.eap_methods;
499 while (eap->vendor != EAP_VENDOR_IETF ||
500 eap->method != EAP_TYPE_NONE) {
501 if (eap->vendor == EAP_VENDOR_IETF) {
502 if (eap->method == EAP_TYPE_SIM)
503 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700504 else if (eap->method == EAP_TYPE_AKA ||
505 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700506 aka = 1;
507 }
508 eap++;
509 }
510 }
511
512 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
513 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700514 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
515 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
516 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700517 aka = 0;
518
519 if (!sim && !aka) {
520 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
521 "use SIM, but neither EAP-SIM nor EAP-AKA are "
522 "enabled");
523 return 0;
524 }
525
526 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
527 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700529 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700530 if (wpa_s->scard == NULL) {
531 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
532 "(pcsc-lite)");
533 return -1;
534 }
535 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
536 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800537#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538#endif /* IEEE8021X_EAPOL */
539
540 return 0;
541}
542
543
544#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700545
Hai Shalomfdcde762020-04-02 11:19:20 -0700546#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700547static int has_wep_key(struct wpa_ssid *ssid)
548{
549 int i;
550
551 for (i = 0; i < NUM_WEP_KEYS; i++) {
552 if (ssid->wep_key_len[i])
553 return 1;
554 }
555
556 return 0;
557}
Hai Shalomfdcde762020-04-02 11:19:20 -0700558#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700559
560
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700561static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562 struct wpa_ssid *ssid)
563{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700564 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700565
566 if (ssid->mixed_cell)
567 return 1;
568
569#ifdef CONFIG_WPS
570 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
571 return 1;
572#endif /* CONFIG_WPS */
573
Roshan Pius3a1667e2018-07-03 15:17:14 -0700574#ifdef CONFIG_OWE
575 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
576 return 1;
577#endif /* CONFIG_OWE */
578
Hai Shalomfdcde762020-04-02 11:19:20 -0700579#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700580 if (has_wep_key(ssid))
581 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700582#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700583
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584#ifdef IEEE8021X_EAPOL
585 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
586 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
587 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
588 privacy = 1;
589#endif /* IEEE8021X_EAPOL */
590
Jouni Malinen75ecf522011-06-27 15:19:46 -0700591 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
592 privacy = 1;
593
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800594 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
595 privacy = 1;
596
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597 if (bss->caps & IEEE80211_CAP_PRIVACY)
598 return privacy;
599 return !privacy;
600}
601
602
603static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
604 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800605 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700606{
607 struct wpa_ie_data ie;
608 int proto_match = 0;
609 const u8 *rsn_ie, *wpa_ie;
610 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700611#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700612 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700613#endif /* CONFIG_WEP */
Sunil Ravi77d572f2023-01-17 23:58:31 +0000614 bool is_6ghz_bss_or_mld = is_6ghz_freq(bss->freq) ||
615 !is_zero_ether_addr(bss->mld_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616
617 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
618 if (ret >= 0)
619 return ret;
620
Hai Shalomfdcde762020-04-02 11:19:20 -0700621#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700622 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
623 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
624 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
625 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
626 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700627#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700628
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700629 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000630 if (is_6ghz_bss_or_mld && !rsn_ie) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700631 if (debug_print)
632 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000633 " skip - 6 GHz/MLD BSS without RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700634 return 0;
635 }
636
Roshan Pius3a1667e2018-07-03 15:17:14 -0700637 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638 proto_match++;
639
640 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800641 if (debug_print)
642 wpa_dbg(wpa_s, MSG_DEBUG,
643 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 break;
645 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700646 if (!ie.has_pairwise)
647 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
648 if (!ie.has_group)
649 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700650
Sunil Ravi77d572f2023-01-17 23:58:31 +0000651 if (is_6ghz_bss_or_mld) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700652 /* WEP and TKIP are not allowed on 6 GHz */
653 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
654 WPA_CIPHER_WEP104 |
655 WPA_CIPHER_TKIP);
656 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
657 WPA_CIPHER_WEP104 |
658 WPA_CIPHER_TKIP);
659 }
660
Hai Shalomfdcde762020-04-02 11:19:20 -0700661#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 if (wep_ok &&
663 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
664 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800665 if (debug_print)
666 wpa_dbg(wpa_s, MSG_DEBUG,
667 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 return 1;
669 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700670#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671
Roshan Pius3a1667e2018-07-03 15:17:14 -0700672 if (!(ie.proto & ssid->proto) &&
673 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800674 if (debug_print)
675 wpa_dbg(wpa_s, MSG_DEBUG,
676 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677 break;
678 }
679
680 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800681 if (debug_print)
682 wpa_dbg(wpa_s, MSG_DEBUG,
683 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 break;
685 }
686
687 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800688 if (debug_print)
689 wpa_dbg(wpa_s, MSG_DEBUG,
690 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691 break;
692 }
693
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700694 if (ssid->group_mgmt_cipher &&
695 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
696 if (debug_print)
697 wpa_dbg(wpa_s, MSG_DEBUG,
698 " skip RSN IE - group mgmt cipher mismatch");
699 break;
700 }
701
Sunil Ravi77d572f2023-01-17 23:58:31 +0000702 if (is_6ghz_bss_or_mld) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700703 /* MFPC must be supported on 6 GHz */
704 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
705 if (debug_print)
706 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000707 " skip RSNE - 6 GHz/MLD without MFPC");
Sunil Ravia04bd252022-05-02 22:54:18 -0700708 break;
709 }
710
711 /* WPA PSK is not allowed on the 6 GHz band */
712 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
713 WPA_KEY_MGMT_FT_PSK |
714 WPA_KEY_MGMT_PSK_SHA256);
715 }
716
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800718 if (debug_print)
719 wpa_dbg(wpa_s, MSG_DEBUG,
720 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 break;
722 }
723
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800725 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800726 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800727 if (debug_print)
728 wpa_dbg(wpa_s, MSG_DEBUG,
729 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 break;
731 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800732 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
733 wpas_get_ssid_pmf(wpa_s, ssid) ==
734 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800735 if (debug_print)
736 wpa_dbg(wpa_s, MSG_DEBUG,
737 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800738 break;
739 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800741 if (debug_print)
742 wpa_dbg(wpa_s, MSG_DEBUG,
743 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744 return 1;
745 }
746
Sunil Ravi77d572f2023-01-17 23:58:31 +0000747 if (is_6ghz_bss_or_mld) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700748 if (debug_print)
749 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000750 " skip - 6 GHz/MLD BSS without matching RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700751 return 0;
752 }
753
Roshan Pius3a1667e2018-07-03 15:17:14 -0700754 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
755 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800756 if (debug_print)
757 wpa_dbg(wpa_s, MSG_DEBUG,
758 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700759 return 0;
760 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700761
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700762 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
764 proto_match++;
765
766 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800767 if (debug_print)
768 wpa_dbg(wpa_s, MSG_DEBUG,
769 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 break;
771 }
772
Hai Shalomfdcde762020-04-02 11:19:20 -0700773#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774 if (wep_ok &&
775 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
776 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800777 if (debug_print)
778 wpa_dbg(wpa_s, MSG_DEBUG,
779 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780 return 1;
781 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700782#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700783
784 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800785 if (debug_print)
786 wpa_dbg(wpa_s, MSG_DEBUG,
787 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788 break;
789 }
790
791 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800792 if (debug_print)
793 wpa_dbg(wpa_s, MSG_DEBUG,
794 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700795 break;
796 }
797
798 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800799 if (debug_print)
800 wpa_dbg(wpa_s, MSG_DEBUG,
801 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802 break;
803 }
804
805 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800806 if (debug_print)
807 wpa_dbg(wpa_s, MSG_DEBUG,
808 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 break;
810 }
811
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800812 if (debug_print)
813 wpa_dbg(wpa_s, MSG_DEBUG,
814 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815 return 1;
816 }
817
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700818 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
819 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800820 if (debug_print)
821 wpa_dbg(wpa_s, MSG_DEBUG,
822 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700823 return 1;
824 }
825
Roshan Pius3a1667e2018-07-03 15:17:14 -0700826#ifdef CONFIG_OWE
827 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
828 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800829 if (wpa_s->owe_transition_select &&
830 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
831 ssid->owe_transition_bss_select_count + 1 <=
832 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
833 ssid->owe_transition_bss_select_count++;
834 if (debug_print)
835 wpa_dbg(wpa_s, MSG_DEBUG,
836 " skip OWE transition BSS (selection count %d does not exceed %d)",
837 ssid->owe_transition_bss_select_count,
838 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
839 wpa_s->owe_transition_search = 1;
840 return 0;
841 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700842 if (debug_print)
843 wpa_dbg(wpa_s, MSG_DEBUG,
844 " allow in OWE transition mode");
845 return 1;
846 }
847#endif /* CONFIG_OWE */
848
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
850 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800851 if (debug_print)
852 wpa_dbg(wpa_s, MSG_DEBUG,
853 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700854 return 0;
855 }
856
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800857 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
858 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800859 if (debug_print)
860 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800861 return 1;
862 }
863
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700864 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800865 if (debug_print)
866 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700867 return 1;
868 }
869
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800870 if (debug_print)
871 wpa_dbg(wpa_s, MSG_DEBUG,
872 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700873
874 return 0;
875}
876
877
878static int freq_allowed(int *freqs, int freq)
879{
880 int i;
881
882 if (freqs == NULL)
883 return 1;
884
885 for (i = 0; freqs[i]; i++)
886 if (freqs[i] == freq)
887 return 1;
888 return 0;
889}
890
891
Hai Shalomfdcde762020-04-02 11:19:20 -0700892static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
893 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800894{
895 const struct hostapd_hw_modes *mode = NULL, *modes;
896 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
897 const u8 *rate_ie;
898 int i, j, k;
899
900 if (bss->freq == 0)
901 return 1; /* Cannot do matching without knowing band */
902
903 modes = wpa_s->hw.modes;
904 if (modes == NULL) {
905 /*
906 * The driver does not provide any additional information
907 * about the utilized hardware, so allow the connection attempt
908 * to continue.
909 */
910 return 1;
911 }
912
913 for (i = 0; i < wpa_s->hw.num_modes; i++) {
914 for (j = 0; j < modes[i].num_channels; j++) {
915 int freq = modes[i].channels[j].freq;
916 if (freq == bss->freq) {
917 if (mode &&
918 mode->mode == HOSTAPD_MODE_IEEE80211G)
919 break; /* do not allow 802.11b replace
920 * 802.11g */
921 mode = &modes[i];
922 break;
923 }
924 }
925 }
926
927 if (mode == NULL)
928 return 0;
929
930 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700931 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800932 if (rate_ie == NULL)
933 continue;
934
935 for (j = 2; j < rate_ie[1] + 2; j++) {
936 int flagged = !!(rate_ie[j] & 0x80);
937 int r = (rate_ie[j] & 0x7f) * 5;
938
939 /*
940 * IEEE Std 802.11n-2009 7.3.2.2:
941 * The new BSS Membership selector value is encoded
942 * like a legacy basic rate, but it is not a rate and
943 * only indicates if the BSS members are required to
944 * support the mandatory features of Clause 20 [HT PHY]
945 * in order to join the BSS.
946 */
947 if (flagged && ((rate_ie[j] & 0x7f) ==
948 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
949 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800950 if (debug_print)
951 wpa_dbg(wpa_s, MSG_DEBUG,
952 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800953 return 0;
954 }
955 continue;
956 }
957
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700958 /* There's also a VHT selector for 802.11ac */
959 if (flagged && ((rate_ie[j] & 0x7f) ==
960 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
961 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800962 if (debug_print)
963 wpa_dbg(wpa_s, MSG_DEBUG,
964 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700965 return 0;
966 }
967 continue;
968 }
969
Sunil Ravi77d572f2023-01-17 23:58:31 +0000970 if (flagged && ((rate_ie[j] & 0x7f) ==
971 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
972 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
973 if (debug_print)
974 wpa_dbg(wpa_s, MSG_DEBUG,
975 " hardware does not support HE PHY");
976 return 0;
977 }
978 continue;
979 }
980
Hai Shalomc3565922019-10-28 11:58:20 -0700981#ifdef CONFIG_SAE
982 if (flagged && ((rate_ie[j] & 0x7f) ==
983 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Sunil Ravi77d572f2023-01-17 23:58:31 +0000984 if (wpa_s->conf->sae_pwe ==
985 SAE_PWE_HUNT_AND_PECK &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700986 !ssid->sae_password_id &&
Sunil Ravi036cec52023-03-29 11:35:17 -0700987 !is_6ghz_freq(bss->freq) &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700988 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700989 if (debug_print)
990 wpa_dbg(wpa_s, MSG_DEBUG,
991 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800992#ifdef CONFIG_TESTING_OPTIONS
993 if (wpa_s->ignore_sae_h2e_only) {
994 wpa_dbg(wpa_s, MSG_DEBUG,
995 "TESTING: Ignore SAE H2E requirement mismatch");
996 continue;
997 }
998#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700999 return 0;
1000 }
1001 continue;
1002 }
1003#endif /* CONFIG_SAE */
1004
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001005 if (!flagged)
1006 continue;
1007
1008 /* check for legacy basic rates */
1009 for (k = 0; k < mode->num_rates; k++) {
1010 if (mode->rates[k] == r)
1011 break;
1012 }
1013 if (k == mode->num_rates) {
1014 /*
1015 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1016 * order to join a BSS all required rates
1017 * have to be supported by the hardware.
1018 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001019 if (debug_print)
1020 wpa_dbg(wpa_s, MSG_DEBUG,
1021 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1022 r / 10, r % 10,
1023 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001024 return 0;
1025 }
1026 }
1027 }
1028
1029 return 1;
1030}
1031
1032
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001033/*
1034 * Test whether BSS is in an ESS.
1035 * This is done differently in DMG (60 GHz) and non-DMG bands
1036 */
1037static int bss_is_ess(struct wpa_bss *bss)
1038{
1039 if (bss_is_dmg(bss)) {
1040 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1041 IEEE80211_CAP_DMG_AP;
1042 }
1043
1044 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1045 IEEE80211_CAP_ESS);
1046}
1047
1048
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001049static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1050{
1051 size_t i;
1052
1053 for (i = 0; i < ETH_ALEN; i++) {
1054 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1055 return 0;
1056 }
1057 return 1;
1058}
1059
1060
1061static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1062{
1063 size_t i;
1064
1065 for (i = 0; i < num; i++) {
1066 const u8 *a = list + i * ETH_ALEN * 2;
1067 const u8 *m = a + ETH_ALEN;
1068
1069 if (match_mac_mask(a, addr, m))
1070 return 1;
1071 }
1072 return 0;
1073}
1074
1075
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001076static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1077 const u8 **ret_ssid, size_t *ret_ssid_len)
1078{
1079#ifdef CONFIG_OWE
1080 const u8 *owe, *pos, *end, *bssid;
1081 u8 ssid_len;
1082 struct wpa_bss *open_bss;
1083
1084 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1085 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
1086 return;
1087
1088 pos = owe + 6;
1089 end = owe + 2 + owe[1];
1090
1091 if (end - pos < ETH_ALEN + 1)
1092 return;
1093 bssid = pos;
1094 pos += ETH_ALEN;
1095 ssid_len = *pos++;
1096 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1097 return;
1098
1099 /* Match the profile SSID against the OWE transition mode SSID on the
1100 * open network. */
1101 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1102 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1103 *ret_ssid = pos;
1104 *ret_ssid_len = ssid_len;
1105
Hai Shalomfdcde762020-04-02 11:19:20 -07001106 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1107 struct wpa_ssid *ssid;
1108
1109 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1110 if (wpas_network_disabled(wpa_s, ssid))
1111 continue;
1112 if (ssid->ssid_len == ssid_len &&
1113 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1114 /* OWE BSS in transition mode for a currently
1115 * enabled OWE network. */
1116 wpa_dbg(wpa_s, MSG_DEBUG,
1117 "OWE: transition mode OWE SSID for active OWE profile");
1118 bss->flags |= WPA_BSS_OWE_TRANSITION;
1119 break;
1120 }
1121 }
1122 }
1123
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001124 if (bss->ssid_len > 0)
1125 return;
1126
1127 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1128 if (!open_bss)
1129 return;
1130 if (ssid_len != open_bss->ssid_len ||
1131 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1132 wpa_dbg(wpa_s, MSG_DEBUG,
1133 "OWE: transition mode SSID mismatch: %s",
1134 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1135 return;
1136 }
1137
1138 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1139 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1140 wpa_dbg(wpa_s, MSG_DEBUG,
1141 "OWE: transition mode open BSS unexpected info");
1142 return;
1143 }
1144
1145 pos = owe + 6;
1146 end = owe + 2 + owe[1];
1147
1148 if (end - pos < ETH_ALEN + 1)
1149 return;
1150 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1151 wpa_dbg(wpa_s, MSG_DEBUG,
1152 "OWE: transition mode BSSID mismatch: " MACSTR,
1153 MAC2STR(pos));
1154 return;
1155 }
1156 pos += ETH_ALEN;
1157 ssid_len = *pos++;
1158 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1159 return;
1160 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1161 wpa_ssid_txt(pos, ssid_len));
1162 os_memcpy(bss->ssid, pos, ssid_len);
1163 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001164 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001165#endif /* CONFIG_OWE */
1166}
1167
1168
Sunil Ravi26978f32021-04-30 15:19:18 -07001169int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001170{
1171 int i, j;
1172
1173 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1174 return 0;
1175
1176 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1177 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1178
1179 for (i = 0; i < mode->num_channels; i++) {
1180 struct hostapd_channel_data *chan = &mode->channels[i];
1181
1182 if (chan->freq == freq)
1183 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1184 }
1185 }
1186
1187 return 1;
1188}
1189
1190
Hai Shalom899fcc72020-10-19 14:38:18 -07001191static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1192 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001193 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001194 bool debug_print);
1195
1196
1197#ifdef CONFIG_SAE_PK
1198static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1199 struct wpa_bss *orig_bss,
1200 struct wpa_ssid *ssid,
1201 const u8 *match_ssid,
1202 size_t match_ssid_len)
1203{
1204 struct wpa_bss *bss;
1205
1206 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1207 int count;
1208 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001209
1210 if (bss == orig_bss)
1211 continue;
1212 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001213 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001214 continue;
1215
1216 /* TODO: Could be more thorough in checking what kind of
1217 * signal strength or throughput estimate would be acceptable
1218 * compared to the originally selected BSS. */
1219 if (bss->est_throughput < 2000)
1220 return false;
1221
Hai Shalom60840252021-02-19 19:02:11 -08001222 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001223 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1224 bss, count, 0))
1225 return true;
1226 }
1227
1228 return false;
1229}
1230#endif /* CONFIG_SAE_PK */
1231
1232
1233static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1234 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001235 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001236 bool debug_print)
1237{
1238 int res;
1239 bool wpa, check_ssid, osen, rsn_osen = false;
1240 struct wpa_ie_data data;
1241#ifdef CONFIG_MBO
1242 const u8 *assoc_disallow;
1243#endif /* CONFIG_MBO */
1244#ifdef CONFIG_SAE
1245 u8 rsnxe_capa = 0;
1246#endif /* CONFIG_SAE */
1247 const u8 *ie;
1248
1249 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1250 wpa = ie && ie[1];
1251 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1252 wpa |= ie && ie[1];
1253 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1254 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1255 rsn_osen = true;
1256 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1257 osen = ie != NULL;
1258
1259#ifdef CONFIG_SAE
1260 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1261 if (ie && ie[1] >= 1)
1262 rsnxe_capa = ie[2];
1263#endif /* CONFIG_SAE */
1264
1265 check_ssid = wpa || ssid->ssid_len > 0;
1266
1267 if (wpas_network_disabled(wpa_s, ssid)) {
1268 if (debug_print)
1269 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1270 return false;
1271 }
1272
1273 res = wpas_temp_disabled(wpa_s, ssid);
1274 if (res > 0) {
1275 if (debug_print)
1276 wpa_dbg(wpa_s, MSG_DEBUG,
1277 " skip - disabled temporarily for %d second(s)",
1278 res);
1279 return false;
1280 }
1281
1282#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001283 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001284 if (debug_print)
1285 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001286 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001287 return false;
1288 }
1289
1290 if (wpa && ssid->ssid_len == 0 &&
1291 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1292 check_ssid = false;
1293
1294 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1295 /* Only allow wildcard SSID match if an AP advertises active
1296 * WPS operation that matches our mode. */
1297 check_ssid = ssid->ssid_len > 0 ||
1298 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1299 }
1300#endif /* CONFIG_WPS */
1301
1302 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1303 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1304 check_ssid = false;
1305
1306 if (check_ssid &&
1307 (match_ssid_len != ssid->ssid_len ||
1308 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1309 if (debug_print)
1310 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1311 return false;
1312 }
1313
1314 if (ssid->bssid_set &&
1315 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1316 if (debug_print)
1317 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1318 return false;
1319 }
1320
Hai Shalom60840252021-02-19 19:02:11 -08001321 /* check the list of BSSIDs to ignore */
1322 if (ssid->num_bssid_ignore &&
1323 addr_in_list(bss->bssid, ssid->bssid_ignore,
1324 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001325 if (debug_print)
1326 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001327 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001328 return false;
1329 }
1330
Hai Shalom60840252021-02-19 19:02:11 -08001331 /* if there is a list of accepted BSSIDs, only accept those APs */
1332 if (ssid->num_bssid_accept &&
1333 !addr_in_list(bss->bssid, ssid->bssid_accept,
1334 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001335 if (debug_print)
1336 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001337 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001338 return false;
1339 }
1340
1341 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1342 return false;
1343
1344 if (!osen && !wpa &&
1345 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1346 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1347 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1348 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1349 if (debug_print)
1350 wpa_dbg(wpa_s, MSG_DEBUG,
1351 " skip - non-WPA network not allowed");
1352 return false;
1353 }
1354
1355#ifdef CONFIG_WEP
1356 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1357 if (debug_print)
1358 wpa_dbg(wpa_s, MSG_DEBUG,
1359 " skip - ignore WPA/WPA2 AP for WEP network block");
1360 return false;
1361 }
1362#endif /* CONFIG_WEP */
1363
1364 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1365 if (debug_print)
1366 wpa_dbg(wpa_s, MSG_DEBUG,
1367 " skip - non-OSEN network not allowed");
1368 return false;
1369 }
1370
1371 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1372 if (debug_print)
1373 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1374 return false;
1375 }
1376
1377 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1378 !bss_is_pbss(bss)) {
1379 if (debug_print)
1380 wpa_dbg(wpa_s, MSG_DEBUG,
1381 " skip - not ESS, PBSS, or MBSS");
1382 return false;
1383 }
1384
1385 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1386 if (debug_print)
1387 wpa_dbg(wpa_s, MSG_DEBUG,
1388 " skip - PBSS mismatch (ssid %d bss %d)",
1389 ssid->pbss, bss_is_pbss(bss));
1390 return false;
1391 }
1392
1393 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1394 if (debug_print)
1395 wpa_dbg(wpa_s, MSG_DEBUG,
1396 " skip - frequency not allowed");
1397 return false;
1398 }
1399
1400#ifdef CONFIG_MESH
1401 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1402 ssid->frequency != bss->freq) {
1403 if (debug_print)
1404 wpa_dbg(wpa_s, MSG_DEBUG,
1405 " skip - frequency not allowed (mesh)");
1406 return false;
1407 }
1408#endif /* CONFIG_MESH */
1409
1410 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1411 if (debug_print)
1412 wpa_dbg(wpa_s, MSG_DEBUG,
1413 " skip - rate sets do not match");
1414 return false;
1415 }
1416
1417#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001418 /* When using SAE Password Identifier and when operationg on the 6 GHz
1419 * band, only H2E is allowed. */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001420 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1421 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1422 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1423 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001424#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301425 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001426#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001427 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1428 if (debug_print)
1429 wpa_dbg(wpa_s, MSG_DEBUG,
1430 " skip - SAE H2E required, but not supported by the AP");
1431 return false;
1432 }
1433#endif /* CONFIG_SAE */
1434
1435#ifdef CONFIG_SAE_PK
1436 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1437 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1438 if (debug_print)
1439 wpa_dbg(wpa_s, MSG_DEBUG,
1440 " skip - SAE-PK required, but not supported by the AP");
1441 return false;
1442 }
1443#endif /* CONFIG_SAE_PK */
1444
1445#ifndef CONFIG_IBSS_RSN
1446 if (ssid->mode == WPAS_MODE_IBSS &&
1447 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1448 if (debug_print)
1449 wpa_dbg(wpa_s, MSG_DEBUG,
1450 " skip - IBSS RSN not supported in the build");
1451 return false;
1452 }
1453#endif /* !CONFIG_IBSS_RSN */
1454
1455#ifdef CONFIG_P2P
1456 if (ssid->p2p_group &&
1457 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1458 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1459 if (debug_print)
1460 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1461 return false;
1462 }
1463
1464 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1465 struct wpabuf *p2p_ie;
1466 u8 dev_addr[ETH_ALEN];
1467
1468 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1469 if (!ie) {
1470 if (debug_print)
1471 wpa_dbg(wpa_s, MSG_DEBUG,
1472 " skip - no P2P element");
1473 return false;
1474 }
1475 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1476 if (!p2p_ie) {
1477 if (debug_print)
1478 wpa_dbg(wpa_s, MSG_DEBUG,
1479 " skip - could not fetch P2P element");
1480 return false;
1481 }
1482
1483 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1484 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1485 if (debug_print)
1486 wpa_dbg(wpa_s, MSG_DEBUG,
1487 " skip - no matching GO P2P Device Address in P2P element");
1488 wpabuf_free(p2p_ie);
1489 return false;
1490 }
1491 wpabuf_free(p2p_ie);
1492 }
1493
1494 /*
1495 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1496 * P2P Group Capability Bitmap and we are not in Group Formation with
1497 * that device.
1498 */
1499#endif /* CONFIG_P2P */
1500
1501 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1502 struct os_reltime diff;
1503
1504 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1505 if (debug_print)
1506 wpa_dbg(wpa_s, MSG_DEBUG,
1507 " skip - scan result not recent enough (%u.%06u seconds too old)",
1508 (unsigned int) diff.sec,
1509 (unsigned int) diff.usec);
1510 return false;
1511 }
1512#ifdef CONFIG_MBO
1513#ifdef CONFIG_TESTING_OPTIONS
1514 if (wpa_s->ignore_assoc_disallow)
1515 goto skip_assoc_disallow;
1516#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001517 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001518 if (assoc_disallow && assoc_disallow[1] >= 1) {
1519 if (debug_print)
1520 wpa_dbg(wpa_s, MSG_DEBUG,
1521 " skip - MBO association disallowed (reason %u)",
1522 assoc_disallow[2]);
1523 return false;
1524 }
1525
1526 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1527 if (debug_print)
1528 wpa_dbg(wpa_s, MSG_DEBUG,
1529 " skip - AP temporarily disallowed");
1530 return false;
1531 }
1532#ifdef CONFIG_TESTING_OPTIONS
1533skip_assoc_disallow:
1534#endif /* CONFIG_TESTING_OPTIONS */
1535#endif /* CONFIG_MBO */
1536
1537#ifdef CONFIG_DPP
1538 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001539 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1540 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001541 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1542 !ssid->dpp_csign)) {
1543 if (debug_print)
1544 wpa_dbg(wpa_s, MSG_DEBUG,
1545 " skip - no PMKSA entry for DPP");
1546 return false;
1547 }
1548#endif /* CONFIG_DPP */
1549
1550#ifdef CONFIG_SAE_PK
1551 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1552 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1553 ((ssid->sae_password &&
1554 sae_pk_valid_password(ssid->sae_password)) ||
1555 (!ssid->sae_password && ssid->passphrase &&
1556 sae_pk_valid_password(ssid->passphrase))) &&
1557 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1558 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1559 match_ssid_len)) {
1560 if (debug_print)
1561 wpa_dbg(wpa_s, MSG_DEBUG,
1562 " skip - another acceptable BSS with SAE-PK in the same ESS");
1563 return false;
1564 }
1565#endif /* CONFIG_SAE_PK */
1566
1567 if (bss->ssid_len == 0) {
1568 if (debug_print)
1569 wpa_dbg(wpa_s, MSG_DEBUG,
1570 " skip - no SSID known for the BSS");
1571 return false;
1572 }
1573
1574 /* Matching configuration found */
1575 return true;
1576}
1577
1578
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001579struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1580 int i, struct wpa_bss *bss,
1581 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001582 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001583{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001584 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001585 const u8 *ie;
1586 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001587 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001588 const u8 *match_ssid;
1589 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001590 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001591
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001592 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001593 wpa_ie_len = ie ? ie[1] : 0;
1594
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001595 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001596 rsn_ie_len = ie ? ie[1] : 0;
1597
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001598 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1599 osen = ie != NULL;
1600
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001601 if (debug_print) {
1602 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1603 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1604 i, MAC2STR(bss->bssid),
1605 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1606 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1607 bss->freq,
1608 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1609 " wps" : "",
1610 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1611 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1612 ? " p2p" : "",
1613 osen ? " osen=1" : "");
1614 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001615
Hai Shalom60840252021-02-19 19:02:11 -08001616 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1617 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001618 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001619 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001620 /*
1621 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001622 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623 * should not be done with multiple enabled networks to
1624 * avoid getting forced to move into a worse ESS on
1625 * single error if there are no other BSSes of the
1626 * current ESS.
1627 */
1628 limit = 0;
1629 }
Hai Shalom60840252021-02-19 19:02:11 -08001630 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001631 if (debug_print) {
1632 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001633 " skip - BSSID ignored (count=%d limit=%d)",
1634 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001635 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001636 return NULL;
1637 }
1638 }
1639
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001640 match_ssid = bss->ssid;
1641 match_ssid_len = bss->ssid_len;
1642 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1643
1644 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001645 if (debug_print)
1646 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647 return NULL;
1648 }
1649
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001650 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001651 if (debug_print)
1652 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001653 return NULL;
1654 }
1655
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001656 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001657 if (debug_print)
1658 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001659 return NULL;
1660 }
1661
Hai Shalomfdcde762020-04-02 11:19:20 -07001662 if (disabled_freq(wpa_s, bss->freq)) {
1663 if (debug_print)
1664 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1665 return NULL;
1666 }
1667
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001668 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001669 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001670 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001671 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672 }
1673
1674 /* No matching configuration found */
1675 return NULL;
1676}
1677
1678
1679static struct wpa_bss *
1680wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001681 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001682 struct wpa_ssid **selected_ssid,
1683 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001684{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001685 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001686
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001687 if (wpa_s->current_ssid) {
1688 struct wpa_ssid *ssid;
1689
1690 wpa_dbg(wpa_s, MSG_DEBUG,
1691 "Scan results matching the currently selected network");
1692 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1693 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1694
1695 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1696 only_first_ssid, 0);
1697 if (ssid != wpa_s->current_ssid)
1698 continue;
1699 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1700 " freq=%d level=%d snr=%d est_throughput=%u",
1701 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1702 bss->snr, bss->est_throughput);
1703 }
1704 }
1705
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001706 if (only_first_ssid)
1707 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1708 group->id);
1709 else
1710 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1711 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001712
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001713 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1714 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001715
1716 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001717 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001718 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001719 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001720 if (!*selected_ssid)
1721 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001722 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001723 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001724 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001725 MAC2STR(bss->bssid),
1726 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1727 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001728 }
1729
1730 return NULL;
1731}
1732
1733
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001734struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1735 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001736{
1737 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001738 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001739 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001740 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001741
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001742 if (wpa_s->last_scan_res == NULL ||
1743 wpa_s->last_scan_res_used == 0)
1744 return NULL; /* no scan results from last update */
1745
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001746 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001747 /* check that next_ssid is still valid */
1748 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1749 if (ssid == wpa_s->next_ssid)
1750 break;
1751 }
1752 next_ssid = ssid;
1753 wpa_s->next_ssid = NULL;
1754 }
1755
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001757 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1758 if (next_ssid && next_ssid->priority ==
1759 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001760 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001761 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001762 if (selected)
1763 break;
1764 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001765 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001766 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001767 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001768 if (selected)
1769 break;
1770 }
1771
Hai Shalom60840252021-02-19 19:02:11 -08001772 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001773 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001774 wpa_dbg(wpa_s, MSG_DEBUG,
1775 "No APs found - clear BSSID ignore list and try again");
1776 wpa_bssid_ignore_clear(wpa_s);
1777 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778 } else if (selected == NULL)
1779 break;
1780 }
1781
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001782 ssid = *selected_ssid;
1783 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1784 !ssid->passphrase && !ssid->ext_psk) {
1785 const char *field_name, *txt = NULL;
1786
1787 wpa_dbg(wpa_s, MSG_DEBUG,
1788 "PSK/passphrase not yet available for the selected network");
1789
1790 wpas_notify_network_request(wpa_s, ssid,
1791 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1792
1793 field_name = wpa_supplicant_ctrl_req_to_string(
1794 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1795 if (field_name == NULL)
1796 return NULL;
1797
1798 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1799
1800 selected = NULL;
1801 }
1802
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001803 return selected;
1804}
1805
1806
1807static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1808 int timeout_sec, int timeout_usec)
1809{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001810 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001811 /*
1812 * No networks are enabled; short-circuit request so
1813 * we don't wait timeout seconds before transitioning
1814 * to INACTIVE state.
1815 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001816 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1817 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001818 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1819 return;
1820 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001821
1822 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1824}
1825
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001826
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001827int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001828 struct wpa_bss *selected,
1829 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830{
Sunil Ravi036cec52023-03-29 11:35:17 -07001831 if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
1832 wpas_wps_partner_link_overlap_detect(wpa_s)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +00001833 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1835 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001836 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001837 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001839 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1840 wpa_s->p2p_in_provisioning) {
1841 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1842 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001843 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001844 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845#endif /* CONFIG_P2P */
1846
1847#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001848 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001849 wpas_wps_cancel(wpa_s);
1850#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001851 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001852 }
1853
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001854 wpa_msg(wpa_s, MSG_DEBUG,
1855 "Considering connect request: reassociate: %d selected: "
1856 MACSTR " bssid: " MACSTR " pending: " MACSTR
1857 " wpa_state: %s ssid=%p current_ssid=%p",
1858 wpa_s->reassociate, MAC2STR(selected->bssid),
1859 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1860 wpa_supplicant_state_txt(wpa_s->wpa_state),
1861 ssid, wpa_s->current_ssid);
1862
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001863 /*
1864 * Do not trigger new association unless the BSSID has changed or if
1865 * reassociation is requested. If we are in process of associating with
1866 * the selected BSSID, do not trigger new attempt.
1867 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001868 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001869 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1870 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1871 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001872 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1873 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1874 0) ||
1875 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1876 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001877 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1878 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001879 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001880 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001881 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1882 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001883 wpa_supplicant_associate(wpa_s, selected, ssid);
1884 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001885 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1886 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001887 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001888
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001889 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001890}
1891
1892
1893static struct wpa_ssid *
1894wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1895{
Hai Shalomfdcde762020-04-02 11:19:20 -07001896 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001897 struct wpa_ssid *ssid;
1898
1899 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1900 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1901 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001902 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001903 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001904#ifndef CONFIG_IBSS_RSN
1905 if (ssid->mode == WPAS_MODE_IBSS &&
1906 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1907 WPA_KEY_MGMT_WPA_NONE))) {
1908 wpa_msg(wpa_s, MSG_INFO,
1909 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1910 wpa_ssid_txt(ssid->ssid,
1911 ssid->ssid_len));
1912 continue;
1913 }
1914#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001915 if (ssid->mode == WPAS_MODE_IBSS ||
1916 ssid->mode == WPAS_MODE_AP ||
1917 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001918 return ssid;
1919 }
1920 }
1921 return NULL;
1922}
1923
1924
1925/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1926 * on BSS added and BSS changed events */
1927static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001928 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001929{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001930 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001931
1932 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1933 return;
1934
Jouni Malinen87fd2792011-05-16 18:35:42 +03001935 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001936 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001937
Jouni Malinen87fd2792011-05-16 18:35:42 +03001938 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001939 if (ssid == NULL)
1940 continue;
1941
Jouni Malinen87fd2792011-05-16 18:35:42 +03001942 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001943 if (rsn == NULL)
1944 continue;
1945
Jouni Malinen87fd2792011-05-16 18:35:42 +03001946 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001947 }
1948
1949}
1950
1951
Hai Shalomfdcde762020-04-02 11:19:20 -07001952#ifndef CONFIG_NO_ROAMING
1953
1954static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1955{
1956 if (noise == WPA_INVALID_NOISE)
1957 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1958 DEFAULT_NOISE_FLOOR_2GHZ;
1959 return avg_signal - noise;
1960}
1961
1962
1963static unsigned int
1964wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1965 const struct wpa_bss *bss, int snr)
1966{
1967 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001968 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001969 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1970
Hai Shalomc1a21442022-02-04 13:43:00 -08001971 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07001972}
1973
Hai Shalomfdcde762020-04-02 11:19:20 -07001974
Hai Shalom899fcc72020-10-19 14:38:18 -07001975int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1976 struct wpa_bss *current_bss,
1977 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001978{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001979 int min_diff, diff;
Sunil Ravi036cec52023-03-29 11:35:17 -07001980 int to_5ghz, to_6ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001981 int cur_level;
1982 unsigned int cur_est, sel_est;
1983 struct wpa_signal_info si;
1984 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001985 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001986
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001987 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001988 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001989 " freq=%d level=%d snr=%d est_throughput=%u",
1990 MAC2STR(current_bss->bssid),
1991 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001992 current_bss->snr, current_bss->est_throughput);
1993 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001994 " freq=%d level=%d snr=%d est_throughput=%u",
1995 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001996 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001997
1998 if (wpa_s->current_ssid->bssid_set &&
1999 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
2000 0) {
2001 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2002 "has preferred BSSID");
2003 return 1;
2004 }
2005
Hai Shalomfdcde762020-04-02 11:19:20 -07002006 cur_level = current_bss->level;
2007 cur_est = current_bss->est_throughput;
2008 sel_est = selected->est_throughput;
2009
2010 /*
2011 * Try to poll the signal from the driver since this will allow to get
2012 * more accurate values. In some cases, there can be big differences
2013 * between the RSSI of the Probe Response frames of the AP we are
2014 * associated with and the Beacon frames we hear from the same AP after
2015 * association. This can happen, e.g., when there are two antennas that
2016 * hear the AP very differently. If the driver chooses to hear the
2017 * Probe Response frames during the scan on the "bad" antenna because
2018 * it wants to save power, but knows to choose the other antenna after
2019 * association, we will hear our AP with a low RSSI as part of the
2020 * scan even when we can hear it decently on the other antenna. To cope
2021 * with this, ask the driver to teach us how it hears the AP. Also, the
2022 * scan results may be a bit old, since we can very quickly get fresh
2023 * information about our currently associated AP.
2024 */
2025 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002026 (si.data.avg_beacon_signal || si.data.avg_signal)) {
2027 cur_level = si.data.avg_beacon_signal ?
2028 si.data.avg_beacon_signal : si.data.avg_signal;
Hai Shalomfdcde762020-04-02 11:19:20 -07002029 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2030 si.current_noise);
2031
2032 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2033 current_bss,
2034 cur_snr);
2035 wpa_dbg(wpa_s, MSG_DEBUG,
2036 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2037 cur_level, cur_snr, cur_est);
2038 }
2039
2040 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002041 wpa_dbg(wpa_s, MSG_DEBUG,
2042 "Allow reassociation - selected BSS has better estimated throughput");
2043 return 1;
2044 }
2045
Dmitry Shmidte4663042016-04-04 10:07:49 -07002046 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
Sunil Ravi036cec52023-03-29 11:35:17 -07002047 to_6ghz = is_6ghz_freq(selected->freq) &&
2048 !is_6ghz_freq(current_bss->freq);
Dmitry Shmidte4663042016-04-04 10:07:49 -07002049
Sunil Ravi036cec52023-03-29 11:35:17 -07002050 if (cur_level < 0 &&
2051 cur_level > selected->level + to_5ghz * 2 + to_6ghz * 2 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002052 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002053 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2054 "signal level");
2055 return 0;
2056 }
2057
Hai Shalomfdcde762020-04-02 11:19:20 -07002058 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002059 wpa_dbg(wpa_s, MSG_DEBUG,
2060 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002061 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002062 }
2063
Hai Shalomfdcde762020-04-02 11:19:20 -07002064 if (cur_snr > GREAT_SNR) {
2065 wpa_dbg(wpa_s, MSG_DEBUG,
2066 "Skip roam - Current BSS has good SNR (%u > %u)",
2067 cur_snr, GREAT_SNR);
2068 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002069 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002070
Hai Shalomfdcde762020-04-02 11:19:20 -07002071 if (cur_level < -85) /* ..-86 dBm */
2072 min_diff = 1;
2073 else if (cur_level < -80) /* -85..-81 dBm */
2074 min_diff = 2;
2075 else if (cur_level < -75) /* -80..-76 dBm */
2076 min_diff = 3;
2077 else if (cur_level < -70) /* -75..-71 dBm */
2078 min_diff = 4;
2079 else if (cur_level < 0) /* -70..-1 dBm */
2080 min_diff = 5;
2081 else /* unspecified units (not in dBm) */
2082 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002083
Hai Shalomfdcde762020-04-02 11:19:20 -07002084 if (cur_est > sel_est * 1.5)
2085 min_diff += 10;
2086 else if (cur_est > sel_est * 1.2)
2087 min_diff += 5;
2088 else if (cur_est > sel_est * 1.1)
2089 min_diff += 2;
2090 else if (cur_est > sel_est)
2091 min_diff++;
2092 else if (sel_est > cur_est * 1.5)
2093 min_diff -= 10;
2094 else if (sel_est > cur_est * 1.2)
2095 min_diff -= 5;
2096 else if (sel_est > cur_est * 1.1)
2097 min_diff -= 2;
2098 else if (sel_est > cur_est)
2099 min_diff--;
2100
2101 if (to_5ghz)
2102 min_diff -= 2;
Sunil Ravi036cec52023-03-29 11:35:17 -07002103 if (to_6ghz)
2104 min_diff -= 2;
Hai Shalomfdcde762020-04-02 11:19:20 -07002105 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002106 if (diff < min_diff) {
2107 wpa_dbg(wpa_s, MSG_DEBUG,
2108 "Skip roam - too small difference in signal level (%d < %d)",
2109 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002110 ret = 0;
2111 } else {
2112 wpa_dbg(wpa_s, MSG_DEBUG,
2113 "Allow reassociation due to difference in signal level (%d >= %d)",
2114 diff, min_diff);
2115 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002116 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002117 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2118 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2119 " sel_freq=%d sel_level=%d sel_est=%d",
2120 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2121 MAC2STR(current_bss->bssid),
2122 current_bss->freq, cur_level, cur_est,
2123 MAC2STR(selected->bssid),
2124 selected->freq, selected->level, sel_est);
2125 return ret;
2126}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002127
Hai Shalom899fcc72020-10-19 14:38:18 -07002128#endif /* CONFIG_NO_ROAMING */
2129
2130
2131static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2132 struct wpa_bss *selected,
2133 struct wpa_ssid *ssid)
2134{
2135 struct wpa_bss *current_bss = NULL;
2136
2137 if (wpa_s->reassociate)
2138 return 1; /* explicit request to reassociate */
2139 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2140 return 1; /* we are not associated; continue */
2141 if (wpa_s->current_ssid == NULL)
2142 return 1; /* unknown current SSID */
2143 if (wpa_s->current_ssid != ssid)
2144 return 1; /* different network block */
2145
2146 if (wpas_driver_bss_selection(wpa_s))
2147 return 0; /* Driver-based roaming */
2148
2149 if (wpa_s->current_ssid->ssid)
2150 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2151 wpa_s->current_ssid->ssid,
2152 wpa_s->current_ssid->ssid_len);
2153 if (!current_bss)
2154 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2155
2156 if (!current_bss)
2157 return 1; /* current BSS not seen in scan results */
2158
2159 if (current_bss == selected)
2160 return 0;
2161
2162 if (selected->last_update_idx > current_bss->last_update_idx)
2163 return 1; /* current BSS not seen in the last scan */
2164
2165#ifndef CONFIG_NO_ROAMING
2166 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2167 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002168#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002169 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002170#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002171}
2172
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002173
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002174/*
2175 * Return a negative value if no scan results could be fetched or if scan
2176 * results should not be shared with other virtual interfaces.
2177 * Return 0 if scan results were fetched and may be shared with other
2178 * interfaces.
2179 * Return 1 if scan results may be shared with other virtual interfaces but may
2180 * not trigger any operations.
2181 * Return 2 if the interface was removed and cannot be used.
2182 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002183static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002184 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002185 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002187 struct wpa_scan_results *scan_res = NULL;
2188 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002189 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002190#ifndef CONFIG_NO_RANDOM_POOL
2191 size_t i, num;
2192#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002193
2194#ifdef CONFIG_AP
2195 if (wpa_s->ap_iface)
2196 ap = 1;
2197#endif /* CONFIG_AP */
2198
2199 wpa_supplicant_notify_scanning(wpa_s, 0);
2200
2201 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2202 data ? &data->scan_info :
2203 NULL, 1);
2204 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002205 if (wpa_s->conf->ap_scan == 2 || ap ||
2206 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002207 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002208 if (!own_request)
2209 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002210 if (data && data->scan_info.external_scan)
2211 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002212 if (wpa_s->scan_res_fail_handler) {
2213 void (*handler)(struct wpa_supplicant *wpa_s);
2214
2215 handler = wpa_s->scan_res_fail_handler;
2216 wpa_s->scan_res_fail_handler = NULL;
2217 handler(wpa_s);
2218 } else {
2219 wpa_dbg(wpa_s, MSG_DEBUG,
2220 "Failed to get scan results - try scanning again");
2221 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2222 }
2223
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002224 ret = -1;
2225 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002226 }
2227
2228#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002229 num = scan_res->num;
2230 if (num > 10)
2231 num = 10;
2232 for (i = 0; i < num; i++) {
2233 u8 buf[5];
2234 struct wpa_scan_res *res = scan_res->res[i];
2235 buf[0] = res->bssid[5];
2236 buf[1] = res->qual & 0xff;
2237 buf[2] = res->noise & 0xff;
2238 buf[3] = res->level & 0xff;
2239 buf[4] = res->tsf & 0xff;
2240 random_add_randomness(buf, sizeof(buf));
2241 }
2242#endif /* CONFIG_NO_RANDOM_POOL */
2243
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002244 if (update_only) {
2245 ret = 1;
2246 goto scan_work_done;
2247 }
2248
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002249 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002250 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002251 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2252 struct wpa_scan_results *scan_res);
2253
2254 scan_res_handler = wpa_s->scan_res_handler;
2255 wpa_s->scan_res_handler = NULL;
2256 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002257 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002258 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002259 }
2260
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002261 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002262 wpa_s->own_scan_running,
2263 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002264 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002265 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2266 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002267 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2268 wpa_s->manual_scan_id);
2269 wpa_s->manual_scan_use_id = 0;
2270 } else {
2271 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2272 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002273 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274
2275 wpas_notify_scan_done(wpa_s, 1);
2276
Hai Shalomfdcde762020-04-02 11:19:20 -07002277 if (ap) {
2278 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2279#ifdef CONFIG_AP
2280 if (wpa_s->ap_iface->scan_cb)
2281 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2282#endif /* CONFIG_AP */
2283 goto scan_work_done;
2284 }
2285
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002286 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002287 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 -07002288 wpa_scan_results_free(scan_res);
2289 return 0;
2290 }
2291
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002292 if (wnm_scan_process(wpa_s, 1) > 0)
2293 goto scan_work_done;
2294
Hai Shalomc1a21442022-02-04 13:43:00 -08002295 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002296 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002297
Hai Shalom021b0b52019-04-10 11:17:58 -07002298 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002299 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2300 goto scan_work_done;
2301
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002302 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2303 goto scan_work_done;
2304
2305 if (autoscan_notify_scan(wpa_s, scan_res))
2306 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 if (wpa_s->disconnected) {
2309 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002310 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002311 }
2312
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002313 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002314 bgscan_notify_scan(wpa_s, scan_res) == 1)
2315 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002316
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002317 wpas_wps_update_ap_info(wpa_s, scan_res);
2318
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002319 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2320 wpa_s->wpa_state < WPA_COMPLETED)
2321 goto scan_work_done;
2322
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002323 wpa_scan_results_free(scan_res);
2324
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002325 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002326 struct wpa_radio_work *work = wpa_s->scan_work;
2327 wpa_s->scan_work = NULL;
2328 radio_work_done(work);
2329 }
2330
Hai Shalomc3565922019-10-28 11:58:20 -07002331 os_free(wpa_s->last_scan_freqs);
2332 wpa_s->last_scan_freqs = NULL;
2333 wpa_s->num_last_scan_freqs = 0;
2334 if (own_request && data &&
2335 data->scan_info.freqs && data->scan_info.num_freqs) {
2336 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2337 data->scan_info.num_freqs);
2338 if (wpa_s->last_scan_freqs) {
2339 os_memcpy(wpa_s->last_scan_freqs,
2340 data->scan_info.freqs,
2341 sizeof(int) * data->scan_info.num_freqs);
2342 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2343 }
2344 }
2345
Sunil Ravi77d572f2023-01-17 23:58:31 +00002346 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2347 return ret;
2348
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002349 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002350
2351scan_work_done:
2352 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002353 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002354 struct wpa_radio_work *work = wpa_s->scan_work;
2355 wpa_s->scan_work = NULL;
2356 radio_work_done(work);
2357 }
2358 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002359}
2360
2361
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002362static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002363 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002364{
2365 struct wpa_bss *selected;
2366 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002367 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2368
2369 if (time_to_reenable > 0) {
2370 wpa_dbg(wpa_s, MSG_DEBUG,
2371 "Postpone network selection by %d seconds since all networks are disabled",
2372 time_to_reenable);
2373 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2374 eloop_register_timeout(time_to_reenable, 0,
2375 wpas_network_reenabled, wpa_s, NULL);
2376 return 0;
2377 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002378
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002379 if (wpa_s->p2p_mgmt)
2380 return 0; /* no normal connection on p2p_mgmt interface */
2381
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002382 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002383 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002385#ifdef CONFIG_MESH
2386 if (wpa_s->ifmsh) {
2387 wpa_msg(wpa_s, MSG_INFO,
2388 "Avoiding join because we already joined a mesh group");
2389 return 0;
2390 }
2391#endif /* CONFIG_MESH */
2392
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002393 if (selected) {
2394 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002395 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002396 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002397 if (new_scan)
2398 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002399 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002400 }
2401
Hai Shalomc3565922019-10-28 11:58:20 -07002402 wpa_s->suitable_network++;
2403
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002404 if (ssid != wpa_s->current_ssid &&
2405 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2406 wpa_s->own_disconnect_req = 1;
2407 wpa_supplicant_deauthenticate(
2408 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2409 }
2410
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002411 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002412 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002413 return -1;
2414 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002415 wpa_s->supp_pbc_active = false;
2416
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002417 if (new_scan)
2418 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002419 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002420 * Do not allow other virtual radios to trigger operations based
2421 * on these scan results since we do not want them to start
2422 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002423 */
2424 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002425 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002426 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002427 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2428 ssid = wpa_supplicant_pick_new_network(wpa_s);
2429 if (ssid) {
2430 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2431 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002432 if (new_scan)
2433 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002434 } else if (own_request) {
2435 /*
2436 * No SSID found. If SCAN results are as a result of
2437 * own scan request and not due to a scan request on
2438 * another shared interface, try another scan.
2439 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002440 int timeout_sec = wpa_s->scan_interval;
2441 int timeout_usec = 0;
2442#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002443 int res;
2444
2445 res = wpas_p2p_scan_no_go_seen(wpa_s);
2446 if (res == 2)
2447 return 2;
2448 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002449 return 0;
2450
Sunil Ravi77d572f2023-01-17 23:58:31 +00002451 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002452 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002453
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002454 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002455 wpa_s->show_group_started ||
2456 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002457 /*
2458 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002459 * state and during P2P join-a-group operation
2460 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002461 */
2462 timeout_sec = 0;
2463 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002464 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2465 timeout_usec);
2466 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002467 }
2468#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002469#ifdef CONFIG_INTERWORKING
2470 if (wpa_s->conf->auto_interworking &&
2471 wpa_s->conf->interworking &&
2472 wpa_s->conf->cred) {
2473 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2474 "start ANQP fetch since no matching "
2475 "networks found");
2476 wpa_s->network_select = 1;
2477 wpa_s->auto_network_select = 1;
2478 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002479 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002480 }
2481#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002482#ifdef CONFIG_WPS
2483 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2484 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2485 timeout_sec = 0;
2486 timeout_usec = 500000;
2487 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2488 timeout_usec);
2489 return 0;
2490 }
2491#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002492#ifdef CONFIG_OWE
2493 if (wpa_s->owe_transition_search) {
2494 wpa_dbg(wpa_s, MSG_DEBUG,
2495 "OWE: Use shorter wait during transition mode search");
2496 timeout_sec = 0;
2497 timeout_usec = 500000;
2498 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2499 timeout_usec);
2500 return 0;
2501 }
2502#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002503 if (wpa_supplicant_req_sched_scan(wpa_s))
2504 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2505 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002506
2507 wpa_msg_ctrl(wpa_s, MSG_INFO,
2508 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002509 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002510 }
2511 }
2512 return 0;
2513}
2514
2515
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002516static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2517 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002518{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002519 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002520 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002521
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002522 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002523 if (res == 2) {
2524 /*
2525 * Interface may have been removed, so must not dereference
2526 * wpa_s after this.
2527 */
2528 return 1;
2529 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002530
2531 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002532 /*
2533 * If no scan results could be fetched, then no need to
2534 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002535 * this scan. Similarly, if scan results started a new operation on this
2536 * interface, do not notify other interfaces to avoid concurrent
2537 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002538 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002539 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002540 }
2541
2542 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002543 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002544 * so, they get updated with this same scan info.
2545 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002546 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2547 radio_list) {
2548 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002549 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2550 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002551 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2552 res > 0);
2553 if (res < 0)
2554 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002555 }
2556 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002557
2558 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002559}
2560
2561#endif /* CONFIG_NO_SCAN_PROCESSING */
2562
2563
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002564int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2565{
2566#ifdef CONFIG_NO_SCAN_PROCESSING
2567 return -1;
2568#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002569 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002570
Dmitry Shmidt29333592017-01-09 12:27:11 -08002571 wpa_s->ignore_post_flush_scan_res = 0;
2572
Dmitry Shmidt41712582015-06-29 11:02:15 -07002573 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002574 return -1;
2575
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002576 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002577 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002578 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002579 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2580 return -1;
2581 }
2582
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002583 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002584#endif /* CONFIG_NO_SCAN_PROCESSING */
2585}
2586
Sunil Ravi77d572f2023-01-17 23:58:31 +00002587
2588int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2589{
2590#ifdef CONFIG_NO_SCAN_PROCESSING
2591 return -1;
2592#else /* CONFIG_NO_SCAN_PROCESSING */
2593 return wpas_select_network_from_last_scan(wpa_s, 1, 1);
2594#endif /* CONFIG_NO_SCAN_PROCESSING */
2595}
2596
2597
Dmitry Shmidt04949592012-07-19 12:16:46 -07002598#ifdef CONFIG_WNM
2599
2600static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2601{
2602 struct wpa_supplicant *wpa_s = eloop_ctx;
2603
2604 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2605 return;
2606
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002607 if (!wpa_s->no_keep_alive) {
2608 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2609 MAC2STR(wpa_s->bssid));
2610 /* TODO: could skip this if normal data traffic has been sent */
2611 /* TODO: Consider using some more appropriate data frame for
2612 * this */
2613 if (wpa_s->l2)
2614 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2615 (u8 *) "", 0);
2616 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002617
2618#ifdef CONFIG_SME
2619 if (wpa_s->sme.bss_max_idle_period) {
2620 unsigned int msec;
2621 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2622 if (msec > 100)
2623 msec -= 100;
2624 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2625 wnm_bss_keep_alive, wpa_s, NULL);
2626 }
2627#endif /* CONFIG_SME */
2628}
2629
2630
2631static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2632 const u8 *ies, size_t ies_len)
2633{
2634 struct ieee802_11_elems elems;
2635
2636 if (ies == NULL)
2637 return;
2638
2639 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2640 return;
2641
2642#ifdef CONFIG_SME
2643 if (elems.bss_max_idle_period) {
2644 unsigned int msec;
2645 wpa_s->sme.bss_max_idle_period =
2646 WPA_GET_LE16(elems.bss_max_idle_period);
2647 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2648 "TU)%s", wpa_s->sme.bss_max_idle_period,
2649 (elems.bss_max_idle_period[2] & 0x01) ?
2650 " (protected keep-live required)" : "");
2651 if (wpa_s->sme.bss_max_idle_period == 0)
2652 wpa_s->sme.bss_max_idle_period = 1;
2653 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2654 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2655 /* msec times 1000 */
2656 msec = wpa_s->sme.bss_max_idle_period * 1024;
2657 if (msec > 100)
2658 msec -= 100;
2659 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2660 wnm_bss_keep_alive, wpa_s,
2661 NULL);
2662 }
2663 }
2664#endif /* CONFIG_SME */
2665}
2666
2667#endif /* CONFIG_WNM */
2668
2669
2670void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2671{
2672#ifdef CONFIG_WNM
2673 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2674#endif /* CONFIG_WNM */
2675}
2676
2677
Dmitry Shmidt051af732013-10-22 13:52:46 -07002678#ifdef CONFIG_INTERWORKING
2679
2680static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2681 size_t len)
2682{
2683 int res;
2684
2685 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2686 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2687 if (res) {
2688 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2689 }
2690
2691 return res;
2692}
2693
2694
2695static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2696 const u8 *ies, size_t ies_len)
2697{
2698 struct ieee802_11_elems elems;
2699
2700 if (ies == NULL)
2701 return;
2702
2703 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2704 return;
2705
2706 if (elems.qos_map_set) {
2707 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2708 elems.qos_map_set_len);
2709 }
2710}
2711
2712#endif /* CONFIG_INTERWORKING */
2713
2714
Sunil Ravi036cec52023-03-29 11:35:17 -07002715static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
2716{
2717 if (wpa_s->enabled_4addr_mode) {
2718 wpa_printf(MSG_DEBUG, "4addr mode already set");
2719 return;
2720 }
2721
2722 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2723 wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
2724 goto fail;
2725 }
2726 wpa_s->enabled_4addr_mode = 1;
2727 wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
2728 return;
2729
2730fail:
2731 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2732}
2733
2734
Hai Shalom74f70d42019-02-11 14:42:39 -08002735static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2736 const u8 *ies, size_t ies_len)
2737{
2738 struct ieee802_11_elems elems;
2739 const u8 *map_sub_elem, *pos;
2740 size_t len;
2741
Hai Shalomfdcde762020-04-02 11:19:20 -07002742 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002743
Hai Shalomfdcde762020-04-02 11:19:20 -07002744 if (!ies ||
2745 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2746 !elems.multi_ap || elems.multi_ap_len < 7)
2747 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002748
2749 pos = elems.multi_ap + 4;
2750 len = elems.multi_ap_len - 4;
2751
2752 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002753 if (!map_sub_elem || map_sub_elem[1] < 1)
2754 return;
2755
2756 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2757 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2758 MULTI_AP_FRONTHAUL_BSS);
2759 wpa_s->multi_ap_ie = 1;
2760}
2761
2762
2763static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2764{
2765 if (!wpa_s->current_ssid ||
2766 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2767 return;
2768
2769 if (!wpa_s->multi_ap_ie) {
2770 wpa_printf(MSG_INFO,
2771 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002772 goto fail;
2773 }
2774
Hai Shalomfdcde762020-04-02 11:19:20 -07002775 if (!wpa_s->multi_ap_backhaul) {
2776 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002777 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2778 wpa_printf(MSG_INFO,
2779 "WPS active, accepting fronthaul-only BSS");
2780 /* Don't set 4addr mode in this case, so just return */
2781 return;
2782 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002783 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2784 goto fail;
2785 }
2786
Sunil Ravi036cec52023-03-29 11:35:17 -07002787 wpa_supplicant_set_4addr_mode(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08002788 return;
2789
2790fail:
2791 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2792}
2793
2794
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002795#ifdef CONFIG_FST
2796static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2797 const u8 *ie, size_t ie_len)
2798{
2799 struct mb_ies_info mb_ies;
2800
2801 if (!ie || !ie_len || !wpa_s->fst)
2802 return -ENOENT;
2803
2804 os_memset(&mb_ies, 0, sizeof(mb_ies));
2805
2806 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2807 size_t len;
2808
2809 len = 2 + ie[1];
2810 if (len > ie_len) {
2811 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2812 ie, ie_len);
2813 break;
2814 }
2815
2816 if (ie[0] == WLAN_EID_MULTI_BAND) {
2817 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2818 (unsigned int) len);
2819 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2820 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2821 mb_ies.nof_ies++;
2822 }
2823
2824 ie_len -= len;
2825 ie += len;
2826 }
2827
2828 if (mb_ies.nof_ies > 0) {
2829 wpabuf_free(wpa_s->received_mb_ies);
2830 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2831 return 0;
2832 }
2833
2834 return -ENOENT;
2835}
2836#endif /* CONFIG_FST */
2837
2838
Hai Shalomc1a21442022-02-04 13:43:00 -08002839static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2840 union wpa_event_data *data)
2841{
2842 int sel;
2843 const u8 *p;
2844 int l, len;
2845 bool found = false;
2846 struct wpa_ie_data ie;
2847 struct wpa_ssid *ssid = wpa_s->current_ssid;
2848 struct wpa_bss *bss = wpa_s->current_bss;
2849 int pmf;
2850
2851 if (!ssid)
2852 return 0;
2853
2854 p = data->assoc_info.req_ies;
2855 l = data->assoc_info.req_ies_len;
2856
2857 while (p && l >= 2) {
2858 len = p[1] + 2;
2859 if (len > l) {
2860 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2861 p, l);
2862 break;
2863 }
2864 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2865 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2866 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2867 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2868 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2869 found = true;
2870 break;
2871 }
2872 l -= len;
2873 p += len;
2874 }
2875
Sunil Ravi036cec52023-03-29 11:35:17 -07002876 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
2877 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
Hai Shalomc1a21442022-02-04 13:43:00 -08002878 return 0;
Sunil Ravi036cec52023-03-29 11:35:17 -07002879 }
Hai Shalomc1a21442022-02-04 13:43:00 -08002880
2881 wpa_hexdump(MSG_DEBUG,
2882 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2883 p, l);
2884
2885 /* Update proto from (Re)Association Request frame info */
2886 wpa_s->wpa_proto = ie.proto;
2887 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2888 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2889 !!(wpa_s->wpa_proto &
2890 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2891
2892 /* Update AKMP suite from (Re)Association Request frame info */
2893 sel = ie.key_mgmt;
2894 if (ssid->key_mgmt)
2895 sel &= ssid->key_mgmt;
2896
2897 wpa_dbg(wpa_s, MSG_DEBUG,
2898 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2899 ie.key_mgmt, ssid->key_mgmt, sel);
2900 if (ie.key_mgmt && !sel) {
2901 wpa_supplicant_deauthenticate(
2902 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2903 return -1;
2904 }
2905
Sunil Ravi036cec52023-03-29 11:35:17 -07002906#ifdef CONFIG_OCV
2907 if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
2908 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
2909 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
2910 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
2911#endif /* CONFIG_OCV */
2912
Sunil Ravi89eba102022-09-13 21:04:37 -07002913 /*
2914 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
2915 * different AKM.
2916 */
2917 if (wpa_s->key_mgmt != ie.key_mgmt &&
2918 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
2919 if (!ssid->psk_set) {
2920 wpa_dbg(wpa_s, MSG_INFO,
2921 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00002922 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07002923 return -1;
2924 }
2925
2926 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
2927 if (wpa_s->conf->key_mgmt_offload &&
2928 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002929 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
2930 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07002931 wpa_dbg(wpa_s, MSG_ERROR,
2932 "WPA: Cannot set PMK for key management offload");
2933 }
2934
Hai Shalomc1a21442022-02-04 13:43:00 -08002935 wpa_s->key_mgmt = ie.key_mgmt;
2936 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2937 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2938 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2939 wpa_s->wpa_proto);
2940
2941 /* Update pairwise cipher from (Re)Association Request frame info */
2942 sel = ie.pairwise_cipher;
2943 if (ssid->pairwise_cipher)
2944 sel &= ssid->pairwise_cipher;
2945
2946 wpa_dbg(wpa_s, MSG_DEBUG,
2947 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2948 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2949 if (ie.pairwise_cipher && !sel) {
2950 wpa_supplicant_deauthenticate(
2951 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2952 return -1;
2953 }
2954
2955 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2956 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2957 wpa_s->pairwise_cipher);
2958 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2959 wpa_cipher_txt(wpa_s->pairwise_cipher));
2960
2961 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2962 if (!bss) {
2963 wpa_dbg(wpa_s, MSG_DEBUG,
2964 "WPA: current_bss == NULL - skip AP IE check");
2965 return 0;
2966 }
2967
2968 /* Update GTK and IGTK from AP's RSNE */
2969 found = false;
2970
2971 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2972 const u8 *bss_rsn;
2973
2974 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2975 if (bss_rsn) {
2976 p = bss_rsn;
2977 len = 2 + bss_rsn[1];
2978 found = true;
2979 }
2980 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2981 const u8 *bss_wpa;
2982
2983 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2984 if (bss_wpa) {
2985 p = bss_wpa;
2986 len = 2 + bss_wpa[1];
2987 found = true;
2988 }
2989 }
2990
2991 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2992 return 0;
2993
2994 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2995 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2996 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
2997 /* AP does not support MFP, local configuration requires it */
2998 wpa_supplicant_deauthenticate(
2999 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3000 return -1;
3001 }
3002 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3003 pmf == NO_MGMT_FRAME_PROTECTION) {
3004 /* AP requires MFP, local configuration disables it */
3005 wpa_supplicant_deauthenticate(
3006 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3007 return -1;
3008 }
3009
3010 /* Update PMF from local configuration now that MFP validation was done
3011 * above */
3012 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3013
3014 /* Update GTK from AP's RSNE */
3015 sel = ie.group_cipher;
3016 if (ssid->group_cipher)
3017 sel &= ssid->group_cipher;
3018
3019 wpa_dbg(wpa_s, MSG_DEBUG,
3020 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3021 ie.group_cipher, ssid->group_cipher, sel);
3022 if (ie.group_cipher && !sel) {
3023 wpa_supplicant_deauthenticate(
3024 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3025 return -1;
3026 }
3027
3028 wpa_s->group_cipher = ie.group_cipher;
3029 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3030 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3031 wpa_cipher_txt(wpa_s->group_cipher));
3032
3033 /* Update IGTK from AP RSN IE */
3034 sel = ie.mgmt_group_cipher;
3035 if (ssid->group_mgmt_cipher)
3036 sel &= ssid->group_mgmt_cipher;
3037
3038 wpa_dbg(wpa_s, MSG_DEBUG,
3039 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3040 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3041
3042 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3043 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3044 wpa_dbg(wpa_s, MSG_DEBUG,
3045 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3046 ie.capabilities);
3047 ie.mgmt_group_cipher = 0;
3048 }
3049
3050 if (ie.mgmt_group_cipher && !sel) {
3051 wpa_supplicant_deauthenticate(
3052 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3053 return -1;
3054 }
3055
3056 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3057 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3058 wpa_s->mgmt_group_cipher);
3059 if (wpa_s->mgmt_group_cipher)
3060 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3061 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3062 else
3063 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3064
3065 return 0;
3066}
3067
3068
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003069static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3070 union wpa_event_data *data)
3071{
Hai Shalomc3565922019-10-28 11:58:20 -07003072 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003074 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003075 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003076#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303077 struct wpa_ie_data ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003078#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003079
3080 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07003081 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003082 if (data->assoc_info.req_ies)
3083 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3084 data->assoc_info.req_ies_len);
3085 if (data->assoc_info.resp_ies) {
3086 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3087 data->assoc_info.resp_ies_len);
3088#ifdef CONFIG_TDLS
3089 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3090 data->assoc_info.resp_ies_len);
3091#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003092#ifdef CONFIG_WNM
3093 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3094 data->assoc_info.resp_ies_len);
3095#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003096#ifdef CONFIG_INTERWORKING
3097 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3098 data->assoc_info.resp_ies_len);
3099#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003100 if (wpa_s->hw_capab == CAPAB_VHT &&
3101 get_ie(data->assoc_info.resp_ies,
3102 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3103 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003104
3105 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3106 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003107 }
3108 if (data->assoc_info.beacon_ies)
3109 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3110 data->assoc_info.beacon_ies,
3111 data->assoc_info.beacon_ies_len);
3112 if (data->assoc_info.freq)
3113 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3114 data->assoc_info.freq);
3115
Hai Shalom021b0b52019-04-10 11:17:58 -07003116 wpa_s->connection_set = 0;
3117 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3118 struct ieee802_11_elems req_elems, resp_elems;
3119
3120 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3121 data->assoc_info.req_ies_len,
3122 &req_elems, 0) != ParseFailed &&
3123 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3124 data->assoc_info.resp_ies_len,
3125 &resp_elems, 0) != ParseFailed) {
3126 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003127 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3128 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003129 wpa_s->connection_ht = req_elems.ht_capabilities &&
3130 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003131 /* Do not include subset of VHT on 2.4 GHz vendor
3132 * extension in consideration for reporting VHT
3133 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003134 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003135 resp_elems.vht_capabilities &&
3136 (!data->assoc_info.freq ||
3137 wpas_freq_to_band(data->assoc_info.freq) !=
3138 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003139 wpa_s->connection_he = req_elems.he_capabilities &&
3140 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003141 wpa_s->connection_eht = req_elems.eht_capabilities &&
3142 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003143
3144 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3145 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3146 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3147 max_nss_rx_req : max_nss_rx_resp;
3148 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3149 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3150 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3151 max_nss_tx_req : max_nss_tx_resp;
3152
3153 struct supported_chan_width sta_supported_chan_width =
3154 get_supported_channel_width(&req_elems);
3155 enum chan_width ap_operation_chan_width =
3156 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303157 if (wpa_s->connection_vht || wpa_s->connection_he ||
3158 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003159 wpa_s->connection_channel_bandwidth =
3160 get_sta_operation_chan_width(ap_operation_chan_width,
3161 sta_supported_chan_width);
3162 } else if (wpa_s->connection_ht) {
3163 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3164 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3165 } else {
3166 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3167 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003168 }
3169 }
3170
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003171 p = data->assoc_info.req_ies;
3172 l = data->assoc_info.req_ies_len;
3173
3174 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3175 while (p && l >= 2) {
3176 len = p[1] + 2;
3177 if (len > l) {
3178 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3179 p, l);
3180 break;
3181 }
Hai Shalomc3565922019-10-28 11:58:20 -07003182 if (!found &&
3183 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3184 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3185 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3186 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3187 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003188 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3189 break;
3190 found = 1;
Sunil Ravi036cec52023-03-29 11:35:17 -07003191 wpa_find_assoc_pmkid(wpa_s,
3192 data->assoc_info.authorized);
Hai Shalomc3565922019-10-28 11:58:20 -07003193 }
3194 if (!found_x && p[0] == WLAN_EID_RSNX) {
3195 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3196 break;
3197 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003198 }
3199 l -= len;
3200 p += len;
3201 }
3202 if (!found && data->assoc_info.req_ies)
3203 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003204 if (!found_x && data->assoc_info.req_ies)
3205 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003206
Winnie Chen4138eec2022-11-10 16:32:53 +08003207#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303208 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3209 * to a different security type, update the current supplicant configuration to use the AKM
3210 * and pairwise suites from the assoc IE passed by the driver.
3211 */
3212 if (wpas_driver_bss_selection(wpa_s)) {
3213 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3214 /* Check if firmware has roamed to a different security network */
3215 if(wpa_s->key_mgmt != ie.key_mgmt) {
3216 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3217 ie.key_mgmt);
3218 wpa_s->key_mgmt = ie.key_mgmt;
3219 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3220
3221 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3222 /* Restore PMK as it can get overwritten if the previous
3223 * association was to 802.1X.
3224 */
3225 if ((!(wpa_s->drv_flags &
3226 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3227 (wpa_s->current_ssid) &&
3228 (wpa_s->current_ssid->psk_set)) {
3229 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3230 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3231 "BSSID");
3232 wpa_supplicant_deauthenticate(
3233 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3234 return -1;
3235 }
3236 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3237 PMK_LEN, NULL, bssid);
3238 }
3239 }
3240 }
3241 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3242 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3243 "from Assoc IE", ie.pairwise_cipher);
3244 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3245 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3246 wpa_s->pairwise_cipher);
3247 }
3248 // TODO: Notify the framework about security type change b/230766005
3249 }
3250 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003251#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303252
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003253#ifdef CONFIG_FILS
3254#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003255 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3256 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003257 (!data->assoc_info.resp_frame ||
3258 fils_process_assoc_resp(wpa_s->wpa,
3259 data->assoc_info.resp_frame,
3260 data->assoc_info.resp_frame_len) < 0)) {
3261 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3262 return -1;
3263 }
3264#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003265
3266 /* Additional processing for FILS when SME is in driver */
3267 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3268 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3269 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003270#endif /* CONFIG_FILS */
3271
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003272#ifdef CONFIG_OWE
3273 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003274 (!bssid_known ||
Sunil Ravi036cec52023-03-29 11:35:17 -07003275 owe_process_assoc_resp(wpa_s->wpa,
3276 wpa_s->valid_links ?
3277 wpa_s->ap_mld_addr : bssid,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003278 data->assoc_info.resp_ies,
3279 data->assoc_info.resp_ies_len) < 0)) {
3280 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3281 return -1;
3282 }
3283#endif /* CONFIG_OWE */
3284
Hai Shalom021b0b52019-04-10 11:17:58 -07003285#ifdef CONFIG_DPP2
3286 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003287 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3288 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003289 struct ieee802_11_elems elems;
3290
3291 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3292 data->assoc_info.resp_ies_len,
3293 &elems, 0) == ParseFailed ||
3294 !elems.owe_dh)
3295 goto no_pfs;
3296 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3297 elems.owe_dh_len) < 0) {
3298 wpa_supplicant_deauthenticate(wpa_s,
3299 WLAN_REASON_UNSPECIFIED);
3300 return -1;
3301 }
3302
3303 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3304 }
3305no_pfs:
3306#endif /* CONFIG_DPP2 */
3307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003308#ifdef CONFIG_IEEE80211R
3309#ifdef CONFIG_SME
3310 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003311 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003312 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3313 data->assoc_info.resp_ies,
3314 data->assoc_info.resp_ies_len,
3315 bssid) < 0) {
3316 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3317 "Reassociation Response failed");
3318 wpa_supplicant_deauthenticate(
3319 wpa_s, WLAN_REASON_INVALID_IE);
3320 return -1;
3321 }
3322 }
3323
3324 p = data->assoc_info.resp_ies;
3325 l = data->assoc_info.resp_ies_len;
3326
3327#ifdef CONFIG_WPS_STRICT
3328 if (p && wpa_s->current_ssid &&
3329 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3330 struct wpabuf *wps;
3331 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3332 if (wps == NULL) {
3333 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3334 "include WPS IE in (Re)Association Response");
3335 return -1;
3336 }
3337
3338 if (wps_validate_assoc_resp(wps) < 0) {
3339 wpabuf_free(wps);
3340 wpa_supplicant_deauthenticate(
3341 wpa_s, WLAN_REASON_INVALID_IE);
3342 return -1;
3343 }
3344 wpabuf_free(wps);
3345 }
3346#endif /* CONFIG_WPS_STRICT */
3347
3348 /* Go through the IEs and make a copy of the MDIE, if present. */
3349 while (p && l >= 2) {
3350 len = p[1] + 2;
3351 if (len > l) {
3352 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3353 p, l);
3354 break;
3355 }
3356 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3357 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3358 wpa_s->sme.ft_used = 1;
3359 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3360 MOBILITY_DOMAIN_ID_LEN);
3361 break;
3362 }
3363 l -= len;
3364 p += len;
3365 }
3366#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003367#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303368 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3369 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3370 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3371 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303372 wpa_ft_is_completed(wpa_s->wpa)) {
3373 return 0;
3374 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003375#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003376
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003377 /* Process FT when SME is in the driver */
3378 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3379 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003380 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003381 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3382 data->assoc_info.resp_ies,
3383 data->assoc_info.resp_ies_len,
3384 bssid) < 0) {
3385 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3386 "Reassociation Response failed");
3387 wpa_supplicant_deauthenticate(
3388 wpa_s, WLAN_REASON_INVALID_IE);
3389 return -1;
3390 }
3391 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3392 }
3393
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003394 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3395 data->assoc_info.resp_ies_len);
3396#endif /* CONFIG_IEEE80211R */
3397
Hai Shalom899fcc72020-10-19 14:38:18 -07003398 if (bssid_known)
3399 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3400 data->assoc_info.resp_ies,
3401 data->assoc_info.resp_ies_len);
3402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003403 /* WPA/RSN IE from Beacon/ProbeResp */
3404 p = data->assoc_info.beacon_ies;
3405 l = data->assoc_info.beacon_ies_len;
3406
3407 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3408 */
3409 wpa_found = rsn_found = 0;
3410 while (p && l >= 2) {
3411 len = p[1] + 2;
3412 if (len > l) {
3413 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3414 p, l);
3415 break;
3416 }
3417 if (!wpa_found &&
3418 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3419 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3420 wpa_found = 1;
3421 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3422 }
3423
3424 if (!rsn_found &&
3425 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3426 rsn_found = 1;
3427 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3428 }
3429
Hai Shalomc3565922019-10-28 11:58:20 -07003430 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3431 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3432
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003433 l -= len;
3434 p += len;
3435 }
3436
3437 if (!wpa_found && data->assoc_info.beacon_ies)
3438 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003439 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003440 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003441 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3442 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003443 if (wpa_found || rsn_found)
3444 wpa_s->ap_ies_from_associnfo = 1;
3445
Jouni Malinen87fd2792011-05-16 18:35:42 +03003446 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3447 wpa_s->assoc_freq != data->assoc_info.freq) {
3448 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3449 "%u to %u MHz",
3450 wpa_s->assoc_freq, data->assoc_info.freq);
3451 wpa_supplicant_update_scan_results(wpa_s);
3452 }
3453
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003454 wpa_s->assoc_freq = data->assoc_info.freq;
3455
Hai Shalomc1a21442022-02-04 13:43:00 -08003456 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3457 data->assoc_info.resp_ies_len);
3458
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003459 return 0;
3460}
3461
3462
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003463static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3464{
Hai Shalomc3565922019-10-28 11:58:20 -07003465 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003466
3467 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3468 return -1;
3469
3470 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3471 return 0;
3472
3473 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3474 WPA_IE_VENDOR_TYPE);
3475 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003476 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003477
3478 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3479 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3480 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003481 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3482 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3483 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003484 return -1;
3485
3486 return 0;
3487}
3488
3489
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003490static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3491 union wpa_event_data *data)
3492{
3493#ifdef CONFIG_FST
3494 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3495 struct wpa_bss *bss = wpa_s->current_bss;
3496 const u8 *ieprb, *iebcn;
3497
3498 wpabuf_free(wpa_s->received_mb_ies);
3499 wpa_s->received_mb_ies = NULL;
3500
3501 if (ai &&
3502 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3503 wpa_printf(MSG_DEBUG,
3504 "FST: MB IEs updated from Association Response frame");
3505 return;
3506 }
3507
3508 if (ai &&
3509 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3510 wpa_printf(MSG_DEBUG,
3511 "FST: MB IEs updated from association event Beacon IEs");
3512 return;
3513 }
3514
3515 if (!bss)
3516 return;
3517
Hai Shalom60840252021-02-19 19:02:11 -08003518 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003519 iebcn = ieprb + bss->ie_len;
3520
3521 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3522 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3523 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3524 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3525#endif /* CONFIG_FST */
3526}
3527
3528
Sunil Ravi89eba102022-09-13 21:04:37 -07003529static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3530{
3531 struct driver_sta_mlo_info mlo;
3532 int i;
3533
Sunil Ravi77d572f2023-01-17 23:58:31 +00003534 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07003535 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3536 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3537 wpa_supplicant_deauthenticate(wpa_s,
3538 WLAN_REASON_DEAUTH_LEAVING);
3539 return -1;
3540 }
3541
3542 if (wpa_s->valid_links == mlo.valid_links) {
3543 bool match = true;
3544
3545 if (!mlo.valid_links)
3546 return 0;
3547
3548 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3549 if (!(mlo.valid_links & BIT(i)))
3550 continue;
3551
3552 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3553 ETH_ALEN) != 0 ||
3554 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3555 ETH_ALEN) != 0) {
3556 match = false;
3557 break;
3558 }
3559 }
3560
Sunil Ravi77d572f2023-01-17 23:58:31 +00003561 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravi89eba102022-09-13 21:04:37 -07003562 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3563 ETH_ALEN) == 0)
3564 return 0;
3565 }
3566
3567 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00003568 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07003569 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3570 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3571 if (!(wpa_s->valid_links & BIT(i)))
3572 continue;
3573
3574 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3575 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3576 wpa_s->links[i].freq = mlo.links[i].freq;
3577 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3578 }
3579
3580 return 0;
3581}
3582
3583
Sunil Ravi77d572f2023-01-17 23:58:31 +00003584static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
3585{
3586 struct driver_sta_mlo_info drv_mlo;
3587 struct wpa_sm_mlo wpa_mlo;
3588 const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
3589 int i;
3590
3591 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
3592 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
3593 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
3594 return -1;
3595 }
3596
3597 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
3598 if (!drv_mlo.valid_links)
3599 goto out;
3600
3601 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
3602 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
3603 wpa_mlo.valid_links = drv_mlo.valid_links;
3604 wpa_mlo.req_links = drv_mlo.req_links;
3605
3606 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3607 struct wpa_bss *bss;
3608
3609 if (!(drv_mlo.req_links & BIT(i)))
3610 continue;
3611
3612 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
3613 if (!bss) {
3614 wpa_supplicant_update_scan_results(wpa_s);
3615 bss = wpa_supplicant_get_new_bss(
3616 wpa_s, drv_mlo.links[i].bssid);
3617 }
3618
3619 if (!bss) {
3620 wpa_dbg(wpa_s, MSG_INFO,
3621 "Failed to get MLO link %d BSS", i);
3622 return -1;
3623 }
3624
3625 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3626 bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
3627
3628 wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
3629 wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
3630 wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
3631 wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
3632
3633 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
3634 ETH_ALEN);
3635 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
3636 ETH_ALEN);
3637 }
3638
3639out:
3640 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
3641}
3642
3643
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003644static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3645 union wpa_event_data *data)
3646{
3647 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003648 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003649 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003650#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3651 struct wpa_bss *bss;
3652#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003653#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303654 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003655#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003656
3657#ifdef CONFIG_AP
3658 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003659 if (!data)
3660 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003661 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3662 data->assoc_info.addr,
3663 data->assoc_info.req_ies,
3664 data->assoc_info.req_ies_len,
3665 data->assoc_info.reassoc);
3666 return;
3667 }
3668#endif /* CONFIG_AP */
3669
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003670 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003671 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003672
Andy Kuoaba17c12022-04-14 16:05:31 +08003673#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303674 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3675 struct wpa_ft_ies parse;
3676 /* Check for FT reassociation is done by the driver */
3677#ifdef CONFIG_IEEE80211R
3678 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303679 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303680 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3681 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3682 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3683 return;
3684 }
3685 if (parse.rsn_pmkid != NULL) {
3686 wpa_set_ft_completed(wpa_s->wpa);
3687 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3688 }
3689 }
3690#endif /* CONFIG_IEEE80211R */
3691 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003692#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303693
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003694 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003695
3696 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3697 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3698 wpa_supplicant_deauthenticate(
3699 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3700 return;
3701 }
3702
Sunil Ravi89eba102022-09-13 21:04:37 -07003703 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3704 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3705 wpa_supplicant_deauthenticate(wpa_s,
3706 WLAN_REASON_DEAUTH_LEAVING);
3707 return;
3708 }
3709
Sunil Ravia04bd252022-05-02 22:54:18 -07003710 if (ft_completed &&
3711 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3712 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3713 MAC2STR(bssid));
3714 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3715 wpa_printf(MSG_ERROR,
3716 "Can't find target AP's information!");
3717 return;
3718 }
3719 wpa_supplicant_assoc_update_ie(wpa_s);
3720 }
3721
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003722 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3723 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003724 /*
3725 * FILS authentication can share the same mechanism to mark the
3726 * connection fully authenticated, so set ft_completed also based on
3727 * FILS result.
3728 */
3729 if (!ft_completed)
3730 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003731
Andy Kuoaba17c12022-04-14 16:05:31 +08003732#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303733 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3734 /*
3735 * For driver based roaming, insert PSK during
3736 * the initial association
3737 */
3738 if (is_zero_ether_addr(wpa_s->bssid) &&
3739 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3740 /*
3741 * In case the driver wants to handle re-assocs,
3742 * pass it down the PMK.
3743 */
3744 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3745 wpa_sm_install_pmk(wpa_s->wpa);
3746 }
Mir Ali677e7482020-11-12 19:49:02 +05303747 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303748#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003749
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003750 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003751 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003752 if (os_reltime_initialized(&wpa_s->session_start)) {
3753 os_reltime_age(&wpa_s->session_start,
3754 &wpa_s->session_length);
3755 wpa_s->session_start.sec = 0;
3756 wpa_s->session_start.usec = 0;
3757 wpas_notify_session_length(wpa_s);
3758 } else {
3759 wpas_notify_auth_changed(wpa_s);
3760 os_get_reltime(&wpa_s->session_start);
3761 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003762 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3763 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003764 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003765 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003766 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3767 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003768 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003769
3770 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3771 wpa_clear_keys(wpa_s, bssid);
3772 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00003773 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003774 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003775 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3776 return;
3777 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003778 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003779
Hai Shalomc1a21442022-02-04 13:43:00 -08003780 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3781 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3782 return;
3783
Hai Shalomfdcde762020-04-02 11:19:20 -07003784 multi_ap_set_4addr_mode(wpa_s);
3785
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003786 if (wpa_s->conf->ap_scan == 1 &&
3787 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003788 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3789 wpa_msg(wpa_s, MSG_WARNING,
3790 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003791 }
3792
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003793 wpas_fst_update_mb_assoc(wpa_s, data);
3794
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003795#ifdef CONFIG_SME
3796 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3797 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003798 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003799#endif /* CONFIG_SME */
3800
3801 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3802 if (wpa_s->current_ssid) {
3803 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3804 * initialized before association, but for other modes,
3805 * initialize PC/SC here, if the current configuration needs
3806 * smartcard or SIM/USIM. */
3807 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3808 }
3809 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00003810
3811 if (wpa_sm_set_ml_info(wpa_s)) {
3812 wpa_dbg(wpa_s, MSG_INFO,
3813 "Failed to set MLO connection info to wpa_sm");
3814 wpa_supplicant_deauthenticate(wpa_s,
3815 WLAN_REASON_DEAUTH_LEAVING);
3816 return;
3817 }
3818
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003819 if (wpa_s->l2)
3820 l2_packet_notify_auth_start(wpa_s->l2);
3821
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003822 already_authorized = data && data->assoc_info.authorized;
3823
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003824 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003825 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003826 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3827 * state machine may transit to AUTHENTICATING state based on obsolete
3828 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3829 * AUTHENTICATED without ever giving chance to EAP state machine to
3830 * reset the state.
3831 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003832 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003833 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3834 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003835 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003836 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3837 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3838 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003839 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003840 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003841 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003842 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003843 wpa_s->eapol_received = 0;
3844 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3845 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3846 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003847 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003848 if (wpa_s->current_ssid &&
3849 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003850 (wpa_s->drv_flags &
3851 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3852 /*
3853 * Set the key after having received joined-IBSS event
3854 * from the driver.
3855 */
3856 wpa_supplicant_set_wpa_none_key(wpa_s,
3857 wpa_s->current_ssid);
3858 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003859 wpa_supplicant_cancel_auth_timeout(wpa_s);
3860 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3861 } else if (!ft_completed) {
3862 /* Timeout for receiving the first EAPOL packet */
3863 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3864 }
3865 wpa_supplicant_cancel_scan(wpa_s);
3866
Hai Shalom5f92bc92019-04-18 11:54:11 -07003867 if (ft_completed) {
3868 /*
3869 * FT protocol completed - make sure EAPOL state machine ends
3870 * up in authenticated.
3871 */
3872 wpa_supplicant_cancel_auth_timeout(wpa_s);
3873 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003874 eapol_sm_notify_portValid(wpa_s->eapol, true);
3875 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003876 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3877 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303878 if (already_authorized) {
3879 /*
3880 * We are done; the driver will take care of RSN 4-way
3881 * handshake.
3882 */
3883 wpa_supplicant_cancel_auth_timeout(wpa_s);
3884 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3885 eapol_sm_notify_portValid(wpa_s->eapol, true);
3886 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3887 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00003888 /* Update port, WPA_COMPLETED state from the
3889 * EVENT_PORT_AUTHORIZED handler when the driver is done
3890 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303891 */
Sunil Ravi167279a2023-05-31 01:12:34 +00003892 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
Sunil Ravi77d572f2023-01-17 23:58:31 +00003893 wpa_msg(wpa_s, MSG_INFO,
3894 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303895 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003896 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003897 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3898 /*
3899 * The driver will take care of RSN 4-way handshake, so we need
3900 * to allow EAPOL supplicant to complete its work without
3901 * waiting for WPA supplicant.
3902 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003903 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003904 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003905#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303906 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3907 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3908 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3909 wpa_s->key_mgmt);
3910 wpa_supplicant_deauthenticate(
3911 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3912 return;
3913 }
3914 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3915 wpa_s->assoc_freq = data->assoc_info.freq;
3916 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3917 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003918#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3919
Jouni Malinena05074c2012-12-21 21:35:35 +02003920 wpa_s->last_eapol_matches_bssid = 0;
3921
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003922#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003923 if (wpa_s->rsne_override_eapol) {
3924 wpa_printf(MSG_DEBUG,
3925 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3926 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3927 wpabuf_head(wpa_s->rsne_override_eapol),
3928 wpabuf_len(wpa_s->rsne_override_eapol));
3929 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003930 if (wpa_s->rsnxe_override_eapol) {
3931 wpa_printf(MSG_DEBUG,
3932 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3933 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3934 wpabuf_head(wpa_s->rsnxe_override_eapol),
3935 wpabuf_len(wpa_s->rsnxe_override_eapol));
3936 }
3937#endif /* CONFIG_TESTING_OPTIONS */
3938
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003939 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003940 struct os_reltime now, age;
3941 os_get_reltime(&now);
3942 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003943 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003944 os_memcmp(wpa_s->pending_eapol_rx_src,
3945 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid,
3946 ETH_ALEN) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003947 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3948 "frame that was received just before "
3949 "association notification");
3950 wpa_supplicant_rx_eapol(
3951 wpa_s, wpa_s->pending_eapol_rx_src,
3952 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00003953 wpabuf_len(wpa_s->pending_eapol_rx),
3954 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003955 }
3956 wpabuf_free(wpa_s->pending_eapol_rx);
3957 wpa_s->pending_eapol_rx = NULL;
3958 }
3959
Hai Shalomfdcde762020-04-02 11:19:20 -07003960#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003961 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3962 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003963 wpa_s->current_ssid &&
3964 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003965 /* Set static WEP keys again */
3966 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3967 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003968#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003969
3970#ifdef CONFIG_IBSS_RSN
3971 if (wpa_s->current_ssid &&
3972 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3973 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3974 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3975 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003976 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003977 if (!wpa_s->ibss_rsn) {
3978 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3979 wpa_supplicant_deauthenticate(
3980 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3981 return;
3982 }
3983
3984 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3985 }
3986#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003987
3988 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003989
3990 if (data) {
3991 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3992 data->assoc_info.resp_ies_len,
3993 &data->assoc_info.wmm_params);
3994
3995 if (wpa_s->reassoc_same_bss)
3996 wmm_ac_restore_tspecs(wpa_s);
3997 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003998
Hai Shalomc3565922019-10-28 11:58:20 -07003999#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4000 bss = wpa_bss_get_bssid(wpa_s, bssid);
4001#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004002#ifdef CONFIG_FILS
4003 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004004 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4005
4006 if (fils_cache_id)
4007 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4008 }
4009#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07004010
4011#ifdef CONFIG_MBO
4012 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4013#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07004014
4015#ifdef CONFIG_DPP2
4016 wpa_s->dpp_pfs_fallback = 0;
4017#endif /* CONFIG_DPP2 */
Sunil Ravi036cec52023-03-29 11:35:17 -07004018
4019 if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4020 wpa_supplicant_set_4addr_mode(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004021}
4022
4023
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004024static int disconnect_reason_recoverable(u16 reason_code)
4025{
4026 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4027 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4028 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4029}
4030
4031
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004032static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004033 u16 reason_code,
4034 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004035{
4036 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03004037
4038 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4039 /*
4040 * At least Host AP driver and a Prism3 card seemed to be
4041 * generating streams of disconnected events when configuring
4042 * IBSS for WPA-None. Ignore them for now.
4043 */
4044 return;
4045 }
4046
4047 bssid = wpa_s->bssid;
4048 if (is_zero_ether_addr(bssid))
4049 bssid = wpa_s->pending_bssid;
4050
4051 if (!is_zero_ether_addr(bssid) ||
4052 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4053 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4054 " reason=%d%s",
4055 MAC2STR(bssid), reason_code,
4056 locally_generated ? " locally_generated=1" : "");
4057 }
4058}
4059
4060
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004061static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4062 int locally_generated)
4063{
4064 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004065 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004066 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4067 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004068 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004069
4070 /*
4071 * It looks like connection was lost while trying to go through PSK
4072 * 4-way handshake. Filter out known disconnection cases that are caused
4073 * by something else than PSK mismatch to avoid confusing reports.
4074 */
4075
4076 if (locally_generated) {
4077 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4078 return 0;
4079 }
4080
4081 return 1;
4082}
4083
4084
Jouni Malinen2b89da82012-08-31 22:04:41 +03004085static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4086 u16 reason_code,
4087 int locally_generated)
4088{
4089 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004090 int authenticating;
4091 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004092 struct wpa_bss *fast_reconnect = NULL;
4093 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004094 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004095 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004096
4097 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
4098 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
4099
4100 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4101 /*
4102 * At least Host AP driver and a Prism3 card seemed to be
4103 * generating streams of disconnected events when configuring
4104 * IBSS for WPA-None. Ignore them for now.
4105 */
4106 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4107 "IBSS/WPA-None mode");
4108 return;
4109 }
4110
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004111 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4112 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4113 locally_generated)
4114 /*
4115 * Remove the inactive AP (which is probably out of range) from
4116 * the BSS list after marking disassociation. In particular
4117 * mac80211-based drivers use the
4118 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4119 * locally generated disconnection events for cases where the
4120 * AP does not reply anymore.
4121 */
4122 curr = wpa_s->current_bss;
4123
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004124 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004125 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4126 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004127 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4128 return; /* P2P group removed */
Sunil Ravi77d572f2023-01-17 23:58:31 +00004129 wpas_auth_failed(wpa_s, "WRONG_KEY", prev_pending_bssid);
Sunil Ravi036cec52023-03-29 11:35:17 -07004130 wpas_notify_psk_mismatch(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004131#ifdef CONFIG_DPP2
4132 wpas_dpp_send_conn_status_result(wpa_s,
4133 DPP_STATUS_AUTH_FAILURE);
4134#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004135 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004136 if (!wpa_s->disconnected &&
4137 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004138 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004139 wpas_wps_searching(wpa_s) ||
4140 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004141 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004142 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004143 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004144 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004145 wpa_s->wpa_state);
4146 if (wpa_s->wpa_state == WPA_COMPLETED &&
4147 wpa_s->current_ssid &&
4148 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004149 (wpa_s->own_reconnect_req ||
4150 (!locally_generated &&
4151 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004152 /*
4153 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004154 * us, but could allow us to get back in. This is also
4155 * triggered for cases where local reconnection request
4156 * is used to force reassociation with the same BSS.
4157 * Try to reconnect to the same BSS without a full scan
4158 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004159 */
4160 fast_reconnect = wpa_s->current_bss;
4161 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004162 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004163 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004164 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004165 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4166 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004167 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004168 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004169 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004170 "try to re-connect");
4171 wpa_s->reassociate = 0;
4172 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004173 if (!wpa_s->pno)
4174 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004175 }
4176 bssid = wpa_s->bssid;
4177 if (is_zero_ether_addr(bssid))
4178 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004179 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4180 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004181 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004182 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4183
Dmitry Shmidt04949592012-07-19 12:16:46 -07004184 if (locally_generated)
4185 wpa_s->disconnect_reason = -reason_code;
4186 else
4187 wpa_s->disconnect_reason = reason_code;
4188 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004189 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4190 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004191 wpa_clear_keys(wpa_s, wpa_s->bssid);
4192 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004193 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004194 wpa_supplicant_mark_disassoc(wpa_s);
4195
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004196 if (curr)
4197 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4198
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004199 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004200 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004201 wpa_s->current_ssid = last_ssid;
4202 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004203
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004204 if (fast_reconnect &&
4205 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4206 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4207 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4208 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004209 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004210 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004211#ifndef CONFIG_NO_SCAN_PROCESSING
4212 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4213 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4214 fast_reconnect_ssid) < 0) {
4215 /* Recover through full scan */
4216 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4217 }
4218#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004219 } else if (fast_reconnect) {
4220 /*
4221 * Could not reconnect to the same BSS due to network being
4222 * disabled. Use a new scan to match the alternative behavior
4223 * above, i.e., to continue automatic reconnection attempt in a
4224 * way that enforces disabled network rules.
4225 */
4226 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004227 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004228}
4229
4230
4231#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004232void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004233{
4234 struct wpa_supplicant *wpa_s = eloop_ctx;
4235
4236 if (!wpa_s->pending_mic_error_report)
4237 return;
4238
4239 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4240 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4241 wpa_s->pending_mic_error_report = 0;
4242}
4243#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4244
4245
4246static void
4247wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4248 union wpa_event_data *data)
4249{
4250 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004251 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252
4253 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4254 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004255 os_get_reltime(&t);
4256 if ((wpa_s->last_michael_mic_error.sec &&
4257 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004258 wpa_s->pending_mic_error_report) {
4259 if (wpa_s->pending_mic_error_report) {
4260 /*
4261 * Send the pending MIC error report immediately since
4262 * we are going to start countermeasures and AP better
4263 * do the same.
4264 */
4265 wpa_sm_key_request(wpa_s->wpa, 1,
4266 wpa_s->pending_mic_error_pairwise);
4267 }
4268
4269 /* Send the new MIC error report immediately since we are going
4270 * to start countermeasures and AP better do the same.
4271 */
4272 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4273
4274 /* initialize countermeasures */
4275 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004276
Hai Shalom60840252021-02-19 19:02:11 -08004277 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004278
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004279 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4280
4281 /*
4282 * Need to wait for completion of request frame. We do not get
4283 * any callback for the message completion, so just wait a
4284 * short while and hope for the best. */
4285 os_sleep(0, 10000);
4286
4287 wpa_drv_set_countermeasures(wpa_s, 1);
4288 wpa_supplicant_deauthenticate(wpa_s,
4289 WLAN_REASON_MICHAEL_MIC_FAILURE);
4290 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4291 wpa_s, NULL);
4292 eloop_register_timeout(60, 0,
4293 wpa_supplicant_stop_countermeasures,
4294 wpa_s, NULL);
4295 /* TODO: mark the AP rejected for 60 second. STA is
4296 * allowed to associate with another AP.. */
4297 } else {
4298#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4299 if (wpa_s->mic_errors_seen) {
4300 /*
4301 * Reduce the effectiveness of Michael MIC error
4302 * reports as a means for attacking against TKIP if
4303 * more than one MIC failure is noticed with the same
4304 * PTK. We delay the transmission of the reports by a
4305 * random time between 0 and 60 seconds in order to
4306 * force the attacker wait 60 seconds before getting
4307 * the information on whether a frame resulted in a MIC
4308 * failure.
4309 */
4310 u8 rval[4];
4311 int sec;
4312
4313 if (os_get_random(rval, sizeof(rval)) < 0)
4314 sec = os_random() % 60;
4315 else
4316 sec = WPA_GET_BE32(rval) % 60;
4317 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4318 "report %d seconds", sec);
4319 wpa_s->pending_mic_error_report = 1;
4320 wpa_s->pending_mic_error_pairwise = pairwise;
4321 eloop_cancel_timeout(
4322 wpa_supplicant_delayed_mic_error_report,
4323 wpa_s, NULL);
4324 eloop_register_timeout(
4325 sec, os_random() % 1000000,
4326 wpa_supplicant_delayed_mic_error_report,
4327 wpa_s, NULL);
4328 } else {
4329 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4330 }
4331#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4332 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4333#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4334 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004335 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004336 wpa_s->mic_errors_seen++;
4337}
4338
4339
4340#ifdef CONFIG_TERMINATE_ONLASTIF
4341static int any_interfaces(struct wpa_supplicant *head)
4342{
4343 struct wpa_supplicant *wpa_s;
4344
4345 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4346 if (!wpa_s->interface_removed)
4347 return 1;
4348 return 0;
4349}
4350#endif /* CONFIG_TERMINATE_ONLASTIF */
4351
4352
4353static void
4354wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4355 union wpa_event_data *data)
4356{
4357 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4358 return;
4359
4360 switch (data->interface_status.ievent) {
4361 case EVENT_INTERFACE_ADDED:
4362 if (!wpa_s->interface_removed)
4363 break;
4364 wpa_s->interface_removed = 0;
4365 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4366 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4367 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4368 "driver after interface was added");
4369 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004370
4371#ifdef CONFIG_P2P
4372 if (!wpa_s->global->p2p &&
4373 !wpa_s->global->p2p_disabled &&
4374 !wpa_s->conf->p2p_disabled &&
4375 (wpa_s->drv_flags &
4376 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4377 wpas_p2p_add_p2pdev_interface(
4378 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4379 wpa_printf(MSG_INFO,
4380 "P2P: Failed to enable P2P Device interface");
4381 /* Try to continue without. P2P will be disabled. */
4382 }
4383#endif /* CONFIG_P2P */
4384
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004385 break;
4386 case EVENT_INTERFACE_REMOVED:
4387 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4388 wpa_s->interface_removed = 1;
4389 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004390 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004391 l2_packet_deinit(wpa_s->l2);
4392 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004393
4394#ifdef CONFIG_P2P
4395 if (wpa_s->global->p2p &&
4396 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4397 (wpa_s->drv_flags &
4398 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4399 wpa_dbg(wpa_s, MSG_DEBUG,
4400 "Removing P2P Device interface");
4401 wpa_supplicant_remove_iface(
4402 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4403 0);
4404 wpa_s->global->p2p_init_wpa_s = NULL;
4405 }
4406#endif /* CONFIG_P2P */
4407
Dmitry Shmidte4663042016-04-04 10:07:49 -07004408#ifdef CONFIG_MATCH_IFACE
4409 if (wpa_s->matched) {
4410 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4411 break;
4412 }
4413#endif /* CONFIG_MATCH_IFACE */
4414
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004415#ifdef CONFIG_TERMINATE_ONLASTIF
4416 /* check if last interface */
4417 if (!any_interfaces(wpa_s->global->ifaces))
4418 eloop_terminate();
4419#endif /* CONFIG_TERMINATE_ONLASTIF */
4420 break;
4421 }
4422}
4423
4424
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004425#ifdef CONFIG_TDLS
4426static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4427 union wpa_event_data *data)
4428{
4429 if (data == NULL)
4430 return;
4431 switch (data->tdls.oper) {
4432 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004433 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4434 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4435 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4436 else
4437 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004438 break;
4439 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004440 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4441 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4442 data->tdls.reason_code);
4443 else
4444 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4445 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004446 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004447 case TDLS_REQUEST_DISCOVER:
4448 wpa_tdls_send_discovery_request(wpa_s->wpa,
4449 data->tdls.peer);
4450 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004451 }
4452}
4453#endif /* CONFIG_TDLS */
4454
4455
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004456#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004457static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4458 union wpa_event_data *data)
4459{
4460 if (data == NULL)
4461 return;
4462 switch (data->wnm.oper) {
4463 case WNM_OPER_SLEEP:
4464 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4465 "(action=%d, intval=%d)",
4466 data->wnm.sleep_action, data->wnm.sleep_intval);
4467 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004468 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004469 break;
4470 }
4471}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004472#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004473
4474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004475#ifdef CONFIG_IEEE80211R
4476static void
4477wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4478 union wpa_event_data *data)
4479{
4480 if (data == NULL)
4481 return;
4482
4483 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4484 data->ft_ies.ies_len,
4485 data->ft_ies.ft_action,
4486 data->ft_ies.target_ap,
4487 data->ft_ies.ric_ies,
4488 data->ft_ies.ric_ies_len) < 0) {
4489 /* TODO: prevent MLME/driver from trying to associate? */
4490 }
4491}
4492#endif /* CONFIG_IEEE80211R */
4493
4494
4495#ifdef CONFIG_IBSS_RSN
4496static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4497 union wpa_event_data *data)
4498{
4499 struct wpa_ssid *ssid;
4500 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4501 return;
4502 if (data == NULL)
4503 return;
4504 ssid = wpa_s->current_ssid;
4505 if (ssid == NULL)
4506 return;
4507 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4508 return;
4509
4510 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4511}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004512
4513
4514static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4515 union wpa_event_data *data)
4516{
4517 struct wpa_ssid *ssid = wpa_s->current_ssid;
4518
4519 if (ssid == NULL)
4520 return;
4521
4522 /* check if the ssid is correctly configured as IBSS/RSN */
4523 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4524 return;
4525
4526 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4527 data->rx_mgmt.frame_len);
4528}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004529#endif /* CONFIG_IBSS_RSN */
4530
4531
4532#ifdef CONFIG_IEEE80211R
4533static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4534 size_t len)
4535{
4536 const u8 *sta_addr, *target_ap_addr;
4537 u16 status;
4538
4539 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4540 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4541 return; /* only SME case supported for now */
4542 if (len < 1 + 2 * ETH_ALEN + 2)
4543 return;
4544 if (data[0] != 2)
4545 return; /* Only FT Action Response is supported for now */
4546 sta_addr = data + 1;
4547 target_ap_addr = data + 1 + ETH_ALEN;
4548 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4549 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4550 MACSTR " TargetAP " MACSTR " status %u",
4551 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4552
4553 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4554 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4555 " in FT Action Response", MAC2STR(sta_addr));
4556 return;
4557 }
4558
4559 if (status) {
4560 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4561 "failure (status code %d)", status);
4562 /* TODO: report error to FT code(?) */
4563 return;
4564 }
4565
4566 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4567 len - (1 + 2 * ETH_ALEN + 2), 1,
4568 target_ap_addr, NULL, 0) < 0)
4569 return;
4570
4571#ifdef CONFIG_SME
4572 {
4573 struct wpa_bss *bss;
4574 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4575 if (bss)
4576 wpa_s->sme.freq = bss->freq;
4577 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4578 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4579 WLAN_AUTH_FT);
4580 }
4581#endif /* CONFIG_SME */
4582}
4583#endif /* CONFIG_IEEE80211R */
4584
4585
4586static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4587 struct unprot_deauth *e)
4588{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004589 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4590 "dropped: " MACSTR " -> " MACSTR
4591 " (reason code %u)",
4592 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4593 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004594}
4595
4596
4597static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4598 struct unprot_disassoc *e)
4599{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004600 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4601 "dropped: " MACSTR " -> " MACSTR
4602 " (reason code %u)",
4603 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4604 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004605}
4606
4607
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004608static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4609 u16 reason_code, int locally_generated,
4610 const u8 *ie, size_t ie_len, int deauth)
4611{
4612#ifdef CONFIG_AP
4613 if (wpa_s->ap_iface && addr) {
4614 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4615 return;
4616 }
4617
4618 if (wpa_s->ap_iface) {
4619 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4620 return;
4621 }
4622#endif /* CONFIG_AP */
4623
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004624 if (!locally_generated)
4625 wpa_s->own_disconnect_req = 0;
4626
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004627 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4628
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004629 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4630 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4631 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4632 eapol_sm_failed(wpa_s->eapol))) &&
4633 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00004634 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004635
4636#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004637 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004638 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4639 locally_generated) > 0) {
4640 /*
4641 * The interface was removed, so cannot continue
4642 * processing any additional operations after this.
4643 */
4644 return;
4645 }
4646 }
4647#endif /* CONFIG_P2P */
4648
4649 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4650 locally_generated);
4651}
4652
4653
4654static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4655 struct disassoc_info *info)
4656{
4657 u16 reason_code = 0;
4658 int locally_generated = 0;
4659 const u8 *addr = NULL;
4660 const u8 *ie = NULL;
4661 size_t ie_len = 0;
4662
4663 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4664
4665 if (info) {
4666 addr = info->addr;
4667 ie = info->ie;
4668 ie_len = info->ie_len;
4669 reason_code = info->reason_code;
4670 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004671 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4672 reason2str(reason_code),
4673 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004674 if (addr)
4675 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4676 MAC2STR(addr));
4677 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4678 ie, ie_len);
4679 }
4680
4681#ifdef CONFIG_AP
4682 if (wpa_s->ap_iface && info && info->addr) {
4683 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4684 return;
4685 }
4686
4687 if (wpa_s->ap_iface) {
4688 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4689 return;
4690 }
4691#endif /* CONFIG_AP */
4692
4693#ifdef CONFIG_P2P
4694 if (info) {
4695 wpas_p2p_disassoc_notif(
4696 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4697 locally_generated);
4698 }
4699#endif /* CONFIG_P2P */
4700
4701 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4702 sme_event_disassoc(wpa_s, info);
4703
4704 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4705 ie, ie_len, 0);
4706}
4707
4708
4709static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4710 struct deauth_info *info)
4711{
4712 u16 reason_code = 0;
4713 int locally_generated = 0;
4714 const u8 *addr = NULL;
4715 const u8 *ie = NULL;
4716 size_t ie_len = 0;
4717
4718 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4719
4720 if (info) {
4721 addr = info->addr;
4722 ie = info->ie;
4723 ie_len = info->ie_len;
4724 reason_code = info->reason_code;
4725 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004726 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4727 reason_code, reason2str(reason_code),
4728 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004729 if (addr) {
4730 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4731 MAC2STR(addr));
4732 }
4733 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4734 ie, ie_len);
4735 }
4736
4737 wpa_reset_ft_completed(wpa_s->wpa);
4738
4739 wpas_event_disconnect(wpa_s, addr, reason_code,
4740 locally_generated, ie, ie_len, 1);
4741}
4742
4743
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004744static const char * reg_init_str(enum reg_change_initiator init)
4745{
4746 switch (init) {
4747 case REGDOM_SET_BY_CORE:
4748 return "CORE";
4749 case REGDOM_SET_BY_USER:
4750 return "USER";
4751 case REGDOM_SET_BY_DRIVER:
4752 return "DRIVER";
4753 case REGDOM_SET_BY_COUNTRY_IE:
4754 return "COUNTRY_IE";
4755 case REGDOM_BEACON_HINT:
4756 return "BEACON_HINT";
4757 }
4758 return "?";
4759}
4760
4761
4762static const char * reg_type_str(enum reg_type type)
4763{
4764 switch (type) {
4765 case REGDOM_TYPE_UNKNOWN:
4766 return "UNKNOWN";
4767 case REGDOM_TYPE_COUNTRY:
4768 return "COUNTRY";
4769 case REGDOM_TYPE_WORLD:
4770 return "WORLD";
4771 case REGDOM_TYPE_CUSTOM_WORLD:
4772 return "CUSTOM_WORLD";
4773 case REGDOM_TYPE_INTERSECTION:
4774 return "INTERSECTION";
4775 }
4776 return "?";
4777}
4778
4779
Hai Shalom74f70d42019-02-11 14:42:39 -08004780void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4781 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004782{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004783 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004784 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004785
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004786 /*
4787 * To allow backwards compatibility with higher level layers that
4788 * assumed the REGDOM_CHANGE event is sent over the initially added
4789 * interface. Find the highest parent of this interface and use it to
4790 * send the event.
4791 */
4792 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4793 ;
4794
Hai Shalom74f70d42019-02-11 14:42:39 -08004795 if (info) {
4796 wpa_msg(ifs, MSG_INFO,
4797 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4798 reg_init_str(info->initiator), reg_type_str(info->type),
4799 info->alpha2[0] ? " alpha2=" : "",
4800 info->alpha2[0] ? info->alpha2 : "");
4801 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004802
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004803 if (wpa_s->drv_priv == NULL)
4804 return; /* Ignore event during drv initialization */
4805
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004806 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4807 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004808 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4809 ifs->ifname);
4810 free_hw_features(ifs);
4811 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004812 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004813
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004814 /* Restart PNO/sched_scan with updated channel list */
4815 if (ifs->pno) {
4816 wpas_stop_pno(ifs);
4817 wpas_start_pno(ifs);
4818 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4819 wpa_dbg(ifs, MSG_DEBUG,
4820 "Channel list changed - restart sched_scan");
4821 wpas_scan_restart_sched_scan(ifs);
4822 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004823 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004824
4825 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004826}
4827
4828
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004829static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004830 const u8 *frame, size_t len, int freq,
4831 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004832{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004833 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004834 const u8 *payload;
4835 size_t plen;
4836 u8 category;
4837
4838 if (len < IEEE80211_HDRLEN + 2)
4839 return;
4840
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004841 mgmt = (const struct ieee80211_mgmt *) frame;
4842 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004843 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004844 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004845
4846 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4847 " Category=%u DataLen=%d freq=%d MHz",
4848 MAC2STR(mgmt->sa), category, (int) plen, freq);
4849
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004850 if (category == WLAN_ACTION_WMM) {
4851 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4852 return;
4853 }
4854
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004855#ifdef CONFIG_IEEE80211R
4856 if (category == WLAN_ACTION_FT) {
4857 ft_rx_action(wpa_s, payload, plen);
4858 return;
4859 }
4860#endif /* CONFIG_IEEE80211R */
4861
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004862#ifdef CONFIG_SME
4863 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004864 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004865 return;
4866 }
4867#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004868
4869#ifdef CONFIG_WNM
4870 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4871 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4872 return;
4873 }
4874#endif /* CONFIG_WNM */
4875
4876#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004877 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4878 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004879 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004880 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004881 payload, plen, freq) == 0)
4882 return;
4883#endif /* CONFIG_GAS */
4884
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004885#ifdef CONFIG_GAS_SERVER
4886 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4887 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4888 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4889 mgmt->u.action.category,
4890 payload, plen, freq) == 0)
4891 return;
4892#endif /* CONFIG_GAS_SERVER */
4893
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004894#ifdef CONFIG_TDLS
4895 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4896 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4897 wpa_dbg(wpa_s, MSG_DEBUG,
4898 "TDLS: Received Discovery Response from " MACSTR,
4899 MAC2STR(mgmt->sa));
4900 return;
4901 }
4902#endif /* CONFIG_TDLS */
4903
4904#ifdef CONFIG_INTERWORKING
4905 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4906 payload[0] == QOS_QOS_MAP_CONFIG) {
4907 const u8 *pos = payload + 1;
4908 size_t qlen = plen - 1;
4909 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4910 MACSTR, MAC2STR(mgmt->sa));
4911 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4912 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4913 pos[1] <= qlen - 2 && pos[1] >= 16)
4914 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4915 return;
4916 }
4917#endif /* CONFIG_INTERWORKING */
4918
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004919 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004920 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4921 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004922 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004923 payload + 1,
4924 plen - 1);
4925 return;
4926 }
4927
4928 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004929 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4930 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4931 return;
4932 }
4933
4934 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4935 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4936 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4937 payload + 1, plen - 1,
4938 rssi);
4939 return;
4940 }
4941
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004942#ifdef CONFIG_FST
4943 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4944 fst_rx_action(wpa_s->fst, mgmt, len);
4945 return;
4946 }
4947#endif /* CONFIG_FST */
4948
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004949#ifdef CONFIG_DPP
4950 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4951 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4952 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4953 payload[4] == DPP_OUI_TYPE) {
4954 payload++;
4955 plen--;
4956 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4957 return;
4958 }
4959#endif /* CONFIG_DPP */
4960
Hai Shalom899fcc72020-10-19 14:38:18 -07004961 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004962 payload[0] == ROBUST_AV_SCS_RESP) {
4963 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4964 payload + 1, plen - 1);
4965 return;
4966 }
4967
4968 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004969 payload[0] == ROBUST_AV_MSCS_RESP) {
4970 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4971 payload + 1, plen - 1);
4972 return;
4973 }
4974
Hai Shalomc1a21442022-02-04 13:43:00 -08004975 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4976 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4977 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4978 payload + 4, plen - 4);
4979 return;
4980 }
4981
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004982 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4983 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004984 if (wpa_s->ifmsh)
4985 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004986}
4987
4988
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004989static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4990 union wpa_event_data *event)
4991{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004992 struct wpa_freq_range_list *list;
4993 char *str = NULL;
4994
4995 list = &event->freq_range;
4996
4997 if (list->num)
4998 str = freq_range_list_str(list);
4999 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5000 str ? str : "");
5001
5002#ifdef CONFIG_P2P
5003 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5004 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5005 __func__);
5006 } else {
5007 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005008
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005009 /*
5010 * The update channel flow will also take care of moving a GO
5011 * from the unsafe frequency if needed.
5012 */
5013 wpas_p2p_update_channel_list(wpa_s,
5014 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005015 }
5016#endif /* CONFIG_P2P */
5017
5018 os_free(str);
5019}
5020
5021
Roshan Pius3a1667e2018-07-03 15:17:14 -07005022static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005023{
Sunil Ravi167279a2023-05-31 01:12:34 +00005024 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005025 wpa_supplicant_cancel_auth_timeout(wpa_s);
5026 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07005027 eapol_sm_notify_portValid(wpa_s->eapol, true);
5028 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07005029 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005030 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005031}
5032
5033
5034static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5035 int freq)
5036{
5037 size_t i;
5038 int j;
5039
5040 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5041 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5042
5043 for (j = 0; j < mode->num_channels; j++) {
5044 const struct hostapd_channel_data *chan;
5045
5046 chan = &mode->channels[j];
5047 if (chan->freq == freq)
5048 return chan->dfs_cac_ms;
5049 }
5050 }
5051
5052 return 0;
5053}
5054
5055
5056static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5057 struct dfs_event *radar)
5058{
5059#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005060 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005061 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5062 } else
5063#endif /* NEED_AP_MLME && CONFIG_AP */
5064 {
5065 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5066
5067 cac_time /= 1000; /* convert from ms to sec */
5068 if (!cac_time)
5069 cac_time = 10 * 60; /* max timeout: 10 minutes */
5070
5071 /* Restart auth timeout: CAC time added to initial timeout */
5072 wpas_auth_timeout_restart(wpa_s, cac_time);
5073 }
5074}
5075
5076
5077static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5078 struct dfs_event *radar)
5079{
5080#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005081 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005082 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5083 } else
5084#endif /* NEED_AP_MLME && CONFIG_AP */
5085 {
5086 /* Restart auth timeout with original value after CAC is
5087 * finished */
5088 wpas_auth_timeout_restart(wpa_s, 0);
5089 }
5090}
5091
5092
5093static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5094 struct dfs_event *radar)
5095{
5096#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005097 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005098 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5099 } else
5100#endif /* NEED_AP_MLME && CONFIG_AP */
5101 {
5102 /* Restart auth timeout with original value after CAC is
5103 * aborted */
5104 wpas_auth_timeout_restart(wpa_s, 0);
5105 }
5106}
5107
5108
5109static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5110 union wpa_event_data *data)
5111{
5112 wpa_dbg(wpa_s, MSG_DEBUG,
5113 "Connection authorized by device, previous state %d",
5114 wpa_s->wpa_state);
5115
5116 wpa_supplicant_event_port_authorized(wpa_s);
5117
Hai Shalomc1a21442022-02-04 13:43:00 -08005118 wpa_s->last_eapol_matches_bssid = 1;
5119
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005120 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5121 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005122 data->assoc_info.ptk_kck_len,
5123 data->assoc_info.ptk_kek,
5124 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005125#ifdef CONFIG_FILS
5126 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5127 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5128 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5129
5130 /* Update ERP next sequence number */
5131 eapol_sm_update_erp_next_seq_num(
5132 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5133
5134 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5135 /* Add the new PMK and PMKID to the PMKSA cache */
5136 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5137 data->assoc_info.fils_pmk,
5138 data->assoc_info.fils_pmk_len,
5139 data->assoc_info.fils_pmkid,
Sunil Ravi036cec52023-03-29 11:35:17 -07005140 wpa_s->valid_links ?
5141 wpa_s->ap_mld_addr :
5142 wpa_s->bssid,
5143 fils_cache_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005144 } else if (data->assoc_info.fils_pmkid) {
5145 /* Update the current PMKSA used for this connection */
5146 pmksa_cache_set_current(wpa_s->wpa,
5147 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005148 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005149 }
5150 }
5151#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005152}
5153
5154
Hai Shalom60840252021-02-19 19:02:11 -08005155static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5156{
5157 switch (code) {
5158 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5159 return "";
5160 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5161 return "no_bss_found";
5162 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5163 return "auth_tx_fail";
5164 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5165 return "auth_no_ack_received";
5166 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5167 return "auth_no_resp_received";
5168 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5169 return "assoc_req_tx_fail";
5170 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5171 return "assoc_no_ack_received";
5172 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5173 return "assoc_no_resp_received";
5174 default:
5175 return "unknown_reason";
5176 }
5177}
5178
5179
Roshan Pius3a1667e2018-07-03 15:17:14 -07005180static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5181 union wpa_event_data *data)
5182{
5183 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005184#ifdef CONFIG_MBO
5185 struct wpa_bss *reject_bss;
5186#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005187
5188 if (!bssid || is_zero_ether_addr(bssid))
5189 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005190#ifdef CONFIG_MBO
5191 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5192 reject_bss = wpa_s->current_bss;
5193 else
5194 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5195#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005196
5197 if (data->assoc_reject.bssid)
5198 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005199 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005200 MAC2STR(data->assoc_reject.bssid),
5201 data->assoc_reject.status_code,
5202 data->assoc_reject.timed_out ? " timeout" : "",
5203 data->assoc_reject.timeout_reason ? "=" : "",
5204 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005205 data->assoc_reject.timeout_reason : "",
5206 data->assoc_reject.reason_code !=
5207 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5208 " qca_driver_reason=" : "",
5209 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005210 else
5211 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005212 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005213 data->assoc_reject.status_code,
5214 data->assoc_reject.timed_out ? " timeout" : "",
5215 data->assoc_reject.timeout_reason ? "=" : "",
5216 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005217 data->assoc_reject.timeout_reason : "",
5218 data->assoc_reject.reason_code !=
5219 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5220 " qca_driver_reason=" : "",
5221 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005222 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005223 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5224 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005225
5226#ifdef CONFIG_OWE
5227 if (data->assoc_reject.status_code ==
5228 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5229 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5230 wpa_s->current_ssid &&
5231 wpa_s->current_ssid->owe_group == 0 &&
5232 wpa_s->last_owe_group != 21) {
5233 struct wpa_ssid *ssid = wpa_s->current_ssid;
5234 struct wpa_bss *bss = wpa_s->current_bss;
5235
5236 if (!bss) {
5237 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5238 if (!bss) {
5239 wpas_connection_failed(wpa_s, bssid);
5240 wpa_supplicant_mark_disassoc(wpa_s);
5241 return;
5242 }
5243 }
5244 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5245 wpas_connect_work_done(wpa_s);
5246 wpa_supplicant_mark_disassoc(wpa_s);
5247 wpa_supplicant_connect(wpa_s, bss, ssid);
5248 return;
5249 }
5250#endif /* CONFIG_OWE */
5251
Hai Shalomfdcde762020-04-02 11:19:20 -07005252#ifdef CONFIG_DPP2
5253 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5254 * the status code defined in the DPP R2 tech spec.
5255 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5256 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005257 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005258 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5259 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5260 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005261 wpa_s->current_ssid->dpp_pfs == 0 &&
5262 (data->assoc_reject.status_code ==
5263 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5264 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5265 struct wpa_ssid *ssid = wpa_s->current_ssid;
5266 struct wpa_bss *bss = wpa_s->current_bss;
5267
5268 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5269 if (!bss)
5270 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5271 if (!bss || wpa_s->dpp_pfs_fallback) {
5272 wpa_printf(MSG_DEBUG,
5273 "DPP: Updated PFS policy for next try");
5274 wpas_connection_failed(wpa_s, bssid);
5275 wpa_supplicant_mark_disassoc(wpa_s);
5276 return;
5277 }
5278 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5279 wpa_s->dpp_pfs_fallback = 1;
5280 wpas_connect_work_done(wpa_s);
5281 wpa_supplicant_mark_disassoc(wpa_s);
5282 wpa_supplicant_connect(wpa_s, bss, ssid);
5283 return;
5284 }
5285#endif /* CONFIG_DPP2 */
5286
Hai Shalom74f70d42019-02-11 14:42:39 -08005287#ifdef CONFIG_MBO
5288 if (data->assoc_reject.status_code ==
5289 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005290 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005291 const u8 *rssi_rej;
5292
5293 rssi_rej = mbo_get_attr_from_ies(
5294 data->assoc_reject.resp_ies,
5295 data->assoc_reject.resp_ies_len,
5296 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5297 if (rssi_rej && rssi_rej[1] == 2) {
5298 wpa_printf(MSG_DEBUG,
5299 "OCE: RSSI-based association rejection from "
5300 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005301 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005302 rssi_rej[2], rssi_rej[3]);
5303 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005304 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005305 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005306 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005307 }
5308 }
5309#endif /* CONFIG_MBO */
5310
Roshan Pius3a1667e2018-07-03 15:17:14 -07005311 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5312 sme_event_assoc_reject(wpa_s, data);
5313 return;
5314 }
5315
5316 /* Driver-based SME cases */
5317
5318#ifdef CONFIG_SAE
5319 if (wpa_s->current_ssid &&
5320 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5321 !data->assoc_reject.timed_out) {
5322 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5323 wpa_sm_aborted_cached(wpa_s->wpa);
5324 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5325 }
5326#endif /* CONFIG_SAE */
5327
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005328#ifdef CONFIG_DPP
5329 if (wpa_s->current_ssid &&
5330 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5331 !data->assoc_reject.timed_out) {
5332 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5333 wpa_sm_aborted_cached(wpa_s->wpa);
5334 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5335 }
5336#endif /* CONFIG_DPP */
5337
Roshan Pius3a1667e2018-07-03 15:17:14 -07005338#ifdef CONFIG_FILS
5339 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005340 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005341 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005342 eapol_sm_update_erp_next_seq_num(
5343 wpa_s->eapol,
5344 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005345 fils_connection_failure(wpa_s);
5346 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005347#endif /* CONFIG_FILS */
5348
5349 wpas_connection_failed(wpa_s, bssid);
5350 wpa_supplicant_mark_disassoc(wpa_s);
5351}
5352
5353
Hai Shalomfdcde762020-04-02 11:19:20 -07005354static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5355 struct unprot_beacon *data)
5356{
5357 struct wpabuf *buf;
5358 int res;
5359
5360 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5361 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5362 return;
5363 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5364 MAC2STR(data->sa));
5365
5366 buf = wpabuf_alloc(4);
5367 if (!buf)
5368 return;
5369
5370 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5371 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5372 wpabuf_put_u8(buf, 1); /* Dialog Token */
5373 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5374
5375 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5376 wpa_s->own_addr, wpa_s->bssid,
5377 wpabuf_head(buf), wpabuf_len(buf), 0);
5378 if (res < 0)
5379 wpa_printf(MSG_DEBUG,
5380 "Failed to send WNM-Notification Request frame");
5381
5382 wpabuf_free(buf);
5383}
5384
5385
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005386void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5387 union wpa_event_data *data)
5388{
5389 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005390 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005391 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005392#ifndef CONFIG_NO_STDOUT_DEBUG
5393 int level = MSG_DEBUG;
5394#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005395
5396 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5397 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005398 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005399 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005400 event != EVENT_SCHED_SCAN_STOPPED) {
5401 wpa_dbg(wpa_s, MSG_DEBUG,
5402 "Ignore event %s (%d) while interface is disabled",
5403 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005404 return;
5405 }
5406
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005407#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005408 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005409 const struct ieee80211_hdr *hdr;
5410 u16 fc;
5411 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5412 fc = le_to_host16(hdr->frame_control);
5413 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5414 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5415 level = MSG_EXCESSIVE;
5416 }
5417
5418 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5419 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005420#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005421
5422 switch (event) {
5423 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005424#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005425 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5426 data->auth.ies_len))
5427 wpa_printf(MSG_DEBUG,
5428 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005429#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005430 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005431 wpa_s->auth_status_code = data->auth.status_code;
5432 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005433 break;
5434 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005435#ifdef CONFIG_TESTING_OPTIONS
5436 if (wpa_s->ignore_auth_resp) {
5437 wpa_printf(MSG_INFO,
5438 "EVENT_ASSOC - ignore_auth_resp active!");
5439 break;
5440 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005441 if (wpa_s->testing_resend_assoc) {
5442 wpa_printf(MSG_INFO,
5443 "EVENT_DEAUTH - testing_resend_assoc");
5444 break;
5445 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005446#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305447 if (wpa_s->disconnected) {
5448 wpa_printf(MSG_INFO,
5449 "Ignore unexpected EVENT_ASSOC in disconnected state");
5450 break;
5451 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005452 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005453 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005454 if (data &&
5455 (data->assoc_info.authorized ||
5456 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5457 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005458 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005459 if (data) {
5460 wpa_msg(wpa_s, MSG_INFO,
5461 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5462 data->assoc_info.subnet_status);
5463 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005464 break;
5465 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005466 wpas_event_disassoc(wpa_s,
5467 data ? &data->disassoc_info : NULL);
5468 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005469 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005470#ifdef CONFIG_TESTING_OPTIONS
5471 if (wpa_s->ignore_auth_resp) {
5472 wpa_printf(MSG_INFO,
5473 "EVENT_DEAUTH - ignore_auth_resp active!");
5474 break;
5475 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005476 if (wpa_s->testing_resend_assoc) {
5477 wpa_printf(MSG_INFO,
5478 "EVENT_DEAUTH - testing_resend_assoc");
5479 break;
5480 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005481#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005482 wpas_event_deauth(wpa_s,
5483 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005484 break;
5485 case EVENT_MICHAEL_MIC_FAILURE:
5486 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5487 break;
5488#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005489 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005490 if (wpa_s->own_scan_requested ||
5491 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005492 struct os_reltime diff;
5493
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005494 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005495 os_reltime_sub(&wpa_s->scan_start_time,
5496 &wpa_s->scan_trigger_time, &diff);
5497 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5498 diff.sec, diff.usec);
5499 wpa_s->own_scan_requested = 0;
5500 wpa_s->own_scan_running = 1;
5501 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5502 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005503 wpa_msg_ctrl(wpa_s, MSG_INFO,
5504 WPA_EVENT_SCAN_STARTED "id=%u",
5505 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005506 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005507 wpa_msg_ctrl(wpa_s, MSG_INFO,
5508 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005509 }
5510 } else {
5511 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005512 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005513 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005514 }
5515 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005516 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005517 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5518 wpa_s->scan_res_handler = NULL;
5519 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005520 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005521 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5522 break;
5523 }
5524
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005525 if (!(data && data->scan_info.external_scan) &&
5526 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005527 struct os_reltime now, diff;
5528 os_get_reltime(&now);
5529 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5530 wpa_s->scan_start_time.sec = 0;
5531 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00005532 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005533 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5534 diff.sec, diff.usec);
5535 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005536 if (wpa_supplicant_event_scan_results(wpa_s, data))
5537 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005538 if (!(data && data->scan_info.external_scan))
5539 wpa_s->own_scan_running = 0;
5540 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005541 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005542 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005543 break;
5544#endif /* CONFIG_NO_SCAN_PROCESSING */
5545 case EVENT_ASSOCINFO:
5546 wpa_supplicant_event_associnfo(wpa_s, data);
5547 break;
5548 case EVENT_INTERFACE_STATUS:
5549 wpa_supplicant_event_interface_status(wpa_s, data);
5550 break;
5551 case EVENT_PMKID_CANDIDATE:
5552 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5553 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005554#ifdef CONFIG_TDLS
5555 case EVENT_TDLS:
5556 wpa_supplicant_event_tdls(wpa_s, data);
5557 break;
5558#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005559#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005560 case EVENT_WNM:
5561 wpa_supplicant_event_wnm(wpa_s, data);
5562 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005563#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005564#ifdef CONFIG_IEEE80211R
5565 case EVENT_FT_RESPONSE:
5566 wpa_supplicant_event_ft_response(wpa_s, data);
5567 break;
5568#endif /* CONFIG_IEEE80211R */
5569#ifdef CONFIG_IBSS_RSN
5570 case EVENT_IBSS_RSN_START:
5571 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5572 break;
5573#endif /* CONFIG_IBSS_RSN */
5574 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005575 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005576 break;
5577 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005578 /* It is possible to get this event from earlier connection */
5579 if (wpa_s->current_ssid &&
5580 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5581 wpa_dbg(wpa_s, MSG_DEBUG,
5582 "Ignore AUTH_TIMED_OUT in mesh configuration");
5583 break;
5584 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005585 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5586 sme_event_auth_timed_out(wpa_s, data);
5587 break;
5588 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005589 /* It is possible to get this event from earlier connection */
5590 if (wpa_s->current_ssid &&
5591 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5592 wpa_dbg(wpa_s, MSG_DEBUG,
5593 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5594 break;
5595 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005596 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5597 sme_event_assoc_timed_out(wpa_s, data);
5598 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005599 case EVENT_TX_STATUS:
5600 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5601 " type=%d stype=%d",
5602 MAC2STR(data->tx_status.dst),
5603 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005604#ifdef CONFIG_PASN
5605 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5606 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5607 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5608 data->tx_status.data_len,
5609 data->tx_status.ack) == 0)
5610 break;
5611#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005612#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005613 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005614#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005615 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5616 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005617 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005618 wpa_s, data->tx_status.dst,
5619 data->tx_status.data,
5620 data->tx_status.data_len,
5621 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005622 OFFCHANNEL_SEND_ACTION_SUCCESS :
5623 OFFCHANNEL_SEND_ACTION_NO_ACK);
5624#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005625 break;
5626 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005627#endif /* CONFIG_AP */
5628#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005629 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005630 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005631 /*
5632 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005633 * interface in GO mode, or via standalone AP interface.
5634 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5635 * except when the primary interface is used as a GO interface
5636 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005637 */
5638 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5639 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005640 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005641 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005642 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005643 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005644 data->tx_status.data,
5645 data->tx_status.data_len,
5646 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005647 OFFCHANNEL_SEND_ACTION_SUCCESS :
5648 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005649 break;
5650 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005651#endif /* CONFIG_OFFCHANNEL */
5652#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005653 switch (data->tx_status.type) {
5654 case WLAN_FC_TYPE_MGMT:
5655 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5656 data->tx_status.data_len,
5657 data->tx_status.stype,
5658 data->tx_status.ack);
5659 break;
5660 case WLAN_FC_TYPE_DATA:
5661 ap_tx_status(wpa_s, data->tx_status.dst,
5662 data->tx_status.data,
5663 data->tx_status.data_len,
5664 data->tx_status.ack);
5665 break;
5666 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005667#endif /* CONFIG_AP */
5668 break;
5669#ifdef CONFIG_AP
5670 case EVENT_EAPOL_TX_STATUS:
5671 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5672 data->eapol_tx_status.data,
5673 data->eapol_tx_status.data_len,
5674 data->eapol_tx_status.ack);
5675 break;
5676 case EVENT_DRIVER_CLIENT_POLL_OK:
5677 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005678 break;
5679 case EVENT_RX_FROM_UNKNOWN:
5680 if (wpa_s->ap_iface == NULL)
5681 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005682 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5683 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005684 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005685#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005686
Sunil Ravi89eba102022-09-13 21:04:37 -07005687 case EVENT_LINK_CH_SWITCH_STARTED:
5688 case EVENT_LINK_CH_SWITCH:
5689 if (!data || !wpa_s->current_ssid ||
5690 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
5691 break;
5692
5693 wpa_msg(wpa_s, MSG_INFO,
5694 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5695 event == EVENT_LINK_CH_SWITCH ?
5696 WPA_EVENT_LINK_CHANNEL_SWITCH :
5697 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
5698 data->ch_switch.freq,
5699 data->ch_switch.link_id,
5700 data->ch_switch.ht_enabled,
5701 data->ch_switch.ch_offset,
5702 channel_width_to_string(data->ch_switch.ch_width),
5703 data->ch_switch.cf1,
5704 data->ch_switch.cf2);
5705 if (event == EVENT_LINK_CH_SWITCH_STARTED)
5706 break;
5707
5708 wpa_s->links[data->ch_switch.link_id].freq =
5709 data->ch_switch.freq;
5710 if (wpa_s->links[data->ch_switch.link_id].bss &&
5711 wpa_s->links[data->ch_switch.link_id].bss->freq !=
5712 data->ch_switch.freq) {
5713 wpa_s->links[data->ch_switch.link_id].bss->freq =
5714 data->ch_switch.freq;
5715 notify_bss_changes(
5716 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5717 wpa_s->links[data->ch_switch.link_id].bss);
5718 }
5719 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07005720 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005721 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005722 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005723 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005724
Hai Shalom81f62d82019-07-22 12:10:00 -07005725 wpa_msg(wpa_s, MSG_INFO,
5726 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5727 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5728 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005729 data->ch_switch.freq,
5730 data->ch_switch.ht_enabled,
5731 data->ch_switch.ch_offset,
5732 channel_width_to_string(data->ch_switch.ch_width),
5733 data->ch_switch.cf1,
5734 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005735 if (event == EVENT_CH_SWITCH_STARTED)
5736 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005737
Sunil Ravi65a724b2022-05-24 11:06:09 -07005738 if (wpa_s->assoc_freq && data->ch_switch.freq &&
5739 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
5740 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
5741 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005742 wpa_s->assoc_freq = data->ch_switch.freq;
5743 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005744 if (wpa_s->current_bss &&
5745 wpa_s->current_bss->freq != data->ch_switch.freq) {
5746 wpa_s->current_bss->freq = data->ch_switch.freq;
5747 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5748 wpa_s->current_bss);
5749 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005750
Hai Shalomfdcde762020-04-02 11:19:20 -07005751#ifdef CONFIG_SME
5752 switch (data->ch_switch.ch_offset) {
5753 case 1:
5754 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5755 break;
5756 case -1:
5757 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5758 break;
5759 default:
5760 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5761 break;
5762 }
5763#endif /* CONFIG_SME */
5764
Roshan Pius3a1667e2018-07-03 15:17:14 -07005765#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005766 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5767 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005768 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005769 wpa_s->current_ssid->mode ==
5770 WPAS_MODE_P2P_GROUP_FORMATION) {
5771 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5772 data->ch_switch.ht_enabled,
5773 data->ch_switch.ch_offset,
5774 data->ch_switch.ch_width,
5775 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005776 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07005777 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07005778 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005779 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005780#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005781
Hai Shalom899fcc72020-10-19 14:38:18 -07005782 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5783 sme_event_ch_switch(wpa_s);
5784
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005785 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005786 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005787 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005788#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005789#ifdef NEED_AP_MLME
5790 case EVENT_DFS_RADAR_DETECTED:
5791 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005792 wpas_ap_event_dfs_radar_detected(wpa_s,
5793 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005794 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005795 case EVENT_DFS_NOP_FINISHED:
5796 if (data)
5797 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5798 &data->dfs_event);
5799 break;
5800#endif /* NEED_AP_MLME */
5801#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005802 case EVENT_DFS_CAC_STARTED:
5803 if (data)
5804 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5805 break;
5806 case EVENT_DFS_CAC_FINISHED:
5807 if (data)
5808 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5809 break;
5810 case EVENT_DFS_CAC_ABORTED:
5811 if (data)
5812 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5813 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005814 case EVENT_RX_MGMT: {
5815 u16 fc, stype;
5816 const struct ieee80211_mgmt *mgmt;
5817
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005818#ifdef CONFIG_TESTING_OPTIONS
5819 if (wpa_s->ext_mgmt_frame_handling) {
5820 struct rx_mgmt *rx = &data->rx_mgmt;
5821 size_t hex_len = 2 * rx->frame_len + 1;
5822 char *hex = os_malloc(hex_len);
5823 if (hex) {
5824 wpa_snprintf_hex(hex, hex_len,
5825 rx->frame, rx->frame_len);
5826 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5827 rx->freq, rx->datarate, rx->ssi_signal,
5828 hex);
5829 os_free(hex);
5830 }
5831 break;
5832 }
5833#endif /* CONFIG_TESTING_OPTIONS */
5834
Dmitry Shmidt04949592012-07-19 12:16:46 -07005835 mgmt = (const struct ieee80211_mgmt *)
5836 data->rx_mgmt.frame;
5837 fc = le_to_host16(mgmt->frame_control);
5838 stype = WLAN_FC_GET_STYPE(fc);
5839
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005840#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005841 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005842#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005843#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005844 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005845 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005846 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005847 const u8 *ie;
5848 size_t ie_len;
5849
5850 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5851 ie_len = data->rx_mgmt.frame_len -
5852 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005853 wpas_p2p_probe_req_rx(
5854 wpa_s, src, mgmt->da,
5855 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005856 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005857 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005858 break;
5859 }
5860#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005861#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005862 if (wpa_s->current_ssid &&
5863 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5864 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005865 data->rx_mgmt.frame_len >= 30) {
5866 wpa_supplicant_event_ibss_auth(wpa_s, data);
5867 break;
5868 }
5869#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005870
5871 if (stype == WLAN_FC_STYPE_ACTION) {
5872 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005873 wpa_s, data->rx_mgmt.frame,
5874 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005875 data->rx_mgmt.freq,
5876 data->rx_mgmt.ssi_signal);
5877 break;
5878 }
5879
5880 if (wpa_s->ifmsh) {
5881 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005882 break;
5883 }
Hai Shalom60840252021-02-19 19:02:11 -08005884#ifdef CONFIG_PASN
5885 if (stype == WLAN_FC_STYPE_AUTH &&
5886 wpas_pasn_auth_rx(wpa_s, mgmt,
5887 data->rx_mgmt.frame_len) != -2)
5888 break;
5889#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005890
Roshan Pius3a1667e2018-07-03 15:17:14 -07005891#ifdef CONFIG_SAE
5892 if (stype == WLAN_FC_STYPE_AUTH &&
5893 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5894 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5895 sme_external_auth_mgmt_rx(
5896 wpa_s, data->rx_mgmt.frame,
5897 data->rx_mgmt.frame_len);
5898 break;
5899 }
5900#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005901 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5902 "management frame in non-AP mode");
5903 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005904#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005905 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005906
5907 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005908 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5909 const u8 *ie;
5910 size_t ie_len;
5911
5912 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5913 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005914
5915 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5916 mgmt->bssid, ie, ie_len,
5917 data->rx_mgmt.ssi_signal);
5918 }
5919
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005920 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005921#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005922 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005923 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005924 case EVENT_RX_PROBE_REQ:
5925 if (data->rx_probe_req.sa == NULL ||
5926 data->rx_probe_req.ie == NULL)
5927 break;
5928#ifdef CONFIG_AP
5929 if (wpa_s->ap_iface) {
5930 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5931 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005932 data->rx_probe_req.da,
5933 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005934 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005935 data->rx_probe_req.ie_len,
5936 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005937 break;
5938 }
5939#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005940 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005941 data->rx_probe_req.da,
5942 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005943 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005944 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005945 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005946 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005947 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005948 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005949#ifdef CONFIG_OFFCHANNEL
5950 offchannel_remain_on_channel_cb(
5951 wpa_s, data->remain_on_channel.freq,
5952 data->remain_on_channel.duration);
5953#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005954 wpas_p2p_remain_on_channel_cb(
5955 wpa_s, data->remain_on_channel.freq,
5956 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005957#ifdef CONFIG_DPP
5958 wpas_dpp_remain_on_channel_cb(
5959 wpa_s, data->remain_on_channel.freq,
5960 data->remain_on_channel.duration);
5961#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005962 break;
5963 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005964#ifdef CONFIG_OFFCHANNEL
5965 offchannel_cancel_remain_on_channel_cb(
5966 wpa_s, data->remain_on_channel.freq);
5967#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005968 wpas_p2p_cancel_remain_on_channel_cb(
5969 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005970#ifdef CONFIG_DPP
5971 wpas_dpp_cancel_remain_on_channel_cb(
5972 wpa_s, data->remain_on_channel.freq);
5973#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005974 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005975 case EVENT_EAPOL_RX:
5976 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5977 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00005978 data->eapol_rx.data_len,
5979 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005980 break;
5981 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005982 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00005983 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005984 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005985 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005986 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005987 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005988 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005989 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005990 bgscan_notify_signal_change(
5991 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005992 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005993 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005994 data->signal_change.data.current_tx_rate);
5995 os_memcpy(&wpa_s->last_signal_info, data,
5996 sizeof(struct wpa_signal_info));
5997 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005998 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005999 case EVENT_INTERFACE_MAC_CHANGED:
6000 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006001 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07006002 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006003 case EVENT_INTERFACE_ENABLED:
6004 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6005 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08006006 u8 addr[ETH_ALEN];
6007
Hai Shalomfdcde762020-04-02 11:19:20 -07006008 eloop_cancel_timeout(wpas_clear_disabled_interface,
6009 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08006010 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006011 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08006012 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
6013 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6014 else
6015 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07006016 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006017 if (wpa_s->p2p_mgmt) {
6018 wpa_supplicant_set_state(wpa_s,
6019 WPA_DISCONNECTED);
6020 break;
6021 }
6022
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006023#ifdef CONFIG_AP
6024 if (!wpa_s->ap_iface) {
6025 wpa_supplicant_set_state(wpa_s,
6026 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006027 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006028 wpa_supplicant_req_scan(wpa_s, 0, 0);
6029 } else
6030 wpa_supplicant_set_state(wpa_s,
6031 WPA_COMPLETED);
6032#else /* CONFIG_AP */
6033 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6034 wpa_supplicant_req_scan(wpa_s, 0, 0);
6035#endif /* CONFIG_AP */
6036 }
6037 break;
6038 case EVENT_INTERFACE_DISABLED:
6039 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006040#ifdef CONFIG_P2P
6041 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6042 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6043 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6044 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006045 * Mark interface disabled if this happens to end up not
6046 * being removed as a separate P2P group interface.
6047 */
6048 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6049 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006050 * The interface was externally disabled. Remove
6051 * it assuming an external entity will start a
6052 * new session if needed.
6053 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006054 if (wpa_s->current_ssid &&
6055 wpa_s->current_ssid->p2p_group)
6056 wpas_p2p_interface_unavailable(wpa_s);
6057 else
6058 wpas_p2p_disconnect(wpa_s);
6059 /*
6060 * wpa_s instance may have been freed, so must not use
6061 * it here anymore.
6062 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006063 break;
6064 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006065 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6066 p2p_in_progress(wpa_s->global->p2p) > 1) {
6067 /* This radio work will be cancelled, so clear P2P
6068 * state as well.
6069 */
6070 p2p_stop_find(wpa_s->global->p2p);
6071 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006072#endif /* CONFIG_P2P */
6073
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006074 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6075 /*
6076 * Indicate disconnection to keep ctrl_iface events
6077 * consistent.
6078 */
6079 wpa_supplicant_event_disassoc(
6080 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6081 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006082 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07006083 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08006084 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6085 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006086 clear_at.usec = 0;
6087 } else {
6088 struct os_reltime tmp;
6089
Hai Shalom60840252021-02-19 19:02:11 -08006090 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006091 tmp.usec = 0;
6092 os_reltime_sub(&tmp, &age, &clear_at);
6093 }
6094 eloop_register_timeout(clear_at.sec, clear_at.usec,
6095 wpas_clear_disabled_interface,
6096 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08006097 radio_remove_works(wpa_s, NULL, 0);
6098
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006099 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6100 break;
6101 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006102 wpa_supplicant_update_channel_list(
6103 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006104 break;
6105 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006106 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006107 break;
6108 case EVENT_BEST_CHANNEL:
6109 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6110 "(%d %d %d)",
6111 data->best_chan.freq_24, data->best_chan.freq_5,
6112 data->best_chan.freq_overall);
6113 wpa_s->best_24_freq = data->best_chan.freq_24;
6114 wpa_s->best_5_freq = data->best_chan.freq_5;
6115 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006116 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6117 data->best_chan.freq_5,
6118 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006119 break;
6120 case EVENT_UNPROT_DEAUTH:
6121 wpa_supplicant_event_unprot_deauth(wpa_s,
6122 &data->unprot_deauth);
6123 break;
6124 case EVENT_UNPROT_DISASSOC:
6125 wpa_supplicant_event_unprot_disassoc(wpa_s,
6126 &data->unprot_disassoc);
6127 break;
6128 case EVENT_STATION_LOW_ACK:
6129#ifdef CONFIG_AP
6130 if (wpa_s->ap_iface && data)
6131 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6132 data->low_ack.addr);
6133#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006134#ifdef CONFIG_TDLS
6135 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07006136 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
6137 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006138#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006139 break;
6140 case EVENT_IBSS_PEER_LOST:
6141#ifdef CONFIG_IBSS_RSN
6142 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6143#endif /* CONFIG_IBSS_RSN */
6144 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006145 case EVENT_DRIVER_GTK_REKEY:
6146 if (os_memcmp(data->driver_gtk_rekey.bssid,
6147 wpa_s->bssid, ETH_ALEN))
6148 break;
6149 if (!wpa_s->wpa)
6150 break;
6151 wpa_sm_update_replay_ctr(wpa_s->wpa,
6152 data->driver_gtk_rekey.replay_ctr);
6153 break;
6154 case EVENT_SCHED_SCAN_STOPPED:
6155 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006156 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006157 wpa_supplicant_notify_scanning(wpa_s, 0);
6158
6159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6160 break;
6161
6162 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006163 * If the driver stopped scanning without being requested to,
6164 * request a new scan to continue scanning for networks.
6165 */
6166 if (!wpa_s->sched_scan_stop_req &&
6167 wpa_s->wpa_state == WPA_SCANNING) {
6168 wpa_dbg(wpa_s, MSG_DEBUG,
6169 "Restart scanning after unexpected sched_scan stop event");
6170 wpa_supplicant_req_scan(wpa_s, 1, 0);
6171 break;
6172 }
6173
6174 wpa_s->sched_scan_stop_req = 0;
6175
6176 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006177 * Start a new sched scan to continue searching for more SSIDs
6178 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006179 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006180 if (wpa_s->sched_scan_timed_out) {
6181 wpa_supplicant_req_sched_scan(wpa_s);
6182 } else if (wpa_s->pno_sched_pending) {
6183 wpa_s->pno_sched_pending = 0;
6184 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006185 } else if (resched) {
6186 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006187 }
6188
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006189 break;
6190 case EVENT_WPS_BUTTON_PUSHED:
6191#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006192 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006193#endif /* CONFIG_WPS */
6194 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006195 case EVENT_AVOID_FREQUENCIES:
6196 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6197 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006198 case EVENT_CONNECT_FAILED_REASON:
6199#ifdef CONFIG_AP
6200 if (!wpa_s->ap_iface || !data)
6201 break;
6202 hostapd_event_connect_failed_reason(
6203 wpa_s->ap_iface->bss[0],
6204 data->connect_failed_reason.addr,
6205 data->connect_failed_reason.code);
6206#endif /* CONFIG_AP */
6207 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006208 case EVENT_NEW_PEER_CANDIDATE:
6209#ifdef CONFIG_MESH
6210 if (!wpa_s->ifmsh || !data)
6211 break;
6212 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6213 data->mesh_peer.ies,
6214 data->mesh_peer.ie_len);
6215#endif /* CONFIG_MESH */
6216 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006217 case EVENT_SURVEY:
6218#ifdef CONFIG_AP
6219 if (!wpa_s->ap_iface)
6220 break;
6221 hostapd_event_get_survey(wpa_s->ap_iface,
6222 &data->survey_results);
6223#endif /* CONFIG_AP */
6224 break;
6225 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006226#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006227#ifdef CONFIG_ACS
6228 if (!wpa_s->ap_iface)
6229 break;
6230 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6231 &data->acs_selected_channels);
6232#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006233#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006234 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006235 case EVENT_P2P_LO_STOP:
6236#ifdef CONFIG_P2P
6237 wpa_s->p2p_lo_started = 0;
6238 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6239 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6240 data->p2p_lo_stop.reason_code);
6241#endif /* CONFIG_P2P */
6242 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006243 case EVENT_BEACON_LOSS:
6244 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6245 break;
6246 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6247 bgscan_notify_beacon_loss(wpa_s);
6248 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006249 case EVENT_EXTERNAL_AUTH:
6250#ifdef CONFIG_SAE
6251 if (!wpa_s->current_ssid) {
6252 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6253 break;
6254 }
6255 sme_external_auth_trigger(wpa_s, data);
6256#endif /* CONFIG_SAE */
6257 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006258#ifdef CONFIG_PASN
6259 case EVENT_PASN_AUTH:
6260 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6261 break;
6262#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006263 case EVENT_PORT_AUTHORIZED:
Sunil Ravi77d572f2023-01-17 23:58:31 +00006264#ifndef CONFIG_NO_WPA
6265 if (data->port_authorized.td_bitmap_len) {
6266 wpa_printf(MSG_DEBUG,
6267 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
6268 data->port_authorized.td_bitmap[0]);
6269 wpas_transition_disable(
6270 wpa_s, data->port_authorized.td_bitmap[0]);
6271 }
6272#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006273 wpa_supplicant_event_port_authorized(wpa_s);
6274 break;
6275 case EVENT_STATION_OPMODE_CHANGED:
6276#ifdef CONFIG_AP
6277 if (!wpa_s->ap_iface || !data)
6278 break;
6279
6280 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6281 data->sta_opmode.addr,
6282 data->sta_opmode.smps_mode,
6283 data->sta_opmode.chan_width,
6284 data->sta_opmode.rx_nss);
6285#endif /* CONFIG_AP */
6286 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07006287 case EVENT_UNPROT_BEACON:
6288 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6289 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08006290 case EVENT_TX_WAIT_EXPIRE:
6291#ifdef CONFIG_DPP
6292 wpas_dpp_tx_wait_expire(wpa_s);
6293#endif /* CONFIG_DPP */
6294 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006295 default:
6296 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6297 break;
6298 }
6299}
Dmitry Shmidte4663042016-04-04 10:07:49 -07006300
6301
6302void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6303 union wpa_event_data *data)
6304{
6305 struct wpa_supplicant *wpa_s;
6306
6307 if (event != EVENT_INTERFACE_STATUS)
6308 return;
6309
6310 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6311 if (wpa_s && wpa_s->driver->get_ifindex) {
6312 unsigned int ifindex;
6313
6314 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6315 if (ifindex != data->interface_status.ifindex) {
6316 wpa_dbg(wpa_s, MSG_DEBUG,
6317 "interface status ifindex %d mismatch (%d)",
6318 ifindex, data->interface_status.ifindex);
6319 return;
6320 }
6321 }
6322#ifdef CONFIG_MATCH_IFACE
6323 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6324 struct wpa_interface *wpa_i;
6325
6326 wpa_i = wpa_supplicant_match_iface(
6327 ctx, data->interface_status.ifname);
6328 if (!wpa_i)
6329 return;
6330 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6331 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006332 }
6333#endif /* CONFIG_MATCH_IFACE */
6334
6335 if (wpa_s)
6336 wpa_supplicant_event(wpa_s, event, data);
6337}