blob: b066d6279aef33a1986fda158a86d9711bf97a49 [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
Matthew Wang06b42472022-11-10 06:56:31 +00002412 if (wpas_p2p_retry_limit_exceeded(wpa_s)) {
2413 return 0;
2414 }
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002415 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002416 wpa_s->show_group_started ||
2417 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418 /*
2419 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002420 * state and during P2P join-a-group operation
2421 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002422 */
2423 timeout_sec = 0;
2424 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002425 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2426 timeout_usec);
2427 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002428 }
2429#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002430#ifdef CONFIG_INTERWORKING
2431 if (wpa_s->conf->auto_interworking &&
2432 wpa_s->conf->interworking &&
2433 wpa_s->conf->cred) {
2434 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2435 "start ANQP fetch since no matching "
2436 "networks found");
2437 wpa_s->network_select = 1;
2438 wpa_s->auto_network_select = 1;
2439 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002440 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002441 }
2442#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002443#ifdef CONFIG_WPS
2444 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2445 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2446 timeout_sec = 0;
2447 timeout_usec = 500000;
2448 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2449 timeout_usec);
2450 return 0;
2451 }
2452#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002453#ifdef CONFIG_OWE
2454 if (wpa_s->owe_transition_search) {
2455 wpa_dbg(wpa_s, MSG_DEBUG,
2456 "OWE: Use shorter wait during transition mode search");
2457 timeout_sec = 0;
2458 timeout_usec = 500000;
2459 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2460 timeout_usec);
2461 return 0;
2462 }
2463#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002464 if (wpa_supplicant_req_sched_scan(wpa_s))
2465 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2466 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002467
2468 wpa_msg_ctrl(wpa_s, MSG_INFO,
2469 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002470 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002471 }
2472 }
2473 return 0;
2474}
2475
2476
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002477static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2478 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002479{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002480 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002481 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002482
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002483 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002484 if (res == 2) {
2485 /*
2486 * Interface may have been removed, so must not dereference
2487 * wpa_s after this.
2488 */
2489 return 1;
2490 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002491
2492 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002493 /*
2494 * If no scan results could be fetched, then no need to
2495 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002496 * this scan. Similarly, if scan results started a new operation on this
2497 * interface, do not notify other interfaces to avoid concurrent
2498 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002499 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002500 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002501 }
2502
2503 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002504 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002505 * so, they get updated with this same scan info.
2506 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002507 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2508 radio_list) {
2509 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002510 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2511 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002512 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2513 res > 0);
2514 if (res < 0)
2515 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002516 }
2517 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002518
2519 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002520}
2521
2522#endif /* CONFIG_NO_SCAN_PROCESSING */
2523
2524
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002525int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2526{
2527#ifdef CONFIG_NO_SCAN_PROCESSING
2528 return -1;
2529#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002530 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002531
Dmitry Shmidt29333592017-01-09 12:27:11 -08002532 wpa_s->ignore_post_flush_scan_res = 0;
2533
Dmitry Shmidt41712582015-06-29 11:02:15 -07002534 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002535 return -1;
2536
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002537 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002538 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002539 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002540 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2541 return -1;
2542 }
2543
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002544 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002545#endif /* CONFIG_NO_SCAN_PROCESSING */
2546}
2547
Dmitry Shmidt04949592012-07-19 12:16:46 -07002548#ifdef CONFIG_WNM
2549
2550static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2551{
2552 struct wpa_supplicant *wpa_s = eloop_ctx;
2553
2554 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2555 return;
2556
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002557 if (!wpa_s->no_keep_alive) {
2558 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2559 MAC2STR(wpa_s->bssid));
2560 /* TODO: could skip this if normal data traffic has been sent */
2561 /* TODO: Consider using some more appropriate data frame for
2562 * this */
2563 if (wpa_s->l2)
2564 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2565 (u8 *) "", 0);
2566 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002567
2568#ifdef CONFIG_SME
2569 if (wpa_s->sme.bss_max_idle_period) {
2570 unsigned int msec;
2571 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2572 if (msec > 100)
2573 msec -= 100;
2574 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2575 wnm_bss_keep_alive, wpa_s, NULL);
2576 }
2577#endif /* CONFIG_SME */
2578}
2579
2580
2581static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2582 const u8 *ies, size_t ies_len)
2583{
2584 struct ieee802_11_elems elems;
2585
2586 if (ies == NULL)
2587 return;
2588
2589 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2590 return;
2591
2592#ifdef CONFIG_SME
2593 if (elems.bss_max_idle_period) {
2594 unsigned int msec;
2595 wpa_s->sme.bss_max_idle_period =
2596 WPA_GET_LE16(elems.bss_max_idle_period);
2597 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2598 "TU)%s", wpa_s->sme.bss_max_idle_period,
2599 (elems.bss_max_idle_period[2] & 0x01) ?
2600 " (protected keep-live required)" : "");
2601 if (wpa_s->sme.bss_max_idle_period == 0)
2602 wpa_s->sme.bss_max_idle_period = 1;
2603 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2604 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2605 /* msec times 1000 */
2606 msec = wpa_s->sme.bss_max_idle_period * 1024;
2607 if (msec > 100)
2608 msec -= 100;
2609 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2610 wnm_bss_keep_alive, wpa_s,
2611 NULL);
2612 }
2613 }
2614#endif /* CONFIG_SME */
2615}
2616
2617#endif /* CONFIG_WNM */
2618
2619
2620void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2621{
2622#ifdef CONFIG_WNM
2623 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2624#endif /* CONFIG_WNM */
2625}
2626
2627
Dmitry Shmidt051af732013-10-22 13:52:46 -07002628#ifdef CONFIG_INTERWORKING
2629
2630static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2631 size_t len)
2632{
2633 int res;
2634
2635 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2636 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2637 if (res) {
2638 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2639 }
2640
2641 return res;
2642}
2643
2644
2645static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2646 const u8 *ies, size_t ies_len)
2647{
2648 struct ieee802_11_elems elems;
2649
2650 if (ies == NULL)
2651 return;
2652
2653 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2654 return;
2655
2656 if (elems.qos_map_set) {
2657 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2658 elems.qos_map_set_len);
2659 }
2660}
2661
2662#endif /* CONFIG_INTERWORKING */
2663
2664
Hai Shalom74f70d42019-02-11 14:42:39 -08002665static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2666 const u8 *ies, size_t ies_len)
2667{
2668 struct ieee802_11_elems elems;
2669 const u8 *map_sub_elem, *pos;
2670 size_t len;
2671
Hai Shalomfdcde762020-04-02 11:19:20 -07002672 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002673
Hai Shalomfdcde762020-04-02 11:19:20 -07002674 if (!ies ||
2675 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2676 !elems.multi_ap || elems.multi_ap_len < 7)
2677 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002678
2679 pos = elems.multi_ap + 4;
2680 len = elems.multi_ap_len - 4;
2681
2682 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002683 if (!map_sub_elem || map_sub_elem[1] < 1)
2684 return;
2685
2686 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2687 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2688 MULTI_AP_FRONTHAUL_BSS);
2689 wpa_s->multi_ap_ie = 1;
2690}
2691
2692
2693static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2694{
2695 if (!wpa_s->current_ssid ||
2696 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2697 return;
2698
2699 if (!wpa_s->multi_ap_ie) {
2700 wpa_printf(MSG_INFO,
2701 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002702 goto fail;
2703 }
2704
Hai Shalomfdcde762020-04-02 11:19:20 -07002705 if (!wpa_s->multi_ap_backhaul) {
2706 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002707 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2708 wpa_printf(MSG_INFO,
2709 "WPS active, accepting fronthaul-only BSS");
2710 /* Don't set 4addr mode in this case, so just return */
2711 return;
2712 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002713 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2714 goto fail;
2715 }
2716
2717 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2718 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2719 goto fail;
2720 }
2721 wpa_s->enabled_4addr_mode = 1;
2722 return;
2723
2724fail:
2725 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2726}
2727
2728
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002729#ifdef CONFIG_FST
2730static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2731 const u8 *ie, size_t ie_len)
2732{
2733 struct mb_ies_info mb_ies;
2734
2735 if (!ie || !ie_len || !wpa_s->fst)
2736 return -ENOENT;
2737
2738 os_memset(&mb_ies, 0, sizeof(mb_ies));
2739
2740 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2741 size_t len;
2742
2743 len = 2 + ie[1];
2744 if (len > ie_len) {
2745 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2746 ie, ie_len);
2747 break;
2748 }
2749
2750 if (ie[0] == WLAN_EID_MULTI_BAND) {
2751 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2752 (unsigned int) len);
2753 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2754 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2755 mb_ies.nof_ies++;
2756 }
2757
2758 ie_len -= len;
2759 ie += len;
2760 }
2761
2762 if (mb_ies.nof_ies > 0) {
2763 wpabuf_free(wpa_s->received_mb_ies);
2764 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2765 return 0;
2766 }
2767
2768 return -ENOENT;
2769}
2770#endif /* CONFIG_FST */
2771
2772
Hai Shalomc1a21442022-02-04 13:43:00 -08002773static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2774 union wpa_event_data *data)
2775{
2776 int sel;
2777 const u8 *p;
2778 int l, len;
2779 bool found = false;
2780 struct wpa_ie_data ie;
2781 struct wpa_ssid *ssid = wpa_s->current_ssid;
2782 struct wpa_bss *bss = wpa_s->current_bss;
2783 int pmf;
2784
2785 if (!ssid)
2786 return 0;
2787
2788 p = data->assoc_info.req_ies;
2789 l = data->assoc_info.req_ies_len;
2790
2791 while (p && l >= 2) {
2792 len = p[1] + 2;
2793 if (len > l) {
2794 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2795 p, l);
2796 break;
2797 }
2798 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2799 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2800 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2801 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2802 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2803 found = true;
2804 break;
2805 }
2806 l -= len;
2807 p += len;
2808 }
2809
2810 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2811 return 0;
2812
2813 wpa_hexdump(MSG_DEBUG,
2814 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2815 p, l);
2816
2817 /* Update proto from (Re)Association Request frame info */
2818 wpa_s->wpa_proto = ie.proto;
2819 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2820 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2821 !!(wpa_s->wpa_proto &
2822 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2823
2824 /* Update AKMP suite from (Re)Association Request frame info */
2825 sel = ie.key_mgmt;
2826 if (ssid->key_mgmt)
2827 sel &= ssid->key_mgmt;
2828
2829 wpa_dbg(wpa_s, MSG_DEBUG,
2830 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2831 ie.key_mgmt, ssid->key_mgmt, sel);
2832 if (ie.key_mgmt && !sel) {
2833 wpa_supplicant_deauthenticate(
2834 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2835 return -1;
2836 }
2837
Sunil Ravi89eba102022-09-13 21:04:37 -07002838 /*
2839 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
2840 * different AKM.
2841 */
2842 if (wpa_s->key_mgmt != ie.key_mgmt &&
2843 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
2844 if (!ssid->psk_set) {
2845 wpa_dbg(wpa_s, MSG_INFO,
2846 "No PSK available for association");
2847 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE");
2848 return -1;
2849 }
2850
2851 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
2852 if (wpa_s->conf->key_mgmt_offload &&
2853 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
2854 wpa_drv_set_key(wpa_s, 0, NULL, 0, 0, NULL, 0, ssid->psk,
2855 PMK_LEN, KEY_FLAG_PMK))
2856 wpa_dbg(wpa_s, MSG_ERROR,
2857 "WPA: Cannot set PMK for key management offload");
2858 }
2859
Hai Shalomc1a21442022-02-04 13:43:00 -08002860 wpa_s->key_mgmt = ie.key_mgmt;
2861 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2862 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2863 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2864 wpa_s->wpa_proto);
2865
2866 /* Update pairwise cipher from (Re)Association Request frame info */
2867 sel = ie.pairwise_cipher;
2868 if (ssid->pairwise_cipher)
2869 sel &= ssid->pairwise_cipher;
2870
2871 wpa_dbg(wpa_s, MSG_DEBUG,
2872 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2873 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2874 if (ie.pairwise_cipher && !sel) {
2875 wpa_supplicant_deauthenticate(
2876 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2877 return -1;
2878 }
2879
2880 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2881 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2882 wpa_s->pairwise_cipher);
2883 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2884 wpa_cipher_txt(wpa_s->pairwise_cipher));
2885
2886 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2887 if (!bss) {
2888 wpa_dbg(wpa_s, MSG_DEBUG,
2889 "WPA: current_bss == NULL - skip AP IE check");
2890 return 0;
2891 }
2892
2893 /* Update GTK and IGTK from AP's RSNE */
2894 found = false;
2895
2896 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2897 const u8 *bss_rsn;
2898
2899 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2900 if (bss_rsn) {
2901 p = bss_rsn;
2902 len = 2 + bss_rsn[1];
2903 found = true;
2904 }
2905 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2906 const u8 *bss_wpa;
2907
2908 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2909 if (bss_wpa) {
2910 p = bss_wpa;
2911 len = 2 + bss_wpa[1];
2912 found = true;
2913 }
2914 }
2915
2916 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2917 return 0;
2918
2919 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2920 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2921 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
2922 /* AP does not support MFP, local configuration requires it */
2923 wpa_supplicant_deauthenticate(
2924 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2925 return -1;
2926 }
2927 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
2928 pmf == NO_MGMT_FRAME_PROTECTION) {
2929 /* AP requires MFP, local configuration disables it */
2930 wpa_supplicant_deauthenticate(
2931 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2932 return -1;
2933 }
2934
2935 /* Update PMF from local configuration now that MFP validation was done
2936 * above */
2937 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
2938
2939 /* Update GTK from AP's RSNE */
2940 sel = ie.group_cipher;
2941 if (ssid->group_cipher)
2942 sel &= ssid->group_cipher;
2943
2944 wpa_dbg(wpa_s, MSG_DEBUG,
2945 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
2946 ie.group_cipher, ssid->group_cipher, sel);
2947 if (ie.group_cipher && !sel) {
2948 wpa_supplicant_deauthenticate(
2949 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
2950 return -1;
2951 }
2952
2953 wpa_s->group_cipher = ie.group_cipher;
2954 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
2955 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
2956 wpa_cipher_txt(wpa_s->group_cipher));
2957
2958 /* Update IGTK from AP RSN IE */
2959 sel = ie.mgmt_group_cipher;
2960 if (ssid->group_mgmt_cipher)
2961 sel &= ssid->group_mgmt_cipher;
2962
2963 wpa_dbg(wpa_s, MSG_DEBUG,
2964 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
2965 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
2966
2967 if (pmf == NO_MGMT_FRAME_PROTECTION ||
2968 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
2969 wpa_dbg(wpa_s, MSG_DEBUG,
2970 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
2971 ie.capabilities);
2972 ie.mgmt_group_cipher = 0;
2973 }
2974
2975 if (ie.mgmt_group_cipher && !sel) {
2976 wpa_supplicant_deauthenticate(
2977 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
2978 return -1;
2979 }
2980
2981 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
2982 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
2983 wpa_s->mgmt_group_cipher);
2984 if (wpa_s->mgmt_group_cipher)
2985 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
2986 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
2987 else
2988 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
2989
2990 return 0;
2991}
2992
2993
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002994static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2995 union wpa_event_data *data)
2996{
Hai Shalomc3565922019-10-28 11:58:20 -07002997 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002998 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002999 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07003000 bool bssid_known;
Vinayak Yadawad14709082022-03-17 14:25:11 +05303001#ifdef CONFIG_DRIVER_NL80211_BRCM
3002 struct wpa_ie_data ie;
3003#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003004
3005 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07003006 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003007 if (data->assoc_info.req_ies)
3008 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3009 data->assoc_info.req_ies_len);
3010 if (data->assoc_info.resp_ies) {
3011 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3012 data->assoc_info.resp_ies_len);
3013#ifdef CONFIG_TDLS
3014 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3015 data->assoc_info.resp_ies_len);
3016#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003017#ifdef CONFIG_WNM
3018 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3019 data->assoc_info.resp_ies_len);
3020#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003021#ifdef CONFIG_INTERWORKING
3022 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3023 data->assoc_info.resp_ies_len);
3024#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003025 if (wpa_s->hw_capab == CAPAB_VHT &&
3026 get_ie(data->assoc_info.resp_ies,
3027 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3028 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003029
3030 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3031 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003032 }
3033 if (data->assoc_info.beacon_ies)
3034 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3035 data->assoc_info.beacon_ies,
3036 data->assoc_info.beacon_ies_len);
3037 if (data->assoc_info.freq)
3038 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3039 data->assoc_info.freq);
3040
Hai Shalom021b0b52019-04-10 11:17:58 -07003041 wpa_s->connection_set = 0;
3042 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3043 struct ieee802_11_elems req_elems, resp_elems;
3044
3045 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3046 data->assoc_info.req_ies_len,
3047 &req_elems, 0) != ParseFailed &&
3048 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3049 data->assoc_info.resp_ies_len,
3050 &resp_elems, 0) != ParseFailed) {
3051 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003052 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3053 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003054 wpa_s->connection_ht = req_elems.ht_capabilities &&
3055 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003056 /* Do not include subset of VHT on 2.4 GHz vendor
3057 * extension in consideration for reporting VHT
3058 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003059 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003060 resp_elems.vht_capabilities &&
3061 (!data->assoc_info.freq ||
3062 wpas_freq_to_band(data->assoc_info.freq) !=
3063 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003064 wpa_s->connection_he = req_elems.he_capabilities &&
3065 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003066 wpa_s->connection_eht = req_elems.eht_capabilities &&
3067 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003068
3069 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3070 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3071 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3072 max_nss_rx_req : max_nss_rx_resp;
3073 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3074 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3075 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3076 max_nss_tx_req : max_nss_tx_resp;
3077
3078 struct supported_chan_width sta_supported_chan_width =
3079 get_supported_channel_width(&req_elems);
3080 enum chan_width ap_operation_chan_width =
3081 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303082 if (wpa_s->connection_vht || wpa_s->connection_he ||
3083 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003084 wpa_s->connection_channel_bandwidth =
3085 get_sta_operation_chan_width(ap_operation_chan_width,
3086 sta_supported_chan_width);
3087 } else if (wpa_s->connection_ht) {
3088 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3089 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3090 } else {
3091 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3092 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003093 }
3094 }
3095
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003096 p = data->assoc_info.req_ies;
3097 l = data->assoc_info.req_ies_len;
3098
3099 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3100 while (p && l >= 2) {
3101 len = p[1] + 2;
3102 if (len > l) {
3103 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3104 p, l);
3105 break;
3106 }
Hai Shalomc3565922019-10-28 11:58:20 -07003107 if (!found &&
3108 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3109 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3110 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3111 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3112 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003113 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3114 break;
3115 found = 1;
3116 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07003117 }
3118 if (!found_x && p[0] == WLAN_EID_RSNX) {
3119 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3120 break;
3121 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003122 }
3123 l -= len;
3124 p += len;
3125 }
3126 if (!found && data->assoc_info.req_ies)
3127 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003128 if (!found_x && data->assoc_info.req_ies)
3129 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003130
Vinayak Yadawad14709082022-03-17 14:25:11 +05303131#ifdef CONFIG_DRIVER_NL80211_BRCM
3132 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3133 * to a different security type, update the current supplicant configuration to use the AKM
3134 * and pairwise suites from the assoc IE passed by the driver.
3135 */
3136 if (wpas_driver_bss_selection(wpa_s)) {
3137 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3138 /* Check if firmware has roamed to a different security network */
3139 if(wpa_s->key_mgmt != ie.key_mgmt) {
3140 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3141 ie.key_mgmt);
3142 wpa_s->key_mgmt = ie.key_mgmt;
3143 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3144
3145 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3146 /* Restore PMK as it can get overwritten if the previous
3147 * association was to 802.1X.
3148 */
3149 if ((!(wpa_s->drv_flags &
3150 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3151 (wpa_s->current_ssid) &&
3152 (wpa_s->current_ssid->psk_set)) {
3153 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3154 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3155 "BSSID");
3156 wpa_supplicant_deauthenticate(
3157 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3158 return -1;
3159 }
3160 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3161 PMK_LEN, NULL, bssid);
3162 }
3163 }
3164 }
3165 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3166 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3167 "from Assoc IE", ie.pairwise_cipher);
3168 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3169 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3170 wpa_s->pairwise_cipher);
3171 }
3172 // TODO: Notify the framework about security type change b/230766005
3173 }
3174 }
3175#endif /* CONFIG_DRIVER_NL80211_BRCM */
3176
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003177#ifdef CONFIG_FILS
3178#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003179 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3180 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003181 (!data->assoc_info.resp_frame ||
3182 fils_process_assoc_resp(wpa_s->wpa,
3183 data->assoc_info.resp_frame,
3184 data->assoc_info.resp_frame_len) < 0)) {
3185 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3186 return -1;
3187 }
3188#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003189
3190 /* Additional processing for FILS when SME is in driver */
3191 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3192 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3193 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003194#endif /* CONFIG_FILS */
3195
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003196#ifdef CONFIG_OWE
3197 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003198 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003199 owe_process_assoc_resp(wpa_s->wpa, bssid,
3200 data->assoc_info.resp_ies,
3201 data->assoc_info.resp_ies_len) < 0)) {
3202 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3203 return -1;
3204 }
3205#endif /* CONFIG_OWE */
3206
Hai Shalom021b0b52019-04-10 11:17:58 -07003207#ifdef CONFIG_DPP2
3208 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003209 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3210 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003211 struct ieee802_11_elems elems;
3212
3213 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3214 data->assoc_info.resp_ies_len,
3215 &elems, 0) == ParseFailed ||
3216 !elems.owe_dh)
3217 goto no_pfs;
3218 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3219 elems.owe_dh_len) < 0) {
3220 wpa_supplicant_deauthenticate(wpa_s,
3221 WLAN_REASON_UNSPECIFIED);
3222 return -1;
3223 }
3224
3225 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3226 }
3227no_pfs:
3228#endif /* CONFIG_DPP2 */
3229
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003230#ifdef CONFIG_IEEE80211R
3231#ifdef CONFIG_SME
3232 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003233 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003234 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3235 data->assoc_info.resp_ies,
3236 data->assoc_info.resp_ies_len,
3237 bssid) < 0) {
3238 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3239 "Reassociation Response failed");
3240 wpa_supplicant_deauthenticate(
3241 wpa_s, WLAN_REASON_INVALID_IE);
3242 return -1;
3243 }
3244 }
3245
3246 p = data->assoc_info.resp_ies;
3247 l = data->assoc_info.resp_ies_len;
3248
3249#ifdef CONFIG_WPS_STRICT
3250 if (p && wpa_s->current_ssid &&
3251 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3252 struct wpabuf *wps;
3253 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3254 if (wps == NULL) {
3255 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3256 "include WPS IE in (Re)Association Response");
3257 return -1;
3258 }
3259
3260 if (wps_validate_assoc_resp(wps) < 0) {
3261 wpabuf_free(wps);
3262 wpa_supplicant_deauthenticate(
3263 wpa_s, WLAN_REASON_INVALID_IE);
3264 return -1;
3265 }
3266 wpabuf_free(wps);
3267 }
3268#endif /* CONFIG_WPS_STRICT */
3269
3270 /* Go through the IEs and make a copy of the MDIE, if present. */
3271 while (p && l >= 2) {
3272 len = p[1] + 2;
3273 if (len > l) {
3274 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3275 p, l);
3276 break;
3277 }
3278 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3279 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3280 wpa_s->sme.ft_used = 1;
3281 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3282 MOBILITY_DOMAIN_ID_LEN);
3283 break;
3284 }
3285 l -= len;
3286 p += len;
3287 }
3288#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003289#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303290 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3291 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3292 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3293 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303294 wpa_ft_is_completed(wpa_s->wpa)) {
3295 return 0;
3296 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003297#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003298
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003299 /* Process FT when SME is in the driver */
3300 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3301 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003302 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003303 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3304 data->assoc_info.resp_ies,
3305 data->assoc_info.resp_ies_len,
3306 bssid) < 0) {
3307 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3308 "Reassociation Response failed");
3309 wpa_supplicant_deauthenticate(
3310 wpa_s, WLAN_REASON_INVALID_IE);
3311 return -1;
3312 }
3313 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3314 }
3315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003316 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3317 data->assoc_info.resp_ies_len);
3318#endif /* CONFIG_IEEE80211R */
3319
Hai Shalom899fcc72020-10-19 14:38:18 -07003320 if (bssid_known)
3321 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3322 data->assoc_info.resp_ies,
3323 data->assoc_info.resp_ies_len);
3324
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003325 /* WPA/RSN IE from Beacon/ProbeResp */
3326 p = data->assoc_info.beacon_ies;
3327 l = data->assoc_info.beacon_ies_len;
3328
3329 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3330 */
3331 wpa_found = rsn_found = 0;
3332 while (p && l >= 2) {
3333 len = p[1] + 2;
3334 if (len > l) {
3335 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3336 p, l);
3337 break;
3338 }
3339 if (!wpa_found &&
3340 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3341 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3342 wpa_found = 1;
3343 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3344 }
3345
3346 if (!rsn_found &&
3347 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3348 rsn_found = 1;
3349 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3350 }
3351
Hai Shalomc3565922019-10-28 11:58:20 -07003352 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3353 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003355 l -= len;
3356 p += len;
3357 }
3358
3359 if (!wpa_found && data->assoc_info.beacon_ies)
3360 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003361 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003362 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003363 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3364 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003365 if (wpa_found || rsn_found)
3366 wpa_s->ap_ies_from_associnfo = 1;
3367
Jouni Malinen87fd2792011-05-16 18:35:42 +03003368 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3369 wpa_s->assoc_freq != data->assoc_info.freq) {
3370 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3371 "%u to %u MHz",
3372 wpa_s->assoc_freq, data->assoc_info.freq);
3373 wpa_supplicant_update_scan_results(wpa_s);
3374 }
3375
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003376 wpa_s->assoc_freq = data->assoc_info.freq;
3377
Hai Shalomc1a21442022-02-04 13:43:00 -08003378 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3379 data->assoc_info.resp_ies_len);
3380
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003381 return 0;
3382}
3383
3384
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003385static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3386{
Hai Shalomc3565922019-10-28 11:58:20 -07003387 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003388
3389 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3390 return -1;
3391
3392 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3393 return 0;
3394
3395 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3396 WPA_IE_VENDOR_TYPE);
3397 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003398 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003399
3400 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3401 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3402 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003403 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3404 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3405 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003406 return -1;
3407
3408 return 0;
3409}
3410
3411
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003412static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3413 union wpa_event_data *data)
3414{
3415#ifdef CONFIG_FST
3416 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3417 struct wpa_bss *bss = wpa_s->current_bss;
3418 const u8 *ieprb, *iebcn;
3419
3420 wpabuf_free(wpa_s->received_mb_ies);
3421 wpa_s->received_mb_ies = NULL;
3422
3423 if (ai &&
3424 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3425 wpa_printf(MSG_DEBUG,
3426 "FST: MB IEs updated from Association Response frame");
3427 return;
3428 }
3429
3430 if (ai &&
3431 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3432 wpa_printf(MSG_DEBUG,
3433 "FST: MB IEs updated from association event Beacon IEs");
3434 return;
3435 }
3436
3437 if (!bss)
3438 return;
3439
Hai Shalom60840252021-02-19 19:02:11 -08003440 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003441 iebcn = ieprb + bss->ie_len;
3442
3443 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3444 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3445 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3446 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3447#endif /* CONFIG_FST */
3448}
3449
3450
Sunil Ravi89eba102022-09-13 21:04:37 -07003451static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3452{
3453 struct driver_sta_mlo_info mlo;
3454 int i;
3455
3456 mlo.valid_links = 0;
3457 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3458 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3459 wpa_supplicant_deauthenticate(wpa_s,
3460 WLAN_REASON_DEAUTH_LEAVING);
3461 return -1;
3462 }
3463
3464 if (wpa_s->valid_links == mlo.valid_links) {
3465 bool match = true;
3466
3467 if (!mlo.valid_links)
3468 return 0;
3469
3470 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3471 if (!(mlo.valid_links & BIT(i)))
3472 continue;
3473
3474 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3475 ETH_ALEN) != 0 ||
3476 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3477 ETH_ALEN) != 0) {
3478 match = false;
3479 break;
3480 }
3481 }
3482
3483 if (match &&
3484 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3485 ETH_ALEN) == 0)
3486 return 0;
3487 }
3488
3489 wpa_s->valid_links = mlo.valid_links;
3490 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3491 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3492 if (!(wpa_s->valid_links & BIT(i)))
3493 continue;
3494
3495 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3496 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3497 wpa_s->links[i].freq = mlo.links[i].freq;
3498 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3499 }
3500
3501 return 0;
3502}
3503
3504
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003505static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3506 union wpa_event_data *data)
3507{
3508 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003509 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003510 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003511#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3512 struct wpa_bss *bss;
3513#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003514#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303515 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003516#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003517
3518#ifdef CONFIG_AP
3519 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003520 if (!data)
3521 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003522 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3523 data->assoc_info.addr,
3524 data->assoc_info.req_ies,
3525 data->assoc_info.req_ies_len,
3526 data->assoc_info.reassoc);
3527 return;
3528 }
3529#endif /* CONFIG_AP */
3530
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003531 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003532 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003533
Andy Kuoaba17c12022-04-14 16:05:31 +08003534#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303535 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3536 struct wpa_ft_ies parse;
3537 /* Check for FT reassociation is done by the driver */
3538#ifdef CONFIG_IEEE80211R
3539 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303540 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303541 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3542 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3543 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3544 return;
3545 }
3546 if (parse.rsn_pmkid != NULL) {
3547 wpa_set_ft_completed(wpa_s->wpa);
3548 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3549 }
3550 }
3551#endif /* CONFIG_IEEE80211R */
3552 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003553#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303554
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003555 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003556
3557 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3558 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3559 wpa_supplicant_deauthenticate(
3560 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3561 return;
3562 }
3563
Sunil Ravi89eba102022-09-13 21:04:37 -07003564 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3565 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3566 wpa_supplicant_deauthenticate(wpa_s,
3567 WLAN_REASON_DEAUTH_LEAVING);
3568 return;
3569 }
3570
Sunil Ravia04bd252022-05-02 22:54:18 -07003571 if (ft_completed &&
3572 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3573 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3574 MAC2STR(bssid));
3575 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3576 wpa_printf(MSG_ERROR,
3577 "Can't find target AP's information!");
3578 return;
3579 }
3580 wpa_supplicant_assoc_update_ie(wpa_s);
3581 }
3582
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003583 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3584 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003585 /*
3586 * FILS authentication can share the same mechanism to mark the
3587 * connection fully authenticated, so set ft_completed also based on
3588 * FILS result.
3589 */
3590 if (!ft_completed)
3591 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003592
Andy Kuoaba17c12022-04-14 16:05:31 +08003593#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303594 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3595 /*
3596 * For driver based roaming, insert PSK during
3597 * the initial association
3598 */
3599 if (is_zero_ether_addr(wpa_s->bssid) &&
3600 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3601 /*
3602 * In case the driver wants to handle re-assocs,
3603 * pass it down the PMK.
3604 */
3605 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3606 wpa_sm_install_pmk(wpa_s->wpa);
3607 }
Mir Ali677e7482020-11-12 19:49:02 +05303608 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303609#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003610
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003611 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003612 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003613 if (os_reltime_initialized(&wpa_s->session_start)) {
3614 os_reltime_age(&wpa_s->session_start,
3615 &wpa_s->session_length);
3616 wpa_s->session_start.sec = 0;
3617 wpa_s->session_start.usec = 0;
3618 wpas_notify_session_length(wpa_s);
3619 } else {
3620 wpas_notify_auth_changed(wpa_s);
3621 os_get_reltime(&wpa_s->session_start);
3622 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003623 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3624 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003625 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003626 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003627 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3628 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003629 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003630
3631 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3632 wpa_clear_keys(wpa_s, bssid);
3633 }
3634 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003635 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003636 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3637 return;
3638 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003639 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003640
Hai Shalomc1a21442022-02-04 13:43:00 -08003641 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3642 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3643 return;
3644
Hai Shalomfdcde762020-04-02 11:19:20 -07003645 multi_ap_set_4addr_mode(wpa_s);
3646
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003647 if (wpa_s->conf->ap_scan == 1 &&
3648 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003649 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3650 wpa_msg(wpa_s, MSG_WARNING,
3651 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003652 }
3653
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003654 wpas_fst_update_mb_assoc(wpa_s, data);
3655
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003656#ifdef CONFIG_SME
3657 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3658 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003659 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003660#endif /* CONFIG_SME */
3661
3662 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3663 if (wpa_s->current_ssid) {
3664 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3665 * initialized before association, but for other modes,
3666 * initialize PC/SC here, if the current configuration needs
3667 * smartcard or SIM/USIM. */
3668 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3669 }
3670 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3671 if (wpa_s->l2)
3672 l2_packet_notify_auth_start(wpa_s->l2);
3673
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003674 already_authorized = data && data->assoc_info.authorized;
3675
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003676 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003677 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003678 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3679 * state machine may transit to AUTHENTICATING state based on obsolete
3680 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3681 * AUTHENTICATED without ever giving chance to EAP state machine to
3682 * reset the state.
3683 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003684 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003685 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3686 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003687 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003688 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3689 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3690 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003691 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003692 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003693 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003694 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003695 wpa_s->eapol_received = 0;
3696 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3697 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3698 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003699 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003700 if (wpa_s->current_ssid &&
3701 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003702 (wpa_s->drv_flags &
3703 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3704 /*
3705 * Set the key after having received joined-IBSS event
3706 * from the driver.
3707 */
3708 wpa_supplicant_set_wpa_none_key(wpa_s,
3709 wpa_s->current_ssid);
3710 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003711 wpa_supplicant_cancel_auth_timeout(wpa_s);
3712 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3713 } else if (!ft_completed) {
3714 /* Timeout for receiving the first EAPOL packet */
3715 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3716 }
3717 wpa_supplicant_cancel_scan(wpa_s);
3718
Hai Shalom5f92bc92019-04-18 11:54:11 -07003719 if (ft_completed) {
3720 /*
3721 * FT protocol completed - make sure EAPOL state machine ends
3722 * up in authenticated.
3723 */
3724 wpa_supplicant_cancel_auth_timeout(wpa_s);
3725 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003726 eapol_sm_notify_portValid(wpa_s->eapol, true);
3727 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003728 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3729 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303730 if (already_authorized) {
3731 /*
3732 * We are done; the driver will take care of RSN 4-way
3733 * handshake.
3734 */
3735 wpa_supplicant_cancel_auth_timeout(wpa_s);
3736 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3737 eapol_sm_notify_portValid(wpa_s->eapol, true);
3738 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3739 } else {
3740 /* Update port, WPA_COMPLETED state from
3741 * EVENT_PORT_AUTHORIZED context when driver is done
3742 * with 4way handshake.
3743 */
3744 wpa_msg(wpa_s, MSG_INFO, "ASSOC INFO: wait for driver port "
3745 "authorized indication");
3746 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003747 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003748 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3749 /*
3750 * The driver will take care of RSN 4-way handshake, so we need
3751 * to allow EAPOL supplicant to complete its work without
3752 * waiting for WPA supplicant.
3753 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003754 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003755 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003756#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303757 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3758 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3759 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3760 wpa_s->key_mgmt);
3761 wpa_supplicant_deauthenticate(
3762 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3763 return;
3764 }
3765 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3766 wpa_s->assoc_freq = data->assoc_info.freq;
3767 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3768 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003769#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3770
Jouni Malinena05074c2012-12-21 21:35:35 +02003771 wpa_s->last_eapol_matches_bssid = 0;
3772
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003773#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003774 if (wpa_s->rsne_override_eapol) {
3775 wpa_printf(MSG_DEBUG,
3776 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3777 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3778 wpabuf_head(wpa_s->rsne_override_eapol),
3779 wpabuf_len(wpa_s->rsne_override_eapol));
3780 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003781 if (wpa_s->rsnxe_override_eapol) {
3782 wpa_printf(MSG_DEBUG,
3783 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3784 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3785 wpabuf_head(wpa_s->rsnxe_override_eapol),
3786 wpabuf_len(wpa_s->rsnxe_override_eapol));
3787 }
3788#endif /* CONFIG_TESTING_OPTIONS */
3789
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003790 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003791 struct os_reltime now, age;
3792 os_get_reltime(&now);
3793 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003794 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003795 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3796 0) {
3797 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3798 "frame that was received just before "
3799 "association notification");
3800 wpa_supplicant_rx_eapol(
3801 wpa_s, wpa_s->pending_eapol_rx_src,
3802 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00003803 wpabuf_len(wpa_s->pending_eapol_rx),
3804 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003805 }
3806 wpabuf_free(wpa_s->pending_eapol_rx);
3807 wpa_s->pending_eapol_rx = NULL;
3808 }
3809
Hai Shalomfdcde762020-04-02 11:19:20 -07003810#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003811 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3812 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003813 wpa_s->current_ssid &&
3814 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003815 /* Set static WEP keys again */
3816 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3817 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003818#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003819
3820#ifdef CONFIG_IBSS_RSN
3821 if (wpa_s->current_ssid &&
3822 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3823 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3824 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3825 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003826 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003827 if (!wpa_s->ibss_rsn) {
3828 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3829 wpa_supplicant_deauthenticate(
3830 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3831 return;
3832 }
3833
3834 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3835 }
3836#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003837
3838 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003839
3840 if (data) {
3841 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3842 data->assoc_info.resp_ies_len,
3843 &data->assoc_info.wmm_params);
3844
3845 if (wpa_s->reassoc_same_bss)
3846 wmm_ac_restore_tspecs(wpa_s);
3847 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003848
Hai Shalomc3565922019-10-28 11:58:20 -07003849#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3850 bss = wpa_bss_get_bssid(wpa_s, bssid);
3851#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003852#ifdef CONFIG_FILS
3853 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003854 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3855
3856 if (fils_cache_id)
3857 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3858 }
3859#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003860
3861#ifdef CONFIG_MBO
3862 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3863#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003864
3865#ifdef CONFIG_DPP2
3866 wpa_s->dpp_pfs_fallback = 0;
3867#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003868}
3869
3870
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003871static int disconnect_reason_recoverable(u16 reason_code)
3872{
3873 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3874 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3875 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3876}
3877
3878
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003879static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003880 u16 reason_code,
3881 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003882{
3883 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003884
3885 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3886 /*
3887 * At least Host AP driver and a Prism3 card seemed to be
3888 * generating streams of disconnected events when configuring
3889 * IBSS for WPA-None. Ignore them for now.
3890 */
3891 return;
3892 }
3893
3894 bssid = wpa_s->bssid;
3895 if (is_zero_ether_addr(bssid))
3896 bssid = wpa_s->pending_bssid;
3897
3898 if (!is_zero_ether_addr(bssid) ||
3899 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3900 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3901 " reason=%d%s",
3902 MAC2STR(bssid), reason_code,
3903 locally_generated ? " locally_generated=1" : "");
3904 }
3905}
3906
3907
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003908static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3909 int locally_generated)
3910{
3911 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003912 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003913 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3914 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003915 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003916
3917 /*
3918 * It looks like connection was lost while trying to go through PSK
3919 * 4-way handshake. Filter out known disconnection cases that are caused
3920 * by something else than PSK mismatch to avoid confusing reports.
3921 */
3922
3923 if (locally_generated) {
3924 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3925 return 0;
3926 }
3927
3928 return 1;
3929}
3930
3931
Jouni Malinen2b89da82012-08-31 22:04:41 +03003932static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3933 u16 reason_code,
3934 int locally_generated)
3935{
3936 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003937 int authenticating;
3938 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003939 struct wpa_bss *fast_reconnect = NULL;
3940 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003941 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003942 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003943
3944 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3945 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3946
3947 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3948 /*
3949 * At least Host AP driver and a Prism3 card seemed to be
3950 * generating streams of disconnected events when configuring
3951 * IBSS for WPA-None. Ignore them for now.
3952 */
3953 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3954 "IBSS/WPA-None mode");
3955 return;
3956 }
3957
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003958 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3959 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3960 locally_generated)
3961 /*
3962 * Remove the inactive AP (which is probably out of range) from
3963 * the BSS list after marking disassociation. In particular
3964 * mac80211-based drivers use the
3965 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3966 * locally generated disconnection events for cases where the
3967 * AP does not reply anymore.
3968 */
3969 curr = wpa_s->current_bss;
3970
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003971 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003972 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3973 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003974 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3975 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003976 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003977#ifdef CONFIG_DPP2
3978 wpas_dpp_send_conn_status_result(wpa_s,
3979 DPP_STATUS_AUTH_FAILURE);
3980#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003981 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003982 if (!wpa_s->disconnected &&
3983 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003984 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003985 wpas_wps_searching(wpa_s) ||
3986 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003987 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003988 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003989 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003990 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003991 wpa_s->wpa_state);
3992 if (wpa_s->wpa_state == WPA_COMPLETED &&
3993 wpa_s->current_ssid &&
3994 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003995 (wpa_s->own_reconnect_req ||
3996 (!locally_generated &&
3997 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003998 /*
3999 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07004000 * us, but could allow us to get back in. This is also
4001 * triggered for cases where local reconnection request
4002 * is used to force reassociation with the same BSS.
4003 * Try to reconnect to the same BSS without a full scan
4004 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004005 */
4006 fast_reconnect = wpa_s->current_bss;
4007 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004008 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004009 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004010 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004011 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4012 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004013 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004014 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004015 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004016 "try to re-connect");
4017 wpa_s->reassociate = 0;
4018 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004019 if (!wpa_s->pno)
4020 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004021 }
4022 bssid = wpa_s->bssid;
4023 if (is_zero_ether_addr(bssid))
4024 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004025 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4026 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004027 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004028 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4029
Dmitry Shmidt04949592012-07-19 12:16:46 -07004030 if (locally_generated)
4031 wpa_s->disconnect_reason = -reason_code;
4032 else
4033 wpa_s->disconnect_reason = reason_code;
4034 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004035 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4036 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004037 wpa_clear_keys(wpa_s, wpa_s->bssid);
4038 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004039 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004040 wpa_supplicant_mark_disassoc(wpa_s);
4041
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004042 if (curr)
4043 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4044
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004045 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004046 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004047 wpa_s->current_ssid = last_ssid;
4048 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004049
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004050 if (fast_reconnect &&
4051 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4052 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4053 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4054 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004055 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004056 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004057#ifndef CONFIG_NO_SCAN_PROCESSING
4058 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4059 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4060 fast_reconnect_ssid) < 0) {
4061 /* Recover through full scan */
4062 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4063 }
4064#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004065 } else if (fast_reconnect) {
4066 /*
4067 * Could not reconnect to the same BSS due to network being
4068 * disabled. Use a new scan to match the alternative behavior
4069 * above, i.e., to continue automatic reconnection attempt in a
4070 * way that enforces disabled network rules.
4071 */
4072 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004073 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004074}
4075
4076
4077#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004078void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004079{
4080 struct wpa_supplicant *wpa_s = eloop_ctx;
4081
4082 if (!wpa_s->pending_mic_error_report)
4083 return;
4084
4085 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4086 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4087 wpa_s->pending_mic_error_report = 0;
4088}
4089#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4090
4091
4092static void
4093wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4094 union wpa_event_data *data)
4095{
4096 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004097 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004098
4099 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4100 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004101 os_get_reltime(&t);
4102 if ((wpa_s->last_michael_mic_error.sec &&
4103 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004104 wpa_s->pending_mic_error_report) {
4105 if (wpa_s->pending_mic_error_report) {
4106 /*
4107 * Send the pending MIC error report immediately since
4108 * we are going to start countermeasures and AP better
4109 * do the same.
4110 */
4111 wpa_sm_key_request(wpa_s->wpa, 1,
4112 wpa_s->pending_mic_error_pairwise);
4113 }
4114
4115 /* Send the new MIC error report immediately since we are going
4116 * to start countermeasures and AP better do the same.
4117 */
4118 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4119
4120 /* initialize countermeasures */
4121 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004122
Hai Shalom60840252021-02-19 19:02:11 -08004123 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004124
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004125 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4126
4127 /*
4128 * Need to wait for completion of request frame. We do not get
4129 * any callback for the message completion, so just wait a
4130 * short while and hope for the best. */
4131 os_sleep(0, 10000);
4132
4133 wpa_drv_set_countermeasures(wpa_s, 1);
4134 wpa_supplicant_deauthenticate(wpa_s,
4135 WLAN_REASON_MICHAEL_MIC_FAILURE);
4136 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4137 wpa_s, NULL);
4138 eloop_register_timeout(60, 0,
4139 wpa_supplicant_stop_countermeasures,
4140 wpa_s, NULL);
4141 /* TODO: mark the AP rejected for 60 second. STA is
4142 * allowed to associate with another AP.. */
4143 } else {
4144#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4145 if (wpa_s->mic_errors_seen) {
4146 /*
4147 * Reduce the effectiveness of Michael MIC error
4148 * reports as a means for attacking against TKIP if
4149 * more than one MIC failure is noticed with the same
4150 * PTK. We delay the transmission of the reports by a
4151 * random time between 0 and 60 seconds in order to
4152 * force the attacker wait 60 seconds before getting
4153 * the information on whether a frame resulted in a MIC
4154 * failure.
4155 */
4156 u8 rval[4];
4157 int sec;
4158
4159 if (os_get_random(rval, sizeof(rval)) < 0)
4160 sec = os_random() % 60;
4161 else
4162 sec = WPA_GET_BE32(rval) % 60;
4163 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4164 "report %d seconds", sec);
4165 wpa_s->pending_mic_error_report = 1;
4166 wpa_s->pending_mic_error_pairwise = pairwise;
4167 eloop_cancel_timeout(
4168 wpa_supplicant_delayed_mic_error_report,
4169 wpa_s, NULL);
4170 eloop_register_timeout(
4171 sec, os_random() % 1000000,
4172 wpa_supplicant_delayed_mic_error_report,
4173 wpa_s, NULL);
4174 } else {
4175 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4176 }
4177#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4178 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4179#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4180 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004181 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004182 wpa_s->mic_errors_seen++;
4183}
4184
4185
4186#ifdef CONFIG_TERMINATE_ONLASTIF
4187static int any_interfaces(struct wpa_supplicant *head)
4188{
4189 struct wpa_supplicant *wpa_s;
4190
4191 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4192 if (!wpa_s->interface_removed)
4193 return 1;
4194 return 0;
4195}
4196#endif /* CONFIG_TERMINATE_ONLASTIF */
4197
4198
4199static void
4200wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4201 union wpa_event_data *data)
4202{
4203 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4204 return;
4205
4206 switch (data->interface_status.ievent) {
4207 case EVENT_INTERFACE_ADDED:
4208 if (!wpa_s->interface_removed)
4209 break;
4210 wpa_s->interface_removed = 0;
4211 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4212 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4213 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4214 "driver after interface was added");
4215 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004216
4217#ifdef CONFIG_P2P
4218 if (!wpa_s->global->p2p &&
4219 !wpa_s->global->p2p_disabled &&
4220 !wpa_s->conf->p2p_disabled &&
4221 (wpa_s->drv_flags &
4222 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4223 wpas_p2p_add_p2pdev_interface(
4224 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4225 wpa_printf(MSG_INFO,
4226 "P2P: Failed to enable P2P Device interface");
4227 /* Try to continue without. P2P will be disabled. */
4228 }
4229#endif /* CONFIG_P2P */
4230
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004231 break;
4232 case EVENT_INTERFACE_REMOVED:
4233 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4234 wpa_s->interface_removed = 1;
4235 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004236 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004237 l2_packet_deinit(wpa_s->l2);
4238 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004239
4240#ifdef CONFIG_P2P
4241 if (wpa_s->global->p2p &&
4242 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4243 (wpa_s->drv_flags &
4244 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4245 wpa_dbg(wpa_s, MSG_DEBUG,
4246 "Removing P2P Device interface");
4247 wpa_supplicant_remove_iface(
4248 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4249 0);
4250 wpa_s->global->p2p_init_wpa_s = NULL;
4251 }
4252#endif /* CONFIG_P2P */
4253
Dmitry Shmidte4663042016-04-04 10:07:49 -07004254#ifdef CONFIG_MATCH_IFACE
4255 if (wpa_s->matched) {
4256 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4257 break;
4258 }
4259#endif /* CONFIG_MATCH_IFACE */
4260
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004261#ifdef CONFIG_TERMINATE_ONLASTIF
4262 /* check if last interface */
4263 if (!any_interfaces(wpa_s->global->ifaces))
4264 eloop_terminate();
4265#endif /* CONFIG_TERMINATE_ONLASTIF */
4266 break;
4267 }
4268}
4269
4270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004271#ifdef CONFIG_TDLS
4272static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4273 union wpa_event_data *data)
4274{
4275 if (data == NULL)
4276 return;
4277 switch (data->tdls.oper) {
4278 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004279 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4280 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4281 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4282 else
4283 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004284 break;
4285 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004286 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4287 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4288 data->tdls.reason_code);
4289 else
4290 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4291 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004292 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004293 case TDLS_REQUEST_DISCOVER:
4294 wpa_tdls_send_discovery_request(wpa_s->wpa,
4295 data->tdls.peer);
4296 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004297 }
4298}
4299#endif /* CONFIG_TDLS */
4300
4301
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004302#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004303static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4304 union wpa_event_data *data)
4305{
4306 if (data == NULL)
4307 return;
4308 switch (data->wnm.oper) {
4309 case WNM_OPER_SLEEP:
4310 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4311 "(action=%d, intval=%d)",
4312 data->wnm.sleep_action, data->wnm.sleep_intval);
4313 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004314 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004315 break;
4316 }
4317}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004318#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004319
4320
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004321#ifdef CONFIG_IEEE80211R
4322static void
4323wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4324 union wpa_event_data *data)
4325{
4326 if (data == NULL)
4327 return;
4328
4329 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4330 data->ft_ies.ies_len,
4331 data->ft_ies.ft_action,
4332 data->ft_ies.target_ap,
4333 data->ft_ies.ric_ies,
4334 data->ft_ies.ric_ies_len) < 0) {
4335 /* TODO: prevent MLME/driver from trying to associate? */
4336 }
4337}
4338#endif /* CONFIG_IEEE80211R */
4339
4340
4341#ifdef CONFIG_IBSS_RSN
4342static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4343 union wpa_event_data *data)
4344{
4345 struct wpa_ssid *ssid;
4346 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4347 return;
4348 if (data == NULL)
4349 return;
4350 ssid = wpa_s->current_ssid;
4351 if (ssid == NULL)
4352 return;
4353 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4354 return;
4355
4356 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4357}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004358
4359
4360static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4361 union wpa_event_data *data)
4362{
4363 struct wpa_ssid *ssid = wpa_s->current_ssid;
4364
4365 if (ssid == NULL)
4366 return;
4367
4368 /* check if the ssid is correctly configured as IBSS/RSN */
4369 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4370 return;
4371
4372 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4373 data->rx_mgmt.frame_len);
4374}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004375#endif /* CONFIG_IBSS_RSN */
4376
4377
4378#ifdef CONFIG_IEEE80211R
4379static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4380 size_t len)
4381{
4382 const u8 *sta_addr, *target_ap_addr;
4383 u16 status;
4384
4385 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4386 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4387 return; /* only SME case supported for now */
4388 if (len < 1 + 2 * ETH_ALEN + 2)
4389 return;
4390 if (data[0] != 2)
4391 return; /* Only FT Action Response is supported for now */
4392 sta_addr = data + 1;
4393 target_ap_addr = data + 1 + ETH_ALEN;
4394 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4395 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4396 MACSTR " TargetAP " MACSTR " status %u",
4397 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4398
4399 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4400 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4401 " in FT Action Response", MAC2STR(sta_addr));
4402 return;
4403 }
4404
4405 if (status) {
4406 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4407 "failure (status code %d)", status);
4408 /* TODO: report error to FT code(?) */
4409 return;
4410 }
4411
4412 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4413 len - (1 + 2 * ETH_ALEN + 2), 1,
4414 target_ap_addr, NULL, 0) < 0)
4415 return;
4416
4417#ifdef CONFIG_SME
4418 {
4419 struct wpa_bss *bss;
4420 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4421 if (bss)
4422 wpa_s->sme.freq = bss->freq;
4423 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4424 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4425 WLAN_AUTH_FT);
4426 }
4427#endif /* CONFIG_SME */
4428}
4429#endif /* CONFIG_IEEE80211R */
4430
4431
4432static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4433 struct unprot_deauth *e)
4434{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004435 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4436 "dropped: " MACSTR " -> " MACSTR
4437 " (reason code %u)",
4438 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4439 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004440}
4441
4442
4443static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4444 struct unprot_disassoc *e)
4445{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004446 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4447 "dropped: " MACSTR " -> " MACSTR
4448 " (reason code %u)",
4449 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4450 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004451}
4452
4453
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004454static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4455 u16 reason_code, int locally_generated,
4456 const u8 *ie, size_t ie_len, int deauth)
4457{
4458#ifdef CONFIG_AP
4459 if (wpa_s->ap_iface && addr) {
4460 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4461 return;
4462 }
4463
4464 if (wpa_s->ap_iface) {
4465 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4466 return;
4467 }
4468#endif /* CONFIG_AP */
4469
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004470 if (!locally_generated)
4471 wpa_s->own_disconnect_req = 0;
4472
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004473 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4474
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004475 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4476 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4477 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4478 eapol_sm_failed(wpa_s->eapol))) &&
4479 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004480 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004481
4482#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004483 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004484 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4485 locally_generated) > 0) {
4486 /*
4487 * The interface was removed, so cannot continue
4488 * processing any additional operations after this.
4489 */
4490 return;
4491 }
4492 }
4493#endif /* CONFIG_P2P */
4494
4495 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4496 locally_generated);
4497}
4498
4499
4500static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4501 struct disassoc_info *info)
4502{
4503 u16 reason_code = 0;
4504 int locally_generated = 0;
4505 const u8 *addr = NULL;
4506 const u8 *ie = NULL;
4507 size_t ie_len = 0;
4508
4509 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4510
4511 if (info) {
4512 addr = info->addr;
4513 ie = info->ie;
4514 ie_len = info->ie_len;
4515 reason_code = info->reason_code;
4516 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004517 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4518 reason2str(reason_code),
4519 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004520 if (addr)
4521 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4522 MAC2STR(addr));
4523 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4524 ie, ie_len);
4525 }
4526
4527#ifdef CONFIG_AP
4528 if (wpa_s->ap_iface && info && info->addr) {
4529 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4530 return;
4531 }
4532
4533 if (wpa_s->ap_iface) {
4534 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4535 return;
4536 }
4537#endif /* CONFIG_AP */
4538
4539#ifdef CONFIG_P2P
4540 if (info) {
4541 wpas_p2p_disassoc_notif(
4542 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4543 locally_generated);
4544 }
4545#endif /* CONFIG_P2P */
4546
4547 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4548 sme_event_disassoc(wpa_s, info);
4549
4550 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4551 ie, ie_len, 0);
4552}
4553
4554
4555static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4556 struct deauth_info *info)
4557{
4558 u16 reason_code = 0;
4559 int locally_generated = 0;
4560 const u8 *addr = NULL;
4561 const u8 *ie = NULL;
4562 size_t ie_len = 0;
4563
4564 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4565
4566 if (info) {
4567 addr = info->addr;
4568 ie = info->ie;
4569 ie_len = info->ie_len;
4570 reason_code = info->reason_code;
4571 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004572 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4573 reason_code, reason2str(reason_code),
4574 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004575 if (addr) {
4576 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4577 MAC2STR(addr));
4578 }
4579 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4580 ie, ie_len);
4581 }
4582
4583 wpa_reset_ft_completed(wpa_s->wpa);
4584
4585 wpas_event_disconnect(wpa_s, addr, reason_code,
4586 locally_generated, ie, ie_len, 1);
4587}
4588
4589
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004590static const char * reg_init_str(enum reg_change_initiator init)
4591{
4592 switch (init) {
4593 case REGDOM_SET_BY_CORE:
4594 return "CORE";
4595 case REGDOM_SET_BY_USER:
4596 return "USER";
4597 case REGDOM_SET_BY_DRIVER:
4598 return "DRIVER";
4599 case REGDOM_SET_BY_COUNTRY_IE:
4600 return "COUNTRY_IE";
4601 case REGDOM_BEACON_HINT:
4602 return "BEACON_HINT";
4603 }
4604 return "?";
4605}
4606
4607
4608static const char * reg_type_str(enum reg_type type)
4609{
4610 switch (type) {
4611 case REGDOM_TYPE_UNKNOWN:
4612 return "UNKNOWN";
4613 case REGDOM_TYPE_COUNTRY:
4614 return "COUNTRY";
4615 case REGDOM_TYPE_WORLD:
4616 return "WORLD";
4617 case REGDOM_TYPE_CUSTOM_WORLD:
4618 return "CUSTOM_WORLD";
4619 case REGDOM_TYPE_INTERSECTION:
4620 return "INTERSECTION";
4621 }
4622 return "?";
4623}
4624
4625
Hai Shalom74f70d42019-02-11 14:42:39 -08004626void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4627 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004628{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004629 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004630 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004631
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004632 /*
4633 * To allow backwards compatibility with higher level layers that
4634 * assumed the REGDOM_CHANGE event is sent over the initially added
4635 * interface. Find the highest parent of this interface and use it to
4636 * send the event.
4637 */
4638 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4639 ;
4640
Hai Shalom74f70d42019-02-11 14:42:39 -08004641 if (info) {
4642 wpa_msg(ifs, MSG_INFO,
4643 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4644 reg_init_str(info->initiator), reg_type_str(info->type),
4645 info->alpha2[0] ? " alpha2=" : "",
4646 info->alpha2[0] ? info->alpha2 : "");
4647 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004648
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004649 if (wpa_s->drv_priv == NULL)
4650 return; /* Ignore event during drv initialization */
4651
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004652 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4653 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004654 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4655 ifs->ifname);
4656 free_hw_features(ifs);
4657 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004658 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004659
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004660 /* Restart PNO/sched_scan with updated channel list */
4661 if (ifs->pno) {
4662 wpas_stop_pno(ifs);
4663 wpas_start_pno(ifs);
4664 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4665 wpa_dbg(ifs, MSG_DEBUG,
4666 "Channel list changed - restart sched_scan");
4667 wpas_scan_restart_sched_scan(ifs);
4668 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004669 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004670
4671 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004672}
4673
4674
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004675static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004676 const u8 *frame, size_t len, int freq,
4677 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004678{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004679 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004680 const u8 *payload;
4681 size_t plen;
4682 u8 category;
4683
4684 if (len < IEEE80211_HDRLEN + 2)
4685 return;
4686
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004687 mgmt = (const struct ieee80211_mgmt *) frame;
4688 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004689 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004690 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004691
4692 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4693 " Category=%u DataLen=%d freq=%d MHz",
4694 MAC2STR(mgmt->sa), category, (int) plen, freq);
4695
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004696 if (category == WLAN_ACTION_WMM) {
4697 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4698 return;
4699 }
4700
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004701#ifdef CONFIG_IEEE80211R
4702 if (category == WLAN_ACTION_FT) {
4703 ft_rx_action(wpa_s, payload, plen);
4704 return;
4705 }
4706#endif /* CONFIG_IEEE80211R */
4707
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004708#ifdef CONFIG_SME
4709 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004710 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004711 return;
4712 }
4713#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004714
4715#ifdef CONFIG_WNM
4716 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4717 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4718 return;
4719 }
4720#endif /* CONFIG_WNM */
4721
4722#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004723 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4724 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004725 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004726 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004727 payload, plen, freq) == 0)
4728 return;
4729#endif /* CONFIG_GAS */
4730
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004731#ifdef CONFIG_GAS_SERVER
4732 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4733 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4734 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4735 mgmt->u.action.category,
4736 payload, plen, freq) == 0)
4737 return;
4738#endif /* CONFIG_GAS_SERVER */
4739
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004740#ifdef CONFIG_TDLS
4741 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4742 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4743 wpa_dbg(wpa_s, MSG_DEBUG,
4744 "TDLS: Received Discovery Response from " MACSTR,
4745 MAC2STR(mgmt->sa));
4746 return;
4747 }
4748#endif /* CONFIG_TDLS */
4749
4750#ifdef CONFIG_INTERWORKING
4751 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4752 payload[0] == QOS_QOS_MAP_CONFIG) {
4753 const u8 *pos = payload + 1;
4754 size_t qlen = plen - 1;
4755 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4756 MACSTR, MAC2STR(mgmt->sa));
4757 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4758 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4759 pos[1] <= qlen - 2 && pos[1] >= 16)
4760 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4761 return;
4762 }
4763#endif /* CONFIG_INTERWORKING */
4764
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004765 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004766 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4767 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004768 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004769 payload + 1,
4770 plen - 1);
4771 return;
4772 }
4773
4774 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004775 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4776 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4777 return;
4778 }
4779
4780 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4781 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4782 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4783 payload + 1, plen - 1,
4784 rssi);
4785 return;
4786 }
4787
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004788#ifdef CONFIG_FST
4789 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4790 fst_rx_action(wpa_s->fst, mgmt, len);
4791 return;
4792 }
4793#endif /* CONFIG_FST */
4794
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004795#ifdef CONFIG_DPP
4796 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4797 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4798 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4799 payload[4] == DPP_OUI_TYPE) {
4800 payload++;
4801 plen--;
4802 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4803 return;
4804 }
4805#endif /* CONFIG_DPP */
4806
Hai Shalom899fcc72020-10-19 14:38:18 -07004807 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004808 payload[0] == ROBUST_AV_SCS_RESP) {
4809 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4810 payload + 1, plen - 1);
4811 return;
4812 }
4813
4814 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004815 payload[0] == ROBUST_AV_MSCS_RESP) {
4816 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4817 payload + 1, plen - 1);
4818 return;
4819 }
4820
Hai Shalomc1a21442022-02-04 13:43:00 -08004821 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4822 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4823 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4824 payload + 4, plen - 4);
4825 return;
4826 }
4827
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004828 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4829 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004830 if (wpa_s->ifmsh)
4831 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004832}
4833
4834
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004835static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4836 union wpa_event_data *event)
4837{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004838 struct wpa_freq_range_list *list;
4839 char *str = NULL;
4840
4841 list = &event->freq_range;
4842
4843 if (list->num)
4844 str = freq_range_list_str(list);
4845 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4846 str ? str : "");
4847
4848#ifdef CONFIG_P2P
4849 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4850 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4851 __func__);
4852 } else {
4853 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004854
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004855 /*
4856 * The update channel flow will also take care of moving a GO
4857 * from the unsafe frequency if needed.
4858 */
4859 wpas_p2p_update_channel_list(wpa_s,
4860 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004861 }
4862#endif /* CONFIG_P2P */
4863
4864 os_free(str);
4865}
4866
4867
Roshan Pius3a1667e2018-07-03 15:17:14 -07004868static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004869{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004870 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4871 wpa_supplicant_cancel_auth_timeout(wpa_s);
4872 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004873 eapol_sm_notify_portValid(wpa_s->eapol, true);
4874 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004875 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004876 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004877}
4878
4879
4880static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4881 int freq)
4882{
4883 size_t i;
4884 int j;
4885
4886 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4887 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4888
4889 for (j = 0; j < mode->num_channels; j++) {
4890 const struct hostapd_channel_data *chan;
4891
4892 chan = &mode->channels[j];
4893 if (chan->freq == freq)
4894 return chan->dfs_cac_ms;
4895 }
4896 }
4897
4898 return 0;
4899}
4900
4901
4902static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4903 struct dfs_event *radar)
4904{
4905#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004906 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004907 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4908 } else
4909#endif /* NEED_AP_MLME && CONFIG_AP */
4910 {
4911 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4912
4913 cac_time /= 1000; /* convert from ms to sec */
4914 if (!cac_time)
4915 cac_time = 10 * 60; /* max timeout: 10 minutes */
4916
4917 /* Restart auth timeout: CAC time added to initial timeout */
4918 wpas_auth_timeout_restart(wpa_s, cac_time);
4919 }
4920}
4921
4922
4923static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4924 struct dfs_event *radar)
4925{
4926#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004927 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004928 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4929 } else
4930#endif /* NEED_AP_MLME && CONFIG_AP */
4931 {
4932 /* Restart auth timeout with original value after CAC is
4933 * finished */
4934 wpas_auth_timeout_restart(wpa_s, 0);
4935 }
4936}
4937
4938
4939static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4940 struct dfs_event *radar)
4941{
4942#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004943 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004944 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4945 } else
4946#endif /* NEED_AP_MLME && CONFIG_AP */
4947 {
4948 /* Restart auth timeout with original value after CAC is
4949 * aborted */
4950 wpas_auth_timeout_restart(wpa_s, 0);
4951 }
4952}
4953
4954
4955static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4956 union wpa_event_data *data)
4957{
4958 wpa_dbg(wpa_s, MSG_DEBUG,
4959 "Connection authorized by device, previous state %d",
4960 wpa_s->wpa_state);
4961
4962 wpa_supplicant_event_port_authorized(wpa_s);
4963
Hai Shalomc1a21442022-02-04 13:43:00 -08004964 wpa_s->last_eapol_matches_bssid = 1;
4965
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004966 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4967 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004968 data->assoc_info.ptk_kck_len,
4969 data->assoc_info.ptk_kek,
4970 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004971#ifdef CONFIG_FILS
4972 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4973 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4974 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4975
4976 /* Update ERP next sequence number */
4977 eapol_sm_update_erp_next_seq_num(
4978 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4979
4980 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4981 /* Add the new PMK and PMKID to the PMKSA cache */
4982 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4983 data->assoc_info.fils_pmk,
4984 data->assoc_info.fils_pmk_len,
4985 data->assoc_info.fils_pmkid,
4986 wpa_s->bssid, fils_cache_id);
4987 } else if (data->assoc_info.fils_pmkid) {
4988 /* Update the current PMKSA used for this connection */
4989 pmksa_cache_set_current(wpa_s->wpa,
4990 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004991 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004992 }
4993 }
4994#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004995}
4996
4997
Hai Shalom60840252021-02-19 19:02:11 -08004998static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4999{
5000 switch (code) {
5001 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5002 return "";
5003 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5004 return "no_bss_found";
5005 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5006 return "auth_tx_fail";
5007 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5008 return "auth_no_ack_received";
5009 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5010 return "auth_no_resp_received";
5011 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5012 return "assoc_req_tx_fail";
5013 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5014 return "assoc_no_ack_received";
5015 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5016 return "assoc_no_resp_received";
5017 default:
5018 return "unknown_reason";
5019 }
5020}
5021
5022
Roshan Pius3a1667e2018-07-03 15:17:14 -07005023static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5024 union wpa_event_data *data)
5025{
5026 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005027#ifdef CONFIG_MBO
5028 struct wpa_bss *reject_bss;
5029#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005030
5031 if (!bssid || is_zero_ether_addr(bssid))
5032 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005033#ifdef CONFIG_MBO
5034 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5035 reject_bss = wpa_s->current_bss;
5036 else
5037 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5038#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005039
5040 if (data->assoc_reject.bssid)
5041 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005042 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005043 MAC2STR(data->assoc_reject.bssid),
5044 data->assoc_reject.status_code,
5045 data->assoc_reject.timed_out ? " timeout" : "",
5046 data->assoc_reject.timeout_reason ? "=" : "",
5047 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005048 data->assoc_reject.timeout_reason : "",
5049 data->assoc_reject.reason_code !=
5050 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5051 " qca_driver_reason=" : "",
5052 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005053 else
5054 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005055 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005056 data->assoc_reject.status_code,
5057 data->assoc_reject.timed_out ? " timeout" : "",
5058 data->assoc_reject.timeout_reason ? "=" : "",
5059 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005060 data->assoc_reject.timeout_reason : "",
5061 data->assoc_reject.reason_code !=
5062 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5063 " qca_driver_reason=" : "",
5064 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005065 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005066 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5067 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005068
5069#ifdef CONFIG_OWE
5070 if (data->assoc_reject.status_code ==
5071 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5072 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5073 wpa_s->current_ssid &&
5074 wpa_s->current_ssid->owe_group == 0 &&
5075 wpa_s->last_owe_group != 21) {
5076 struct wpa_ssid *ssid = wpa_s->current_ssid;
5077 struct wpa_bss *bss = wpa_s->current_bss;
5078
5079 if (!bss) {
5080 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5081 if (!bss) {
5082 wpas_connection_failed(wpa_s, bssid);
5083 wpa_supplicant_mark_disassoc(wpa_s);
5084 return;
5085 }
5086 }
5087 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5088 wpas_connect_work_done(wpa_s);
5089 wpa_supplicant_mark_disassoc(wpa_s);
5090 wpa_supplicant_connect(wpa_s, bss, ssid);
5091 return;
5092 }
5093#endif /* CONFIG_OWE */
5094
Hai Shalomfdcde762020-04-02 11:19:20 -07005095#ifdef CONFIG_DPP2
5096 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5097 * the status code defined in the DPP R2 tech spec.
5098 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5099 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005100 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005101 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5102 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5103 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005104 wpa_s->current_ssid->dpp_pfs == 0 &&
5105 (data->assoc_reject.status_code ==
5106 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5107 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5108 struct wpa_ssid *ssid = wpa_s->current_ssid;
5109 struct wpa_bss *bss = wpa_s->current_bss;
5110
5111 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5112 if (!bss)
5113 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5114 if (!bss || wpa_s->dpp_pfs_fallback) {
5115 wpa_printf(MSG_DEBUG,
5116 "DPP: Updated PFS policy for next try");
5117 wpas_connection_failed(wpa_s, bssid);
5118 wpa_supplicant_mark_disassoc(wpa_s);
5119 return;
5120 }
5121 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5122 wpa_s->dpp_pfs_fallback = 1;
5123 wpas_connect_work_done(wpa_s);
5124 wpa_supplicant_mark_disassoc(wpa_s);
5125 wpa_supplicant_connect(wpa_s, bss, ssid);
5126 return;
5127 }
5128#endif /* CONFIG_DPP2 */
5129
Hai Shalom74f70d42019-02-11 14:42:39 -08005130#ifdef CONFIG_MBO
5131 if (data->assoc_reject.status_code ==
5132 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005133 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005134 const u8 *rssi_rej;
5135
5136 rssi_rej = mbo_get_attr_from_ies(
5137 data->assoc_reject.resp_ies,
5138 data->assoc_reject.resp_ies_len,
5139 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5140 if (rssi_rej && rssi_rej[1] == 2) {
5141 wpa_printf(MSG_DEBUG,
5142 "OCE: RSSI-based association rejection from "
5143 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005144 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005145 rssi_rej[2], rssi_rej[3]);
5146 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005147 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005148 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005149 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005150 }
5151 }
5152#endif /* CONFIG_MBO */
5153
Roshan Pius3a1667e2018-07-03 15:17:14 -07005154 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5155 sme_event_assoc_reject(wpa_s, data);
5156 return;
5157 }
5158
5159 /* Driver-based SME cases */
5160
5161#ifdef CONFIG_SAE
5162 if (wpa_s->current_ssid &&
5163 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5164 !data->assoc_reject.timed_out) {
5165 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5166 wpa_sm_aborted_cached(wpa_s->wpa);
5167 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5168 }
5169#endif /* CONFIG_SAE */
5170
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005171#ifdef CONFIG_DPP
5172 if (wpa_s->current_ssid &&
5173 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5174 !data->assoc_reject.timed_out) {
5175 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5176 wpa_sm_aborted_cached(wpa_s->wpa);
5177 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5178 }
5179#endif /* CONFIG_DPP */
5180
Roshan Pius3a1667e2018-07-03 15:17:14 -07005181#ifdef CONFIG_FILS
5182 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005183 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005184 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005185 eapol_sm_update_erp_next_seq_num(
5186 wpa_s->eapol,
5187 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005188 fils_connection_failure(wpa_s);
5189 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005190#endif /* CONFIG_FILS */
5191
5192 wpas_connection_failed(wpa_s, bssid);
5193 wpa_supplicant_mark_disassoc(wpa_s);
5194}
5195
5196
Hai Shalomfdcde762020-04-02 11:19:20 -07005197static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5198 struct unprot_beacon *data)
5199{
5200 struct wpabuf *buf;
5201 int res;
5202
5203 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5204 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5205 return;
5206 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5207 MAC2STR(data->sa));
5208
5209 buf = wpabuf_alloc(4);
5210 if (!buf)
5211 return;
5212
5213 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5214 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5215 wpabuf_put_u8(buf, 1); /* Dialog Token */
5216 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5217
5218 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5219 wpa_s->own_addr, wpa_s->bssid,
5220 wpabuf_head(buf), wpabuf_len(buf), 0);
5221 if (res < 0)
5222 wpa_printf(MSG_DEBUG,
5223 "Failed to send WNM-Notification Request frame");
5224
5225 wpabuf_free(buf);
5226}
5227
5228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005229void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5230 union wpa_event_data *data)
5231{
5232 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005233 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005234 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005235#ifndef CONFIG_NO_STDOUT_DEBUG
5236 int level = MSG_DEBUG;
5237#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005238
5239 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5240 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005241 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005242 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005243 event != EVENT_SCHED_SCAN_STOPPED) {
5244 wpa_dbg(wpa_s, MSG_DEBUG,
5245 "Ignore event %s (%d) while interface is disabled",
5246 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005247 return;
5248 }
5249
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005250#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005251 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005252 const struct ieee80211_hdr *hdr;
5253 u16 fc;
5254 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5255 fc = le_to_host16(hdr->frame_control);
5256 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5257 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5258 level = MSG_EXCESSIVE;
5259 }
5260
5261 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5262 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005263#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005264
5265 switch (event) {
5266 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005267#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005268 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5269 data->auth.ies_len))
5270 wpa_printf(MSG_DEBUG,
5271 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005272#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005273 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005274 wpa_s->auth_status_code = data->auth.status_code;
5275 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005276 break;
5277 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005278#ifdef CONFIG_TESTING_OPTIONS
5279 if (wpa_s->ignore_auth_resp) {
5280 wpa_printf(MSG_INFO,
5281 "EVENT_ASSOC - ignore_auth_resp active!");
5282 break;
5283 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005284 if (wpa_s->testing_resend_assoc) {
5285 wpa_printf(MSG_INFO,
5286 "EVENT_DEAUTH - testing_resend_assoc");
5287 break;
5288 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005289#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305290 if (wpa_s->disconnected) {
5291 wpa_printf(MSG_INFO,
5292 "Ignore unexpected EVENT_ASSOC in disconnected state");
5293 break;
5294 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005295 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005296 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005297 if (data &&
5298 (data->assoc_info.authorized ||
5299 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5300 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005301 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005302 if (data) {
5303 wpa_msg(wpa_s, MSG_INFO,
5304 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5305 data->assoc_info.subnet_status);
5306 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005307 break;
5308 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005309 wpas_event_disassoc(wpa_s,
5310 data ? &data->disassoc_info : NULL);
5311 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005312 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005313#ifdef CONFIG_TESTING_OPTIONS
5314 if (wpa_s->ignore_auth_resp) {
5315 wpa_printf(MSG_INFO,
5316 "EVENT_DEAUTH - ignore_auth_resp active!");
5317 break;
5318 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005319 if (wpa_s->testing_resend_assoc) {
5320 wpa_printf(MSG_INFO,
5321 "EVENT_DEAUTH - testing_resend_assoc");
5322 break;
5323 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005324#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005325 wpas_event_deauth(wpa_s,
5326 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005327 break;
5328 case EVENT_MICHAEL_MIC_FAILURE:
5329 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5330 break;
5331#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005332 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005333 if (wpa_s->own_scan_requested ||
5334 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005335 struct os_reltime diff;
5336
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005337 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005338 os_reltime_sub(&wpa_s->scan_start_time,
5339 &wpa_s->scan_trigger_time, &diff);
5340 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5341 diff.sec, diff.usec);
5342 wpa_s->own_scan_requested = 0;
5343 wpa_s->own_scan_running = 1;
5344 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5345 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005346 wpa_msg_ctrl(wpa_s, MSG_INFO,
5347 WPA_EVENT_SCAN_STARTED "id=%u",
5348 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005349 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005350 wpa_msg_ctrl(wpa_s, MSG_INFO,
5351 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005352 }
5353 } else {
5354 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005355 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005356 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005357 }
5358 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005359 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005360 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5361 wpa_s->scan_res_handler = NULL;
5362 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005363 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005364 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5365 break;
5366 }
5367
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005368 if (!(data && data->scan_info.external_scan) &&
5369 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005370 struct os_reltime now, diff;
5371 os_get_reltime(&now);
5372 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5373 wpa_s->scan_start_time.sec = 0;
5374 wpa_s->scan_start_time.usec = 0;
5375 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5376 diff.sec, diff.usec);
5377 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005378 if (wpa_supplicant_event_scan_results(wpa_s, data))
5379 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005380 if (!(data && data->scan_info.external_scan))
5381 wpa_s->own_scan_running = 0;
5382 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005383 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005384 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005385 break;
5386#endif /* CONFIG_NO_SCAN_PROCESSING */
5387 case EVENT_ASSOCINFO:
5388 wpa_supplicant_event_associnfo(wpa_s, data);
5389 break;
5390 case EVENT_INTERFACE_STATUS:
5391 wpa_supplicant_event_interface_status(wpa_s, data);
5392 break;
5393 case EVENT_PMKID_CANDIDATE:
5394 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5395 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005396#ifdef CONFIG_TDLS
5397 case EVENT_TDLS:
5398 wpa_supplicant_event_tdls(wpa_s, data);
5399 break;
5400#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005401#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005402 case EVENT_WNM:
5403 wpa_supplicant_event_wnm(wpa_s, data);
5404 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005405#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005406#ifdef CONFIG_IEEE80211R
5407 case EVENT_FT_RESPONSE:
5408 wpa_supplicant_event_ft_response(wpa_s, data);
5409 break;
5410#endif /* CONFIG_IEEE80211R */
5411#ifdef CONFIG_IBSS_RSN
5412 case EVENT_IBSS_RSN_START:
5413 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5414 break;
5415#endif /* CONFIG_IBSS_RSN */
5416 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005417 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005418 break;
5419 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005420 /* It is possible to get this event from earlier connection */
5421 if (wpa_s->current_ssid &&
5422 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5423 wpa_dbg(wpa_s, MSG_DEBUG,
5424 "Ignore AUTH_TIMED_OUT in mesh configuration");
5425 break;
5426 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005427 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5428 sme_event_auth_timed_out(wpa_s, data);
5429 break;
5430 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005431 /* It is possible to get this event from earlier connection */
5432 if (wpa_s->current_ssid &&
5433 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5434 wpa_dbg(wpa_s, MSG_DEBUG,
5435 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5436 break;
5437 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005438 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5439 sme_event_assoc_timed_out(wpa_s, data);
5440 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005441 case EVENT_TX_STATUS:
5442 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5443 " type=%d stype=%d",
5444 MAC2STR(data->tx_status.dst),
5445 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005446#ifdef CONFIG_PASN
5447 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5448 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5449 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5450 data->tx_status.data_len,
5451 data->tx_status.ack) == 0)
5452 break;
5453#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005454#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005455 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005456#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005457 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5458 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005459 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005460 wpa_s, data->tx_status.dst,
5461 data->tx_status.data,
5462 data->tx_status.data_len,
5463 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005464 OFFCHANNEL_SEND_ACTION_SUCCESS :
5465 OFFCHANNEL_SEND_ACTION_NO_ACK);
5466#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005467 break;
5468 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005469#endif /* CONFIG_AP */
5470#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005471 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005472 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005473 /*
5474 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005475 * interface in GO mode, or via standalone AP interface.
5476 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5477 * except when the primary interface is used as a GO interface
5478 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005479 */
5480 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5481 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005482 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005483 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005484 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005485 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005486 data->tx_status.data,
5487 data->tx_status.data_len,
5488 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005489 OFFCHANNEL_SEND_ACTION_SUCCESS :
5490 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005491 break;
5492 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005493#endif /* CONFIG_OFFCHANNEL */
5494#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005495 switch (data->tx_status.type) {
5496 case WLAN_FC_TYPE_MGMT:
5497 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5498 data->tx_status.data_len,
5499 data->tx_status.stype,
5500 data->tx_status.ack);
5501 break;
5502 case WLAN_FC_TYPE_DATA:
5503 ap_tx_status(wpa_s, data->tx_status.dst,
5504 data->tx_status.data,
5505 data->tx_status.data_len,
5506 data->tx_status.ack);
5507 break;
5508 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005509#endif /* CONFIG_AP */
5510 break;
5511#ifdef CONFIG_AP
5512 case EVENT_EAPOL_TX_STATUS:
5513 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5514 data->eapol_tx_status.data,
5515 data->eapol_tx_status.data_len,
5516 data->eapol_tx_status.ack);
5517 break;
5518 case EVENT_DRIVER_CLIENT_POLL_OK:
5519 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005520 break;
5521 case EVENT_RX_FROM_UNKNOWN:
5522 if (wpa_s->ap_iface == NULL)
5523 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005524 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5525 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005526 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005527#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005528
Sunil Ravi89eba102022-09-13 21:04:37 -07005529 case EVENT_LINK_CH_SWITCH_STARTED:
5530 case EVENT_LINK_CH_SWITCH:
5531 if (!data || !wpa_s->current_ssid ||
5532 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
5533 break;
5534
5535 wpa_msg(wpa_s, MSG_INFO,
5536 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5537 event == EVENT_LINK_CH_SWITCH ?
5538 WPA_EVENT_LINK_CHANNEL_SWITCH :
5539 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
5540 data->ch_switch.freq,
5541 data->ch_switch.link_id,
5542 data->ch_switch.ht_enabled,
5543 data->ch_switch.ch_offset,
5544 channel_width_to_string(data->ch_switch.ch_width),
5545 data->ch_switch.cf1,
5546 data->ch_switch.cf2);
5547 if (event == EVENT_LINK_CH_SWITCH_STARTED)
5548 break;
5549
5550 wpa_s->links[data->ch_switch.link_id].freq =
5551 data->ch_switch.freq;
5552 if (wpa_s->links[data->ch_switch.link_id].bss &&
5553 wpa_s->links[data->ch_switch.link_id].bss->freq !=
5554 data->ch_switch.freq) {
5555 wpa_s->links[data->ch_switch.link_id].bss->freq =
5556 data->ch_switch.freq;
5557 notify_bss_changes(
5558 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5559 wpa_s->links[data->ch_switch.link_id].bss);
5560 }
5561 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07005562 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005563 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005564 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005565 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005566
Hai Shalom81f62d82019-07-22 12:10:00 -07005567 wpa_msg(wpa_s, MSG_INFO,
5568 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5569 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5570 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005571 data->ch_switch.freq,
5572 data->ch_switch.ht_enabled,
5573 data->ch_switch.ch_offset,
5574 channel_width_to_string(data->ch_switch.ch_width),
5575 data->ch_switch.cf1,
5576 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005577 if (event == EVENT_CH_SWITCH_STARTED)
5578 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005579
Sunil Ravi65a724b2022-05-24 11:06:09 -07005580 if (wpa_s->assoc_freq && data->ch_switch.freq &&
5581 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
5582 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
5583 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005584 wpa_s->assoc_freq = data->ch_switch.freq;
5585 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005586 if (wpa_s->current_bss &&
5587 wpa_s->current_bss->freq != data->ch_switch.freq) {
5588 wpa_s->current_bss->freq = data->ch_switch.freq;
5589 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5590 wpa_s->current_bss);
5591 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005592
Hai Shalomfdcde762020-04-02 11:19:20 -07005593#ifdef CONFIG_SME
5594 switch (data->ch_switch.ch_offset) {
5595 case 1:
5596 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5597 break;
5598 case -1:
5599 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5600 break;
5601 default:
5602 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5603 break;
5604 }
5605#endif /* CONFIG_SME */
5606
Roshan Pius3a1667e2018-07-03 15:17:14 -07005607#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005608 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5609 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005610 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005611 wpa_s->current_ssid->mode ==
5612 WPAS_MODE_P2P_GROUP_FORMATION) {
5613 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5614 data->ch_switch.ht_enabled,
5615 data->ch_switch.ch_offset,
5616 data->ch_switch.ch_width,
5617 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005618 data->ch_switch.cf2,
5619 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005620 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005621#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005622
Hai Shalom899fcc72020-10-19 14:38:18 -07005623 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5624 sme_event_ch_switch(wpa_s);
5625
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005626 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005627 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005628 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005629#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005630#ifdef NEED_AP_MLME
5631 case EVENT_DFS_RADAR_DETECTED:
5632 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005633 wpas_ap_event_dfs_radar_detected(wpa_s,
5634 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005635 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005636 case EVENT_DFS_NOP_FINISHED:
5637 if (data)
5638 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5639 &data->dfs_event);
5640 break;
5641#endif /* NEED_AP_MLME */
5642#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005643 case EVENT_DFS_CAC_STARTED:
5644 if (data)
5645 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5646 break;
5647 case EVENT_DFS_CAC_FINISHED:
5648 if (data)
5649 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5650 break;
5651 case EVENT_DFS_CAC_ABORTED:
5652 if (data)
5653 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5654 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005655 case EVENT_RX_MGMT: {
5656 u16 fc, stype;
5657 const struct ieee80211_mgmt *mgmt;
5658
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005659#ifdef CONFIG_TESTING_OPTIONS
5660 if (wpa_s->ext_mgmt_frame_handling) {
5661 struct rx_mgmt *rx = &data->rx_mgmt;
5662 size_t hex_len = 2 * rx->frame_len + 1;
5663 char *hex = os_malloc(hex_len);
5664 if (hex) {
5665 wpa_snprintf_hex(hex, hex_len,
5666 rx->frame, rx->frame_len);
5667 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5668 rx->freq, rx->datarate, rx->ssi_signal,
5669 hex);
5670 os_free(hex);
5671 }
5672 break;
5673 }
5674#endif /* CONFIG_TESTING_OPTIONS */
5675
Dmitry Shmidt04949592012-07-19 12:16:46 -07005676 mgmt = (const struct ieee80211_mgmt *)
5677 data->rx_mgmt.frame;
5678 fc = le_to_host16(mgmt->frame_control);
5679 stype = WLAN_FC_GET_STYPE(fc);
5680
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005681#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005682 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005683#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005684#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005685 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005686 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005687 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005688 const u8 *ie;
5689 size_t ie_len;
5690
5691 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5692 ie_len = data->rx_mgmt.frame_len -
5693 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005694 wpas_p2p_probe_req_rx(
5695 wpa_s, src, mgmt->da,
5696 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005697 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005698 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005699 break;
5700 }
5701#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005702#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005703 if (wpa_s->current_ssid &&
5704 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5705 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005706 data->rx_mgmt.frame_len >= 30) {
5707 wpa_supplicant_event_ibss_auth(wpa_s, data);
5708 break;
5709 }
5710#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005711
5712 if (stype == WLAN_FC_STYPE_ACTION) {
5713 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005714 wpa_s, data->rx_mgmt.frame,
5715 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005716 data->rx_mgmt.freq,
5717 data->rx_mgmt.ssi_signal);
5718 break;
5719 }
5720
5721 if (wpa_s->ifmsh) {
5722 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005723 break;
5724 }
Hai Shalom60840252021-02-19 19:02:11 -08005725#ifdef CONFIG_PASN
5726 if (stype == WLAN_FC_STYPE_AUTH &&
5727 wpas_pasn_auth_rx(wpa_s, mgmt,
5728 data->rx_mgmt.frame_len) != -2)
5729 break;
5730#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005731
Roshan Pius3a1667e2018-07-03 15:17:14 -07005732#ifdef CONFIG_SAE
5733 if (stype == WLAN_FC_STYPE_AUTH &&
5734 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5735 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5736 sme_external_auth_mgmt_rx(
5737 wpa_s, data->rx_mgmt.frame,
5738 data->rx_mgmt.frame_len);
5739 break;
5740 }
5741#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005742 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5743 "management frame in non-AP mode");
5744 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005745#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005746 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005747
5748 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005749 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5750 const u8 *ie;
5751 size_t ie_len;
5752
5753 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5754 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005755
5756 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5757 mgmt->bssid, ie, ie_len,
5758 data->rx_mgmt.ssi_signal);
5759 }
5760
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005761 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005762#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005763 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005764 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005765 case EVENT_RX_PROBE_REQ:
5766 if (data->rx_probe_req.sa == NULL ||
5767 data->rx_probe_req.ie == NULL)
5768 break;
5769#ifdef CONFIG_AP
5770 if (wpa_s->ap_iface) {
5771 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5772 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005773 data->rx_probe_req.da,
5774 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005775 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005776 data->rx_probe_req.ie_len,
5777 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005778 break;
5779 }
5780#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005781 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005782 data->rx_probe_req.da,
5783 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005784 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005785 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005786 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005787 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005788 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005789 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005790#ifdef CONFIG_OFFCHANNEL
5791 offchannel_remain_on_channel_cb(
5792 wpa_s, data->remain_on_channel.freq,
5793 data->remain_on_channel.duration);
5794#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005795 wpas_p2p_remain_on_channel_cb(
5796 wpa_s, data->remain_on_channel.freq,
5797 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005798#ifdef CONFIG_DPP
5799 wpas_dpp_remain_on_channel_cb(
5800 wpa_s, data->remain_on_channel.freq,
5801 data->remain_on_channel.duration);
5802#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005803 break;
5804 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005805#ifdef CONFIG_OFFCHANNEL
5806 offchannel_cancel_remain_on_channel_cb(
5807 wpa_s, data->remain_on_channel.freq);
5808#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005809 wpas_p2p_cancel_remain_on_channel_cb(
5810 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005811#ifdef CONFIG_DPP
5812 wpas_dpp_cancel_remain_on_channel_cb(
5813 wpa_s, data->remain_on_channel.freq);
5814#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005815 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005816 case EVENT_EAPOL_RX:
5817 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5818 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00005819 data->eapol_rx.data_len,
5820 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005821 break;
5822 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005823 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5824 "above=%d signal=%d noise=%d txrate=%d",
5825 data->signal_change.above_threshold,
5826 data->signal_change.current_signal,
5827 data->signal_change.current_noise,
5828 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005829 wpa_bss_update_level(wpa_s->current_bss,
5830 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005831 bgscan_notify_signal_change(
5832 wpa_s, data->signal_change.above_threshold,
5833 data->signal_change.current_signal,
5834 data->signal_change.current_noise,
5835 data->signal_change.current_txrate);
5836 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005837 case EVENT_INTERFACE_MAC_CHANGED:
5838 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005839 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005840 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005841 case EVENT_INTERFACE_ENABLED:
5842 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5843 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005844 u8 addr[ETH_ALEN];
5845
Hai Shalomfdcde762020-04-02 11:19:20 -07005846 eloop_cancel_timeout(wpas_clear_disabled_interface,
5847 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005848 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005849 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005850 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5851 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5852 else
5853 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005854 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005855 if (wpa_s->p2p_mgmt) {
5856 wpa_supplicant_set_state(wpa_s,
5857 WPA_DISCONNECTED);
5858 break;
5859 }
5860
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005861#ifdef CONFIG_AP
5862 if (!wpa_s->ap_iface) {
5863 wpa_supplicant_set_state(wpa_s,
5864 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005865 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005866 wpa_supplicant_req_scan(wpa_s, 0, 0);
5867 } else
5868 wpa_supplicant_set_state(wpa_s,
5869 WPA_COMPLETED);
5870#else /* CONFIG_AP */
5871 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5872 wpa_supplicant_req_scan(wpa_s, 0, 0);
5873#endif /* CONFIG_AP */
5874 }
5875 break;
5876 case EVENT_INTERFACE_DISABLED:
5877 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005878#ifdef CONFIG_P2P
5879 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5880 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5881 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5882 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005883 * Mark interface disabled if this happens to end up not
5884 * being removed as a separate P2P group interface.
5885 */
5886 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5887 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005888 * The interface was externally disabled. Remove
5889 * it assuming an external entity will start a
5890 * new session if needed.
5891 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005892 if (wpa_s->current_ssid &&
5893 wpa_s->current_ssid->p2p_group)
5894 wpas_p2p_interface_unavailable(wpa_s);
5895 else
5896 wpas_p2p_disconnect(wpa_s);
5897 /*
5898 * wpa_s instance may have been freed, so must not use
5899 * it here anymore.
5900 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005901 break;
5902 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005903 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5904 p2p_in_progress(wpa_s->global->p2p) > 1) {
5905 /* This radio work will be cancelled, so clear P2P
5906 * state as well.
5907 */
5908 p2p_stop_find(wpa_s->global->p2p);
5909 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005910#endif /* CONFIG_P2P */
5911
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005912 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5913 /*
5914 * Indicate disconnection to keep ctrl_iface events
5915 * consistent.
5916 */
5917 wpa_supplicant_event_disassoc(
5918 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5919 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005920 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005921 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005922 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5923 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005924 clear_at.usec = 0;
5925 } else {
5926 struct os_reltime tmp;
5927
Hai Shalom60840252021-02-19 19:02:11 -08005928 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005929 tmp.usec = 0;
5930 os_reltime_sub(&tmp, &age, &clear_at);
5931 }
5932 eloop_register_timeout(clear_at.sec, clear_at.usec,
5933 wpas_clear_disabled_interface,
5934 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005935 radio_remove_works(wpa_s, NULL, 0);
5936
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005937 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5938 break;
5939 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005940 wpa_supplicant_update_channel_list(
5941 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005942 break;
5943 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005944 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005945 break;
5946 case EVENT_BEST_CHANNEL:
5947 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5948 "(%d %d %d)",
5949 data->best_chan.freq_24, data->best_chan.freq_5,
5950 data->best_chan.freq_overall);
5951 wpa_s->best_24_freq = data->best_chan.freq_24;
5952 wpa_s->best_5_freq = data->best_chan.freq_5;
5953 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005954 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5955 data->best_chan.freq_5,
5956 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005957 break;
5958 case EVENT_UNPROT_DEAUTH:
5959 wpa_supplicant_event_unprot_deauth(wpa_s,
5960 &data->unprot_deauth);
5961 break;
5962 case EVENT_UNPROT_DISASSOC:
5963 wpa_supplicant_event_unprot_disassoc(wpa_s,
5964 &data->unprot_disassoc);
5965 break;
5966 case EVENT_STATION_LOW_ACK:
5967#ifdef CONFIG_AP
5968 if (wpa_s->ap_iface && data)
5969 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5970 data->low_ack.addr);
5971#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005972#ifdef CONFIG_TDLS
5973 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005974 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5975 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005976#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005977 break;
5978 case EVENT_IBSS_PEER_LOST:
5979#ifdef CONFIG_IBSS_RSN
5980 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5981#endif /* CONFIG_IBSS_RSN */
5982 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005983 case EVENT_DRIVER_GTK_REKEY:
5984 if (os_memcmp(data->driver_gtk_rekey.bssid,
5985 wpa_s->bssid, ETH_ALEN))
5986 break;
5987 if (!wpa_s->wpa)
5988 break;
5989 wpa_sm_update_replay_ctr(wpa_s->wpa,
5990 data->driver_gtk_rekey.replay_ctr);
5991 break;
5992 case EVENT_SCHED_SCAN_STOPPED:
5993 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005994 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005995 wpa_supplicant_notify_scanning(wpa_s, 0);
5996
5997 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5998 break;
5999
6000 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006001 * If the driver stopped scanning without being requested to,
6002 * request a new scan to continue scanning for networks.
6003 */
6004 if (!wpa_s->sched_scan_stop_req &&
6005 wpa_s->wpa_state == WPA_SCANNING) {
6006 wpa_dbg(wpa_s, MSG_DEBUG,
6007 "Restart scanning after unexpected sched_scan stop event");
6008 wpa_supplicant_req_scan(wpa_s, 1, 0);
6009 break;
6010 }
6011
6012 wpa_s->sched_scan_stop_req = 0;
6013
6014 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006015 * Start a new sched scan to continue searching for more SSIDs
6016 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006017 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006018 if (wpa_s->sched_scan_timed_out) {
6019 wpa_supplicant_req_sched_scan(wpa_s);
6020 } else if (wpa_s->pno_sched_pending) {
6021 wpa_s->pno_sched_pending = 0;
6022 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006023 } else if (resched) {
6024 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006025 }
6026
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006027 break;
6028 case EVENT_WPS_BUTTON_PUSHED:
6029#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006030 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006031#endif /* CONFIG_WPS */
6032 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006033 case EVENT_AVOID_FREQUENCIES:
6034 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6035 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006036 case EVENT_CONNECT_FAILED_REASON:
6037#ifdef CONFIG_AP
6038 if (!wpa_s->ap_iface || !data)
6039 break;
6040 hostapd_event_connect_failed_reason(
6041 wpa_s->ap_iface->bss[0],
6042 data->connect_failed_reason.addr,
6043 data->connect_failed_reason.code);
6044#endif /* CONFIG_AP */
6045 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006046 case EVENT_NEW_PEER_CANDIDATE:
6047#ifdef CONFIG_MESH
6048 if (!wpa_s->ifmsh || !data)
6049 break;
6050 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6051 data->mesh_peer.ies,
6052 data->mesh_peer.ie_len);
6053#endif /* CONFIG_MESH */
6054 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006055 case EVENT_SURVEY:
6056#ifdef CONFIG_AP
6057 if (!wpa_s->ap_iface)
6058 break;
6059 hostapd_event_get_survey(wpa_s->ap_iface,
6060 &data->survey_results);
6061#endif /* CONFIG_AP */
6062 break;
6063 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006064#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006065#ifdef CONFIG_ACS
6066 if (!wpa_s->ap_iface)
6067 break;
6068 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6069 &data->acs_selected_channels);
6070#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006071#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006072 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006073 case EVENT_P2P_LO_STOP:
6074#ifdef CONFIG_P2P
6075 wpa_s->p2p_lo_started = 0;
6076 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6077 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6078 data->p2p_lo_stop.reason_code);
6079#endif /* CONFIG_P2P */
6080 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006081 case EVENT_BEACON_LOSS:
6082 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6083 break;
6084 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6085 bgscan_notify_beacon_loss(wpa_s);
6086 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006087 case EVENT_EXTERNAL_AUTH:
6088#ifdef CONFIG_SAE
6089 if (!wpa_s->current_ssid) {
6090 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6091 break;
6092 }
6093 sme_external_auth_trigger(wpa_s, data);
6094#endif /* CONFIG_SAE */
6095 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006096#ifdef CONFIG_PASN
6097 case EVENT_PASN_AUTH:
6098 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6099 break;
6100#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006101 case EVENT_PORT_AUTHORIZED:
6102 wpa_supplicant_event_port_authorized(wpa_s);
6103 break;
6104 case EVENT_STATION_OPMODE_CHANGED:
6105#ifdef CONFIG_AP
6106 if (!wpa_s->ap_iface || !data)
6107 break;
6108
6109 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6110 data->sta_opmode.addr,
6111 data->sta_opmode.smps_mode,
6112 data->sta_opmode.chan_width,
6113 data->sta_opmode.rx_nss);
6114#endif /* CONFIG_AP */
6115 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07006116 case EVENT_UNPROT_BEACON:
6117 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6118 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08006119 case EVENT_TX_WAIT_EXPIRE:
6120#ifdef CONFIG_DPP
6121 wpas_dpp_tx_wait_expire(wpa_s);
6122#endif /* CONFIG_DPP */
6123 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006124 default:
6125 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6126 break;
6127 }
6128}
Dmitry Shmidte4663042016-04-04 10:07:49 -07006129
6130
6131void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6132 union wpa_event_data *data)
6133{
6134 struct wpa_supplicant *wpa_s;
6135
6136 if (event != EVENT_INTERFACE_STATUS)
6137 return;
6138
6139 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6140 if (wpa_s && wpa_s->driver->get_ifindex) {
6141 unsigned int ifindex;
6142
6143 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6144 if (ifindex != data->interface_status.ifindex) {
6145 wpa_dbg(wpa_s, MSG_DEBUG,
6146 "interface status ifindex %d mismatch (%d)",
6147 ifindex, data->interface_status.ifindex);
6148 return;
6149 }
6150 }
6151#ifdef CONFIG_MATCH_IFACE
6152 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6153 struct wpa_interface *wpa_i;
6154
6155 wpa_i = wpa_supplicant_match_iface(
6156 ctx, data->interface_status.ifname);
6157 if (!wpa_i)
6158 return;
6159 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6160 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006161 }
6162#endif /* CONFIG_MATCH_IFACE */
6163
6164 if (wpa_s)
6165 wpa_supplicant_event(wpa_s, event, data);
6166}