blob: 1ec7d5ebf81adf87c71a19a26dcbc81bd228a701 [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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
172{
173 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700174 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700175 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700176 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700177
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700178 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700179 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700180
181 if (wpa_s->current_ssid->ssid_len == 0)
182 return 0; /* current profile still in use */
183 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
184 if (res < 0) {
185 wpa_msg(wpa_s, MSG_INFO,
186 "Failed to read SSID from driver");
187 return 0; /* try to use current profile */
188 }
189 drv_ssid_len = res;
190
191 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
192 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
193 drv_ssid_len) == 0)
194 return 0; /* current profile still in use */
195
Hai Shalomfdcde762020-04-02 11:19:20 -0700196#ifdef CONFIG_OWE
197 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
198 wpa_s->current_bss &&
199 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
200 drv_ssid_len == wpa_s->current_bss->ssid_len &&
201 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
202 drv_ssid_len) == 0)
203 return 0; /* current profile still in use */
204#endif /* CONFIG_OWE */
205
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700206 wpa_msg(wpa_s, MSG_DEBUG,
207 "Driver-initiated BSS selection changed the SSID to %s",
208 wpa_ssid_txt(drv_ssid, drv_ssid_len));
209 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700210 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211
212 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
213 "information");
214 ssid = wpa_supplicant_get_ssid(wpa_s);
215 if (ssid == NULL) {
216 wpa_msg(wpa_s, MSG_INFO,
217 "No network configuration found for the current AP");
218 return -1;
219 }
220
Dmitry Shmidt04949592012-07-19 12:16:46 -0700221 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
223 return -1;
224 }
225
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800226 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
227 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
228 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
229 return -1;
230 }
231
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700232 res = wpas_temp_disabled(wpa_s, ssid);
233 if (res > 0) {
234 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
235 "disabled for %d second(s)", res);
236 return -1;
237 }
238
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
240 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800241 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242 u8 wpa_ie[80];
243 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800244 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
245 wpa_ie, &wpa_ie_len) < 0)
246 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700247 } else {
248 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
249 }
250
251 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
252 eapol_sm_invalidate_cached_session(wpa_s->eapol);
253 old_ssid = wpa_s->current_ssid;
254 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800255
Sunil Ravia04bd252022-05-02 22:54:18 -0700256 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800257
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
259 wpa_supplicant_initiate_eapol(wpa_s);
260 if (old_ssid != wpa_s->current_ssid)
261 wpas_notify_network_changed(wpa_s);
262
263 return 0;
264}
265
266
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800267void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268{
269 struct wpa_supplicant *wpa_s = eloop_ctx;
270
271 if (wpa_s->countermeasures) {
272 wpa_s->countermeasures = 0;
273 wpa_drv_set_countermeasures(wpa_s, 0);
274 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800275
276 /*
277 * It is possible that the device is sched scanning, which means
278 * that a connection attempt will be done only when we receive
279 * scan results. However, in this case, it would be preferable
280 * to scan and connect immediately, so cancel the sched_scan and
281 * issue a regular scan flow.
282 */
283 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700284 wpa_supplicant_req_scan(wpa_s, 0, 0);
285 }
286}
287
288
289void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
290{
291 int bssid_changed;
292
Dmitry Shmidt04949592012-07-19 12:16:46 -0700293 wnm_bss_keep_alive_deinit(wpa_s);
294
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700295#ifdef CONFIG_IBSS_RSN
296 ibss_rsn_deinit(wpa_s->ibss_rsn);
297 wpa_s->ibss_rsn = NULL;
298#endif /* CONFIG_IBSS_RSN */
299
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700300#ifdef CONFIG_AP
301 wpa_supplicant_ap_deinit(wpa_s);
302#endif /* CONFIG_AP */
303
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700304#ifdef CONFIG_HS20
305 /* Clear possibly configured frame filters */
306 wpa_drv_configure_frame_filters(wpa_s, 0);
307#endif /* CONFIG_HS20 */
308
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700309 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
310 return;
311
Hai Shalom74f70d42019-02-11 14:42:39 -0800312 if (os_reltime_initialized(&wpa_s->session_start)) {
313 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
314 wpa_s->session_start.sec = 0;
315 wpa_s->session_start.usec = 0;
316 wpas_notify_session_length(wpa_s);
317 }
318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
320 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
321 os_memset(wpa_s->bssid, 0, ETH_ALEN);
322 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800323 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 wpa_s->current_bss = NULL;
325 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700326
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700327 if (bssid_changed)
328 wpas_notify_bssid_changed(wpa_s);
329
Hai Shalome21d4e82020-04-29 16:34:06 -0700330 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
331 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700332 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
333 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700334 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700335 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700336 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700338 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700339 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700340 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800341
342 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800343 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800344 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700345 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700346
347#ifdef CONFIG_TESTING_OPTIONS
348 wpa_s->last_tk_alg = WPA_ALG_NONE;
349 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
350#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700351 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800352
353 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
354 wpa_s->enabled_4addr_mode = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700355}
356
357
358static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
359{
360 struct wpa_ie_data ie;
361 int pmksa_set = -1;
362 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800363 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364
Hai Shalomc1a21442022-02-04 13:43:00 -0800365 /* Start with assumption of no PMKSA cache entry match for cases other
366 * than SAE. In particular, this is needed to generate the PMKSA cache
367 * entries for Suite B cases with driver-based roaming indication. */
368 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
369 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
370 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700372 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
373 ie.pmkid == NULL)
374 return;
375
376 for (i = 0; i < ie.num_pmkid; i++) {
377 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
378 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700379 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800381 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700382 break;
383 }
384 }
385
386 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
387 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
388}
389
390
391static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
392 union wpa_event_data *data)
393{
394 if (data == NULL) {
395 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
396 "event");
397 return;
398 }
399 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
400 " index=%d preauth=%d",
401 MAC2STR(data->pmkid_candidate.bssid),
402 data->pmkid_candidate.index,
403 data->pmkid_candidate.preauth);
404
405 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
406 data->pmkid_candidate.index,
407 data->pmkid_candidate.preauth);
408}
409
410
411static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
412{
413 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
414 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
415 return 0;
416
417#ifdef IEEE8021X_EAPOL
418 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
419 wpa_s->current_ssid &&
420 !(wpa_s->current_ssid->eapol_flags &
421 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
422 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
423 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
424 * plaintext or static WEP keys). */
425 return 0;
426 }
427#endif /* IEEE8021X_EAPOL */
428
429 return 1;
430}
431
432
433/**
434 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
435 * @wpa_s: pointer to wpa_supplicant data
436 * @ssid: Configuration data for the network
437 * Returns: 0 on success, -1 on failure
438 *
439 * This function is called when starting authentication with a network that is
440 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
441 */
442int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
443 struct wpa_ssid *ssid)
444{
445#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800446#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700447 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700448
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700449 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
450 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 return 0;
452
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700453 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454 sim = 1;
455 aka = 1;
456 } else {
457 struct eap_method_type *eap = ssid->eap.eap_methods;
458 while (eap->vendor != EAP_VENDOR_IETF ||
459 eap->method != EAP_TYPE_NONE) {
460 if (eap->vendor == EAP_VENDOR_IETF) {
461 if (eap->method == EAP_TYPE_SIM)
462 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700463 else if (eap->method == EAP_TYPE_AKA ||
464 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700465 aka = 1;
466 }
467 eap++;
468 }
469 }
470
471 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
472 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700473 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
474 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
475 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700476 aka = 0;
477
478 if (!sim && !aka) {
479 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
480 "use SIM, but neither EAP-SIM nor EAP-AKA are "
481 "enabled");
482 return 0;
483 }
484
485 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
486 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700488 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700489 if (wpa_s->scard == NULL) {
490 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
491 "(pcsc-lite)");
492 return -1;
493 }
494 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
495 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800496#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700497#endif /* IEEE8021X_EAPOL */
498
499 return 0;
500}
501
502
503#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700504
Hai Shalomfdcde762020-04-02 11:19:20 -0700505#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700506static int has_wep_key(struct wpa_ssid *ssid)
507{
508 int i;
509
510 for (i = 0; i < NUM_WEP_KEYS; i++) {
511 if (ssid->wep_key_len[i])
512 return 1;
513 }
514
515 return 0;
516}
Hai Shalomfdcde762020-04-02 11:19:20 -0700517#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700518
519
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700520static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521 struct wpa_ssid *ssid)
522{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700523 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700524
525 if (ssid->mixed_cell)
526 return 1;
527
528#ifdef CONFIG_WPS
529 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
530 return 1;
531#endif /* CONFIG_WPS */
532
Roshan Pius3a1667e2018-07-03 15:17:14 -0700533#ifdef CONFIG_OWE
534 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
535 return 1;
536#endif /* CONFIG_OWE */
537
Hai Shalomfdcde762020-04-02 11:19:20 -0700538#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700539 if (has_wep_key(ssid))
540 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700541#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700542
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543#ifdef IEEE8021X_EAPOL
544 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
545 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
546 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
547 privacy = 1;
548#endif /* IEEE8021X_EAPOL */
549
Jouni Malinen75ecf522011-06-27 15:19:46 -0700550 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
551 privacy = 1;
552
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800553 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
554 privacy = 1;
555
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556 if (bss->caps & IEEE80211_CAP_PRIVACY)
557 return privacy;
558 return !privacy;
559}
560
561
562static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
563 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800564 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700565{
566 struct wpa_ie_data ie;
567 int proto_match = 0;
568 const u8 *rsn_ie, *wpa_ie;
569 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700570#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700571 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700572#endif /* CONFIG_WEP */
Sunil Ravia04bd252022-05-02 22:54:18 -0700573 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574
575 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
576 if (ret >= 0)
577 return ret;
578
Hai Shalomfdcde762020-04-02 11:19:20 -0700579#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
581 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
582 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
583 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
584 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700585#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700586
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700587 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Sunil Ravia04bd252022-05-02 22:54:18 -0700588 if (is_6ghz_bss && !rsn_ie) {
589 if (debug_print)
590 wpa_dbg(wpa_s, MSG_DEBUG,
591 " skip - 6 GHz BSS without RSNE");
592 return 0;
593 }
594
Roshan Pius3a1667e2018-07-03 15:17:14 -0700595 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596 proto_match++;
597
598 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800599 if (debug_print)
600 wpa_dbg(wpa_s, MSG_DEBUG,
601 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602 break;
603 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700604 if (!ie.has_pairwise)
605 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
606 if (!ie.has_group)
607 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700608
Sunil Ravia04bd252022-05-02 22:54:18 -0700609 if (is_6ghz_bss) {
610 /* WEP and TKIP are not allowed on 6 GHz */
611 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
612 WPA_CIPHER_WEP104 |
613 WPA_CIPHER_TKIP);
614 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
615 WPA_CIPHER_WEP104 |
616 WPA_CIPHER_TKIP);
617 }
618
Hai Shalomfdcde762020-04-02 11:19:20 -0700619#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700620 if (wep_ok &&
621 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
622 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800623 if (debug_print)
624 wpa_dbg(wpa_s, MSG_DEBUG,
625 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700626 return 1;
627 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700628#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700629
Roshan Pius3a1667e2018-07-03 15:17:14 -0700630 if (!(ie.proto & ssid->proto) &&
631 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800632 if (debug_print)
633 wpa_dbg(wpa_s, MSG_DEBUG,
634 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700635 break;
636 }
637
638 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800639 if (debug_print)
640 wpa_dbg(wpa_s, MSG_DEBUG,
641 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642 break;
643 }
644
645 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800646 if (debug_print)
647 wpa_dbg(wpa_s, MSG_DEBUG,
648 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 break;
650 }
651
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700652 if (ssid->group_mgmt_cipher &&
653 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
654 if (debug_print)
655 wpa_dbg(wpa_s, MSG_DEBUG,
656 " skip RSN IE - group mgmt cipher mismatch");
657 break;
658 }
659
Sunil Ravia04bd252022-05-02 22:54:18 -0700660 if (is_6ghz_bss) {
661 /* MFPC must be supported on 6 GHz */
662 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
663 if (debug_print)
664 wpa_dbg(wpa_s, MSG_DEBUG,
665 " skip RSNE - 6 GHz without MFPC");
666 break;
667 }
668
669 /* WPA PSK is not allowed on the 6 GHz band */
670 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
671 WPA_KEY_MGMT_FT_PSK |
672 WPA_KEY_MGMT_PSK_SHA256);
673 }
674
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700675 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800676 if (debug_print)
677 wpa_dbg(wpa_s, MSG_DEBUG,
678 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679 break;
680 }
681
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800683 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800684 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800685 if (debug_print)
686 wpa_dbg(wpa_s, MSG_DEBUG,
687 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700688 break;
689 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800690 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
691 wpas_get_ssid_pmf(wpa_s, ssid) ==
692 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800693 if (debug_print)
694 wpa_dbg(wpa_s, MSG_DEBUG,
695 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800696 break;
697 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800699 if (debug_print)
700 wpa_dbg(wpa_s, MSG_DEBUG,
701 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700702 return 1;
703 }
704
Sunil Ravia04bd252022-05-02 22:54:18 -0700705 if (is_6ghz_bss) {
706 if (debug_print)
707 wpa_dbg(wpa_s, MSG_DEBUG,
708 " skip - 6 GHz BSS without matching RSNE");
709 return 0;
710 }
711
Roshan Pius3a1667e2018-07-03 15:17:14 -0700712 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
713 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800714 if (debug_print)
715 wpa_dbg(wpa_s, MSG_DEBUG,
716 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700717 return 0;
718 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700719
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700720 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
722 proto_match++;
723
724 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800725 if (debug_print)
726 wpa_dbg(wpa_s, MSG_DEBUG,
727 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728 break;
729 }
730
Hai Shalomfdcde762020-04-02 11:19:20 -0700731#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700732 if (wep_ok &&
733 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
734 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800735 if (debug_print)
736 wpa_dbg(wpa_s, MSG_DEBUG,
737 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700738 return 1;
739 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700740#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700741
742 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800743 if (debug_print)
744 wpa_dbg(wpa_s, MSG_DEBUG,
745 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700746 break;
747 }
748
749 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800750 if (debug_print)
751 wpa_dbg(wpa_s, MSG_DEBUG,
752 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700753 break;
754 }
755
756 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800757 if (debug_print)
758 wpa_dbg(wpa_s, MSG_DEBUG,
759 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760 break;
761 }
762
763 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800764 if (debug_print)
765 wpa_dbg(wpa_s, MSG_DEBUG,
766 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767 break;
768 }
769
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800770 if (debug_print)
771 wpa_dbg(wpa_s, MSG_DEBUG,
772 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 return 1;
774 }
775
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700776 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
777 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800778 if (debug_print)
779 wpa_dbg(wpa_s, MSG_DEBUG,
780 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700781 return 1;
782 }
783
Roshan Pius3a1667e2018-07-03 15:17:14 -0700784#ifdef CONFIG_OWE
785 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
786 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800787 if (wpa_s->owe_transition_select &&
788 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
789 ssid->owe_transition_bss_select_count + 1 <=
790 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
791 ssid->owe_transition_bss_select_count++;
792 if (debug_print)
793 wpa_dbg(wpa_s, MSG_DEBUG,
794 " skip OWE transition BSS (selection count %d does not exceed %d)",
795 ssid->owe_transition_bss_select_count,
796 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
797 wpa_s->owe_transition_search = 1;
798 return 0;
799 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700800 if (debug_print)
801 wpa_dbg(wpa_s, MSG_DEBUG,
802 " allow in OWE transition mode");
803 return 1;
804 }
805#endif /* CONFIG_OWE */
806
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
808 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800809 if (debug_print)
810 wpa_dbg(wpa_s, MSG_DEBUG,
811 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700812 return 0;
813 }
814
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800815 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
816 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800817 if (debug_print)
818 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800819 return 1;
820 }
821
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800823 if (debug_print)
824 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700825 return 1;
826 }
827
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800828 if (debug_print)
829 wpa_dbg(wpa_s, MSG_DEBUG,
830 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700831
832 return 0;
833}
834
835
836static int freq_allowed(int *freqs, int freq)
837{
838 int i;
839
840 if (freqs == NULL)
841 return 1;
842
843 for (i = 0; freqs[i]; i++)
844 if (freqs[i] == freq)
845 return 1;
846 return 0;
847}
848
849
Hai Shalomfdcde762020-04-02 11:19:20 -0700850static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
851 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800852{
853 const struct hostapd_hw_modes *mode = NULL, *modes;
854 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
855 const u8 *rate_ie;
856 int i, j, k;
857
858 if (bss->freq == 0)
859 return 1; /* Cannot do matching without knowing band */
860
861 modes = wpa_s->hw.modes;
862 if (modes == NULL) {
863 /*
864 * The driver does not provide any additional information
865 * about the utilized hardware, so allow the connection attempt
866 * to continue.
867 */
868 return 1;
869 }
870
871 for (i = 0; i < wpa_s->hw.num_modes; i++) {
872 for (j = 0; j < modes[i].num_channels; j++) {
873 int freq = modes[i].channels[j].freq;
874 if (freq == bss->freq) {
875 if (mode &&
876 mode->mode == HOSTAPD_MODE_IEEE80211G)
877 break; /* do not allow 802.11b replace
878 * 802.11g */
879 mode = &modes[i];
880 break;
881 }
882 }
883 }
884
885 if (mode == NULL)
886 return 0;
887
888 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700889 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800890 if (rate_ie == NULL)
891 continue;
892
893 for (j = 2; j < rate_ie[1] + 2; j++) {
894 int flagged = !!(rate_ie[j] & 0x80);
895 int r = (rate_ie[j] & 0x7f) * 5;
896
897 /*
898 * IEEE Std 802.11n-2009 7.3.2.2:
899 * The new BSS Membership selector value is encoded
900 * like a legacy basic rate, but it is not a rate and
901 * only indicates if the BSS members are required to
902 * support the mandatory features of Clause 20 [HT PHY]
903 * in order to join the BSS.
904 */
905 if (flagged && ((rate_ie[j] & 0x7f) ==
906 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
907 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800908 if (debug_print)
909 wpa_dbg(wpa_s, MSG_DEBUG,
910 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800911 return 0;
912 }
913 continue;
914 }
915
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700916 /* There's also a VHT selector for 802.11ac */
917 if (flagged && ((rate_ie[j] & 0x7f) ==
918 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
919 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800920 if (debug_print)
921 wpa_dbg(wpa_s, MSG_DEBUG,
922 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700923 return 0;
924 }
925 continue;
926 }
927
Hai Shalomc3565922019-10-28 11:58:20 -0700928#ifdef CONFIG_SAE
929 if (flagged && ((rate_ie[j] & 0x7f) ==
930 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700931 if (wpa_s->conf->sae_pwe == 0 &&
932 !ssid->sae_password_id &&
933 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700934 if (debug_print)
935 wpa_dbg(wpa_s, MSG_DEBUG,
936 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800937#ifdef CONFIG_TESTING_OPTIONS
938 if (wpa_s->ignore_sae_h2e_only) {
939 wpa_dbg(wpa_s, MSG_DEBUG,
940 "TESTING: Ignore SAE H2E requirement mismatch");
941 continue;
942 }
943#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700944 return 0;
945 }
946 continue;
947 }
948#endif /* CONFIG_SAE */
949
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800950 if (!flagged)
951 continue;
952
953 /* check for legacy basic rates */
954 for (k = 0; k < mode->num_rates; k++) {
955 if (mode->rates[k] == r)
956 break;
957 }
958 if (k == mode->num_rates) {
959 /*
960 * IEEE Std 802.11-2007 7.3.2.2 demands that in
961 * order to join a BSS all required rates
962 * have to be supported by the hardware.
963 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800964 if (debug_print)
965 wpa_dbg(wpa_s, MSG_DEBUG,
966 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
967 r / 10, r % 10,
968 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800969 return 0;
970 }
971 }
972 }
973
974 return 1;
975}
976
977
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800978/*
979 * Test whether BSS is in an ESS.
980 * This is done differently in DMG (60 GHz) and non-DMG bands
981 */
982static int bss_is_ess(struct wpa_bss *bss)
983{
984 if (bss_is_dmg(bss)) {
985 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
986 IEEE80211_CAP_DMG_AP;
987 }
988
989 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
990 IEEE80211_CAP_ESS);
991}
992
993
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800994static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
995{
996 size_t i;
997
998 for (i = 0; i < ETH_ALEN; i++) {
999 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1000 return 0;
1001 }
1002 return 1;
1003}
1004
1005
1006static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1007{
1008 size_t i;
1009
1010 for (i = 0; i < num; i++) {
1011 const u8 *a = list + i * ETH_ALEN * 2;
1012 const u8 *m = a + ETH_ALEN;
1013
1014 if (match_mac_mask(a, addr, m))
1015 return 1;
1016 }
1017 return 0;
1018}
1019
1020
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001021static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1022 const u8 **ret_ssid, size_t *ret_ssid_len)
1023{
1024#ifdef CONFIG_OWE
1025 const u8 *owe, *pos, *end, *bssid;
1026 u8 ssid_len;
1027 struct wpa_bss *open_bss;
1028
1029 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1030 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
1031 return;
1032
1033 pos = owe + 6;
1034 end = owe + 2 + owe[1];
1035
1036 if (end - pos < ETH_ALEN + 1)
1037 return;
1038 bssid = pos;
1039 pos += ETH_ALEN;
1040 ssid_len = *pos++;
1041 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1042 return;
1043
1044 /* Match the profile SSID against the OWE transition mode SSID on the
1045 * open network. */
1046 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1047 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1048 *ret_ssid = pos;
1049 *ret_ssid_len = ssid_len;
1050
Hai Shalomfdcde762020-04-02 11:19:20 -07001051 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1052 struct wpa_ssid *ssid;
1053
1054 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1055 if (wpas_network_disabled(wpa_s, ssid))
1056 continue;
1057 if (ssid->ssid_len == ssid_len &&
1058 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1059 /* OWE BSS in transition mode for a currently
1060 * enabled OWE network. */
1061 wpa_dbg(wpa_s, MSG_DEBUG,
1062 "OWE: transition mode OWE SSID for active OWE profile");
1063 bss->flags |= WPA_BSS_OWE_TRANSITION;
1064 break;
1065 }
1066 }
1067 }
1068
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001069 if (bss->ssid_len > 0)
1070 return;
1071
1072 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1073 if (!open_bss)
1074 return;
1075 if (ssid_len != open_bss->ssid_len ||
1076 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1077 wpa_dbg(wpa_s, MSG_DEBUG,
1078 "OWE: transition mode SSID mismatch: %s",
1079 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1080 return;
1081 }
1082
1083 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1084 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1085 wpa_dbg(wpa_s, MSG_DEBUG,
1086 "OWE: transition mode open BSS unexpected info");
1087 return;
1088 }
1089
1090 pos = owe + 6;
1091 end = owe + 2 + owe[1];
1092
1093 if (end - pos < ETH_ALEN + 1)
1094 return;
1095 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1096 wpa_dbg(wpa_s, MSG_DEBUG,
1097 "OWE: transition mode BSSID mismatch: " MACSTR,
1098 MAC2STR(pos));
1099 return;
1100 }
1101 pos += ETH_ALEN;
1102 ssid_len = *pos++;
1103 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1104 return;
1105 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1106 wpa_ssid_txt(pos, ssid_len));
1107 os_memcpy(bss->ssid, pos, ssid_len);
1108 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001109 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001110#endif /* CONFIG_OWE */
1111}
1112
1113
Sunil Ravi26978f32021-04-30 15:19:18 -07001114int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001115{
1116 int i, j;
1117
1118 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1119 return 0;
1120
1121 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1122 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1123
1124 for (i = 0; i < mode->num_channels; i++) {
1125 struct hostapd_channel_data *chan = &mode->channels[i];
1126
1127 if (chan->freq == freq)
1128 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1129 }
1130 }
1131
1132 return 1;
1133}
1134
1135
Hai Shalom899fcc72020-10-19 14:38:18 -07001136static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1137 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001138 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001139 bool debug_print);
1140
1141
1142#ifdef CONFIG_SAE_PK
1143static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1144 struct wpa_bss *orig_bss,
1145 struct wpa_ssid *ssid,
1146 const u8 *match_ssid,
1147 size_t match_ssid_len)
1148{
1149 struct wpa_bss *bss;
1150
1151 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1152 int count;
1153 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001154
1155 if (bss == orig_bss)
1156 continue;
1157 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001158 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001159 continue;
1160
1161 /* TODO: Could be more thorough in checking what kind of
1162 * signal strength or throughput estimate would be acceptable
1163 * compared to the originally selected BSS. */
1164 if (bss->est_throughput < 2000)
1165 return false;
1166
Hai Shalom60840252021-02-19 19:02:11 -08001167 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001168 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1169 bss, count, 0))
1170 return true;
1171 }
1172
1173 return false;
1174}
1175#endif /* CONFIG_SAE_PK */
1176
1177
1178static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1179 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001180 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001181 bool debug_print)
1182{
1183 int res;
1184 bool wpa, check_ssid, osen, rsn_osen = false;
1185 struct wpa_ie_data data;
1186#ifdef CONFIG_MBO
1187 const u8 *assoc_disallow;
1188#endif /* CONFIG_MBO */
1189#ifdef CONFIG_SAE
1190 u8 rsnxe_capa = 0;
1191#endif /* CONFIG_SAE */
1192 const u8 *ie;
1193
1194 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1195 wpa = ie && ie[1];
1196 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1197 wpa |= ie && ie[1];
1198 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1199 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1200 rsn_osen = true;
1201 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1202 osen = ie != NULL;
1203
1204#ifdef CONFIG_SAE
1205 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1206 if (ie && ie[1] >= 1)
1207 rsnxe_capa = ie[2];
1208#endif /* CONFIG_SAE */
1209
1210 check_ssid = wpa || ssid->ssid_len > 0;
1211
1212 if (wpas_network_disabled(wpa_s, ssid)) {
1213 if (debug_print)
1214 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1215 return false;
1216 }
1217
1218 res = wpas_temp_disabled(wpa_s, ssid);
1219 if (res > 0) {
1220 if (debug_print)
1221 wpa_dbg(wpa_s, MSG_DEBUG,
1222 " skip - disabled temporarily for %d second(s)",
1223 res);
1224 return false;
1225 }
1226
1227#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001228 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001229 if (debug_print)
1230 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001231 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001232 return false;
1233 }
1234
1235 if (wpa && ssid->ssid_len == 0 &&
1236 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1237 check_ssid = false;
1238
1239 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1240 /* Only allow wildcard SSID match if an AP advertises active
1241 * WPS operation that matches our mode. */
1242 check_ssid = ssid->ssid_len > 0 ||
1243 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1244 }
1245#endif /* CONFIG_WPS */
1246
1247 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1248 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1249 check_ssid = false;
1250
1251 if (check_ssid &&
1252 (match_ssid_len != ssid->ssid_len ||
1253 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1254 if (debug_print)
1255 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1256 return false;
1257 }
1258
1259 if (ssid->bssid_set &&
1260 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1261 if (debug_print)
1262 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1263 return false;
1264 }
1265
Hai Shalom60840252021-02-19 19:02:11 -08001266 /* check the list of BSSIDs to ignore */
1267 if (ssid->num_bssid_ignore &&
1268 addr_in_list(bss->bssid, ssid->bssid_ignore,
1269 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001270 if (debug_print)
1271 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001272 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001273 return false;
1274 }
1275
Hai Shalom60840252021-02-19 19:02:11 -08001276 /* if there is a list of accepted BSSIDs, only accept those APs */
1277 if (ssid->num_bssid_accept &&
1278 !addr_in_list(bss->bssid, ssid->bssid_accept,
1279 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001280 if (debug_print)
1281 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001282 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001283 return false;
1284 }
1285
1286 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1287 return false;
1288
1289 if (!osen && !wpa &&
1290 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1291 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1292 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1293 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1294 if (debug_print)
1295 wpa_dbg(wpa_s, MSG_DEBUG,
1296 " skip - non-WPA network not allowed");
1297 return false;
1298 }
1299
1300#ifdef CONFIG_WEP
1301 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1302 if (debug_print)
1303 wpa_dbg(wpa_s, MSG_DEBUG,
1304 " skip - ignore WPA/WPA2 AP for WEP network block");
1305 return false;
1306 }
1307#endif /* CONFIG_WEP */
1308
1309 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1310 if (debug_print)
1311 wpa_dbg(wpa_s, MSG_DEBUG,
1312 " skip - non-OSEN network not allowed");
1313 return false;
1314 }
1315
1316 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1317 if (debug_print)
1318 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1319 return false;
1320 }
1321
1322 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1323 !bss_is_pbss(bss)) {
1324 if (debug_print)
1325 wpa_dbg(wpa_s, MSG_DEBUG,
1326 " skip - not ESS, PBSS, or MBSS");
1327 return false;
1328 }
1329
1330 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1331 if (debug_print)
1332 wpa_dbg(wpa_s, MSG_DEBUG,
1333 " skip - PBSS mismatch (ssid %d bss %d)",
1334 ssid->pbss, bss_is_pbss(bss));
1335 return false;
1336 }
1337
1338 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1339 if (debug_print)
1340 wpa_dbg(wpa_s, MSG_DEBUG,
1341 " skip - frequency not allowed");
1342 return false;
1343 }
1344
1345#ifdef CONFIG_MESH
1346 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1347 ssid->frequency != bss->freq) {
1348 if (debug_print)
1349 wpa_dbg(wpa_s, MSG_DEBUG,
1350 " skip - frequency not allowed (mesh)");
1351 return false;
1352 }
1353#endif /* CONFIG_MESH */
1354
1355 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1356 if (debug_print)
1357 wpa_dbg(wpa_s, MSG_DEBUG,
1358 " skip - rate sets do not match");
1359 return false;
1360 }
1361
1362#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001363 /* When using SAE Password Identifier and when operationg on the 6 GHz
1364 * band, only H2E is allowed. */
1365 if ((wpa_s->conf->sae_pwe == 1 || is_6ghz_freq(bss->freq) ||
1366 ssid->sae_password_id) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001367 wpa_s->conf->sae_pwe != 3 && wpa_key_mgmt_sae(ssid->key_mgmt) &&
Vinayak Yadawad14709082022-03-17 14:25:11 +05301368#ifdef CONFIG_DRIVER_NL80211_BRCM
1369 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
1370#endif /* CONFIG_DRIVER_NL80211_BRCM */
Hai Shalom899fcc72020-10-19 14:38:18 -07001371 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1372 if (debug_print)
1373 wpa_dbg(wpa_s, MSG_DEBUG,
1374 " skip - SAE H2E required, but not supported by the AP");
1375 return false;
1376 }
1377#endif /* CONFIG_SAE */
1378
1379#ifdef CONFIG_SAE_PK
1380 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1381 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1382 if (debug_print)
1383 wpa_dbg(wpa_s, MSG_DEBUG,
1384 " skip - SAE-PK required, but not supported by the AP");
1385 return false;
1386 }
1387#endif /* CONFIG_SAE_PK */
1388
1389#ifndef CONFIG_IBSS_RSN
1390 if (ssid->mode == WPAS_MODE_IBSS &&
1391 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1392 if (debug_print)
1393 wpa_dbg(wpa_s, MSG_DEBUG,
1394 " skip - IBSS RSN not supported in the build");
1395 return false;
1396 }
1397#endif /* !CONFIG_IBSS_RSN */
1398
1399#ifdef CONFIG_P2P
1400 if (ssid->p2p_group &&
1401 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1402 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1403 if (debug_print)
1404 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1405 return false;
1406 }
1407
1408 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1409 struct wpabuf *p2p_ie;
1410 u8 dev_addr[ETH_ALEN];
1411
1412 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1413 if (!ie) {
1414 if (debug_print)
1415 wpa_dbg(wpa_s, MSG_DEBUG,
1416 " skip - no P2P element");
1417 return false;
1418 }
1419 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1420 if (!p2p_ie) {
1421 if (debug_print)
1422 wpa_dbg(wpa_s, MSG_DEBUG,
1423 " skip - could not fetch P2P element");
1424 return false;
1425 }
1426
1427 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1428 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1429 if (debug_print)
1430 wpa_dbg(wpa_s, MSG_DEBUG,
1431 " skip - no matching GO P2P Device Address in P2P element");
1432 wpabuf_free(p2p_ie);
1433 return false;
1434 }
1435 wpabuf_free(p2p_ie);
1436 }
1437
1438 /*
1439 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1440 * P2P Group Capability Bitmap and we are not in Group Formation with
1441 * that device.
1442 */
1443#endif /* CONFIG_P2P */
1444
1445 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1446 struct os_reltime diff;
1447
1448 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1449 if (debug_print)
1450 wpa_dbg(wpa_s, MSG_DEBUG,
1451 " skip - scan result not recent enough (%u.%06u seconds too old)",
1452 (unsigned int) diff.sec,
1453 (unsigned int) diff.usec);
1454 return false;
1455 }
1456#ifdef CONFIG_MBO
1457#ifdef CONFIG_TESTING_OPTIONS
1458 if (wpa_s->ignore_assoc_disallow)
1459 goto skip_assoc_disallow;
1460#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001461 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001462 if (assoc_disallow && assoc_disallow[1] >= 1) {
1463 if (debug_print)
1464 wpa_dbg(wpa_s, MSG_DEBUG,
1465 " skip - MBO association disallowed (reason %u)",
1466 assoc_disallow[2]);
1467 return false;
1468 }
1469
1470 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1471 if (debug_print)
1472 wpa_dbg(wpa_s, MSG_DEBUG,
1473 " skip - AP temporarily disallowed");
1474 return false;
1475 }
1476#ifdef CONFIG_TESTING_OPTIONS
1477skip_assoc_disallow:
1478#endif /* CONFIG_TESTING_OPTIONS */
1479#endif /* CONFIG_MBO */
1480
1481#ifdef CONFIG_DPP
1482 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1483 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1484 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1485 !ssid->dpp_csign)) {
1486 if (debug_print)
1487 wpa_dbg(wpa_s, MSG_DEBUG,
1488 " skip - no PMKSA entry for DPP");
1489 return false;
1490 }
1491#endif /* CONFIG_DPP */
1492
1493#ifdef CONFIG_SAE_PK
1494 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1495 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1496 ((ssid->sae_password &&
1497 sae_pk_valid_password(ssid->sae_password)) ||
1498 (!ssid->sae_password && ssid->passphrase &&
1499 sae_pk_valid_password(ssid->passphrase))) &&
1500 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1501 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1502 match_ssid_len)) {
1503 if (debug_print)
1504 wpa_dbg(wpa_s, MSG_DEBUG,
1505 " skip - another acceptable BSS with SAE-PK in the same ESS");
1506 return false;
1507 }
1508#endif /* CONFIG_SAE_PK */
1509
1510 if (bss->ssid_len == 0) {
1511 if (debug_print)
1512 wpa_dbg(wpa_s, MSG_DEBUG,
1513 " skip - no SSID known for the BSS");
1514 return false;
1515 }
1516
1517 /* Matching configuration found */
1518 return true;
1519}
1520
1521
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001522struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1523 int i, struct wpa_bss *bss,
1524 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001525 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001526{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001527 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528 const u8 *ie;
1529 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001530 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001531 const u8 *match_ssid;
1532 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001533 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001534
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001535 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001536 wpa_ie_len = ie ? ie[1] : 0;
1537
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001538 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001539 rsn_ie_len = ie ? ie[1] : 0;
1540
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001541 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1542 osen = ie != NULL;
1543
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001544 if (debug_print) {
1545 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1546 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1547 i, MAC2STR(bss->bssid),
1548 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1549 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1550 bss->freq,
1551 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1552 " wps" : "",
1553 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1554 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1555 ? " p2p" : "",
1556 osen ? " osen=1" : "");
1557 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001558
Hai Shalom60840252021-02-19 19:02:11 -08001559 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1560 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001561 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001562 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001563 /*
1564 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001565 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001566 * should not be done with multiple enabled networks to
1567 * avoid getting forced to move into a worse ESS on
1568 * single error if there are no other BSSes of the
1569 * current ESS.
1570 */
1571 limit = 0;
1572 }
Hai Shalom60840252021-02-19 19:02:11 -08001573 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001574 if (debug_print) {
1575 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001576 " skip - BSSID ignored (count=%d limit=%d)",
1577 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001578 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001579 return NULL;
1580 }
1581 }
1582
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001583 match_ssid = bss->ssid;
1584 match_ssid_len = bss->ssid_len;
1585 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1586
1587 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001588 if (debug_print)
1589 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001590 return NULL;
1591 }
1592
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001593 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001594 if (debug_print)
1595 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001596 return NULL;
1597 }
1598
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001599 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001600 if (debug_print)
1601 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001602 return NULL;
1603 }
1604
Hai Shalomfdcde762020-04-02 11:19:20 -07001605 if (disabled_freq(wpa_s, bss->freq)) {
1606 if (debug_print)
1607 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1608 return NULL;
1609 }
1610
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001611 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001612 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001613 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001614 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001615 }
1616
1617 /* No matching configuration found */
1618 return NULL;
1619}
1620
1621
1622static struct wpa_bss *
1623wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001624 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001625 struct wpa_ssid **selected_ssid,
1626 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001627{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001628 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001629
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001630 if (wpa_s->current_ssid) {
1631 struct wpa_ssid *ssid;
1632
1633 wpa_dbg(wpa_s, MSG_DEBUG,
1634 "Scan results matching the currently selected network");
1635 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1636 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1637
1638 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1639 only_first_ssid, 0);
1640 if (ssid != wpa_s->current_ssid)
1641 continue;
1642 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1643 " freq=%d level=%d snr=%d est_throughput=%u",
1644 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1645 bss->snr, bss->est_throughput);
1646 }
1647 }
1648
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001649 if (only_first_ssid)
1650 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1651 group->id);
1652 else
1653 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1654 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001656 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1657 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001658
1659 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001660 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001661 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001662 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001663 if (!*selected_ssid)
1664 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001665 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001666 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001667 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001668 MAC2STR(bss->bssid),
1669 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1670 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001671 }
1672
1673 return NULL;
1674}
1675
1676
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001677struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1678 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679{
1680 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001681 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001682 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001683 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001684
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001685 if (wpa_s->last_scan_res == NULL ||
1686 wpa_s->last_scan_res_used == 0)
1687 return NULL; /* no scan results from last update */
1688
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001689 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001690 /* check that next_ssid is still valid */
1691 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1692 if (ssid == wpa_s->next_ssid)
1693 break;
1694 }
1695 next_ssid = ssid;
1696 wpa_s->next_ssid = NULL;
1697 }
1698
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001699 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001700 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1701 if (next_ssid && next_ssid->priority ==
1702 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001703 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001704 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001705 if (selected)
1706 break;
1707 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001708 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001709 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001710 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001711 if (selected)
1712 break;
1713 }
1714
Hai Shalom60840252021-02-19 19:02:11 -08001715 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001716 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001717 wpa_dbg(wpa_s, MSG_DEBUG,
1718 "No APs found - clear BSSID ignore list and try again");
1719 wpa_bssid_ignore_clear(wpa_s);
1720 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001721 } else if (selected == NULL)
1722 break;
1723 }
1724
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001725 ssid = *selected_ssid;
1726 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1727 !ssid->passphrase && !ssid->ext_psk) {
1728 const char *field_name, *txt = NULL;
1729
1730 wpa_dbg(wpa_s, MSG_DEBUG,
1731 "PSK/passphrase not yet available for the selected network");
1732
1733 wpas_notify_network_request(wpa_s, ssid,
1734 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1735
1736 field_name = wpa_supplicant_ctrl_req_to_string(
1737 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1738 if (field_name == NULL)
1739 return NULL;
1740
1741 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1742
1743 selected = NULL;
1744 }
1745
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001746 return selected;
1747}
1748
1749
1750static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1751 int timeout_sec, int timeout_usec)
1752{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001753 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001754 /*
1755 * No networks are enabled; short-circuit request so
1756 * we don't wait timeout seconds before transitioning
1757 * to INACTIVE state.
1758 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001759 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1760 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001761 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1762 return;
1763 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001764
1765 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001766 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1767}
1768
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001769
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001770int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001771 struct wpa_bss *selected,
1772 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001773{
1774 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1775 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1776 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001777 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001779 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1780 wpa_s->p2p_in_provisioning) {
1781 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1782 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001783 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001784 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001785#endif /* CONFIG_P2P */
1786
1787#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001788 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001789 wpas_wps_cancel(wpa_s);
1790#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001791 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001792 }
1793
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001794 wpa_msg(wpa_s, MSG_DEBUG,
1795 "Considering connect request: reassociate: %d selected: "
1796 MACSTR " bssid: " MACSTR " pending: " MACSTR
1797 " wpa_state: %s ssid=%p current_ssid=%p",
1798 wpa_s->reassociate, MAC2STR(selected->bssid),
1799 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1800 wpa_supplicant_state_txt(wpa_s->wpa_state),
1801 ssid, wpa_s->current_ssid);
1802
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001803 /*
1804 * Do not trigger new association unless the BSSID has changed or if
1805 * reassociation is requested. If we are in process of associating with
1806 * the selected BSSID, do not trigger new attempt.
1807 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001808 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001809 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1810 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1811 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001812 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1813 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1814 0) ||
1815 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1816 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1818 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001819 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001821 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1822 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823 wpa_supplicant_associate(wpa_s, selected, ssid);
1824 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001825 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1826 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001828
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001829 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830}
1831
1832
1833static struct wpa_ssid *
1834wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1835{
Hai Shalomfdcde762020-04-02 11:19:20 -07001836 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001837 struct wpa_ssid *ssid;
1838
1839 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1840 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1841 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001842 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001843 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001844#ifndef CONFIG_IBSS_RSN
1845 if (ssid->mode == WPAS_MODE_IBSS &&
1846 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1847 WPA_KEY_MGMT_WPA_NONE))) {
1848 wpa_msg(wpa_s, MSG_INFO,
1849 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1850 wpa_ssid_txt(ssid->ssid,
1851 ssid->ssid_len));
1852 continue;
1853 }
1854#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001855 if (ssid->mode == WPAS_MODE_IBSS ||
1856 ssid->mode == WPAS_MODE_AP ||
1857 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858 return ssid;
1859 }
1860 }
1861 return NULL;
1862}
1863
1864
1865/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1866 * on BSS added and BSS changed events */
1867static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001868 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001869{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001870 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001871
1872 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1873 return;
1874
Jouni Malinen87fd2792011-05-16 18:35:42 +03001875 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001876 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001877
Jouni Malinen87fd2792011-05-16 18:35:42 +03001878 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001879 if (ssid == NULL)
1880 continue;
1881
Jouni Malinen87fd2792011-05-16 18:35:42 +03001882 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001883 if (rsn == NULL)
1884 continue;
1885
Jouni Malinen87fd2792011-05-16 18:35:42 +03001886 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001887 }
1888
1889}
1890
1891
Hai Shalomfdcde762020-04-02 11:19:20 -07001892#ifndef CONFIG_NO_ROAMING
1893
1894static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1895{
1896 if (noise == WPA_INVALID_NOISE)
1897 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1898 DEFAULT_NOISE_FLOOR_2GHZ;
1899 return avg_signal - noise;
1900}
1901
1902
1903static unsigned int
1904wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1905 const struct wpa_bss *bss, int snr)
1906{
1907 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001908 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001909 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1910
Hai Shalomc1a21442022-02-04 13:43:00 -08001911 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07001912}
1913
Hai Shalomfdcde762020-04-02 11:19:20 -07001914
Hai Shalom899fcc72020-10-19 14:38:18 -07001915int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1916 struct wpa_bss *current_bss,
1917 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001918{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001919 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001920 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001921 int cur_level;
1922 unsigned int cur_est, sel_est;
1923 struct wpa_signal_info si;
1924 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001925 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001926
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001927 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001928 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001929 " freq=%d level=%d snr=%d est_throughput=%u",
1930 MAC2STR(current_bss->bssid),
1931 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001932 current_bss->snr, current_bss->est_throughput);
1933 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001934 " freq=%d level=%d snr=%d est_throughput=%u",
1935 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001936 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001937
1938 if (wpa_s->current_ssid->bssid_set &&
1939 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1940 0) {
1941 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1942 "has preferred BSSID");
1943 return 1;
1944 }
1945
Hai Shalomfdcde762020-04-02 11:19:20 -07001946 cur_level = current_bss->level;
1947 cur_est = current_bss->est_throughput;
1948 sel_est = selected->est_throughput;
1949
1950 /*
1951 * Try to poll the signal from the driver since this will allow to get
1952 * more accurate values. In some cases, there can be big differences
1953 * between the RSSI of the Probe Response frames of the AP we are
1954 * associated with and the Beacon frames we hear from the same AP after
1955 * association. This can happen, e.g., when there are two antennas that
1956 * hear the AP very differently. If the driver chooses to hear the
1957 * Probe Response frames during the scan on the "bad" antenna because
1958 * it wants to save power, but knows to choose the other antenna after
1959 * association, we will hear our AP with a low RSSI as part of the
1960 * scan even when we can hear it decently on the other antenna. To cope
1961 * with this, ask the driver to teach us how it hears the AP. Also, the
1962 * scan results may be a bit old, since we can very quickly get fresh
1963 * information about our currently associated AP.
1964 */
1965 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1966 (si.avg_beacon_signal || si.avg_signal)) {
1967 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1968 si.avg_signal;
1969 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
1970 si.current_noise);
1971
1972 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
1973 current_bss,
1974 cur_snr);
1975 wpa_dbg(wpa_s, MSG_DEBUG,
1976 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
1977 cur_level, cur_snr, cur_est);
1978 }
1979
1980 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001981 wpa_dbg(wpa_s, MSG_DEBUG,
1982 "Allow reassociation - selected BSS has better estimated throughput");
1983 return 1;
1984 }
1985
Dmitry Shmidte4663042016-04-04 10:07:49 -07001986 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1987
Hai Shalomfdcde762020-04-02 11:19:20 -07001988 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
1989 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001990 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1991 "signal level");
1992 return 0;
1993 }
1994
Hai Shalomfdcde762020-04-02 11:19:20 -07001995 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001996 wpa_dbg(wpa_s, MSG_DEBUG,
1997 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001998 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001999 }
2000
Hai Shalomfdcde762020-04-02 11:19:20 -07002001 if (cur_snr > GREAT_SNR) {
2002 wpa_dbg(wpa_s, MSG_DEBUG,
2003 "Skip roam - Current BSS has good SNR (%u > %u)",
2004 cur_snr, GREAT_SNR);
2005 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002006 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002007
Hai Shalomfdcde762020-04-02 11:19:20 -07002008 if (cur_level < -85) /* ..-86 dBm */
2009 min_diff = 1;
2010 else if (cur_level < -80) /* -85..-81 dBm */
2011 min_diff = 2;
2012 else if (cur_level < -75) /* -80..-76 dBm */
2013 min_diff = 3;
2014 else if (cur_level < -70) /* -75..-71 dBm */
2015 min_diff = 4;
2016 else if (cur_level < 0) /* -70..-1 dBm */
2017 min_diff = 5;
2018 else /* unspecified units (not in dBm) */
2019 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002020
Hai Shalomfdcde762020-04-02 11:19:20 -07002021 if (cur_est > sel_est * 1.5)
2022 min_diff += 10;
2023 else if (cur_est > sel_est * 1.2)
2024 min_diff += 5;
2025 else if (cur_est > sel_est * 1.1)
2026 min_diff += 2;
2027 else if (cur_est > sel_est)
2028 min_diff++;
2029 else if (sel_est > cur_est * 1.5)
2030 min_diff -= 10;
2031 else if (sel_est > cur_est * 1.2)
2032 min_diff -= 5;
2033 else if (sel_est > cur_est * 1.1)
2034 min_diff -= 2;
2035 else if (sel_est > cur_est)
2036 min_diff--;
2037
2038 if (to_5ghz)
2039 min_diff -= 2;
2040 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002041 if (diff < min_diff) {
2042 wpa_dbg(wpa_s, MSG_DEBUG,
2043 "Skip roam - too small difference in signal level (%d < %d)",
2044 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002045 ret = 0;
2046 } else {
2047 wpa_dbg(wpa_s, MSG_DEBUG,
2048 "Allow reassociation due to difference in signal level (%d >= %d)",
2049 diff, min_diff);
2050 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002051 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002052 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2053 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2054 " sel_freq=%d sel_level=%d sel_est=%d",
2055 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2056 MAC2STR(current_bss->bssid),
2057 current_bss->freq, cur_level, cur_est,
2058 MAC2STR(selected->bssid),
2059 selected->freq, selected->level, sel_est);
2060 return ret;
2061}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002062
Hai Shalom899fcc72020-10-19 14:38:18 -07002063#endif /* CONFIG_NO_ROAMING */
2064
2065
2066static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2067 struct wpa_bss *selected,
2068 struct wpa_ssid *ssid)
2069{
2070 struct wpa_bss *current_bss = NULL;
2071
2072 if (wpa_s->reassociate)
2073 return 1; /* explicit request to reassociate */
2074 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2075 return 1; /* we are not associated; continue */
2076 if (wpa_s->current_ssid == NULL)
2077 return 1; /* unknown current SSID */
2078 if (wpa_s->current_ssid != ssid)
2079 return 1; /* different network block */
2080
2081 if (wpas_driver_bss_selection(wpa_s))
2082 return 0; /* Driver-based roaming */
2083
2084 if (wpa_s->current_ssid->ssid)
2085 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2086 wpa_s->current_ssid->ssid,
2087 wpa_s->current_ssid->ssid_len);
2088 if (!current_bss)
2089 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2090
2091 if (!current_bss)
2092 return 1; /* current BSS not seen in scan results */
2093
2094 if (current_bss == selected)
2095 return 0;
2096
2097 if (selected->last_update_idx > current_bss->last_update_idx)
2098 return 1; /* current BSS not seen in the last scan */
2099
2100#ifndef CONFIG_NO_ROAMING
2101 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2102 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002103#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002104 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002105#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002106}
2107
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002108
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002109/*
2110 * Return a negative value if no scan results could be fetched or if scan
2111 * results should not be shared with other virtual interfaces.
2112 * Return 0 if scan results were fetched and may be shared with other
2113 * interfaces.
2114 * Return 1 if scan results may be shared with other virtual interfaces but may
2115 * not trigger any operations.
2116 * Return 2 if the interface was removed and cannot be used.
2117 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002118static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002119 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002120 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002121{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002122 struct wpa_scan_results *scan_res = NULL;
2123 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002124 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002125#ifndef CONFIG_NO_RANDOM_POOL
2126 size_t i, num;
2127#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002128
2129#ifdef CONFIG_AP
2130 if (wpa_s->ap_iface)
2131 ap = 1;
2132#endif /* CONFIG_AP */
2133
2134 wpa_supplicant_notify_scanning(wpa_s, 0);
2135
2136 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2137 data ? &data->scan_info :
2138 NULL, 1);
2139 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002140 if (wpa_s->conf->ap_scan == 2 || ap ||
2141 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002142 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002143 if (!own_request)
2144 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002145 if (data && data->scan_info.external_scan)
2146 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002147 if (wpa_s->scan_res_fail_handler) {
2148 void (*handler)(struct wpa_supplicant *wpa_s);
2149
2150 handler = wpa_s->scan_res_fail_handler;
2151 wpa_s->scan_res_fail_handler = NULL;
2152 handler(wpa_s);
2153 } else {
2154 wpa_dbg(wpa_s, MSG_DEBUG,
2155 "Failed to get scan results - try scanning again");
2156 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2157 }
2158
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002159 ret = -1;
2160 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002161 }
2162
2163#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164 num = scan_res->num;
2165 if (num > 10)
2166 num = 10;
2167 for (i = 0; i < num; i++) {
2168 u8 buf[5];
2169 struct wpa_scan_res *res = scan_res->res[i];
2170 buf[0] = res->bssid[5];
2171 buf[1] = res->qual & 0xff;
2172 buf[2] = res->noise & 0xff;
2173 buf[3] = res->level & 0xff;
2174 buf[4] = res->tsf & 0xff;
2175 random_add_randomness(buf, sizeof(buf));
2176 }
2177#endif /* CONFIG_NO_RANDOM_POOL */
2178
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002179 if (update_only) {
2180 ret = 1;
2181 goto scan_work_done;
2182 }
2183
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002184 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002185 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2187 struct wpa_scan_results *scan_res);
2188
2189 scan_res_handler = wpa_s->scan_res_handler;
2190 wpa_s->scan_res_handler = NULL;
2191 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002192 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002193 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002194 }
2195
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002196 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002197 wpa_s->own_scan_running,
2198 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002199 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002200 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2201 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002202 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2203 wpa_s->manual_scan_id);
2204 wpa_s->manual_scan_use_id = 0;
2205 } else {
2206 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2207 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002208 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002209
2210 wpas_notify_scan_done(wpa_s, 1);
2211
Hai Shalomfdcde762020-04-02 11:19:20 -07002212 if (ap) {
2213 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2214#ifdef CONFIG_AP
2215 if (wpa_s->ap_iface->scan_cb)
2216 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2217#endif /* CONFIG_AP */
2218 goto scan_work_done;
2219 }
2220
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002221 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002222 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 -07002223 wpa_scan_results_free(scan_res);
2224 return 0;
2225 }
2226
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002227 if (wnm_scan_process(wpa_s, 1) > 0)
2228 goto scan_work_done;
2229
Hai Shalomc1a21442022-02-04 13:43:00 -08002230 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002231 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002232
Hai Shalom021b0b52019-04-10 11:17:58 -07002233 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002234 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2235 goto scan_work_done;
2236
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002237 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2238 goto scan_work_done;
2239
2240 if (autoscan_notify_scan(wpa_s, scan_res))
2241 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002242
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002243 if (wpa_s->disconnected) {
2244 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002245 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002246 }
2247
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002248 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002249 bgscan_notify_scan(wpa_s, scan_res) == 1)
2250 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002251
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002252 wpas_wps_update_ap_info(wpa_s, scan_res);
2253
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002254 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2255 wpa_s->wpa_state < WPA_COMPLETED)
2256 goto scan_work_done;
2257
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002258 wpa_scan_results_free(scan_res);
2259
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002260 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002261 struct wpa_radio_work *work = wpa_s->scan_work;
2262 wpa_s->scan_work = NULL;
2263 radio_work_done(work);
2264 }
2265
Hai Shalomc3565922019-10-28 11:58:20 -07002266 os_free(wpa_s->last_scan_freqs);
2267 wpa_s->last_scan_freqs = NULL;
2268 wpa_s->num_last_scan_freqs = 0;
2269 if (own_request && data &&
2270 data->scan_info.freqs && data->scan_info.num_freqs) {
2271 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2272 data->scan_info.num_freqs);
2273 if (wpa_s->last_scan_freqs) {
2274 os_memcpy(wpa_s->last_scan_freqs,
2275 data->scan_info.freqs,
2276 sizeof(int) * data->scan_info.num_freqs);
2277 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2278 }
2279 }
2280
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002281 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002282
2283scan_work_done:
2284 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002285 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002286 struct wpa_radio_work *work = wpa_s->scan_work;
2287 wpa_s->scan_work = NULL;
2288 radio_work_done(work);
2289 }
2290 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002291}
2292
2293
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002294static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002295 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002296{
2297 struct wpa_bss *selected;
2298 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002299 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2300
2301 if (time_to_reenable > 0) {
2302 wpa_dbg(wpa_s, MSG_DEBUG,
2303 "Postpone network selection by %d seconds since all networks are disabled",
2304 time_to_reenable);
2305 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2306 eloop_register_timeout(time_to_reenable, 0,
2307 wpas_network_reenabled, wpa_s, NULL);
2308 return 0;
2309 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002310
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002311 if (wpa_s->p2p_mgmt)
2312 return 0; /* no normal connection on p2p_mgmt interface */
2313
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002314 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002315 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002316
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002317#ifdef CONFIG_MESH
2318 if (wpa_s->ifmsh) {
2319 wpa_msg(wpa_s, MSG_INFO,
2320 "Avoiding join because we already joined a mesh group");
2321 return 0;
2322 }
2323#endif /* CONFIG_MESH */
2324
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002325 if (selected) {
2326 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002327 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002328 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002329 if (new_scan)
2330 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002331 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002332 }
2333
Hai Shalomc3565922019-10-28 11:58:20 -07002334 wpa_s->suitable_network++;
2335
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002336 if (ssid != wpa_s->current_ssid &&
2337 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2338 wpa_s->own_disconnect_req = 1;
2339 wpa_supplicant_deauthenticate(
2340 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2341 }
2342
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002343 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002344 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002345 return -1;
2346 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002347 if (new_scan)
2348 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002349 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002350 * Do not allow other virtual radios to trigger operations based
2351 * on these scan results since we do not want them to start
2352 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002353 */
2354 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002355 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002356 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002357 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2358 ssid = wpa_supplicant_pick_new_network(wpa_s);
2359 if (ssid) {
2360 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2361 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002362 if (new_scan)
2363 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002364 } else if (own_request) {
2365 /*
2366 * No SSID found. If SCAN results are as a result of
2367 * own scan request and not due to a scan request on
2368 * another shared interface, try another scan.
2369 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002370 int timeout_sec = wpa_s->scan_interval;
2371 int timeout_usec = 0;
2372#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002373 int res;
2374
2375 res = wpas_p2p_scan_no_go_seen(wpa_s);
2376 if (res == 2)
2377 return 2;
2378 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002379 return 0;
2380
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002381 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002382 wpa_s->show_group_started ||
2383 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384 /*
2385 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002386 * state and during P2P join-a-group operation
2387 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002388 */
2389 timeout_sec = 0;
2390 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002391 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2392 timeout_usec);
2393 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002394 }
2395#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002396#ifdef CONFIG_INTERWORKING
2397 if (wpa_s->conf->auto_interworking &&
2398 wpa_s->conf->interworking &&
2399 wpa_s->conf->cred) {
2400 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2401 "start ANQP fetch since no matching "
2402 "networks found");
2403 wpa_s->network_select = 1;
2404 wpa_s->auto_network_select = 1;
2405 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002406 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002407 }
2408#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002409#ifdef CONFIG_WPS
2410 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2411 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2412 timeout_sec = 0;
2413 timeout_usec = 500000;
2414 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2415 timeout_usec);
2416 return 0;
2417 }
2418#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002419#ifdef CONFIG_OWE
2420 if (wpa_s->owe_transition_search) {
2421 wpa_dbg(wpa_s, MSG_DEBUG,
2422 "OWE: Use shorter wait during transition mode search");
2423 timeout_sec = 0;
2424 timeout_usec = 500000;
2425 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2426 timeout_usec);
2427 return 0;
2428 }
2429#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002430 if (wpa_supplicant_req_sched_scan(wpa_s))
2431 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2432 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002433
2434 wpa_msg_ctrl(wpa_s, MSG_INFO,
2435 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002436 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002437 }
2438 }
2439 return 0;
2440}
2441
2442
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002443static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2444 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002445{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002446 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002447 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002448
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002449 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002450 if (res == 2) {
2451 /*
2452 * Interface may have been removed, so must not dereference
2453 * wpa_s after this.
2454 */
2455 return 1;
2456 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002457
2458 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002459 /*
2460 * If no scan results could be fetched, then no need to
2461 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002462 * this scan. Similarly, if scan results started a new operation on this
2463 * interface, do not notify other interfaces to avoid concurrent
2464 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002465 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002466 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002467 }
2468
2469 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002470 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002471 * so, they get updated with this same scan info.
2472 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002473 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2474 radio_list) {
2475 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002476 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2477 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002478 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2479 res > 0);
2480 if (res < 0)
2481 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002482 }
2483 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002484
2485 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002486}
2487
2488#endif /* CONFIG_NO_SCAN_PROCESSING */
2489
2490
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002491int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2492{
2493#ifdef CONFIG_NO_SCAN_PROCESSING
2494 return -1;
2495#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002496 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002497
Dmitry Shmidt29333592017-01-09 12:27:11 -08002498 wpa_s->ignore_post_flush_scan_res = 0;
2499
Dmitry Shmidt41712582015-06-29 11:02:15 -07002500 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002501 return -1;
2502
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002503 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002504 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002505 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002506 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2507 return -1;
2508 }
2509
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002510 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002511#endif /* CONFIG_NO_SCAN_PROCESSING */
2512}
2513
Dmitry Shmidt04949592012-07-19 12:16:46 -07002514#ifdef CONFIG_WNM
2515
2516static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2517{
2518 struct wpa_supplicant *wpa_s = eloop_ctx;
2519
2520 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2521 return;
2522
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002523 if (!wpa_s->no_keep_alive) {
2524 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2525 MAC2STR(wpa_s->bssid));
2526 /* TODO: could skip this if normal data traffic has been sent */
2527 /* TODO: Consider using some more appropriate data frame for
2528 * this */
2529 if (wpa_s->l2)
2530 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2531 (u8 *) "", 0);
2532 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002533
2534#ifdef CONFIG_SME
2535 if (wpa_s->sme.bss_max_idle_period) {
2536 unsigned int msec;
2537 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2538 if (msec > 100)
2539 msec -= 100;
2540 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2541 wnm_bss_keep_alive, wpa_s, NULL);
2542 }
2543#endif /* CONFIG_SME */
2544}
2545
2546
2547static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2548 const u8 *ies, size_t ies_len)
2549{
2550 struct ieee802_11_elems elems;
2551
2552 if (ies == NULL)
2553 return;
2554
2555 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2556 return;
2557
2558#ifdef CONFIG_SME
2559 if (elems.bss_max_idle_period) {
2560 unsigned int msec;
2561 wpa_s->sme.bss_max_idle_period =
2562 WPA_GET_LE16(elems.bss_max_idle_period);
2563 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2564 "TU)%s", wpa_s->sme.bss_max_idle_period,
2565 (elems.bss_max_idle_period[2] & 0x01) ?
2566 " (protected keep-live required)" : "");
2567 if (wpa_s->sme.bss_max_idle_period == 0)
2568 wpa_s->sme.bss_max_idle_period = 1;
2569 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2570 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2571 /* msec times 1000 */
2572 msec = wpa_s->sme.bss_max_idle_period * 1024;
2573 if (msec > 100)
2574 msec -= 100;
2575 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2576 wnm_bss_keep_alive, wpa_s,
2577 NULL);
2578 }
2579 }
2580#endif /* CONFIG_SME */
2581}
2582
2583#endif /* CONFIG_WNM */
2584
2585
2586void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2587{
2588#ifdef CONFIG_WNM
2589 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2590#endif /* CONFIG_WNM */
2591}
2592
2593
Dmitry Shmidt051af732013-10-22 13:52:46 -07002594#ifdef CONFIG_INTERWORKING
2595
2596static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2597 size_t len)
2598{
2599 int res;
2600
2601 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2602 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2603 if (res) {
2604 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2605 }
2606
2607 return res;
2608}
2609
2610
2611static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2612 const u8 *ies, size_t ies_len)
2613{
2614 struct ieee802_11_elems elems;
2615
2616 if (ies == NULL)
2617 return;
2618
2619 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2620 return;
2621
2622 if (elems.qos_map_set) {
2623 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2624 elems.qos_map_set_len);
2625 }
2626}
2627
2628#endif /* CONFIG_INTERWORKING */
2629
2630
Hai Shalom74f70d42019-02-11 14:42:39 -08002631static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2632 const u8 *ies, size_t ies_len)
2633{
2634 struct ieee802_11_elems elems;
2635 const u8 *map_sub_elem, *pos;
2636 size_t len;
2637
Hai Shalomfdcde762020-04-02 11:19:20 -07002638 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002639
Hai Shalomfdcde762020-04-02 11:19:20 -07002640 if (!ies ||
2641 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2642 !elems.multi_ap || elems.multi_ap_len < 7)
2643 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002644
2645 pos = elems.multi_ap + 4;
2646 len = elems.multi_ap_len - 4;
2647
2648 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002649 if (!map_sub_elem || map_sub_elem[1] < 1)
2650 return;
2651
2652 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2653 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2654 MULTI_AP_FRONTHAUL_BSS);
2655 wpa_s->multi_ap_ie = 1;
2656}
2657
2658
2659static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2660{
2661 if (!wpa_s->current_ssid ||
2662 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2663 return;
2664
2665 if (!wpa_s->multi_ap_ie) {
2666 wpa_printf(MSG_INFO,
2667 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002668 goto fail;
2669 }
2670
Hai Shalomfdcde762020-04-02 11:19:20 -07002671 if (!wpa_s->multi_ap_backhaul) {
2672 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002673 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2674 wpa_printf(MSG_INFO,
2675 "WPS active, accepting fronthaul-only BSS");
2676 /* Don't set 4addr mode in this case, so just return */
2677 return;
2678 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002679 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2680 goto fail;
2681 }
2682
2683 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2684 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2685 goto fail;
2686 }
2687 wpa_s->enabled_4addr_mode = 1;
2688 return;
2689
2690fail:
2691 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2692}
2693
2694
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002695#ifdef CONFIG_FST
2696static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2697 const u8 *ie, size_t ie_len)
2698{
2699 struct mb_ies_info mb_ies;
2700
2701 if (!ie || !ie_len || !wpa_s->fst)
2702 return -ENOENT;
2703
2704 os_memset(&mb_ies, 0, sizeof(mb_ies));
2705
2706 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2707 size_t len;
2708
2709 len = 2 + ie[1];
2710 if (len > ie_len) {
2711 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2712 ie, ie_len);
2713 break;
2714 }
2715
2716 if (ie[0] == WLAN_EID_MULTI_BAND) {
2717 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2718 (unsigned int) len);
2719 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2720 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2721 mb_ies.nof_ies++;
2722 }
2723
2724 ie_len -= len;
2725 ie += len;
2726 }
2727
2728 if (mb_ies.nof_ies > 0) {
2729 wpabuf_free(wpa_s->received_mb_ies);
2730 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2731 return 0;
2732 }
2733
2734 return -ENOENT;
2735}
2736#endif /* CONFIG_FST */
2737
2738
Hai Shalomc1a21442022-02-04 13:43:00 -08002739static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2740 union wpa_event_data *data)
2741{
2742 int sel;
2743 const u8 *p;
2744 int l, len;
2745 bool found = false;
2746 struct wpa_ie_data ie;
2747 struct wpa_ssid *ssid = wpa_s->current_ssid;
2748 struct wpa_bss *bss = wpa_s->current_bss;
2749 int pmf;
2750
2751 if (!ssid)
2752 return 0;
2753
2754 p = data->assoc_info.req_ies;
2755 l = data->assoc_info.req_ies_len;
2756
2757 while (p && l >= 2) {
2758 len = p[1] + 2;
2759 if (len > l) {
2760 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2761 p, l);
2762 break;
2763 }
2764 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2765 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2766 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2767 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2768 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2769 found = true;
2770 break;
2771 }
2772 l -= len;
2773 p += len;
2774 }
2775
2776 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2777 return 0;
2778
2779 wpa_hexdump(MSG_DEBUG,
2780 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2781 p, l);
2782
2783 /* Update proto from (Re)Association Request frame info */
2784 wpa_s->wpa_proto = ie.proto;
2785 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2786 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2787 !!(wpa_s->wpa_proto &
2788 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2789
2790 /* Update AKMP suite from (Re)Association Request frame info */
2791 sel = ie.key_mgmt;
2792 if (ssid->key_mgmt)
2793 sel &= ssid->key_mgmt;
2794
2795 wpa_dbg(wpa_s, MSG_DEBUG,
2796 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2797 ie.key_mgmt, ssid->key_mgmt, sel);
2798 if (ie.key_mgmt && !sel) {
2799 wpa_supplicant_deauthenticate(
2800 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2801 return -1;
2802 }
2803
2804 wpa_s->key_mgmt = ie.key_mgmt;
2805 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2806 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2807 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2808 wpa_s->wpa_proto);
2809
2810 /* Update pairwise cipher from (Re)Association Request frame info */
2811 sel = ie.pairwise_cipher;
2812 if (ssid->pairwise_cipher)
2813 sel &= ssid->pairwise_cipher;
2814
2815 wpa_dbg(wpa_s, MSG_DEBUG,
2816 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2817 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2818 if (ie.pairwise_cipher && !sel) {
2819 wpa_supplicant_deauthenticate(
2820 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2821 return -1;
2822 }
2823
2824 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2825 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2826 wpa_s->pairwise_cipher);
2827 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2828 wpa_cipher_txt(wpa_s->pairwise_cipher));
2829
2830 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2831 if (!bss) {
2832 wpa_dbg(wpa_s, MSG_DEBUG,
2833 "WPA: current_bss == NULL - skip AP IE check");
2834 return 0;
2835 }
2836
2837 /* Update GTK and IGTK from AP's RSNE */
2838 found = false;
2839
2840 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2841 const u8 *bss_rsn;
2842
2843 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2844 if (bss_rsn) {
2845 p = bss_rsn;
2846 len = 2 + bss_rsn[1];
2847 found = true;
2848 }
2849 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2850 const u8 *bss_wpa;
2851
2852 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2853 if (bss_wpa) {
2854 p = bss_wpa;
2855 len = 2 + bss_wpa[1];
2856 found = true;
2857 }
2858 }
2859
2860 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2861 return 0;
2862
2863 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2864 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2865 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
2866 /* AP does not support MFP, local configuration requires it */
2867 wpa_supplicant_deauthenticate(
2868 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2869 return -1;
2870 }
2871 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
2872 pmf == NO_MGMT_FRAME_PROTECTION) {
2873 /* AP requires MFP, local configuration disables it */
2874 wpa_supplicant_deauthenticate(
2875 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2876 return -1;
2877 }
2878
2879 /* Update PMF from local configuration now that MFP validation was done
2880 * above */
2881 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
2882
2883 /* Update GTK from AP's RSNE */
2884 sel = ie.group_cipher;
2885 if (ssid->group_cipher)
2886 sel &= ssid->group_cipher;
2887
2888 wpa_dbg(wpa_s, MSG_DEBUG,
2889 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
2890 ie.group_cipher, ssid->group_cipher, sel);
2891 if (ie.group_cipher && !sel) {
2892 wpa_supplicant_deauthenticate(
2893 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
2894 return -1;
2895 }
2896
2897 wpa_s->group_cipher = ie.group_cipher;
2898 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
2899 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
2900 wpa_cipher_txt(wpa_s->group_cipher));
2901
2902 /* Update IGTK from AP RSN IE */
2903 sel = ie.mgmt_group_cipher;
2904 if (ssid->group_mgmt_cipher)
2905 sel &= ssid->group_mgmt_cipher;
2906
2907 wpa_dbg(wpa_s, MSG_DEBUG,
2908 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
2909 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
2910
2911 if (pmf == NO_MGMT_FRAME_PROTECTION ||
2912 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
2913 wpa_dbg(wpa_s, MSG_DEBUG,
2914 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
2915 ie.capabilities);
2916 ie.mgmt_group_cipher = 0;
2917 }
2918
2919 if (ie.mgmt_group_cipher && !sel) {
2920 wpa_supplicant_deauthenticate(
2921 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
2922 return -1;
2923 }
2924
2925 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
2926 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
2927 wpa_s->mgmt_group_cipher);
2928 if (wpa_s->mgmt_group_cipher)
2929 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
2930 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
2931 else
2932 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
2933
2934 return 0;
2935}
2936
2937
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002938static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2939 union wpa_event_data *data)
2940{
Hai Shalomc3565922019-10-28 11:58:20 -07002941 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002942 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002943 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002944 bool bssid_known;
Vinayak Yadawad14709082022-03-17 14:25:11 +05302945#ifdef CONFIG_DRIVER_NL80211_BRCM
2946 struct wpa_ie_data ie;
2947#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002948
2949 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07002950 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002951 if (data->assoc_info.req_ies)
2952 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2953 data->assoc_info.req_ies_len);
2954 if (data->assoc_info.resp_ies) {
2955 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2956 data->assoc_info.resp_ies_len);
2957#ifdef CONFIG_TDLS
2958 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2959 data->assoc_info.resp_ies_len);
2960#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002961#ifdef CONFIG_WNM
2962 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2963 data->assoc_info.resp_ies_len);
2964#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002965#ifdef CONFIG_INTERWORKING
2966 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2967 data->assoc_info.resp_ies_len);
2968#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002969 if (wpa_s->hw_capab == CAPAB_VHT &&
2970 get_ie(data->assoc_info.resp_ies,
2971 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2972 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002973
2974 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2975 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002976 }
2977 if (data->assoc_info.beacon_ies)
2978 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2979 data->assoc_info.beacon_ies,
2980 data->assoc_info.beacon_ies_len);
2981 if (data->assoc_info.freq)
2982 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2983 data->assoc_info.freq);
2984
Hai Shalom021b0b52019-04-10 11:17:58 -07002985 wpa_s->connection_set = 0;
2986 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2987 struct ieee802_11_elems req_elems, resp_elems;
2988
2989 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2990 data->assoc_info.req_ies_len,
2991 &req_elems, 0) != ParseFailed &&
2992 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2993 data->assoc_info.resp_ies_len,
2994 &resp_elems, 0) != ParseFailed) {
2995 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07002996 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
2997 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07002998 wpa_s->connection_ht = req_elems.ht_capabilities &&
2999 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003000 /* Do not include subset of VHT on 2.4 GHz vendor
3001 * extension in consideration for reporting VHT
3002 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003003 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003004 resp_elems.vht_capabilities &&
3005 (!data->assoc_info.freq ||
3006 wpas_freq_to_band(data->assoc_info.freq) !=
3007 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003008 wpa_s->connection_he = req_elems.he_capabilities &&
3009 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003010 wpa_s->connection_eht = req_elems.eht_capabilities &&
3011 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003012
3013 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3014 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3015 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3016 max_nss_rx_req : max_nss_rx_resp;
3017 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3018 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3019 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3020 max_nss_tx_req : max_nss_tx_resp;
3021
3022 struct supported_chan_width sta_supported_chan_width =
3023 get_supported_channel_width(&req_elems);
3024 enum chan_width ap_operation_chan_width =
3025 get_operation_channel_width(&resp_elems);
3026 if (wpa_s->connection_vht || wpa_s->connection_he) {
3027 wpa_s->connection_channel_bandwidth =
3028 get_sta_operation_chan_width(ap_operation_chan_width,
3029 sta_supported_chan_width);
3030 } else if (wpa_s->connection_ht) {
3031 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3032 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3033 } else {
3034 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3035 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003036 }
3037 }
3038
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003039 p = data->assoc_info.req_ies;
3040 l = data->assoc_info.req_ies_len;
3041
3042 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3043 while (p && l >= 2) {
3044 len = p[1] + 2;
3045 if (len > l) {
3046 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3047 p, l);
3048 break;
3049 }
Hai Shalomc3565922019-10-28 11:58:20 -07003050 if (!found &&
3051 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3052 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3053 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3054 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3055 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003056 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3057 break;
3058 found = 1;
3059 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07003060 }
3061 if (!found_x && p[0] == WLAN_EID_RSNX) {
3062 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3063 break;
3064 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003065 }
3066 l -= len;
3067 p += len;
3068 }
3069 if (!found && data->assoc_info.req_ies)
3070 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003071 if (!found_x && data->assoc_info.req_ies)
3072 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073
Vinayak Yadawad14709082022-03-17 14:25:11 +05303074#ifdef CONFIG_DRIVER_NL80211_BRCM
3075 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3076 * to a different security type, update the current supplicant configuration to use the AKM
3077 * and pairwise suites from the assoc IE passed by the driver.
3078 */
3079 if (wpas_driver_bss_selection(wpa_s)) {
3080 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3081 /* Check if firmware has roamed to a different security network */
3082 if(wpa_s->key_mgmt != ie.key_mgmt) {
3083 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3084 ie.key_mgmt);
3085 wpa_s->key_mgmt = ie.key_mgmt;
3086 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3087
3088 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3089 /* Restore PMK as it can get overwritten if the previous
3090 * association was to 802.1X.
3091 */
3092 if ((!(wpa_s->drv_flags &
3093 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3094 (wpa_s->current_ssid) &&
3095 (wpa_s->current_ssid->psk_set)) {
3096 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3097 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3098 "BSSID");
3099 wpa_supplicant_deauthenticate(
3100 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3101 return -1;
3102 }
3103 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3104 PMK_LEN, NULL, bssid);
3105 }
3106 }
3107 }
3108 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3109 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3110 "from Assoc IE", ie.pairwise_cipher);
3111 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3112 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3113 wpa_s->pairwise_cipher);
3114 }
3115 // TODO: Notify the framework about security type change b/230766005
3116 }
3117 }
3118#endif /* CONFIG_DRIVER_NL80211_BRCM */
3119
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003120#ifdef CONFIG_FILS
3121#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003122 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3123 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003124 (!data->assoc_info.resp_frame ||
3125 fils_process_assoc_resp(wpa_s->wpa,
3126 data->assoc_info.resp_frame,
3127 data->assoc_info.resp_frame_len) < 0)) {
3128 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3129 return -1;
3130 }
3131#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003132
3133 /* Additional processing for FILS when SME is in driver */
3134 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3135 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3136 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003137#endif /* CONFIG_FILS */
3138
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003139#ifdef CONFIG_OWE
3140 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003141 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003142 owe_process_assoc_resp(wpa_s->wpa, bssid,
3143 data->assoc_info.resp_ies,
3144 data->assoc_info.resp_ies_len) < 0)) {
3145 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3146 return -1;
3147 }
3148#endif /* CONFIG_OWE */
3149
Hai Shalom021b0b52019-04-10 11:17:58 -07003150#ifdef CONFIG_DPP2
3151 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003152 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3153 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003154 struct ieee802_11_elems elems;
3155
3156 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3157 data->assoc_info.resp_ies_len,
3158 &elems, 0) == ParseFailed ||
3159 !elems.owe_dh)
3160 goto no_pfs;
3161 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3162 elems.owe_dh_len) < 0) {
3163 wpa_supplicant_deauthenticate(wpa_s,
3164 WLAN_REASON_UNSPECIFIED);
3165 return -1;
3166 }
3167
3168 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3169 }
3170no_pfs:
3171#endif /* CONFIG_DPP2 */
3172
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003173#ifdef CONFIG_IEEE80211R
3174#ifdef CONFIG_SME
3175 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003176 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003177 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3178 data->assoc_info.resp_ies,
3179 data->assoc_info.resp_ies_len,
3180 bssid) < 0) {
3181 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3182 "Reassociation Response failed");
3183 wpa_supplicant_deauthenticate(
3184 wpa_s, WLAN_REASON_INVALID_IE);
3185 return -1;
3186 }
3187 }
3188
3189 p = data->assoc_info.resp_ies;
3190 l = data->assoc_info.resp_ies_len;
3191
3192#ifdef CONFIG_WPS_STRICT
3193 if (p && wpa_s->current_ssid &&
3194 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3195 struct wpabuf *wps;
3196 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3197 if (wps == NULL) {
3198 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3199 "include WPS IE in (Re)Association Response");
3200 return -1;
3201 }
3202
3203 if (wps_validate_assoc_resp(wps) < 0) {
3204 wpabuf_free(wps);
3205 wpa_supplicant_deauthenticate(
3206 wpa_s, WLAN_REASON_INVALID_IE);
3207 return -1;
3208 }
3209 wpabuf_free(wps);
3210 }
3211#endif /* CONFIG_WPS_STRICT */
3212
3213 /* Go through the IEs and make a copy of the MDIE, if present. */
3214 while (p && l >= 2) {
3215 len = p[1] + 2;
3216 if (len > l) {
3217 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3218 p, l);
3219 break;
3220 }
3221 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3222 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3223 wpa_s->sme.ft_used = 1;
3224 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3225 MOBILITY_DOMAIN_ID_LEN);
3226 break;
3227 }
3228 l -= len;
3229 p += len;
3230 }
3231#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003232#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303233 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3234 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3235 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3236 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303237 wpa_ft_is_completed(wpa_s->wpa)) {
3238 return 0;
3239 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003240#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003241
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003242 /* Process FT when SME is in the driver */
3243 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3244 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003245 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003246 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3247 data->assoc_info.resp_ies,
3248 data->assoc_info.resp_ies_len,
3249 bssid) < 0) {
3250 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3251 "Reassociation Response failed");
3252 wpa_supplicant_deauthenticate(
3253 wpa_s, WLAN_REASON_INVALID_IE);
3254 return -1;
3255 }
3256 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3257 }
3258
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003259 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3260 data->assoc_info.resp_ies_len);
3261#endif /* CONFIG_IEEE80211R */
3262
Hai Shalom899fcc72020-10-19 14:38:18 -07003263 if (bssid_known)
3264 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3265 data->assoc_info.resp_ies,
3266 data->assoc_info.resp_ies_len);
3267
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003268 /* WPA/RSN IE from Beacon/ProbeResp */
3269 p = data->assoc_info.beacon_ies;
3270 l = data->assoc_info.beacon_ies_len;
3271
3272 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3273 */
3274 wpa_found = rsn_found = 0;
3275 while (p && l >= 2) {
3276 len = p[1] + 2;
3277 if (len > l) {
3278 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3279 p, l);
3280 break;
3281 }
3282 if (!wpa_found &&
3283 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3284 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3285 wpa_found = 1;
3286 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3287 }
3288
3289 if (!rsn_found &&
3290 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3291 rsn_found = 1;
3292 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3293 }
3294
Hai Shalomc3565922019-10-28 11:58:20 -07003295 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3296 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003298 l -= len;
3299 p += len;
3300 }
3301
3302 if (!wpa_found && data->assoc_info.beacon_ies)
3303 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003304 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003305 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003306 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3307 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003308 if (wpa_found || rsn_found)
3309 wpa_s->ap_ies_from_associnfo = 1;
3310
Jouni Malinen87fd2792011-05-16 18:35:42 +03003311 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3312 wpa_s->assoc_freq != data->assoc_info.freq) {
3313 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3314 "%u to %u MHz",
3315 wpa_s->assoc_freq, data->assoc_info.freq);
3316 wpa_supplicant_update_scan_results(wpa_s);
3317 }
3318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003319 wpa_s->assoc_freq = data->assoc_info.freq;
3320
Hai Shalomc1a21442022-02-04 13:43:00 -08003321 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3322 data->assoc_info.resp_ies_len);
3323
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003324 return 0;
3325}
3326
3327
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003328static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3329{
Hai Shalomc3565922019-10-28 11:58:20 -07003330 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003331
3332 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3333 return -1;
3334
3335 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3336 return 0;
3337
3338 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3339 WPA_IE_VENDOR_TYPE);
3340 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003341 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003342
3343 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3344 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3345 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003346 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3347 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3348 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003349 return -1;
3350
3351 return 0;
3352}
3353
3354
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003355static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3356 union wpa_event_data *data)
3357{
3358#ifdef CONFIG_FST
3359 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3360 struct wpa_bss *bss = wpa_s->current_bss;
3361 const u8 *ieprb, *iebcn;
3362
3363 wpabuf_free(wpa_s->received_mb_ies);
3364 wpa_s->received_mb_ies = NULL;
3365
3366 if (ai &&
3367 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3368 wpa_printf(MSG_DEBUG,
3369 "FST: MB IEs updated from Association Response frame");
3370 return;
3371 }
3372
3373 if (ai &&
3374 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3375 wpa_printf(MSG_DEBUG,
3376 "FST: MB IEs updated from association event Beacon IEs");
3377 return;
3378 }
3379
3380 if (!bss)
3381 return;
3382
Hai Shalom60840252021-02-19 19:02:11 -08003383 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003384 iebcn = ieprb + bss->ie_len;
3385
3386 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3387 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3388 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3389 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3390#endif /* CONFIG_FST */
3391}
3392
3393
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003394static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3395 union wpa_event_data *data)
3396{
3397 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003398 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003399 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003400#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3401 struct wpa_bss *bss;
3402#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003403#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303404 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003405#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003406
3407#ifdef CONFIG_AP
3408 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003409 if (!data)
3410 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003411 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3412 data->assoc_info.addr,
3413 data->assoc_info.req_ies,
3414 data->assoc_info.req_ies_len,
3415 data->assoc_info.reassoc);
3416 return;
3417 }
3418#endif /* CONFIG_AP */
3419
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003420 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003421 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003422
Andy Kuoaba17c12022-04-14 16:05:31 +08003423#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303424 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3425 struct wpa_ft_ies parse;
3426 /* Check for FT reassociation is done by the driver */
3427#ifdef CONFIG_IEEE80211R
3428 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303429 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303430 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3431 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3432 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3433 return;
3434 }
3435 if (parse.rsn_pmkid != NULL) {
3436 wpa_set_ft_completed(wpa_s->wpa);
3437 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3438 }
3439 }
3440#endif /* CONFIG_IEEE80211R */
3441 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003442#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303443
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003444 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003445
3446 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3447 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3448 wpa_supplicant_deauthenticate(
3449 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3450 return;
3451 }
3452
3453 if (ft_completed &&
3454 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3455 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3456 MAC2STR(bssid));
3457 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3458 wpa_printf(MSG_ERROR,
3459 "Can't find target AP's information!");
3460 return;
3461 }
3462 wpa_supplicant_assoc_update_ie(wpa_s);
3463 }
3464
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003465 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3466 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003467 /*
3468 * FILS authentication can share the same mechanism to mark the
3469 * connection fully authenticated, so set ft_completed also based on
3470 * FILS result.
3471 */
3472 if (!ft_completed)
3473 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003474
Andy Kuoaba17c12022-04-14 16:05:31 +08003475#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303476 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3477 /*
3478 * For driver based roaming, insert PSK during
3479 * the initial association
3480 */
3481 if (is_zero_ether_addr(wpa_s->bssid) &&
3482 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3483 /*
3484 * In case the driver wants to handle re-assocs,
3485 * pass it down the PMK.
3486 */
3487 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3488 wpa_sm_install_pmk(wpa_s->wpa);
3489 }
Mir Ali677e7482020-11-12 19:49:02 +05303490 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303491#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003492
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003493 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003494 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003495 if (os_reltime_initialized(&wpa_s->session_start)) {
3496 os_reltime_age(&wpa_s->session_start,
3497 &wpa_s->session_length);
3498 wpa_s->session_start.sec = 0;
3499 wpa_s->session_start.usec = 0;
3500 wpas_notify_session_length(wpa_s);
3501 } else {
3502 wpas_notify_auth_changed(wpa_s);
3503 os_get_reltime(&wpa_s->session_start);
3504 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003505 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3506 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003507 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003508 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003509 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3510 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003511 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003512
3513 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3514 wpa_clear_keys(wpa_s, bssid);
3515 }
3516 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003517 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003518 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3519 return;
3520 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003521 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003522
Hai Shalomc1a21442022-02-04 13:43:00 -08003523 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3524 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3525 return;
3526
Hai Shalomfdcde762020-04-02 11:19:20 -07003527 multi_ap_set_4addr_mode(wpa_s);
3528
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003529 if (wpa_s->conf->ap_scan == 1 &&
3530 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003531 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3532 wpa_msg(wpa_s, MSG_WARNING,
3533 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003534 }
3535
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003536 wpas_fst_update_mb_assoc(wpa_s, data);
3537
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003538#ifdef CONFIG_SME
3539 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3540 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003541 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003542#endif /* CONFIG_SME */
3543
3544 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3545 if (wpa_s->current_ssid) {
3546 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3547 * initialized before association, but for other modes,
3548 * initialize PC/SC here, if the current configuration needs
3549 * smartcard or SIM/USIM. */
3550 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3551 }
3552 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3553 if (wpa_s->l2)
3554 l2_packet_notify_auth_start(wpa_s->l2);
3555
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003556 already_authorized = data && data->assoc_info.authorized;
3557
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003558 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003559 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003560 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3561 * state machine may transit to AUTHENTICATING state based on obsolete
3562 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3563 * AUTHENTICATED without ever giving chance to EAP state machine to
3564 * reset the state.
3565 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003566 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003567 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3568 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003569 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003570 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3571 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3572 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003573 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003574 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003575 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003576 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003577 wpa_s->eapol_received = 0;
3578 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3579 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3580 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003581 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003582 if (wpa_s->current_ssid &&
3583 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003584 (wpa_s->drv_flags &
3585 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3586 /*
3587 * Set the key after having received joined-IBSS event
3588 * from the driver.
3589 */
3590 wpa_supplicant_set_wpa_none_key(wpa_s,
3591 wpa_s->current_ssid);
3592 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003593 wpa_supplicant_cancel_auth_timeout(wpa_s);
3594 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3595 } else if (!ft_completed) {
3596 /* Timeout for receiving the first EAPOL packet */
3597 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3598 }
3599 wpa_supplicant_cancel_scan(wpa_s);
3600
Hai Shalom5f92bc92019-04-18 11:54:11 -07003601 if (ft_completed) {
3602 /*
3603 * FT protocol completed - make sure EAPOL state machine ends
3604 * up in authenticated.
3605 */
3606 wpa_supplicant_cancel_auth_timeout(wpa_s);
3607 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003608 eapol_sm_notify_portValid(wpa_s->eapol, true);
3609 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003610 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3611 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303612 if (already_authorized) {
3613 /*
3614 * We are done; the driver will take care of RSN 4-way
3615 * handshake.
3616 */
3617 wpa_supplicant_cancel_auth_timeout(wpa_s);
3618 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3619 eapol_sm_notify_portValid(wpa_s->eapol, true);
3620 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3621 } else {
3622 /* Update port, WPA_COMPLETED state from
3623 * EVENT_PORT_AUTHORIZED context when driver is done
3624 * with 4way handshake.
3625 */
3626 wpa_msg(wpa_s, MSG_INFO, "ASSOC INFO: wait for driver port "
3627 "authorized indication");
3628 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003629 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003630 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3631 /*
3632 * The driver will take care of RSN 4-way handshake, so we need
3633 * to allow EAPOL supplicant to complete its work without
3634 * waiting for WPA supplicant.
3635 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003636 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003637 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003638#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303639 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3640 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3641 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3642 wpa_s->key_mgmt);
3643 wpa_supplicant_deauthenticate(
3644 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3645 return;
3646 }
3647 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3648 wpa_s->assoc_freq = data->assoc_info.freq;
3649 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3650 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003651#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3652
Jouni Malinena05074c2012-12-21 21:35:35 +02003653 wpa_s->last_eapol_matches_bssid = 0;
3654
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003655#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003656 if (wpa_s->rsne_override_eapol) {
3657 wpa_printf(MSG_DEBUG,
3658 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3659 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3660 wpabuf_head(wpa_s->rsne_override_eapol),
3661 wpabuf_len(wpa_s->rsne_override_eapol));
3662 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003663 if (wpa_s->rsnxe_override_eapol) {
3664 wpa_printf(MSG_DEBUG,
3665 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3666 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3667 wpabuf_head(wpa_s->rsnxe_override_eapol),
3668 wpabuf_len(wpa_s->rsnxe_override_eapol));
3669 }
3670#endif /* CONFIG_TESTING_OPTIONS */
3671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003672 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003673 struct os_reltime now, age;
3674 os_get_reltime(&now);
3675 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003676 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003677 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3678 0) {
3679 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3680 "frame that was received just before "
3681 "association notification");
3682 wpa_supplicant_rx_eapol(
3683 wpa_s, wpa_s->pending_eapol_rx_src,
3684 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00003685 wpabuf_len(wpa_s->pending_eapol_rx),
3686 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003687 }
3688 wpabuf_free(wpa_s->pending_eapol_rx);
3689 wpa_s->pending_eapol_rx = NULL;
3690 }
3691
Hai Shalomfdcde762020-04-02 11:19:20 -07003692#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003693 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3694 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003695 wpa_s->current_ssid &&
3696 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003697 /* Set static WEP keys again */
3698 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3699 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003700#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003701
3702#ifdef CONFIG_IBSS_RSN
3703 if (wpa_s->current_ssid &&
3704 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3705 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3706 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3707 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003708 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003709 if (!wpa_s->ibss_rsn) {
3710 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3711 wpa_supplicant_deauthenticate(
3712 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3713 return;
3714 }
3715
3716 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3717 }
3718#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003719
3720 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003721
3722 if (data) {
3723 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3724 data->assoc_info.resp_ies_len,
3725 &data->assoc_info.wmm_params);
3726
3727 if (wpa_s->reassoc_same_bss)
3728 wmm_ac_restore_tspecs(wpa_s);
3729 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003730
Hai Shalomc3565922019-10-28 11:58:20 -07003731#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3732 bss = wpa_bss_get_bssid(wpa_s, bssid);
3733#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003734#ifdef CONFIG_FILS
3735 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003736 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3737
3738 if (fils_cache_id)
3739 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3740 }
3741#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003742
3743#ifdef CONFIG_MBO
3744 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3745#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003746
3747#ifdef CONFIG_DPP2
3748 wpa_s->dpp_pfs_fallback = 0;
3749#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003750}
3751
3752
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003753static int disconnect_reason_recoverable(u16 reason_code)
3754{
3755 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3756 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3757 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3758}
3759
3760
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003761static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003762 u16 reason_code,
3763 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003764{
3765 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003766
3767 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3768 /*
3769 * At least Host AP driver and a Prism3 card seemed to be
3770 * generating streams of disconnected events when configuring
3771 * IBSS for WPA-None. Ignore them for now.
3772 */
3773 return;
3774 }
3775
3776 bssid = wpa_s->bssid;
3777 if (is_zero_ether_addr(bssid))
3778 bssid = wpa_s->pending_bssid;
3779
3780 if (!is_zero_ether_addr(bssid) ||
3781 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3782 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3783 " reason=%d%s",
3784 MAC2STR(bssid), reason_code,
3785 locally_generated ? " locally_generated=1" : "");
3786 }
3787}
3788
3789
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003790static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3791 int locally_generated)
3792{
3793 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003794 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003795 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3796 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003797 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003798
3799 /*
3800 * It looks like connection was lost while trying to go through PSK
3801 * 4-way handshake. Filter out known disconnection cases that are caused
3802 * by something else than PSK mismatch to avoid confusing reports.
3803 */
3804
3805 if (locally_generated) {
3806 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3807 return 0;
3808 }
3809
3810 return 1;
3811}
3812
3813
Jouni Malinen2b89da82012-08-31 22:04:41 +03003814static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3815 u16 reason_code,
3816 int locally_generated)
3817{
3818 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003819 int authenticating;
3820 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003821 struct wpa_bss *fast_reconnect = NULL;
3822 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003823 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003824 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003825
3826 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3827 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3828
3829 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3830 /*
3831 * At least Host AP driver and a Prism3 card seemed to be
3832 * generating streams of disconnected events when configuring
3833 * IBSS for WPA-None. Ignore them for now.
3834 */
3835 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3836 "IBSS/WPA-None mode");
3837 return;
3838 }
3839
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003840 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3841 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3842 locally_generated)
3843 /*
3844 * Remove the inactive AP (which is probably out of range) from
3845 * the BSS list after marking disassociation. In particular
3846 * mac80211-based drivers use the
3847 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3848 * locally generated disconnection events for cases where the
3849 * AP does not reply anymore.
3850 */
3851 curr = wpa_s->current_bss;
3852
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003853 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003854 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3855 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003856 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3857 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003858 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003859#ifdef CONFIG_DPP2
3860 wpas_dpp_send_conn_status_result(wpa_s,
3861 DPP_STATUS_AUTH_FAILURE);
3862#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003863 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003864 if (!wpa_s->disconnected &&
3865 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003866 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003867 wpas_wps_searching(wpa_s) ||
3868 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003869 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003870 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003871 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003872 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003873 wpa_s->wpa_state);
3874 if (wpa_s->wpa_state == WPA_COMPLETED &&
3875 wpa_s->current_ssid &&
3876 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003877 (wpa_s->own_reconnect_req ||
3878 (!locally_generated &&
3879 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003880 /*
3881 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003882 * us, but could allow us to get back in. This is also
3883 * triggered for cases where local reconnection request
3884 * is used to force reassociation with the same BSS.
3885 * Try to reconnect to the same BSS without a full scan
3886 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003887 */
3888 fast_reconnect = wpa_s->current_bss;
3889 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003890 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003891 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003892 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003893 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3894 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003895 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003896 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003897 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003898 "try to re-connect");
3899 wpa_s->reassociate = 0;
3900 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003901 if (!wpa_s->pno)
3902 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003903 }
3904 bssid = wpa_s->bssid;
3905 if (is_zero_ether_addr(bssid))
3906 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003907 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3908 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003909 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08003910 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
3911
Dmitry Shmidt04949592012-07-19 12:16:46 -07003912 if (locally_generated)
3913 wpa_s->disconnect_reason = -reason_code;
3914 else
3915 wpa_s->disconnect_reason = reason_code;
3916 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003917 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3918 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003919 wpa_clear_keys(wpa_s, wpa_s->bssid);
3920 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003921 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003922 wpa_supplicant_mark_disassoc(wpa_s);
3923
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003924 if (curr)
3925 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3926
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003927 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003928 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003929 wpa_s->current_ssid = last_ssid;
3930 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003931
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003932 if (fast_reconnect &&
3933 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3934 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3935 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3936 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003937 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003938 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003939#ifndef CONFIG_NO_SCAN_PROCESSING
3940 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3941 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3942 fast_reconnect_ssid) < 0) {
3943 /* Recover through full scan */
3944 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3945 }
3946#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003947 } else if (fast_reconnect) {
3948 /*
3949 * Could not reconnect to the same BSS due to network being
3950 * disabled. Use a new scan to match the alternative behavior
3951 * above, i.e., to continue automatic reconnection attempt in a
3952 * way that enforces disabled network rules.
3953 */
3954 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003955 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003956}
3957
3958
3959#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003960void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003961{
3962 struct wpa_supplicant *wpa_s = eloop_ctx;
3963
3964 if (!wpa_s->pending_mic_error_report)
3965 return;
3966
3967 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3968 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3969 wpa_s->pending_mic_error_report = 0;
3970}
3971#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3972
3973
3974static void
3975wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3976 union wpa_event_data *data)
3977{
3978 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003979 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003980
3981 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3982 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003983 os_get_reltime(&t);
3984 if ((wpa_s->last_michael_mic_error.sec &&
3985 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003986 wpa_s->pending_mic_error_report) {
3987 if (wpa_s->pending_mic_error_report) {
3988 /*
3989 * Send the pending MIC error report immediately since
3990 * we are going to start countermeasures and AP better
3991 * do the same.
3992 */
3993 wpa_sm_key_request(wpa_s->wpa, 1,
3994 wpa_s->pending_mic_error_pairwise);
3995 }
3996
3997 /* Send the new MIC error report immediately since we are going
3998 * to start countermeasures and AP better do the same.
3999 */
4000 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4001
4002 /* initialize countermeasures */
4003 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004004
Hai Shalom60840252021-02-19 19:02:11 -08004005 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004006
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004007 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4008
4009 /*
4010 * Need to wait for completion of request frame. We do not get
4011 * any callback for the message completion, so just wait a
4012 * short while and hope for the best. */
4013 os_sleep(0, 10000);
4014
4015 wpa_drv_set_countermeasures(wpa_s, 1);
4016 wpa_supplicant_deauthenticate(wpa_s,
4017 WLAN_REASON_MICHAEL_MIC_FAILURE);
4018 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4019 wpa_s, NULL);
4020 eloop_register_timeout(60, 0,
4021 wpa_supplicant_stop_countermeasures,
4022 wpa_s, NULL);
4023 /* TODO: mark the AP rejected for 60 second. STA is
4024 * allowed to associate with another AP.. */
4025 } else {
4026#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4027 if (wpa_s->mic_errors_seen) {
4028 /*
4029 * Reduce the effectiveness of Michael MIC error
4030 * reports as a means for attacking against TKIP if
4031 * more than one MIC failure is noticed with the same
4032 * PTK. We delay the transmission of the reports by a
4033 * random time between 0 and 60 seconds in order to
4034 * force the attacker wait 60 seconds before getting
4035 * the information on whether a frame resulted in a MIC
4036 * failure.
4037 */
4038 u8 rval[4];
4039 int sec;
4040
4041 if (os_get_random(rval, sizeof(rval)) < 0)
4042 sec = os_random() % 60;
4043 else
4044 sec = WPA_GET_BE32(rval) % 60;
4045 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4046 "report %d seconds", sec);
4047 wpa_s->pending_mic_error_report = 1;
4048 wpa_s->pending_mic_error_pairwise = pairwise;
4049 eloop_cancel_timeout(
4050 wpa_supplicant_delayed_mic_error_report,
4051 wpa_s, NULL);
4052 eloop_register_timeout(
4053 sec, os_random() % 1000000,
4054 wpa_supplicant_delayed_mic_error_report,
4055 wpa_s, NULL);
4056 } else {
4057 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4058 }
4059#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4060 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4061#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4062 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004063 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004064 wpa_s->mic_errors_seen++;
4065}
4066
4067
4068#ifdef CONFIG_TERMINATE_ONLASTIF
4069static int any_interfaces(struct wpa_supplicant *head)
4070{
4071 struct wpa_supplicant *wpa_s;
4072
4073 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4074 if (!wpa_s->interface_removed)
4075 return 1;
4076 return 0;
4077}
4078#endif /* CONFIG_TERMINATE_ONLASTIF */
4079
4080
4081static void
4082wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4083 union wpa_event_data *data)
4084{
4085 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4086 return;
4087
4088 switch (data->interface_status.ievent) {
4089 case EVENT_INTERFACE_ADDED:
4090 if (!wpa_s->interface_removed)
4091 break;
4092 wpa_s->interface_removed = 0;
4093 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4094 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4095 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4096 "driver after interface was added");
4097 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004098
4099#ifdef CONFIG_P2P
4100 if (!wpa_s->global->p2p &&
4101 !wpa_s->global->p2p_disabled &&
4102 !wpa_s->conf->p2p_disabled &&
4103 (wpa_s->drv_flags &
4104 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4105 wpas_p2p_add_p2pdev_interface(
4106 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4107 wpa_printf(MSG_INFO,
4108 "P2P: Failed to enable P2P Device interface");
4109 /* Try to continue without. P2P will be disabled. */
4110 }
4111#endif /* CONFIG_P2P */
4112
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004113 break;
4114 case EVENT_INTERFACE_REMOVED:
4115 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4116 wpa_s->interface_removed = 1;
4117 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004118 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004119 l2_packet_deinit(wpa_s->l2);
4120 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004121
4122#ifdef CONFIG_P2P
4123 if (wpa_s->global->p2p &&
4124 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4125 (wpa_s->drv_flags &
4126 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4127 wpa_dbg(wpa_s, MSG_DEBUG,
4128 "Removing P2P Device interface");
4129 wpa_supplicant_remove_iface(
4130 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4131 0);
4132 wpa_s->global->p2p_init_wpa_s = NULL;
4133 }
4134#endif /* CONFIG_P2P */
4135
Dmitry Shmidte4663042016-04-04 10:07:49 -07004136#ifdef CONFIG_MATCH_IFACE
4137 if (wpa_s->matched) {
4138 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4139 break;
4140 }
4141#endif /* CONFIG_MATCH_IFACE */
4142
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004143#ifdef CONFIG_TERMINATE_ONLASTIF
4144 /* check if last interface */
4145 if (!any_interfaces(wpa_s->global->ifaces))
4146 eloop_terminate();
4147#endif /* CONFIG_TERMINATE_ONLASTIF */
4148 break;
4149 }
4150}
4151
4152
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004153#ifdef CONFIG_TDLS
4154static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4155 union wpa_event_data *data)
4156{
4157 if (data == NULL)
4158 return;
4159 switch (data->tdls.oper) {
4160 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004161 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4162 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4163 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4164 else
4165 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004166 break;
4167 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004168 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4169 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4170 data->tdls.reason_code);
4171 else
4172 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4173 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004174 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004175 case TDLS_REQUEST_DISCOVER:
4176 wpa_tdls_send_discovery_request(wpa_s->wpa,
4177 data->tdls.peer);
4178 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004179 }
4180}
4181#endif /* CONFIG_TDLS */
4182
4183
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004184#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004185static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4186 union wpa_event_data *data)
4187{
4188 if (data == NULL)
4189 return;
4190 switch (data->wnm.oper) {
4191 case WNM_OPER_SLEEP:
4192 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4193 "(action=%d, intval=%d)",
4194 data->wnm.sleep_action, data->wnm.sleep_intval);
4195 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004196 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004197 break;
4198 }
4199}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004200#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004201
4202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004203#ifdef CONFIG_IEEE80211R
4204static void
4205wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4206 union wpa_event_data *data)
4207{
4208 if (data == NULL)
4209 return;
4210
4211 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4212 data->ft_ies.ies_len,
4213 data->ft_ies.ft_action,
4214 data->ft_ies.target_ap,
4215 data->ft_ies.ric_ies,
4216 data->ft_ies.ric_ies_len) < 0) {
4217 /* TODO: prevent MLME/driver from trying to associate? */
4218 }
4219}
4220#endif /* CONFIG_IEEE80211R */
4221
4222
4223#ifdef CONFIG_IBSS_RSN
4224static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4225 union wpa_event_data *data)
4226{
4227 struct wpa_ssid *ssid;
4228 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4229 return;
4230 if (data == NULL)
4231 return;
4232 ssid = wpa_s->current_ssid;
4233 if (ssid == NULL)
4234 return;
4235 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4236 return;
4237
4238 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4239}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004240
4241
4242static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4243 union wpa_event_data *data)
4244{
4245 struct wpa_ssid *ssid = wpa_s->current_ssid;
4246
4247 if (ssid == NULL)
4248 return;
4249
4250 /* check if the ssid is correctly configured as IBSS/RSN */
4251 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4252 return;
4253
4254 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4255 data->rx_mgmt.frame_len);
4256}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004257#endif /* CONFIG_IBSS_RSN */
4258
4259
4260#ifdef CONFIG_IEEE80211R
4261static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4262 size_t len)
4263{
4264 const u8 *sta_addr, *target_ap_addr;
4265 u16 status;
4266
4267 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4268 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4269 return; /* only SME case supported for now */
4270 if (len < 1 + 2 * ETH_ALEN + 2)
4271 return;
4272 if (data[0] != 2)
4273 return; /* Only FT Action Response is supported for now */
4274 sta_addr = data + 1;
4275 target_ap_addr = data + 1 + ETH_ALEN;
4276 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4277 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4278 MACSTR " TargetAP " MACSTR " status %u",
4279 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4280
4281 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4282 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4283 " in FT Action Response", MAC2STR(sta_addr));
4284 return;
4285 }
4286
4287 if (status) {
4288 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4289 "failure (status code %d)", status);
4290 /* TODO: report error to FT code(?) */
4291 return;
4292 }
4293
4294 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4295 len - (1 + 2 * ETH_ALEN + 2), 1,
4296 target_ap_addr, NULL, 0) < 0)
4297 return;
4298
4299#ifdef CONFIG_SME
4300 {
4301 struct wpa_bss *bss;
4302 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4303 if (bss)
4304 wpa_s->sme.freq = bss->freq;
4305 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4306 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4307 WLAN_AUTH_FT);
4308 }
4309#endif /* CONFIG_SME */
4310}
4311#endif /* CONFIG_IEEE80211R */
4312
4313
4314static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4315 struct unprot_deauth *e)
4316{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004317 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4318 "dropped: " MACSTR " -> " MACSTR
4319 " (reason code %u)",
4320 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4321 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004322}
4323
4324
4325static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4326 struct unprot_disassoc *e)
4327{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004328 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4329 "dropped: " MACSTR " -> " MACSTR
4330 " (reason code %u)",
4331 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4332 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004333}
4334
4335
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004336static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4337 u16 reason_code, int locally_generated,
4338 const u8 *ie, size_t ie_len, int deauth)
4339{
4340#ifdef CONFIG_AP
4341 if (wpa_s->ap_iface && addr) {
4342 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4343 return;
4344 }
4345
4346 if (wpa_s->ap_iface) {
4347 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4348 return;
4349 }
4350#endif /* CONFIG_AP */
4351
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004352 if (!locally_generated)
4353 wpa_s->own_disconnect_req = 0;
4354
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004355 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4356
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004357 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4358 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4359 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4360 eapol_sm_failed(wpa_s->eapol))) &&
4361 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004362 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004363
4364#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004365 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004366 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4367 locally_generated) > 0) {
4368 /*
4369 * The interface was removed, so cannot continue
4370 * processing any additional operations after this.
4371 */
4372 return;
4373 }
4374 }
4375#endif /* CONFIG_P2P */
4376
4377 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4378 locally_generated);
4379}
4380
4381
4382static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4383 struct disassoc_info *info)
4384{
4385 u16 reason_code = 0;
4386 int locally_generated = 0;
4387 const u8 *addr = NULL;
4388 const u8 *ie = NULL;
4389 size_t ie_len = 0;
4390
4391 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4392
4393 if (info) {
4394 addr = info->addr;
4395 ie = info->ie;
4396 ie_len = info->ie_len;
4397 reason_code = info->reason_code;
4398 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004399 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4400 reason2str(reason_code),
4401 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004402 if (addr)
4403 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4404 MAC2STR(addr));
4405 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4406 ie, ie_len);
4407 }
4408
4409#ifdef CONFIG_AP
4410 if (wpa_s->ap_iface && info && info->addr) {
4411 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4412 return;
4413 }
4414
4415 if (wpa_s->ap_iface) {
4416 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4417 return;
4418 }
4419#endif /* CONFIG_AP */
4420
4421#ifdef CONFIG_P2P
4422 if (info) {
4423 wpas_p2p_disassoc_notif(
4424 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4425 locally_generated);
4426 }
4427#endif /* CONFIG_P2P */
4428
4429 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4430 sme_event_disassoc(wpa_s, info);
4431
4432 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4433 ie, ie_len, 0);
4434}
4435
4436
4437static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4438 struct deauth_info *info)
4439{
4440 u16 reason_code = 0;
4441 int locally_generated = 0;
4442 const u8 *addr = NULL;
4443 const u8 *ie = NULL;
4444 size_t ie_len = 0;
4445
4446 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4447
4448 if (info) {
4449 addr = info->addr;
4450 ie = info->ie;
4451 ie_len = info->ie_len;
4452 reason_code = info->reason_code;
4453 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004454 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4455 reason_code, reason2str(reason_code),
4456 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004457 if (addr) {
4458 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4459 MAC2STR(addr));
4460 }
4461 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4462 ie, ie_len);
4463 }
4464
4465 wpa_reset_ft_completed(wpa_s->wpa);
4466
4467 wpas_event_disconnect(wpa_s, addr, reason_code,
4468 locally_generated, ie, ie_len, 1);
4469}
4470
4471
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004472static const char * reg_init_str(enum reg_change_initiator init)
4473{
4474 switch (init) {
4475 case REGDOM_SET_BY_CORE:
4476 return "CORE";
4477 case REGDOM_SET_BY_USER:
4478 return "USER";
4479 case REGDOM_SET_BY_DRIVER:
4480 return "DRIVER";
4481 case REGDOM_SET_BY_COUNTRY_IE:
4482 return "COUNTRY_IE";
4483 case REGDOM_BEACON_HINT:
4484 return "BEACON_HINT";
4485 }
4486 return "?";
4487}
4488
4489
4490static const char * reg_type_str(enum reg_type type)
4491{
4492 switch (type) {
4493 case REGDOM_TYPE_UNKNOWN:
4494 return "UNKNOWN";
4495 case REGDOM_TYPE_COUNTRY:
4496 return "COUNTRY";
4497 case REGDOM_TYPE_WORLD:
4498 return "WORLD";
4499 case REGDOM_TYPE_CUSTOM_WORLD:
4500 return "CUSTOM_WORLD";
4501 case REGDOM_TYPE_INTERSECTION:
4502 return "INTERSECTION";
4503 }
4504 return "?";
4505}
4506
4507
Hai Shalom74f70d42019-02-11 14:42:39 -08004508void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4509 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004510{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004511 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004512 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004513
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004514 /*
4515 * To allow backwards compatibility with higher level layers that
4516 * assumed the REGDOM_CHANGE event is sent over the initially added
4517 * interface. Find the highest parent of this interface and use it to
4518 * send the event.
4519 */
4520 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4521 ;
4522
Hai Shalom74f70d42019-02-11 14:42:39 -08004523 if (info) {
4524 wpa_msg(ifs, MSG_INFO,
4525 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4526 reg_init_str(info->initiator), reg_type_str(info->type),
4527 info->alpha2[0] ? " alpha2=" : "",
4528 info->alpha2[0] ? info->alpha2 : "");
4529 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004530
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004531 if (wpa_s->drv_priv == NULL)
4532 return; /* Ignore event during drv initialization */
4533
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004534 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4535 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004536 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4537 ifs->ifname);
4538 free_hw_features(ifs);
4539 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004540 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004541
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004542 /* Restart PNO/sched_scan with updated channel list */
4543 if (ifs->pno) {
4544 wpas_stop_pno(ifs);
4545 wpas_start_pno(ifs);
4546 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4547 wpa_dbg(ifs, MSG_DEBUG,
4548 "Channel list changed - restart sched_scan");
4549 wpas_scan_restart_sched_scan(ifs);
4550 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004551 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004552
4553 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004554}
4555
4556
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004557static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004558 const u8 *frame, size_t len, int freq,
4559 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004560{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004561 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004562 const u8 *payload;
4563 size_t plen;
4564 u8 category;
4565
4566 if (len < IEEE80211_HDRLEN + 2)
4567 return;
4568
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004569 mgmt = (const struct ieee80211_mgmt *) frame;
4570 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004571 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004572 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004573
4574 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4575 " Category=%u DataLen=%d freq=%d MHz",
4576 MAC2STR(mgmt->sa), category, (int) plen, freq);
4577
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004578 if (category == WLAN_ACTION_WMM) {
4579 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4580 return;
4581 }
4582
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004583#ifdef CONFIG_IEEE80211R
4584 if (category == WLAN_ACTION_FT) {
4585 ft_rx_action(wpa_s, payload, plen);
4586 return;
4587 }
4588#endif /* CONFIG_IEEE80211R */
4589
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004590#ifdef CONFIG_SME
4591 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004592 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004593 return;
4594 }
4595#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004596
4597#ifdef CONFIG_WNM
4598 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4599 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4600 return;
4601 }
4602#endif /* CONFIG_WNM */
4603
4604#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004605 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4606 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004607 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004608 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004609 payload, plen, freq) == 0)
4610 return;
4611#endif /* CONFIG_GAS */
4612
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004613#ifdef CONFIG_GAS_SERVER
4614 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4615 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4616 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4617 mgmt->u.action.category,
4618 payload, plen, freq) == 0)
4619 return;
4620#endif /* CONFIG_GAS_SERVER */
4621
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004622#ifdef CONFIG_TDLS
4623 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4624 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4625 wpa_dbg(wpa_s, MSG_DEBUG,
4626 "TDLS: Received Discovery Response from " MACSTR,
4627 MAC2STR(mgmt->sa));
4628 return;
4629 }
4630#endif /* CONFIG_TDLS */
4631
4632#ifdef CONFIG_INTERWORKING
4633 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4634 payload[0] == QOS_QOS_MAP_CONFIG) {
4635 const u8 *pos = payload + 1;
4636 size_t qlen = plen - 1;
4637 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4638 MACSTR, MAC2STR(mgmt->sa));
4639 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4640 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4641 pos[1] <= qlen - 2 && pos[1] >= 16)
4642 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4643 return;
4644 }
4645#endif /* CONFIG_INTERWORKING */
4646
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004647 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004648 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4649 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004650 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004651 payload + 1,
4652 plen - 1);
4653 return;
4654 }
4655
4656 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004657 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4658 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4659 return;
4660 }
4661
4662 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4663 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4664 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4665 payload + 1, plen - 1,
4666 rssi);
4667 return;
4668 }
4669
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004670#ifdef CONFIG_FST
4671 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4672 fst_rx_action(wpa_s->fst, mgmt, len);
4673 return;
4674 }
4675#endif /* CONFIG_FST */
4676
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004677#ifdef CONFIG_DPP
4678 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4679 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4680 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4681 payload[4] == DPP_OUI_TYPE) {
4682 payload++;
4683 plen--;
4684 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4685 return;
4686 }
4687#endif /* CONFIG_DPP */
4688
Hai Shalom899fcc72020-10-19 14:38:18 -07004689 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004690 payload[0] == ROBUST_AV_SCS_RESP) {
4691 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4692 payload + 1, plen - 1);
4693 return;
4694 }
4695
4696 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004697 payload[0] == ROBUST_AV_MSCS_RESP) {
4698 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4699 payload + 1, plen - 1);
4700 return;
4701 }
4702
Hai Shalomc1a21442022-02-04 13:43:00 -08004703 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4704 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4705 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4706 payload + 4, plen - 4);
4707 return;
4708 }
4709
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004710 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4711 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004712 if (wpa_s->ifmsh)
4713 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004714}
4715
4716
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004717static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4718 union wpa_event_data *event)
4719{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004720 struct wpa_freq_range_list *list;
4721 char *str = NULL;
4722
4723 list = &event->freq_range;
4724
4725 if (list->num)
4726 str = freq_range_list_str(list);
4727 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4728 str ? str : "");
4729
4730#ifdef CONFIG_P2P
4731 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4732 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4733 __func__);
4734 } else {
4735 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004736
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004737 /*
4738 * The update channel flow will also take care of moving a GO
4739 * from the unsafe frequency if needed.
4740 */
4741 wpas_p2p_update_channel_list(wpa_s,
4742 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004743 }
4744#endif /* CONFIG_P2P */
4745
4746 os_free(str);
4747}
4748
4749
Roshan Pius3a1667e2018-07-03 15:17:14 -07004750static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004751{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004752 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4753 wpa_supplicant_cancel_auth_timeout(wpa_s);
4754 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004755 eapol_sm_notify_portValid(wpa_s->eapol, true);
4756 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004757 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004758 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004759}
4760
4761
4762static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4763 int freq)
4764{
4765 size_t i;
4766 int j;
4767
4768 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4769 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4770
4771 for (j = 0; j < mode->num_channels; j++) {
4772 const struct hostapd_channel_data *chan;
4773
4774 chan = &mode->channels[j];
4775 if (chan->freq == freq)
4776 return chan->dfs_cac_ms;
4777 }
4778 }
4779
4780 return 0;
4781}
4782
4783
4784static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4785 struct dfs_event *radar)
4786{
4787#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004788 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004789 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4790 } else
4791#endif /* NEED_AP_MLME && CONFIG_AP */
4792 {
4793 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4794
4795 cac_time /= 1000; /* convert from ms to sec */
4796 if (!cac_time)
4797 cac_time = 10 * 60; /* max timeout: 10 minutes */
4798
4799 /* Restart auth timeout: CAC time added to initial timeout */
4800 wpas_auth_timeout_restart(wpa_s, cac_time);
4801 }
4802}
4803
4804
4805static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4806 struct dfs_event *radar)
4807{
4808#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004809 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004810 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4811 } else
4812#endif /* NEED_AP_MLME && CONFIG_AP */
4813 {
4814 /* Restart auth timeout with original value after CAC is
4815 * finished */
4816 wpas_auth_timeout_restart(wpa_s, 0);
4817 }
4818}
4819
4820
4821static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4822 struct dfs_event *radar)
4823{
4824#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004825 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004826 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4827 } else
4828#endif /* NEED_AP_MLME && CONFIG_AP */
4829 {
4830 /* Restart auth timeout with original value after CAC is
4831 * aborted */
4832 wpas_auth_timeout_restart(wpa_s, 0);
4833 }
4834}
4835
4836
4837static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4838 union wpa_event_data *data)
4839{
4840 wpa_dbg(wpa_s, MSG_DEBUG,
4841 "Connection authorized by device, previous state %d",
4842 wpa_s->wpa_state);
4843
4844 wpa_supplicant_event_port_authorized(wpa_s);
4845
Hai Shalomc1a21442022-02-04 13:43:00 -08004846 wpa_s->last_eapol_matches_bssid = 1;
4847
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004848 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4849 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004850 data->assoc_info.ptk_kck_len,
4851 data->assoc_info.ptk_kek,
4852 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004853#ifdef CONFIG_FILS
4854 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4855 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4856 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4857
4858 /* Update ERP next sequence number */
4859 eapol_sm_update_erp_next_seq_num(
4860 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4861
4862 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4863 /* Add the new PMK and PMKID to the PMKSA cache */
4864 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4865 data->assoc_info.fils_pmk,
4866 data->assoc_info.fils_pmk_len,
4867 data->assoc_info.fils_pmkid,
4868 wpa_s->bssid, fils_cache_id);
4869 } else if (data->assoc_info.fils_pmkid) {
4870 /* Update the current PMKSA used for this connection */
4871 pmksa_cache_set_current(wpa_s->wpa,
4872 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004873 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004874 }
4875 }
4876#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004877}
4878
4879
Hai Shalom60840252021-02-19 19:02:11 -08004880static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4881{
4882 switch (code) {
4883 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
4884 return "";
4885 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
4886 return "no_bss_found";
4887 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
4888 return "auth_tx_fail";
4889 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
4890 return "auth_no_ack_received";
4891 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
4892 return "auth_no_resp_received";
4893 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
4894 return "assoc_req_tx_fail";
4895 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
4896 return "assoc_no_ack_received";
4897 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
4898 return "assoc_no_resp_received";
4899 default:
4900 return "unknown_reason";
4901 }
4902}
4903
4904
Roshan Pius3a1667e2018-07-03 15:17:14 -07004905static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4906 union wpa_event_data *data)
4907{
4908 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004909#ifdef CONFIG_MBO
4910 struct wpa_bss *reject_bss;
4911#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004912
4913 if (!bssid || is_zero_ether_addr(bssid))
4914 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004915#ifdef CONFIG_MBO
4916 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4917 reject_bss = wpa_s->current_bss;
4918 else
4919 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4920#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004921
4922 if (data->assoc_reject.bssid)
4923 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004924 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004925 MAC2STR(data->assoc_reject.bssid),
4926 data->assoc_reject.status_code,
4927 data->assoc_reject.timed_out ? " timeout" : "",
4928 data->assoc_reject.timeout_reason ? "=" : "",
4929 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004930 data->assoc_reject.timeout_reason : "",
4931 data->assoc_reject.reason_code !=
4932 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4933 " qca_driver_reason=" : "",
4934 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004935 else
4936 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004937 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004938 data->assoc_reject.status_code,
4939 data->assoc_reject.timed_out ? " timeout" : "",
4940 data->assoc_reject.timeout_reason ? "=" : "",
4941 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004942 data->assoc_reject.timeout_reason : "",
4943 data->assoc_reject.reason_code !=
4944 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4945 " qca_driver_reason=" : "",
4946 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004947 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08004948 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
4949 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004950
4951#ifdef CONFIG_OWE
4952 if (data->assoc_reject.status_code ==
4953 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4954 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4955 wpa_s->current_ssid &&
4956 wpa_s->current_ssid->owe_group == 0 &&
4957 wpa_s->last_owe_group != 21) {
4958 struct wpa_ssid *ssid = wpa_s->current_ssid;
4959 struct wpa_bss *bss = wpa_s->current_bss;
4960
4961 if (!bss) {
4962 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4963 if (!bss) {
4964 wpas_connection_failed(wpa_s, bssid);
4965 wpa_supplicant_mark_disassoc(wpa_s);
4966 return;
4967 }
4968 }
4969 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4970 wpas_connect_work_done(wpa_s);
4971 wpa_supplicant_mark_disassoc(wpa_s);
4972 wpa_supplicant_connect(wpa_s, bss, ssid);
4973 return;
4974 }
4975#endif /* CONFIG_OWE */
4976
Hai Shalomfdcde762020-04-02 11:19:20 -07004977#ifdef CONFIG_DPP2
4978 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4979 * the status code defined in the DPP R2 tech spec.
4980 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4981 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004982 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004983 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4984 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4985 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004986 wpa_s->current_ssid->dpp_pfs == 0 &&
4987 (data->assoc_reject.status_code ==
4988 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4989 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4990 struct wpa_ssid *ssid = wpa_s->current_ssid;
4991 struct wpa_bss *bss = wpa_s->current_bss;
4992
4993 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4994 if (!bss)
4995 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4996 if (!bss || wpa_s->dpp_pfs_fallback) {
4997 wpa_printf(MSG_DEBUG,
4998 "DPP: Updated PFS policy for next try");
4999 wpas_connection_failed(wpa_s, bssid);
5000 wpa_supplicant_mark_disassoc(wpa_s);
5001 return;
5002 }
5003 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5004 wpa_s->dpp_pfs_fallback = 1;
5005 wpas_connect_work_done(wpa_s);
5006 wpa_supplicant_mark_disassoc(wpa_s);
5007 wpa_supplicant_connect(wpa_s, bss, ssid);
5008 return;
5009 }
5010#endif /* CONFIG_DPP2 */
5011
Hai Shalom74f70d42019-02-11 14:42:39 -08005012#ifdef CONFIG_MBO
5013 if (data->assoc_reject.status_code ==
5014 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005015 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005016 const u8 *rssi_rej;
5017
5018 rssi_rej = mbo_get_attr_from_ies(
5019 data->assoc_reject.resp_ies,
5020 data->assoc_reject.resp_ies_len,
5021 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5022 if (rssi_rej && rssi_rej[1] == 2) {
5023 wpa_printf(MSG_DEBUG,
5024 "OCE: RSSI-based association rejection from "
5025 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005026 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005027 rssi_rej[2], rssi_rej[3]);
5028 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005029 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005030 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005031 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005032 }
5033 }
5034#endif /* CONFIG_MBO */
5035
Roshan Pius3a1667e2018-07-03 15:17:14 -07005036 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5037 sme_event_assoc_reject(wpa_s, data);
5038 return;
5039 }
5040
5041 /* Driver-based SME cases */
5042
5043#ifdef CONFIG_SAE
5044 if (wpa_s->current_ssid &&
5045 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5046 !data->assoc_reject.timed_out) {
5047 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5048 wpa_sm_aborted_cached(wpa_s->wpa);
5049 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5050 }
5051#endif /* CONFIG_SAE */
5052
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005053#ifdef CONFIG_DPP
5054 if (wpa_s->current_ssid &&
5055 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5056 !data->assoc_reject.timed_out) {
5057 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5058 wpa_sm_aborted_cached(wpa_s->wpa);
5059 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5060 }
5061#endif /* CONFIG_DPP */
5062
Roshan Pius3a1667e2018-07-03 15:17:14 -07005063#ifdef CONFIG_FILS
5064 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005065 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005066 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005067 eapol_sm_update_erp_next_seq_num(
5068 wpa_s->eapol,
5069 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005070 fils_connection_failure(wpa_s);
5071 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005072#endif /* CONFIG_FILS */
5073
5074 wpas_connection_failed(wpa_s, bssid);
5075 wpa_supplicant_mark_disassoc(wpa_s);
5076}
5077
5078
Hai Shalomfdcde762020-04-02 11:19:20 -07005079static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5080 struct unprot_beacon *data)
5081{
5082 struct wpabuf *buf;
5083 int res;
5084
5085 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5086 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5087 return;
5088 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5089 MAC2STR(data->sa));
5090
5091 buf = wpabuf_alloc(4);
5092 if (!buf)
5093 return;
5094
5095 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5096 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5097 wpabuf_put_u8(buf, 1); /* Dialog Token */
5098 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5099
5100 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5101 wpa_s->own_addr, wpa_s->bssid,
5102 wpabuf_head(buf), wpabuf_len(buf), 0);
5103 if (res < 0)
5104 wpa_printf(MSG_DEBUG,
5105 "Failed to send WNM-Notification Request frame");
5106
5107 wpabuf_free(buf);
5108}
5109
5110
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005111void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5112 union wpa_event_data *data)
5113{
5114 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005115 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005116 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005117#ifndef CONFIG_NO_STDOUT_DEBUG
5118 int level = MSG_DEBUG;
5119#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005120
5121 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5122 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005123 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005124 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005125 event != EVENT_SCHED_SCAN_STOPPED) {
5126 wpa_dbg(wpa_s, MSG_DEBUG,
5127 "Ignore event %s (%d) while interface is disabled",
5128 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005129 return;
5130 }
5131
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005132#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005133 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005134 const struct ieee80211_hdr *hdr;
5135 u16 fc;
5136 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5137 fc = le_to_host16(hdr->frame_control);
5138 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5139 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5140 level = MSG_EXCESSIVE;
5141 }
5142
5143 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5144 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005145#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005146
5147 switch (event) {
5148 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005149#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005150 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5151 data->auth.ies_len))
5152 wpa_printf(MSG_DEBUG,
5153 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005154#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005155 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005156 wpa_s->auth_status_code = data->auth.status_code;
5157 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005158 break;
5159 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005160#ifdef CONFIG_TESTING_OPTIONS
5161 if (wpa_s->ignore_auth_resp) {
5162 wpa_printf(MSG_INFO,
5163 "EVENT_ASSOC - ignore_auth_resp active!");
5164 break;
5165 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005166 if (wpa_s->testing_resend_assoc) {
5167 wpa_printf(MSG_INFO,
5168 "EVENT_DEAUTH - testing_resend_assoc");
5169 break;
5170 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005171#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305172 if (wpa_s->disconnected) {
5173 wpa_printf(MSG_INFO,
5174 "Ignore unexpected EVENT_ASSOC in disconnected state");
5175 break;
5176 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005177 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005178 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005179 if (data &&
5180 (data->assoc_info.authorized ||
5181 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5182 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005183 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005184 if (data) {
5185 wpa_msg(wpa_s, MSG_INFO,
5186 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5187 data->assoc_info.subnet_status);
5188 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005189 break;
5190 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005191 wpas_event_disassoc(wpa_s,
5192 data ? &data->disassoc_info : NULL);
5193 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005194 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005195#ifdef CONFIG_TESTING_OPTIONS
5196 if (wpa_s->ignore_auth_resp) {
5197 wpa_printf(MSG_INFO,
5198 "EVENT_DEAUTH - ignore_auth_resp active!");
5199 break;
5200 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005201 if (wpa_s->testing_resend_assoc) {
5202 wpa_printf(MSG_INFO,
5203 "EVENT_DEAUTH - testing_resend_assoc");
5204 break;
5205 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005206#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005207 wpas_event_deauth(wpa_s,
5208 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005209 break;
5210 case EVENT_MICHAEL_MIC_FAILURE:
5211 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5212 break;
5213#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005214 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005215 if (wpa_s->own_scan_requested ||
5216 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005217 struct os_reltime diff;
5218
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005219 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005220 os_reltime_sub(&wpa_s->scan_start_time,
5221 &wpa_s->scan_trigger_time, &diff);
5222 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5223 diff.sec, diff.usec);
5224 wpa_s->own_scan_requested = 0;
5225 wpa_s->own_scan_running = 1;
5226 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5227 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005228 wpa_msg_ctrl(wpa_s, MSG_INFO,
5229 WPA_EVENT_SCAN_STARTED "id=%u",
5230 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005231 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005232 wpa_msg_ctrl(wpa_s, MSG_INFO,
5233 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005234 }
5235 } else {
5236 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005237 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005238 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005239 }
5240 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005241 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005242 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5243 wpa_s->scan_res_handler = NULL;
5244 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005245 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005246 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5247 break;
5248 }
5249
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005250 if (!(data && data->scan_info.external_scan) &&
5251 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005252 struct os_reltime now, diff;
5253 os_get_reltime(&now);
5254 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5255 wpa_s->scan_start_time.sec = 0;
5256 wpa_s->scan_start_time.usec = 0;
5257 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5258 diff.sec, diff.usec);
5259 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005260 if (wpa_supplicant_event_scan_results(wpa_s, data))
5261 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005262 if (!(data && data->scan_info.external_scan))
5263 wpa_s->own_scan_running = 0;
5264 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005265 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005266 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005267 break;
5268#endif /* CONFIG_NO_SCAN_PROCESSING */
5269 case EVENT_ASSOCINFO:
5270 wpa_supplicant_event_associnfo(wpa_s, data);
5271 break;
5272 case EVENT_INTERFACE_STATUS:
5273 wpa_supplicant_event_interface_status(wpa_s, data);
5274 break;
5275 case EVENT_PMKID_CANDIDATE:
5276 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5277 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005278#ifdef CONFIG_TDLS
5279 case EVENT_TDLS:
5280 wpa_supplicant_event_tdls(wpa_s, data);
5281 break;
5282#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005283#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005284 case EVENT_WNM:
5285 wpa_supplicant_event_wnm(wpa_s, data);
5286 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005287#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005288#ifdef CONFIG_IEEE80211R
5289 case EVENT_FT_RESPONSE:
5290 wpa_supplicant_event_ft_response(wpa_s, data);
5291 break;
5292#endif /* CONFIG_IEEE80211R */
5293#ifdef CONFIG_IBSS_RSN
5294 case EVENT_IBSS_RSN_START:
5295 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5296 break;
5297#endif /* CONFIG_IBSS_RSN */
5298 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005299 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005300 break;
5301 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005302 /* It is possible to get this event from earlier connection */
5303 if (wpa_s->current_ssid &&
5304 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5305 wpa_dbg(wpa_s, MSG_DEBUG,
5306 "Ignore AUTH_TIMED_OUT in mesh configuration");
5307 break;
5308 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005309 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5310 sme_event_auth_timed_out(wpa_s, data);
5311 break;
5312 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005313 /* It is possible to get this event from earlier connection */
5314 if (wpa_s->current_ssid &&
5315 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5316 wpa_dbg(wpa_s, MSG_DEBUG,
5317 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5318 break;
5319 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005320 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5321 sme_event_assoc_timed_out(wpa_s, data);
5322 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005323 case EVENT_TX_STATUS:
5324 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5325 " type=%d stype=%d",
5326 MAC2STR(data->tx_status.dst),
5327 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005328#ifdef CONFIG_PASN
5329 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5330 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5331 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5332 data->tx_status.data_len,
5333 data->tx_status.ack) == 0)
5334 break;
5335#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005336#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005337 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005338#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005339 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5340 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005341 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005342 wpa_s, data->tx_status.dst,
5343 data->tx_status.data,
5344 data->tx_status.data_len,
5345 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005346 OFFCHANNEL_SEND_ACTION_SUCCESS :
5347 OFFCHANNEL_SEND_ACTION_NO_ACK);
5348#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005349 break;
5350 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005351#endif /* CONFIG_AP */
5352#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005353 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005354 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005355 /*
5356 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005357 * interface in GO mode, or via standalone AP interface.
5358 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5359 * except when the primary interface is used as a GO interface
5360 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005361 */
5362 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5363 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005364 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005365 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005366 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005367 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005368 data->tx_status.data,
5369 data->tx_status.data_len,
5370 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005371 OFFCHANNEL_SEND_ACTION_SUCCESS :
5372 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005373 break;
5374 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005375#endif /* CONFIG_OFFCHANNEL */
5376#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005377 switch (data->tx_status.type) {
5378 case WLAN_FC_TYPE_MGMT:
5379 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5380 data->tx_status.data_len,
5381 data->tx_status.stype,
5382 data->tx_status.ack);
5383 break;
5384 case WLAN_FC_TYPE_DATA:
5385 ap_tx_status(wpa_s, data->tx_status.dst,
5386 data->tx_status.data,
5387 data->tx_status.data_len,
5388 data->tx_status.ack);
5389 break;
5390 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005391#endif /* CONFIG_AP */
5392 break;
5393#ifdef CONFIG_AP
5394 case EVENT_EAPOL_TX_STATUS:
5395 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5396 data->eapol_tx_status.data,
5397 data->eapol_tx_status.data_len,
5398 data->eapol_tx_status.ack);
5399 break;
5400 case EVENT_DRIVER_CLIENT_POLL_OK:
5401 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005402 break;
5403 case EVENT_RX_FROM_UNKNOWN:
5404 if (wpa_s->ap_iface == NULL)
5405 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005406 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5407 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005408 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005409#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005410
5411 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005412 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005413 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005414 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005415
Hai Shalom81f62d82019-07-22 12:10:00 -07005416 wpa_msg(wpa_s, MSG_INFO,
5417 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5418 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5419 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005420 data->ch_switch.freq,
5421 data->ch_switch.ht_enabled,
5422 data->ch_switch.ch_offset,
5423 channel_width_to_string(data->ch_switch.ch_width),
5424 data->ch_switch.cf1,
5425 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005426 if (event == EVENT_CH_SWITCH_STARTED)
5427 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005428
Sunil Ravi65a724b2022-05-24 11:06:09 -07005429 if (wpa_s->assoc_freq && data->ch_switch.freq &&
5430 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
5431 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
5432 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005433 wpa_s->assoc_freq = data->ch_switch.freq;
5434 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005435 if (wpa_s->current_bss &&
5436 wpa_s->current_bss->freq != data->ch_switch.freq) {
5437 wpa_s->current_bss->freq = data->ch_switch.freq;
5438 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5439 wpa_s->current_bss);
5440 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005441
Hai Shalomfdcde762020-04-02 11:19:20 -07005442#ifdef CONFIG_SME
5443 switch (data->ch_switch.ch_offset) {
5444 case 1:
5445 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5446 break;
5447 case -1:
5448 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5449 break;
5450 default:
5451 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5452 break;
5453 }
5454#endif /* CONFIG_SME */
5455
Roshan Pius3a1667e2018-07-03 15:17:14 -07005456#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005457 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5458 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005459 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005460 wpa_s->current_ssid->mode ==
5461 WPAS_MODE_P2P_GROUP_FORMATION) {
5462 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5463 data->ch_switch.ht_enabled,
5464 data->ch_switch.ch_offset,
5465 data->ch_switch.ch_width,
5466 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005467 data->ch_switch.cf2,
5468 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005469 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005470#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005471
Hai Shalom899fcc72020-10-19 14:38:18 -07005472 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5473 sme_event_ch_switch(wpa_s);
5474
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005475 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005476 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005477 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005478#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005479#ifdef NEED_AP_MLME
5480 case EVENT_DFS_RADAR_DETECTED:
5481 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005482 wpas_ap_event_dfs_radar_detected(wpa_s,
5483 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005484 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005485 case EVENT_DFS_NOP_FINISHED:
5486 if (data)
5487 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5488 &data->dfs_event);
5489 break;
5490#endif /* NEED_AP_MLME */
5491#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005492 case EVENT_DFS_CAC_STARTED:
5493 if (data)
5494 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5495 break;
5496 case EVENT_DFS_CAC_FINISHED:
5497 if (data)
5498 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5499 break;
5500 case EVENT_DFS_CAC_ABORTED:
5501 if (data)
5502 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5503 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005504 case EVENT_RX_MGMT: {
5505 u16 fc, stype;
5506 const struct ieee80211_mgmt *mgmt;
5507
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005508#ifdef CONFIG_TESTING_OPTIONS
5509 if (wpa_s->ext_mgmt_frame_handling) {
5510 struct rx_mgmt *rx = &data->rx_mgmt;
5511 size_t hex_len = 2 * rx->frame_len + 1;
5512 char *hex = os_malloc(hex_len);
5513 if (hex) {
5514 wpa_snprintf_hex(hex, hex_len,
5515 rx->frame, rx->frame_len);
5516 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5517 rx->freq, rx->datarate, rx->ssi_signal,
5518 hex);
5519 os_free(hex);
5520 }
5521 break;
5522 }
5523#endif /* CONFIG_TESTING_OPTIONS */
5524
Dmitry Shmidt04949592012-07-19 12:16:46 -07005525 mgmt = (const struct ieee80211_mgmt *)
5526 data->rx_mgmt.frame;
5527 fc = le_to_host16(mgmt->frame_control);
5528 stype = WLAN_FC_GET_STYPE(fc);
5529
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005530#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005531 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005532#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005533#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005534 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005535 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005536 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005537 const u8 *ie;
5538 size_t ie_len;
5539
5540 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5541 ie_len = data->rx_mgmt.frame_len -
5542 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005543 wpas_p2p_probe_req_rx(
5544 wpa_s, src, mgmt->da,
5545 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005546 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005547 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005548 break;
5549 }
5550#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005551#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005552 if (wpa_s->current_ssid &&
5553 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5554 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005555 data->rx_mgmt.frame_len >= 30) {
5556 wpa_supplicant_event_ibss_auth(wpa_s, data);
5557 break;
5558 }
5559#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005560
5561 if (stype == WLAN_FC_STYPE_ACTION) {
5562 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005563 wpa_s, data->rx_mgmt.frame,
5564 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005565 data->rx_mgmt.freq,
5566 data->rx_mgmt.ssi_signal);
5567 break;
5568 }
5569
5570 if (wpa_s->ifmsh) {
5571 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005572 break;
5573 }
Hai Shalom60840252021-02-19 19:02:11 -08005574#ifdef CONFIG_PASN
5575 if (stype == WLAN_FC_STYPE_AUTH &&
5576 wpas_pasn_auth_rx(wpa_s, mgmt,
5577 data->rx_mgmt.frame_len) != -2)
5578 break;
5579#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005580
Roshan Pius3a1667e2018-07-03 15:17:14 -07005581#ifdef CONFIG_SAE
5582 if (stype == WLAN_FC_STYPE_AUTH &&
5583 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5584 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5585 sme_external_auth_mgmt_rx(
5586 wpa_s, data->rx_mgmt.frame,
5587 data->rx_mgmt.frame_len);
5588 break;
5589 }
5590#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005591 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5592 "management frame in non-AP mode");
5593 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005594#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005595 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005596
5597 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005598 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5599 const u8 *ie;
5600 size_t ie_len;
5601
5602 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5603 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005604
5605 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5606 mgmt->bssid, ie, ie_len,
5607 data->rx_mgmt.ssi_signal);
5608 }
5609
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005610 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005611#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005612 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005613 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005614 case EVENT_RX_PROBE_REQ:
5615 if (data->rx_probe_req.sa == NULL ||
5616 data->rx_probe_req.ie == NULL)
5617 break;
5618#ifdef CONFIG_AP
5619 if (wpa_s->ap_iface) {
5620 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5621 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005622 data->rx_probe_req.da,
5623 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005624 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005625 data->rx_probe_req.ie_len,
5626 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005627 break;
5628 }
5629#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005630 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005631 data->rx_probe_req.da,
5632 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005633 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005634 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005635 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005636 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005637 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005638 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005639#ifdef CONFIG_OFFCHANNEL
5640 offchannel_remain_on_channel_cb(
5641 wpa_s, data->remain_on_channel.freq,
5642 data->remain_on_channel.duration);
5643#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005644 wpas_p2p_remain_on_channel_cb(
5645 wpa_s, data->remain_on_channel.freq,
5646 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005647#ifdef CONFIG_DPP
5648 wpas_dpp_remain_on_channel_cb(
5649 wpa_s, data->remain_on_channel.freq,
5650 data->remain_on_channel.duration);
5651#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005652 break;
5653 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005654#ifdef CONFIG_OFFCHANNEL
5655 offchannel_cancel_remain_on_channel_cb(
5656 wpa_s, data->remain_on_channel.freq);
5657#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005658 wpas_p2p_cancel_remain_on_channel_cb(
5659 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005660#ifdef CONFIG_DPP
5661 wpas_dpp_cancel_remain_on_channel_cb(
5662 wpa_s, data->remain_on_channel.freq);
5663#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005664 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005665 case EVENT_EAPOL_RX:
5666 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5667 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00005668 data->eapol_rx.data_len,
5669 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005670 break;
5671 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005672 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5673 "above=%d signal=%d noise=%d txrate=%d",
5674 data->signal_change.above_threshold,
5675 data->signal_change.current_signal,
5676 data->signal_change.current_noise,
5677 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005678 wpa_bss_update_level(wpa_s->current_bss,
5679 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005680 bgscan_notify_signal_change(
5681 wpa_s, data->signal_change.above_threshold,
5682 data->signal_change.current_signal,
5683 data->signal_change.current_noise,
5684 data->signal_change.current_txrate);
5685 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005686 case EVENT_INTERFACE_MAC_CHANGED:
5687 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005688 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005689 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005690 case EVENT_INTERFACE_ENABLED:
5691 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5692 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005693 u8 addr[ETH_ALEN];
5694
Hai Shalomfdcde762020-04-02 11:19:20 -07005695 eloop_cancel_timeout(wpas_clear_disabled_interface,
5696 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005697 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005698 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005699 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5700 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5701 else
5702 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005703 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005704 if (wpa_s->p2p_mgmt) {
5705 wpa_supplicant_set_state(wpa_s,
5706 WPA_DISCONNECTED);
5707 break;
5708 }
5709
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005710#ifdef CONFIG_AP
5711 if (!wpa_s->ap_iface) {
5712 wpa_supplicant_set_state(wpa_s,
5713 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005714 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005715 wpa_supplicant_req_scan(wpa_s, 0, 0);
5716 } else
5717 wpa_supplicant_set_state(wpa_s,
5718 WPA_COMPLETED);
5719#else /* CONFIG_AP */
5720 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5721 wpa_supplicant_req_scan(wpa_s, 0, 0);
5722#endif /* CONFIG_AP */
5723 }
5724 break;
5725 case EVENT_INTERFACE_DISABLED:
5726 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005727#ifdef CONFIG_P2P
5728 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5729 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5730 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5731 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005732 * Mark interface disabled if this happens to end up not
5733 * being removed as a separate P2P group interface.
5734 */
5735 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5736 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005737 * The interface was externally disabled. Remove
5738 * it assuming an external entity will start a
5739 * new session if needed.
5740 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005741 if (wpa_s->current_ssid &&
5742 wpa_s->current_ssid->p2p_group)
5743 wpas_p2p_interface_unavailable(wpa_s);
5744 else
5745 wpas_p2p_disconnect(wpa_s);
5746 /*
5747 * wpa_s instance may have been freed, so must not use
5748 * it here anymore.
5749 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005750 break;
5751 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005752 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5753 p2p_in_progress(wpa_s->global->p2p) > 1) {
5754 /* This radio work will be cancelled, so clear P2P
5755 * state as well.
5756 */
5757 p2p_stop_find(wpa_s->global->p2p);
5758 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005759#endif /* CONFIG_P2P */
5760
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005761 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5762 /*
5763 * Indicate disconnection to keep ctrl_iface events
5764 * consistent.
5765 */
5766 wpa_supplicant_event_disassoc(
5767 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5768 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005769 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005770 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005771 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5772 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005773 clear_at.usec = 0;
5774 } else {
5775 struct os_reltime tmp;
5776
Hai Shalom60840252021-02-19 19:02:11 -08005777 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005778 tmp.usec = 0;
5779 os_reltime_sub(&tmp, &age, &clear_at);
5780 }
5781 eloop_register_timeout(clear_at.sec, clear_at.usec,
5782 wpas_clear_disabled_interface,
5783 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005784 radio_remove_works(wpa_s, NULL, 0);
5785
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005786 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5787 break;
5788 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005789 wpa_supplicant_update_channel_list(
5790 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005791 break;
5792 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005793 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005794 break;
5795 case EVENT_BEST_CHANNEL:
5796 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5797 "(%d %d %d)",
5798 data->best_chan.freq_24, data->best_chan.freq_5,
5799 data->best_chan.freq_overall);
5800 wpa_s->best_24_freq = data->best_chan.freq_24;
5801 wpa_s->best_5_freq = data->best_chan.freq_5;
5802 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005803 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5804 data->best_chan.freq_5,
5805 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005806 break;
5807 case EVENT_UNPROT_DEAUTH:
5808 wpa_supplicant_event_unprot_deauth(wpa_s,
5809 &data->unprot_deauth);
5810 break;
5811 case EVENT_UNPROT_DISASSOC:
5812 wpa_supplicant_event_unprot_disassoc(wpa_s,
5813 &data->unprot_disassoc);
5814 break;
5815 case EVENT_STATION_LOW_ACK:
5816#ifdef CONFIG_AP
5817 if (wpa_s->ap_iface && data)
5818 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5819 data->low_ack.addr);
5820#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005821#ifdef CONFIG_TDLS
5822 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005823 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5824 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005825#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005826 break;
5827 case EVENT_IBSS_PEER_LOST:
5828#ifdef CONFIG_IBSS_RSN
5829 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5830#endif /* CONFIG_IBSS_RSN */
5831 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005832 case EVENT_DRIVER_GTK_REKEY:
5833 if (os_memcmp(data->driver_gtk_rekey.bssid,
5834 wpa_s->bssid, ETH_ALEN))
5835 break;
5836 if (!wpa_s->wpa)
5837 break;
5838 wpa_sm_update_replay_ctr(wpa_s->wpa,
5839 data->driver_gtk_rekey.replay_ctr);
5840 break;
5841 case EVENT_SCHED_SCAN_STOPPED:
5842 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005843 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005844 wpa_supplicant_notify_scanning(wpa_s, 0);
5845
5846 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5847 break;
5848
5849 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005850 * If the driver stopped scanning without being requested to,
5851 * request a new scan to continue scanning for networks.
5852 */
5853 if (!wpa_s->sched_scan_stop_req &&
5854 wpa_s->wpa_state == WPA_SCANNING) {
5855 wpa_dbg(wpa_s, MSG_DEBUG,
5856 "Restart scanning after unexpected sched_scan stop event");
5857 wpa_supplicant_req_scan(wpa_s, 1, 0);
5858 break;
5859 }
5860
5861 wpa_s->sched_scan_stop_req = 0;
5862
5863 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005864 * Start a new sched scan to continue searching for more SSIDs
5865 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005866 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005867 if (wpa_s->sched_scan_timed_out) {
5868 wpa_supplicant_req_sched_scan(wpa_s);
5869 } else if (wpa_s->pno_sched_pending) {
5870 wpa_s->pno_sched_pending = 0;
5871 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005872 } else if (resched) {
5873 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005874 }
5875
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005876 break;
5877 case EVENT_WPS_BUTTON_PUSHED:
5878#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005879 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005880#endif /* CONFIG_WPS */
5881 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005882 case EVENT_AVOID_FREQUENCIES:
5883 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5884 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005885 case EVENT_CONNECT_FAILED_REASON:
5886#ifdef CONFIG_AP
5887 if (!wpa_s->ap_iface || !data)
5888 break;
5889 hostapd_event_connect_failed_reason(
5890 wpa_s->ap_iface->bss[0],
5891 data->connect_failed_reason.addr,
5892 data->connect_failed_reason.code);
5893#endif /* CONFIG_AP */
5894 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005895 case EVENT_NEW_PEER_CANDIDATE:
5896#ifdef CONFIG_MESH
5897 if (!wpa_s->ifmsh || !data)
5898 break;
5899 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5900 data->mesh_peer.ies,
5901 data->mesh_peer.ie_len);
5902#endif /* CONFIG_MESH */
5903 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005904 case EVENT_SURVEY:
5905#ifdef CONFIG_AP
5906 if (!wpa_s->ap_iface)
5907 break;
5908 hostapd_event_get_survey(wpa_s->ap_iface,
5909 &data->survey_results);
5910#endif /* CONFIG_AP */
5911 break;
5912 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005913#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005914#ifdef CONFIG_ACS
5915 if (!wpa_s->ap_iface)
5916 break;
5917 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5918 &data->acs_selected_channels);
5919#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005920#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005921 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005922 case EVENT_P2P_LO_STOP:
5923#ifdef CONFIG_P2P
5924 wpa_s->p2p_lo_started = 0;
5925 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5926 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5927 data->p2p_lo_stop.reason_code);
5928#endif /* CONFIG_P2P */
5929 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005930 case EVENT_BEACON_LOSS:
5931 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5932 break;
5933 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5934 bgscan_notify_beacon_loss(wpa_s);
5935 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005936 case EVENT_EXTERNAL_AUTH:
5937#ifdef CONFIG_SAE
5938 if (!wpa_s->current_ssid) {
5939 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5940 break;
5941 }
5942 sme_external_auth_trigger(wpa_s, data);
5943#endif /* CONFIG_SAE */
5944 break;
5945 case EVENT_PORT_AUTHORIZED:
5946 wpa_supplicant_event_port_authorized(wpa_s);
5947 break;
5948 case EVENT_STATION_OPMODE_CHANGED:
5949#ifdef CONFIG_AP
5950 if (!wpa_s->ap_iface || !data)
5951 break;
5952
5953 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5954 data->sta_opmode.addr,
5955 data->sta_opmode.smps_mode,
5956 data->sta_opmode.chan_width,
5957 data->sta_opmode.rx_nss);
5958#endif /* CONFIG_AP */
5959 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005960 case EVENT_UNPROT_BEACON:
5961 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5962 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08005963 case EVENT_TX_WAIT_EXPIRE:
5964#ifdef CONFIG_DPP
5965 wpas_dpp_tx_wait_expire(wpa_s);
5966#endif /* CONFIG_DPP */
5967 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005968 default:
5969 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5970 break;
5971 }
5972}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005973
5974
5975void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5976 union wpa_event_data *data)
5977{
5978 struct wpa_supplicant *wpa_s;
5979
5980 if (event != EVENT_INTERFACE_STATUS)
5981 return;
5982
5983 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5984 if (wpa_s && wpa_s->driver->get_ifindex) {
5985 unsigned int ifindex;
5986
5987 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5988 if (ifindex != data->interface_status.ifindex) {
5989 wpa_dbg(wpa_s, MSG_DEBUG,
5990 "interface status ifindex %d mismatch (%d)",
5991 ifindex, data->interface_status.ifindex);
5992 return;
5993 }
5994 }
5995#ifdef CONFIG_MATCH_IFACE
5996 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5997 struct wpa_interface *wpa_i;
5998
5999 wpa_i = wpa_supplicant_match_iface(
6000 ctx, data->interface_status.ifname);
6001 if (!wpa_i)
6002 return;
6003 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6004 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006005 }
6006#endif /* CONFIG_MATCH_IFACE */
6007
6008 if (wpa_s)
6009 wpa_supplicant_event(wpa_s, event, data);
6010}