blob: 35467ce9518238950504e406441d1673d33eca69 [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 */
Andy Kuoaba17c12022-04-14 16:05:31 +08003184#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
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 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003192#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
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 */
Andy Kuoaba17c12022-04-14 16:05:31 +08003355#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303356 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003357#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
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
Andy Kuoaba17c12022-04-14 16:05:31 +08003375#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303376 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 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003394#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303395
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
Andy Kuoaba17c12022-04-14 16:05:31 +08003414#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303415 /* 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 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003422#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3423
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003424 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003425 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003426 if (os_reltime_initialized(&wpa_s->session_start)) {
3427 os_reltime_age(&wpa_s->session_start,
3428 &wpa_s->session_length);
3429 wpa_s->session_start.sec = 0;
3430 wpa_s->session_start.usec = 0;
3431 wpas_notify_session_length(wpa_s);
3432 } else {
3433 wpas_notify_auth_changed(wpa_s);
3434 os_get_reltime(&wpa_s->session_start);
3435 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003436 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3437 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003438 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003439 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003440 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3441 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003442 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003443
3444 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3445 wpa_clear_keys(wpa_s, bssid);
3446 }
3447 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003448 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003449 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3450 return;
3451 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003452 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003453
Hai Shalomc1a21442022-02-04 13:43:00 -08003454 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3455 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3456 return;
3457
Hai Shalomfdcde762020-04-02 11:19:20 -07003458 multi_ap_set_4addr_mode(wpa_s);
3459
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003460 if (wpa_s->conf->ap_scan == 1 &&
3461 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003462 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3463 wpa_msg(wpa_s, MSG_WARNING,
3464 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003465 }
3466
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003467 wpas_fst_update_mb_assoc(wpa_s, data);
3468
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003469#ifdef CONFIG_SME
3470 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3471 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003472 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003473#endif /* CONFIG_SME */
3474
3475 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3476 if (wpa_s->current_ssid) {
3477 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3478 * initialized before association, but for other modes,
3479 * initialize PC/SC here, if the current configuration needs
3480 * smartcard or SIM/USIM. */
3481 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3482 }
3483 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3484 if (wpa_s->l2)
3485 l2_packet_notify_auth_start(wpa_s->l2);
3486
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003487 already_authorized = data && data->assoc_info.authorized;
3488
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003489 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003490 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003491 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3492 * state machine may transit to AUTHENTICATING state based on obsolete
3493 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3494 * AUTHENTICATED without ever giving chance to EAP state machine to
3495 * reset the state.
3496 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003497 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003498 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3499 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003500 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003501 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3502 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3503 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003504 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003505 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003506 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003507 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003508 wpa_s->eapol_received = 0;
3509 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3510 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3511 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003512 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003513 if (wpa_s->current_ssid &&
3514 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003515 (wpa_s->drv_flags &
3516 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3517 /*
3518 * Set the key after having received joined-IBSS event
3519 * from the driver.
3520 */
3521 wpa_supplicant_set_wpa_none_key(wpa_s,
3522 wpa_s->current_ssid);
3523 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003524 wpa_supplicant_cancel_auth_timeout(wpa_s);
3525 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3526 } else if (!ft_completed) {
3527 /* Timeout for receiving the first EAPOL packet */
3528 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3529 }
3530 wpa_supplicant_cancel_scan(wpa_s);
3531
Hai Shalom5f92bc92019-04-18 11:54:11 -07003532 if (ft_completed) {
3533 /*
3534 * FT protocol completed - make sure EAPOL state machine ends
3535 * up in authenticated.
3536 */
3537 wpa_supplicant_cancel_auth_timeout(wpa_s);
3538 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003539 eapol_sm_notify_portValid(wpa_s->eapol, true);
3540 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003541 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3542 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003543 /*
3544 * We are done; the driver will take care of RSN 4-way
3545 * handshake.
3546 */
3547 wpa_supplicant_cancel_auth_timeout(wpa_s);
3548 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003549 eapol_sm_notify_portValid(wpa_s->eapol, true);
3550 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003551 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003552 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3553 /*
3554 * The driver will take care of RSN 4-way handshake, so we need
3555 * to allow EAPOL supplicant to complete its work without
3556 * waiting for WPA supplicant.
3557 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003558 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003559 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003560#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303561 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3562 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3563 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3564 wpa_s->key_mgmt);
3565 wpa_supplicant_deauthenticate(
3566 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3567 return;
3568 }
3569 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3570 wpa_s->assoc_freq = data->assoc_info.freq;
3571 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3572 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003573#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3574
Jouni Malinena05074c2012-12-21 21:35:35 +02003575 wpa_s->last_eapol_matches_bssid = 0;
3576
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003577#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003578 if (wpa_s->rsne_override_eapol) {
3579 wpa_printf(MSG_DEBUG,
3580 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3581 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3582 wpabuf_head(wpa_s->rsne_override_eapol),
3583 wpabuf_len(wpa_s->rsne_override_eapol));
3584 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003585 if (wpa_s->rsnxe_override_eapol) {
3586 wpa_printf(MSG_DEBUG,
3587 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3588 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3589 wpabuf_head(wpa_s->rsnxe_override_eapol),
3590 wpabuf_len(wpa_s->rsnxe_override_eapol));
3591 }
3592#endif /* CONFIG_TESTING_OPTIONS */
3593
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003594 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003595 struct os_reltime now, age;
3596 os_get_reltime(&now);
3597 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003598 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003599 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3600 0) {
3601 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3602 "frame that was received just before "
3603 "association notification");
3604 wpa_supplicant_rx_eapol(
3605 wpa_s, wpa_s->pending_eapol_rx_src,
3606 wpabuf_head(wpa_s->pending_eapol_rx),
3607 wpabuf_len(wpa_s->pending_eapol_rx));
3608 }
3609 wpabuf_free(wpa_s->pending_eapol_rx);
3610 wpa_s->pending_eapol_rx = NULL;
3611 }
3612
Hai Shalomfdcde762020-04-02 11:19:20 -07003613#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003614 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3615 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003616 wpa_s->current_ssid &&
3617 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003618 /* Set static WEP keys again */
3619 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3620 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003621#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003622
3623#ifdef CONFIG_IBSS_RSN
3624 if (wpa_s->current_ssid &&
3625 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3626 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3627 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3628 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003629 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003630 if (!wpa_s->ibss_rsn) {
3631 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3632 wpa_supplicant_deauthenticate(
3633 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3634 return;
3635 }
3636
3637 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3638 }
3639#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003640
3641 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003642
3643 if (data) {
3644 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3645 data->assoc_info.resp_ies_len,
3646 &data->assoc_info.wmm_params);
3647
3648 if (wpa_s->reassoc_same_bss)
3649 wmm_ac_restore_tspecs(wpa_s);
3650 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003651
Hai Shalomc3565922019-10-28 11:58:20 -07003652#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3653 bss = wpa_bss_get_bssid(wpa_s, bssid);
3654#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003655#ifdef CONFIG_FILS
3656 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003657 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3658
3659 if (fils_cache_id)
3660 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3661 }
3662#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003663
3664#ifdef CONFIG_MBO
3665 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3666#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003667
3668#ifdef CONFIG_DPP2
3669 wpa_s->dpp_pfs_fallback = 0;
3670#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003671}
3672
3673
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003674static int disconnect_reason_recoverable(u16 reason_code)
3675{
3676 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3677 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3678 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3679}
3680
3681
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003682static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003683 u16 reason_code,
3684 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003685{
3686 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003687
3688 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3689 /*
3690 * At least Host AP driver and a Prism3 card seemed to be
3691 * generating streams of disconnected events when configuring
3692 * IBSS for WPA-None. Ignore them for now.
3693 */
3694 return;
3695 }
3696
3697 bssid = wpa_s->bssid;
3698 if (is_zero_ether_addr(bssid))
3699 bssid = wpa_s->pending_bssid;
3700
3701 if (!is_zero_ether_addr(bssid) ||
3702 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3703 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3704 " reason=%d%s",
3705 MAC2STR(bssid), reason_code,
3706 locally_generated ? " locally_generated=1" : "");
3707 }
3708}
3709
3710
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003711static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3712 int locally_generated)
3713{
3714 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003715 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003716 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3717 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003718 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003719
3720 /*
3721 * It looks like connection was lost while trying to go through PSK
3722 * 4-way handshake. Filter out known disconnection cases that are caused
3723 * by something else than PSK mismatch to avoid confusing reports.
3724 */
3725
3726 if (locally_generated) {
3727 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3728 return 0;
3729 }
3730
3731 return 1;
3732}
3733
3734
Jouni Malinen2b89da82012-08-31 22:04:41 +03003735static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3736 u16 reason_code,
3737 int locally_generated)
3738{
3739 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003740 int authenticating;
3741 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003742 struct wpa_bss *fast_reconnect = NULL;
3743 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003744 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003745 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003746
3747 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3748 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3749
3750 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3751 /*
3752 * At least Host AP driver and a Prism3 card seemed to be
3753 * generating streams of disconnected events when configuring
3754 * IBSS for WPA-None. Ignore them for now.
3755 */
3756 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3757 "IBSS/WPA-None mode");
3758 return;
3759 }
3760
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003761 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3762 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3763 locally_generated)
3764 /*
3765 * Remove the inactive AP (which is probably out of range) from
3766 * the BSS list after marking disassociation. In particular
3767 * mac80211-based drivers use the
3768 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3769 * locally generated disconnection events for cases where the
3770 * AP does not reply anymore.
3771 */
3772 curr = wpa_s->current_bss;
3773
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003774 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003775 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3776 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003777 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3778 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003779 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003780#ifdef CONFIG_DPP2
3781 wpas_dpp_send_conn_status_result(wpa_s,
3782 DPP_STATUS_AUTH_FAILURE);
3783#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003784 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003785 if (!wpa_s->disconnected &&
3786 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003787 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003788 wpas_wps_searching(wpa_s) ||
3789 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003790 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003791 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003792 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003793 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003794 wpa_s->wpa_state);
3795 if (wpa_s->wpa_state == WPA_COMPLETED &&
3796 wpa_s->current_ssid &&
3797 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003798 (wpa_s->own_reconnect_req ||
3799 (!locally_generated &&
3800 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003801 /*
3802 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003803 * us, but could allow us to get back in. This is also
3804 * triggered for cases where local reconnection request
3805 * is used to force reassociation with the same BSS.
3806 * Try to reconnect to the same BSS without a full scan
3807 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003808 */
3809 fast_reconnect = wpa_s->current_bss;
3810 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003811 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003812 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003813 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003814 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3815 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003816 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003817 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003818 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003819 "try to re-connect");
3820 wpa_s->reassociate = 0;
3821 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003822 if (!wpa_s->pno)
3823 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003824 }
3825 bssid = wpa_s->bssid;
3826 if (is_zero_ether_addr(bssid))
3827 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003828 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3829 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003830 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08003831 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
3832
Dmitry Shmidt04949592012-07-19 12:16:46 -07003833 if (locally_generated)
3834 wpa_s->disconnect_reason = -reason_code;
3835 else
3836 wpa_s->disconnect_reason = reason_code;
3837 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003838 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3839 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003840 wpa_clear_keys(wpa_s, wpa_s->bssid);
3841 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003842 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003843 wpa_supplicant_mark_disassoc(wpa_s);
3844
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003845 if (curr)
3846 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3847
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003848 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003849 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003850 wpa_s->current_ssid = last_ssid;
3851 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003852
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003853 if (fast_reconnect &&
3854 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3855 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3856 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3857 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003858 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003859 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003860#ifndef CONFIG_NO_SCAN_PROCESSING
3861 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3862 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3863 fast_reconnect_ssid) < 0) {
3864 /* Recover through full scan */
3865 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3866 }
3867#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003868 } else if (fast_reconnect) {
3869 /*
3870 * Could not reconnect to the same BSS due to network being
3871 * disabled. Use a new scan to match the alternative behavior
3872 * above, i.e., to continue automatic reconnection attempt in a
3873 * way that enforces disabled network rules.
3874 */
3875 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003876 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003877}
3878
3879
3880#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003881void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003882{
3883 struct wpa_supplicant *wpa_s = eloop_ctx;
3884
3885 if (!wpa_s->pending_mic_error_report)
3886 return;
3887
3888 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3889 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3890 wpa_s->pending_mic_error_report = 0;
3891}
3892#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3893
3894
3895static void
3896wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3897 union wpa_event_data *data)
3898{
3899 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003900 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003901
3902 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3903 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003904 os_get_reltime(&t);
3905 if ((wpa_s->last_michael_mic_error.sec &&
3906 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003907 wpa_s->pending_mic_error_report) {
3908 if (wpa_s->pending_mic_error_report) {
3909 /*
3910 * Send the pending MIC error report immediately since
3911 * we are going to start countermeasures and AP better
3912 * do the same.
3913 */
3914 wpa_sm_key_request(wpa_s->wpa, 1,
3915 wpa_s->pending_mic_error_pairwise);
3916 }
3917
3918 /* Send the new MIC error report immediately since we are going
3919 * to start countermeasures and AP better do the same.
3920 */
3921 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3922
3923 /* initialize countermeasures */
3924 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003925
Hai Shalom60840252021-02-19 19:02:11 -08003926 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003927
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003928 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3929
3930 /*
3931 * Need to wait for completion of request frame. We do not get
3932 * any callback for the message completion, so just wait a
3933 * short while and hope for the best. */
3934 os_sleep(0, 10000);
3935
3936 wpa_drv_set_countermeasures(wpa_s, 1);
3937 wpa_supplicant_deauthenticate(wpa_s,
3938 WLAN_REASON_MICHAEL_MIC_FAILURE);
3939 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3940 wpa_s, NULL);
3941 eloop_register_timeout(60, 0,
3942 wpa_supplicant_stop_countermeasures,
3943 wpa_s, NULL);
3944 /* TODO: mark the AP rejected for 60 second. STA is
3945 * allowed to associate with another AP.. */
3946 } else {
3947#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3948 if (wpa_s->mic_errors_seen) {
3949 /*
3950 * Reduce the effectiveness of Michael MIC error
3951 * reports as a means for attacking against TKIP if
3952 * more than one MIC failure is noticed with the same
3953 * PTK. We delay the transmission of the reports by a
3954 * random time between 0 and 60 seconds in order to
3955 * force the attacker wait 60 seconds before getting
3956 * the information on whether a frame resulted in a MIC
3957 * failure.
3958 */
3959 u8 rval[4];
3960 int sec;
3961
3962 if (os_get_random(rval, sizeof(rval)) < 0)
3963 sec = os_random() % 60;
3964 else
3965 sec = WPA_GET_BE32(rval) % 60;
3966 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3967 "report %d seconds", sec);
3968 wpa_s->pending_mic_error_report = 1;
3969 wpa_s->pending_mic_error_pairwise = pairwise;
3970 eloop_cancel_timeout(
3971 wpa_supplicant_delayed_mic_error_report,
3972 wpa_s, NULL);
3973 eloop_register_timeout(
3974 sec, os_random() % 1000000,
3975 wpa_supplicant_delayed_mic_error_report,
3976 wpa_s, NULL);
3977 } else {
3978 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3979 }
3980#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3981 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3982#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3983 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003984 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003985 wpa_s->mic_errors_seen++;
3986}
3987
3988
3989#ifdef CONFIG_TERMINATE_ONLASTIF
3990static int any_interfaces(struct wpa_supplicant *head)
3991{
3992 struct wpa_supplicant *wpa_s;
3993
3994 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3995 if (!wpa_s->interface_removed)
3996 return 1;
3997 return 0;
3998}
3999#endif /* CONFIG_TERMINATE_ONLASTIF */
4000
4001
4002static void
4003wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4004 union wpa_event_data *data)
4005{
4006 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4007 return;
4008
4009 switch (data->interface_status.ievent) {
4010 case EVENT_INTERFACE_ADDED:
4011 if (!wpa_s->interface_removed)
4012 break;
4013 wpa_s->interface_removed = 0;
4014 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4015 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4016 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4017 "driver after interface was added");
4018 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004019
4020#ifdef CONFIG_P2P
4021 if (!wpa_s->global->p2p &&
4022 !wpa_s->global->p2p_disabled &&
4023 !wpa_s->conf->p2p_disabled &&
4024 (wpa_s->drv_flags &
4025 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4026 wpas_p2p_add_p2pdev_interface(
4027 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4028 wpa_printf(MSG_INFO,
4029 "P2P: Failed to enable P2P Device interface");
4030 /* Try to continue without. P2P will be disabled. */
4031 }
4032#endif /* CONFIG_P2P */
4033
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004034 break;
4035 case EVENT_INTERFACE_REMOVED:
4036 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4037 wpa_s->interface_removed = 1;
4038 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004039 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004040 l2_packet_deinit(wpa_s->l2);
4041 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004042
4043#ifdef CONFIG_P2P
4044 if (wpa_s->global->p2p &&
4045 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4046 (wpa_s->drv_flags &
4047 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4048 wpa_dbg(wpa_s, MSG_DEBUG,
4049 "Removing P2P Device interface");
4050 wpa_supplicant_remove_iface(
4051 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4052 0);
4053 wpa_s->global->p2p_init_wpa_s = NULL;
4054 }
4055#endif /* CONFIG_P2P */
4056
Dmitry Shmidte4663042016-04-04 10:07:49 -07004057#ifdef CONFIG_MATCH_IFACE
4058 if (wpa_s->matched) {
4059 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4060 break;
4061 }
4062#endif /* CONFIG_MATCH_IFACE */
4063
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004064#ifdef CONFIG_TERMINATE_ONLASTIF
4065 /* check if last interface */
4066 if (!any_interfaces(wpa_s->global->ifaces))
4067 eloop_terminate();
4068#endif /* CONFIG_TERMINATE_ONLASTIF */
4069 break;
4070 }
4071}
4072
4073
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004074#ifdef CONFIG_TDLS
4075static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4076 union wpa_event_data *data)
4077{
4078 if (data == NULL)
4079 return;
4080 switch (data->tdls.oper) {
4081 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004082 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4083 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4084 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4085 else
4086 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004087 break;
4088 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004089 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4090 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4091 data->tdls.reason_code);
4092 else
4093 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4094 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004095 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004096 case TDLS_REQUEST_DISCOVER:
4097 wpa_tdls_send_discovery_request(wpa_s->wpa,
4098 data->tdls.peer);
4099 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004100 }
4101}
4102#endif /* CONFIG_TDLS */
4103
4104
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004105#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004106static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4107 union wpa_event_data *data)
4108{
4109 if (data == NULL)
4110 return;
4111 switch (data->wnm.oper) {
4112 case WNM_OPER_SLEEP:
4113 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4114 "(action=%d, intval=%d)",
4115 data->wnm.sleep_action, data->wnm.sleep_intval);
4116 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004117 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004118 break;
4119 }
4120}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004121#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004122
4123
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004124#ifdef CONFIG_IEEE80211R
4125static void
4126wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4127 union wpa_event_data *data)
4128{
4129 if (data == NULL)
4130 return;
4131
4132 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4133 data->ft_ies.ies_len,
4134 data->ft_ies.ft_action,
4135 data->ft_ies.target_ap,
4136 data->ft_ies.ric_ies,
4137 data->ft_ies.ric_ies_len) < 0) {
4138 /* TODO: prevent MLME/driver from trying to associate? */
4139 }
4140}
4141#endif /* CONFIG_IEEE80211R */
4142
4143
4144#ifdef CONFIG_IBSS_RSN
4145static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4146 union wpa_event_data *data)
4147{
4148 struct wpa_ssid *ssid;
4149 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4150 return;
4151 if (data == NULL)
4152 return;
4153 ssid = wpa_s->current_ssid;
4154 if (ssid == NULL)
4155 return;
4156 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4157 return;
4158
4159 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4160}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004161
4162
4163static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4164 union wpa_event_data *data)
4165{
4166 struct wpa_ssid *ssid = wpa_s->current_ssid;
4167
4168 if (ssid == NULL)
4169 return;
4170
4171 /* check if the ssid is correctly configured as IBSS/RSN */
4172 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4173 return;
4174
4175 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4176 data->rx_mgmt.frame_len);
4177}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004178#endif /* CONFIG_IBSS_RSN */
4179
4180
4181#ifdef CONFIG_IEEE80211R
4182static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4183 size_t len)
4184{
4185 const u8 *sta_addr, *target_ap_addr;
4186 u16 status;
4187
4188 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4189 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4190 return; /* only SME case supported for now */
4191 if (len < 1 + 2 * ETH_ALEN + 2)
4192 return;
4193 if (data[0] != 2)
4194 return; /* Only FT Action Response is supported for now */
4195 sta_addr = data + 1;
4196 target_ap_addr = data + 1 + ETH_ALEN;
4197 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4198 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4199 MACSTR " TargetAP " MACSTR " status %u",
4200 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4201
4202 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4203 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4204 " in FT Action Response", MAC2STR(sta_addr));
4205 return;
4206 }
4207
4208 if (status) {
4209 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4210 "failure (status code %d)", status);
4211 /* TODO: report error to FT code(?) */
4212 return;
4213 }
4214
4215 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4216 len - (1 + 2 * ETH_ALEN + 2), 1,
4217 target_ap_addr, NULL, 0) < 0)
4218 return;
4219
4220#ifdef CONFIG_SME
4221 {
4222 struct wpa_bss *bss;
4223 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4224 if (bss)
4225 wpa_s->sme.freq = bss->freq;
4226 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4227 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4228 WLAN_AUTH_FT);
4229 }
4230#endif /* CONFIG_SME */
4231}
4232#endif /* CONFIG_IEEE80211R */
4233
4234
4235static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4236 struct unprot_deauth *e)
4237{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004238 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4239 "dropped: " MACSTR " -> " MACSTR
4240 " (reason code %u)",
4241 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4242 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004243}
4244
4245
4246static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4247 struct unprot_disassoc *e)
4248{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004249 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4250 "dropped: " MACSTR " -> " MACSTR
4251 " (reason code %u)",
4252 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4253 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004254}
4255
4256
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004257static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4258 u16 reason_code, int locally_generated,
4259 const u8 *ie, size_t ie_len, int deauth)
4260{
4261#ifdef CONFIG_AP
4262 if (wpa_s->ap_iface && addr) {
4263 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4264 return;
4265 }
4266
4267 if (wpa_s->ap_iface) {
4268 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4269 return;
4270 }
4271#endif /* CONFIG_AP */
4272
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004273 if (!locally_generated)
4274 wpa_s->own_disconnect_req = 0;
4275
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004276 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4277
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004278 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4279 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4280 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4281 eapol_sm_failed(wpa_s->eapol))) &&
4282 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004283 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004284
4285#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004286 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004287 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4288 locally_generated) > 0) {
4289 /*
4290 * The interface was removed, so cannot continue
4291 * processing any additional operations after this.
4292 */
4293 return;
4294 }
4295 }
4296#endif /* CONFIG_P2P */
4297
4298 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4299 locally_generated);
4300}
4301
4302
4303static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4304 struct disassoc_info *info)
4305{
4306 u16 reason_code = 0;
4307 int locally_generated = 0;
4308 const u8 *addr = NULL;
4309 const u8 *ie = NULL;
4310 size_t ie_len = 0;
4311
4312 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4313
4314 if (info) {
4315 addr = info->addr;
4316 ie = info->ie;
4317 ie_len = info->ie_len;
4318 reason_code = info->reason_code;
4319 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004320 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4321 reason2str(reason_code),
4322 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004323 if (addr)
4324 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4325 MAC2STR(addr));
4326 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4327 ie, ie_len);
4328 }
4329
4330#ifdef CONFIG_AP
4331 if (wpa_s->ap_iface && info && info->addr) {
4332 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4333 return;
4334 }
4335
4336 if (wpa_s->ap_iface) {
4337 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4338 return;
4339 }
4340#endif /* CONFIG_AP */
4341
4342#ifdef CONFIG_P2P
4343 if (info) {
4344 wpas_p2p_disassoc_notif(
4345 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4346 locally_generated);
4347 }
4348#endif /* CONFIG_P2P */
4349
4350 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4351 sme_event_disassoc(wpa_s, info);
4352
4353 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4354 ie, ie_len, 0);
4355}
4356
4357
4358static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4359 struct deauth_info *info)
4360{
4361 u16 reason_code = 0;
4362 int locally_generated = 0;
4363 const u8 *addr = NULL;
4364 const u8 *ie = NULL;
4365 size_t ie_len = 0;
4366
4367 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4368
4369 if (info) {
4370 addr = info->addr;
4371 ie = info->ie;
4372 ie_len = info->ie_len;
4373 reason_code = info->reason_code;
4374 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004375 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4376 reason_code, reason2str(reason_code),
4377 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004378 if (addr) {
4379 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4380 MAC2STR(addr));
4381 }
4382 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4383 ie, ie_len);
4384 }
4385
4386 wpa_reset_ft_completed(wpa_s->wpa);
4387
4388 wpas_event_disconnect(wpa_s, addr, reason_code,
4389 locally_generated, ie, ie_len, 1);
4390}
4391
4392
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004393static const char * reg_init_str(enum reg_change_initiator init)
4394{
4395 switch (init) {
4396 case REGDOM_SET_BY_CORE:
4397 return "CORE";
4398 case REGDOM_SET_BY_USER:
4399 return "USER";
4400 case REGDOM_SET_BY_DRIVER:
4401 return "DRIVER";
4402 case REGDOM_SET_BY_COUNTRY_IE:
4403 return "COUNTRY_IE";
4404 case REGDOM_BEACON_HINT:
4405 return "BEACON_HINT";
4406 }
4407 return "?";
4408}
4409
4410
4411static const char * reg_type_str(enum reg_type type)
4412{
4413 switch (type) {
4414 case REGDOM_TYPE_UNKNOWN:
4415 return "UNKNOWN";
4416 case REGDOM_TYPE_COUNTRY:
4417 return "COUNTRY";
4418 case REGDOM_TYPE_WORLD:
4419 return "WORLD";
4420 case REGDOM_TYPE_CUSTOM_WORLD:
4421 return "CUSTOM_WORLD";
4422 case REGDOM_TYPE_INTERSECTION:
4423 return "INTERSECTION";
4424 }
4425 return "?";
4426}
4427
4428
Hai Shalom74f70d42019-02-11 14:42:39 -08004429void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4430 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004431{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004432 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004433 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004434
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004435 /*
4436 * To allow backwards compatibility with higher level layers that
4437 * assumed the REGDOM_CHANGE event is sent over the initially added
4438 * interface. Find the highest parent of this interface and use it to
4439 * send the event.
4440 */
4441 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4442 ;
4443
Hai Shalom74f70d42019-02-11 14:42:39 -08004444 if (info) {
4445 wpa_msg(ifs, MSG_INFO,
4446 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4447 reg_init_str(info->initiator), reg_type_str(info->type),
4448 info->alpha2[0] ? " alpha2=" : "",
4449 info->alpha2[0] ? info->alpha2 : "");
4450 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004451
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004452 if (wpa_s->drv_priv == NULL)
4453 return; /* Ignore event during drv initialization */
4454
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004455 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4456 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004457 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4458 ifs->ifname);
4459 free_hw_features(ifs);
4460 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004461 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004462
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004463 /* Restart PNO/sched_scan with updated channel list */
4464 if (ifs->pno) {
4465 wpas_stop_pno(ifs);
4466 wpas_start_pno(ifs);
4467 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4468 wpa_dbg(ifs, MSG_DEBUG,
4469 "Channel list changed - restart sched_scan");
4470 wpas_scan_restart_sched_scan(ifs);
4471 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004472 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004473
4474 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004475}
4476
4477
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004478static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004479 const u8 *frame, size_t len, int freq,
4480 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004481{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004482 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004483 const u8 *payload;
4484 size_t plen;
4485 u8 category;
4486
4487 if (len < IEEE80211_HDRLEN + 2)
4488 return;
4489
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004490 mgmt = (const struct ieee80211_mgmt *) frame;
4491 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004492 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004493 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004494
4495 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4496 " Category=%u DataLen=%d freq=%d MHz",
4497 MAC2STR(mgmt->sa), category, (int) plen, freq);
4498
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004499 if (category == WLAN_ACTION_WMM) {
4500 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4501 return;
4502 }
4503
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004504#ifdef CONFIG_IEEE80211R
4505 if (category == WLAN_ACTION_FT) {
4506 ft_rx_action(wpa_s, payload, plen);
4507 return;
4508 }
4509#endif /* CONFIG_IEEE80211R */
4510
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004511#ifdef CONFIG_SME
4512 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004513 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004514 return;
4515 }
4516#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004517
4518#ifdef CONFIG_WNM
4519 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4520 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4521 return;
4522 }
4523#endif /* CONFIG_WNM */
4524
4525#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004526 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4527 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004528 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004529 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004530 payload, plen, freq) == 0)
4531 return;
4532#endif /* CONFIG_GAS */
4533
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004534#ifdef CONFIG_GAS_SERVER
4535 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4536 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4537 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4538 mgmt->u.action.category,
4539 payload, plen, freq) == 0)
4540 return;
4541#endif /* CONFIG_GAS_SERVER */
4542
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004543#ifdef CONFIG_TDLS
4544 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4545 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4546 wpa_dbg(wpa_s, MSG_DEBUG,
4547 "TDLS: Received Discovery Response from " MACSTR,
4548 MAC2STR(mgmt->sa));
4549 return;
4550 }
4551#endif /* CONFIG_TDLS */
4552
4553#ifdef CONFIG_INTERWORKING
4554 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4555 payload[0] == QOS_QOS_MAP_CONFIG) {
4556 const u8 *pos = payload + 1;
4557 size_t qlen = plen - 1;
4558 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4559 MACSTR, MAC2STR(mgmt->sa));
4560 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4561 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4562 pos[1] <= qlen - 2 && pos[1] >= 16)
4563 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4564 return;
4565 }
4566#endif /* CONFIG_INTERWORKING */
4567
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004568 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004569 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4570 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004571 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004572 payload + 1,
4573 plen - 1);
4574 return;
4575 }
4576
4577 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004578 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4579 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4580 return;
4581 }
4582
4583 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4584 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4585 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4586 payload + 1, plen - 1,
4587 rssi);
4588 return;
4589 }
4590
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004591#ifdef CONFIG_FST
4592 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4593 fst_rx_action(wpa_s->fst, mgmt, len);
4594 return;
4595 }
4596#endif /* CONFIG_FST */
4597
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004598#ifdef CONFIG_DPP
4599 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4600 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4601 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4602 payload[4] == DPP_OUI_TYPE) {
4603 payload++;
4604 plen--;
4605 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4606 return;
4607 }
4608#endif /* CONFIG_DPP */
4609
Hai Shalom899fcc72020-10-19 14:38:18 -07004610 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004611 payload[0] == ROBUST_AV_SCS_RESP) {
4612 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4613 payload + 1, plen - 1);
4614 return;
4615 }
4616
4617 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004618 payload[0] == ROBUST_AV_MSCS_RESP) {
4619 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4620 payload + 1, plen - 1);
4621 return;
4622 }
4623
Hai Shalomc1a21442022-02-04 13:43:00 -08004624 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4625 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4626 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4627 payload + 4, plen - 4);
4628 return;
4629 }
4630
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004631 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4632 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004633 if (wpa_s->ifmsh)
4634 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004635}
4636
4637
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004638static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4639 union wpa_event_data *event)
4640{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004641 struct wpa_freq_range_list *list;
4642 char *str = NULL;
4643
4644 list = &event->freq_range;
4645
4646 if (list->num)
4647 str = freq_range_list_str(list);
4648 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4649 str ? str : "");
4650
4651#ifdef CONFIG_P2P
4652 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4653 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4654 __func__);
4655 } else {
4656 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004657
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004658 /*
4659 * The update channel flow will also take care of moving a GO
4660 * from the unsafe frequency if needed.
4661 */
4662 wpas_p2p_update_channel_list(wpa_s,
4663 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004664 }
4665#endif /* CONFIG_P2P */
4666
4667 os_free(str);
4668}
4669
4670
Roshan Pius3a1667e2018-07-03 15:17:14 -07004671static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004672{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004673 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4674 wpa_supplicant_cancel_auth_timeout(wpa_s);
4675 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004676 eapol_sm_notify_portValid(wpa_s->eapol, true);
4677 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004678 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004679 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004680}
4681
4682
4683static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4684 int freq)
4685{
4686 size_t i;
4687 int j;
4688
4689 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4690 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4691
4692 for (j = 0; j < mode->num_channels; j++) {
4693 const struct hostapd_channel_data *chan;
4694
4695 chan = &mode->channels[j];
4696 if (chan->freq == freq)
4697 return chan->dfs_cac_ms;
4698 }
4699 }
4700
4701 return 0;
4702}
4703
4704
4705static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4706 struct dfs_event *radar)
4707{
4708#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004709 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004710 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4711 } else
4712#endif /* NEED_AP_MLME && CONFIG_AP */
4713 {
4714 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4715
4716 cac_time /= 1000; /* convert from ms to sec */
4717 if (!cac_time)
4718 cac_time = 10 * 60; /* max timeout: 10 minutes */
4719
4720 /* Restart auth timeout: CAC time added to initial timeout */
4721 wpas_auth_timeout_restart(wpa_s, cac_time);
4722 }
4723}
4724
4725
4726static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4727 struct dfs_event *radar)
4728{
4729#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004730 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004731 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4732 } else
4733#endif /* NEED_AP_MLME && CONFIG_AP */
4734 {
4735 /* Restart auth timeout with original value after CAC is
4736 * finished */
4737 wpas_auth_timeout_restart(wpa_s, 0);
4738 }
4739}
4740
4741
4742static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4743 struct dfs_event *radar)
4744{
4745#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004746 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004747 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4748 } else
4749#endif /* NEED_AP_MLME && CONFIG_AP */
4750 {
4751 /* Restart auth timeout with original value after CAC is
4752 * aborted */
4753 wpas_auth_timeout_restart(wpa_s, 0);
4754 }
4755}
4756
4757
4758static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4759 union wpa_event_data *data)
4760{
4761 wpa_dbg(wpa_s, MSG_DEBUG,
4762 "Connection authorized by device, previous state %d",
4763 wpa_s->wpa_state);
4764
4765 wpa_supplicant_event_port_authorized(wpa_s);
4766
Hai Shalomc1a21442022-02-04 13:43:00 -08004767 wpa_s->last_eapol_matches_bssid = 1;
4768
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004769 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4770 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004771 data->assoc_info.ptk_kck_len,
4772 data->assoc_info.ptk_kek,
4773 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004774#ifdef CONFIG_FILS
4775 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4776 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4777 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4778
4779 /* Update ERP next sequence number */
4780 eapol_sm_update_erp_next_seq_num(
4781 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4782
4783 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4784 /* Add the new PMK and PMKID to the PMKSA cache */
4785 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4786 data->assoc_info.fils_pmk,
4787 data->assoc_info.fils_pmk_len,
4788 data->assoc_info.fils_pmkid,
4789 wpa_s->bssid, fils_cache_id);
4790 } else if (data->assoc_info.fils_pmkid) {
4791 /* Update the current PMKSA used for this connection */
4792 pmksa_cache_set_current(wpa_s->wpa,
4793 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004794 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004795 }
4796 }
4797#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004798}
4799
4800
Hai Shalom60840252021-02-19 19:02:11 -08004801static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4802{
4803 switch (code) {
4804 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
4805 return "";
4806 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
4807 return "no_bss_found";
4808 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
4809 return "auth_tx_fail";
4810 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
4811 return "auth_no_ack_received";
4812 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
4813 return "auth_no_resp_received";
4814 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
4815 return "assoc_req_tx_fail";
4816 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
4817 return "assoc_no_ack_received";
4818 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
4819 return "assoc_no_resp_received";
4820 default:
4821 return "unknown_reason";
4822 }
4823}
4824
4825
Roshan Pius3a1667e2018-07-03 15:17:14 -07004826static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4827 union wpa_event_data *data)
4828{
4829 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004830#ifdef CONFIG_MBO
4831 struct wpa_bss *reject_bss;
4832#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004833
4834 if (!bssid || is_zero_ether_addr(bssid))
4835 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004836#ifdef CONFIG_MBO
4837 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4838 reject_bss = wpa_s->current_bss;
4839 else
4840 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4841#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004842
4843 if (data->assoc_reject.bssid)
4844 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004845 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004846 MAC2STR(data->assoc_reject.bssid),
4847 data->assoc_reject.status_code,
4848 data->assoc_reject.timed_out ? " timeout" : "",
4849 data->assoc_reject.timeout_reason ? "=" : "",
4850 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004851 data->assoc_reject.timeout_reason : "",
4852 data->assoc_reject.reason_code !=
4853 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4854 " qca_driver_reason=" : "",
4855 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004856 else
4857 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004858 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004859 data->assoc_reject.status_code,
4860 data->assoc_reject.timed_out ? " timeout" : "",
4861 data->assoc_reject.timeout_reason ? "=" : "",
4862 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004863 data->assoc_reject.timeout_reason : "",
4864 data->assoc_reject.reason_code !=
4865 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4866 " qca_driver_reason=" : "",
4867 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004868 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08004869 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
4870 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004871
4872#ifdef CONFIG_OWE
4873 if (data->assoc_reject.status_code ==
4874 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4875 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4876 wpa_s->current_ssid &&
4877 wpa_s->current_ssid->owe_group == 0 &&
4878 wpa_s->last_owe_group != 21) {
4879 struct wpa_ssid *ssid = wpa_s->current_ssid;
4880 struct wpa_bss *bss = wpa_s->current_bss;
4881
4882 if (!bss) {
4883 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4884 if (!bss) {
4885 wpas_connection_failed(wpa_s, bssid);
4886 wpa_supplicant_mark_disassoc(wpa_s);
4887 return;
4888 }
4889 }
4890 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4891 wpas_connect_work_done(wpa_s);
4892 wpa_supplicant_mark_disassoc(wpa_s);
4893 wpa_supplicant_connect(wpa_s, bss, ssid);
4894 return;
4895 }
4896#endif /* CONFIG_OWE */
4897
Hai Shalomfdcde762020-04-02 11:19:20 -07004898#ifdef CONFIG_DPP2
4899 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4900 * the status code defined in the DPP R2 tech spec.
4901 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4902 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004903 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004904 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4905 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4906 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004907 wpa_s->current_ssid->dpp_pfs == 0 &&
4908 (data->assoc_reject.status_code ==
4909 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4910 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4911 struct wpa_ssid *ssid = wpa_s->current_ssid;
4912 struct wpa_bss *bss = wpa_s->current_bss;
4913
4914 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4915 if (!bss)
4916 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4917 if (!bss || wpa_s->dpp_pfs_fallback) {
4918 wpa_printf(MSG_DEBUG,
4919 "DPP: Updated PFS policy for next try");
4920 wpas_connection_failed(wpa_s, bssid);
4921 wpa_supplicant_mark_disassoc(wpa_s);
4922 return;
4923 }
4924 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4925 wpa_s->dpp_pfs_fallback = 1;
4926 wpas_connect_work_done(wpa_s);
4927 wpa_supplicant_mark_disassoc(wpa_s);
4928 wpa_supplicant_connect(wpa_s, bss, ssid);
4929 return;
4930 }
4931#endif /* CONFIG_DPP2 */
4932
Hai Shalom74f70d42019-02-11 14:42:39 -08004933#ifdef CONFIG_MBO
4934 if (data->assoc_reject.status_code ==
4935 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004936 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004937 const u8 *rssi_rej;
4938
4939 rssi_rej = mbo_get_attr_from_ies(
4940 data->assoc_reject.resp_ies,
4941 data->assoc_reject.resp_ies_len,
4942 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4943 if (rssi_rej && rssi_rej[1] == 2) {
4944 wpa_printf(MSG_DEBUG,
4945 "OCE: RSSI-based association rejection from "
4946 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004947 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004948 rssi_rej[2], rssi_rej[3]);
4949 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004950 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004951 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004952 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004953 }
4954 }
4955#endif /* CONFIG_MBO */
4956
Roshan Pius3a1667e2018-07-03 15:17:14 -07004957 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4958 sme_event_assoc_reject(wpa_s, data);
4959 return;
4960 }
4961
4962 /* Driver-based SME cases */
4963
4964#ifdef CONFIG_SAE
4965 if (wpa_s->current_ssid &&
4966 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4967 !data->assoc_reject.timed_out) {
4968 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4969 wpa_sm_aborted_cached(wpa_s->wpa);
4970 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4971 }
4972#endif /* CONFIG_SAE */
4973
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004974#ifdef CONFIG_DPP
4975 if (wpa_s->current_ssid &&
4976 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4977 !data->assoc_reject.timed_out) {
4978 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4979 wpa_sm_aborted_cached(wpa_s->wpa);
4980 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4981 }
4982#endif /* CONFIG_DPP */
4983
Roshan Pius3a1667e2018-07-03 15:17:14 -07004984#ifdef CONFIG_FILS
4985 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004986 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004987 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004988 eapol_sm_update_erp_next_seq_num(
4989 wpa_s->eapol,
4990 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004991 fils_connection_failure(wpa_s);
4992 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004993#endif /* CONFIG_FILS */
4994
4995 wpas_connection_failed(wpa_s, bssid);
4996 wpa_supplicant_mark_disassoc(wpa_s);
4997}
4998
4999
Hai Shalomfdcde762020-04-02 11:19:20 -07005000static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5001 struct unprot_beacon *data)
5002{
5003 struct wpabuf *buf;
5004 int res;
5005
5006 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5007 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5008 return;
5009 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5010 MAC2STR(data->sa));
5011
5012 buf = wpabuf_alloc(4);
5013 if (!buf)
5014 return;
5015
5016 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5017 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5018 wpabuf_put_u8(buf, 1); /* Dialog Token */
5019 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5020
5021 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5022 wpa_s->own_addr, wpa_s->bssid,
5023 wpabuf_head(buf), wpabuf_len(buf), 0);
5024 if (res < 0)
5025 wpa_printf(MSG_DEBUG,
5026 "Failed to send WNM-Notification Request frame");
5027
5028 wpabuf_free(buf);
5029}
5030
5031
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005032void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5033 union wpa_event_data *data)
5034{
5035 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005036 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005037 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005038#ifndef CONFIG_NO_STDOUT_DEBUG
5039 int level = MSG_DEBUG;
5040#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005041
5042 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5043 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005044 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005045 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005046 event != EVENT_SCHED_SCAN_STOPPED) {
5047 wpa_dbg(wpa_s, MSG_DEBUG,
5048 "Ignore event %s (%d) while interface is disabled",
5049 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005050 return;
5051 }
5052
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005053#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005054 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005055 const struct ieee80211_hdr *hdr;
5056 u16 fc;
5057 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5058 fc = le_to_host16(hdr->frame_control);
5059 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5060 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5061 level = MSG_EXCESSIVE;
5062 }
5063
5064 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5065 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005066#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005067
5068 switch (event) {
5069 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005070#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005071 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5072 data->auth.ies_len))
5073 wpa_printf(MSG_DEBUG,
5074 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005075#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005076 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005077 wpa_s->auth_status_code = data->auth.status_code;
5078 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005079 break;
5080 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005081#ifdef CONFIG_TESTING_OPTIONS
5082 if (wpa_s->ignore_auth_resp) {
5083 wpa_printf(MSG_INFO,
5084 "EVENT_ASSOC - ignore_auth_resp active!");
5085 break;
5086 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005087 if (wpa_s->testing_resend_assoc) {
5088 wpa_printf(MSG_INFO,
5089 "EVENT_DEAUTH - testing_resend_assoc");
5090 break;
5091 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005092#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305093 if (wpa_s->disconnected) {
5094 wpa_printf(MSG_INFO,
5095 "Ignore unexpected EVENT_ASSOC in disconnected state");
5096 break;
5097 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005098 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005099 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005100 if (data &&
5101 (data->assoc_info.authorized ||
5102 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5103 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005104 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005105 if (data) {
5106 wpa_msg(wpa_s, MSG_INFO,
5107 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5108 data->assoc_info.subnet_status);
5109 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005110 break;
5111 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005112 wpas_event_disassoc(wpa_s,
5113 data ? &data->disassoc_info : NULL);
5114 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005115 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005116#ifdef CONFIG_TESTING_OPTIONS
5117 if (wpa_s->ignore_auth_resp) {
5118 wpa_printf(MSG_INFO,
5119 "EVENT_DEAUTH - ignore_auth_resp active!");
5120 break;
5121 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005122 if (wpa_s->testing_resend_assoc) {
5123 wpa_printf(MSG_INFO,
5124 "EVENT_DEAUTH - testing_resend_assoc");
5125 break;
5126 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005127#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005128 wpas_event_deauth(wpa_s,
5129 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005130 break;
5131 case EVENT_MICHAEL_MIC_FAILURE:
5132 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5133 break;
5134#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005135 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005136 if (wpa_s->own_scan_requested ||
5137 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005138 struct os_reltime diff;
5139
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005140 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005141 os_reltime_sub(&wpa_s->scan_start_time,
5142 &wpa_s->scan_trigger_time, &diff);
5143 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5144 diff.sec, diff.usec);
5145 wpa_s->own_scan_requested = 0;
5146 wpa_s->own_scan_running = 1;
5147 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5148 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005149 wpa_msg_ctrl(wpa_s, MSG_INFO,
5150 WPA_EVENT_SCAN_STARTED "id=%u",
5151 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005152 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005153 wpa_msg_ctrl(wpa_s, MSG_INFO,
5154 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005155 }
5156 } else {
5157 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005158 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005159 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005160 }
5161 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005162 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005163 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5164 wpa_s->scan_res_handler = NULL;
5165 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005166 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005167 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5168 break;
5169 }
5170
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005171 if (!(data && data->scan_info.external_scan) &&
5172 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005173 struct os_reltime now, diff;
5174 os_get_reltime(&now);
5175 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5176 wpa_s->scan_start_time.sec = 0;
5177 wpa_s->scan_start_time.usec = 0;
5178 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5179 diff.sec, diff.usec);
5180 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005181 if (wpa_supplicant_event_scan_results(wpa_s, data))
5182 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005183 if (!(data && data->scan_info.external_scan))
5184 wpa_s->own_scan_running = 0;
5185 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005186 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005187 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005188 break;
5189#endif /* CONFIG_NO_SCAN_PROCESSING */
5190 case EVENT_ASSOCINFO:
5191 wpa_supplicant_event_associnfo(wpa_s, data);
5192 break;
5193 case EVENT_INTERFACE_STATUS:
5194 wpa_supplicant_event_interface_status(wpa_s, data);
5195 break;
5196 case EVENT_PMKID_CANDIDATE:
5197 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5198 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005199#ifdef CONFIG_TDLS
5200 case EVENT_TDLS:
5201 wpa_supplicant_event_tdls(wpa_s, data);
5202 break;
5203#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005204#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005205 case EVENT_WNM:
5206 wpa_supplicant_event_wnm(wpa_s, data);
5207 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005208#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005209#ifdef CONFIG_IEEE80211R
5210 case EVENT_FT_RESPONSE:
5211 wpa_supplicant_event_ft_response(wpa_s, data);
5212 break;
5213#endif /* CONFIG_IEEE80211R */
5214#ifdef CONFIG_IBSS_RSN
5215 case EVENT_IBSS_RSN_START:
5216 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5217 break;
5218#endif /* CONFIG_IBSS_RSN */
5219 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005220 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005221 break;
5222 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005223 /* It is possible to get this event from earlier connection */
5224 if (wpa_s->current_ssid &&
5225 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5226 wpa_dbg(wpa_s, MSG_DEBUG,
5227 "Ignore AUTH_TIMED_OUT in mesh configuration");
5228 break;
5229 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005230 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5231 sme_event_auth_timed_out(wpa_s, data);
5232 break;
5233 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005234 /* It is possible to get this event from earlier connection */
5235 if (wpa_s->current_ssid &&
5236 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5237 wpa_dbg(wpa_s, MSG_DEBUG,
5238 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5239 break;
5240 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005241 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5242 sme_event_assoc_timed_out(wpa_s, data);
5243 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005244 case EVENT_TX_STATUS:
5245 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5246 " type=%d stype=%d",
5247 MAC2STR(data->tx_status.dst),
5248 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005249#ifdef CONFIG_PASN
5250 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5251 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5252 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5253 data->tx_status.data_len,
5254 data->tx_status.ack) == 0)
5255 break;
5256#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005257#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005258 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005259#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005260 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5261 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005262 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005263 wpa_s, data->tx_status.dst,
5264 data->tx_status.data,
5265 data->tx_status.data_len,
5266 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005267 OFFCHANNEL_SEND_ACTION_SUCCESS :
5268 OFFCHANNEL_SEND_ACTION_NO_ACK);
5269#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005270 break;
5271 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005272#endif /* CONFIG_AP */
5273#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005274 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005275 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005276 /*
5277 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005278 * interface in GO mode, or via standalone AP interface.
5279 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5280 * except when the primary interface is used as a GO interface
5281 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005282 */
5283 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5284 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005285 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005286 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005287 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005288 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005289 data->tx_status.data,
5290 data->tx_status.data_len,
5291 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005292 OFFCHANNEL_SEND_ACTION_SUCCESS :
5293 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005294 break;
5295 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005296#endif /* CONFIG_OFFCHANNEL */
5297#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005298 switch (data->tx_status.type) {
5299 case WLAN_FC_TYPE_MGMT:
5300 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5301 data->tx_status.data_len,
5302 data->tx_status.stype,
5303 data->tx_status.ack);
5304 break;
5305 case WLAN_FC_TYPE_DATA:
5306 ap_tx_status(wpa_s, data->tx_status.dst,
5307 data->tx_status.data,
5308 data->tx_status.data_len,
5309 data->tx_status.ack);
5310 break;
5311 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005312#endif /* CONFIG_AP */
5313 break;
5314#ifdef CONFIG_AP
5315 case EVENT_EAPOL_TX_STATUS:
5316 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5317 data->eapol_tx_status.data,
5318 data->eapol_tx_status.data_len,
5319 data->eapol_tx_status.ack);
5320 break;
5321 case EVENT_DRIVER_CLIENT_POLL_OK:
5322 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005323 break;
5324 case EVENT_RX_FROM_UNKNOWN:
5325 if (wpa_s->ap_iface == NULL)
5326 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005327 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5328 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005329 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005330#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005331
5332 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005333 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005334 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005335 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005336
Hai Shalom81f62d82019-07-22 12:10:00 -07005337 wpa_msg(wpa_s, MSG_INFO,
5338 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5339 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5340 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005341 data->ch_switch.freq,
5342 data->ch_switch.ht_enabled,
5343 data->ch_switch.ch_offset,
5344 channel_width_to_string(data->ch_switch.ch_width),
5345 data->ch_switch.cf1,
5346 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005347 if (event == EVENT_CH_SWITCH_STARTED)
5348 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005349
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005350 wpa_s->assoc_freq = data->ch_switch.freq;
5351 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005352 if (wpa_s->current_bss &&
5353 wpa_s->current_bss->freq != data->ch_switch.freq) {
5354 wpa_s->current_bss->freq = data->ch_switch.freq;
5355 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5356 wpa_s->current_bss);
5357 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005358
Hai Shalomfdcde762020-04-02 11:19:20 -07005359#ifdef CONFIG_SME
5360 switch (data->ch_switch.ch_offset) {
5361 case 1:
5362 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5363 break;
5364 case -1:
5365 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5366 break;
5367 default:
5368 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5369 break;
5370 }
5371#endif /* CONFIG_SME */
5372
Roshan Pius3a1667e2018-07-03 15:17:14 -07005373#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005374 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5375 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005376 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005377 wpa_s->current_ssid->mode ==
5378 WPAS_MODE_P2P_GROUP_FORMATION) {
5379 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5380 data->ch_switch.ht_enabled,
5381 data->ch_switch.ch_offset,
5382 data->ch_switch.ch_width,
5383 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005384 data->ch_switch.cf2,
5385 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005386 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005387#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005388
Hai Shalom899fcc72020-10-19 14:38:18 -07005389 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5390 sme_event_ch_switch(wpa_s);
5391
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005392 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005393 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005394 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005395#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005396#ifdef NEED_AP_MLME
5397 case EVENT_DFS_RADAR_DETECTED:
5398 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005399 wpas_ap_event_dfs_radar_detected(wpa_s,
5400 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005401 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005402 case EVENT_DFS_NOP_FINISHED:
5403 if (data)
5404 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5405 &data->dfs_event);
5406 break;
5407#endif /* NEED_AP_MLME */
5408#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005409 case EVENT_DFS_CAC_STARTED:
5410 if (data)
5411 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5412 break;
5413 case EVENT_DFS_CAC_FINISHED:
5414 if (data)
5415 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5416 break;
5417 case EVENT_DFS_CAC_ABORTED:
5418 if (data)
5419 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5420 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005421 case EVENT_RX_MGMT: {
5422 u16 fc, stype;
5423 const struct ieee80211_mgmt *mgmt;
5424
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005425#ifdef CONFIG_TESTING_OPTIONS
5426 if (wpa_s->ext_mgmt_frame_handling) {
5427 struct rx_mgmt *rx = &data->rx_mgmt;
5428 size_t hex_len = 2 * rx->frame_len + 1;
5429 char *hex = os_malloc(hex_len);
5430 if (hex) {
5431 wpa_snprintf_hex(hex, hex_len,
5432 rx->frame, rx->frame_len);
5433 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5434 rx->freq, rx->datarate, rx->ssi_signal,
5435 hex);
5436 os_free(hex);
5437 }
5438 break;
5439 }
5440#endif /* CONFIG_TESTING_OPTIONS */
5441
Dmitry Shmidt04949592012-07-19 12:16:46 -07005442 mgmt = (const struct ieee80211_mgmt *)
5443 data->rx_mgmt.frame;
5444 fc = le_to_host16(mgmt->frame_control);
5445 stype = WLAN_FC_GET_STYPE(fc);
5446
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005447#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005448 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005449#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005450#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005451 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005452 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005453 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005454 const u8 *ie;
5455 size_t ie_len;
5456
5457 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5458 ie_len = data->rx_mgmt.frame_len -
5459 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005460 wpas_p2p_probe_req_rx(
5461 wpa_s, src, mgmt->da,
5462 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005463 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005464 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005465 break;
5466 }
5467#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005468#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005469 if (wpa_s->current_ssid &&
5470 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5471 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005472 data->rx_mgmt.frame_len >= 30) {
5473 wpa_supplicant_event_ibss_auth(wpa_s, data);
5474 break;
5475 }
5476#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005477
5478 if (stype == WLAN_FC_STYPE_ACTION) {
5479 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005480 wpa_s, data->rx_mgmt.frame,
5481 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005482 data->rx_mgmt.freq,
5483 data->rx_mgmt.ssi_signal);
5484 break;
5485 }
5486
5487 if (wpa_s->ifmsh) {
5488 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005489 break;
5490 }
Hai Shalom60840252021-02-19 19:02:11 -08005491#ifdef CONFIG_PASN
5492 if (stype == WLAN_FC_STYPE_AUTH &&
5493 wpas_pasn_auth_rx(wpa_s, mgmt,
5494 data->rx_mgmt.frame_len) != -2)
5495 break;
5496#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005497
Roshan Pius3a1667e2018-07-03 15:17:14 -07005498#ifdef CONFIG_SAE
5499 if (stype == WLAN_FC_STYPE_AUTH &&
5500 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5501 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5502 sme_external_auth_mgmt_rx(
5503 wpa_s, data->rx_mgmt.frame,
5504 data->rx_mgmt.frame_len);
5505 break;
5506 }
5507#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005508 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5509 "management frame in non-AP mode");
5510 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005511#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005512 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005513
5514 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005515 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5516 const u8 *ie;
5517 size_t ie_len;
5518
5519 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5520 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005521
5522 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5523 mgmt->bssid, ie, ie_len,
5524 data->rx_mgmt.ssi_signal);
5525 }
5526
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005527 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005528#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005529 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005530 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005531 case EVENT_RX_PROBE_REQ:
5532 if (data->rx_probe_req.sa == NULL ||
5533 data->rx_probe_req.ie == NULL)
5534 break;
5535#ifdef CONFIG_AP
5536 if (wpa_s->ap_iface) {
5537 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5538 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005539 data->rx_probe_req.da,
5540 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005541 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005542 data->rx_probe_req.ie_len,
5543 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005544 break;
5545 }
5546#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005547 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005548 data->rx_probe_req.da,
5549 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005550 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005551 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005552 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005553 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005554 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005555 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005556#ifdef CONFIG_OFFCHANNEL
5557 offchannel_remain_on_channel_cb(
5558 wpa_s, data->remain_on_channel.freq,
5559 data->remain_on_channel.duration);
5560#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005561 wpas_p2p_remain_on_channel_cb(
5562 wpa_s, data->remain_on_channel.freq,
5563 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005564#ifdef CONFIG_DPP
5565 wpas_dpp_remain_on_channel_cb(
5566 wpa_s, data->remain_on_channel.freq,
5567 data->remain_on_channel.duration);
5568#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005569 break;
5570 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005571#ifdef CONFIG_OFFCHANNEL
5572 offchannel_cancel_remain_on_channel_cb(
5573 wpa_s, data->remain_on_channel.freq);
5574#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005575 wpas_p2p_cancel_remain_on_channel_cb(
5576 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005577#ifdef CONFIG_DPP
5578 wpas_dpp_cancel_remain_on_channel_cb(
5579 wpa_s, data->remain_on_channel.freq);
5580#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005581 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005582 case EVENT_EAPOL_RX:
5583 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5584 data->eapol_rx.data,
5585 data->eapol_rx.data_len);
5586 break;
5587 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005588 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5589 "above=%d signal=%d noise=%d txrate=%d",
5590 data->signal_change.above_threshold,
5591 data->signal_change.current_signal,
5592 data->signal_change.current_noise,
5593 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005594 wpa_bss_update_level(wpa_s->current_bss,
5595 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005596 bgscan_notify_signal_change(
5597 wpa_s, data->signal_change.above_threshold,
5598 data->signal_change.current_signal,
5599 data->signal_change.current_noise,
5600 data->signal_change.current_txrate);
5601 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005602 case EVENT_INTERFACE_MAC_CHANGED:
5603 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005604 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005605 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005606 case EVENT_INTERFACE_ENABLED:
5607 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5608 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005609 u8 addr[ETH_ALEN];
5610
Hai Shalomfdcde762020-04-02 11:19:20 -07005611 eloop_cancel_timeout(wpas_clear_disabled_interface,
5612 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005613 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005614 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005615 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5616 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5617 else
5618 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005619 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005620 if (wpa_s->p2p_mgmt) {
5621 wpa_supplicant_set_state(wpa_s,
5622 WPA_DISCONNECTED);
5623 break;
5624 }
5625
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005626#ifdef CONFIG_AP
5627 if (!wpa_s->ap_iface) {
5628 wpa_supplicant_set_state(wpa_s,
5629 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005630 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005631 wpa_supplicant_req_scan(wpa_s, 0, 0);
5632 } else
5633 wpa_supplicant_set_state(wpa_s,
5634 WPA_COMPLETED);
5635#else /* CONFIG_AP */
5636 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5637 wpa_supplicant_req_scan(wpa_s, 0, 0);
5638#endif /* CONFIG_AP */
5639 }
5640 break;
5641 case EVENT_INTERFACE_DISABLED:
5642 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005643#ifdef CONFIG_P2P
5644 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5645 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5646 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5647 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005648 * Mark interface disabled if this happens to end up not
5649 * being removed as a separate P2P group interface.
5650 */
5651 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5652 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005653 * The interface was externally disabled. Remove
5654 * it assuming an external entity will start a
5655 * new session if needed.
5656 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005657 if (wpa_s->current_ssid &&
5658 wpa_s->current_ssid->p2p_group)
5659 wpas_p2p_interface_unavailable(wpa_s);
5660 else
5661 wpas_p2p_disconnect(wpa_s);
5662 /*
5663 * wpa_s instance may have been freed, so must not use
5664 * it here anymore.
5665 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005666 break;
5667 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005668 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5669 p2p_in_progress(wpa_s->global->p2p) > 1) {
5670 /* This radio work will be cancelled, so clear P2P
5671 * state as well.
5672 */
5673 p2p_stop_find(wpa_s->global->p2p);
5674 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005675#endif /* CONFIG_P2P */
5676
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005677 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5678 /*
5679 * Indicate disconnection to keep ctrl_iface events
5680 * consistent.
5681 */
5682 wpa_supplicant_event_disassoc(
5683 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5684 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005685 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005686 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005687 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5688 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005689 clear_at.usec = 0;
5690 } else {
5691 struct os_reltime tmp;
5692
Hai Shalom60840252021-02-19 19:02:11 -08005693 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005694 tmp.usec = 0;
5695 os_reltime_sub(&tmp, &age, &clear_at);
5696 }
5697 eloop_register_timeout(clear_at.sec, clear_at.usec,
5698 wpas_clear_disabled_interface,
5699 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005700 radio_remove_works(wpa_s, NULL, 0);
5701
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005702 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5703 break;
5704 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005705 wpa_supplicant_update_channel_list(
5706 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005707 break;
5708 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005709 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005710 break;
5711 case EVENT_BEST_CHANNEL:
5712 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5713 "(%d %d %d)",
5714 data->best_chan.freq_24, data->best_chan.freq_5,
5715 data->best_chan.freq_overall);
5716 wpa_s->best_24_freq = data->best_chan.freq_24;
5717 wpa_s->best_5_freq = data->best_chan.freq_5;
5718 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005719 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5720 data->best_chan.freq_5,
5721 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005722 break;
5723 case EVENT_UNPROT_DEAUTH:
5724 wpa_supplicant_event_unprot_deauth(wpa_s,
5725 &data->unprot_deauth);
5726 break;
5727 case EVENT_UNPROT_DISASSOC:
5728 wpa_supplicant_event_unprot_disassoc(wpa_s,
5729 &data->unprot_disassoc);
5730 break;
5731 case EVENT_STATION_LOW_ACK:
5732#ifdef CONFIG_AP
5733 if (wpa_s->ap_iface && data)
5734 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5735 data->low_ack.addr);
5736#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005737#ifdef CONFIG_TDLS
5738 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005739 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5740 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005741#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005742 break;
5743 case EVENT_IBSS_PEER_LOST:
5744#ifdef CONFIG_IBSS_RSN
5745 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5746#endif /* CONFIG_IBSS_RSN */
5747 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005748 case EVENT_DRIVER_GTK_REKEY:
5749 if (os_memcmp(data->driver_gtk_rekey.bssid,
5750 wpa_s->bssid, ETH_ALEN))
5751 break;
5752 if (!wpa_s->wpa)
5753 break;
5754 wpa_sm_update_replay_ctr(wpa_s->wpa,
5755 data->driver_gtk_rekey.replay_ctr);
5756 break;
5757 case EVENT_SCHED_SCAN_STOPPED:
5758 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005759 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005760 wpa_supplicant_notify_scanning(wpa_s, 0);
5761
5762 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5763 break;
5764
5765 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005766 * If the driver stopped scanning without being requested to,
5767 * request a new scan to continue scanning for networks.
5768 */
5769 if (!wpa_s->sched_scan_stop_req &&
5770 wpa_s->wpa_state == WPA_SCANNING) {
5771 wpa_dbg(wpa_s, MSG_DEBUG,
5772 "Restart scanning after unexpected sched_scan stop event");
5773 wpa_supplicant_req_scan(wpa_s, 1, 0);
5774 break;
5775 }
5776
5777 wpa_s->sched_scan_stop_req = 0;
5778
5779 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005780 * Start a new sched scan to continue searching for more SSIDs
5781 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005782 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005783 if (wpa_s->sched_scan_timed_out) {
5784 wpa_supplicant_req_sched_scan(wpa_s);
5785 } else if (wpa_s->pno_sched_pending) {
5786 wpa_s->pno_sched_pending = 0;
5787 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005788 } else if (resched) {
5789 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005790 }
5791
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005792 break;
5793 case EVENT_WPS_BUTTON_PUSHED:
5794#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005795 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005796#endif /* CONFIG_WPS */
5797 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005798 case EVENT_AVOID_FREQUENCIES:
5799 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5800 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005801 case EVENT_CONNECT_FAILED_REASON:
5802#ifdef CONFIG_AP
5803 if (!wpa_s->ap_iface || !data)
5804 break;
5805 hostapd_event_connect_failed_reason(
5806 wpa_s->ap_iface->bss[0],
5807 data->connect_failed_reason.addr,
5808 data->connect_failed_reason.code);
5809#endif /* CONFIG_AP */
5810 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005811 case EVENT_NEW_PEER_CANDIDATE:
5812#ifdef CONFIG_MESH
5813 if (!wpa_s->ifmsh || !data)
5814 break;
5815 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5816 data->mesh_peer.ies,
5817 data->mesh_peer.ie_len);
5818#endif /* CONFIG_MESH */
5819 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005820 case EVENT_SURVEY:
5821#ifdef CONFIG_AP
5822 if (!wpa_s->ap_iface)
5823 break;
5824 hostapd_event_get_survey(wpa_s->ap_iface,
5825 &data->survey_results);
5826#endif /* CONFIG_AP */
5827 break;
5828 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005829#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005830#ifdef CONFIG_ACS
5831 if (!wpa_s->ap_iface)
5832 break;
5833 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5834 &data->acs_selected_channels);
5835#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005836#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005837 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005838 case EVENT_P2P_LO_STOP:
5839#ifdef CONFIG_P2P
5840 wpa_s->p2p_lo_started = 0;
5841 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5842 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5843 data->p2p_lo_stop.reason_code);
5844#endif /* CONFIG_P2P */
5845 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005846 case EVENT_BEACON_LOSS:
5847 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5848 break;
5849 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5850 bgscan_notify_beacon_loss(wpa_s);
5851 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005852 case EVENT_EXTERNAL_AUTH:
5853#ifdef CONFIG_SAE
5854 if (!wpa_s->current_ssid) {
5855 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5856 break;
5857 }
5858 sme_external_auth_trigger(wpa_s, data);
5859#endif /* CONFIG_SAE */
5860 break;
5861 case EVENT_PORT_AUTHORIZED:
5862 wpa_supplicant_event_port_authorized(wpa_s);
5863 break;
5864 case EVENT_STATION_OPMODE_CHANGED:
5865#ifdef CONFIG_AP
5866 if (!wpa_s->ap_iface || !data)
5867 break;
5868
5869 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5870 data->sta_opmode.addr,
5871 data->sta_opmode.smps_mode,
5872 data->sta_opmode.chan_width,
5873 data->sta_opmode.rx_nss);
5874#endif /* CONFIG_AP */
5875 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005876 case EVENT_UNPROT_BEACON:
5877 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5878 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08005879 case EVENT_TX_WAIT_EXPIRE:
5880#ifdef CONFIG_DPP
5881 wpas_dpp_tx_wait_expire(wpa_s);
5882#endif /* CONFIG_DPP */
5883 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005884 default:
5885 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5886 break;
5887 }
5888}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005889
5890
5891void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5892 union wpa_event_data *data)
5893{
5894 struct wpa_supplicant *wpa_s;
5895
5896 if (event != EVENT_INTERFACE_STATUS)
5897 return;
5898
5899 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5900 if (wpa_s && wpa_s->driver->get_ifindex) {
5901 unsigned int ifindex;
5902
5903 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5904 if (ifindex != data->interface_status.ifindex) {
5905 wpa_dbg(wpa_s, MSG_DEBUG,
5906 "interface status ifindex %d mismatch (%d)",
5907 ifindex, data->interface_status.ifindex);
5908 return;
5909 }
5910 }
5911#ifdef CONFIG_MATCH_IFACE
5912 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5913 struct wpa_interface *wpa_i;
5914
5915 wpa_i = wpa_supplicant_match_iface(
5916 ctx, data->interface_status.ifname);
5917 if (!wpa_i)
5918 return;
5919 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5920 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07005921 }
5922#endif /* CONFIG_MATCH_IFACE */
5923
5924 if (wpa_s)
5925 wpa_supplicant_event(wpa_s, event, data);
5926}