blob: 43c93446c028e86006444fb6d50a7276939db5cd [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
143 if (ssid->ssid_len > 0)
144 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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700186static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
187{
188 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700189 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700190 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700191 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700193 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700194 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700195
196 if (wpa_s->current_ssid->ssid_len == 0)
197 return 0; /* current profile still in use */
198 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
199 if (res < 0) {
200 wpa_msg(wpa_s, MSG_INFO,
201 "Failed to read SSID from driver");
202 return 0; /* try to use current profile */
203 }
204 drv_ssid_len = res;
205
206 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
207 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
208 drv_ssid_len) == 0)
209 return 0; /* current profile still in use */
210
Hai Shalomfdcde762020-04-02 11:19:20 -0700211#ifdef CONFIG_OWE
212 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
213 wpa_s->current_bss &&
214 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
215 drv_ssid_len == wpa_s->current_bss->ssid_len &&
216 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
217 drv_ssid_len) == 0)
218 return 0; /* current profile still in use */
219#endif /* CONFIG_OWE */
220
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700221 wpa_msg(wpa_s, MSG_DEBUG,
222 "Driver-initiated BSS selection changed the SSID to %s",
223 wpa_ssid_txt(drv_ssid, drv_ssid_len));
224 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700225 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226
227 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
228 "information");
229 ssid = wpa_supplicant_get_ssid(wpa_s);
230 if (ssid == NULL) {
231 wpa_msg(wpa_s, MSG_INFO,
232 "No network configuration found for the current AP");
233 return -1;
234 }
235
Dmitry Shmidt04949592012-07-19 12:16:46 -0700236 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
238 return -1;
239 }
240
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800241 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
242 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
243 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
244 return -1;
245 }
246
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700247 res = wpas_temp_disabled(wpa_s, ssid);
248 if (res > 0) {
249 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
250 "disabled for %d second(s)", res);
251 return -1;
252 }
253
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
255 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800256 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257 u8 wpa_ie[80];
258 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800259 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
260 wpa_ie, &wpa_ie_len) < 0)
261 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262 } else {
263 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
264 }
265
266 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
267 eapol_sm_invalidate_cached_session(wpa_s->eapol);
268 old_ssid = wpa_s->current_ssid;
269 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800270
Sunil Ravia04bd252022-05-02 22:54:18 -0700271 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800272
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
274 wpa_supplicant_initiate_eapol(wpa_s);
275 if (old_ssid != wpa_s->current_ssid)
276 wpas_notify_network_changed(wpa_s);
277
278 return 0;
279}
280
281
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800282void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283{
284 struct wpa_supplicant *wpa_s = eloop_ctx;
285
286 if (wpa_s->countermeasures) {
287 wpa_s->countermeasures = 0;
288 wpa_drv_set_countermeasures(wpa_s, 0);
289 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800290
291 /*
292 * It is possible that the device is sched scanning, which means
293 * that a connection attempt will be done only when we receive
294 * scan results. However, in this case, it would be preferable
295 * to scan and connect immediately, so cancel the sched_scan and
296 * issue a regular scan flow.
297 */
298 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299 wpa_supplicant_req_scan(wpa_s, 0, 0);
300 }
301}
302
303
Sunil Ravi89eba102022-09-13 21:04:37 -0700304static void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
305{
306 int i;
307
308 if (!wpa_s->valid_links)
309 return;
310
311 wpa_s->valid_links = 0;
312 for (i = 0; i < MAX_NUM_MLD_LINKS; i++)
313 wpa_s->links[i].bss = NULL;
314}
315
316
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
318{
319 int bssid_changed;
320
Dmitry Shmidt04949592012-07-19 12:16:46 -0700321 wnm_bss_keep_alive_deinit(wpa_s);
322
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323#ifdef CONFIG_IBSS_RSN
324 ibss_rsn_deinit(wpa_s->ibss_rsn);
325 wpa_s->ibss_rsn = NULL;
326#endif /* CONFIG_IBSS_RSN */
327
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700328#ifdef CONFIG_AP
329 wpa_supplicant_ap_deinit(wpa_s);
330#endif /* CONFIG_AP */
331
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700332#ifdef CONFIG_HS20
333 /* Clear possibly configured frame filters */
334 wpa_drv_configure_frame_filters(wpa_s, 0);
335#endif /* CONFIG_HS20 */
336
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
338 return;
339
Hai Shalom74f70d42019-02-11 14:42:39 -0800340 if (os_reltime_initialized(&wpa_s->session_start)) {
341 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
342 wpa_s->session_start.sec = 0;
343 wpa_s->session_start.usec = 0;
344 wpas_notify_session_length(wpa_s);
345 }
346
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
348 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
349 os_memset(wpa_s->bssid, 0, ETH_ALEN);
350 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800351 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352 wpa_s->current_bss = NULL;
353 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700355 if (bssid_changed)
356 wpas_notify_bssid_changed(wpa_s);
357
Hai Shalome21d4e82020-04-29 16:34:06 -0700358 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
359 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700360 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
361 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700362 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700363 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700364 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700365 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700366 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700367 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700368 wpa_s->key_mgmt = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700369 wpa_s->allowed_key_mgmts = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800370
371 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800372 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800373 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700374 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700375
376#ifdef CONFIG_TESTING_OPTIONS
377 wpa_s->last_tk_alg = WPA_ALG_NONE;
378 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
379#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700380 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800381
382 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
383 wpa_s->enabled_4addr_mode = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700384
385 wpas_reset_mlo_info(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700386}
387
388
389static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
390{
391 struct wpa_ie_data ie;
392 int pmksa_set = -1;
393 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800394 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700395
Hai Shalomc1a21442022-02-04 13:43:00 -0800396 /* Start with assumption of no PMKSA cache entry match for cases other
397 * than SAE. In particular, this is needed to generate the PMKSA cache
398 * entries for Suite B cases with driver-based roaming indication. */
399 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
400 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
401 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
404 ie.pmkid == NULL)
405 return;
406
407 for (i = 0; i < ie.num_pmkid; i++) {
408 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
409 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700410 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800412 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700413 break;
414 }
415 }
416
417 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
418 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
419}
420
421
422static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
423 union wpa_event_data *data)
424{
425 if (data == NULL) {
426 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
427 "event");
428 return;
429 }
430 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
431 " index=%d preauth=%d",
432 MAC2STR(data->pmkid_candidate.bssid),
433 data->pmkid_candidate.index,
434 data->pmkid_candidate.preauth);
435
436 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
437 data->pmkid_candidate.index,
438 data->pmkid_candidate.preauth);
439}
440
441
442static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
443{
444 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
445 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
446 return 0;
447
448#ifdef IEEE8021X_EAPOL
449 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
450 wpa_s->current_ssid &&
451 !(wpa_s->current_ssid->eapol_flags &
452 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
453 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
454 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
455 * plaintext or static WEP keys). */
456 return 0;
457 }
458#endif /* IEEE8021X_EAPOL */
459
460 return 1;
461}
462
463
464/**
465 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
466 * @wpa_s: pointer to wpa_supplicant data
467 * @ssid: Configuration data for the network
468 * Returns: 0 on success, -1 on failure
469 *
470 * This function is called when starting authentication with a network that is
471 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
472 */
473int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
474 struct wpa_ssid *ssid)
475{
476#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800477#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700478 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700480 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
481 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482 return 0;
483
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700484 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485 sim = 1;
486 aka = 1;
487 } else {
488 struct eap_method_type *eap = ssid->eap.eap_methods;
489 while (eap->vendor != EAP_VENDOR_IETF ||
490 eap->method != EAP_TYPE_NONE) {
491 if (eap->vendor == EAP_VENDOR_IETF) {
492 if (eap->method == EAP_TYPE_SIM)
493 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700494 else if (eap->method == EAP_TYPE_AKA ||
495 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700496 aka = 1;
497 }
498 eap++;
499 }
500 }
501
502 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
503 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700504 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
505 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
506 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 aka = 0;
508
509 if (!sim && !aka) {
510 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
511 "use SIM, but neither EAP-SIM nor EAP-AKA are "
512 "enabled");
513 return 0;
514 }
515
516 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
517 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700519 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 if (wpa_s->scard == NULL) {
521 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
522 "(pcsc-lite)");
523 return -1;
524 }
525 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
526 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800527#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528#endif /* IEEE8021X_EAPOL */
529
530 return 0;
531}
532
533
534#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700535
Hai Shalomfdcde762020-04-02 11:19:20 -0700536#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700537static int has_wep_key(struct wpa_ssid *ssid)
538{
539 int i;
540
541 for (i = 0; i < NUM_WEP_KEYS; i++) {
542 if (ssid->wep_key_len[i])
543 return 1;
544 }
545
546 return 0;
547}
Hai Shalomfdcde762020-04-02 11:19:20 -0700548#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700549
550
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700551static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552 struct wpa_ssid *ssid)
553{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700554 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555
556 if (ssid->mixed_cell)
557 return 1;
558
559#ifdef CONFIG_WPS
560 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
561 return 1;
562#endif /* CONFIG_WPS */
563
Roshan Pius3a1667e2018-07-03 15:17:14 -0700564#ifdef CONFIG_OWE
565 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
566 return 1;
567#endif /* CONFIG_OWE */
568
Hai Shalomfdcde762020-04-02 11:19:20 -0700569#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700570 if (has_wep_key(ssid))
571 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700572#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700573
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574#ifdef IEEE8021X_EAPOL
575 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
576 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
577 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
578 privacy = 1;
579#endif /* IEEE8021X_EAPOL */
580
Jouni Malinen75ecf522011-06-27 15:19:46 -0700581 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
582 privacy = 1;
583
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800584 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
585 privacy = 1;
586
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700587 if (bss->caps & IEEE80211_CAP_PRIVACY)
588 return privacy;
589 return !privacy;
590}
591
592
593static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
594 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800595 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596{
597 struct wpa_ie_data ie;
598 int proto_match = 0;
599 const u8 *rsn_ie, *wpa_ie;
600 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700601#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700603#endif /* CONFIG_WEP */
Sunil Ravia04bd252022-05-02 22:54:18 -0700604 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605
606 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
607 if (ret >= 0)
608 return ret;
609
Hai Shalomfdcde762020-04-02 11:19:20 -0700610#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700611 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
612 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
613 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
614 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
615 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700616#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700617
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700618 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Sunil Ravia04bd252022-05-02 22:54:18 -0700619 if (is_6ghz_bss && !rsn_ie) {
620 if (debug_print)
621 wpa_dbg(wpa_s, MSG_DEBUG,
622 " skip - 6 GHz BSS without RSNE");
623 return 0;
624 }
625
Roshan Pius3a1667e2018-07-03 15:17:14 -0700626 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627 proto_match++;
628
629 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800630 if (debug_print)
631 wpa_dbg(wpa_s, MSG_DEBUG,
632 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633 break;
634 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700635 if (!ie.has_pairwise)
636 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
637 if (!ie.has_group)
638 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639
Sunil Ravia04bd252022-05-02 22:54:18 -0700640 if (is_6ghz_bss) {
641 /* WEP and TKIP are not allowed on 6 GHz */
642 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
643 WPA_CIPHER_WEP104 |
644 WPA_CIPHER_TKIP);
645 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
646 WPA_CIPHER_WEP104 |
647 WPA_CIPHER_TKIP);
648 }
649
Hai Shalomfdcde762020-04-02 11:19:20 -0700650#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700651 if (wep_ok &&
652 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
653 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800654 if (debug_print)
655 wpa_dbg(wpa_s, MSG_DEBUG,
656 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700657 return 1;
658 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700659#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700660
Roshan Pius3a1667e2018-07-03 15:17:14 -0700661 if (!(ie.proto & ssid->proto) &&
662 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800663 if (debug_print)
664 wpa_dbg(wpa_s, MSG_DEBUG,
665 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666 break;
667 }
668
669 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800670 if (debug_print)
671 wpa_dbg(wpa_s, MSG_DEBUG,
672 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673 break;
674 }
675
676 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800677 if (debug_print)
678 wpa_dbg(wpa_s, MSG_DEBUG,
679 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680 break;
681 }
682
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700683 if (ssid->group_mgmt_cipher &&
684 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
685 if (debug_print)
686 wpa_dbg(wpa_s, MSG_DEBUG,
687 " skip RSN IE - group mgmt cipher mismatch");
688 break;
689 }
690
Sunil Ravia04bd252022-05-02 22:54:18 -0700691 if (is_6ghz_bss) {
692 /* MFPC must be supported on 6 GHz */
693 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
694 if (debug_print)
695 wpa_dbg(wpa_s, MSG_DEBUG,
696 " skip RSNE - 6 GHz without MFPC");
697 break;
698 }
699
700 /* WPA PSK is not allowed on the 6 GHz band */
701 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
702 WPA_KEY_MGMT_FT_PSK |
703 WPA_KEY_MGMT_PSK_SHA256);
704 }
705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800707 if (debug_print)
708 wpa_dbg(wpa_s, MSG_DEBUG,
709 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710 break;
711 }
712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700713 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800714 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800715 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800716 if (debug_print)
717 wpa_dbg(wpa_s, MSG_DEBUG,
718 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719 break;
720 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800721 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
722 wpas_get_ssid_pmf(wpa_s, ssid) ==
723 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800724 if (debug_print)
725 wpa_dbg(wpa_s, MSG_DEBUG,
726 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800727 break;
728 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800730 if (debug_print)
731 wpa_dbg(wpa_s, MSG_DEBUG,
732 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 return 1;
734 }
735
Sunil Ravia04bd252022-05-02 22:54:18 -0700736 if (is_6ghz_bss) {
737 if (debug_print)
738 wpa_dbg(wpa_s, MSG_DEBUG,
739 " skip - 6 GHz BSS without matching RSNE");
740 return 0;
741 }
742
Roshan Pius3a1667e2018-07-03 15:17:14 -0700743 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
744 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800745 if (debug_print)
746 wpa_dbg(wpa_s, MSG_DEBUG,
747 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700748 return 0;
749 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700750
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700751 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
753 proto_match++;
754
755 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800756 if (debug_print)
757 wpa_dbg(wpa_s, MSG_DEBUG,
758 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759 break;
760 }
761
Hai Shalomfdcde762020-04-02 11:19:20 -0700762#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 if (wep_ok &&
764 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
765 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800766 if (debug_print)
767 wpa_dbg(wpa_s, MSG_DEBUG,
768 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 return 1;
770 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700771#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700772
773 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800774 if (debug_print)
775 wpa_dbg(wpa_s, MSG_DEBUG,
776 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700777 break;
778 }
779
780 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800781 if (debug_print)
782 wpa_dbg(wpa_s, MSG_DEBUG,
783 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784 break;
785 }
786
787 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800788 if (debug_print)
789 wpa_dbg(wpa_s, MSG_DEBUG,
790 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700791 break;
792 }
793
794 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800795 if (debug_print)
796 wpa_dbg(wpa_s, MSG_DEBUG,
797 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798 break;
799 }
800
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800801 if (debug_print)
802 wpa_dbg(wpa_s, MSG_DEBUG,
803 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 return 1;
805 }
806
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700807 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
808 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800809 if (debug_print)
810 wpa_dbg(wpa_s, MSG_DEBUG,
811 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700812 return 1;
813 }
814
Roshan Pius3a1667e2018-07-03 15:17:14 -0700815#ifdef CONFIG_OWE
816 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
817 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800818 if (wpa_s->owe_transition_select &&
819 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
820 ssid->owe_transition_bss_select_count + 1 <=
821 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
822 ssid->owe_transition_bss_select_count++;
823 if (debug_print)
824 wpa_dbg(wpa_s, MSG_DEBUG,
825 " skip OWE transition BSS (selection count %d does not exceed %d)",
826 ssid->owe_transition_bss_select_count,
827 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
828 wpa_s->owe_transition_search = 1;
829 return 0;
830 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700831 if (debug_print)
832 wpa_dbg(wpa_s, MSG_DEBUG,
833 " allow in OWE transition mode");
834 return 1;
835 }
836#endif /* CONFIG_OWE */
837
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
839 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800840 if (debug_print)
841 wpa_dbg(wpa_s, MSG_DEBUG,
842 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843 return 0;
844 }
845
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800846 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
847 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800848 if (debug_print)
849 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800850 return 1;
851 }
852
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700853 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800854 if (debug_print)
855 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856 return 1;
857 }
858
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800859 if (debug_print)
860 wpa_dbg(wpa_s, MSG_DEBUG,
861 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862
863 return 0;
864}
865
866
867static int freq_allowed(int *freqs, int freq)
868{
869 int i;
870
871 if (freqs == NULL)
872 return 1;
873
874 for (i = 0; freqs[i]; i++)
875 if (freqs[i] == freq)
876 return 1;
877 return 0;
878}
879
880
Hai Shalomfdcde762020-04-02 11:19:20 -0700881static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
882 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800883{
884 const struct hostapd_hw_modes *mode = NULL, *modes;
885 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
886 const u8 *rate_ie;
887 int i, j, k;
888
889 if (bss->freq == 0)
890 return 1; /* Cannot do matching without knowing band */
891
892 modes = wpa_s->hw.modes;
893 if (modes == NULL) {
894 /*
895 * The driver does not provide any additional information
896 * about the utilized hardware, so allow the connection attempt
897 * to continue.
898 */
899 return 1;
900 }
901
902 for (i = 0; i < wpa_s->hw.num_modes; i++) {
903 for (j = 0; j < modes[i].num_channels; j++) {
904 int freq = modes[i].channels[j].freq;
905 if (freq == bss->freq) {
906 if (mode &&
907 mode->mode == HOSTAPD_MODE_IEEE80211G)
908 break; /* do not allow 802.11b replace
909 * 802.11g */
910 mode = &modes[i];
911 break;
912 }
913 }
914 }
915
916 if (mode == NULL)
917 return 0;
918
919 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700920 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800921 if (rate_ie == NULL)
922 continue;
923
924 for (j = 2; j < rate_ie[1] + 2; j++) {
925 int flagged = !!(rate_ie[j] & 0x80);
926 int r = (rate_ie[j] & 0x7f) * 5;
927
928 /*
929 * IEEE Std 802.11n-2009 7.3.2.2:
930 * The new BSS Membership selector value is encoded
931 * like a legacy basic rate, but it is not a rate and
932 * only indicates if the BSS members are required to
933 * support the mandatory features of Clause 20 [HT PHY]
934 * in order to join the BSS.
935 */
936 if (flagged && ((rate_ie[j] & 0x7f) ==
937 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
938 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800939 if (debug_print)
940 wpa_dbg(wpa_s, MSG_DEBUG,
941 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800942 return 0;
943 }
944 continue;
945 }
946
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700947 /* There's also a VHT selector for 802.11ac */
948 if (flagged && ((rate_ie[j] & 0x7f) ==
949 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
950 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800951 if (debug_print)
952 wpa_dbg(wpa_s, MSG_DEBUG,
953 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700954 return 0;
955 }
956 continue;
957 }
958
Hai Shalomc3565922019-10-28 11:58:20 -0700959#ifdef CONFIG_SAE
960 if (flagged && ((rate_ie[j] & 0x7f) ==
961 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700962 if (wpa_s->conf->sae_pwe == 0 &&
963 !ssid->sae_password_id &&
964 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700965 if (debug_print)
966 wpa_dbg(wpa_s, MSG_DEBUG,
967 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800968#ifdef CONFIG_TESTING_OPTIONS
969 if (wpa_s->ignore_sae_h2e_only) {
970 wpa_dbg(wpa_s, MSG_DEBUG,
971 "TESTING: Ignore SAE H2E requirement mismatch");
972 continue;
973 }
974#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700975 return 0;
976 }
977 continue;
978 }
979#endif /* CONFIG_SAE */
980
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800981 if (!flagged)
982 continue;
983
984 /* check for legacy basic rates */
985 for (k = 0; k < mode->num_rates; k++) {
986 if (mode->rates[k] == r)
987 break;
988 }
989 if (k == mode->num_rates) {
990 /*
991 * IEEE Std 802.11-2007 7.3.2.2 demands that in
992 * order to join a BSS all required rates
993 * have to be supported by the hardware.
994 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800995 if (debug_print)
996 wpa_dbg(wpa_s, MSG_DEBUG,
997 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
998 r / 10, r % 10,
999 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001000 return 0;
1001 }
1002 }
1003 }
1004
1005 return 1;
1006}
1007
1008
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001009/*
1010 * Test whether BSS is in an ESS.
1011 * This is done differently in DMG (60 GHz) and non-DMG bands
1012 */
1013static int bss_is_ess(struct wpa_bss *bss)
1014{
1015 if (bss_is_dmg(bss)) {
1016 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1017 IEEE80211_CAP_DMG_AP;
1018 }
1019
1020 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1021 IEEE80211_CAP_ESS);
1022}
1023
1024
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001025static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1026{
1027 size_t i;
1028
1029 for (i = 0; i < ETH_ALEN; i++) {
1030 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1031 return 0;
1032 }
1033 return 1;
1034}
1035
1036
1037static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1038{
1039 size_t i;
1040
1041 for (i = 0; i < num; i++) {
1042 const u8 *a = list + i * ETH_ALEN * 2;
1043 const u8 *m = a + ETH_ALEN;
1044
1045 if (match_mac_mask(a, addr, m))
1046 return 1;
1047 }
1048 return 0;
1049}
1050
1051
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001052static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1053 const u8 **ret_ssid, size_t *ret_ssid_len)
1054{
1055#ifdef CONFIG_OWE
1056 const u8 *owe, *pos, *end, *bssid;
1057 u8 ssid_len;
1058 struct wpa_bss *open_bss;
1059
1060 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1061 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
1062 return;
1063
1064 pos = owe + 6;
1065 end = owe + 2 + owe[1];
1066
1067 if (end - pos < ETH_ALEN + 1)
1068 return;
1069 bssid = pos;
1070 pos += ETH_ALEN;
1071 ssid_len = *pos++;
1072 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1073 return;
1074
1075 /* Match the profile SSID against the OWE transition mode SSID on the
1076 * open network. */
1077 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1078 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1079 *ret_ssid = pos;
1080 *ret_ssid_len = ssid_len;
1081
Hai Shalomfdcde762020-04-02 11:19:20 -07001082 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1083 struct wpa_ssid *ssid;
1084
1085 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1086 if (wpas_network_disabled(wpa_s, ssid))
1087 continue;
1088 if (ssid->ssid_len == ssid_len &&
1089 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1090 /* OWE BSS in transition mode for a currently
1091 * enabled OWE network. */
1092 wpa_dbg(wpa_s, MSG_DEBUG,
1093 "OWE: transition mode OWE SSID for active OWE profile");
1094 bss->flags |= WPA_BSS_OWE_TRANSITION;
1095 break;
1096 }
1097 }
1098 }
1099
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001100 if (bss->ssid_len > 0)
1101 return;
1102
1103 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1104 if (!open_bss)
1105 return;
1106 if (ssid_len != open_bss->ssid_len ||
1107 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1108 wpa_dbg(wpa_s, MSG_DEBUG,
1109 "OWE: transition mode SSID mismatch: %s",
1110 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1111 return;
1112 }
1113
1114 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1115 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1116 wpa_dbg(wpa_s, MSG_DEBUG,
1117 "OWE: transition mode open BSS unexpected info");
1118 return;
1119 }
1120
1121 pos = owe + 6;
1122 end = owe + 2 + owe[1];
1123
1124 if (end - pos < ETH_ALEN + 1)
1125 return;
1126 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1127 wpa_dbg(wpa_s, MSG_DEBUG,
1128 "OWE: transition mode BSSID mismatch: " MACSTR,
1129 MAC2STR(pos));
1130 return;
1131 }
1132 pos += ETH_ALEN;
1133 ssid_len = *pos++;
1134 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1135 return;
1136 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1137 wpa_ssid_txt(pos, ssid_len));
1138 os_memcpy(bss->ssid, pos, ssid_len);
1139 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001140 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001141#endif /* CONFIG_OWE */
1142}
1143
1144
Sunil Ravi26978f32021-04-30 15:19:18 -07001145int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001146{
1147 int i, j;
1148
1149 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1150 return 0;
1151
1152 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1153 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1154
1155 for (i = 0; i < mode->num_channels; i++) {
1156 struct hostapd_channel_data *chan = &mode->channels[i];
1157
1158 if (chan->freq == freq)
1159 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1160 }
1161 }
1162
1163 return 1;
1164}
1165
1166
Hai Shalom899fcc72020-10-19 14:38:18 -07001167static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1168 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001169 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001170 bool debug_print);
1171
1172
1173#ifdef CONFIG_SAE_PK
1174static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1175 struct wpa_bss *orig_bss,
1176 struct wpa_ssid *ssid,
1177 const u8 *match_ssid,
1178 size_t match_ssid_len)
1179{
1180 struct wpa_bss *bss;
1181
1182 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1183 int count;
1184 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001185
1186 if (bss == orig_bss)
1187 continue;
1188 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001189 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001190 continue;
1191
1192 /* TODO: Could be more thorough in checking what kind of
1193 * signal strength or throughput estimate would be acceptable
1194 * compared to the originally selected BSS. */
1195 if (bss->est_throughput < 2000)
1196 return false;
1197
Hai Shalom60840252021-02-19 19:02:11 -08001198 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001199 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1200 bss, count, 0))
1201 return true;
1202 }
1203
1204 return false;
1205}
1206#endif /* CONFIG_SAE_PK */
1207
1208
1209static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1210 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001211 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001212 bool debug_print)
1213{
1214 int res;
1215 bool wpa, check_ssid, osen, rsn_osen = false;
1216 struct wpa_ie_data data;
1217#ifdef CONFIG_MBO
1218 const u8 *assoc_disallow;
1219#endif /* CONFIG_MBO */
1220#ifdef CONFIG_SAE
1221 u8 rsnxe_capa = 0;
1222#endif /* CONFIG_SAE */
1223 const u8 *ie;
1224
1225 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1226 wpa = ie && ie[1];
1227 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1228 wpa |= ie && ie[1];
1229 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1230 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1231 rsn_osen = true;
1232 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1233 osen = ie != NULL;
1234
1235#ifdef CONFIG_SAE
1236 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1237 if (ie && ie[1] >= 1)
1238 rsnxe_capa = ie[2];
1239#endif /* CONFIG_SAE */
1240
1241 check_ssid = wpa || ssid->ssid_len > 0;
1242
1243 if (wpas_network_disabled(wpa_s, ssid)) {
1244 if (debug_print)
1245 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1246 return false;
1247 }
1248
1249 res = wpas_temp_disabled(wpa_s, ssid);
1250 if (res > 0) {
1251 if (debug_print)
1252 wpa_dbg(wpa_s, MSG_DEBUG,
1253 " skip - disabled temporarily for %d second(s)",
1254 res);
1255 return false;
1256 }
1257
1258#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001259 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001260 if (debug_print)
1261 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001262 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001263 return false;
1264 }
1265
1266 if (wpa && ssid->ssid_len == 0 &&
1267 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1268 check_ssid = false;
1269
1270 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1271 /* Only allow wildcard SSID match if an AP advertises active
1272 * WPS operation that matches our mode. */
1273 check_ssid = ssid->ssid_len > 0 ||
1274 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1275 }
1276#endif /* CONFIG_WPS */
1277
1278 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1279 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1280 check_ssid = false;
1281
1282 if (check_ssid &&
1283 (match_ssid_len != ssid->ssid_len ||
1284 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1285 if (debug_print)
1286 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1287 return false;
1288 }
1289
1290 if (ssid->bssid_set &&
1291 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1292 if (debug_print)
1293 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1294 return false;
1295 }
1296
Hai Shalom60840252021-02-19 19:02:11 -08001297 /* check the list of BSSIDs to ignore */
1298 if (ssid->num_bssid_ignore &&
1299 addr_in_list(bss->bssid, ssid->bssid_ignore,
1300 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001301 if (debug_print)
1302 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001303 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001304 return false;
1305 }
1306
Hai Shalom60840252021-02-19 19:02:11 -08001307 /* if there is a list of accepted BSSIDs, only accept those APs */
1308 if (ssid->num_bssid_accept &&
1309 !addr_in_list(bss->bssid, ssid->bssid_accept,
1310 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001311 if (debug_print)
1312 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001313 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001314 return false;
1315 }
1316
1317 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1318 return false;
1319
1320 if (!osen && !wpa &&
1321 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1322 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1323 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1324 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1325 if (debug_print)
1326 wpa_dbg(wpa_s, MSG_DEBUG,
1327 " skip - non-WPA network not allowed");
1328 return false;
1329 }
1330
1331#ifdef CONFIG_WEP
1332 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1333 if (debug_print)
1334 wpa_dbg(wpa_s, MSG_DEBUG,
1335 " skip - ignore WPA/WPA2 AP for WEP network block");
1336 return false;
1337 }
1338#endif /* CONFIG_WEP */
1339
1340 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1341 if (debug_print)
1342 wpa_dbg(wpa_s, MSG_DEBUG,
1343 " skip - non-OSEN network not allowed");
1344 return false;
1345 }
1346
1347 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1348 if (debug_print)
1349 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1350 return false;
1351 }
1352
1353 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1354 !bss_is_pbss(bss)) {
1355 if (debug_print)
1356 wpa_dbg(wpa_s, MSG_DEBUG,
1357 " skip - not ESS, PBSS, or MBSS");
1358 return false;
1359 }
1360
1361 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1362 if (debug_print)
1363 wpa_dbg(wpa_s, MSG_DEBUG,
1364 " skip - PBSS mismatch (ssid %d bss %d)",
1365 ssid->pbss, bss_is_pbss(bss));
1366 return false;
1367 }
1368
1369 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1370 if (debug_print)
1371 wpa_dbg(wpa_s, MSG_DEBUG,
1372 " skip - frequency not allowed");
1373 return false;
1374 }
1375
1376#ifdef CONFIG_MESH
1377 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1378 ssid->frequency != bss->freq) {
1379 if (debug_print)
1380 wpa_dbg(wpa_s, MSG_DEBUG,
1381 " skip - frequency not allowed (mesh)");
1382 return false;
1383 }
1384#endif /* CONFIG_MESH */
1385
1386 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1387 if (debug_print)
1388 wpa_dbg(wpa_s, MSG_DEBUG,
1389 " skip - rate sets do not match");
1390 return false;
1391 }
1392
1393#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001394 /* When using SAE Password Identifier and when operationg on the 6 GHz
1395 * band, only H2E is allowed. */
1396 if ((wpa_s->conf->sae_pwe == 1 || is_6ghz_freq(bss->freq) ||
1397 ssid->sae_password_id) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001398 wpa_s->conf->sae_pwe != 3 && wpa_key_mgmt_sae(ssid->key_mgmt) &&
Vinayak Yadawad14709082022-03-17 14:25:11 +05301399#ifdef CONFIG_DRIVER_NL80211_BRCM
1400 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
1401#endif /* CONFIG_DRIVER_NL80211_BRCM */
Hai Shalom899fcc72020-10-19 14:38:18 -07001402 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1403 if (debug_print)
1404 wpa_dbg(wpa_s, MSG_DEBUG,
1405 " skip - SAE H2E required, but not supported by the AP");
1406 return false;
1407 }
1408#endif /* CONFIG_SAE */
1409
1410#ifdef CONFIG_SAE_PK
1411 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1412 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1413 if (debug_print)
1414 wpa_dbg(wpa_s, MSG_DEBUG,
1415 " skip - SAE-PK required, but not supported by the AP");
1416 return false;
1417 }
1418#endif /* CONFIG_SAE_PK */
1419
1420#ifndef CONFIG_IBSS_RSN
1421 if (ssid->mode == WPAS_MODE_IBSS &&
1422 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1423 if (debug_print)
1424 wpa_dbg(wpa_s, MSG_DEBUG,
1425 " skip - IBSS RSN not supported in the build");
1426 return false;
1427 }
1428#endif /* !CONFIG_IBSS_RSN */
1429
1430#ifdef CONFIG_P2P
1431 if (ssid->p2p_group &&
1432 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1433 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1434 if (debug_print)
1435 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1436 return false;
1437 }
1438
1439 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1440 struct wpabuf *p2p_ie;
1441 u8 dev_addr[ETH_ALEN];
1442
1443 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1444 if (!ie) {
1445 if (debug_print)
1446 wpa_dbg(wpa_s, MSG_DEBUG,
1447 " skip - no P2P element");
1448 return false;
1449 }
1450 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1451 if (!p2p_ie) {
1452 if (debug_print)
1453 wpa_dbg(wpa_s, MSG_DEBUG,
1454 " skip - could not fetch P2P element");
1455 return false;
1456 }
1457
1458 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1459 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1460 if (debug_print)
1461 wpa_dbg(wpa_s, MSG_DEBUG,
1462 " skip - no matching GO P2P Device Address in P2P element");
1463 wpabuf_free(p2p_ie);
1464 return false;
1465 }
1466 wpabuf_free(p2p_ie);
1467 }
1468
1469 /*
1470 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1471 * P2P Group Capability Bitmap and we are not in Group Formation with
1472 * that device.
1473 */
1474#endif /* CONFIG_P2P */
1475
1476 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1477 struct os_reltime diff;
1478
1479 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1480 if (debug_print)
1481 wpa_dbg(wpa_s, MSG_DEBUG,
1482 " skip - scan result not recent enough (%u.%06u seconds too old)",
1483 (unsigned int) diff.sec,
1484 (unsigned int) diff.usec);
1485 return false;
1486 }
1487#ifdef CONFIG_MBO
1488#ifdef CONFIG_TESTING_OPTIONS
1489 if (wpa_s->ignore_assoc_disallow)
1490 goto skip_assoc_disallow;
1491#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001492 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001493 if (assoc_disallow && assoc_disallow[1] >= 1) {
1494 if (debug_print)
1495 wpa_dbg(wpa_s, MSG_DEBUG,
1496 " skip - MBO association disallowed (reason %u)",
1497 assoc_disallow[2]);
1498 return false;
1499 }
1500
1501 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1502 if (debug_print)
1503 wpa_dbg(wpa_s, MSG_DEBUG,
1504 " skip - AP temporarily disallowed");
1505 return false;
1506 }
1507#ifdef CONFIG_TESTING_OPTIONS
1508skip_assoc_disallow:
1509#endif /* CONFIG_TESTING_OPTIONS */
1510#endif /* CONFIG_MBO */
1511
1512#ifdef CONFIG_DPP
1513 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1514 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1515 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1516 !ssid->dpp_csign)) {
1517 if (debug_print)
1518 wpa_dbg(wpa_s, MSG_DEBUG,
1519 " skip - no PMKSA entry for DPP");
1520 return false;
1521 }
1522#endif /* CONFIG_DPP */
1523
1524#ifdef CONFIG_SAE_PK
1525 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1526 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1527 ((ssid->sae_password &&
1528 sae_pk_valid_password(ssid->sae_password)) ||
1529 (!ssid->sae_password && ssid->passphrase &&
1530 sae_pk_valid_password(ssid->passphrase))) &&
1531 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1532 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1533 match_ssid_len)) {
1534 if (debug_print)
1535 wpa_dbg(wpa_s, MSG_DEBUG,
1536 " skip - another acceptable BSS with SAE-PK in the same ESS");
1537 return false;
1538 }
1539#endif /* CONFIG_SAE_PK */
1540
1541 if (bss->ssid_len == 0) {
1542 if (debug_print)
1543 wpa_dbg(wpa_s, MSG_DEBUG,
1544 " skip - no SSID known for the BSS");
1545 return false;
1546 }
1547
1548 /* Matching configuration found */
1549 return true;
1550}
1551
1552
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001553struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1554 int i, struct wpa_bss *bss,
1555 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001556 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001557{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001558 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001559 const u8 *ie;
1560 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001561 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001562 const u8 *match_ssid;
1563 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001564 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001566 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001567 wpa_ie_len = ie ? ie[1] : 0;
1568
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001569 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001570 rsn_ie_len = ie ? ie[1] : 0;
1571
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001572 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1573 osen = ie != NULL;
1574
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001575 if (debug_print) {
1576 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1577 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1578 i, MAC2STR(bss->bssid),
1579 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1580 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1581 bss->freq,
1582 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1583 " wps" : "",
1584 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1585 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1586 ? " p2p" : "",
1587 osen ? " osen=1" : "");
1588 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001589
Hai Shalom60840252021-02-19 19:02:11 -08001590 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1591 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001592 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001593 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001594 /*
1595 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001596 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001597 * should not be done with multiple enabled networks to
1598 * avoid getting forced to move into a worse ESS on
1599 * single error if there are no other BSSes of the
1600 * current ESS.
1601 */
1602 limit = 0;
1603 }
Hai Shalom60840252021-02-19 19:02:11 -08001604 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001605 if (debug_print) {
1606 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001607 " skip - BSSID ignored (count=%d limit=%d)",
1608 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001609 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001610 return NULL;
1611 }
1612 }
1613
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001614 match_ssid = bss->ssid;
1615 match_ssid_len = bss->ssid_len;
1616 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1617
1618 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001619 if (debug_print)
1620 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621 return NULL;
1622 }
1623
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001624 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001625 if (debug_print)
1626 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001627 return NULL;
1628 }
1629
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001630 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001631 if (debug_print)
1632 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001633 return NULL;
1634 }
1635
Hai Shalomfdcde762020-04-02 11:19:20 -07001636 if (disabled_freq(wpa_s, bss->freq)) {
1637 if (debug_print)
1638 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1639 return NULL;
1640 }
1641
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001642 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001643 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001644 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001645 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001646 }
1647
1648 /* No matching configuration found */
1649 return NULL;
1650}
1651
1652
1653static struct wpa_bss *
1654wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001656 struct wpa_ssid **selected_ssid,
1657 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001658{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001659 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001661 if (wpa_s->current_ssid) {
1662 struct wpa_ssid *ssid;
1663
1664 wpa_dbg(wpa_s, MSG_DEBUG,
1665 "Scan results matching the currently selected network");
1666 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1667 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1668
1669 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1670 only_first_ssid, 0);
1671 if (ssid != wpa_s->current_ssid)
1672 continue;
1673 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1674 " freq=%d level=%d snr=%d est_throughput=%u",
1675 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1676 bss->snr, bss->est_throughput);
1677 }
1678 }
1679
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001680 if (only_first_ssid)
1681 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1682 group->id);
1683 else
1684 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1685 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001686
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001687 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1688 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001689
1690 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001691 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001692 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001693 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001694 if (!*selected_ssid)
1695 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001696 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001698 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001699 MAC2STR(bss->bssid),
1700 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1701 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001702 }
1703
1704 return NULL;
1705}
1706
1707
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001708struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1709 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001710{
1711 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001712 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001713 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001714 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001716 if (wpa_s->last_scan_res == NULL ||
1717 wpa_s->last_scan_res_used == 0)
1718 return NULL; /* no scan results from last update */
1719
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001720 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001721 /* check that next_ssid is still valid */
1722 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1723 if (ssid == wpa_s->next_ssid)
1724 break;
1725 }
1726 next_ssid = ssid;
1727 wpa_s->next_ssid = NULL;
1728 }
1729
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001730 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001731 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1732 if (next_ssid && next_ssid->priority ==
1733 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001734 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001735 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001736 if (selected)
1737 break;
1738 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001739 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001740 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001741 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001742 if (selected)
1743 break;
1744 }
1745
Hai Shalom60840252021-02-19 19:02:11 -08001746 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001747 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001748 wpa_dbg(wpa_s, MSG_DEBUG,
1749 "No APs found - clear BSSID ignore list and try again");
1750 wpa_bssid_ignore_clear(wpa_s);
1751 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001752 } else if (selected == NULL)
1753 break;
1754 }
1755
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001756 ssid = *selected_ssid;
1757 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1758 !ssid->passphrase && !ssid->ext_psk) {
1759 const char *field_name, *txt = NULL;
1760
1761 wpa_dbg(wpa_s, MSG_DEBUG,
1762 "PSK/passphrase not yet available for the selected network");
1763
1764 wpas_notify_network_request(wpa_s, ssid,
1765 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1766
1767 field_name = wpa_supplicant_ctrl_req_to_string(
1768 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1769 if (field_name == NULL)
1770 return NULL;
1771
1772 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1773
1774 selected = NULL;
1775 }
1776
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777 return selected;
1778}
1779
1780
1781static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1782 int timeout_sec, int timeout_usec)
1783{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001784 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001785 /*
1786 * No networks are enabled; short-circuit request so
1787 * we don't wait timeout seconds before transitioning
1788 * to INACTIVE state.
1789 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001790 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1791 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001792 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1793 return;
1794 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001795
1796 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1798}
1799
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001800
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001801int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001802 struct wpa_bss *selected,
1803 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001804{
1805 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1806 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1807 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001808 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001809#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001810 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1811 wpa_s->p2p_in_provisioning) {
1812 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1813 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001814 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001815 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001816#endif /* CONFIG_P2P */
1817
1818#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001819 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 wpas_wps_cancel(wpa_s);
1821#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001822 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823 }
1824
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001825 wpa_msg(wpa_s, MSG_DEBUG,
1826 "Considering connect request: reassociate: %d selected: "
1827 MACSTR " bssid: " MACSTR " pending: " MACSTR
1828 " wpa_state: %s ssid=%p current_ssid=%p",
1829 wpa_s->reassociate, MAC2STR(selected->bssid),
1830 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1831 wpa_supplicant_state_txt(wpa_s->wpa_state),
1832 ssid, wpa_s->current_ssid);
1833
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834 /*
1835 * Do not trigger new association unless the BSSID has changed or if
1836 * reassociation is requested. If we are in process of associating with
1837 * the selected BSSID, do not trigger new attempt.
1838 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001839 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001840 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1841 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1842 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001843 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1844 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1845 0) ||
1846 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1847 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001848 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1849 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001850 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001851 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001852 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1853 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001854 wpa_supplicant_associate(wpa_s, selected, ssid);
1855 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001856 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1857 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001859
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001860 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001861}
1862
1863
1864static struct wpa_ssid *
1865wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1866{
Hai Shalomfdcde762020-04-02 11:19:20 -07001867 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001868 struct wpa_ssid *ssid;
1869
1870 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1871 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1872 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001873 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001875#ifndef CONFIG_IBSS_RSN
1876 if (ssid->mode == WPAS_MODE_IBSS &&
1877 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1878 WPA_KEY_MGMT_WPA_NONE))) {
1879 wpa_msg(wpa_s, MSG_INFO,
1880 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1881 wpa_ssid_txt(ssid->ssid,
1882 ssid->ssid_len));
1883 continue;
1884 }
1885#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001886 if (ssid->mode == WPAS_MODE_IBSS ||
1887 ssid->mode == WPAS_MODE_AP ||
1888 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001889 return ssid;
1890 }
1891 }
1892 return NULL;
1893}
1894
1895
1896/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1897 * on BSS added and BSS changed events */
1898static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001899 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001900{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001901 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001902
1903 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1904 return;
1905
Jouni Malinen87fd2792011-05-16 18:35:42 +03001906 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001907 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001908
Jouni Malinen87fd2792011-05-16 18:35:42 +03001909 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001910 if (ssid == NULL)
1911 continue;
1912
Jouni Malinen87fd2792011-05-16 18:35:42 +03001913 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001914 if (rsn == NULL)
1915 continue;
1916
Jouni Malinen87fd2792011-05-16 18:35:42 +03001917 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001918 }
1919
1920}
1921
1922
Hai Shalomfdcde762020-04-02 11:19:20 -07001923#ifndef CONFIG_NO_ROAMING
1924
1925static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1926{
1927 if (noise == WPA_INVALID_NOISE)
1928 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1929 DEFAULT_NOISE_FLOOR_2GHZ;
1930 return avg_signal - noise;
1931}
1932
1933
1934static unsigned int
1935wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1936 const struct wpa_bss *bss, int snr)
1937{
1938 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001939 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001940 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1941
Hai Shalomc1a21442022-02-04 13:43:00 -08001942 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07001943}
1944
Hai Shalomfdcde762020-04-02 11:19:20 -07001945
Hai Shalom899fcc72020-10-19 14:38:18 -07001946int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1947 struct wpa_bss *current_bss,
1948 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001949{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001950 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001951 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001952 int cur_level;
1953 unsigned int cur_est, sel_est;
1954 struct wpa_signal_info si;
1955 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001956 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001957
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001958 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001959 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001960 " freq=%d level=%d snr=%d est_throughput=%u",
1961 MAC2STR(current_bss->bssid),
1962 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001963 current_bss->snr, current_bss->est_throughput);
1964 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001965 " freq=%d level=%d snr=%d est_throughput=%u",
1966 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001967 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001968
1969 if (wpa_s->current_ssid->bssid_set &&
1970 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1971 0) {
1972 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1973 "has preferred BSSID");
1974 return 1;
1975 }
1976
Hai Shalomfdcde762020-04-02 11:19:20 -07001977 cur_level = current_bss->level;
1978 cur_est = current_bss->est_throughput;
1979 sel_est = selected->est_throughput;
1980
1981 /*
1982 * Try to poll the signal from the driver since this will allow to get
1983 * more accurate values. In some cases, there can be big differences
1984 * between the RSSI of the Probe Response frames of the AP we are
1985 * associated with and the Beacon frames we hear from the same AP after
1986 * association. This can happen, e.g., when there are two antennas that
1987 * hear the AP very differently. If the driver chooses to hear the
1988 * Probe Response frames during the scan on the "bad" antenna because
1989 * it wants to save power, but knows to choose the other antenna after
1990 * association, we will hear our AP with a low RSSI as part of the
1991 * scan even when we can hear it decently on the other antenna. To cope
1992 * with this, ask the driver to teach us how it hears the AP. Also, the
1993 * scan results may be a bit old, since we can very quickly get fresh
1994 * information about our currently associated AP.
1995 */
1996 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1997 (si.avg_beacon_signal || si.avg_signal)) {
1998 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1999 si.avg_signal;
2000 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2001 si.current_noise);
2002
2003 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2004 current_bss,
2005 cur_snr);
2006 wpa_dbg(wpa_s, MSG_DEBUG,
2007 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2008 cur_level, cur_snr, cur_est);
2009 }
2010
2011 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002012 wpa_dbg(wpa_s, MSG_DEBUG,
2013 "Allow reassociation - selected BSS has better estimated throughput");
2014 return 1;
2015 }
2016
Dmitry Shmidte4663042016-04-04 10:07:49 -07002017 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
2018
Hai Shalomfdcde762020-04-02 11:19:20 -07002019 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
2020 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002021 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2022 "signal level");
2023 return 0;
2024 }
2025
Hai Shalomfdcde762020-04-02 11:19:20 -07002026 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002027 wpa_dbg(wpa_s, MSG_DEBUG,
2028 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002029 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002030 }
2031
Hai Shalomfdcde762020-04-02 11:19:20 -07002032 if (cur_snr > GREAT_SNR) {
2033 wpa_dbg(wpa_s, MSG_DEBUG,
2034 "Skip roam - Current BSS has good SNR (%u > %u)",
2035 cur_snr, GREAT_SNR);
2036 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002037 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002038
Hai Shalomfdcde762020-04-02 11:19:20 -07002039 if (cur_level < -85) /* ..-86 dBm */
2040 min_diff = 1;
2041 else if (cur_level < -80) /* -85..-81 dBm */
2042 min_diff = 2;
2043 else if (cur_level < -75) /* -80..-76 dBm */
2044 min_diff = 3;
2045 else if (cur_level < -70) /* -75..-71 dBm */
2046 min_diff = 4;
2047 else if (cur_level < 0) /* -70..-1 dBm */
2048 min_diff = 5;
2049 else /* unspecified units (not in dBm) */
2050 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002051
Hai Shalomfdcde762020-04-02 11:19:20 -07002052 if (cur_est > sel_est * 1.5)
2053 min_diff += 10;
2054 else if (cur_est > sel_est * 1.2)
2055 min_diff += 5;
2056 else if (cur_est > sel_est * 1.1)
2057 min_diff += 2;
2058 else if (cur_est > sel_est)
2059 min_diff++;
2060 else if (sel_est > cur_est * 1.5)
2061 min_diff -= 10;
2062 else if (sel_est > cur_est * 1.2)
2063 min_diff -= 5;
2064 else if (sel_est > cur_est * 1.1)
2065 min_diff -= 2;
2066 else if (sel_est > cur_est)
2067 min_diff--;
2068
2069 if (to_5ghz)
2070 min_diff -= 2;
2071 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002072 if (diff < min_diff) {
2073 wpa_dbg(wpa_s, MSG_DEBUG,
2074 "Skip roam - too small difference in signal level (%d < %d)",
2075 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002076 ret = 0;
2077 } else {
2078 wpa_dbg(wpa_s, MSG_DEBUG,
2079 "Allow reassociation due to difference in signal level (%d >= %d)",
2080 diff, min_diff);
2081 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002083 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2084 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2085 " sel_freq=%d sel_level=%d sel_est=%d",
2086 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2087 MAC2STR(current_bss->bssid),
2088 current_bss->freq, cur_level, cur_est,
2089 MAC2STR(selected->bssid),
2090 selected->freq, selected->level, sel_est);
2091 return ret;
2092}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002093
Hai Shalom899fcc72020-10-19 14:38:18 -07002094#endif /* CONFIG_NO_ROAMING */
2095
2096
2097static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2098 struct wpa_bss *selected,
2099 struct wpa_ssid *ssid)
2100{
2101 struct wpa_bss *current_bss = NULL;
2102
2103 if (wpa_s->reassociate)
2104 return 1; /* explicit request to reassociate */
2105 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2106 return 1; /* we are not associated; continue */
2107 if (wpa_s->current_ssid == NULL)
2108 return 1; /* unknown current SSID */
2109 if (wpa_s->current_ssid != ssid)
2110 return 1; /* different network block */
2111
2112 if (wpas_driver_bss_selection(wpa_s))
2113 return 0; /* Driver-based roaming */
2114
2115 if (wpa_s->current_ssid->ssid)
2116 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2117 wpa_s->current_ssid->ssid,
2118 wpa_s->current_ssid->ssid_len);
2119 if (!current_bss)
2120 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2121
2122 if (!current_bss)
2123 return 1; /* current BSS not seen in scan results */
2124
2125 if (current_bss == selected)
2126 return 0;
2127
2128 if (selected->last_update_idx > current_bss->last_update_idx)
2129 return 1; /* current BSS not seen in the last scan */
2130
2131#ifndef CONFIG_NO_ROAMING
2132 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2133 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002134#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002135 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002136#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002137}
2138
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002139
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002140/*
2141 * Return a negative value if no scan results could be fetched or if scan
2142 * results should not be shared with other virtual interfaces.
2143 * Return 0 if scan results were fetched and may be shared with other
2144 * interfaces.
2145 * Return 1 if scan results may be shared with other virtual interfaces but may
2146 * not trigger any operations.
2147 * Return 2 if the interface was removed and cannot be used.
2148 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002149static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002150 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002151 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002152{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002153 struct wpa_scan_results *scan_res = NULL;
2154 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002156#ifndef CONFIG_NO_RANDOM_POOL
2157 size_t i, num;
2158#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002159
2160#ifdef CONFIG_AP
2161 if (wpa_s->ap_iface)
2162 ap = 1;
2163#endif /* CONFIG_AP */
2164
2165 wpa_supplicant_notify_scanning(wpa_s, 0);
2166
2167 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2168 data ? &data->scan_info :
2169 NULL, 1);
2170 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002171 if (wpa_s->conf->ap_scan == 2 || ap ||
2172 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002173 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002174 if (!own_request)
2175 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002176 if (data && data->scan_info.external_scan)
2177 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002178 if (wpa_s->scan_res_fail_handler) {
2179 void (*handler)(struct wpa_supplicant *wpa_s);
2180
2181 handler = wpa_s->scan_res_fail_handler;
2182 wpa_s->scan_res_fail_handler = NULL;
2183 handler(wpa_s);
2184 } else {
2185 wpa_dbg(wpa_s, MSG_DEBUG,
2186 "Failed to get scan results - try scanning again");
2187 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2188 }
2189
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002190 ret = -1;
2191 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002192 }
2193
2194#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002195 num = scan_res->num;
2196 if (num > 10)
2197 num = 10;
2198 for (i = 0; i < num; i++) {
2199 u8 buf[5];
2200 struct wpa_scan_res *res = scan_res->res[i];
2201 buf[0] = res->bssid[5];
2202 buf[1] = res->qual & 0xff;
2203 buf[2] = res->noise & 0xff;
2204 buf[3] = res->level & 0xff;
2205 buf[4] = res->tsf & 0xff;
2206 random_add_randomness(buf, sizeof(buf));
2207 }
2208#endif /* CONFIG_NO_RANDOM_POOL */
2209
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002210 if (update_only) {
2211 ret = 1;
2212 goto scan_work_done;
2213 }
2214
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002215 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002216 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2218 struct wpa_scan_results *scan_res);
2219
2220 scan_res_handler = wpa_s->scan_res_handler;
2221 wpa_s->scan_res_handler = NULL;
2222 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002223 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002224 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002225 }
2226
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002227 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002228 wpa_s->own_scan_running,
2229 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002230 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002231 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2232 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002233 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2234 wpa_s->manual_scan_id);
2235 wpa_s->manual_scan_use_id = 0;
2236 } else {
2237 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2238 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002239 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002240
2241 wpas_notify_scan_done(wpa_s, 1);
2242
Hai Shalomfdcde762020-04-02 11:19:20 -07002243 if (ap) {
2244 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2245#ifdef CONFIG_AP
2246 if (wpa_s->ap_iface->scan_cb)
2247 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2248#endif /* CONFIG_AP */
2249 goto scan_work_done;
2250 }
2251
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002252 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002253 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 -07002254 wpa_scan_results_free(scan_res);
2255 return 0;
2256 }
2257
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002258 if (wnm_scan_process(wpa_s, 1) > 0)
2259 goto scan_work_done;
2260
Hai Shalomc1a21442022-02-04 13:43:00 -08002261 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002262 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263
Hai Shalom021b0b52019-04-10 11:17:58 -07002264 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002265 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2266 goto scan_work_done;
2267
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002268 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2269 goto scan_work_done;
2270
2271 if (autoscan_notify_scan(wpa_s, scan_res))
2272 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002273
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274 if (wpa_s->disconnected) {
2275 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002276 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002277 }
2278
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002279 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002280 bgscan_notify_scan(wpa_s, scan_res) == 1)
2281 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002282
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002283 wpas_wps_update_ap_info(wpa_s, scan_res);
2284
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002285 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2286 wpa_s->wpa_state < WPA_COMPLETED)
2287 goto scan_work_done;
2288
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002289 wpa_scan_results_free(scan_res);
2290
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002291 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002292 struct wpa_radio_work *work = wpa_s->scan_work;
2293 wpa_s->scan_work = NULL;
2294 radio_work_done(work);
2295 }
2296
Hai Shalomc3565922019-10-28 11:58:20 -07002297 os_free(wpa_s->last_scan_freqs);
2298 wpa_s->last_scan_freqs = NULL;
2299 wpa_s->num_last_scan_freqs = 0;
2300 if (own_request && data &&
2301 data->scan_info.freqs && data->scan_info.num_freqs) {
2302 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2303 data->scan_info.num_freqs);
2304 if (wpa_s->last_scan_freqs) {
2305 os_memcpy(wpa_s->last_scan_freqs,
2306 data->scan_info.freqs,
2307 sizeof(int) * data->scan_info.num_freqs);
2308 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2309 }
2310 }
2311
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002312 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002313
2314scan_work_done:
2315 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002316 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002317 struct wpa_radio_work *work = wpa_s->scan_work;
2318 wpa_s->scan_work = NULL;
2319 radio_work_done(work);
2320 }
2321 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002322}
2323
2324
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002325static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002326 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002327{
2328 struct wpa_bss *selected;
2329 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002330 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2331
2332 if (time_to_reenable > 0) {
2333 wpa_dbg(wpa_s, MSG_DEBUG,
2334 "Postpone network selection by %d seconds since all networks are disabled",
2335 time_to_reenable);
2336 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2337 eloop_register_timeout(time_to_reenable, 0,
2338 wpas_network_reenabled, wpa_s, NULL);
2339 return 0;
2340 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002341
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002342 if (wpa_s->p2p_mgmt)
2343 return 0; /* no normal connection on p2p_mgmt interface */
2344
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002345 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002346 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002347
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002348#ifdef CONFIG_MESH
2349 if (wpa_s->ifmsh) {
2350 wpa_msg(wpa_s, MSG_INFO,
2351 "Avoiding join because we already joined a mesh group");
2352 return 0;
2353 }
2354#endif /* CONFIG_MESH */
2355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002356 if (selected) {
2357 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002358 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002359 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002360 if (new_scan)
2361 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002362 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002363 }
2364
Hai Shalomc3565922019-10-28 11:58:20 -07002365 wpa_s->suitable_network++;
2366
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002367 if (ssid != wpa_s->current_ssid &&
2368 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2369 wpa_s->own_disconnect_req = 1;
2370 wpa_supplicant_deauthenticate(
2371 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2372 }
2373
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002374 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002375 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002376 return -1;
2377 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002378 if (new_scan)
2379 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002380 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002381 * Do not allow other virtual radios to trigger operations based
2382 * on these scan results since we do not want them to start
2383 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002384 */
2385 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002386 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002387 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002388 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2389 ssid = wpa_supplicant_pick_new_network(wpa_s);
2390 if (ssid) {
2391 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2392 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002393 if (new_scan)
2394 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002395 } else if (own_request) {
2396 /*
2397 * No SSID found. If SCAN results are as a result of
2398 * own scan request and not due to a scan request on
2399 * another shared interface, try another scan.
2400 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002401 int timeout_sec = wpa_s->scan_interval;
2402 int timeout_usec = 0;
2403#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002404 int res;
2405
2406 res = wpas_p2p_scan_no_go_seen(wpa_s);
2407 if (res == 2)
2408 return 2;
2409 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002410 return 0;
2411
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002412 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002413 wpa_s->show_group_started ||
2414 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002415 /*
2416 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002417 * state and during P2P join-a-group operation
2418 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002419 */
2420 timeout_sec = 0;
2421 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002422 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2423 timeout_usec);
2424 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002425 }
2426#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002427#ifdef CONFIG_INTERWORKING
2428 if (wpa_s->conf->auto_interworking &&
2429 wpa_s->conf->interworking &&
2430 wpa_s->conf->cred) {
2431 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2432 "start ANQP fetch since no matching "
2433 "networks found");
2434 wpa_s->network_select = 1;
2435 wpa_s->auto_network_select = 1;
2436 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002437 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002438 }
2439#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002440#ifdef CONFIG_WPS
2441 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2442 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2443 timeout_sec = 0;
2444 timeout_usec = 500000;
2445 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2446 timeout_usec);
2447 return 0;
2448 }
2449#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002450#ifdef CONFIG_OWE
2451 if (wpa_s->owe_transition_search) {
2452 wpa_dbg(wpa_s, MSG_DEBUG,
2453 "OWE: Use shorter wait during transition mode search");
2454 timeout_sec = 0;
2455 timeout_usec = 500000;
2456 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2457 timeout_usec);
2458 return 0;
2459 }
2460#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002461 if (wpa_supplicant_req_sched_scan(wpa_s))
2462 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2463 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002464
2465 wpa_msg_ctrl(wpa_s, MSG_INFO,
2466 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002467 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002468 }
2469 }
2470 return 0;
2471}
2472
2473
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002474static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2475 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002476{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002477 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002478 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002479
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002480 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002481 if (res == 2) {
2482 /*
2483 * Interface may have been removed, so must not dereference
2484 * wpa_s after this.
2485 */
2486 return 1;
2487 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002488
2489 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002490 /*
2491 * If no scan results could be fetched, then no need to
2492 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002493 * this scan. Similarly, if scan results started a new operation on this
2494 * interface, do not notify other interfaces to avoid concurrent
2495 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002496 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002497 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002498 }
2499
2500 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002501 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002502 * so, they get updated with this same scan info.
2503 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002504 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2505 radio_list) {
2506 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002507 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2508 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002509 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2510 res > 0);
2511 if (res < 0)
2512 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002513 }
2514 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002515
2516 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002517}
2518
2519#endif /* CONFIG_NO_SCAN_PROCESSING */
2520
2521
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002522int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2523{
2524#ifdef CONFIG_NO_SCAN_PROCESSING
2525 return -1;
2526#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002527 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002528
Dmitry Shmidt29333592017-01-09 12:27:11 -08002529 wpa_s->ignore_post_flush_scan_res = 0;
2530
Dmitry Shmidt41712582015-06-29 11:02:15 -07002531 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002532 return -1;
2533
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002534 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002535 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002536 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002537 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2538 return -1;
2539 }
2540
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002541 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002542#endif /* CONFIG_NO_SCAN_PROCESSING */
2543}
2544
Dmitry Shmidt04949592012-07-19 12:16:46 -07002545#ifdef CONFIG_WNM
2546
2547static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2548{
2549 struct wpa_supplicant *wpa_s = eloop_ctx;
2550
2551 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2552 return;
2553
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002554 if (!wpa_s->no_keep_alive) {
2555 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2556 MAC2STR(wpa_s->bssid));
2557 /* TODO: could skip this if normal data traffic has been sent */
2558 /* TODO: Consider using some more appropriate data frame for
2559 * this */
2560 if (wpa_s->l2)
2561 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2562 (u8 *) "", 0);
2563 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002564
2565#ifdef CONFIG_SME
2566 if (wpa_s->sme.bss_max_idle_period) {
2567 unsigned int msec;
2568 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2569 if (msec > 100)
2570 msec -= 100;
2571 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2572 wnm_bss_keep_alive, wpa_s, NULL);
2573 }
2574#endif /* CONFIG_SME */
2575}
2576
2577
2578static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2579 const u8 *ies, size_t ies_len)
2580{
2581 struct ieee802_11_elems elems;
2582
2583 if (ies == NULL)
2584 return;
2585
2586 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2587 return;
2588
2589#ifdef CONFIG_SME
2590 if (elems.bss_max_idle_period) {
2591 unsigned int msec;
2592 wpa_s->sme.bss_max_idle_period =
2593 WPA_GET_LE16(elems.bss_max_idle_period);
2594 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2595 "TU)%s", wpa_s->sme.bss_max_idle_period,
2596 (elems.bss_max_idle_period[2] & 0x01) ?
2597 " (protected keep-live required)" : "");
2598 if (wpa_s->sme.bss_max_idle_period == 0)
2599 wpa_s->sme.bss_max_idle_period = 1;
2600 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2601 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2602 /* msec times 1000 */
2603 msec = wpa_s->sme.bss_max_idle_period * 1024;
2604 if (msec > 100)
2605 msec -= 100;
2606 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2607 wnm_bss_keep_alive, wpa_s,
2608 NULL);
2609 }
2610 }
2611#endif /* CONFIG_SME */
2612}
2613
2614#endif /* CONFIG_WNM */
2615
2616
2617void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2618{
2619#ifdef CONFIG_WNM
2620 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2621#endif /* CONFIG_WNM */
2622}
2623
2624
Dmitry Shmidt051af732013-10-22 13:52:46 -07002625#ifdef CONFIG_INTERWORKING
2626
2627static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2628 size_t len)
2629{
2630 int res;
2631
2632 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2633 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2634 if (res) {
2635 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2636 }
2637
2638 return res;
2639}
2640
2641
2642static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2643 const u8 *ies, size_t ies_len)
2644{
2645 struct ieee802_11_elems elems;
2646
2647 if (ies == NULL)
2648 return;
2649
2650 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2651 return;
2652
2653 if (elems.qos_map_set) {
2654 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2655 elems.qos_map_set_len);
2656 }
2657}
2658
2659#endif /* CONFIG_INTERWORKING */
2660
2661
Hai Shalom74f70d42019-02-11 14:42:39 -08002662static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2663 const u8 *ies, size_t ies_len)
2664{
2665 struct ieee802_11_elems elems;
2666 const u8 *map_sub_elem, *pos;
2667 size_t len;
2668
Hai Shalomfdcde762020-04-02 11:19:20 -07002669 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002670
Hai Shalomfdcde762020-04-02 11:19:20 -07002671 if (!ies ||
2672 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2673 !elems.multi_ap || elems.multi_ap_len < 7)
2674 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002675
2676 pos = elems.multi_ap + 4;
2677 len = elems.multi_ap_len - 4;
2678
2679 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002680 if (!map_sub_elem || map_sub_elem[1] < 1)
2681 return;
2682
2683 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2684 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2685 MULTI_AP_FRONTHAUL_BSS);
2686 wpa_s->multi_ap_ie = 1;
2687}
2688
2689
2690static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2691{
2692 if (!wpa_s->current_ssid ||
2693 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2694 return;
2695
2696 if (!wpa_s->multi_ap_ie) {
2697 wpa_printf(MSG_INFO,
2698 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002699 goto fail;
2700 }
2701
Hai Shalomfdcde762020-04-02 11:19:20 -07002702 if (!wpa_s->multi_ap_backhaul) {
2703 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002704 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2705 wpa_printf(MSG_INFO,
2706 "WPS active, accepting fronthaul-only BSS");
2707 /* Don't set 4addr mode in this case, so just return */
2708 return;
2709 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002710 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2711 goto fail;
2712 }
2713
2714 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2715 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2716 goto fail;
2717 }
2718 wpa_s->enabled_4addr_mode = 1;
2719 return;
2720
2721fail:
2722 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2723}
2724
2725
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002726#ifdef CONFIG_FST
2727static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2728 const u8 *ie, size_t ie_len)
2729{
2730 struct mb_ies_info mb_ies;
2731
2732 if (!ie || !ie_len || !wpa_s->fst)
2733 return -ENOENT;
2734
2735 os_memset(&mb_ies, 0, sizeof(mb_ies));
2736
2737 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2738 size_t len;
2739
2740 len = 2 + ie[1];
2741 if (len > ie_len) {
2742 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2743 ie, ie_len);
2744 break;
2745 }
2746
2747 if (ie[0] == WLAN_EID_MULTI_BAND) {
2748 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2749 (unsigned int) len);
2750 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2751 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2752 mb_ies.nof_ies++;
2753 }
2754
2755 ie_len -= len;
2756 ie += len;
2757 }
2758
2759 if (mb_ies.nof_ies > 0) {
2760 wpabuf_free(wpa_s->received_mb_ies);
2761 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2762 return 0;
2763 }
2764
2765 return -ENOENT;
2766}
2767#endif /* CONFIG_FST */
2768
2769
Hai Shalomc1a21442022-02-04 13:43:00 -08002770static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2771 union wpa_event_data *data)
2772{
2773 int sel;
2774 const u8 *p;
2775 int l, len;
2776 bool found = false;
2777 struct wpa_ie_data ie;
2778 struct wpa_ssid *ssid = wpa_s->current_ssid;
2779 struct wpa_bss *bss = wpa_s->current_bss;
2780 int pmf;
2781
2782 if (!ssid)
2783 return 0;
2784
2785 p = data->assoc_info.req_ies;
2786 l = data->assoc_info.req_ies_len;
2787
2788 while (p && l >= 2) {
2789 len = p[1] + 2;
2790 if (len > l) {
2791 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2792 p, l);
2793 break;
2794 }
2795 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2796 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2797 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2798 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2799 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2800 found = true;
2801 break;
2802 }
2803 l -= len;
2804 p += len;
2805 }
2806
2807 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2808 return 0;
2809
2810 wpa_hexdump(MSG_DEBUG,
2811 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2812 p, l);
2813
2814 /* Update proto from (Re)Association Request frame info */
2815 wpa_s->wpa_proto = ie.proto;
2816 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2817 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2818 !!(wpa_s->wpa_proto &
2819 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2820
2821 /* Update AKMP suite from (Re)Association Request frame info */
2822 sel = ie.key_mgmt;
2823 if (ssid->key_mgmt)
2824 sel &= ssid->key_mgmt;
2825
2826 wpa_dbg(wpa_s, MSG_DEBUG,
2827 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2828 ie.key_mgmt, ssid->key_mgmt, sel);
2829 if (ie.key_mgmt && !sel) {
2830 wpa_supplicant_deauthenticate(
2831 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2832 return -1;
2833 }
2834
Sunil Ravi89eba102022-09-13 21:04:37 -07002835 /*
2836 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
2837 * different AKM.
2838 */
2839 if (wpa_s->key_mgmt != ie.key_mgmt &&
2840 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
2841 if (!ssid->psk_set) {
2842 wpa_dbg(wpa_s, MSG_INFO,
2843 "No PSK available for association");
2844 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE");
2845 return -1;
2846 }
2847
2848 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
2849 if (wpa_s->conf->key_mgmt_offload &&
2850 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
2851 wpa_drv_set_key(wpa_s, 0, NULL, 0, 0, NULL, 0, ssid->psk,
2852 PMK_LEN, KEY_FLAG_PMK))
2853 wpa_dbg(wpa_s, MSG_ERROR,
2854 "WPA: Cannot set PMK for key management offload");
2855 }
2856
Hai Shalomc1a21442022-02-04 13:43:00 -08002857 wpa_s->key_mgmt = ie.key_mgmt;
2858 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2859 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2860 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2861 wpa_s->wpa_proto);
2862
2863 /* Update pairwise cipher from (Re)Association Request frame info */
2864 sel = ie.pairwise_cipher;
2865 if (ssid->pairwise_cipher)
2866 sel &= ssid->pairwise_cipher;
2867
2868 wpa_dbg(wpa_s, MSG_DEBUG,
2869 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2870 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2871 if (ie.pairwise_cipher && !sel) {
2872 wpa_supplicant_deauthenticate(
2873 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2874 return -1;
2875 }
2876
2877 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2878 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2879 wpa_s->pairwise_cipher);
2880 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2881 wpa_cipher_txt(wpa_s->pairwise_cipher));
2882
2883 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2884 if (!bss) {
2885 wpa_dbg(wpa_s, MSG_DEBUG,
2886 "WPA: current_bss == NULL - skip AP IE check");
2887 return 0;
2888 }
2889
2890 /* Update GTK and IGTK from AP's RSNE */
2891 found = false;
2892
2893 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2894 const u8 *bss_rsn;
2895
2896 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2897 if (bss_rsn) {
2898 p = bss_rsn;
2899 len = 2 + bss_rsn[1];
2900 found = true;
2901 }
2902 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2903 const u8 *bss_wpa;
2904
2905 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2906 if (bss_wpa) {
2907 p = bss_wpa;
2908 len = 2 + bss_wpa[1];
2909 found = true;
2910 }
2911 }
2912
2913 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2914 return 0;
2915
2916 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2917 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2918 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
2919 /* AP does not support MFP, local configuration requires it */
2920 wpa_supplicant_deauthenticate(
2921 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2922 return -1;
2923 }
2924 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
2925 pmf == NO_MGMT_FRAME_PROTECTION) {
2926 /* AP requires MFP, local configuration disables it */
2927 wpa_supplicant_deauthenticate(
2928 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2929 return -1;
2930 }
2931
2932 /* Update PMF from local configuration now that MFP validation was done
2933 * above */
2934 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
2935
2936 /* Update GTK from AP's RSNE */
2937 sel = ie.group_cipher;
2938 if (ssid->group_cipher)
2939 sel &= ssid->group_cipher;
2940
2941 wpa_dbg(wpa_s, MSG_DEBUG,
2942 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
2943 ie.group_cipher, ssid->group_cipher, sel);
2944 if (ie.group_cipher && !sel) {
2945 wpa_supplicant_deauthenticate(
2946 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
2947 return -1;
2948 }
2949
2950 wpa_s->group_cipher = ie.group_cipher;
2951 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
2952 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
2953 wpa_cipher_txt(wpa_s->group_cipher));
2954
2955 /* Update IGTK from AP RSN IE */
2956 sel = ie.mgmt_group_cipher;
2957 if (ssid->group_mgmt_cipher)
2958 sel &= ssid->group_mgmt_cipher;
2959
2960 wpa_dbg(wpa_s, MSG_DEBUG,
2961 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
2962 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
2963
2964 if (pmf == NO_MGMT_FRAME_PROTECTION ||
2965 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
2966 wpa_dbg(wpa_s, MSG_DEBUG,
2967 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
2968 ie.capabilities);
2969 ie.mgmt_group_cipher = 0;
2970 }
2971
2972 if (ie.mgmt_group_cipher && !sel) {
2973 wpa_supplicant_deauthenticate(
2974 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
2975 return -1;
2976 }
2977
2978 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
2979 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
2980 wpa_s->mgmt_group_cipher);
2981 if (wpa_s->mgmt_group_cipher)
2982 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
2983 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
2984 else
2985 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
2986
2987 return 0;
2988}
2989
2990
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002991static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2992 union wpa_event_data *data)
2993{
Hai Shalomc3565922019-10-28 11:58:20 -07002994 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002995 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002996 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002997 bool bssid_known;
Vinayak Yadawad14709082022-03-17 14:25:11 +05302998#ifdef CONFIG_DRIVER_NL80211_BRCM
2999 struct wpa_ie_data ie;
3000#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003001
3002 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07003003 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003004 if (data->assoc_info.req_ies)
3005 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3006 data->assoc_info.req_ies_len);
3007 if (data->assoc_info.resp_ies) {
3008 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3009 data->assoc_info.resp_ies_len);
3010#ifdef CONFIG_TDLS
3011 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3012 data->assoc_info.resp_ies_len);
3013#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003014#ifdef CONFIG_WNM
3015 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3016 data->assoc_info.resp_ies_len);
3017#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003018#ifdef CONFIG_INTERWORKING
3019 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3020 data->assoc_info.resp_ies_len);
3021#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003022 if (wpa_s->hw_capab == CAPAB_VHT &&
3023 get_ie(data->assoc_info.resp_ies,
3024 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3025 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003026
3027 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3028 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003029 }
3030 if (data->assoc_info.beacon_ies)
3031 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3032 data->assoc_info.beacon_ies,
3033 data->assoc_info.beacon_ies_len);
3034 if (data->assoc_info.freq)
3035 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3036 data->assoc_info.freq);
3037
Hai Shalom021b0b52019-04-10 11:17:58 -07003038 wpa_s->connection_set = 0;
3039 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3040 struct ieee802_11_elems req_elems, resp_elems;
3041
3042 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3043 data->assoc_info.req_ies_len,
3044 &req_elems, 0) != ParseFailed &&
3045 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3046 data->assoc_info.resp_ies_len,
3047 &resp_elems, 0) != ParseFailed) {
3048 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003049 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3050 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003051 wpa_s->connection_ht = req_elems.ht_capabilities &&
3052 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003053 /* Do not include subset of VHT on 2.4 GHz vendor
3054 * extension in consideration for reporting VHT
3055 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003056 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003057 resp_elems.vht_capabilities &&
3058 (!data->assoc_info.freq ||
3059 wpas_freq_to_band(data->assoc_info.freq) !=
3060 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003061 wpa_s->connection_he = req_elems.he_capabilities &&
3062 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003063 wpa_s->connection_eht = req_elems.eht_capabilities &&
3064 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003065
3066 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3067 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3068 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3069 max_nss_rx_req : max_nss_rx_resp;
3070 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3071 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3072 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3073 max_nss_tx_req : max_nss_tx_resp;
3074
3075 struct supported_chan_width sta_supported_chan_width =
3076 get_supported_channel_width(&req_elems);
3077 enum chan_width ap_operation_chan_width =
3078 get_operation_channel_width(&resp_elems);
3079 if (wpa_s->connection_vht || wpa_s->connection_he) {
3080 wpa_s->connection_channel_bandwidth =
3081 get_sta_operation_chan_width(ap_operation_chan_width,
3082 sta_supported_chan_width);
3083 } else if (wpa_s->connection_ht) {
3084 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3085 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3086 } else {
3087 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3088 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003089 }
3090 }
3091
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003092 p = data->assoc_info.req_ies;
3093 l = data->assoc_info.req_ies_len;
3094
3095 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3096 while (p && l >= 2) {
3097 len = p[1] + 2;
3098 if (len > l) {
3099 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3100 p, l);
3101 break;
3102 }
Hai Shalomc3565922019-10-28 11:58:20 -07003103 if (!found &&
3104 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3105 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3106 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3107 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3108 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003109 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3110 break;
3111 found = 1;
3112 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07003113 }
3114 if (!found_x && p[0] == WLAN_EID_RSNX) {
3115 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3116 break;
3117 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003118 }
3119 l -= len;
3120 p += len;
3121 }
3122 if (!found && data->assoc_info.req_ies)
3123 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003124 if (!found_x && data->assoc_info.req_ies)
3125 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003126
Vinayak Yadawad14709082022-03-17 14:25:11 +05303127#ifdef CONFIG_DRIVER_NL80211_BRCM
3128 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3129 * to a different security type, update the current supplicant configuration to use the AKM
3130 * and pairwise suites from the assoc IE passed by the driver.
3131 */
3132 if (wpas_driver_bss_selection(wpa_s)) {
3133 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3134 /* Check if firmware has roamed to a different security network */
3135 if(wpa_s->key_mgmt != ie.key_mgmt) {
3136 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3137 ie.key_mgmt);
3138 wpa_s->key_mgmt = ie.key_mgmt;
3139 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3140
3141 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3142 /* Restore PMK as it can get overwritten if the previous
3143 * association was to 802.1X.
3144 */
3145 if ((!(wpa_s->drv_flags &
3146 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3147 (wpa_s->current_ssid) &&
3148 (wpa_s->current_ssid->psk_set)) {
3149 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3150 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3151 "BSSID");
3152 wpa_supplicant_deauthenticate(
3153 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3154 return -1;
3155 }
3156 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3157 PMK_LEN, NULL, bssid);
3158 }
3159 }
3160 }
3161 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3162 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3163 "from Assoc IE", ie.pairwise_cipher);
3164 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3165 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3166 wpa_s->pairwise_cipher);
3167 }
3168 // TODO: Notify the framework about security type change b/230766005
3169 }
3170 }
3171#endif /* CONFIG_DRIVER_NL80211_BRCM */
3172
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003173#ifdef CONFIG_FILS
3174#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003175 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3176 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003177 (!data->assoc_info.resp_frame ||
3178 fils_process_assoc_resp(wpa_s->wpa,
3179 data->assoc_info.resp_frame,
3180 data->assoc_info.resp_frame_len) < 0)) {
3181 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3182 return -1;
3183 }
3184#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003185
3186 /* Additional processing for FILS when SME is in driver */
3187 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3188 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3189 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003190#endif /* CONFIG_FILS */
3191
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003192#ifdef CONFIG_OWE
3193 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003194 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003195 owe_process_assoc_resp(wpa_s->wpa, bssid,
3196 data->assoc_info.resp_ies,
3197 data->assoc_info.resp_ies_len) < 0)) {
3198 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3199 return -1;
3200 }
3201#endif /* CONFIG_OWE */
3202
Hai Shalom021b0b52019-04-10 11:17:58 -07003203#ifdef CONFIG_DPP2
3204 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003205 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3206 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003207 struct ieee802_11_elems elems;
3208
3209 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3210 data->assoc_info.resp_ies_len,
3211 &elems, 0) == ParseFailed ||
3212 !elems.owe_dh)
3213 goto no_pfs;
3214 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3215 elems.owe_dh_len) < 0) {
3216 wpa_supplicant_deauthenticate(wpa_s,
3217 WLAN_REASON_UNSPECIFIED);
3218 return -1;
3219 }
3220
3221 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3222 }
3223no_pfs:
3224#endif /* CONFIG_DPP2 */
3225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003226#ifdef CONFIG_IEEE80211R
3227#ifdef CONFIG_SME
3228 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003229 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003230 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3231 data->assoc_info.resp_ies,
3232 data->assoc_info.resp_ies_len,
3233 bssid) < 0) {
3234 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3235 "Reassociation Response failed");
3236 wpa_supplicant_deauthenticate(
3237 wpa_s, WLAN_REASON_INVALID_IE);
3238 return -1;
3239 }
3240 }
3241
3242 p = data->assoc_info.resp_ies;
3243 l = data->assoc_info.resp_ies_len;
3244
3245#ifdef CONFIG_WPS_STRICT
3246 if (p && wpa_s->current_ssid &&
3247 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3248 struct wpabuf *wps;
3249 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3250 if (wps == NULL) {
3251 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3252 "include WPS IE in (Re)Association Response");
3253 return -1;
3254 }
3255
3256 if (wps_validate_assoc_resp(wps) < 0) {
3257 wpabuf_free(wps);
3258 wpa_supplicant_deauthenticate(
3259 wpa_s, WLAN_REASON_INVALID_IE);
3260 return -1;
3261 }
3262 wpabuf_free(wps);
3263 }
3264#endif /* CONFIG_WPS_STRICT */
3265
3266 /* Go through the IEs and make a copy of the MDIE, if present. */
3267 while (p && l >= 2) {
3268 len = p[1] + 2;
3269 if (len > l) {
3270 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3271 p, l);
3272 break;
3273 }
3274 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3275 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3276 wpa_s->sme.ft_used = 1;
3277 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3278 MOBILITY_DOMAIN_ID_LEN);
3279 break;
3280 }
3281 l -= len;
3282 p += len;
3283 }
3284#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003285#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303286 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3287 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3288 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3289 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303290 wpa_ft_is_completed(wpa_s->wpa)) {
3291 return 0;
3292 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003293#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003294
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003295 /* Process FT when SME is in the driver */
3296 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3297 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003298 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003299 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3300 data->assoc_info.resp_ies,
3301 data->assoc_info.resp_ies_len,
3302 bssid) < 0) {
3303 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3304 "Reassociation Response failed");
3305 wpa_supplicant_deauthenticate(
3306 wpa_s, WLAN_REASON_INVALID_IE);
3307 return -1;
3308 }
3309 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3310 }
3311
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003312 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3313 data->assoc_info.resp_ies_len);
3314#endif /* CONFIG_IEEE80211R */
3315
Hai Shalom899fcc72020-10-19 14:38:18 -07003316 if (bssid_known)
3317 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3318 data->assoc_info.resp_ies,
3319 data->assoc_info.resp_ies_len);
3320
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003321 /* WPA/RSN IE from Beacon/ProbeResp */
3322 p = data->assoc_info.beacon_ies;
3323 l = data->assoc_info.beacon_ies_len;
3324
3325 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3326 */
3327 wpa_found = rsn_found = 0;
3328 while (p && l >= 2) {
3329 len = p[1] + 2;
3330 if (len > l) {
3331 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3332 p, l);
3333 break;
3334 }
3335 if (!wpa_found &&
3336 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3337 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3338 wpa_found = 1;
3339 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3340 }
3341
3342 if (!rsn_found &&
3343 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3344 rsn_found = 1;
3345 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3346 }
3347
Hai Shalomc3565922019-10-28 11:58:20 -07003348 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3349 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3350
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003351 l -= len;
3352 p += len;
3353 }
3354
3355 if (!wpa_found && data->assoc_info.beacon_ies)
3356 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003357 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003358 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003359 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3360 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003361 if (wpa_found || rsn_found)
3362 wpa_s->ap_ies_from_associnfo = 1;
3363
Jouni Malinen87fd2792011-05-16 18:35:42 +03003364 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3365 wpa_s->assoc_freq != data->assoc_info.freq) {
3366 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3367 "%u to %u MHz",
3368 wpa_s->assoc_freq, data->assoc_info.freq);
3369 wpa_supplicant_update_scan_results(wpa_s);
3370 }
3371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003372 wpa_s->assoc_freq = data->assoc_info.freq;
3373
Hai Shalomc1a21442022-02-04 13:43:00 -08003374 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3375 data->assoc_info.resp_ies_len);
3376
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003377 return 0;
3378}
3379
3380
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003381static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3382{
Hai Shalomc3565922019-10-28 11:58:20 -07003383 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003384
3385 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3386 return -1;
3387
3388 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3389 return 0;
3390
3391 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3392 WPA_IE_VENDOR_TYPE);
3393 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003394 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003395
3396 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3397 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3398 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003399 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3400 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3401 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003402 return -1;
3403
3404 return 0;
3405}
3406
3407
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003408static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3409 union wpa_event_data *data)
3410{
3411#ifdef CONFIG_FST
3412 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3413 struct wpa_bss *bss = wpa_s->current_bss;
3414 const u8 *ieprb, *iebcn;
3415
3416 wpabuf_free(wpa_s->received_mb_ies);
3417 wpa_s->received_mb_ies = NULL;
3418
3419 if (ai &&
3420 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3421 wpa_printf(MSG_DEBUG,
3422 "FST: MB IEs updated from Association Response frame");
3423 return;
3424 }
3425
3426 if (ai &&
3427 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3428 wpa_printf(MSG_DEBUG,
3429 "FST: MB IEs updated from association event Beacon IEs");
3430 return;
3431 }
3432
3433 if (!bss)
3434 return;
3435
Hai Shalom60840252021-02-19 19:02:11 -08003436 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003437 iebcn = ieprb + bss->ie_len;
3438
3439 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3440 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3441 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3442 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3443#endif /* CONFIG_FST */
3444}
3445
3446
Sunil Ravi89eba102022-09-13 21:04:37 -07003447static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3448{
3449 struct driver_sta_mlo_info mlo;
3450 int i;
3451
3452 mlo.valid_links = 0;
3453 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3454 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3455 wpa_supplicant_deauthenticate(wpa_s,
3456 WLAN_REASON_DEAUTH_LEAVING);
3457 return -1;
3458 }
3459
3460 if (wpa_s->valid_links == mlo.valid_links) {
3461 bool match = true;
3462
3463 if (!mlo.valid_links)
3464 return 0;
3465
3466 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3467 if (!(mlo.valid_links & BIT(i)))
3468 continue;
3469
3470 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3471 ETH_ALEN) != 0 ||
3472 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3473 ETH_ALEN) != 0) {
3474 match = false;
3475 break;
3476 }
3477 }
3478
3479 if (match &&
3480 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3481 ETH_ALEN) == 0)
3482 return 0;
3483 }
3484
3485 wpa_s->valid_links = mlo.valid_links;
3486 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3487 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3488 if (!(wpa_s->valid_links & BIT(i)))
3489 continue;
3490
3491 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3492 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3493 wpa_s->links[i].freq = mlo.links[i].freq;
3494 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3495 }
3496
3497 return 0;
3498}
3499
3500
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003501static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3502 union wpa_event_data *data)
3503{
3504 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003505 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003506 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003507#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3508 struct wpa_bss *bss;
3509#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003510#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303511 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003512#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003513
3514#ifdef CONFIG_AP
3515 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003516 if (!data)
3517 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003518 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3519 data->assoc_info.addr,
3520 data->assoc_info.req_ies,
3521 data->assoc_info.req_ies_len,
3522 data->assoc_info.reassoc);
3523 return;
3524 }
3525#endif /* CONFIG_AP */
3526
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003527 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003528 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003529
Andy Kuoaba17c12022-04-14 16:05:31 +08003530#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303531 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3532 struct wpa_ft_ies parse;
3533 /* Check for FT reassociation is done by the driver */
3534#ifdef CONFIG_IEEE80211R
3535 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303536 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303537 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3538 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3539 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3540 return;
3541 }
3542 if (parse.rsn_pmkid != NULL) {
3543 wpa_set_ft_completed(wpa_s->wpa);
3544 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3545 }
3546 }
3547#endif /* CONFIG_IEEE80211R */
3548 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003549#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303550
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003551 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003552
3553 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3554 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3555 wpa_supplicant_deauthenticate(
3556 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3557 return;
3558 }
3559
Sunil Ravi89eba102022-09-13 21:04:37 -07003560 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3561 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3562 wpa_supplicant_deauthenticate(wpa_s,
3563 WLAN_REASON_DEAUTH_LEAVING);
3564 return;
3565 }
3566
Sunil Ravia04bd252022-05-02 22:54:18 -07003567 if (ft_completed &&
3568 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3569 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3570 MAC2STR(bssid));
3571 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3572 wpa_printf(MSG_ERROR,
3573 "Can't find target AP's information!");
3574 return;
3575 }
3576 wpa_supplicant_assoc_update_ie(wpa_s);
3577 }
3578
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003579 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3580 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003581 /*
3582 * FILS authentication can share the same mechanism to mark the
3583 * connection fully authenticated, so set ft_completed also based on
3584 * FILS result.
3585 */
3586 if (!ft_completed)
3587 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003588
Andy Kuoaba17c12022-04-14 16:05:31 +08003589#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303590 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3591 /*
3592 * For driver based roaming, insert PSK during
3593 * the initial association
3594 */
3595 if (is_zero_ether_addr(wpa_s->bssid) &&
3596 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3597 /*
3598 * In case the driver wants to handle re-assocs,
3599 * pass it down the PMK.
3600 */
3601 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3602 wpa_sm_install_pmk(wpa_s->wpa);
3603 }
Mir Ali677e7482020-11-12 19:49:02 +05303604 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303605#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003606
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003607 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003608 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003609 if (os_reltime_initialized(&wpa_s->session_start)) {
3610 os_reltime_age(&wpa_s->session_start,
3611 &wpa_s->session_length);
3612 wpa_s->session_start.sec = 0;
3613 wpa_s->session_start.usec = 0;
3614 wpas_notify_session_length(wpa_s);
3615 } else {
3616 wpas_notify_auth_changed(wpa_s);
3617 os_get_reltime(&wpa_s->session_start);
3618 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003619 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3620 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003621 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003622 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003623 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3624 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003625 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003626
3627 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3628 wpa_clear_keys(wpa_s, bssid);
3629 }
3630 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003631 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003632 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3633 return;
3634 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003635 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003636
Hai Shalomc1a21442022-02-04 13:43:00 -08003637 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3638 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3639 return;
3640
Hai Shalomfdcde762020-04-02 11:19:20 -07003641 multi_ap_set_4addr_mode(wpa_s);
3642
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003643 if (wpa_s->conf->ap_scan == 1 &&
3644 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003645 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3646 wpa_msg(wpa_s, MSG_WARNING,
3647 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003648 }
3649
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003650 wpas_fst_update_mb_assoc(wpa_s, data);
3651
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003652#ifdef CONFIG_SME
3653 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3654 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003655 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003656#endif /* CONFIG_SME */
3657
3658 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3659 if (wpa_s->current_ssid) {
3660 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3661 * initialized before association, but for other modes,
3662 * initialize PC/SC here, if the current configuration needs
3663 * smartcard or SIM/USIM. */
3664 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3665 }
3666 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3667 if (wpa_s->l2)
3668 l2_packet_notify_auth_start(wpa_s->l2);
3669
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003670 already_authorized = data && data->assoc_info.authorized;
3671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003672 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003673 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003674 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3675 * state machine may transit to AUTHENTICATING state based on obsolete
3676 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3677 * AUTHENTICATED without ever giving chance to EAP state machine to
3678 * reset the state.
3679 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003680 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003681 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3682 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003683 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003684 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3685 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3686 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003687 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003688 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003689 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003690 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003691 wpa_s->eapol_received = 0;
3692 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3693 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3694 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003695 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003696 if (wpa_s->current_ssid &&
3697 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003698 (wpa_s->drv_flags &
3699 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3700 /*
3701 * Set the key after having received joined-IBSS event
3702 * from the driver.
3703 */
3704 wpa_supplicant_set_wpa_none_key(wpa_s,
3705 wpa_s->current_ssid);
3706 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003707 wpa_supplicant_cancel_auth_timeout(wpa_s);
3708 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3709 } else if (!ft_completed) {
3710 /* Timeout for receiving the first EAPOL packet */
3711 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3712 }
3713 wpa_supplicant_cancel_scan(wpa_s);
3714
Hai Shalom5f92bc92019-04-18 11:54:11 -07003715 if (ft_completed) {
3716 /*
3717 * FT protocol completed - make sure EAPOL state machine ends
3718 * up in authenticated.
3719 */
3720 wpa_supplicant_cancel_auth_timeout(wpa_s);
3721 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003722 eapol_sm_notify_portValid(wpa_s->eapol, true);
3723 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003724 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3725 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303726 if (already_authorized) {
3727 /*
3728 * We are done; the driver will take care of RSN 4-way
3729 * handshake.
3730 */
3731 wpa_supplicant_cancel_auth_timeout(wpa_s);
3732 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3733 eapol_sm_notify_portValid(wpa_s->eapol, true);
3734 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3735 } else {
3736 /* Update port, WPA_COMPLETED state from
3737 * EVENT_PORT_AUTHORIZED context when driver is done
3738 * with 4way handshake.
3739 */
3740 wpa_msg(wpa_s, MSG_INFO, "ASSOC INFO: wait for driver port "
3741 "authorized indication");
3742 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003743 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003744 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3745 /*
3746 * The driver will take care of RSN 4-way handshake, so we need
3747 * to allow EAPOL supplicant to complete its work without
3748 * waiting for WPA supplicant.
3749 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003750 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003751 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003752#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303753 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3754 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3755 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3756 wpa_s->key_mgmt);
3757 wpa_supplicant_deauthenticate(
3758 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3759 return;
3760 }
3761 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3762 wpa_s->assoc_freq = data->assoc_info.freq;
3763 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3764 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003765#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3766
Jouni Malinena05074c2012-12-21 21:35:35 +02003767 wpa_s->last_eapol_matches_bssid = 0;
3768
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003769#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003770 if (wpa_s->rsne_override_eapol) {
3771 wpa_printf(MSG_DEBUG,
3772 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3773 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3774 wpabuf_head(wpa_s->rsne_override_eapol),
3775 wpabuf_len(wpa_s->rsne_override_eapol));
3776 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003777 if (wpa_s->rsnxe_override_eapol) {
3778 wpa_printf(MSG_DEBUG,
3779 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3780 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3781 wpabuf_head(wpa_s->rsnxe_override_eapol),
3782 wpabuf_len(wpa_s->rsnxe_override_eapol));
3783 }
3784#endif /* CONFIG_TESTING_OPTIONS */
3785
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003786 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003787 struct os_reltime now, age;
3788 os_get_reltime(&now);
3789 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003790 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003791 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3792 0) {
3793 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3794 "frame that was received just before "
3795 "association notification");
3796 wpa_supplicant_rx_eapol(
3797 wpa_s, wpa_s->pending_eapol_rx_src,
3798 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00003799 wpabuf_len(wpa_s->pending_eapol_rx),
3800 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003801 }
3802 wpabuf_free(wpa_s->pending_eapol_rx);
3803 wpa_s->pending_eapol_rx = NULL;
3804 }
3805
Hai Shalomfdcde762020-04-02 11:19:20 -07003806#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003807 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3808 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003809 wpa_s->current_ssid &&
3810 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003811 /* Set static WEP keys again */
3812 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3813 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003814#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003815
3816#ifdef CONFIG_IBSS_RSN
3817 if (wpa_s->current_ssid &&
3818 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3819 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3820 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3821 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003822 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003823 if (!wpa_s->ibss_rsn) {
3824 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3825 wpa_supplicant_deauthenticate(
3826 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3827 return;
3828 }
3829
3830 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3831 }
3832#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003833
3834 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003835
3836 if (data) {
3837 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3838 data->assoc_info.resp_ies_len,
3839 &data->assoc_info.wmm_params);
3840
3841 if (wpa_s->reassoc_same_bss)
3842 wmm_ac_restore_tspecs(wpa_s);
3843 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003844
Hai Shalomc3565922019-10-28 11:58:20 -07003845#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3846 bss = wpa_bss_get_bssid(wpa_s, bssid);
3847#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003848#ifdef CONFIG_FILS
3849 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003850 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3851
3852 if (fils_cache_id)
3853 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3854 }
3855#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003856
3857#ifdef CONFIG_MBO
3858 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3859#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003860
3861#ifdef CONFIG_DPP2
3862 wpa_s->dpp_pfs_fallback = 0;
3863#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003864}
3865
3866
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003867static int disconnect_reason_recoverable(u16 reason_code)
3868{
3869 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3870 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3871 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3872}
3873
3874
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003875static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003876 u16 reason_code,
3877 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003878{
3879 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003880
3881 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3882 /*
3883 * At least Host AP driver and a Prism3 card seemed to be
3884 * generating streams of disconnected events when configuring
3885 * IBSS for WPA-None. Ignore them for now.
3886 */
3887 return;
3888 }
3889
3890 bssid = wpa_s->bssid;
3891 if (is_zero_ether_addr(bssid))
3892 bssid = wpa_s->pending_bssid;
3893
3894 if (!is_zero_ether_addr(bssid) ||
3895 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3896 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3897 " reason=%d%s",
3898 MAC2STR(bssid), reason_code,
3899 locally_generated ? " locally_generated=1" : "");
3900 }
3901}
3902
3903
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003904static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3905 int locally_generated)
3906{
3907 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003908 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003909 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3910 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003911 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003912
3913 /*
3914 * It looks like connection was lost while trying to go through PSK
3915 * 4-way handshake. Filter out known disconnection cases that are caused
3916 * by something else than PSK mismatch to avoid confusing reports.
3917 */
3918
3919 if (locally_generated) {
3920 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3921 return 0;
3922 }
3923
3924 return 1;
3925}
3926
3927
Jouni Malinen2b89da82012-08-31 22:04:41 +03003928static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3929 u16 reason_code,
3930 int locally_generated)
3931{
3932 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003933 int authenticating;
3934 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003935 struct wpa_bss *fast_reconnect = NULL;
3936 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003937 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003938 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003939
3940 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3941 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3942
3943 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3944 /*
3945 * At least Host AP driver and a Prism3 card seemed to be
3946 * generating streams of disconnected events when configuring
3947 * IBSS for WPA-None. Ignore them for now.
3948 */
3949 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3950 "IBSS/WPA-None mode");
3951 return;
3952 }
3953
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003954 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3955 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3956 locally_generated)
3957 /*
3958 * Remove the inactive AP (which is probably out of range) from
3959 * the BSS list after marking disassociation. In particular
3960 * mac80211-based drivers use the
3961 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3962 * locally generated disconnection events for cases where the
3963 * AP does not reply anymore.
3964 */
3965 curr = wpa_s->current_bss;
3966
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003967 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003968 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3969 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003970 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3971 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003972 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003973#ifdef CONFIG_DPP2
3974 wpas_dpp_send_conn_status_result(wpa_s,
3975 DPP_STATUS_AUTH_FAILURE);
3976#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003977 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003978 if (!wpa_s->disconnected &&
3979 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003980 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003981 wpas_wps_searching(wpa_s) ||
3982 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003983 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003984 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003985 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003986 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003987 wpa_s->wpa_state);
3988 if (wpa_s->wpa_state == WPA_COMPLETED &&
3989 wpa_s->current_ssid &&
3990 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003991 (wpa_s->own_reconnect_req ||
3992 (!locally_generated &&
3993 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003994 /*
3995 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003996 * us, but could allow us to get back in. This is also
3997 * triggered for cases where local reconnection request
3998 * is used to force reassociation with the same BSS.
3999 * Try to reconnect to the same BSS without a full scan
4000 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004001 */
4002 fast_reconnect = wpa_s->current_bss;
4003 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004004 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004005 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004006 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004007 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4008 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004009 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004010 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004011 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004012 "try to re-connect");
4013 wpa_s->reassociate = 0;
4014 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004015 if (!wpa_s->pno)
4016 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004017 }
4018 bssid = wpa_s->bssid;
4019 if (is_zero_ether_addr(bssid))
4020 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004021 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4022 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004023 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004024 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4025
Dmitry Shmidt04949592012-07-19 12:16:46 -07004026 if (locally_generated)
4027 wpa_s->disconnect_reason = -reason_code;
4028 else
4029 wpa_s->disconnect_reason = reason_code;
4030 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004031 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4032 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004033 wpa_clear_keys(wpa_s, wpa_s->bssid);
4034 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004035 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004036 wpa_supplicant_mark_disassoc(wpa_s);
4037
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004038 if (curr)
4039 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4040
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004041 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004042 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004043 wpa_s->current_ssid = last_ssid;
4044 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004045
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004046 if (fast_reconnect &&
4047 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4048 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4049 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4050 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004051 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004052 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004053#ifndef CONFIG_NO_SCAN_PROCESSING
4054 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4055 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4056 fast_reconnect_ssid) < 0) {
4057 /* Recover through full scan */
4058 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4059 }
4060#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004061 } else if (fast_reconnect) {
4062 /*
4063 * Could not reconnect to the same BSS due to network being
4064 * disabled. Use a new scan to match the alternative behavior
4065 * above, i.e., to continue automatic reconnection attempt in a
4066 * way that enforces disabled network rules.
4067 */
4068 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004069 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004070}
4071
4072
4073#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004074void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004075{
4076 struct wpa_supplicant *wpa_s = eloop_ctx;
4077
4078 if (!wpa_s->pending_mic_error_report)
4079 return;
4080
4081 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4082 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4083 wpa_s->pending_mic_error_report = 0;
4084}
4085#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4086
4087
4088static void
4089wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4090 union wpa_event_data *data)
4091{
4092 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004093 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004094
4095 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4096 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004097 os_get_reltime(&t);
4098 if ((wpa_s->last_michael_mic_error.sec &&
4099 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004100 wpa_s->pending_mic_error_report) {
4101 if (wpa_s->pending_mic_error_report) {
4102 /*
4103 * Send the pending MIC error report immediately since
4104 * we are going to start countermeasures and AP better
4105 * do the same.
4106 */
4107 wpa_sm_key_request(wpa_s->wpa, 1,
4108 wpa_s->pending_mic_error_pairwise);
4109 }
4110
4111 /* Send the new MIC error report immediately since we are going
4112 * to start countermeasures and AP better do the same.
4113 */
4114 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4115
4116 /* initialize countermeasures */
4117 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004118
Hai Shalom60840252021-02-19 19:02:11 -08004119 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004121 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4122
4123 /*
4124 * Need to wait for completion of request frame. We do not get
4125 * any callback for the message completion, so just wait a
4126 * short while and hope for the best. */
4127 os_sleep(0, 10000);
4128
4129 wpa_drv_set_countermeasures(wpa_s, 1);
4130 wpa_supplicant_deauthenticate(wpa_s,
4131 WLAN_REASON_MICHAEL_MIC_FAILURE);
4132 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4133 wpa_s, NULL);
4134 eloop_register_timeout(60, 0,
4135 wpa_supplicant_stop_countermeasures,
4136 wpa_s, NULL);
4137 /* TODO: mark the AP rejected for 60 second. STA is
4138 * allowed to associate with another AP.. */
4139 } else {
4140#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4141 if (wpa_s->mic_errors_seen) {
4142 /*
4143 * Reduce the effectiveness of Michael MIC error
4144 * reports as a means for attacking against TKIP if
4145 * more than one MIC failure is noticed with the same
4146 * PTK. We delay the transmission of the reports by a
4147 * random time between 0 and 60 seconds in order to
4148 * force the attacker wait 60 seconds before getting
4149 * the information on whether a frame resulted in a MIC
4150 * failure.
4151 */
4152 u8 rval[4];
4153 int sec;
4154
4155 if (os_get_random(rval, sizeof(rval)) < 0)
4156 sec = os_random() % 60;
4157 else
4158 sec = WPA_GET_BE32(rval) % 60;
4159 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4160 "report %d seconds", sec);
4161 wpa_s->pending_mic_error_report = 1;
4162 wpa_s->pending_mic_error_pairwise = pairwise;
4163 eloop_cancel_timeout(
4164 wpa_supplicant_delayed_mic_error_report,
4165 wpa_s, NULL);
4166 eloop_register_timeout(
4167 sec, os_random() % 1000000,
4168 wpa_supplicant_delayed_mic_error_report,
4169 wpa_s, NULL);
4170 } else {
4171 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4172 }
4173#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4174 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4175#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4176 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004177 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004178 wpa_s->mic_errors_seen++;
4179}
4180
4181
4182#ifdef CONFIG_TERMINATE_ONLASTIF
4183static int any_interfaces(struct wpa_supplicant *head)
4184{
4185 struct wpa_supplicant *wpa_s;
4186
4187 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4188 if (!wpa_s->interface_removed)
4189 return 1;
4190 return 0;
4191}
4192#endif /* CONFIG_TERMINATE_ONLASTIF */
4193
4194
4195static void
4196wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4197 union wpa_event_data *data)
4198{
4199 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4200 return;
4201
4202 switch (data->interface_status.ievent) {
4203 case EVENT_INTERFACE_ADDED:
4204 if (!wpa_s->interface_removed)
4205 break;
4206 wpa_s->interface_removed = 0;
4207 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4208 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4209 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4210 "driver after interface was added");
4211 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004212
4213#ifdef CONFIG_P2P
4214 if (!wpa_s->global->p2p &&
4215 !wpa_s->global->p2p_disabled &&
4216 !wpa_s->conf->p2p_disabled &&
4217 (wpa_s->drv_flags &
4218 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4219 wpas_p2p_add_p2pdev_interface(
4220 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4221 wpa_printf(MSG_INFO,
4222 "P2P: Failed to enable P2P Device interface");
4223 /* Try to continue without. P2P will be disabled. */
4224 }
4225#endif /* CONFIG_P2P */
4226
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004227 break;
4228 case EVENT_INTERFACE_REMOVED:
4229 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4230 wpa_s->interface_removed = 1;
4231 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004232 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004233 l2_packet_deinit(wpa_s->l2);
4234 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004235
4236#ifdef CONFIG_P2P
4237 if (wpa_s->global->p2p &&
4238 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4239 (wpa_s->drv_flags &
4240 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4241 wpa_dbg(wpa_s, MSG_DEBUG,
4242 "Removing P2P Device interface");
4243 wpa_supplicant_remove_iface(
4244 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4245 0);
4246 wpa_s->global->p2p_init_wpa_s = NULL;
4247 }
4248#endif /* CONFIG_P2P */
4249
Dmitry Shmidte4663042016-04-04 10:07:49 -07004250#ifdef CONFIG_MATCH_IFACE
4251 if (wpa_s->matched) {
4252 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4253 break;
4254 }
4255#endif /* CONFIG_MATCH_IFACE */
4256
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004257#ifdef CONFIG_TERMINATE_ONLASTIF
4258 /* check if last interface */
4259 if (!any_interfaces(wpa_s->global->ifaces))
4260 eloop_terminate();
4261#endif /* CONFIG_TERMINATE_ONLASTIF */
4262 break;
4263 }
4264}
4265
4266
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004267#ifdef CONFIG_TDLS
4268static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4269 union wpa_event_data *data)
4270{
4271 if (data == NULL)
4272 return;
4273 switch (data->tdls.oper) {
4274 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004275 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4276 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4277 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4278 else
4279 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004280 break;
4281 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004282 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4283 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4284 data->tdls.reason_code);
4285 else
4286 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4287 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004288 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004289 case TDLS_REQUEST_DISCOVER:
4290 wpa_tdls_send_discovery_request(wpa_s->wpa,
4291 data->tdls.peer);
4292 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004293 }
4294}
4295#endif /* CONFIG_TDLS */
4296
4297
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004298#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004299static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4300 union wpa_event_data *data)
4301{
4302 if (data == NULL)
4303 return;
4304 switch (data->wnm.oper) {
4305 case WNM_OPER_SLEEP:
4306 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4307 "(action=%d, intval=%d)",
4308 data->wnm.sleep_action, data->wnm.sleep_intval);
4309 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004310 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004311 break;
4312 }
4313}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004314#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004315
4316
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004317#ifdef CONFIG_IEEE80211R
4318static void
4319wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4320 union wpa_event_data *data)
4321{
4322 if (data == NULL)
4323 return;
4324
4325 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4326 data->ft_ies.ies_len,
4327 data->ft_ies.ft_action,
4328 data->ft_ies.target_ap,
4329 data->ft_ies.ric_ies,
4330 data->ft_ies.ric_ies_len) < 0) {
4331 /* TODO: prevent MLME/driver from trying to associate? */
4332 }
4333}
4334#endif /* CONFIG_IEEE80211R */
4335
4336
4337#ifdef CONFIG_IBSS_RSN
4338static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4339 union wpa_event_data *data)
4340{
4341 struct wpa_ssid *ssid;
4342 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4343 return;
4344 if (data == NULL)
4345 return;
4346 ssid = wpa_s->current_ssid;
4347 if (ssid == NULL)
4348 return;
4349 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4350 return;
4351
4352 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4353}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004354
4355
4356static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4357 union wpa_event_data *data)
4358{
4359 struct wpa_ssid *ssid = wpa_s->current_ssid;
4360
4361 if (ssid == NULL)
4362 return;
4363
4364 /* check if the ssid is correctly configured as IBSS/RSN */
4365 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4366 return;
4367
4368 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4369 data->rx_mgmt.frame_len);
4370}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004371#endif /* CONFIG_IBSS_RSN */
4372
4373
4374#ifdef CONFIG_IEEE80211R
4375static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4376 size_t len)
4377{
4378 const u8 *sta_addr, *target_ap_addr;
4379 u16 status;
4380
4381 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4382 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4383 return; /* only SME case supported for now */
4384 if (len < 1 + 2 * ETH_ALEN + 2)
4385 return;
4386 if (data[0] != 2)
4387 return; /* Only FT Action Response is supported for now */
4388 sta_addr = data + 1;
4389 target_ap_addr = data + 1 + ETH_ALEN;
4390 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4391 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4392 MACSTR " TargetAP " MACSTR " status %u",
4393 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4394
4395 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4396 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4397 " in FT Action Response", MAC2STR(sta_addr));
4398 return;
4399 }
4400
4401 if (status) {
4402 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4403 "failure (status code %d)", status);
4404 /* TODO: report error to FT code(?) */
4405 return;
4406 }
4407
4408 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4409 len - (1 + 2 * ETH_ALEN + 2), 1,
4410 target_ap_addr, NULL, 0) < 0)
4411 return;
4412
4413#ifdef CONFIG_SME
4414 {
4415 struct wpa_bss *bss;
4416 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4417 if (bss)
4418 wpa_s->sme.freq = bss->freq;
4419 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4420 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4421 WLAN_AUTH_FT);
4422 }
4423#endif /* CONFIG_SME */
4424}
4425#endif /* CONFIG_IEEE80211R */
4426
4427
4428static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4429 struct unprot_deauth *e)
4430{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004431 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4432 "dropped: " MACSTR " -> " MACSTR
4433 " (reason code %u)",
4434 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4435 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004436}
4437
4438
4439static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4440 struct unprot_disassoc *e)
4441{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004442 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4443 "dropped: " MACSTR " -> " MACSTR
4444 " (reason code %u)",
4445 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4446 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004447}
4448
4449
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004450static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4451 u16 reason_code, int locally_generated,
4452 const u8 *ie, size_t ie_len, int deauth)
4453{
4454#ifdef CONFIG_AP
4455 if (wpa_s->ap_iface && addr) {
4456 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4457 return;
4458 }
4459
4460 if (wpa_s->ap_iface) {
4461 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4462 return;
4463 }
4464#endif /* CONFIG_AP */
4465
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004466 if (!locally_generated)
4467 wpa_s->own_disconnect_req = 0;
4468
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004469 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4470
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004471 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4472 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4473 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4474 eapol_sm_failed(wpa_s->eapol))) &&
4475 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004476 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004477
4478#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004479 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004480 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4481 locally_generated) > 0) {
4482 /*
4483 * The interface was removed, so cannot continue
4484 * processing any additional operations after this.
4485 */
4486 return;
4487 }
4488 }
4489#endif /* CONFIG_P2P */
4490
4491 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4492 locally_generated);
4493}
4494
4495
4496static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4497 struct disassoc_info *info)
4498{
4499 u16 reason_code = 0;
4500 int locally_generated = 0;
4501 const u8 *addr = NULL;
4502 const u8 *ie = NULL;
4503 size_t ie_len = 0;
4504
4505 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4506
4507 if (info) {
4508 addr = info->addr;
4509 ie = info->ie;
4510 ie_len = info->ie_len;
4511 reason_code = info->reason_code;
4512 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004513 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4514 reason2str(reason_code),
4515 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004516 if (addr)
4517 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4518 MAC2STR(addr));
4519 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4520 ie, ie_len);
4521 }
4522
4523#ifdef CONFIG_AP
4524 if (wpa_s->ap_iface && info && info->addr) {
4525 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4526 return;
4527 }
4528
4529 if (wpa_s->ap_iface) {
4530 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4531 return;
4532 }
4533#endif /* CONFIG_AP */
4534
4535#ifdef CONFIG_P2P
4536 if (info) {
4537 wpas_p2p_disassoc_notif(
4538 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4539 locally_generated);
4540 }
4541#endif /* CONFIG_P2P */
4542
4543 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4544 sme_event_disassoc(wpa_s, info);
4545
4546 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4547 ie, ie_len, 0);
4548}
4549
4550
4551static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4552 struct deauth_info *info)
4553{
4554 u16 reason_code = 0;
4555 int locally_generated = 0;
4556 const u8 *addr = NULL;
4557 const u8 *ie = NULL;
4558 size_t ie_len = 0;
4559
4560 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4561
4562 if (info) {
4563 addr = info->addr;
4564 ie = info->ie;
4565 ie_len = info->ie_len;
4566 reason_code = info->reason_code;
4567 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004568 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4569 reason_code, reason2str(reason_code),
4570 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004571 if (addr) {
4572 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4573 MAC2STR(addr));
4574 }
4575 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4576 ie, ie_len);
4577 }
4578
4579 wpa_reset_ft_completed(wpa_s->wpa);
4580
4581 wpas_event_disconnect(wpa_s, addr, reason_code,
4582 locally_generated, ie, ie_len, 1);
4583}
4584
4585
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004586static const char * reg_init_str(enum reg_change_initiator init)
4587{
4588 switch (init) {
4589 case REGDOM_SET_BY_CORE:
4590 return "CORE";
4591 case REGDOM_SET_BY_USER:
4592 return "USER";
4593 case REGDOM_SET_BY_DRIVER:
4594 return "DRIVER";
4595 case REGDOM_SET_BY_COUNTRY_IE:
4596 return "COUNTRY_IE";
4597 case REGDOM_BEACON_HINT:
4598 return "BEACON_HINT";
4599 }
4600 return "?";
4601}
4602
4603
4604static const char * reg_type_str(enum reg_type type)
4605{
4606 switch (type) {
4607 case REGDOM_TYPE_UNKNOWN:
4608 return "UNKNOWN";
4609 case REGDOM_TYPE_COUNTRY:
4610 return "COUNTRY";
4611 case REGDOM_TYPE_WORLD:
4612 return "WORLD";
4613 case REGDOM_TYPE_CUSTOM_WORLD:
4614 return "CUSTOM_WORLD";
4615 case REGDOM_TYPE_INTERSECTION:
4616 return "INTERSECTION";
4617 }
4618 return "?";
4619}
4620
4621
Hai Shalom74f70d42019-02-11 14:42:39 -08004622void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4623 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004624{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004625 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004626 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004627
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004628 /*
4629 * To allow backwards compatibility with higher level layers that
4630 * assumed the REGDOM_CHANGE event is sent over the initially added
4631 * interface. Find the highest parent of this interface and use it to
4632 * send the event.
4633 */
4634 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4635 ;
4636
Hai Shalom74f70d42019-02-11 14:42:39 -08004637 if (info) {
4638 wpa_msg(ifs, MSG_INFO,
4639 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4640 reg_init_str(info->initiator), reg_type_str(info->type),
4641 info->alpha2[0] ? " alpha2=" : "",
4642 info->alpha2[0] ? info->alpha2 : "");
4643 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004644
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004645 if (wpa_s->drv_priv == NULL)
4646 return; /* Ignore event during drv initialization */
4647
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004648 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4649 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004650 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4651 ifs->ifname);
4652 free_hw_features(ifs);
4653 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004654 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004655
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004656 /* Restart PNO/sched_scan with updated channel list */
4657 if (ifs->pno) {
4658 wpas_stop_pno(ifs);
4659 wpas_start_pno(ifs);
4660 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4661 wpa_dbg(ifs, MSG_DEBUG,
4662 "Channel list changed - restart sched_scan");
4663 wpas_scan_restart_sched_scan(ifs);
4664 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004665 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004666
4667 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004668}
4669
4670
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004671static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004672 const u8 *frame, size_t len, int freq,
4673 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004674{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004675 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004676 const u8 *payload;
4677 size_t plen;
4678 u8 category;
4679
4680 if (len < IEEE80211_HDRLEN + 2)
4681 return;
4682
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004683 mgmt = (const struct ieee80211_mgmt *) frame;
4684 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004685 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004686 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004687
4688 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4689 " Category=%u DataLen=%d freq=%d MHz",
4690 MAC2STR(mgmt->sa), category, (int) plen, freq);
4691
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004692 if (category == WLAN_ACTION_WMM) {
4693 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4694 return;
4695 }
4696
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004697#ifdef CONFIG_IEEE80211R
4698 if (category == WLAN_ACTION_FT) {
4699 ft_rx_action(wpa_s, payload, plen);
4700 return;
4701 }
4702#endif /* CONFIG_IEEE80211R */
4703
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004704#ifdef CONFIG_SME
4705 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004706 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004707 return;
4708 }
4709#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004710
4711#ifdef CONFIG_WNM
4712 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4713 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4714 return;
4715 }
4716#endif /* CONFIG_WNM */
4717
4718#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004719 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4720 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004721 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004722 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004723 payload, plen, freq) == 0)
4724 return;
4725#endif /* CONFIG_GAS */
4726
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004727#ifdef CONFIG_GAS_SERVER
4728 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4729 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4730 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4731 mgmt->u.action.category,
4732 payload, plen, freq) == 0)
4733 return;
4734#endif /* CONFIG_GAS_SERVER */
4735
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004736#ifdef CONFIG_TDLS
4737 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4738 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4739 wpa_dbg(wpa_s, MSG_DEBUG,
4740 "TDLS: Received Discovery Response from " MACSTR,
4741 MAC2STR(mgmt->sa));
4742 return;
4743 }
4744#endif /* CONFIG_TDLS */
4745
4746#ifdef CONFIG_INTERWORKING
4747 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4748 payload[0] == QOS_QOS_MAP_CONFIG) {
4749 const u8 *pos = payload + 1;
4750 size_t qlen = plen - 1;
4751 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4752 MACSTR, MAC2STR(mgmt->sa));
4753 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4754 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4755 pos[1] <= qlen - 2 && pos[1] >= 16)
4756 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4757 return;
4758 }
4759#endif /* CONFIG_INTERWORKING */
4760
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004761 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004762 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4763 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004764 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004765 payload + 1,
4766 plen - 1);
4767 return;
4768 }
4769
4770 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004771 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4772 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4773 return;
4774 }
4775
4776 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4777 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4778 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4779 payload + 1, plen - 1,
4780 rssi);
4781 return;
4782 }
4783
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004784#ifdef CONFIG_FST
4785 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4786 fst_rx_action(wpa_s->fst, mgmt, len);
4787 return;
4788 }
4789#endif /* CONFIG_FST */
4790
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004791#ifdef CONFIG_DPP
4792 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4793 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4794 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4795 payload[4] == DPP_OUI_TYPE) {
4796 payload++;
4797 plen--;
4798 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4799 return;
4800 }
4801#endif /* CONFIG_DPP */
4802
Hai Shalom899fcc72020-10-19 14:38:18 -07004803 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004804 payload[0] == ROBUST_AV_SCS_RESP) {
4805 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4806 payload + 1, plen - 1);
4807 return;
4808 }
4809
4810 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004811 payload[0] == ROBUST_AV_MSCS_RESP) {
4812 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4813 payload + 1, plen - 1);
4814 return;
4815 }
4816
Hai Shalomc1a21442022-02-04 13:43:00 -08004817 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4818 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4819 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4820 payload + 4, plen - 4);
4821 return;
4822 }
4823
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004824 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4825 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004826 if (wpa_s->ifmsh)
4827 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004828}
4829
4830
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004831static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4832 union wpa_event_data *event)
4833{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004834 struct wpa_freq_range_list *list;
4835 char *str = NULL;
4836
4837 list = &event->freq_range;
4838
4839 if (list->num)
4840 str = freq_range_list_str(list);
4841 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4842 str ? str : "");
4843
4844#ifdef CONFIG_P2P
4845 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4846 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4847 __func__);
4848 } else {
4849 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004850
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004851 /*
4852 * The update channel flow will also take care of moving a GO
4853 * from the unsafe frequency if needed.
4854 */
4855 wpas_p2p_update_channel_list(wpa_s,
4856 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004857 }
4858#endif /* CONFIG_P2P */
4859
4860 os_free(str);
4861}
4862
4863
Roshan Pius3a1667e2018-07-03 15:17:14 -07004864static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004865{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004866 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4867 wpa_supplicant_cancel_auth_timeout(wpa_s);
4868 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004869 eapol_sm_notify_portValid(wpa_s->eapol, true);
4870 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004871 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004872 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004873}
4874
4875
4876static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4877 int freq)
4878{
4879 size_t i;
4880 int j;
4881
4882 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4883 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4884
4885 for (j = 0; j < mode->num_channels; j++) {
4886 const struct hostapd_channel_data *chan;
4887
4888 chan = &mode->channels[j];
4889 if (chan->freq == freq)
4890 return chan->dfs_cac_ms;
4891 }
4892 }
4893
4894 return 0;
4895}
4896
4897
4898static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4899 struct dfs_event *radar)
4900{
4901#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004902 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004903 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4904 } else
4905#endif /* NEED_AP_MLME && CONFIG_AP */
4906 {
4907 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4908
4909 cac_time /= 1000; /* convert from ms to sec */
4910 if (!cac_time)
4911 cac_time = 10 * 60; /* max timeout: 10 minutes */
4912
4913 /* Restart auth timeout: CAC time added to initial timeout */
4914 wpas_auth_timeout_restart(wpa_s, cac_time);
4915 }
4916}
4917
4918
4919static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4920 struct dfs_event *radar)
4921{
4922#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004923 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004924 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4925 } else
4926#endif /* NEED_AP_MLME && CONFIG_AP */
4927 {
4928 /* Restart auth timeout with original value after CAC is
4929 * finished */
4930 wpas_auth_timeout_restart(wpa_s, 0);
4931 }
4932}
4933
4934
4935static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4936 struct dfs_event *radar)
4937{
4938#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004939 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004940 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4941 } else
4942#endif /* NEED_AP_MLME && CONFIG_AP */
4943 {
4944 /* Restart auth timeout with original value after CAC is
4945 * aborted */
4946 wpas_auth_timeout_restart(wpa_s, 0);
4947 }
4948}
4949
4950
4951static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4952 union wpa_event_data *data)
4953{
4954 wpa_dbg(wpa_s, MSG_DEBUG,
4955 "Connection authorized by device, previous state %d",
4956 wpa_s->wpa_state);
4957
4958 wpa_supplicant_event_port_authorized(wpa_s);
4959
Hai Shalomc1a21442022-02-04 13:43:00 -08004960 wpa_s->last_eapol_matches_bssid = 1;
4961
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004962 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4963 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004964 data->assoc_info.ptk_kck_len,
4965 data->assoc_info.ptk_kek,
4966 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004967#ifdef CONFIG_FILS
4968 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4969 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4970 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4971
4972 /* Update ERP next sequence number */
4973 eapol_sm_update_erp_next_seq_num(
4974 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4975
4976 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4977 /* Add the new PMK and PMKID to the PMKSA cache */
4978 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4979 data->assoc_info.fils_pmk,
4980 data->assoc_info.fils_pmk_len,
4981 data->assoc_info.fils_pmkid,
4982 wpa_s->bssid, fils_cache_id);
4983 } else if (data->assoc_info.fils_pmkid) {
4984 /* Update the current PMKSA used for this connection */
4985 pmksa_cache_set_current(wpa_s->wpa,
4986 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004987 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004988 }
4989 }
4990#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004991}
4992
4993
Hai Shalom60840252021-02-19 19:02:11 -08004994static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4995{
4996 switch (code) {
4997 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
4998 return "";
4999 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5000 return "no_bss_found";
5001 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5002 return "auth_tx_fail";
5003 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5004 return "auth_no_ack_received";
5005 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5006 return "auth_no_resp_received";
5007 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5008 return "assoc_req_tx_fail";
5009 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5010 return "assoc_no_ack_received";
5011 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5012 return "assoc_no_resp_received";
5013 default:
5014 return "unknown_reason";
5015 }
5016}
5017
5018
Roshan Pius3a1667e2018-07-03 15:17:14 -07005019static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5020 union wpa_event_data *data)
5021{
5022 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005023#ifdef CONFIG_MBO
5024 struct wpa_bss *reject_bss;
5025#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005026
5027 if (!bssid || is_zero_ether_addr(bssid))
5028 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005029#ifdef CONFIG_MBO
5030 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5031 reject_bss = wpa_s->current_bss;
5032 else
5033 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5034#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005035
5036 if (data->assoc_reject.bssid)
5037 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005038 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005039 MAC2STR(data->assoc_reject.bssid),
5040 data->assoc_reject.status_code,
5041 data->assoc_reject.timed_out ? " timeout" : "",
5042 data->assoc_reject.timeout_reason ? "=" : "",
5043 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005044 data->assoc_reject.timeout_reason : "",
5045 data->assoc_reject.reason_code !=
5046 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5047 " qca_driver_reason=" : "",
5048 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005049 else
5050 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005051 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005052 data->assoc_reject.status_code,
5053 data->assoc_reject.timed_out ? " timeout" : "",
5054 data->assoc_reject.timeout_reason ? "=" : "",
5055 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005056 data->assoc_reject.timeout_reason : "",
5057 data->assoc_reject.reason_code !=
5058 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5059 " qca_driver_reason=" : "",
5060 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005061 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005062 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5063 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005064
5065#ifdef CONFIG_OWE
5066 if (data->assoc_reject.status_code ==
5067 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5068 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5069 wpa_s->current_ssid &&
5070 wpa_s->current_ssid->owe_group == 0 &&
5071 wpa_s->last_owe_group != 21) {
5072 struct wpa_ssid *ssid = wpa_s->current_ssid;
5073 struct wpa_bss *bss = wpa_s->current_bss;
5074
5075 if (!bss) {
5076 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5077 if (!bss) {
5078 wpas_connection_failed(wpa_s, bssid);
5079 wpa_supplicant_mark_disassoc(wpa_s);
5080 return;
5081 }
5082 }
5083 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5084 wpas_connect_work_done(wpa_s);
5085 wpa_supplicant_mark_disassoc(wpa_s);
5086 wpa_supplicant_connect(wpa_s, bss, ssid);
5087 return;
5088 }
5089#endif /* CONFIG_OWE */
5090
Hai Shalomfdcde762020-04-02 11:19:20 -07005091#ifdef CONFIG_DPP2
5092 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5093 * the status code defined in the DPP R2 tech spec.
5094 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5095 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005096 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005097 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5098 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5099 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005100 wpa_s->current_ssid->dpp_pfs == 0 &&
5101 (data->assoc_reject.status_code ==
5102 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5103 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5104 struct wpa_ssid *ssid = wpa_s->current_ssid;
5105 struct wpa_bss *bss = wpa_s->current_bss;
5106
5107 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5108 if (!bss)
5109 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5110 if (!bss || wpa_s->dpp_pfs_fallback) {
5111 wpa_printf(MSG_DEBUG,
5112 "DPP: Updated PFS policy for next try");
5113 wpas_connection_failed(wpa_s, bssid);
5114 wpa_supplicant_mark_disassoc(wpa_s);
5115 return;
5116 }
5117 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5118 wpa_s->dpp_pfs_fallback = 1;
5119 wpas_connect_work_done(wpa_s);
5120 wpa_supplicant_mark_disassoc(wpa_s);
5121 wpa_supplicant_connect(wpa_s, bss, ssid);
5122 return;
5123 }
5124#endif /* CONFIG_DPP2 */
5125
Hai Shalom74f70d42019-02-11 14:42:39 -08005126#ifdef CONFIG_MBO
5127 if (data->assoc_reject.status_code ==
5128 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005129 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005130 const u8 *rssi_rej;
5131
5132 rssi_rej = mbo_get_attr_from_ies(
5133 data->assoc_reject.resp_ies,
5134 data->assoc_reject.resp_ies_len,
5135 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5136 if (rssi_rej && rssi_rej[1] == 2) {
5137 wpa_printf(MSG_DEBUG,
5138 "OCE: RSSI-based association rejection from "
5139 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005140 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005141 rssi_rej[2], rssi_rej[3]);
5142 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005143 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005144 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005145 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005146 }
5147 }
5148#endif /* CONFIG_MBO */
5149
Roshan Pius3a1667e2018-07-03 15:17:14 -07005150 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5151 sme_event_assoc_reject(wpa_s, data);
5152 return;
5153 }
5154
5155 /* Driver-based SME cases */
5156
5157#ifdef CONFIG_SAE
5158 if (wpa_s->current_ssid &&
5159 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5160 !data->assoc_reject.timed_out) {
5161 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5162 wpa_sm_aborted_cached(wpa_s->wpa);
5163 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5164 }
5165#endif /* CONFIG_SAE */
5166
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005167#ifdef CONFIG_DPP
5168 if (wpa_s->current_ssid &&
5169 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5170 !data->assoc_reject.timed_out) {
5171 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5172 wpa_sm_aborted_cached(wpa_s->wpa);
5173 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5174 }
5175#endif /* CONFIG_DPP */
5176
Roshan Pius3a1667e2018-07-03 15:17:14 -07005177#ifdef CONFIG_FILS
5178 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005179 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005180 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005181 eapol_sm_update_erp_next_seq_num(
5182 wpa_s->eapol,
5183 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005184 fils_connection_failure(wpa_s);
5185 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005186#endif /* CONFIG_FILS */
5187
5188 wpas_connection_failed(wpa_s, bssid);
5189 wpa_supplicant_mark_disassoc(wpa_s);
5190}
5191
5192
Hai Shalomfdcde762020-04-02 11:19:20 -07005193static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5194 struct unprot_beacon *data)
5195{
5196 struct wpabuf *buf;
5197 int res;
5198
5199 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5200 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5201 return;
5202 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5203 MAC2STR(data->sa));
5204
5205 buf = wpabuf_alloc(4);
5206 if (!buf)
5207 return;
5208
5209 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5210 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5211 wpabuf_put_u8(buf, 1); /* Dialog Token */
5212 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5213
5214 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5215 wpa_s->own_addr, wpa_s->bssid,
5216 wpabuf_head(buf), wpabuf_len(buf), 0);
5217 if (res < 0)
5218 wpa_printf(MSG_DEBUG,
5219 "Failed to send WNM-Notification Request frame");
5220
5221 wpabuf_free(buf);
5222}
5223
5224
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005225void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5226 union wpa_event_data *data)
5227{
5228 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005229 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005230 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005231#ifndef CONFIG_NO_STDOUT_DEBUG
5232 int level = MSG_DEBUG;
5233#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005234
5235 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5236 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005237 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005238 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005239 event != EVENT_SCHED_SCAN_STOPPED) {
5240 wpa_dbg(wpa_s, MSG_DEBUG,
5241 "Ignore event %s (%d) while interface is disabled",
5242 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005243 return;
5244 }
5245
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005246#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005247 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005248 const struct ieee80211_hdr *hdr;
5249 u16 fc;
5250 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5251 fc = le_to_host16(hdr->frame_control);
5252 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5253 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5254 level = MSG_EXCESSIVE;
5255 }
5256
5257 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5258 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005259#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005260
5261 switch (event) {
5262 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005263#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005264 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5265 data->auth.ies_len))
5266 wpa_printf(MSG_DEBUG,
5267 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005268#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005269 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005270 wpa_s->auth_status_code = data->auth.status_code;
5271 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005272 break;
5273 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005274#ifdef CONFIG_TESTING_OPTIONS
5275 if (wpa_s->ignore_auth_resp) {
5276 wpa_printf(MSG_INFO,
5277 "EVENT_ASSOC - ignore_auth_resp active!");
5278 break;
5279 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005280 if (wpa_s->testing_resend_assoc) {
5281 wpa_printf(MSG_INFO,
5282 "EVENT_DEAUTH - testing_resend_assoc");
5283 break;
5284 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005285#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305286 if (wpa_s->disconnected) {
5287 wpa_printf(MSG_INFO,
5288 "Ignore unexpected EVENT_ASSOC in disconnected state");
5289 break;
5290 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005291 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005292 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005293 if (data &&
5294 (data->assoc_info.authorized ||
5295 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5296 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005297 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005298 if (data) {
5299 wpa_msg(wpa_s, MSG_INFO,
5300 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5301 data->assoc_info.subnet_status);
5302 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005303 break;
5304 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005305 wpas_event_disassoc(wpa_s,
5306 data ? &data->disassoc_info : NULL);
5307 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005308 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005309#ifdef CONFIG_TESTING_OPTIONS
5310 if (wpa_s->ignore_auth_resp) {
5311 wpa_printf(MSG_INFO,
5312 "EVENT_DEAUTH - ignore_auth_resp active!");
5313 break;
5314 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005315 if (wpa_s->testing_resend_assoc) {
5316 wpa_printf(MSG_INFO,
5317 "EVENT_DEAUTH - testing_resend_assoc");
5318 break;
5319 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005320#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005321 wpas_event_deauth(wpa_s,
5322 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005323 break;
5324 case EVENT_MICHAEL_MIC_FAILURE:
5325 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5326 break;
5327#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005328 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005329 if (wpa_s->own_scan_requested ||
5330 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005331 struct os_reltime diff;
5332
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005333 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005334 os_reltime_sub(&wpa_s->scan_start_time,
5335 &wpa_s->scan_trigger_time, &diff);
5336 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5337 diff.sec, diff.usec);
5338 wpa_s->own_scan_requested = 0;
5339 wpa_s->own_scan_running = 1;
5340 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5341 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005342 wpa_msg_ctrl(wpa_s, MSG_INFO,
5343 WPA_EVENT_SCAN_STARTED "id=%u",
5344 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005345 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005346 wpa_msg_ctrl(wpa_s, MSG_INFO,
5347 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005348 }
5349 } else {
5350 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005351 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005352 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005353 }
5354 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005355 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005356 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5357 wpa_s->scan_res_handler = NULL;
5358 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005359 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005360 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5361 break;
5362 }
5363
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005364 if (!(data && data->scan_info.external_scan) &&
5365 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005366 struct os_reltime now, diff;
5367 os_get_reltime(&now);
5368 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5369 wpa_s->scan_start_time.sec = 0;
5370 wpa_s->scan_start_time.usec = 0;
5371 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5372 diff.sec, diff.usec);
5373 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005374 if (wpa_supplicant_event_scan_results(wpa_s, data))
5375 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005376 if (!(data && data->scan_info.external_scan))
5377 wpa_s->own_scan_running = 0;
5378 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005379 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005380 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005381 break;
5382#endif /* CONFIG_NO_SCAN_PROCESSING */
5383 case EVENT_ASSOCINFO:
5384 wpa_supplicant_event_associnfo(wpa_s, data);
5385 break;
5386 case EVENT_INTERFACE_STATUS:
5387 wpa_supplicant_event_interface_status(wpa_s, data);
5388 break;
5389 case EVENT_PMKID_CANDIDATE:
5390 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5391 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005392#ifdef CONFIG_TDLS
5393 case EVENT_TDLS:
5394 wpa_supplicant_event_tdls(wpa_s, data);
5395 break;
5396#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005397#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005398 case EVENT_WNM:
5399 wpa_supplicant_event_wnm(wpa_s, data);
5400 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005401#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005402#ifdef CONFIG_IEEE80211R
5403 case EVENT_FT_RESPONSE:
5404 wpa_supplicant_event_ft_response(wpa_s, data);
5405 break;
5406#endif /* CONFIG_IEEE80211R */
5407#ifdef CONFIG_IBSS_RSN
5408 case EVENT_IBSS_RSN_START:
5409 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5410 break;
5411#endif /* CONFIG_IBSS_RSN */
5412 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005413 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005414 break;
5415 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005416 /* It is possible to get this event from earlier connection */
5417 if (wpa_s->current_ssid &&
5418 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5419 wpa_dbg(wpa_s, MSG_DEBUG,
5420 "Ignore AUTH_TIMED_OUT in mesh configuration");
5421 break;
5422 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005423 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5424 sme_event_auth_timed_out(wpa_s, data);
5425 break;
5426 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005427 /* It is possible to get this event from earlier connection */
5428 if (wpa_s->current_ssid &&
5429 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5430 wpa_dbg(wpa_s, MSG_DEBUG,
5431 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5432 break;
5433 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005434 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5435 sme_event_assoc_timed_out(wpa_s, data);
5436 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005437 case EVENT_TX_STATUS:
5438 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5439 " type=%d stype=%d",
5440 MAC2STR(data->tx_status.dst),
5441 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005442#ifdef CONFIG_PASN
5443 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5444 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5445 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5446 data->tx_status.data_len,
5447 data->tx_status.ack) == 0)
5448 break;
5449#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005450#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005451 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005452#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005453 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5454 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005455 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005456 wpa_s, data->tx_status.dst,
5457 data->tx_status.data,
5458 data->tx_status.data_len,
5459 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005460 OFFCHANNEL_SEND_ACTION_SUCCESS :
5461 OFFCHANNEL_SEND_ACTION_NO_ACK);
5462#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005463 break;
5464 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005465#endif /* CONFIG_AP */
5466#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005467 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005468 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005469 /*
5470 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005471 * interface in GO mode, or via standalone AP interface.
5472 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5473 * except when the primary interface is used as a GO interface
5474 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005475 */
5476 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5477 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005478 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005479 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005480 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005481 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005482 data->tx_status.data,
5483 data->tx_status.data_len,
5484 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005485 OFFCHANNEL_SEND_ACTION_SUCCESS :
5486 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005487 break;
5488 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005489#endif /* CONFIG_OFFCHANNEL */
5490#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005491 switch (data->tx_status.type) {
5492 case WLAN_FC_TYPE_MGMT:
5493 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5494 data->tx_status.data_len,
5495 data->tx_status.stype,
5496 data->tx_status.ack);
5497 break;
5498 case WLAN_FC_TYPE_DATA:
5499 ap_tx_status(wpa_s, data->tx_status.dst,
5500 data->tx_status.data,
5501 data->tx_status.data_len,
5502 data->tx_status.ack);
5503 break;
5504 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005505#endif /* CONFIG_AP */
5506 break;
5507#ifdef CONFIG_AP
5508 case EVENT_EAPOL_TX_STATUS:
5509 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5510 data->eapol_tx_status.data,
5511 data->eapol_tx_status.data_len,
5512 data->eapol_tx_status.ack);
5513 break;
5514 case EVENT_DRIVER_CLIENT_POLL_OK:
5515 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005516 break;
5517 case EVENT_RX_FROM_UNKNOWN:
5518 if (wpa_s->ap_iface == NULL)
5519 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005520 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5521 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005522 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005523#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005524
Sunil Ravi89eba102022-09-13 21:04:37 -07005525 case EVENT_LINK_CH_SWITCH_STARTED:
5526 case EVENT_LINK_CH_SWITCH:
5527 if (!data || !wpa_s->current_ssid ||
5528 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
5529 break;
5530
5531 wpa_msg(wpa_s, MSG_INFO,
5532 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5533 event == EVENT_LINK_CH_SWITCH ?
5534 WPA_EVENT_LINK_CHANNEL_SWITCH :
5535 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
5536 data->ch_switch.freq,
5537 data->ch_switch.link_id,
5538 data->ch_switch.ht_enabled,
5539 data->ch_switch.ch_offset,
5540 channel_width_to_string(data->ch_switch.ch_width),
5541 data->ch_switch.cf1,
5542 data->ch_switch.cf2);
5543 if (event == EVENT_LINK_CH_SWITCH_STARTED)
5544 break;
5545
5546 wpa_s->links[data->ch_switch.link_id].freq =
5547 data->ch_switch.freq;
5548 if (wpa_s->links[data->ch_switch.link_id].bss &&
5549 wpa_s->links[data->ch_switch.link_id].bss->freq !=
5550 data->ch_switch.freq) {
5551 wpa_s->links[data->ch_switch.link_id].bss->freq =
5552 data->ch_switch.freq;
5553 notify_bss_changes(
5554 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5555 wpa_s->links[data->ch_switch.link_id].bss);
5556 }
5557 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07005558 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005559 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005560 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005561 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005562
Hai Shalom81f62d82019-07-22 12:10:00 -07005563 wpa_msg(wpa_s, MSG_INFO,
5564 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5565 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5566 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005567 data->ch_switch.freq,
5568 data->ch_switch.ht_enabled,
5569 data->ch_switch.ch_offset,
5570 channel_width_to_string(data->ch_switch.ch_width),
5571 data->ch_switch.cf1,
5572 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005573 if (event == EVENT_CH_SWITCH_STARTED)
5574 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005575
Sunil Ravi65a724b2022-05-24 11:06:09 -07005576 if (wpa_s->assoc_freq && data->ch_switch.freq &&
5577 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
5578 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
5579 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005580 wpa_s->assoc_freq = data->ch_switch.freq;
5581 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005582 if (wpa_s->current_bss &&
5583 wpa_s->current_bss->freq != data->ch_switch.freq) {
5584 wpa_s->current_bss->freq = data->ch_switch.freq;
5585 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5586 wpa_s->current_bss);
5587 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005588
Hai Shalomfdcde762020-04-02 11:19:20 -07005589#ifdef CONFIG_SME
5590 switch (data->ch_switch.ch_offset) {
5591 case 1:
5592 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5593 break;
5594 case -1:
5595 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5596 break;
5597 default:
5598 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5599 break;
5600 }
5601#endif /* CONFIG_SME */
5602
Roshan Pius3a1667e2018-07-03 15:17:14 -07005603#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005604 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5605 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005606 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005607 wpa_s->current_ssid->mode ==
5608 WPAS_MODE_P2P_GROUP_FORMATION) {
5609 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5610 data->ch_switch.ht_enabled,
5611 data->ch_switch.ch_offset,
5612 data->ch_switch.ch_width,
5613 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005614 data->ch_switch.cf2,
5615 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005616 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005617#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005618
Hai Shalom899fcc72020-10-19 14:38:18 -07005619 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5620 sme_event_ch_switch(wpa_s);
5621
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005622 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005623 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005624 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005625#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005626#ifdef NEED_AP_MLME
5627 case EVENT_DFS_RADAR_DETECTED:
5628 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005629 wpas_ap_event_dfs_radar_detected(wpa_s,
5630 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005631 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005632 case EVENT_DFS_NOP_FINISHED:
5633 if (data)
5634 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5635 &data->dfs_event);
5636 break;
5637#endif /* NEED_AP_MLME */
5638#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005639 case EVENT_DFS_CAC_STARTED:
5640 if (data)
5641 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5642 break;
5643 case EVENT_DFS_CAC_FINISHED:
5644 if (data)
5645 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5646 break;
5647 case EVENT_DFS_CAC_ABORTED:
5648 if (data)
5649 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5650 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005651 case EVENT_RX_MGMT: {
5652 u16 fc, stype;
5653 const struct ieee80211_mgmt *mgmt;
5654
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005655#ifdef CONFIG_TESTING_OPTIONS
5656 if (wpa_s->ext_mgmt_frame_handling) {
5657 struct rx_mgmt *rx = &data->rx_mgmt;
5658 size_t hex_len = 2 * rx->frame_len + 1;
5659 char *hex = os_malloc(hex_len);
5660 if (hex) {
5661 wpa_snprintf_hex(hex, hex_len,
5662 rx->frame, rx->frame_len);
5663 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5664 rx->freq, rx->datarate, rx->ssi_signal,
5665 hex);
5666 os_free(hex);
5667 }
5668 break;
5669 }
5670#endif /* CONFIG_TESTING_OPTIONS */
5671
Dmitry Shmidt04949592012-07-19 12:16:46 -07005672 mgmt = (const struct ieee80211_mgmt *)
5673 data->rx_mgmt.frame;
5674 fc = le_to_host16(mgmt->frame_control);
5675 stype = WLAN_FC_GET_STYPE(fc);
5676
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005677#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005678 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005679#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005680#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005681 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005682 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005683 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005684 const u8 *ie;
5685 size_t ie_len;
5686
5687 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5688 ie_len = data->rx_mgmt.frame_len -
5689 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005690 wpas_p2p_probe_req_rx(
5691 wpa_s, src, mgmt->da,
5692 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005693 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005694 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005695 break;
5696 }
5697#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005698#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005699 if (wpa_s->current_ssid &&
5700 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5701 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005702 data->rx_mgmt.frame_len >= 30) {
5703 wpa_supplicant_event_ibss_auth(wpa_s, data);
5704 break;
5705 }
5706#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005707
5708 if (stype == WLAN_FC_STYPE_ACTION) {
5709 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005710 wpa_s, data->rx_mgmt.frame,
5711 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005712 data->rx_mgmt.freq,
5713 data->rx_mgmt.ssi_signal);
5714 break;
5715 }
5716
5717 if (wpa_s->ifmsh) {
5718 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005719 break;
5720 }
Hai Shalom60840252021-02-19 19:02:11 -08005721#ifdef CONFIG_PASN
5722 if (stype == WLAN_FC_STYPE_AUTH &&
5723 wpas_pasn_auth_rx(wpa_s, mgmt,
5724 data->rx_mgmt.frame_len) != -2)
5725 break;
5726#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005727
Roshan Pius3a1667e2018-07-03 15:17:14 -07005728#ifdef CONFIG_SAE
5729 if (stype == WLAN_FC_STYPE_AUTH &&
5730 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5731 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5732 sme_external_auth_mgmt_rx(
5733 wpa_s, data->rx_mgmt.frame,
5734 data->rx_mgmt.frame_len);
5735 break;
5736 }
5737#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005738 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5739 "management frame in non-AP mode");
5740 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005741#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005742 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005743
5744 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005745 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5746 const u8 *ie;
5747 size_t ie_len;
5748
5749 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5750 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005751
5752 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5753 mgmt->bssid, ie, ie_len,
5754 data->rx_mgmt.ssi_signal);
5755 }
5756
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005757 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005758#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005759 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005760 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005761 case EVENT_RX_PROBE_REQ:
5762 if (data->rx_probe_req.sa == NULL ||
5763 data->rx_probe_req.ie == NULL)
5764 break;
5765#ifdef CONFIG_AP
5766 if (wpa_s->ap_iface) {
5767 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5768 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005769 data->rx_probe_req.da,
5770 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005771 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005772 data->rx_probe_req.ie_len,
5773 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005774 break;
5775 }
5776#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005777 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005778 data->rx_probe_req.da,
5779 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005780 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005781 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005782 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005783 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005784 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005785 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005786#ifdef CONFIG_OFFCHANNEL
5787 offchannel_remain_on_channel_cb(
5788 wpa_s, data->remain_on_channel.freq,
5789 data->remain_on_channel.duration);
5790#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005791 wpas_p2p_remain_on_channel_cb(
5792 wpa_s, data->remain_on_channel.freq,
5793 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005794#ifdef CONFIG_DPP
5795 wpas_dpp_remain_on_channel_cb(
5796 wpa_s, data->remain_on_channel.freq,
5797 data->remain_on_channel.duration);
5798#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005799 break;
5800 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005801#ifdef CONFIG_OFFCHANNEL
5802 offchannel_cancel_remain_on_channel_cb(
5803 wpa_s, data->remain_on_channel.freq);
5804#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005805 wpas_p2p_cancel_remain_on_channel_cb(
5806 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005807#ifdef CONFIG_DPP
5808 wpas_dpp_cancel_remain_on_channel_cb(
5809 wpa_s, data->remain_on_channel.freq);
5810#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005811 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005812 case EVENT_EAPOL_RX:
5813 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5814 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00005815 data->eapol_rx.data_len,
5816 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005817 break;
5818 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005819 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5820 "above=%d signal=%d noise=%d txrate=%d",
5821 data->signal_change.above_threshold,
5822 data->signal_change.current_signal,
5823 data->signal_change.current_noise,
5824 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005825 wpa_bss_update_level(wpa_s->current_bss,
5826 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005827 bgscan_notify_signal_change(
5828 wpa_s, data->signal_change.above_threshold,
5829 data->signal_change.current_signal,
5830 data->signal_change.current_noise,
5831 data->signal_change.current_txrate);
5832 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005833 case EVENT_INTERFACE_MAC_CHANGED:
5834 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005835 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005836 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005837 case EVENT_INTERFACE_ENABLED:
5838 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5839 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005840 u8 addr[ETH_ALEN];
5841
Hai Shalomfdcde762020-04-02 11:19:20 -07005842 eloop_cancel_timeout(wpas_clear_disabled_interface,
5843 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005844 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005845 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005846 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5847 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5848 else
5849 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005850 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005851 if (wpa_s->p2p_mgmt) {
5852 wpa_supplicant_set_state(wpa_s,
5853 WPA_DISCONNECTED);
5854 break;
5855 }
5856
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005857#ifdef CONFIG_AP
5858 if (!wpa_s->ap_iface) {
5859 wpa_supplicant_set_state(wpa_s,
5860 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005861 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005862 wpa_supplicant_req_scan(wpa_s, 0, 0);
5863 } else
5864 wpa_supplicant_set_state(wpa_s,
5865 WPA_COMPLETED);
5866#else /* CONFIG_AP */
5867 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5868 wpa_supplicant_req_scan(wpa_s, 0, 0);
5869#endif /* CONFIG_AP */
5870 }
5871 break;
5872 case EVENT_INTERFACE_DISABLED:
5873 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005874#ifdef CONFIG_P2P
5875 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5876 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5877 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5878 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005879 * Mark interface disabled if this happens to end up not
5880 * being removed as a separate P2P group interface.
5881 */
5882 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5883 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005884 * The interface was externally disabled. Remove
5885 * it assuming an external entity will start a
5886 * new session if needed.
5887 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005888 if (wpa_s->current_ssid &&
5889 wpa_s->current_ssid->p2p_group)
5890 wpas_p2p_interface_unavailable(wpa_s);
5891 else
5892 wpas_p2p_disconnect(wpa_s);
5893 /*
5894 * wpa_s instance may have been freed, so must not use
5895 * it here anymore.
5896 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005897 break;
5898 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005899 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5900 p2p_in_progress(wpa_s->global->p2p) > 1) {
5901 /* This radio work will be cancelled, so clear P2P
5902 * state as well.
5903 */
5904 p2p_stop_find(wpa_s->global->p2p);
5905 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005906#endif /* CONFIG_P2P */
5907
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005908 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5909 /*
5910 * Indicate disconnection to keep ctrl_iface events
5911 * consistent.
5912 */
5913 wpa_supplicant_event_disassoc(
5914 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5915 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005916 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005917 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005918 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5919 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005920 clear_at.usec = 0;
5921 } else {
5922 struct os_reltime tmp;
5923
Hai Shalom60840252021-02-19 19:02:11 -08005924 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005925 tmp.usec = 0;
5926 os_reltime_sub(&tmp, &age, &clear_at);
5927 }
5928 eloop_register_timeout(clear_at.sec, clear_at.usec,
5929 wpas_clear_disabled_interface,
5930 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005931 radio_remove_works(wpa_s, NULL, 0);
5932
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005933 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5934 break;
5935 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005936 wpa_supplicant_update_channel_list(
5937 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005938 break;
5939 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005940 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005941 break;
5942 case EVENT_BEST_CHANNEL:
5943 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5944 "(%d %d %d)",
5945 data->best_chan.freq_24, data->best_chan.freq_5,
5946 data->best_chan.freq_overall);
5947 wpa_s->best_24_freq = data->best_chan.freq_24;
5948 wpa_s->best_5_freq = data->best_chan.freq_5;
5949 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005950 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5951 data->best_chan.freq_5,
5952 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005953 break;
5954 case EVENT_UNPROT_DEAUTH:
5955 wpa_supplicant_event_unprot_deauth(wpa_s,
5956 &data->unprot_deauth);
5957 break;
5958 case EVENT_UNPROT_DISASSOC:
5959 wpa_supplicant_event_unprot_disassoc(wpa_s,
5960 &data->unprot_disassoc);
5961 break;
5962 case EVENT_STATION_LOW_ACK:
5963#ifdef CONFIG_AP
5964 if (wpa_s->ap_iface && data)
5965 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5966 data->low_ack.addr);
5967#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005968#ifdef CONFIG_TDLS
5969 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005970 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5971 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005972#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005973 break;
5974 case EVENT_IBSS_PEER_LOST:
5975#ifdef CONFIG_IBSS_RSN
5976 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5977#endif /* CONFIG_IBSS_RSN */
5978 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005979 case EVENT_DRIVER_GTK_REKEY:
5980 if (os_memcmp(data->driver_gtk_rekey.bssid,
5981 wpa_s->bssid, ETH_ALEN))
5982 break;
5983 if (!wpa_s->wpa)
5984 break;
5985 wpa_sm_update_replay_ctr(wpa_s->wpa,
5986 data->driver_gtk_rekey.replay_ctr);
5987 break;
5988 case EVENT_SCHED_SCAN_STOPPED:
5989 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005990 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005991 wpa_supplicant_notify_scanning(wpa_s, 0);
5992
5993 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5994 break;
5995
5996 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005997 * If the driver stopped scanning without being requested to,
5998 * request a new scan to continue scanning for networks.
5999 */
6000 if (!wpa_s->sched_scan_stop_req &&
6001 wpa_s->wpa_state == WPA_SCANNING) {
6002 wpa_dbg(wpa_s, MSG_DEBUG,
6003 "Restart scanning after unexpected sched_scan stop event");
6004 wpa_supplicant_req_scan(wpa_s, 1, 0);
6005 break;
6006 }
6007
6008 wpa_s->sched_scan_stop_req = 0;
6009
6010 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006011 * Start a new sched scan to continue searching for more SSIDs
6012 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006013 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006014 if (wpa_s->sched_scan_timed_out) {
6015 wpa_supplicant_req_sched_scan(wpa_s);
6016 } else if (wpa_s->pno_sched_pending) {
6017 wpa_s->pno_sched_pending = 0;
6018 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006019 } else if (resched) {
6020 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006021 }
6022
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006023 break;
6024 case EVENT_WPS_BUTTON_PUSHED:
6025#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006026 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006027#endif /* CONFIG_WPS */
6028 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006029 case EVENT_AVOID_FREQUENCIES:
6030 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6031 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006032 case EVENT_CONNECT_FAILED_REASON:
6033#ifdef CONFIG_AP
6034 if (!wpa_s->ap_iface || !data)
6035 break;
6036 hostapd_event_connect_failed_reason(
6037 wpa_s->ap_iface->bss[0],
6038 data->connect_failed_reason.addr,
6039 data->connect_failed_reason.code);
6040#endif /* CONFIG_AP */
6041 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006042 case EVENT_NEW_PEER_CANDIDATE:
6043#ifdef CONFIG_MESH
6044 if (!wpa_s->ifmsh || !data)
6045 break;
6046 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6047 data->mesh_peer.ies,
6048 data->mesh_peer.ie_len);
6049#endif /* CONFIG_MESH */
6050 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006051 case EVENT_SURVEY:
6052#ifdef CONFIG_AP
6053 if (!wpa_s->ap_iface)
6054 break;
6055 hostapd_event_get_survey(wpa_s->ap_iface,
6056 &data->survey_results);
6057#endif /* CONFIG_AP */
6058 break;
6059 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006060#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006061#ifdef CONFIG_ACS
6062 if (!wpa_s->ap_iface)
6063 break;
6064 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6065 &data->acs_selected_channels);
6066#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006067#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006068 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006069 case EVENT_P2P_LO_STOP:
6070#ifdef CONFIG_P2P
6071 wpa_s->p2p_lo_started = 0;
6072 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6073 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6074 data->p2p_lo_stop.reason_code);
6075#endif /* CONFIG_P2P */
6076 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006077 case EVENT_BEACON_LOSS:
6078 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6079 break;
6080 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6081 bgscan_notify_beacon_loss(wpa_s);
6082 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006083 case EVENT_EXTERNAL_AUTH:
6084#ifdef CONFIG_SAE
6085 if (!wpa_s->current_ssid) {
6086 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6087 break;
6088 }
6089 sme_external_auth_trigger(wpa_s, data);
6090#endif /* CONFIG_SAE */
6091 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006092#ifdef CONFIG_PASN
6093 case EVENT_PASN_AUTH:
6094 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6095 break;
6096#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006097 case EVENT_PORT_AUTHORIZED:
6098 wpa_supplicant_event_port_authorized(wpa_s);
6099 break;
6100 case EVENT_STATION_OPMODE_CHANGED:
6101#ifdef CONFIG_AP
6102 if (!wpa_s->ap_iface || !data)
6103 break;
6104
6105 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6106 data->sta_opmode.addr,
6107 data->sta_opmode.smps_mode,
6108 data->sta_opmode.chan_width,
6109 data->sta_opmode.rx_nss);
6110#endif /* CONFIG_AP */
6111 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07006112 case EVENT_UNPROT_BEACON:
6113 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6114 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08006115 case EVENT_TX_WAIT_EXPIRE:
6116#ifdef CONFIG_DPP
6117 wpas_dpp_tx_wait_expire(wpa_s);
6118#endif /* CONFIG_DPP */
6119 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006120 default:
6121 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6122 break;
6123 }
6124}
Dmitry Shmidte4663042016-04-04 10:07:49 -07006125
6126
6127void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6128 union wpa_event_data *data)
6129{
6130 struct wpa_supplicant *wpa_s;
6131
6132 if (event != EVENT_INTERFACE_STATUS)
6133 return;
6134
6135 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6136 if (wpa_s && wpa_s->driver->get_ifindex) {
6137 unsigned int ifindex;
6138
6139 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6140 if (ifindex != data->interface_status.ifindex) {
6141 wpa_dbg(wpa_s, MSG_DEBUG,
6142 "interface status ifindex %d mismatch (%d)",
6143 ifindex, data->interface_status.ifindex);
6144 return;
6145 }
6146 }
6147#ifdef CONFIG_MATCH_IFACE
6148 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6149 struct wpa_interface *wpa_i;
6150
6151 wpa_i = wpa_supplicant_match_iface(
6152 ctx, data->interface_status.ifname);
6153 if (!wpa_i)
6154 return;
6155 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6156 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006157 }
6158#endif /* CONFIG_MATCH_IFACE */
6159
6160 if (wpa_s)
6161 wpa_supplicant_event(wpa_s, event, data);
6162}