blob: 2d364bca0f6b6c50bca496125fa4848af1ad60c0 [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);
3082 if (wpa_s->connection_vht || wpa_s->connection_he) {
3083 wpa_s->connection_channel_bandwidth =
3084 get_sta_operation_chan_width(ap_operation_chan_width,
3085 sta_supported_chan_width);
3086 } else if (wpa_s->connection_ht) {
3087 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3088 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3089 } else {
3090 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3091 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003092 }
3093 }
3094
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003095 p = data->assoc_info.req_ies;
3096 l = data->assoc_info.req_ies_len;
3097
3098 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3099 while (p && l >= 2) {
3100 len = p[1] + 2;
3101 if (len > l) {
3102 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3103 p, l);
3104 break;
3105 }
Hai Shalomc3565922019-10-28 11:58:20 -07003106 if (!found &&
3107 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3108 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3109 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3110 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3111 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003112 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3113 break;
3114 found = 1;
3115 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07003116 }
3117 if (!found_x && p[0] == WLAN_EID_RSNX) {
3118 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3119 break;
3120 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003121 }
3122 l -= len;
3123 p += len;
3124 }
3125 if (!found && data->assoc_info.req_ies)
3126 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003127 if (!found_x && data->assoc_info.req_ies)
3128 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003129
Vinayak Yadawad14709082022-03-17 14:25:11 +05303130#ifdef CONFIG_DRIVER_NL80211_BRCM
3131 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3132 * to a different security type, update the current supplicant configuration to use the AKM
3133 * and pairwise suites from the assoc IE passed by the driver.
3134 */
3135 if (wpas_driver_bss_selection(wpa_s)) {
3136 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3137 /* Check if firmware has roamed to a different security network */
3138 if(wpa_s->key_mgmt != ie.key_mgmt) {
3139 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3140 ie.key_mgmt);
3141 wpa_s->key_mgmt = ie.key_mgmt;
3142 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3143
3144 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3145 /* Restore PMK as it can get overwritten if the previous
3146 * association was to 802.1X.
3147 */
3148 if ((!(wpa_s->drv_flags &
3149 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3150 (wpa_s->current_ssid) &&
3151 (wpa_s->current_ssid->psk_set)) {
3152 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3153 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3154 "BSSID");
3155 wpa_supplicant_deauthenticate(
3156 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3157 return -1;
3158 }
3159 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3160 PMK_LEN, NULL, bssid);
3161 }
3162 }
3163 }
3164 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3165 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3166 "from Assoc IE", ie.pairwise_cipher);
3167 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3168 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3169 wpa_s->pairwise_cipher);
3170 }
3171 // TODO: Notify the framework about security type change b/230766005
3172 }
3173 }
3174#endif /* CONFIG_DRIVER_NL80211_BRCM */
3175
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003176#ifdef CONFIG_FILS
3177#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003178 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3179 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003180 (!data->assoc_info.resp_frame ||
3181 fils_process_assoc_resp(wpa_s->wpa,
3182 data->assoc_info.resp_frame,
3183 data->assoc_info.resp_frame_len) < 0)) {
3184 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3185 return -1;
3186 }
3187#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003188
3189 /* Additional processing for FILS when SME is in driver */
3190 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3191 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3192 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003193#endif /* CONFIG_FILS */
3194
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003195#ifdef CONFIG_OWE
3196 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003197 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003198 owe_process_assoc_resp(wpa_s->wpa, bssid,
3199 data->assoc_info.resp_ies,
3200 data->assoc_info.resp_ies_len) < 0)) {
3201 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3202 return -1;
3203 }
3204#endif /* CONFIG_OWE */
3205
Hai Shalom021b0b52019-04-10 11:17:58 -07003206#ifdef CONFIG_DPP2
3207 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003208 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3209 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003210 struct ieee802_11_elems elems;
3211
3212 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3213 data->assoc_info.resp_ies_len,
3214 &elems, 0) == ParseFailed ||
3215 !elems.owe_dh)
3216 goto no_pfs;
3217 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3218 elems.owe_dh_len) < 0) {
3219 wpa_supplicant_deauthenticate(wpa_s,
3220 WLAN_REASON_UNSPECIFIED);
3221 return -1;
3222 }
3223
3224 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3225 }
3226no_pfs:
3227#endif /* CONFIG_DPP2 */
3228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003229#ifdef CONFIG_IEEE80211R
3230#ifdef CONFIG_SME
3231 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003232 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003233 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3234 data->assoc_info.resp_ies,
3235 data->assoc_info.resp_ies_len,
3236 bssid) < 0) {
3237 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3238 "Reassociation Response failed");
3239 wpa_supplicant_deauthenticate(
3240 wpa_s, WLAN_REASON_INVALID_IE);
3241 return -1;
3242 }
3243 }
3244
3245 p = data->assoc_info.resp_ies;
3246 l = data->assoc_info.resp_ies_len;
3247
3248#ifdef CONFIG_WPS_STRICT
3249 if (p && wpa_s->current_ssid &&
3250 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3251 struct wpabuf *wps;
3252 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3253 if (wps == NULL) {
3254 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3255 "include WPS IE in (Re)Association Response");
3256 return -1;
3257 }
3258
3259 if (wps_validate_assoc_resp(wps) < 0) {
3260 wpabuf_free(wps);
3261 wpa_supplicant_deauthenticate(
3262 wpa_s, WLAN_REASON_INVALID_IE);
3263 return -1;
3264 }
3265 wpabuf_free(wps);
3266 }
3267#endif /* CONFIG_WPS_STRICT */
3268
3269 /* Go through the IEs and make a copy of the MDIE, if present. */
3270 while (p && l >= 2) {
3271 len = p[1] + 2;
3272 if (len > l) {
3273 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3274 p, l);
3275 break;
3276 }
3277 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3278 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3279 wpa_s->sme.ft_used = 1;
3280 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3281 MOBILITY_DOMAIN_ID_LEN);
3282 break;
3283 }
3284 l -= len;
3285 p += len;
3286 }
3287#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003288#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303289 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3290 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3291 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3292 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303293 wpa_ft_is_completed(wpa_s->wpa)) {
3294 return 0;
3295 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003296#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003297
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003298 /* Process FT when SME is in the driver */
3299 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3300 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003301 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003302 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3303 data->assoc_info.resp_ies,
3304 data->assoc_info.resp_ies_len,
3305 bssid) < 0) {
3306 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3307 "Reassociation Response failed");
3308 wpa_supplicant_deauthenticate(
3309 wpa_s, WLAN_REASON_INVALID_IE);
3310 return -1;
3311 }
3312 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3313 }
3314
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003315 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3316 data->assoc_info.resp_ies_len);
3317#endif /* CONFIG_IEEE80211R */
3318
Hai Shalom899fcc72020-10-19 14:38:18 -07003319 if (bssid_known)
3320 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3321 data->assoc_info.resp_ies,
3322 data->assoc_info.resp_ies_len);
3323
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003324 /* WPA/RSN IE from Beacon/ProbeResp */
3325 p = data->assoc_info.beacon_ies;
3326 l = data->assoc_info.beacon_ies_len;
3327
3328 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3329 */
3330 wpa_found = rsn_found = 0;
3331 while (p && l >= 2) {
3332 len = p[1] + 2;
3333 if (len > l) {
3334 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3335 p, l);
3336 break;
3337 }
3338 if (!wpa_found &&
3339 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3340 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3341 wpa_found = 1;
3342 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3343 }
3344
3345 if (!rsn_found &&
3346 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3347 rsn_found = 1;
3348 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3349 }
3350
Hai Shalomc3565922019-10-28 11:58:20 -07003351 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3352 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003354 l -= len;
3355 p += len;
3356 }
3357
3358 if (!wpa_found && data->assoc_info.beacon_ies)
3359 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003360 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003361 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003362 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3363 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003364 if (wpa_found || rsn_found)
3365 wpa_s->ap_ies_from_associnfo = 1;
3366
Jouni Malinen87fd2792011-05-16 18:35:42 +03003367 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3368 wpa_s->assoc_freq != data->assoc_info.freq) {
3369 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3370 "%u to %u MHz",
3371 wpa_s->assoc_freq, data->assoc_info.freq);
3372 wpa_supplicant_update_scan_results(wpa_s);
3373 }
3374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003375 wpa_s->assoc_freq = data->assoc_info.freq;
3376
Hai Shalomc1a21442022-02-04 13:43:00 -08003377 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3378 data->assoc_info.resp_ies_len);
3379
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003380 return 0;
3381}
3382
3383
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003384static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3385{
Hai Shalomc3565922019-10-28 11:58:20 -07003386 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003387
3388 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3389 return -1;
3390
3391 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3392 return 0;
3393
3394 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3395 WPA_IE_VENDOR_TYPE);
3396 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003397 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003398
3399 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3400 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3401 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003402 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3403 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3404 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003405 return -1;
3406
3407 return 0;
3408}
3409
3410
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003411static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3412 union wpa_event_data *data)
3413{
3414#ifdef CONFIG_FST
3415 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3416 struct wpa_bss *bss = wpa_s->current_bss;
3417 const u8 *ieprb, *iebcn;
3418
3419 wpabuf_free(wpa_s->received_mb_ies);
3420 wpa_s->received_mb_ies = NULL;
3421
3422 if (ai &&
3423 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3424 wpa_printf(MSG_DEBUG,
3425 "FST: MB IEs updated from Association Response frame");
3426 return;
3427 }
3428
3429 if (ai &&
3430 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3431 wpa_printf(MSG_DEBUG,
3432 "FST: MB IEs updated from association event Beacon IEs");
3433 return;
3434 }
3435
3436 if (!bss)
3437 return;
3438
Hai Shalom60840252021-02-19 19:02:11 -08003439 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003440 iebcn = ieprb + bss->ie_len;
3441
3442 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3443 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3444 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3445 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3446#endif /* CONFIG_FST */
3447}
3448
3449
Sunil Ravi89eba102022-09-13 21:04:37 -07003450static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3451{
3452 struct driver_sta_mlo_info mlo;
3453 int i;
3454
3455 mlo.valid_links = 0;
3456 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3457 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3458 wpa_supplicant_deauthenticate(wpa_s,
3459 WLAN_REASON_DEAUTH_LEAVING);
3460 return -1;
3461 }
3462
3463 if (wpa_s->valid_links == mlo.valid_links) {
3464 bool match = true;
3465
3466 if (!mlo.valid_links)
3467 return 0;
3468
3469 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3470 if (!(mlo.valid_links & BIT(i)))
3471 continue;
3472
3473 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3474 ETH_ALEN) != 0 ||
3475 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3476 ETH_ALEN) != 0) {
3477 match = false;
3478 break;
3479 }
3480 }
3481
3482 if (match &&
3483 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3484 ETH_ALEN) == 0)
3485 return 0;
3486 }
3487
3488 wpa_s->valid_links = mlo.valid_links;
3489 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3490 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3491 if (!(wpa_s->valid_links & BIT(i)))
3492 continue;
3493
3494 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3495 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3496 wpa_s->links[i].freq = mlo.links[i].freq;
3497 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3498 }
3499
3500 return 0;
3501}
3502
3503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003504static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3505 union wpa_event_data *data)
3506{
3507 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003508 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003509 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003510#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3511 struct wpa_bss *bss;
3512#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003513#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303514 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003515#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003516
3517#ifdef CONFIG_AP
3518 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003519 if (!data)
3520 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003521 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3522 data->assoc_info.addr,
3523 data->assoc_info.req_ies,
3524 data->assoc_info.req_ies_len,
3525 data->assoc_info.reassoc);
3526 return;
3527 }
3528#endif /* CONFIG_AP */
3529
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003530 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003531 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003532
Andy Kuoaba17c12022-04-14 16:05:31 +08003533#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303534 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3535 struct wpa_ft_ies parse;
3536 /* Check for FT reassociation is done by the driver */
3537#ifdef CONFIG_IEEE80211R
3538 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303539 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303540 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3541 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3542 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3543 return;
3544 }
3545 if (parse.rsn_pmkid != NULL) {
3546 wpa_set_ft_completed(wpa_s->wpa);
3547 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3548 }
3549 }
3550#endif /* CONFIG_IEEE80211R */
3551 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003552#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303553
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003554 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003555
3556 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3557 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3558 wpa_supplicant_deauthenticate(
3559 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3560 return;
3561 }
3562
Sunil Ravi89eba102022-09-13 21:04:37 -07003563 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3564 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3565 wpa_supplicant_deauthenticate(wpa_s,
3566 WLAN_REASON_DEAUTH_LEAVING);
3567 return;
3568 }
3569
Sunil Ravia04bd252022-05-02 22:54:18 -07003570 if (ft_completed &&
3571 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3572 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3573 MAC2STR(bssid));
3574 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3575 wpa_printf(MSG_ERROR,
3576 "Can't find target AP's information!");
3577 return;
3578 }
3579 wpa_supplicant_assoc_update_ie(wpa_s);
3580 }
3581
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003582 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3583 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003584 /*
3585 * FILS authentication can share the same mechanism to mark the
3586 * connection fully authenticated, so set ft_completed also based on
3587 * FILS result.
3588 */
3589 if (!ft_completed)
3590 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003591
Andy Kuoaba17c12022-04-14 16:05:31 +08003592#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303593 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3594 /*
3595 * For driver based roaming, insert PSK during
3596 * the initial association
3597 */
3598 if (is_zero_ether_addr(wpa_s->bssid) &&
3599 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3600 /*
3601 * In case the driver wants to handle re-assocs,
3602 * pass it down the PMK.
3603 */
3604 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3605 wpa_sm_install_pmk(wpa_s->wpa);
3606 }
Mir Ali677e7482020-11-12 19:49:02 +05303607 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303608#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003609
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003610 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003611 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003612 if (os_reltime_initialized(&wpa_s->session_start)) {
3613 os_reltime_age(&wpa_s->session_start,
3614 &wpa_s->session_length);
3615 wpa_s->session_start.sec = 0;
3616 wpa_s->session_start.usec = 0;
3617 wpas_notify_session_length(wpa_s);
3618 } else {
3619 wpas_notify_auth_changed(wpa_s);
3620 os_get_reltime(&wpa_s->session_start);
3621 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003622 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3623 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003624 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003625 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003626 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3627 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003628 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003629
3630 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3631 wpa_clear_keys(wpa_s, bssid);
3632 }
3633 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003634 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003635 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3636 return;
3637 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003638 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003639
Hai Shalomc1a21442022-02-04 13:43:00 -08003640 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3641 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3642 return;
3643
Hai Shalomfdcde762020-04-02 11:19:20 -07003644 multi_ap_set_4addr_mode(wpa_s);
3645
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003646 if (wpa_s->conf->ap_scan == 1 &&
3647 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003648 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3649 wpa_msg(wpa_s, MSG_WARNING,
3650 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003651 }
3652
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003653 wpas_fst_update_mb_assoc(wpa_s, data);
3654
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003655#ifdef CONFIG_SME
3656 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3657 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003658 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003659#endif /* CONFIG_SME */
3660
3661 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3662 if (wpa_s->current_ssid) {
3663 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3664 * initialized before association, but for other modes,
3665 * initialize PC/SC here, if the current configuration needs
3666 * smartcard or SIM/USIM. */
3667 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3668 }
3669 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3670 if (wpa_s->l2)
3671 l2_packet_notify_auth_start(wpa_s->l2);
3672
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003673 already_authorized = data && data->assoc_info.authorized;
3674
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003675 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003676 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003677 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3678 * state machine may transit to AUTHENTICATING state based on obsolete
3679 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3680 * AUTHENTICATED without ever giving chance to EAP state machine to
3681 * reset the state.
3682 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003683 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003684 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3685 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003686 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003687 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3688 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3689 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003690 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003691 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003692 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003693 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003694 wpa_s->eapol_received = 0;
3695 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3696 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3697 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003698 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003699 if (wpa_s->current_ssid &&
3700 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003701 (wpa_s->drv_flags &
3702 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3703 /*
3704 * Set the key after having received joined-IBSS event
3705 * from the driver.
3706 */
3707 wpa_supplicant_set_wpa_none_key(wpa_s,
3708 wpa_s->current_ssid);
3709 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003710 wpa_supplicant_cancel_auth_timeout(wpa_s);
3711 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3712 } else if (!ft_completed) {
3713 /* Timeout for receiving the first EAPOL packet */
3714 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3715 }
3716 wpa_supplicant_cancel_scan(wpa_s);
3717
Hai Shalom5f92bc92019-04-18 11:54:11 -07003718 if (ft_completed) {
3719 /*
3720 * FT protocol completed - make sure EAPOL state machine ends
3721 * up in authenticated.
3722 */
3723 wpa_supplicant_cancel_auth_timeout(wpa_s);
3724 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003725 eapol_sm_notify_portValid(wpa_s->eapol, true);
3726 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003727 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3728 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303729 if (already_authorized) {
3730 /*
3731 * We are done; the driver will take care of RSN 4-way
3732 * handshake.
3733 */
3734 wpa_supplicant_cancel_auth_timeout(wpa_s);
3735 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3736 eapol_sm_notify_portValid(wpa_s->eapol, true);
3737 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3738 } else {
3739 /* Update port, WPA_COMPLETED state from
3740 * EVENT_PORT_AUTHORIZED context when driver is done
3741 * with 4way handshake.
3742 */
3743 wpa_msg(wpa_s, MSG_INFO, "ASSOC INFO: wait for driver port "
3744 "authorized indication");
3745 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003746 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003747 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3748 /*
3749 * The driver will take care of RSN 4-way handshake, so we need
3750 * to allow EAPOL supplicant to complete its work without
3751 * waiting for WPA supplicant.
3752 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003753 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003754 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003755#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303756 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3757 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3758 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3759 wpa_s->key_mgmt);
3760 wpa_supplicant_deauthenticate(
3761 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3762 return;
3763 }
3764 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3765 wpa_s->assoc_freq = data->assoc_info.freq;
3766 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3767 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003768#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3769
Jouni Malinena05074c2012-12-21 21:35:35 +02003770 wpa_s->last_eapol_matches_bssid = 0;
3771
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003772#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003773 if (wpa_s->rsne_override_eapol) {
3774 wpa_printf(MSG_DEBUG,
3775 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3776 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3777 wpabuf_head(wpa_s->rsne_override_eapol),
3778 wpabuf_len(wpa_s->rsne_override_eapol));
3779 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003780 if (wpa_s->rsnxe_override_eapol) {
3781 wpa_printf(MSG_DEBUG,
3782 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3783 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3784 wpabuf_head(wpa_s->rsnxe_override_eapol),
3785 wpabuf_len(wpa_s->rsnxe_override_eapol));
3786 }
3787#endif /* CONFIG_TESTING_OPTIONS */
3788
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003789 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003790 struct os_reltime now, age;
3791 os_get_reltime(&now);
3792 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003793 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003794 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3795 0) {
3796 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3797 "frame that was received just before "
3798 "association notification");
3799 wpa_supplicant_rx_eapol(
3800 wpa_s, wpa_s->pending_eapol_rx_src,
3801 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00003802 wpabuf_len(wpa_s->pending_eapol_rx),
3803 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003804 }
3805 wpabuf_free(wpa_s->pending_eapol_rx);
3806 wpa_s->pending_eapol_rx = NULL;
3807 }
3808
Hai Shalomfdcde762020-04-02 11:19:20 -07003809#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003810 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3811 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003812 wpa_s->current_ssid &&
3813 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003814 /* Set static WEP keys again */
3815 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3816 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003817#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003818
3819#ifdef CONFIG_IBSS_RSN
3820 if (wpa_s->current_ssid &&
3821 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3822 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3823 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3824 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003825 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003826 if (!wpa_s->ibss_rsn) {
3827 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3828 wpa_supplicant_deauthenticate(
3829 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3830 return;
3831 }
3832
3833 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3834 }
3835#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003836
3837 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003838
3839 if (data) {
3840 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3841 data->assoc_info.resp_ies_len,
3842 &data->assoc_info.wmm_params);
3843
3844 if (wpa_s->reassoc_same_bss)
3845 wmm_ac_restore_tspecs(wpa_s);
3846 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003847
Hai Shalomc3565922019-10-28 11:58:20 -07003848#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3849 bss = wpa_bss_get_bssid(wpa_s, bssid);
3850#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003851#ifdef CONFIG_FILS
3852 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003853 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3854
3855 if (fils_cache_id)
3856 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3857 }
3858#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003859
3860#ifdef CONFIG_MBO
3861 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3862#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003863
3864#ifdef CONFIG_DPP2
3865 wpa_s->dpp_pfs_fallback = 0;
3866#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003867}
3868
3869
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003870static int disconnect_reason_recoverable(u16 reason_code)
3871{
3872 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3873 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3874 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3875}
3876
3877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003878static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003879 u16 reason_code,
3880 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003881{
3882 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003883
3884 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3885 /*
3886 * At least Host AP driver and a Prism3 card seemed to be
3887 * generating streams of disconnected events when configuring
3888 * IBSS for WPA-None. Ignore them for now.
3889 */
3890 return;
3891 }
3892
3893 bssid = wpa_s->bssid;
3894 if (is_zero_ether_addr(bssid))
3895 bssid = wpa_s->pending_bssid;
3896
3897 if (!is_zero_ether_addr(bssid) ||
3898 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3899 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3900 " reason=%d%s",
3901 MAC2STR(bssid), reason_code,
3902 locally_generated ? " locally_generated=1" : "");
3903 }
3904}
3905
3906
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003907static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3908 int locally_generated)
3909{
3910 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003911 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003912 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3913 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003914 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003915
3916 /*
3917 * It looks like connection was lost while trying to go through PSK
3918 * 4-way handshake. Filter out known disconnection cases that are caused
3919 * by something else than PSK mismatch to avoid confusing reports.
3920 */
3921
3922 if (locally_generated) {
3923 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3924 return 0;
3925 }
3926
3927 return 1;
3928}
3929
3930
Jouni Malinen2b89da82012-08-31 22:04:41 +03003931static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3932 u16 reason_code,
3933 int locally_generated)
3934{
3935 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003936 int authenticating;
3937 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003938 struct wpa_bss *fast_reconnect = NULL;
3939 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003940 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003941 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003942
3943 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3944 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3945
3946 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3947 /*
3948 * At least Host AP driver and a Prism3 card seemed to be
3949 * generating streams of disconnected events when configuring
3950 * IBSS for WPA-None. Ignore them for now.
3951 */
3952 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3953 "IBSS/WPA-None mode");
3954 return;
3955 }
3956
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003957 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3958 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3959 locally_generated)
3960 /*
3961 * Remove the inactive AP (which is probably out of range) from
3962 * the BSS list after marking disassociation. In particular
3963 * mac80211-based drivers use the
3964 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3965 * locally generated disconnection events for cases where the
3966 * AP does not reply anymore.
3967 */
3968 curr = wpa_s->current_bss;
3969
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003970 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003971 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3972 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003973 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3974 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003975 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003976#ifdef CONFIG_DPP2
3977 wpas_dpp_send_conn_status_result(wpa_s,
3978 DPP_STATUS_AUTH_FAILURE);
3979#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003980 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003981 if (!wpa_s->disconnected &&
3982 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003983 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003984 wpas_wps_searching(wpa_s) ||
3985 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003986 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003987 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003988 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003989 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003990 wpa_s->wpa_state);
3991 if (wpa_s->wpa_state == WPA_COMPLETED &&
3992 wpa_s->current_ssid &&
3993 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003994 (wpa_s->own_reconnect_req ||
3995 (!locally_generated &&
3996 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003997 /*
3998 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003999 * us, but could allow us to get back in. This is also
4000 * triggered for cases where local reconnection request
4001 * is used to force reassociation with the same BSS.
4002 * Try to reconnect to the same BSS without a full scan
4003 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004004 */
4005 fast_reconnect = wpa_s->current_bss;
4006 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004007 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004008 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004009 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004010 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4011 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004012 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004013 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004014 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004015 "try to re-connect");
4016 wpa_s->reassociate = 0;
4017 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004018 if (!wpa_s->pno)
4019 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004020 }
4021 bssid = wpa_s->bssid;
4022 if (is_zero_ether_addr(bssid))
4023 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004024 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4025 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004026 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004027 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4028
Dmitry Shmidt04949592012-07-19 12:16:46 -07004029 if (locally_generated)
4030 wpa_s->disconnect_reason = -reason_code;
4031 else
4032 wpa_s->disconnect_reason = reason_code;
4033 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004034 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4035 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004036 wpa_clear_keys(wpa_s, wpa_s->bssid);
4037 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004038 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004039 wpa_supplicant_mark_disassoc(wpa_s);
4040
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004041 if (curr)
4042 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4043
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004044 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004045 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004046 wpa_s->current_ssid = last_ssid;
4047 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004048
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004049 if (fast_reconnect &&
4050 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4051 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4052 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4053 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004054 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004055 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004056#ifndef CONFIG_NO_SCAN_PROCESSING
4057 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4058 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4059 fast_reconnect_ssid) < 0) {
4060 /* Recover through full scan */
4061 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4062 }
4063#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004064 } else if (fast_reconnect) {
4065 /*
4066 * Could not reconnect to the same BSS due to network being
4067 * disabled. Use a new scan to match the alternative behavior
4068 * above, i.e., to continue automatic reconnection attempt in a
4069 * way that enforces disabled network rules.
4070 */
4071 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004072 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004073}
4074
4075
4076#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004077void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004078{
4079 struct wpa_supplicant *wpa_s = eloop_ctx;
4080
4081 if (!wpa_s->pending_mic_error_report)
4082 return;
4083
4084 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4085 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4086 wpa_s->pending_mic_error_report = 0;
4087}
4088#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4089
4090
4091static void
4092wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4093 union wpa_event_data *data)
4094{
4095 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004096 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004097
4098 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4099 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004100 os_get_reltime(&t);
4101 if ((wpa_s->last_michael_mic_error.sec &&
4102 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004103 wpa_s->pending_mic_error_report) {
4104 if (wpa_s->pending_mic_error_report) {
4105 /*
4106 * Send the pending MIC error report immediately since
4107 * we are going to start countermeasures and AP better
4108 * do the same.
4109 */
4110 wpa_sm_key_request(wpa_s->wpa, 1,
4111 wpa_s->pending_mic_error_pairwise);
4112 }
4113
4114 /* Send the new MIC error report immediately since we are going
4115 * to start countermeasures and AP better do the same.
4116 */
4117 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4118
4119 /* initialize countermeasures */
4120 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004121
Hai Shalom60840252021-02-19 19:02:11 -08004122 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004123
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004124 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4125
4126 /*
4127 * Need to wait for completion of request frame. We do not get
4128 * any callback for the message completion, so just wait a
4129 * short while and hope for the best. */
4130 os_sleep(0, 10000);
4131
4132 wpa_drv_set_countermeasures(wpa_s, 1);
4133 wpa_supplicant_deauthenticate(wpa_s,
4134 WLAN_REASON_MICHAEL_MIC_FAILURE);
4135 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4136 wpa_s, NULL);
4137 eloop_register_timeout(60, 0,
4138 wpa_supplicant_stop_countermeasures,
4139 wpa_s, NULL);
4140 /* TODO: mark the AP rejected for 60 second. STA is
4141 * allowed to associate with another AP.. */
4142 } else {
4143#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4144 if (wpa_s->mic_errors_seen) {
4145 /*
4146 * Reduce the effectiveness of Michael MIC error
4147 * reports as a means for attacking against TKIP if
4148 * more than one MIC failure is noticed with the same
4149 * PTK. We delay the transmission of the reports by a
4150 * random time between 0 and 60 seconds in order to
4151 * force the attacker wait 60 seconds before getting
4152 * the information on whether a frame resulted in a MIC
4153 * failure.
4154 */
4155 u8 rval[4];
4156 int sec;
4157
4158 if (os_get_random(rval, sizeof(rval)) < 0)
4159 sec = os_random() % 60;
4160 else
4161 sec = WPA_GET_BE32(rval) % 60;
4162 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4163 "report %d seconds", sec);
4164 wpa_s->pending_mic_error_report = 1;
4165 wpa_s->pending_mic_error_pairwise = pairwise;
4166 eloop_cancel_timeout(
4167 wpa_supplicant_delayed_mic_error_report,
4168 wpa_s, NULL);
4169 eloop_register_timeout(
4170 sec, os_random() % 1000000,
4171 wpa_supplicant_delayed_mic_error_report,
4172 wpa_s, NULL);
4173 } else {
4174 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4175 }
4176#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4177 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4178#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4179 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004180 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004181 wpa_s->mic_errors_seen++;
4182}
4183
4184
4185#ifdef CONFIG_TERMINATE_ONLASTIF
4186static int any_interfaces(struct wpa_supplicant *head)
4187{
4188 struct wpa_supplicant *wpa_s;
4189
4190 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4191 if (!wpa_s->interface_removed)
4192 return 1;
4193 return 0;
4194}
4195#endif /* CONFIG_TERMINATE_ONLASTIF */
4196
4197
4198static void
4199wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4200 union wpa_event_data *data)
4201{
4202 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4203 return;
4204
4205 switch (data->interface_status.ievent) {
4206 case EVENT_INTERFACE_ADDED:
4207 if (!wpa_s->interface_removed)
4208 break;
4209 wpa_s->interface_removed = 0;
4210 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4211 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4212 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4213 "driver after interface was added");
4214 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004215
4216#ifdef CONFIG_P2P
4217 if (!wpa_s->global->p2p &&
4218 !wpa_s->global->p2p_disabled &&
4219 !wpa_s->conf->p2p_disabled &&
4220 (wpa_s->drv_flags &
4221 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4222 wpas_p2p_add_p2pdev_interface(
4223 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4224 wpa_printf(MSG_INFO,
4225 "P2P: Failed to enable P2P Device interface");
4226 /* Try to continue without. P2P will be disabled. */
4227 }
4228#endif /* CONFIG_P2P */
4229
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004230 break;
4231 case EVENT_INTERFACE_REMOVED:
4232 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4233 wpa_s->interface_removed = 1;
4234 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004235 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004236 l2_packet_deinit(wpa_s->l2);
4237 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004238
4239#ifdef CONFIG_P2P
4240 if (wpa_s->global->p2p &&
4241 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4242 (wpa_s->drv_flags &
4243 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4244 wpa_dbg(wpa_s, MSG_DEBUG,
4245 "Removing P2P Device interface");
4246 wpa_supplicant_remove_iface(
4247 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4248 0);
4249 wpa_s->global->p2p_init_wpa_s = NULL;
4250 }
4251#endif /* CONFIG_P2P */
4252
Dmitry Shmidte4663042016-04-04 10:07:49 -07004253#ifdef CONFIG_MATCH_IFACE
4254 if (wpa_s->matched) {
4255 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4256 break;
4257 }
4258#endif /* CONFIG_MATCH_IFACE */
4259
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004260#ifdef CONFIG_TERMINATE_ONLASTIF
4261 /* check if last interface */
4262 if (!any_interfaces(wpa_s->global->ifaces))
4263 eloop_terminate();
4264#endif /* CONFIG_TERMINATE_ONLASTIF */
4265 break;
4266 }
4267}
4268
4269
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004270#ifdef CONFIG_TDLS
4271static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4272 union wpa_event_data *data)
4273{
4274 if (data == NULL)
4275 return;
4276 switch (data->tdls.oper) {
4277 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004278 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4279 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4280 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4281 else
4282 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004283 break;
4284 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004285 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4286 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4287 data->tdls.reason_code);
4288 else
4289 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4290 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004291 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004292 case TDLS_REQUEST_DISCOVER:
4293 wpa_tdls_send_discovery_request(wpa_s->wpa,
4294 data->tdls.peer);
4295 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004296 }
4297}
4298#endif /* CONFIG_TDLS */
4299
4300
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004301#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004302static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4303 union wpa_event_data *data)
4304{
4305 if (data == NULL)
4306 return;
4307 switch (data->wnm.oper) {
4308 case WNM_OPER_SLEEP:
4309 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4310 "(action=%d, intval=%d)",
4311 data->wnm.sleep_action, data->wnm.sleep_intval);
4312 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004313 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004314 break;
4315 }
4316}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004317#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004318
4319
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004320#ifdef CONFIG_IEEE80211R
4321static void
4322wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4323 union wpa_event_data *data)
4324{
4325 if (data == NULL)
4326 return;
4327
4328 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4329 data->ft_ies.ies_len,
4330 data->ft_ies.ft_action,
4331 data->ft_ies.target_ap,
4332 data->ft_ies.ric_ies,
4333 data->ft_ies.ric_ies_len) < 0) {
4334 /* TODO: prevent MLME/driver from trying to associate? */
4335 }
4336}
4337#endif /* CONFIG_IEEE80211R */
4338
4339
4340#ifdef CONFIG_IBSS_RSN
4341static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4342 union wpa_event_data *data)
4343{
4344 struct wpa_ssid *ssid;
4345 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4346 return;
4347 if (data == NULL)
4348 return;
4349 ssid = wpa_s->current_ssid;
4350 if (ssid == NULL)
4351 return;
4352 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4353 return;
4354
4355 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4356}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004357
4358
4359static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4360 union wpa_event_data *data)
4361{
4362 struct wpa_ssid *ssid = wpa_s->current_ssid;
4363
4364 if (ssid == NULL)
4365 return;
4366
4367 /* check if the ssid is correctly configured as IBSS/RSN */
4368 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4369 return;
4370
4371 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4372 data->rx_mgmt.frame_len);
4373}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004374#endif /* CONFIG_IBSS_RSN */
4375
4376
4377#ifdef CONFIG_IEEE80211R
4378static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4379 size_t len)
4380{
4381 const u8 *sta_addr, *target_ap_addr;
4382 u16 status;
4383
4384 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4385 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4386 return; /* only SME case supported for now */
4387 if (len < 1 + 2 * ETH_ALEN + 2)
4388 return;
4389 if (data[0] != 2)
4390 return; /* Only FT Action Response is supported for now */
4391 sta_addr = data + 1;
4392 target_ap_addr = data + 1 + ETH_ALEN;
4393 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4394 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4395 MACSTR " TargetAP " MACSTR " status %u",
4396 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4397
4398 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4399 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4400 " in FT Action Response", MAC2STR(sta_addr));
4401 return;
4402 }
4403
4404 if (status) {
4405 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4406 "failure (status code %d)", status);
4407 /* TODO: report error to FT code(?) */
4408 return;
4409 }
4410
4411 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4412 len - (1 + 2 * ETH_ALEN + 2), 1,
4413 target_ap_addr, NULL, 0) < 0)
4414 return;
4415
4416#ifdef CONFIG_SME
4417 {
4418 struct wpa_bss *bss;
4419 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4420 if (bss)
4421 wpa_s->sme.freq = bss->freq;
4422 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4423 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4424 WLAN_AUTH_FT);
4425 }
4426#endif /* CONFIG_SME */
4427}
4428#endif /* CONFIG_IEEE80211R */
4429
4430
4431static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4432 struct unprot_deauth *e)
4433{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004434 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4435 "dropped: " MACSTR " -> " MACSTR
4436 " (reason code %u)",
4437 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4438 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004439}
4440
4441
4442static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4443 struct unprot_disassoc *e)
4444{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004445 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4446 "dropped: " MACSTR " -> " MACSTR
4447 " (reason code %u)",
4448 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4449 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004450}
4451
4452
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004453static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4454 u16 reason_code, int locally_generated,
4455 const u8 *ie, size_t ie_len, int deauth)
4456{
4457#ifdef CONFIG_AP
4458 if (wpa_s->ap_iface && addr) {
4459 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4460 return;
4461 }
4462
4463 if (wpa_s->ap_iface) {
4464 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4465 return;
4466 }
4467#endif /* CONFIG_AP */
4468
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004469 if (!locally_generated)
4470 wpa_s->own_disconnect_req = 0;
4471
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004472 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4473
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004474 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4475 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4476 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4477 eapol_sm_failed(wpa_s->eapol))) &&
4478 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004479 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004480
4481#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004482 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004483 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4484 locally_generated) > 0) {
4485 /*
4486 * The interface was removed, so cannot continue
4487 * processing any additional operations after this.
4488 */
4489 return;
4490 }
4491 }
4492#endif /* CONFIG_P2P */
4493
4494 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4495 locally_generated);
4496}
4497
4498
4499static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4500 struct disassoc_info *info)
4501{
4502 u16 reason_code = 0;
4503 int locally_generated = 0;
4504 const u8 *addr = NULL;
4505 const u8 *ie = NULL;
4506 size_t ie_len = 0;
4507
4508 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4509
4510 if (info) {
4511 addr = info->addr;
4512 ie = info->ie;
4513 ie_len = info->ie_len;
4514 reason_code = info->reason_code;
4515 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004516 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4517 reason2str(reason_code),
4518 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004519 if (addr)
4520 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4521 MAC2STR(addr));
4522 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4523 ie, ie_len);
4524 }
4525
4526#ifdef CONFIG_AP
4527 if (wpa_s->ap_iface && info && info->addr) {
4528 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4529 return;
4530 }
4531
4532 if (wpa_s->ap_iface) {
4533 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4534 return;
4535 }
4536#endif /* CONFIG_AP */
4537
4538#ifdef CONFIG_P2P
4539 if (info) {
4540 wpas_p2p_disassoc_notif(
4541 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4542 locally_generated);
4543 }
4544#endif /* CONFIG_P2P */
4545
4546 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4547 sme_event_disassoc(wpa_s, info);
4548
4549 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4550 ie, ie_len, 0);
4551}
4552
4553
4554static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4555 struct deauth_info *info)
4556{
4557 u16 reason_code = 0;
4558 int locally_generated = 0;
4559 const u8 *addr = NULL;
4560 const u8 *ie = NULL;
4561 size_t ie_len = 0;
4562
4563 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4564
4565 if (info) {
4566 addr = info->addr;
4567 ie = info->ie;
4568 ie_len = info->ie_len;
4569 reason_code = info->reason_code;
4570 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004571 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4572 reason_code, reason2str(reason_code),
4573 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004574 if (addr) {
4575 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4576 MAC2STR(addr));
4577 }
4578 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4579 ie, ie_len);
4580 }
4581
4582 wpa_reset_ft_completed(wpa_s->wpa);
4583
4584 wpas_event_disconnect(wpa_s, addr, reason_code,
4585 locally_generated, ie, ie_len, 1);
4586}
4587
4588
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004589static const char * reg_init_str(enum reg_change_initiator init)
4590{
4591 switch (init) {
4592 case REGDOM_SET_BY_CORE:
4593 return "CORE";
4594 case REGDOM_SET_BY_USER:
4595 return "USER";
4596 case REGDOM_SET_BY_DRIVER:
4597 return "DRIVER";
4598 case REGDOM_SET_BY_COUNTRY_IE:
4599 return "COUNTRY_IE";
4600 case REGDOM_BEACON_HINT:
4601 return "BEACON_HINT";
4602 }
4603 return "?";
4604}
4605
4606
4607static const char * reg_type_str(enum reg_type type)
4608{
4609 switch (type) {
4610 case REGDOM_TYPE_UNKNOWN:
4611 return "UNKNOWN";
4612 case REGDOM_TYPE_COUNTRY:
4613 return "COUNTRY";
4614 case REGDOM_TYPE_WORLD:
4615 return "WORLD";
4616 case REGDOM_TYPE_CUSTOM_WORLD:
4617 return "CUSTOM_WORLD";
4618 case REGDOM_TYPE_INTERSECTION:
4619 return "INTERSECTION";
4620 }
4621 return "?";
4622}
4623
4624
Hai Shalom74f70d42019-02-11 14:42:39 -08004625void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4626 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004627{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004628 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004629 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004630
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004631 /*
4632 * To allow backwards compatibility with higher level layers that
4633 * assumed the REGDOM_CHANGE event is sent over the initially added
4634 * interface. Find the highest parent of this interface and use it to
4635 * send the event.
4636 */
4637 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4638 ;
4639
Hai Shalom74f70d42019-02-11 14:42:39 -08004640 if (info) {
4641 wpa_msg(ifs, MSG_INFO,
4642 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4643 reg_init_str(info->initiator), reg_type_str(info->type),
4644 info->alpha2[0] ? " alpha2=" : "",
4645 info->alpha2[0] ? info->alpha2 : "");
4646 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004647
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004648 if (wpa_s->drv_priv == NULL)
4649 return; /* Ignore event during drv initialization */
4650
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004651 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4652 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004653 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4654 ifs->ifname);
4655 free_hw_features(ifs);
4656 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004657 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004658
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004659 /* Restart PNO/sched_scan with updated channel list */
4660 if (ifs->pno) {
4661 wpas_stop_pno(ifs);
4662 wpas_start_pno(ifs);
4663 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4664 wpa_dbg(ifs, MSG_DEBUG,
4665 "Channel list changed - restart sched_scan");
4666 wpas_scan_restart_sched_scan(ifs);
4667 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004668 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004669
4670 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004671}
4672
4673
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004674static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004675 const u8 *frame, size_t len, int freq,
4676 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004677{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004678 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004679 const u8 *payload;
4680 size_t plen;
4681 u8 category;
4682
4683 if (len < IEEE80211_HDRLEN + 2)
4684 return;
4685
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004686 mgmt = (const struct ieee80211_mgmt *) frame;
4687 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004688 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004689 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004690
4691 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4692 " Category=%u DataLen=%d freq=%d MHz",
4693 MAC2STR(mgmt->sa), category, (int) plen, freq);
4694
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004695 if (category == WLAN_ACTION_WMM) {
4696 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4697 return;
4698 }
4699
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004700#ifdef CONFIG_IEEE80211R
4701 if (category == WLAN_ACTION_FT) {
4702 ft_rx_action(wpa_s, payload, plen);
4703 return;
4704 }
4705#endif /* CONFIG_IEEE80211R */
4706
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004707#ifdef CONFIG_SME
4708 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004709 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004710 return;
4711 }
4712#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004713
4714#ifdef CONFIG_WNM
4715 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4716 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4717 return;
4718 }
4719#endif /* CONFIG_WNM */
4720
4721#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004722 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4723 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004724 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004725 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004726 payload, plen, freq) == 0)
4727 return;
4728#endif /* CONFIG_GAS */
4729
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004730#ifdef CONFIG_GAS_SERVER
4731 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4732 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4733 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4734 mgmt->u.action.category,
4735 payload, plen, freq) == 0)
4736 return;
4737#endif /* CONFIG_GAS_SERVER */
4738
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004739#ifdef CONFIG_TDLS
4740 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4741 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4742 wpa_dbg(wpa_s, MSG_DEBUG,
4743 "TDLS: Received Discovery Response from " MACSTR,
4744 MAC2STR(mgmt->sa));
4745 return;
4746 }
4747#endif /* CONFIG_TDLS */
4748
4749#ifdef CONFIG_INTERWORKING
4750 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4751 payload[0] == QOS_QOS_MAP_CONFIG) {
4752 const u8 *pos = payload + 1;
4753 size_t qlen = plen - 1;
4754 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4755 MACSTR, MAC2STR(mgmt->sa));
4756 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4757 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4758 pos[1] <= qlen - 2 && pos[1] >= 16)
4759 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4760 return;
4761 }
4762#endif /* CONFIG_INTERWORKING */
4763
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004764 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004765 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4766 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004767 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004768 payload + 1,
4769 plen - 1);
4770 return;
4771 }
4772
4773 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004774 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4775 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4776 return;
4777 }
4778
4779 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4780 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4781 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4782 payload + 1, plen - 1,
4783 rssi);
4784 return;
4785 }
4786
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004787#ifdef CONFIG_FST
4788 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4789 fst_rx_action(wpa_s->fst, mgmt, len);
4790 return;
4791 }
4792#endif /* CONFIG_FST */
4793
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004794#ifdef CONFIG_DPP
4795 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4796 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4797 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4798 payload[4] == DPP_OUI_TYPE) {
4799 payload++;
4800 plen--;
4801 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4802 return;
4803 }
4804#endif /* CONFIG_DPP */
4805
Hai Shalom899fcc72020-10-19 14:38:18 -07004806 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004807 payload[0] == ROBUST_AV_SCS_RESP) {
4808 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4809 payload + 1, plen - 1);
4810 return;
4811 }
4812
4813 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004814 payload[0] == ROBUST_AV_MSCS_RESP) {
4815 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4816 payload + 1, plen - 1);
4817 return;
4818 }
4819
Hai Shalomc1a21442022-02-04 13:43:00 -08004820 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4821 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4822 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4823 payload + 4, plen - 4);
4824 return;
4825 }
4826
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004827 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4828 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004829 if (wpa_s->ifmsh)
4830 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004831}
4832
4833
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004834static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4835 union wpa_event_data *event)
4836{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004837 struct wpa_freq_range_list *list;
4838 char *str = NULL;
4839
4840 list = &event->freq_range;
4841
4842 if (list->num)
4843 str = freq_range_list_str(list);
4844 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4845 str ? str : "");
4846
4847#ifdef CONFIG_P2P
4848 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4849 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4850 __func__);
4851 } else {
4852 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004853
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004854 /*
4855 * The update channel flow will also take care of moving a GO
4856 * from the unsafe frequency if needed.
4857 */
4858 wpas_p2p_update_channel_list(wpa_s,
4859 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004860 }
4861#endif /* CONFIG_P2P */
4862
4863 os_free(str);
4864}
4865
4866
Roshan Pius3a1667e2018-07-03 15:17:14 -07004867static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004868{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004869 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4870 wpa_supplicant_cancel_auth_timeout(wpa_s);
4871 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004872 eapol_sm_notify_portValid(wpa_s->eapol, true);
4873 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004874 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004875 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004876}
4877
4878
4879static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4880 int freq)
4881{
4882 size_t i;
4883 int j;
4884
4885 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4886 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4887
4888 for (j = 0; j < mode->num_channels; j++) {
4889 const struct hostapd_channel_data *chan;
4890
4891 chan = &mode->channels[j];
4892 if (chan->freq == freq)
4893 return chan->dfs_cac_ms;
4894 }
4895 }
4896
4897 return 0;
4898}
4899
4900
4901static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4902 struct dfs_event *radar)
4903{
4904#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004905 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004906 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4907 } else
4908#endif /* NEED_AP_MLME && CONFIG_AP */
4909 {
4910 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4911
4912 cac_time /= 1000; /* convert from ms to sec */
4913 if (!cac_time)
4914 cac_time = 10 * 60; /* max timeout: 10 minutes */
4915
4916 /* Restart auth timeout: CAC time added to initial timeout */
4917 wpas_auth_timeout_restart(wpa_s, cac_time);
4918 }
4919}
4920
4921
4922static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4923 struct dfs_event *radar)
4924{
4925#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004926 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004927 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4928 } else
4929#endif /* NEED_AP_MLME && CONFIG_AP */
4930 {
4931 /* Restart auth timeout with original value after CAC is
4932 * finished */
4933 wpas_auth_timeout_restart(wpa_s, 0);
4934 }
4935}
4936
4937
4938static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4939 struct dfs_event *radar)
4940{
4941#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004942 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004943 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4944 } else
4945#endif /* NEED_AP_MLME && CONFIG_AP */
4946 {
4947 /* Restart auth timeout with original value after CAC is
4948 * aborted */
4949 wpas_auth_timeout_restart(wpa_s, 0);
4950 }
4951}
4952
4953
4954static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4955 union wpa_event_data *data)
4956{
4957 wpa_dbg(wpa_s, MSG_DEBUG,
4958 "Connection authorized by device, previous state %d",
4959 wpa_s->wpa_state);
4960
4961 wpa_supplicant_event_port_authorized(wpa_s);
4962
Hai Shalomc1a21442022-02-04 13:43:00 -08004963 wpa_s->last_eapol_matches_bssid = 1;
4964
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004965 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4966 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004967 data->assoc_info.ptk_kck_len,
4968 data->assoc_info.ptk_kek,
4969 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004970#ifdef CONFIG_FILS
4971 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4972 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4973 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4974
4975 /* Update ERP next sequence number */
4976 eapol_sm_update_erp_next_seq_num(
4977 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4978
4979 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4980 /* Add the new PMK and PMKID to the PMKSA cache */
4981 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4982 data->assoc_info.fils_pmk,
4983 data->assoc_info.fils_pmk_len,
4984 data->assoc_info.fils_pmkid,
4985 wpa_s->bssid, fils_cache_id);
4986 } else if (data->assoc_info.fils_pmkid) {
4987 /* Update the current PMKSA used for this connection */
4988 pmksa_cache_set_current(wpa_s->wpa,
4989 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004990 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004991 }
4992 }
4993#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004994}
4995
4996
Hai Shalom60840252021-02-19 19:02:11 -08004997static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4998{
4999 switch (code) {
5000 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5001 return "";
5002 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5003 return "no_bss_found";
5004 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5005 return "auth_tx_fail";
5006 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5007 return "auth_no_ack_received";
5008 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5009 return "auth_no_resp_received";
5010 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5011 return "assoc_req_tx_fail";
5012 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5013 return "assoc_no_ack_received";
5014 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5015 return "assoc_no_resp_received";
5016 default:
5017 return "unknown_reason";
5018 }
5019}
5020
5021
Roshan Pius3a1667e2018-07-03 15:17:14 -07005022static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5023 union wpa_event_data *data)
5024{
5025 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005026#ifdef CONFIG_MBO
5027 struct wpa_bss *reject_bss;
5028#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005029
5030 if (!bssid || is_zero_ether_addr(bssid))
5031 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005032#ifdef CONFIG_MBO
5033 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5034 reject_bss = wpa_s->current_bss;
5035 else
5036 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5037#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005038
5039 if (data->assoc_reject.bssid)
5040 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005041 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005042 MAC2STR(data->assoc_reject.bssid),
5043 data->assoc_reject.status_code,
5044 data->assoc_reject.timed_out ? " timeout" : "",
5045 data->assoc_reject.timeout_reason ? "=" : "",
5046 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005047 data->assoc_reject.timeout_reason : "",
5048 data->assoc_reject.reason_code !=
5049 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5050 " qca_driver_reason=" : "",
5051 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005052 else
5053 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005054 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005055 data->assoc_reject.status_code,
5056 data->assoc_reject.timed_out ? " timeout" : "",
5057 data->assoc_reject.timeout_reason ? "=" : "",
5058 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005059 data->assoc_reject.timeout_reason : "",
5060 data->assoc_reject.reason_code !=
5061 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5062 " qca_driver_reason=" : "",
5063 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005064 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005065 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5066 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005067
5068#ifdef CONFIG_OWE
5069 if (data->assoc_reject.status_code ==
5070 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5071 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5072 wpa_s->current_ssid &&
5073 wpa_s->current_ssid->owe_group == 0 &&
5074 wpa_s->last_owe_group != 21) {
5075 struct wpa_ssid *ssid = wpa_s->current_ssid;
5076 struct wpa_bss *bss = wpa_s->current_bss;
5077
5078 if (!bss) {
5079 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5080 if (!bss) {
5081 wpas_connection_failed(wpa_s, bssid);
5082 wpa_supplicant_mark_disassoc(wpa_s);
5083 return;
5084 }
5085 }
5086 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5087 wpas_connect_work_done(wpa_s);
5088 wpa_supplicant_mark_disassoc(wpa_s);
5089 wpa_supplicant_connect(wpa_s, bss, ssid);
5090 return;
5091 }
5092#endif /* CONFIG_OWE */
5093
Hai Shalomfdcde762020-04-02 11:19:20 -07005094#ifdef CONFIG_DPP2
5095 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5096 * the status code defined in the DPP R2 tech spec.
5097 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5098 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005099 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005100 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5101 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5102 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005103 wpa_s->current_ssid->dpp_pfs == 0 &&
5104 (data->assoc_reject.status_code ==
5105 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5106 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5107 struct wpa_ssid *ssid = wpa_s->current_ssid;
5108 struct wpa_bss *bss = wpa_s->current_bss;
5109
5110 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5111 if (!bss)
5112 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5113 if (!bss || wpa_s->dpp_pfs_fallback) {
5114 wpa_printf(MSG_DEBUG,
5115 "DPP: Updated PFS policy for next try");
5116 wpas_connection_failed(wpa_s, bssid);
5117 wpa_supplicant_mark_disassoc(wpa_s);
5118 return;
5119 }
5120 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5121 wpa_s->dpp_pfs_fallback = 1;
5122 wpas_connect_work_done(wpa_s);
5123 wpa_supplicant_mark_disassoc(wpa_s);
5124 wpa_supplicant_connect(wpa_s, bss, ssid);
5125 return;
5126 }
5127#endif /* CONFIG_DPP2 */
5128
Hai Shalom74f70d42019-02-11 14:42:39 -08005129#ifdef CONFIG_MBO
5130 if (data->assoc_reject.status_code ==
5131 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005132 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005133 const u8 *rssi_rej;
5134
5135 rssi_rej = mbo_get_attr_from_ies(
5136 data->assoc_reject.resp_ies,
5137 data->assoc_reject.resp_ies_len,
5138 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5139 if (rssi_rej && rssi_rej[1] == 2) {
5140 wpa_printf(MSG_DEBUG,
5141 "OCE: RSSI-based association rejection from "
5142 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005143 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005144 rssi_rej[2], rssi_rej[3]);
5145 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005146 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005147 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005148 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005149 }
5150 }
5151#endif /* CONFIG_MBO */
5152
Roshan Pius3a1667e2018-07-03 15:17:14 -07005153 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5154 sme_event_assoc_reject(wpa_s, data);
5155 return;
5156 }
5157
5158 /* Driver-based SME cases */
5159
5160#ifdef CONFIG_SAE
5161 if (wpa_s->current_ssid &&
5162 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5163 !data->assoc_reject.timed_out) {
5164 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5165 wpa_sm_aborted_cached(wpa_s->wpa);
5166 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5167 }
5168#endif /* CONFIG_SAE */
5169
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005170#ifdef CONFIG_DPP
5171 if (wpa_s->current_ssid &&
5172 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5173 !data->assoc_reject.timed_out) {
5174 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5175 wpa_sm_aborted_cached(wpa_s->wpa);
5176 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5177 }
5178#endif /* CONFIG_DPP */
5179
Roshan Pius3a1667e2018-07-03 15:17:14 -07005180#ifdef CONFIG_FILS
5181 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005182 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005183 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005184 eapol_sm_update_erp_next_seq_num(
5185 wpa_s->eapol,
5186 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005187 fils_connection_failure(wpa_s);
5188 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005189#endif /* CONFIG_FILS */
5190
5191 wpas_connection_failed(wpa_s, bssid);
5192 wpa_supplicant_mark_disassoc(wpa_s);
5193}
5194
5195
Hai Shalomfdcde762020-04-02 11:19:20 -07005196static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5197 struct unprot_beacon *data)
5198{
5199 struct wpabuf *buf;
5200 int res;
5201
5202 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5203 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5204 return;
5205 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5206 MAC2STR(data->sa));
5207
5208 buf = wpabuf_alloc(4);
5209 if (!buf)
5210 return;
5211
5212 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5213 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5214 wpabuf_put_u8(buf, 1); /* Dialog Token */
5215 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5216
5217 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5218 wpa_s->own_addr, wpa_s->bssid,
5219 wpabuf_head(buf), wpabuf_len(buf), 0);
5220 if (res < 0)
5221 wpa_printf(MSG_DEBUG,
5222 "Failed to send WNM-Notification Request frame");
5223
5224 wpabuf_free(buf);
5225}
5226
5227
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005228void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5229 union wpa_event_data *data)
5230{
5231 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005232 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005233 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005234#ifndef CONFIG_NO_STDOUT_DEBUG
5235 int level = MSG_DEBUG;
5236#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005237
5238 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5239 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005240 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005241 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005242 event != EVENT_SCHED_SCAN_STOPPED) {
5243 wpa_dbg(wpa_s, MSG_DEBUG,
5244 "Ignore event %s (%d) while interface is disabled",
5245 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005246 return;
5247 }
5248
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005249#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005250 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005251 const struct ieee80211_hdr *hdr;
5252 u16 fc;
5253 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5254 fc = le_to_host16(hdr->frame_control);
5255 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5256 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5257 level = MSG_EXCESSIVE;
5258 }
5259
5260 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5261 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005262#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005263
5264 switch (event) {
5265 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005266#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005267 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5268 data->auth.ies_len))
5269 wpa_printf(MSG_DEBUG,
5270 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005271#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005272 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005273 wpa_s->auth_status_code = data->auth.status_code;
5274 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005275 break;
5276 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005277#ifdef CONFIG_TESTING_OPTIONS
5278 if (wpa_s->ignore_auth_resp) {
5279 wpa_printf(MSG_INFO,
5280 "EVENT_ASSOC - ignore_auth_resp active!");
5281 break;
5282 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005283 if (wpa_s->testing_resend_assoc) {
5284 wpa_printf(MSG_INFO,
5285 "EVENT_DEAUTH - testing_resend_assoc");
5286 break;
5287 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005288#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305289 if (wpa_s->disconnected) {
5290 wpa_printf(MSG_INFO,
5291 "Ignore unexpected EVENT_ASSOC in disconnected state");
5292 break;
5293 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005294 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005295 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005296 if (data &&
5297 (data->assoc_info.authorized ||
5298 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5299 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005300 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005301 if (data) {
5302 wpa_msg(wpa_s, MSG_INFO,
5303 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5304 data->assoc_info.subnet_status);
5305 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005306 break;
5307 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005308 wpas_event_disassoc(wpa_s,
5309 data ? &data->disassoc_info : NULL);
5310 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005311 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005312#ifdef CONFIG_TESTING_OPTIONS
5313 if (wpa_s->ignore_auth_resp) {
5314 wpa_printf(MSG_INFO,
5315 "EVENT_DEAUTH - ignore_auth_resp active!");
5316 break;
5317 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005318 if (wpa_s->testing_resend_assoc) {
5319 wpa_printf(MSG_INFO,
5320 "EVENT_DEAUTH - testing_resend_assoc");
5321 break;
5322 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005323#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005324 wpas_event_deauth(wpa_s,
5325 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005326 break;
5327 case EVENT_MICHAEL_MIC_FAILURE:
5328 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5329 break;
5330#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005331 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005332 if (wpa_s->own_scan_requested ||
5333 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005334 struct os_reltime diff;
5335
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005336 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005337 os_reltime_sub(&wpa_s->scan_start_time,
5338 &wpa_s->scan_trigger_time, &diff);
5339 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5340 diff.sec, diff.usec);
5341 wpa_s->own_scan_requested = 0;
5342 wpa_s->own_scan_running = 1;
5343 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5344 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005345 wpa_msg_ctrl(wpa_s, MSG_INFO,
5346 WPA_EVENT_SCAN_STARTED "id=%u",
5347 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005348 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005349 wpa_msg_ctrl(wpa_s, MSG_INFO,
5350 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005351 }
5352 } else {
5353 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005354 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005355 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005356 }
5357 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005358 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005359 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5360 wpa_s->scan_res_handler = NULL;
5361 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005362 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005363 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5364 break;
5365 }
5366
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005367 if (!(data && data->scan_info.external_scan) &&
5368 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005369 struct os_reltime now, diff;
5370 os_get_reltime(&now);
5371 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5372 wpa_s->scan_start_time.sec = 0;
5373 wpa_s->scan_start_time.usec = 0;
5374 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5375 diff.sec, diff.usec);
5376 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005377 if (wpa_supplicant_event_scan_results(wpa_s, data))
5378 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005379 if (!(data && data->scan_info.external_scan))
5380 wpa_s->own_scan_running = 0;
5381 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005382 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005383 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005384 break;
5385#endif /* CONFIG_NO_SCAN_PROCESSING */
5386 case EVENT_ASSOCINFO:
5387 wpa_supplicant_event_associnfo(wpa_s, data);
5388 break;
5389 case EVENT_INTERFACE_STATUS:
5390 wpa_supplicant_event_interface_status(wpa_s, data);
5391 break;
5392 case EVENT_PMKID_CANDIDATE:
5393 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5394 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005395#ifdef CONFIG_TDLS
5396 case EVENT_TDLS:
5397 wpa_supplicant_event_tdls(wpa_s, data);
5398 break;
5399#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005400#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005401 case EVENT_WNM:
5402 wpa_supplicant_event_wnm(wpa_s, data);
5403 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005404#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005405#ifdef CONFIG_IEEE80211R
5406 case EVENT_FT_RESPONSE:
5407 wpa_supplicant_event_ft_response(wpa_s, data);
5408 break;
5409#endif /* CONFIG_IEEE80211R */
5410#ifdef CONFIG_IBSS_RSN
5411 case EVENT_IBSS_RSN_START:
5412 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5413 break;
5414#endif /* CONFIG_IBSS_RSN */
5415 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005416 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005417 break;
5418 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005419 /* It is possible to get this event from earlier connection */
5420 if (wpa_s->current_ssid &&
5421 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5422 wpa_dbg(wpa_s, MSG_DEBUG,
5423 "Ignore AUTH_TIMED_OUT in mesh configuration");
5424 break;
5425 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005426 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5427 sme_event_auth_timed_out(wpa_s, data);
5428 break;
5429 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005430 /* It is possible to get this event from earlier connection */
5431 if (wpa_s->current_ssid &&
5432 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5433 wpa_dbg(wpa_s, MSG_DEBUG,
5434 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5435 break;
5436 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005437 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5438 sme_event_assoc_timed_out(wpa_s, data);
5439 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005440 case EVENT_TX_STATUS:
5441 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5442 " type=%d stype=%d",
5443 MAC2STR(data->tx_status.dst),
5444 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005445#ifdef CONFIG_PASN
5446 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5447 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5448 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5449 data->tx_status.data_len,
5450 data->tx_status.ack) == 0)
5451 break;
5452#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005453#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005454 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005455#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005456 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5457 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005458 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005459 wpa_s, data->tx_status.dst,
5460 data->tx_status.data,
5461 data->tx_status.data_len,
5462 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005463 OFFCHANNEL_SEND_ACTION_SUCCESS :
5464 OFFCHANNEL_SEND_ACTION_NO_ACK);
5465#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005466 break;
5467 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005468#endif /* CONFIG_AP */
5469#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005470 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005471 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005472 /*
5473 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005474 * interface in GO mode, or via standalone AP interface.
5475 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5476 * except when the primary interface is used as a GO interface
5477 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005478 */
5479 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5480 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005481 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005482 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005483 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005484 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005485 data->tx_status.data,
5486 data->tx_status.data_len,
5487 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005488 OFFCHANNEL_SEND_ACTION_SUCCESS :
5489 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005490 break;
5491 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005492#endif /* CONFIG_OFFCHANNEL */
5493#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005494 switch (data->tx_status.type) {
5495 case WLAN_FC_TYPE_MGMT:
5496 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5497 data->tx_status.data_len,
5498 data->tx_status.stype,
5499 data->tx_status.ack);
5500 break;
5501 case WLAN_FC_TYPE_DATA:
5502 ap_tx_status(wpa_s, data->tx_status.dst,
5503 data->tx_status.data,
5504 data->tx_status.data_len,
5505 data->tx_status.ack);
5506 break;
5507 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005508#endif /* CONFIG_AP */
5509 break;
5510#ifdef CONFIG_AP
5511 case EVENT_EAPOL_TX_STATUS:
5512 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5513 data->eapol_tx_status.data,
5514 data->eapol_tx_status.data_len,
5515 data->eapol_tx_status.ack);
5516 break;
5517 case EVENT_DRIVER_CLIENT_POLL_OK:
5518 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005519 break;
5520 case EVENT_RX_FROM_UNKNOWN:
5521 if (wpa_s->ap_iface == NULL)
5522 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005523 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5524 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005525 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005526#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005527
Sunil Ravi89eba102022-09-13 21:04:37 -07005528 case EVENT_LINK_CH_SWITCH_STARTED:
5529 case EVENT_LINK_CH_SWITCH:
5530 if (!data || !wpa_s->current_ssid ||
5531 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
5532 break;
5533
5534 wpa_msg(wpa_s, MSG_INFO,
5535 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5536 event == EVENT_LINK_CH_SWITCH ?
5537 WPA_EVENT_LINK_CHANNEL_SWITCH :
5538 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
5539 data->ch_switch.freq,
5540 data->ch_switch.link_id,
5541 data->ch_switch.ht_enabled,
5542 data->ch_switch.ch_offset,
5543 channel_width_to_string(data->ch_switch.ch_width),
5544 data->ch_switch.cf1,
5545 data->ch_switch.cf2);
5546 if (event == EVENT_LINK_CH_SWITCH_STARTED)
5547 break;
5548
5549 wpa_s->links[data->ch_switch.link_id].freq =
5550 data->ch_switch.freq;
5551 if (wpa_s->links[data->ch_switch.link_id].bss &&
5552 wpa_s->links[data->ch_switch.link_id].bss->freq !=
5553 data->ch_switch.freq) {
5554 wpa_s->links[data->ch_switch.link_id].bss->freq =
5555 data->ch_switch.freq;
5556 notify_bss_changes(
5557 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5558 wpa_s->links[data->ch_switch.link_id].bss);
5559 }
5560 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07005561 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005562 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005563 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005564 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005565
Hai Shalom81f62d82019-07-22 12:10:00 -07005566 wpa_msg(wpa_s, MSG_INFO,
5567 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5568 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5569 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005570 data->ch_switch.freq,
5571 data->ch_switch.ht_enabled,
5572 data->ch_switch.ch_offset,
5573 channel_width_to_string(data->ch_switch.ch_width),
5574 data->ch_switch.cf1,
5575 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005576 if (event == EVENT_CH_SWITCH_STARTED)
5577 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005578
Sunil Ravi65a724b2022-05-24 11:06:09 -07005579 if (wpa_s->assoc_freq && data->ch_switch.freq &&
5580 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
5581 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
5582 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005583 wpa_s->assoc_freq = data->ch_switch.freq;
5584 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005585 if (wpa_s->current_bss &&
5586 wpa_s->current_bss->freq != data->ch_switch.freq) {
5587 wpa_s->current_bss->freq = data->ch_switch.freq;
5588 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5589 wpa_s->current_bss);
5590 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005591
Hai Shalomfdcde762020-04-02 11:19:20 -07005592#ifdef CONFIG_SME
5593 switch (data->ch_switch.ch_offset) {
5594 case 1:
5595 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5596 break;
5597 case -1:
5598 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5599 break;
5600 default:
5601 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5602 break;
5603 }
5604#endif /* CONFIG_SME */
5605
Roshan Pius3a1667e2018-07-03 15:17:14 -07005606#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005607 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5608 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005609 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005610 wpa_s->current_ssid->mode ==
5611 WPAS_MODE_P2P_GROUP_FORMATION) {
5612 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5613 data->ch_switch.ht_enabled,
5614 data->ch_switch.ch_offset,
5615 data->ch_switch.ch_width,
5616 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005617 data->ch_switch.cf2,
5618 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005619 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005620#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005621
Hai Shalom899fcc72020-10-19 14:38:18 -07005622 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5623 sme_event_ch_switch(wpa_s);
5624
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005625 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005626 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005627 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005628#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005629#ifdef NEED_AP_MLME
5630 case EVENT_DFS_RADAR_DETECTED:
5631 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005632 wpas_ap_event_dfs_radar_detected(wpa_s,
5633 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005634 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005635 case EVENT_DFS_NOP_FINISHED:
5636 if (data)
5637 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5638 &data->dfs_event);
5639 break;
5640#endif /* NEED_AP_MLME */
5641#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005642 case EVENT_DFS_CAC_STARTED:
5643 if (data)
5644 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5645 break;
5646 case EVENT_DFS_CAC_FINISHED:
5647 if (data)
5648 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5649 break;
5650 case EVENT_DFS_CAC_ABORTED:
5651 if (data)
5652 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5653 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005654 case EVENT_RX_MGMT: {
5655 u16 fc, stype;
5656 const struct ieee80211_mgmt *mgmt;
5657
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005658#ifdef CONFIG_TESTING_OPTIONS
5659 if (wpa_s->ext_mgmt_frame_handling) {
5660 struct rx_mgmt *rx = &data->rx_mgmt;
5661 size_t hex_len = 2 * rx->frame_len + 1;
5662 char *hex = os_malloc(hex_len);
5663 if (hex) {
5664 wpa_snprintf_hex(hex, hex_len,
5665 rx->frame, rx->frame_len);
5666 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5667 rx->freq, rx->datarate, rx->ssi_signal,
5668 hex);
5669 os_free(hex);
5670 }
5671 break;
5672 }
5673#endif /* CONFIG_TESTING_OPTIONS */
5674
Dmitry Shmidt04949592012-07-19 12:16:46 -07005675 mgmt = (const struct ieee80211_mgmt *)
5676 data->rx_mgmt.frame;
5677 fc = le_to_host16(mgmt->frame_control);
5678 stype = WLAN_FC_GET_STYPE(fc);
5679
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005680#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005681 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005682#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005683#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005684 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005685 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005686 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005687 const u8 *ie;
5688 size_t ie_len;
5689
5690 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5691 ie_len = data->rx_mgmt.frame_len -
5692 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005693 wpas_p2p_probe_req_rx(
5694 wpa_s, src, mgmt->da,
5695 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005696 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005697 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005698 break;
5699 }
5700#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005701#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005702 if (wpa_s->current_ssid &&
5703 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5704 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005705 data->rx_mgmt.frame_len >= 30) {
5706 wpa_supplicant_event_ibss_auth(wpa_s, data);
5707 break;
5708 }
5709#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005710
5711 if (stype == WLAN_FC_STYPE_ACTION) {
5712 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005713 wpa_s, data->rx_mgmt.frame,
5714 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005715 data->rx_mgmt.freq,
5716 data->rx_mgmt.ssi_signal);
5717 break;
5718 }
5719
5720 if (wpa_s->ifmsh) {
5721 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005722 break;
5723 }
Hai Shalom60840252021-02-19 19:02:11 -08005724#ifdef CONFIG_PASN
5725 if (stype == WLAN_FC_STYPE_AUTH &&
5726 wpas_pasn_auth_rx(wpa_s, mgmt,
5727 data->rx_mgmt.frame_len) != -2)
5728 break;
5729#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005730
Roshan Pius3a1667e2018-07-03 15:17:14 -07005731#ifdef CONFIG_SAE
5732 if (stype == WLAN_FC_STYPE_AUTH &&
5733 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5734 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5735 sme_external_auth_mgmt_rx(
5736 wpa_s, data->rx_mgmt.frame,
5737 data->rx_mgmt.frame_len);
5738 break;
5739 }
5740#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005741 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5742 "management frame in non-AP mode");
5743 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005744#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005745 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005746
5747 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005748 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5749 const u8 *ie;
5750 size_t ie_len;
5751
5752 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5753 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005754
5755 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5756 mgmt->bssid, ie, ie_len,
5757 data->rx_mgmt.ssi_signal);
5758 }
5759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005760 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005761#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005762 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005763 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005764 case EVENT_RX_PROBE_REQ:
5765 if (data->rx_probe_req.sa == NULL ||
5766 data->rx_probe_req.ie == NULL)
5767 break;
5768#ifdef CONFIG_AP
5769 if (wpa_s->ap_iface) {
5770 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5771 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005772 data->rx_probe_req.da,
5773 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005774 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005775 data->rx_probe_req.ie_len,
5776 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005777 break;
5778 }
5779#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005780 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005781 data->rx_probe_req.da,
5782 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005783 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005784 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005785 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005786 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005787 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005788 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005789#ifdef CONFIG_OFFCHANNEL
5790 offchannel_remain_on_channel_cb(
5791 wpa_s, data->remain_on_channel.freq,
5792 data->remain_on_channel.duration);
5793#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005794 wpas_p2p_remain_on_channel_cb(
5795 wpa_s, data->remain_on_channel.freq,
5796 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005797#ifdef CONFIG_DPP
5798 wpas_dpp_remain_on_channel_cb(
5799 wpa_s, data->remain_on_channel.freq,
5800 data->remain_on_channel.duration);
5801#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005802 break;
5803 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005804#ifdef CONFIG_OFFCHANNEL
5805 offchannel_cancel_remain_on_channel_cb(
5806 wpa_s, data->remain_on_channel.freq);
5807#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005808 wpas_p2p_cancel_remain_on_channel_cb(
5809 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005810#ifdef CONFIG_DPP
5811 wpas_dpp_cancel_remain_on_channel_cb(
5812 wpa_s, data->remain_on_channel.freq);
5813#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005814 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005815 case EVENT_EAPOL_RX:
5816 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5817 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00005818 data->eapol_rx.data_len,
5819 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005820 break;
5821 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005822 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5823 "above=%d signal=%d noise=%d txrate=%d",
5824 data->signal_change.above_threshold,
5825 data->signal_change.current_signal,
5826 data->signal_change.current_noise,
5827 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005828 wpa_bss_update_level(wpa_s->current_bss,
5829 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005830 bgscan_notify_signal_change(
5831 wpa_s, data->signal_change.above_threshold,
5832 data->signal_change.current_signal,
5833 data->signal_change.current_noise,
5834 data->signal_change.current_txrate);
5835 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005836 case EVENT_INTERFACE_MAC_CHANGED:
5837 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005838 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005839 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005840 case EVENT_INTERFACE_ENABLED:
5841 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5842 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005843 u8 addr[ETH_ALEN];
5844
Hai Shalomfdcde762020-04-02 11:19:20 -07005845 eloop_cancel_timeout(wpas_clear_disabled_interface,
5846 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005847 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005848 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005849 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5850 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5851 else
5852 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005853 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005854 if (wpa_s->p2p_mgmt) {
5855 wpa_supplicant_set_state(wpa_s,
5856 WPA_DISCONNECTED);
5857 break;
5858 }
5859
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005860#ifdef CONFIG_AP
5861 if (!wpa_s->ap_iface) {
5862 wpa_supplicant_set_state(wpa_s,
5863 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005864 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005865 wpa_supplicant_req_scan(wpa_s, 0, 0);
5866 } else
5867 wpa_supplicant_set_state(wpa_s,
5868 WPA_COMPLETED);
5869#else /* CONFIG_AP */
5870 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5871 wpa_supplicant_req_scan(wpa_s, 0, 0);
5872#endif /* CONFIG_AP */
5873 }
5874 break;
5875 case EVENT_INTERFACE_DISABLED:
5876 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005877#ifdef CONFIG_P2P
5878 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5879 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5880 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5881 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005882 * Mark interface disabled if this happens to end up not
5883 * being removed as a separate P2P group interface.
5884 */
5885 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5886 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005887 * The interface was externally disabled. Remove
5888 * it assuming an external entity will start a
5889 * new session if needed.
5890 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005891 if (wpa_s->current_ssid &&
5892 wpa_s->current_ssid->p2p_group)
5893 wpas_p2p_interface_unavailable(wpa_s);
5894 else
5895 wpas_p2p_disconnect(wpa_s);
5896 /*
5897 * wpa_s instance may have been freed, so must not use
5898 * it here anymore.
5899 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005900 break;
5901 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005902 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5903 p2p_in_progress(wpa_s->global->p2p) > 1) {
5904 /* This radio work will be cancelled, so clear P2P
5905 * state as well.
5906 */
5907 p2p_stop_find(wpa_s->global->p2p);
5908 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005909#endif /* CONFIG_P2P */
5910
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005911 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5912 /*
5913 * Indicate disconnection to keep ctrl_iface events
5914 * consistent.
5915 */
5916 wpa_supplicant_event_disassoc(
5917 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5918 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005919 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005920 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005921 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5922 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005923 clear_at.usec = 0;
5924 } else {
5925 struct os_reltime tmp;
5926
Hai Shalom60840252021-02-19 19:02:11 -08005927 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005928 tmp.usec = 0;
5929 os_reltime_sub(&tmp, &age, &clear_at);
5930 }
5931 eloop_register_timeout(clear_at.sec, clear_at.usec,
5932 wpas_clear_disabled_interface,
5933 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005934 radio_remove_works(wpa_s, NULL, 0);
5935
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005936 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5937 break;
5938 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005939 wpa_supplicant_update_channel_list(
5940 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005941 break;
5942 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005943 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005944 break;
5945 case EVENT_BEST_CHANNEL:
5946 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5947 "(%d %d %d)",
5948 data->best_chan.freq_24, data->best_chan.freq_5,
5949 data->best_chan.freq_overall);
5950 wpa_s->best_24_freq = data->best_chan.freq_24;
5951 wpa_s->best_5_freq = data->best_chan.freq_5;
5952 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005953 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5954 data->best_chan.freq_5,
5955 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005956 break;
5957 case EVENT_UNPROT_DEAUTH:
5958 wpa_supplicant_event_unprot_deauth(wpa_s,
5959 &data->unprot_deauth);
5960 break;
5961 case EVENT_UNPROT_DISASSOC:
5962 wpa_supplicant_event_unprot_disassoc(wpa_s,
5963 &data->unprot_disassoc);
5964 break;
5965 case EVENT_STATION_LOW_ACK:
5966#ifdef CONFIG_AP
5967 if (wpa_s->ap_iface && data)
5968 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5969 data->low_ack.addr);
5970#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005971#ifdef CONFIG_TDLS
5972 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005973 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5974 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005975#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005976 break;
5977 case EVENT_IBSS_PEER_LOST:
5978#ifdef CONFIG_IBSS_RSN
5979 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5980#endif /* CONFIG_IBSS_RSN */
5981 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005982 case EVENT_DRIVER_GTK_REKEY:
5983 if (os_memcmp(data->driver_gtk_rekey.bssid,
5984 wpa_s->bssid, ETH_ALEN))
5985 break;
5986 if (!wpa_s->wpa)
5987 break;
5988 wpa_sm_update_replay_ctr(wpa_s->wpa,
5989 data->driver_gtk_rekey.replay_ctr);
5990 break;
5991 case EVENT_SCHED_SCAN_STOPPED:
5992 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005993 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005994 wpa_supplicant_notify_scanning(wpa_s, 0);
5995
5996 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5997 break;
5998
5999 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08006000 * If the driver stopped scanning without being requested to,
6001 * request a new scan to continue scanning for networks.
6002 */
6003 if (!wpa_s->sched_scan_stop_req &&
6004 wpa_s->wpa_state == WPA_SCANNING) {
6005 wpa_dbg(wpa_s, MSG_DEBUG,
6006 "Restart scanning after unexpected sched_scan stop event");
6007 wpa_supplicant_req_scan(wpa_s, 1, 0);
6008 break;
6009 }
6010
6011 wpa_s->sched_scan_stop_req = 0;
6012
6013 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006014 * Start a new sched scan to continue searching for more SSIDs
6015 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006016 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006017 if (wpa_s->sched_scan_timed_out) {
6018 wpa_supplicant_req_sched_scan(wpa_s);
6019 } else if (wpa_s->pno_sched_pending) {
6020 wpa_s->pno_sched_pending = 0;
6021 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006022 } else if (resched) {
6023 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006024 }
6025
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006026 break;
6027 case EVENT_WPS_BUTTON_PUSHED:
6028#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006029 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006030#endif /* CONFIG_WPS */
6031 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006032 case EVENT_AVOID_FREQUENCIES:
6033 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6034 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006035 case EVENT_CONNECT_FAILED_REASON:
6036#ifdef CONFIG_AP
6037 if (!wpa_s->ap_iface || !data)
6038 break;
6039 hostapd_event_connect_failed_reason(
6040 wpa_s->ap_iface->bss[0],
6041 data->connect_failed_reason.addr,
6042 data->connect_failed_reason.code);
6043#endif /* CONFIG_AP */
6044 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006045 case EVENT_NEW_PEER_CANDIDATE:
6046#ifdef CONFIG_MESH
6047 if (!wpa_s->ifmsh || !data)
6048 break;
6049 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6050 data->mesh_peer.ies,
6051 data->mesh_peer.ie_len);
6052#endif /* CONFIG_MESH */
6053 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006054 case EVENT_SURVEY:
6055#ifdef CONFIG_AP
6056 if (!wpa_s->ap_iface)
6057 break;
6058 hostapd_event_get_survey(wpa_s->ap_iface,
6059 &data->survey_results);
6060#endif /* CONFIG_AP */
6061 break;
6062 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006063#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006064#ifdef CONFIG_ACS
6065 if (!wpa_s->ap_iface)
6066 break;
6067 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6068 &data->acs_selected_channels);
6069#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006070#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006071 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006072 case EVENT_P2P_LO_STOP:
6073#ifdef CONFIG_P2P
6074 wpa_s->p2p_lo_started = 0;
6075 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6076 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6077 data->p2p_lo_stop.reason_code);
6078#endif /* CONFIG_P2P */
6079 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006080 case EVENT_BEACON_LOSS:
6081 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6082 break;
6083 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6084 bgscan_notify_beacon_loss(wpa_s);
6085 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006086 case EVENT_EXTERNAL_AUTH:
6087#ifdef CONFIG_SAE
6088 if (!wpa_s->current_ssid) {
6089 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6090 break;
6091 }
6092 sme_external_auth_trigger(wpa_s, data);
6093#endif /* CONFIG_SAE */
6094 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006095#ifdef CONFIG_PASN
6096 case EVENT_PASN_AUTH:
6097 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6098 break;
6099#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006100 case EVENT_PORT_AUTHORIZED:
6101 wpa_supplicant_event_port_authorized(wpa_s);
6102 break;
6103 case EVENT_STATION_OPMODE_CHANGED:
6104#ifdef CONFIG_AP
6105 if (!wpa_s->ap_iface || !data)
6106 break;
6107
6108 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6109 data->sta_opmode.addr,
6110 data->sta_opmode.smps_mode,
6111 data->sta_opmode.chan_width,
6112 data->sta_opmode.rx_nss);
6113#endif /* CONFIG_AP */
6114 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07006115 case EVENT_UNPROT_BEACON:
6116 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6117 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08006118 case EVENT_TX_WAIT_EXPIRE:
6119#ifdef CONFIG_DPP
6120 wpas_dpp_tx_wait_expire(wpa_s);
6121#endif /* CONFIG_DPP */
6122 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006123 default:
6124 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6125 break;
6126 }
6127}
Dmitry Shmidte4663042016-04-04 10:07:49 -07006128
6129
6130void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6131 union wpa_event_data *data)
6132{
6133 struct wpa_supplicant *wpa_s;
6134
6135 if (event != EVENT_INTERFACE_STATUS)
6136 return;
6137
6138 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6139 if (wpa_s && wpa_s->driver->get_ifindex) {
6140 unsigned int ifindex;
6141
6142 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6143 if (ifindex != data->interface_status.ifindex) {
6144 wpa_dbg(wpa_s, MSG_DEBUG,
6145 "interface status ifindex %d mismatch (%d)",
6146 ifindex, data->interface_status.ifindex);
6147 return;
6148 }
6149 }
6150#ifdef CONFIG_MATCH_IFACE
6151 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6152 struct wpa_interface *wpa_i;
6153
6154 wpa_i = wpa_supplicant_match_iface(
6155 ctx, data->interface_status.ifname);
6156 if (!wpa_i)
6157 return;
6158 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6159 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006160 }
6161#endif /* CONFIG_MATCH_IFACE */
6162
6163 if (wpa_s)
6164 wpa_supplicant_event(wpa_s, event, data);
6165}