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