blob: 0003d1f572ae43b990b1aaead5e5a5b347c57732 [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) &&
Vinayak Yadawad14709082022-03-17 14:25:11 +05301322#ifdef CONFIG_DRIVER_NL80211_BRCM
1323 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
1324#endif /* CONFIG_DRIVER_NL80211_BRCM */
Hai Shalom899fcc72020-10-19 14:38:18 -07001325 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1326 if (debug_print)
1327 wpa_dbg(wpa_s, MSG_DEBUG,
1328 " skip - SAE H2E required, but not supported by the AP");
1329 return false;
1330 }
1331#endif /* CONFIG_SAE */
1332
1333#ifdef CONFIG_SAE_PK
1334 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1335 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1336 if (debug_print)
1337 wpa_dbg(wpa_s, MSG_DEBUG,
1338 " skip - SAE-PK required, but not supported by the AP");
1339 return false;
1340 }
1341#endif /* CONFIG_SAE_PK */
1342
1343#ifndef CONFIG_IBSS_RSN
1344 if (ssid->mode == WPAS_MODE_IBSS &&
1345 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1346 if (debug_print)
1347 wpa_dbg(wpa_s, MSG_DEBUG,
1348 " skip - IBSS RSN not supported in the build");
1349 return false;
1350 }
1351#endif /* !CONFIG_IBSS_RSN */
1352
1353#ifdef CONFIG_P2P
1354 if (ssid->p2p_group &&
1355 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1356 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1357 if (debug_print)
1358 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1359 return false;
1360 }
1361
1362 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1363 struct wpabuf *p2p_ie;
1364 u8 dev_addr[ETH_ALEN];
1365
1366 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1367 if (!ie) {
1368 if (debug_print)
1369 wpa_dbg(wpa_s, MSG_DEBUG,
1370 " skip - no P2P element");
1371 return false;
1372 }
1373 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1374 if (!p2p_ie) {
1375 if (debug_print)
1376 wpa_dbg(wpa_s, MSG_DEBUG,
1377 " skip - could not fetch P2P element");
1378 return false;
1379 }
1380
1381 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1382 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1383 if (debug_print)
1384 wpa_dbg(wpa_s, MSG_DEBUG,
1385 " skip - no matching GO P2P Device Address in P2P element");
1386 wpabuf_free(p2p_ie);
1387 return false;
1388 }
1389 wpabuf_free(p2p_ie);
1390 }
1391
1392 /*
1393 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1394 * P2P Group Capability Bitmap and we are not in Group Formation with
1395 * that device.
1396 */
1397#endif /* CONFIG_P2P */
1398
1399 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1400 struct os_reltime diff;
1401
1402 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1403 if (debug_print)
1404 wpa_dbg(wpa_s, MSG_DEBUG,
1405 " skip - scan result not recent enough (%u.%06u seconds too old)",
1406 (unsigned int) diff.sec,
1407 (unsigned int) diff.usec);
1408 return false;
1409 }
1410#ifdef CONFIG_MBO
1411#ifdef CONFIG_TESTING_OPTIONS
1412 if (wpa_s->ignore_assoc_disallow)
1413 goto skip_assoc_disallow;
1414#endif /* CONFIG_TESTING_OPTIONS */
1415 assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1416 if (assoc_disallow && assoc_disallow[1] >= 1) {
1417 if (debug_print)
1418 wpa_dbg(wpa_s, MSG_DEBUG,
1419 " skip - MBO association disallowed (reason %u)",
1420 assoc_disallow[2]);
1421 return false;
1422 }
1423
1424 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1425 if (debug_print)
1426 wpa_dbg(wpa_s, MSG_DEBUG,
1427 " skip - AP temporarily disallowed");
1428 return false;
1429 }
1430#ifdef CONFIG_TESTING_OPTIONS
1431skip_assoc_disallow:
1432#endif /* CONFIG_TESTING_OPTIONS */
1433#endif /* CONFIG_MBO */
1434
1435#ifdef CONFIG_DPP
1436 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1437 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1438 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1439 !ssid->dpp_csign)) {
1440 if (debug_print)
1441 wpa_dbg(wpa_s, MSG_DEBUG,
1442 " skip - no PMKSA entry for DPP");
1443 return false;
1444 }
1445#endif /* CONFIG_DPP */
1446
1447#ifdef CONFIG_SAE_PK
1448 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1449 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1450 ((ssid->sae_password &&
1451 sae_pk_valid_password(ssid->sae_password)) ||
1452 (!ssid->sae_password && ssid->passphrase &&
1453 sae_pk_valid_password(ssid->passphrase))) &&
1454 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1455 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1456 match_ssid_len)) {
1457 if (debug_print)
1458 wpa_dbg(wpa_s, MSG_DEBUG,
1459 " skip - another acceptable BSS with SAE-PK in the same ESS");
1460 return false;
1461 }
1462#endif /* CONFIG_SAE_PK */
1463
1464 if (bss->ssid_len == 0) {
1465 if (debug_print)
1466 wpa_dbg(wpa_s, MSG_DEBUG,
1467 " skip - no SSID known for the BSS");
1468 return false;
1469 }
1470
1471 /* Matching configuration found */
1472 return true;
1473}
1474
1475
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001476struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1477 int i, struct wpa_bss *bss,
1478 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001479 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001480{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001481 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482 const u8 *ie;
1483 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001484 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001485 const u8 *match_ssid;
1486 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001487 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001488
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001489 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001490 wpa_ie_len = ie ? ie[1] : 0;
1491
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001492 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001493 rsn_ie_len = ie ? ie[1] : 0;
1494
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001495 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1496 osen = ie != NULL;
1497
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001498 if (debug_print) {
1499 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1500 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1501 i, MAC2STR(bss->bssid),
1502 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1503 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1504 bss->freq,
1505 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1506 " wps" : "",
1507 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1508 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1509 ? " p2p" : "",
1510 osen ? " osen=1" : "");
1511 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001512
Hai Shalom60840252021-02-19 19:02:11 -08001513 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1514 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001515 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001516 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001517 /*
1518 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001519 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001520 * should not be done with multiple enabled networks to
1521 * avoid getting forced to move into a worse ESS on
1522 * single error if there are no other BSSes of the
1523 * current ESS.
1524 */
1525 limit = 0;
1526 }
Hai Shalom60840252021-02-19 19:02:11 -08001527 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001528 if (debug_print) {
1529 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001530 " skip - BSSID ignored (count=%d limit=%d)",
1531 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001532 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001533 return NULL;
1534 }
1535 }
1536
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001537 match_ssid = bss->ssid;
1538 match_ssid_len = bss->ssid_len;
1539 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1540
1541 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001542 if (debug_print)
1543 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001544 return NULL;
1545 }
1546
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001547 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001548 if (debug_print)
1549 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001550 return NULL;
1551 }
1552
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001553 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001554 if (debug_print)
1555 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001556 return NULL;
1557 }
1558
Hai Shalomfdcde762020-04-02 11:19:20 -07001559 if (disabled_freq(wpa_s, bss->freq)) {
1560 if (debug_print)
1561 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1562 return NULL;
1563 }
1564
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001565 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001566 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001567 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001568 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001569 }
1570
1571 /* No matching configuration found */
1572 return NULL;
1573}
1574
1575
1576static struct wpa_bss *
1577wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001578 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001579 struct wpa_ssid **selected_ssid,
1580 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001581{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001582 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001583
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001584 if (wpa_s->current_ssid) {
1585 struct wpa_ssid *ssid;
1586
1587 wpa_dbg(wpa_s, MSG_DEBUG,
1588 "Scan results matching the currently selected network");
1589 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1590 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1591
1592 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1593 only_first_ssid, 0);
1594 if (ssid != wpa_s->current_ssid)
1595 continue;
1596 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1597 " freq=%d level=%d snr=%d est_throughput=%u",
1598 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1599 bss->snr, bss->est_throughput);
1600 }
1601 }
1602
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001603 if (only_first_ssid)
1604 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1605 group->id);
1606 else
1607 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1608 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001609
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001610 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1611 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001612
1613 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001614 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001615 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001616 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001617 if (!*selected_ssid)
1618 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001619 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001620 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001621 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001622 MAC2STR(bss->bssid),
1623 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1624 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001625 }
1626
1627 return NULL;
1628}
1629
1630
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001631struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1632 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001633{
1634 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001635 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001636 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001637 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001638
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001639 if (wpa_s->last_scan_res == NULL ||
1640 wpa_s->last_scan_res_used == 0)
1641 return NULL; /* no scan results from last update */
1642
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001643 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001644 /* check that next_ssid is still valid */
1645 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1646 if (ssid == wpa_s->next_ssid)
1647 break;
1648 }
1649 next_ssid = ssid;
1650 wpa_s->next_ssid = NULL;
1651 }
1652
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001653 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001654 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1655 if (next_ssid && next_ssid->priority ==
1656 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001657 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001658 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001659 if (selected)
1660 break;
1661 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001662 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001663 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001664 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001665 if (selected)
1666 break;
1667 }
1668
Hai Shalom60840252021-02-19 19:02:11 -08001669 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001670 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001671 wpa_dbg(wpa_s, MSG_DEBUG,
1672 "No APs found - clear BSSID ignore list and try again");
1673 wpa_bssid_ignore_clear(wpa_s);
1674 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675 } else if (selected == NULL)
1676 break;
1677 }
1678
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001679 ssid = *selected_ssid;
1680 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1681 !ssid->passphrase && !ssid->ext_psk) {
1682 const char *field_name, *txt = NULL;
1683
1684 wpa_dbg(wpa_s, MSG_DEBUG,
1685 "PSK/passphrase not yet available for the selected network");
1686
1687 wpas_notify_network_request(wpa_s, ssid,
1688 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1689
1690 field_name = wpa_supplicant_ctrl_req_to_string(
1691 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1692 if (field_name == NULL)
1693 return NULL;
1694
1695 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1696
1697 selected = NULL;
1698 }
1699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001700 return selected;
1701}
1702
1703
1704static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1705 int timeout_sec, int timeout_usec)
1706{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001707 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001708 /*
1709 * No networks are enabled; short-circuit request so
1710 * we don't wait timeout seconds before transitioning
1711 * to INACTIVE state.
1712 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001713 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1714 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1716 return;
1717 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001718
1719 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001720 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1721}
1722
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001723
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001724int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001725 struct wpa_bss *selected,
1726 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001727{
1728 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1729 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1730 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001731 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001732#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001733 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1734 wpa_s->p2p_in_provisioning) {
1735 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1736 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001737 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001738 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001739#endif /* CONFIG_P2P */
1740
1741#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001742 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743 wpas_wps_cancel(wpa_s);
1744#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001745 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001746 }
1747
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001748 wpa_msg(wpa_s, MSG_DEBUG,
1749 "Considering connect request: reassociate: %d selected: "
1750 MACSTR " bssid: " MACSTR " pending: " MACSTR
1751 " wpa_state: %s ssid=%p current_ssid=%p",
1752 wpa_s->reassociate, MAC2STR(selected->bssid),
1753 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1754 wpa_supplicant_state_txt(wpa_s->wpa_state),
1755 ssid, wpa_s->current_ssid);
1756
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 /*
1758 * Do not trigger new association unless the BSSID has changed or if
1759 * reassociation is requested. If we are in process of associating with
1760 * the selected BSSID, do not trigger new attempt.
1761 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001762 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1764 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1765 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001766 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1767 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1768 0) ||
1769 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1770 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001771 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1772 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001773 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001774 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001775 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1776 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777 wpa_supplicant_associate(wpa_s, selected, ssid);
1778 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001779 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1780 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001781 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001782
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001783 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001784}
1785
1786
1787static struct wpa_ssid *
1788wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1789{
Hai Shalomfdcde762020-04-02 11:19:20 -07001790 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001791 struct wpa_ssid *ssid;
1792
1793 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1794 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1795 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001796 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001798#ifndef CONFIG_IBSS_RSN
1799 if (ssid->mode == WPAS_MODE_IBSS &&
1800 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1801 WPA_KEY_MGMT_WPA_NONE))) {
1802 wpa_msg(wpa_s, MSG_INFO,
1803 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1804 wpa_ssid_txt(ssid->ssid,
1805 ssid->ssid_len));
1806 continue;
1807 }
1808#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001809 if (ssid->mode == WPAS_MODE_IBSS ||
1810 ssid->mode == WPAS_MODE_AP ||
1811 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001812 return ssid;
1813 }
1814 }
1815 return NULL;
1816}
1817
1818
1819/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1820 * on BSS added and BSS changed events */
1821static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001822 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001824 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001825
1826 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1827 return;
1828
Jouni Malinen87fd2792011-05-16 18:35:42 +03001829 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001831
Jouni Malinen87fd2792011-05-16 18:35:42 +03001832 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001833 if (ssid == NULL)
1834 continue;
1835
Jouni Malinen87fd2792011-05-16 18:35:42 +03001836 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001837 if (rsn == NULL)
1838 continue;
1839
Jouni Malinen87fd2792011-05-16 18:35:42 +03001840 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 }
1842
1843}
1844
1845
Hai Shalomfdcde762020-04-02 11:19:20 -07001846#ifndef CONFIG_NO_ROAMING
1847
1848static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1849{
1850 if (noise == WPA_INVALID_NOISE)
1851 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1852 DEFAULT_NOISE_FLOOR_2GHZ;
1853 return avg_signal - noise;
1854}
1855
1856
1857static unsigned int
1858wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1859 const struct wpa_bss *bss, int snr)
1860{
1861 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001862 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001863 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1864
Hai Shalomc1a21442022-02-04 13:43:00 -08001865 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07001866}
1867
Hai Shalomfdcde762020-04-02 11:19:20 -07001868
Hai Shalom899fcc72020-10-19 14:38:18 -07001869int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1870 struct wpa_bss *current_bss,
1871 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001872{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001873 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001874 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001875 int cur_level;
1876 unsigned int cur_est, sel_est;
1877 struct wpa_signal_info si;
1878 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001879 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001880
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001881 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001882 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001883 " freq=%d level=%d snr=%d est_throughput=%u",
1884 MAC2STR(current_bss->bssid),
1885 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001886 current_bss->snr, current_bss->est_throughput);
1887 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001888 " freq=%d level=%d snr=%d est_throughput=%u",
1889 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001890 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001891
1892 if (wpa_s->current_ssid->bssid_set &&
1893 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1894 0) {
1895 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1896 "has preferred BSSID");
1897 return 1;
1898 }
1899
Hai Shalomfdcde762020-04-02 11:19:20 -07001900 cur_level = current_bss->level;
1901 cur_est = current_bss->est_throughput;
1902 sel_est = selected->est_throughput;
1903
1904 /*
1905 * Try to poll the signal from the driver since this will allow to get
1906 * more accurate values. In some cases, there can be big differences
1907 * between the RSSI of the Probe Response frames of the AP we are
1908 * associated with and the Beacon frames we hear from the same AP after
1909 * association. This can happen, e.g., when there are two antennas that
1910 * hear the AP very differently. If the driver chooses to hear the
1911 * Probe Response frames during the scan on the "bad" antenna because
1912 * it wants to save power, but knows to choose the other antenna after
1913 * association, we will hear our AP with a low RSSI as part of the
1914 * scan even when we can hear it decently on the other antenna. To cope
1915 * with this, ask the driver to teach us how it hears the AP. Also, the
1916 * scan results may be a bit old, since we can very quickly get fresh
1917 * information about our currently associated AP.
1918 */
1919 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1920 (si.avg_beacon_signal || si.avg_signal)) {
1921 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1922 si.avg_signal;
1923 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
1924 si.current_noise);
1925
1926 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
1927 current_bss,
1928 cur_snr);
1929 wpa_dbg(wpa_s, MSG_DEBUG,
1930 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
1931 cur_level, cur_snr, cur_est);
1932 }
1933
1934 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001935 wpa_dbg(wpa_s, MSG_DEBUG,
1936 "Allow reassociation - selected BSS has better estimated throughput");
1937 return 1;
1938 }
1939
Dmitry Shmidte4663042016-04-04 10:07:49 -07001940 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1941
Hai Shalomfdcde762020-04-02 11:19:20 -07001942 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
1943 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001944 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1945 "signal level");
1946 return 0;
1947 }
1948
Hai Shalomfdcde762020-04-02 11:19:20 -07001949 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001950 wpa_dbg(wpa_s, MSG_DEBUG,
1951 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001952 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001953 }
1954
Hai Shalomfdcde762020-04-02 11:19:20 -07001955 if (cur_snr > GREAT_SNR) {
1956 wpa_dbg(wpa_s, MSG_DEBUG,
1957 "Skip roam - Current BSS has good SNR (%u > %u)",
1958 cur_snr, GREAT_SNR);
1959 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001960 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001961
Hai Shalomfdcde762020-04-02 11:19:20 -07001962 if (cur_level < -85) /* ..-86 dBm */
1963 min_diff = 1;
1964 else if (cur_level < -80) /* -85..-81 dBm */
1965 min_diff = 2;
1966 else if (cur_level < -75) /* -80..-76 dBm */
1967 min_diff = 3;
1968 else if (cur_level < -70) /* -75..-71 dBm */
1969 min_diff = 4;
1970 else if (cur_level < 0) /* -70..-1 dBm */
1971 min_diff = 5;
1972 else /* unspecified units (not in dBm) */
1973 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001974
Hai Shalomfdcde762020-04-02 11:19:20 -07001975 if (cur_est > sel_est * 1.5)
1976 min_diff += 10;
1977 else if (cur_est > sel_est * 1.2)
1978 min_diff += 5;
1979 else if (cur_est > sel_est * 1.1)
1980 min_diff += 2;
1981 else if (cur_est > sel_est)
1982 min_diff++;
1983 else if (sel_est > cur_est * 1.5)
1984 min_diff -= 10;
1985 else if (sel_est > cur_est * 1.2)
1986 min_diff -= 5;
1987 else if (sel_est > cur_est * 1.1)
1988 min_diff -= 2;
1989 else if (sel_est > cur_est)
1990 min_diff--;
1991
1992 if (to_5ghz)
1993 min_diff -= 2;
1994 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001995 if (diff < min_diff) {
1996 wpa_dbg(wpa_s, MSG_DEBUG,
1997 "Skip roam - too small difference in signal level (%d < %d)",
1998 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07001999 ret = 0;
2000 } else {
2001 wpa_dbg(wpa_s, MSG_DEBUG,
2002 "Allow reassociation due to difference in signal level (%d >= %d)",
2003 diff, min_diff);
2004 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002005 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002006 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2007 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2008 " sel_freq=%d sel_level=%d sel_est=%d",
2009 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2010 MAC2STR(current_bss->bssid),
2011 current_bss->freq, cur_level, cur_est,
2012 MAC2STR(selected->bssid),
2013 selected->freq, selected->level, sel_est);
2014 return ret;
2015}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002016
Hai Shalom899fcc72020-10-19 14:38:18 -07002017#endif /* CONFIG_NO_ROAMING */
2018
2019
2020static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2021 struct wpa_bss *selected,
2022 struct wpa_ssid *ssid)
2023{
2024 struct wpa_bss *current_bss = NULL;
2025
2026 if (wpa_s->reassociate)
2027 return 1; /* explicit request to reassociate */
2028 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2029 return 1; /* we are not associated; continue */
2030 if (wpa_s->current_ssid == NULL)
2031 return 1; /* unknown current SSID */
2032 if (wpa_s->current_ssid != ssid)
2033 return 1; /* different network block */
2034
2035 if (wpas_driver_bss_selection(wpa_s))
2036 return 0; /* Driver-based roaming */
2037
2038 if (wpa_s->current_ssid->ssid)
2039 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2040 wpa_s->current_ssid->ssid,
2041 wpa_s->current_ssid->ssid_len);
2042 if (!current_bss)
2043 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2044
2045 if (!current_bss)
2046 return 1; /* current BSS not seen in scan results */
2047
2048 if (current_bss == selected)
2049 return 0;
2050
2051 if (selected->last_update_idx > current_bss->last_update_idx)
2052 return 1; /* current BSS not seen in the last scan */
2053
2054#ifndef CONFIG_NO_ROAMING
2055 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2056 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002057#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002058 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002059#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002060}
2061
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002062
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002063/*
2064 * Return a negative value if no scan results could be fetched or if scan
2065 * results should not be shared with other virtual interfaces.
2066 * Return 0 if scan results were fetched and may be shared with other
2067 * interfaces.
2068 * Return 1 if scan results may be shared with other virtual interfaces but may
2069 * not trigger any operations.
2070 * Return 2 if the interface was removed and cannot be used.
2071 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002072static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002073 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002074 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002076 struct wpa_scan_results *scan_res = NULL;
2077 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002078 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002079#ifndef CONFIG_NO_RANDOM_POOL
2080 size_t i, num;
2081#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082
2083#ifdef CONFIG_AP
2084 if (wpa_s->ap_iface)
2085 ap = 1;
2086#endif /* CONFIG_AP */
2087
2088 wpa_supplicant_notify_scanning(wpa_s, 0);
2089
2090 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2091 data ? &data->scan_info :
2092 NULL, 1);
2093 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002094 if (wpa_s->conf->ap_scan == 2 || ap ||
2095 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002096 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002097 if (!own_request)
2098 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002099 if (data && data->scan_info.external_scan)
2100 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002101 if (wpa_s->scan_res_fail_handler) {
2102 void (*handler)(struct wpa_supplicant *wpa_s);
2103
2104 handler = wpa_s->scan_res_fail_handler;
2105 wpa_s->scan_res_fail_handler = NULL;
2106 handler(wpa_s);
2107 } else {
2108 wpa_dbg(wpa_s, MSG_DEBUG,
2109 "Failed to get scan results - try scanning again");
2110 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2111 }
2112
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002113 ret = -1;
2114 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002115 }
2116
2117#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002118 num = scan_res->num;
2119 if (num > 10)
2120 num = 10;
2121 for (i = 0; i < num; i++) {
2122 u8 buf[5];
2123 struct wpa_scan_res *res = scan_res->res[i];
2124 buf[0] = res->bssid[5];
2125 buf[1] = res->qual & 0xff;
2126 buf[2] = res->noise & 0xff;
2127 buf[3] = res->level & 0xff;
2128 buf[4] = res->tsf & 0xff;
2129 random_add_randomness(buf, sizeof(buf));
2130 }
2131#endif /* CONFIG_NO_RANDOM_POOL */
2132
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002133 if (update_only) {
2134 ret = 1;
2135 goto scan_work_done;
2136 }
2137
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002138 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002139 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002140 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2141 struct wpa_scan_results *scan_res);
2142
2143 scan_res_handler = wpa_s->scan_res_handler;
2144 wpa_s->scan_res_handler = NULL;
2145 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002146 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002147 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002148 }
2149
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002150 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002151 wpa_s->own_scan_running,
2152 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002153 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002154 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2155 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002156 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2157 wpa_s->manual_scan_id);
2158 wpa_s->manual_scan_use_id = 0;
2159 } else {
2160 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2161 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002162 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002163
2164 wpas_notify_scan_done(wpa_s, 1);
2165
Hai Shalomfdcde762020-04-02 11:19:20 -07002166 if (ap) {
2167 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2168#ifdef CONFIG_AP
2169 if (wpa_s->ap_iface->scan_cb)
2170 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2171#endif /* CONFIG_AP */
2172 goto scan_work_done;
2173 }
2174
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002175 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002176 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 -07002177 wpa_scan_results_free(scan_res);
2178 return 0;
2179 }
2180
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002181 if (wnm_scan_process(wpa_s, 1) > 0)
2182 goto scan_work_done;
2183
Hai Shalomc1a21442022-02-04 13:43:00 -08002184 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002185 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186
Hai Shalom021b0b52019-04-10 11:17:58 -07002187 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002188 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2189 goto scan_work_done;
2190
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002191 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2192 goto scan_work_done;
2193
2194 if (autoscan_notify_scan(wpa_s, scan_res))
2195 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002196
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002197 if (wpa_s->disconnected) {
2198 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002199 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002200 }
2201
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002202 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002203 bgscan_notify_scan(wpa_s, scan_res) == 1)
2204 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002205
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002206 wpas_wps_update_ap_info(wpa_s, scan_res);
2207
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002208 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2209 wpa_s->wpa_state < WPA_COMPLETED)
2210 goto scan_work_done;
2211
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002212 wpa_scan_results_free(scan_res);
2213
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002214 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002215 struct wpa_radio_work *work = wpa_s->scan_work;
2216 wpa_s->scan_work = NULL;
2217 radio_work_done(work);
2218 }
2219
Hai Shalomc3565922019-10-28 11:58:20 -07002220 os_free(wpa_s->last_scan_freqs);
2221 wpa_s->last_scan_freqs = NULL;
2222 wpa_s->num_last_scan_freqs = 0;
2223 if (own_request && data &&
2224 data->scan_info.freqs && data->scan_info.num_freqs) {
2225 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2226 data->scan_info.num_freqs);
2227 if (wpa_s->last_scan_freqs) {
2228 os_memcpy(wpa_s->last_scan_freqs,
2229 data->scan_info.freqs,
2230 sizeof(int) * data->scan_info.num_freqs);
2231 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2232 }
2233 }
2234
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002235 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002236
2237scan_work_done:
2238 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002239 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002240 struct wpa_radio_work *work = wpa_s->scan_work;
2241 wpa_s->scan_work = NULL;
2242 radio_work_done(work);
2243 }
2244 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002245}
2246
2247
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002248static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002249 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002250{
2251 struct wpa_bss *selected;
2252 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002253 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2254
2255 if (time_to_reenable > 0) {
2256 wpa_dbg(wpa_s, MSG_DEBUG,
2257 "Postpone network selection by %d seconds since all networks are disabled",
2258 time_to_reenable);
2259 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2260 eloop_register_timeout(time_to_reenable, 0,
2261 wpas_network_reenabled, wpa_s, NULL);
2262 return 0;
2263 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002264
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002265 if (wpa_s->p2p_mgmt)
2266 return 0; /* no normal connection on p2p_mgmt interface */
2267
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002268 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002269 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002270
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002271#ifdef CONFIG_MESH
2272 if (wpa_s->ifmsh) {
2273 wpa_msg(wpa_s, MSG_INFO,
2274 "Avoiding join because we already joined a mesh group");
2275 return 0;
2276 }
2277#endif /* CONFIG_MESH */
2278
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002279 if (selected) {
2280 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002281 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002282 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002283 if (new_scan)
2284 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002285 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002286 }
2287
Hai Shalomc3565922019-10-28 11:58:20 -07002288 wpa_s->suitable_network++;
2289
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002290 if (ssid != wpa_s->current_ssid &&
2291 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2292 wpa_s->own_disconnect_req = 1;
2293 wpa_supplicant_deauthenticate(
2294 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2295 }
2296
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002297 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002298 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002299 return -1;
2300 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002301 if (new_scan)
2302 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002303 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002304 * Do not allow other virtual radios to trigger operations based
2305 * on these scan results since we do not want them to start
2306 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002307 */
2308 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002309 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002310 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002311 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2312 ssid = wpa_supplicant_pick_new_network(wpa_s);
2313 if (ssid) {
2314 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2315 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002316 if (new_scan)
2317 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002318 } else if (own_request) {
2319 /*
2320 * No SSID found. If SCAN results are as a result of
2321 * own scan request and not due to a scan request on
2322 * another shared interface, try another scan.
2323 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002324 int timeout_sec = wpa_s->scan_interval;
2325 int timeout_usec = 0;
2326#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002327 int res;
2328
2329 res = wpas_p2p_scan_no_go_seen(wpa_s);
2330 if (res == 2)
2331 return 2;
2332 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002333 return 0;
2334
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002335 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002336 wpa_s->show_group_started ||
2337 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002338 /*
2339 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002340 * state and during P2P join-a-group operation
2341 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002342 */
2343 timeout_sec = 0;
2344 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002345 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2346 timeout_usec);
2347 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002348 }
2349#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002350#ifdef CONFIG_INTERWORKING
2351 if (wpa_s->conf->auto_interworking &&
2352 wpa_s->conf->interworking &&
2353 wpa_s->conf->cred) {
2354 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2355 "start ANQP fetch since no matching "
2356 "networks found");
2357 wpa_s->network_select = 1;
2358 wpa_s->auto_network_select = 1;
2359 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002360 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002361 }
2362#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002363#ifdef CONFIG_WPS
2364 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2365 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2366 timeout_sec = 0;
2367 timeout_usec = 500000;
2368 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2369 timeout_usec);
2370 return 0;
2371 }
2372#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002373#ifdef CONFIG_OWE
2374 if (wpa_s->owe_transition_search) {
2375 wpa_dbg(wpa_s, MSG_DEBUG,
2376 "OWE: Use shorter wait during transition mode search");
2377 timeout_sec = 0;
2378 timeout_usec = 500000;
2379 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2380 timeout_usec);
2381 return 0;
2382 }
2383#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002384 if (wpa_supplicant_req_sched_scan(wpa_s))
2385 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2386 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002387
2388 wpa_msg_ctrl(wpa_s, MSG_INFO,
2389 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002390 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002391 }
2392 }
2393 return 0;
2394}
2395
2396
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002397static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2398 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002399{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002400 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002401 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002402
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002403 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002404 if (res == 2) {
2405 /*
2406 * Interface may have been removed, so must not dereference
2407 * wpa_s after this.
2408 */
2409 return 1;
2410 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002411
2412 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002413 /*
2414 * If no scan results could be fetched, then no need to
2415 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002416 * this scan. Similarly, if scan results started a new operation on this
2417 * interface, do not notify other interfaces to avoid concurrent
2418 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002419 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002420 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002421 }
2422
2423 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002424 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002425 * so, they get updated with this same scan info.
2426 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002427 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2428 radio_list) {
2429 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002430 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2431 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002432 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2433 res > 0);
2434 if (res < 0)
2435 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002436 }
2437 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002438
2439 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002440}
2441
2442#endif /* CONFIG_NO_SCAN_PROCESSING */
2443
2444
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002445int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2446{
2447#ifdef CONFIG_NO_SCAN_PROCESSING
2448 return -1;
2449#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002450 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002451
Dmitry Shmidt29333592017-01-09 12:27:11 -08002452 wpa_s->ignore_post_flush_scan_res = 0;
2453
Dmitry Shmidt41712582015-06-29 11:02:15 -07002454 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002455 return -1;
2456
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002457 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002458 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002459 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002460 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2461 return -1;
2462 }
2463
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002464 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002465#endif /* CONFIG_NO_SCAN_PROCESSING */
2466}
2467
Dmitry Shmidt04949592012-07-19 12:16:46 -07002468#ifdef CONFIG_WNM
2469
2470static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2471{
2472 struct wpa_supplicant *wpa_s = eloop_ctx;
2473
2474 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2475 return;
2476
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002477 if (!wpa_s->no_keep_alive) {
2478 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2479 MAC2STR(wpa_s->bssid));
2480 /* TODO: could skip this if normal data traffic has been sent */
2481 /* TODO: Consider using some more appropriate data frame for
2482 * this */
2483 if (wpa_s->l2)
2484 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2485 (u8 *) "", 0);
2486 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002487
2488#ifdef CONFIG_SME
2489 if (wpa_s->sme.bss_max_idle_period) {
2490 unsigned int msec;
2491 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2492 if (msec > 100)
2493 msec -= 100;
2494 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2495 wnm_bss_keep_alive, wpa_s, NULL);
2496 }
2497#endif /* CONFIG_SME */
2498}
2499
2500
2501static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2502 const u8 *ies, size_t ies_len)
2503{
2504 struct ieee802_11_elems elems;
2505
2506 if (ies == NULL)
2507 return;
2508
2509 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2510 return;
2511
2512#ifdef CONFIG_SME
2513 if (elems.bss_max_idle_period) {
2514 unsigned int msec;
2515 wpa_s->sme.bss_max_idle_period =
2516 WPA_GET_LE16(elems.bss_max_idle_period);
2517 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2518 "TU)%s", wpa_s->sme.bss_max_idle_period,
2519 (elems.bss_max_idle_period[2] & 0x01) ?
2520 " (protected keep-live required)" : "");
2521 if (wpa_s->sme.bss_max_idle_period == 0)
2522 wpa_s->sme.bss_max_idle_period = 1;
2523 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2524 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2525 /* msec times 1000 */
2526 msec = wpa_s->sme.bss_max_idle_period * 1024;
2527 if (msec > 100)
2528 msec -= 100;
2529 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2530 wnm_bss_keep_alive, wpa_s,
2531 NULL);
2532 }
2533 }
2534#endif /* CONFIG_SME */
2535}
2536
2537#endif /* CONFIG_WNM */
2538
2539
2540void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2541{
2542#ifdef CONFIG_WNM
2543 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2544#endif /* CONFIG_WNM */
2545}
2546
2547
Dmitry Shmidt051af732013-10-22 13:52:46 -07002548#ifdef CONFIG_INTERWORKING
2549
2550static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2551 size_t len)
2552{
2553 int res;
2554
2555 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2556 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2557 if (res) {
2558 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2559 }
2560
2561 return res;
2562}
2563
2564
2565static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2566 const u8 *ies, size_t ies_len)
2567{
2568 struct ieee802_11_elems elems;
2569
2570 if (ies == NULL)
2571 return;
2572
2573 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2574 return;
2575
2576 if (elems.qos_map_set) {
2577 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2578 elems.qos_map_set_len);
2579 }
2580}
2581
2582#endif /* CONFIG_INTERWORKING */
2583
2584
Hai Shalom74f70d42019-02-11 14:42:39 -08002585static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2586 const u8 *ies, size_t ies_len)
2587{
2588 struct ieee802_11_elems elems;
2589 const u8 *map_sub_elem, *pos;
2590 size_t len;
2591
Hai Shalomfdcde762020-04-02 11:19:20 -07002592 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002593
Hai Shalomfdcde762020-04-02 11:19:20 -07002594 if (!ies ||
2595 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2596 !elems.multi_ap || elems.multi_ap_len < 7)
2597 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002598
2599 pos = elems.multi_ap + 4;
2600 len = elems.multi_ap_len - 4;
2601
2602 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002603 if (!map_sub_elem || map_sub_elem[1] < 1)
2604 return;
2605
2606 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2607 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2608 MULTI_AP_FRONTHAUL_BSS);
2609 wpa_s->multi_ap_ie = 1;
2610}
2611
2612
2613static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2614{
2615 if (!wpa_s->current_ssid ||
2616 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2617 return;
2618
2619 if (!wpa_s->multi_ap_ie) {
2620 wpa_printf(MSG_INFO,
2621 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002622 goto fail;
2623 }
2624
Hai Shalomfdcde762020-04-02 11:19:20 -07002625 if (!wpa_s->multi_ap_backhaul) {
2626 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002627 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2628 wpa_printf(MSG_INFO,
2629 "WPS active, accepting fronthaul-only BSS");
2630 /* Don't set 4addr mode in this case, so just return */
2631 return;
2632 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002633 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2634 goto fail;
2635 }
2636
2637 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2638 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2639 goto fail;
2640 }
2641 wpa_s->enabled_4addr_mode = 1;
2642 return;
2643
2644fail:
2645 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2646}
2647
2648
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002649#ifdef CONFIG_FST
2650static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2651 const u8 *ie, size_t ie_len)
2652{
2653 struct mb_ies_info mb_ies;
2654
2655 if (!ie || !ie_len || !wpa_s->fst)
2656 return -ENOENT;
2657
2658 os_memset(&mb_ies, 0, sizeof(mb_ies));
2659
2660 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2661 size_t len;
2662
2663 len = 2 + ie[1];
2664 if (len > ie_len) {
2665 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2666 ie, ie_len);
2667 break;
2668 }
2669
2670 if (ie[0] == WLAN_EID_MULTI_BAND) {
2671 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2672 (unsigned int) len);
2673 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2674 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2675 mb_ies.nof_ies++;
2676 }
2677
2678 ie_len -= len;
2679 ie += len;
2680 }
2681
2682 if (mb_ies.nof_ies > 0) {
2683 wpabuf_free(wpa_s->received_mb_ies);
2684 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2685 return 0;
2686 }
2687
2688 return -ENOENT;
2689}
2690#endif /* CONFIG_FST */
2691
2692
Hai Shalomc1a21442022-02-04 13:43:00 -08002693static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2694 union wpa_event_data *data)
2695{
2696 int sel;
2697 const u8 *p;
2698 int l, len;
2699 bool found = false;
2700 struct wpa_ie_data ie;
2701 struct wpa_ssid *ssid = wpa_s->current_ssid;
2702 struct wpa_bss *bss = wpa_s->current_bss;
2703 int pmf;
2704
2705 if (!ssid)
2706 return 0;
2707
2708 p = data->assoc_info.req_ies;
2709 l = data->assoc_info.req_ies_len;
2710
2711 while (p && l >= 2) {
2712 len = p[1] + 2;
2713 if (len > l) {
2714 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2715 p, l);
2716 break;
2717 }
2718 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2719 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2720 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2721 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2722 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2723 found = true;
2724 break;
2725 }
2726 l -= len;
2727 p += len;
2728 }
2729
2730 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2731 return 0;
2732
2733 wpa_hexdump(MSG_DEBUG,
2734 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2735 p, l);
2736
2737 /* Update proto from (Re)Association Request frame info */
2738 wpa_s->wpa_proto = ie.proto;
2739 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2740 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2741 !!(wpa_s->wpa_proto &
2742 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2743
2744 /* Update AKMP suite from (Re)Association Request frame info */
2745 sel = ie.key_mgmt;
2746 if (ssid->key_mgmt)
2747 sel &= ssid->key_mgmt;
2748
2749 wpa_dbg(wpa_s, MSG_DEBUG,
2750 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2751 ie.key_mgmt, ssid->key_mgmt, sel);
2752 if (ie.key_mgmt && !sel) {
2753 wpa_supplicant_deauthenticate(
2754 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2755 return -1;
2756 }
2757
2758 wpa_s->key_mgmt = ie.key_mgmt;
2759 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2760 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2761 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2762 wpa_s->wpa_proto);
2763
2764 /* Update pairwise cipher from (Re)Association Request frame info */
2765 sel = ie.pairwise_cipher;
2766 if (ssid->pairwise_cipher)
2767 sel &= ssid->pairwise_cipher;
2768
2769 wpa_dbg(wpa_s, MSG_DEBUG,
2770 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2771 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2772 if (ie.pairwise_cipher && !sel) {
2773 wpa_supplicant_deauthenticate(
2774 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2775 return -1;
2776 }
2777
2778 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2779 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2780 wpa_s->pairwise_cipher);
2781 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2782 wpa_cipher_txt(wpa_s->pairwise_cipher));
2783
2784 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2785 if (!bss) {
2786 wpa_dbg(wpa_s, MSG_DEBUG,
2787 "WPA: current_bss == NULL - skip AP IE check");
2788 return 0;
2789 }
2790
2791 /* Update GTK and IGTK from AP's RSNE */
2792 found = false;
2793
2794 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2795 const u8 *bss_rsn;
2796
2797 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2798 if (bss_rsn) {
2799 p = bss_rsn;
2800 len = 2 + bss_rsn[1];
2801 found = true;
2802 }
2803 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2804 const u8 *bss_wpa;
2805
2806 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2807 if (bss_wpa) {
2808 p = bss_wpa;
2809 len = 2 + bss_wpa[1];
2810 found = true;
2811 }
2812 }
2813
2814 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2815 return 0;
2816
2817 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2818 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2819 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
2820 /* AP does not support MFP, local configuration requires it */
2821 wpa_supplicant_deauthenticate(
2822 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2823 return -1;
2824 }
2825 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
2826 pmf == NO_MGMT_FRAME_PROTECTION) {
2827 /* AP requires MFP, local configuration disables it */
2828 wpa_supplicant_deauthenticate(
2829 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2830 return -1;
2831 }
2832
2833 /* Update PMF from local configuration now that MFP validation was done
2834 * above */
2835 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
2836
2837 /* Update GTK from AP's RSNE */
2838 sel = ie.group_cipher;
2839 if (ssid->group_cipher)
2840 sel &= ssid->group_cipher;
2841
2842 wpa_dbg(wpa_s, MSG_DEBUG,
2843 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
2844 ie.group_cipher, ssid->group_cipher, sel);
2845 if (ie.group_cipher && !sel) {
2846 wpa_supplicant_deauthenticate(
2847 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
2848 return -1;
2849 }
2850
2851 wpa_s->group_cipher = ie.group_cipher;
2852 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
2853 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
2854 wpa_cipher_txt(wpa_s->group_cipher));
2855
2856 /* Update IGTK from AP RSN IE */
2857 sel = ie.mgmt_group_cipher;
2858 if (ssid->group_mgmt_cipher)
2859 sel &= ssid->group_mgmt_cipher;
2860
2861 wpa_dbg(wpa_s, MSG_DEBUG,
2862 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
2863 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
2864
2865 if (pmf == NO_MGMT_FRAME_PROTECTION ||
2866 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
2867 wpa_dbg(wpa_s, MSG_DEBUG,
2868 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
2869 ie.capabilities);
2870 ie.mgmt_group_cipher = 0;
2871 }
2872
2873 if (ie.mgmt_group_cipher && !sel) {
2874 wpa_supplicant_deauthenticate(
2875 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
2876 return -1;
2877 }
2878
2879 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
2880 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
2881 wpa_s->mgmt_group_cipher);
2882 if (wpa_s->mgmt_group_cipher)
2883 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
2884 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
2885 else
2886 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
2887
2888 return 0;
2889}
2890
2891
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002892static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2893 union wpa_event_data *data)
2894{
Hai Shalomc3565922019-10-28 11:58:20 -07002895 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002896 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002897 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002898 bool bssid_known;
Vinayak Yadawad14709082022-03-17 14:25:11 +05302899#ifdef CONFIG_DRIVER_NL80211_BRCM
2900 struct wpa_ie_data ie;
2901#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002902
2903 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07002904 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002905 if (data->assoc_info.req_ies)
2906 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2907 data->assoc_info.req_ies_len);
2908 if (data->assoc_info.resp_ies) {
2909 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2910 data->assoc_info.resp_ies_len);
2911#ifdef CONFIG_TDLS
2912 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2913 data->assoc_info.resp_ies_len);
2914#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002915#ifdef CONFIG_WNM
2916 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2917 data->assoc_info.resp_ies_len);
2918#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002919#ifdef CONFIG_INTERWORKING
2920 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2921 data->assoc_info.resp_ies_len);
2922#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002923 if (wpa_s->hw_capab == CAPAB_VHT &&
2924 get_ie(data->assoc_info.resp_ies,
2925 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2926 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002927
2928 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2929 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002930 }
2931 if (data->assoc_info.beacon_ies)
2932 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2933 data->assoc_info.beacon_ies,
2934 data->assoc_info.beacon_ies_len);
2935 if (data->assoc_info.freq)
2936 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2937 data->assoc_info.freq);
2938
Hai Shalom021b0b52019-04-10 11:17:58 -07002939 wpa_s->connection_set = 0;
2940 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2941 struct ieee802_11_elems req_elems, resp_elems;
2942
2943 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2944 data->assoc_info.req_ies_len,
2945 &req_elems, 0) != ParseFailed &&
2946 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2947 data->assoc_info.resp_ies_len,
2948 &resp_elems, 0) != ParseFailed) {
2949 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07002950 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
2951 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07002952 wpa_s->connection_ht = req_elems.ht_capabilities &&
2953 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07002954 /* Do not include subset of VHT on 2.4 GHz vendor
2955 * extension in consideration for reporting VHT
2956 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07002957 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002958 resp_elems.vht_capabilities &&
2959 (!data->assoc_info.freq ||
2960 wpas_freq_to_band(data->assoc_info.freq) !=
2961 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07002962 wpa_s->connection_he = req_elems.he_capabilities &&
2963 resp_elems.he_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08002964
2965 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
2966 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
2967 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
2968 max_nss_rx_req : max_nss_rx_resp;
2969 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
2970 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
2971 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
2972 max_nss_tx_req : max_nss_tx_resp;
2973
2974 struct supported_chan_width sta_supported_chan_width =
2975 get_supported_channel_width(&req_elems);
2976 enum chan_width ap_operation_chan_width =
2977 get_operation_channel_width(&resp_elems);
2978 if (wpa_s->connection_vht || wpa_s->connection_he) {
2979 wpa_s->connection_channel_bandwidth =
2980 get_sta_operation_chan_width(ap_operation_chan_width,
2981 sta_supported_chan_width);
2982 } else if (wpa_s->connection_ht) {
2983 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
2984 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
2985 } else {
2986 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
2987 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002988 }
2989 }
2990
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002991 p = data->assoc_info.req_ies;
2992 l = data->assoc_info.req_ies_len;
2993
2994 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2995 while (p && l >= 2) {
2996 len = p[1] + 2;
2997 if (len > l) {
2998 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2999 p, l);
3000 break;
3001 }
Hai Shalomc3565922019-10-28 11:58:20 -07003002 if (!found &&
3003 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3004 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3005 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3006 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3007 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003008 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3009 break;
3010 found = 1;
3011 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07003012 }
3013 if (!found_x && p[0] == WLAN_EID_RSNX) {
3014 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3015 break;
3016 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003017 }
3018 l -= len;
3019 p += len;
3020 }
3021 if (!found && data->assoc_info.req_ies)
3022 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003023 if (!found_x && data->assoc_info.req_ies)
3024 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003025
Vinayak Yadawad14709082022-03-17 14:25:11 +05303026#ifdef CONFIG_DRIVER_NL80211_BRCM
3027 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3028 * to a different security type, update the current supplicant configuration to use the AKM
3029 * and pairwise suites from the assoc IE passed by the driver.
3030 */
3031 if (wpas_driver_bss_selection(wpa_s)) {
3032 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3033 /* Check if firmware has roamed to a different security network */
3034 if(wpa_s->key_mgmt != ie.key_mgmt) {
3035 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3036 ie.key_mgmt);
3037 wpa_s->key_mgmt = ie.key_mgmt;
3038 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3039
3040 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3041 /* Restore PMK as it can get overwritten if the previous
3042 * association was to 802.1X.
3043 */
3044 if ((!(wpa_s->drv_flags &
3045 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3046 (wpa_s->current_ssid) &&
3047 (wpa_s->current_ssid->psk_set)) {
3048 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3049 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3050 "BSSID");
3051 wpa_supplicant_deauthenticate(
3052 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3053 return -1;
3054 }
3055 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3056 PMK_LEN, NULL, bssid);
3057 }
3058 }
3059 }
3060 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3061 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3062 "from Assoc IE", ie.pairwise_cipher);
3063 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3064 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3065 wpa_s->pairwise_cipher);
3066 }
3067 // TODO: Notify the framework about security type change b/230766005
3068 }
3069 }
3070#endif /* CONFIG_DRIVER_NL80211_BRCM */
3071
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003072#ifdef CONFIG_FILS
3073#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003074 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3075 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003076 (!data->assoc_info.resp_frame ||
3077 fils_process_assoc_resp(wpa_s->wpa,
3078 data->assoc_info.resp_frame,
3079 data->assoc_info.resp_frame_len) < 0)) {
3080 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3081 return -1;
3082 }
3083#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003084
3085 /* Additional processing for FILS when SME is in driver */
3086 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3087 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3088 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003089#endif /* CONFIG_FILS */
3090
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003091#ifdef CONFIG_OWE
3092 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003093 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003094 owe_process_assoc_resp(wpa_s->wpa, bssid,
3095 data->assoc_info.resp_ies,
3096 data->assoc_info.resp_ies_len) < 0)) {
3097 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3098 return -1;
3099 }
3100#endif /* CONFIG_OWE */
3101
Hai Shalom021b0b52019-04-10 11:17:58 -07003102#ifdef CONFIG_DPP2
3103 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003104 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3105 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003106 struct ieee802_11_elems elems;
3107
3108 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3109 data->assoc_info.resp_ies_len,
3110 &elems, 0) == ParseFailed ||
3111 !elems.owe_dh)
3112 goto no_pfs;
3113 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3114 elems.owe_dh_len) < 0) {
3115 wpa_supplicant_deauthenticate(wpa_s,
3116 WLAN_REASON_UNSPECIFIED);
3117 return -1;
3118 }
3119
3120 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3121 }
3122no_pfs:
3123#endif /* CONFIG_DPP2 */
3124
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003125#ifdef CONFIG_IEEE80211R
3126#ifdef CONFIG_SME
3127 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003128 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003129 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3130 data->assoc_info.resp_ies,
3131 data->assoc_info.resp_ies_len,
3132 bssid) < 0) {
3133 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3134 "Reassociation Response failed");
3135 wpa_supplicant_deauthenticate(
3136 wpa_s, WLAN_REASON_INVALID_IE);
3137 return -1;
3138 }
3139 }
3140
3141 p = data->assoc_info.resp_ies;
3142 l = data->assoc_info.resp_ies_len;
3143
3144#ifdef CONFIG_WPS_STRICT
3145 if (p && wpa_s->current_ssid &&
3146 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3147 struct wpabuf *wps;
3148 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3149 if (wps == NULL) {
3150 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3151 "include WPS IE in (Re)Association Response");
3152 return -1;
3153 }
3154
3155 if (wps_validate_assoc_resp(wps) < 0) {
3156 wpabuf_free(wps);
3157 wpa_supplicant_deauthenticate(
3158 wpa_s, WLAN_REASON_INVALID_IE);
3159 return -1;
3160 }
3161 wpabuf_free(wps);
3162 }
3163#endif /* CONFIG_WPS_STRICT */
3164
3165 /* Go through the IEs and make a copy of the MDIE, if present. */
3166 while (p && l >= 2) {
3167 len = p[1] + 2;
3168 if (len > l) {
3169 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3170 p, l);
3171 break;
3172 }
3173 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3174 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3175 wpa_s->sme.ft_used = 1;
3176 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3177 MOBILITY_DOMAIN_ID_LEN);
3178 break;
3179 }
3180 l -= len;
3181 p += len;
3182 }
3183#endif /* CONFIG_SME */
Mir Ali677e7482020-11-12 19:49:02 +05303184#ifdef CONFIG_DRIVER_NL80211_BRCM
Mir Alieaaf04e2021-06-07 12:17:29 +05303185 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3186 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3187 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3188 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303189 wpa_ft_is_completed(wpa_s->wpa)) {
3190 return 0;
3191 }
3192#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003193
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003194 /* Process FT when SME is in the driver */
3195 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3196 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003197 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003198 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3199 data->assoc_info.resp_ies,
3200 data->assoc_info.resp_ies_len,
3201 bssid) < 0) {
3202 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3203 "Reassociation Response failed");
3204 wpa_supplicant_deauthenticate(
3205 wpa_s, WLAN_REASON_INVALID_IE);
3206 return -1;
3207 }
3208 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3209 }
3210
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003211 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3212 data->assoc_info.resp_ies_len);
3213#endif /* CONFIG_IEEE80211R */
3214
Hai Shalom899fcc72020-10-19 14:38:18 -07003215 if (bssid_known)
3216 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3217 data->assoc_info.resp_ies,
3218 data->assoc_info.resp_ies_len);
3219
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003220 /* WPA/RSN IE from Beacon/ProbeResp */
3221 p = data->assoc_info.beacon_ies;
3222 l = data->assoc_info.beacon_ies_len;
3223
3224 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3225 */
3226 wpa_found = rsn_found = 0;
3227 while (p && l >= 2) {
3228 len = p[1] + 2;
3229 if (len > l) {
3230 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3231 p, l);
3232 break;
3233 }
3234 if (!wpa_found &&
3235 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3236 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3237 wpa_found = 1;
3238 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3239 }
3240
3241 if (!rsn_found &&
3242 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3243 rsn_found = 1;
3244 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3245 }
3246
Hai Shalomc3565922019-10-28 11:58:20 -07003247 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3248 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3249
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003250 l -= len;
3251 p += len;
3252 }
3253
3254 if (!wpa_found && data->assoc_info.beacon_ies)
3255 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003256 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003257 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003258 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3259 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003260 if (wpa_found || rsn_found)
3261 wpa_s->ap_ies_from_associnfo = 1;
3262
Jouni Malinen87fd2792011-05-16 18:35:42 +03003263 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3264 wpa_s->assoc_freq != data->assoc_info.freq) {
3265 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3266 "%u to %u MHz",
3267 wpa_s->assoc_freq, data->assoc_info.freq);
3268 wpa_supplicant_update_scan_results(wpa_s);
3269 }
3270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003271 wpa_s->assoc_freq = data->assoc_info.freq;
3272
Hai Shalomc1a21442022-02-04 13:43:00 -08003273 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3274 data->assoc_info.resp_ies_len);
3275
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003276 return 0;
3277}
3278
3279
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003280static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3281{
Hai Shalomc3565922019-10-28 11:58:20 -07003282 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003283
3284 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3285 return -1;
3286
3287 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3288 return 0;
3289
3290 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3291 WPA_IE_VENDOR_TYPE);
3292 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003293 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003294
3295 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3296 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3297 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003298 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3299 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3300 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003301 return -1;
3302
3303 return 0;
3304}
3305
3306
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003307static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3308 union wpa_event_data *data)
3309{
3310#ifdef CONFIG_FST
3311 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3312 struct wpa_bss *bss = wpa_s->current_bss;
3313 const u8 *ieprb, *iebcn;
3314
3315 wpabuf_free(wpa_s->received_mb_ies);
3316 wpa_s->received_mb_ies = NULL;
3317
3318 if (ai &&
3319 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3320 wpa_printf(MSG_DEBUG,
3321 "FST: MB IEs updated from Association Response frame");
3322 return;
3323 }
3324
3325 if (ai &&
3326 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3327 wpa_printf(MSG_DEBUG,
3328 "FST: MB IEs updated from association event Beacon IEs");
3329 return;
3330 }
3331
3332 if (!bss)
3333 return;
3334
Hai Shalom60840252021-02-19 19:02:11 -08003335 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003336 iebcn = ieprb + bss->ie_len;
3337
3338 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3339 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3340 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3341 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3342#endif /* CONFIG_FST */
3343}
3344
3345
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003346static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3347 union wpa_event_data *data)
3348{
3349 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003350 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003351 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003352#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3353 struct wpa_bss *bss;
3354#endif /* CONFIG_FILS || CONFIG_MBO */
Mir Ali677e7482020-11-12 19:49:02 +05303355#ifdef CONFIG_DRIVER_NL80211_BRCM
3356 struct wpa_ie_data ie;
3357#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003358
3359#ifdef CONFIG_AP
3360 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003361 if (!data)
3362 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003363 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3364 data->assoc_info.addr,
3365 data->assoc_info.req_ies,
3366 data->assoc_info.req_ies_len,
3367 data->assoc_info.reassoc);
3368 return;
3369 }
3370#endif /* CONFIG_AP */
3371
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003372 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003373 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003374
Mir Ali677e7482020-11-12 19:49:02 +05303375#ifdef CONFIG_DRIVER_NL80211_BRCM
3376 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3377 struct wpa_ft_ies parse;
3378 /* Check for FT reassociation is done by the driver */
3379#ifdef CONFIG_IEEE80211R
3380 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303381 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303382 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3383 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3384 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3385 return;
3386 }
3387 if (parse.rsn_pmkid != NULL) {
3388 wpa_set_ft_completed(wpa_s->wpa);
3389 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3390 }
3391 }
3392#endif /* CONFIG_IEEE80211R */
3393 }
3394#endif /* CONFIG_DRIVER_NL80211_BRCM */
3395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003396 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
3397 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3398 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003399 /*
3400 * FILS authentication can share the same mechanism to mark the
3401 * connection fully authenticated, so set ft_completed also based on
3402 * FILS result.
3403 */
3404 if (!ft_completed)
3405 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003406
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003407 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3408 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003409 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003410 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3411 return;
3412 }
3413
Mir Ali677e7482020-11-12 19:49:02 +05303414#ifdef CONFIG_DRIVER_NL80211_BRCM
3415 /* For driver based roaming, insert PSK during the initial association */
3416 if (is_zero_ether_addr(wpa_s->bssid) &&
3417 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3418 /* In case the driver wants to handle re-assocs, pass it down the PMK. */
3419 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3420 wpa_sm_install_pmk(wpa_s->wpa);
3421 }
3422#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003423 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003424 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003425 if (os_reltime_initialized(&wpa_s->session_start)) {
3426 os_reltime_age(&wpa_s->session_start,
3427 &wpa_s->session_length);
3428 wpa_s->session_start.sec = 0;
3429 wpa_s->session_start.usec = 0;
3430 wpas_notify_session_length(wpa_s);
3431 } else {
3432 wpas_notify_auth_changed(wpa_s);
3433 os_get_reltime(&wpa_s->session_start);
3434 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003435 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3436 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003437 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003438 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003439 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3440 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003441 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003442
3443 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3444 wpa_clear_keys(wpa_s, bssid);
3445 }
3446 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003447 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003448 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3449 return;
3450 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003451 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003452
Hai Shalomc1a21442022-02-04 13:43:00 -08003453 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3454 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3455 return;
3456
Hai Shalomfdcde762020-04-02 11:19:20 -07003457 multi_ap_set_4addr_mode(wpa_s);
3458
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003459 if (wpa_s->conf->ap_scan == 1 &&
3460 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003461 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3462 wpa_msg(wpa_s, MSG_WARNING,
3463 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003464 }
3465
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003466 wpas_fst_update_mb_assoc(wpa_s, data);
3467
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003468#ifdef CONFIG_SME
3469 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3470 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003471 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003472#endif /* CONFIG_SME */
3473
3474 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3475 if (wpa_s->current_ssid) {
3476 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3477 * initialized before association, but for other modes,
3478 * initialize PC/SC here, if the current configuration needs
3479 * smartcard or SIM/USIM. */
3480 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3481 }
3482 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3483 if (wpa_s->l2)
3484 l2_packet_notify_auth_start(wpa_s->l2);
3485
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003486 already_authorized = data && data->assoc_info.authorized;
3487
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003488 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003489 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003490 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3491 * state machine may transit to AUTHENTICATING state based on obsolete
3492 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3493 * AUTHENTICATED without ever giving chance to EAP state machine to
3494 * reset the state.
3495 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003496 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003497 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3498 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003499 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003500 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3501 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3502 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003503 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003504 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003505 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003506 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003507 wpa_s->eapol_received = 0;
3508 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3509 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3510 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003511 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003512 if (wpa_s->current_ssid &&
3513 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003514 (wpa_s->drv_flags &
3515 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3516 /*
3517 * Set the key after having received joined-IBSS event
3518 * from the driver.
3519 */
3520 wpa_supplicant_set_wpa_none_key(wpa_s,
3521 wpa_s->current_ssid);
3522 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003523 wpa_supplicant_cancel_auth_timeout(wpa_s);
3524 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3525 } else if (!ft_completed) {
3526 /* Timeout for receiving the first EAPOL packet */
3527 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3528 }
3529 wpa_supplicant_cancel_scan(wpa_s);
3530
Hai Shalom5f92bc92019-04-18 11:54:11 -07003531 if (ft_completed) {
3532 /*
3533 * FT protocol completed - make sure EAPOL state machine ends
3534 * up in authenticated.
3535 */
3536 wpa_supplicant_cancel_auth_timeout(wpa_s);
3537 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003538 eapol_sm_notify_portValid(wpa_s->eapol, true);
3539 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003540 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3541 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003542 /*
3543 * We are done; the driver will take care of RSN 4-way
3544 * handshake.
3545 */
3546 wpa_supplicant_cancel_auth_timeout(wpa_s);
3547 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003548 eapol_sm_notify_portValid(wpa_s->eapol, true);
3549 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003550 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003551 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3552 /*
3553 * The driver will take care of RSN 4-way handshake, so we need
3554 * to allow EAPOL supplicant to complete its work without
3555 * waiting for WPA supplicant.
3556 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003557 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003558 }
Mir Alieaaf04e2021-06-07 12:17:29 +05303559#ifdef CONFIG_DRIVER_NL80211_BRCM
3560 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3561 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3562 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3563 wpa_s->key_mgmt);
3564 wpa_supplicant_deauthenticate(
3565 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3566 return;
3567 }
3568 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3569 wpa_s->assoc_freq = data->assoc_info.freq;
3570 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3571 }
3572#endif /* CONFIG_DRIVER_NL80211_BRCM */
Jouni Malinena05074c2012-12-21 21:35:35 +02003573 wpa_s->last_eapol_matches_bssid = 0;
3574
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003575#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003576 if (wpa_s->rsne_override_eapol) {
3577 wpa_printf(MSG_DEBUG,
3578 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3579 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3580 wpabuf_head(wpa_s->rsne_override_eapol),
3581 wpabuf_len(wpa_s->rsne_override_eapol));
3582 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003583 if (wpa_s->rsnxe_override_eapol) {
3584 wpa_printf(MSG_DEBUG,
3585 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3586 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3587 wpabuf_head(wpa_s->rsnxe_override_eapol),
3588 wpabuf_len(wpa_s->rsnxe_override_eapol));
3589 }
3590#endif /* CONFIG_TESTING_OPTIONS */
3591
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003592 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003593 struct os_reltime now, age;
3594 os_get_reltime(&now);
3595 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003596 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003597 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3598 0) {
3599 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3600 "frame that was received just before "
3601 "association notification");
3602 wpa_supplicant_rx_eapol(
3603 wpa_s, wpa_s->pending_eapol_rx_src,
3604 wpabuf_head(wpa_s->pending_eapol_rx),
3605 wpabuf_len(wpa_s->pending_eapol_rx));
3606 }
3607 wpabuf_free(wpa_s->pending_eapol_rx);
3608 wpa_s->pending_eapol_rx = NULL;
3609 }
3610
Hai Shalomfdcde762020-04-02 11:19:20 -07003611#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003612 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3613 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003614 wpa_s->current_ssid &&
3615 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003616 /* Set static WEP keys again */
3617 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3618 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003619#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003620
3621#ifdef CONFIG_IBSS_RSN
3622 if (wpa_s->current_ssid &&
3623 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3624 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3625 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3626 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003627 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003628 if (!wpa_s->ibss_rsn) {
3629 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3630 wpa_supplicant_deauthenticate(
3631 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3632 return;
3633 }
3634
3635 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3636 }
3637#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003638
3639 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003640
3641 if (data) {
3642 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3643 data->assoc_info.resp_ies_len,
3644 &data->assoc_info.wmm_params);
3645
3646 if (wpa_s->reassoc_same_bss)
3647 wmm_ac_restore_tspecs(wpa_s);
3648 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003649
Hai Shalomc3565922019-10-28 11:58:20 -07003650#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3651 bss = wpa_bss_get_bssid(wpa_s, bssid);
3652#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003653#ifdef CONFIG_FILS
3654 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003655 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3656
3657 if (fils_cache_id)
3658 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3659 }
3660#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003661
3662#ifdef CONFIG_MBO
3663 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3664#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003665
3666#ifdef CONFIG_DPP2
3667 wpa_s->dpp_pfs_fallback = 0;
3668#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003669}
3670
3671
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003672static int disconnect_reason_recoverable(u16 reason_code)
3673{
3674 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3675 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3676 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3677}
3678
3679
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003680static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003681 u16 reason_code,
3682 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003683{
3684 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003685
3686 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3687 /*
3688 * At least Host AP driver and a Prism3 card seemed to be
3689 * generating streams of disconnected events when configuring
3690 * IBSS for WPA-None. Ignore them for now.
3691 */
3692 return;
3693 }
3694
3695 bssid = wpa_s->bssid;
3696 if (is_zero_ether_addr(bssid))
3697 bssid = wpa_s->pending_bssid;
3698
3699 if (!is_zero_ether_addr(bssid) ||
3700 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3701 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3702 " reason=%d%s",
3703 MAC2STR(bssid), reason_code,
3704 locally_generated ? " locally_generated=1" : "");
3705 }
3706}
3707
3708
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003709static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3710 int locally_generated)
3711{
3712 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003713 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003714 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3715 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003716 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003717
3718 /*
3719 * It looks like connection was lost while trying to go through PSK
3720 * 4-way handshake. Filter out known disconnection cases that are caused
3721 * by something else than PSK mismatch to avoid confusing reports.
3722 */
3723
3724 if (locally_generated) {
3725 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3726 return 0;
3727 }
3728
3729 return 1;
3730}
3731
3732
Jouni Malinen2b89da82012-08-31 22:04:41 +03003733static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3734 u16 reason_code,
3735 int locally_generated)
3736{
3737 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003738 int authenticating;
3739 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003740 struct wpa_bss *fast_reconnect = NULL;
3741 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003742 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003743 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003744
3745 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3746 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3747
3748 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3749 /*
3750 * At least Host AP driver and a Prism3 card seemed to be
3751 * generating streams of disconnected events when configuring
3752 * IBSS for WPA-None. Ignore them for now.
3753 */
3754 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3755 "IBSS/WPA-None mode");
3756 return;
3757 }
3758
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003759 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3760 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3761 locally_generated)
3762 /*
3763 * Remove the inactive AP (which is probably out of range) from
3764 * the BSS list after marking disassociation. In particular
3765 * mac80211-based drivers use the
3766 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3767 * locally generated disconnection events for cases where the
3768 * AP does not reply anymore.
3769 */
3770 curr = wpa_s->current_bss;
3771
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003772 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003773 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3774 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003775 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3776 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003777 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003778#ifdef CONFIG_DPP2
3779 wpas_dpp_send_conn_status_result(wpa_s,
3780 DPP_STATUS_AUTH_FAILURE);
3781#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003782 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003783 if (!wpa_s->disconnected &&
3784 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003785 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003786 wpas_wps_searching(wpa_s) ||
3787 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003788 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003789 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003790 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003791 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003792 wpa_s->wpa_state);
3793 if (wpa_s->wpa_state == WPA_COMPLETED &&
3794 wpa_s->current_ssid &&
3795 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003796 (wpa_s->own_reconnect_req ||
3797 (!locally_generated &&
3798 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003799 /*
3800 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003801 * us, but could allow us to get back in. This is also
3802 * triggered for cases where local reconnection request
3803 * is used to force reassociation with the same BSS.
3804 * Try to reconnect to the same BSS without a full scan
3805 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003806 */
3807 fast_reconnect = wpa_s->current_bss;
3808 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003809 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003810 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003811 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003812 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3813 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003814 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003815 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003816 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003817 "try to re-connect");
3818 wpa_s->reassociate = 0;
3819 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003820 if (!wpa_s->pno)
3821 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003822 }
3823 bssid = wpa_s->bssid;
3824 if (is_zero_ether_addr(bssid))
3825 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003826 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3827 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003828 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08003829 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
3830
Dmitry Shmidt04949592012-07-19 12:16:46 -07003831 if (locally_generated)
3832 wpa_s->disconnect_reason = -reason_code;
3833 else
3834 wpa_s->disconnect_reason = reason_code;
3835 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003836 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3837 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003838 wpa_clear_keys(wpa_s, wpa_s->bssid);
3839 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003840 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003841 wpa_supplicant_mark_disassoc(wpa_s);
3842
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003843 if (curr)
3844 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3845
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003846 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003847 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003848 wpa_s->current_ssid = last_ssid;
3849 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003850
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003851 if (fast_reconnect &&
3852 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3853 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3854 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3855 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003856 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003857 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003858#ifndef CONFIG_NO_SCAN_PROCESSING
3859 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3860 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3861 fast_reconnect_ssid) < 0) {
3862 /* Recover through full scan */
3863 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3864 }
3865#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003866 } else if (fast_reconnect) {
3867 /*
3868 * Could not reconnect to the same BSS due to network being
3869 * disabled. Use a new scan to match the alternative behavior
3870 * above, i.e., to continue automatic reconnection attempt in a
3871 * way that enforces disabled network rules.
3872 */
3873 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003874 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003875}
3876
3877
3878#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003879void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003880{
3881 struct wpa_supplicant *wpa_s = eloop_ctx;
3882
3883 if (!wpa_s->pending_mic_error_report)
3884 return;
3885
3886 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3887 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3888 wpa_s->pending_mic_error_report = 0;
3889}
3890#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3891
3892
3893static void
3894wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3895 union wpa_event_data *data)
3896{
3897 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003898 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003899
3900 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3901 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003902 os_get_reltime(&t);
3903 if ((wpa_s->last_michael_mic_error.sec &&
3904 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003905 wpa_s->pending_mic_error_report) {
3906 if (wpa_s->pending_mic_error_report) {
3907 /*
3908 * Send the pending MIC error report immediately since
3909 * we are going to start countermeasures and AP better
3910 * do the same.
3911 */
3912 wpa_sm_key_request(wpa_s->wpa, 1,
3913 wpa_s->pending_mic_error_pairwise);
3914 }
3915
3916 /* Send the new MIC error report immediately since we are going
3917 * to start countermeasures and AP better do the same.
3918 */
3919 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3920
3921 /* initialize countermeasures */
3922 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003923
Hai Shalom60840252021-02-19 19:02:11 -08003924 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003925
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003926 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3927
3928 /*
3929 * Need to wait for completion of request frame. We do not get
3930 * any callback for the message completion, so just wait a
3931 * short while and hope for the best. */
3932 os_sleep(0, 10000);
3933
3934 wpa_drv_set_countermeasures(wpa_s, 1);
3935 wpa_supplicant_deauthenticate(wpa_s,
3936 WLAN_REASON_MICHAEL_MIC_FAILURE);
3937 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3938 wpa_s, NULL);
3939 eloop_register_timeout(60, 0,
3940 wpa_supplicant_stop_countermeasures,
3941 wpa_s, NULL);
3942 /* TODO: mark the AP rejected for 60 second. STA is
3943 * allowed to associate with another AP.. */
3944 } else {
3945#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3946 if (wpa_s->mic_errors_seen) {
3947 /*
3948 * Reduce the effectiveness of Michael MIC error
3949 * reports as a means for attacking against TKIP if
3950 * more than one MIC failure is noticed with the same
3951 * PTK. We delay the transmission of the reports by a
3952 * random time between 0 and 60 seconds in order to
3953 * force the attacker wait 60 seconds before getting
3954 * the information on whether a frame resulted in a MIC
3955 * failure.
3956 */
3957 u8 rval[4];
3958 int sec;
3959
3960 if (os_get_random(rval, sizeof(rval)) < 0)
3961 sec = os_random() % 60;
3962 else
3963 sec = WPA_GET_BE32(rval) % 60;
3964 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3965 "report %d seconds", sec);
3966 wpa_s->pending_mic_error_report = 1;
3967 wpa_s->pending_mic_error_pairwise = pairwise;
3968 eloop_cancel_timeout(
3969 wpa_supplicant_delayed_mic_error_report,
3970 wpa_s, NULL);
3971 eloop_register_timeout(
3972 sec, os_random() % 1000000,
3973 wpa_supplicant_delayed_mic_error_report,
3974 wpa_s, NULL);
3975 } else {
3976 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3977 }
3978#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3979 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3980#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3981 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003982 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003983 wpa_s->mic_errors_seen++;
3984}
3985
3986
3987#ifdef CONFIG_TERMINATE_ONLASTIF
3988static int any_interfaces(struct wpa_supplicant *head)
3989{
3990 struct wpa_supplicant *wpa_s;
3991
3992 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3993 if (!wpa_s->interface_removed)
3994 return 1;
3995 return 0;
3996}
3997#endif /* CONFIG_TERMINATE_ONLASTIF */
3998
3999
4000static void
4001wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4002 union wpa_event_data *data)
4003{
4004 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4005 return;
4006
4007 switch (data->interface_status.ievent) {
4008 case EVENT_INTERFACE_ADDED:
4009 if (!wpa_s->interface_removed)
4010 break;
4011 wpa_s->interface_removed = 0;
4012 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4013 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4014 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4015 "driver after interface was added");
4016 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004017
4018#ifdef CONFIG_P2P
4019 if (!wpa_s->global->p2p &&
4020 !wpa_s->global->p2p_disabled &&
4021 !wpa_s->conf->p2p_disabled &&
4022 (wpa_s->drv_flags &
4023 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4024 wpas_p2p_add_p2pdev_interface(
4025 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4026 wpa_printf(MSG_INFO,
4027 "P2P: Failed to enable P2P Device interface");
4028 /* Try to continue without. P2P will be disabled. */
4029 }
4030#endif /* CONFIG_P2P */
4031
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004032 break;
4033 case EVENT_INTERFACE_REMOVED:
4034 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4035 wpa_s->interface_removed = 1;
4036 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004037 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004038 l2_packet_deinit(wpa_s->l2);
4039 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004040
4041#ifdef CONFIG_P2P
4042 if (wpa_s->global->p2p &&
4043 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4044 (wpa_s->drv_flags &
4045 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4046 wpa_dbg(wpa_s, MSG_DEBUG,
4047 "Removing P2P Device interface");
4048 wpa_supplicant_remove_iface(
4049 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4050 0);
4051 wpa_s->global->p2p_init_wpa_s = NULL;
4052 }
4053#endif /* CONFIG_P2P */
4054
Dmitry Shmidte4663042016-04-04 10:07:49 -07004055#ifdef CONFIG_MATCH_IFACE
4056 if (wpa_s->matched) {
4057 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4058 break;
4059 }
4060#endif /* CONFIG_MATCH_IFACE */
4061
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004062#ifdef CONFIG_TERMINATE_ONLASTIF
4063 /* check if last interface */
4064 if (!any_interfaces(wpa_s->global->ifaces))
4065 eloop_terminate();
4066#endif /* CONFIG_TERMINATE_ONLASTIF */
4067 break;
4068 }
4069}
4070
4071
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004072#ifdef CONFIG_TDLS
4073static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4074 union wpa_event_data *data)
4075{
4076 if (data == NULL)
4077 return;
4078 switch (data->tdls.oper) {
4079 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004080 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4081 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4082 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4083 else
4084 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004085 break;
4086 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004087 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4088 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4089 data->tdls.reason_code);
4090 else
4091 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4092 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004093 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004094 case TDLS_REQUEST_DISCOVER:
4095 wpa_tdls_send_discovery_request(wpa_s->wpa,
4096 data->tdls.peer);
4097 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004098 }
4099}
4100#endif /* CONFIG_TDLS */
4101
4102
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004103#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004104static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4105 union wpa_event_data *data)
4106{
4107 if (data == NULL)
4108 return;
4109 switch (data->wnm.oper) {
4110 case WNM_OPER_SLEEP:
4111 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4112 "(action=%d, intval=%d)",
4113 data->wnm.sleep_action, data->wnm.sleep_intval);
4114 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004115 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004116 break;
4117 }
4118}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004119#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004120
4121
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004122#ifdef CONFIG_IEEE80211R
4123static void
4124wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4125 union wpa_event_data *data)
4126{
4127 if (data == NULL)
4128 return;
4129
4130 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4131 data->ft_ies.ies_len,
4132 data->ft_ies.ft_action,
4133 data->ft_ies.target_ap,
4134 data->ft_ies.ric_ies,
4135 data->ft_ies.ric_ies_len) < 0) {
4136 /* TODO: prevent MLME/driver from trying to associate? */
4137 }
4138}
4139#endif /* CONFIG_IEEE80211R */
4140
4141
4142#ifdef CONFIG_IBSS_RSN
4143static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4144 union wpa_event_data *data)
4145{
4146 struct wpa_ssid *ssid;
4147 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4148 return;
4149 if (data == NULL)
4150 return;
4151 ssid = wpa_s->current_ssid;
4152 if (ssid == NULL)
4153 return;
4154 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4155 return;
4156
4157 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4158}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004159
4160
4161static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4162 union wpa_event_data *data)
4163{
4164 struct wpa_ssid *ssid = wpa_s->current_ssid;
4165
4166 if (ssid == NULL)
4167 return;
4168
4169 /* check if the ssid is correctly configured as IBSS/RSN */
4170 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4171 return;
4172
4173 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4174 data->rx_mgmt.frame_len);
4175}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004176#endif /* CONFIG_IBSS_RSN */
4177
4178
4179#ifdef CONFIG_IEEE80211R
4180static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4181 size_t len)
4182{
4183 const u8 *sta_addr, *target_ap_addr;
4184 u16 status;
4185
4186 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4187 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4188 return; /* only SME case supported for now */
4189 if (len < 1 + 2 * ETH_ALEN + 2)
4190 return;
4191 if (data[0] != 2)
4192 return; /* Only FT Action Response is supported for now */
4193 sta_addr = data + 1;
4194 target_ap_addr = data + 1 + ETH_ALEN;
4195 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4196 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4197 MACSTR " TargetAP " MACSTR " status %u",
4198 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4199
4200 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4201 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4202 " in FT Action Response", MAC2STR(sta_addr));
4203 return;
4204 }
4205
4206 if (status) {
4207 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4208 "failure (status code %d)", status);
4209 /* TODO: report error to FT code(?) */
4210 return;
4211 }
4212
4213 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4214 len - (1 + 2 * ETH_ALEN + 2), 1,
4215 target_ap_addr, NULL, 0) < 0)
4216 return;
4217
4218#ifdef CONFIG_SME
4219 {
4220 struct wpa_bss *bss;
4221 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4222 if (bss)
4223 wpa_s->sme.freq = bss->freq;
4224 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4225 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4226 WLAN_AUTH_FT);
4227 }
4228#endif /* CONFIG_SME */
4229}
4230#endif /* CONFIG_IEEE80211R */
4231
4232
4233static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4234 struct unprot_deauth *e)
4235{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004236 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4237 "dropped: " MACSTR " -> " MACSTR
4238 " (reason code %u)",
4239 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4240 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004241}
4242
4243
4244static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4245 struct unprot_disassoc *e)
4246{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004247 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4248 "dropped: " MACSTR " -> " MACSTR
4249 " (reason code %u)",
4250 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4251 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252}
4253
4254
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004255static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4256 u16 reason_code, int locally_generated,
4257 const u8 *ie, size_t ie_len, int deauth)
4258{
4259#ifdef CONFIG_AP
4260 if (wpa_s->ap_iface && addr) {
4261 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4262 return;
4263 }
4264
4265 if (wpa_s->ap_iface) {
4266 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4267 return;
4268 }
4269#endif /* CONFIG_AP */
4270
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004271 if (!locally_generated)
4272 wpa_s->own_disconnect_req = 0;
4273
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004274 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4275
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004276 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4277 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4278 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4279 eapol_sm_failed(wpa_s->eapol))) &&
4280 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004281 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004282
4283#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004284 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004285 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4286 locally_generated) > 0) {
4287 /*
4288 * The interface was removed, so cannot continue
4289 * processing any additional operations after this.
4290 */
4291 return;
4292 }
4293 }
4294#endif /* CONFIG_P2P */
4295
4296 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4297 locally_generated);
4298}
4299
4300
4301static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4302 struct disassoc_info *info)
4303{
4304 u16 reason_code = 0;
4305 int locally_generated = 0;
4306 const u8 *addr = NULL;
4307 const u8 *ie = NULL;
4308 size_t ie_len = 0;
4309
4310 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4311
4312 if (info) {
4313 addr = info->addr;
4314 ie = info->ie;
4315 ie_len = info->ie_len;
4316 reason_code = info->reason_code;
4317 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004318 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4319 reason2str(reason_code),
4320 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004321 if (addr)
4322 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4323 MAC2STR(addr));
4324 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4325 ie, ie_len);
4326 }
4327
4328#ifdef CONFIG_AP
4329 if (wpa_s->ap_iface && info && info->addr) {
4330 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4331 return;
4332 }
4333
4334 if (wpa_s->ap_iface) {
4335 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4336 return;
4337 }
4338#endif /* CONFIG_AP */
4339
4340#ifdef CONFIG_P2P
4341 if (info) {
4342 wpas_p2p_disassoc_notif(
4343 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4344 locally_generated);
4345 }
4346#endif /* CONFIG_P2P */
4347
4348 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4349 sme_event_disassoc(wpa_s, info);
4350
4351 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4352 ie, ie_len, 0);
4353}
4354
4355
4356static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4357 struct deauth_info *info)
4358{
4359 u16 reason_code = 0;
4360 int locally_generated = 0;
4361 const u8 *addr = NULL;
4362 const u8 *ie = NULL;
4363 size_t ie_len = 0;
4364
4365 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4366
4367 if (info) {
4368 addr = info->addr;
4369 ie = info->ie;
4370 ie_len = info->ie_len;
4371 reason_code = info->reason_code;
4372 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004373 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4374 reason_code, reason2str(reason_code),
4375 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004376 if (addr) {
4377 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4378 MAC2STR(addr));
4379 }
4380 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4381 ie, ie_len);
4382 }
4383
4384 wpa_reset_ft_completed(wpa_s->wpa);
4385
4386 wpas_event_disconnect(wpa_s, addr, reason_code,
4387 locally_generated, ie, ie_len, 1);
4388}
4389
4390
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004391static const char * reg_init_str(enum reg_change_initiator init)
4392{
4393 switch (init) {
4394 case REGDOM_SET_BY_CORE:
4395 return "CORE";
4396 case REGDOM_SET_BY_USER:
4397 return "USER";
4398 case REGDOM_SET_BY_DRIVER:
4399 return "DRIVER";
4400 case REGDOM_SET_BY_COUNTRY_IE:
4401 return "COUNTRY_IE";
4402 case REGDOM_BEACON_HINT:
4403 return "BEACON_HINT";
4404 }
4405 return "?";
4406}
4407
4408
4409static const char * reg_type_str(enum reg_type type)
4410{
4411 switch (type) {
4412 case REGDOM_TYPE_UNKNOWN:
4413 return "UNKNOWN";
4414 case REGDOM_TYPE_COUNTRY:
4415 return "COUNTRY";
4416 case REGDOM_TYPE_WORLD:
4417 return "WORLD";
4418 case REGDOM_TYPE_CUSTOM_WORLD:
4419 return "CUSTOM_WORLD";
4420 case REGDOM_TYPE_INTERSECTION:
4421 return "INTERSECTION";
4422 }
4423 return "?";
4424}
4425
4426
Hai Shalom74f70d42019-02-11 14:42:39 -08004427void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4428 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004429{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004430 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004431 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004432
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004433 /*
4434 * To allow backwards compatibility with higher level layers that
4435 * assumed the REGDOM_CHANGE event is sent over the initially added
4436 * interface. Find the highest parent of this interface and use it to
4437 * send the event.
4438 */
4439 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4440 ;
4441
Hai Shalom74f70d42019-02-11 14:42:39 -08004442 if (info) {
4443 wpa_msg(ifs, MSG_INFO,
4444 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4445 reg_init_str(info->initiator), reg_type_str(info->type),
4446 info->alpha2[0] ? " alpha2=" : "",
4447 info->alpha2[0] ? info->alpha2 : "");
4448 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004449
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004450 if (wpa_s->drv_priv == NULL)
4451 return; /* Ignore event during drv initialization */
4452
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004453 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4454 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004455 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4456 ifs->ifname);
4457 free_hw_features(ifs);
4458 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004459 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004460
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004461 /* Restart PNO/sched_scan with updated channel list */
4462 if (ifs->pno) {
4463 wpas_stop_pno(ifs);
4464 wpas_start_pno(ifs);
4465 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4466 wpa_dbg(ifs, MSG_DEBUG,
4467 "Channel list changed - restart sched_scan");
4468 wpas_scan_restart_sched_scan(ifs);
4469 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004470 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004471
4472 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004473}
4474
4475
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004476static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004477 const u8 *frame, size_t len, int freq,
4478 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004479{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004480 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004481 const u8 *payload;
4482 size_t plen;
4483 u8 category;
4484
4485 if (len < IEEE80211_HDRLEN + 2)
4486 return;
4487
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004488 mgmt = (const struct ieee80211_mgmt *) frame;
4489 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004490 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004491 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004492
4493 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4494 " Category=%u DataLen=%d freq=%d MHz",
4495 MAC2STR(mgmt->sa), category, (int) plen, freq);
4496
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004497 if (category == WLAN_ACTION_WMM) {
4498 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4499 return;
4500 }
4501
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004502#ifdef CONFIG_IEEE80211R
4503 if (category == WLAN_ACTION_FT) {
4504 ft_rx_action(wpa_s, payload, plen);
4505 return;
4506 }
4507#endif /* CONFIG_IEEE80211R */
4508
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004509#ifdef CONFIG_SME
4510 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004511 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004512 return;
4513 }
4514#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004515
4516#ifdef CONFIG_WNM
4517 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4518 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4519 return;
4520 }
4521#endif /* CONFIG_WNM */
4522
4523#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004524 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4525 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004526 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004527 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004528 payload, plen, freq) == 0)
4529 return;
4530#endif /* CONFIG_GAS */
4531
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004532#ifdef CONFIG_GAS_SERVER
4533 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4534 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4535 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4536 mgmt->u.action.category,
4537 payload, plen, freq) == 0)
4538 return;
4539#endif /* CONFIG_GAS_SERVER */
4540
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004541#ifdef CONFIG_TDLS
4542 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4543 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4544 wpa_dbg(wpa_s, MSG_DEBUG,
4545 "TDLS: Received Discovery Response from " MACSTR,
4546 MAC2STR(mgmt->sa));
4547 return;
4548 }
4549#endif /* CONFIG_TDLS */
4550
4551#ifdef CONFIG_INTERWORKING
4552 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4553 payload[0] == QOS_QOS_MAP_CONFIG) {
4554 const u8 *pos = payload + 1;
4555 size_t qlen = plen - 1;
4556 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4557 MACSTR, MAC2STR(mgmt->sa));
4558 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4559 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4560 pos[1] <= qlen - 2 && pos[1] >= 16)
4561 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4562 return;
4563 }
4564#endif /* CONFIG_INTERWORKING */
4565
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004566 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004567 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4568 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004569 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004570 payload + 1,
4571 plen - 1);
4572 return;
4573 }
4574
4575 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004576 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4577 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4578 return;
4579 }
4580
4581 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4582 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4583 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4584 payload + 1, plen - 1,
4585 rssi);
4586 return;
4587 }
4588
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004589#ifdef CONFIG_FST
4590 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4591 fst_rx_action(wpa_s->fst, mgmt, len);
4592 return;
4593 }
4594#endif /* CONFIG_FST */
4595
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004596#ifdef CONFIG_DPP
4597 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4598 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4599 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4600 payload[4] == DPP_OUI_TYPE) {
4601 payload++;
4602 plen--;
4603 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4604 return;
4605 }
4606#endif /* CONFIG_DPP */
4607
Hai Shalom899fcc72020-10-19 14:38:18 -07004608 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004609 payload[0] == ROBUST_AV_SCS_RESP) {
4610 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4611 payload + 1, plen - 1);
4612 return;
4613 }
4614
4615 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004616 payload[0] == ROBUST_AV_MSCS_RESP) {
4617 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4618 payload + 1, plen - 1);
4619 return;
4620 }
4621
Hai Shalomc1a21442022-02-04 13:43:00 -08004622 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4623 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4624 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4625 payload + 4, plen - 4);
4626 return;
4627 }
4628
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004629 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4630 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004631 if (wpa_s->ifmsh)
4632 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004633}
4634
4635
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004636static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4637 union wpa_event_data *event)
4638{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004639 struct wpa_freq_range_list *list;
4640 char *str = NULL;
4641
4642 list = &event->freq_range;
4643
4644 if (list->num)
4645 str = freq_range_list_str(list);
4646 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4647 str ? str : "");
4648
4649#ifdef CONFIG_P2P
4650 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4651 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4652 __func__);
4653 } else {
4654 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004655
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004656 /*
4657 * The update channel flow will also take care of moving a GO
4658 * from the unsafe frequency if needed.
4659 */
4660 wpas_p2p_update_channel_list(wpa_s,
4661 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004662 }
4663#endif /* CONFIG_P2P */
4664
4665 os_free(str);
4666}
4667
4668
Roshan Pius3a1667e2018-07-03 15:17:14 -07004669static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004670{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004671 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4672 wpa_supplicant_cancel_auth_timeout(wpa_s);
4673 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004674 eapol_sm_notify_portValid(wpa_s->eapol, true);
4675 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004676 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004677 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004678}
4679
4680
4681static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4682 int freq)
4683{
4684 size_t i;
4685 int j;
4686
4687 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4688 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4689
4690 for (j = 0; j < mode->num_channels; j++) {
4691 const struct hostapd_channel_data *chan;
4692
4693 chan = &mode->channels[j];
4694 if (chan->freq == freq)
4695 return chan->dfs_cac_ms;
4696 }
4697 }
4698
4699 return 0;
4700}
4701
4702
4703static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4704 struct dfs_event *radar)
4705{
4706#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004707 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004708 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4709 } else
4710#endif /* NEED_AP_MLME && CONFIG_AP */
4711 {
4712 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4713
4714 cac_time /= 1000; /* convert from ms to sec */
4715 if (!cac_time)
4716 cac_time = 10 * 60; /* max timeout: 10 minutes */
4717
4718 /* Restart auth timeout: CAC time added to initial timeout */
4719 wpas_auth_timeout_restart(wpa_s, cac_time);
4720 }
4721}
4722
4723
4724static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4725 struct dfs_event *radar)
4726{
4727#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004728 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004729 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4730 } else
4731#endif /* NEED_AP_MLME && CONFIG_AP */
4732 {
4733 /* Restart auth timeout with original value after CAC is
4734 * finished */
4735 wpas_auth_timeout_restart(wpa_s, 0);
4736 }
4737}
4738
4739
4740static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4741 struct dfs_event *radar)
4742{
4743#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004744 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004745 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4746 } else
4747#endif /* NEED_AP_MLME && CONFIG_AP */
4748 {
4749 /* Restart auth timeout with original value after CAC is
4750 * aborted */
4751 wpas_auth_timeout_restart(wpa_s, 0);
4752 }
4753}
4754
4755
4756static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4757 union wpa_event_data *data)
4758{
4759 wpa_dbg(wpa_s, MSG_DEBUG,
4760 "Connection authorized by device, previous state %d",
4761 wpa_s->wpa_state);
4762
4763 wpa_supplicant_event_port_authorized(wpa_s);
4764
Hai Shalomc1a21442022-02-04 13:43:00 -08004765 wpa_s->last_eapol_matches_bssid = 1;
4766
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004767 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4768 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004769 data->assoc_info.ptk_kck_len,
4770 data->assoc_info.ptk_kek,
4771 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004772#ifdef CONFIG_FILS
4773 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4774 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4775 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4776
4777 /* Update ERP next sequence number */
4778 eapol_sm_update_erp_next_seq_num(
4779 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4780
4781 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4782 /* Add the new PMK and PMKID to the PMKSA cache */
4783 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4784 data->assoc_info.fils_pmk,
4785 data->assoc_info.fils_pmk_len,
4786 data->assoc_info.fils_pmkid,
4787 wpa_s->bssid, fils_cache_id);
4788 } else if (data->assoc_info.fils_pmkid) {
4789 /* Update the current PMKSA used for this connection */
4790 pmksa_cache_set_current(wpa_s->wpa,
4791 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004792 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004793 }
4794 }
4795#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004796}
4797
4798
Hai Shalom60840252021-02-19 19:02:11 -08004799static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4800{
4801 switch (code) {
4802 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
4803 return "";
4804 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
4805 return "no_bss_found";
4806 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
4807 return "auth_tx_fail";
4808 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
4809 return "auth_no_ack_received";
4810 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
4811 return "auth_no_resp_received";
4812 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
4813 return "assoc_req_tx_fail";
4814 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
4815 return "assoc_no_ack_received";
4816 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
4817 return "assoc_no_resp_received";
4818 default:
4819 return "unknown_reason";
4820 }
4821}
4822
4823
Roshan Pius3a1667e2018-07-03 15:17:14 -07004824static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4825 union wpa_event_data *data)
4826{
4827 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004828#ifdef CONFIG_MBO
4829 struct wpa_bss *reject_bss;
4830#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004831
4832 if (!bssid || is_zero_ether_addr(bssid))
4833 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004834#ifdef CONFIG_MBO
4835 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4836 reject_bss = wpa_s->current_bss;
4837 else
4838 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4839#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004840
4841 if (data->assoc_reject.bssid)
4842 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004843 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004844 MAC2STR(data->assoc_reject.bssid),
4845 data->assoc_reject.status_code,
4846 data->assoc_reject.timed_out ? " timeout" : "",
4847 data->assoc_reject.timeout_reason ? "=" : "",
4848 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004849 data->assoc_reject.timeout_reason : "",
4850 data->assoc_reject.reason_code !=
4851 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4852 " qca_driver_reason=" : "",
4853 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004854 else
4855 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004856 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004857 data->assoc_reject.status_code,
4858 data->assoc_reject.timed_out ? " timeout" : "",
4859 data->assoc_reject.timeout_reason ? "=" : "",
4860 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004861 data->assoc_reject.timeout_reason : "",
4862 data->assoc_reject.reason_code !=
4863 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4864 " qca_driver_reason=" : "",
4865 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004866 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08004867 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
4868 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004869
4870#ifdef CONFIG_OWE
4871 if (data->assoc_reject.status_code ==
4872 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4873 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4874 wpa_s->current_ssid &&
4875 wpa_s->current_ssid->owe_group == 0 &&
4876 wpa_s->last_owe_group != 21) {
4877 struct wpa_ssid *ssid = wpa_s->current_ssid;
4878 struct wpa_bss *bss = wpa_s->current_bss;
4879
4880 if (!bss) {
4881 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4882 if (!bss) {
4883 wpas_connection_failed(wpa_s, bssid);
4884 wpa_supplicant_mark_disassoc(wpa_s);
4885 return;
4886 }
4887 }
4888 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4889 wpas_connect_work_done(wpa_s);
4890 wpa_supplicant_mark_disassoc(wpa_s);
4891 wpa_supplicant_connect(wpa_s, bss, ssid);
4892 return;
4893 }
4894#endif /* CONFIG_OWE */
4895
Hai Shalomfdcde762020-04-02 11:19:20 -07004896#ifdef CONFIG_DPP2
4897 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4898 * the status code defined in the DPP R2 tech spec.
4899 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4900 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004901 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004902 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4903 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4904 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004905 wpa_s->current_ssid->dpp_pfs == 0 &&
4906 (data->assoc_reject.status_code ==
4907 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4908 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4909 struct wpa_ssid *ssid = wpa_s->current_ssid;
4910 struct wpa_bss *bss = wpa_s->current_bss;
4911
4912 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4913 if (!bss)
4914 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4915 if (!bss || wpa_s->dpp_pfs_fallback) {
4916 wpa_printf(MSG_DEBUG,
4917 "DPP: Updated PFS policy for next try");
4918 wpas_connection_failed(wpa_s, bssid);
4919 wpa_supplicant_mark_disassoc(wpa_s);
4920 return;
4921 }
4922 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4923 wpa_s->dpp_pfs_fallback = 1;
4924 wpas_connect_work_done(wpa_s);
4925 wpa_supplicant_mark_disassoc(wpa_s);
4926 wpa_supplicant_connect(wpa_s, bss, ssid);
4927 return;
4928 }
4929#endif /* CONFIG_DPP2 */
4930
Hai Shalom74f70d42019-02-11 14:42:39 -08004931#ifdef CONFIG_MBO
4932 if (data->assoc_reject.status_code ==
4933 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004934 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004935 const u8 *rssi_rej;
4936
4937 rssi_rej = mbo_get_attr_from_ies(
4938 data->assoc_reject.resp_ies,
4939 data->assoc_reject.resp_ies_len,
4940 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4941 if (rssi_rej && rssi_rej[1] == 2) {
4942 wpa_printf(MSG_DEBUG,
4943 "OCE: RSSI-based association rejection from "
4944 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004945 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004946 rssi_rej[2], rssi_rej[3]);
4947 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004948 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004949 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004950 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004951 }
4952 }
4953#endif /* CONFIG_MBO */
4954
Roshan Pius3a1667e2018-07-03 15:17:14 -07004955 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4956 sme_event_assoc_reject(wpa_s, data);
4957 return;
4958 }
4959
4960 /* Driver-based SME cases */
4961
4962#ifdef CONFIG_SAE
4963 if (wpa_s->current_ssid &&
4964 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4965 !data->assoc_reject.timed_out) {
4966 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4967 wpa_sm_aborted_cached(wpa_s->wpa);
4968 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4969 }
4970#endif /* CONFIG_SAE */
4971
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004972#ifdef CONFIG_DPP
4973 if (wpa_s->current_ssid &&
4974 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4975 !data->assoc_reject.timed_out) {
4976 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4977 wpa_sm_aborted_cached(wpa_s->wpa);
4978 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4979 }
4980#endif /* CONFIG_DPP */
4981
Roshan Pius3a1667e2018-07-03 15:17:14 -07004982#ifdef CONFIG_FILS
4983 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004984 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004985 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004986 eapol_sm_update_erp_next_seq_num(
4987 wpa_s->eapol,
4988 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004989 fils_connection_failure(wpa_s);
4990 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004991#endif /* CONFIG_FILS */
4992
4993 wpas_connection_failed(wpa_s, bssid);
4994 wpa_supplicant_mark_disassoc(wpa_s);
4995}
4996
4997
Hai Shalomfdcde762020-04-02 11:19:20 -07004998static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
4999 struct unprot_beacon *data)
5000{
5001 struct wpabuf *buf;
5002 int res;
5003
5004 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5005 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5006 return;
5007 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5008 MAC2STR(data->sa));
5009
5010 buf = wpabuf_alloc(4);
5011 if (!buf)
5012 return;
5013
5014 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5015 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5016 wpabuf_put_u8(buf, 1); /* Dialog Token */
5017 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5018
5019 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5020 wpa_s->own_addr, wpa_s->bssid,
5021 wpabuf_head(buf), wpabuf_len(buf), 0);
5022 if (res < 0)
5023 wpa_printf(MSG_DEBUG,
5024 "Failed to send WNM-Notification Request frame");
5025
5026 wpabuf_free(buf);
5027}
5028
5029
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005030void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5031 union wpa_event_data *data)
5032{
5033 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005034 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005035 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005036#ifndef CONFIG_NO_STDOUT_DEBUG
5037 int level = MSG_DEBUG;
5038#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005039
5040 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5041 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005042 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005043 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005044 event != EVENT_SCHED_SCAN_STOPPED) {
5045 wpa_dbg(wpa_s, MSG_DEBUG,
5046 "Ignore event %s (%d) while interface is disabled",
5047 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005048 return;
5049 }
5050
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005051#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005052 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005053 const struct ieee80211_hdr *hdr;
5054 u16 fc;
5055 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5056 fc = le_to_host16(hdr->frame_control);
5057 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5058 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5059 level = MSG_EXCESSIVE;
5060 }
5061
5062 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5063 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005064#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005065
5066 switch (event) {
5067 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005068#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005069 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5070 data->auth.ies_len))
5071 wpa_printf(MSG_DEBUG,
5072 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005073#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005074 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005075 wpa_s->auth_status_code = data->auth.status_code;
5076 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005077 break;
5078 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005079#ifdef CONFIG_TESTING_OPTIONS
5080 if (wpa_s->ignore_auth_resp) {
5081 wpa_printf(MSG_INFO,
5082 "EVENT_ASSOC - ignore_auth_resp active!");
5083 break;
5084 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005085 if (wpa_s->testing_resend_assoc) {
5086 wpa_printf(MSG_INFO,
5087 "EVENT_DEAUTH - testing_resend_assoc");
5088 break;
5089 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005090#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305091 if (wpa_s->disconnected) {
5092 wpa_printf(MSG_INFO,
5093 "Ignore unexpected EVENT_ASSOC in disconnected state");
5094 break;
5095 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005096 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005097 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005098 if (data &&
5099 (data->assoc_info.authorized ||
5100 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5101 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005102 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005103 if (data) {
5104 wpa_msg(wpa_s, MSG_INFO,
5105 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5106 data->assoc_info.subnet_status);
5107 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005108 break;
5109 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005110 wpas_event_disassoc(wpa_s,
5111 data ? &data->disassoc_info : NULL);
5112 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005113 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005114#ifdef CONFIG_TESTING_OPTIONS
5115 if (wpa_s->ignore_auth_resp) {
5116 wpa_printf(MSG_INFO,
5117 "EVENT_DEAUTH - ignore_auth_resp active!");
5118 break;
5119 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005120 if (wpa_s->testing_resend_assoc) {
5121 wpa_printf(MSG_INFO,
5122 "EVENT_DEAUTH - testing_resend_assoc");
5123 break;
5124 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005125#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005126 wpas_event_deauth(wpa_s,
5127 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005128 break;
5129 case EVENT_MICHAEL_MIC_FAILURE:
5130 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5131 break;
5132#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005133 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005134 if (wpa_s->own_scan_requested ||
5135 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005136 struct os_reltime diff;
5137
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005138 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005139 os_reltime_sub(&wpa_s->scan_start_time,
5140 &wpa_s->scan_trigger_time, &diff);
5141 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5142 diff.sec, diff.usec);
5143 wpa_s->own_scan_requested = 0;
5144 wpa_s->own_scan_running = 1;
5145 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5146 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005147 wpa_msg_ctrl(wpa_s, MSG_INFO,
5148 WPA_EVENT_SCAN_STARTED "id=%u",
5149 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005150 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005151 wpa_msg_ctrl(wpa_s, MSG_INFO,
5152 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005153 }
5154 } else {
5155 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005156 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005157 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005158 }
5159 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005160 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005161 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5162 wpa_s->scan_res_handler = NULL;
5163 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005164 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005165 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5166 break;
5167 }
5168
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005169 if (!(data && data->scan_info.external_scan) &&
5170 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005171 struct os_reltime now, diff;
5172 os_get_reltime(&now);
5173 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5174 wpa_s->scan_start_time.sec = 0;
5175 wpa_s->scan_start_time.usec = 0;
5176 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5177 diff.sec, diff.usec);
5178 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005179 if (wpa_supplicant_event_scan_results(wpa_s, data))
5180 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005181 if (!(data && data->scan_info.external_scan))
5182 wpa_s->own_scan_running = 0;
5183 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005184 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005185 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005186 break;
5187#endif /* CONFIG_NO_SCAN_PROCESSING */
5188 case EVENT_ASSOCINFO:
5189 wpa_supplicant_event_associnfo(wpa_s, data);
5190 break;
5191 case EVENT_INTERFACE_STATUS:
5192 wpa_supplicant_event_interface_status(wpa_s, data);
5193 break;
5194 case EVENT_PMKID_CANDIDATE:
5195 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5196 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005197#ifdef CONFIG_TDLS
5198 case EVENT_TDLS:
5199 wpa_supplicant_event_tdls(wpa_s, data);
5200 break;
5201#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005202#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005203 case EVENT_WNM:
5204 wpa_supplicant_event_wnm(wpa_s, data);
5205 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005206#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005207#ifdef CONFIG_IEEE80211R
5208 case EVENT_FT_RESPONSE:
5209 wpa_supplicant_event_ft_response(wpa_s, data);
5210 break;
5211#endif /* CONFIG_IEEE80211R */
5212#ifdef CONFIG_IBSS_RSN
5213 case EVENT_IBSS_RSN_START:
5214 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5215 break;
5216#endif /* CONFIG_IBSS_RSN */
5217 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005218 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005219 break;
5220 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005221 /* It is possible to get this event from earlier connection */
5222 if (wpa_s->current_ssid &&
5223 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5224 wpa_dbg(wpa_s, MSG_DEBUG,
5225 "Ignore AUTH_TIMED_OUT in mesh configuration");
5226 break;
5227 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005228 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5229 sme_event_auth_timed_out(wpa_s, data);
5230 break;
5231 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005232 /* It is possible to get this event from earlier connection */
5233 if (wpa_s->current_ssid &&
5234 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5235 wpa_dbg(wpa_s, MSG_DEBUG,
5236 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5237 break;
5238 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005239 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5240 sme_event_assoc_timed_out(wpa_s, data);
5241 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005242 case EVENT_TX_STATUS:
5243 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5244 " type=%d stype=%d",
5245 MAC2STR(data->tx_status.dst),
5246 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005247#ifdef CONFIG_PASN
5248 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5249 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5250 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5251 data->tx_status.data_len,
5252 data->tx_status.ack) == 0)
5253 break;
5254#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005255#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005256 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005257#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005258 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5259 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005260 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005261 wpa_s, data->tx_status.dst,
5262 data->tx_status.data,
5263 data->tx_status.data_len,
5264 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005265 OFFCHANNEL_SEND_ACTION_SUCCESS :
5266 OFFCHANNEL_SEND_ACTION_NO_ACK);
5267#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005268 break;
5269 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005270#endif /* CONFIG_AP */
5271#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005272 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005273 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005274 /*
5275 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005276 * interface in GO mode, or via standalone AP interface.
5277 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5278 * except when the primary interface is used as a GO interface
5279 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005280 */
5281 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5282 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005283 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005284 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005285 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005286 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005287 data->tx_status.data,
5288 data->tx_status.data_len,
5289 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005290 OFFCHANNEL_SEND_ACTION_SUCCESS :
5291 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005292 break;
5293 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005294#endif /* CONFIG_OFFCHANNEL */
5295#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005296 switch (data->tx_status.type) {
5297 case WLAN_FC_TYPE_MGMT:
5298 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5299 data->tx_status.data_len,
5300 data->tx_status.stype,
5301 data->tx_status.ack);
5302 break;
5303 case WLAN_FC_TYPE_DATA:
5304 ap_tx_status(wpa_s, data->tx_status.dst,
5305 data->tx_status.data,
5306 data->tx_status.data_len,
5307 data->tx_status.ack);
5308 break;
5309 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005310#endif /* CONFIG_AP */
5311 break;
5312#ifdef CONFIG_AP
5313 case EVENT_EAPOL_TX_STATUS:
5314 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5315 data->eapol_tx_status.data,
5316 data->eapol_tx_status.data_len,
5317 data->eapol_tx_status.ack);
5318 break;
5319 case EVENT_DRIVER_CLIENT_POLL_OK:
5320 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005321 break;
5322 case EVENT_RX_FROM_UNKNOWN:
5323 if (wpa_s->ap_iface == NULL)
5324 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005325 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5326 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005327 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005328#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005329
5330 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005331 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005332 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005333 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005334
Hai Shalom81f62d82019-07-22 12:10:00 -07005335 wpa_msg(wpa_s, MSG_INFO,
5336 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5337 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5338 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005339 data->ch_switch.freq,
5340 data->ch_switch.ht_enabled,
5341 data->ch_switch.ch_offset,
5342 channel_width_to_string(data->ch_switch.ch_width),
5343 data->ch_switch.cf1,
5344 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005345 if (event == EVENT_CH_SWITCH_STARTED)
5346 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005347
Sunil Ravi65a724b2022-05-24 11:06:09 -07005348 if (wpa_s->assoc_freq && data->ch_switch.freq &&
5349 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
5350 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
5351 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005352 wpa_s->assoc_freq = data->ch_switch.freq;
5353 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005354 if (wpa_s->current_bss &&
5355 wpa_s->current_bss->freq != data->ch_switch.freq) {
5356 wpa_s->current_bss->freq = data->ch_switch.freq;
5357 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5358 wpa_s->current_bss);
5359 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005360
Hai Shalomfdcde762020-04-02 11:19:20 -07005361#ifdef CONFIG_SME
5362 switch (data->ch_switch.ch_offset) {
5363 case 1:
5364 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5365 break;
5366 case -1:
5367 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5368 break;
5369 default:
5370 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5371 break;
5372 }
5373#endif /* CONFIG_SME */
5374
Roshan Pius3a1667e2018-07-03 15:17:14 -07005375#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005376 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5377 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005378 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005379 wpa_s->current_ssid->mode ==
5380 WPAS_MODE_P2P_GROUP_FORMATION) {
5381 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5382 data->ch_switch.ht_enabled,
5383 data->ch_switch.ch_offset,
5384 data->ch_switch.ch_width,
5385 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005386 data->ch_switch.cf2,
5387 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005388 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005389#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005390
Hai Shalom899fcc72020-10-19 14:38:18 -07005391 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5392 sme_event_ch_switch(wpa_s);
5393
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005394 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005395 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005396 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005397#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005398#ifdef NEED_AP_MLME
5399 case EVENT_DFS_RADAR_DETECTED:
5400 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005401 wpas_ap_event_dfs_radar_detected(wpa_s,
5402 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005403 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005404 case EVENT_DFS_NOP_FINISHED:
5405 if (data)
5406 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5407 &data->dfs_event);
5408 break;
5409#endif /* NEED_AP_MLME */
5410#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005411 case EVENT_DFS_CAC_STARTED:
5412 if (data)
5413 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5414 break;
5415 case EVENT_DFS_CAC_FINISHED:
5416 if (data)
5417 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5418 break;
5419 case EVENT_DFS_CAC_ABORTED:
5420 if (data)
5421 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5422 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005423 case EVENT_RX_MGMT: {
5424 u16 fc, stype;
5425 const struct ieee80211_mgmt *mgmt;
5426
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005427#ifdef CONFIG_TESTING_OPTIONS
5428 if (wpa_s->ext_mgmt_frame_handling) {
5429 struct rx_mgmt *rx = &data->rx_mgmt;
5430 size_t hex_len = 2 * rx->frame_len + 1;
5431 char *hex = os_malloc(hex_len);
5432 if (hex) {
5433 wpa_snprintf_hex(hex, hex_len,
5434 rx->frame, rx->frame_len);
5435 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5436 rx->freq, rx->datarate, rx->ssi_signal,
5437 hex);
5438 os_free(hex);
5439 }
5440 break;
5441 }
5442#endif /* CONFIG_TESTING_OPTIONS */
5443
Dmitry Shmidt04949592012-07-19 12:16:46 -07005444 mgmt = (const struct ieee80211_mgmt *)
5445 data->rx_mgmt.frame;
5446 fc = le_to_host16(mgmt->frame_control);
5447 stype = WLAN_FC_GET_STYPE(fc);
5448
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005449#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005450 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005451#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005452#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005453 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005454 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005455 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005456 const u8 *ie;
5457 size_t ie_len;
5458
5459 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5460 ie_len = data->rx_mgmt.frame_len -
5461 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005462 wpas_p2p_probe_req_rx(
5463 wpa_s, src, mgmt->da,
5464 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005465 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005466 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005467 break;
5468 }
5469#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005470#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005471 if (wpa_s->current_ssid &&
5472 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5473 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005474 data->rx_mgmt.frame_len >= 30) {
5475 wpa_supplicant_event_ibss_auth(wpa_s, data);
5476 break;
5477 }
5478#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005479
5480 if (stype == WLAN_FC_STYPE_ACTION) {
5481 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005482 wpa_s, data->rx_mgmt.frame,
5483 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005484 data->rx_mgmt.freq,
5485 data->rx_mgmt.ssi_signal);
5486 break;
5487 }
5488
5489 if (wpa_s->ifmsh) {
5490 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005491 break;
5492 }
Hai Shalom60840252021-02-19 19:02:11 -08005493#ifdef CONFIG_PASN
5494 if (stype == WLAN_FC_STYPE_AUTH &&
5495 wpas_pasn_auth_rx(wpa_s, mgmt,
5496 data->rx_mgmt.frame_len) != -2)
5497 break;
5498#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005499
Roshan Pius3a1667e2018-07-03 15:17:14 -07005500#ifdef CONFIG_SAE
5501 if (stype == WLAN_FC_STYPE_AUTH &&
5502 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5503 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5504 sme_external_auth_mgmt_rx(
5505 wpa_s, data->rx_mgmt.frame,
5506 data->rx_mgmt.frame_len);
5507 break;
5508 }
5509#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005510 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5511 "management frame in non-AP mode");
5512 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005513#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005514 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005515
5516 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005517 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5518 const u8 *ie;
5519 size_t ie_len;
5520
5521 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5522 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005523
5524 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5525 mgmt->bssid, ie, ie_len,
5526 data->rx_mgmt.ssi_signal);
5527 }
5528
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005529 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005530#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005531 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005532 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005533 case EVENT_RX_PROBE_REQ:
5534 if (data->rx_probe_req.sa == NULL ||
5535 data->rx_probe_req.ie == NULL)
5536 break;
5537#ifdef CONFIG_AP
5538 if (wpa_s->ap_iface) {
5539 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5540 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005541 data->rx_probe_req.da,
5542 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005543 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005544 data->rx_probe_req.ie_len,
5545 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005546 break;
5547 }
5548#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005549 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005550 data->rx_probe_req.da,
5551 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005552 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005553 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005554 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005555 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005556 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005557 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005558#ifdef CONFIG_OFFCHANNEL
5559 offchannel_remain_on_channel_cb(
5560 wpa_s, data->remain_on_channel.freq,
5561 data->remain_on_channel.duration);
5562#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005563 wpas_p2p_remain_on_channel_cb(
5564 wpa_s, data->remain_on_channel.freq,
5565 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005566#ifdef CONFIG_DPP
5567 wpas_dpp_remain_on_channel_cb(
5568 wpa_s, data->remain_on_channel.freq,
5569 data->remain_on_channel.duration);
5570#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005571 break;
5572 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005573#ifdef CONFIG_OFFCHANNEL
5574 offchannel_cancel_remain_on_channel_cb(
5575 wpa_s, data->remain_on_channel.freq);
5576#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005577 wpas_p2p_cancel_remain_on_channel_cb(
5578 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005579#ifdef CONFIG_DPP
5580 wpas_dpp_cancel_remain_on_channel_cb(
5581 wpa_s, data->remain_on_channel.freq);
5582#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005583 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005584 case EVENT_EAPOL_RX:
5585 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5586 data->eapol_rx.data,
5587 data->eapol_rx.data_len);
5588 break;
5589 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005590 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5591 "above=%d signal=%d noise=%d txrate=%d",
5592 data->signal_change.above_threshold,
5593 data->signal_change.current_signal,
5594 data->signal_change.current_noise,
5595 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005596 wpa_bss_update_level(wpa_s->current_bss,
5597 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005598 bgscan_notify_signal_change(
5599 wpa_s, data->signal_change.above_threshold,
5600 data->signal_change.current_signal,
5601 data->signal_change.current_noise,
5602 data->signal_change.current_txrate);
5603 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005604 case EVENT_INTERFACE_MAC_CHANGED:
5605 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005606 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005607 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005608 case EVENT_INTERFACE_ENABLED:
5609 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5610 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005611 u8 addr[ETH_ALEN];
5612
Hai Shalomfdcde762020-04-02 11:19:20 -07005613 eloop_cancel_timeout(wpas_clear_disabled_interface,
5614 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005615 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005616 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005617 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5618 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5619 else
5620 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005621 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005622 if (wpa_s->p2p_mgmt) {
5623 wpa_supplicant_set_state(wpa_s,
5624 WPA_DISCONNECTED);
5625 break;
5626 }
5627
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005628#ifdef CONFIG_AP
5629 if (!wpa_s->ap_iface) {
5630 wpa_supplicant_set_state(wpa_s,
5631 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005632 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005633 wpa_supplicant_req_scan(wpa_s, 0, 0);
5634 } else
5635 wpa_supplicant_set_state(wpa_s,
5636 WPA_COMPLETED);
5637#else /* CONFIG_AP */
5638 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5639 wpa_supplicant_req_scan(wpa_s, 0, 0);
5640#endif /* CONFIG_AP */
5641 }
5642 break;
5643 case EVENT_INTERFACE_DISABLED:
5644 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005645#ifdef CONFIG_P2P
5646 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5647 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5648 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5649 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005650 * Mark interface disabled if this happens to end up not
5651 * being removed as a separate P2P group interface.
5652 */
5653 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5654 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005655 * The interface was externally disabled. Remove
5656 * it assuming an external entity will start a
5657 * new session if needed.
5658 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005659 if (wpa_s->current_ssid &&
5660 wpa_s->current_ssid->p2p_group)
5661 wpas_p2p_interface_unavailable(wpa_s);
5662 else
5663 wpas_p2p_disconnect(wpa_s);
5664 /*
5665 * wpa_s instance may have been freed, so must not use
5666 * it here anymore.
5667 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005668 break;
5669 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005670 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5671 p2p_in_progress(wpa_s->global->p2p) > 1) {
5672 /* This radio work will be cancelled, so clear P2P
5673 * state as well.
5674 */
5675 p2p_stop_find(wpa_s->global->p2p);
5676 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005677#endif /* CONFIG_P2P */
5678
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005679 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5680 /*
5681 * Indicate disconnection to keep ctrl_iface events
5682 * consistent.
5683 */
5684 wpa_supplicant_event_disassoc(
5685 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5686 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005687 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005688 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005689 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5690 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005691 clear_at.usec = 0;
5692 } else {
5693 struct os_reltime tmp;
5694
Hai Shalom60840252021-02-19 19:02:11 -08005695 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005696 tmp.usec = 0;
5697 os_reltime_sub(&tmp, &age, &clear_at);
5698 }
5699 eloop_register_timeout(clear_at.sec, clear_at.usec,
5700 wpas_clear_disabled_interface,
5701 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005702 radio_remove_works(wpa_s, NULL, 0);
5703
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005704 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5705 break;
5706 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005707 wpa_supplicant_update_channel_list(
5708 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005709 break;
5710 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005711 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005712 break;
5713 case EVENT_BEST_CHANNEL:
5714 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5715 "(%d %d %d)",
5716 data->best_chan.freq_24, data->best_chan.freq_5,
5717 data->best_chan.freq_overall);
5718 wpa_s->best_24_freq = data->best_chan.freq_24;
5719 wpa_s->best_5_freq = data->best_chan.freq_5;
5720 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005721 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5722 data->best_chan.freq_5,
5723 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005724 break;
5725 case EVENT_UNPROT_DEAUTH:
5726 wpa_supplicant_event_unprot_deauth(wpa_s,
5727 &data->unprot_deauth);
5728 break;
5729 case EVENT_UNPROT_DISASSOC:
5730 wpa_supplicant_event_unprot_disassoc(wpa_s,
5731 &data->unprot_disassoc);
5732 break;
5733 case EVENT_STATION_LOW_ACK:
5734#ifdef CONFIG_AP
5735 if (wpa_s->ap_iface && data)
5736 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5737 data->low_ack.addr);
5738#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005739#ifdef CONFIG_TDLS
5740 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005741 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5742 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005743#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005744 break;
5745 case EVENT_IBSS_PEER_LOST:
5746#ifdef CONFIG_IBSS_RSN
5747 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5748#endif /* CONFIG_IBSS_RSN */
5749 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005750 case EVENT_DRIVER_GTK_REKEY:
5751 if (os_memcmp(data->driver_gtk_rekey.bssid,
5752 wpa_s->bssid, ETH_ALEN))
5753 break;
5754 if (!wpa_s->wpa)
5755 break;
5756 wpa_sm_update_replay_ctr(wpa_s->wpa,
5757 data->driver_gtk_rekey.replay_ctr);
5758 break;
5759 case EVENT_SCHED_SCAN_STOPPED:
5760 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005761 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005762 wpa_supplicant_notify_scanning(wpa_s, 0);
5763
5764 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5765 break;
5766
5767 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005768 * If the driver stopped scanning without being requested to,
5769 * request a new scan to continue scanning for networks.
5770 */
5771 if (!wpa_s->sched_scan_stop_req &&
5772 wpa_s->wpa_state == WPA_SCANNING) {
5773 wpa_dbg(wpa_s, MSG_DEBUG,
5774 "Restart scanning after unexpected sched_scan stop event");
5775 wpa_supplicant_req_scan(wpa_s, 1, 0);
5776 break;
5777 }
5778
5779 wpa_s->sched_scan_stop_req = 0;
5780
5781 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005782 * Start a new sched scan to continue searching for more SSIDs
5783 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005784 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005785 if (wpa_s->sched_scan_timed_out) {
5786 wpa_supplicant_req_sched_scan(wpa_s);
5787 } else if (wpa_s->pno_sched_pending) {
5788 wpa_s->pno_sched_pending = 0;
5789 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005790 } else if (resched) {
5791 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005792 }
5793
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005794 break;
5795 case EVENT_WPS_BUTTON_PUSHED:
5796#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005797 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005798#endif /* CONFIG_WPS */
5799 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005800 case EVENT_AVOID_FREQUENCIES:
5801 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5802 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005803 case EVENT_CONNECT_FAILED_REASON:
5804#ifdef CONFIG_AP
5805 if (!wpa_s->ap_iface || !data)
5806 break;
5807 hostapd_event_connect_failed_reason(
5808 wpa_s->ap_iface->bss[0],
5809 data->connect_failed_reason.addr,
5810 data->connect_failed_reason.code);
5811#endif /* CONFIG_AP */
5812 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005813 case EVENT_NEW_PEER_CANDIDATE:
5814#ifdef CONFIG_MESH
5815 if (!wpa_s->ifmsh || !data)
5816 break;
5817 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5818 data->mesh_peer.ies,
5819 data->mesh_peer.ie_len);
5820#endif /* CONFIG_MESH */
5821 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005822 case EVENT_SURVEY:
5823#ifdef CONFIG_AP
5824 if (!wpa_s->ap_iface)
5825 break;
5826 hostapd_event_get_survey(wpa_s->ap_iface,
5827 &data->survey_results);
5828#endif /* CONFIG_AP */
5829 break;
5830 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005831#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005832#ifdef CONFIG_ACS
5833 if (!wpa_s->ap_iface)
5834 break;
5835 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5836 &data->acs_selected_channels);
5837#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005838#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005839 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005840 case EVENT_P2P_LO_STOP:
5841#ifdef CONFIG_P2P
5842 wpa_s->p2p_lo_started = 0;
5843 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5844 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5845 data->p2p_lo_stop.reason_code);
5846#endif /* CONFIG_P2P */
5847 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005848 case EVENT_BEACON_LOSS:
5849 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5850 break;
5851 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5852 bgscan_notify_beacon_loss(wpa_s);
5853 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005854 case EVENT_EXTERNAL_AUTH:
5855#ifdef CONFIG_SAE
5856 if (!wpa_s->current_ssid) {
5857 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5858 break;
5859 }
5860 sme_external_auth_trigger(wpa_s, data);
5861#endif /* CONFIG_SAE */
5862 break;
5863 case EVENT_PORT_AUTHORIZED:
5864 wpa_supplicant_event_port_authorized(wpa_s);
5865 break;
5866 case EVENT_STATION_OPMODE_CHANGED:
5867#ifdef CONFIG_AP
5868 if (!wpa_s->ap_iface || !data)
5869 break;
5870
5871 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5872 data->sta_opmode.addr,
5873 data->sta_opmode.smps_mode,
5874 data->sta_opmode.chan_width,
5875 data->sta_opmode.rx_nss);
5876#endif /* CONFIG_AP */
5877 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005878 case EVENT_UNPROT_BEACON:
5879 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5880 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08005881 case EVENT_TX_WAIT_EXPIRE:
5882#ifdef CONFIG_DPP
5883 wpas_dpp_tx_wait_expire(wpa_s);
5884#endif /* CONFIG_DPP */
5885 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005886 default:
5887 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5888 break;
5889 }
5890}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005891
5892
5893void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5894 union wpa_event_data *data)
5895{
5896 struct wpa_supplicant *wpa_s;
5897
5898 if (event != EVENT_INTERFACE_STATUS)
5899 return;
5900
5901 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5902 if (wpa_s && wpa_s->driver->get_ifindex) {
5903 unsigned int ifindex;
5904
5905 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5906 if (ifindex != data->interface_status.ifindex) {
5907 wpa_dbg(wpa_s, MSG_DEBUG,
5908 "interface status ifindex %d mismatch (%d)",
5909 ifindex, data->interface_status.ifindex);
5910 return;
5911 }
5912 }
5913#ifdef CONFIG_MATCH_IFACE
5914 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5915 struct wpa_interface *wpa_i;
5916
5917 wpa_i = wpa_supplicant_match_iface(
5918 ctx, data->interface_status.ifname);
5919 if (!wpa_i)
5920 return;
5921 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5922 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07005923 }
5924#endif /* CONFIG_MATCH_IFACE */
5925
5926 if (wpa_s)
5927 wpa_supplicant_event(wpa_s, event, data);
5928}