blob: 3275b645ca5e8e1f485d41dccf0455edf140d422 [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
397static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
398{
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);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 break;
422 }
423 }
424
425 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
426 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
427}
428
429
430static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
431 union wpa_event_data *data)
432{
433 if (data == NULL) {
434 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
435 "event");
436 return;
437 }
438 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
439 " index=%d preauth=%d",
440 MAC2STR(data->pmkid_candidate.bssid),
441 data->pmkid_candidate.index,
442 data->pmkid_candidate.preauth);
443
444 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
445 data->pmkid_candidate.index,
446 data->pmkid_candidate.preauth);
447}
448
449
450static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
451{
452 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
453 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
454 return 0;
455
456#ifdef IEEE8021X_EAPOL
457 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
458 wpa_s->current_ssid &&
459 !(wpa_s->current_ssid->eapol_flags &
460 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
461 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
462 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
463 * plaintext or static WEP keys). */
464 return 0;
465 }
466#endif /* IEEE8021X_EAPOL */
467
468 return 1;
469}
470
471
472/**
473 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
474 * @wpa_s: pointer to wpa_supplicant data
475 * @ssid: Configuration data for the network
476 * Returns: 0 on success, -1 on failure
477 *
478 * This function is called when starting authentication with a network that is
479 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
480 */
481int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
482 struct wpa_ssid *ssid)
483{
484#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800485#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700486 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700488 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
489 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700490 return 0;
491
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700492 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 sim = 1;
494 aka = 1;
495 } else {
496 struct eap_method_type *eap = ssid->eap.eap_methods;
497 while (eap->vendor != EAP_VENDOR_IETF ||
498 eap->method != EAP_TYPE_NONE) {
499 if (eap->vendor == EAP_VENDOR_IETF) {
500 if (eap->method == EAP_TYPE_SIM)
501 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700502 else if (eap->method == EAP_TYPE_AKA ||
503 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504 aka = 1;
505 }
506 eap++;
507 }
508 }
509
510 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
511 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700512 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
513 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
514 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515 aka = 0;
516
517 if (!sim && !aka) {
518 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
519 "use SIM, but neither EAP-SIM nor EAP-AKA are "
520 "enabled");
521 return 0;
522 }
523
524 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
525 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700526
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700527 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528 if (wpa_s->scard == NULL) {
529 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
530 "(pcsc-lite)");
531 return -1;
532 }
533 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
534 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800535#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536#endif /* IEEE8021X_EAPOL */
537
538 return 0;
539}
540
541
542#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700543
Hai Shalomfdcde762020-04-02 11:19:20 -0700544#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700545static int has_wep_key(struct wpa_ssid *ssid)
546{
547 int i;
548
549 for (i = 0; i < NUM_WEP_KEYS; i++) {
550 if (ssid->wep_key_len[i])
551 return 1;
552 }
553
554 return 0;
555}
Hai Shalomfdcde762020-04-02 11:19:20 -0700556#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700557
558
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700559static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560 struct wpa_ssid *ssid)
561{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700562 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563
564 if (ssid->mixed_cell)
565 return 1;
566
567#ifdef CONFIG_WPS
568 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
569 return 1;
570#endif /* CONFIG_WPS */
571
Roshan Pius3a1667e2018-07-03 15:17:14 -0700572#ifdef CONFIG_OWE
573 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
574 return 1;
575#endif /* CONFIG_OWE */
576
Hai Shalomfdcde762020-04-02 11:19:20 -0700577#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700578 if (has_wep_key(ssid))
579 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700580#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700581
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582#ifdef IEEE8021X_EAPOL
583 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
584 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
585 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
586 privacy = 1;
587#endif /* IEEE8021X_EAPOL */
588
Jouni Malinen75ecf522011-06-27 15:19:46 -0700589 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
590 privacy = 1;
591
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800592 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
593 privacy = 1;
594
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700595 if (bss->caps & IEEE80211_CAP_PRIVACY)
596 return privacy;
597 return !privacy;
598}
599
600
601static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
602 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800603 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700604{
605 struct wpa_ie_data ie;
606 int proto_match = 0;
607 const u8 *rsn_ie, *wpa_ie;
608 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700609#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700610 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700611#endif /* CONFIG_WEP */
Sunil Ravi77d572f2023-01-17 23:58:31 +0000612 bool is_6ghz_bss_or_mld = is_6ghz_freq(bss->freq) ||
613 !is_zero_ether_addr(bss->mld_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614
615 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
616 if (ret >= 0)
617 return ret;
618
Hai Shalomfdcde762020-04-02 11:19:20 -0700619#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700620 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
621 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
622 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
623 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
624 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700625#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700626
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700627 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000628 if (is_6ghz_bss_or_mld && !rsn_ie) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700629 if (debug_print)
630 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000631 " skip - 6 GHz/MLD BSS without RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700632 return 0;
633 }
634
Roshan Pius3a1667e2018-07-03 15:17:14 -0700635 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636 proto_match++;
637
638 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800639 if (debug_print)
640 wpa_dbg(wpa_s, MSG_DEBUG,
641 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642 break;
643 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700644 if (!ie.has_pairwise)
645 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
646 if (!ie.has_group)
647 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700648
Sunil Ravi77d572f2023-01-17 23:58:31 +0000649 if (is_6ghz_bss_or_mld) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700650 /* WEP and TKIP are not allowed on 6 GHz */
651 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
652 WPA_CIPHER_WEP104 |
653 WPA_CIPHER_TKIP);
654 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
655 WPA_CIPHER_WEP104 |
656 WPA_CIPHER_TKIP);
657 }
658
Hai Shalomfdcde762020-04-02 11:19:20 -0700659#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700660 if (wep_ok &&
661 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
662 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800663 if (debug_print)
664 wpa_dbg(wpa_s, MSG_DEBUG,
665 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666 return 1;
667 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700668#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700669
Roshan Pius3a1667e2018-07-03 15:17:14 -0700670 if (!(ie.proto & ssid->proto) &&
671 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800672 if (debug_print)
673 wpa_dbg(wpa_s, MSG_DEBUG,
674 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700675 break;
676 }
677
678 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800679 if (debug_print)
680 wpa_dbg(wpa_s, MSG_DEBUG,
681 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682 break;
683 }
684
685 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800686 if (debug_print)
687 wpa_dbg(wpa_s, MSG_DEBUG,
688 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689 break;
690 }
691
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700692 if (ssid->group_mgmt_cipher &&
693 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
694 if (debug_print)
695 wpa_dbg(wpa_s, MSG_DEBUG,
696 " skip RSN IE - group mgmt cipher mismatch");
697 break;
698 }
699
Sunil Ravi77d572f2023-01-17 23:58:31 +0000700 if (is_6ghz_bss_or_mld) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700701 /* MFPC must be supported on 6 GHz */
702 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
703 if (debug_print)
704 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000705 " skip RSNE - 6 GHz/MLD without MFPC");
Sunil Ravia04bd252022-05-02 22:54:18 -0700706 break;
707 }
708
709 /* WPA PSK is not allowed on the 6 GHz band */
710 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
711 WPA_KEY_MGMT_FT_PSK |
712 WPA_KEY_MGMT_PSK_SHA256);
713 }
714
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800716 if (debug_print)
717 wpa_dbg(wpa_s, MSG_DEBUG,
718 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719 break;
720 }
721
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800723 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800724 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800725 if (debug_print)
726 wpa_dbg(wpa_s, MSG_DEBUG,
727 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728 break;
729 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800730 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
731 wpas_get_ssid_pmf(wpa_s, ssid) ==
732 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800733 if (debug_print)
734 wpa_dbg(wpa_s, MSG_DEBUG,
735 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800736 break;
737 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700738
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800739 if (debug_print)
740 wpa_dbg(wpa_s, MSG_DEBUG,
741 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700742 return 1;
743 }
744
Sunil Ravi77d572f2023-01-17 23:58:31 +0000745 if (is_6ghz_bss_or_mld) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700746 if (debug_print)
747 wpa_dbg(wpa_s, MSG_DEBUG,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000748 " skip - 6 GHz/MLD BSS without matching RSNE");
Sunil Ravia04bd252022-05-02 22:54:18 -0700749 return 0;
750 }
751
Roshan Pius3a1667e2018-07-03 15:17:14 -0700752 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
753 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800754 if (debug_print)
755 wpa_dbg(wpa_s, MSG_DEBUG,
756 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700757 return 0;
758 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700759
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700760 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
762 proto_match++;
763
764 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800765 if (debug_print)
766 wpa_dbg(wpa_s, MSG_DEBUG,
767 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768 break;
769 }
770
Hai Shalomfdcde762020-04-02 11:19:20 -0700771#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700772 if (wep_ok &&
773 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
774 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800775 if (debug_print)
776 wpa_dbg(wpa_s, MSG_DEBUG,
777 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778 return 1;
779 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700780#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781
782 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800783 if (debug_print)
784 wpa_dbg(wpa_s, MSG_DEBUG,
785 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700786 break;
787 }
788
789 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800790 if (debug_print)
791 wpa_dbg(wpa_s, MSG_DEBUG,
792 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700793 break;
794 }
795
796 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800797 if (debug_print)
798 wpa_dbg(wpa_s, MSG_DEBUG,
799 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700800 break;
801 }
802
803 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800804 if (debug_print)
805 wpa_dbg(wpa_s, MSG_DEBUG,
806 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 break;
808 }
809
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800810 if (debug_print)
811 wpa_dbg(wpa_s, MSG_DEBUG,
812 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813 return 1;
814 }
815
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700816 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
817 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800818 if (debug_print)
819 wpa_dbg(wpa_s, MSG_DEBUG,
820 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700821 return 1;
822 }
823
Roshan Pius3a1667e2018-07-03 15:17:14 -0700824#ifdef CONFIG_OWE
825 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
826 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800827 if (wpa_s->owe_transition_select &&
828 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
829 ssid->owe_transition_bss_select_count + 1 <=
830 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
831 ssid->owe_transition_bss_select_count++;
832 if (debug_print)
833 wpa_dbg(wpa_s, MSG_DEBUG,
834 " skip OWE transition BSS (selection count %d does not exceed %d)",
835 ssid->owe_transition_bss_select_count,
836 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
837 wpa_s->owe_transition_search = 1;
838 return 0;
839 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700840 if (debug_print)
841 wpa_dbg(wpa_s, MSG_DEBUG,
842 " allow in OWE transition mode");
843 return 1;
844 }
845#endif /* CONFIG_OWE */
846
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
848 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800849 if (debug_print)
850 wpa_dbg(wpa_s, MSG_DEBUG,
851 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700852 return 0;
853 }
854
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800855 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
856 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800857 if (debug_print)
858 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800859 return 1;
860 }
861
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800863 if (debug_print)
864 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700865 return 1;
866 }
867
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800868 if (debug_print)
869 wpa_dbg(wpa_s, MSG_DEBUG,
870 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871
872 return 0;
873}
874
875
876static int freq_allowed(int *freqs, int freq)
877{
878 int i;
879
880 if (freqs == NULL)
881 return 1;
882
883 for (i = 0; freqs[i]; i++)
884 if (freqs[i] == freq)
885 return 1;
886 return 0;
887}
888
889
Hai Shalomfdcde762020-04-02 11:19:20 -0700890static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
891 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800892{
893 const struct hostapd_hw_modes *mode = NULL, *modes;
894 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
895 const u8 *rate_ie;
896 int i, j, k;
897
898 if (bss->freq == 0)
899 return 1; /* Cannot do matching without knowing band */
900
901 modes = wpa_s->hw.modes;
902 if (modes == NULL) {
903 /*
904 * The driver does not provide any additional information
905 * about the utilized hardware, so allow the connection attempt
906 * to continue.
907 */
908 return 1;
909 }
910
911 for (i = 0; i < wpa_s->hw.num_modes; i++) {
912 for (j = 0; j < modes[i].num_channels; j++) {
913 int freq = modes[i].channels[j].freq;
914 if (freq == bss->freq) {
915 if (mode &&
916 mode->mode == HOSTAPD_MODE_IEEE80211G)
917 break; /* do not allow 802.11b replace
918 * 802.11g */
919 mode = &modes[i];
920 break;
921 }
922 }
923 }
924
925 if (mode == NULL)
926 return 0;
927
928 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700929 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800930 if (rate_ie == NULL)
931 continue;
932
933 for (j = 2; j < rate_ie[1] + 2; j++) {
934 int flagged = !!(rate_ie[j] & 0x80);
935 int r = (rate_ie[j] & 0x7f) * 5;
936
937 /*
938 * IEEE Std 802.11n-2009 7.3.2.2:
939 * The new BSS Membership selector value is encoded
940 * like a legacy basic rate, but it is not a rate and
941 * only indicates if the BSS members are required to
942 * support the mandatory features of Clause 20 [HT PHY]
943 * in order to join the BSS.
944 */
945 if (flagged && ((rate_ie[j] & 0x7f) ==
946 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
947 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800948 if (debug_print)
949 wpa_dbg(wpa_s, MSG_DEBUG,
950 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800951 return 0;
952 }
953 continue;
954 }
955
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700956 /* There's also a VHT selector for 802.11ac */
957 if (flagged && ((rate_ie[j] & 0x7f) ==
958 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
959 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800960 if (debug_print)
961 wpa_dbg(wpa_s, MSG_DEBUG,
962 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700963 return 0;
964 }
965 continue;
966 }
967
Sunil Ravi77d572f2023-01-17 23:58:31 +0000968 if (flagged && ((rate_ie[j] & 0x7f) ==
969 BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
970 if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
971 if (debug_print)
972 wpa_dbg(wpa_s, MSG_DEBUG,
973 " hardware does not support HE PHY");
974 return 0;
975 }
976 continue;
977 }
978
Hai Shalomc3565922019-10-28 11:58:20 -0700979#ifdef CONFIG_SAE
980 if (flagged && ((rate_ie[j] & 0x7f) ==
981 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Sunil Ravi77d572f2023-01-17 23:58:31 +0000982 if (wpa_s->conf->sae_pwe ==
983 SAE_PWE_HUNT_AND_PECK &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700984 !ssid->sae_password_id &&
985 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700986 if (debug_print)
987 wpa_dbg(wpa_s, MSG_DEBUG,
988 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800989#ifdef CONFIG_TESTING_OPTIONS
990 if (wpa_s->ignore_sae_h2e_only) {
991 wpa_dbg(wpa_s, MSG_DEBUG,
992 "TESTING: Ignore SAE H2E requirement mismatch");
993 continue;
994 }
995#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700996 return 0;
997 }
998 continue;
999 }
1000#endif /* CONFIG_SAE */
1001
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001002 if (!flagged)
1003 continue;
1004
1005 /* check for legacy basic rates */
1006 for (k = 0; k < mode->num_rates; k++) {
1007 if (mode->rates[k] == r)
1008 break;
1009 }
1010 if (k == mode->num_rates) {
1011 /*
1012 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1013 * order to join a BSS all required rates
1014 * have to be supported by the hardware.
1015 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001016 if (debug_print)
1017 wpa_dbg(wpa_s, MSG_DEBUG,
1018 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1019 r / 10, r % 10,
1020 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001021 return 0;
1022 }
1023 }
1024 }
1025
1026 return 1;
1027}
1028
1029
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001030/*
1031 * Test whether BSS is in an ESS.
1032 * This is done differently in DMG (60 GHz) and non-DMG bands
1033 */
1034static int bss_is_ess(struct wpa_bss *bss)
1035{
1036 if (bss_is_dmg(bss)) {
1037 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1038 IEEE80211_CAP_DMG_AP;
1039 }
1040
1041 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1042 IEEE80211_CAP_ESS);
1043}
1044
1045
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001046static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1047{
1048 size_t i;
1049
1050 for (i = 0; i < ETH_ALEN; i++) {
1051 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1052 return 0;
1053 }
1054 return 1;
1055}
1056
1057
1058static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1059{
1060 size_t i;
1061
1062 for (i = 0; i < num; i++) {
1063 const u8 *a = list + i * ETH_ALEN * 2;
1064 const u8 *m = a + ETH_ALEN;
1065
1066 if (match_mac_mask(a, addr, m))
1067 return 1;
1068 }
1069 return 0;
1070}
1071
1072
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001073static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1074 const u8 **ret_ssid, size_t *ret_ssid_len)
1075{
1076#ifdef CONFIG_OWE
1077 const u8 *owe, *pos, *end, *bssid;
1078 u8 ssid_len;
1079 struct wpa_bss *open_bss;
1080
1081 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1082 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
1083 return;
1084
1085 pos = owe + 6;
1086 end = owe + 2 + owe[1];
1087
1088 if (end - pos < ETH_ALEN + 1)
1089 return;
1090 bssid = pos;
1091 pos += ETH_ALEN;
1092 ssid_len = *pos++;
1093 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1094 return;
1095
1096 /* Match the profile SSID against the OWE transition mode SSID on the
1097 * open network. */
1098 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1099 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1100 *ret_ssid = pos;
1101 *ret_ssid_len = ssid_len;
1102
Hai Shalomfdcde762020-04-02 11:19:20 -07001103 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1104 struct wpa_ssid *ssid;
1105
1106 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1107 if (wpas_network_disabled(wpa_s, ssid))
1108 continue;
1109 if (ssid->ssid_len == ssid_len &&
1110 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1111 /* OWE BSS in transition mode for a currently
1112 * enabled OWE network. */
1113 wpa_dbg(wpa_s, MSG_DEBUG,
1114 "OWE: transition mode OWE SSID for active OWE profile");
1115 bss->flags |= WPA_BSS_OWE_TRANSITION;
1116 break;
1117 }
1118 }
1119 }
1120
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001121 if (bss->ssid_len > 0)
1122 return;
1123
1124 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1125 if (!open_bss)
1126 return;
1127 if (ssid_len != open_bss->ssid_len ||
1128 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1129 wpa_dbg(wpa_s, MSG_DEBUG,
1130 "OWE: transition mode SSID mismatch: %s",
1131 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1132 return;
1133 }
1134
1135 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1136 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1137 wpa_dbg(wpa_s, MSG_DEBUG,
1138 "OWE: transition mode open BSS unexpected info");
1139 return;
1140 }
1141
1142 pos = owe + 6;
1143 end = owe + 2 + owe[1];
1144
1145 if (end - pos < ETH_ALEN + 1)
1146 return;
1147 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1148 wpa_dbg(wpa_s, MSG_DEBUG,
1149 "OWE: transition mode BSSID mismatch: " MACSTR,
1150 MAC2STR(pos));
1151 return;
1152 }
1153 pos += ETH_ALEN;
1154 ssid_len = *pos++;
1155 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1156 return;
1157 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1158 wpa_ssid_txt(pos, ssid_len));
1159 os_memcpy(bss->ssid, pos, ssid_len);
1160 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001161 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001162#endif /* CONFIG_OWE */
1163}
1164
1165
Sunil Ravi26978f32021-04-30 15:19:18 -07001166int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001167{
1168 int i, j;
1169
1170 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1171 return 0;
1172
1173 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1174 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1175
1176 for (i = 0; i < mode->num_channels; i++) {
1177 struct hostapd_channel_data *chan = &mode->channels[i];
1178
1179 if (chan->freq == freq)
1180 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1181 }
1182 }
1183
1184 return 1;
1185}
1186
1187
Hai Shalom899fcc72020-10-19 14:38:18 -07001188static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1189 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001190 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001191 bool debug_print);
1192
1193
1194#ifdef CONFIG_SAE_PK
1195static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1196 struct wpa_bss *orig_bss,
1197 struct wpa_ssid *ssid,
1198 const u8 *match_ssid,
1199 size_t match_ssid_len)
1200{
1201 struct wpa_bss *bss;
1202
1203 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1204 int count;
1205 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001206
1207 if (bss == orig_bss)
1208 continue;
1209 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001210 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001211 continue;
1212
1213 /* TODO: Could be more thorough in checking what kind of
1214 * signal strength or throughput estimate would be acceptable
1215 * compared to the originally selected BSS. */
1216 if (bss->est_throughput < 2000)
1217 return false;
1218
Hai Shalom60840252021-02-19 19:02:11 -08001219 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001220 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1221 bss, count, 0))
1222 return true;
1223 }
1224
1225 return false;
1226}
1227#endif /* CONFIG_SAE_PK */
1228
1229
1230static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1231 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001232 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001233 bool debug_print)
1234{
1235 int res;
1236 bool wpa, check_ssid, osen, rsn_osen = false;
1237 struct wpa_ie_data data;
1238#ifdef CONFIG_MBO
1239 const u8 *assoc_disallow;
1240#endif /* CONFIG_MBO */
1241#ifdef CONFIG_SAE
1242 u8 rsnxe_capa = 0;
1243#endif /* CONFIG_SAE */
1244 const u8 *ie;
1245
1246 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1247 wpa = ie && ie[1];
1248 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1249 wpa |= ie && ie[1];
1250 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1251 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1252 rsn_osen = true;
1253 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1254 osen = ie != NULL;
1255
1256#ifdef CONFIG_SAE
1257 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1258 if (ie && ie[1] >= 1)
1259 rsnxe_capa = ie[2];
1260#endif /* CONFIG_SAE */
1261
1262 check_ssid = wpa || ssid->ssid_len > 0;
1263
1264 if (wpas_network_disabled(wpa_s, ssid)) {
1265 if (debug_print)
1266 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1267 return false;
1268 }
1269
1270 res = wpas_temp_disabled(wpa_s, ssid);
1271 if (res > 0) {
1272 if (debug_print)
1273 wpa_dbg(wpa_s, MSG_DEBUG,
1274 " skip - disabled temporarily for %d second(s)",
1275 res);
1276 return false;
1277 }
1278
1279#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001280 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001281 if (debug_print)
1282 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001283 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001284 return false;
1285 }
1286
1287 if (wpa && ssid->ssid_len == 0 &&
1288 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1289 check_ssid = false;
1290
1291 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1292 /* Only allow wildcard SSID match if an AP advertises active
1293 * WPS operation that matches our mode. */
1294 check_ssid = ssid->ssid_len > 0 ||
1295 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1296 }
1297#endif /* CONFIG_WPS */
1298
1299 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1300 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1301 check_ssid = false;
1302
1303 if (check_ssid &&
1304 (match_ssid_len != ssid->ssid_len ||
1305 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1306 if (debug_print)
1307 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1308 return false;
1309 }
1310
1311 if (ssid->bssid_set &&
1312 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1313 if (debug_print)
1314 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1315 return false;
1316 }
1317
Hai Shalom60840252021-02-19 19:02:11 -08001318 /* check the list of BSSIDs to ignore */
1319 if (ssid->num_bssid_ignore &&
1320 addr_in_list(bss->bssid, ssid->bssid_ignore,
1321 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001322 if (debug_print)
1323 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001324 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001325 return false;
1326 }
1327
Hai Shalom60840252021-02-19 19:02:11 -08001328 /* if there is a list of accepted BSSIDs, only accept those APs */
1329 if (ssid->num_bssid_accept &&
1330 !addr_in_list(bss->bssid, ssid->bssid_accept,
1331 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001332 if (debug_print)
1333 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001334 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001335 return false;
1336 }
1337
1338 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1339 return false;
1340
1341 if (!osen && !wpa &&
1342 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1343 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1344 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1345 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1346 if (debug_print)
1347 wpa_dbg(wpa_s, MSG_DEBUG,
1348 " skip - non-WPA network not allowed");
1349 return false;
1350 }
1351
1352#ifdef CONFIG_WEP
1353 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1354 if (debug_print)
1355 wpa_dbg(wpa_s, MSG_DEBUG,
1356 " skip - ignore WPA/WPA2 AP for WEP network block");
1357 return false;
1358 }
1359#endif /* CONFIG_WEP */
1360
1361 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1362 if (debug_print)
1363 wpa_dbg(wpa_s, MSG_DEBUG,
1364 " skip - non-OSEN network not allowed");
1365 return false;
1366 }
1367
1368 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1369 if (debug_print)
1370 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1371 return false;
1372 }
1373
1374 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1375 !bss_is_pbss(bss)) {
1376 if (debug_print)
1377 wpa_dbg(wpa_s, MSG_DEBUG,
1378 " skip - not ESS, PBSS, or MBSS");
1379 return false;
1380 }
1381
1382 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1383 if (debug_print)
1384 wpa_dbg(wpa_s, MSG_DEBUG,
1385 " skip - PBSS mismatch (ssid %d bss %d)",
1386 ssid->pbss, bss_is_pbss(bss));
1387 return false;
1388 }
1389
1390 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1391 if (debug_print)
1392 wpa_dbg(wpa_s, MSG_DEBUG,
1393 " skip - frequency not allowed");
1394 return false;
1395 }
1396
1397#ifdef CONFIG_MESH
1398 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1399 ssid->frequency != bss->freq) {
1400 if (debug_print)
1401 wpa_dbg(wpa_s, MSG_DEBUG,
1402 " skip - frequency not allowed (mesh)");
1403 return false;
1404 }
1405#endif /* CONFIG_MESH */
1406
1407 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1408 if (debug_print)
1409 wpa_dbg(wpa_s, MSG_DEBUG,
1410 " skip - rate sets do not match");
1411 return false;
1412 }
1413
1414#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001415 /* When using SAE Password Identifier and when operationg on the 6 GHz
1416 * band, only H2E is allowed. */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001417 if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1418 is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1419 wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1420 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001421#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05301422 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
Winnie Chen4138eec2022-11-10 16:32:53 +08001423#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom899fcc72020-10-19 14:38:18 -07001424 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1425 if (debug_print)
1426 wpa_dbg(wpa_s, MSG_DEBUG,
1427 " skip - SAE H2E required, but not supported by the AP");
1428 return false;
1429 }
1430#endif /* CONFIG_SAE */
1431
1432#ifdef CONFIG_SAE_PK
1433 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1434 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1435 if (debug_print)
1436 wpa_dbg(wpa_s, MSG_DEBUG,
1437 " skip - SAE-PK required, but not supported by the AP");
1438 return false;
1439 }
1440#endif /* CONFIG_SAE_PK */
1441
1442#ifndef CONFIG_IBSS_RSN
1443 if (ssid->mode == WPAS_MODE_IBSS &&
1444 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1445 if (debug_print)
1446 wpa_dbg(wpa_s, MSG_DEBUG,
1447 " skip - IBSS RSN not supported in the build");
1448 return false;
1449 }
1450#endif /* !CONFIG_IBSS_RSN */
1451
1452#ifdef CONFIG_P2P
1453 if (ssid->p2p_group &&
1454 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1455 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1456 if (debug_print)
1457 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1458 return false;
1459 }
1460
1461 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1462 struct wpabuf *p2p_ie;
1463 u8 dev_addr[ETH_ALEN];
1464
1465 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1466 if (!ie) {
1467 if (debug_print)
1468 wpa_dbg(wpa_s, MSG_DEBUG,
1469 " skip - no P2P element");
1470 return false;
1471 }
1472 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1473 if (!p2p_ie) {
1474 if (debug_print)
1475 wpa_dbg(wpa_s, MSG_DEBUG,
1476 " skip - could not fetch P2P element");
1477 return false;
1478 }
1479
1480 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1481 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1482 if (debug_print)
1483 wpa_dbg(wpa_s, MSG_DEBUG,
1484 " skip - no matching GO P2P Device Address in P2P element");
1485 wpabuf_free(p2p_ie);
1486 return false;
1487 }
1488 wpabuf_free(p2p_ie);
1489 }
1490
1491 /*
1492 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1493 * P2P Group Capability Bitmap and we are not in Group Formation with
1494 * that device.
1495 */
1496#endif /* CONFIG_P2P */
1497
1498 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1499 struct os_reltime diff;
1500
1501 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1502 if (debug_print)
1503 wpa_dbg(wpa_s, MSG_DEBUG,
1504 " skip - scan result not recent enough (%u.%06u seconds too old)",
1505 (unsigned int) diff.sec,
1506 (unsigned int) diff.usec);
1507 return false;
1508 }
1509#ifdef CONFIG_MBO
1510#ifdef CONFIG_TESTING_OPTIONS
1511 if (wpa_s->ignore_assoc_disallow)
1512 goto skip_assoc_disallow;
1513#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001514 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001515 if (assoc_disallow && assoc_disallow[1] >= 1) {
1516 if (debug_print)
1517 wpa_dbg(wpa_s, MSG_DEBUG,
1518 " skip - MBO association disallowed (reason %u)",
1519 assoc_disallow[2]);
1520 return false;
1521 }
1522
1523 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1524 if (debug_print)
1525 wpa_dbg(wpa_s, MSG_DEBUG,
1526 " skip - AP temporarily disallowed");
1527 return false;
1528 }
1529#ifdef CONFIG_TESTING_OPTIONS
1530skip_assoc_disallow:
1531#endif /* CONFIG_TESTING_OPTIONS */
1532#endif /* CONFIG_MBO */
1533
1534#ifdef CONFIG_DPP
1535 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00001536 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1537 ssid) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001538 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1539 !ssid->dpp_csign)) {
1540 if (debug_print)
1541 wpa_dbg(wpa_s, MSG_DEBUG,
1542 " skip - no PMKSA entry for DPP");
1543 return false;
1544 }
1545#endif /* CONFIG_DPP */
1546
1547#ifdef CONFIG_SAE_PK
1548 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1549 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1550 ((ssid->sae_password &&
1551 sae_pk_valid_password(ssid->sae_password)) ||
1552 (!ssid->sae_password && ssid->passphrase &&
1553 sae_pk_valid_password(ssid->passphrase))) &&
1554 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1555 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1556 match_ssid_len)) {
1557 if (debug_print)
1558 wpa_dbg(wpa_s, MSG_DEBUG,
1559 " skip - another acceptable BSS with SAE-PK in the same ESS");
1560 return false;
1561 }
1562#endif /* CONFIG_SAE_PK */
1563
1564 if (bss->ssid_len == 0) {
1565 if (debug_print)
1566 wpa_dbg(wpa_s, MSG_DEBUG,
1567 " skip - no SSID known for the BSS");
1568 return false;
1569 }
1570
1571 /* Matching configuration found */
1572 return true;
1573}
1574
1575
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001576struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1577 int i, struct wpa_bss *bss,
1578 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001579 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001580{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001581 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001582 const u8 *ie;
1583 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001584 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001585 const u8 *match_ssid;
1586 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001587 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001588
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001589 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001590 wpa_ie_len = ie ? ie[1] : 0;
1591
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001592 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001593 rsn_ie_len = ie ? ie[1] : 0;
1594
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001595 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1596 osen = ie != NULL;
1597
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001598 if (debug_print) {
1599 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1600 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1601 i, MAC2STR(bss->bssid),
1602 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1603 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1604 bss->freq,
1605 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1606 " wps" : "",
1607 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1608 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1609 ? " p2p" : "",
1610 osen ? " osen=1" : "");
1611 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001612
Hai Shalom60840252021-02-19 19:02:11 -08001613 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1614 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001615 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001616 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001617 /*
1618 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001619 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001620 * should not be done with multiple enabled networks to
1621 * avoid getting forced to move into a worse ESS on
1622 * single error if there are no other BSSes of the
1623 * current ESS.
1624 */
1625 limit = 0;
1626 }
Hai Shalom60840252021-02-19 19:02:11 -08001627 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001628 if (debug_print) {
1629 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001630 " skip - BSSID ignored (count=%d limit=%d)",
1631 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001632 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001633 return NULL;
1634 }
1635 }
1636
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001637 match_ssid = bss->ssid;
1638 match_ssid_len = bss->ssid_len;
1639 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1640
1641 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001642 if (debug_print)
1643 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001644 return NULL;
1645 }
1646
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001647 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001648 if (debug_print)
1649 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001650 return NULL;
1651 }
1652
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001653 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001654 if (debug_print)
1655 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001656 return NULL;
1657 }
1658
Hai Shalomfdcde762020-04-02 11:19:20 -07001659 if (disabled_freq(wpa_s, bss->freq)) {
1660 if (debug_print)
1661 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1662 return NULL;
1663 }
1664
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001665 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001666 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001667 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001668 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001669 }
1670
1671 /* No matching configuration found */
1672 return NULL;
1673}
1674
1675
1676static struct wpa_bss *
1677wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001678 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001679 struct wpa_ssid **selected_ssid,
1680 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001681{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001682 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001683
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001684 if (wpa_s->current_ssid) {
1685 struct wpa_ssid *ssid;
1686
1687 wpa_dbg(wpa_s, MSG_DEBUG,
1688 "Scan results matching the currently selected network");
1689 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1690 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1691
1692 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1693 only_first_ssid, 0);
1694 if (ssid != wpa_s->current_ssid)
1695 continue;
1696 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1697 " freq=%d level=%d snr=%d est_throughput=%u",
1698 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1699 bss->snr, bss->est_throughput);
1700 }
1701 }
1702
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001703 if (only_first_ssid)
1704 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1705 group->id);
1706 else
1707 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1708 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001709
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001710 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1711 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001712
1713 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001714 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001715 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001716 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001717 if (!*selected_ssid)
1718 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001719 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001720 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001721 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001722 MAC2STR(bss->bssid),
1723 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1724 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001725 }
1726
1727 return NULL;
1728}
1729
1730
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001731struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1732 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001733{
1734 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001735 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001736 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001737 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001738
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001739 if (wpa_s->last_scan_res == NULL ||
1740 wpa_s->last_scan_res_used == 0)
1741 return NULL; /* no scan results from last update */
1742
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001743 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001744 /* check that next_ssid is still valid */
1745 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1746 if (ssid == wpa_s->next_ssid)
1747 break;
1748 }
1749 next_ssid = ssid;
1750 wpa_s->next_ssid = NULL;
1751 }
1752
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001753 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001754 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1755 if (next_ssid && next_ssid->priority ==
1756 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001757 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001758 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001759 if (selected)
1760 break;
1761 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001762 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001763 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001764 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001765 if (selected)
1766 break;
1767 }
1768
Hai Shalom60840252021-02-19 19:02:11 -08001769 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001770 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001771 wpa_dbg(wpa_s, MSG_DEBUG,
1772 "No APs found - clear BSSID ignore list and try again");
1773 wpa_bssid_ignore_clear(wpa_s);
1774 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001775 } else if (selected == NULL)
1776 break;
1777 }
1778
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001779 ssid = *selected_ssid;
1780 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1781 !ssid->passphrase && !ssid->ext_psk) {
1782 const char *field_name, *txt = NULL;
1783
1784 wpa_dbg(wpa_s, MSG_DEBUG,
1785 "PSK/passphrase not yet available for the selected network");
1786
1787 wpas_notify_network_request(wpa_s, ssid,
1788 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1789
1790 field_name = wpa_supplicant_ctrl_req_to_string(
1791 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1792 if (field_name == NULL)
1793 return NULL;
1794
1795 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1796
1797 selected = NULL;
1798 }
1799
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001800 return selected;
1801}
1802
1803
1804static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1805 int timeout_sec, int timeout_usec)
1806{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001807 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001808 /*
1809 * No networks are enabled; short-circuit request so
1810 * we don't wait timeout seconds before transitioning
1811 * to INACTIVE state.
1812 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001813 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1814 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001815 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1816 return;
1817 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001818
1819 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1821}
1822
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001823
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001824int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001825 struct wpa_bss *selected,
1826 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827{
Sunil Ravi77d572f2023-01-17 23:58:31 +00001828 if (wpas_wps_partner_link_overlap_detect(wpa_s) ||
1829 wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1831 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001832 wpas_notify_wps_event_pbc_overlap(wpa_s);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001833 wpa_s->wps_overlap = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001835 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1836 wpa_s->p2p_in_provisioning) {
1837 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1838 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001839 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001840 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841#endif /* CONFIG_P2P */
1842
1843#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001844 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845 wpas_wps_cancel(wpa_s);
1846#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001847 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001848 }
1849
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001850 wpa_msg(wpa_s, MSG_DEBUG,
1851 "Considering connect request: reassociate: %d selected: "
1852 MACSTR " bssid: " MACSTR " pending: " MACSTR
1853 " wpa_state: %s ssid=%p current_ssid=%p",
1854 wpa_s->reassociate, MAC2STR(selected->bssid),
1855 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1856 wpa_supplicant_state_txt(wpa_s->wpa_state),
1857 ssid, wpa_s->current_ssid);
1858
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001859 /*
1860 * Do not trigger new association unless the BSSID has changed or if
1861 * reassociation is requested. If we are in process of associating with
1862 * the selected BSSID, do not trigger new attempt.
1863 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001864 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1866 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1867 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001868 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1869 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1870 0) ||
1871 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1872 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001873 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1874 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001875 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001876 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001877 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1878 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001879 wpa_supplicant_associate(wpa_s, selected, ssid);
1880 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001881 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1882 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001883 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001884
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001885 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001886}
1887
1888
1889static struct wpa_ssid *
1890wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1891{
Hai Shalomfdcde762020-04-02 11:19:20 -07001892 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001893 struct wpa_ssid *ssid;
1894
1895 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1896 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1897 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001898 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001899 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001900#ifndef CONFIG_IBSS_RSN
1901 if (ssid->mode == WPAS_MODE_IBSS &&
1902 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1903 WPA_KEY_MGMT_WPA_NONE))) {
1904 wpa_msg(wpa_s, MSG_INFO,
1905 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1906 wpa_ssid_txt(ssid->ssid,
1907 ssid->ssid_len));
1908 continue;
1909 }
1910#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001911 if (ssid->mode == WPAS_MODE_IBSS ||
1912 ssid->mode == WPAS_MODE_AP ||
1913 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001914 return ssid;
1915 }
1916 }
1917 return NULL;
1918}
1919
1920
1921/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1922 * on BSS added and BSS changed events */
1923static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001924 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001925{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001926 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001927
1928 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1929 return;
1930
Jouni Malinen87fd2792011-05-16 18:35:42 +03001931 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001932 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001933
Jouni Malinen87fd2792011-05-16 18:35:42 +03001934 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001935 if (ssid == NULL)
1936 continue;
1937
Jouni Malinen87fd2792011-05-16 18:35:42 +03001938 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001939 if (rsn == NULL)
1940 continue;
1941
Jouni Malinen87fd2792011-05-16 18:35:42 +03001942 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001943 }
1944
1945}
1946
1947
Hai Shalomfdcde762020-04-02 11:19:20 -07001948#ifndef CONFIG_NO_ROAMING
1949
1950static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1951{
1952 if (noise == WPA_INVALID_NOISE)
1953 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1954 DEFAULT_NOISE_FLOOR_2GHZ;
1955 return avg_signal - noise;
1956}
1957
1958
1959static unsigned int
1960wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1961 const struct wpa_bss *bss, int snr)
1962{
1963 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001964 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001965 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1966
Hai Shalomc1a21442022-02-04 13:43:00 -08001967 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07001968}
1969
Hai Shalomfdcde762020-04-02 11:19:20 -07001970
Hai Shalom899fcc72020-10-19 14:38:18 -07001971int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1972 struct wpa_bss *current_bss,
1973 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001974{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001975 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001976 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001977 int cur_level;
1978 unsigned int cur_est, sel_est;
1979 struct wpa_signal_info si;
1980 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001981 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001982
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001983 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001984 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001985 " freq=%d level=%d snr=%d est_throughput=%u",
1986 MAC2STR(current_bss->bssid),
1987 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001988 current_bss->snr, current_bss->est_throughput);
1989 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001990 " freq=%d level=%d snr=%d est_throughput=%u",
1991 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001992 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001993
1994 if (wpa_s->current_ssid->bssid_set &&
1995 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1996 0) {
1997 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1998 "has preferred BSSID");
1999 return 1;
2000 }
2001
Hai Shalomfdcde762020-04-02 11:19:20 -07002002 cur_level = current_bss->level;
2003 cur_est = current_bss->est_throughput;
2004 sel_est = selected->est_throughput;
2005
2006 /*
2007 * Try to poll the signal from the driver since this will allow to get
2008 * more accurate values. In some cases, there can be big differences
2009 * between the RSSI of the Probe Response frames of the AP we are
2010 * associated with and the Beacon frames we hear from the same AP after
2011 * association. This can happen, e.g., when there are two antennas that
2012 * hear the AP very differently. If the driver chooses to hear the
2013 * Probe Response frames during the scan on the "bad" antenna because
2014 * it wants to save power, but knows to choose the other antenna after
2015 * association, we will hear our AP with a low RSSI as part of the
2016 * scan even when we can hear it decently on the other antenna. To cope
2017 * with this, ask the driver to teach us how it hears the AP. Also, the
2018 * scan results may be a bit old, since we can very quickly get fresh
2019 * information about our currently associated AP.
2020 */
2021 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002022 (si.data.avg_beacon_signal || si.data.avg_signal)) {
2023 cur_level = si.data.avg_beacon_signal ?
2024 si.data.avg_beacon_signal : si.data.avg_signal;
Hai Shalomfdcde762020-04-02 11:19:20 -07002025 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2026 si.current_noise);
2027
2028 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2029 current_bss,
2030 cur_snr);
2031 wpa_dbg(wpa_s, MSG_DEBUG,
2032 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2033 cur_level, cur_snr, cur_est);
2034 }
2035
2036 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002037 wpa_dbg(wpa_s, MSG_DEBUG,
2038 "Allow reassociation - selected BSS has better estimated throughput");
2039 return 1;
2040 }
2041
Dmitry Shmidte4663042016-04-04 10:07:49 -07002042 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
2043
Hai Shalomfdcde762020-04-02 11:19:20 -07002044 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
2045 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002046 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2047 "signal level");
2048 return 0;
2049 }
2050
Hai Shalomfdcde762020-04-02 11:19:20 -07002051 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002052 wpa_dbg(wpa_s, MSG_DEBUG,
2053 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002054 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002055 }
2056
Hai Shalomfdcde762020-04-02 11:19:20 -07002057 if (cur_snr > GREAT_SNR) {
2058 wpa_dbg(wpa_s, MSG_DEBUG,
2059 "Skip roam - Current BSS has good SNR (%u > %u)",
2060 cur_snr, GREAT_SNR);
2061 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002062 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002063
Hai Shalomfdcde762020-04-02 11:19:20 -07002064 if (cur_level < -85) /* ..-86 dBm */
2065 min_diff = 1;
2066 else if (cur_level < -80) /* -85..-81 dBm */
2067 min_diff = 2;
2068 else if (cur_level < -75) /* -80..-76 dBm */
2069 min_diff = 3;
2070 else if (cur_level < -70) /* -75..-71 dBm */
2071 min_diff = 4;
2072 else if (cur_level < 0) /* -70..-1 dBm */
2073 min_diff = 5;
2074 else /* unspecified units (not in dBm) */
2075 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002076
Hai Shalomfdcde762020-04-02 11:19:20 -07002077 if (cur_est > sel_est * 1.5)
2078 min_diff += 10;
2079 else if (cur_est > sel_est * 1.2)
2080 min_diff += 5;
2081 else if (cur_est > sel_est * 1.1)
2082 min_diff += 2;
2083 else if (cur_est > sel_est)
2084 min_diff++;
2085 else if (sel_est > cur_est * 1.5)
2086 min_diff -= 10;
2087 else if (sel_est > cur_est * 1.2)
2088 min_diff -= 5;
2089 else if (sel_est > cur_est * 1.1)
2090 min_diff -= 2;
2091 else if (sel_est > cur_est)
2092 min_diff--;
2093
2094 if (to_5ghz)
2095 min_diff -= 2;
2096 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002097 if (diff < min_diff) {
2098 wpa_dbg(wpa_s, MSG_DEBUG,
2099 "Skip roam - too small difference in signal level (%d < %d)",
2100 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002101 ret = 0;
2102 } else {
2103 wpa_dbg(wpa_s, MSG_DEBUG,
2104 "Allow reassociation due to difference in signal level (%d >= %d)",
2105 diff, min_diff);
2106 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002107 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002108 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2109 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2110 " sel_freq=%d sel_level=%d sel_est=%d",
2111 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2112 MAC2STR(current_bss->bssid),
2113 current_bss->freq, cur_level, cur_est,
2114 MAC2STR(selected->bssid),
2115 selected->freq, selected->level, sel_est);
2116 return ret;
2117}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002118
Hai Shalom899fcc72020-10-19 14:38:18 -07002119#endif /* CONFIG_NO_ROAMING */
2120
2121
2122static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2123 struct wpa_bss *selected,
2124 struct wpa_ssid *ssid)
2125{
2126 struct wpa_bss *current_bss = NULL;
2127
2128 if (wpa_s->reassociate)
2129 return 1; /* explicit request to reassociate */
2130 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2131 return 1; /* we are not associated; continue */
2132 if (wpa_s->current_ssid == NULL)
2133 return 1; /* unknown current SSID */
2134 if (wpa_s->current_ssid != ssid)
2135 return 1; /* different network block */
2136
2137 if (wpas_driver_bss_selection(wpa_s))
2138 return 0; /* Driver-based roaming */
2139
2140 if (wpa_s->current_ssid->ssid)
2141 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2142 wpa_s->current_ssid->ssid,
2143 wpa_s->current_ssid->ssid_len);
2144 if (!current_bss)
2145 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2146
2147 if (!current_bss)
2148 return 1; /* current BSS not seen in scan results */
2149
2150 if (current_bss == selected)
2151 return 0;
2152
2153 if (selected->last_update_idx > current_bss->last_update_idx)
2154 return 1; /* current BSS not seen in the last scan */
2155
2156#ifndef CONFIG_NO_ROAMING
2157 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2158 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002159#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002160 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002161#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162}
2163
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002164
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002165/*
2166 * Return a negative value if no scan results could be fetched or if scan
2167 * results should not be shared with other virtual interfaces.
2168 * Return 0 if scan results were fetched and may be shared with other
2169 * interfaces.
2170 * Return 1 if scan results may be shared with other virtual interfaces but may
2171 * not trigger any operations.
2172 * Return 2 if the interface was removed and cannot be used.
2173 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002174static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002175 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002176 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002177{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002178 struct wpa_scan_results *scan_res = NULL;
2179 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002180 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002181#ifndef CONFIG_NO_RANDOM_POOL
2182 size_t i, num;
2183#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002184
2185#ifdef CONFIG_AP
2186 if (wpa_s->ap_iface)
2187 ap = 1;
2188#endif /* CONFIG_AP */
2189
2190 wpa_supplicant_notify_scanning(wpa_s, 0);
2191
2192 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2193 data ? &data->scan_info :
2194 NULL, 1);
2195 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002196 if (wpa_s->conf->ap_scan == 2 || ap ||
2197 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002198 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002199 if (!own_request)
2200 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002201 if (data && data->scan_info.external_scan)
2202 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002203 if (wpa_s->scan_res_fail_handler) {
2204 void (*handler)(struct wpa_supplicant *wpa_s);
2205
2206 handler = wpa_s->scan_res_fail_handler;
2207 wpa_s->scan_res_fail_handler = NULL;
2208 handler(wpa_s);
2209 } else {
2210 wpa_dbg(wpa_s, MSG_DEBUG,
2211 "Failed to get scan results - try scanning again");
2212 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2213 }
2214
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002215 ret = -1;
2216 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217 }
2218
2219#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002220 num = scan_res->num;
2221 if (num > 10)
2222 num = 10;
2223 for (i = 0; i < num; i++) {
2224 u8 buf[5];
2225 struct wpa_scan_res *res = scan_res->res[i];
2226 buf[0] = res->bssid[5];
2227 buf[1] = res->qual & 0xff;
2228 buf[2] = res->noise & 0xff;
2229 buf[3] = res->level & 0xff;
2230 buf[4] = res->tsf & 0xff;
2231 random_add_randomness(buf, sizeof(buf));
2232 }
2233#endif /* CONFIG_NO_RANDOM_POOL */
2234
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002235 if (update_only) {
2236 ret = 1;
2237 goto scan_work_done;
2238 }
2239
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002240 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002241 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2243 struct wpa_scan_results *scan_res);
2244
2245 scan_res_handler = wpa_s->scan_res_handler;
2246 wpa_s->scan_res_handler = NULL;
2247 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002248 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002249 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002250 }
2251
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002252 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002253 wpa_s->own_scan_running,
2254 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002255 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002256 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2257 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002258 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2259 wpa_s->manual_scan_id);
2260 wpa_s->manual_scan_use_id = 0;
2261 } else {
2262 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2263 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002264 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002265
2266 wpas_notify_scan_done(wpa_s, 1);
2267
Hai Shalomfdcde762020-04-02 11:19:20 -07002268 if (ap) {
2269 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2270#ifdef CONFIG_AP
2271 if (wpa_s->ap_iface->scan_cb)
2272 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2273#endif /* CONFIG_AP */
2274 goto scan_work_done;
2275 }
2276
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002277 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002278 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 -07002279 wpa_scan_results_free(scan_res);
2280 return 0;
2281 }
2282
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002283 if (wnm_scan_process(wpa_s, 1) > 0)
2284 goto scan_work_done;
2285
Hai Shalomc1a21442022-02-04 13:43:00 -08002286 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002287 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002288
Hai Shalom021b0b52019-04-10 11:17:58 -07002289 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002290 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2291 goto scan_work_done;
2292
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002293 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2294 goto scan_work_done;
2295
2296 if (autoscan_notify_scan(wpa_s, scan_res))
2297 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002298
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002299 if (wpa_s->disconnected) {
2300 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002301 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002302 }
2303
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002304 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002305 bgscan_notify_scan(wpa_s, scan_res) == 1)
2306 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002307
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002308 wpas_wps_update_ap_info(wpa_s, scan_res);
2309
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002310 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2311 wpa_s->wpa_state < WPA_COMPLETED)
2312 goto scan_work_done;
2313
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002314 wpa_scan_results_free(scan_res);
2315
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002316 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002317 struct wpa_radio_work *work = wpa_s->scan_work;
2318 wpa_s->scan_work = NULL;
2319 radio_work_done(work);
2320 }
2321
Hai Shalomc3565922019-10-28 11:58:20 -07002322 os_free(wpa_s->last_scan_freqs);
2323 wpa_s->last_scan_freqs = NULL;
2324 wpa_s->num_last_scan_freqs = 0;
2325 if (own_request && data &&
2326 data->scan_info.freqs && data->scan_info.num_freqs) {
2327 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2328 data->scan_info.num_freqs);
2329 if (wpa_s->last_scan_freqs) {
2330 os_memcpy(wpa_s->last_scan_freqs,
2331 data->scan_info.freqs,
2332 sizeof(int) * data->scan_info.num_freqs);
2333 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2334 }
2335 }
2336
Sunil Ravi77d572f2023-01-17 23:58:31 +00002337 if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2338 return ret;
2339
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002340 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002341
2342scan_work_done:
2343 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002344 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002345 struct wpa_radio_work *work = wpa_s->scan_work;
2346 wpa_s->scan_work = NULL;
2347 radio_work_done(work);
2348 }
2349 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002350}
2351
2352
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002353static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002354 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002355{
2356 struct wpa_bss *selected;
2357 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002358 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2359
2360 if (time_to_reenable > 0) {
2361 wpa_dbg(wpa_s, MSG_DEBUG,
2362 "Postpone network selection by %d seconds since all networks are disabled",
2363 time_to_reenable);
2364 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2365 eloop_register_timeout(time_to_reenable, 0,
2366 wpas_network_reenabled, wpa_s, NULL);
2367 return 0;
2368 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002369
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002370 if (wpa_s->p2p_mgmt)
2371 return 0; /* no normal connection on p2p_mgmt interface */
2372
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002373 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002374 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002375
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002376#ifdef CONFIG_MESH
2377 if (wpa_s->ifmsh) {
2378 wpa_msg(wpa_s, MSG_INFO,
2379 "Avoiding join because we already joined a mesh group");
2380 return 0;
2381 }
2382#endif /* CONFIG_MESH */
2383
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384 if (selected) {
2385 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002386 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002387 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002388 if (new_scan)
2389 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002390 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002391 }
2392
Hai Shalomc3565922019-10-28 11:58:20 -07002393 wpa_s->suitable_network++;
2394
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002395 if (ssid != wpa_s->current_ssid &&
2396 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2397 wpa_s->own_disconnect_req = 1;
2398 wpa_supplicant_deauthenticate(
2399 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2400 }
2401
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002402 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002403 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002404 return -1;
2405 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00002406 wpa_s->supp_pbc_active = false;
2407
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002408 if (new_scan)
2409 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002410 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002411 * Do not allow other virtual radios to trigger operations based
2412 * on these scan results since we do not want them to start
2413 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002414 */
2415 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002416 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002417 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2419 ssid = wpa_supplicant_pick_new_network(wpa_s);
2420 if (ssid) {
2421 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2422 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002423 if (new_scan)
2424 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002425 } else if (own_request) {
2426 /*
2427 * No SSID found. If SCAN results are as a result of
2428 * own scan request and not due to a scan request on
2429 * another shared interface, try another scan.
2430 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002431 int timeout_sec = wpa_s->scan_interval;
2432 int timeout_usec = 0;
2433#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002434 int res;
2435
2436 res = wpas_p2p_scan_no_go_seen(wpa_s);
2437 if (res == 2)
2438 return 2;
2439 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002440 return 0;
2441
Sunil Ravi77d572f2023-01-17 23:58:31 +00002442 if (wpas_p2p_retry_limit_exceeded(wpa_s))
Matthew Wang06b42472022-11-10 06:56:31 +00002443 return 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002444
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002445 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002446 wpa_s->show_group_started ||
2447 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002448 /*
2449 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002450 * state and during P2P join-a-group operation
2451 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002452 */
2453 timeout_sec = 0;
2454 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002455 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2456 timeout_usec);
2457 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002458 }
2459#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002460#ifdef CONFIG_INTERWORKING
2461 if (wpa_s->conf->auto_interworking &&
2462 wpa_s->conf->interworking &&
2463 wpa_s->conf->cred) {
2464 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2465 "start ANQP fetch since no matching "
2466 "networks found");
2467 wpa_s->network_select = 1;
2468 wpa_s->auto_network_select = 1;
2469 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002470 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002471 }
2472#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002473#ifdef CONFIG_WPS
2474 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2475 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2476 timeout_sec = 0;
2477 timeout_usec = 500000;
2478 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2479 timeout_usec);
2480 return 0;
2481 }
2482#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002483#ifdef CONFIG_OWE
2484 if (wpa_s->owe_transition_search) {
2485 wpa_dbg(wpa_s, MSG_DEBUG,
2486 "OWE: Use shorter wait during transition mode search");
2487 timeout_sec = 0;
2488 timeout_usec = 500000;
2489 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2490 timeout_usec);
2491 return 0;
2492 }
2493#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002494 if (wpa_supplicant_req_sched_scan(wpa_s))
2495 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2496 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002497
2498 wpa_msg_ctrl(wpa_s, MSG_INFO,
2499 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002500 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002501 }
2502 }
2503 return 0;
2504}
2505
2506
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002507static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2508 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002509{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002510 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002511 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002512
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002513 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002514 if (res == 2) {
2515 /*
2516 * Interface may have been removed, so must not dereference
2517 * wpa_s after this.
2518 */
2519 return 1;
2520 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002521
2522 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002523 /*
2524 * If no scan results could be fetched, then no need to
2525 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002526 * this scan. Similarly, if scan results started a new operation on this
2527 * interface, do not notify other interfaces to avoid concurrent
2528 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002529 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002530 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002531 }
2532
2533 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002534 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002535 * so, they get updated with this same scan info.
2536 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002537 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2538 radio_list) {
2539 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002540 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2541 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002542 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2543 res > 0);
2544 if (res < 0)
2545 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002546 }
2547 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002548
2549 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002550}
2551
2552#endif /* CONFIG_NO_SCAN_PROCESSING */
2553
2554
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002555int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2556{
2557#ifdef CONFIG_NO_SCAN_PROCESSING
2558 return -1;
2559#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002560 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002561
Dmitry Shmidt29333592017-01-09 12:27:11 -08002562 wpa_s->ignore_post_flush_scan_res = 0;
2563
Dmitry Shmidt41712582015-06-29 11:02:15 -07002564 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002565 return -1;
2566
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002567 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002568 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002569 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002570 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2571 return -1;
2572 }
2573
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002574 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002575#endif /* CONFIG_NO_SCAN_PROCESSING */
2576}
2577
Sunil Ravi77d572f2023-01-17 23:58:31 +00002578
2579int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2580{
2581#ifdef CONFIG_NO_SCAN_PROCESSING
2582 return -1;
2583#else /* CONFIG_NO_SCAN_PROCESSING */
2584 return wpas_select_network_from_last_scan(wpa_s, 1, 1);
2585#endif /* CONFIG_NO_SCAN_PROCESSING */
2586}
2587
2588
Dmitry Shmidt04949592012-07-19 12:16:46 -07002589#ifdef CONFIG_WNM
2590
2591static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2592{
2593 struct wpa_supplicant *wpa_s = eloop_ctx;
2594
2595 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2596 return;
2597
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002598 if (!wpa_s->no_keep_alive) {
2599 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2600 MAC2STR(wpa_s->bssid));
2601 /* TODO: could skip this if normal data traffic has been sent */
2602 /* TODO: Consider using some more appropriate data frame for
2603 * this */
2604 if (wpa_s->l2)
2605 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2606 (u8 *) "", 0);
2607 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002608
2609#ifdef CONFIG_SME
2610 if (wpa_s->sme.bss_max_idle_period) {
2611 unsigned int msec;
2612 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2613 if (msec > 100)
2614 msec -= 100;
2615 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2616 wnm_bss_keep_alive, wpa_s, NULL);
2617 }
2618#endif /* CONFIG_SME */
2619}
2620
2621
2622static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2623 const u8 *ies, size_t ies_len)
2624{
2625 struct ieee802_11_elems elems;
2626
2627 if (ies == NULL)
2628 return;
2629
2630 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2631 return;
2632
2633#ifdef CONFIG_SME
2634 if (elems.bss_max_idle_period) {
2635 unsigned int msec;
2636 wpa_s->sme.bss_max_idle_period =
2637 WPA_GET_LE16(elems.bss_max_idle_period);
2638 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2639 "TU)%s", wpa_s->sme.bss_max_idle_period,
2640 (elems.bss_max_idle_period[2] & 0x01) ?
2641 " (protected keep-live required)" : "");
2642 if (wpa_s->sme.bss_max_idle_period == 0)
2643 wpa_s->sme.bss_max_idle_period = 1;
2644 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2645 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2646 /* msec times 1000 */
2647 msec = wpa_s->sme.bss_max_idle_period * 1024;
2648 if (msec > 100)
2649 msec -= 100;
2650 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2651 wnm_bss_keep_alive, wpa_s,
2652 NULL);
2653 }
2654 }
2655#endif /* CONFIG_SME */
2656}
2657
2658#endif /* CONFIG_WNM */
2659
2660
2661void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2662{
2663#ifdef CONFIG_WNM
2664 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2665#endif /* CONFIG_WNM */
2666}
2667
2668
Dmitry Shmidt051af732013-10-22 13:52:46 -07002669#ifdef CONFIG_INTERWORKING
2670
2671static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2672 size_t len)
2673{
2674 int res;
2675
2676 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2677 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2678 if (res) {
2679 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2680 }
2681
2682 return res;
2683}
2684
2685
2686static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2687 const u8 *ies, size_t ies_len)
2688{
2689 struct ieee802_11_elems elems;
2690
2691 if (ies == NULL)
2692 return;
2693
2694 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2695 return;
2696
2697 if (elems.qos_map_set) {
2698 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2699 elems.qos_map_set_len);
2700 }
2701}
2702
2703#endif /* CONFIG_INTERWORKING */
2704
2705
Hai Shalom74f70d42019-02-11 14:42:39 -08002706static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2707 const u8 *ies, size_t ies_len)
2708{
2709 struct ieee802_11_elems elems;
2710 const u8 *map_sub_elem, *pos;
2711 size_t len;
2712
Hai Shalomfdcde762020-04-02 11:19:20 -07002713 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002714
Hai Shalomfdcde762020-04-02 11:19:20 -07002715 if (!ies ||
2716 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2717 !elems.multi_ap || elems.multi_ap_len < 7)
2718 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002719
2720 pos = elems.multi_ap + 4;
2721 len = elems.multi_ap_len - 4;
2722
2723 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002724 if (!map_sub_elem || map_sub_elem[1] < 1)
2725 return;
2726
2727 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2728 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2729 MULTI_AP_FRONTHAUL_BSS);
2730 wpa_s->multi_ap_ie = 1;
2731}
2732
2733
2734static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2735{
2736 if (!wpa_s->current_ssid ||
2737 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2738 return;
2739
2740 if (!wpa_s->multi_ap_ie) {
2741 wpa_printf(MSG_INFO,
2742 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002743 goto fail;
2744 }
2745
Hai Shalomfdcde762020-04-02 11:19:20 -07002746 if (!wpa_s->multi_ap_backhaul) {
2747 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002748 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2749 wpa_printf(MSG_INFO,
2750 "WPS active, accepting fronthaul-only BSS");
2751 /* Don't set 4addr mode in this case, so just return */
2752 return;
2753 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002754 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2755 goto fail;
2756 }
2757
2758 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2759 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2760 goto fail;
2761 }
2762 wpa_s->enabled_4addr_mode = 1;
2763 return;
2764
2765fail:
2766 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2767}
2768
2769
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002770#ifdef CONFIG_FST
2771static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2772 const u8 *ie, size_t ie_len)
2773{
2774 struct mb_ies_info mb_ies;
2775
2776 if (!ie || !ie_len || !wpa_s->fst)
2777 return -ENOENT;
2778
2779 os_memset(&mb_ies, 0, sizeof(mb_ies));
2780
2781 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2782 size_t len;
2783
2784 len = 2 + ie[1];
2785 if (len > ie_len) {
2786 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2787 ie, ie_len);
2788 break;
2789 }
2790
2791 if (ie[0] == WLAN_EID_MULTI_BAND) {
2792 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2793 (unsigned int) len);
2794 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2795 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2796 mb_ies.nof_ies++;
2797 }
2798
2799 ie_len -= len;
2800 ie += len;
2801 }
2802
2803 if (mb_ies.nof_ies > 0) {
2804 wpabuf_free(wpa_s->received_mb_ies);
2805 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2806 return 0;
2807 }
2808
2809 return -ENOENT;
2810}
2811#endif /* CONFIG_FST */
2812
2813
Hai Shalomc1a21442022-02-04 13:43:00 -08002814static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2815 union wpa_event_data *data)
2816{
2817 int sel;
2818 const u8 *p;
2819 int l, len;
2820 bool found = false;
2821 struct wpa_ie_data ie;
2822 struct wpa_ssid *ssid = wpa_s->current_ssid;
2823 struct wpa_bss *bss = wpa_s->current_bss;
2824 int pmf;
2825
2826 if (!ssid)
2827 return 0;
2828
2829 p = data->assoc_info.req_ies;
2830 l = data->assoc_info.req_ies_len;
2831
2832 while (p && l >= 2) {
2833 len = p[1] + 2;
2834 if (len > l) {
2835 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2836 p, l);
2837 break;
2838 }
2839 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2840 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2841 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2842 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2843 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2844 found = true;
2845 break;
2846 }
2847 l -= len;
2848 p += len;
2849 }
2850
2851 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2852 return 0;
2853
2854 wpa_hexdump(MSG_DEBUG,
2855 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2856 p, l);
2857
2858 /* Update proto from (Re)Association Request frame info */
2859 wpa_s->wpa_proto = ie.proto;
2860 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2861 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2862 !!(wpa_s->wpa_proto &
2863 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2864
2865 /* Update AKMP suite from (Re)Association Request frame info */
2866 sel = ie.key_mgmt;
2867 if (ssid->key_mgmt)
2868 sel &= ssid->key_mgmt;
2869
2870 wpa_dbg(wpa_s, MSG_DEBUG,
2871 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2872 ie.key_mgmt, ssid->key_mgmt, sel);
2873 if (ie.key_mgmt && !sel) {
2874 wpa_supplicant_deauthenticate(
2875 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2876 return -1;
2877 }
2878
Sunil Ravi89eba102022-09-13 21:04:37 -07002879 /*
2880 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
2881 * different AKM.
2882 */
2883 if (wpa_s->key_mgmt != ie.key_mgmt &&
2884 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
2885 if (!ssid->psk_set) {
2886 wpa_dbg(wpa_s, MSG_INFO,
2887 "No PSK available for association");
Sunil Ravi77d572f2023-01-17 23:58:31 +00002888 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
Sunil Ravi89eba102022-09-13 21:04:37 -07002889 return -1;
2890 }
2891
2892 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
2893 if (wpa_s->conf->key_mgmt_offload &&
2894 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00002895 wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
2896 ssid->psk, PMK_LEN, KEY_FLAG_PMK))
Sunil Ravi89eba102022-09-13 21:04:37 -07002897 wpa_dbg(wpa_s, MSG_ERROR,
2898 "WPA: Cannot set PMK for key management offload");
2899 }
2900
Hai Shalomc1a21442022-02-04 13:43:00 -08002901 wpa_s->key_mgmt = ie.key_mgmt;
2902 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2903 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2904 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2905 wpa_s->wpa_proto);
2906
2907 /* Update pairwise cipher from (Re)Association Request frame info */
2908 sel = ie.pairwise_cipher;
2909 if (ssid->pairwise_cipher)
2910 sel &= ssid->pairwise_cipher;
2911
2912 wpa_dbg(wpa_s, MSG_DEBUG,
2913 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2914 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2915 if (ie.pairwise_cipher && !sel) {
2916 wpa_supplicant_deauthenticate(
2917 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2918 return -1;
2919 }
2920
2921 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2922 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2923 wpa_s->pairwise_cipher);
2924 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2925 wpa_cipher_txt(wpa_s->pairwise_cipher));
2926
2927 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2928 if (!bss) {
2929 wpa_dbg(wpa_s, MSG_DEBUG,
2930 "WPA: current_bss == NULL - skip AP IE check");
2931 return 0;
2932 }
2933
2934 /* Update GTK and IGTK from AP's RSNE */
2935 found = false;
2936
2937 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2938 const u8 *bss_rsn;
2939
2940 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2941 if (bss_rsn) {
2942 p = bss_rsn;
2943 len = 2 + bss_rsn[1];
2944 found = true;
2945 }
2946 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2947 const u8 *bss_wpa;
2948
2949 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2950 if (bss_wpa) {
2951 p = bss_wpa;
2952 len = 2 + bss_wpa[1];
2953 found = true;
2954 }
2955 }
2956
2957 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2958 return 0;
2959
2960 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2961 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2962 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
2963 /* AP does not support MFP, local configuration requires it */
2964 wpa_supplicant_deauthenticate(
2965 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2966 return -1;
2967 }
2968 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
2969 pmf == NO_MGMT_FRAME_PROTECTION) {
2970 /* AP requires MFP, local configuration disables it */
2971 wpa_supplicant_deauthenticate(
2972 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2973 return -1;
2974 }
2975
2976 /* Update PMF from local configuration now that MFP validation was done
2977 * above */
2978 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
2979
2980 /* Update GTK from AP's RSNE */
2981 sel = ie.group_cipher;
2982 if (ssid->group_cipher)
2983 sel &= ssid->group_cipher;
2984
2985 wpa_dbg(wpa_s, MSG_DEBUG,
2986 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
2987 ie.group_cipher, ssid->group_cipher, sel);
2988 if (ie.group_cipher && !sel) {
2989 wpa_supplicant_deauthenticate(
2990 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
2991 return -1;
2992 }
2993
2994 wpa_s->group_cipher = ie.group_cipher;
2995 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
2996 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
2997 wpa_cipher_txt(wpa_s->group_cipher));
2998
2999 /* Update IGTK from AP RSN IE */
3000 sel = ie.mgmt_group_cipher;
3001 if (ssid->group_mgmt_cipher)
3002 sel &= ssid->group_mgmt_cipher;
3003
3004 wpa_dbg(wpa_s, MSG_DEBUG,
3005 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3006 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3007
3008 if (pmf == NO_MGMT_FRAME_PROTECTION ||
3009 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3010 wpa_dbg(wpa_s, MSG_DEBUG,
3011 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3012 ie.capabilities);
3013 ie.mgmt_group_cipher = 0;
3014 }
3015
3016 if (ie.mgmt_group_cipher && !sel) {
3017 wpa_supplicant_deauthenticate(
3018 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3019 return -1;
3020 }
3021
3022 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3023 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3024 wpa_s->mgmt_group_cipher);
3025 if (wpa_s->mgmt_group_cipher)
3026 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3027 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3028 else
3029 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3030
3031 return 0;
3032}
3033
3034
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003035static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3036 union wpa_event_data *data)
3037{
Hai Shalomc3565922019-10-28 11:58:20 -07003038 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003039 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003040 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003041 bool bssid_known;
Winnie Chen4138eec2022-11-10 16:32:53 +08003042#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303043 struct wpa_ie_data ie;
Winnie Chen4138eec2022-11-10 16:32:53 +08003044#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003045
3046 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07003047 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003048 if (data->assoc_info.req_ies)
3049 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3050 data->assoc_info.req_ies_len);
3051 if (data->assoc_info.resp_ies) {
3052 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3053 data->assoc_info.resp_ies_len);
3054#ifdef CONFIG_TDLS
3055 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3056 data->assoc_info.resp_ies_len);
3057#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003058#ifdef CONFIG_WNM
3059 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3060 data->assoc_info.resp_ies_len);
3061#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003062#ifdef CONFIG_INTERWORKING
3063 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3064 data->assoc_info.resp_ies_len);
3065#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003066 if (wpa_s->hw_capab == CAPAB_VHT &&
3067 get_ie(data->assoc_info.resp_ies,
3068 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3069 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003070
3071 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3072 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073 }
3074 if (data->assoc_info.beacon_ies)
3075 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3076 data->assoc_info.beacon_ies,
3077 data->assoc_info.beacon_ies_len);
3078 if (data->assoc_info.freq)
3079 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3080 data->assoc_info.freq);
3081
Hai Shalom021b0b52019-04-10 11:17:58 -07003082 wpa_s->connection_set = 0;
3083 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3084 struct ieee802_11_elems req_elems, resp_elems;
3085
3086 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3087 data->assoc_info.req_ies_len,
3088 &req_elems, 0) != ParseFailed &&
3089 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3090 data->assoc_info.resp_ies_len,
3091 &resp_elems, 0) != ParseFailed) {
3092 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003093 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3094 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003095 wpa_s->connection_ht = req_elems.ht_capabilities &&
3096 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003097 /* Do not include subset of VHT on 2.4 GHz vendor
3098 * extension in consideration for reporting VHT
3099 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003100 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003101 resp_elems.vht_capabilities &&
3102 (!data->assoc_info.freq ||
3103 wpas_freq_to_band(data->assoc_info.freq) !=
3104 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003105 wpa_s->connection_he = req_elems.he_capabilities &&
3106 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003107 wpa_s->connection_eht = req_elems.eht_capabilities &&
3108 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003109
3110 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3111 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3112 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3113 max_nss_rx_req : max_nss_rx_resp;
3114 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3115 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3116 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3117 max_nss_tx_req : max_nss_tx_resp;
3118
3119 struct supported_chan_width sta_supported_chan_width =
3120 get_supported_channel_width(&req_elems);
3121 enum chan_width ap_operation_chan_width =
3122 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303123 if (wpa_s->connection_vht || wpa_s->connection_he ||
3124 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003125 wpa_s->connection_channel_bandwidth =
3126 get_sta_operation_chan_width(ap_operation_chan_width,
3127 sta_supported_chan_width);
3128 } else if (wpa_s->connection_ht) {
3129 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3130 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3131 } else {
3132 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3133 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003134 }
3135 }
3136
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003137 p = data->assoc_info.req_ies;
3138 l = data->assoc_info.req_ies_len;
3139
3140 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3141 while (p && l >= 2) {
3142 len = p[1] + 2;
3143 if (len > l) {
3144 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3145 p, l);
3146 break;
3147 }
Hai Shalomc3565922019-10-28 11:58:20 -07003148 if (!found &&
3149 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3150 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3151 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3152 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3153 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3155 break;
3156 found = 1;
3157 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07003158 }
3159 if (!found_x && p[0] == WLAN_EID_RSNX) {
3160 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3161 break;
3162 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003163 }
3164 l -= len;
3165 p += len;
3166 }
3167 if (!found && data->assoc_info.req_ies)
3168 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003169 if (!found_x && data->assoc_info.req_ies)
3170 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003171
Winnie Chen4138eec2022-11-10 16:32:53 +08003172#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawad14709082022-03-17 14:25:11 +05303173 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3174 * to a different security type, update the current supplicant configuration to use the AKM
3175 * and pairwise suites from the assoc IE passed by the driver.
3176 */
3177 if (wpas_driver_bss_selection(wpa_s)) {
3178 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3179 /* Check if firmware has roamed to a different security network */
3180 if(wpa_s->key_mgmt != ie.key_mgmt) {
3181 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3182 ie.key_mgmt);
3183 wpa_s->key_mgmt = ie.key_mgmt;
3184 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3185
3186 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3187 /* Restore PMK as it can get overwritten if the previous
3188 * association was to 802.1X.
3189 */
3190 if ((!(wpa_s->drv_flags &
3191 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3192 (wpa_s->current_ssid) &&
3193 (wpa_s->current_ssid->psk_set)) {
3194 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3195 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3196 "BSSID");
3197 wpa_supplicant_deauthenticate(
3198 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3199 return -1;
3200 }
3201 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3202 PMK_LEN, NULL, bssid);
3203 }
3204 }
3205 }
3206 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3207 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3208 "from Assoc IE", ie.pairwise_cipher);
3209 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3210 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3211 wpa_s->pairwise_cipher);
3212 }
3213 // TODO: Notify the framework about security type change b/230766005
3214 }
3215 }
Winnie Chen4138eec2022-11-10 16:32:53 +08003216#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Vinayak Yadawad14709082022-03-17 14:25:11 +05303217
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003218#ifdef CONFIG_FILS
3219#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003220 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3221 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003222 (!data->assoc_info.resp_frame ||
3223 fils_process_assoc_resp(wpa_s->wpa,
3224 data->assoc_info.resp_frame,
3225 data->assoc_info.resp_frame_len) < 0)) {
3226 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3227 return -1;
3228 }
3229#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003230
3231 /* Additional processing for FILS when SME is in driver */
3232 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3233 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3234 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003235#endif /* CONFIG_FILS */
3236
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003237#ifdef CONFIG_OWE
3238 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003239 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003240 owe_process_assoc_resp(wpa_s->wpa, bssid,
3241 data->assoc_info.resp_ies,
3242 data->assoc_info.resp_ies_len) < 0)) {
3243 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3244 return -1;
3245 }
3246#endif /* CONFIG_OWE */
3247
Hai Shalom021b0b52019-04-10 11:17:58 -07003248#ifdef CONFIG_DPP2
3249 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003250 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3251 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003252 struct ieee802_11_elems elems;
3253
3254 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3255 data->assoc_info.resp_ies_len,
3256 &elems, 0) == ParseFailed ||
3257 !elems.owe_dh)
3258 goto no_pfs;
3259 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3260 elems.owe_dh_len) < 0) {
3261 wpa_supplicant_deauthenticate(wpa_s,
3262 WLAN_REASON_UNSPECIFIED);
3263 return -1;
3264 }
3265
3266 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3267 }
3268no_pfs:
3269#endif /* CONFIG_DPP2 */
3270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003271#ifdef CONFIG_IEEE80211R
3272#ifdef CONFIG_SME
3273 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003274 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003275 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3276 data->assoc_info.resp_ies,
3277 data->assoc_info.resp_ies_len,
3278 bssid) < 0) {
3279 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3280 "Reassociation Response failed");
3281 wpa_supplicant_deauthenticate(
3282 wpa_s, WLAN_REASON_INVALID_IE);
3283 return -1;
3284 }
3285 }
3286
3287 p = data->assoc_info.resp_ies;
3288 l = data->assoc_info.resp_ies_len;
3289
3290#ifdef CONFIG_WPS_STRICT
3291 if (p && wpa_s->current_ssid &&
3292 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3293 struct wpabuf *wps;
3294 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3295 if (wps == NULL) {
3296 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3297 "include WPS IE in (Re)Association Response");
3298 return -1;
3299 }
3300
3301 if (wps_validate_assoc_resp(wps) < 0) {
3302 wpabuf_free(wps);
3303 wpa_supplicant_deauthenticate(
3304 wpa_s, WLAN_REASON_INVALID_IE);
3305 return -1;
3306 }
3307 wpabuf_free(wps);
3308 }
3309#endif /* CONFIG_WPS_STRICT */
3310
3311 /* Go through the IEs and make a copy of the MDIE, if present. */
3312 while (p && l >= 2) {
3313 len = p[1] + 2;
3314 if (len > l) {
3315 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3316 p, l);
3317 break;
3318 }
3319 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3320 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3321 wpa_s->sme.ft_used = 1;
3322 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3323 MOBILITY_DOMAIN_ID_LEN);
3324 break;
3325 }
3326 l -= len;
3327 p += len;
3328 }
3329#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003330#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303331 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3332 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3333 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3334 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303335 wpa_ft_is_completed(wpa_s->wpa)) {
3336 return 0;
3337 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003338#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003339
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003340 /* Process FT when SME is in the driver */
3341 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3342 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003343 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003344 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3345 data->assoc_info.resp_ies,
3346 data->assoc_info.resp_ies_len,
3347 bssid) < 0) {
3348 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3349 "Reassociation Response failed");
3350 wpa_supplicant_deauthenticate(
3351 wpa_s, WLAN_REASON_INVALID_IE);
3352 return -1;
3353 }
3354 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3355 }
3356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003357 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3358 data->assoc_info.resp_ies_len);
3359#endif /* CONFIG_IEEE80211R */
3360
Hai Shalom899fcc72020-10-19 14:38:18 -07003361 if (bssid_known)
3362 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3363 data->assoc_info.resp_ies,
3364 data->assoc_info.resp_ies_len);
3365
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003366 /* WPA/RSN IE from Beacon/ProbeResp */
3367 p = data->assoc_info.beacon_ies;
3368 l = data->assoc_info.beacon_ies_len;
3369
3370 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3371 */
3372 wpa_found = rsn_found = 0;
3373 while (p && l >= 2) {
3374 len = p[1] + 2;
3375 if (len > l) {
3376 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3377 p, l);
3378 break;
3379 }
3380 if (!wpa_found &&
3381 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3382 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3383 wpa_found = 1;
3384 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3385 }
3386
3387 if (!rsn_found &&
3388 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3389 rsn_found = 1;
3390 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3391 }
3392
Hai Shalomc3565922019-10-28 11:58:20 -07003393 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3394 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003396 l -= len;
3397 p += len;
3398 }
3399
3400 if (!wpa_found && data->assoc_info.beacon_ies)
3401 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003402 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003403 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003404 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3405 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003406 if (wpa_found || rsn_found)
3407 wpa_s->ap_ies_from_associnfo = 1;
3408
Jouni Malinen87fd2792011-05-16 18:35:42 +03003409 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3410 wpa_s->assoc_freq != data->assoc_info.freq) {
3411 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3412 "%u to %u MHz",
3413 wpa_s->assoc_freq, data->assoc_info.freq);
3414 wpa_supplicant_update_scan_results(wpa_s);
3415 }
3416
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003417 wpa_s->assoc_freq = data->assoc_info.freq;
3418
Hai Shalomc1a21442022-02-04 13:43:00 -08003419 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3420 data->assoc_info.resp_ies_len);
3421
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003422 return 0;
3423}
3424
3425
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003426static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3427{
Hai Shalomc3565922019-10-28 11:58:20 -07003428 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003429
3430 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3431 return -1;
3432
3433 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3434 return 0;
3435
3436 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3437 WPA_IE_VENDOR_TYPE);
3438 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003439 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003440
3441 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3442 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3443 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003444 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3445 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3446 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003447 return -1;
3448
3449 return 0;
3450}
3451
3452
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003453static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3454 union wpa_event_data *data)
3455{
3456#ifdef CONFIG_FST
3457 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3458 struct wpa_bss *bss = wpa_s->current_bss;
3459 const u8 *ieprb, *iebcn;
3460
3461 wpabuf_free(wpa_s->received_mb_ies);
3462 wpa_s->received_mb_ies = NULL;
3463
3464 if (ai &&
3465 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3466 wpa_printf(MSG_DEBUG,
3467 "FST: MB IEs updated from Association Response frame");
3468 return;
3469 }
3470
3471 if (ai &&
3472 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3473 wpa_printf(MSG_DEBUG,
3474 "FST: MB IEs updated from association event Beacon IEs");
3475 return;
3476 }
3477
3478 if (!bss)
3479 return;
3480
Hai Shalom60840252021-02-19 19:02:11 -08003481 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003482 iebcn = ieprb + bss->ie_len;
3483
3484 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3485 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3486 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3487 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3488#endif /* CONFIG_FST */
3489}
3490
3491
Sunil Ravi89eba102022-09-13 21:04:37 -07003492static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3493{
3494 struct driver_sta_mlo_info mlo;
3495 int i;
3496
Sunil Ravi77d572f2023-01-17 23:58:31 +00003497 os_memset(&mlo, 0, sizeof(mlo));
Sunil Ravi89eba102022-09-13 21:04:37 -07003498 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3499 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3500 wpa_supplicant_deauthenticate(wpa_s,
3501 WLAN_REASON_DEAUTH_LEAVING);
3502 return -1;
3503 }
3504
3505 if (wpa_s->valid_links == mlo.valid_links) {
3506 bool match = true;
3507
3508 if (!mlo.valid_links)
3509 return 0;
3510
3511 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3512 if (!(mlo.valid_links & BIT(i)))
3513 continue;
3514
3515 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3516 ETH_ALEN) != 0 ||
3517 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3518 ETH_ALEN) != 0) {
3519 match = false;
3520 break;
3521 }
3522 }
3523
Sunil Ravi77d572f2023-01-17 23:58:31 +00003524 if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
Sunil Ravi89eba102022-09-13 21:04:37 -07003525 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3526 ETH_ALEN) == 0)
3527 return 0;
3528 }
3529
3530 wpa_s->valid_links = mlo.valid_links;
Sunil Ravi77d572f2023-01-17 23:58:31 +00003531 wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
Sunil Ravi89eba102022-09-13 21:04:37 -07003532 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3533 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3534 if (!(wpa_s->valid_links & BIT(i)))
3535 continue;
3536
3537 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3538 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3539 wpa_s->links[i].freq = mlo.links[i].freq;
3540 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3541 }
3542
3543 return 0;
3544}
3545
3546
Sunil Ravi77d572f2023-01-17 23:58:31 +00003547static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
3548{
3549 struct driver_sta_mlo_info drv_mlo;
3550 struct wpa_sm_mlo wpa_mlo;
3551 const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
3552 int i;
3553
3554 os_memset(&drv_mlo, 0, sizeof(drv_mlo));
3555 if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
3556 wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
3557 return -1;
3558 }
3559
3560 os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
3561 if (!drv_mlo.valid_links)
3562 goto out;
3563
3564 os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
3565 wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
3566 wpa_mlo.valid_links = drv_mlo.valid_links;
3567 wpa_mlo.req_links = drv_mlo.req_links;
3568
3569 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3570 struct wpa_bss *bss;
3571
3572 if (!(drv_mlo.req_links & BIT(i)))
3573 continue;
3574
3575 bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
3576 if (!bss) {
3577 wpa_supplicant_update_scan_results(wpa_s);
3578 bss = wpa_supplicant_get_new_bss(
3579 wpa_s, drv_mlo.links[i].bssid);
3580 }
3581
3582 if (!bss) {
3583 wpa_dbg(wpa_s, MSG_INFO,
3584 "Failed to get MLO link %d BSS", i);
3585 return -1;
3586 }
3587
3588 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3589 bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
3590
3591 wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
3592 wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
3593 wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
3594 wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
3595
3596 os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
3597 ETH_ALEN);
3598 os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
3599 ETH_ALEN);
3600 }
3601
3602out:
3603 return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
3604}
3605
3606
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003607static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3608 union wpa_event_data *data)
3609{
3610 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003611 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003612 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003613#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3614 struct wpa_bss *bss;
3615#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003616#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303617 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003618#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003619
3620#ifdef CONFIG_AP
3621 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003622 if (!data)
3623 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003624 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3625 data->assoc_info.addr,
3626 data->assoc_info.req_ies,
3627 data->assoc_info.req_ies_len,
3628 data->assoc_info.reassoc);
3629 return;
3630 }
3631#endif /* CONFIG_AP */
3632
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003633 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003634 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003635
Andy Kuoaba17c12022-04-14 16:05:31 +08003636#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303637 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3638 struct wpa_ft_ies parse;
3639 /* Check for FT reassociation is done by the driver */
3640#ifdef CONFIG_IEEE80211R
3641 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303642 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303643 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3644 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3645 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3646 return;
3647 }
3648 if (parse.rsn_pmkid != NULL) {
3649 wpa_set_ft_completed(wpa_s->wpa);
3650 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3651 }
3652 }
3653#endif /* CONFIG_IEEE80211R */
3654 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003655#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303656
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003657 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003658
3659 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3660 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3661 wpa_supplicant_deauthenticate(
3662 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3663 return;
3664 }
3665
Sunil Ravi89eba102022-09-13 21:04:37 -07003666 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3667 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3668 wpa_supplicant_deauthenticate(wpa_s,
3669 WLAN_REASON_DEAUTH_LEAVING);
3670 return;
3671 }
3672
Sunil Ravia04bd252022-05-02 22:54:18 -07003673 if (ft_completed &&
3674 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3675 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3676 MAC2STR(bssid));
3677 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3678 wpa_printf(MSG_ERROR,
3679 "Can't find target AP's information!");
3680 return;
3681 }
3682 wpa_supplicant_assoc_update_ie(wpa_s);
3683 }
3684
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003685 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3686 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003687 /*
3688 * FILS authentication can share the same mechanism to mark the
3689 * connection fully authenticated, so set ft_completed also based on
3690 * FILS result.
3691 */
3692 if (!ft_completed)
3693 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003694
Andy Kuoaba17c12022-04-14 16:05:31 +08003695#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303696 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3697 /*
3698 * For driver based roaming, insert PSK during
3699 * the initial association
3700 */
3701 if (is_zero_ether_addr(wpa_s->bssid) &&
3702 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3703 /*
3704 * In case the driver wants to handle re-assocs,
3705 * pass it down the PMK.
3706 */
3707 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3708 wpa_sm_install_pmk(wpa_s->wpa);
3709 }
Mir Ali677e7482020-11-12 19:49:02 +05303710 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303711#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003713 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003714 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003715 if (os_reltime_initialized(&wpa_s->session_start)) {
3716 os_reltime_age(&wpa_s->session_start,
3717 &wpa_s->session_length);
3718 wpa_s->session_start.sec = 0;
3719 wpa_s->session_start.usec = 0;
3720 wpas_notify_session_length(wpa_s);
3721 } else {
3722 wpas_notify_auth_changed(wpa_s);
3723 os_get_reltime(&wpa_s->session_start);
3724 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003725 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3726 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003727 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003728 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003729 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3730 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003731 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003732
3733 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3734 wpa_clear_keys(wpa_s, bssid);
3735 }
Sunil Ravi77d572f2023-01-17 23:58:31 +00003736 if (wpa_supplicant_select_config(wpa_s, data) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003737 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003738 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3739 return;
3740 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003741 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003742
Hai Shalomc1a21442022-02-04 13:43:00 -08003743 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3744 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3745 return;
3746
Hai Shalomfdcde762020-04-02 11:19:20 -07003747 multi_ap_set_4addr_mode(wpa_s);
3748
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003749 if (wpa_s->conf->ap_scan == 1 &&
3750 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003751 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3752 wpa_msg(wpa_s, MSG_WARNING,
3753 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003754 }
3755
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003756 wpas_fst_update_mb_assoc(wpa_s, data);
3757
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003758#ifdef CONFIG_SME
3759 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3760 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003761 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003762#endif /* CONFIG_SME */
3763
3764 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3765 if (wpa_s->current_ssid) {
3766 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3767 * initialized before association, but for other modes,
3768 * initialize PC/SC here, if the current configuration needs
3769 * smartcard or SIM/USIM. */
3770 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3771 }
3772 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
Sunil Ravi77d572f2023-01-17 23:58:31 +00003773
3774 if (wpa_sm_set_ml_info(wpa_s)) {
3775 wpa_dbg(wpa_s, MSG_INFO,
3776 "Failed to set MLO connection info to wpa_sm");
3777 wpa_supplicant_deauthenticate(wpa_s,
3778 WLAN_REASON_DEAUTH_LEAVING);
3779 return;
3780 }
3781
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003782 if (wpa_s->l2)
3783 l2_packet_notify_auth_start(wpa_s->l2);
3784
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003785 already_authorized = data && data->assoc_info.authorized;
3786
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003787 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003788 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003789 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3790 * state machine may transit to AUTHENTICATING state based on obsolete
3791 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3792 * AUTHENTICATED without ever giving chance to EAP state machine to
3793 * reset the state.
3794 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003795 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003796 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3797 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003798 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003799 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3800 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3801 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003802 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003803 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003804 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003805 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003806 wpa_s->eapol_received = 0;
3807 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3808 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3809 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003810 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003811 if (wpa_s->current_ssid &&
3812 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003813 (wpa_s->drv_flags &
3814 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3815 /*
3816 * Set the key after having received joined-IBSS event
3817 * from the driver.
3818 */
3819 wpa_supplicant_set_wpa_none_key(wpa_s,
3820 wpa_s->current_ssid);
3821 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003822 wpa_supplicant_cancel_auth_timeout(wpa_s);
3823 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3824 } else if (!ft_completed) {
3825 /* Timeout for receiving the first EAPOL packet */
3826 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3827 }
3828 wpa_supplicant_cancel_scan(wpa_s);
3829
Hai Shalom5f92bc92019-04-18 11:54:11 -07003830 if (ft_completed) {
3831 /*
3832 * FT protocol completed - make sure EAPOL state machine ends
3833 * up in authenticated.
3834 */
3835 wpa_supplicant_cancel_auth_timeout(wpa_s);
3836 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003837 eapol_sm_notify_portValid(wpa_s->eapol, true);
3838 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003839 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3840 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303841 if (already_authorized) {
3842 /*
3843 * We are done; the driver will take care of RSN 4-way
3844 * handshake.
3845 */
3846 wpa_supplicant_cancel_auth_timeout(wpa_s);
3847 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3848 eapol_sm_notify_portValid(wpa_s->eapol, true);
3849 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3850 } else {
Sunil Ravi77d572f2023-01-17 23:58:31 +00003851 /* Update port, WPA_COMPLETED state from the
3852 * EVENT_PORT_AUTHORIZED handler when the driver is done
3853 * with the 4-way handshake.
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303854 */
Sunil Ravi77d572f2023-01-17 23:58:31 +00003855 wpa_msg(wpa_s, MSG_INFO,
3856 "ASSOC INFO: wait for driver port authorized indication");
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303857 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003858 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003859 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3860 /*
3861 * The driver will take care of RSN 4-way handshake, so we need
3862 * to allow EAPOL supplicant to complete its work without
3863 * waiting for WPA supplicant.
3864 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003865 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003866 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003867#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303868 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3869 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3870 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3871 wpa_s->key_mgmt);
3872 wpa_supplicant_deauthenticate(
3873 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3874 return;
3875 }
3876 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3877 wpa_s->assoc_freq = data->assoc_info.freq;
3878 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3879 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003880#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3881
Jouni Malinena05074c2012-12-21 21:35:35 +02003882 wpa_s->last_eapol_matches_bssid = 0;
3883
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003884#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003885 if (wpa_s->rsne_override_eapol) {
3886 wpa_printf(MSG_DEBUG,
3887 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3888 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3889 wpabuf_head(wpa_s->rsne_override_eapol),
3890 wpabuf_len(wpa_s->rsne_override_eapol));
3891 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003892 if (wpa_s->rsnxe_override_eapol) {
3893 wpa_printf(MSG_DEBUG,
3894 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3895 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3896 wpabuf_head(wpa_s->rsnxe_override_eapol),
3897 wpabuf_len(wpa_s->rsnxe_override_eapol));
3898 }
3899#endif /* CONFIG_TESTING_OPTIONS */
3900
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003901 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003902 struct os_reltime now, age;
3903 os_get_reltime(&now);
3904 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003905 if (age.sec == 0 && age.usec < 200000 &&
Sunil Ravi77d572f2023-01-17 23:58:31 +00003906 os_memcmp(wpa_s->pending_eapol_rx_src,
3907 wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid,
3908 ETH_ALEN) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003909 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3910 "frame that was received just before "
3911 "association notification");
3912 wpa_supplicant_rx_eapol(
3913 wpa_s, wpa_s->pending_eapol_rx_src,
3914 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00003915 wpabuf_len(wpa_s->pending_eapol_rx),
3916 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003917 }
3918 wpabuf_free(wpa_s->pending_eapol_rx);
3919 wpa_s->pending_eapol_rx = NULL;
3920 }
3921
Hai Shalomfdcde762020-04-02 11:19:20 -07003922#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003923 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3924 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003925 wpa_s->current_ssid &&
3926 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003927 /* Set static WEP keys again */
3928 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3929 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003930#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003931
3932#ifdef CONFIG_IBSS_RSN
3933 if (wpa_s->current_ssid &&
3934 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3935 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3936 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3937 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003938 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003939 if (!wpa_s->ibss_rsn) {
3940 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3941 wpa_supplicant_deauthenticate(
3942 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3943 return;
3944 }
3945
3946 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3947 }
3948#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003949
3950 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003951
3952 if (data) {
3953 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3954 data->assoc_info.resp_ies_len,
3955 &data->assoc_info.wmm_params);
3956
3957 if (wpa_s->reassoc_same_bss)
3958 wmm_ac_restore_tspecs(wpa_s);
3959 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003960
Hai Shalomc3565922019-10-28 11:58:20 -07003961#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3962 bss = wpa_bss_get_bssid(wpa_s, bssid);
3963#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003964#ifdef CONFIG_FILS
3965 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003966 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3967
3968 if (fils_cache_id)
3969 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3970 }
3971#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003972
3973#ifdef CONFIG_MBO
3974 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3975#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003976
3977#ifdef CONFIG_DPP2
3978 wpa_s->dpp_pfs_fallback = 0;
3979#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003980}
3981
3982
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003983static int disconnect_reason_recoverable(u16 reason_code)
3984{
3985 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3986 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3987 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3988}
3989
3990
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003991static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003992 u16 reason_code,
3993 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003994{
3995 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003996
3997 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3998 /*
3999 * At least Host AP driver and a Prism3 card seemed to be
4000 * generating streams of disconnected events when configuring
4001 * IBSS for WPA-None. Ignore them for now.
4002 */
4003 return;
4004 }
4005
4006 bssid = wpa_s->bssid;
4007 if (is_zero_ether_addr(bssid))
4008 bssid = wpa_s->pending_bssid;
4009
4010 if (!is_zero_ether_addr(bssid) ||
4011 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4012 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4013 " reason=%d%s",
4014 MAC2STR(bssid), reason_code,
4015 locally_generated ? " locally_generated=1" : "");
4016 }
4017}
4018
4019
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004020static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4021 int locally_generated)
4022{
4023 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004024 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07004025 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4026 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004027 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004028
4029 /*
4030 * It looks like connection was lost while trying to go through PSK
4031 * 4-way handshake. Filter out known disconnection cases that are caused
4032 * by something else than PSK mismatch to avoid confusing reports.
4033 */
4034
4035 if (locally_generated) {
4036 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4037 return 0;
4038 }
4039
4040 return 1;
4041}
4042
4043
Jouni Malinen2b89da82012-08-31 22:04:41 +03004044static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4045 u16 reason_code,
4046 int locally_generated)
4047{
4048 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004049 int authenticating;
4050 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004051 struct wpa_bss *fast_reconnect = NULL;
4052 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004053 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004054 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004055
4056 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
4057 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
4058
4059 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4060 /*
4061 * At least Host AP driver and a Prism3 card seemed to be
4062 * generating streams of disconnected events when configuring
4063 * IBSS for WPA-None. Ignore them for now.
4064 */
4065 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
4066 "IBSS/WPA-None mode");
4067 return;
4068 }
4069
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004070 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4071 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4072 locally_generated)
4073 /*
4074 * Remove the inactive AP (which is probably out of range) from
4075 * the BSS list after marking disassociation. In particular
4076 * mac80211-based drivers use the
4077 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4078 * locally generated disconnection events for cases where the
4079 * AP does not reply anymore.
4080 */
4081 curr = wpa_s->current_bss;
4082
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004083 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004084 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4085 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004086 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4087 return; /* P2P group removed */
Sunil Ravi77d572f2023-01-17 23:58:31 +00004088 wpas_auth_failed(wpa_s, "WRONG_KEY", prev_pending_bssid);
Hai Shalomc3565922019-10-28 11:58:20 -07004089#ifdef CONFIG_DPP2
4090 wpas_dpp_send_conn_status_result(wpa_s,
4091 DPP_STATUS_AUTH_FAILURE);
4092#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004093 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07004094 if (!wpa_s->disconnected &&
4095 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004096 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004097 wpas_wps_searching(wpa_s) ||
4098 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004099 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004100 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004101 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004102 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004103 wpa_s->wpa_state);
4104 if (wpa_s->wpa_state == WPA_COMPLETED &&
4105 wpa_s->current_ssid &&
4106 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004107 (wpa_s->own_reconnect_req ||
4108 (!locally_generated &&
4109 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004110 /*
4111 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004112 * us, but could allow us to get back in. This is also
4113 * triggered for cases where local reconnection request
4114 * is used to force reassociation with the same BSS.
4115 * Try to reconnect to the same BSS without a full scan
4116 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004117 */
4118 fast_reconnect = wpa_s->current_bss;
4119 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004120 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004121 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004122 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004123 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4124 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004125 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004126 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004127 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004128 "try to re-connect");
4129 wpa_s->reassociate = 0;
4130 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004131 if (!wpa_s->pno)
4132 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004133 }
4134 bssid = wpa_s->bssid;
4135 if (is_zero_ether_addr(bssid))
4136 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004137 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4138 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004139 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004140 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4141
Dmitry Shmidt04949592012-07-19 12:16:46 -07004142 if (locally_generated)
4143 wpa_s->disconnect_reason = -reason_code;
4144 else
4145 wpa_s->disconnect_reason = reason_code;
4146 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004147 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4148 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004149 wpa_clear_keys(wpa_s, wpa_s->bssid);
4150 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004151 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004152 wpa_supplicant_mark_disassoc(wpa_s);
4153
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004154 if (curr)
4155 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4156
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004157 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004158 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004159 wpa_s->current_ssid = last_ssid;
4160 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004161
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004162 if (fast_reconnect &&
4163 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4164 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4165 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4166 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004167 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004168 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004169#ifndef CONFIG_NO_SCAN_PROCESSING
4170 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4171 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4172 fast_reconnect_ssid) < 0) {
4173 /* Recover through full scan */
4174 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4175 }
4176#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004177 } else if (fast_reconnect) {
4178 /*
4179 * Could not reconnect to the same BSS due to network being
4180 * disabled. Use a new scan to match the alternative behavior
4181 * above, i.e., to continue automatic reconnection attempt in a
4182 * way that enforces disabled network rules.
4183 */
4184 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004185 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004186}
4187
4188
4189#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004190void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004191{
4192 struct wpa_supplicant *wpa_s = eloop_ctx;
4193
4194 if (!wpa_s->pending_mic_error_report)
4195 return;
4196
4197 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4198 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4199 wpa_s->pending_mic_error_report = 0;
4200}
4201#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4202
4203
4204static void
4205wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4206 union wpa_event_data *data)
4207{
4208 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004209 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004210
4211 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4212 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004213 os_get_reltime(&t);
4214 if ((wpa_s->last_michael_mic_error.sec &&
4215 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004216 wpa_s->pending_mic_error_report) {
4217 if (wpa_s->pending_mic_error_report) {
4218 /*
4219 * Send the pending MIC error report immediately since
4220 * we are going to start countermeasures and AP better
4221 * do the same.
4222 */
4223 wpa_sm_key_request(wpa_s->wpa, 1,
4224 wpa_s->pending_mic_error_pairwise);
4225 }
4226
4227 /* Send the new MIC error report immediately since we are going
4228 * to start countermeasures and AP better do the same.
4229 */
4230 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4231
4232 /* initialize countermeasures */
4233 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004234
Hai Shalom60840252021-02-19 19:02:11 -08004235 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004236
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004237 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4238
4239 /*
4240 * Need to wait for completion of request frame. We do not get
4241 * any callback for the message completion, so just wait a
4242 * short while and hope for the best. */
4243 os_sleep(0, 10000);
4244
4245 wpa_drv_set_countermeasures(wpa_s, 1);
4246 wpa_supplicant_deauthenticate(wpa_s,
4247 WLAN_REASON_MICHAEL_MIC_FAILURE);
4248 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4249 wpa_s, NULL);
4250 eloop_register_timeout(60, 0,
4251 wpa_supplicant_stop_countermeasures,
4252 wpa_s, NULL);
4253 /* TODO: mark the AP rejected for 60 second. STA is
4254 * allowed to associate with another AP.. */
4255 } else {
4256#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4257 if (wpa_s->mic_errors_seen) {
4258 /*
4259 * Reduce the effectiveness of Michael MIC error
4260 * reports as a means for attacking against TKIP if
4261 * more than one MIC failure is noticed with the same
4262 * PTK. We delay the transmission of the reports by a
4263 * random time between 0 and 60 seconds in order to
4264 * force the attacker wait 60 seconds before getting
4265 * the information on whether a frame resulted in a MIC
4266 * failure.
4267 */
4268 u8 rval[4];
4269 int sec;
4270
4271 if (os_get_random(rval, sizeof(rval)) < 0)
4272 sec = os_random() % 60;
4273 else
4274 sec = WPA_GET_BE32(rval) % 60;
4275 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4276 "report %d seconds", sec);
4277 wpa_s->pending_mic_error_report = 1;
4278 wpa_s->pending_mic_error_pairwise = pairwise;
4279 eloop_cancel_timeout(
4280 wpa_supplicant_delayed_mic_error_report,
4281 wpa_s, NULL);
4282 eloop_register_timeout(
4283 sec, os_random() % 1000000,
4284 wpa_supplicant_delayed_mic_error_report,
4285 wpa_s, NULL);
4286 } else {
4287 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4288 }
4289#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4290 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4291#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4292 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004293 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004294 wpa_s->mic_errors_seen++;
4295}
4296
4297
4298#ifdef CONFIG_TERMINATE_ONLASTIF
4299static int any_interfaces(struct wpa_supplicant *head)
4300{
4301 struct wpa_supplicant *wpa_s;
4302
4303 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4304 if (!wpa_s->interface_removed)
4305 return 1;
4306 return 0;
4307}
4308#endif /* CONFIG_TERMINATE_ONLASTIF */
4309
4310
4311static void
4312wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4313 union wpa_event_data *data)
4314{
4315 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4316 return;
4317
4318 switch (data->interface_status.ievent) {
4319 case EVENT_INTERFACE_ADDED:
4320 if (!wpa_s->interface_removed)
4321 break;
4322 wpa_s->interface_removed = 0;
4323 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4324 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4325 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4326 "driver after interface was added");
4327 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004328
4329#ifdef CONFIG_P2P
4330 if (!wpa_s->global->p2p &&
4331 !wpa_s->global->p2p_disabled &&
4332 !wpa_s->conf->p2p_disabled &&
4333 (wpa_s->drv_flags &
4334 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4335 wpas_p2p_add_p2pdev_interface(
4336 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4337 wpa_printf(MSG_INFO,
4338 "P2P: Failed to enable P2P Device interface");
4339 /* Try to continue without. P2P will be disabled. */
4340 }
4341#endif /* CONFIG_P2P */
4342
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004343 break;
4344 case EVENT_INTERFACE_REMOVED:
4345 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4346 wpa_s->interface_removed = 1;
4347 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004348 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004349 l2_packet_deinit(wpa_s->l2);
4350 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004351
4352#ifdef CONFIG_P2P
4353 if (wpa_s->global->p2p &&
4354 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4355 (wpa_s->drv_flags &
4356 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4357 wpa_dbg(wpa_s, MSG_DEBUG,
4358 "Removing P2P Device interface");
4359 wpa_supplicant_remove_iface(
4360 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4361 0);
4362 wpa_s->global->p2p_init_wpa_s = NULL;
4363 }
4364#endif /* CONFIG_P2P */
4365
Dmitry Shmidte4663042016-04-04 10:07:49 -07004366#ifdef CONFIG_MATCH_IFACE
4367 if (wpa_s->matched) {
4368 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4369 break;
4370 }
4371#endif /* CONFIG_MATCH_IFACE */
4372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004373#ifdef CONFIG_TERMINATE_ONLASTIF
4374 /* check if last interface */
4375 if (!any_interfaces(wpa_s->global->ifaces))
4376 eloop_terminate();
4377#endif /* CONFIG_TERMINATE_ONLASTIF */
4378 break;
4379 }
4380}
4381
4382
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004383#ifdef CONFIG_TDLS
4384static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4385 union wpa_event_data *data)
4386{
4387 if (data == NULL)
4388 return;
4389 switch (data->tdls.oper) {
4390 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004391 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4392 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4393 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4394 else
4395 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004396 break;
4397 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004398 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4399 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4400 data->tdls.reason_code);
4401 else
4402 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4403 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004404 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004405 case TDLS_REQUEST_DISCOVER:
4406 wpa_tdls_send_discovery_request(wpa_s->wpa,
4407 data->tdls.peer);
4408 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004409 }
4410}
4411#endif /* CONFIG_TDLS */
4412
4413
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004414#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004415static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4416 union wpa_event_data *data)
4417{
4418 if (data == NULL)
4419 return;
4420 switch (data->wnm.oper) {
4421 case WNM_OPER_SLEEP:
4422 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4423 "(action=%d, intval=%d)",
4424 data->wnm.sleep_action, data->wnm.sleep_intval);
4425 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004426 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004427 break;
4428 }
4429}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004430#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004431
4432
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004433#ifdef CONFIG_IEEE80211R
4434static void
4435wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4436 union wpa_event_data *data)
4437{
4438 if (data == NULL)
4439 return;
4440
4441 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4442 data->ft_ies.ies_len,
4443 data->ft_ies.ft_action,
4444 data->ft_ies.target_ap,
4445 data->ft_ies.ric_ies,
4446 data->ft_ies.ric_ies_len) < 0) {
4447 /* TODO: prevent MLME/driver from trying to associate? */
4448 }
4449}
4450#endif /* CONFIG_IEEE80211R */
4451
4452
4453#ifdef CONFIG_IBSS_RSN
4454static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4455 union wpa_event_data *data)
4456{
4457 struct wpa_ssid *ssid;
4458 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4459 return;
4460 if (data == NULL)
4461 return;
4462 ssid = wpa_s->current_ssid;
4463 if (ssid == NULL)
4464 return;
4465 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4466 return;
4467
4468 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4469}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004470
4471
4472static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4473 union wpa_event_data *data)
4474{
4475 struct wpa_ssid *ssid = wpa_s->current_ssid;
4476
4477 if (ssid == NULL)
4478 return;
4479
4480 /* check if the ssid is correctly configured as IBSS/RSN */
4481 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4482 return;
4483
4484 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4485 data->rx_mgmt.frame_len);
4486}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004487#endif /* CONFIG_IBSS_RSN */
4488
4489
4490#ifdef CONFIG_IEEE80211R
4491static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4492 size_t len)
4493{
4494 const u8 *sta_addr, *target_ap_addr;
4495 u16 status;
4496
4497 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4498 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4499 return; /* only SME case supported for now */
4500 if (len < 1 + 2 * ETH_ALEN + 2)
4501 return;
4502 if (data[0] != 2)
4503 return; /* Only FT Action Response is supported for now */
4504 sta_addr = data + 1;
4505 target_ap_addr = data + 1 + ETH_ALEN;
4506 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4507 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4508 MACSTR " TargetAP " MACSTR " status %u",
4509 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4510
4511 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4512 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4513 " in FT Action Response", MAC2STR(sta_addr));
4514 return;
4515 }
4516
4517 if (status) {
4518 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4519 "failure (status code %d)", status);
4520 /* TODO: report error to FT code(?) */
4521 return;
4522 }
4523
4524 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4525 len - (1 + 2 * ETH_ALEN + 2), 1,
4526 target_ap_addr, NULL, 0) < 0)
4527 return;
4528
4529#ifdef CONFIG_SME
4530 {
4531 struct wpa_bss *bss;
4532 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4533 if (bss)
4534 wpa_s->sme.freq = bss->freq;
4535 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4536 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4537 WLAN_AUTH_FT);
4538 }
4539#endif /* CONFIG_SME */
4540}
4541#endif /* CONFIG_IEEE80211R */
4542
4543
4544static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4545 struct unprot_deauth *e)
4546{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004547 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4548 "dropped: " MACSTR " -> " MACSTR
4549 " (reason code %u)",
4550 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4551 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004552}
4553
4554
4555static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4556 struct unprot_disassoc *e)
4557{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004558 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4559 "dropped: " MACSTR " -> " MACSTR
4560 " (reason code %u)",
4561 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4562 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004563}
4564
4565
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004566static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4567 u16 reason_code, int locally_generated,
4568 const u8 *ie, size_t ie_len, int deauth)
4569{
4570#ifdef CONFIG_AP
4571 if (wpa_s->ap_iface && addr) {
4572 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4573 return;
4574 }
4575
4576 if (wpa_s->ap_iface) {
4577 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4578 return;
4579 }
4580#endif /* CONFIG_AP */
4581
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004582 if (!locally_generated)
4583 wpa_s->own_disconnect_req = 0;
4584
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004585 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4586
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004587 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4588 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4589 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4590 eapol_sm_failed(wpa_s->eapol))) &&
4591 !wpa_s->eap_expected_failure))
Sunil Ravi77d572f2023-01-17 23:58:31 +00004592 wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004593
4594#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004595 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004596 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4597 locally_generated) > 0) {
4598 /*
4599 * The interface was removed, so cannot continue
4600 * processing any additional operations after this.
4601 */
4602 return;
4603 }
4604 }
4605#endif /* CONFIG_P2P */
4606
4607 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4608 locally_generated);
4609}
4610
4611
4612static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4613 struct disassoc_info *info)
4614{
4615 u16 reason_code = 0;
4616 int locally_generated = 0;
4617 const u8 *addr = NULL;
4618 const u8 *ie = NULL;
4619 size_t ie_len = 0;
4620
4621 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4622
4623 if (info) {
4624 addr = info->addr;
4625 ie = info->ie;
4626 ie_len = info->ie_len;
4627 reason_code = info->reason_code;
4628 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004629 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4630 reason2str(reason_code),
4631 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004632 if (addr)
4633 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4634 MAC2STR(addr));
4635 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4636 ie, ie_len);
4637 }
4638
4639#ifdef CONFIG_AP
4640 if (wpa_s->ap_iface && info && info->addr) {
4641 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4642 return;
4643 }
4644
4645 if (wpa_s->ap_iface) {
4646 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4647 return;
4648 }
4649#endif /* CONFIG_AP */
4650
4651#ifdef CONFIG_P2P
4652 if (info) {
4653 wpas_p2p_disassoc_notif(
4654 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4655 locally_generated);
4656 }
4657#endif /* CONFIG_P2P */
4658
4659 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4660 sme_event_disassoc(wpa_s, info);
4661
4662 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4663 ie, ie_len, 0);
4664}
4665
4666
4667static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4668 struct deauth_info *info)
4669{
4670 u16 reason_code = 0;
4671 int locally_generated = 0;
4672 const u8 *addr = NULL;
4673 const u8 *ie = NULL;
4674 size_t ie_len = 0;
4675
4676 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4677
4678 if (info) {
4679 addr = info->addr;
4680 ie = info->ie;
4681 ie_len = info->ie_len;
4682 reason_code = info->reason_code;
4683 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004684 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4685 reason_code, reason2str(reason_code),
4686 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004687 if (addr) {
4688 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4689 MAC2STR(addr));
4690 }
4691 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4692 ie, ie_len);
4693 }
4694
4695 wpa_reset_ft_completed(wpa_s->wpa);
4696
4697 wpas_event_disconnect(wpa_s, addr, reason_code,
4698 locally_generated, ie, ie_len, 1);
4699}
4700
4701
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004702static const char * reg_init_str(enum reg_change_initiator init)
4703{
4704 switch (init) {
4705 case REGDOM_SET_BY_CORE:
4706 return "CORE";
4707 case REGDOM_SET_BY_USER:
4708 return "USER";
4709 case REGDOM_SET_BY_DRIVER:
4710 return "DRIVER";
4711 case REGDOM_SET_BY_COUNTRY_IE:
4712 return "COUNTRY_IE";
4713 case REGDOM_BEACON_HINT:
4714 return "BEACON_HINT";
4715 }
4716 return "?";
4717}
4718
4719
4720static const char * reg_type_str(enum reg_type type)
4721{
4722 switch (type) {
4723 case REGDOM_TYPE_UNKNOWN:
4724 return "UNKNOWN";
4725 case REGDOM_TYPE_COUNTRY:
4726 return "COUNTRY";
4727 case REGDOM_TYPE_WORLD:
4728 return "WORLD";
4729 case REGDOM_TYPE_CUSTOM_WORLD:
4730 return "CUSTOM_WORLD";
4731 case REGDOM_TYPE_INTERSECTION:
4732 return "INTERSECTION";
4733 }
4734 return "?";
4735}
4736
4737
Hai Shalom74f70d42019-02-11 14:42:39 -08004738void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4739 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004740{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004741 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004742 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004743
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004744 /*
4745 * To allow backwards compatibility with higher level layers that
4746 * assumed the REGDOM_CHANGE event is sent over the initially added
4747 * interface. Find the highest parent of this interface and use it to
4748 * send the event.
4749 */
4750 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4751 ;
4752
Hai Shalom74f70d42019-02-11 14:42:39 -08004753 if (info) {
4754 wpa_msg(ifs, MSG_INFO,
4755 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4756 reg_init_str(info->initiator), reg_type_str(info->type),
4757 info->alpha2[0] ? " alpha2=" : "",
4758 info->alpha2[0] ? info->alpha2 : "");
4759 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004760
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004761 if (wpa_s->drv_priv == NULL)
4762 return; /* Ignore event during drv initialization */
4763
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004764 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4765 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004766 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4767 ifs->ifname);
4768 free_hw_features(ifs);
4769 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004770 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004771
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004772 /* Restart PNO/sched_scan with updated channel list */
4773 if (ifs->pno) {
4774 wpas_stop_pno(ifs);
4775 wpas_start_pno(ifs);
4776 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4777 wpa_dbg(ifs, MSG_DEBUG,
4778 "Channel list changed - restart sched_scan");
4779 wpas_scan_restart_sched_scan(ifs);
4780 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004781 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004782
4783 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004784}
4785
4786
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004787static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004788 const u8 *frame, size_t len, int freq,
4789 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004790{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004791 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004792 const u8 *payload;
4793 size_t plen;
4794 u8 category;
4795
4796 if (len < IEEE80211_HDRLEN + 2)
4797 return;
4798
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004799 mgmt = (const struct ieee80211_mgmt *) frame;
4800 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004801 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004802 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004803
4804 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4805 " Category=%u DataLen=%d freq=%d MHz",
4806 MAC2STR(mgmt->sa), category, (int) plen, freq);
4807
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004808 if (category == WLAN_ACTION_WMM) {
4809 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4810 return;
4811 }
4812
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004813#ifdef CONFIG_IEEE80211R
4814 if (category == WLAN_ACTION_FT) {
4815 ft_rx_action(wpa_s, payload, plen);
4816 return;
4817 }
4818#endif /* CONFIG_IEEE80211R */
4819
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004820#ifdef CONFIG_SME
4821 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004822 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004823 return;
4824 }
4825#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004826
4827#ifdef CONFIG_WNM
4828 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4829 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4830 return;
4831 }
4832#endif /* CONFIG_WNM */
4833
4834#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004835 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4836 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004837 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004838 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004839 payload, plen, freq) == 0)
4840 return;
4841#endif /* CONFIG_GAS */
4842
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004843#ifdef CONFIG_GAS_SERVER
4844 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4845 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4846 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4847 mgmt->u.action.category,
4848 payload, plen, freq) == 0)
4849 return;
4850#endif /* CONFIG_GAS_SERVER */
4851
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004852#ifdef CONFIG_TDLS
4853 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4854 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4855 wpa_dbg(wpa_s, MSG_DEBUG,
4856 "TDLS: Received Discovery Response from " MACSTR,
4857 MAC2STR(mgmt->sa));
4858 return;
4859 }
4860#endif /* CONFIG_TDLS */
4861
4862#ifdef CONFIG_INTERWORKING
4863 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4864 payload[0] == QOS_QOS_MAP_CONFIG) {
4865 const u8 *pos = payload + 1;
4866 size_t qlen = plen - 1;
4867 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4868 MACSTR, MAC2STR(mgmt->sa));
4869 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4870 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4871 pos[1] <= qlen - 2 && pos[1] >= 16)
4872 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4873 return;
4874 }
4875#endif /* CONFIG_INTERWORKING */
4876
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004877 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004878 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4879 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004880 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004881 payload + 1,
4882 plen - 1);
4883 return;
4884 }
4885
4886 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004887 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4888 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4889 return;
4890 }
4891
4892 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4893 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4894 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4895 payload + 1, plen - 1,
4896 rssi);
4897 return;
4898 }
4899
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004900#ifdef CONFIG_FST
4901 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4902 fst_rx_action(wpa_s->fst, mgmt, len);
4903 return;
4904 }
4905#endif /* CONFIG_FST */
4906
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004907#ifdef CONFIG_DPP
4908 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4909 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4910 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4911 payload[4] == DPP_OUI_TYPE) {
4912 payload++;
4913 plen--;
4914 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4915 return;
4916 }
4917#endif /* CONFIG_DPP */
4918
Hai Shalom899fcc72020-10-19 14:38:18 -07004919 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004920 payload[0] == ROBUST_AV_SCS_RESP) {
4921 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4922 payload + 1, plen - 1);
4923 return;
4924 }
4925
4926 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004927 payload[0] == ROBUST_AV_MSCS_RESP) {
4928 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4929 payload + 1, plen - 1);
4930 return;
4931 }
4932
Hai Shalomc1a21442022-02-04 13:43:00 -08004933 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4934 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4935 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4936 payload + 4, plen - 4);
4937 return;
4938 }
4939
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004940 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4941 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004942 if (wpa_s->ifmsh)
4943 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004944}
4945
4946
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004947static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4948 union wpa_event_data *event)
4949{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004950 struct wpa_freq_range_list *list;
4951 char *str = NULL;
4952
4953 list = &event->freq_range;
4954
4955 if (list->num)
4956 str = freq_range_list_str(list);
4957 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4958 str ? str : "");
4959
4960#ifdef CONFIG_P2P
4961 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4962 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4963 __func__);
4964 } else {
4965 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004966
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004967 /*
4968 * The update channel flow will also take care of moving a GO
4969 * from the unsafe frequency if needed.
4970 */
4971 wpas_p2p_update_channel_list(wpa_s,
4972 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004973 }
4974#endif /* CONFIG_P2P */
4975
4976 os_free(str);
4977}
4978
4979
Roshan Pius3a1667e2018-07-03 15:17:14 -07004980static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004981{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004982 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4983 wpa_supplicant_cancel_auth_timeout(wpa_s);
4984 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004985 eapol_sm_notify_portValid(wpa_s->eapol, true);
4986 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004987 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004988 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004989}
4990
4991
4992static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4993 int freq)
4994{
4995 size_t i;
4996 int j;
4997
4998 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4999 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5000
5001 for (j = 0; j < mode->num_channels; j++) {
5002 const struct hostapd_channel_data *chan;
5003
5004 chan = &mode->channels[j];
5005 if (chan->freq == freq)
5006 return chan->dfs_cac_ms;
5007 }
5008 }
5009
5010 return 0;
5011}
5012
5013
5014static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5015 struct dfs_event *radar)
5016{
5017#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005018 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005019 wpas_ap_event_dfs_cac_started(wpa_s, radar);
5020 } else
5021#endif /* NEED_AP_MLME && CONFIG_AP */
5022 {
5023 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5024
5025 cac_time /= 1000; /* convert from ms to sec */
5026 if (!cac_time)
5027 cac_time = 10 * 60; /* max timeout: 10 minutes */
5028
5029 /* Restart auth timeout: CAC time added to initial timeout */
5030 wpas_auth_timeout_restart(wpa_s, cac_time);
5031 }
5032}
5033
5034
5035static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5036 struct dfs_event *radar)
5037{
5038#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005039 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005040 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5041 } else
5042#endif /* NEED_AP_MLME && CONFIG_AP */
5043 {
5044 /* Restart auth timeout with original value after CAC is
5045 * finished */
5046 wpas_auth_timeout_restart(wpa_s, 0);
5047 }
5048}
5049
5050
5051static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5052 struct dfs_event *radar)
5053{
5054#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08005055 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005056 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5057 } else
5058#endif /* NEED_AP_MLME && CONFIG_AP */
5059 {
5060 /* Restart auth timeout with original value after CAC is
5061 * aborted */
5062 wpas_auth_timeout_restart(wpa_s, 0);
5063 }
5064}
5065
5066
5067static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5068 union wpa_event_data *data)
5069{
5070 wpa_dbg(wpa_s, MSG_DEBUG,
5071 "Connection authorized by device, previous state %d",
5072 wpa_s->wpa_state);
5073
5074 wpa_supplicant_event_port_authorized(wpa_s);
5075
Hai Shalomc1a21442022-02-04 13:43:00 -08005076 wpa_s->last_eapol_matches_bssid = 1;
5077
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005078 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5079 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08005080 data->assoc_info.ptk_kck_len,
5081 data->assoc_info.ptk_kek,
5082 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005083#ifdef CONFIG_FILS
5084 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5085 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5086 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5087
5088 /* Update ERP next sequence number */
5089 eapol_sm_update_erp_next_seq_num(
5090 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5091
5092 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5093 /* Add the new PMK and PMKID to the PMKSA cache */
5094 wpa_sm_pmksa_cache_add(wpa_s->wpa,
5095 data->assoc_info.fils_pmk,
5096 data->assoc_info.fils_pmk_len,
5097 data->assoc_info.fils_pmkid,
5098 wpa_s->bssid, fils_cache_id);
5099 } else if (data->assoc_info.fils_pmkid) {
5100 /* Update the current PMKSA used for this connection */
5101 pmksa_cache_set_current(wpa_s->wpa,
5102 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005103 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005104 }
5105 }
5106#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005107}
5108
5109
Hai Shalom60840252021-02-19 19:02:11 -08005110static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5111{
5112 switch (code) {
5113 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5114 return "";
5115 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5116 return "no_bss_found";
5117 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5118 return "auth_tx_fail";
5119 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5120 return "auth_no_ack_received";
5121 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5122 return "auth_no_resp_received";
5123 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5124 return "assoc_req_tx_fail";
5125 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5126 return "assoc_no_ack_received";
5127 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5128 return "assoc_no_resp_received";
5129 default:
5130 return "unknown_reason";
5131 }
5132}
5133
5134
Roshan Pius3a1667e2018-07-03 15:17:14 -07005135static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5136 union wpa_event_data *data)
5137{
5138 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005139#ifdef CONFIG_MBO
5140 struct wpa_bss *reject_bss;
5141#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005142
5143 if (!bssid || is_zero_ether_addr(bssid))
5144 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005145#ifdef CONFIG_MBO
5146 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5147 reject_bss = wpa_s->current_bss;
5148 else
5149 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5150#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005151
5152 if (data->assoc_reject.bssid)
5153 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005154 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005155 MAC2STR(data->assoc_reject.bssid),
5156 data->assoc_reject.status_code,
5157 data->assoc_reject.timed_out ? " timeout" : "",
5158 data->assoc_reject.timeout_reason ? "=" : "",
5159 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005160 data->assoc_reject.timeout_reason : "",
5161 data->assoc_reject.reason_code !=
5162 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5163 " qca_driver_reason=" : "",
5164 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005165 else
5166 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005167 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005168 data->assoc_reject.status_code,
5169 data->assoc_reject.timed_out ? " timeout" : "",
5170 data->assoc_reject.timeout_reason ? "=" : "",
5171 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005172 data->assoc_reject.timeout_reason : "",
5173 data->assoc_reject.reason_code !=
5174 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5175 " qca_driver_reason=" : "",
5176 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005177 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005178 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5179 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005180
5181#ifdef CONFIG_OWE
5182 if (data->assoc_reject.status_code ==
5183 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5184 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5185 wpa_s->current_ssid &&
5186 wpa_s->current_ssid->owe_group == 0 &&
5187 wpa_s->last_owe_group != 21) {
5188 struct wpa_ssid *ssid = wpa_s->current_ssid;
5189 struct wpa_bss *bss = wpa_s->current_bss;
5190
5191 if (!bss) {
5192 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5193 if (!bss) {
5194 wpas_connection_failed(wpa_s, bssid);
5195 wpa_supplicant_mark_disassoc(wpa_s);
5196 return;
5197 }
5198 }
5199 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5200 wpas_connect_work_done(wpa_s);
5201 wpa_supplicant_mark_disassoc(wpa_s);
5202 wpa_supplicant_connect(wpa_s, bss, ssid);
5203 return;
5204 }
5205#endif /* CONFIG_OWE */
5206
Hai Shalomfdcde762020-04-02 11:19:20 -07005207#ifdef CONFIG_DPP2
5208 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5209 * the status code defined in the DPP R2 tech spec.
5210 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5211 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005212 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005213 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5214 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5215 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005216 wpa_s->current_ssid->dpp_pfs == 0 &&
5217 (data->assoc_reject.status_code ==
5218 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5219 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5220 struct wpa_ssid *ssid = wpa_s->current_ssid;
5221 struct wpa_bss *bss = wpa_s->current_bss;
5222
5223 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5224 if (!bss)
5225 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5226 if (!bss || wpa_s->dpp_pfs_fallback) {
5227 wpa_printf(MSG_DEBUG,
5228 "DPP: Updated PFS policy for next try");
5229 wpas_connection_failed(wpa_s, bssid);
5230 wpa_supplicant_mark_disassoc(wpa_s);
5231 return;
5232 }
5233 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5234 wpa_s->dpp_pfs_fallback = 1;
5235 wpas_connect_work_done(wpa_s);
5236 wpa_supplicant_mark_disassoc(wpa_s);
5237 wpa_supplicant_connect(wpa_s, bss, ssid);
5238 return;
5239 }
5240#endif /* CONFIG_DPP2 */
5241
Hai Shalom74f70d42019-02-11 14:42:39 -08005242#ifdef CONFIG_MBO
5243 if (data->assoc_reject.status_code ==
5244 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005245 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005246 const u8 *rssi_rej;
5247
5248 rssi_rej = mbo_get_attr_from_ies(
5249 data->assoc_reject.resp_ies,
5250 data->assoc_reject.resp_ies_len,
5251 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5252 if (rssi_rej && rssi_rej[1] == 2) {
5253 wpa_printf(MSG_DEBUG,
5254 "OCE: RSSI-based association rejection from "
5255 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005256 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005257 rssi_rej[2], rssi_rej[3]);
5258 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005259 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005260 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005261 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005262 }
5263 }
5264#endif /* CONFIG_MBO */
5265
Roshan Pius3a1667e2018-07-03 15:17:14 -07005266 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5267 sme_event_assoc_reject(wpa_s, data);
5268 return;
5269 }
5270
5271 /* Driver-based SME cases */
5272
5273#ifdef CONFIG_SAE
5274 if (wpa_s->current_ssid &&
5275 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5276 !data->assoc_reject.timed_out) {
5277 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5278 wpa_sm_aborted_cached(wpa_s->wpa);
5279 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5280 }
5281#endif /* CONFIG_SAE */
5282
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005283#ifdef CONFIG_DPP
5284 if (wpa_s->current_ssid &&
5285 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5286 !data->assoc_reject.timed_out) {
5287 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5288 wpa_sm_aborted_cached(wpa_s->wpa);
5289 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5290 }
5291#endif /* CONFIG_DPP */
5292
Roshan Pius3a1667e2018-07-03 15:17:14 -07005293#ifdef CONFIG_FILS
5294 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005295 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005296 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005297 eapol_sm_update_erp_next_seq_num(
5298 wpa_s->eapol,
5299 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005300 fils_connection_failure(wpa_s);
5301 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005302#endif /* CONFIG_FILS */
5303
5304 wpas_connection_failed(wpa_s, bssid);
5305 wpa_supplicant_mark_disassoc(wpa_s);
5306}
5307
5308
Hai Shalomfdcde762020-04-02 11:19:20 -07005309static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5310 struct unprot_beacon *data)
5311{
5312 struct wpabuf *buf;
5313 int res;
5314
5315 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5316 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5317 return;
5318 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5319 MAC2STR(data->sa));
5320
5321 buf = wpabuf_alloc(4);
5322 if (!buf)
5323 return;
5324
5325 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5326 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5327 wpabuf_put_u8(buf, 1); /* Dialog Token */
5328 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5329
5330 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5331 wpa_s->own_addr, wpa_s->bssid,
5332 wpabuf_head(buf), wpabuf_len(buf), 0);
5333 if (res < 0)
5334 wpa_printf(MSG_DEBUG,
5335 "Failed to send WNM-Notification Request frame");
5336
5337 wpabuf_free(buf);
5338}
5339
5340
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005341void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5342 union wpa_event_data *data)
5343{
5344 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005345 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005346 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005347#ifndef CONFIG_NO_STDOUT_DEBUG
5348 int level = MSG_DEBUG;
5349#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005350
5351 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5352 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005353 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005354 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005355 event != EVENT_SCHED_SCAN_STOPPED) {
5356 wpa_dbg(wpa_s, MSG_DEBUG,
5357 "Ignore event %s (%d) while interface is disabled",
5358 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005359 return;
5360 }
5361
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005362#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005363 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005364 const struct ieee80211_hdr *hdr;
5365 u16 fc;
5366 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5367 fc = le_to_host16(hdr->frame_control);
5368 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5369 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5370 level = MSG_EXCESSIVE;
5371 }
5372
5373 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5374 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005375#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005376
5377 switch (event) {
5378 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005379#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005380 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5381 data->auth.ies_len))
5382 wpa_printf(MSG_DEBUG,
5383 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005384#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005385 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005386 wpa_s->auth_status_code = data->auth.status_code;
5387 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005388 break;
5389 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005390#ifdef CONFIG_TESTING_OPTIONS
5391 if (wpa_s->ignore_auth_resp) {
5392 wpa_printf(MSG_INFO,
5393 "EVENT_ASSOC - ignore_auth_resp active!");
5394 break;
5395 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005396 if (wpa_s->testing_resend_assoc) {
5397 wpa_printf(MSG_INFO,
5398 "EVENT_DEAUTH - testing_resend_assoc");
5399 break;
5400 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005401#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305402 if (wpa_s->disconnected) {
5403 wpa_printf(MSG_INFO,
5404 "Ignore unexpected EVENT_ASSOC in disconnected state");
5405 break;
5406 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005407 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005408 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005409 if (data &&
5410 (data->assoc_info.authorized ||
5411 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5412 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005413 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005414 if (data) {
5415 wpa_msg(wpa_s, MSG_INFO,
5416 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5417 data->assoc_info.subnet_status);
5418 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005419 break;
5420 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005421 wpas_event_disassoc(wpa_s,
5422 data ? &data->disassoc_info : NULL);
5423 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005424 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005425#ifdef CONFIG_TESTING_OPTIONS
5426 if (wpa_s->ignore_auth_resp) {
5427 wpa_printf(MSG_INFO,
5428 "EVENT_DEAUTH - ignore_auth_resp active!");
5429 break;
5430 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005431 if (wpa_s->testing_resend_assoc) {
5432 wpa_printf(MSG_INFO,
5433 "EVENT_DEAUTH - testing_resend_assoc");
5434 break;
5435 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005436#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005437 wpas_event_deauth(wpa_s,
5438 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005439 break;
5440 case EVENT_MICHAEL_MIC_FAILURE:
5441 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5442 break;
5443#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005444 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005445 if (wpa_s->own_scan_requested ||
5446 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005447 struct os_reltime diff;
5448
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005449 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005450 os_reltime_sub(&wpa_s->scan_start_time,
5451 &wpa_s->scan_trigger_time, &diff);
5452 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5453 diff.sec, diff.usec);
5454 wpa_s->own_scan_requested = 0;
5455 wpa_s->own_scan_running = 1;
5456 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5457 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005458 wpa_msg_ctrl(wpa_s, MSG_INFO,
5459 WPA_EVENT_SCAN_STARTED "id=%u",
5460 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005461 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005462 wpa_msg_ctrl(wpa_s, MSG_INFO,
5463 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005464 }
5465 } else {
5466 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005467 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005468 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005469 }
5470 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005471 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005472 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5473 wpa_s->scan_res_handler = NULL;
5474 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005475 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005476 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5477 break;
5478 }
5479
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005480 if (!(data && data->scan_info.external_scan) &&
5481 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005482 struct os_reltime now, diff;
5483 os_get_reltime(&now);
5484 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5485 wpa_s->scan_start_time.sec = 0;
5486 wpa_s->scan_start_time.usec = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +00005487 wpa_s->wps_scan_done = true;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005488 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5489 diff.sec, diff.usec);
5490 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005491 if (wpa_supplicant_event_scan_results(wpa_s, data))
5492 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005493 if (!(data && data->scan_info.external_scan))
5494 wpa_s->own_scan_running = 0;
5495 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005496 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005497 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005498 break;
5499#endif /* CONFIG_NO_SCAN_PROCESSING */
5500 case EVENT_ASSOCINFO:
5501 wpa_supplicant_event_associnfo(wpa_s, data);
5502 break;
5503 case EVENT_INTERFACE_STATUS:
5504 wpa_supplicant_event_interface_status(wpa_s, data);
5505 break;
5506 case EVENT_PMKID_CANDIDATE:
5507 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5508 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005509#ifdef CONFIG_TDLS
5510 case EVENT_TDLS:
5511 wpa_supplicant_event_tdls(wpa_s, data);
5512 break;
5513#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005514#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005515 case EVENT_WNM:
5516 wpa_supplicant_event_wnm(wpa_s, data);
5517 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005518#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005519#ifdef CONFIG_IEEE80211R
5520 case EVENT_FT_RESPONSE:
5521 wpa_supplicant_event_ft_response(wpa_s, data);
5522 break;
5523#endif /* CONFIG_IEEE80211R */
5524#ifdef CONFIG_IBSS_RSN
5525 case EVENT_IBSS_RSN_START:
5526 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5527 break;
5528#endif /* CONFIG_IBSS_RSN */
5529 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005530 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005531 break;
5532 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005533 /* It is possible to get this event from earlier connection */
5534 if (wpa_s->current_ssid &&
5535 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5536 wpa_dbg(wpa_s, MSG_DEBUG,
5537 "Ignore AUTH_TIMED_OUT in mesh configuration");
5538 break;
5539 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005540 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5541 sme_event_auth_timed_out(wpa_s, data);
5542 break;
5543 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005544 /* It is possible to get this event from earlier connection */
5545 if (wpa_s->current_ssid &&
5546 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5547 wpa_dbg(wpa_s, MSG_DEBUG,
5548 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5549 break;
5550 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005551 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5552 sme_event_assoc_timed_out(wpa_s, data);
5553 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005554 case EVENT_TX_STATUS:
5555 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5556 " type=%d stype=%d",
5557 MAC2STR(data->tx_status.dst),
5558 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005559#ifdef CONFIG_PASN
5560 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5561 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5562 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5563 data->tx_status.data_len,
5564 data->tx_status.ack) == 0)
5565 break;
5566#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005567#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005568 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005569#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005570 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5571 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005572 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005573 wpa_s, data->tx_status.dst,
5574 data->tx_status.data,
5575 data->tx_status.data_len,
5576 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005577 OFFCHANNEL_SEND_ACTION_SUCCESS :
5578 OFFCHANNEL_SEND_ACTION_NO_ACK);
5579#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005580 break;
5581 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005582#endif /* CONFIG_AP */
5583#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005584 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005585 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005586 /*
5587 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005588 * interface in GO mode, or via standalone AP interface.
5589 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5590 * except when the primary interface is used as a GO interface
5591 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005592 */
5593 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5594 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005595 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005596 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005597 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005598 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005599 data->tx_status.data,
5600 data->tx_status.data_len,
5601 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005602 OFFCHANNEL_SEND_ACTION_SUCCESS :
5603 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005604 break;
5605 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005606#endif /* CONFIG_OFFCHANNEL */
5607#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005608 switch (data->tx_status.type) {
5609 case WLAN_FC_TYPE_MGMT:
5610 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5611 data->tx_status.data_len,
5612 data->tx_status.stype,
5613 data->tx_status.ack);
5614 break;
5615 case WLAN_FC_TYPE_DATA:
5616 ap_tx_status(wpa_s, data->tx_status.dst,
5617 data->tx_status.data,
5618 data->tx_status.data_len,
5619 data->tx_status.ack);
5620 break;
5621 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005622#endif /* CONFIG_AP */
5623 break;
5624#ifdef CONFIG_AP
5625 case EVENT_EAPOL_TX_STATUS:
5626 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5627 data->eapol_tx_status.data,
5628 data->eapol_tx_status.data_len,
5629 data->eapol_tx_status.ack);
5630 break;
5631 case EVENT_DRIVER_CLIENT_POLL_OK:
5632 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005633 break;
5634 case EVENT_RX_FROM_UNKNOWN:
5635 if (wpa_s->ap_iface == NULL)
5636 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005637 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5638 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005639 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005640#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005641
Sunil Ravi89eba102022-09-13 21:04:37 -07005642 case EVENT_LINK_CH_SWITCH_STARTED:
5643 case EVENT_LINK_CH_SWITCH:
5644 if (!data || !wpa_s->current_ssid ||
5645 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
5646 break;
5647
5648 wpa_msg(wpa_s, MSG_INFO,
5649 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5650 event == EVENT_LINK_CH_SWITCH ?
5651 WPA_EVENT_LINK_CHANNEL_SWITCH :
5652 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
5653 data->ch_switch.freq,
5654 data->ch_switch.link_id,
5655 data->ch_switch.ht_enabled,
5656 data->ch_switch.ch_offset,
5657 channel_width_to_string(data->ch_switch.ch_width),
5658 data->ch_switch.cf1,
5659 data->ch_switch.cf2);
5660 if (event == EVENT_LINK_CH_SWITCH_STARTED)
5661 break;
5662
5663 wpa_s->links[data->ch_switch.link_id].freq =
5664 data->ch_switch.freq;
5665 if (wpa_s->links[data->ch_switch.link_id].bss &&
5666 wpa_s->links[data->ch_switch.link_id].bss->freq !=
5667 data->ch_switch.freq) {
5668 wpa_s->links[data->ch_switch.link_id].bss->freq =
5669 data->ch_switch.freq;
5670 notify_bss_changes(
5671 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5672 wpa_s->links[data->ch_switch.link_id].bss);
5673 }
5674 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07005675 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005676 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005677 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005678 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005679
Hai Shalom81f62d82019-07-22 12:10:00 -07005680 wpa_msg(wpa_s, MSG_INFO,
5681 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5682 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5683 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005684 data->ch_switch.freq,
5685 data->ch_switch.ht_enabled,
5686 data->ch_switch.ch_offset,
5687 channel_width_to_string(data->ch_switch.ch_width),
5688 data->ch_switch.cf1,
5689 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005690 if (event == EVENT_CH_SWITCH_STARTED)
5691 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005692
Sunil Ravi65a724b2022-05-24 11:06:09 -07005693 if (wpa_s->assoc_freq && data->ch_switch.freq &&
5694 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
5695 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
5696 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005697 wpa_s->assoc_freq = data->ch_switch.freq;
5698 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005699 if (wpa_s->current_bss &&
5700 wpa_s->current_bss->freq != data->ch_switch.freq) {
5701 wpa_s->current_bss->freq = data->ch_switch.freq;
5702 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5703 wpa_s->current_bss);
5704 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005705
Hai Shalomfdcde762020-04-02 11:19:20 -07005706#ifdef CONFIG_SME
5707 switch (data->ch_switch.ch_offset) {
5708 case 1:
5709 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5710 break;
5711 case -1:
5712 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5713 break;
5714 default:
5715 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5716 break;
5717 }
5718#endif /* CONFIG_SME */
5719
Roshan Pius3a1667e2018-07-03 15:17:14 -07005720#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005721 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5722 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005723 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005724 wpa_s->current_ssid->mode ==
5725 WPAS_MODE_P2P_GROUP_FORMATION) {
5726 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5727 data->ch_switch.ht_enabled,
5728 data->ch_switch.ch_offset,
5729 data->ch_switch.ch_width,
5730 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005731 data->ch_switch.cf2,
5732 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005733 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005734#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005735
Hai Shalom899fcc72020-10-19 14:38:18 -07005736 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5737 sme_event_ch_switch(wpa_s);
5738
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005739 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005740 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005741 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005742#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005743#ifdef NEED_AP_MLME
5744 case EVENT_DFS_RADAR_DETECTED:
5745 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005746 wpas_ap_event_dfs_radar_detected(wpa_s,
5747 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005748 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005749 case EVENT_DFS_NOP_FINISHED:
5750 if (data)
5751 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5752 &data->dfs_event);
5753 break;
5754#endif /* NEED_AP_MLME */
5755#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005756 case EVENT_DFS_CAC_STARTED:
5757 if (data)
5758 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5759 break;
5760 case EVENT_DFS_CAC_FINISHED:
5761 if (data)
5762 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5763 break;
5764 case EVENT_DFS_CAC_ABORTED:
5765 if (data)
5766 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5767 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005768 case EVENT_RX_MGMT: {
5769 u16 fc, stype;
5770 const struct ieee80211_mgmt *mgmt;
5771
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005772#ifdef CONFIG_TESTING_OPTIONS
5773 if (wpa_s->ext_mgmt_frame_handling) {
5774 struct rx_mgmt *rx = &data->rx_mgmt;
5775 size_t hex_len = 2 * rx->frame_len + 1;
5776 char *hex = os_malloc(hex_len);
5777 if (hex) {
5778 wpa_snprintf_hex(hex, hex_len,
5779 rx->frame, rx->frame_len);
5780 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5781 rx->freq, rx->datarate, rx->ssi_signal,
5782 hex);
5783 os_free(hex);
5784 }
5785 break;
5786 }
5787#endif /* CONFIG_TESTING_OPTIONS */
5788
Dmitry Shmidt04949592012-07-19 12:16:46 -07005789 mgmt = (const struct ieee80211_mgmt *)
5790 data->rx_mgmt.frame;
5791 fc = le_to_host16(mgmt->frame_control);
5792 stype = WLAN_FC_GET_STYPE(fc);
5793
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005794#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005795 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005796#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005797#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005798 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005799 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005800 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005801 const u8 *ie;
5802 size_t ie_len;
5803
5804 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5805 ie_len = data->rx_mgmt.frame_len -
5806 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005807 wpas_p2p_probe_req_rx(
5808 wpa_s, src, mgmt->da,
5809 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005810 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005811 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005812 break;
5813 }
5814#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005815#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005816 if (wpa_s->current_ssid &&
5817 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5818 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005819 data->rx_mgmt.frame_len >= 30) {
5820 wpa_supplicant_event_ibss_auth(wpa_s, data);
5821 break;
5822 }
5823#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005824
5825 if (stype == WLAN_FC_STYPE_ACTION) {
5826 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005827 wpa_s, data->rx_mgmt.frame,
5828 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005829 data->rx_mgmt.freq,
5830 data->rx_mgmt.ssi_signal);
5831 break;
5832 }
5833
5834 if (wpa_s->ifmsh) {
5835 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005836 break;
5837 }
Hai Shalom60840252021-02-19 19:02:11 -08005838#ifdef CONFIG_PASN
5839 if (stype == WLAN_FC_STYPE_AUTH &&
5840 wpas_pasn_auth_rx(wpa_s, mgmt,
5841 data->rx_mgmt.frame_len) != -2)
5842 break;
5843#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005844
Roshan Pius3a1667e2018-07-03 15:17:14 -07005845#ifdef CONFIG_SAE
5846 if (stype == WLAN_FC_STYPE_AUTH &&
5847 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5848 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5849 sme_external_auth_mgmt_rx(
5850 wpa_s, data->rx_mgmt.frame,
5851 data->rx_mgmt.frame_len);
5852 break;
5853 }
5854#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005855 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5856 "management frame in non-AP mode");
5857 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005858#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005859 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005860
5861 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005862 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5863 const u8 *ie;
5864 size_t ie_len;
5865
5866 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5867 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005868
5869 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5870 mgmt->bssid, ie, ie_len,
5871 data->rx_mgmt.ssi_signal);
5872 }
5873
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005874 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005875#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005876 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005877 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005878 case EVENT_RX_PROBE_REQ:
5879 if (data->rx_probe_req.sa == NULL ||
5880 data->rx_probe_req.ie == NULL)
5881 break;
5882#ifdef CONFIG_AP
5883 if (wpa_s->ap_iface) {
5884 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5885 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005886 data->rx_probe_req.da,
5887 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005888 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005889 data->rx_probe_req.ie_len,
5890 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005891 break;
5892 }
5893#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005894 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005895 data->rx_probe_req.da,
5896 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005897 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005898 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005899 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005900 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005901 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005902 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005903#ifdef CONFIG_OFFCHANNEL
5904 offchannel_remain_on_channel_cb(
5905 wpa_s, data->remain_on_channel.freq,
5906 data->remain_on_channel.duration);
5907#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005908 wpas_p2p_remain_on_channel_cb(
5909 wpa_s, data->remain_on_channel.freq,
5910 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005911#ifdef CONFIG_DPP
5912 wpas_dpp_remain_on_channel_cb(
5913 wpa_s, data->remain_on_channel.freq,
5914 data->remain_on_channel.duration);
5915#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005916 break;
5917 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005918#ifdef CONFIG_OFFCHANNEL
5919 offchannel_cancel_remain_on_channel_cb(
5920 wpa_s, data->remain_on_channel.freq);
5921#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005922 wpas_p2p_cancel_remain_on_channel_cb(
5923 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005924#ifdef CONFIG_DPP
5925 wpas_dpp_cancel_remain_on_channel_cb(
5926 wpa_s, data->remain_on_channel.freq);
5927#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005928 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005929 case EVENT_EAPOL_RX:
5930 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5931 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00005932 data->eapol_rx.data_len,
5933 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005934 break;
5935 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005936 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
Sunil Ravi77d572f2023-01-17 23:58:31 +00005937 "above=%d signal=%d noise=%d txrate=%lu",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005938 data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005939 data->signal_change.data.signal,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005940 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005941 data->signal_change.data.current_tx_rate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005942 wpa_bss_update_level(wpa_s->current_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005943 data->signal_change.data.signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005944 bgscan_notify_signal_change(
5945 wpa_s, data->signal_change.above_threshold,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005946 data->signal_change.data.signal,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005947 data->signal_change.current_noise,
Sunil Ravi77d572f2023-01-17 23:58:31 +00005948 data->signal_change.data.current_tx_rate);
5949 os_memcpy(&wpa_s->last_signal_info, data,
5950 sizeof(struct wpa_signal_info));
5951 wpas_notify_signal_change(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005952 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005953 case EVENT_INTERFACE_MAC_CHANGED:
5954 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005955 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005956 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005957 case EVENT_INTERFACE_ENABLED:
5958 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5959 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005960 u8 addr[ETH_ALEN];
5961
Hai Shalomfdcde762020-04-02 11:19:20 -07005962 eloop_cancel_timeout(wpas_clear_disabled_interface,
5963 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005964 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005965 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005966 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5967 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5968 else
5969 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005970 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005971 if (wpa_s->p2p_mgmt) {
5972 wpa_supplicant_set_state(wpa_s,
5973 WPA_DISCONNECTED);
5974 break;
5975 }
5976
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005977#ifdef CONFIG_AP
5978 if (!wpa_s->ap_iface) {
5979 wpa_supplicant_set_state(wpa_s,
5980 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005981 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005982 wpa_supplicant_req_scan(wpa_s, 0, 0);
5983 } else
5984 wpa_supplicant_set_state(wpa_s,
5985 WPA_COMPLETED);
5986#else /* CONFIG_AP */
5987 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5988 wpa_supplicant_req_scan(wpa_s, 0, 0);
5989#endif /* CONFIG_AP */
5990 }
5991 break;
5992 case EVENT_INTERFACE_DISABLED:
5993 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005994#ifdef CONFIG_P2P
5995 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5996 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5997 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5998 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005999 * Mark interface disabled if this happens to end up not
6000 * being removed as a separate P2P group interface.
6001 */
6002 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6003 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006004 * The interface was externally disabled. Remove
6005 * it assuming an external entity will start a
6006 * new session if needed.
6007 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006008 if (wpa_s->current_ssid &&
6009 wpa_s->current_ssid->p2p_group)
6010 wpas_p2p_interface_unavailable(wpa_s);
6011 else
6012 wpas_p2p_disconnect(wpa_s);
6013 /*
6014 * wpa_s instance may have been freed, so must not use
6015 * it here anymore.
6016 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006017 break;
6018 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006019 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6020 p2p_in_progress(wpa_s->global->p2p) > 1) {
6021 /* This radio work will be cancelled, so clear P2P
6022 * state as well.
6023 */
6024 p2p_stop_find(wpa_s->global->p2p);
6025 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006026#endif /* CONFIG_P2P */
6027
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07006028 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6029 /*
6030 * Indicate disconnection to keep ctrl_iface events
6031 * consistent.
6032 */
6033 wpa_supplicant_event_disassoc(
6034 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6035 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006036 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07006037 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08006038 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6039 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006040 clear_at.usec = 0;
6041 } else {
6042 struct os_reltime tmp;
6043
Hai Shalom60840252021-02-19 19:02:11 -08006044 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07006045 tmp.usec = 0;
6046 os_reltime_sub(&tmp, &age, &clear_at);
6047 }
6048 eloop_register_timeout(clear_at.sec, clear_at.usec,
6049 wpas_clear_disabled_interface,
6050 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08006051 radio_remove_works(wpa_s, NULL, 0);
6052
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006053 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6054 break;
6055 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07006056 wpa_supplicant_update_channel_list(
6057 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006058 break;
6059 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006060 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006061 break;
6062 case EVENT_BEST_CHANNEL:
6063 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6064 "(%d %d %d)",
6065 data->best_chan.freq_24, data->best_chan.freq_5,
6066 data->best_chan.freq_overall);
6067 wpa_s->best_24_freq = data->best_chan.freq_24;
6068 wpa_s->best_5_freq = data->best_chan.freq_5;
6069 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006070 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6071 data->best_chan.freq_5,
6072 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006073 break;
6074 case EVENT_UNPROT_DEAUTH:
6075 wpa_supplicant_event_unprot_deauth(wpa_s,
6076 &data->unprot_deauth);
6077 break;
6078 case EVENT_UNPROT_DISASSOC:
6079 wpa_supplicant_event_unprot_disassoc(wpa_s,
6080 &data->unprot_disassoc);
6081 break;
6082 case EVENT_STATION_LOW_ACK:
6083#ifdef CONFIG_AP
6084 if (wpa_s->ap_iface && data)
6085 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6086 data->low_ack.addr);
6087#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006088#ifdef CONFIG_TDLS
6089 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07006090 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
6091 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006092#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006093 break;
6094 case EVENT_IBSS_PEER_LOST:
6095#ifdef CONFIG_IBSS_RSN
6096 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6097#endif /* CONFIG_IBSS_RSN */
6098 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006099 case EVENT_DRIVER_GTK_REKEY:
6100 if (os_memcmp(data->driver_gtk_rekey.bssid,
6101 wpa_s->bssid, ETH_ALEN))
6102 break;
6103 if (!wpa_s->wpa)
6104 break;
6105 wpa_sm_update_replay_ctr(wpa_s->wpa,
6106 data->driver_gtk_rekey.replay_ctr);
6107 break;
6108 case EVENT_SCHED_SCAN_STOPPED:
6109 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006110 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006111 wpa_supplicant_notify_scanning(wpa_s, 0);
6112
6113 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6114 break;
6115
6116 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006117 * If the driver stopped scanning without being requested to,
6118 * request a new scan to continue scanning for networks.
6119 */
6120 if (!wpa_s->sched_scan_stop_req &&
6121 wpa_s->wpa_state == WPA_SCANNING) {
6122 wpa_dbg(wpa_s, MSG_DEBUG,
6123 "Restart scanning after unexpected sched_scan stop event");
6124 wpa_supplicant_req_scan(wpa_s, 1, 0);
6125 break;
6126 }
6127
6128 wpa_s->sched_scan_stop_req = 0;
6129
6130 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006131 * Start a new sched scan to continue searching for more SSIDs
6132 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006133 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006134 if (wpa_s->sched_scan_timed_out) {
6135 wpa_supplicant_req_sched_scan(wpa_s);
6136 } else if (wpa_s->pno_sched_pending) {
6137 wpa_s->pno_sched_pending = 0;
6138 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006139 } else if (resched) {
6140 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006141 }
6142
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006143 break;
6144 case EVENT_WPS_BUTTON_PUSHED:
6145#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006146 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006147#endif /* CONFIG_WPS */
6148 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006149 case EVENT_AVOID_FREQUENCIES:
6150 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6151 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006152 case EVENT_CONNECT_FAILED_REASON:
6153#ifdef CONFIG_AP
6154 if (!wpa_s->ap_iface || !data)
6155 break;
6156 hostapd_event_connect_failed_reason(
6157 wpa_s->ap_iface->bss[0],
6158 data->connect_failed_reason.addr,
6159 data->connect_failed_reason.code);
6160#endif /* CONFIG_AP */
6161 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006162 case EVENT_NEW_PEER_CANDIDATE:
6163#ifdef CONFIG_MESH
6164 if (!wpa_s->ifmsh || !data)
6165 break;
6166 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6167 data->mesh_peer.ies,
6168 data->mesh_peer.ie_len);
6169#endif /* CONFIG_MESH */
6170 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006171 case EVENT_SURVEY:
6172#ifdef CONFIG_AP
6173 if (!wpa_s->ap_iface)
6174 break;
6175 hostapd_event_get_survey(wpa_s->ap_iface,
6176 &data->survey_results);
6177#endif /* CONFIG_AP */
6178 break;
6179 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006180#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006181#ifdef CONFIG_ACS
6182 if (!wpa_s->ap_iface)
6183 break;
6184 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6185 &data->acs_selected_channels);
6186#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006187#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006188 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006189 case EVENT_P2P_LO_STOP:
6190#ifdef CONFIG_P2P
6191 wpa_s->p2p_lo_started = 0;
6192 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6193 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6194 data->p2p_lo_stop.reason_code);
6195#endif /* CONFIG_P2P */
6196 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006197 case EVENT_BEACON_LOSS:
6198 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6199 break;
6200 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6201 bgscan_notify_beacon_loss(wpa_s);
6202 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006203 case EVENT_EXTERNAL_AUTH:
6204#ifdef CONFIG_SAE
6205 if (!wpa_s->current_ssid) {
6206 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6207 break;
6208 }
6209 sme_external_auth_trigger(wpa_s, data);
6210#endif /* CONFIG_SAE */
6211 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006212#ifdef CONFIG_PASN
6213 case EVENT_PASN_AUTH:
6214 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6215 break;
6216#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006217 case EVENT_PORT_AUTHORIZED:
Sunil Ravi77d572f2023-01-17 23:58:31 +00006218#ifndef CONFIG_NO_WPA
6219 if (data->port_authorized.td_bitmap_len) {
6220 wpa_printf(MSG_DEBUG,
6221 "WPA3: Transition Disable bitmap from the driver event: 0x%x",
6222 data->port_authorized.td_bitmap[0]);
6223 wpas_transition_disable(
6224 wpa_s, data->port_authorized.td_bitmap[0]);
6225 }
6226#endif /* CONFIG_NO_WPA */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006227 wpa_supplicant_event_port_authorized(wpa_s);
6228 break;
6229 case EVENT_STATION_OPMODE_CHANGED:
6230#ifdef CONFIG_AP
6231 if (!wpa_s->ap_iface || !data)
6232 break;
6233
6234 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6235 data->sta_opmode.addr,
6236 data->sta_opmode.smps_mode,
6237 data->sta_opmode.chan_width,
6238 data->sta_opmode.rx_nss);
6239#endif /* CONFIG_AP */
6240 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07006241 case EVENT_UNPROT_BEACON:
6242 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6243 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08006244 case EVENT_TX_WAIT_EXPIRE:
6245#ifdef CONFIG_DPP
6246 wpas_dpp_tx_wait_expire(wpa_s);
6247#endif /* CONFIG_DPP */
6248 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006249 default:
6250 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6251 break;
6252 }
6253}
Dmitry Shmidte4663042016-04-04 10:07:49 -07006254
6255
6256void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6257 union wpa_event_data *data)
6258{
6259 struct wpa_supplicant *wpa_s;
6260
6261 if (event != EVENT_INTERFACE_STATUS)
6262 return;
6263
6264 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6265 if (wpa_s && wpa_s->driver->get_ifindex) {
6266 unsigned int ifindex;
6267
6268 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6269 if (ifindex != data->interface_status.ifindex) {
6270 wpa_dbg(wpa_s, MSG_DEBUG,
6271 "interface status ifindex %d mismatch (%d)",
6272 ifindex, data->interface_status.ifindex);
6273 return;
6274 }
6275 }
6276#ifdef CONFIG_MATCH_IFACE
6277 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6278 struct wpa_interface *wpa_i;
6279
6280 wpa_i = wpa_supplicant_match_iface(
6281 ctx, data->interface_status.ifname);
6282 if (!wpa_i)
6283 return;
6284 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6285 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006286 }
6287#endif /* CONFIG_MATCH_IFACE */
6288
6289 if (wpa_s)
6290 wpa_supplicant_event(wpa_s, event, data);
6291}