blob: e682895923c04e78e5da908780bf1ce94394b3e7 [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
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700152static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
153{
154 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
155
156 if (!bss) {
157 wpa_supplicant_update_scan_results(wpa_s);
158
159 /* Get the BSS from the new scan results */
160 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
161 }
162
163 if (bss)
164 wpa_s->current_bss = bss;
165}
166
167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
169{
170 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700171 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700172 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700173 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700175 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
176 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700177
178 if (wpa_s->current_ssid->ssid_len == 0)
179 return 0; /* current profile still in use */
180 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
181 if (res < 0) {
182 wpa_msg(wpa_s, MSG_INFO,
183 "Failed to read SSID from driver");
184 return 0; /* try to use current profile */
185 }
186 drv_ssid_len = res;
187
188 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
189 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
190 drv_ssid_len) == 0)
191 return 0; /* current profile still in use */
192
Hai Shalomfdcde762020-04-02 11:19:20 -0700193#ifdef CONFIG_OWE
194 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
195 wpa_s->current_bss &&
196 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
197 drv_ssid_len == wpa_s->current_bss->ssid_len &&
198 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
199 drv_ssid_len) == 0)
200 return 0; /* current profile still in use */
201#endif /* CONFIG_OWE */
202
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700203 wpa_msg(wpa_s, MSG_DEBUG,
204 "Driver-initiated BSS selection changed the SSID to %s",
205 wpa_ssid_txt(drv_ssid, drv_ssid_len));
206 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700207 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208
209 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
210 "information");
211 ssid = wpa_supplicant_get_ssid(wpa_s);
212 if (ssid == NULL) {
213 wpa_msg(wpa_s, MSG_INFO,
214 "No network configuration found for the current AP");
215 return -1;
216 }
217
Dmitry Shmidt04949592012-07-19 12:16:46 -0700218 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
220 return -1;
221 }
222
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800223 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
224 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
225 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
226 return -1;
227 }
228
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700229 res = wpas_temp_disabled(wpa_s, ssid);
230 if (res > 0) {
231 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
232 "disabled for %d second(s)", res);
233 return -1;
234 }
235
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700236 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
237 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800238 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239 u8 wpa_ie[80];
240 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800241 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
242 wpa_ie, &wpa_ie_len) < 0)
243 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700244 } else {
245 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
246 }
247
248 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
249 eapol_sm_invalidate_cached_session(wpa_s->eapol);
250 old_ssid = wpa_s->current_ssid;
251 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800252
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700253 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700255 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
256 wpa_supplicant_initiate_eapol(wpa_s);
257 if (old_ssid != wpa_s->current_ssid)
258 wpas_notify_network_changed(wpa_s);
259
260 return 0;
261}
262
263
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265{
266 struct wpa_supplicant *wpa_s = eloop_ctx;
267
268 if (wpa_s->countermeasures) {
269 wpa_s->countermeasures = 0;
270 wpa_drv_set_countermeasures(wpa_s, 0);
271 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800272
273 /*
274 * It is possible that the device is sched scanning, which means
275 * that a connection attempt will be done only when we receive
276 * scan results. However, in this case, it would be preferable
277 * to scan and connect immediately, so cancel the sched_scan and
278 * issue a regular scan flow.
279 */
280 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281 wpa_supplicant_req_scan(wpa_s, 0, 0);
282 }
283}
284
285
286void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
287{
288 int bssid_changed;
289
Dmitry Shmidt04949592012-07-19 12:16:46 -0700290 wnm_bss_keep_alive_deinit(wpa_s);
291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292#ifdef CONFIG_IBSS_RSN
293 ibss_rsn_deinit(wpa_s->ibss_rsn);
294 wpa_s->ibss_rsn = NULL;
295#endif /* CONFIG_IBSS_RSN */
296
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700297#ifdef CONFIG_AP
298 wpa_supplicant_ap_deinit(wpa_s);
299#endif /* CONFIG_AP */
300
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700301#ifdef CONFIG_HS20
302 /* Clear possibly configured frame filters */
303 wpa_drv_configure_frame_filters(wpa_s, 0);
304#endif /* CONFIG_HS20 */
305
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700306 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
307 return;
308
Hai Shalom74f70d42019-02-11 14:42:39 -0800309 if (os_reltime_initialized(&wpa_s->session_start)) {
310 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
311 wpa_s->session_start.sec = 0;
312 wpa_s->session_start.usec = 0;
313 wpas_notify_session_length(wpa_s);
314 }
315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
317 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
318 os_memset(wpa_s->bssid, 0, ETH_ALEN);
319 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800320 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321 wpa_s->current_bss = NULL;
322 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700323
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 if (bssid_changed)
325 wpas_notify_bssid_changed(wpa_s);
326
Hai Shalome21d4e82020-04-29 16:34:06 -0700327 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
328 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700329 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
330 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700331 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700332 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700333 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700334 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700335 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700336 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700337 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800338
339 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800340 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800341 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700342 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700343
344#ifdef CONFIG_TESTING_OPTIONS
345 wpa_s->last_tk_alg = WPA_ALG_NONE;
346 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
347#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700348 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800349
350 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
351 wpa_s->enabled_4addr_mode = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352}
353
354
355static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
356{
357 struct wpa_ie_data ie;
358 int pmksa_set = -1;
359 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800360 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700361
Hai Shalomc1a21442022-02-04 13:43:00 -0800362 /* Start with assumption of no PMKSA cache entry match for cases other
363 * than SAE. In particular, this is needed to generate the PMKSA cache
364 * entries for Suite B cases with driver-based roaming indication. */
365 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
366 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
367 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700368
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700369 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
370 ie.pmkid == NULL)
371 return;
372
373 for (i = 0; i < ie.num_pmkid; i++) {
374 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
375 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700376 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800378 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700379 break;
380 }
381 }
382
383 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
384 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
385}
386
387
388static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
389 union wpa_event_data *data)
390{
391 if (data == NULL) {
392 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
393 "event");
394 return;
395 }
396 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
397 " index=%d preauth=%d",
398 MAC2STR(data->pmkid_candidate.bssid),
399 data->pmkid_candidate.index,
400 data->pmkid_candidate.preauth);
401
402 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
403 data->pmkid_candidate.index,
404 data->pmkid_candidate.preauth);
405}
406
407
408static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
409{
410 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
411 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
412 return 0;
413
414#ifdef IEEE8021X_EAPOL
415 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
416 wpa_s->current_ssid &&
417 !(wpa_s->current_ssid->eapol_flags &
418 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
419 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
420 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
421 * plaintext or static WEP keys). */
422 return 0;
423 }
424#endif /* IEEE8021X_EAPOL */
425
426 return 1;
427}
428
429
430/**
431 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
432 * @wpa_s: pointer to wpa_supplicant data
433 * @ssid: Configuration data for the network
434 * Returns: 0 on success, -1 on failure
435 *
436 * This function is called when starting authentication with a network that is
437 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
438 */
439int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
440 struct wpa_ssid *ssid)
441{
442#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800443#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700444 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700445
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700446 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
447 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700448 return 0;
449
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700450 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 sim = 1;
452 aka = 1;
453 } else {
454 struct eap_method_type *eap = ssid->eap.eap_methods;
455 while (eap->vendor != EAP_VENDOR_IETF ||
456 eap->method != EAP_TYPE_NONE) {
457 if (eap->vendor == EAP_VENDOR_IETF) {
458 if (eap->method == EAP_TYPE_SIM)
459 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700460 else if (eap->method == EAP_TYPE_AKA ||
461 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700462 aka = 1;
463 }
464 eap++;
465 }
466 }
467
468 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
469 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700470 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
471 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
472 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 aka = 0;
474
475 if (!sim && !aka) {
476 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
477 "use SIM, but neither EAP-SIM nor EAP-AKA are "
478 "enabled");
479 return 0;
480 }
481
482 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
483 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700484
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700485 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700486 if (wpa_s->scard == NULL) {
487 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
488 "(pcsc-lite)");
489 return -1;
490 }
491 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
492 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800493#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700494#endif /* IEEE8021X_EAPOL */
495
496 return 0;
497}
498
499
500#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700501
Hai Shalomfdcde762020-04-02 11:19:20 -0700502#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700503static int has_wep_key(struct wpa_ssid *ssid)
504{
505 int i;
506
507 for (i = 0; i < NUM_WEP_KEYS; i++) {
508 if (ssid->wep_key_len[i])
509 return 1;
510 }
511
512 return 0;
513}
Hai Shalomfdcde762020-04-02 11:19:20 -0700514#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700515
516
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700517static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 struct wpa_ssid *ssid)
519{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700520 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521
522 if (ssid->mixed_cell)
523 return 1;
524
525#ifdef CONFIG_WPS
526 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
527 return 1;
528#endif /* CONFIG_WPS */
529
Roshan Pius3a1667e2018-07-03 15:17:14 -0700530#ifdef CONFIG_OWE
531 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
532 return 1;
533#endif /* CONFIG_OWE */
534
Hai Shalomfdcde762020-04-02 11:19:20 -0700535#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700536 if (has_wep_key(ssid))
537 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700538#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700539
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700540#ifdef IEEE8021X_EAPOL
541 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
542 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
543 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
544 privacy = 1;
545#endif /* IEEE8021X_EAPOL */
546
Jouni Malinen75ecf522011-06-27 15:19:46 -0700547 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
548 privacy = 1;
549
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800550 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
551 privacy = 1;
552
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553 if (bss->caps & IEEE80211_CAP_PRIVACY)
554 return privacy;
555 return !privacy;
556}
557
558
559static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
560 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800561 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562{
563 struct wpa_ie_data ie;
564 int proto_match = 0;
565 const u8 *rsn_ie, *wpa_ie;
566 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700567#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700568 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700569#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570
571 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
572 if (ret >= 0)
573 return ret;
574
Hai Shalomfdcde762020-04-02 11:19:20 -0700575#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
577 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
578 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
579 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
580 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700581#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700583 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700584 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585 proto_match++;
586
587 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800588 if (debug_print)
589 wpa_dbg(wpa_s, MSG_DEBUG,
590 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591 break;
592 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700593 if (!ie.has_pairwise)
594 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
595 if (!ie.has_group)
596 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597
Hai Shalomfdcde762020-04-02 11:19:20 -0700598#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700599 if (wep_ok &&
600 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
601 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800602 if (debug_print)
603 wpa_dbg(wpa_s, MSG_DEBUG,
604 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605 return 1;
606 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700607#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700608
Roshan Pius3a1667e2018-07-03 15:17:14 -0700609 if (!(ie.proto & ssid->proto) &&
610 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800611 if (debug_print)
612 wpa_dbg(wpa_s, MSG_DEBUG,
613 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614 break;
615 }
616
617 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800618 if (debug_print)
619 wpa_dbg(wpa_s, MSG_DEBUG,
620 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621 break;
622 }
623
624 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800625 if (debug_print)
626 wpa_dbg(wpa_s, MSG_DEBUG,
627 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700628 break;
629 }
630
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700631 if (ssid->group_mgmt_cipher &&
632 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
633 if (debug_print)
634 wpa_dbg(wpa_s, MSG_DEBUG,
635 " skip RSN IE - group mgmt cipher mismatch");
636 break;
637 }
638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800640 if (debug_print)
641 wpa_dbg(wpa_s, MSG_DEBUG,
642 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643 break;
644 }
645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800647 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800648 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800649 if (debug_print)
650 wpa_dbg(wpa_s, MSG_DEBUG,
651 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652 break;
653 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800654 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
655 wpas_get_ssid_pmf(wpa_s, ssid) ==
656 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800657 if (debug_print)
658 wpa_dbg(wpa_s, MSG_DEBUG,
659 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800660 break;
661 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800663 if (debug_print)
664 wpa_dbg(wpa_s, MSG_DEBUG,
665 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666 return 1;
667 }
668
Roshan Pius3a1667e2018-07-03 15:17:14 -0700669 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
670 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800671 if (debug_print)
672 wpa_dbg(wpa_s, MSG_DEBUG,
673 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700674 return 0;
675 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700676
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700677 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
679 proto_match++;
680
681 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800682 if (debug_print)
683 wpa_dbg(wpa_s, MSG_DEBUG,
684 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700685 break;
686 }
687
Hai Shalomfdcde762020-04-02 11:19:20 -0700688#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689 if (wep_ok &&
690 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
691 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800692 if (debug_print)
693 wpa_dbg(wpa_s, MSG_DEBUG,
694 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695 return 1;
696 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700697#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698
699 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800700 if (debug_print)
701 wpa_dbg(wpa_s, MSG_DEBUG,
702 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 break;
704 }
705
706 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800707 if (debug_print)
708 wpa_dbg(wpa_s, MSG_DEBUG,
709 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710 break;
711 }
712
713 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800714 if (debug_print)
715 wpa_dbg(wpa_s, MSG_DEBUG,
716 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 break;
718 }
719
720 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800721 if (debug_print)
722 wpa_dbg(wpa_s, MSG_DEBUG,
723 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 break;
725 }
726
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800727 if (debug_print)
728 wpa_dbg(wpa_s, MSG_DEBUG,
729 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 return 1;
731 }
732
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700733 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
734 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800735 if (debug_print)
736 wpa_dbg(wpa_s, MSG_DEBUG,
737 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700738 return 1;
739 }
740
Roshan Pius3a1667e2018-07-03 15:17:14 -0700741#ifdef CONFIG_OWE
742 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
743 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800744 if (wpa_s->owe_transition_select &&
745 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
746 ssid->owe_transition_bss_select_count + 1 <=
747 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
748 ssid->owe_transition_bss_select_count++;
749 if (debug_print)
750 wpa_dbg(wpa_s, MSG_DEBUG,
751 " skip OWE transition BSS (selection count %d does not exceed %d)",
752 ssid->owe_transition_bss_select_count,
753 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
754 wpa_s->owe_transition_search = 1;
755 return 0;
756 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700757 if (debug_print)
758 wpa_dbg(wpa_s, MSG_DEBUG,
759 " allow in OWE transition mode");
760 return 1;
761 }
762#endif /* CONFIG_OWE */
763
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
765 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800766 if (debug_print)
767 wpa_dbg(wpa_s, MSG_DEBUG,
768 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 return 0;
770 }
771
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800772 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
773 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800774 if (debug_print)
775 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800776 return 1;
777 }
778
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800780 if (debug_print)
781 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782 return 1;
783 }
784
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800785 if (debug_print)
786 wpa_dbg(wpa_s, MSG_DEBUG,
787 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788
789 return 0;
790}
791
792
793static int freq_allowed(int *freqs, int freq)
794{
795 int i;
796
797 if (freqs == NULL)
798 return 1;
799
800 for (i = 0; freqs[i]; i++)
801 if (freqs[i] == freq)
802 return 1;
803 return 0;
804}
805
806
Hai Shalomfdcde762020-04-02 11:19:20 -0700807static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
808 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800809{
810 const struct hostapd_hw_modes *mode = NULL, *modes;
811 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
812 const u8 *rate_ie;
813 int i, j, k;
814
815 if (bss->freq == 0)
816 return 1; /* Cannot do matching without knowing band */
817
818 modes = wpa_s->hw.modes;
819 if (modes == NULL) {
820 /*
821 * The driver does not provide any additional information
822 * about the utilized hardware, so allow the connection attempt
823 * to continue.
824 */
825 return 1;
826 }
827
828 for (i = 0; i < wpa_s->hw.num_modes; i++) {
829 for (j = 0; j < modes[i].num_channels; j++) {
830 int freq = modes[i].channels[j].freq;
831 if (freq == bss->freq) {
832 if (mode &&
833 mode->mode == HOSTAPD_MODE_IEEE80211G)
834 break; /* do not allow 802.11b replace
835 * 802.11g */
836 mode = &modes[i];
837 break;
838 }
839 }
840 }
841
842 if (mode == NULL)
843 return 0;
844
845 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700846 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800847 if (rate_ie == NULL)
848 continue;
849
850 for (j = 2; j < rate_ie[1] + 2; j++) {
851 int flagged = !!(rate_ie[j] & 0x80);
852 int r = (rate_ie[j] & 0x7f) * 5;
853
854 /*
855 * IEEE Std 802.11n-2009 7.3.2.2:
856 * The new BSS Membership selector value is encoded
857 * like a legacy basic rate, but it is not a rate and
858 * only indicates if the BSS members are required to
859 * support the mandatory features of Clause 20 [HT PHY]
860 * in order to join the BSS.
861 */
862 if (flagged && ((rate_ie[j] & 0x7f) ==
863 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
864 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800865 if (debug_print)
866 wpa_dbg(wpa_s, MSG_DEBUG,
867 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800868 return 0;
869 }
870 continue;
871 }
872
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700873 /* There's also a VHT selector for 802.11ac */
874 if (flagged && ((rate_ie[j] & 0x7f) ==
875 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
876 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800877 if (debug_print)
878 wpa_dbg(wpa_s, MSG_DEBUG,
879 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700880 return 0;
881 }
882 continue;
883 }
884
Hai Shalomc3565922019-10-28 11:58:20 -0700885#ifdef CONFIG_SAE
886 if (flagged && ((rate_ie[j] & 0x7f) ==
887 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700888 if (wpa_s->conf->sae_pwe == 0 &&
889 !ssid->sae_password_id &&
890 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700891 if (debug_print)
892 wpa_dbg(wpa_s, MSG_DEBUG,
893 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800894#ifdef CONFIG_TESTING_OPTIONS
895 if (wpa_s->ignore_sae_h2e_only) {
896 wpa_dbg(wpa_s, MSG_DEBUG,
897 "TESTING: Ignore SAE H2E requirement mismatch");
898 continue;
899 }
900#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700901 return 0;
902 }
903 continue;
904 }
905#endif /* CONFIG_SAE */
906
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800907 if (!flagged)
908 continue;
909
910 /* check for legacy basic rates */
911 for (k = 0; k < mode->num_rates; k++) {
912 if (mode->rates[k] == r)
913 break;
914 }
915 if (k == mode->num_rates) {
916 /*
917 * IEEE Std 802.11-2007 7.3.2.2 demands that in
918 * order to join a BSS all required rates
919 * have to be supported by the hardware.
920 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800921 if (debug_print)
922 wpa_dbg(wpa_s, MSG_DEBUG,
923 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
924 r / 10, r % 10,
925 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800926 return 0;
927 }
928 }
929 }
930
931 return 1;
932}
933
934
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800935/*
936 * Test whether BSS is in an ESS.
937 * This is done differently in DMG (60 GHz) and non-DMG bands
938 */
939static int bss_is_ess(struct wpa_bss *bss)
940{
941 if (bss_is_dmg(bss)) {
942 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
943 IEEE80211_CAP_DMG_AP;
944 }
945
946 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
947 IEEE80211_CAP_ESS);
948}
949
950
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800951static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
952{
953 size_t i;
954
955 for (i = 0; i < ETH_ALEN; i++) {
956 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
957 return 0;
958 }
959 return 1;
960}
961
962
963static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
964{
965 size_t i;
966
967 for (i = 0; i < num; i++) {
968 const u8 *a = list + i * ETH_ALEN * 2;
969 const u8 *m = a + ETH_ALEN;
970
971 if (match_mac_mask(a, addr, m))
972 return 1;
973 }
974 return 0;
975}
976
977
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700978static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
979 const u8 **ret_ssid, size_t *ret_ssid_len)
980{
981#ifdef CONFIG_OWE
982 const u8 *owe, *pos, *end, *bssid;
983 u8 ssid_len;
984 struct wpa_bss *open_bss;
985
986 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
987 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
988 return;
989
990 pos = owe + 6;
991 end = owe + 2 + owe[1];
992
993 if (end - pos < ETH_ALEN + 1)
994 return;
995 bssid = pos;
996 pos += ETH_ALEN;
997 ssid_len = *pos++;
998 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
999 return;
1000
1001 /* Match the profile SSID against the OWE transition mode SSID on the
1002 * open network. */
1003 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1004 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1005 *ret_ssid = pos;
1006 *ret_ssid_len = ssid_len;
1007
Hai Shalomfdcde762020-04-02 11:19:20 -07001008 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1009 struct wpa_ssid *ssid;
1010
1011 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1012 if (wpas_network_disabled(wpa_s, ssid))
1013 continue;
1014 if (ssid->ssid_len == ssid_len &&
1015 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1016 /* OWE BSS in transition mode for a currently
1017 * enabled OWE network. */
1018 wpa_dbg(wpa_s, MSG_DEBUG,
1019 "OWE: transition mode OWE SSID for active OWE profile");
1020 bss->flags |= WPA_BSS_OWE_TRANSITION;
1021 break;
1022 }
1023 }
1024 }
1025
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001026 if (bss->ssid_len > 0)
1027 return;
1028
1029 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1030 if (!open_bss)
1031 return;
1032 if (ssid_len != open_bss->ssid_len ||
1033 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1034 wpa_dbg(wpa_s, MSG_DEBUG,
1035 "OWE: transition mode SSID mismatch: %s",
1036 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1037 return;
1038 }
1039
1040 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1041 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1042 wpa_dbg(wpa_s, MSG_DEBUG,
1043 "OWE: transition mode open BSS unexpected info");
1044 return;
1045 }
1046
1047 pos = owe + 6;
1048 end = owe + 2 + owe[1];
1049
1050 if (end - pos < ETH_ALEN + 1)
1051 return;
1052 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1053 wpa_dbg(wpa_s, MSG_DEBUG,
1054 "OWE: transition mode BSSID mismatch: " MACSTR,
1055 MAC2STR(pos));
1056 return;
1057 }
1058 pos += ETH_ALEN;
1059 ssid_len = *pos++;
1060 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1061 return;
1062 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1063 wpa_ssid_txt(pos, ssid_len));
1064 os_memcpy(bss->ssid, pos, ssid_len);
1065 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001066 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001067#endif /* CONFIG_OWE */
1068}
1069
1070
Sunil Ravi26978f32021-04-30 15:19:18 -07001071int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001072{
1073 int i, j;
1074
1075 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1076 return 0;
1077
1078 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1079 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1080
1081 for (i = 0; i < mode->num_channels; i++) {
1082 struct hostapd_channel_data *chan = &mode->channels[i];
1083
1084 if (chan->freq == freq)
1085 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1086 }
1087 }
1088
1089 return 1;
1090}
1091
1092
Hai Shalom899fcc72020-10-19 14:38:18 -07001093static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1094 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001095 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001096 bool debug_print);
1097
1098
1099#ifdef CONFIG_SAE_PK
1100static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1101 struct wpa_bss *orig_bss,
1102 struct wpa_ssid *ssid,
1103 const u8 *match_ssid,
1104 size_t match_ssid_len)
1105{
1106 struct wpa_bss *bss;
1107
1108 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1109 int count;
1110 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001111
1112 if (bss == orig_bss)
1113 continue;
1114 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001115 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001116 continue;
1117
1118 /* TODO: Could be more thorough in checking what kind of
1119 * signal strength or throughput estimate would be acceptable
1120 * compared to the originally selected BSS. */
1121 if (bss->est_throughput < 2000)
1122 return false;
1123
Hai Shalom60840252021-02-19 19:02:11 -08001124 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001125 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1126 bss, count, 0))
1127 return true;
1128 }
1129
1130 return false;
1131}
1132#endif /* CONFIG_SAE_PK */
1133
1134
1135static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1136 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001137 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001138 bool debug_print)
1139{
1140 int res;
1141 bool wpa, check_ssid, osen, rsn_osen = false;
1142 struct wpa_ie_data data;
1143#ifdef CONFIG_MBO
1144 const u8 *assoc_disallow;
1145#endif /* CONFIG_MBO */
1146#ifdef CONFIG_SAE
1147 u8 rsnxe_capa = 0;
1148#endif /* CONFIG_SAE */
1149 const u8 *ie;
1150
1151 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1152 wpa = ie && ie[1];
1153 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1154 wpa |= ie && ie[1];
1155 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1156 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1157 rsn_osen = true;
1158 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1159 osen = ie != NULL;
1160
1161#ifdef CONFIG_SAE
1162 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1163 if (ie && ie[1] >= 1)
1164 rsnxe_capa = ie[2];
1165#endif /* CONFIG_SAE */
1166
1167 check_ssid = wpa || ssid->ssid_len > 0;
1168
1169 if (wpas_network_disabled(wpa_s, ssid)) {
1170 if (debug_print)
1171 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1172 return false;
1173 }
1174
1175 res = wpas_temp_disabled(wpa_s, ssid);
1176 if (res > 0) {
1177 if (debug_print)
1178 wpa_dbg(wpa_s, MSG_DEBUG,
1179 " skip - disabled temporarily for %d second(s)",
1180 res);
1181 return false;
1182 }
1183
1184#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001185 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001186 if (debug_print)
1187 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001188 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001189 return false;
1190 }
1191
1192 if (wpa && ssid->ssid_len == 0 &&
1193 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1194 check_ssid = false;
1195
1196 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1197 /* Only allow wildcard SSID match if an AP advertises active
1198 * WPS operation that matches our mode. */
1199 check_ssid = ssid->ssid_len > 0 ||
1200 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1201 }
1202#endif /* CONFIG_WPS */
1203
1204 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1205 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1206 check_ssid = false;
1207
1208 if (check_ssid &&
1209 (match_ssid_len != ssid->ssid_len ||
1210 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1211 if (debug_print)
1212 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1213 return false;
1214 }
1215
1216 if (ssid->bssid_set &&
1217 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1218 if (debug_print)
1219 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1220 return false;
1221 }
1222
Hai Shalom60840252021-02-19 19:02:11 -08001223 /* check the list of BSSIDs to ignore */
1224 if (ssid->num_bssid_ignore &&
1225 addr_in_list(bss->bssid, ssid->bssid_ignore,
1226 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001227 if (debug_print)
1228 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001229 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001230 return false;
1231 }
1232
Hai Shalom60840252021-02-19 19:02:11 -08001233 /* if there is a list of accepted BSSIDs, only accept those APs */
1234 if (ssid->num_bssid_accept &&
1235 !addr_in_list(bss->bssid, ssid->bssid_accept,
1236 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001237 if (debug_print)
1238 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001239 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001240 return false;
1241 }
1242
1243 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1244 return false;
1245
1246 if (!osen && !wpa &&
1247 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1248 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1249 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1250 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1251 if (debug_print)
1252 wpa_dbg(wpa_s, MSG_DEBUG,
1253 " skip - non-WPA network not allowed");
1254 return false;
1255 }
1256
1257#ifdef CONFIG_WEP
1258 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1259 if (debug_print)
1260 wpa_dbg(wpa_s, MSG_DEBUG,
1261 " skip - ignore WPA/WPA2 AP for WEP network block");
1262 return false;
1263 }
1264#endif /* CONFIG_WEP */
1265
1266 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1267 if (debug_print)
1268 wpa_dbg(wpa_s, MSG_DEBUG,
1269 " skip - non-OSEN network not allowed");
1270 return false;
1271 }
1272
1273 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1274 if (debug_print)
1275 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1276 return false;
1277 }
1278
1279 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1280 !bss_is_pbss(bss)) {
1281 if (debug_print)
1282 wpa_dbg(wpa_s, MSG_DEBUG,
1283 " skip - not ESS, PBSS, or MBSS");
1284 return false;
1285 }
1286
1287 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1288 if (debug_print)
1289 wpa_dbg(wpa_s, MSG_DEBUG,
1290 " skip - PBSS mismatch (ssid %d bss %d)",
1291 ssid->pbss, bss_is_pbss(bss));
1292 return false;
1293 }
1294
1295 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1296 if (debug_print)
1297 wpa_dbg(wpa_s, MSG_DEBUG,
1298 " skip - frequency not allowed");
1299 return false;
1300 }
1301
1302#ifdef CONFIG_MESH
1303 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1304 ssid->frequency != bss->freq) {
1305 if (debug_print)
1306 wpa_dbg(wpa_s, MSG_DEBUG,
1307 " skip - frequency not allowed (mesh)");
1308 return false;
1309 }
1310#endif /* CONFIG_MESH */
1311
1312 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1313 if (debug_print)
1314 wpa_dbg(wpa_s, MSG_DEBUG,
1315 " skip - rate sets do not match");
1316 return false;
1317 }
1318
1319#ifdef CONFIG_SAE
1320 if ((wpa_s->conf->sae_pwe == 1 || ssid->sae_password_id) &&
1321 wpa_s->conf->sae_pwe != 3 && wpa_key_mgmt_sae(ssid->key_mgmt) &&
1322 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1323 if (debug_print)
1324 wpa_dbg(wpa_s, MSG_DEBUG,
1325 " skip - SAE H2E required, but not supported by the AP");
1326 return false;
1327 }
1328#endif /* CONFIG_SAE */
1329
1330#ifdef CONFIG_SAE_PK
1331 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1332 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1333 if (debug_print)
1334 wpa_dbg(wpa_s, MSG_DEBUG,
1335 " skip - SAE-PK required, but not supported by the AP");
1336 return false;
1337 }
1338#endif /* CONFIG_SAE_PK */
1339
1340#ifndef CONFIG_IBSS_RSN
1341 if (ssid->mode == WPAS_MODE_IBSS &&
1342 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1343 if (debug_print)
1344 wpa_dbg(wpa_s, MSG_DEBUG,
1345 " skip - IBSS RSN not supported in the build");
1346 return false;
1347 }
1348#endif /* !CONFIG_IBSS_RSN */
1349
1350#ifdef CONFIG_P2P
1351 if (ssid->p2p_group &&
1352 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1353 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1354 if (debug_print)
1355 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1356 return false;
1357 }
1358
1359 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1360 struct wpabuf *p2p_ie;
1361 u8 dev_addr[ETH_ALEN];
1362
1363 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1364 if (!ie) {
1365 if (debug_print)
1366 wpa_dbg(wpa_s, MSG_DEBUG,
1367 " skip - no P2P element");
1368 return false;
1369 }
1370 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1371 if (!p2p_ie) {
1372 if (debug_print)
1373 wpa_dbg(wpa_s, MSG_DEBUG,
1374 " skip - could not fetch P2P element");
1375 return false;
1376 }
1377
1378 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1379 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1380 if (debug_print)
1381 wpa_dbg(wpa_s, MSG_DEBUG,
1382 " skip - no matching GO P2P Device Address in P2P element");
1383 wpabuf_free(p2p_ie);
1384 return false;
1385 }
1386 wpabuf_free(p2p_ie);
1387 }
1388
1389 /*
1390 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1391 * P2P Group Capability Bitmap and we are not in Group Formation with
1392 * that device.
1393 */
1394#endif /* CONFIG_P2P */
1395
1396 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1397 struct os_reltime diff;
1398
1399 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1400 if (debug_print)
1401 wpa_dbg(wpa_s, MSG_DEBUG,
1402 " skip - scan result not recent enough (%u.%06u seconds too old)",
1403 (unsigned int) diff.sec,
1404 (unsigned int) diff.usec);
1405 return false;
1406 }
1407#ifdef CONFIG_MBO
1408#ifdef CONFIG_TESTING_OPTIONS
1409 if (wpa_s->ignore_assoc_disallow)
1410 goto skip_assoc_disallow;
1411#endif /* CONFIG_TESTING_OPTIONS */
1412 assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1413 if (assoc_disallow && assoc_disallow[1] >= 1) {
1414 if (debug_print)
1415 wpa_dbg(wpa_s, MSG_DEBUG,
1416 " skip - MBO association disallowed (reason %u)",
1417 assoc_disallow[2]);
1418 return false;
1419 }
1420
1421 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1422 if (debug_print)
1423 wpa_dbg(wpa_s, MSG_DEBUG,
1424 " skip - AP temporarily disallowed");
1425 return false;
1426 }
1427#ifdef CONFIG_TESTING_OPTIONS
1428skip_assoc_disallow:
1429#endif /* CONFIG_TESTING_OPTIONS */
1430#endif /* CONFIG_MBO */
1431
1432#ifdef CONFIG_DPP
1433 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1434 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1435 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1436 !ssid->dpp_csign)) {
1437 if (debug_print)
1438 wpa_dbg(wpa_s, MSG_DEBUG,
1439 " skip - no PMKSA entry for DPP");
1440 return false;
1441 }
1442#endif /* CONFIG_DPP */
1443
1444#ifdef CONFIG_SAE_PK
1445 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1446 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1447 ((ssid->sae_password &&
1448 sae_pk_valid_password(ssid->sae_password)) ||
1449 (!ssid->sae_password && ssid->passphrase &&
1450 sae_pk_valid_password(ssid->passphrase))) &&
1451 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1452 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1453 match_ssid_len)) {
1454 if (debug_print)
1455 wpa_dbg(wpa_s, MSG_DEBUG,
1456 " skip - another acceptable BSS with SAE-PK in the same ESS");
1457 return false;
1458 }
1459#endif /* CONFIG_SAE_PK */
1460
1461 if (bss->ssid_len == 0) {
1462 if (debug_print)
1463 wpa_dbg(wpa_s, MSG_DEBUG,
1464 " skip - no SSID known for the BSS");
1465 return false;
1466 }
1467
1468 /* Matching configuration found */
1469 return true;
1470}
1471
1472
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001473struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1474 int i, struct wpa_bss *bss,
1475 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001476 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001477{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001478 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001479 const u8 *ie;
1480 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001481 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001482 const u8 *match_ssid;
1483 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001484 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001485
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001486 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001487 wpa_ie_len = ie ? ie[1] : 0;
1488
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001489 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001490 rsn_ie_len = ie ? ie[1] : 0;
1491
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001492 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1493 osen = ie != NULL;
1494
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001495 if (debug_print) {
1496 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1497 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1498 i, MAC2STR(bss->bssid),
1499 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1500 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1501 bss->freq,
1502 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1503 " wps" : "",
1504 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1505 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1506 ? " p2p" : "",
1507 osen ? " osen=1" : "");
1508 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001509
Hai Shalom60840252021-02-19 19:02:11 -08001510 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1511 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001512 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001513 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001514 /*
1515 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001516 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001517 * should not be done with multiple enabled networks to
1518 * avoid getting forced to move into a worse ESS on
1519 * single error if there are no other BSSes of the
1520 * current ESS.
1521 */
1522 limit = 0;
1523 }
Hai Shalom60840252021-02-19 19:02:11 -08001524 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001525 if (debug_print) {
1526 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001527 " skip - BSSID ignored (count=%d limit=%d)",
1528 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001529 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001530 return NULL;
1531 }
1532 }
1533
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001534 match_ssid = bss->ssid;
1535 match_ssid_len = bss->ssid_len;
1536 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1537
1538 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001539 if (debug_print)
1540 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001541 return NULL;
1542 }
1543
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001544 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001545 if (debug_print)
1546 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001547 return NULL;
1548 }
1549
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001550 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001551 if (debug_print)
1552 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001553 return NULL;
1554 }
1555
Hai Shalomfdcde762020-04-02 11:19:20 -07001556 if (disabled_freq(wpa_s, bss->freq)) {
1557 if (debug_print)
1558 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1559 return NULL;
1560 }
1561
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001562 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001563 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001564 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001565 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001566 }
1567
1568 /* No matching configuration found */
1569 return NULL;
1570}
1571
1572
1573static struct wpa_bss *
1574wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001576 struct wpa_ssid **selected_ssid,
1577 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001578{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001579 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001580
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001581 if (wpa_s->current_ssid) {
1582 struct wpa_ssid *ssid;
1583
1584 wpa_dbg(wpa_s, MSG_DEBUG,
1585 "Scan results matching the currently selected network");
1586 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1587 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1588
1589 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1590 only_first_ssid, 0);
1591 if (ssid != wpa_s->current_ssid)
1592 continue;
1593 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1594 " freq=%d level=%d snr=%d est_throughput=%u",
1595 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1596 bss->snr, bss->est_throughput);
1597 }
1598 }
1599
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001600 if (only_first_ssid)
1601 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1602 group->id);
1603 else
1604 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1605 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001606
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001607 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1608 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001609
1610 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001611 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001612 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001613 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001614 if (!*selected_ssid)
1615 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001616 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001617 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001618 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001619 MAC2STR(bss->bssid),
1620 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1621 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001622 }
1623
1624 return NULL;
1625}
1626
1627
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001628struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1629 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001630{
1631 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001632 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001633 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001634 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001636 if (wpa_s->last_scan_res == NULL ||
1637 wpa_s->last_scan_res_used == 0)
1638 return NULL; /* no scan results from last update */
1639
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001640 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001641 /* check that next_ssid is still valid */
1642 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1643 if (ssid == wpa_s->next_ssid)
1644 break;
1645 }
1646 next_ssid = ssid;
1647 wpa_s->next_ssid = NULL;
1648 }
1649
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001650 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001651 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1652 if (next_ssid && next_ssid->priority ==
1653 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001654 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001655 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001656 if (selected)
1657 break;
1658 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001659 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001660 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001661 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001662 if (selected)
1663 break;
1664 }
1665
Hai Shalom60840252021-02-19 19:02:11 -08001666 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001667 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001668 wpa_dbg(wpa_s, MSG_DEBUG,
1669 "No APs found - clear BSSID ignore list and try again");
1670 wpa_bssid_ignore_clear(wpa_s);
1671 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672 } else if (selected == NULL)
1673 break;
1674 }
1675
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001676 ssid = *selected_ssid;
1677 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1678 !ssid->passphrase && !ssid->ext_psk) {
1679 const char *field_name, *txt = NULL;
1680
1681 wpa_dbg(wpa_s, MSG_DEBUG,
1682 "PSK/passphrase not yet available for the selected network");
1683
1684 wpas_notify_network_request(wpa_s, ssid,
1685 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1686
1687 field_name = wpa_supplicant_ctrl_req_to_string(
1688 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1689 if (field_name == NULL)
1690 return NULL;
1691
1692 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1693
1694 selected = NULL;
1695 }
1696
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697 return selected;
1698}
1699
1700
1701static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1702 int timeout_sec, int timeout_usec)
1703{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001704 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001705 /*
1706 * No networks are enabled; short-circuit request so
1707 * we don't wait timeout seconds before transitioning
1708 * to INACTIVE state.
1709 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001710 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1711 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001712 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1713 return;
1714 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001715
1716 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001717 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1718}
1719
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001720
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001721int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001722 struct wpa_bss *selected,
1723 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001724{
1725 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1726 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1727 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001728 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001729#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001730 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1731 wpa_s->p2p_in_provisioning) {
1732 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1733 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001734 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001735 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001736#endif /* CONFIG_P2P */
1737
1738#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001739 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001740 wpas_wps_cancel(wpa_s);
1741#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001742 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743 }
1744
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001745 wpa_msg(wpa_s, MSG_DEBUG,
1746 "Considering connect request: reassociate: %d selected: "
1747 MACSTR " bssid: " MACSTR " pending: " MACSTR
1748 " wpa_state: %s ssid=%p current_ssid=%p",
1749 wpa_s->reassociate, MAC2STR(selected->bssid),
1750 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1751 wpa_supplicant_state_txt(wpa_s->wpa_state),
1752 ssid, wpa_s->current_ssid);
1753
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001754 /*
1755 * Do not trigger new association unless the BSSID has changed or if
1756 * reassociation is requested. If we are in process of associating with
1757 * the selected BSSID, do not trigger new attempt.
1758 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001759 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001760 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1761 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1762 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001763 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1764 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1765 0) ||
1766 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1767 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001768 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1769 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001770 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001771 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001772 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1773 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001774 wpa_supplicant_associate(wpa_s, selected, ssid);
1775 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001776 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1777 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001779
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001780 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001781}
1782
1783
1784static struct wpa_ssid *
1785wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1786{
Hai Shalomfdcde762020-04-02 11:19:20 -07001787 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001788 struct wpa_ssid *ssid;
1789
1790 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1791 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1792 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001793 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001794 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001795#ifndef CONFIG_IBSS_RSN
1796 if (ssid->mode == WPAS_MODE_IBSS &&
1797 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1798 WPA_KEY_MGMT_WPA_NONE))) {
1799 wpa_msg(wpa_s, MSG_INFO,
1800 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1801 wpa_ssid_txt(ssid->ssid,
1802 ssid->ssid_len));
1803 continue;
1804 }
1805#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001806 if (ssid->mode == WPAS_MODE_IBSS ||
1807 ssid->mode == WPAS_MODE_AP ||
1808 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001809 return ssid;
1810 }
1811 }
1812 return NULL;
1813}
1814
1815
1816/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1817 * on BSS added and BSS changed events */
1818static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001819 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001821 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001822
1823 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1824 return;
1825
Jouni Malinen87fd2792011-05-16 18:35:42 +03001826 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001828
Jouni Malinen87fd2792011-05-16 18:35:42 +03001829 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 if (ssid == NULL)
1831 continue;
1832
Jouni Malinen87fd2792011-05-16 18:35:42 +03001833 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834 if (rsn == NULL)
1835 continue;
1836
Jouni Malinen87fd2792011-05-16 18:35:42 +03001837 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 }
1839
1840}
1841
1842
Hai Shalomfdcde762020-04-02 11:19:20 -07001843#ifndef CONFIG_NO_ROAMING
1844
1845static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1846{
1847 if (noise == WPA_INVALID_NOISE)
1848 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1849 DEFAULT_NOISE_FLOOR_2GHZ;
1850 return avg_signal - noise;
1851}
1852
1853
1854static unsigned int
1855wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1856 const struct wpa_bss *bss, int snr)
1857{
1858 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001859 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001860 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1861
Hai Shalomc1a21442022-02-04 13:43:00 -08001862 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07001863}
1864
Hai Shalomfdcde762020-04-02 11:19:20 -07001865
Hai Shalom899fcc72020-10-19 14:38:18 -07001866int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1867 struct wpa_bss *current_bss,
1868 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001869{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001870 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001871 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001872 int cur_level;
1873 unsigned int cur_est, sel_est;
1874 struct wpa_signal_info si;
1875 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001876 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001879 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001880 " freq=%d level=%d snr=%d est_throughput=%u",
1881 MAC2STR(current_bss->bssid),
1882 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001883 current_bss->snr, current_bss->est_throughput);
1884 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001885 " freq=%d level=%d snr=%d est_throughput=%u",
1886 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001887 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001888
1889 if (wpa_s->current_ssid->bssid_set &&
1890 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1891 0) {
1892 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1893 "has preferred BSSID");
1894 return 1;
1895 }
1896
Hai Shalomfdcde762020-04-02 11:19:20 -07001897 cur_level = current_bss->level;
1898 cur_est = current_bss->est_throughput;
1899 sel_est = selected->est_throughput;
1900
1901 /*
1902 * Try to poll the signal from the driver since this will allow to get
1903 * more accurate values. In some cases, there can be big differences
1904 * between the RSSI of the Probe Response frames of the AP we are
1905 * associated with and the Beacon frames we hear from the same AP after
1906 * association. This can happen, e.g., when there are two antennas that
1907 * hear the AP very differently. If the driver chooses to hear the
1908 * Probe Response frames during the scan on the "bad" antenna because
1909 * it wants to save power, but knows to choose the other antenna after
1910 * association, we will hear our AP with a low RSSI as part of the
1911 * scan even when we can hear it decently on the other antenna. To cope
1912 * with this, ask the driver to teach us how it hears the AP. Also, the
1913 * scan results may be a bit old, since we can very quickly get fresh
1914 * information about our currently associated AP.
1915 */
1916 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1917 (si.avg_beacon_signal || si.avg_signal)) {
1918 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1919 si.avg_signal;
1920 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
1921 si.current_noise);
1922
1923 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
1924 current_bss,
1925 cur_snr);
1926 wpa_dbg(wpa_s, MSG_DEBUG,
1927 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
1928 cur_level, cur_snr, cur_est);
1929 }
1930
1931 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001932 wpa_dbg(wpa_s, MSG_DEBUG,
1933 "Allow reassociation - selected BSS has better estimated throughput");
1934 return 1;
1935 }
1936
Dmitry Shmidte4663042016-04-04 10:07:49 -07001937 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1938
Hai Shalomfdcde762020-04-02 11:19:20 -07001939 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
1940 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001941 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1942 "signal level");
1943 return 0;
1944 }
1945
Hai Shalomfdcde762020-04-02 11:19:20 -07001946 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001947 wpa_dbg(wpa_s, MSG_DEBUG,
1948 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001949 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001950 }
1951
Hai Shalomfdcde762020-04-02 11:19:20 -07001952 if (cur_snr > GREAT_SNR) {
1953 wpa_dbg(wpa_s, MSG_DEBUG,
1954 "Skip roam - Current BSS has good SNR (%u > %u)",
1955 cur_snr, GREAT_SNR);
1956 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001957 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001958
Hai Shalomfdcde762020-04-02 11:19:20 -07001959 if (cur_level < -85) /* ..-86 dBm */
1960 min_diff = 1;
1961 else if (cur_level < -80) /* -85..-81 dBm */
1962 min_diff = 2;
1963 else if (cur_level < -75) /* -80..-76 dBm */
1964 min_diff = 3;
1965 else if (cur_level < -70) /* -75..-71 dBm */
1966 min_diff = 4;
1967 else if (cur_level < 0) /* -70..-1 dBm */
1968 min_diff = 5;
1969 else /* unspecified units (not in dBm) */
1970 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001971
Hai Shalomfdcde762020-04-02 11:19:20 -07001972 if (cur_est > sel_est * 1.5)
1973 min_diff += 10;
1974 else if (cur_est > sel_est * 1.2)
1975 min_diff += 5;
1976 else if (cur_est > sel_est * 1.1)
1977 min_diff += 2;
1978 else if (cur_est > sel_est)
1979 min_diff++;
1980 else if (sel_est > cur_est * 1.5)
1981 min_diff -= 10;
1982 else if (sel_est > cur_est * 1.2)
1983 min_diff -= 5;
1984 else if (sel_est > cur_est * 1.1)
1985 min_diff -= 2;
1986 else if (sel_est > cur_est)
1987 min_diff--;
1988
1989 if (to_5ghz)
1990 min_diff -= 2;
1991 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001992 if (diff < min_diff) {
1993 wpa_dbg(wpa_s, MSG_DEBUG,
1994 "Skip roam - too small difference in signal level (%d < %d)",
1995 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07001996 ret = 0;
1997 } else {
1998 wpa_dbg(wpa_s, MSG_DEBUG,
1999 "Allow reassociation due to difference in signal level (%d >= %d)",
2000 diff, min_diff);
2001 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002002 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002003 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2004 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2005 " sel_freq=%d sel_level=%d sel_est=%d",
2006 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2007 MAC2STR(current_bss->bssid),
2008 current_bss->freq, cur_level, cur_est,
2009 MAC2STR(selected->bssid),
2010 selected->freq, selected->level, sel_est);
2011 return ret;
2012}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002013
Hai Shalom899fcc72020-10-19 14:38:18 -07002014#endif /* CONFIG_NO_ROAMING */
2015
2016
2017static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2018 struct wpa_bss *selected,
2019 struct wpa_ssid *ssid)
2020{
2021 struct wpa_bss *current_bss = NULL;
2022
2023 if (wpa_s->reassociate)
2024 return 1; /* explicit request to reassociate */
2025 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2026 return 1; /* we are not associated; continue */
2027 if (wpa_s->current_ssid == NULL)
2028 return 1; /* unknown current SSID */
2029 if (wpa_s->current_ssid != ssid)
2030 return 1; /* different network block */
2031
2032 if (wpas_driver_bss_selection(wpa_s))
2033 return 0; /* Driver-based roaming */
2034
2035 if (wpa_s->current_ssid->ssid)
2036 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2037 wpa_s->current_ssid->ssid,
2038 wpa_s->current_ssid->ssid_len);
2039 if (!current_bss)
2040 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2041
2042 if (!current_bss)
2043 return 1; /* current BSS not seen in scan results */
2044
2045 if (current_bss == selected)
2046 return 0;
2047
2048 if (selected->last_update_idx > current_bss->last_update_idx)
2049 return 1; /* current BSS not seen in the last scan */
2050
2051#ifndef CONFIG_NO_ROAMING
2052 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2053 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002054#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002055 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002056#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002057}
2058
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002059
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002060/*
2061 * Return a negative value if no scan results could be fetched or if scan
2062 * results should not be shared with other virtual interfaces.
2063 * Return 0 if scan results were fetched and may be shared with other
2064 * interfaces.
2065 * Return 1 if scan results may be shared with other virtual interfaces but may
2066 * not trigger any operations.
2067 * Return 2 if the interface was removed and cannot be used.
2068 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002069static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002070 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002071 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002072{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002073 struct wpa_scan_results *scan_res = NULL;
2074 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002076#ifndef CONFIG_NO_RANDOM_POOL
2077 size_t i, num;
2078#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002079
2080#ifdef CONFIG_AP
2081 if (wpa_s->ap_iface)
2082 ap = 1;
2083#endif /* CONFIG_AP */
2084
2085 wpa_supplicant_notify_scanning(wpa_s, 0);
2086
2087 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2088 data ? &data->scan_info :
2089 NULL, 1);
2090 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002091 if (wpa_s->conf->ap_scan == 2 || ap ||
2092 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002093 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002094 if (!own_request)
2095 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002096 if (data && data->scan_info.external_scan)
2097 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002098 if (wpa_s->scan_res_fail_handler) {
2099 void (*handler)(struct wpa_supplicant *wpa_s);
2100
2101 handler = wpa_s->scan_res_fail_handler;
2102 wpa_s->scan_res_fail_handler = NULL;
2103 handler(wpa_s);
2104 } else {
2105 wpa_dbg(wpa_s, MSG_DEBUG,
2106 "Failed to get scan results - try scanning again");
2107 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2108 }
2109
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002110 ret = -1;
2111 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002112 }
2113
2114#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002115 num = scan_res->num;
2116 if (num > 10)
2117 num = 10;
2118 for (i = 0; i < num; i++) {
2119 u8 buf[5];
2120 struct wpa_scan_res *res = scan_res->res[i];
2121 buf[0] = res->bssid[5];
2122 buf[1] = res->qual & 0xff;
2123 buf[2] = res->noise & 0xff;
2124 buf[3] = res->level & 0xff;
2125 buf[4] = res->tsf & 0xff;
2126 random_add_randomness(buf, sizeof(buf));
2127 }
2128#endif /* CONFIG_NO_RANDOM_POOL */
2129
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002130 if (update_only) {
2131 ret = 1;
2132 goto scan_work_done;
2133 }
2134
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002135 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002136 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002137 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2138 struct wpa_scan_results *scan_res);
2139
2140 scan_res_handler = wpa_s->scan_res_handler;
2141 wpa_s->scan_res_handler = NULL;
2142 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002143 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002144 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002145 }
2146
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002147 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002148 wpa_s->own_scan_running,
2149 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002150 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002151 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2152 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002153 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2154 wpa_s->manual_scan_id);
2155 wpa_s->manual_scan_use_id = 0;
2156 } else {
2157 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2158 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002159 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160
2161 wpas_notify_scan_done(wpa_s, 1);
2162
Hai Shalomfdcde762020-04-02 11:19:20 -07002163 if (ap) {
2164 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2165#ifdef CONFIG_AP
2166 if (wpa_s->ap_iface->scan_cb)
2167 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2168#endif /* CONFIG_AP */
2169 goto scan_work_done;
2170 }
2171
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002172 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002173 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 -07002174 wpa_scan_results_free(scan_res);
2175 return 0;
2176 }
2177
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002178 if (wnm_scan_process(wpa_s, 1) > 0)
2179 goto scan_work_done;
2180
Hai Shalomc1a21442022-02-04 13:43:00 -08002181 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002182 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002183
Hai Shalom021b0b52019-04-10 11:17:58 -07002184 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002185 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2186 goto scan_work_done;
2187
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002188 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2189 goto scan_work_done;
2190
2191 if (autoscan_notify_scan(wpa_s, scan_res))
2192 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002193
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002194 if (wpa_s->disconnected) {
2195 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002196 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002197 }
2198
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002199 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002200 bgscan_notify_scan(wpa_s, scan_res) == 1)
2201 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002202
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002203 wpas_wps_update_ap_info(wpa_s, scan_res);
2204
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002205 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2206 wpa_s->wpa_state < WPA_COMPLETED)
2207 goto scan_work_done;
2208
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002209 wpa_scan_results_free(scan_res);
2210
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002211 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002212 struct wpa_radio_work *work = wpa_s->scan_work;
2213 wpa_s->scan_work = NULL;
2214 radio_work_done(work);
2215 }
2216
Hai Shalomc3565922019-10-28 11:58:20 -07002217 os_free(wpa_s->last_scan_freqs);
2218 wpa_s->last_scan_freqs = NULL;
2219 wpa_s->num_last_scan_freqs = 0;
2220 if (own_request && data &&
2221 data->scan_info.freqs && data->scan_info.num_freqs) {
2222 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2223 data->scan_info.num_freqs);
2224 if (wpa_s->last_scan_freqs) {
2225 os_memcpy(wpa_s->last_scan_freqs,
2226 data->scan_info.freqs,
2227 sizeof(int) * data->scan_info.num_freqs);
2228 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2229 }
2230 }
2231
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002232 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002233
2234scan_work_done:
2235 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002236 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002237 struct wpa_radio_work *work = wpa_s->scan_work;
2238 wpa_s->scan_work = NULL;
2239 radio_work_done(work);
2240 }
2241 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002242}
2243
2244
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002245static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002246 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002247{
2248 struct wpa_bss *selected;
2249 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002250 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2251
2252 if (time_to_reenable > 0) {
2253 wpa_dbg(wpa_s, MSG_DEBUG,
2254 "Postpone network selection by %d seconds since all networks are disabled",
2255 time_to_reenable);
2256 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2257 eloop_register_timeout(time_to_reenable, 0,
2258 wpas_network_reenabled, wpa_s, NULL);
2259 return 0;
2260 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002261
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002262 if (wpa_s->p2p_mgmt)
2263 return 0; /* no normal connection on p2p_mgmt interface */
2264
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002265 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002266 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002267
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002268#ifdef CONFIG_MESH
2269 if (wpa_s->ifmsh) {
2270 wpa_msg(wpa_s, MSG_INFO,
2271 "Avoiding join because we already joined a mesh group");
2272 return 0;
2273 }
2274#endif /* CONFIG_MESH */
2275
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002276 if (selected) {
2277 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002278 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002279 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002280 if (new_scan)
2281 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002282 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283 }
2284
Hai Shalomc3565922019-10-28 11:58:20 -07002285 wpa_s->suitable_network++;
2286
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002287 if (ssid != wpa_s->current_ssid &&
2288 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2289 wpa_s->own_disconnect_req = 1;
2290 wpa_supplicant_deauthenticate(
2291 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2292 }
2293
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002294 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002295 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002296 return -1;
2297 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002298 if (new_scan)
2299 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002300 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002301 * Do not allow other virtual radios to trigger operations based
2302 * on these scan results since we do not want them to start
2303 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002304 */
2305 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002307 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2309 ssid = wpa_supplicant_pick_new_network(wpa_s);
2310 if (ssid) {
2311 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2312 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002313 if (new_scan)
2314 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002315 } else if (own_request) {
2316 /*
2317 * No SSID found. If SCAN results are as a result of
2318 * own scan request and not due to a scan request on
2319 * another shared interface, try another scan.
2320 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002321 int timeout_sec = wpa_s->scan_interval;
2322 int timeout_usec = 0;
2323#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002324 int res;
2325
2326 res = wpas_p2p_scan_no_go_seen(wpa_s);
2327 if (res == 2)
2328 return 2;
2329 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002330 return 0;
2331
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002332 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002333 wpa_s->show_group_started ||
2334 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002335 /*
2336 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002337 * state and during P2P join-a-group operation
2338 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002339 */
2340 timeout_sec = 0;
2341 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002342 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2343 timeout_usec);
2344 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002345 }
2346#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002347#ifdef CONFIG_INTERWORKING
2348 if (wpa_s->conf->auto_interworking &&
2349 wpa_s->conf->interworking &&
2350 wpa_s->conf->cred) {
2351 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2352 "start ANQP fetch since no matching "
2353 "networks found");
2354 wpa_s->network_select = 1;
2355 wpa_s->auto_network_select = 1;
2356 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002357 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002358 }
2359#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002360#ifdef CONFIG_WPS
2361 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2362 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2363 timeout_sec = 0;
2364 timeout_usec = 500000;
2365 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2366 timeout_usec);
2367 return 0;
2368 }
2369#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002370#ifdef CONFIG_OWE
2371 if (wpa_s->owe_transition_search) {
2372 wpa_dbg(wpa_s, MSG_DEBUG,
2373 "OWE: Use shorter wait during transition mode search");
2374 timeout_sec = 0;
2375 timeout_usec = 500000;
2376 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2377 timeout_usec);
2378 return 0;
2379 }
2380#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002381 if (wpa_supplicant_req_sched_scan(wpa_s))
2382 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2383 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002384
2385 wpa_msg_ctrl(wpa_s, MSG_INFO,
2386 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002387 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002388 }
2389 }
2390 return 0;
2391}
2392
2393
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002394static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2395 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002396{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002397 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002398 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002399
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002400 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002401 if (res == 2) {
2402 /*
2403 * Interface may have been removed, so must not dereference
2404 * wpa_s after this.
2405 */
2406 return 1;
2407 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002408
2409 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002410 /*
2411 * If no scan results could be fetched, then no need to
2412 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002413 * this scan. Similarly, if scan results started a new operation on this
2414 * interface, do not notify other interfaces to avoid concurrent
2415 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002416 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002417 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418 }
2419
2420 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002421 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002422 * so, they get updated with this same scan info.
2423 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002424 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2425 radio_list) {
2426 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002427 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2428 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002429 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2430 res > 0);
2431 if (res < 0)
2432 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002433 }
2434 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002435
2436 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002437}
2438
2439#endif /* CONFIG_NO_SCAN_PROCESSING */
2440
2441
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002442int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2443{
2444#ifdef CONFIG_NO_SCAN_PROCESSING
2445 return -1;
2446#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002447 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002448
Dmitry Shmidt29333592017-01-09 12:27:11 -08002449 wpa_s->ignore_post_flush_scan_res = 0;
2450
Dmitry Shmidt41712582015-06-29 11:02:15 -07002451 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002452 return -1;
2453
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002454 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002455 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002456 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002457 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2458 return -1;
2459 }
2460
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002461 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002462#endif /* CONFIG_NO_SCAN_PROCESSING */
2463}
2464
Dmitry Shmidt04949592012-07-19 12:16:46 -07002465#ifdef CONFIG_WNM
2466
2467static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2468{
2469 struct wpa_supplicant *wpa_s = eloop_ctx;
2470
2471 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2472 return;
2473
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002474 if (!wpa_s->no_keep_alive) {
2475 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2476 MAC2STR(wpa_s->bssid));
2477 /* TODO: could skip this if normal data traffic has been sent */
2478 /* TODO: Consider using some more appropriate data frame for
2479 * this */
2480 if (wpa_s->l2)
2481 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2482 (u8 *) "", 0);
2483 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002484
2485#ifdef CONFIG_SME
2486 if (wpa_s->sme.bss_max_idle_period) {
2487 unsigned int msec;
2488 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2489 if (msec > 100)
2490 msec -= 100;
2491 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2492 wnm_bss_keep_alive, wpa_s, NULL);
2493 }
2494#endif /* CONFIG_SME */
2495}
2496
2497
2498static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2499 const u8 *ies, size_t ies_len)
2500{
2501 struct ieee802_11_elems elems;
2502
2503 if (ies == NULL)
2504 return;
2505
2506 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2507 return;
2508
2509#ifdef CONFIG_SME
2510 if (elems.bss_max_idle_period) {
2511 unsigned int msec;
2512 wpa_s->sme.bss_max_idle_period =
2513 WPA_GET_LE16(elems.bss_max_idle_period);
2514 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2515 "TU)%s", wpa_s->sme.bss_max_idle_period,
2516 (elems.bss_max_idle_period[2] & 0x01) ?
2517 " (protected keep-live required)" : "");
2518 if (wpa_s->sme.bss_max_idle_period == 0)
2519 wpa_s->sme.bss_max_idle_period = 1;
2520 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2521 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2522 /* msec times 1000 */
2523 msec = wpa_s->sme.bss_max_idle_period * 1024;
2524 if (msec > 100)
2525 msec -= 100;
2526 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2527 wnm_bss_keep_alive, wpa_s,
2528 NULL);
2529 }
2530 }
2531#endif /* CONFIG_SME */
2532}
2533
2534#endif /* CONFIG_WNM */
2535
2536
2537void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2538{
2539#ifdef CONFIG_WNM
2540 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2541#endif /* CONFIG_WNM */
2542}
2543
2544
Dmitry Shmidt051af732013-10-22 13:52:46 -07002545#ifdef CONFIG_INTERWORKING
2546
2547static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2548 size_t len)
2549{
2550 int res;
2551
2552 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2553 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2554 if (res) {
2555 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2556 }
2557
2558 return res;
2559}
2560
2561
2562static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2563 const u8 *ies, size_t ies_len)
2564{
2565 struct ieee802_11_elems elems;
2566
2567 if (ies == NULL)
2568 return;
2569
2570 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2571 return;
2572
2573 if (elems.qos_map_set) {
2574 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2575 elems.qos_map_set_len);
2576 }
2577}
2578
2579#endif /* CONFIG_INTERWORKING */
2580
2581
Hai Shalom74f70d42019-02-11 14:42:39 -08002582static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2583 const u8 *ies, size_t ies_len)
2584{
2585 struct ieee802_11_elems elems;
2586 const u8 *map_sub_elem, *pos;
2587 size_t len;
2588
Hai Shalomfdcde762020-04-02 11:19:20 -07002589 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002590
Hai Shalomfdcde762020-04-02 11:19:20 -07002591 if (!ies ||
2592 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2593 !elems.multi_ap || elems.multi_ap_len < 7)
2594 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002595
2596 pos = elems.multi_ap + 4;
2597 len = elems.multi_ap_len - 4;
2598
2599 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002600 if (!map_sub_elem || map_sub_elem[1] < 1)
2601 return;
2602
2603 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2604 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2605 MULTI_AP_FRONTHAUL_BSS);
2606 wpa_s->multi_ap_ie = 1;
2607}
2608
2609
2610static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2611{
2612 if (!wpa_s->current_ssid ||
2613 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2614 return;
2615
2616 if (!wpa_s->multi_ap_ie) {
2617 wpa_printf(MSG_INFO,
2618 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002619 goto fail;
2620 }
2621
Hai Shalomfdcde762020-04-02 11:19:20 -07002622 if (!wpa_s->multi_ap_backhaul) {
2623 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002624 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2625 wpa_printf(MSG_INFO,
2626 "WPS active, accepting fronthaul-only BSS");
2627 /* Don't set 4addr mode in this case, so just return */
2628 return;
2629 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002630 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2631 goto fail;
2632 }
2633
2634 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2635 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2636 goto fail;
2637 }
2638 wpa_s->enabled_4addr_mode = 1;
2639 return;
2640
2641fail:
2642 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2643}
2644
2645
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002646#ifdef CONFIG_FST
2647static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2648 const u8 *ie, size_t ie_len)
2649{
2650 struct mb_ies_info mb_ies;
2651
2652 if (!ie || !ie_len || !wpa_s->fst)
2653 return -ENOENT;
2654
2655 os_memset(&mb_ies, 0, sizeof(mb_ies));
2656
2657 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2658 size_t len;
2659
2660 len = 2 + ie[1];
2661 if (len > ie_len) {
2662 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2663 ie, ie_len);
2664 break;
2665 }
2666
2667 if (ie[0] == WLAN_EID_MULTI_BAND) {
2668 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2669 (unsigned int) len);
2670 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2671 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2672 mb_ies.nof_ies++;
2673 }
2674
2675 ie_len -= len;
2676 ie += len;
2677 }
2678
2679 if (mb_ies.nof_ies > 0) {
2680 wpabuf_free(wpa_s->received_mb_ies);
2681 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2682 return 0;
2683 }
2684
2685 return -ENOENT;
2686}
2687#endif /* CONFIG_FST */
2688
2689
Hai Shalomc1a21442022-02-04 13:43:00 -08002690static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2691 union wpa_event_data *data)
2692{
2693 int sel;
2694 const u8 *p;
2695 int l, len;
2696 bool found = false;
2697 struct wpa_ie_data ie;
2698 struct wpa_ssid *ssid = wpa_s->current_ssid;
2699 struct wpa_bss *bss = wpa_s->current_bss;
2700 int pmf;
2701
2702 if (!ssid)
2703 return 0;
2704
2705 p = data->assoc_info.req_ies;
2706 l = data->assoc_info.req_ies_len;
2707
2708 while (p && l >= 2) {
2709 len = p[1] + 2;
2710 if (len > l) {
2711 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2712 p, l);
2713 break;
2714 }
2715 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2716 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2717 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2718 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2719 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2720 found = true;
2721 break;
2722 }
2723 l -= len;
2724 p += len;
2725 }
2726
2727 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2728 return 0;
2729
2730 wpa_hexdump(MSG_DEBUG,
2731 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2732 p, l);
2733
2734 /* Update proto from (Re)Association Request frame info */
2735 wpa_s->wpa_proto = ie.proto;
2736 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2737 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2738 !!(wpa_s->wpa_proto &
2739 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2740
2741 /* Update AKMP suite from (Re)Association Request frame info */
2742 sel = ie.key_mgmt;
2743 if (ssid->key_mgmt)
2744 sel &= ssid->key_mgmt;
2745
2746 wpa_dbg(wpa_s, MSG_DEBUG,
2747 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2748 ie.key_mgmt, ssid->key_mgmt, sel);
2749 if (ie.key_mgmt && !sel) {
2750 wpa_supplicant_deauthenticate(
2751 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2752 return -1;
2753 }
2754
2755 wpa_s->key_mgmt = ie.key_mgmt;
2756 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2757 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2758 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2759 wpa_s->wpa_proto);
2760
2761 /* Update pairwise cipher from (Re)Association Request frame info */
2762 sel = ie.pairwise_cipher;
2763 if (ssid->pairwise_cipher)
2764 sel &= ssid->pairwise_cipher;
2765
2766 wpa_dbg(wpa_s, MSG_DEBUG,
2767 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2768 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2769 if (ie.pairwise_cipher && !sel) {
2770 wpa_supplicant_deauthenticate(
2771 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2772 return -1;
2773 }
2774
2775 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2776 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2777 wpa_s->pairwise_cipher);
2778 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2779 wpa_cipher_txt(wpa_s->pairwise_cipher));
2780
2781 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2782 if (!bss) {
2783 wpa_dbg(wpa_s, MSG_DEBUG,
2784 "WPA: current_bss == NULL - skip AP IE check");
2785 return 0;
2786 }
2787
2788 /* Update GTK and IGTK from AP's RSNE */
2789 found = false;
2790
2791 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2792 const u8 *bss_rsn;
2793
2794 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2795 if (bss_rsn) {
2796 p = bss_rsn;
2797 len = 2 + bss_rsn[1];
2798 found = true;
2799 }
2800 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2801 const u8 *bss_wpa;
2802
2803 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2804 if (bss_wpa) {
2805 p = bss_wpa;
2806 len = 2 + bss_wpa[1];
2807 found = true;
2808 }
2809 }
2810
2811 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2812 return 0;
2813
2814 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2815 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2816 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
2817 /* AP does not support MFP, local configuration requires it */
2818 wpa_supplicant_deauthenticate(
2819 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2820 return -1;
2821 }
2822 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
2823 pmf == NO_MGMT_FRAME_PROTECTION) {
2824 /* AP requires MFP, local configuration disables it */
2825 wpa_supplicant_deauthenticate(
2826 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2827 return -1;
2828 }
2829
2830 /* Update PMF from local configuration now that MFP validation was done
2831 * above */
2832 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
2833
2834 /* Update GTK from AP's RSNE */
2835 sel = ie.group_cipher;
2836 if (ssid->group_cipher)
2837 sel &= ssid->group_cipher;
2838
2839 wpa_dbg(wpa_s, MSG_DEBUG,
2840 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
2841 ie.group_cipher, ssid->group_cipher, sel);
2842 if (ie.group_cipher && !sel) {
2843 wpa_supplicant_deauthenticate(
2844 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
2845 return -1;
2846 }
2847
2848 wpa_s->group_cipher = ie.group_cipher;
2849 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
2850 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
2851 wpa_cipher_txt(wpa_s->group_cipher));
2852
2853 /* Update IGTK from AP RSN IE */
2854 sel = ie.mgmt_group_cipher;
2855 if (ssid->group_mgmt_cipher)
2856 sel &= ssid->group_mgmt_cipher;
2857
2858 wpa_dbg(wpa_s, MSG_DEBUG,
2859 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
2860 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
2861
2862 if (pmf == NO_MGMT_FRAME_PROTECTION ||
2863 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
2864 wpa_dbg(wpa_s, MSG_DEBUG,
2865 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
2866 ie.capabilities);
2867 ie.mgmt_group_cipher = 0;
2868 }
2869
2870 if (ie.mgmt_group_cipher && !sel) {
2871 wpa_supplicant_deauthenticate(
2872 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
2873 return -1;
2874 }
2875
2876 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
2877 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
2878 wpa_s->mgmt_group_cipher);
2879 if (wpa_s->mgmt_group_cipher)
2880 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
2881 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
2882 else
2883 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
2884
2885 return 0;
2886}
2887
2888
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002889static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2890 union wpa_event_data *data)
2891{
Hai Shalomc3565922019-10-28 11:58:20 -07002892 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002893 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002894 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002895 bool bssid_known;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002896
2897 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07002898 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002899 if (data->assoc_info.req_ies)
2900 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2901 data->assoc_info.req_ies_len);
2902 if (data->assoc_info.resp_ies) {
2903 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2904 data->assoc_info.resp_ies_len);
2905#ifdef CONFIG_TDLS
2906 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2907 data->assoc_info.resp_ies_len);
2908#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002909#ifdef CONFIG_WNM
2910 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2911 data->assoc_info.resp_ies_len);
2912#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002913#ifdef CONFIG_INTERWORKING
2914 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2915 data->assoc_info.resp_ies_len);
2916#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002917 if (wpa_s->hw_capab == CAPAB_VHT &&
2918 get_ie(data->assoc_info.resp_ies,
2919 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2920 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002921
2922 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2923 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002924 }
2925 if (data->assoc_info.beacon_ies)
2926 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2927 data->assoc_info.beacon_ies,
2928 data->assoc_info.beacon_ies_len);
2929 if (data->assoc_info.freq)
2930 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2931 data->assoc_info.freq);
2932
Hai Shalom021b0b52019-04-10 11:17:58 -07002933 wpa_s->connection_set = 0;
2934 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2935 struct ieee802_11_elems req_elems, resp_elems;
2936
2937 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2938 data->assoc_info.req_ies_len,
2939 &req_elems, 0) != ParseFailed &&
2940 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2941 data->assoc_info.resp_ies_len,
2942 &resp_elems, 0) != ParseFailed) {
2943 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07002944 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
2945 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07002946 wpa_s->connection_ht = req_elems.ht_capabilities &&
2947 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07002948 /* Do not include subset of VHT on 2.4 GHz vendor
2949 * extension in consideration for reporting VHT
2950 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07002951 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002952 resp_elems.vht_capabilities &&
2953 (!data->assoc_info.freq ||
2954 wpas_freq_to_band(data->assoc_info.freq) !=
2955 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07002956 wpa_s->connection_he = req_elems.he_capabilities &&
2957 resp_elems.he_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08002958
2959 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
2960 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
2961 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
2962 max_nss_rx_req : max_nss_rx_resp;
2963 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
2964 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
2965 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
2966 max_nss_tx_req : max_nss_tx_resp;
2967
2968 struct supported_chan_width sta_supported_chan_width =
2969 get_supported_channel_width(&req_elems);
2970 enum chan_width ap_operation_chan_width =
2971 get_operation_channel_width(&resp_elems);
2972 if (wpa_s->connection_vht || wpa_s->connection_he) {
2973 wpa_s->connection_channel_bandwidth =
2974 get_sta_operation_chan_width(ap_operation_chan_width,
2975 sta_supported_chan_width);
2976 } else if (wpa_s->connection_ht) {
2977 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
2978 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
2979 } else {
2980 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
2981 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002982 }
2983 }
2984
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002985 p = data->assoc_info.req_ies;
2986 l = data->assoc_info.req_ies_len;
2987
2988 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2989 while (p && l >= 2) {
2990 len = p[1] + 2;
2991 if (len > l) {
2992 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2993 p, l);
2994 break;
2995 }
Hai Shalomc3565922019-10-28 11:58:20 -07002996 if (!found &&
2997 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2998 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2999 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3000 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3001 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003002 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3003 break;
3004 found = 1;
3005 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07003006 }
3007 if (!found_x && p[0] == WLAN_EID_RSNX) {
3008 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3009 break;
3010 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003011 }
3012 l -= len;
3013 p += len;
3014 }
3015 if (!found && data->assoc_info.req_ies)
3016 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003017 if (!found_x && data->assoc_info.req_ies)
3018 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003019
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003020#ifdef CONFIG_FILS
3021#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003022 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3023 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003024 (!data->assoc_info.resp_frame ||
3025 fils_process_assoc_resp(wpa_s->wpa,
3026 data->assoc_info.resp_frame,
3027 data->assoc_info.resp_frame_len) < 0)) {
3028 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3029 return -1;
3030 }
3031#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003032
3033 /* Additional processing for FILS when SME is in driver */
3034 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3035 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3036 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003037#endif /* CONFIG_FILS */
3038
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003039#ifdef CONFIG_OWE
3040 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003041 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003042 owe_process_assoc_resp(wpa_s->wpa, bssid,
3043 data->assoc_info.resp_ies,
3044 data->assoc_info.resp_ies_len) < 0)) {
3045 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3046 return -1;
3047 }
3048#endif /* CONFIG_OWE */
3049
Hai Shalom021b0b52019-04-10 11:17:58 -07003050#ifdef CONFIG_DPP2
3051 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003052 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3053 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003054 struct ieee802_11_elems elems;
3055
3056 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3057 data->assoc_info.resp_ies_len,
3058 &elems, 0) == ParseFailed ||
3059 !elems.owe_dh)
3060 goto no_pfs;
3061 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3062 elems.owe_dh_len) < 0) {
3063 wpa_supplicant_deauthenticate(wpa_s,
3064 WLAN_REASON_UNSPECIFIED);
3065 return -1;
3066 }
3067
3068 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3069 }
3070no_pfs:
3071#endif /* CONFIG_DPP2 */
3072
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073#ifdef CONFIG_IEEE80211R
3074#ifdef CONFIG_SME
3075 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003076 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003077 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3078 data->assoc_info.resp_ies,
3079 data->assoc_info.resp_ies_len,
3080 bssid) < 0) {
3081 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3082 "Reassociation Response failed");
3083 wpa_supplicant_deauthenticate(
3084 wpa_s, WLAN_REASON_INVALID_IE);
3085 return -1;
3086 }
3087 }
3088
3089 p = data->assoc_info.resp_ies;
3090 l = data->assoc_info.resp_ies_len;
3091
3092#ifdef CONFIG_WPS_STRICT
3093 if (p && wpa_s->current_ssid &&
3094 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3095 struct wpabuf *wps;
3096 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3097 if (wps == NULL) {
3098 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3099 "include WPS IE in (Re)Association Response");
3100 return -1;
3101 }
3102
3103 if (wps_validate_assoc_resp(wps) < 0) {
3104 wpabuf_free(wps);
3105 wpa_supplicant_deauthenticate(
3106 wpa_s, WLAN_REASON_INVALID_IE);
3107 return -1;
3108 }
3109 wpabuf_free(wps);
3110 }
3111#endif /* CONFIG_WPS_STRICT */
3112
3113 /* Go through the IEs and make a copy of the MDIE, if present. */
3114 while (p && l >= 2) {
3115 len = p[1] + 2;
3116 if (len > l) {
3117 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3118 p, l);
3119 break;
3120 }
3121 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3122 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3123 wpa_s->sme.ft_used = 1;
3124 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3125 MOBILITY_DOMAIN_ID_LEN);
3126 break;
3127 }
3128 l -= len;
3129 p += len;
3130 }
3131#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003132#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303133 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3134 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3135 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3136 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303137 wpa_ft_is_completed(wpa_s->wpa)) {
3138 return 0;
3139 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003140#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003141
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003142 /* Process FT when SME is in the driver */
3143 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3144 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003145 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003146 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3147 data->assoc_info.resp_ies,
3148 data->assoc_info.resp_ies_len,
3149 bssid) < 0) {
3150 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3151 "Reassociation Response failed");
3152 wpa_supplicant_deauthenticate(
3153 wpa_s, WLAN_REASON_INVALID_IE);
3154 return -1;
3155 }
3156 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3157 }
3158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003159 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3160 data->assoc_info.resp_ies_len);
3161#endif /* CONFIG_IEEE80211R */
3162
Hai Shalom899fcc72020-10-19 14:38:18 -07003163 if (bssid_known)
3164 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3165 data->assoc_info.resp_ies,
3166 data->assoc_info.resp_ies_len);
3167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003168 /* WPA/RSN IE from Beacon/ProbeResp */
3169 p = data->assoc_info.beacon_ies;
3170 l = data->assoc_info.beacon_ies_len;
3171
3172 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3173 */
3174 wpa_found = rsn_found = 0;
3175 while (p && l >= 2) {
3176 len = p[1] + 2;
3177 if (len > l) {
3178 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3179 p, l);
3180 break;
3181 }
3182 if (!wpa_found &&
3183 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3184 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3185 wpa_found = 1;
3186 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3187 }
3188
3189 if (!rsn_found &&
3190 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3191 rsn_found = 1;
3192 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3193 }
3194
Hai Shalomc3565922019-10-28 11:58:20 -07003195 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3196 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003198 l -= len;
3199 p += len;
3200 }
3201
3202 if (!wpa_found && data->assoc_info.beacon_ies)
3203 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003204 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003205 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003206 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3207 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003208 if (wpa_found || rsn_found)
3209 wpa_s->ap_ies_from_associnfo = 1;
3210
Jouni Malinen87fd2792011-05-16 18:35:42 +03003211 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3212 wpa_s->assoc_freq != data->assoc_info.freq) {
3213 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3214 "%u to %u MHz",
3215 wpa_s->assoc_freq, data->assoc_info.freq);
3216 wpa_supplicant_update_scan_results(wpa_s);
3217 }
3218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003219 wpa_s->assoc_freq = data->assoc_info.freq;
3220
Hai Shalomc1a21442022-02-04 13:43:00 -08003221 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3222 data->assoc_info.resp_ies_len);
3223
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003224 return 0;
3225}
3226
3227
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003228static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3229{
Hai Shalomc3565922019-10-28 11:58:20 -07003230 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003231
3232 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3233 return -1;
3234
3235 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3236 return 0;
3237
3238 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3239 WPA_IE_VENDOR_TYPE);
3240 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003241 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003242
3243 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3244 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3245 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003246 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3247 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3248 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003249 return -1;
3250
3251 return 0;
3252}
3253
3254
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003255static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3256 union wpa_event_data *data)
3257{
3258#ifdef CONFIG_FST
3259 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3260 struct wpa_bss *bss = wpa_s->current_bss;
3261 const u8 *ieprb, *iebcn;
3262
3263 wpabuf_free(wpa_s->received_mb_ies);
3264 wpa_s->received_mb_ies = NULL;
3265
3266 if (ai &&
3267 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3268 wpa_printf(MSG_DEBUG,
3269 "FST: MB IEs updated from Association Response frame");
3270 return;
3271 }
3272
3273 if (ai &&
3274 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3275 wpa_printf(MSG_DEBUG,
3276 "FST: MB IEs updated from association event Beacon IEs");
3277 return;
3278 }
3279
3280 if (!bss)
3281 return;
3282
Hai Shalom60840252021-02-19 19:02:11 -08003283 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003284 iebcn = ieprb + bss->ie_len;
3285
3286 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3287 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3288 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3289 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3290#endif /* CONFIG_FST */
3291}
3292
3293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003294static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3295 union wpa_event_data *data)
3296{
3297 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003298 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003299 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003300#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3301 struct wpa_bss *bss;
3302#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003303#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303304 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003305#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003306
3307#ifdef CONFIG_AP
3308 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003309 if (!data)
3310 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003311 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3312 data->assoc_info.addr,
3313 data->assoc_info.req_ies,
3314 data->assoc_info.req_ies_len,
3315 data->assoc_info.reassoc);
3316 return;
3317 }
3318#endif /* CONFIG_AP */
3319
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003320 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003321 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003322
Andy Kuoaba17c12022-04-14 16:05:31 +08003323#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303324 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3325 struct wpa_ft_ies parse;
3326 /* Check for FT reassociation is done by the driver */
3327#ifdef CONFIG_IEEE80211R
3328 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303329 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303330 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3331 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3332 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3333 return;
3334 }
3335 if (parse.rsn_pmkid != NULL) {
3336 wpa_set_ft_completed(wpa_s->wpa);
3337 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3338 }
3339 }
3340#endif /* CONFIG_IEEE80211R */
3341 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003342#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303343
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003344 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
3345 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3346 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003347 /*
3348 * FILS authentication can share the same mechanism to mark the
3349 * connection fully authenticated, so set ft_completed also based on
3350 * FILS result.
3351 */
3352 if (!ft_completed)
3353 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003354
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003355 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3356 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003357 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003358 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3359 return;
3360 }
3361
Andy Kuoaba17c12022-04-14 16:05:31 +08003362#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303363 /* For driver based roaming, insert PSK during the initial association */
3364 if (is_zero_ether_addr(wpa_s->bssid) &&
3365 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3366 /* In case the driver wants to handle re-assocs, pass it down the PMK. */
3367 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3368 wpa_sm_install_pmk(wpa_s->wpa);
3369 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003370#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003372 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003373 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003374 if (os_reltime_initialized(&wpa_s->session_start)) {
3375 os_reltime_age(&wpa_s->session_start,
3376 &wpa_s->session_length);
3377 wpa_s->session_start.sec = 0;
3378 wpa_s->session_start.usec = 0;
3379 wpas_notify_session_length(wpa_s);
3380 } else {
3381 wpas_notify_auth_changed(wpa_s);
3382 os_get_reltime(&wpa_s->session_start);
3383 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003384 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3385 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003386 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003387 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003388 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3389 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003390 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003391
3392 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3393 wpa_clear_keys(wpa_s, bssid);
3394 }
3395 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003396 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003397 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3398 return;
3399 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003400 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003401
Hai Shalomc1a21442022-02-04 13:43:00 -08003402 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3403 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3404 return;
3405
Hai Shalomfdcde762020-04-02 11:19:20 -07003406 multi_ap_set_4addr_mode(wpa_s);
3407
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003408 if (wpa_s->conf->ap_scan == 1 &&
3409 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003410 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3411 wpa_msg(wpa_s, MSG_WARNING,
3412 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003413 }
3414
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003415 wpas_fst_update_mb_assoc(wpa_s, data);
3416
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003417#ifdef CONFIG_SME
3418 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3419 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003420 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003421#endif /* CONFIG_SME */
3422
3423 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3424 if (wpa_s->current_ssid) {
3425 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3426 * initialized before association, but for other modes,
3427 * initialize PC/SC here, if the current configuration needs
3428 * smartcard or SIM/USIM. */
3429 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3430 }
3431 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3432 if (wpa_s->l2)
3433 l2_packet_notify_auth_start(wpa_s->l2);
3434
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003435 already_authorized = data && data->assoc_info.authorized;
3436
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003437 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003438 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003439 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3440 * state machine may transit to AUTHENTICATING state based on obsolete
3441 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3442 * AUTHENTICATED without ever giving chance to EAP state machine to
3443 * reset the state.
3444 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003445 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003446 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3447 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003448 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003449 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3450 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3451 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003452 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003453 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003454 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003455 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003456 wpa_s->eapol_received = 0;
3457 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3458 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3459 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003460 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003461 if (wpa_s->current_ssid &&
3462 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003463 (wpa_s->drv_flags &
3464 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3465 /*
3466 * Set the key after having received joined-IBSS event
3467 * from the driver.
3468 */
3469 wpa_supplicant_set_wpa_none_key(wpa_s,
3470 wpa_s->current_ssid);
3471 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003472 wpa_supplicant_cancel_auth_timeout(wpa_s);
3473 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3474 } else if (!ft_completed) {
3475 /* Timeout for receiving the first EAPOL packet */
3476 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3477 }
3478 wpa_supplicant_cancel_scan(wpa_s);
3479
Hai Shalom5f92bc92019-04-18 11:54:11 -07003480 if (ft_completed) {
3481 /*
3482 * FT protocol completed - make sure EAPOL state machine ends
3483 * up in authenticated.
3484 */
3485 wpa_supplicant_cancel_auth_timeout(wpa_s);
3486 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003487 eapol_sm_notify_portValid(wpa_s->eapol, true);
3488 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003489 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3490 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003491 /*
3492 * We are done; the driver will take care of RSN 4-way
3493 * handshake.
3494 */
3495 wpa_supplicant_cancel_auth_timeout(wpa_s);
3496 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003497 eapol_sm_notify_portValid(wpa_s->eapol, true);
3498 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003499 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003500 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3501 /*
3502 * The driver will take care of RSN 4-way handshake, so we need
3503 * to allow EAPOL supplicant to complete its work without
3504 * waiting for WPA supplicant.
3505 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003506 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003507 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003508#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303509 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3510 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3511 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3512 wpa_s->key_mgmt);
3513 wpa_supplicant_deauthenticate(
3514 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3515 return;
3516 }
3517 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3518 wpa_s->assoc_freq = data->assoc_info.freq;
3519 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3520 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003521#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3522
Jouni Malinena05074c2012-12-21 21:35:35 +02003523 wpa_s->last_eapol_matches_bssid = 0;
3524
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003525#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003526 if (wpa_s->rsne_override_eapol) {
3527 wpa_printf(MSG_DEBUG,
3528 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3529 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3530 wpabuf_head(wpa_s->rsne_override_eapol),
3531 wpabuf_len(wpa_s->rsne_override_eapol));
3532 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003533 if (wpa_s->rsnxe_override_eapol) {
3534 wpa_printf(MSG_DEBUG,
3535 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3536 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3537 wpabuf_head(wpa_s->rsnxe_override_eapol),
3538 wpabuf_len(wpa_s->rsnxe_override_eapol));
3539 }
3540#endif /* CONFIG_TESTING_OPTIONS */
3541
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003542 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003543 struct os_reltime now, age;
3544 os_get_reltime(&now);
3545 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003546 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003547 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3548 0) {
3549 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3550 "frame that was received just before "
3551 "association notification");
3552 wpa_supplicant_rx_eapol(
3553 wpa_s, wpa_s->pending_eapol_rx_src,
3554 wpabuf_head(wpa_s->pending_eapol_rx),
3555 wpabuf_len(wpa_s->pending_eapol_rx));
3556 }
3557 wpabuf_free(wpa_s->pending_eapol_rx);
3558 wpa_s->pending_eapol_rx = NULL;
3559 }
3560
Hai Shalomfdcde762020-04-02 11:19:20 -07003561#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003562 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3563 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003564 wpa_s->current_ssid &&
3565 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003566 /* Set static WEP keys again */
3567 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3568 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003569#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003570
3571#ifdef CONFIG_IBSS_RSN
3572 if (wpa_s->current_ssid &&
3573 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3574 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3575 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3576 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003577 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003578 if (!wpa_s->ibss_rsn) {
3579 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3580 wpa_supplicant_deauthenticate(
3581 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3582 return;
3583 }
3584
3585 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3586 }
3587#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003588
3589 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003590
3591 if (data) {
3592 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3593 data->assoc_info.resp_ies_len,
3594 &data->assoc_info.wmm_params);
3595
3596 if (wpa_s->reassoc_same_bss)
3597 wmm_ac_restore_tspecs(wpa_s);
3598 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003599
Hai Shalomc3565922019-10-28 11:58:20 -07003600#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3601 bss = wpa_bss_get_bssid(wpa_s, bssid);
3602#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003603#ifdef CONFIG_FILS
3604 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003605 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3606
3607 if (fils_cache_id)
3608 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3609 }
3610#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003611
3612#ifdef CONFIG_MBO
3613 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3614#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003615
3616#ifdef CONFIG_DPP2
3617 wpa_s->dpp_pfs_fallback = 0;
3618#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003619}
3620
3621
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003622static int disconnect_reason_recoverable(u16 reason_code)
3623{
3624 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3625 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3626 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3627}
3628
3629
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003630static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003631 u16 reason_code,
3632 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003633{
3634 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003635
3636 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3637 /*
3638 * At least Host AP driver and a Prism3 card seemed to be
3639 * generating streams of disconnected events when configuring
3640 * IBSS for WPA-None. Ignore them for now.
3641 */
3642 return;
3643 }
3644
3645 bssid = wpa_s->bssid;
3646 if (is_zero_ether_addr(bssid))
3647 bssid = wpa_s->pending_bssid;
3648
3649 if (!is_zero_ether_addr(bssid) ||
3650 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3651 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3652 " reason=%d%s",
3653 MAC2STR(bssid), reason_code,
3654 locally_generated ? " locally_generated=1" : "");
3655 }
3656}
3657
3658
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003659static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3660 int locally_generated)
3661{
3662 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003663 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003664 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3665 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003666 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003667
3668 /*
3669 * It looks like connection was lost while trying to go through PSK
3670 * 4-way handshake. Filter out known disconnection cases that are caused
3671 * by something else than PSK mismatch to avoid confusing reports.
3672 */
3673
3674 if (locally_generated) {
3675 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3676 return 0;
3677 }
3678
3679 return 1;
3680}
3681
3682
Jouni Malinen2b89da82012-08-31 22:04:41 +03003683static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3684 u16 reason_code,
3685 int locally_generated)
3686{
3687 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003688 int authenticating;
3689 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003690 struct wpa_bss *fast_reconnect = NULL;
3691 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003692 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003693 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003694
3695 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3696 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3697
3698 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3699 /*
3700 * At least Host AP driver and a Prism3 card seemed to be
3701 * generating streams of disconnected events when configuring
3702 * IBSS for WPA-None. Ignore them for now.
3703 */
3704 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3705 "IBSS/WPA-None mode");
3706 return;
3707 }
3708
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003709 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3710 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3711 locally_generated)
3712 /*
3713 * Remove the inactive AP (which is probably out of range) from
3714 * the BSS list after marking disassociation. In particular
3715 * mac80211-based drivers use the
3716 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3717 * locally generated disconnection events for cases where the
3718 * AP does not reply anymore.
3719 */
3720 curr = wpa_s->current_bss;
3721
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003722 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003723 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3724 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003725 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3726 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003727 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003728#ifdef CONFIG_DPP2
3729 wpas_dpp_send_conn_status_result(wpa_s,
3730 DPP_STATUS_AUTH_FAILURE);
3731#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003732 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003733 if (!wpa_s->disconnected &&
3734 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003735 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003736 wpas_wps_searching(wpa_s) ||
3737 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003738 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003739 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003740 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003741 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003742 wpa_s->wpa_state);
3743 if (wpa_s->wpa_state == WPA_COMPLETED &&
3744 wpa_s->current_ssid &&
3745 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003746 (wpa_s->own_reconnect_req ||
3747 (!locally_generated &&
3748 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003749 /*
3750 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003751 * us, but could allow us to get back in. This is also
3752 * triggered for cases where local reconnection request
3753 * is used to force reassociation with the same BSS.
3754 * Try to reconnect to the same BSS without a full scan
3755 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003756 */
3757 fast_reconnect = wpa_s->current_bss;
3758 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003759 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003760 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003761 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003762 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3763 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003764 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003765 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003766 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003767 "try to re-connect");
3768 wpa_s->reassociate = 0;
3769 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003770 if (!wpa_s->pno)
3771 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003772 }
3773 bssid = wpa_s->bssid;
3774 if (is_zero_ether_addr(bssid))
3775 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003776 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3777 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003778 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08003779 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
3780
Dmitry Shmidt04949592012-07-19 12:16:46 -07003781 if (locally_generated)
3782 wpa_s->disconnect_reason = -reason_code;
3783 else
3784 wpa_s->disconnect_reason = reason_code;
3785 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003786 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3787 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003788 wpa_clear_keys(wpa_s, wpa_s->bssid);
3789 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003790 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003791 wpa_supplicant_mark_disassoc(wpa_s);
3792
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003793 if (curr)
3794 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3795
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003796 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003797 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003798 wpa_s->current_ssid = last_ssid;
3799 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003800
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003801 if (fast_reconnect &&
3802 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3803 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3804 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3805 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003806 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003807 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003808#ifndef CONFIG_NO_SCAN_PROCESSING
3809 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3810 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3811 fast_reconnect_ssid) < 0) {
3812 /* Recover through full scan */
3813 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3814 }
3815#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003816 } else if (fast_reconnect) {
3817 /*
3818 * Could not reconnect to the same BSS due to network being
3819 * disabled. Use a new scan to match the alternative behavior
3820 * above, i.e., to continue automatic reconnection attempt in a
3821 * way that enforces disabled network rules.
3822 */
3823 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003824 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003825}
3826
3827
3828#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003829void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003830{
3831 struct wpa_supplicant *wpa_s = eloop_ctx;
3832
3833 if (!wpa_s->pending_mic_error_report)
3834 return;
3835
3836 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3837 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3838 wpa_s->pending_mic_error_report = 0;
3839}
3840#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3841
3842
3843static void
3844wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3845 union wpa_event_data *data)
3846{
3847 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003848 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003849
3850 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3851 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003852 os_get_reltime(&t);
3853 if ((wpa_s->last_michael_mic_error.sec &&
3854 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003855 wpa_s->pending_mic_error_report) {
3856 if (wpa_s->pending_mic_error_report) {
3857 /*
3858 * Send the pending MIC error report immediately since
3859 * we are going to start countermeasures and AP better
3860 * do the same.
3861 */
3862 wpa_sm_key_request(wpa_s->wpa, 1,
3863 wpa_s->pending_mic_error_pairwise);
3864 }
3865
3866 /* Send the new MIC error report immediately since we are going
3867 * to start countermeasures and AP better do the same.
3868 */
3869 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3870
3871 /* initialize countermeasures */
3872 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003873
Hai Shalom60840252021-02-19 19:02:11 -08003874 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003875
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003876 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3877
3878 /*
3879 * Need to wait for completion of request frame. We do not get
3880 * any callback for the message completion, so just wait a
3881 * short while and hope for the best. */
3882 os_sleep(0, 10000);
3883
3884 wpa_drv_set_countermeasures(wpa_s, 1);
3885 wpa_supplicant_deauthenticate(wpa_s,
3886 WLAN_REASON_MICHAEL_MIC_FAILURE);
3887 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3888 wpa_s, NULL);
3889 eloop_register_timeout(60, 0,
3890 wpa_supplicant_stop_countermeasures,
3891 wpa_s, NULL);
3892 /* TODO: mark the AP rejected for 60 second. STA is
3893 * allowed to associate with another AP.. */
3894 } else {
3895#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3896 if (wpa_s->mic_errors_seen) {
3897 /*
3898 * Reduce the effectiveness of Michael MIC error
3899 * reports as a means for attacking against TKIP if
3900 * more than one MIC failure is noticed with the same
3901 * PTK. We delay the transmission of the reports by a
3902 * random time between 0 and 60 seconds in order to
3903 * force the attacker wait 60 seconds before getting
3904 * the information on whether a frame resulted in a MIC
3905 * failure.
3906 */
3907 u8 rval[4];
3908 int sec;
3909
3910 if (os_get_random(rval, sizeof(rval)) < 0)
3911 sec = os_random() % 60;
3912 else
3913 sec = WPA_GET_BE32(rval) % 60;
3914 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3915 "report %d seconds", sec);
3916 wpa_s->pending_mic_error_report = 1;
3917 wpa_s->pending_mic_error_pairwise = pairwise;
3918 eloop_cancel_timeout(
3919 wpa_supplicant_delayed_mic_error_report,
3920 wpa_s, NULL);
3921 eloop_register_timeout(
3922 sec, os_random() % 1000000,
3923 wpa_supplicant_delayed_mic_error_report,
3924 wpa_s, NULL);
3925 } else {
3926 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3927 }
3928#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3929 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3930#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3931 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003932 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003933 wpa_s->mic_errors_seen++;
3934}
3935
3936
3937#ifdef CONFIG_TERMINATE_ONLASTIF
3938static int any_interfaces(struct wpa_supplicant *head)
3939{
3940 struct wpa_supplicant *wpa_s;
3941
3942 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3943 if (!wpa_s->interface_removed)
3944 return 1;
3945 return 0;
3946}
3947#endif /* CONFIG_TERMINATE_ONLASTIF */
3948
3949
3950static void
3951wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3952 union wpa_event_data *data)
3953{
3954 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3955 return;
3956
3957 switch (data->interface_status.ievent) {
3958 case EVENT_INTERFACE_ADDED:
3959 if (!wpa_s->interface_removed)
3960 break;
3961 wpa_s->interface_removed = 0;
3962 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3963 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3964 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3965 "driver after interface was added");
3966 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003967
3968#ifdef CONFIG_P2P
3969 if (!wpa_s->global->p2p &&
3970 !wpa_s->global->p2p_disabled &&
3971 !wpa_s->conf->p2p_disabled &&
3972 (wpa_s->drv_flags &
3973 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3974 wpas_p2p_add_p2pdev_interface(
3975 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3976 wpa_printf(MSG_INFO,
3977 "P2P: Failed to enable P2P Device interface");
3978 /* Try to continue without. P2P will be disabled. */
3979 }
3980#endif /* CONFIG_P2P */
3981
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003982 break;
3983 case EVENT_INTERFACE_REMOVED:
3984 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3985 wpa_s->interface_removed = 1;
3986 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003987 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003988 l2_packet_deinit(wpa_s->l2);
3989 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003990
3991#ifdef CONFIG_P2P
3992 if (wpa_s->global->p2p &&
3993 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3994 (wpa_s->drv_flags &
3995 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3996 wpa_dbg(wpa_s, MSG_DEBUG,
3997 "Removing P2P Device interface");
3998 wpa_supplicant_remove_iface(
3999 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4000 0);
4001 wpa_s->global->p2p_init_wpa_s = NULL;
4002 }
4003#endif /* CONFIG_P2P */
4004
Dmitry Shmidte4663042016-04-04 10:07:49 -07004005#ifdef CONFIG_MATCH_IFACE
4006 if (wpa_s->matched) {
4007 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4008 break;
4009 }
4010#endif /* CONFIG_MATCH_IFACE */
4011
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004012#ifdef CONFIG_TERMINATE_ONLASTIF
4013 /* check if last interface */
4014 if (!any_interfaces(wpa_s->global->ifaces))
4015 eloop_terminate();
4016#endif /* CONFIG_TERMINATE_ONLASTIF */
4017 break;
4018 }
4019}
4020
4021
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004022#ifdef CONFIG_TDLS
4023static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4024 union wpa_event_data *data)
4025{
4026 if (data == NULL)
4027 return;
4028 switch (data->tdls.oper) {
4029 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004030 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4031 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4032 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4033 else
4034 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004035 break;
4036 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004037 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4038 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4039 data->tdls.reason_code);
4040 else
4041 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4042 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004043 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004044 case TDLS_REQUEST_DISCOVER:
4045 wpa_tdls_send_discovery_request(wpa_s->wpa,
4046 data->tdls.peer);
4047 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004048 }
4049}
4050#endif /* CONFIG_TDLS */
4051
4052
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004053#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004054static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4055 union wpa_event_data *data)
4056{
4057 if (data == NULL)
4058 return;
4059 switch (data->wnm.oper) {
4060 case WNM_OPER_SLEEP:
4061 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4062 "(action=%d, intval=%d)",
4063 data->wnm.sleep_action, data->wnm.sleep_intval);
4064 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004065 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004066 break;
4067 }
4068}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004069#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004070
4071
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004072#ifdef CONFIG_IEEE80211R
4073static void
4074wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4075 union wpa_event_data *data)
4076{
4077 if (data == NULL)
4078 return;
4079
4080 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4081 data->ft_ies.ies_len,
4082 data->ft_ies.ft_action,
4083 data->ft_ies.target_ap,
4084 data->ft_ies.ric_ies,
4085 data->ft_ies.ric_ies_len) < 0) {
4086 /* TODO: prevent MLME/driver from trying to associate? */
4087 }
4088}
4089#endif /* CONFIG_IEEE80211R */
4090
4091
4092#ifdef CONFIG_IBSS_RSN
4093static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4094 union wpa_event_data *data)
4095{
4096 struct wpa_ssid *ssid;
4097 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4098 return;
4099 if (data == NULL)
4100 return;
4101 ssid = wpa_s->current_ssid;
4102 if (ssid == NULL)
4103 return;
4104 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4105 return;
4106
4107 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4108}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004109
4110
4111static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4112 union wpa_event_data *data)
4113{
4114 struct wpa_ssid *ssid = wpa_s->current_ssid;
4115
4116 if (ssid == NULL)
4117 return;
4118
4119 /* check if the ssid is correctly configured as IBSS/RSN */
4120 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4121 return;
4122
4123 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4124 data->rx_mgmt.frame_len);
4125}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004126#endif /* CONFIG_IBSS_RSN */
4127
4128
4129#ifdef CONFIG_IEEE80211R
4130static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4131 size_t len)
4132{
4133 const u8 *sta_addr, *target_ap_addr;
4134 u16 status;
4135
4136 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4137 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4138 return; /* only SME case supported for now */
4139 if (len < 1 + 2 * ETH_ALEN + 2)
4140 return;
4141 if (data[0] != 2)
4142 return; /* Only FT Action Response is supported for now */
4143 sta_addr = data + 1;
4144 target_ap_addr = data + 1 + ETH_ALEN;
4145 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4146 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4147 MACSTR " TargetAP " MACSTR " status %u",
4148 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4149
4150 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4151 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4152 " in FT Action Response", MAC2STR(sta_addr));
4153 return;
4154 }
4155
4156 if (status) {
4157 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4158 "failure (status code %d)", status);
4159 /* TODO: report error to FT code(?) */
4160 return;
4161 }
4162
4163 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4164 len - (1 + 2 * ETH_ALEN + 2), 1,
4165 target_ap_addr, NULL, 0) < 0)
4166 return;
4167
4168#ifdef CONFIG_SME
4169 {
4170 struct wpa_bss *bss;
4171 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4172 if (bss)
4173 wpa_s->sme.freq = bss->freq;
4174 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4175 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4176 WLAN_AUTH_FT);
4177 }
4178#endif /* CONFIG_SME */
4179}
4180#endif /* CONFIG_IEEE80211R */
4181
4182
4183static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4184 struct unprot_deauth *e)
4185{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004186 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4187 "dropped: " MACSTR " -> " MACSTR
4188 " (reason code %u)",
4189 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4190 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004191}
4192
4193
4194static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4195 struct unprot_disassoc *e)
4196{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004197 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4198 "dropped: " MACSTR " -> " MACSTR
4199 " (reason code %u)",
4200 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4201 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004202}
4203
4204
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004205static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4206 u16 reason_code, int locally_generated,
4207 const u8 *ie, size_t ie_len, int deauth)
4208{
4209#ifdef CONFIG_AP
4210 if (wpa_s->ap_iface && addr) {
4211 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4212 return;
4213 }
4214
4215 if (wpa_s->ap_iface) {
4216 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4217 return;
4218 }
4219#endif /* CONFIG_AP */
4220
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004221 if (!locally_generated)
4222 wpa_s->own_disconnect_req = 0;
4223
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004224 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4225
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004226 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4227 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4228 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4229 eapol_sm_failed(wpa_s->eapol))) &&
4230 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004231 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004232
4233#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004234 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004235 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4236 locally_generated) > 0) {
4237 /*
4238 * The interface was removed, so cannot continue
4239 * processing any additional operations after this.
4240 */
4241 return;
4242 }
4243 }
4244#endif /* CONFIG_P2P */
4245
4246 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4247 locally_generated);
4248}
4249
4250
4251static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4252 struct disassoc_info *info)
4253{
4254 u16 reason_code = 0;
4255 int locally_generated = 0;
4256 const u8 *addr = NULL;
4257 const u8 *ie = NULL;
4258 size_t ie_len = 0;
4259
4260 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4261
4262 if (info) {
4263 addr = info->addr;
4264 ie = info->ie;
4265 ie_len = info->ie_len;
4266 reason_code = info->reason_code;
4267 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004268 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4269 reason2str(reason_code),
4270 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004271 if (addr)
4272 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4273 MAC2STR(addr));
4274 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4275 ie, ie_len);
4276 }
4277
4278#ifdef CONFIG_AP
4279 if (wpa_s->ap_iface && info && info->addr) {
4280 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4281 return;
4282 }
4283
4284 if (wpa_s->ap_iface) {
4285 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4286 return;
4287 }
4288#endif /* CONFIG_AP */
4289
4290#ifdef CONFIG_P2P
4291 if (info) {
4292 wpas_p2p_disassoc_notif(
4293 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4294 locally_generated);
4295 }
4296#endif /* CONFIG_P2P */
4297
4298 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4299 sme_event_disassoc(wpa_s, info);
4300
4301 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4302 ie, ie_len, 0);
4303}
4304
4305
4306static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4307 struct deauth_info *info)
4308{
4309 u16 reason_code = 0;
4310 int locally_generated = 0;
4311 const u8 *addr = NULL;
4312 const u8 *ie = NULL;
4313 size_t ie_len = 0;
4314
4315 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4316
4317 if (info) {
4318 addr = info->addr;
4319 ie = info->ie;
4320 ie_len = info->ie_len;
4321 reason_code = info->reason_code;
4322 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004323 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4324 reason_code, reason2str(reason_code),
4325 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004326 if (addr) {
4327 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4328 MAC2STR(addr));
4329 }
4330 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4331 ie, ie_len);
4332 }
4333
4334 wpa_reset_ft_completed(wpa_s->wpa);
4335
4336 wpas_event_disconnect(wpa_s, addr, reason_code,
4337 locally_generated, ie, ie_len, 1);
4338}
4339
4340
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004341static const char * reg_init_str(enum reg_change_initiator init)
4342{
4343 switch (init) {
4344 case REGDOM_SET_BY_CORE:
4345 return "CORE";
4346 case REGDOM_SET_BY_USER:
4347 return "USER";
4348 case REGDOM_SET_BY_DRIVER:
4349 return "DRIVER";
4350 case REGDOM_SET_BY_COUNTRY_IE:
4351 return "COUNTRY_IE";
4352 case REGDOM_BEACON_HINT:
4353 return "BEACON_HINT";
4354 }
4355 return "?";
4356}
4357
4358
4359static const char * reg_type_str(enum reg_type type)
4360{
4361 switch (type) {
4362 case REGDOM_TYPE_UNKNOWN:
4363 return "UNKNOWN";
4364 case REGDOM_TYPE_COUNTRY:
4365 return "COUNTRY";
4366 case REGDOM_TYPE_WORLD:
4367 return "WORLD";
4368 case REGDOM_TYPE_CUSTOM_WORLD:
4369 return "CUSTOM_WORLD";
4370 case REGDOM_TYPE_INTERSECTION:
4371 return "INTERSECTION";
4372 }
4373 return "?";
4374}
4375
4376
Hai Shalom74f70d42019-02-11 14:42:39 -08004377void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4378 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004379{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004380 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004381 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004382
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004383 /*
4384 * To allow backwards compatibility with higher level layers that
4385 * assumed the REGDOM_CHANGE event is sent over the initially added
4386 * interface. Find the highest parent of this interface and use it to
4387 * send the event.
4388 */
4389 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4390 ;
4391
Hai Shalom74f70d42019-02-11 14:42:39 -08004392 if (info) {
4393 wpa_msg(ifs, MSG_INFO,
4394 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4395 reg_init_str(info->initiator), reg_type_str(info->type),
4396 info->alpha2[0] ? " alpha2=" : "",
4397 info->alpha2[0] ? info->alpha2 : "");
4398 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004399
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004400 if (wpa_s->drv_priv == NULL)
4401 return; /* Ignore event during drv initialization */
4402
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004403 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4404 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004405 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4406 ifs->ifname);
4407 free_hw_features(ifs);
4408 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004409 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004410
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004411 /* Restart PNO/sched_scan with updated channel list */
4412 if (ifs->pno) {
4413 wpas_stop_pno(ifs);
4414 wpas_start_pno(ifs);
4415 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4416 wpa_dbg(ifs, MSG_DEBUG,
4417 "Channel list changed - restart sched_scan");
4418 wpas_scan_restart_sched_scan(ifs);
4419 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004420 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004421
4422 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004423}
4424
4425
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004426static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004427 const u8 *frame, size_t len, int freq,
4428 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004429{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004430 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004431 const u8 *payload;
4432 size_t plen;
4433 u8 category;
4434
4435 if (len < IEEE80211_HDRLEN + 2)
4436 return;
4437
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004438 mgmt = (const struct ieee80211_mgmt *) frame;
4439 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004440 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004441 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004442
4443 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4444 " Category=%u DataLen=%d freq=%d MHz",
4445 MAC2STR(mgmt->sa), category, (int) plen, freq);
4446
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004447 if (category == WLAN_ACTION_WMM) {
4448 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4449 return;
4450 }
4451
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004452#ifdef CONFIG_IEEE80211R
4453 if (category == WLAN_ACTION_FT) {
4454 ft_rx_action(wpa_s, payload, plen);
4455 return;
4456 }
4457#endif /* CONFIG_IEEE80211R */
4458
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004459#ifdef CONFIG_SME
4460 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004461 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004462 return;
4463 }
4464#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004465
4466#ifdef CONFIG_WNM
4467 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4468 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4469 return;
4470 }
4471#endif /* CONFIG_WNM */
4472
4473#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004474 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4475 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004476 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004477 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004478 payload, plen, freq) == 0)
4479 return;
4480#endif /* CONFIG_GAS */
4481
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004482#ifdef CONFIG_GAS_SERVER
4483 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4484 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4485 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4486 mgmt->u.action.category,
4487 payload, plen, freq) == 0)
4488 return;
4489#endif /* CONFIG_GAS_SERVER */
4490
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004491#ifdef CONFIG_TDLS
4492 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4493 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4494 wpa_dbg(wpa_s, MSG_DEBUG,
4495 "TDLS: Received Discovery Response from " MACSTR,
4496 MAC2STR(mgmt->sa));
4497 return;
4498 }
4499#endif /* CONFIG_TDLS */
4500
4501#ifdef CONFIG_INTERWORKING
4502 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4503 payload[0] == QOS_QOS_MAP_CONFIG) {
4504 const u8 *pos = payload + 1;
4505 size_t qlen = plen - 1;
4506 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4507 MACSTR, MAC2STR(mgmt->sa));
4508 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4509 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4510 pos[1] <= qlen - 2 && pos[1] >= 16)
4511 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4512 return;
4513 }
4514#endif /* CONFIG_INTERWORKING */
4515
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004516 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004517 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4518 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004519 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004520 payload + 1,
4521 plen - 1);
4522 return;
4523 }
4524
4525 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004526 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4527 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4528 return;
4529 }
4530
4531 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4532 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4533 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4534 payload + 1, plen - 1,
4535 rssi);
4536 return;
4537 }
4538
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004539#ifdef CONFIG_FST
4540 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4541 fst_rx_action(wpa_s->fst, mgmt, len);
4542 return;
4543 }
4544#endif /* CONFIG_FST */
4545
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004546#ifdef CONFIG_DPP
4547 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4548 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4549 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4550 payload[4] == DPP_OUI_TYPE) {
4551 payload++;
4552 plen--;
4553 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4554 return;
4555 }
4556#endif /* CONFIG_DPP */
4557
Hai Shalom899fcc72020-10-19 14:38:18 -07004558 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004559 payload[0] == ROBUST_AV_SCS_RESP) {
4560 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4561 payload + 1, plen - 1);
4562 return;
4563 }
4564
4565 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004566 payload[0] == ROBUST_AV_MSCS_RESP) {
4567 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4568 payload + 1, plen - 1);
4569 return;
4570 }
4571
Hai Shalomc1a21442022-02-04 13:43:00 -08004572 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4573 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4574 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4575 payload + 4, plen - 4);
4576 return;
4577 }
4578
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004579 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4580 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004581 if (wpa_s->ifmsh)
4582 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004583}
4584
4585
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004586static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4587 union wpa_event_data *event)
4588{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004589 struct wpa_freq_range_list *list;
4590 char *str = NULL;
4591
4592 list = &event->freq_range;
4593
4594 if (list->num)
4595 str = freq_range_list_str(list);
4596 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4597 str ? str : "");
4598
4599#ifdef CONFIG_P2P
4600 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4601 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4602 __func__);
4603 } else {
4604 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004605
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004606 /*
4607 * The update channel flow will also take care of moving a GO
4608 * from the unsafe frequency if needed.
4609 */
4610 wpas_p2p_update_channel_list(wpa_s,
4611 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004612 }
4613#endif /* CONFIG_P2P */
4614
4615 os_free(str);
4616}
4617
4618
Roshan Pius3a1667e2018-07-03 15:17:14 -07004619static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004620{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004621 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4622 wpa_supplicant_cancel_auth_timeout(wpa_s);
4623 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004624 eapol_sm_notify_portValid(wpa_s->eapol, true);
4625 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004626 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004627 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004628}
4629
4630
4631static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4632 int freq)
4633{
4634 size_t i;
4635 int j;
4636
4637 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4638 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4639
4640 for (j = 0; j < mode->num_channels; j++) {
4641 const struct hostapd_channel_data *chan;
4642
4643 chan = &mode->channels[j];
4644 if (chan->freq == freq)
4645 return chan->dfs_cac_ms;
4646 }
4647 }
4648
4649 return 0;
4650}
4651
4652
4653static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4654 struct dfs_event *radar)
4655{
4656#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004657 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004658 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4659 } else
4660#endif /* NEED_AP_MLME && CONFIG_AP */
4661 {
4662 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4663
4664 cac_time /= 1000; /* convert from ms to sec */
4665 if (!cac_time)
4666 cac_time = 10 * 60; /* max timeout: 10 minutes */
4667
4668 /* Restart auth timeout: CAC time added to initial timeout */
4669 wpas_auth_timeout_restart(wpa_s, cac_time);
4670 }
4671}
4672
4673
4674static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4675 struct dfs_event *radar)
4676{
4677#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004678 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004679 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4680 } else
4681#endif /* NEED_AP_MLME && CONFIG_AP */
4682 {
4683 /* Restart auth timeout with original value after CAC is
4684 * finished */
4685 wpas_auth_timeout_restart(wpa_s, 0);
4686 }
4687}
4688
4689
4690static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4691 struct dfs_event *radar)
4692{
4693#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004694 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004695 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4696 } else
4697#endif /* NEED_AP_MLME && CONFIG_AP */
4698 {
4699 /* Restart auth timeout with original value after CAC is
4700 * aborted */
4701 wpas_auth_timeout_restart(wpa_s, 0);
4702 }
4703}
4704
4705
4706static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4707 union wpa_event_data *data)
4708{
4709 wpa_dbg(wpa_s, MSG_DEBUG,
4710 "Connection authorized by device, previous state %d",
4711 wpa_s->wpa_state);
4712
4713 wpa_supplicant_event_port_authorized(wpa_s);
4714
Hai Shalomc1a21442022-02-04 13:43:00 -08004715 wpa_s->last_eapol_matches_bssid = 1;
4716
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004717 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4718 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004719 data->assoc_info.ptk_kck_len,
4720 data->assoc_info.ptk_kek,
4721 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004722#ifdef CONFIG_FILS
4723 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4724 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4725 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4726
4727 /* Update ERP next sequence number */
4728 eapol_sm_update_erp_next_seq_num(
4729 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4730
4731 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4732 /* Add the new PMK and PMKID to the PMKSA cache */
4733 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4734 data->assoc_info.fils_pmk,
4735 data->assoc_info.fils_pmk_len,
4736 data->assoc_info.fils_pmkid,
4737 wpa_s->bssid, fils_cache_id);
4738 } else if (data->assoc_info.fils_pmkid) {
4739 /* Update the current PMKSA used for this connection */
4740 pmksa_cache_set_current(wpa_s->wpa,
4741 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004742 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004743 }
4744 }
4745#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004746}
4747
4748
Hai Shalom60840252021-02-19 19:02:11 -08004749static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4750{
4751 switch (code) {
4752 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
4753 return "";
4754 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
4755 return "no_bss_found";
4756 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
4757 return "auth_tx_fail";
4758 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
4759 return "auth_no_ack_received";
4760 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
4761 return "auth_no_resp_received";
4762 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
4763 return "assoc_req_tx_fail";
4764 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
4765 return "assoc_no_ack_received";
4766 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
4767 return "assoc_no_resp_received";
4768 default:
4769 return "unknown_reason";
4770 }
4771}
4772
4773
Roshan Pius3a1667e2018-07-03 15:17:14 -07004774static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4775 union wpa_event_data *data)
4776{
4777 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004778#ifdef CONFIG_MBO
4779 struct wpa_bss *reject_bss;
4780#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004781
4782 if (!bssid || is_zero_ether_addr(bssid))
4783 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004784#ifdef CONFIG_MBO
4785 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4786 reject_bss = wpa_s->current_bss;
4787 else
4788 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4789#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004790
4791 if (data->assoc_reject.bssid)
4792 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004793 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004794 MAC2STR(data->assoc_reject.bssid),
4795 data->assoc_reject.status_code,
4796 data->assoc_reject.timed_out ? " timeout" : "",
4797 data->assoc_reject.timeout_reason ? "=" : "",
4798 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004799 data->assoc_reject.timeout_reason : "",
4800 data->assoc_reject.reason_code !=
4801 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4802 " qca_driver_reason=" : "",
4803 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004804 else
4805 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004806 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004807 data->assoc_reject.status_code,
4808 data->assoc_reject.timed_out ? " timeout" : "",
4809 data->assoc_reject.timeout_reason ? "=" : "",
4810 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004811 data->assoc_reject.timeout_reason : "",
4812 data->assoc_reject.reason_code !=
4813 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4814 " qca_driver_reason=" : "",
4815 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004816 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08004817 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
4818 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004819
4820#ifdef CONFIG_OWE
4821 if (data->assoc_reject.status_code ==
4822 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4823 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4824 wpa_s->current_ssid &&
4825 wpa_s->current_ssid->owe_group == 0 &&
4826 wpa_s->last_owe_group != 21) {
4827 struct wpa_ssid *ssid = wpa_s->current_ssid;
4828 struct wpa_bss *bss = wpa_s->current_bss;
4829
4830 if (!bss) {
4831 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4832 if (!bss) {
4833 wpas_connection_failed(wpa_s, bssid);
4834 wpa_supplicant_mark_disassoc(wpa_s);
4835 return;
4836 }
4837 }
4838 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4839 wpas_connect_work_done(wpa_s);
4840 wpa_supplicant_mark_disassoc(wpa_s);
4841 wpa_supplicant_connect(wpa_s, bss, ssid);
4842 return;
4843 }
4844#endif /* CONFIG_OWE */
4845
Hai Shalomfdcde762020-04-02 11:19:20 -07004846#ifdef CONFIG_DPP2
4847 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4848 * the status code defined in the DPP R2 tech spec.
4849 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4850 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004851 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004852 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4853 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4854 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004855 wpa_s->current_ssid->dpp_pfs == 0 &&
4856 (data->assoc_reject.status_code ==
4857 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4858 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4859 struct wpa_ssid *ssid = wpa_s->current_ssid;
4860 struct wpa_bss *bss = wpa_s->current_bss;
4861
4862 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4863 if (!bss)
4864 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4865 if (!bss || wpa_s->dpp_pfs_fallback) {
4866 wpa_printf(MSG_DEBUG,
4867 "DPP: Updated PFS policy for next try");
4868 wpas_connection_failed(wpa_s, bssid);
4869 wpa_supplicant_mark_disassoc(wpa_s);
4870 return;
4871 }
4872 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4873 wpa_s->dpp_pfs_fallback = 1;
4874 wpas_connect_work_done(wpa_s);
4875 wpa_supplicant_mark_disassoc(wpa_s);
4876 wpa_supplicant_connect(wpa_s, bss, ssid);
4877 return;
4878 }
4879#endif /* CONFIG_DPP2 */
4880
Hai Shalom74f70d42019-02-11 14:42:39 -08004881#ifdef CONFIG_MBO
4882 if (data->assoc_reject.status_code ==
4883 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004884 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004885 const u8 *rssi_rej;
4886
4887 rssi_rej = mbo_get_attr_from_ies(
4888 data->assoc_reject.resp_ies,
4889 data->assoc_reject.resp_ies_len,
4890 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4891 if (rssi_rej && rssi_rej[1] == 2) {
4892 wpa_printf(MSG_DEBUG,
4893 "OCE: RSSI-based association rejection from "
4894 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004895 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004896 rssi_rej[2], rssi_rej[3]);
4897 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004898 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004899 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004900 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004901 }
4902 }
4903#endif /* CONFIG_MBO */
4904
Roshan Pius3a1667e2018-07-03 15:17:14 -07004905 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4906 sme_event_assoc_reject(wpa_s, data);
4907 return;
4908 }
4909
4910 /* Driver-based SME cases */
4911
4912#ifdef CONFIG_SAE
4913 if (wpa_s->current_ssid &&
4914 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4915 !data->assoc_reject.timed_out) {
4916 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4917 wpa_sm_aborted_cached(wpa_s->wpa);
4918 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4919 }
4920#endif /* CONFIG_SAE */
4921
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004922#ifdef CONFIG_DPP
4923 if (wpa_s->current_ssid &&
4924 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4925 !data->assoc_reject.timed_out) {
4926 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4927 wpa_sm_aborted_cached(wpa_s->wpa);
4928 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4929 }
4930#endif /* CONFIG_DPP */
4931
Roshan Pius3a1667e2018-07-03 15:17:14 -07004932#ifdef CONFIG_FILS
4933 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004934 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004935 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004936 eapol_sm_update_erp_next_seq_num(
4937 wpa_s->eapol,
4938 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004939 fils_connection_failure(wpa_s);
4940 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004941#endif /* CONFIG_FILS */
4942
4943 wpas_connection_failed(wpa_s, bssid);
4944 wpa_supplicant_mark_disassoc(wpa_s);
4945}
4946
4947
Hai Shalomfdcde762020-04-02 11:19:20 -07004948static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
4949 struct unprot_beacon *data)
4950{
4951 struct wpabuf *buf;
4952 int res;
4953
4954 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
4955 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
4956 return;
4957 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
4958 MAC2STR(data->sa));
4959
4960 buf = wpabuf_alloc(4);
4961 if (!buf)
4962 return;
4963
4964 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
4965 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
4966 wpabuf_put_u8(buf, 1); /* Dialog Token */
4967 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
4968
4969 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
4970 wpa_s->own_addr, wpa_s->bssid,
4971 wpabuf_head(buf), wpabuf_len(buf), 0);
4972 if (res < 0)
4973 wpa_printf(MSG_DEBUG,
4974 "Failed to send WNM-Notification Request frame");
4975
4976 wpabuf_free(buf);
4977}
4978
4979
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004980void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4981 union wpa_event_data *data)
4982{
4983 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004984 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07004985 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08004986#ifndef CONFIG_NO_STDOUT_DEBUG
4987 int level = MSG_DEBUG;
4988#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004989
4990 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4991 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004992 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004993 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004994 event != EVENT_SCHED_SCAN_STOPPED) {
4995 wpa_dbg(wpa_s, MSG_DEBUG,
4996 "Ignore event %s (%d) while interface is disabled",
4997 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004998 return;
4999 }
5000
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005001#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005002 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005003 const struct ieee80211_hdr *hdr;
5004 u16 fc;
5005 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5006 fc = le_to_host16(hdr->frame_control);
5007 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5008 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5009 level = MSG_EXCESSIVE;
5010 }
5011
5012 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5013 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005014#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005015
5016 switch (event) {
5017 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005018#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005019 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5020 data->auth.ies_len))
5021 wpa_printf(MSG_DEBUG,
5022 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005023#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005024 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005025 wpa_s->auth_status_code = data->auth.status_code;
5026 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005027 break;
5028 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005029#ifdef CONFIG_TESTING_OPTIONS
5030 if (wpa_s->ignore_auth_resp) {
5031 wpa_printf(MSG_INFO,
5032 "EVENT_ASSOC - ignore_auth_resp active!");
5033 break;
5034 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005035 if (wpa_s->testing_resend_assoc) {
5036 wpa_printf(MSG_INFO,
5037 "EVENT_DEAUTH - testing_resend_assoc");
5038 break;
5039 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005040#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305041 if (wpa_s->disconnected) {
5042 wpa_printf(MSG_INFO,
5043 "Ignore unexpected EVENT_ASSOC in disconnected state");
5044 break;
5045 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005046 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005047 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005048 if (data &&
5049 (data->assoc_info.authorized ||
5050 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5051 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005052 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005053 if (data) {
5054 wpa_msg(wpa_s, MSG_INFO,
5055 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5056 data->assoc_info.subnet_status);
5057 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005058 break;
5059 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005060 wpas_event_disassoc(wpa_s,
5061 data ? &data->disassoc_info : NULL);
5062 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005063 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005064#ifdef CONFIG_TESTING_OPTIONS
5065 if (wpa_s->ignore_auth_resp) {
5066 wpa_printf(MSG_INFO,
5067 "EVENT_DEAUTH - ignore_auth_resp active!");
5068 break;
5069 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005070 if (wpa_s->testing_resend_assoc) {
5071 wpa_printf(MSG_INFO,
5072 "EVENT_DEAUTH - testing_resend_assoc");
5073 break;
5074 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005075#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005076 wpas_event_deauth(wpa_s,
5077 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005078 break;
5079 case EVENT_MICHAEL_MIC_FAILURE:
5080 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5081 break;
5082#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005083 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005084 if (wpa_s->own_scan_requested ||
5085 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005086 struct os_reltime diff;
5087
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005088 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005089 os_reltime_sub(&wpa_s->scan_start_time,
5090 &wpa_s->scan_trigger_time, &diff);
5091 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5092 diff.sec, diff.usec);
5093 wpa_s->own_scan_requested = 0;
5094 wpa_s->own_scan_running = 1;
5095 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5096 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005097 wpa_msg_ctrl(wpa_s, MSG_INFO,
5098 WPA_EVENT_SCAN_STARTED "id=%u",
5099 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005100 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005101 wpa_msg_ctrl(wpa_s, MSG_INFO,
5102 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005103 }
5104 } else {
5105 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005106 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005107 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005108 }
5109 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005110 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005111 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5112 wpa_s->scan_res_handler = NULL;
5113 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005114 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005115 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5116 break;
5117 }
5118
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005119 if (!(data && data->scan_info.external_scan) &&
5120 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005121 struct os_reltime now, diff;
5122 os_get_reltime(&now);
5123 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5124 wpa_s->scan_start_time.sec = 0;
5125 wpa_s->scan_start_time.usec = 0;
5126 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5127 diff.sec, diff.usec);
5128 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005129 if (wpa_supplicant_event_scan_results(wpa_s, data))
5130 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005131 if (!(data && data->scan_info.external_scan))
5132 wpa_s->own_scan_running = 0;
5133 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005134 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005135 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005136 break;
5137#endif /* CONFIG_NO_SCAN_PROCESSING */
5138 case EVENT_ASSOCINFO:
5139 wpa_supplicant_event_associnfo(wpa_s, data);
5140 break;
5141 case EVENT_INTERFACE_STATUS:
5142 wpa_supplicant_event_interface_status(wpa_s, data);
5143 break;
5144 case EVENT_PMKID_CANDIDATE:
5145 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5146 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005147#ifdef CONFIG_TDLS
5148 case EVENT_TDLS:
5149 wpa_supplicant_event_tdls(wpa_s, data);
5150 break;
5151#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005152#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005153 case EVENT_WNM:
5154 wpa_supplicant_event_wnm(wpa_s, data);
5155 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005156#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005157#ifdef CONFIG_IEEE80211R
5158 case EVENT_FT_RESPONSE:
5159 wpa_supplicant_event_ft_response(wpa_s, data);
5160 break;
5161#endif /* CONFIG_IEEE80211R */
5162#ifdef CONFIG_IBSS_RSN
5163 case EVENT_IBSS_RSN_START:
5164 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5165 break;
5166#endif /* CONFIG_IBSS_RSN */
5167 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005168 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005169 break;
5170 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005171 /* It is possible to get this event from earlier connection */
5172 if (wpa_s->current_ssid &&
5173 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5174 wpa_dbg(wpa_s, MSG_DEBUG,
5175 "Ignore AUTH_TIMED_OUT in mesh configuration");
5176 break;
5177 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005178 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5179 sme_event_auth_timed_out(wpa_s, data);
5180 break;
5181 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005182 /* It is possible to get this event from earlier connection */
5183 if (wpa_s->current_ssid &&
5184 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5185 wpa_dbg(wpa_s, MSG_DEBUG,
5186 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5187 break;
5188 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005189 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5190 sme_event_assoc_timed_out(wpa_s, data);
5191 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005192 case EVENT_TX_STATUS:
5193 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5194 " type=%d stype=%d",
5195 MAC2STR(data->tx_status.dst),
5196 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005197#ifdef CONFIG_PASN
5198 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5199 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5200 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5201 data->tx_status.data_len,
5202 data->tx_status.ack) == 0)
5203 break;
5204#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005205#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005206 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005207#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005208 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5209 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005210 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005211 wpa_s, data->tx_status.dst,
5212 data->tx_status.data,
5213 data->tx_status.data_len,
5214 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005215 OFFCHANNEL_SEND_ACTION_SUCCESS :
5216 OFFCHANNEL_SEND_ACTION_NO_ACK);
5217#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005218 break;
5219 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005220#endif /* CONFIG_AP */
5221#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005222 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005223 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005224 /*
5225 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005226 * interface in GO mode, or via standalone AP interface.
5227 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5228 * except when the primary interface is used as a GO interface
5229 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005230 */
5231 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5232 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005233 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005234 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005235 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005236 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005237 data->tx_status.data,
5238 data->tx_status.data_len,
5239 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005240 OFFCHANNEL_SEND_ACTION_SUCCESS :
5241 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005242 break;
5243 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005244#endif /* CONFIG_OFFCHANNEL */
5245#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005246 switch (data->tx_status.type) {
5247 case WLAN_FC_TYPE_MGMT:
5248 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5249 data->tx_status.data_len,
5250 data->tx_status.stype,
5251 data->tx_status.ack);
5252 break;
5253 case WLAN_FC_TYPE_DATA:
5254 ap_tx_status(wpa_s, data->tx_status.dst,
5255 data->tx_status.data,
5256 data->tx_status.data_len,
5257 data->tx_status.ack);
5258 break;
5259 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005260#endif /* CONFIG_AP */
5261 break;
5262#ifdef CONFIG_AP
5263 case EVENT_EAPOL_TX_STATUS:
5264 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5265 data->eapol_tx_status.data,
5266 data->eapol_tx_status.data_len,
5267 data->eapol_tx_status.ack);
5268 break;
5269 case EVENT_DRIVER_CLIENT_POLL_OK:
5270 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005271 break;
5272 case EVENT_RX_FROM_UNKNOWN:
5273 if (wpa_s->ap_iface == NULL)
5274 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005275 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5276 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005277 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005278#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005279
5280 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005281 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005282 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005283 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005284
Hai Shalom81f62d82019-07-22 12:10:00 -07005285 wpa_msg(wpa_s, MSG_INFO,
5286 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5287 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5288 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005289 data->ch_switch.freq,
5290 data->ch_switch.ht_enabled,
5291 data->ch_switch.ch_offset,
5292 channel_width_to_string(data->ch_switch.ch_width),
5293 data->ch_switch.cf1,
5294 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005295 if (event == EVENT_CH_SWITCH_STARTED)
5296 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005297
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005298 wpa_s->assoc_freq = data->ch_switch.freq;
5299 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005300 if (wpa_s->current_bss &&
5301 wpa_s->current_bss->freq != data->ch_switch.freq) {
5302 wpa_s->current_bss->freq = data->ch_switch.freq;
5303 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5304 wpa_s->current_bss);
5305 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005306
Hai Shalomfdcde762020-04-02 11:19:20 -07005307#ifdef CONFIG_SME
5308 switch (data->ch_switch.ch_offset) {
5309 case 1:
5310 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5311 break;
5312 case -1:
5313 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5314 break;
5315 default:
5316 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5317 break;
5318 }
5319#endif /* CONFIG_SME */
5320
Roshan Pius3a1667e2018-07-03 15:17:14 -07005321#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005322 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5323 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005324 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005325 wpa_s->current_ssid->mode ==
5326 WPAS_MODE_P2P_GROUP_FORMATION) {
5327 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5328 data->ch_switch.ht_enabled,
5329 data->ch_switch.ch_offset,
5330 data->ch_switch.ch_width,
5331 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005332 data->ch_switch.cf2,
5333 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005334 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005335#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005336
Hai Shalom899fcc72020-10-19 14:38:18 -07005337 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5338 sme_event_ch_switch(wpa_s);
5339
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005340 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005341 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005342 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005343#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005344#ifdef NEED_AP_MLME
5345 case EVENT_DFS_RADAR_DETECTED:
5346 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005347 wpas_ap_event_dfs_radar_detected(wpa_s,
5348 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005349 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005350 case EVENT_DFS_NOP_FINISHED:
5351 if (data)
5352 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5353 &data->dfs_event);
5354 break;
5355#endif /* NEED_AP_MLME */
5356#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005357 case EVENT_DFS_CAC_STARTED:
5358 if (data)
5359 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5360 break;
5361 case EVENT_DFS_CAC_FINISHED:
5362 if (data)
5363 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5364 break;
5365 case EVENT_DFS_CAC_ABORTED:
5366 if (data)
5367 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5368 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005369 case EVENT_RX_MGMT: {
5370 u16 fc, stype;
5371 const struct ieee80211_mgmt *mgmt;
5372
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005373#ifdef CONFIG_TESTING_OPTIONS
5374 if (wpa_s->ext_mgmt_frame_handling) {
5375 struct rx_mgmt *rx = &data->rx_mgmt;
5376 size_t hex_len = 2 * rx->frame_len + 1;
5377 char *hex = os_malloc(hex_len);
5378 if (hex) {
5379 wpa_snprintf_hex(hex, hex_len,
5380 rx->frame, rx->frame_len);
5381 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5382 rx->freq, rx->datarate, rx->ssi_signal,
5383 hex);
5384 os_free(hex);
5385 }
5386 break;
5387 }
5388#endif /* CONFIG_TESTING_OPTIONS */
5389
Dmitry Shmidt04949592012-07-19 12:16:46 -07005390 mgmt = (const struct ieee80211_mgmt *)
5391 data->rx_mgmt.frame;
5392 fc = le_to_host16(mgmt->frame_control);
5393 stype = WLAN_FC_GET_STYPE(fc);
5394
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005395#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005396 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005397#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005398#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005399 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005400 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005401 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005402 const u8 *ie;
5403 size_t ie_len;
5404
5405 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5406 ie_len = data->rx_mgmt.frame_len -
5407 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005408 wpas_p2p_probe_req_rx(
5409 wpa_s, src, mgmt->da,
5410 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005411 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005412 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005413 break;
5414 }
5415#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005416#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005417 if (wpa_s->current_ssid &&
5418 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5419 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005420 data->rx_mgmt.frame_len >= 30) {
5421 wpa_supplicant_event_ibss_auth(wpa_s, data);
5422 break;
5423 }
5424#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005425
5426 if (stype == WLAN_FC_STYPE_ACTION) {
5427 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005428 wpa_s, data->rx_mgmt.frame,
5429 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005430 data->rx_mgmt.freq,
5431 data->rx_mgmt.ssi_signal);
5432 break;
5433 }
5434
5435 if (wpa_s->ifmsh) {
5436 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005437 break;
5438 }
Hai Shalom60840252021-02-19 19:02:11 -08005439#ifdef CONFIG_PASN
5440 if (stype == WLAN_FC_STYPE_AUTH &&
5441 wpas_pasn_auth_rx(wpa_s, mgmt,
5442 data->rx_mgmt.frame_len) != -2)
5443 break;
5444#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005445
Roshan Pius3a1667e2018-07-03 15:17:14 -07005446#ifdef CONFIG_SAE
5447 if (stype == WLAN_FC_STYPE_AUTH &&
5448 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5449 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5450 sme_external_auth_mgmt_rx(
5451 wpa_s, data->rx_mgmt.frame,
5452 data->rx_mgmt.frame_len);
5453 break;
5454 }
5455#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005456 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5457 "management frame in non-AP mode");
5458 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005459#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005460 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005461
5462 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005463 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5464 const u8 *ie;
5465 size_t ie_len;
5466
5467 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5468 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005469
5470 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5471 mgmt->bssid, ie, ie_len,
5472 data->rx_mgmt.ssi_signal);
5473 }
5474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005475 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005476#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005477 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005478 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005479 case EVENT_RX_PROBE_REQ:
5480 if (data->rx_probe_req.sa == NULL ||
5481 data->rx_probe_req.ie == NULL)
5482 break;
5483#ifdef CONFIG_AP
5484 if (wpa_s->ap_iface) {
5485 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5486 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005487 data->rx_probe_req.da,
5488 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005489 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005490 data->rx_probe_req.ie_len,
5491 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005492 break;
5493 }
5494#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005495 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005496 data->rx_probe_req.da,
5497 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005498 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005499 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005500 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005501 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005502 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005503 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005504#ifdef CONFIG_OFFCHANNEL
5505 offchannel_remain_on_channel_cb(
5506 wpa_s, data->remain_on_channel.freq,
5507 data->remain_on_channel.duration);
5508#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005509 wpas_p2p_remain_on_channel_cb(
5510 wpa_s, data->remain_on_channel.freq,
5511 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005512#ifdef CONFIG_DPP
5513 wpas_dpp_remain_on_channel_cb(
5514 wpa_s, data->remain_on_channel.freq,
5515 data->remain_on_channel.duration);
5516#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005517 break;
5518 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005519#ifdef CONFIG_OFFCHANNEL
5520 offchannel_cancel_remain_on_channel_cb(
5521 wpa_s, data->remain_on_channel.freq);
5522#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005523 wpas_p2p_cancel_remain_on_channel_cb(
5524 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005525#ifdef CONFIG_DPP
5526 wpas_dpp_cancel_remain_on_channel_cb(
5527 wpa_s, data->remain_on_channel.freq);
5528#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005529 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005530 case EVENT_EAPOL_RX:
5531 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5532 data->eapol_rx.data,
5533 data->eapol_rx.data_len);
5534 break;
5535 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005536 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5537 "above=%d signal=%d noise=%d txrate=%d",
5538 data->signal_change.above_threshold,
5539 data->signal_change.current_signal,
5540 data->signal_change.current_noise,
5541 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005542 wpa_bss_update_level(wpa_s->current_bss,
5543 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005544 bgscan_notify_signal_change(
5545 wpa_s, data->signal_change.above_threshold,
5546 data->signal_change.current_signal,
5547 data->signal_change.current_noise,
5548 data->signal_change.current_txrate);
5549 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005550 case EVENT_INTERFACE_MAC_CHANGED:
5551 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005552 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005553 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005554 case EVENT_INTERFACE_ENABLED:
5555 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5556 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005557 u8 addr[ETH_ALEN];
5558
Hai Shalomfdcde762020-04-02 11:19:20 -07005559 eloop_cancel_timeout(wpas_clear_disabled_interface,
5560 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005561 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005562 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005563 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5564 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5565 else
5566 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005567 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005568 if (wpa_s->p2p_mgmt) {
5569 wpa_supplicant_set_state(wpa_s,
5570 WPA_DISCONNECTED);
5571 break;
5572 }
5573
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005574#ifdef CONFIG_AP
5575 if (!wpa_s->ap_iface) {
5576 wpa_supplicant_set_state(wpa_s,
5577 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005578 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005579 wpa_supplicant_req_scan(wpa_s, 0, 0);
5580 } else
5581 wpa_supplicant_set_state(wpa_s,
5582 WPA_COMPLETED);
5583#else /* CONFIG_AP */
5584 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5585 wpa_supplicant_req_scan(wpa_s, 0, 0);
5586#endif /* CONFIG_AP */
5587 }
5588 break;
5589 case EVENT_INTERFACE_DISABLED:
5590 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005591#ifdef CONFIG_P2P
5592 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5593 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5594 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5595 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005596 * Mark interface disabled if this happens to end up not
5597 * being removed as a separate P2P group interface.
5598 */
5599 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5600 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005601 * The interface was externally disabled. Remove
5602 * it assuming an external entity will start a
5603 * new session if needed.
5604 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005605 if (wpa_s->current_ssid &&
5606 wpa_s->current_ssid->p2p_group)
5607 wpas_p2p_interface_unavailable(wpa_s);
5608 else
5609 wpas_p2p_disconnect(wpa_s);
5610 /*
5611 * wpa_s instance may have been freed, so must not use
5612 * it here anymore.
5613 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005614 break;
5615 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005616 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5617 p2p_in_progress(wpa_s->global->p2p) > 1) {
5618 /* This radio work will be cancelled, so clear P2P
5619 * state as well.
5620 */
5621 p2p_stop_find(wpa_s->global->p2p);
5622 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005623#endif /* CONFIG_P2P */
5624
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005625 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5626 /*
5627 * Indicate disconnection to keep ctrl_iface events
5628 * consistent.
5629 */
5630 wpa_supplicant_event_disassoc(
5631 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5632 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005633 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005634 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005635 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5636 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005637 clear_at.usec = 0;
5638 } else {
5639 struct os_reltime tmp;
5640
Hai Shalom60840252021-02-19 19:02:11 -08005641 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005642 tmp.usec = 0;
5643 os_reltime_sub(&tmp, &age, &clear_at);
5644 }
5645 eloop_register_timeout(clear_at.sec, clear_at.usec,
5646 wpas_clear_disabled_interface,
5647 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005648 radio_remove_works(wpa_s, NULL, 0);
5649
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005650 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5651 break;
5652 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005653 wpa_supplicant_update_channel_list(
5654 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005655 break;
5656 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005657 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005658 break;
5659 case EVENT_BEST_CHANNEL:
5660 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5661 "(%d %d %d)",
5662 data->best_chan.freq_24, data->best_chan.freq_5,
5663 data->best_chan.freq_overall);
5664 wpa_s->best_24_freq = data->best_chan.freq_24;
5665 wpa_s->best_5_freq = data->best_chan.freq_5;
5666 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005667 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5668 data->best_chan.freq_5,
5669 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005670 break;
5671 case EVENT_UNPROT_DEAUTH:
5672 wpa_supplicant_event_unprot_deauth(wpa_s,
5673 &data->unprot_deauth);
5674 break;
5675 case EVENT_UNPROT_DISASSOC:
5676 wpa_supplicant_event_unprot_disassoc(wpa_s,
5677 &data->unprot_disassoc);
5678 break;
5679 case EVENT_STATION_LOW_ACK:
5680#ifdef CONFIG_AP
5681 if (wpa_s->ap_iface && data)
5682 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5683 data->low_ack.addr);
5684#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005685#ifdef CONFIG_TDLS
5686 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005687 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5688 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005689#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005690 break;
5691 case EVENT_IBSS_PEER_LOST:
5692#ifdef CONFIG_IBSS_RSN
5693 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5694#endif /* CONFIG_IBSS_RSN */
5695 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005696 case EVENT_DRIVER_GTK_REKEY:
5697 if (os_memcmp(data->driver_gtk_rekey.bssid,
5698 wpa_s->bssid, ETH_ALEN))
5699 break;
5700 if (!wpa_s->wpa)
5701 break;
5702 wpa_sm_update_replay_ctr(wpa_s->wpa,
5703 data->driver_gtk_rekey.replay_ctr);
5704 break;
5705 case EVENT_SCHED_SCAN_STOPPED:
5706 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005707 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005708 wpa_supplicant_notify_scanning(wpa_s, 0);
5709
5710 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5711 break;
5712
5713 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005714 * If the driver stopped scanning without being requested to,
5715 * request a new scan to continue scanning for networks.
5716 */
5717 if (!wpa_s->sched_scan_stop_req &&
5718 wpa_s->wpa_state == WPA_SCANNING) {
5719 wpa_dbg(wpa_s, MSG_DEBUG,
5720 "Restart scanning after unexpected sched_scan stop event");
5721 wpa_supplicant_req_scan(wpa_s, 1, 0);
5722 break;
5723 }
5724
5725 wpa_s->sched_scan_stop_req = 0;
5726
5727 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005728 * Start a new sched scan to continue searching for more SSIDs
5729 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005730 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005731 if (wpa_s->sched_scan_timed_out) {
5732 wpa_supplicant_req_sched_scan(wpa_s);
5733 } else if (wpa_s->pno_sched_pending) {
5734 wpa_s->pno_sched_pending = 0;
5735 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005736 } else if (resched) {
5737 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005738 }
5739
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005740 break;
5741 case EVENT_WPS_BUTTON_PUSHED:
5742#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005743 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005744#endif /* CONFIG_WPS */
5745 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005746 case EVENT_AVOID_FREQUENCIES:
5747 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5748 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005749 case EVENT_CONNECT_FAILED_REASON:
5750#ifdef CONFIG_AP
5751 if (!wpa_s->ap_iface || !data)
5752 break;
5753 hostapd_event_connect_failed_reason(
5754 wpa_s->ap_iface->bss[0],
5755 data->connect_failed_reason.addr,
5756 data->connect_failed_reason.code);
5757#endif /* CONFIG_AP */
5758 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005759 case EVENT_NEW_PEER_CANDIDATE:
5760#ifdef CONFIG_MESH
5761 if (!wpa_s->ifmsh || !data)
5762 break;
5763 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5764 data->mesh_peer.ies,
5765 data->mesh_peer.ie_len);
5766#endif /* CONFIG_MESH */
5767 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005768 case EVENT_SURVEY:
5769#ifdef CONFIG_AP
5770 if (!wpa_s->ap_iface)
5771 break;
5772 hostapd_event_get_survey(wpa_s->ap_iface,
5773 &data->survey_results);
5774#endif /* CONFIG_AP */
5775 break;
5776 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005777#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005778#ifdef CONFIG_ACS
5779 if (!wpa_s->ap_iface)
5780 break;
5781 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5782 &data->acs_selected_channels);
5783#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005784#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005785 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005786 case EVENT_P2P_LO_STOP:
5787#ifdef CONFIG_P2P
5788 wpa_s->p2p_lo_started = 0;
5789 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5790 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5791 data->p2p_lo_stop.reason_code);
5792#endif /* CONFIG_P2P */
5793 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005794 case EVENT_BEACON_LOSS:
5795 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5796 break;
5797 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5798 bgscan_notify_beacon_loss(wpa_s);
5799 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005800 case EVENT_EXTERNAL_AUTH:
5801#ifdef CONFIG_SAE
5802 if (!wpa_s->current_ssid) {
5803 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5804 break;
5805 }
5806 sme_external_auth_trigger(wpa_s, data);
5807#endif /* CONFIG_SAE */
5808 break;
5809 case EVENT_PORT_AUTHORIZED:
5810 wpa_supplicant_event_port_authorized(wpa_s);
5811 break;
5812 case EVENT_STATION_OPMODE_CHANGED:
5813#ifdef CONFIG_AP
5814 if (!wpa_s->ap_iface || !data)
5815 break;
5816
5817 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5818 data->sta_opmode.addr,
5819 data->sta_opmode.smps_mode,
5820 data->sta_opmode.chan_width,
5821 data->sta_opmode.rx_nss);
5822#endif /* CONFIG_AP */
5823 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005824 case EVENT_UNPROT_BEACON:
5825 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5826 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08005827 case EVENT_TX_WAIT_EXPIRE:
5828#ifdef CONFIG_DPP
5829 wpas_dpp_tx_wait_expire(wpa_s);
5830#endif /* CONFIG_DPP */
5831 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005832 default:
5833 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5834 break;
5835 }
5836}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005837
5838
5839void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5840 union wpa_event_data *data)
5841{
5842 struct wpa_supplicant *wpa_s;
5843
5844 if (event != EVENT_INTERFACE_STATUS)
5845 return;
5846
5847 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5848 if (wpa_s && wpa_s->driver->get_ifindex) {
5849 unsigned int ifindex;
5850
5851 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5852 if (ifindex != data->interface_status.ifindex) {
5853 wpa_dbg(wpa_s, MSG_DEBUG,
5854 "interface status ifindex %d mismatch (%d)",
5855 ifindex, data->interface_status.ifindex);
5856 return;
5857 }
5858 }
5859#ifdef CONFIG_MATCH_IFACE
5860 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5861 struct wpa_interface *wpa_i;
5862
5863 wpa_i = wpa_supplicant_match_iface(
5864 ctx, data->interface_status.ifname);
5865 if (!wpa_i)
5866 return;
5867 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5868 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07005869 }
5870#endif /* CONFIG_MATCH_IFACE */
5871
5872 if (wpa_s)
5873 wpa_supplicant_event(wpa_s, event, data);
5874}