blob: 170cec788dce572fbf3c1e45b22010abfb0ce18e [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)
Mir Ali677e7482020-11-12 19:49:02 +05303476 /* For driver based roaming, insert PSK during the initial association */
3477 if (is_zero_ether_addr(wpa_s->bssid) &&
3478 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3479 /* In case the driver wants to handle re-assocs, pass it down the PMK. */
3480 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3481 wpa_sm_install_pmk(wpa_s->wpa);
3482 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003483#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3484
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003485 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003486 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003487 if (os_reltime_initialized(&wpa_s->session_start)) {
3488 os_reltime_age(&wpa_s->session_start,
3489 &wpa_s->session_length);
3490 wpa_s->session_start.sec = 0;
3491 wpa_s->session_start.usec = 0;
3492 wpas_notify_session_length(wpa_s);
3493 } else {
3494 wpas_notify_auth_changed(wpa_s);
3495 os_get_reltime(&wpa_s->session_start);
3496 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003497 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3498 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003499 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003500 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003501 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3502 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003503 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003504
3505 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3506 wpa_clear_keys(wpa_s, bssid);
3507 }
3508 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003509 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003510 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3511 return;
3512 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003513 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003514
Hai Shalomc1a21442022-02-04 13:43:00 -08003515 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3516 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3517 return;
3518
Hai Shalomfdcde762020-04-02 11:19:20 -07003519 multi_ap_set_4addr_mode(wpa_s);
3520
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003521 if (wpa_s->conf->ap_scan == 1 &&
3522 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003523 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3524 wpa_msg(wpa_s, MSG_WARNING,
3525 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003526 }
3527
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003528 wpas_fst_update_mb_assoc(wpa_s, data);
3529
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003530#ifdef CONFIG_SME
3531 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3532 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003533 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003534#endif /* CONFIG_SME */
3535
3536 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3537 if (wpa_s->current_ssid) {
3538 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3539 * initialized before association, but for other modes,
3540 * initialize PC/SC here, if the current configuration needs
3541 * smartcard or SIM/USIM. */
3542 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3543 }
3544 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3545 if (wpa_s->l2)
3546 l2_packet_notify_auth_start(wpa_s->l2);
3547
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003548 already_authorized = data && data->assoc_info.authorized;
3549
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003550 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003551 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003552 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3553 * state machine may transit to AUTHENTICATING state based on obsolete
3554 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3555 * AUTHENTICATED without ever giving chance to EAP state machine to
3556 * reset the state.
3557 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003558 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003559 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3560 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003561 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003562 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3563 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3564 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003565 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003566 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003567 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003568 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003569 wpa_s->eapol_received = 0;
3570 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3571 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3572 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003573 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003574 if (wpa_s->current_ssid &&
3575 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003576 (wpa_s->drv_flags &
3577 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3578 /*
3579 * Set the key after having received joined-IBSS event
3580 * from the driver.
3581 */
3582 wpa_supplicant_set_wpa_none_key(wpa_s,
3583 wpa_s->current_ssid);
3584 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003585 wpa_supplicant_cancel_auth_timeout(wpa_s);
3586 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3587 } else if (!ft_completed) {
3588 /* Timeout for receiving the first EAPOL packet */
3589 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3590 }
3591 wpa_supplicant_cancel_scan(wpa_s);
3592
Hai Shalom5f92bc92019-04-18 11:54:11 -07003593 if (ft_completed) {
3594 /*
3595 * FT protocol completed - make sure EAPOL state machine ends
3596 * up in authenticated.
3597 */
3598 wpa_supplicant_cancel_auth_timeout(wpa_s);
3599 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003600 eapol_sm_notify_portValid(wpa_s->eapol, true);
3601 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003602 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3603 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003604 /*
3605 * We are done; the driver will take care of RSN 4-way
3606 * handshake.
3607 */
3608 wpa_supplicant_cancel_auth_timeout(wpa_s);
3609 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003610 eapol_sm_notify_portValid(wpa_s->eapol, true);
3611 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003612 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003613 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3614 /*
3615 * The driver will take care of RSN 4-way handshake, so we need
3616 * to allow EAPOL supplicant to complete its work without
3617 * waiting for WPA supplicant.
3618 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003619 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003620 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003621#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303622 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3623 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3624 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3625 wpa_s->key_mgmt);
3626 wpa_supplicant_deauthenticate(
3627 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3628 return;
3629 }
3630 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3631 wpa_s->assoc_freq = data->assoc_info.freq;
3632 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3633 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003634#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3635
Jouni Malinena05074c2012-12-21 21:35:35 +02003636 wpa_s->last_eapol_matches_bssid = 0;
3637
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003638#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003639 if (wpa_s->rsne_override_eapol) {
3640 wpa_printf(MSG_DEBUG,
3641 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3642 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3643 wpabuf_head(wpa_s->rsne_override_eapol),
3644 wpabuf_len(wpa_s->rsne_override_eapol));
3645 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003646 if (wpa_s->rsnxe_override_eapol) {
3647 wpa_printf(MSG_DEBUG,
3648 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3649 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3650 wpabuf_head(wpa_s->rsnxe_override_eapol),
3651 wpabuf_len(wpa_s->rsnxe_override_eapol));
3652 }
3653#endif /* CONFIG_TESTING_OPTIONS */
3654
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003655 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003656 struct os_reltime now, age;
3657 os_get_reltime(&now);
3658 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003659 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003660 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3661 0) {
3662 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3663 "frame that was received just before "
3664 "association notification");
3665 wpa_supplicant_rx_eapol(
3666 wpa_s, wpa_s->pending_eapol_rx_src,
3667 wpabuf_head(wpa_s->pending_eapol_rx),
3668 wpabuf_len(wpa_s->pending_eapol_rx));
3669 }
3670 wpabuf_free(wpa_s->pending_eapol_rx);
3671 wpa_s->pending_eapol_rx = NULL;
3672 }
3673
Hai Shalomfdcde762020-04-02 11:19:20 -07003674#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003675 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3676 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003677 wpa_s->current_ssid &&
3678 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003679 /* Set static WEP keys again */
3680 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3681 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003682#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003683
3684#ifdef CONFIG_IBSS_RSN
3685 if (wpa_s->current_ssid &&
3686 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3687 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3688 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3689 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003690 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003691 if (!wpa_s->ibss_rsn) {
3692 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3693 wpa_supplicant_deauthenticate(
3694 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3695 return;
3696 }
3697
3698 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3699 }
3700#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003701
3702 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003703
3704 if (data) {
3705 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3706 data->assoc_info.resp_ies_len,
3707 &data->assoc_info.wmm_params);
3708
3709 if (wpa_s->reassoc_same_bss)
3710 wmm_ac_restore_tspecs(wpa_s);
3711 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003712
Hai Shalomc3565922019-10-28 11:58:20 -07003713#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3714 bss = wpa_bss_get_bssid(wpa_s, bssid);
3715#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003716#ifdef CONFIG_FILS
3717 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003718 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3719
3720 if (fils_cache_id)
3721 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3722 }
3723#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003724
3725#ifdef CONFIG_MBO
3726 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3727#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003728
3729#ifdef CONFIG_DPP2
3730 wpa_s->dpp_pfs_fallback = 0;
3731#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003732}
3733
3734
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003735static int disconnect_reason_recoverable(u16 reason_code)
3736{
3737 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3738 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3739 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3740}
3741
3742
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003743static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003744 u16 reason_code,
3745 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003746{
3747 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003748
3749 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3750 /*
3751 * At least Host AP driver and a Prism3 card seemed to be
3752 * generating streams of disconnected events when configuring
3753 * IBSS for WPA-None. Ignore them for now.
3754 */
3755 return;
3756 }
3757
3758 bssid = wpa_s->bssid;
3759 if (is_zero_ether_addr(bssid))
3760 bssid = wpa_s->pending_bssid;
3761
3762 if (!is_zero_ether_addr(bssid) ||
3763 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3764 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3765 " reason=%d%s",
3766 MAC2STR(bssid), reason_code,
3767 locally_generated ? " locally_generated=1" : "");
3768 }
3769}
3770
3771
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003772static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3773 int locally_generated)
3774{
3775 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003776 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003777 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3778 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003779 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003780
3781 /*
3782 * It looks like connection was lost while trying to go through PSK
3783 * 4-way handshake. Filter out known disconnection cases that are caused
3784 * by something else than PSK mismatch to avoid confusing reports.
3785 */
3786
3787 if (locally_generated) {
3788 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3789 return 0;
3790 }
3791
3792 return 1;
3793}
3794
3795
Jouni Malinen2b89da82012-08-31 22:04:41 +03003796static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3797 u16 reason_code,
3798 int locally_generated)
3799{
3800 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003801 int authenticating;
3802 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003803 struct wpa_bss *fast_reconnect = NULL;
3804 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003805 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003806 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003807
3808 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3809 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3810
3811 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3812 /*
3813 * At least Host AP driver and a Prism3 card seemed to be
3814 * generating streams of disconnected events when configuring
3815 * IBSS for WPA-None. Ignore them for now.
3816 */
3817 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3818 "IBSS/WPA-None mode");
3819 return;
3820 }
3821
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003822 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3823 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3824 locally_generated)
3825 /*
3826 * Remove the inactive AP (which is probably out of range) from
3827 * the BSS list after marking disassociation. In particular
3828 * mac80211-based drivers use the
3829 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3830 * locally generated disconnection events for cases where the
3831 * AP does not reply anymore.
3832 */
3833 curr = wpa_s->current_bss;
3834
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003835 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003836 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3837 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003838 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3839 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003840 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003841#ifdef CONFIG_DPP2
3842 wpas_dpp_send_conn_status_result(wpa_s,
3843 DPP_STATUS_AUTH_FAILURE);
3844#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003845 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003846 if (!wpa_s->disconnected &&
3847 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003848 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003849 wpas_wps_searching(wpa_s) ||
3850 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003851 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003852 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003853 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003854 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003855 wpa_s->wpa_state);
3856 if (wpa_s->wpa_state == WPA_COMPLETED &&
3857 wpa_s->current_ssid &&
3858 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003859 (wpa_s->own_reconnect_req ||
3860 (!locally_generated &&
3861 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003862 /*
3863 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003864 * us, but could allow us to get back in. This is also
3865 * triggered for cases where local reconnection request
3866 * is used to force reassociation with the same BSS.
3867 * Try to reconnect to the same BSS without a full scan
3868 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003869 */
3870 fast_reconnect = wpa_s->current_bss;
3871 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003872 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003873 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003874 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003875 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3876 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003877 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003878 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003879 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003880 "try to re-connect");
3881 wpa_s->reassociate = 0;
3882 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003883 if (!wpa_s->pno)
3884 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003885 }
3886 bssid = wpa_s->bssid;
3887 if (is_zero_ether_addr(bssid))
3888 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003889 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3890 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003891 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08003892 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
3893
Dmitry Shmidt04949592012-07-19 12:16:46 -07003894 if (locally_generated)
3895 wpa_s->disconnect_reason = -reason_code;
3896 else
3897 wpa_s->disconnect_reason = reason_code;
3898 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003899 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3900 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003901 wpa_clear_keys(wpa_s, wpa_s->bssid);
3902 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003903 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003904 wpa_supplicant_mark_disassoc(wpa_s);
3905
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003906 if (curr)
3907 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3908
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003909 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003910 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003911 wpa_s->current_ssid = last_ssid;
3912 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003913
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003914 if (fast_reconnect &&
3915 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3916 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3917 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3918 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003919 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003920 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003921#ifndef CONFIG_NO_SCAN_PROCESSING
3922 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3923 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3924 fast_reconnect_ssid) < 0) {
3925 /* Recover through full scan */
3926 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3927 }
3928#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003929 } else if (fast_reconnect) {
3930 /*
3931 * Could not reconnect to the same BSS due to network being
3932 * disabled. Use a new scan to match the alternative behavior
3933 * above, i.e., to continue automatic reconnection attempt in a
3934 * way that enforces disabled network rules.
3935 */
3936 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003937 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003938}
3939
3940
3941#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003942void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003943{
3944 struct wpa_supplicant *wpa_s = eloop_ctx;
3945
3946 if (!wpa_s->pending_mic_error_report)
3947 return;
3948
3949 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3950 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3951 wpa_s->pending_mic_error_report = 0;
3952}
3953#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3954
3955
3956static void
3957wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3958 union wpa_event_data *data)
3959{
3960 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003961 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003962
3963 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3964 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003965 os_get_reltime(&t);
3966 if ((wpa_s->last_michael_mic_error.sec &&
3967 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003968 wpa_s->pending_mic_error_report) {
3969 if (wpa_s->pending_mic_error_report) {
3970 /*
3971 * Send the pending MIC error report immediately since
3972 * we are going to start countermeasures and AP better
3973 * do the same.
3974 */
3975 wpa_sm_key_request(wpa_s->wpa, 1,
3976 wpa_s->pending_mic_error_pairwise);
3977 }
3978
3979 /* Send the new MIC error report immediately since we are going
3980 * to start countermeasures and AP better do the same.
3981 */
3982 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3983
3984 /* initialize countermeasures */
3985 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003986
Hai Shalom60840252021-02-19 19:02:11 -08003987 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003988
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003989 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3990
3991 /*
3992 * Need to wait for completion of request frame. We do not get
3993 * any callback for the message completion, so just wait a
3994 * short while and hope for the best. */
3995 os_sleep(0, 10000);
3996
3997 wpa_drv_set_countermeasures(wpa_s, 1);
3998 wpa_supplicant_deauthenticate(wpa_s,
3999 WLAN_REASON_MICHAEL_MIC_FAILURE);
4000 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4001 wpa_s, NULL);
4002 eloop_register_timeout(60, 0,
4003 wpa_supplicant_stop_countermeasures,
4004 wpa_s, NULL);
4005 /* TODO: mark the AP rejected for 60 second. STA is
4006 * allowed to associate with another AP.. */
4007 } else {
4008#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4009 if (wpa_s->mic_errors_seen) {
4010 /*
4011 * Reduce the effectiveness of Michael MIC error
4012 * reports as a means for attacking against TKIP if
4013 * more than one MIC failure is noticed with the same
4014 * PTK. We delay the transmission of the reports by a
4015 * random time between 0 and 60 seconds in order to
4016 * force the attacker wait 60 seconds before getting
4017 * the information on whether a frame resulted in a MIC
4018 * failure.
4019 */
4020 u8 rval[4];
4021 int sec;
4022
4023 if (os_get_random(rval, sizeof(rval)) < 0)
4024 sec = os_random() % 60;
4025 else
4026 sec = WPA_GET_BE32(rval) % 60;
4027 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4028 "report %d seconds", sec);
4029 wpa_s->pending_mic_error_report = 1;
4030 wpa_s->pending_mic_error_pairwise = pairwise;
4031 eloop_cancel_timeout(
4032 wpa_supplicant_delayed_mic_error_report,
4033 wpa_s, NULL);
4034 eloop_register_timeout(
4035 sec, os_random() % 1000000,
4036 wpa_supplicant_delayed_mic_error_report,
4037 wpa_s, NULL);
4038 } else {
4039 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4040 }
4041#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4042 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4043#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4044 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004045 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004046 wpa_s->mic_errors_seen++;
4047}
4048
4049
4050#ifdef CONFIG_TERMINATE_ONLASTIF
4051static int any_interfaces(struct wpa_supplicant *head)
4052{
4053 struct wpa_supplicant *wpa_s;
4054
4055 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4056 if (!wpa_s->interface_removed)
4057 return 1;
4058 return 0;
4059}
4060#endif /* CONFIG_TERMINATE_ONLASTIF */
4061
4062
4063static void
4064wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4065 union wpa_event_data *data)
4066{
4067 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4068 return;
4069
4070 switch (data->interface_status.ievent) {
4071 case EVENT_INTERFACE_ADDED:
4072 if (!wpa_s->interface_removed)
4073 break;
4074 wpa_s->interface_removed = 0;
4075 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4076 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4077 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4078 "driver after interface was added");
4079 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004080
4081#ifdef CONFIG_P2P
4082 if (!wpa_s->global->p2p &&
4083 !wpa_s->global->p2p_disabled &&
4084 !wpa_s->conf->p2p_disabled &&
4085 (wpa_s->drv_flags &
4086 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4087 wpas_p2p_add_p2pdev_interface(
4088 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4089 wpa_printf(MSG_INFO,
4090 "P2P: Failed to enable P2P Device interface");
4091 /* Try to continue without. P2P will be disabled. */
4092 }
4093#endif /* CONFIG_P2P */
4094
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004095 break;
4096 case EVENT_INTERFACE_REMOVED:
4097 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4098 wpa_s->interface_removed = 1;
4099 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004100 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004101 l2_packet_deinit(wpa_s->l2);
4102 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004103
4104#ifdef CONFIG_P2P
4105 if (wpa_s->global->p2p &&
4106 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4107 (wpa_s->drv_flags &
4108 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4109 wpa_dbg(wpa_s, MSG_DEBUG,
4110 "Removing P2P Device interface");
4111 wpa_supplicant_remove_iface(
4112 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4113 0);
4114 wpa_s->global->p2p_init_wpa_s = NULL;
4115 }
4116#endif /* CONFIG_P2P */
4117
Dmitry Shmidte4663042016-04-04 10:07:49 -07004118#ifdef CONFIG_MATCH_IFACE
4119 if (wpa_s->matched) {
4120 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4121 break;
4122 }
4123#endif /* CONFIG_MATCH_IFACE */
4124
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004125#ifdef CONFIG_TERMINATE_ONLASTIF
4126 /* check if last interface */
4127 if (!any_interfaces(wpa_s->global->ifaces))
4128 eloop_terminate();
4129#endif /* CONFIG_TERMINATE_ONLASTIF */
4130 break;
4131 }
4132}
4133
4134
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004135#ifdef CONFIG_TDLS
4136static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4137 union wpa_event_data *data)
4138{
4139 if (data == NULL)
4140 return;
4141 switch (data->tdls.oper) {
4142 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004143 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4144 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4145 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4146 else
4147 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004148 break;
4149 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004150 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4151 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4152 data->tdls.reason_code);
4153 else
4154 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4155 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004156 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004157 case TDLS_REQUEST_DISCOVER:
4158 wpa_tdls_send_discovery_request(wpa_s->wpa,
4159 data->tdls.peer);
4160 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004161 }
4162}
4163#endif /* CONFIG_TDLS */
4164
4165
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004166#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004167static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4168 union wpa_event_data *data)
4169{
4170 if (data == NULL)
4171 return;
4172 switch (data->wnm.oper) {
4173 case WNM_OPER_SLEEP:
4174 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4175 "(action=%d, intval=%d)",
4176 data->wnm.sleep_action, data->wnm.sleep_intval);
4177 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004178 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004179 break;
4180 }
4181}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004182#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004183
4184
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004185#ifdef CONFIG_IEEE80211R
4186static void
4187wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4188 union wpa_event_data *data)
4189{
4190 if (data == NULL)
4191 return;
4192
4193 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4194 data->ft_ies.ies_len,
4195 data->ft_ies.ft_action,
4196 data->ft_ies.target_ap,
4197 data->ft_ies.ric_ies,
4198 data->ft_ies.ric_ies_len) < 0) {
4199 /* TODO: prevent MLME/driver from trying to associate? */
4200 }
4201}
4202#endif /* CONFIG_IEEE80211R */
4203
4204
4205#ifdef CONFIG_IBSS_RSN
4206static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4207 union wpa_event_data *data)
4208{
4209 struct wpa_ssid *ssid;
4210 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4211 return;
4212 if (data == NULL)
4213 return;
4214 ssid = wpa_s->current_ssid;
4215 if (ssid == NULL)
4216 return;
4217 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4218 return;
4219
4220 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4221}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004222
4223
4224static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4225 union wpa_event_data *data)
4226{
4227 struct wpa_ssid *ssid = wpa_s->current_ssid;
4228
4229 if (ssid == NULL)
4230 return;
4231
4232 /* check if the ssid is correctly configured as IBSS/RSN */
4233 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4234 return;
4235
4236 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4237 data->rx_mgmt.frame_len);
4238}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004239#endif /* CONFIG_IBSS_RSN */
4240
4241
4242#ifdef CONFIG_IEEE80211R
4243static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4244 size_t len)
4245{
4246 const u8 *sta_addr, *target_ap_addr;
4247 u16 status;
4248
4249 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4250 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4251 return; /* only SME case supported for now */
4252 if (len < 1 + 2 * ETH_ALEN + 2)
4253 return;
4254 if (data[0] != 2)
4255 return; /* Only FT Action Response is supported for now */
4256 sta_addr = data + 1;
4257 target_ap_addr = data + 1 + ETH_ALEN;
4258 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4259 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4260 MACSTR " TargetAP " MACSTR " status %u",
4261 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4262
4263 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4264 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4265 " in FT Action Response", MAC2STR(sta_addr));
4266 return;
4267 }
4268
4269 if (status) {
4270 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4271 "failure (status code %d)", status);
4272 /* TODO: report error to FT code(?) */
4273 return;
4274 }
4275
4276 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4277 len - (1 + 2 * ETH_ALEN + 2), 1,
4278 target_ap_addr, NULL, 0) < 0)
4279 return;
4280
4281#ifdef CONFIG_SME
4282 {
4283 struct wpa_bss *bss;
4284 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4285 if (bss)
4286 wpa_s->sme.freq = bss->freq;
4287 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4288 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4289 WLAN_AUTH_FT);
4290 }
4291#endif /* CONFIG_SME */
4292}
4293#endif /* CONFIG_IEEE80211R */
4294
4295
4296static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4297 struct unprot_deauth *e)
4298{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004299 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4300 "dropped: " MACSTR " -> " MACSTR
4301 " (reason code %u)",
4302 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4303 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004304}
4305
4306
4307static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4308 struct unprot_disassoc *e)
4309{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004310 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4311 "dropped: " MACSTR " -> " MACSTR
4312 " (reason code %u)",
4313 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4314 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004315}
4316
4317
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004318static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4319 u16 reason_code, int locally_generated,
4320 const u8 *ie, size_t ie_len, int deauth)
4321{
4322#ifdef CONFIG_AP
4323 if (wpa_s->ap_iface && addr) {
4324 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4325 return;
4326 }
4327
4328 if (wpa_s->ap_iface) {
4329 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4330 return;
4331 }
4332#endif /* CONFIG_AP */
4333
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004334 if (!locally_generated)
4335 wpa_s->own_disconnect_req = 0;
4336
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004337 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4338
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004339 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4340 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4341 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4342 eapol_sm_failed(wpa_s->eapol))) &&
4343 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004344 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004345
4346#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004347 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004348 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4349 locally_generated) > 0) {
4350 /*
4351 * The interface was removed, so cannot continue
4352 * processing any additional operations after this.
4353 */
4354 return;
4355 }
4356 }
4357#endif /* CONFIG_P2P */
4358
4359 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4360 locally_generated);
4361}
4362
4363
4364static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4365 struct disassoc_info *info)
4366{
4367 u16 reason_code = 0;
4368 int locally_generated = 0;
4369 const u8 *addr = NULL;
4370 const u8 *ie = NULL;
4371 size_t ie_len = 0;
4372
4373 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4374
4375 if (info) {
4376 addr = info->addr;
4377 ie = info->ie;
4378 ie_len = info->ie_len;
4379 reason_code = info->reason_code;
4380 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004381 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4382 reason2str(reason_code),
4383 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004384 if (addr)
4385 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4386 MAC2STR(addr));
4387 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4388 ie, ie_len);
4389 }
4390
4391#ifdef CONFIG_AP
4392 if (wpa_s->ap_iface && info && info->addr) {
4393 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4394 return;
4395 }
4396
4397 if (wpa_s->ap_iface) {
4398 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4399 return;
4400 }
4401#endif /* CONFIG_AP */
4402
4403#ifdef CONFIG_P2P
4404 if (info) {
4405 wpas_p2p_disassoc_notif(
4406 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4407 locally_generated);
4408 }
4409#endif /* CONFIG_P2P */
4410
4411 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4412 sme_event_disassoc(wpa_s, info);
4413
4414 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4415 ie, ie_len, 0);
4416}
4417
4418
4419static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4420 struct deauth_info *info)
4421{
4422 u16 reason_code = 0;
4423 int locally_generated = 0;
4424 const u8 *addr = NULL;
4425 const u8 *ie = NULL;
4426 size_t ie_len = 0;
4427
4428 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4429
4430 if (info) {
4431 addr = info->addr;
4432 ie = info->ie;
4433 ie_len = info->ie_len;
4434 reason_code = info->reason_code;
4435 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004436 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4437 reason_code, reason2str(reason_code),
4438 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004439 if (addr) {
4440 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4441 MAC2STR(addr));
4442 }
4443 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4444 ie, ie_len);
4445 }
4446
4447 wpa_reset_ft_completed(wpa_s->wpa);
4448
4449 wpas_event_disconnect(wpa_s, addr, reason_code,
4450 locally_generated, ie, ie_len, 1);
4451}
4452
4453
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004454static const char * reg_init_str(enum reg_change_initiator init)
4455{
4456 switch (init) {
4457 case REGDOM_SET_BY_CORE:
4458 return "CORE";
4459 case REGDOM_SET_BY_USER:
4460 return "USER";
4461 case REGDOM_SET_BY_DRIVER:
4462 return "DRIVER";
4463 case REGDOM_SET_BY_COUNTRY_IE:
4464 return "COUNTRY_IE";
4465 case REGDOM_BEACON_HINT:
4466 return "BEACON_HINT";
4467 }
4468 return "?";
4469}
4470
4471
4472static const char * reg_type_str(enum reg_type type)
4473{
4474 switch (type) {
4475 case REGDOM_TYPE_UNKNOWN:
4476 return "UNKNOWN";
4477 case REGDOM_TYPE_COUNTRY:
4478 return "COUNTRY";
4479 case REGDOM_TYPE_WORLD:
4480 return "WORLD";
4481 case REGDOM_TYPE_CUSTOM_WORLD:
4482 return "CUSTOM_WORLD";
4483 case REGDOM_TYPE_INTERSECTION:
4484 return "INTERSECTION";
4485 }
4486 return "?";
4487}
4488
4489
Hai Shalom74f70d42019-02-11 14:42:39 -08004490void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4491 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004492{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004493 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004494 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004495
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004496 /*
4497 * To allow backwards compatibility with higher level layers that
4498 * assumed the REGDOM_CHANGE event is sent over the initially added
4499 * interface. Find the highest parent of this interface and use it to
4500 * send the event.
4501 */
4502 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4503 ;
4504
Hai Shalom74f70d42019-02-11 14:42:39 -08004505 if (info) {
4506 wpa_msg(ifs, MSG_INFO,
4507 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4508 reg_init_str(info->initiator), reg_type_str(info->type),
4509 info->alpha2[0] ? " alpha2=" : "",
4510 info->alpha2[0] ? info->alpha2 : "");
4511 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004512
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004513 if (wpa_s->drv_priv == NULL)
4514 return; /* Ignore event during drv initialization */
4515
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004516 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4517 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004518 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4519 ifs->ifname);
4520 free_hw_features(ifs);
4521 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004522 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004523
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004524 /* Restart PNO/sched_scan with updated channel list */
4525 if (ifs->pno) {
4526 wpas_stop_pno(ifs);
4527 wpas_start_pno(ifs);
4528 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4529 wpa_dbg(ifs, MSG_DEBUG,
4530 "Channel list changed - restart sched_scan");
4531 wpas_scan_restart_sched_scan(ifs);
4532 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004533 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004534
4535 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004536}
4537
4538
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004539static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004540 const u8 *frame, size_t len, int freq,
4541 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004542{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004543 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004544 const u8 *payload;
4545 size_t plen;
4546 u8 category;
4547
4548 if (len < IEEE80211_HDRLEN + 2)
4549 return;
4550
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004551 mgmt = (const struct ieee80211_mgmt *) frame;
4552 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004553 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004554 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004555
4556 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4557 " Category=%u DataLen=%d freq=%d MHz",
4558 MAC2STR(mgmt->sa), category, (int) plen, freq);
4559
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004560 if (category == WLAN_ACTION_WMM) {
4561 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4562 return;
4563 }
4564
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004565#ifdef CONFIG_IEEE80211R
4566 if (category == WLAN_ACTION_FT) {
4567 ft_rx_action(wpa_s, payload, plen);
4568 return;
4569 }
4570#endif /* CONFIG_IEEE80211R */
4571
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004572#ifdef CONFIG_SME
4573 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004574 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004575 return;
4576 }
4577#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004578
4579#ifdef CONFIG_WNM
4580 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4581 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4582 return;
4583 }
4584#endif /* CONFIG_WNM */
4585
4586#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004587 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4588 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004589 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004590 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004591 payload, plen, freq) == 0)
4592 return;
4593#endif /* CONFIG_GAS */
4594
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004595#ifdef CONFIG_GAS_SERVER
4596 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4597 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4598 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4599 mgmt->u.action.category,
4600 payload, plen, freq) == 0)
4601 return;
4602#endif /* CONFIG_GAS_SERVER */
4603
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004604#ifdef CONFIG_TDLS
4605 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4606 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4607 wpa_dbg(wpa_s, MSG_DEBUG,
4608 "TDLS: Received Discovery Response from " MACSTR,
4609 MAC2STR(mgmt->sa));
4610 return;
4611 }
4612#endif /* CONFIG_TDLS */
4613
4614#ifdef CONFIG_INTERWORKING
4615 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4616 payload[0] == QOS_QOS_MAP_CONFIG) {
4617 const u8 *pos = payload + 1;
4618 size_t qlen = plen - 1;
4619 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4620 MACSTR, MAC2STR(mgmt->sa));
4621 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4622 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4623 pos[1] <= qlen - 2 && pos[1] >= 16)
4624 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4625 return;
4626 }
4627#endif /* CONFIG_INTERWORKING */
4628
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004629 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004630 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4631 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004632 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004633 payload + 1,
4634 plen - 1);
4635 return;
4636 }
4637
4638 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004639 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4640 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4641 return;
4642 }
4643
4644 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4645 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4646 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4647 payload + 1, plen - 1,
4648 rssi);
4649 return;
4650 }
4651
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004652#ifdef CONFIG_FST
4653 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4654 fst_rx_action(wpa_s->fst, mgmt, len);
4655 return;
4656 }
4657#endif /* CONFIG_FST */
4658
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004659#ifdef CONFIG_DPP
4660 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4661 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4662 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4663 payload[4] == DPP_OUI_TYPE) {
4664 payload++;
4665 plen--;
4666 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4667 return;
4668 }
4669#endif /* CONFIG_DPP */
4670
Hai Shalom899fcc72020-10-19 14:38:18 -07004671 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004672 payload[0] == ROBUST_AV_SCS_RESP) {
4673 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4674 payload + 1, plen - 1);
4675 return;
4676 }
4677
4678 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004679 payload[0] == ROBUST_AV_MSCS_RESP) {
4680 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4681 payload + 1, plen - 1);
4682 return;
4683 }
4684
Hai Shalomc1a21442022-02-04 13:43:00 -08004685 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4686 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4687 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4688 payload + 4, plen - 4);
4689 return;
4690 }
4691
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004692 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4693 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004694 if (wpa_s->ifmsh)
4695 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004696}
4697
4698
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004699static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4700 union wpa_event_data *event)
4701{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004702 struct wpa_freq_range_list *list;
4703 char *str = NULL;
4704
4705 list = &event->freq_range;
4706
4707 if (list->num)
4708 str = freq_range_list_str(list);
4709 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4710 str ? str : "");
4711
4712#ifdef CONFIG_P2P
4713 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4714 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4715 __func__);
4716 } else {
4717 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004718
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004719 /*
4720 * The update channel flow will also take care of moving a GO
4721 * from the unsafe frequency if needed.
4722 */
4723 wpas_p2p_update_channel_list(wpa_s,
4724 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004725 }
4726#endif /* CONFIG_P2P */
4727
4728 os_free(str);
4729}
4730
4731
Roshan Pius3a1667e2018-07-03 15:17:14 -07004732static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004733{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004734 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4735 wpa_supplicant_cancel_auth_timeout(wpa_s);
4736 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004737 eapol_sm_notify_portValid(wpa_s->eapol, true);
4738 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004739 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004740 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004741}
4742
4743
4744static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4745 int freq)
4746{
4747 size_t i;
4748 int j;
4749
4750 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4751 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4752
4753 for (j = 0; j < mode->num_channels; j++) {
4754 const struct hostapd_channel_data *chan;
4755
4756 chan = &mode->channels[j];
4757 if (chan->freq == freq)
4758 return chan->dfs_cac_ms;
4759 }
4760 }
4761
4762 return 0;
4763}
4764
4765
4766static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4767 struct dfs_event *radar)
4768{
4769#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004770 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004771 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4772 } else
4773#endif /* NEED_AP_MLME && CONFIG_AP */
4774 {
4775 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4776
4777 cac_time /= 1000; /* convert from ms to sec */
4778 if (!cac_time)
4779 cac_time = 10 * 60; /* max timeout: 10 minutes */
4780
4781 /* Restart auth timeout: CAC time added to initial timeout */
4782 wpas_auth_timeout_restart(wpa_s, cac_time);
4783 }
4784}
4785
4786
4787static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4788 struct dfs_event *radar)
4789{
4790#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004791 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004792 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4793 } else
4794#endif /* NEED_AP_MLME && CONFIG_AP */
4795 {
4796 /* Restart auth timeout with original value after CAC is
4797 * finished */
4798 wpas_auth_timeout_restart(wpa_s, 0);
4799 }
4800}
4801
4802
4803static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4804 struct dfs_event *radar)
4805{
4806#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004807 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004808 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4809 } else
4810#endif /* NEED_AP_MLME && CONFIG_AP */
4811 {
4812 /* Restart auth timeout with original value after CAC is
4813 * aborted */
4814 wpas_auth_timeout_restart(wpa_s, 0);
4815 }
4816}
4817
4818
4819static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4820 union wpa_event_data *data)
4821{
4822 wpa_dbg(wpa_s, MSG_DEBUG,
4823 "Connection authorized by device, previous state %d",
4824 wpa_s->wpa_state);
4825
4826 wpa_supplicant_event_port_authorized(wpa_s);
4827
Hai Shalomc1a21442022-02-04 13:43:00 -08004828 wpa_s->last_eapol_matches_bssid = 1;
4829
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004830 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4831 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004832 data->assoc_info.ptk_kck_len,
4833 data->assoc_info.ptk_kek,
4834 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004835#ifdef CONFIG_FILS
4836 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4837 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4838 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4839
4840 /* Update ERP next sequence number */
4841 eapol_sm_update_erp_next_seq_num(
4842 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4843
4844 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4845 /* Add the new PMK and PMKID to the PMKSA cache */
4846 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4847 data->assoc_info.fils_pmk,
4848 data->assoc_info.fils_pmk_len,
4849 data->assoc_info.fils_pmkid,
4850 wpa_s->bssid, fils_cache_id);
4851 } else if (data->assoc_info.fils_pmkid) {
4852 /* Update the current PMKSA used for this connection */
4853 pmksa_cache_set_current(wpa_s->wpa,
4854 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004855 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004856 }
4857 }
4858#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004859}
4860
4861
Hai Shalom60840252021-02-19 19:02:11 -08004862static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4863{
4864 switch (code) {
4865 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
4866 return "";
4867 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
4868 return "no_bss_found";
4869 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
4870 return "auth_tx_fail";
4871 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
4872 return "auth_no_ack_received";
4873 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
4874 return "auth_no_resp_received";
4875 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
4876 return "assoc_req_tx_fail";
4877 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
4878 return "assoc_no_ack_received";
4879 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
4880 return "assoc_no_resp_received";
4881 default:
4882 return "unknown_reason";
4883 }
4884}
4885
4886
Roshan Pius3a1667e2018-07-03 15:17:14 -07004887static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4888 union wpa_event_data *data)
4889{
4890 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004891#ifdef CONFIG_MBO
4892 struct wpa_bss *reject_bss;
4893#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004894
4895 if (!bssid || is_zero_ether_addr(bssid))
4896 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004897#ifdef CONFIG_MBO
4898 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4899 reject_bss = wpa_s->current_bss;
4900 else
4901 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4902#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004903
4904 if (data->assoc_reject.bssid)
4905 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004906 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004907 MAC2STR(data->assoc_reject.bssid),
4908 data->assoc_reject.status_code,
4909 data->assoc_reject.timed_out ? " timeout" : "",
4910 data->assoc_reject.timeout_reason ? "=" : "",
4911 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004912 data->assoc_reject.timeout_reason : "",
4913 data->assoc_reject.reason_code !=
4914 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4915 " qca_driver_reason=" : "",
4916 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004917 else
4918 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004919 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004920 data->assoc_reject.status_code,
4921 data->assoc_reject.timed_out ? " timeout" : "",
4922 data->assoc_reject.timeout_reason ? "=" : "",
4923 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004924 data->assoc_reject.timeout_reason : "",
4925 data->assoc_reject.reason_code !=
4926 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4927 " qca_driver_reason=" : "",
4928 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004929 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08004930 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
4931 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004932
4933#ifdef CONFIG_OWE
4934 if (data->assoc_reject.status_code ==
4935 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4936 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4937 wpa_s->current_ssid &&
4938 wpa_s->current_ssid->owe_group == 0 &&
4939 wpa_s->last_owe_group != 21) {
4940 struct wpa_ssid *ssid = wpa_s->current_ssid;
4941 struct wpa_bss *bss = wpa_s->current_bss;
4942
4943 if (!bss) {
4944 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4945 if (!bss) {
4946 wpas_connection_failed(wpa_s, bssid);
4947 wpa_supplicant_mark_disassoc(wpa_s);
4948 return;
4949 }
4950 }
4951 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4952 wpas_connect_work_done(wpa_s);
4953 wpa_supplicant_mark_disassoc(wpa_s);
4954 wpa_supplicant_connect(wpa_s, bss, ssid);
4955 return;
4956 }
4957#endif /* CONFIG_OWE */
4958
Hai Shalomfdcde762020-04-02 11:19:20 -07004959#ifdef CONFIG_DPP2
4960 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4961 * the status code defined in the DPP R2 tech spec.
4962 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4963 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004964 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004965 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4966 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4967 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004968 wpa_s->current_ssid->dpp_pfs == 0 &&
4969 (data->assoc_reject.status_code ==
4970 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4971 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4972 struct wpa_ssid *ssid = wpa_s->current_ssid;
4973 struct wpa_bss *bss = wpa_s->current_bss;
4974
4975 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4976 if (!bss)
4977 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4978 if (!bss || wpa_s->dpp_pfs_fallback) {
4979 wpa_printf(MSG_DEBUG,
4980 "DPP: Updated PFS policy for next try");
4981 wpas_connection_failed(wpa_s, bssid);
4982 wpa_supplicant_mark_disassoc(wpa_s);
4983 return;
4984 }
4985 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4986 wpa_s->dpp_pfs_fallback = 1;
4987 wpas_connect_work_done(wpa_s);
4988 wpa_supplicant_mark_disassoc(wpa_s);
4989 wpa_supplicant_connect(wpa_s, bss, ssid);
4990 return;
4991 }
4992#endif /* CONFIG_DPP2 */
4993
Hai Shalom74f70d42019-02-11 14:42:39 -08004994#ifdef CONFIG_MBO
4995 if (data->assoc_reject.status_code ==
4996 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004997 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004998 const u8 *rssi_rej;
4999
5000 rssi_rej = mbo_get_attr_from_ies(
5001 data->assoc_reject.resp_ies,
5002 data->assoc_reject.resp_ies_len,
5003 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5004 if (rssi_rej && rssi_rej[1] == 2) {
5005 wpa_printf(MSG_DEBUG,
5006 "OCE: RSSI-based association rejection from "
5007 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005008 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005009 rssi_rej[2], rssi_rej[3]);
5010 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005011 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005012 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005013 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005014 }
5015 }
5016#endif /* CONFIG_MBO */
5017
Roshan Pius3a1667e2018-07-03 15:17:14 -07005018 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5019 sme_event_assoc_reject(wpa_s, data);
5020 return;
5021 }
5022
5023 /* Driver-based SME cases */
5024
5025#ifdef CONFIG_SAE
5026 if (wpa_s->current_ssid &&
5027 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5028 !data->assoc_reject.timed_out) {
5029 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5030 wpa_sm_aborted_cached(wpa_s->wpa);
5031 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5032 }
5033#endif /* CONFIG_SAE */
5034
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005035#ifdef CONFIG_DPP
5036 if (wpa_s->current_ssid &&
5037 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5038 !data->assoc_reject.timed_out) {
5039 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5040 wpa_sm_aborted_cached(wpa_s->wpa);
5041 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5042 }
5043#endif /* CONFIG_DPP */
5044
Roshan Pius3a1667e2018-07-03 15:17:14 -07005045#ifdef CONFIG_FILS
5046 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005047 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005048 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005049 eapol_sm_update_erp_next_seq_num(
5050 wpa_s->eapol,
5051 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005052 fils_connection_failure(wpa_s);
5053 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005054#endif /* CONFIG_FILS */
5055
5056 wpas_connection_failed(wpa_s, bssid);
5057 wpa_supplicant_mark_disassoc(wpa_s);
5058}
5059
5060
Hai Shalomfdcde762020-04-02 11:19:20 -07005061static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5062 struct unprot_beacon *data)
5063{
5064 struct wpabuf *buf;
5065 int res;
5066
5067 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5068 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5069 return;
5070 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5071 MAC2STR(data->sa));
5072
5073 buf = wpabuf_alloc(4);
5074 if (!buf)
5075 return;
5076
5077 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5078 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5079 wpabuf_put_u8(buf, 1); /* Dialog Token */
5080 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5081
5082 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5083 wpa_s->own_addr, wpa_s->bssid,
5084 wpabuf_head(buf), wpabuf_len(buf), 0);
5085 if (res < 0)
5086 wpa_printf(MSG_DEBUG,
5087 "Failed to send WNM-Notification Request frame");
5088
5089 wpabuf_free(buf);
5090}
5091
5092
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005093void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5094 union wpa_event_data *data)
5095{
5096 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005097 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005098 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005099#ifndef CONFIG_NO_STDOUT_DEBUG
5100 int level = MSG_DEBUG;
5101#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005102
5103 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5104 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005105 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005106 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005107 event != EVENT_SCHED_SCAN_STOPPED) {
5108 wpa_dbg(wpa_s, MSG_DEBUG,
5109 "Ignore event %s (%d) while interface is disabled",
5110 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005111 return;
5112 }
5113
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005114#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005115 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005116 const struct ieee80211_hdr *hdr;
5117 u16 fc;
5118 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5119 fc = le_to_host16(hdr->frame_control);
5120 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5121 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5122 level = MSG_EXCESSIVE;
5123 }
5124
5125 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5126 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005127#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005128
5129 switch (event) {
5130 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005131#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005132 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5133 data->auth.ies_len))
5134 wpa_printf(MSG_DEBUG,
5135 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005136#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005137 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005138 wpa_s->auth_status_code = data->auth.status_code;
5139 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005140 break;
5141 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005142#ifdef CONFIG_TESTING_OPTIONS
5143 if (wpa_s->ignore_auth_resp) {
5144 wpa_printf(MSG_INFO,
5145 "EVENT_ASSOC - ignore_auth_resp active!");
5146 break;
5147 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005148 if (wpa_s->testing_resend_assoc) {
5149 wpa_printf(MSG_INFO,
5150 "EVENT_DEAUTH - testing_resend_assoc");
5151 break;
5152 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005153#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305154 if (wpa_s->disconnected) {
5155 wpa_printf(MSG_INFO,
5156 "Ignore unexpected EVENT_ASSOC in disconnected state");
5157 break;
5158 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005159 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005160 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005161 if (data &&
5162 (data->assoc_info.authorized ||
5163 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5164 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005165 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005166 if (data) {
5167 wpa_msg(wpa_s, MSG_INFO,
5168 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5169 data->assoc_info.subnet_status);
5170 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005171 break;
5172 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005173 wpas_event_disassoc(wpa_s,
5174 data ? &data->disassoc_info : NULL);
5175 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005176 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005177#ifdef CONFIG_TESTING_OPTIONS
5178 if (wpa_s->ignore_auth_resp) {
5179 wpa_printf(MSG_INFO,
5180 "EVENT_DEAUTH - ignore_auth_resp active!");
5181 break;
5182 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005183 if (wpa_s->testing_resend_assoc) {
5184 wpa_printf(MSG_INFO,
5185 "EVENT_DEAUTH - testing_resend_assoc");
5186 break;
5187 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005188#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005189 wpas_event_deauth(wpa_s,
5190 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005191 break;
5192 case EVENT_MICHAEL_MIC_FAILURE:
5193 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5194 break;
5195#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005196 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005197 if (wpa_s->own_scan_requested ||
5198 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005199 struct os_reltime diff;
5200
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005201 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005202 os_reltime_sub(&wpa_s->scan_start_time,
5203 &wpa_s->scan_trigger_time, &diff);
5204 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5205 diff.sec, diff.usec);
5206 wpa_s->own_scan_requested = 0;
5207 wpa_s->own_scan_running = 1;
5208 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5209 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005210 wpa_msg_ctrl(wpa_s, MSG_INFO,
5211 WPA_EVENT_SCAN_STARTED "id=%u",
5212 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005213 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005214 wpa_msg_ctrl(wpa_s, MSG_INFO,
5215 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005216 }
5217 } else {
5218 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005219 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005220 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005221 }
5222 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005223 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005224 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5225 wpa_s->scan_res_handler = NULL;
5226 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005227 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005228 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5229 break;
5230 }
5231
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005232 if (!(data && data->scan_info.external_scan) &&
5233 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005234 struct os_reltime now, diff;
5235 os_get_reltime(&now);
5236 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5237 wpa_s->scan_start_time.sec = 0;
5238 wpa_s->scan_start_time.usec = 0;
5239 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5240 diff.sec, diff.usec);
5241 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005242 if (wpa_supplicant_event_scan_results(wpa_s, data))
5243 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005244 if (!(data && data->scan_info.external_scan))
5245 wpa_s->own_scan_running = 0;
5246 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005247 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005248 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005249 break;
5250#endif /* CONFIG_NO_SCAN_PROCESSING */
5251 case EVENT_ASSOCINFO:
5252 wpa_supplicant_event_associnfo(wpa_s, data);
5253 break;
5254 case EVENT_INTERFACE_STATUS:
5255 wpa_supplicant_event_interface_status(wpa_s, data);
5256 break;
5257 case EVENT_PMKID_CANDIDATE:
5258 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5259 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005260#ifdef CONFIG_TDLS
5261 case EVENT_TDLS:
5262 wpa_supplicant_event_tdls(wpa_s, data);
5263 break;
5264#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005265#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005266 case EVENT_WNM:
5267 wpa_supplicant_event_wnm(wpa_s, data);
5268 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005269#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005270#ifdef CONFIG_IEEE80211R
5271 case EVENT_FT_RESPONSE:
5272 wpa_supplicant_event_ft_response(wpa_s, data);
5273 break;
5274#endif /* CONFIG_IEEE80211R */
5275#ifdef CONFIG_IBSS_RSN
5276 case EVENT_IBSS_RSN_START:
5277 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5278 break;
5279#endif /* CONFIG_IBSS_RSN */
5280 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005281 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005282 break;
5283 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005284 /* It is possible to get this event from earlier connection */
5285 if (wpa_s->current_ssid &&
5286 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5287 wpa_dbg(wpa_s, MSG_DEBUG,
5288 "Ignore AUTH_TIMED_OUT in mesh configuration");
5289 break;
5290 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005291 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5292 sme_event_auth_timed_out(wpa_s, data);
5293 break;
5294 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005295 /* It is possible to get this event from earlier connection */
5296 if (wpa_s->current_ssid &&
5297 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5298 wpa_dbg(wpa_s, MSG_DEBUG,
5299 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5300 break;
5301 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005302 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5303 sme_event_assoc_timed_out(wpa_s, data);
5304 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005305 case EVENT_TX_STATUS:
5306 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5307 " type=%d stype=%d",
5308 MAC2STR(data->tx_status.dst),
5309 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005310#ifdef CONFIG_PASN
5311 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5312 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5313 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5314 data->tx_status.data_len,
5315 data->tx_status.ack) == 0)
5316 break;
5317#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005318#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005319 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005320#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005321 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5322 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005323 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005324 wpa_s, data->tx_status.dst,
5325 data->tx_status.data,
5326 data->tx_status.data_len,
5327 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005328 OFFCHANNEL_SEND_ACTION_SUCCESS :
5329 OFFCHANNEL_SEND_ACTION_NO_ACK);
5330#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005331 break;
5332 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005333#endif /* CONFIG_AP */
5334#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005335 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005336 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005337 /*
5338 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005339 * interface in GO mode, or via standalone AP interface.
5340 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5341 * except when the primary interface is used as a GO interface
5342 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005343 */
5344 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5345 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005346 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005347 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005348 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005349 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005350 data->tx_status.data,
5351 data->tx_status.data_len,
5352 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005353 OFFCHANNEL_SEND_ACTION_SUCCESS :
5354 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005355 break;
5356 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005357#endif /* CONFIG_OFFCHANNEL */
5358#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005359 switch (data->tx_status.type) {
5360 case WLAN_FC_TYPE_MGMT:
5361 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5362 data->tx_status.data_len,
5363 data->tx_status.stype,
5364 data->tx_status.ack);
5365 break;
5366 case WLAN_FC_TYPE_DATA:
5367 ap_tx_status(wpa_s, data->tx_status.dst,
5368 data->tx_status.data,
5369 data->tx_status.data_len,
5370 data->tx_status.ack);
5371 break;
5372 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005373#endif /* CONFIG_AP */
5374 break;
5375#ifdef CONFIG_AP
5376 case EVENT_EAPOL_TX_STATUS:
5377 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5378 data->eapol_tx_status.data,
5379 data->eapol_tx_status.data_len,
5380 data->eapol_tx_status.ack);
5381 break;
5382 case EVENT_DRIVER_CLIENT_POLL_OK:
5383 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005384 break;
5385 case EVENT_RX_FROM_UNKNOWN:
5386 if (wpa_s->ap_iface == NULL)
5387 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005388 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5389 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005390 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005391#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005392
5393 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005394 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005395 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005396 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005397
Hai Shalom81f62d82019-07-22 12:10:00 -07005398 wpa_msg(wpa_s, MSG_INFO,
5399 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5400 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5401 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005402 data->ch_switch.freq,
5403 data->ch_switch.ht_enabled,
5404 data->ch_switch.ch_offset,
5405 channel_width_to_string(data->ch_switch.ch_width),
5406 data->ch_switch.cf1,
5407 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005408 if (event == EVENT_CH_SWITCH_STARTED)
5409 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005410
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005411 wpa_s->assoc_freq = data->ch_switch.freq;
5412 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005413 if (wpa_s->current_bss &&
5414 wpa_s->current_bss->freq != data->ch_switch.freq) {
5415 wpa_s->current_bss->freq = data->ch_switch.freq;
5416 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5417 wpa_s->current_bss);
5418 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005419
Hai Shalomfdcde762020-04-02 11:19:20 -07005420#ifdef CONFIG_SME
5421 switch (data->ch_switch.ch_offset) {
5422 case 1:
5423 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5424 break;
5425 case -1:
5426 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5427 break;
5428 default:
5429 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5430 break;
5431 }
5432#endif /* CONFIG_SME */
5433
Roshan Pius3a1667e2018-07-03 15:17:14 -07005434#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005435 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5436 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005437 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005438 wpa_s->current_ssid->mode ==
5439 WPAS_MODE_P2P_GROUP_FORMATION) {
5440 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5441 data->ch_switch.ht_enabled,
5442 data->ch_switch.ch_offset,
5443 data->ch_switch.ch_width,
5444 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005445 data->ch_switch.cf2,
5446 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005447 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005448#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005449
Hai Shalom899fcc72020-10-19 14:38:18 -07005450 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5451 sme_event_ch_switch(wpa_s);
5452
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005453 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005454 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005455 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005456#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005457#ifdef NEED_AP_MLME
5458 case EVENT_DFS_RADAR_DETECTED:
5459 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005460 wpas_ap_event_dfs_radar_detected(wpa_s,
5461 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005462 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005463 case EVENT_DFS_NOP_FINISHED:
5464 if (data)
5465 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5466 &data->dfs_event);
5467 break;
5468#endif /* NEED_AP_MLME */
5469#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005470 case EVENT_DFS_CAC_STARTED:
5471 if (data)
5472 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5473 break;
5474 case EVENT_DFS_CAC_FINISHED:
5475 if (data)
5476 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5477 break;
5478 case EVENT_DFS_CAC_ABORTED:
5479 if (data)
5480 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5481 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005482 case EVENT_RX_MGMT: {
5483 u16 fc, stype;
5484 const struct ieee80211_mgmt *mgmt;
5485
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005486#ifdef CONFIG_TESTING_OPTIONS
5487 if (wpa_s->ext_mgmt_frame_handling) {
5488 struct rx_mgmt *rx = &data->rx_mgmt;
5489 size_t hex_len = 2 * rx->frame_len + 1;
5490 char *hex = os_malloc(hex_len);
5491 if (hex) {
5492 wpa_snprintf_hex(hex, hex_len,
5493 rx->frame, rx->frame_len);
5494 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5495 rx->freq, rx->datarate, rx->ssi_signal,
5496 hex);
5497 os_free(hex);
5498 }
5499 break;
5500 }
5501#endif /* CONFIG_TESTING_OPTIONS */
5502
Dmitry Shmidt04949592012-07-19 12:16:46 -07005503 mgmt = (const struct ieee80211_mgmt *)
5504 data->rx_mgmt.frame;
5505 fc = le_to_host16(mgmt->frame_control);
5506 stype = WLAN_FC_GET_STYPE(fc);
5507
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005508#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005509 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005510#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005511#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005512 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005513 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005514 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005515 const u8 *ie;
5516 size_t ie_len;
5517
5518 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5519 ie_len = data->rx_mgmt.frame_len -
5520 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005521 wpas_p2p_probe_req_rx(
5522 wpa_s, src, mgmt->da,
5523 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005524 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005525 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005526 break;
5527 }
5528#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005529#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005530 if (wpa_s->current_ssid &&
5531 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5532 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005533 data->rx_mgmt.frame_len >= 30) {
5534 wpa_supplicant_event_ibss_auth(wpa_s, data);
5535 break;
5536 }
5537#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005538
5539 if (stype == WLAN_FC_STYPE_ACTION) {
5540 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005541 wpa_s, data->rx_mgmt.frame,
5542 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005543 data->rx_mgmt.freq,
5544 data->rx_mgmt.ssi_signal);
5545 break;
5546 }
5547
5548 if (wpa_s->ifmsh) {
5549 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005550 break;
5551 }
Hai Shalom60840252021-02-19 19:02:11 -08005552#ifdef CONFIG_PASN
5553 if (stype == WLAN_FC_STYPE_AUTH &&
5554 wpas_pasn_auth_rx(wpa_s, mgmt,
5555 data->rx_mgmt.frame_len) != -2)
5556 break;
5557#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005558
Roshan Pius3a1667e2018-07-03 15:17:14 -07005559#ifdef CONFIG_SAE
5560 if (stype == WLAN_FC_STYPE_AUTH &&
5561 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5562 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5563 sme_external_auth_mgmt_rx(
5564 wpa_s, data->rx_mgmt.frame,
5565 data->rx_mgmt.frame_len);
5566 break;
5567 }
5568#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005569 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5570 "management frame in non-AP mode");
5571 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005572#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005573 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005574
5575 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005576 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5577 const u8 *ie;
5578 size_t ie_len;
5579
5580 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5581 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005582
5583 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5584 mgmt->bssid, ie, ie_len,
5585 data->rx_mgmt.ssi_signal);
5586 }
5587
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005588 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005589#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005590 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005591 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005592 case EVENT_RX_PROBE_REQ:
5593 if (data->rx_probe_req.sa == NULL ||
5594 data->rx_probe_req.ie == NULL)
5595 break;
5596#ifdef CONFIG_AP
5597 if (wpa_s->ap_iface) {
5598 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5599 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005600 data->rx_probe_req.da,
5601 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005602 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005603 data->rx_probe_req.ie_len,
5604 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005605 break;
5606 }
5607#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005608 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005609 data->rx_probe_req.da,
5610 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005611 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005612 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005613 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005614 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005615 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005616 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005617#ifdef CONFIG_OFFCHANNEL
5618 offchannel_remain_on_channel_cb(
5619 wpa_s, data->remain_on_channel.freq,
5620 data->remain_on_channel.duration);
5621#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005622 wpas_p2p_remain_on_channel_cb(
5623 wpa_s, data->remain_on_channel.freq,
5624 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005625#ifdef CONFIG_DPP
5626 wpas_dpp_remain_on_channel_cb(
5627 wpa_s, data->remain_on_channel.freq,
5628 data->remain_on_channel.duration);
5629#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005630 break;
5631 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005632#ifdef CONFIG_OFFCHANNEL
5633 offchannel_cancel_remain_on_channel_cb(
5634 wpa_s, data->remain_on_channel.freq);
5635#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005636 wpas_p2p_cancel_remain_on_channel_cb(
5637 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005638#ifdef CONFIG_DPP
5639 wpas_dpp_cancel_remain_on_channel_cb(
5640 wpa_s, data->remain_on_channel.freq);
5641#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005642 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005643 case EVENT_EAPOL_RX:
5644 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5645 data->eapol_rx.data,
5646 data->eapol_rx.data_len);
5647 break;
5648 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005649 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5650 "above=%d signal=%d noise=%d txrate=%d",
5651 data->signal_change.above_threshold,
5652 data->signal_change.current_signal,
5653 data->signal_change.current_noise,
5654 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005655 wpa_bss_update_level(wpa_s->current_bss,
5656 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005657 bgscan_notify_signal_change(
5658 wpa_s, data->signal_change.above_threshold,
5659 data->signal_change.current_signal,
5660 data->signal_change.current_noise,
5661 data->signal_change.current_txrate);
5662 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005663 case EVENT_INTERFACE_MAC_CHANGED:
5664 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005665 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005666 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005667 case EVENT_INTERFACE_ENABLED:
5668 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5669 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005670 u8 addr[ETH_ALEN];
5671
Hai Shalomfdcde762020-04-02 11:19:20 -07005672 eloop_cancel_timeout(wpas_clear_disabled_interface,
5673 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005674 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005675 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005676 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5677 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5678 else
5679 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005680 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005681 if (wpa_s->p2p_mgmt) {
5682 wpa_supplicant_set_state(wpa_s,
5683 WPA_DISCONNECTED);
5684 break;
5685 }
5686
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005687#ifdef CONFIG_AP
5688 if (!wpa_s->ap_iface) {
5689 wpa_supplicant_set_state(wpa_s,
5690 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005691 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005692 wpa_supplicant_req_scan(wpa_s, 0, 0);
5693 } else
5694 wpa_supplicant_set_state(wpa_s,
5695 WPA_COMPLETED);
5696#else /* CONFIG_AP */
5697 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5698 wpa_supplicant_req_scan(wpa_s, 0, 0);
5699#endif /* CONFIG_AP */
5700 }
5701 break;
5702 case EVENT_INTERFACE_DISABLED:
5703 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005704#ifdef CONFIG_P2P
5705 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5706 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5707 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5708 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005709 * Mark interface disabled if this happens to end up not
5710 * being removed as a separate P2P group interface.
5711 */
5712 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5713 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005714 * The interface was externally disabled. Remove
5715 * it assuming an external entity will start a
5716 * new session if needed.
5717 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005718 if (wpa_s->current_ssid &&
5719 wpa_s->current_ssid->p2p_group)
5720 wpas_p2p_interface_unavailable(wpa_s);
5721 else
5722 wpas_p2p_disconnect(wpa_s);
5723 /*
5724 * wpa_s instance may have been freed, so must not use
5725 * it here anymore.
5726 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005727 break;
5728 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005729 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5730 p2p_in_progress(wpa_s->global->p2p) > 1) {
5731 /* This radio work will be cancelled, so clear P2P
5732 * state as well.
5733 */
5734 p2p_stop_find(wpa_s->global->p2p);
5735 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005736#endif /* CONFIG_P2P */
5737
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005738 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5739 /*
5740 * Indicate disconnection to keep ctrl_iface events
5741 * consistent.
5742 */
5743 wpa_supplicant_event_disassoc(
5744 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5745 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005746 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005747 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005748 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5749 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005750 clear_at.usec = 0;
5751 } else {
5752 struct os_reltime tmp;
5753
Hai Shalom60840252021-02-19 19:02:11 -08005754 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005755 tmp.usec = 0;
5756 os_reltime_sub(&tmp, &age, &clear_at);
5757 }
5758 eloop_register_timeout(clear_at.sec, clear_at.usec,
5759 wpas_clear_disabled_interface,
5760 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005761 radio_remove_works(wpa_s, NULL, 0);
5762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005763 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5764 break;
5765 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005766 wpa_supplicant_update_channel_list(
5767 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005768 break;
5769 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005770 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005771 break;
5772 case EVENT_BEST_CHANNEL:
5773 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5774 "(%d %d %d)",
5775 data->best_chan.freq_24, data->best_chan.freq_5,
5776 data->best_chan.freq_overall);
5777 wpa_s->best_24_freq = data->best_chan.freq_24;
5778 wpa_s->best_5_freq = data->best_chan.freq_5;
5779 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005780 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5781 data->best_chan.freq_5,
5782 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005783 break;
5784 case EVENT_UNPROT_DEAUTH:
5785 wpa_supplicant_event_unprot_deauth(wpa_s,
5786 &data->unprot_deauth);
5787 break;
5788 case EVENT_UNPROT_DISASSOC:
5789 wpa_supplicant_event_unprot_disassoc(wpa_s,
5790 &data->unprot_disassoc);
5791 break;
5792 case EVENT_STATION_LOW_ACK:
5793#ifdef CONFIG_AP
5794 if (wpa_s->ap_iface && data)
5795 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5796 data->low_ack.addr);
5797#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005798#ifdef CONFIG_TDLS
5799 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005800 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5801 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005802#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005803 break;
5804 case EVENT_IBSS_PEER_LOST:
5805#ifdef CONFIG_IBSS_RSN
5806 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5807#endif /* CONFIG_IBSS_RSN */
5808 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005809 case EVENT_DRIVER_GTK_REKEY:
5810 if (os_memcmp(data->driver_gtk_rekey.bssid,
5811 wpa_s->bssid, ETH_ALEN))
5812 break;
5813 if (!wpa_s->wpa)
5814 break;
5815 wpa_sm_update_replay_ctr(wpa_s->wpa,
5816 data->driver_gtk_rekey.replay_ctr);
5817 break;
5818 case EVENT_SCHED_SCAN_STOPPED:
5819 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005820 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005821 wpa_supplicant_notify_scanning(wpa_s, 0);
5822
5823 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5824 break;
5825
5826 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005827 * If the driver stopped scanning without being requested to,
5828 * request a new scan to continue scanning for networks.
5829 */
5830 if (!wpa_s->sched_scan_stop_req &&
5831 wpa_s->wpa_state == WPA_SCANNING) {
5832 wpa_dbg(wpa_s, MSG_DEBUG,
5833 "Restart scanning after unexpected sched_scan stop event");
5834 wpa_supplicant_req_scan(wpa_s, 1, 0);
5835 break;
5836 }
5837
5838 wpa_s->sched_scan_stop_req = 0;
5839
5840 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005841 * Start a new sched scan to continue searching for more SSIDs
5842 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005843 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005844 if (wpa_s->sched_scan_timed_out) {
5845 wpa_supplicant_req_sched_scan(wpa_s);
5846 } else if (wpa_s->pno_sched_pending) {
5847 wpa_s->pno_sched_pending = 0;
5848 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005849 } else if (resched) {
5850 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005851 }
5852
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005853 break;
5854 case EVENT_WPS_BUTTON_PUSHED:
5855#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005856 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005857#endif /* CONFIG_WPS */
5858 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005859 case EVENT_AVOID_FREQUENCIES:
5860 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5861 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005862 case EVENT_CONNECT_FAILED_REASON:
5863#ifdef CONFIG_AP
5864 if (!wpa_s->ap_iface || !data)
5865 break;
5866 hostapd_event_connect_failed_reason(
5867 wpa_s->ap_iface->bss[0],
5868 data->connect_failed_reason.addr,
5869 data->connect_failed_reason.code);
5870#endif /* CONFIG_AP */
5871 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005872 case EVENT_NEW_PEER_CANDIDATE:
5873#ifdef CONFIG_MESH
5874 if (!wpa_s->ifmsh || !data)
5875 break;
5876 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5877 data->mesh_peer.ies,
5878 data->mesh_peer.ie_len);
5879#endif /* CONFIG_MESH */
5880 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005881 case EVENT_SURVEY:
5882#ifdef CONFIG_AP
5883 if (!wpa_s->ap_iface)
5884 break;
5885 hostapd_event_get_survey(wpa_s->ap_iface,
5886 &data->survey_results);
5887#endif /* CONFIG_AP */
5888 break;
5889 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005890#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005891#ifdef CONFIG_ACS
5892 if (!wpa_s->ap_iface)
5893 break;
5894 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5895 &data->acs_selected_channels);
5896#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005897#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005898 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005899 case EVENT_P2P_LO_STOP:
5900#ifdef CONFIG_P2P
5901 wpa_s->p2p_lo_started = 0;
5902 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5903 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5904 data->p2p_lo_stop.reason_code);
5905#endif /* CONFIG_P2P */
5906 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005907 case EVENT_BEACON_LOSS:
5908 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5909 break;
5910 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5911 bgscan_notify_beacon_loss(wpa_s);
5912 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005913 case EVENT_EXTERNAL_AUTH:
5914#ifdef CONFIG_SAE
5915 if (!wpa_s->current_ssid) {
5916 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5917 break;
5918 }
5919 sme_external_auth_trigger(wpa_s, data);
5920#endif /* CONFIG_SAE */
5921 break;
5922 case EVENT_PORT_AUTHORIZED:
5923 wpa_supplicant_event_port_authorized(wpa_s);
5924 break;
5925 case EVENT_STATION_OPMODE_CHANGED:
5926#ifdef CONFIG_AP
5927 if (!wpa_s->ap_iface || !data)
5928 break;
5929
5930 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5931 data->sta_opmode.addr,
5932 data->sta_opmode.smps_mode,
5933 data->sta_opmode.chan_width,
5934 data->sta_opmode.rx_nss);
5935#endif /* CONFIG_AP */
5936 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005937 case EVENT_UNPROT_BEACON:
5938 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5939 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08005940 case EVENT_TX_WAIT_EXPIRE:
5941#ifdef CONFIG_DPP
5942 wpas_dpp_tx_wait_expire(wpa_s);
5943#endif /* CONFIG_DPP */
5944 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005945 default:
5946 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5947 break;
5948 }
5949}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005950
5951
5952void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5953 union wpa_event_data *data)
5954{
5955 struct wpa_supplicant *wpa_s;
5956
5957 if (event != EVENT_INTERFACE_STATUS)
5958 return;
5959
5960 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5961 if (wpa_s && wpa_s->driver->get_ifindex) {
5962 unsigned int ifindex;
5963
5964 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5965 if (ifindex != data->interface_status.ifindex) {
5966 wpa_dbg(wpa_s, MSG_DEBUG,
5967 "interface status ifindex %d mismatch (%d)",
5968 ifindex, data->interface_status.ifindex);
5969 return;
5970 }
5971 }
5972#ifdef CONFIG_MATCH_IFACE
5973 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5974 struct wpa_interface *wpa_i;
5975
5976 wpa_i = wpa_supplicant_match_iface(
5977 ctx, data->interface_status.ifname);
5978 if (!wpa_i)
5979 return;
5980 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5981 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07005982 }
5983#endif /* CONFIG_MATCH_IFACE */
5984
5985 if (wpa_s)
5986 wpa_supplicant_event(wpa_s, event, data);
5987}