blob: ae494f6eb28531bef209049818ae9a621304c529 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Hai Shalom021b0b52019-04-10 11:17:58 -07003 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "notify.h"
29#include "common/ieee802_11_defs.h"
30#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070031#include "common/gas_server.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070032#include "common/dpp.h"
Hai Shalom60840252021-02-19 19:02:11 -080033#include "common/ptksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "crypto/random.h"
Hai Shalom60840252021-02-19 19:02:11 -080035#include "bssid_ignore.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "wpas_glue.h"
37#include "wps_supplicant.h"
38#include "ibss_rsn.h"
39#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080040#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "p2p_supplicant.h"
42#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070043#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044#include "ap.h"
45#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080047#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080049#include "mesh.h"
50#include "mesh_mpm.h"
51#include "wmm_ac.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070052#include "dpp_supplicant.h"
Mir Ali677e7482020-11-12 19:49:02 +053053#include "rsn_supp/wpa_i.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070054
55
Hai Shalom39ba6fc2019-01-22 12:40:38 -080056#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
57
58
Dmitry Shmidt34af3062013-07-11 10:46:32 -070059#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070060static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080061 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070062#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080063
64
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070065int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080067 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070068
69 if (ssid == NULL || ssid->disabled_until.sec == 0)
70 return 0;
71
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080072 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070073 if (ssid->disabled_until.sec > now.sec)
74 return ssid->disabled_until.sec - now.sec;
75
76 wpas_clear_temp_disabled(wpa_s, ssid, 0);
77
78 return 0;
79}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080
81
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080082#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070083/**
84 * wpas_reenabled_network_time - Time until first network is re-enabled
85 * @wpa_s: Pointer to wpa_supplicant data
86 * Returns: If all enabled networks are temporarily disabled, returns the time
87 * (in sec) until the first network is re-enabled. Otherwise returns 0.
88 *
89 * This function is used in case all enabled networks are temporarily disabled,
90 * in which case it returns the time (in sec) that the first network will be
91 * re-enabled. The function assumes that at least one network is enabled.
92 */
93static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
94{
95 struct wpa_ssid *ssid;
96 int disabled_for, res = 0;
97
98#ifdef CONFIG_INTERWORKING
99 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
100 wpa_s->conf->cred)
101 return 0;
102#endif /* CONFIG_INTERWORKING */
103
104 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
105 if (ssid->disabled)
106 continue;
107
108 disabled_for = wpas_temp_disabled(wpa_s, ssid);
109 if (!disabled_for)
110 return 0;
111
112 if (!res || disabled_for < res)
113 res = disabled_for;
114 }
115
116 return res;
117}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800118#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700119
120
121void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
122{
123 struct wpa_supplicant *wpa_s = eloop_ctx;
124
125 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
126 return;
127
128 wpa_dbg(wpa_s, MSG_DEBUG,
129 "Try to associate due to network getting re-enabled");
130 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
131 wpa_supplicant_cancel_sched_scan(wpa_s);
132 wpa_supplicant_req_scan(wpa_s, 0, 0);
133 }
134}
135
136
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800137static struct wpa_bss * wpa_supplicant_get_new_bss(
138 struct wpa_supplicant *wpa_s, const u8 *bssid)
139{
140 struct wpa_bss *bss = NULL;
141 struct wpa_ssid *ssid = wpa_s->current_ssid;
142
143 if (ssid->ssid_len > 0)
144 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
145 if (!bss)
146 bss = wpa_bss_get_bssid(wpa_s, bssid);
147
148 return bss;
149}
150
151
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700152static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
153{
154 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
155
156 if (!bss) {
157 wpa_supplicant_update_scan_results(wpa_s);
158
159 /* Get the BSS from the new scan results */
160 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
161 }
162
163 if (bss)
164 wpa_s->current_bss = bss;
165}
166
167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
169{
170 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700171 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700172 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700173 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700175 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
176 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700177
178 if (wpa_s->current_ssid->ssid_len == 0)
179 return 0; /* current profile still in use */
180 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
181 if (res < 0) {
182 wpa_msg(wpa_s, MSG_INFO,
183 "Failed to read SSID from driver");
184 return 0; /* try to use current profile */
185 }
186 drv_ssid_len = res;
187
188 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
189 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
190 drv_ssid_len) == 0)
191 return 0; /* current profile still in use */
192
Hai Shalomfdcde762020-04-02 11:19:20 -0700193#ifdef CONFIG_OWE
194 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
195 wpa_s->current_bss &&
196 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
197 drv_ssid_len == wpa_s->current_bss->ssid_len &&
198 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
199 drv_ssid_len) == 0)
200 return 0; /* current profile still in use */
201#endif /* CONFIG_OWE */
202
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700203 wpa_msg(wpa_s, MSG_DEBUG,
204 "Driver-initiated BSS selection changed the SSID to %s",
205 wpa_ssid_txt(drv_ssid, drv_ssid_len));
206 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700207 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208
209 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
210 "information");
211 ssid = wpa_supplicant_get_ssid(wpa_s);
212 if (ssid == NULL) {
213 wpa_msg(wpa_s, MSG_INFO,
214 "No network configuration found for the current AP");
215 return -1;
216 }
217
Dmitry Shmidt04949592012-07-19 12:16:46 -0700218 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
220 return -1;
221 }
222
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800223 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
224 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
225 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
226 return -1;
227 }
228
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700229 res = wpas_temp_disabled(wpa_s, ssid);
230 if (res > 0) {
231 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
232 "disabled for %d second(s)", res);
233 return -1;
234 }
235
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700236 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
237 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800238 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239 u8 wpa_ie[80];
240 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800241 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
242 wpa_ie, &wpa_ie_len) < 0)
243 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700244 } else {
245 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
246 }
247
248 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
249 eapol_sm_invalidate_cached_session(wpa_s->eapol);
250 old_ssid = wpa_s->current_ssid;
251 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800252
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700253 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700255 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
256 wpa_supplicant_initiate_eapol(wpa_s);
257 if (old_ssid != wpa_s->current_ssid)
258 wpas_notify_network_changed(wpa_s);
259
260 return 0;
261}
262
263
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265{
266 struct wpa_supplicant *wpa_s = eloop_ctx;
267
268 if (wpa_s->countermeasures) {
269 wpa_s->countermeasures = 0;
270 wpa_drv_set_countermeasures(wpa_s, 0);
271 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800272
273 /*
274 * It is possible that the device is sched scanning, which means
275 * that a connection attempt will be done only when we receive
276 * scan results. However, in this case, it would be preferable
277 * to scan and connect immediately, so cancel the sched_scan and
278 * issue a regular scan flow.
279 */
280 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281 wpa_supplicant_req_scan(wpa_s, 0, 0);
282 }
283}
284
285
286void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
287{
288 int bssid_changed;
289
Dmitry Shmidt04949592012-07-19 12:16:46 -0700290 wnm_bss_keep_alive_deinit(wpa_s);
291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292#ifdef CONFIG_IBSS_RSN
293 ibss_rsn_deinit(wpa_s->ibss_rsn);
294 wpa_s->ibss_rsn = NULL;
295#endif /* CONFIG_IBSS_RSN */
296
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700297#ifdef CONFIG_AP
298 wpa_supplicant_ap_deinit(wpa_s);
299#endif /* CONFIG_AP */
300
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700301#ifdef CONFIG_HS20
302 /* Clear possibly configured frame filters */
303 wpa_drv_configure_frame_filters(wpa_s, 0);
304#endif /* CONFIG_HS20 */
305
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700306 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
307 return;
308
Hai Shalom74f70d42019-02-11 14:42:39 -0800309 if (os_reltime_initialized(&wpa_s->session_start)) {
310 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
311 wpa_s->session_start.sec = 0;
312 wpa_s->session_start.usec = 0;
313 wpas_notify_session_length(wpa_s);
314 }
315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
317 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
318 os_memset(wpa_s->bssid, 0, ETH_ALEN);
319 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800320 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321 wpa_s->current_bss = NULL;
322 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700323
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 if (bssid_changed)
325 wpas_notify_bssid_changed(wpa_s);
326
Hai Shalome21d4e82020-04-29 16:34:06 -0700327 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
328 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700329 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
330 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700331 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700332 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700333 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700334 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700335 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700336 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700337 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800338
339 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800340 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800341 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700342 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700343
344#ifdef CONFIG_TESTING_OPTIONS
345 wpa_s->last_tk_alg = WPA_ALG_NONE;
346 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
347#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700348 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800349
350 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
351 wpa_s->enabled_4addr_mode = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352}
353
354
355static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
356{
357 struct wpa_ie_data ie;
358 int pmksa_set = -1;
359 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800360 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700361
Hai Shalomc1a21442022-02-04 13:43:00 -0800362 /* Start with assumption of no PMKSA cache entry match for cases other
363 * than SAE. In particular, this is needed to generate the PMKSA cache
364 * entries for Suite B cases with driver-based roaming indication. */
365 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
366 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
367 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700368
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700369 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
370 ie.pmkid == NULL)
371 return;
372
373 for (i = 0; i < ie.num_pmkid; i++) {
374 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
375 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700376 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800378 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700379 break;
380 }
381 }
382
383 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
384 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
385}
386
387
388static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
389 union wpa_event_data *data)
390{
391 if (data == NULL) {
392 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
393 "event");
394 return;
395 }
396 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
397 " index=%d preauth=%d",
398 MAC2STR(data->pmkid_candidate.bssid),
399 data->pmkid_candidate.index,
400 data->pmkid_candidate.preauth);
401
402 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
403 data->pmkid_candidate.index,
404 data->pmkid_candidate.preauth);
405}
406
407
408static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
409{
410 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
411 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
412 return 0;
413
414#ifdef IEEE8021X_EAPOL
415 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
416 wpa_s->current_ssid &&
417 !(wpa_s->current_ssid->eapol_flags &
418 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
419 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
420 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
421 * plaintext or static WEP keys). */
422 return 0;
423 }
424#endif /* IEEE8021X_EAPOL */
425
426 return 1;
427}
428
429
430/**
431 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
432 * @wpa_s: pointer to wpa_supplicant data
433 * @ssid: Configuration data for the network
434 * Returns: 0 on success, -1 on failure
435 *
436 * This function is called when starting authentication with a network that is
437 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
438 */
439int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
440 struct wpa_ssid *ssid)
441{
442#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800443#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700444 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700445
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700446 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
447 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700448 return 0;
449
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700450 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 sim = 1;
452 aka = 1;
453 } else {
454 struct eap_method_type *eap = ssid->eap.eap_methods;
455 while (eap->vendor != EAP_VENDOR_IETF ||
456 eap->method != EAP_TYPE_NONE) {
457 if (eap->vendor == EAP_VENDOR_IETF) {
458 if (eap->method == EAP_TYPE_SIM)
459 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700460 else if (eap->method == EAP_TYPE_AKA ||
461 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700462 aka = 1;
463 }
464 eap++;
465 }
466 }
467
468 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
469 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700470 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
471 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
472 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 aka = 0;
474
475 if (!sim && !aka) {
476 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
477 "use SIM, but neither EAP-SIM nor EAP-AKA are "
478 "enabled");
479 return 0;
480 }
481
482 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
483 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700484
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700485 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700486 if (wpa_s->scard == NULL) {
487 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
488 "(pcsc-lite)");
489 return -1;
490 }
491 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
492 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800493#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700494#endif /* IEEE8021X_EAPOL */
495
496 return 0;
497}
498
499
500#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700501
Hai Shalomfdcde762020-04-02 11:19:20 -0700502#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700503static int has_wep_key(struct wpa_ssid *ssid)
504{
505 int i;
506
507 for (i = 0; i < NUM_WEP_KEYS; i++) {
508 if (ssid->wep_key_len[i])
509 return 1;
510 }
511
512 return 0;
513}
Hai Shalomfdcde762020-04-02 11:19:20 -0700514#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700515
516
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700517static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 struct wpa_ssid *ssid)
519{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700520 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521
522 if (ssid->mixed_cell)
523 return 1;
524
525#ifdef CONFIG_WPS
526 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
527 return 1;
528#endif /* CONFIG_WPS */
529
Roshan Pius3a1667e2018-07-03 15:17:14 -0700530#ifdef CONFIG_OWE
531 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
532 return 1;
533#endif /* CONFIG_OWE */
534
Hai Shalomfdcde762020-04-02 11:19:20 -0700535#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700536 if (has_wep_key(ssid))
537 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700538#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700539
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700540#ifdef IEEE8021X_EAPOL
541 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
542 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
543 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
544 privacy = 1;
545#endif /* IEEE8021X_EAPOL */
546
Jouni Malinen75ecf522011-06-27 15:19:46 -0700547 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
548 privacy = 1;
549
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800550 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
551 privacy = 1;
552
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553 if (bss->caps & IEEE80211_CAP_PRIVACY)
554 return privacy;
555 return !privacy;
556}
557
558
559static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
560 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800561 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562{
563 struct wpa_ie_data ie;
564 int proto_match = 0;
565 const u8 *rsn_ie, *wpa_ie;
566 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700567#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700568 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700569#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570
571 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
572 if (ret >= 0)
573 return ret;
574
Hai Shalomfdcde762020-04-02 11:19:20 -0700575#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
577 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
578 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
579 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
580 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700581#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700583 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700584 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585 proto_match++;
586
587 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800588 if (debug_print)
589 wpa_dbg(wpa_s, MSG_DEBUG,
590 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591 break;
592 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700593 if (!ie.has_pairwise)
594 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
595 if (!ie.has_group)
596 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597
Hai Shalomfdcde762020-04-02 11:19:20 -0700598#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700599 if (wep_ok &&
600 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
601 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800602 if (debug_print)
603 wpa_dbg(wpa_s, MSG_DEBUG,
604 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605 return 1;
606 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700607#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700608
Roshan Pius3a1667e2018-07-03 15:17:14 -0700609 if (!(ie.proto & ssid->proto) &&
610 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800611 if (debug_print)
612 wpa_dbg(wpa_s, MSG_DEBUG,
613 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614 break;
615 }
616
617 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800618 if (debug_print)
619 wpa_dbg(wpa_s, MSG_DEBUG,
620 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621 break;
622 }
623
624 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800625 if (debug_print)
626 wpa_dbg(wpa_s, MSG_DEBUG,
627 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700628 break;
629 }
630
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700631 if (ssid->group_mgmt_cipher &&
632 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
633 if (debug_print)
634 wpa_dbg(wpa_s, MSG_DEBUG,
635 " skip RSN IE - group mgmt cipher mismatch");
636 break;
637 }
638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800640 if (debug_print)
641 wpa_dbg(wpa_s, MSG_DEBUG,
642 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643 break;
644 }
645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800647 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800648 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800649 if (debug_print)
650 wpa_dbg(wpa_s, MSG_DEBUG,
651 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652 break;
653 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800654 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
655 wpas_get_ssid_pmf(wpa_s, ssid) ==
656 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800657 if (debug_print)
658 wpa_dbg(wpa_s, MSG_DEBUG,
659 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800660 break;
661 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800663 if (debug_print)
664 wpa_dbg(wpa_s, MSG_DEBUG,
665 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666 return 1;
667 }
668
Roshan Pius3a1667e2018-07-03 15:17:14 -0700669 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
670 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800671 if (debug_print)
672 wpa_dbg(wpa_s, MSG_DEBUG,
673 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700674 return 0;
675 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700676
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700677 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
679 proto_match++;
680
681 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800682 if (debug_print)
683 wpa_dbg(wpa_s, MSG_DEBUG,
684 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700685 break;
686 }
687
Hai Shalomfdcde762020-04-02 11:19:20 -0700688#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689 if (wep_ok &&
690 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
691 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800692 if (debug_print)
693 wpa_dbg(wpa_s, MSG_DEBUG,
694 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695 return 1;
696 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700697#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698
699 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800700 if (debug_print)
701 wpa_dbg(wpa_s, MSG_DEBUG,
702 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 break;
704 }
705
706 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800707 if (debug_print)
708 wpa_dbg(wpa_s, MSG_DEBUG,
709 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710 break;
711 }
712
713 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800714 if (debug_print)
715 wpa_dbg(wpa_s, MSG_DEBUG,
716 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 break;
718 }
719
720 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800721 if (debug_print)
722 wpa_dbg(wpa_s, MSG_DEBUG,
723 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 break;
725 }
726
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800727 if (debug_print)
728 wpa_dbg(wpa_s, MSG_DEBUG,
729 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 return 1;
731 }
732
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700733 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
734 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800735 if (debug_print)
736 wpa_dbg(wpa_s, MSG_DEBUG,
737 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700738 return 1;
739 }
740
Roshan Pius3a1667e2018-07-03 15:17:14 -0700741#ifdef CONFIG_OWE
742 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
743 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800744 if (wpa_s->owe_transition_select &&
745 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
746 ssid->owe_transition_bss_select_count + 1 <=
747 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
748 ssid->owe_transition_bss_select_count++;
749 if (debug_print)
750 wpa_dbg(wpa_s, MSG_DEBUG,
751 " skip OWE transition BSS (selection count %d does not exceed %d)",
752 ssid->owe_transition_bss_select_count,
753 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
754 wpa_s->owe_transition_search = 1;
755 return 0;
756 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700757 if (debug_print)
758 wpa_dbg(wpa_s, MSG_DEBUG,
759 " allow in OWE transition mode");
760 return 1;
761 }
762#endif /* CONFIG_OWE */
763
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
765 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800766 if (debug_print)
767 wpa_dbg(wpa_s, MSG_DEBUG,
768 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 return 0;
770 }
771
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800772 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
773 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800774 if (debug_print)
775 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800776 return 1;
777 }
778
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800780 if (debug_print)
781 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782 return 1;
783 }
784
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800785 if (debug_print)
786 wpa_dbg(wpa_s, MSG_DEBUG,
787 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788
789 return 0;
790}
791
792
793static int freq_allowed(int *freqs, int freq)
794{
795 int i;
796
797 if (freqs == NULL)
798 return 1;
799
800 for (i = 0; freqs[i]; i++)
801 if (freqs[i] == freq)
802 return 1;
803 return 0;
804}
805
806
Hai Shalomfdcde762020-04-02 11:19:20 -0700807static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
808 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800809{
810 const struct hostapd_hw_modes *mode = NULL, *modes;
811 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
812 const u8 *rate_ie;
813 int i, j, k;
814
815 if (bss->freq == 0)
816 return 1; /* Cannot do matching without knowing band */
817
818 modes = wpa_s->hw.modes;
819 if (modes == NULL) {
820 /*
821 * The driver does not provide any additional information
822 * about the utilized hardware, so allow the connection attempt
823 * to continue.
824 */
825 return 1;
826 }
827
828 for (i = 0; i < wpa_s->hw.num_modes; i++) {
829 for (j = 0; j < modes[i].num_channels; j++) {
830 int freq = modes[i].channels[j].freq;
831 if (freq == bss->freq) {
832 if (mode &&
833 mode->mode == HOSTAPD_MODE_IEEE80211G)
834 break; /* do not allow 802.11b replace
835 * 802.11g */
836 mode = &modes[i];
837 break;
838 }
839 }
840 }
841
842 if (mode == NULL)
843 return 0;
844
845 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700846 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800847 if (rate_ie == NULL)
848 continue;
849
850 for (j = 2; j < rate_ie[1] + 2; j++) {
851 int flagged = !!(rate_ie[j] & 0x80);
852 int r = (rate_ie[j] & 0x7f) * 5;
853
854 /*
855 * IEEE Std 802.11n-2009 7.3.2.2:
856 * The new BSS Membership selector value is encoded
857 * like a legacy basic rate, but it is not a rate and
858 * only indicates if the BSS members are required to
859 * support the mandatory features of Clause 20 [HT PHY]
860 * in order to join the BSS.
861 */
862 if (flagged && ((rate_ie[j] & 0x7f) ==
863 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
864 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800865 if (debug_print)
866 wpa_dbg(wpa_s, MSG_DEBUG,
867 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800868 return 0;
869 }
870 continue;
871 }
872
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700873 /* There's also a VHT selector for 802.11ac */
874 if (flagged && ((rate_ie[j] & 0x7f) ==
875 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
876 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800877 if (debug_print)
878 wpa_dbg(wpa_s, MSG_DEBUG,
879 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700880 return 0;
881 }
882 continue;
883 }
884
Hai Shalomc3565922019-10-28 11:58:20 -0700885#ifdef CONFIG_SAE
886 if (flagged && ((rate_ie[j] & 0x7f) ==
887 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700888 if (wpa_s->conf->sae_pwe == 0 &&
889 !ssid->sae_password_id &&
890 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700891 if (debug_print)
892 wpa_dbg(wpa_s, MSG_DEBUG,
893 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800894#ifdef CONFIG_TESTING_OPTIONS
895 if (wpa_s->ignore_sae_h2e_only) {
896 wpa_dbg(wpa_s, MSG_DEBUG,
897 "TESTING: Ignore SAE H2E requirement mismatch");
898 continue;
899 }
900#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700901 return 0;
902 }
903 continue;
904 }
905#endif /* CONFIG_SAE */
906
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800907 if (!flagged)
908 continue;
909
910 /* check for legacy basic rates */
911 for (k = 0; k < mode->num_rates; k++) {
912 if (mode->rates[k] == r)
913 break;
914 }
915 if (k == mode->num_rates) {
916 /*
917 * IEEE Std 802.11-2007 7.3.2.2 demands that in
918 * order to join a BSS all required rates
919 * have to be supported by the hardware.
920 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800921 if (debug_print)
922 wpa_dbg(wpa_s, MSG_DEBUG,
923 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
924 r / 10, r % 10,
925 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800926 return 0;
927 }
928 }
929 }
930
931 return 1;
932}
933
934
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800935/*
936 * Test whether BSS is in an ESS.
937 * This is done differently in DMG (60 GHz) and non-DMG bands
938 */
939static int bss_is_ess(struct wpa_bss *bss)
940{
941 if (bss_is_dmg(bss)) {
942 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
943 IEEE80211_CAP_DMG_AP;
944 }
945
946 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
947 IEEE80211_CAP_ESS);
948}
949
950
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800951static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
952{
953 size_t i;
954
955 for (i = 0; i < ETH_ALEN; i++) {
956 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
957 return 0;
958 }
959 return 1;
960}
961
962
963static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
964{
965 size_t i;
966
967 for (i = 0; i < num; i++) {
968 const u8 *a = list + i * ETH_ALEN * 2;
969 const u8 *m = a + ETH_ALEN;
970
971 if (match_mac_mask(a, addr, m))
972 return 1;
973 }
974 return 0;
975}
976
977
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700978static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
979 const u8 **ret_ssid, size_t *ret_ssid_len)
980{
981#ifdef CONFIG_OWE
982 const u8 *owe, *pos, *end, *bssid;
983 u8 ssid_len;
984 struct wpa_bss *open_bss;
985
986 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
987 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
988 return;
989
990 pos = owe + 6;
991 end = owe + 2 + owe[1];
992
993 if (end - pos < ETH_ALEN + 1)
994 return;
995 bssid = pos;
996 pos += ETH_ALEN;
997 ssid_len = *pos++;
998 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
999 return;
1000
1001 /* Match the profile SSID against the OWE transition mode SSID on the
1002 * open network. */
1003 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1004 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1005 *ret_ssid = pos;
1006 *ret_ssid_len = ssid_len;
1007
Hai Shalomfdcde762020-04-02 11:19:20 -07001008 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1009 struct wpa_ssid *ssid;
1010
1011 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1012 if (wpas_network_disabled(wpa_s, ssid))
1013 continue;
1014 if (ssid->ssid_len == ssid_len &&
1015 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1016 /* OWE BSS in transition mode for a currently
1017 * enabled OWE network. */
1018 wpa_dbg(wpa_s, MSG_DEBUG,
1019 "OWE: transition mode OWE SSID for active OWE profile");
1020 bss->flags |= WPA_BSS_OWE_TRANSITION;
1021 break;
1022 }
1023 }
1024 }
1025
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001026 if (bss->ssid_len > 0)
1027 return;
1028
1029 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1030 if (!open_bss)
1031 return;
1032 if (ssid_len != open_bss->ssid_len ||
1033 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1034 wpa_dbg(wpa_s, MSG_DEBUG,
1035 "OWE: transition mode SSID mismatch: %s",
1036 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1037 return;
1038 }
1039
1040 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1041 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1042 wpa_dbg(wpa_s, MSG_DEBUG,
1043 "OWE: transition mode open BSS unexpected info");
1044 return;
1045 }
1046
1047 pos = owe + 6;
1048 end = owe + 2 + owe[1];
1049
1050 if (end - pos < ETH_ALEN + 1)
1051 return;
1052 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1053 wpa_dbg(wpa_s, MSG_DEBUG,
1054 "OWE: transition mode BSSID mismatch: " MACSTR,
1055 MAC2STR(pos));
1056 return;
1057 }
1058 pos += ETH_ALEN;
1059 ssid_len = *pos++;
1060 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1061 return;
1062 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1063 wpa_ssid_txt(pos, ssid_len));
1064 os_memcpy(bss->ssid, pos, ssid_len);
1065 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001066 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001067#endif /* CONFIG_OWE */
1068}
1069
1070
Sunil Ravi26978f32021-04-30 15:19:18 -07001071int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001072{
1073 int i, j;
1074
1075 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1076 return 0;
1077
1078 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1079 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1080
1081 for (i = 0; i < mode->num_channels; i++) {
1082 struct hostapd_channel_data *chan = &mode->channels[i];
1083
1084 if (chan->freq == freq)
1085 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1086 }
1087 }
1088
1089 return 1;
1090}
1091
1092
Hai Shalom899fcc72020-10-19 14:38:18 -07001093static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1094 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001095 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001096 bool debug_print);
1097
1098
1099#ifdef CONFIG_SAE_PK
1100static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1101 struct wpa_bss *orig_bss,
1102 struct wpa_ssid *ssid,
1103 const u8 *match_ssid,
1104 size_t match_ssid_len)
1105{
1106 struct wpa_bss *bss;
1107
1108 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1109 int count;
1110 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001111
1112 if (bss == orig_bss)
1113 continue;
1114 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001115 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001116 continue;
1117
1118 /* TODO: Could be more thorough in checking what kind of
1119 * signal strength or throughput estimate would be acceptable
1120 * compared to the originally selected BSS. */
1121 if (bss->est_throughput < 2000)
1122 return false;
1123
Hai Shalom60840252021-02-19 19:02:11 -08001124 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001125 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1126 bss, count, 0))
1127 return true;
1128 }
1129
1130 return false;
1131}
1132#endif /* CONFIG_SAE_PK */
1133
1134
1135static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1136 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001137 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001138 bool debug_print)
1139{
1140 int res;
1141 bool wpa, check_ssid, osen, rsn_osen = false;
1142 struct wpa_ie_data data;
1143#ifdef CONFIG_MBO
1144 const u8 *assoc_disallow;
1145#endif /* CONFIG_MBO */
1146#ifdef CONFIG_SAE
1147 u8 rsnxe_capa = 0;
1148#endif /* CONFIG_SAE */
1149 const u8 *ie;
1150
1151 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1152 wpa = ie && ie[1];
1153 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1154 wpa |= ie && ie[1];
1155 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1156 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1157 rsn_osen = true;
1158 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1159 osen = ie != NULL;
1160
1161#ifdef CONFIG_SAE
1162 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1163 if (ie && ie[1] >= 1)
1164 rsnxe_capa = ie[2];
1165#endif /* CONFIG_SAE */
1166
1167 check_ssid = wpa || ssid->ssid_len > 0;
1168
1169 if (wpas_network_disabled(wpa_s, ssid)) {
1170 if (debug_print)
1171 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1172 return false;
1173 }
1174
1175 res = wpas_temp_disabled(wpa_s, ssid);
1176 if (res > 0) {
1177 if (debug_print)
1178 wpa_dbg(wpa_s, MSG_DEBUG,
1179 " skip - disabled temporarily for %d second(s)",
1180 res);
1181 return false;
1182 }
1183
1184#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001185 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001186 if (debug_print)
1187 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001188 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001189 return false;
1190 }
1191
1192 if (wpa && ssid->ssid_len == 0 &&
1193 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1194 check_ssid = false;
1195
1196 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1197 /* Only allow wildcard SSID match if an AP advertises active
1198 * WPS operation that matches our mode. */
1199 check_ssid = ssid->ssid_len > 0 ||
1200 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1201 }
1202#endif /* CONFIG_WPS */
1203
1204 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1205 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1206 check_ssid = false;
1207
1208 if (check_ssid &&
1209 (match_ssid_len != ssid->ssid_len ||
1210 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1211 if (debug_print)
1212 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1213 return false;
1214 }
1215
1216 if (ssid->bssid_set &&
1217 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1218 if (debug_print)
1219 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1220 return false;
1221 }
1222
Hai Shalom60840252021-02-19 19:02:11 -08001223 /* check the list of BSSIDs to ignore */
1224 if (ssid->num_bssid_ignore &&
1225 addr_in_list(bss->bssid, ssid->bssid_ignore,
1226 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001227 if (debug_print)
1228 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001229 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001230 return false;
1231 }
1232
Hai Shalom60840252021-02-19 19:02:11 -08001233 /* if there is a list of accepted BSSIDs, only accept those APs */
1234 if (ssid->num_bssid_accept &&
1235 !addr_in_list(bss->bssid, ssid->bssid_accept,
1236 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001237 if (debug_print)
1238 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001239 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001240 return false;
1241 }
1242
1243 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1244 return false;
1245
1246 if (!osen && !wpa &&
1247 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1248 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1249 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1250 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1251 if (debug_print)
1252 wpa_dbg(wpa_s, MSG_DEBUG,
1253 " skip - non-WPA network not allowed");
1254 return false;
1255 }
1256
1257#ifdef CONFIG_WEP
1258 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1259 if (debug_print)
1260 wpa_dbg(wpa_s, MSG_DEBUG,
1261 " skip - ignore WPA/WPA2 AP for WEP network block");
1262 return false;
1263 }
1264#endif /* CONFIG_WEP */
1265
1266 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1267 if (debug_print)
1268 wpa_dbg(wpa_s, MSG_DEBUG,
1269 " skip - non-OSEN network not allowed");
1270 return false;
1271 }
1272
1273 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1274 if (debug_print)
1275 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1276 return false;
1277 }
1278
1279 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1280 !bss_is_pbss(bss)) {
1281 if (debug_print)
1282 wpa_dbg(wpa_s, MSG_DEBUG,
1283 " skip - not ESS, PBSS, or MBSS");
1284 return false;
1285 }
1286
1287 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1288 if (debug_print)
1289 wpa_dbg(wpa_s, MSG_DEBUG,
1290 " skip - PBSS mismatch (ssid %d bss %d)",
1291 ssid->pbss, bss_is_pbss(bss));
1292 return false;
1293 }
1294
1295 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1296 if (debug_print)
1297 wpa_dbg(wpa_s, MSG_DEBUG,
1298 " skip - frequency not allowed");
1299 return false;
1300 }
1301
1302#ifdef CONFIG_MESH
1303 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1304 ssid->frequency != bss->freq) {
1305 if (debug_print)
1306 wpa_dbg(wpa_s, MSG_DEBUG,
1307 " skip - frequency not allowed (mesh)");
1308 return false;
1309 }
1310#endif /* CONFIG_MESH */
1311
1312 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1313 if (debug_print)
1314 wpa_dbg(wpa_s, MSG_DEBUG,
1315 " skip - rate sets do not match");
1316 return false;
1317 }
1318
1319#ifdef CONFIG_SAE
1320 if ((wpa_s->conf->sae_pwe == 1 || ssid->sae_password_id) &&
1321 wpa_s->conf->sae_pwe != 3 && wpa_key_mgmt_sae(ssid->key_mgmt) &&
1322 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1323 if (debug_print)
1324 wpa_dbg(wpa_s, MSG_DEBUG,
1325 " skip - SAE H2E required, but not supported by the AP");
1326 return false;
1327 }
1328#endif /* CONFIG_SAE */
1329
1330#ifdef CONFIG_SAE_PK
1331 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1332 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1333 if (debug_print)
1334 wpa_dbg(wpa_s, MSG_DEBUG,
1335 " skip - SAE-PK required, but not supported by the AP");
1336 return false;
1337 }
1338#endif /* CONFIG_SAE_PK */
1339
1340#ifndef CONFIG_IBSS_RSN
1341 if (ssid->mode == WPAS_MODE_IBSS &&
1342 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1343 if (debug_print)
1344 wpa_dbg(wpa_s, MSG_DEBUG,
1345 " skip - IBSS RSN not supported in the build");
1346 return false;
1347 }
1348#endif /* !CONFIG_IBSS_RSN */
1349
1350#ifdef CONFIG_P2P
1351 if (ssid->p2p_group &&
1352 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1353 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1354 if (debug_print)
1355 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1356 return false;
1357 }
1358
1359 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1360 struct wpabuf *p2p_ie;
1361 u8 dev_addr[ETH_ALEN];
1362
1363 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1364 if (!ie) {
1365 if (debug_print)
1366 wpa_dbg(wpa_s, MSG_DEBUG,
1367 " skip - no P2P element");
1368 return false;
1369 }
1370 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1371 if (!p2p_ie) {
1372 if (debug_print)
1373 wpa_dbg(wpa_s, MSG_DEBUG,
1374 " skip - could not fetch P2P element");
1375 return false;
1376 }
1377
1378 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1379 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1380 if (debug_print)
1381 wpa_dbg(wpa_s, MSG_DEBUG,
1382 " skip - no matching GO P2P Device Address in P2P element");
1383 wpabuf_free(p2p_ie);
1384 return false;
1385 }
1386 wpabuf_free(p2p_ie);
1387 }
1388
1389 /*
1390 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1391 * P2P Group Capability Bitmap and we are not in Group Formation with
1392 * that device.
1393 */
1394#endif /* CONFIG_P2P */
1395
1396 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1397 struct os_reltime diff;
1398
1399 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1400 if (debug_print)
1401 wpa_dbg(wpa_s, MSG_DEBUG,
1402 " skip - scan result not recent enough (%u.%06u seconds too old)",
1403 (unsigned int) diff.sec,
1404 (unsigned int) diff.usec);
1405 return false;
1406 }
1407#ifdef CONFIG_MBO
1408#ifdef CONFIG_TESTING_OPTIONS
1409 if (wpa_s->ignore_assoc_disallow)
1410 goto skip_assoc_disallow;
1411#endif /* CONFIG_TESTING_OPTIONS */
1412 assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1413 if (assoc_disallow && assoc_disallow[1] >= 1) {
1414 if (debug_print)
1415 wpa_dbg(wpa_s, MSG_DEBUG,
1416 " skip - MBO association disallowed (reason %u)",
1417 assoc_disallow[2]);
1418 return false;
1419 }
1420
1421 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1422 if (debug_print)
1423 wpa_dbg(wpa_s, MSG_DEBUG,
1424 " skip - AP temporarily disallowed");
1425 return false;
1426 }
1427#ifdef CONFIG_TESTING_OPTIONS
1428skip_assoc_disallow:
1429#endif /* CONFIG_TESTING_OPTIONS */
1430#endif /* CONFIG_MBO */
1431
1432#ifdef CONFIG_DPP
1433 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1434 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1435 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1436 !ssid->dpp_csign)) {
1437 if (debug_print)
1438 wpa_dbg(wpa_s, MSG_DEBUG,
1439 " skip - no PMKSA entry for DPP");
1440 return false;
1441 }
1442#endif /* CONFIG_DPP */
1443
1444#ifdef CONFIG_SAE_PK
1445 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1446 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1447 ((ssid->sae_password &&
1448 sae_pk_valid_password(ssid->sae_password)) ||
1449 (!ssid->sae_password && ssid->passphrase &&
1450 sae_pk_valid_password(ssid->passphrase))) &&
1451 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1452 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1453 match_ssid_len)) {
1454 if (debug_print)
1455 wpa_dbg(wpa_s, MSG_DEBUG,
1456 " skip - another acceptable BSS with SAE-PK in the same ESS");
1457 return false;
1458 }
1459#endif /* CONFIG_SAE_PK */
1460
1461 if (bss->ssid_len == 0) {
1462 if (debug_print)
1463 wpa_dbg(wpa_s, MSG_DEBUG,
1464 " skip - no SSID known for the BSS");
1465 return false;
1466 }
1467
1468 /* Matching configuration found */
1469 return true;
1470}
1471
1472
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001473struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1474 int i, struct wpa_bss *bss,
1475 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001476 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001477{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001478 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001479 const u8 *ie;
1480 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001481 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001482 const u8 *match_ssid;
1483 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001484 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001485
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001486 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001487 wpa_ie_len = ie ? ie[1] : 0;
1488
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001489 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001490 rsn_ie_len = ie ? ie[1] : 0;
1491
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001492 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1493 osen = ie != NULL;
1494
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001495 if (debug_print) {
1496 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1497 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1498 i, MAC2STR(bss->bssid),
1499 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1500 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1501 bss->freq,
1502 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1503 " wps" : "",
1504 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1505 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1506 ? " p2p" : "",
1507 osen ? " osen=1" : "");
1508 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001509
Hai Shalom60840252021-02-19 19:02:11 -08001510 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1511 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001512 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001513 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001514 /*
1515 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001516 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001517 * should not be done with multiple enabled networks to
1518 * avoid getting forced to move into a worse ESS on
1519 * single error if there are no other BSSes of the
1520 * current ESS.
1521 */
1522 limit = 0;
1523 }
Hai Shalom60840252021-02-19 19:02:11 -08001524 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001525 if (debug_print) {
1526 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001527 " skip - BSSID ignored (count=%d limit=%d)",
1528 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001529 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001530 return NULL;
1531 }
1532 }
1533
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001534 match_ssid = bss->ssid;
1535 match_ssid_len = bss->ssid_len;
1536 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1537
1538 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001539 if (debug_print)
1540 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001541 return NULL;
1542 }
1543
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001544 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001545 if (debug_print)
1546 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001547 return NULL;
1548 }
1549
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001550 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001551 if (debug_print)
1552 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001553 return NULL;
1554 }
1555
Hai Shalomfdcde762020-04-02 11:19:20 -07001556 if (disabled_freq(wpa_s, bss->freq)) {
1557 if (debug_print)
1558 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1559 return NULL;
1560 }
1561
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001562 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001563 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001564 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001565 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001566 }
1567
1568 /* No matching configuration found */
1569 return NULL;
1570}
1571
1572
1573static struct wpa_bss *
1574wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001576 struct wpa_ssid **selected_ssid,
1577 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001578{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001579 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001580
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001581 if (wpa_s->current_ssid) {
1582 struct wpa_ssid *ssid;
1583
1584 wpa_dbg(wpa_s, MSG_DEBUG,
1585 "Scan results matching the currently selected network");
1586 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1587 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1588
1589 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1590 only_first_ssid, 0);
1591 if (ssid != wpa_s->current_ssid)
1592 continue;
1593 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1594 " freq=%d level=%d snr=%d est_throughput=%u",
1595 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1596 bss->snr, bss->est_throughput);
1597 }
1598 }
1599
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001600 if (only_first_ssid)
1601 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1602 group->id);
1603 else
1604 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1605 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001606
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001607 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1608 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001609
1610 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001611 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001612 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001613 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001614 if (!*selected_ssid)
1615 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001616 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001617 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001618 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001619 MAC2STR(bss->bssid),
1620 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1621 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001622 }
1623
1624 return NULL;
1625}
1626
1627
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001628struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1629 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001630{
1631 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001632 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001633 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001634 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001636 if (wpa_s->last_scan_res == NULL ||
1637 wpa_s->last_scan_res_used == 0)
1638 return NULL; /* no scan results from last update */
1639
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001640 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001641 /* check that next_ssid is still valid */
1642 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1643 if (ssid == wpa_s->next_ssid)
1644 break;
1645 }
1646 next_ssid = ssid;
1647 wpa_s->next_ssid = NULL;
1648 }
1649
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001650 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001651 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1652 if (next_ssid && next_ssid->priority ==
1653 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001654 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001655 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001656 if (selected)
1657 break;
1658 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001659 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001660 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001661 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001662 if (selected)
1663 break;
1664 }
1665
Hai Shalom60840252021-02-19 19:02:11 -08001666 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001667 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001668 wpa_dbg(wpa_s, MSG_DEBUG,
1669 "No APs found - clear BSSID ignore list and try again");
1670 wpa_bssid_ignore_clear(wpa_s);
1671 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672 } else if (selected == NULL)
1673 break;
1674 }
1675
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001676 ssid = *selected_ssid;
1677 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1678 !ssid->passphrase && !ssid->ext_psk) {
1679 const char *field_name, *txt = NULL;
1680
1681 wpa_dbg(wpa_s, MSG_DEBUG,
1682 "PSK/passphrase not yet available for the selected network");
1683
1684 wpas_notify_network_request(wpa_s, ssid,
1685 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1686
1687 field_name = wpa_supplicant_ctrl_req_to_string(
1688 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1689 if (field_name == NULL)
1690 return NULL;
1691
1692 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1693
1694 selected = NULL;
1695 }
1696
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697 return selected;
1698}
1699
1700
1701static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1702 int timeout_sec, int timeout_usec)
1703{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001704 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001705 /*
1706 * No networks are enabled; short-circuit request so
1707 * we don't wait timeout seconds before transitioning
1708 * to INACTIVE state.
1709 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001710 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1711 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001712 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1713 return;
1714 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001715
1716 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001717 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1718}
1719
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001720
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001721int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001722 struct wpa_bss *selected,
1723 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001724{
1725 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1726 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1727 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001728 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001729#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001730 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1731 wpa_s->p2p_in_provisioning) {
1732 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1733 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001734 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001735 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001736#endif /* CONFIG_P2P */
1737
1738#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001739 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001740 wpas_wps_cancel(wpa_s);
1741#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001742 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743 }
1744
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001745 wpa_msg(wpa_s, MSG_DEBUG,
1746 "Considering connect request: reassociate: %d selected: "
1747 MACSTR " bssid: " MACSTR " pending: " MACSTR
1748 " wpa_state: %s ssid=%p current_ssid=%p",
1749 wpa_s->reassociate, MAC2STR(selected->bssid),
1750 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1751 wpa_supplicant_state_txt(wpa_s->wpa_state),
1752 ssid, wpa_s->current_ssid);
1753
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001754 /*
1755 * Do not trigger new association unless the BSSID has changed or if
1756 * reassociation is requested. If we are in process of associating with
1757 * the selected BSSID, do not trigger new attempt.
1758 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001759 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001760 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1761 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1762 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001763 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1764 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1765 0) ||
1766 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1767 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001768 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1769 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001770 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001771 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001772 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1773 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001774 wpa_supplicant_associate(wpa_s, selected, ssid);
1775 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001776 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1777 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001779
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001780 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001781}
1782
1783
1784static struct wpa_ssid *
1785wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1786{
Hai Shalomfdcde762020-04-02 11:19:20 -07001787 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001788 struct wpa_ssid *ssid;
1789
1790 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1791 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1792 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001793 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001794 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001795#ifndef CONFIG_IBSS_RSN
1796 if (ssid->mode == WPAS_MODE_IBSS &&
1797 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1798 WPA_KEY_MGMT_WPA_NONE))) {
1799 wpa_msg(wpa_s, MSG_INFO,
1800 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1801 wpa_ssid_txt(ssid->ssid,
1802 ssid->ssid_len));
1803 continue;
1804 }
1805#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001806 if (ssid->mode == WPAS_MODE_IBSS ||
1807 ssid->mode == WPAS_MODE_AP ||
1808 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001809 return ssid;
1810 }
1811 }
1812 return NULL;
1813}
1814
1815
1816/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1817 * on BSS added and BSS changed events */
1818static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001819 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001821 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001822
1823 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1824 return;
1825
Jouni Malinen87fd2792011-05-16 18:35:42 +03001826 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001828
Jouni Malinen87fd2792011-05-16 18:35:42 +03001829 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 if (ssid == NULL)
1831 continue;
1832
Jouni Malinen87fd2792011-05-16 18:35:42 +03001833 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834 if (rsn == NULL)
1835 continue;
1836
Jouni Malinen87fd2792011-05-16 18:35:42 +03001837 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 }
1839
1840}
1841
1842
Hai Shalomfdcde762020-04-02 11:19:20 -07001843#ifndef CONFIG_NO_ROAMING
1844
1845static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1846{
1847 if (noise == WPA_INVALID_NOISE)
1848 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1849 DEFAULT_NOISE_FLOOR_2GHZ;
1850 return avg_signal - noise;
1851}
1852
1853
1854static unsigned int
1855wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1856 const struct wpa_bss *bss, int snr)
1857{
1858 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001859 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001860 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1861
Hai Shalomc1a21442022-02-04 13:43:00 -08001862 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07001863}
1864
Hai Shalomfdcde762020-04-02 11:19:20 -07001865
Hai Shalom899fcc72020-10-19 14:38:18 -07001866int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1867 struct wpa_bss *current_bss,
1868 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001869{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001870 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001871 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001872 int cur_level;
1873 unsigned int cur_est, sel_est;
1874 struct wpa_signal_info si;
1875 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001876 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001879 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001880 " freq=%d level=%d snr=%d est_throughput=%u",
1881 MAC2STR(current_bss->bssid),
1882 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001883 current_bss->snr, current_bss->est_throughput);
1884 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001885 " freq=%d level=%d snr=%d est_throughput=%u",
1886 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001887 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001888
1889 if (wpa_s->current_ssid->bssid_set &&
1890 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1891 0) {
1892 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1893 "has preferred BSSID");
1894 return 1;
1895 }
1896
Hai Shalomfdcde762020-04-02 11:19:20 -07001897 cur_level = current_bss->level;
1898 cur_est = current_bss->est_throughput;
1899 sel_est = selected->est_throughput;
1900
1901 /*
1902 * Try to poll the signal from the driver since this will allow to get
1903 * more accurate values. In some cases, there can be big differences
1904 * between the RSSI of the Probe Response frames of the AP we are
1905 * associated with and the Beacon frames we hear from the same AP after
1906 * association. This can happen, e.g., when there are two antennas that
1907 * hear the AP very differently. If the driver chooses to hear the
1908 * Probe Response frames during the scan on the "bad" antenna because
1909 * it wants to save power, but knows to choose the other antenna after
1910 * association, we will hear our AP with a low RSSI as part of the
1911 * scan even when we can hear it decently on the other antenna. To cope
1912 * with this, ask the driver to teach us how it hears the AP. Also, the
1913 * scan results may be a bit old, since we can very quickly get fresh
1914 * information about our currently associated AP.
1915 */
1916 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1917 (si.avg_beacon_signal || si.avg_signal)) {
1918 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1919 si.avg_signal;
1920 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
1921 si.current_noise);
1922
1923 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
1924 current_bss,
1925 cur_snr);
1926 wpa_dbg(wpa_s, MSG_DEBUG,
1927 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
1928 cur_level, cur_snr, cur_est);
1929 }
1930
1931 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001932 wpa_dbg(wpa_s, MSG_DEBUG,
1933 "Allow reassociation - selected BSS has better estimated throughput");
1934 return 1;
1935 }
1936
Dmitry Shmidte4663042016-04-04 10:07:49 -07001937 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1938
Hai Shalomfdcde762020-04-02 11:19:20 -07001939 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
1940 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001941 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1942 "signal level");
1943 return 0;
1944 }
1945
Hai Shalomfdcde762020-04-02 11:19:20 -07001946 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001947 wpa_dbg(wpa_s, MSG_DEBUG,
1948 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001949 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001950 }
1951
Hai Shalomfdcde762020-04-02 11:19:20 -07001952 if (cur_snr > GREAT_SNR) {
1953 wpa_dbg(wpa_s, MSG_DEBUG,
1954 "Skip roam - Current BSS has good SNR (%u > %u)",
1955 cur_snr, GREAT_SNR);
1956 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001957 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001958
Hai Shalomfdcde762020-04-02 11:19:20 -07001959 if (cur_level < -85) /* ..-86 dBm */
1960 min_diff = 1;
1961 else if (cur_level < -80) /* -85..-81 dBm */
1962 min_diff = 2;
1963 else if (cur_level < -75) /* -80..-76 dBm */
1964 min_diff = 3;
1965 else if (cur_level < -70) /* -75..-71 dBm */
1966 min_diff = 4;
1967 else if (cur_level < 0) /* -70..-1 dBm */
1968 min_diff = 5;
1969 else /* unspecified units (not in dBm) */
1970 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001971
Hai Shalomfdcde762020-04-02 11:19:20 -07001972 if (cur_est > sel_est * 1.5)
1973 min_diff += 10;
1974 else if (cur_est > sel_est * 1.2)
1975 min_diff += 5;
1976 else if (cur_est > sel_est * 1.1)
1977 min_diff += 2;
1978 else if (cur_est > sel_est)
1979 min_diff++;
1980 else if (sel_est > cur_est * 1.5)
1981 min_diff -= 10;
1982 else if (sel_est > cur_est * 1.2)
1983 min_diff -= 5;
1984 else if (sel_est > cur_est * 1.1)
1985 min_diff -= 2;
1986 else if (sel_est > cur_est)
1987 min_diff--;
1988
1989 if (to_5ghz)
1990 min_diff -= 2;
1991 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001992 if (diff < min_diff) {
1993 wpa_dbg(wpa_s, MSG_DEBUG,
1994 "Skip roam - too small difference in signal level (%d < %d)",
1995 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07001996 ret = 0;
1997 } else {
1998 wpa_dbg(wpa_s, MSG_DEBUG,
1999 "Allow reassociation due to difference in signal level (%d >= %d)",
2000 diff, min_diff);
2001 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002002 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002003 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2004 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2005 " sel_freq=%d sel_level=%d sel_est=%d",
2006 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2007 MAC2STR(current_bss->bssid),
2008 current_bss->freq, cur_level, cur_est,
2009 MAC2STR(selected->bssid),
2010 selected->freq, selected->level, sel_est);
2011 return ret;
2012}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002013
Hai Shalom899fcc72020-10-19 14:38:18 -07002014#endif /* CONFIG_NO_ROAMING */
2015
2016
2017static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2018 struct wpa_bss *selected,
2019 struct wpa_ssid *ssid)
2020{
2021 struct wpa_bss *current_bss = NULL;
2022
2023 if (wpa_s->reassociate)
2024 return 1; /* explicit request to reassociate */
2025 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2026 return 1; /* we are not associated; continue */
2027 if (wpa_s->current_ssid == NULL)
2028 return 1; /* unknown current SSID */
2029 if (wpa_s->current_ssid != ssid)
2030 return 1; /* different network block */
2031
2032 if (wpas_driver_bss_selection(wpa_s))
2033 return 0; /* Driver-based roaming */
2034
2035 if (wpa_s->current_ssid->ssid)
2036 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2037 wpa_s->current_ssid->ssid,
2038 wpa_s->current_ssid->ssid_len);
2039 if (!current_bss)
2040 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2041
2042 if (!current_bss)
2043 return 1; /* current BSS not seen in scan results */
2044
2045 if (current_bss == selected)
2046 return 0;
2047
2048 if (selected->last_update_idx > current_bss->last_update_idx)
2049 return 1; /* current BSS not seen in the last scan */
2050
2051#ifndef CONFIG_NO_ROAMING
2052 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2053 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002054#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002055 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002056#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002057}
2058
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002059
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002060/*
2061 * Return a negative value if no scan results could be fetched or if scan
2062 * results should not be shared with other virtual interfaces.
2063 * Return 0 if scan results were fetched and may be shared with other
2064 * interfaces.
2065 * Return 1 if scan results may be shared with other virtual interfaces but may
2066 * not trigger any operations.
2067 * Return 2 if the interface was removed and cannot be used.
2068 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002069static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002070 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002071 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002072{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002073 struct wpa_scan_results *scan_res = NULL;
2074 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002076#ifndef CONFIG_NO_RANDOM_POOL
2077 size_t i, num;
2078#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002079
2080#ifdef CONFIG_AP
2081 if (wpa_s->ap_iface)
2082 ap = 1;
2083#endif /* CONFIG_AP */
2084
2085 wpa_supplicant_notify_scanning(wpa_s, 0);
2086
2087 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2088 data ? &data->scan_info :
2089 NULL, 1);
2090 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002091 if (wpa_s->conf->ap_scan == 2 || ap ||
2092 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002093 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002094 if (!own_request)
2095 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002096 if (data && data->scan_info.external_scan)
2097 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002098 if (wpa_s->scan_res_fail_handler) {
2099 void (*handler)(struct wpa_supplicant *wpa_s);
2100
2101 handler = wpa_s->scan_res_fail_handler;
2102 wpa_s->scan_res_fail_handler = NULL;
2103 handler(wpa_s);
2104 } else {
2105 wpa_dbg(wpa_s, MSG_DEBUG,
2106 "Failed to get scan results - try scanning again");
2107 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2108 }
2109
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002110 ret = -1;
2111 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002112 }
2113
2114#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002115 num = scan_res->num;
2116 if (num > 10)
2117 num = 10;
2118 for (i = 0; i < num; i++) {
2119 u8 buf[5];
2120 struct wpa_scan_res *res = scan_res->res[i];
2121 buf[0] = res->bssid[5];
2122 buf[1] = res->qual & 0xff;
2123 buf[2] = res->noise & 0xff;
2124 buf[3] = res->level & 0xff;
2125 buf[4] = res->tsf & 0xff;
2126 random_add_randomness(buf, sizeof(buf));
2127 }
2128#endif /* CONFIG_NO_RANDOM_POOL */
2129
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002130 if (update_only) {
2131 ret = 1;
2132 goto scan_work_done;
2133 }
2134
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002135 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002136 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002137 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2138 struct wpa_scan_results *scan_res);
2139
2140 scan_res_handler = wpa_s->scan_res_handler;
2141 wpa_s->scan_res_handler = NULL;
2142 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002143 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002144 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002145 }
2146
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002147 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002148 wpa_s->own_scan_running,
2149 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002150 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002151 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2152 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002153 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2154 wpa_s->manual_scan_id);
2155 wpa_s->manual_scan_use_id = 0;
2156 } else {
2157 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2158 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002159 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160
2161 wpas_notify_scan_done(wpa_s, 1);
2162
Hai Shalomfdcde762020-04-02 11:19:20 -07002163 if (ap) {
2164 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2165#ifdef CONFIG_AP
2166 if (wpa_s->ap_iface->scan_cb)
2167 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2168#endif /* CONFIG_AP */
2169 goto scan_work_done;
2170 }
2171
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002172 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002173 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
Dmitry Shmidt04949592012-07-19 12:16:46 -07002174 wpa_scan_results_free(scan_res);
2175 return 0;
2176 }
2177
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002178 if (wnm_scan_process(wpa_s, 1) > 0)
2179 goto scan_work_done;
2180
Hai Shalomc1a21442022-02-04 13:43:00 -08002181 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002182 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002183
Hai Shalom021b0b52019-04-10 11:17:58 -07002184 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002185 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2186 goto scan_work_done;
2187
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002188 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2189 goto scan_work_done;
2190
2191 if (autoscan_notify_scan(wpa_s, scan_res))
2192 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002193
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002194 if (wpa_s->disconnected) {
2195 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002196 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002197 }
2198
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002199 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002200 bgscan_notify_scan(wpa_s, scan_res) == 1)
2201 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002202
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002203 wpas_wps_update_ap_info(wpa_s, scan_res);
2204
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002205 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2206 wpa_s->wpa_state < WPA_COMPLETED)
2207 goto scan_work_done;
2208
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002209 wpa_scan_results_free(scan_res);
2210
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002211 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002212 struct wpa_radio_work *work = wpa_s->scan_work;
2213 wpa_s->scan_work = NULL;
2214 radio_work_done(work);
2215 }
2216
Hai Shalomc3565922019-10-28 11:58:20 -07002217 os_free(wpa_s->last_scan_freqs);
2218 wpa_s->last_scan_freqs = NULL;
2219 wpa_s->num_last_scan_freqs = 0;
2220 if (own_request && data &&
2221 data->scan_info.freqs && data->scan_info.num_freqs) {
2222 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2223 data->scan_info.num_freqs);
2224 if (wpa_s->last_scan_freqs) {
2225 os_memcpy(wpa_s->last_scan_freqs,
2226 data->scan_info.freqs,
2227 sizeof(int) * data->scan_info.num_freqs);
2228 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2229 }
2230 }
2231
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002232 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002233
2234scan_work_done:
2235 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002236 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002237 struct wpa_radio_work *work = wpa_s->scan_work;
2238 wpa_s->scan_work = NULL;
2239 radio_work_done(work);
2240 }
2241 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002242}
2243
2244
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002245static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002246 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002247{
2248 struct wpa_bss *selected;
2249 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002250 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2251
2252 if (time_to_reenable > 0) {
2253 wpa_dbg(wpa_s, MSG_DEBUG,
2254 "Postpone network selection by %d seconds since all networks are disabled",
2255 time_to_reenable);
2256 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2257 eloop_register_timeout(time_to_reenable, 0,
2258 wpas_network_reenabled, wpa_s, NULL);
2259 return 0;
2260 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002261
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002262 if (wpa_s->p2p_mgmt)
2263 return 0; /* no normal connection on p2p_mgmt interface */
2264
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002265 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002266 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002267
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002268#ifdef CONFIG_MESH
2269 if (wpa_s->ifmsh) {
2270 wpa_msg(wpa_s, MSG_INFO,
2271 "Avoiding join because we already joined a mesh group");
2272 return 0;
2273 }
2274#endif /* CONFIG_MESH */
2275
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002276 if (selected) {
2277 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002278 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002279 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002280 if (new_scan)
2281 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002282 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283 }
2284
Hai Shalomc3565922019-10-28 11:58:20 -07002285 wpa_s->suitable_network++;
2286
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002287 if (ssid != wpa_s->current_ssid &&
2288 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2289 wpa_s->own_disconnect_req = 1;
2290 wpa_supplicant_deauthenticate(
2291 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2292 }
2293
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002294 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002295 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002296 return -1;
2297 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002298 if (new_scan)
2299 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002300 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002301 * Do not allow other virtual radios to trigger operations based
2302 * on these scan results since we do not want them to start
2303 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002304 */
2305 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002307 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2309 ssid = wpa_supplicant_pick_new_network(wpa_s);
2310 if (ssid) {
2311 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2312 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002313 if (new_scan)
2314 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002315 } else if (own_request) {
2316 /*
2317 * No SSID found. If SCAN results are as a result of
2318 * own scan request and not due to a scan request on
2319 * another shared interface, try another scan.
2320 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002321 int timeout_sec = wpa_s->scan_interval;
2322 int timeout_usec = 0;
2323#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002324 int res;
2325
2326 res = wpas_p2p_scan_no_go_seen(wpa_s);
2327 if (res == 2)
2328 return 2;
2329 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002330 return 0;
2331
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002332 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002333 wpa_s->show_group_started ||
2334 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002335 /*
2336 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002337 * state and during P2P join-a-group operation
2338 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002339 */
2340 timeout_sec = 0;
2341 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002342 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2343 timeout_usec);
2344 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002345 }
2346#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002347#ifdef CONFIG_INTERWORKING
2348 if (wpa_s->conf->auto_interworking &&
2349 wpa_s->conf->interworking &&
2350 wpa_s->conf->cred) {
2351 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2352 "start ANQP fetch since no matching "
2353 "networks found");
2354 wpa_s->network_select = 1;
2355 wpa_s->auto_network_select = 1;
2356 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002357 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002358 }
2359#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002360#ifdef CONFIG_WPS
2361 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2362 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2363 timeout_sec = 0;
2364 timeout_usec = 500000;
2365 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2366 timeout_usec);
2367 return 0;
2368 }
2369#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002370#ifdef CONFIG_OWE
2371 if (wpa_s->owe_transition_search) {
2372 wpa_dbg(wpa_s, MSG_DEBUG,
2373 "OWE: Use shorter wait during transition mode search");
2374 timeout_sec = 0;
2375 timeout_usec = 500000;
2376 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2377 timeout_usec);
2378 return 0;
2379 }
2380#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002381 if (wpa_supplicant_req_sched_scan(wpa_s))
2382 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2383 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002384
2385 wpa_msg_ctrl(wpa_s, MSG_INFO,
2386 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002387 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002388 }
2389 }
2390 return 0;
2391}
2392
2393
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002394static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2395 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002396{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002397 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002398 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002399
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002400 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002401 if (res == 2) {
2402 /*
2403 * Interface may have been removed, so must not dereference
2404 * wpa_s after this.
2405 */
2406 return 1;
2407 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002408
2409 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002410 /*
2411 * If no scan results could be fetched, then no need to
2412 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002413 * this scan. Similarly, if scan results started a new operation on this
2414 * interface, do not notify other interfaces to avoid concurrent
2415 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002416 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002417 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418 }
2419
2420 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002421 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002422 * so, they get updated with this same scan info.
2423 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002424 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2425 radio_list) {
2426 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002427 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2428 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002429 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2430 res > 0);
2431 if (res < 0)
2432 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002433 }
2434 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002435
2436 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002437}
2438
2439#endif /* CONFIG_NO_SCAN_PROCESSING */
2440
2441
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002442int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2443{
2444#ifdef CONFIG_NO_SCAN_PROCESSING
2445 return -1;
2446#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002447 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002448
Dmitry Shmidt29333592017-01-09 12:27:11 -08002449 wpa_s->ignore_post_flush_scan_res = 0;
2450
Dmitry Shmidt41712582015-06-29 11:02:15 -07002451 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002452 return -1;
2453
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002454 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002455 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002456 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002457 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2458 return -1;
2459 }
2460
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002461 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002462#endif /* CONFIG_NO_SCAN_PROCESSING */
2463}
2464
Dmitry Shmidt04949592012-07-19 12:16:46 -07002465#ifdef CONFIG_WNM
2466
2467static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2468{
2469 struct wpa_supplicant *wpa_s = eloop_ctx;
2470
2471 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2472 return;
2473
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002474 if (!wpa_s->no_keep_alive) {
2475 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2476 MAC2STR(wpa_s->bssid));
2477 /* TODO: could skip this if normal data traffic has been sent */
2478 /* TODO: Consider using some more appropriate data frame for
2479 * this */
2480 if (wpa_s->l2)
2481 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2482 (u8 *) "", 0);
2483 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002484
2485#ifdef CONFIG_SME
2486 if (wpa_s->sme.bss_max_idle_period) {
2487 unsigned int msec;
2488 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2489 if (msec > 100)
2490 msec -= 100;
2491 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2492 wnm_bss_keep_alive, wpa_s, NULL);
2493 }
2494#endif /* CONFIG_SME */
2495}
2496
2497
2498static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2499 const u8 *ies, size_t ies_len)
2500{
2501 struct ieee802_11_elems elems;
2502
2503 if (ies == NULL)
2504 return;
2505
2506 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2507 return;
2508
2509#ifdef CONFIG_SME
2510 if (elems.bss_max_idle_period) {
2511 unsigned int msec;
2512 wpa_s->sme.bss_max_idle_period =
2513 WPA_GET_LE16(elems.bss_max_idle_period);
2514 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2515 "TU)%s", wpa_s->sme.bss_max_idle_period,
2516 (elems.bss_max_idle_period[2] & 0x01) ?
2517 " (protected keep-live required)" : "");
2518 if (wpa_s->sme.bss_max_idle_period == 0)
2519 wpa_s->sme.bss_max_idle_period = 1;
2520 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2521 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2522 /* msec times 1000 */
2523 msec = wpa_s->sme.bss_max_idle_period * 1024;
2524 if (msec > 100)
2525 msec -= 100;
2526 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2527 wnm_bss_keep_alive, wpa_s,
2528 NULL);
2529 }
2530 }
2531#endif /* CONFIG_SME */
2532}
2533
2534#endif /* CONFIG_WNM */
2535
2536
2537void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2538{
2539#ifdef CONFIG_WNM
2540 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2541#endif /* CONFIG_WNM */
2542}
2543
2544
Dmitry Shmidt051af732013-10-22 13:52:46 -07002545#ifdef CONFIG_INTERWORKING
2546
2547static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2548 size_t len)
2549{
2550 int res;
2551
2552 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2553 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2554 if (res) {
2555 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2556 }
2557
2558 return res;
2559}
2560
2561
2562static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2563 const u8 *ies, size_t ies_len)
2564{
2565 struct ieee802_11_elems elems;
2566
2567 if (ies == NULL)
2568 return;
2569
2570 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2571 return;
2572
2573 if (elems.qos_map_set) {
2574 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2575 elems.qos_map_set_len);
2576 }
2577}
2578
2579#endif /* CONFIG_INTERWORKING */
2580
2581
Hai Shalom74f70d42019-02-11 14:42:39 -08002582static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2583 const u8 *ies, size_t ies_len)
2584{
2585 struct ieee802_11_elems elems;
2586 const u8 *map_sub_elem, *pos;
2587 size_t len;
2588
Hai Shalomfdcde762020-04-02 11:19:20 -07002589 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002590
Hai Shalomfdcde762020-04-02 11:19:20 -07002591 if (!ies ||
2592 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2593 !elems.multi_ap || elems.multi_ap_len < 7)
2594 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002595
2596 pos = elems.multi_ap + 4;
2597 len = elems.multi_ap_len - 4;
2598
2599 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002600 if (!map_sub_elem || map_sub_elem[1] < 1)
2601 return;
2602
2603 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2604 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2605 MULTI_AP_FRONTHAUL_BSS);
2606 wpa_s->multi_ap_ie = 1;
2607}
2608
2609
2610static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2611{
2612 if (!wpa_s->current_ssid ||
2613 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2614 return;
2615
2616 if (!wpa_s->multi_ap_ie) {
2617 wpa_printf(MSG_INFO,
2618 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002619 goto fail;
2620 }
2621
Hai Shalomfdcde762020-04-02 11:19:20 -07002622 if (!wpa_s->multi_ap_backhaul) {
2623 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002624 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2625 wpa_printf(MSG_INFO,
2626 "WPS active, accepting fronthaul-only BSS");
2627 /* Don't set 4addr mode in this case, so just return */
2628 return;
2629 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002630 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2631 goto fail;
2632 }
2633
2634 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2635 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2636 goto fail;
2637 }
2638 wpa_s->enabled_4addr_mode = 1;
2639 return;
2640
2641fail:
2642 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2643}
2644
2645
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002646#ifdef CONFIG_FST
2647static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2648 const u8 *ie, size_t ie_len)
2649{
2650 struct mb_ies_info mb_ies;
2651
2652 if (!ie || !ie_len || !wpa_s->fst)
2653 return -ENOENT;
2654
2655 os_memset(&mb_ies, 0, sizeof(mb_ies));
2656
2657 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2658 size_t len;
2659
2660 len = 2 + ie[1];
2661 if (len > ie_len) {
2662 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2663 ie, ie_len);
2664 break;
2665 }
2666
2667 if (ie[0] == WLAN_EID_MULTI_BAND) {
2668 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2669 (unsigned int) len);
2670 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2671 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2672 mb_ies.nof_ies++;
2673 }
2674
2675 ie_len -= len;
2676 ie += len;
2677 }
2678
2679 if (mb_ies.nof_ies > 0) {
2680 wpabuf_free(wpa_s->received_mb_ies);
2681 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2682 return 0;
2683 }
2684
2685 return -ENOENT;
2686}
2687#endif /* CONFIG_FST */
2688
2689
Hai Shalomc1a21442022-02-04 13:43:00 -08002690static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2691 union wpa_event_data *data)
2692{
2693 int sel;
2694 const u8 *p;
2695 int l, len;
2696 bool found = false;
2697 struct wpa_ie_data ie;
2698 struct wpa_ssid *ssid = wpa_s->current_ssid;
2699 struct wpa_bss *bss = wpa_s->current_bss;
2700 int pmf;
2701
2702 if (!ssid)
2703 return 0;
2704
2705 p = data->assoc_info.req_ies;
2706 l = data->assoc_info.req_ies_len;
2707
2708 while (p && l >= 2) {
2709 len = p[1] + 2;
2710 if (len > l) {
2711 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2712 p, l);
2713 break;
2714 }
2715 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2716 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2717 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2718 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2719 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2720 found = true;
2721 break;
2722 }
2723 l -= len;
2724 p += len;
2725 }
2726
2727 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2728 return 0;
2729
2730 wpa_hexdump(MSG_DEBUG,
2731 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2732 p, l);
2733
2734 /* Update proto from (Re)Association Request frame info */
2735 wpa_s->wpa_proto = ie.proto;
2736 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2737 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2738 !!(wpa_s->wpa_proto &
2739 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2740
2741 /* Update AKMP suite from (Re)Association Request frame info */
2742 sel = ie.key_mgmt;
2743 if (ssid->key_mgmt)
2744 sel &= ssid->key_mgmt;
2745
2746 wpa_dbg(wpa_s, MSG_DEBUG,
2747 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2748 ie.key_mgmt, ssid->key_mgmt, sel);
2749 if (ie.key_mgmt && !sel) {
2750 wpa_supplicant_deauthenticate(
2751 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2752 return -1;
2753 }
2754
2755 wpa_s->key_mgmt = ie.key_mgmt;
2756 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2757 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2758 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2759 wpa_s->wpa_proto);
2760
2761 /* Update pairwise cipher from (Re)Association Request frame info */
2762 sel = ie.pairwise_cipher;
2763 if (ssid->pairwise_cipher)
2764 sel &= ssid->pairwise_cipher;
2765
2766 wpa_dbg(wpa_s, MSG_DEBUG,
2767 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2768 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2769 if (ie.pairwise_cipher && !sel) {
2770 wpa_supplicant_deauthenticate(
2771 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2772 return -1;
2773 }
2774
2775 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2776 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2777 wpa_s->pairwise_cipher);
2778 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2779 wpa_cipher_txt(wpa_s->pairwise_cipher));
2780
2781 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2782 if (!bss) {
2783 wpa_dbg(wpa_s, MSG_DEBUG,
2784 "WPA: current_bss == NULL - skip AP IE check");
2785 return 0;
2786 }
2787
2788 /* Update GTK and IGTK from AP's RSNE */
2789 found = false;
2790
2791 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2792 const u8 *bss_rsn;
2793
2794 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2795 if (bss_rsn) {
2796 p = bss_rsn;
2797 len = 2 + bss_rsn[1];
2798 found = true;
2799 }
2800 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2801 const u8 *bss_wpa;
2802
2803 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2804 if (bss_wpa) {
2805 p = bss_wpa;
2806 len = 2 + bss_wpa[1];
2807 found = true;
2808 }
2809 }
2810
2811 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2812 return 0;
2813
2814 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2815 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2816 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
2817 /* AP does not support MFP, local configuration requires it */
2818 wpa_supplicant_deauthenticate(
2819 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2820 return -1;
2821 }
2822 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
2823 pmf == NO_MGMT_FRAME_PROTECTION) {
2824 /* AP requires MFP, local configuration disables it */
2825 wpa_supplicant_deauthenticate(
2826 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2827 return -1;
2828 }
2829
2830 /* Update PMF from local configuration now that MFP validation was done
2831 * above */
2832 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
2833
2834 /* Update GTK from AP's RSNE */
2835 sel = ie.group_cipher;
2836 if (ssid->group_cipher)
2837 sel &= ssid->group_cipher;
2838
2839 wpa_dbg(wpa_s, MSG_DEBUG,
2840 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
2841 ie.group_cipher, ssid->group_cipher, sel);
2842 if (ie.group_cipher && !sel) {
2843 wpa_supplicant_deauthenticate(
2844 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
2845 return -1;
2846 }
2847
2848 wpa_s->group_cipher = ie.group_cipher;
2849 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
2850 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
2851 wpa_cipher_txt(wpa_s->group_cipher));
2852
2853 /* Update IGTK from AP RSN IE */
2854 sel = ie.mgmt_group_cipher;
2855 if (ssid->group_mgmt_cipher)
2856 sel &= ssid->group_mgmt_cipher;
2857
2858 wpa_dbg(wpa_s, MSG_DEBUG,
2859 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
2860 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
2861
2862 if (pmf == NO_MGMT_FRAME_PROTECTION ||
2863 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
2864 wpa_dbg(wpa_s, MSG_DEBUG,
2865 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
2866 ie.capabilities);
2867 ie.mgmt_group_cipher = 0;
2868 }
2869
2870 if (ie.mgmt_group_cipher && !sel) {
2871 wpa_supplicant_deauthenticate(
2872 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
2873 return -1;
2874 }
2875
2876 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
2877 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
2878 wpa_s->mgmt_group_cipher);
2879 if (wpa_s->mgmt_group_cipher)
2880 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
2881 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
2882 else
2883 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
2884
2885 return 0;
2886}
2887
2888
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002889static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2890 union wpa_event_data *data)
2891{
Hai Shalomc3565922019-10-28 11:58:20 -07002892 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002893 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002894 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002895 bool bssid_known;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002896
2897 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07002898 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002899 if (data->assoc_info.req_ies)
2900 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2901 data->assoc_info.req_ies_len);
2902 if (data->assoc_info.resp_ies) {
2903 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2904 data->assoc_info.resp_ies_len);
2905#ifdef CONFIG_TDLS
2906 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2907 data->assoc_info.resp_ies_len);
2908#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002909#ifdef CONFIG_WNM
2910 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2911 data->assoc_info.resp_ies_len);
2912#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002913#ifdef CONFIG_INTERWORKING
2914 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2915 data->assoc_info.resp_ies_len);
2916#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002917 if (wpa_s->hw_capab == CAPAB_VHT &&
2918 get_ie(data->assoc_info.resp_ies,
2919 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2920 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002921
2922 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2923 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002924 }
2925 if (data->assoc_info.beacon_ies)
2926 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2927 data->assoc_info.beacon_ies,
2928 data->assoc_info.beacon_ies_len);
2929 if (data->assoc_info.freq)
2930 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2931 data->assoc_info.freq);
2932
Hai Shalom021b0b52019-04-10 11:17:58 -07002933 wpa_s->connection_set = 0;
2934 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2935 struct ieee802_11_elems req_elems, resp_elems;
2936
2937 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2938 data->assoc_info.req_ies_len,
2939 &req_elems, 0) != ParseFailed &&
2940 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2941 data->assoc_info.resp_ies_len,
2942 &resp_elems, 0) != ParseFailed) {
2943 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07002944 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
2945 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07002946 wpa_s->connection_ht = req_elems.ht_capabilities &&
2947 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07002948 /* Do not include subset of VHT on 2.4 GHz vendor
2949 * extension in consideration for reporting VHT
2950 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07002951 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002952 resp_elems.vht_capabilities &&
2953 (!data->assoc_info.freq ||
2954 wpas_freq_to_band(data->assoc_info.freq) !=
2955 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07002956 wpa_s->connection_he = req_elems.he_capabilities &&
2957 resp_elems.he_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08002958
2959 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
2960 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
2961 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
2962 max_nss_rx_req : max_nss_rx_resp;
2963 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
2964 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
2965 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
2966 max_nss_tx_req : max_nss_tx_resp;
2967
2968 struct supported_chan_width sta_supported_chan_width =
2969 get_supported_channel_width(&req_elems);
2970 enum chan_width ap_operation_chan_width =
2971 get_operation_channel_width(&resp_elems);
2972 if (wpa_s->connection_vht || wpa_s->connection_he) {
2973 wpa_s->connection_channel_bandwidth =
2974 get_sta_operation_chan_width(ap_operation_chan_width,
2975 sta_supported_chan_width);
2976 } else if (wpa_s->connection_ht) {
2977 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
2978 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
2979 } else {
2980 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
2981 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002982 }
2983 }
2984
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002985 p = data->assoc_info.req_ies;
2986 l = data->assoc_info.req_ies_len;
2987
2988 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2989 while (p && l >= 2) {
2990 len = p[1] + 2;
2991 if (len > l) {
2992 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2993 p, l);
2994 break;
2995 }
Hai Shalomc3565922019-10-28 11:58:20 -07002996 if (!found &&
2997 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2998 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2999 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3000 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3001 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003002 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3003 break;
3004 found = 1;
3005 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07003006 }
3007 if (!found_x && p[0] == WLAN_EID_RSNX) {
3008 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3009 break;
3010 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003011 }
3012 l -= len;
3013 p += len;
3014 }
3015 if (!found && data->assoc_info.req_ies)
3016 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003017 if (!found_x && data->assoc_info.req_ies)
3018 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003019
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003020#ifdef CONFIG_FILS
3021#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003022 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3023 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003024 (!data->assoc_info.resp_frame ||
3025 fils_process_assoc_resp(wpa_s->wpa,
3026 data->assoc_info.resp_frame,
3027 data->assoc_info.resp_frame_len) < 0)) {
3028 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3029 return -1;
3030 }
3031#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003032
3033 /* Additional processing for FILS when SME is in driver */
3034 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3035 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3036 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003037#endif /* CONFIG_FILS */
3038
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003039#ifdef CONFIG_OWE
3040 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003041 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003042 owe_process_assoc_resp(wpa_s->wpa, bssid,
3043 data->assoc_info.resp_ies,
3044 data->assoc_info.resp_ies_len) < 0)) {
3045 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3046 return -1;
3047 }
3048#endif /* CONFIG_OWE */
3049
Hai Shalom021b0b52019-04-10 11:17:58 -07003050#ifdef CONFIG_DPP2
3051 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003052 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3053 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003054 struct ieee802_11_elems elems;
3055
3056 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3057 data->assoc_info.resp_ies_len,
3058 &elems, 0) == ParseFailed ||
3059 !elems.owe_dh)
3060 goto no_pfs;
3061 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3062 elems.owe_dh_len) < 0) {
3063 wpa_supplicant_deauthenticate(wpa_s,
3064 WLAN_REASON_UNSPECIFIED);
3065 return -1;
3066 }
3067
3068 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3069 }
3070no_pfs:
3071#endif /* CONFIG_DPP2 */
3072
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073#ifdef CONFIG_IEEE80211R
3074#ifdef CONFIG_SME
3075 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003076 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003077 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3078 data->assoc_info.resp_ies,
3079 data->assoc_info.resp_ies_len,
3080 bssid) < 0) {
3081 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3082 "Reassociation Response failed");
3083 wpa_supplicant_deauthenticate(
3084 wpa_s, WLAN_REASON_INVALID_IE);
3085 return -1;
3086 }
3087 }
3088
3089 p = data->assoc_info.resp_ies;
3090 l = data->assoc_info.resp_ies_len;
3091
3092#ifdef CONFIG_WPS_STRICT
3093 if (p && wpa_s->current_ssid &&
3094 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3095 struct wpabuf *wps;
3096 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3097 if (wps == NULL) {
3098 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3099 "include WPS IE in (Re)Association Response");
3100 return -1;
3101 }
3102
3103 if (wps_validate_assoc_resp(wps) < 0) {
3104 wpabuf_free(wps);
3105 wpa_supplicant_deauthenticate(
3106 wpa_s, WLAN_REASON_INVALID_IE);
3107 return -1;
3108 }
3109 wpabuf_free(wps);
3110 }
3111#endif /* CONFIG_WPS_STRICT */
3112
3113 /* Go through the IEs and make a copy of the MDIE, if present. */
3114 while (p && l >= 2) {
3115 len = p[1] + 2;
3116 if (len > l) {
3117 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3118 p, l);
3119 break;
3120 }
3121 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3122 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3123 wpa_s->sme.ft_used = 1;
3124 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3125 MOBILITY_DOMAIN_ID_LEN);
3126 break;
3127 }
3128 l -= len;
3129 p += len;
3130 }
3131#endif /* CONFIG_SME */
Mir Ali677e7482020-11-12 19:49:02 +05303132#ifdef CONFIG_DRIVER_NL80211_BRCM
Mir Alieaaf04e2021-06-07 12:17:29 +05303133 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3134 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3135 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3136 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303137 wpa_ft_is_completed(wpa_s->wpa)) {
3138 return 0;
3139 }
3140#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003141
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003142 /* Process FT when SME is in the driver */
3143 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3144 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003145 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003146 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3147 data->assoc_info.resp_ies,
3148 data->assoc_info.resp_ies_len,
3149 bssid) < 0) {
3150 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3151 "Reassociation Response failed");
3152 wpa_supplicant_deauthenticate(
3153 wpa_s, WLAN_REASON_INVALID_IE);
3154 return -1;
3155 }
3156 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3157 }
3158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003159 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3160 data->assoc_info.resp_ies_len);
3161#endif /* CONFIG_IEEE80211R */
3162
Hai Shalom899fcc72020-10-19 14:38:18 -07003163 if (bssid_known)
3164 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3165 data->assoc_info.resp_ies,
3166 data->assoc_info.resp_ies_len);
3167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003168 /* WPA/RSN IE from Beacon/ProbeResp */
3169 p = data->assoc_info.beacon_ies;
3170 l = data->assoc_info.beacon_ies_len;
3171
3172 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3173 */
3174 wpa_found = rsn_found = 0;
3175 while (p && l >= 2) {
3176 len = p[1] + 2;
3177 if (len > l) {
3178 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3179 p, l);
3180 break;
3181 }
3182 if (!wpa_found &&
3183 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3184 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3185 wpa_found = 1;
3186 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3187 }
3188
3189 if (!rsn_found &&
3190 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3191 rsn_found = 1;
3192 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3193 }
3194
Hai Shalomc3565922019-10-28 11:58:20 -07003195 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3196 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003198 l -= len;
3199 p += len;
3200 }
3201
3202 if (!wpa_found && data->assoc_info.beacon_ies)
3203 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003204 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003205 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003206 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3207 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003208 if (wpa_found || rsn_found)
3209 wpa_s->ap_ies_from_associnfo = 1;
3210
Jouni Malinen87fd2792011-05-16 18:35:42 +03003211 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3212 wpa_s->assoc_freq != data->assoc_info.freq) {
3213 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3214 "%u to %u MHz",
3215 wpa_s->assoc_freq, data->assoc_info.freq);
3216 wpa_supplicant_update_scan_results(wpa_s);
3217 }
3218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003219 wpa_s->assoc_freq = data->assoc_info.freq;
3220
Hai Shalomc1a21442022-02-04 13:43:00 -08003221 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3222 data->assoc_info.resp_ies_len);
3223
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003224 return 0;
3225}
3226
3227
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003228static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3229{
Hai Shalomc3565922019-10-28 11:58:20 -07003230 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003231
3232 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3233 return -1;
3234
3235 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3236 return 0;
3237
3238 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3239 WPA_IE_VENDOR_TYPE);
3240 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003241 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003242
3243 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3244 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3245 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003246 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3247 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3248 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003249 return -1;
3250
3251 return 0;
3252}
3253
3254
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003255static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3256 union wpa_event_data *data)
3257{
3258#ifdef CONFIG_FST
3259 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3260 struct wpa_bss *bss = wpa_s->current_bss;
3261 const u8 *ieprb, *iebcn;
3262
3263 wpabuf_free(wpa_s->received_mb_ies);
3264 wpa_s->received_mb_ies = NULL;
3265
3266 if (ai &&
3267 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3268 wpa_printf(MSG_DEBUG,
3269 "FST: MB IEs updated from Association Response frame");
3270 return;
3271 }
3272
3273 if (ai &&
3274 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3275 wpa_printf(MSG_DEBUG,
3276 "FST: MB IEs updated from association event Beacon IEs");
3277 return;
3278 }
3279
3280 if (!bss)
3281 return;
3282
Hai Shalom60840252021-02-19 19:02:11 -08003283 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003284 iebcn = ieprb + bss->ie_len;
3285
3286 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3287 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3288 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3289 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3290#endif /* CONFIG_FST */
3291}
3292
3293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003294static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3295 union wpa_event_data *data)
3296{
3297 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003298 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003299 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003300#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3301 struct wpa_bss *bss;
3302#endif /* CONFIG_FILS || CONFIG_MBO */
Mir Ali677e7482020-11-12 19:49:02 +05303303#ifdef CONFIG_DRIVER_NL80211_BRCM
3304 struct wpa_ie_data ie;
3305#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003306
3307#ifdef CONFIG_AP
3308 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003309 if (!data)
3310 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003311 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3312 data->assoc_info.addr,
3313 data->assoc_info.req_ies,
3314 data->assoc_info.req_ies_len,
3315 data->assoc_info.reassoc);
3316 return;
3317 }
3318#endif /* CONFIG_AP */
3319
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003320 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003321 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003322
Mir Ali677e7482020-11-12 19:49:02 +05303323#ifdef CONFIG_DRIVER_NL80211_BRCM
3324 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3325 struct wpa_ft_ies parse;
3326 /* Check for FT reassociation is done by the driver */
3327#ifdef CONFIG_IEEE80211R
3328 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303329 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303330 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3331 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3332 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3333 return;
3334 }
3335 if (parse.rsn_pmkid != NULL) {
3336 wpa_set_ft_completed(wpa_s->wpa);
3337 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3338 }
3339 }
3340#endif /* CONFIG_IEEE80211R */
3341 }
3342#endif /* CONFIG_DRIVER_NL80211_BRCM */
3343
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003344 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
3345 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3346 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003347 /*
3348 * FILS authentication can share the same mechanism to mark the
3349 * connection fully authenticated, so set ft_completed also based on
3350 * FILS result.
3351 */
3352 if (!ft_completed)
3353 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003354
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003355 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3356 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003357 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003358 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3359 return;
3360 }
3361
Mir Ali677e7482020-11-12 19:49:02 +05303362#ifdef CONFIG_DRIVER_NL80211_BRCM
3363 /* For driver based roaming, insert PSK during the initial association */
3364 if (is_zero_ether_addr(wpa_s->bssid) &&
3365 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3366 /* In case the driver wants to handle re-assocs, pass it down the PMK. */
3367 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3368 wpa_sm_install_pmk(wpa_s->wpa);
3369 }
3370#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003371 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003372 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003373 if (os_reltime_initialized(&wpa_s->session_start)) {
3374 os_reltime_age(&wpa_s->session_start,
3375 &wpa_s->session_length);
3376 wpa_s->session_start.sec = 0;
3377 wpa_s->session_start.usec = 0;
3378 wpas_notify_session_length(wpa_s);
3379 } else {
3380 wpas_notify_auth_changed(wpa_s);
3381 os_get_reltime(&wpa_s->session_start);
3382 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003383 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3384 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003385 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003386 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003387 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3388 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003389 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003390
3391 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3392 wpa_clear_keys(wpa_s, bssid);
3393 }
3394 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003395 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003396 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3397 return;
3398 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003399 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003400
Hai Shalomc1a21442022-02-04 13:43:00 -08003401 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3402 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3403 return;
3404
Hai Shalomfdcde762020-04-02 11:19:20 -07003405 multi_ap_set_4addr_mode(wpa_s);
3406
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003407 if (wpa_s->conf->ap_scan == 1 &&
3408 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003409 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3410 wpa_msg(wpa_s, MSG_WARNING,
3411 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003412 }
3413
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003414 wpas_fst_update_mb_assoc(wpa_s, data);
3415
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003416#ifdef CONFIG_SME
3417 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3418 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003419 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003420#endif /* CONFIG_SME */
3421
3422 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3423 if (wpa_s->current_ssid) {
3424 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3425 * initialized before association, but for other modes,
3426 * initialize PC/SC here, if the current configuration needs
3427 * smartcard or SIM/USIM. */
3428 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3429 }
3430 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3431 if (wpa_s->l2)
3432 l2_packet_notify_auth_start(wpa_s->l2);
3433
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003434 already_authorized = data && data->assoc_info.authorized;
3435
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003436 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003437 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003438 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3439 * state machine may transit to AUTHENTICATING state based on obsolete
3440 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3441 * AUTHENTICATED without ever giving chance to EAP state machine to
3442 * reset the state.
3443 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003444 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003445 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3446 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003447 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003448 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3449 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3450 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003451 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003452 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003453 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003454 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003455 wpa_s->eapol_received = 0;
3456 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3457 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3458 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003459 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003460 if (wpa_s->current_ssid &&
3461 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003462 (wpa_s->drv_flags &
3463 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3464 /*
3465 * Set the key after having received joined-IBSS event
3466 * from the driver.
3467 */
3468 wpa_supplicant_set_wpa_none_key(wpa_s,
3469 wpa_s->current_ssid);
3470 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003471 wpa_supplicant_cancel_auth_timeout(wpa_s);
3472 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3473 } else if (!ft_completed) {
3474 /* Timeout for receiving the first EAPOL packet */
3475 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3476 }
3477 wpa_supplicant_cancel_scan(wpa_s);
3478
Hai Shalom5f92bc92019-04-18 11:54:11 -07003479 if (ft_completed) {
3480 /*
3481 * FT protocol completed - make sure EAPOL state machine ends
3482 * up in authenticated.
3483 */
3484 wpa_supplicant_cancel_auth_timeout(wpa_s);
3485 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003486 eapol_sm_notify_portValid(wpa_s->eapol, true);
3487 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003488 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3489 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003490 /*
3491 * We are done; the driver will take care of RSN 4-way
3492 * handshake.
3493 */
3494 wpa_supplicant_cancel_auth_timeout(wpa_s);
3495 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003496 eapol_sm_notify_portValid(wpa_s->eapol, true);
3497 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003498 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003499 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3500 /*
3501 * The driver will take care of RSN 4-way handshake, so we need
3502 * to allow EAPOL supplicant to complete its work without
3503 * waiting for WPA supplicant.
3504 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003505 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003506 }
Mir Alieaaf04e2021-06-07 12:17:29 +05303507#ifdef CONFIG_DRIVER_NL80211_BRCM
3508 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3509 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3510 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3511 wpa_s->key_mgmt);
3512 wpa_supplicant_deauthenticate(
3513 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3514 return;
3515 }
3516 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3517 wpa_s->assoc_freq = data->assoc_info.freq;
3518 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3519 }
3520#endif /* CONFIG_DRIVER_NL80211_BRCM */
Jouni Malinena05074c2012-12-21 21:35:35 +02003521 wpa_s->last_eapol_matches_bssid = 0;
3522
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003523#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003524 if (wpa_s->rsne_override_eapol) {
3525 wpa_printf(MSG_DEBUG,
3526 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3527 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3528 wpabuf_head(wpa_s->rsne_override_eapol),
3529 wpabuf_len(wpa_s->rsne_override_eapol));
3530 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003531 if (wpa_s->rsnxe_override_eapol) {
3532 wpa_printf(MSG_DEBUG,
3533 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3534 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3535 wpabuf_head(wpa_s->rsnxe_override_eapol),
3536 wpabuf_len(wpa_s->rsnxe_override_eapol));
3537 }
3538#endif /* CONFIG_TESTING_OPTIONS */
3539
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003540 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003541 struct os_reltime now, age;
3542 os_get_reltime(&now);
3543 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003544 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003545 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3546 0) {
3547 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3548 "frame that was received just before "
3549 "association notification");
3550 wpa_supplicant_rx_eapol(
3551 wpa_s, wpa_s->pending_eapol_rx_src,
3552 wpabuf_head(wpa_s->pending_eapol_rx),
3553 wpabuf_len(wpa_s->pending_eapol_rx));
3554 }
3555 wpabuf_free(wpa_s->pending_eapol_rx);
3556 wpa_s->pending_eapol_rx = NULL;
3557 }
3558
Hai Shalomfdcde762020-04-02 11:19:20 -07003559#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003560 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3561 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003562 wpa_s->current_ssid &&
3563 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003564 /* Set static WEP keys again */
3565 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3566 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003567#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003568
3569#ifdef CONFIG_IBSS_RSN
3570 if (wpa_s->current_ssid &&
3571 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3572 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3573 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3574 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003575 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003576 if (!wpa_s->ibss_rsn) {
3577 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3578 wpa_supplicant_deauthenticate(
3579 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3580 return;
3581 }
3582
3583 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3584 }
3585#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003586
3587 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003588
3589 if (data) {
3590 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3591 data->assoc_info.resp_ies_len,
3592 &data->assoc_info.wmm_params);
3593
3594 if (wpa_s->reassoc_same_bss)
3595 wmm_ac_restore_tspecs(wpa_s);
3596 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003597
Hai Shalomc3565922019-10-28 11:58:20 -07003598#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3599 bss = wpa_bss_get_bssid(wpa_s, bssid);
3600#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003601#ifdef CONFIG_FILS
3602 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003603 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3604
3605 if (fils_cache_id)
3606 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3607 }
3608#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003609
3610#ifdef CONFIG_MBO
3611 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3612#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003613
3614#ifdef CONFIG_DPP2
3615 wpa_s->dpp_pfs_fallback = 0;
3616#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003617}
3618
3619
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003620static int disconnect_reason_recoverable(u16 reason_code)
3621{
3622 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3623 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3624 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3625}
3626
3627
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003628static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003629 u16 reason_code,
3630 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003631{
3632 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003633
3634 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3635 /*
3636 * At least Host AP driver and a Prism3 card seemed to be
3637 * generating streams of disconnected events when configuring
3638 * IBSS for WPA-None. Ignore them for now.
3639 */
3640 return;
3641 }
3642
3643 bssid = wpa_s->bssid;
3644 if (is_zero_ether_addr(bssid))
3645 bssid = wpa_s->pending_bssid;
3646
3647 if (!is_zero_ether_addr(bssid) ||
3648 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3649 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3650 " reason=%d%s",
3651 MAC2STR(bssid), reason_code,
3652 locally_generated ? " locally_generated=1" : "");
3653 }
3654}
3655
3656
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003657static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3658 int locally_generated)
3659{
3660 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003661 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003662 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3663 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003664 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003665
3666 /*
3667 * It looks like connection was lost while trying to go through PSK
3668 * 4-way handshake. Filter out known disconnection cases that are caused
3669 * by something else than PSK mismatch to avoid confusing reports.
3670 */
3671
3672 if (locally_generated) {
3673 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3674 return 0;
3675 }
3676
3677 return 1;
3678}
3679
3680
Jouni Malinen2b89da82012-08-31 22:04:41 +03003681static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3682 u16 reason_code,
3683 int locally_generated)
3684{
3685 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003686 int authenticating;
3687 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003688 struct wpa_bss *fast_reconnect = NULL;
3689 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003690 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003691 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003692
3693 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3694 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3695
3696 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3697 /*
3698 * At least Host AP driver and a Prism3 card seemed to be
3699 * generating streams of disconnected events when configuring
3700 * IBSS for WPA-None. Ignore them for now.
3701 */
3702 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3703 "IBSS/WPA-None mode");
3704 return;
3705 }
3706
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003707 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3708 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3709 locally_generated)
3710 /*
3711 * Remove the inactive AP (which is probably out of range) from
3712 * the BSS list after marking disassociation. In particular
3713 * mac80211-based drivers use the
3714 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3715 * locally generated disconnection events for cases where the
3716 * AP does not reply anymore.
3717 */
3718 curr = wpa_s->current_bss;
3719
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003720 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003721 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3722 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003723 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3724 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003725 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003726#ifdef CONFIG_DPP2
3727 wpas_dpp_send_conn_status_result(wpa_s,
3728 DPP_STATUS_AUTH_FAILURE);
3729#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003730 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003731 if (!wpa_s->disconnected &&
3732 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003733 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003734 wpas_wps_searching(wpa_s) ||
3735 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003736 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003737 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003738 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003739 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003740 wpa_s->wpa_state);
3741 if (wpa_s->wpa_state == WPA_COMPLETED &&
3742 wpa_s->current_ssid &&
3743 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003744 (wpa_s->own_reconnect_req ||
3745 (!locally_generated &&
3746 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003747 /*
3748 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003749 * us, but could allow us to get back in. This is also
3750 * triggered for cases where local reconnection request
3751 * is used to force reassociation with the same BSS.
3752 * Try to reconnect to the same BSS without a full scan
3753 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003754 */
3755 fast_reconnect = wpa_s->current_bss;
3756 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003757 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003758 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003759 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003760 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3761 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003762 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003763 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003764 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003765 "try to re-connect");
3766 wpa_s->reassociate = 0;
3767 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003768 if (!wpa_s->pno)
3769 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003770 }
3771 bssid = wpa_s->bssid;
3772 if (is_zero_ether_addr(bssid))
3773 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003774 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3775 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003776 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08003777 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
3778
Dmitry Shmidt04949592012-07-19 12:16:46 -07003779 if (locally_generated)
3780 wpa_s->disconnect_reason = -reason_code;
3781 else
3782 wpa_s->disconnect_reason = reason_code;
3783 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003784 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3785 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003786 wpa_clear_keys(wpa_s, wpa_s->bssid);
3787 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003788 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003789 wpa_supplicant_mark_disassoc(wpa_s);
3790
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003791 if (curr)
3792 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3793
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003794 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003795 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003796 wpa_s->current_ssid = last_ssid;
3797 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003798
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003799 if (fast_reconnect &&
3800 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3801 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3802 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3803 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003804 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003805 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003806#ifndef CONFIG_NO_SCAN_PROCESSING
3807 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3808 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3809 fast_reconnect_ssid) < 0) {
3810 /* Recover through full scan */
3811 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3812 }
3813#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003814 } else if (fast_reconnect) {
3815 /*
3816 * Could not reconnect to the same BSS due to network being
3817 * disabled. Use a new scan to match the alternative behavior
3818 * above, i.e., to continue automatic reconnection attempt in a
3819 * way that enforces disabled network rules.
3820 */
3821 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003822 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003823}
3824
3825
3826#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003827void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003828{
3829 struct wpa_supplicant *wpa_s = eloop_ctx;
3830
3831 if (!wpa_s->pending_mic_error_report)
3832 return;
3833
3834 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3835 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3836 wpa_s->pending_mic_error_report = 0;
3837}
3838#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3839
3840
3841static void
3842wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3843 union wpa_event_data *data)
3844{
3845 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003846 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003847
3848 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3849 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003850 os_get_reltime(&t);
3851 if ((wpa_s->last_michael_mic_error.sec &&
3852 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003853 wpa_s->pending_mic_error_report) {
3854 if (wpa_s->pending_mic_error_report) {
3855 /*
3856 * Send the pending MIC error report immediately since
3857 * we are going to start countermeasures and AP better
3858 * do the same.
3859 */
3860 wpa_sm_key_request(wpa_s->wpa, 1,
3861 wpa_s->pending_mic_error_pairwise);
3862 }
3863
3864 /* Send the new MIC error report immediately since we are going
3865 * to start countermeasures and AP better do the same.
3866 */
3867 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3868
3869 /* initialize countermeasures */
3870 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003871
Hai Shalom60840252021-02-19 19:02:11 -08003872 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003873
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003874 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3875
3876 /*
3877 * Need to wait for completion of request frame. We do not get
3878 * any callback for the message completion, so just wait a
3879 * short while and hope for the best. */
3880 os_sleep(0, 10000);
3881
3882 wpa_drv_set_countermeasures(wpa_s, 1);
3883 wpa_supplicant_deauthenticate(wpa_s,
3884 WLAN_REASON_MICHAEL_MIC_FAILURE);
3885 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3886 wpa_s, NULL);
3887 eloop_register_timeout(60, 0,
3888 wpa_supplicant_stop_countermeasures,
3889 wpa_s, NULL);
3890 /* TODO: mark the AP rejected for 60 second. STA is
3891 * allowed to associate with another AP.. */
3892 } else {
3893#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3894 if (wpa_s->mic_errors_seen) {
3895 /*
3896 * Reduce the effectiveness of Michael MIC error
3897 * reports as a means for attacking against TKIP if
3898 * more than one MIC failure is noticed with the same
3899 * PTK. We delay the transmission of the reports by a
3900 * random time between 0 and 60 seconds in order to
3901 * force the attacker wait 60 seconds before getting
3902 * the information on whether a frame resulted in a MIC
3903 * failure.
3904 */
3905 u8 rval[4];
3906 int sec;
3907
3908 if (os_get_random(rval, sizeof(rval)) < 0)
3909 sec = os_random() % 60;
3910 else
3911 sec = WPA_GET_BE32(rval) % 60;
3912 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3913 "report %d seconds", sec);
3914 wpa_s->pending_mic_error_report = 1;
3915 wpa_s->pending_mic_error_pairwise = pairwise;
3916 eloop_cancel_timeout(
3917 wpa_supplicant_delayed_mic_error_report,
3918 wpa_s, NULL);
3919 eloop_register_timeout(
3920 sec, os_random() % 1000000,
3921 wpa_supplicant_delayed_mic_error_report,
3922 wpa_s, NULL);
3923 } else {
3924 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3925 }
3926#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3927 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3928#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3929 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003930 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003931 wpa_s->mic_errors_seen++;
3932}
3933
3934
3935#ifdef CONFIG_TERMINATE_ONLASTIF
3936static int any_interfaces(struct wpa_supplicant *head)
3937{
3938 struct wpa_supplicant *wpa_s;
3939
3940 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3941 if (!wpa_s->interface_removed)
3942 return 1;
3943 return 0;
3944}
3945#endif /* CONFIG_TERMINATE_ONLASTIF */
3946
3947
3948static void
3949wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3950 union wpa_event_data *data)
3951{
3952 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3953 return;
3954
3955 switch (data->interface_status.ievent) {
3956 case EVENT_INTERFACE_ADDED:
3957 if (!wpa_s->interface_removed)
3958 break;
3959 wpa_s->interface_removed = 0;
3960 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3961 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3962 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3963 "driver after interface was added");
3964 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003965
3966#ifdef CONFIG_P2P
3967 if (!wpa_s->global->p2p &&
3968 !wpa_s->global->p2p_disabled &&
3969 !wpa_s->conf->p2p_disabled &&
3970 (wpa_s->drv_flags &
3971 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3972 wpas_p2p_add_p2pdev_interface(
3973 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3974 wpa_printf(MSG_INFO,
3975 "P2P: Failed to enable P2P Device interface");
3976 /* Try to continue without. P2P will be disabled. */
3977 }
3978#endif /* CONFIG_P2P */
3979
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003980 break;
3981 case EVENT_INTERFACE_REMOVED:
3982 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3983 wpa_s->interface_removed = 1;
3984 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003985 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003986 l2_packet_deinit(wpa_s->l2);
3987 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003988
3989#ifdef CONFIG_P2P
3990 if (wpa_s->global->p2p &&
3991 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3992 (wpa_s->drv_flags &
3993 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3994 wpa_dbg(wpa_s, MSG_DEBUG,
3995 "Removing P2P Device interface");
3996 wpa_supplicant_remove_iface(
3997 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3998 0);
3999 wpa_s->global->p2p_init_wpa_s = NULL;
4000 }
4001#endif /* CONFIG_P2P */
4002
Dmitry Shmidte4663042016-04-04 10:07:49 -07004003#ifdef CONFIG_MATCH_IFACE
4004 if (wpa_s->matched) {
4005 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4006 break;
4007 }
4008#endif /* CONFIG_MATCH_IFACE */
4009
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004010#ifdef CONFIG_TERMINATE_ONLASTIF
4011 /* check if last interface */
4012 if (!any_interfaces(wpa_s->global->ifaces))
4013 eloop_terminate();
4014#endif /* CONFIG_TERMINATE_ONLASTIF */
4015 break;
4016 }
4017}
4018
4019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004020#ifdef CONFIG_TDLS
4021static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4022 union wpa_event_data *data)
4023{
4024 if (data == NULL)
4025 return;
4026 switch (data->tdls.oper) {
4027 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004028 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4029 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4030 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4031 else
4032 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004033 break;
4034 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004035 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4036 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4037 data->tdls.reason_code);
4038 else
4039 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4040 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004041 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004042 case TDLS_REQUEST_DISCOVER:
4043 wpa_tdls_send_discovery_request(wpa_s->wpa,
4044 data->tdls.peer);
4045 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004046 }
4047}
4048#endif /* CONFIG_TDLS */
4049
4050
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004051#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004052static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4053 union wpa_event_data *data)
4054{
4055 if (data == NULL)
4056 return;
4057 switch (data->wnm.oper) {
4058 case WNM_OPER_SLEEP:
4059 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4060 "(action=%d, intval=%d)",
4061 data->wnm.sleep_action, data->wnm.sleep_intval);
4062 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004063 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004064 break;
4065 }
4066}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004067#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004068
4069
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004070#ifdef CONFIG_IEEE80211R
4071static void
4072wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4073 union wpa_event_data *data)
4074{
4075 if (data == NULL)
4076 return;
4077
4078 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4079 data->ft_ies.ies_len,
4080 data->ft_ies.ft_action,
4081 data->ft_ies.target_ap,
4082 data->ft_ies.ric_ies,
4083 data->ft_ies.ric_ies_len) < 0) {
4084 /* TODO: prevent MLME/driver from trying to associate? */
4085 }
4086}
4087#endif /* CONFIG_IEEE80211R */
4088
4089
4090#ifdef CONFIG_IBSS_RSN
4091static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4092 union wpa_event_data *data)
4093{
4094 struct wpa_ssid *ssid;
4095 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4096 return;
4097 if (data == NULL)
4098 return;
4099 ssid = wpa_s->current_ssid;
4100 if (ssid == NULL)
4101 return;
4102 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4103 return;
4104
4105 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4106}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004107
4108
4109static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4110 union wpa_event_data *data)
4111{
4112 struct wpa_ssid *ssid = wpa_s->current_ssid;
4113
4114 if (ssid == NULL)
4115 return;
4116
4117 /* check if the ssid is correctly configured as IBSS/RSN */
4118 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4119 return;
4120
4121 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4122 data->rx_mgmt.frame_len);
4123}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004124#endif /* CONFIG_IBSS_RSN */
4125
4126
4127#ifdef CONFIG_IEEE80211R
4128static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4129 size_t len)
4130{
4131 const u8 *sta_addr, *target_ap_addr;
4132 u16 status;
4133
4134 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4135 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4136 return; /* only SME case supported for now */
4137 if (len < 1 + 2 * ETH_ALEN + 2)
4138 return;
4139 if (data[0] != 2)
4140 return; /* Only FT Action Response is supported for now */
4141 sta_addr = data + 1;
4142 target_ap_addr = data + 1 + ETH_ALEN;
4143 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4144 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4145 MACSTR " TargetAP " MACSTR " status %u",
4146 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4147
4148 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4149 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4150 " in FT Action Response", MAC2STR(sta_addr));
4151 return;
4152 }
4153
4154 if (status) {
4155 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4156 "failure (status code %d)", status);
4157 /* TODO: report error to FT code(?) */
4158 return;
4159 }
4160
4161 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4162 len - (1 + 2 * ETH_ALEN + 2), 1,
4163 target_ap_addr, NULL, 0) < 0)
4164 return;
4165
4166#ifdef CONFIG_SME
4167 {
4168 struct wpa_bss *bss;
4169 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4170 if (bss)
4171 wpa_s->sme.freq = bss->freq;
4172 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4173 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4174 WLAN_AUTH_FT);
4175 }
4176#endif /* CONFIG_SME */
4177}
4178#endif /* CONFIG_IEEE80211R */
4179
4180
4181static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4182 struct unprot_deauth *e)
4183{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004184 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4185 "dropped: " MACSTR " -> " MACSTR
4186 " (reason code %u)",
4187 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4188 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004189}
4190
4191
4192static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4193 struct unprot_disassoc *e)
4194{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004195 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4196 "dropped: " MACSTR " -> " MACSTR
4197 " (reason code %u)",
4198 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4199 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004200}
4201
4202
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004203static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4204 u16 reason_code, int locally_generated,
4205 const u8 *ie, size_t ie_len, int deauth)
4206{
4207#ifdef CONFIG_AP
4208 if (wpa_s->ap_iface && addr) {
4209 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4210 return;
4211 }
4212
4213 if (wpa_s->ap_iface) {
4214 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4215 return;
4216 }
4217#endif /* CONFIG_AP */
4218
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004219 if (!locally_generated)
4220 wpa_s->own_disconnect_req = 0;
4221
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004222 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4223
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004224 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4225 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4226 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4227 eapol_sm_failed(wpa_s->eapol))) &&
4228 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004229 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004230
4231#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004232 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004233 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4234 locally_generated) > 0) {
4235 /*
4236 * The interface was removed, so cannot continue
4237 * processing any additional operations after this.
4238 */
4239 return;
4240 }
4241 }
4242#endif /* CONFIG_P2P */
4243
4244 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4245 locally_generated);
4246}
4247
4248
4249static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4250 struct disassoc_info *info)
4251{
4252 u16 reason_code = 0;
4253 int locally_generated = 0;
4254 const u8 *addr = NULL;
4255 const u8 *ie = NULL;
4256 size_t ie_len = 0;
4257
4258 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4259
4260 if (info) {
4261 addr = info->addr;
4262 ie = info->ie;
4263 ie_len = info->ie_len;
4264 reason_code = info->reason_code;
4265 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004266 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4267 reason2str(reason_code),
4268 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004269 if (addr)
4270 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4271 MAC2STR(addr));
4272 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4273 ie, ie_len);
4274 }
4275
4276#ifdef CONFIG_AP
4277 if (wpa_s->ap_iface && info && info->addr) {
4278 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4279 return;
4280 }
4281
4282 if (wpa_s->ap_iface) {
4283 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4284 return;
4285 }
4286#endif /* CONFIG_AP */
4287
4288#ifdef CONFIG_P2P
4289 if (info) {
4290 wpas_p2p_disassoc_notif(
4291 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4292 locally_generated);
4293 }
4294#endif /* CONFIG_P2P */
4295
4296 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4297 sme_event_disassoc(wpa_s, info);
4298
4299 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4300 ie, ie_len, 0);
4301}
4302
4303
4304static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4305 struct deauth_info *info)
4306{
4307 u16 reason_code = 0;
4308 int locally_generated = 0;
4309 const u8 *addr = NULL;
4310 const u8 *ie = NULL;
4311 size_t ie_len = 0;
4312
4313 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4314
4315 if (info) {
4316 addr = info->addr;
4317 ie = info->ie;
4318 ie_len = info->ie_len;
4319 reason_code = info->reason_code;
4320 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004321 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4322 reason_code, reason2str(reason_code),
4323 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004324 if (addr) {
4325 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4326 MAC2STR(addr));
4327 }
4328 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4329 ie, ie_len);
4330 }
4331
4332 wpa_reset_ft_completed(wpa_s->wpa);
4333
4334 wpas_event_disconnect(wpa_s, addr, reason_code,
4335 locally_generated, ie, ie_len, 1);
4336}
4337
4338
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004339static const char * reg_init_str(enum reg_change_initiator init)
4340{
4341 switch (init) {
4342 case REGDOM_SET_BY_CORE:
4343 return "CORE";
4344 case REGDOM_SET_BY_USER:
4345 return "USER";
4346 case REGDOM_SET_BY_DRIVER:
4347 return "DRIVER";
4348 case REGDOM_SET_BY_COUNTRY_IE:
4349 return "COUNTRY_IE";
4350 case REGDOM_BEACON_HINT:
4351 return "BEACON_HINT";
4352 }
4353 return "?";
4354}
4355
4356
4357static const char * reg_type_str(enum reg_type type)
4358{
4359 switch (type) {
4360 case REGDOM_TYPE_UNKNOWN:
4361 return "UNKNOWN";
4362 case REGDOM_TYPE_COUNTRY:
4363 return "COUNTRY";
4364 case REGDOM_TYPE_WORLD:
4365 return "WORLD";
4366 case REGDOM_TYPE_CUSTOM_WORLD:
4367 return "CUSTOM_WORLD";
4368 case REGDOM_TYPE_INTERSECTION:
4369 return "INTERSECTION";
4370 }
4371 return "?";
4372}
4373
4374
Hai Shalom74f70d42019-02-11 14:42:39 -08004375void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4376 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004377{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004378 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004379 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004380
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004381 /*
4382 * To allow backwards compatibility with higher level layers that
4383 * assumed the REGDOM_CHANGE event is sent over the initially added
4384 * interface. Find the highest parent of this interface and use it to
4385 * send the event.
4386 */
4387 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4388 ;
4389
Hai Shalom74f70d42019-02-11 14:42:39 -08004390 if (info) {
4391 wpa_msg(ifs, MSG_INFO,
4392 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4393 reg_init_str(info->initiator), reg_type_str(info->type),
4394 info->alpha2[0] ? " alpha2=" : "",
4395 info->alpha2[0] ? info->alpha2 : "");
4396 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004397
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004398 if (wpa_s->drv_priv == NULL)
4399 return; /* Ignore event during drv initialization */
4400
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004401 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4402 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004403 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4404 ifs->ifname);
4405 free_hw_features(ifs);
4406 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004407 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004408
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004409 /* Restart PNO/sched_scan with updated channel list */
4410 if (ifs->pno) {
4411 wpas_stop_pno(ifs);
4412 wpas_start_pno(ifs);
4413 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4414 wpa_dbg(ifs, MSG_DEBUG,
4415 "Channel list changed - restart sched_scan");
4416 wpas_scan_restart_sched_scan(ifs);
4417 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004418 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004419
4420 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004421}
4422
4423
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004424static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004425 const u8 *frame, size_t len, int freq,
4426 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004427{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004428 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004429 const u8 *payload;
4430 size_t plen;
4431 u8 category;
4432
4433 if (len < IEEE80211_HDRLEN + 2)
4434 return;
4435
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004436 mgmt = (const struct ieee80211_mgmt *) frame;
4437 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004438 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004439 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004440
4441 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4442 " Category=%u DataLen=%d freq=%d MHz",
4443 MAC2STR(mgmt->sa), category, (int) plen, freq);
4444
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004445 if (category == WLAN_ACTION_WMM) {
4446 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4447 return;
4448 }
4449
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004450#ifdef CONFIG_IEEE80211R
4451 if (category == WLAN_ACTION_FT) {
4452 ft_rx_action(wpa_s, payload, plen);
4453 return;
4454 }
4455#endif /* CONFIG_IEEE80211R */
4456
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004457#ifdef CONFIG_SME
4458 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004459 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004460 return;
4461 }
4462#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004463
4464#ifdef CONFIG_WNM
4465 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4466 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4467 return;
4468 }
4469#endif /* CONFIG_WNM */
4470
4471#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004472 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4473 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004474 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004475 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004476 payload, plen, freq) == 0)
4477 return;
4478#endif /* CONFIG_GAS */
4479
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004480#ifdef CONFIG_GAS_SERVER
4481 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4482 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4483 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4484 mgmt->u.action.category,
4485 payload, plen, freq) == 0)
4486 return;
4487#endif /* CONFIG_GAS_SERVER */
4488
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004489#ifdef CONFIG_TDLS
4490 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4491 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4492 wpa_dbg(wpa_s, MSG_DEBUG,
4493 "TDLS: Received Discovery Response from " MACSTR,
4494 MAC2STR(mgmt->sa));
4495 return;
4496 }
4497#endif /* CONFIG_TDLS */
4498
4499#ifdef CONFIG_INTERWORKING
4500 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4501 payload[0] == QOS_QOS_MAP_CONFIG) {
4502 const u8 *pos = payload + 1;
4503 size_t qlen = plen - 1;
4504 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4505 MACSTR, MAC2STR(mgmt->sa));
4506 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4507 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4508 pos[1] <= qlen - 2 && pos[1] >= 16)
4509 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4510 return;
4511 }
4512#endif /* CONFIG_INTERWORKING */
4513
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004514 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004515 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4516 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004517 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004518 payload + 1,
4519 plen - 1);
4520 return;
4521 }
4522
4523 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004524 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4525 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4526 return;
4527 }
4528
4529 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4530 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4531 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4532 payload + 1, plen - 1,
4533 rssi);
4534 return;
4535 }
4536
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004537#ifdef CONFIG_FST
4538 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4539 fst_rx_action(wpa_s->fst, mgmt, len);
4540 return;
4541 }
4542#endif /* CONFIG_FST */
4543
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004544#ifdef CONFIG_DPP
4545 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4546 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4547 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4548 payload[4] == DPP_OUI_TYPE) {
4549 payload++;
4550 plen--;
4551 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4552 return;
4553 }
4554#endif /* CONFIG_DPP */
4555
Hai Shalom899fcc72020-10-19 14:38:18 -07004556 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004557 payload[0] == ROBUST_AV_SCS_RESP) {
4558 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4559 payload + 1, plen - 1);
4560 return;
4561 }
4562
4563 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004564 payload[0] == ROBUST_AV_MSCS_RESP) {
4565 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4566 payload + 1, plen - 1);
4567 return;
4568 }
4569
Hai Shalomc1a21442022-02-04 13:43:00 -08004570 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4571 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4572 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4573 payload + 4, plen - 4);
4574 return;
4575 }
4576
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004577 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4578 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004579 if (wpa_s->ifmsh)
4580 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004581}
4582
4583
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004584static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4585 union wpa_event_data *event)
4586{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004587 struct wpa_freq_range_list *list;
4588 char *str = NULL;
4589
4590 list = &event->freq_range;
4591
4592 if (list->num)
4593 str = freq_range_list_str(list);
4594 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4595 str ? str : "");
4596
4597#ifdef CONFIG_P2P
4598 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4599 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4600 __func__);
4601 } else {
4602 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004603
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004604 /*
4605 * The update channel flow will also take care of moving a GO
4606 * from the unsafe frequency if needed.
4607 */
4608 wpas_p2p_update_channel_list(wpa_s,
4609 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004610 }
4611#endif /* CONFIG_P2P */
4612
4613 os_free(str);
4614}
4615
4616
Roshan Pius3a1667e2018-07-03 15:17:14 -07004617static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004618{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004619 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4620 wpa_supplicant_cancel_auth_timeout(wpa_s);
4621 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004622 eapol_sm_notify_portValid(wpa_s->eapol, true);
4623 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004624 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004625 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004626}
4627
4628
4629static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4630 int freq)
4631{
4632 size_t i;
4633 int j;
4634
4635 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4636 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4637
4638 for (j = 0; j < mode->num_channels; j++) {
4639 const struct hostapd_channel_data *chan;
4640
4641 chan = &mode->channels[j];
4642 if (chan->freq == freq)
4643 return chan->dfs_cac_ms;
4644 }
4645 }
4646
4647 return 0;
4648}
4649
4650
4651static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4652 struct dfs_event *radar)
4653{
4654#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004655 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004656 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4657 } else
4658#endif /* NEED_AP_MLME && CONFIG_AP */
4659 {
4660 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4661
4662 cac_time /= 1000; /* convert from ms to sec */
4663 if (!cac_time)
4664 cac_time = 10 * 60; /* max timeout: 10 minutes */
4665
4666 /* Restart auth timeout: CAC time added to initial timeout */
4667 wpas_auth_timeout_restart(wpa_s, cac_time);
4668 }
4669}
4670
4671
4672static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4673 struct dfs_event *radar)
4674{
4675#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004676 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004677 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4678 } else
4679#endif /* NEED_AP_MLME && CONFIG_AP */
4680 {
4681 /* Restart auth timeout with original value after CAC is
4682 * finished */
4683 wpas_auth_timeout_restart(wpa_s, 0);
4684 }
4685}
4686
4687
4688static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4689 struct dfs_event *radar)
4690{
4691#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004692 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004693 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4694 } else
4695#endif /* NEED_AP_MLME && CONFIG_AP */
4696 {
4697 /* Restart auth timeout with original value after CAC is
4698 * aborted */
4699 wpas_auth_timeout_restart(wpa_s, 0);
4700 }
4701}
4702
4703
4704static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4705 union wpa_event_data *data)
4706{
4707 wpa_dbg(wpa_s, MSG_DEBUG,
4708 "Connection authorized by device, previous state %d",
4709 wpa_s->wpa_state);
4710
4711 wpa_supplicant_event_port_authorized(wpa_s);
4712
Hai Shalomc1a21442022-02-04 13:43:00 -08004713 wpa_s->last_eapol_matches_bssid = 1;
4714
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004715 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4716 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004717 data->assoc_info.ptk_kck_len,
4718 data->assoc_info.ptk_kek,
4719 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004720#ifdef CONFIG_FILS
4721 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4722 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4723 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4724
4725 /* Update ERP next sequence number */
4726 eapol_sm_update_erp_next_seq_num(
4727 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4728
4729 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4730 /* Add the new PMK and PMKID to the PMKSA cache */
4731 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4732 data->assoc_info.fils_pmk,
4733 data->assoc_info.fils_pmk_len,
4734 data->assoc_info.fils_pmkid,
4735 wpa_s->bssid, fils_cache_id);
4736 } else if (data->assoc_info.fils_pmkid) {
4737 /* Update the current PMKSA used for this connection */
4738 pmksa_cache_set_current(wpa_s->wpa,
4739 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004740 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004741 }
4742 }
4743#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004744}
4745
4746
Hai Shalom60840252021-02-19 19:02:11 -08004747static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4748{
4749 switch (code) {
4750 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
4751 return "";
4752 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
4753 return "no_bss_found";
4754 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
4755 return "auth_tx_fail";
4756 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
4757 return "auth_no_ack_received";
4758 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
4759 return "auth_no_resp_received";
4760 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
4761 return "assoc_req_tx_fail";
4762 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
4763 return "assoc_no_ack_received";
4764 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
4765 return "assoc_no_resp_received";
4766 default:
4767 return "unknown_reason";
4768 }
4769}
4770
4771
Roshan Pius3a1667e2018-07-03 15:17:14 -07004772static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4773 union wpa_event_data *data)
4774{
4775 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004776#ifdef CONFIG_MBO
4777 struct wpa_bss *reject_bss;
4778#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004779
4780 if (!bssid || is_zero_ether_addr(bssid))
4781 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004782#ifdef CONFIG_MBO
4783 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4784 reject_bss = wpa_s->current_bss;
4785 else
4786 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4787#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004788
4789 if (data->assoc_reject.bssid)
4790 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004791 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004792 MAC2STR(data->assoc_reject.bssid),
4793 data->assoc_reject.status_code,
4794 data->assoc_reject.timed_out ? " timeout" : "",
4795 data->assoc_reject.timeout_reason ? "=" : "",
4796 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004797 data->assoc_reject.timeout_reason : "",
4798 data->assoc_reject.reason_code !=
4799 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4800 " qca_driver_reason=" : "",
4801 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004802 else
4803 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004804 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004805 data->assoc_reject.status_code,
4806 data->assoc_reject.timed_out ? " timeout" : "",
4807 data->assoc_reject.timeout_reason ? "=" : "",
4808 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004809 data->assoc_reject.timeout_reason : "",
4810 data->assoc_reject.reason_code !=
4811 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4812 " qca_driver_reason=" : "",
4813 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004814 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08004815 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
4816 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004817
4818#ifdef CONFIG_OWE
4819 if (data->assoc_reject.status_code ==
4820 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4821 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4822 wpa_s->current_ssid &&
4823 wpa_s->current_ssid->owe_group == 0 &&
4824 wpa_s->last_owe_group != 21) {
4825 struct wpa_ssid *ssid = wpa_s->current_ssid;
4826 struct wpa_bss *bss = wpa_s->current_bss;
4827
4828 if (!bss) {
4829 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4830 if (!bss) {
4831 wpas_connection_failed(wpa_s, bssid);
4832 wpa_supplicant_mark_disassoc(wpa_s);
4833 return;
4834 }
4835 }
4836 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4837 wpas_connect_work_done(wpa_s);
4838 wpa_supplicant_mark_disassoc(wpa_s);
4839 wpa_supplicant_connect(wpa_s, bss, ssid);
4840 return;
4841 }
4842#endif /* CONFIG_OWE */
4843
Hai Shalomfdcde762020-04-02 11:19:20 -07004844#ifdef CONFIG_DPP2
4845 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4846 * the status code defined in the DPP R2 tech spec.
4847 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4848 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004849 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004850 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4851 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4852 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004853 wpa_s->current_ssid->dpp_pfs == 0 &&
4854 (data->assoc_reject.status_code ==
4855 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4856 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4857 struct wpa_ssid *ssid = wpa_s->current_ssid;
4858 struct wpa_bss *bss = wpa_s->current_bss;
4859
4860 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4861 if (!bss)
4862 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4863 if (!bss || wpa_s->dpp_pfs_fallback) {
4864 wpa_printf(MSG_DEBUG,
4865 "DPP: Updated PFS policy for next try");
4866 wpas_connection_failed(wpa_s, bssid);
4867 wpa_supplicant_mark_disassoc(wpa_s);
4868 return;
4869 }
4870 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4871 wpa_s->dpp_pfs_fallback = 1;
4872 wpas_connect_work_done(wpa_s);
4873 wpa_supplicant_mark_disassoc(wpa_s);
4874 wpa_supplicant_connect(wpa_s, bss, ssid);
4875 return;
4876 }
4877#endif /* CONFIG_DPP2 */
4878
Hai Shalom74f70d42019-02-11 14:42:39 -08004879#ifdef CONFIG_MBO
4880 if (data->assoc_reject.status_code ==
4881 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004882 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004883 const u8 *rssi_rej;
4884
4885 rssi_rej = mbo_get_attr_from_ies(
4886 data->assoc_reject.resp_ies,
4887 data->assoc_reject.resp_ies_len,
4888 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4889 if (rssi_rej && rssi_rej[1] == 2) {
4890 wpa_printf(MSG_DEBUG,
4891 "OCE: RSSI-based association rejection from "
4892 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004893 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004894 rssi_rej[2], rssi_rej[3]);
4895 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004896 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004897 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004898 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004899 }
4900 }
4901#endif /* CONFIG_MBO */
4902
Roshan Pius3a1667e2018-07-03 15:17:14 -07004903 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4904 sme_event_assoc_reject(wpa_s, data);
4905 return;
4906 }
4907
4908 /* Driver-based SME cases */
4909
4910#ifdef CONFIG_SAE
4911 if (wpa_s->current_ssid &&
4912 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4913 !data->assoc_reject.timed_out) {
4914 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4915 wpa_sm_aborted_cached(wpa_s->wpa);
4916 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4917 }
4918#endif /* CONFIG_SAE */
4919
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004920#ifdef CONFIG_DPP
4921 if (wpa_s->current_ssid &&
4922 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4923 !data->assoc_reject.timed_out) {
4924 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4925 wpa_sm_aborted_cached(wpa_s->wpa);
4926 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4927 }
4928#endif /* CONFIG_DPP */
4929
Roshan Pius3a1667e2018-07-03 15:17:14 -07004930#ifdef CONFIG_FILS
4931 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004932 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004933 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004934 eapol_sm_update_erp_next_seq_num(
4935 wpa_s->eapol,
4936 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004937 fils_connection_failure(wpa_s);
4938 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004939#endif /* CONFIG_FILS */
4940
4941 wpas_connection_failed(wpa_s, bssid);
4942 wpa_supplicant_mark_disassoc(wpa_s);
4943}
4944
4945
Hai Shalomfdcde762020-04-02 11:19:20 -07004946static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
4947 struct unprot_beacon *data)
4948{
4949 struct wpabuf *buf;
4950 int res;
4951
4952 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
4953 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
4954 return;
4955 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
4956 MAC2STR(data->sa));
4957
4958 buf = wpabuf_alloc(4);
4959 if (!buf)
4960 return;
4961
4962 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
4963 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
4964 wpabuf_put_u8(buf, 1); /* Dialog Token */
4965 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
4966
4967 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
4968 wpa_s->own_addr, wpa_s->bssid,
4969 wpabuf_head(buf), wpabuf_len(buf), 0);
4970 if (res < 0)
4971 wpa_printf(MSG_DEBUG,
4972 "Failed to send WNM-Notification Request frame");
4973
4974 wpabuf_free(buf);
4975}
4976
4977
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004978void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4979 union wpa_event_data *data)
4980{
4981 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004982 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07004983 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08004984#ifndef CONFIG_NO_STDOUT_DEBUG
4985 int level = MSG_DEBUG;
4986#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004987
4988 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4989 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004990 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004991 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004992 event != EVENT_SCHED_SCAN_STOPPED) {
4993 wpa_dbg(wpa_s, MSG_DEBUG,
4994 "Ignore event %s (%d) while interface is disabled",
4995 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004996 return;
4997 }
4998
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004999#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005000 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005001 const struct ieee80211_hdr *hdr;
5002 u16 fc;
5003 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5004 fc = le_to_host16(hdr->frame_control);
5005 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5006 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5007 level = MSG_EXCESSIVE;
5008 }
5009
5010 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5011 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005012#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005013
5014 switch (event) {
5015 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005016#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005017 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5018 data->auth.ies_len))
5019 wpa_printf(MSG_DEBUG,
5020 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005021#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005022 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005023 wpa_s->auth_status_code = data->auth.status_code;
5024 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005025 break;
5026 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005027#ifdef CONFIG_TESTING_OPTIONS
5028 if (wpa_s->ignore_auth_resp) {
5029 wpa_printf(MSG_INFO,
5030 "EVENT_ASSOC - ignore_auth_resp active!");
5031 break;
5032 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005033 if (wpa_s->testing_resend_assoc) {
5034 wpa_printf(MSG_INFO,
5035 "EVENT_DEAUTH - testing_resend_assoc");
5036 break;
5037 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005038#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305039 if (wpa_s->disconnected) {
5040 wpa_printf(MSG_INFO,
5041 "Ignore unexpected EVENT_ASSOC in disconnected state");
5042 break;
5043 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005044 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005045 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005046 if (data &&
5047 (data->assoc_info.authorized ||
5048 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5049 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005050 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005051 if (data) {
5052 wpa_msg(wpa_s, MSG_INFO,
5053 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5054 data->assoc_info.subnet_status);
5055 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005056 break;
5057 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005058 wpas_event_disassoc(wpa_s,
5059 data ? &data->disassoc_info : NULL);
5060 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005061 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005062#ifdef CONFIG_TESTING_OPTIONS
5063 if (wpa_s->ignore_auth_resp) {
5064 wpa_printf(MSG_INFO,
5065 "EVENT_DEAUTH - ignore_auth_resp active!");
5066 break;
5067 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005068 if (wpa_s->testing_resend_assoc) {
5069 wpa_printf(MSG_INFO,
5070 "EVENT_DEAUTH - testing_resend_assoc");
5071 break;
5072 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005073#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005074 wpas_event_deauth(wpa_s,
5075 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005076 break;
5077 case EVENT_MICHAEL_MIC_FAILURE:
5078 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5079 break;
5080#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005081 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005082 if (wpa_s->own_scan_requested ||
5083 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005084 struct os_reltime diff;
5085
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005086 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005087 os_reltime_sub(&wpa_s->scan_start_time,
5088 &wpa_s->scan_trigger_time, &diff);
5089 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5090 diff.sec, diff.usec);
5091 wpa_s->own_scan_requested = 0;
5092 wpa_s->own_scan_running = 1;
5093 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5094 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005095 wpa_msg_ctrl(wpa_s, MSG_INFO,
5096 WPA_EVENT_SCAN_STARTED "id=%u",
5097 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005098 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005099 wpa_msg_ctrl(wpa_s, MSG_INFO,
5100 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005101 }
5102 } else {
5103 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005104 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005105 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005106 }
5107 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005108 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005109 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5110 wpa_s->scan_res_handler = NULL;
5111 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005112 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005113 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5114 break;
5115 }
5116
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005117 if (!(data && data->scan_info.external_scan) &&
5118 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005119 struct os_reltime now, diff;
5120 os_get_reltime(&now);
5121 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5122 wpa_s->scan_start_time.sec = 0;
5123 wpa_s->scan_start_time.usec = 0;
5124 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5125 diff.sec, diff.usec);
5126 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005127 if (wpa_supplicant_event_scan_results(wpa_s, data))
5128 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005129 if (!(data && data->scan_info.external_scan))
5130 wpa_s->own_scan_running = 0;
5131 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005132 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005133 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005134 break;
5135#endif /* CONFIG_NO_SCAN_PROCESSING */
5136 case EVENT_ASSOCINFO:
5137 wpa_supplicant_event_associnfo(wpa_s, data);
5138 break;
5139 case EVENT_INTERFACE_STATUS:
5140 wpa_supplicant_event_interface_status(wpa_s, data);
5141 break;
5142 case EVENT_PMKID_CANDIDATE:
5143 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5144 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005145#ifdef CONFIG_TDLS
5146 case EVENT_TDLS:
5147 wpa_supplicant_event_tdls(wpa_s, data);
5148 break;
5149#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005150#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005151 case EVENT_WNM:
5152 wpa_supplicant_event_wnm(wpa_s, data);
5153 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005154#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005155#ifdef CONFIG_IEEE80211R
5156 case EVENT_FT_RESPONSE:
5157 wpa_supplicant_event_ft_response(wpa_s, data);
5158 break;
5159#endif /* CONFIG_IEEE80211R */
5160#ifdef CONFIG_IBSS_RSN
5161 case EVENT_IBSS_RSN_START:
5162 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5163 break;
5164#endif /* CONFIG_IBSS_RSN */
5165 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005166 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005167 break;
5168 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005169 /* It is possible to get this event from earlier connection */
5170 if (wpa_s->current_ssid &&
5171 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5172 wpa_dbg(wpa_s, MSG_DEBUG,
5173 "Ignore AUTH_TIMED_OUT in mesh configuration");
5174 break;
5175 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005176 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5177 sme_event_auth_timed_out(wpa_s, data);
5178 break;
5179 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005180 /* It is possible to get this event from earlier connection */
5181 if (wpa_s->current_ssid &&
5182 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5183 wpa_dbg(wpa_s, MSG_DEBUG,
5184 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5185 break;
5186 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005187 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5188 sme_event_assoc_timed_out(wpa_s, data);
5189 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005190 case EVENT_TX_STATUS:
5191 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5192 " type=%d stype=%d",
5193 MAC2STR(data->tx_status.dst),
5194 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005195#ifdef CONFIG_PASN
5196 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5197 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5198 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5199 data->tx_status.data_len,
5200 data->tx_status.ack) == 0)
5201 break;
5202#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005203#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005204 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005205#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005206 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5207 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005208 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005209 wpa_s, data->tx_status.dst,
5210 data->tx_status.data,
5211 data->tx_status.data_len,
5212 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005213 OFFCHANNEL_SEND_ACTION_SUCCESS :
5214 OFFCHANNEL_SEND_ACTION_NO_ACK);
5215#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005216 break;
5217 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005218#endif /* CONFIG_AP */
5219#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005220 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005221 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005222 /*
5223 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005224 * interface in GO mode, or via standalone AP interface.
5225 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5226 * except when the primary interface is used as a GO interface
5227 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005228 */
5229 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5230 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005231 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005232 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005233 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005234 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005235 data->tx_status.data,
5236 data->tx_status.data_len,
5237 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005238 OFFCHANNEL_SEND_ACTION_SUCCESS :
5239 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005240 break;
5241 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005242#endif /* CONFIG_OFFCHANNEL */
5243#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005244 switch (data->tx_status.type) {
5245 case WLAN_FC_TYPE_MGMT:
5246 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5247 data->tx_status.data_len,
5248 data->tx_status.stype,
5249 data->tx_status.ack);
5250 break;
5251 case WLAN_FC_TYPE_DATA:
5252 ap_tx_status(wpa_s, data->tx_status.dst,
5253 data->tx_status.data,
5254 data->tx_status.data_len,
5255 data->tx_status.ack);
5256 break;
5257 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005258#endif /* CONFIG_AP */
5259 break;
5260#ifdef CONFIG_AP
5261 case EVENT_EAPOL_TX_STATUS:
5262 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5263 data->eapol_tx_status.data,
5264 data->eapol_tx_status.data_len,
5265 data->eapol_tx_status.ack);
5266 break;
5267 case EVENT_DRIVER_CLIENT_POLL_OK:
5268 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005269 break;
5270 case EVENT_RX_FROM_UNKNOWN:
5271 if (wpa_s->ap_iface == NULL)
5272 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005273 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5274 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005275 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005276#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005277
5278 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005279 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005280 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005281 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005282
Hai Shalom81f62d82019-07-22 12:10:00 -07005283 wpa_msg(wpa_s, MSG_INFO,
5284 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5285 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5286 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005287 data->ch_switch.freq,
5288 data->ch_switch.ht_enabled,
5289 data->ch_switch.ch_offset,
5290 channel_width_to_string(data->ch_switch.ch_width),
5291 data->ch_switch.cf1,
5292 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005293 if (event == EVENT_CH_SWITCH_STARTED)
5294 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005295
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005296 wpa_s->assoc_freq = data->ch_switch.freq;
5297 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005298 if (wpa_s->current_bss &&
5299 wpa_s->current_bss->freq != data->ch_switch.freq) {
5300 wpa_s->current_bss->freq = data->ch_switch.freq;
5301 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5302 wpa_s->current_bss);
5303 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005304
Hai Shalomfdcde762020-04-02 11:19:20 -07005305#ifdef CONFIG_SME
5306 switch (data->ch_switch.ch_offset) {
5307 case 1:
5308 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5309 break;
5310 case -1:
5311 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5312 break;
5313 default:
5314 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5315 break;
5316 }
5317#endif /* CONFIG_SME */
5318
Roshan Pius3a1667e2018-07-03 15:17:14 -07005319#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005320 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5321 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005322 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005323 wpa_s->current_ssid->mode ==
5324 WPAS_MODE_P2P_GROUP_FORMATION) {
5325 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5326 data->ch_switch.ht_enabled,
5327 data->ch_switch.ch_offset,
5328 data->ch_switch.ch_width,
5329 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005330 data->ch_switch.cf2,
5331 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005332 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005333#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005334
Hai Shalom899fcc72020-10-19 14:38:18 -07005335 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5336 sme_event_ch_switch(wpa_s);
5337
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005338 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005339 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005340 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005341#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005342#ifdef NEED_AP_MLME
5343 case EVENT_DFS_RADAR_DETECTED:
5344 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005345 wpas_ap_event_dfs_radar_detected(wpa_s,
5346 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005347 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005348 case EVENT_DFS_NOP_FINISHED:
5349 if (data)
5350 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5351 &data->dfs_event);
5352 break;
5353#endif /* NEED_AP_MLME */
5354#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005355 case EVENT_DFS_CAC_STARTED:
5356 if (data)
5357 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5358 break;
5359 case EVENT_DFS_CAC_FINISHED:
5360 if (data)
5361 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5362 break;
5363 case EVENT_DFS_CAC_ABORTED:
5364 if (data)
5365 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5366 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005367 case EVENT_RX_MGMT: {
5368 u16 fc, stype;
5369 const struct ieee80211_mgmt *mgmt;
5370
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005371#ifdef CONFIG_TESTING_OPTIONS
5372 if (wpa_s->ext_mgmt_frame_handling) {
5373 struct rx_mgmt *rx = &data->rx_mgmt;
5374 size_t hex_len = 2 * rx->frame_len + 1;
5375 char *hex = os_malloc(hex_len);
5376 if (hex) {
5377 wpa_snprintf_hex(hex, hex_len,
5378 rx->frame, rx->frame_len);
5379 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5380 rx->freq, rx->datarate, rx->ssi_signal,
5381 hex);
5382 os_free(hex);
5383 }
5384 break;
5385 }
5386#endif /* CONFIG_TESTING_OPTIONS */
5387
Dmitry Shmidt04949592012-07-19 12:16:46 -07005388 mgmt = (const struct ieee80211_mgmt *)
5389 data->rx_mgmt.frame;
5390 fc = le_to_host16(mgmt->frame_control);
5391 stype = WLAN_FC_GET_STYPE(fc);
5392
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005393#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005394 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005395#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005396#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005397 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005398 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005399 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005400 const u8 *ie;
5401 size_t ie_len;
5402
5403 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5404 ie_len = data->rx_mgmt.frame_len -
5405 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005406 wpas_p2p_probe_req_rx(
5407 wpa_s, src, mgmt->da,
5408 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005409 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005410 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005411 break;
5412 }
5413#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005414#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005415 if (wpa_s->current_ssid &&
5416 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5417 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005418 data->rx_mgmt.frame_len >= 30) {
5419 wpa_supplicant_event_ibss_auth(wpa_s, data);
5420 break;
5421 }
5422#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005423
5424 if (stype == WLAN_FC_STYPE_ACTION) {
5425 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005426 wpa_s, data->rx_mgmt.frame,
5427 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005428 data->rx_mgmt.freq,
5429 data->rx_mgmt.ssi_signal);
5430 break;
5431 }
5432
5433 if (wpa_s->ifmsh) {
5434 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005435 break;
5436 }
Hai Shalom60840252021-02-19 19:02:11 -08005437#ifdef CONFIG_PASN
5438 if (stype == WLAN_FC_STYPE_AUTH &&
5439 wpas_pasn_auth_rx(wpa_s, mgmt,
5440 data->rx_mgmt.frame_len) != -2)
5441 break;
5442#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005443
Roshan Pius3a1667e2018-07-03 15:17:14 -07005444#ifdef CONFIG_SAE
5445 if (stype == WLAN_FC_STYPE_AUTH &&
5446 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5447 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5448 sme_external_auth_mgmt_rx(
5449 wpa_s, data->rx_mgmt.frame,
5450 data->rx_mgmt.frame_len);
5451 break;
5452 }
5453#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005454 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5455 "management frame in non-AP mode");
5456 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005457#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005458 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005459
5460 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005461 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5462 const u8 *ie;
5463 size_t ie_len;
5464
5465 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5466 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005467
5468 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5469 mgmt->bssid, ie, ie_len,
5470 data->rx_mgmt.ssi_signal);
5471 }
5472
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005473 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005474#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005475 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005476 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005477 case EVENT_RX_PROBE_REQ:
5478 if (data->rx_probe_req.sa == NULL ||
5479 data->rx_probe_req.ie == NULL)
5480 break;
5481#ifdef CONFIG_AP
5482 if (wpa_s->ap_iface) {
5483 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5484 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005485 data->rx_probe_req.da,
5486 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005487 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005488 data->rx_probe_req.ie_len,
5489 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005490 break;
5491 }
5492#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005493 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005494 data->rx_probe_req.da,
5495 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005496 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005497 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005498 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005499 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005500 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005501 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005502#ifdef CONFIG_OFFCHANNEL
5503 offchannel_remain_on_channel_cb(
5504 wpa_s, data->remain_on_channel.freq,
5505 data->remain_on_channel.duration);
5506#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005507 wpas_p2p_remain_on_channel_cb(
5508 wpa_s, data->remain_on_channel.freq,
5509 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005510#ifdef CONFIG_DPP
5511 wpas_dpp_remain_on_channel_cb(
5512 wpa_s, data->remain_on_channel.freq,
5513 data->remain_on_channel.duration);
5514#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005515 break;
5516 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005517#ifdef CONFIG_OFFCHANNEL
5518 offchannel_cancel_remain_on_channel_cb(
5519 wpa_s, data->remain_on_channel.freq);
5520#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005521 wpas_p2p_cancel_remain_on_channel_cb(
5522 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005523#ifdef CONFIG_DPP
5524 wpas_dpp_cancel_remain_on_channel_cb(
5525 wpa_s, data->remain_on_channel.freq);
5526#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005527 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005528 case EVENT_EAPOL_RX:
5529 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5530 data->eapol_rx.data,
5531 data->eapol_rx.data_len);
5532 break;
5533 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005534 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5535 "above=%d signal=%d noise=%d txrate=%d",
5536 data->signal_change.above_threshold,
5537 data->signal_change.current_signal,
5538 data->signal_change.current_noise,
5539 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005540 wpa_bss_update_level(wpa_s->current_bss,
5541 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005542 bgscan_notify_signal_change(
5543 wpa_s, data->signal_change.above_threshold,
5544 data->signal_change.current_signal,
5545 data->signal_change.current_noise,
5546 data->signal_change.current_txrate);
5547 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005548 case EVENT_INTERFACE_MAC_CHANGED:
5549 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005550 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005551 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005552 case EVENT_INTERFACE_ENABLED:
5553 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5554 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005555 u8 addr[ETH_ALEN];
5556
Hai Shalomfdcde762020-04-02 11:19:20 -07005557 eloop_cancel_timeout(wpas_clear_disabled_interface,
5558 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005559 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005560 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005561 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5562 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5563 else
5564 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005565 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005566 if (wpa_s->p2p_mgmt) {
5567 wpa_supplicant_set_state(wpa_s,
5568 WPA_DISCONNECTED);
5569 break;
5570 }
5571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005572#ifdef CONFIG_AP
5573 if (!wpa_s->ap_iface) {
5574 wpa_supplicant_set_state(wpa_s,
5575 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005576 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005577 wpa_supplicant_req_scan(wpa_s, 0, 0);
5578 } else
5579 wpa_supplicant_set_state(wpa_s,
5580 WPA_COMPLETED);
5581#else /* CONFIG_AP */
5582 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5583 wpa_supplicant_req_scan(wpa_s, 0, 0);
5584#endif /* CONFIG_AP */
5585 }
5586 break;
5587 case EVENT_INTERFACE_DISABLED:
5588 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005589#ifdef CONFIG_P2P
5590 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5591 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5592 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5593 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005594 * Mark interface disabled if this happens to end up not
5595 * being removed as a separate P2P group interface.
5596 */
5597 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5598 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005599 * The interface was externally disabled. Remove
5600 * it assuming an external entity will start a
5601 * new session if needed.
5602 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005603 if (wpa_s->current_ssid &&
5604 wpa_s->current_ssid->p2p_group)
5605 wpas_p2p_interface_unavailable(wpa_s);
5606 else
5607 wpas_p2p_disconnect(wpa_s);
5608 /*
5609 * wpa_s instance may have been freed, so must not use
5610 * it here anymore.
5611 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005612 break;
5613 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005614 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5615 p2p_in_progress(wpa_s->global->p2p) > 1) {
5616 /* This radio work will be cancelled, so clear P2P
5617 * state as well.
5618 */
5619 p2p_stop_find(wpa_s->global->p2p);
5620 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005621#endif /* CONFIG_P2P */
5622
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005623 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5624 /*
5625 * Indicate disconnection to keep ctrl_iface events
5626 * consistent.
5627 */
5628 wpa_supplicant_event_disassoc(
5629 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5630 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005631 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005632 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005633 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5634 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005635 clear_at.usec = 0;
5636 } else {
5637 struct os_reltime tmp;
5638
Hai Shalom60840252021-02-19 19:02:11 -08005639 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005640 tmp.usec = 0;
5641 os_reltime_sub(&tmp, &age, &clear_at);
5642 }
5643 eloop_register_timeout(clear_at.sec, clear_at.usec,
5644 wpas_clear_disabled_interface,
5645 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005646 radio_remove_works(wpa_s, NULL, 0);
5647
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005648 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5649 break;
5650 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005651 wpa_supplicant_update_channel_list(
5652 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005653 break;
5654 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005655 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005656 break;
5657 case EVENT_BEST_CHANNEL:
5658 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5659 "(%d %d %d)",
5660 data->best_chan.freq_24, data->best_chan.freq_5,
5661 data->best_chan.freq_overall);
5662 wpa_s->best_24_freq = data->best_chan.freq_24;
5663 wpa_s->best_5_freq = data->best_chan.freq_5;
5664 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005665 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5666 data->best_chan.freq_5,
5667 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005668 break;
5669 case EVENT_UNPROT_DEAUTH:
5670 wpa_supplicant_event_unprot_deauth(wpa_s,
5671 &data->unprot_deauth);
5672 break;
5673 case EVENT_UNPROT_DISASSOC:
5674 wpa_supplicant_event_unprot_disassoc(wpa_s,
5675 &data->unprot_disassoc);
5676 break;
5677 case EVENT_STATION_LOW_ACK:
5678#ifdef CONFIG_AP
5679 if (wpa_s->ap_iface && data)
5680 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5681 data->low_ack.addr);
5682#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005683#ifdef CONFIG_TDLS
5684 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005685 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5686 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005687#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005688 break;
5689 case EVENT_IBSS_PEER_LOST:
5690#ifdef CONFIG_IBSS_RSN
5691 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5692#endif /* CONFIG_IBSS_RSN */
5693 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005694 case EVENT_DRIVER_GTK_REKEY:
5695 if (os_memcmp(data->driver_gtk_rekey.bssid,
5696 wpa_s->bssid, ETH_ALEN))
5697 break;
5698 if (!wpa_s->wpa)
5699 break;
5700 wpa_sm_update_replay_ctr(wpa_s->wpa,
5701 data->driver_gtk_rekey.replay_ctr);
5702 break;
5703 case EVENT_SCHED_SCAN_STOPPED:
5704 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005705 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005706 wpa_supplicant_notify_scanning(wpa_s, 0);
5707
5708 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5709 break;
5710
5711 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005712 * If the driver stopped scanning without being requested to,
5713 * request a new scan to continue scanning for networks.
5714 */
5715 if (!wpa_s->sched_scan_stop_req &&
5716 wpa_s->wpa_state == WPA_SCANNING) {
5717 wpa_dbg(wpa_s, MSG_DEBUG,
5718 "Restart scanning after unexpected sched_scan stop event");
5719 wpa_supplicant_req_scan(wpa_s, 1, 0);
5720 break;
5721 }
5722
5723 wpa_s->sched_scan_stop_req = 0;
5724
5725 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005726 * Start a new sched scan to continue searching for more SSIDs
5727 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005728 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005729 if (wpa_s->sched_scan_timed_out) {
5730 wpa_supplicant_req_sched_scan(wpa_s);
5731 } else if (wpa_s->pno_sched_pending) {
5732 wpa_s->pno_sched_pending = 0;
5733 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005734 } else if (resched) {
5735 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005736 }
5737
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005738 break;
5739 case EVENT_WPS_BUTTON_PUSHED:
5740#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005741 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005742#endif /* CONFIG_WPS */
5743 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005744 case EVENT_AVOID_FREQUENCIES:
5745 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5746 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005747 case EVENT_CONNECT_FAILED_REASON:
5748#ifdef CONFIG_AP
5749 if (!wpa_s->ap_iface || !data)
5750 break;
5751 hostapd_event_connect_failed_reason(
5752 wpa_s->ap_iface->bss[0],
5753 data->connect_failed_reason.addr,
5754 data->connect_failed_reason.code);
5755#endif /* CONFIG_AP */
5756 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005757 case EVENT_NEW_PEER_CANDIDATE:
5758#ifdef CONFIG_MESH
5759 if (!wpa_s->ifmsh || !data)
5760 break;
5761 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5762 data->mesh_peer.ies,
5763 data->mesh_peer.ie_len);
5764#endif /* CONFIG_MESH */
5765 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005766 case EVENT_SURVEY:
5767#ifdef CONFIG_AP
5768 if (!wpa_s->ap_iface)
5769 break;
5770 hostapd_event_get_survey(wpa_s->ap_iface,
5771 &data->survey_results);
5772#endif /* CONFIG_AP */
5773 break;
5774 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005775#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005776#ifdef CONFIG_ACS
5777 if (!wpa_s->ap_iface)
5778 break;
5779 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5780 &data->acs_selected_channels);
5781#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005782#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005783 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005784 case EVENT_P2P_LO_STOP:
5785#ifdef CONFIG_P2P
5786 wpa_s->p2p_lo_started = 0;
5787 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5788 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5789 data->p2p_lo_stop.reason_code);
5790#endif /* CONFIG_P2P */
5791 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005792 case EVENT_BEACON_LOSS:
5793 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5794 break;
5795 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5796 bgscan_notify_beacon_loss(wpa_s);
5797 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005798 case EVENT_EXTERNAL_AUTH:
5799#ifdef CONFIG_SAE
5800 if (!wpa_s->current_ssid) {
5801 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5802 break;
5803 }
5804 sme_external_auth_trigger(wpa_s, data);
5805#endif /* CONFIG_SAE */
5806 break;
5807 case EVENT_PORT_AUTHORIZED:
5808 wpa_supplicant_event_port_authorized(wpa_s);
5809 break;
5810 case EVENT_STATION_OPMODE_CHANGED:
5811#ifdef CONFIG_AP
5812 if (!wpa_s->ap_iface || !data)
5813 break;
5814
5815 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5816 data->sta_opmode.addr,
5817 data->sta_opmode.smps_mode,
5818 data->sta_opmode.chan_width,
5819 data->sta_opmode.rx_nss);
5820#endif /* CONFIG_AP */
5821 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005822 case EVENT_UNPROT_BEACON:
5823 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5824 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08005825 case EVENT_TX_WAIT_EXPIRE:
5826#ifdef CONFIG_DPP
5827 wpas_dpp_tx_wait_expire(wpa_s);
5828#endif /* CONFIG_DPP */
5829 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005830 default:
5831 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5832 break;
5833 }
5834}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005835
5836
5837void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5838 union wpa_event_data *data)
5839{
5840 struct wpa_supplicant *wpa_s;
5841
5842 if (event != EVENT_INTERFACE_STATUS)
5843 return;
5844
5845 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5846 if (wpa_s && wpa_s->driver->get_ifindex) {
5847 unsigned int ifindex;
5848
5849 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5850 if (ifindex != data->interface_status.ifindex) {
5851 wpa_dbg(wpa_s, MSG_DEBUG,
5852 "interface status ifindex %d mismatch (%d)",
5853 ifindex, data->interface_status.ifindex);
5854 return;
5855 }
5856 }
5857#ifdef CONFIG_MATCH_IFACE
5858 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5859 struct wpa_interface *wpa_i;
5860
5861 wpa_i = wpa_supplicant_match_iface(
5862 ctx, data->interface_status.ifname);
5863 if (!wpa_i)
5864 return;
5865 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5866 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07005867 }
5868#endif /* CONFIG_MATCH_IFACE */
5869
5870 if (wpa_s)
5871 wpa_supplicant_event(wpa_s, event, data);
5872}