blob: aa01245bf050bf599f8a2f6853142a9f15bd24cf [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Hai Shalom021b0b52019-04-10 11:17:58 -07003 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "notify.h"
29#include "common/ieee802_11_defs.h"
30#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070031#include "common/gas_server.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070032#include "common/dpp.h"
Hai Shalom60840252021-02-19 19:02:11 -080033#include "common/ptksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "crypto/random.h"
Hai Shalom60840252021-02-19 19:02:11 -080035#include "bssid_ignore.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "wpas_glue.h"
37#include "wps_supplicant.h"
38#include "ibss_rsn.h"
39#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080040#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "p2p_supplicant.h"
42#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070043#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044#include "ap.h"
45#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080047#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080049#include "mesh.h"
50#include "mesh_mpm.h"
51#include "wmm_ac.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070052#include "dpp_supplicant.h"
Mir Ali677e7482020-11-12 19:49:02 +053053#include "rsn_supp/wpa_i.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070054
55
Hai Shalom39ba6fc2019-01-22 12:40:38 -080056#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
57
58
Dmitry Shmidt34af3062013-07-11 10:46:32 -070059#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070060static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080061 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070062#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080063
64
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070065int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080067 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070068
69 if (ssid == NULL || ssid->disabled_until.sec == 0)
70 return 0;
71
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080072 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070073 if (ssid->disabled_until.sec > now.sec)
74 return ssid->disabled_until.sec - now.sec;
75
76 wpas_clear_temp_disabled(wpa_s, ssid, 0);
77
78 return 0;
79}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080
81
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080082#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070083/**
84 * wpas_reenabled_network_time - Time until first network is re-enabled
85 * @wpa_s: Pointer to wpa_supplicant data
86 * Returns: If all enabled networks are temporarily disabled, returns the time
87 * (in sec) until the first network is re-enabled. Otherwise returns 0.
88 *
89 * This function is used in case all enabled networks are temporarily disabled,
90 * in which case it returns the time (in sec) that the first network will be
91 * re-enabled. The function assumes that at least one network is enabled.
92 */
93static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
94{
95 struct wpa_ssid *ssid;
96 int disabled_for, res = 0;
97
98#ifdef CONFIG_INTERWORKING
99 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
100 wpa_s->conf->cred)
101 return 0;
102#endif /* CONFIG_INTERWORKING */
103
104 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
105 if (ssid->disabled)
106 continue;
107
108 disabled_for = wpas_temp_disabled(wpa_s, ssid);
109 if (!disabled_for)
110 return 0;
111
112 if (!res || disabled_for < res)
113 res = disabled_for;
114 }
115
116 return res;
117}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800118#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700119
120
121void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
122{
123 struct wpa_supplicant *wpa_s = eloop_ctx;
124
125 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
126 return;
127
128 wpa_dbg(wpa_s, MSG_DEBUG,
129 "Try to associate due to network getting re-enabled");
130 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
131 wpa_supplicant_cancel_sched_scan(wpa_s);
132 wpa_supplicant_req_scan(wpa_s, 0, 0);
133 }
134}
135
136
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800137static struct wpa_bss * wpa_supplicant_get_new_bss(
138 struct wpa_supplicant *wpa_s, const u8 *bssid)
139{
140 struct wpa_bss *bss = NULL;
141 struct wpa_ssid *ssid = wpa_s->current_ssid;
142
143 if (ssid->ssid_len > 0)
144 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
145 if (!bss)
146 bss = wpa_bss_get_bssid(wpa_s, bssid);
147
148 return bss;
149}
150
151
Sunil Ravia04bd252022-05-02 22:54:18 -0700152static struct wpa_bss *
153wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700154{
Sunil Ravia04bd252022-05-02 22:54:18 -0700155 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700156
157 if (!bss) {
158 wpa_supplicant_update_scan_results(wpa_s);
159
160 /* Get the BSS from the new scan results */
Sunil Ravia04bd252022-05-02 22:54:18 -0700161 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700162 }
163
164 if (bss)
165 wpa_s->current_bss = bss;
Sunil Ravia04bd252022-05-02 22:54:18 -0700166
167 return bss;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700168}
169
170
Sunil Ravi89eba102022-09-13 21:04:37 -0700171static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
172 u8 link_id, const u8 *bssid)
173{
174 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
175
176 if (!bss) {
177 wpa_supplicant_update_scan_results(wpa_s);
178 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
179 }
180
181 if (bss)
182 wpa_s->links[link_id].bss = bss;
183}
184
185
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700186static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
187{
188 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700189 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700190 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700191 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700193 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700194 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700195
196 if (wpa_s->current_ssid->ssid_len == 0)
197 return 0; /* current profile still in use */
198 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
199 if (res < 0) {
200 wpa_msg(wpa_s, MSG_INFO,
201 "Failed to read SSID from driver");
202 return 0; /* try to use current profile */
203 }
204 drv_ssid_len = res;
205
206 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
207 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
208 drv_ssid_len) == 0)
209 return 0; /* current profile still in use */
210
Hai Shalomfdcde762020-04-02 11:19:20 -0700211#ifdef CONFIG_OWE
212 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
213 wpa_s->current_bss &&
214 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
215 drv_ssid_len == wpa_s->current_bss->ssid_len &&
216 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
217 drv_ssid_len) == 0)
218 return 0; /* current profile still in use */
219#endif /* CONFIG_OWE */
220
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700221 wpa_msg(wpa_s, MSG_DEBUG,
222 "Driver-initiated BSS selection changed the SSID to %s",
223 wpa_ssid_txt(drv_ssid, drv_ssid_len));
224 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700225 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226
227 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
228 "information");
229 ssid = wpa_supplicant_get_ssid(wpa_s);
230 if (ssid == NULL) {
231 wpa_msg(wpa_s, MSG_INFO,
232 "No network configuration found for the current AP");
233 return -1;
234 }
235
Dmitry Shmidt04949592012-07-19 12:16:46 -0700236 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
238 return -1;
239 }
240
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800241 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
242 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
243 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
244 return -1;
245 }
246
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700247 res = wpas_temp_disabled(wpa_s, ssid);
248 if (res > 0) {
249 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
250 "disabled for %d second(s)", res);
251 return -1;
252 }
253
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
255 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800256 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257 u8 wpa_ie[80];
258 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800259 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
260 wpa_ie, &wpa_ie_len) < 0)
261 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262 } else {
263 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
264 }
265
266 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
267 eapol_sm_invalidate_cached_session(wpa_s->eapol);
268 old_ssid = wpa_s->current_ssid;
269 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800270
Sunil Ravia04bd252022-05-02 22:54:18 -0700271 wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800272
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
274 wpa_supplicant_initiate_eapol(wpa_s);
275 if (old_ssid != wpa_s->current_ssid)
276 wpas_notify_network_changed(wpa_s);
277
278 return 0;
279}
280
281
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800282void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283{
284 struct wpa_supplicant *wpa_s = eloop_ctx;
285
286 if (wpa_s->countermeasures) {
287 wpa_s->countermeasures = 0;
288 wpa_drv_set_countermeasures(wpa_s, 0);
289 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800290
291 /*
292 * It is possible that the device is sched scanning, which means
293 * that a connection attempt will be done only when we receive
294 * scan results. However, in this case, it would be preferable
295 * to scan and connect immediately, so cancel the sched_scan and
296 * issue a regular scan flow.
297 */
298 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299 wpa_supplicant_req_scan(wpa_s, 0, 0);
300 }
301}
302
303
Sunil Ravi89eba102022-09-13 21:04:37 -0700304static void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
305{
306 int i;
307
308 if (!wpa_s->valid_links)
309 return;
310
311 wpa_s->valid_links = 0;
312 for (i = 0; i < MAX_NUM_MLD_LINKS; i++)
313 wpa_s->links[i].bss = NULL;
314}
315
316
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
318{
319 int bssid_changed;
320
Dmitry Shmidt04949592012-07-19 12:16:46 -0700321 wnm_bss_keep_alive_deinit(wpa_s);
322
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323#ifdef CONFIG_IBSS_RSN
324 ibss_rsn_deinit(wpa_s->ibss_rsn);
325 wpa_s->ibss_rsn = NULL;
326#endif /* CONFIG_IBSS_RSN */
327
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700328#ifdef CONFIG_AP
329 wpa_supplicant_ap_deinit(wpa_s);
330#endif /* CONFIG_AP */
331
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700332#ifdef CONFIG_HS20
333 /* Clear possibly configured frame filters */
334 wpa_drv_configure_frame_filters(wpa_s, 0);
335#endif /* CONFIG_HS20 */
336
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
338 return;
339
Hai Shalom74f70d42019-02-11 14:42:39 -0800340 if (os_reltime_initialized(&wpa_s->session_start)) {
341 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
342 wpa_s->session_start.sec = 0;
343 wpa_s->session_start.usec = 0;
344 wpas_notify_session_length(wpa_s);
345 }
346
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
348 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
349 os_memset(wpa_s->bssid, 0, ETH_ALEN);
350 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800351 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352 wpa_s->current_bss = NULL;
353 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700355 if (bssid_changed)
356 wpas_notify_bssid_changed(wpa_s);
357
Hai Shalome21d4e82020-04-29 16:34:06 -0700358 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
359 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700360 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
361 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700362 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700363 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700364 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700365 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700366 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700367 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700368 wpa_s->key_mgmt = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700369 wpa_s->allowed_key_mgmts = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800370
371 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800372 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800373 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700374 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700375
376#ifdef CONFIG_TESTING_OPTIONS
377 wpa_s->last_tk_alg = WPA_ALG_NONE;
378 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
379#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700380 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800381
382 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
383 wpa_s->enabled_4addr_mode = 0;
Sunil Ravi89eba102022-09-13 21:04:37 -0700384
385 wpas_reset_mlo_info(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700386}
387
388
389static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
390{
391 struct wpa_ie_data ie;
392 int pmksa_set = -1;
393 size_t i;
Hai Shalomc1a21442022-02-04 13:43:00 -0800394 struct rsn_pmksa_cache_entry *cur_pmksa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700395
Hai Shalomc1a21442022-02-04 13:43:00 -0800396 /* Start with assumption of no PMKSA cache entry match for cases other
397 * than SAE. In particular, this is needed to generate the PMKSA cache
398 * entries for Suite B cases with driver-based roaming indication. */
399 cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
400 if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
401 pmksa_cache_clear_current(wpa_s->wpa);
Hai Shalom899fcc72020-10-19 14:38:18 -0700402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
404 ie.pmkid == NULL)
405 return;
406
407 for (i = 0; i < ie.num_pmkid; i++) {
408 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
409 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700410 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800412 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700413 break;
414 }
415 }
416
417 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
418 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
419}
420
421
422static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
423 union wpa_event_data *data)
424{
425 if (data == NULL) {
426 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
427 "event");
428 return;
429 }
430 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
431 " index=%d preauth=%d",
432 MAC2STR(data->pmkid_candidate.bssid),
433 data->pmkid_candidate.index,
434 data->pmkid_candidate.preauth);
435
436 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
437 data->pmkid_candidate.index,
438 data->pmkid_candidate.preauth);
439}
440
441
442static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
443{
444 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
445 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
446 return 0;
447
448#ifdef IEEE8021X_EAPOL
449 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
450 wpa_s->current_ssid &&
451 !(wpa_s->current_ssid->eapol_flags &
452 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
453 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
454 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
455 * plaintext or static WEP keys). */
456 return 0;
457 }
458#endif /* IEEE8021X_EAPOL */
459
460 return 1;
461}
462
463
464/**
465 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
466 * @wpa_s: pointer to wpa_supplicant data
467 * @ssid: Configuration data for the network
468 * Returns: 0 on success, -1 on failure
469 *
470 * This function is called when starting authentication with a network that is
471 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
472 */
473int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
474 struct wpa_ssid *ssid)
475{
476#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800477#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700478 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700480 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
481 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482 return 0;
483
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700484 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485 sim = 1;
486 aka = 1;
487 } else {
488 struct eap_method_type *eap = ssid->eap.eap_methods;
489 while (eap->vendor != EAP_VENDOR_IETF ||
490 eap->method != EAP_TYPE_NONE) {
491 if (eap->vendor == EAP_VENDOR_IETF) {
492 if (eap->method == EAP_TYPE_SIM)
493 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700494 else if (eap->method == EAP_TYPE_AKA ||
495 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700496 aka = 1;
497 }
498 eap++;
499 }
500 }
501
502 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
503 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700504 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
505 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
506 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 aka = 0;
508
509 if (!sim && !aka) {
510 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
511 "use SIM, but neither EAP-SIM nor EAP-AKA are "
512 "enabled");
513 return 0;
514 }
515
516 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
517 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700519 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 if (wpa_s->scard == NULL) {
521 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
522 "(pcsc-lite)");
523 return -1;
524 }
525 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
526 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800527#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528#endif /* IEEE8021X_EAPOL */
529
530 return 0;
531}
532
533
534#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700535
Hai Shalomfdcde762020-04-02 11:19:20 -0700536#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700537static int has_wep_key(struct wpa_ssid *ssid)
538{
539 int i;
540
541 for (i = 0; i < NUM_WEP_KEYS; i++) {
542 if (ssid->wep_key_len[i])
543 return 1;
544 }
545
546 return 0;
547}
Hai Shalomfdcde762020-04-02 11:19:20 -0700548#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700549
550
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700551static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552 struct wpa_ssid *ssid)
553{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700554 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555
556 if (ssid->mixed_cell)
557 return 1;
558
559#ifdef CONFIG_WPS
560 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
561 return 1;
562#endif /* CONFIG_WPS */
563
Roshan Pius3a1667e2018-07-03 15:17:14 -0700564#ifdef CONFIG_OWE
565 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
566 return 1;
567#endif /* CONFIG_OWE */
568
Hai Shalomfdcde762020-04-02 11:19:20 -0700569#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700570 if (has_wep_key(ssid))
571 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700572#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700573
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574#ifdef IEEE8021X_EAPOL
575 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
576 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
577 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
578 privacy = 1;
579#endif /* IEEE8021X_EAPOL */
580
Jouni Malinen75ecf522011-06-27 15:19:46 -0700581 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
582 privacy = 1;
583
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800584 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
585 privacy = 1;
586
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700587 if (bss->caps & IEEE80211_CAP_PRIVACY)
588 return privacy;
589 return !privacy;
590}
591
592
593static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
594 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800595 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596{
597 struct wpa_ie_data ie;
598 int proto_match = 0;
599 const u8 *rsn_ie, *wpa_ie;
600 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700601#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700603#endif /* CONFIG_WEP */
Sunil Ravia04bd252022-05-02 22:54:18 -0700604 bool is_6ghz_bss = is_6ghz_freq(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605
606 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
607 if (ret >= 0)
608 return ret;
609
Hai Shalomfdcde762020-04-02 11:19:20 -0700610#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700611 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
612 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
613 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
614 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
615 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700616#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700617
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700618 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Sunil Ravia04bd252022-05-02 22:54:18 -0700619 if (is_6ghz_bss && !rsn_ie) {
620 if (debug_print)
621 wpa_dbg(wpa_s, MSG_DEBUG,
622 " skip - 6 GHz BSS without RSNE");
623 return 0;
624 }
625
Roshan Pius3a1667e2018-07-03 15:17:14 -0700626 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627 proto_match++;
628
629 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800630 if (debug_print)
631 wpa_dbg(wpa_s, MSG_DEBUG,
632 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633 break;
634 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700635 if (!ie.has_pairwise)
636 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
637 if (!ie.has_group)
638 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639
Sunil Ravia04bd252022-05-02 22:54:18 -0700640 if (is_6ghz_bss) {
641 /* WEP and TKIP are not allowed on 6 GHz */
642 ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
643 WPA_CIPHER_WEP104 |
644 WPA_CIPHER_TKIP);
645 ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
646 WPA_CIPHER_WEP104 |
647 WPA_CIPHER_TKIP);
648 }
649
Hai Shalomfdcde762020-04-02 11:19:20 -0700650#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700651 if (wep_ok &&
652 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
653 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800654 if (debug_print)
655 wpa_dbg(wpa_s, MSG_DEBUG,
656 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700657 return 1;
658 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700659#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700660
Roshan Pius3a1667e2018-07-03 15:17:14 -0700661 if (!(ie.proto & ssid->proto) &&
662 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800663 if (debug_print)
664 wpa_dbg(wpa_s, MSG_DEBUG,
665 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666 break;
667 }
668
669 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800670 if (debug_print)
671 wpa_dbg(wpa_s, MSG_DEBUG,
672 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673 break;
674 }
675
676 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800677 if (debug_print)
678 wpa_dbg(wpa_s, MSG_DEBUG,
679 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680 break;
681 }
682
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700683 if (ssid->group_mgmt_cipher &&
684 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
685 if (debug_print)
686 wpa_dbg(wpa_s, MSG_DEBUG,
687 " skip RSN IE - group mgmt cipher mismatch");
688 break;
689 }
690
Sunil Ravia04bd252022-05-02 22:54:18 -0700691 if (is_6ghz_bss) {
692 /* MFPC must be supported on 6 GHz */
693 if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
694 if (debug_print)
695 wpa_dbg(wpa_s, MSG_DEBUG,
696 " skip RSNE - 6 GHz without MFPC");
697 break;
698 }
699
700 /* WPA PSK is not allowed on the 6 GHz band */
701 ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
702 WPA_KEY_MGMT_FT_PSK |
703 WPA_KEY_MGMT_PSK_SHA256);
704 }
705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800707 if (debug_print)
708 wpa_dbg(wpa_s, MSG_DEBUG,
709 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710 break;
711 }
712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700713 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800714 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800715 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800716 if (debug_print)
717 wpa_dbg(wpa_s, MSG_DEBUG,
718 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719 break;
720 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800721 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
722 wpas_get_ssid_pmf(wpa_s, ssid) ==
723 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800724 if (debug_print)
725 wpa_dbg(wpa_s, MSG_DEBUG,
726 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800727 break;
728 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800730 if (debug_print)
731 wpa_dbg(wpa_s, MSG_DEBUG,
732 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 return 1;
734 }
735
Sunil Ravia04bd252022-05-02 22:54:18 -0700736 if (is_6ghz_bss) {
737 if (debug_print)
738 wpa_dbg(wpa_s, MSG_DEBUG,
739 " skip - 6 GHz BSS without matching RSNE");
740 return 0;
741 }
742
Roshan Pius3a1667e2018-07-03 15:17:14 -0700743 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
744 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800745 if (debug_print)
746 wpa_dbg(wpa_s, MSG_DEBUG,
747 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700748 return 0;
749 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700750
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700751 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
753 proto_match++;
754
755 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800756 if (debug_print)
757 wpa_dbg(wpa_s, MSG_DEBUG,
758 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759 break;
760 }
761
Hai Shalomfdcde762020-04-02 11:19:20 -0700762#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 if (wep_ok &&
764 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
765 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800766 if (debug_print)
767 wpa_dbg(wpa_s, MSG_DEBUG,
768 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 return 1;
770 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700771#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700772
773 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800774 if (debug_print)
775 wpa_dbg(wpa_s, MSG_DEBUG,
776 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700777 break;
778 }
779
780 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800781 if (debug_print)
782 wpa_dbg(wpa_s, MSG_DEBUG,
783 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784 break;
785 }
786
787 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800788 if (debug_print)
789 wpa_dbg(wpa_s, MSG_DEBUG,
790 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700791 break;
792 }
793
794 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800795 if (debug_print)
796 wpa_dbg(wpa_s, MSG_DEBUG,
797 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798 break;
799 }
800
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800801 if (debug_print)
802 wpa_dbg(wpa_s, MSG_DEBUG,
803 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 return 1;
805 }
806
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700807 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
808 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800809 if (debug_print)
810 wpa_dbg(wpa_s, MSG_DEBUG,
811 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700812 return 1;
813 }
814
Roshan Pius3a1667e2018-07-03 15:17:14 -0700815#ifdef CONFIG_OWE
816 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
817 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800818 if (wpa_s->owe_transition_select &&
819 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
820 ssid->owe_transition_bss_select_count + 1 <=
821 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
822 ssid->owe_transition_bss_select_count++;
823 if (debug_print)
824 wpa_dbg(wpa_s, MSG_DEBUG,
825 " skip OWE transition BSS (selection count %d does not exceed %d)",
826 ssid->owe_transition_bss_select_count,
827 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
828 wpa_s->owe_transition_search = 1;
829 return 0;
830 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700831 if (debug_print)
832 wpa_dbg(wpa_s, MSG_DEBUG,
833 " allow in OWE transition mode");
834 return 1;
835 }
836#endif /* CONFIG_OWE */
837
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
839 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800840 if (debug_print)
841 wpa_dbg(wpa_s, MSG_DEBUG,
842 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843 return 0;
844 }
845
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800846 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
847 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800848 if (debug_print)
849 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800850 return 1;
851 }
852
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700853 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800854 if (debug_print)
855 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856 return 1;
857 }
858
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800859 if (debug_print)
860 wpa_dbg(wpa_s, MSG_DEBUG,
861 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862
863 return 0;
864}
865
866
867static int freq_allowed(int *freqs, int freq)
868{
869 int i;
870
871 if (freqs == NULL)
872 return 1;
873
874 for (i = 0; freqs[i]; i++)
875 if (freqs[i] == freq)
876 return 1;
877 return 0;
878}
879
880
Hai Shalomfdcde762020-04-02 11:19:20 -0700881static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
882 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800883{
884 const struct hostapd_hw_modes *mode = NULL, *modes;
885 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
886 const u8 *rate_ie;
887 int i, j, k;
888
889 if (bss->freq == 0)
890 return 1; /* Cannot do matching without knowing band */
891
892 modes = wpa_s->hw.modes;
893 if (modes == NULL) {
894 /*
895 * The driver does not provide any additional information
896 * about the utilized hardware, so allow the connection attempt
897 * to continue.
898 */
899 return 1;
900 }
901
902 for (i = 0; i < wpa_s->hw.num_modes; i++) {
903 for (j = 0; j < modes[i].num_channels; j++) {
904 int freq = modes[i].channels[j].freq;
905 if (freq == bss->freq) {
906 if (mode &&
907 mode->mode == HOSTAPD_MODE_IEEE80211G)
908 break; /* do not allow 802.11b replace
909 * 802.11g */
910 mode = &modes[i];
911 break;
912 }
913 }
914 }
915
916 if (mode == NULL)
917 return 0;
918
919 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700920 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800921 if (rate_ie == NULL)
922 continue;
923
924 for (j = 2; j < rate_ie[1] + 2; j++) {
925 int flagged = !!(rate_ie[j] & 0x80);
926 int r = (rate_ie[j] & 0x7f) * 5;
927
928 /*
929 * IEEE Std 802.11n-2009 7.3.2.2:
930 * The new BSS Membership selector value is encoded
931 * like a legacy basic rate, but it is not a rate and
932 * only indicates if the BSS members are required to
933 * support the mandatory features of Clause 20 [HT PHY]
934 * in order to join the BSS.
935 */
936 if (flagged && ((rate_ie[j] & 0x7f) ==
937 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
938 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800939 if (debug_print)
940 wpa_dbg(wpa_s, MSG_DEBUG,
941 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800942 return 0;
943 }
944 continue;
945 }
946
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700947 /* There's also a VHT selector for 802.11ac */
948 if (flagged && ((rate_ie[j] & 0x7f) ==
949 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
950 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800951 if (debug_print)
952 wpa_dbg(wpa_s, MSG_DEBUG,
953 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700954 return 0;
955 }
956 continue;
957 }
958
Hai Shalomc3565922019-10-28 11:58:20 -0700959#ifdef CONFIG_SAE
960 if (flagged && ((rate_ie[j] & 0x7f) ==
961 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700962 if (wpa_s->conf->sae_pwe == 0 &&
963 !ssid->sae_password_id &&
964 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700965 if (debug_print)
966 wpa_dbg(wpa_s, MSG_DEBUG,
967 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800968#ifdef CONFIG_TESTING_OPTIONS
969 if (wpa_s->ignore_sae_h2e_only) {
970 wpa_dbg(wpa_s, MSG_DEBUG,
971 "TESTING: Ignore SAE H2E requirement mismatch");
972 continue;
973 }
974#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700975 return 0;
976 }
977 continue;
978 }
979#endif /* CONFIG_SAE */
980
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800981 if (!flagged)
982 continue;
983
984 /* check for legacy basic rates */
985 for (k = 0; k < mode->num_rates; k++) {
986 if (mode->rates[k] == r)
987 break;
988 }
989 if (k == mode->num_rates) {
990 /*
991 * IEEE Std 802.11-2007 7.3.2.2 demands that in
992 * order to join a BSS all required rates
993 * have to be supported by the hardware.
994 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800995 if (debug_print)
996 wpa_dbg(wpa_s, MSG_DEBUG,
997 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
998 r / 10, r % 10,
999 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001000 return 0;
1001 }
1002 }
1003 }
1004
1005 return 1;
1006}
1007
1008
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001009/*
1010 * Test whether BSS is in an ESS.
1011 * This is done differently in DMG (60 GHz) and non-DMG bands
1012 */
1013static int bss_is_ess(struct wpa_bss *bss)
1014{
1015 if (bss_is_dmg(bss)) {
1016 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1017 IEEE80211_CAP_DMG_AP;
1018 }
1019
1020 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1021 IEEE80211_CAP_ESS);
1022}
1023
1024
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001025static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1026{
1027 size_t i;
1028
1029 for (i = 0; i < ETH_ALEN; i++) {
1030 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1031 return 0;
1032 }
1033 return 1;
1034}
1035
1036
1037static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1038{
1039 size_t i;
1040
1041 for (i = 0; i < num; i++) {
1042 const u8 *a = list + i * ETH_ALEN * 2;
1043 const u8 *m = a + ETH_ALEN;
1044
1045 if (match_mac_mask(a, addr, m))
1046 return 1;
1047 }
1048 return 0;
1049}
1050
1051
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001052static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1053 const u8 **ret_ssid, size_t *ret_ssid_len)
1054{
1055#ifdef CONFIG_OWE
1056 const u8 *owe, *pos, *end, *bssid;
1057 u8 ssid_len;
1058 struct wpa_bss *open_bss;
1059
1060 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1061 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
1062 return;
1063
1064 pos = owe + 6;
1065 end = owe + 2 + owe[1];
1066
1067 if (end - pos < ETH_ALEN + 1)
1068 return;
1069 bssid = pos;
1070 pos += ETH_ALEN;
1071 ssid_len = *pos++;
1072 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1073 return;
1074
1075 /* Match the profile SSID against the OWE transition mode SSID on the
1076 * open network. */
1077 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1078 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1079 *ret_ssid = pos;
1080 *ret_ssid_len = ssid_len;
1081
Hai Shalomfdcde762020-04-02 11:19:20 -07001082 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1083 struct wpa_ssid *ssid;
1084
1085 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1086 if (wpas_network_disabled(wpa_s, ssid))
1087 continue;
1088 if (ssid->ssid_len == ssid_len &&
1089 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1090 /* OWE BSS in transition mode for a currently
1091 * enabled OWE network. */
1092 wpa_dbg(wpa_s, MSG_DEBUG,
1093 "OWE: transition mode OWE SSID for active OWE profile");
1094 bss->flags |= WPA_BSS_OWE_TRANSITION;
1095 break;
1096 }
1097 }
1098 }
1099
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001100 if (bss->ssid_len > 0)
1101 return;
1102
1103 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1104 if (!open_bss)
1105 return;
1106 if (ssid_len != open_bss->ssid_len ||
1107 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1108 wpa_dbg(wpa_s, MSG_DEBUG,
1109 "OWE: transition mode SSID mismatch: %s",
1110 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1111 return;
1112 }
1113
1114 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1115 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1116 wpa_dbg(wpa_s, MSG_DEBUG,
1117 "OWE: transition mode open BSS unexpected info");
1118 return;
1119 }
1120
1121 pos = owe + 6;
1122 end = owe + 2 + owe[1];
1123
1124 if (end - pos < ETH_ALEN + 1)
1125 return;
1126 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1127 wpa_dbg(wpa_s, MSG_DEBUG,
1128 "OWE: transition mode BSSID mismatch: " MACSTR,
1129 MAC2STR(pos));
1130 return;
1131 }
1132 pos += ETH_ALEN;
1133 ssid_len = *pos++;
1134 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1135 return;
1136 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1137 wpa_ssid_txt(pos, ssid_len));
1138 os_memcpy(bss->ssid, pos, ssid_len);
1139 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001140 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001141#endif /* CONFIG_OWE */
1142}
1143
1144
Sunil Ravi26978f32021-04-30 15:19:18 -07001145int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001146{
1147 int i, j;
1148
1149 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1150 return 0;
1151
1152 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1153 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1154
1155 for (i = 0; i < mode->num_channels; i++) {
1156 struct hostapd_channel_data *chan = &mode->channels[i];
1157
1158 if (chan->freq == freq)
1159 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1160 }
1161 }
1162
1163 return 1;
1164}
1165
1166
Hai Shalom899fcc72020-10-19 14:38:18 -07001167static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1168 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001169 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001170 bool debug_print);
1171
1172
1173#ifdef CONFIG_SAE_PK
1174static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1175 struct wpa_bss *orig_bss,
1176 struct wpa_ssid *ssid,
1177 const u8 *match_ssid,
1178 size_t match_ssid_len)
1179{
1180 struct wpa_bss *bss;
1181
1182 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1183 int count;
1184 const u8 *ie;
Hai Shalom899fcc72020-10-19 14:38:18 -07001185
1186 if (bss == orig_bss)
1187 continue;
1188 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shalomc1a21442022-02-04 13:43:00 -08001189 if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
Hai Shalom899fcc72020-10-19 14:38:18 -07001190 continue;
1191
1192 /* TODO: Could be more thorough in checking what kind of
1193 * signal strength or throughput estimate would be acceptable
1194 * compared to the originally selected BSS. */
1195 if (bss->est_throughput < 2000)
1196 return false;
1197
Hai Shalom60840252021-02-19 19:02:11 -08001198 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001199 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1200 bss, count, 0))
1201 return true;
1202 }
1203
1204 return false;
1205}
1206#endif /* CONFIG_SAE_PK */
1207
1208
1209static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1210 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001211 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001212 bool debug_print)
1213{
1214 int res;
1215 bool wpa, check_ssid, osen, rsn_osen = false;
1216 struct wpa_ie_data data;
1217#ifdef CONFIG_MBO
1218 const u8 *assoc_disallow;
1219#endif /* CONFIG_MBO */
1220#ifdef CONFIG_SAE
1221 u8 rsnxe_capa = 0;
1222#endif /* CONFIG_SAE */
1223 const u8 *ie;
1224
1225 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1226 wpa = ie && ie[1];
1227 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1228 wpa |= ie && ie[1];
1229 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1230 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1231 rsn_osen = true;
1232 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1233 osen = ie != NULL;
1234
1235#ifdef CONFIG_SAE
1236 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1237 if (ie && ie[1] >= 1)
1238 rsnxe_capa = ie[2];
1239#endif /* CONFIG_SAE */
1240
1241 check_ssid = wpa || ssid->ssid_len > 0;
1242
1243 if (wpas_network_disabled(wpa_s, ssid)) {
1244 if (debug_print)
1245 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1246 return false;
1247 }
1248
1249 res = wpas_temp_disabled(wpa_s, ssid);
1250 if (res > 0) {
1251 if (debug_print)
1252 wpa_dbg(wpa_s, MSG_DEBUG,
1253 " skip - disabled temporarily for %d second(s)",
1254 res);
1255 return false;
1256 }
1257
1258#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001259 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001260 if (debug_print)
1261 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001262 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001263 return false;
1264 }
1265
1266 if (wpa && ssid->ssid_len == 0 &&
1267 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1268 check_ssid = false;
1269
1270 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1271 /* Only allow wildcard SSID match if an AP advertises active
1272 * WPS operation that matches our mode. */
1273 check_ssid = ssid->ssid_len > 0 ||
1274 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1275 }
1276#endif /* CONFIG_WPS */
1277
1278 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1279 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1280 check_ssid = false;
1281
1282 if (check_ssid &&
1283 (match_ssid_len != ssid->ssid_len ||
1284 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1285 if (debug_print)
1286 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1287 return false;
1288 }
1289
1290 if (ssid->bssid_set &&
1291 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1292 if (debug_print)
1293 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1294 return false;
1295 }
1296
Hai Shalom60840252021-02-19 19:02:11 -08001297 /* check the list of BSSIDs to ignore */
1298 if (ssid->num_bssid_ignore &&
1299 addr_in_list(bss->bssid, ssid->bssid_ignore,
1300 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001301 if (debug_print)
1302 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001303 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001304 return false;
1305 }
1306
Hai Shalom60840252021-02-19 19:02:11 -08001307 /* if there is a list of accepted BSSIDs, only accept those APs */
1308 if (ssid->num_bssid_accept &&
1309 !addr_in_list(bss->bssid, ssid->bssid_accept,
1310 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001311 if (debug_print)
1312 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001313 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001314 return false;
1315 }
1316
1317 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1318 return false;
1319
1320 if (!osen && !wpa &&
1321 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1322 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1323 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1324 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1325 if (debug_print)
1326 wpa_dbg(wpa_s, MSG_DEBUG,
1327 " skip - non-WPA network not allowed");
1328 return false;
1329 }
1330
1331#ifdef CONFIG_WEP
1332 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1333 if (debug_print)
1334 wpa_dbg(wpa_s, MSG_DEBUG,
1335 " skip - ignore WPA/WPA2 AP for WEP network block");
1336 return false;
1337 }
1338#endif /* CONFIG_WEP */
1339
1340 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1341 if (debug_print)
1342 wpa_dbg(wpa_s, MSG_DEBUG,
1343 " skip - non-OSEN network not allowed");
1344 return false;
1345 }
1346
1347 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1348 if (debug_print)
1349 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1350 return false;
1351 }
1352
1353 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1354 !bss_is_pbss(bss)) {
1355 if (debug_print)
1356 wpa_dbg(wpa_s, MSG_DEBUG,
1357 " skip - not ESS, PBSS, or MBSS");
1358 return false;
1359 }
1360
1361 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1362 if (debug_print)
1363 wpa_dbg(wpa_s, MSG_DEBUG,
1364 " skip - PBSS mismatch (ssid %d bss %d)",
1365 ssid->pbss, bss_is_pbss(bss));
1366 return false;
1367 }
1368
1369 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1370 if (debug_print)
1371 wpa_dbg(wpa_s, MSG_DEBUG,
1372 " skip - frequency not allowed");
1373 return false;
1374 }
1375
1376#ifdef CONFIG_MESH
1377 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1378 ssid->frequency != bss->freq) {
1379 if (debug_print)
1380 wpa_dbg(wpa_s, MSG_DEBUG,
1381 " skip - frequency not allowed (mesh)");
1382 return false;
1383 }
1384#endif /* CONFIG_MESH */
1385
1386 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1387 if (debug_print)
1388 wpa_dbg(wpa_s, MSG_DEBUG,
1389 " skip - rate sets do not match");
1390 return false;
1391 }
1392
1393#ifdef CONFIG_SAE
Sunil Ravia04bd252022-05-02 22:54:18 -07001394 /* When using SAE Password Identifier and when operationg on the 6 GHz
1395 * band, only H2E is allowed. */
1396 if ((wpa_s->conf->sae_pwe == 1 || is_6ghz_freq(bss->freq) ||
1397 ssid->sae_password_id) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001398 wpa_s->conf->sae_pwe != 3 && wpa_key_mgmt_sae(ssid->key_mgmt) &&
Vinayak Yadawad14709082022-03-17 14:25:11 +05301399#ifdef CONFIG_DRIVER_NL80211_BRCM
1400 !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) &&
1401#endif /* CONFIG_DRIVER_NL80211_BRCM */
Hai Shalom899fcc72020-10-19 14:38:18 -07001402 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1403 if (debug_print)
1404 wpa_dbg(wpa_s, MSG_DEBUG,
1405 " skip - SAE H2E required, but not supported by the AP");
1406 return false;
1407 }
1408#endif /* CONFIG_SAE */
1409
1410#ifdef CONFIG_SAE_PK
1411 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1412 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1413 if (debug_print)
1414 wpa_dbg(wpa_s, MSG_DEBUG,
1415 " skip - SAE-PK required, but not supported by the AP");
1416 return false;
1417 }
1418#endif /* CONFIG_SAE_PK */
1419
1420#ifndef CONFIG_IBSS_RSN
1421 if (ssid->mode == WPAS_MODE_IBSS &&
1422 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1423 if (debug_print)
1424 wpa_dbg(wpa_s, MSG_DEBUG,
1425 " skip - IBSS RSN not supported in the build");
1426 return false;
1427 }
1428#endif /* !CONFIG_IBSS_RSN */
1429
1430#ifdef CONFIG_P2P
1431 if (ssid->p2p_group &&
1432 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1433 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1434 if (debug_print)
1435 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1436 return false;
1437 }
1438
1439 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1440 struct wpabuf *p2p_ie;
1441 u8 dev_addr[ETH_ALEN];
1442
1443 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1444 if (!ie) {
1445 if (debug_print)
1446 wpa_dbg(wpa_s, MSG_DEBUG,
1447 " skip - no P2P element");
1448 return false;
1449 }
1450 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1451 if (!p2p_ie) {
1452 if (debug_print)
1453 wpa_dbg(wpa_s, MSG_DEBUG,
1454 " skip - could not fetch P2P element");
1455 return false;
1456 }
1457
1458 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1459 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1460 if (debug_print)
1461 wpa_dbg(wpa_s, MSG_DEBUG,
1462 " skip - no matching GO P2P Device Address in P2P element");
1463 wpabuf_free(p2p_ie);
1464 return false;
1465 }
1466 wpabuf_free(p2p_ie);
1467 }
1468
1469 /*
1470 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1471 * P2P Group Capability Bitmap and we are not in Group Formation with
1472 * that device.
1473 */
1474#endif /* CONFIG_P2P */
1475
1476 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1477 struct os_reltime diff;
1478
1479 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1480 if (debug_print)
1481 wpa_dbg(wpa_s, MSG_DEBUG,
1482 " skip - scan result not recent enough (%u.%06u seconds too old)",
1483 (unsigned int) diff.sec,
1484 (unsigned int) diff.usec);
1485 return false;
1486 }
1487#ifdef CONFIG_MBO
1488#ifdef CONFIG_TESTING_OPTIONS
1489 if (wpa_s->ignore_assoc_disallow)
1490 goto skip_assoc_disallow;
1491#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001492 assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
Hai Shalom899fcc72020-10-19 14:38:18 -07001493 if (assoc_disallow && assoc_disallow[1] >= 1) {
1494 if (debug_print)
1495 wpa_dbg(wpa_s, MSG_DEBUG,
1496 " skip - MBO association disallowed (reason %u)",
1497 assoc_disallow[2]);
1498 return false;
1499 }
1500
1501 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1502 if (debug_print)
1503 wpa_dbg(wpa_s, MSG_DEBUG,
1504 " skip - AP temporarily disallowed");
1505 return false;
1506 }
1507#ifdef CONFIG_TESTING_OPTIONS
1508skip_assoc_disallow:
1509#endif /* CONFIG_TESTING_OPTIONS */
1510#endif /* CONFIG_MBO */
1511
1512#ifdef CONFIG_DPP
1513 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1514 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1515 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1516 !ssid->dpp_csign)) {
1517 if (debug_print)
1518 wpa_dbg(wpa_s, MSG_DEBUG,
1519 " skip - no PMKSA entry for DPP");
1520 return false;
1521 }
1522#endif /* CONFIG_DPP */
1523
1524#ifdef CONFIG_SAE_PK
1525 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1526 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1527 ((ssid->sae_password &&
1528 sae_pk_valid_password(ssid->sae_password)) ||
1529 (!ssid->sae_password && ssid->passphrase &&
1530 sae_pk_valid_password(ssid->passphrase))) &&
1531 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1532 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1533 match_ssid_len)) {
1534 if (debug_print)
1535 wpa_dbg(wpa_s, MSG_DEBUG,
1536 " skip - another acceptable BSS with SAE-PK in the same ESS");
1537 return false;
1538 }
1539#endif /* CONFIG_SAE_PK */
1540
1541 if (bss->ssid_len == 0) {
1542 if (debug_print)
1543 wpa_dbg(wpa_s, MSG_DEBUG,
1544 " skip - no SSID known for the BSS");
1545 return false;
1546 }
1547
1548 /* Matching configuration found */
1549 return true;
1550}
1551
1552
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001553struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1554 int i, struct wpa_bss *bss,
1555 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001556 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001557{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001558 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001559 const u8 *ie;
1560 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001561 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001562 const u8 *match_ssid;
1563 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001564 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001566 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001567 wpa_ie_len = ie ? ie[1] : 0;
1568
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001569 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001570 rsn_ie_len = ie ? ie[1] : 0;
1571
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001572 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1573 osen = ie != NULL;
1574
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001575 if (debug_print) {
1576 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1577 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1578 i, MAC2STR(bss->bssid),
1579 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1580 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1581 bss->freq,
1582 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1583 " wps" : "",
1584 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1585 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1586 ? " p2p" : "",
1587 osen ? " osen=1" : "");
1588 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001589
Hai Shalom60840252021-02-19 19:02:11 -08001590 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1591 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001592 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001593 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001594 /*
1595 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001596 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001597 * should not be done with multiple enabled networks to
1598 * avoid getting forced to move into a worse ESS on
1599 * single error if there are no other BSSes of the
1600 * current ESS.
1601 */
1602 limit = 0;
1603 }
Hai Shalom60840252021-02-19 19:02:11 -08001604 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001605 if (debug_print) {
1606 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001607 " skip - BSSID ignored (count=%d limit=%d)",
1608 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001609 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001610 return NULL;
1611 }
1612 }
1613
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001614 match_ssid = bss->ssid;
1615 match_ssid_len = bss->ssid_len;
1616 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1617
1618 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001619 if (debug_print)
1620 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621 return NULL;
1622 }
1623
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001624 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001625 if (debug_print)
1626 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001627 return NULL;
1628 }
1629
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001630 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001631 if (debug_print)
1632 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001633 return NULL;
1634 }
1635
Hai Shalomfdcde762020-04-02 11:19:20 -07001636 if (disabled_freq(wpa_s, bss->freq)) {
1637 if (debug_print)
1638 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1639 return NULL;
1640 }
1641
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001642 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001643 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001644 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001645 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001646 }
1647
1648 /* No matching configuration found */
1649 return NULL;
1650}
1651
1652
1653static struct wpa_bss *
1654wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001656 struct wpa_ssid **selected_ssid,
1657 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001658{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001659 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001661 if (wpa_s->current_ssid) {
1662 struct wpa_ssid *ssid;
1663
1664 wpa_dbg(wpa_s, MSG_DEBUG,
1665 "Scan results matching the currently selected network");
1666 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1667 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1668
1669 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1670 only_first_ssid, 0);
1671 if (ssid != wpa_s->current_ssid)
1672 continue;
1673 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1674 " freq=%d level=%d snr=%d est_throughput=%u",
1675 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1676 bss->snr, bss->est_throughput);
1677 }
1678 }
1679
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001680 if (only_first_ssid)
1681 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1682 group->id);
1683 else
1684 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1685 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001686
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001687 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1688 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001689
1690 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001691 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001692 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001693 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001694 if (!*selected_ssid)
1695 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001696 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001698 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001699 MAC2STR(bss->bssid),
1700 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1701 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001702 }
1703
1704 return NULL;
1705}
1706
1707
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001708struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1709 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001710{
1711 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001712 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001713 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001714 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001716 if (wpa_s->last_scan_res == NULL ||
1717 wpa_s->last_scan_res_used == 0)
1718 return NULL; /* no scan results from last update */
1719
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001720 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001721 /* check that next_ssid is still valid */
1722 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1723 if (ssid == wpa_s->next_ssid)
1724 break;
1725 }
1726 next_ssid = ssid;
1727 wpa_s->next_ssid = NULL;
1728 }
1729
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001730 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001731 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1732 if (next_ssid && next_ssid->priority ==
1733 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001734 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001735 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001736 if (selected)
1737 break;
1738 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001739 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001740 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001741 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001742 if (selected)
1743 break;
1744 }
1745
Hai Shalom60840252021-02-19 19:02:11 -08001746 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001747 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001748 wpa_dbg(wpa_s, MSG_DEBUG,
1749 "No APs found - clear BSSID ignore list and try again");
1750 wpa_bssid_ignore_clear(wpa_s);
1751 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001752 } else if (selected == NULL)
1753 break;
1754 }
1755
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001756 ssid = *selected_ssid;
1757 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1758 !ssid->passphrase && !ssid->ext_psk) {
1759 const char *field_name, *txt = NULL;
1760
1761 wpa_dbg(wpa_s, MSG_DEBUG,
1762 "PSK/passphrase not yet available for the selected network");
1763
1764 wpas_notify_network_request(wpa_s, ssid,
1765 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1766
1767 field_name = wpa_supplicant_ctrl_req_to_string(
1768 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1769 if (field_name == NULL)
1770 return NULL;
1771
1772 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1773
1774 selected = NULL;
1775 }
1776
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777 return selected;
1778}
1779
1780
1781static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1782 int timeout_sec, int timeout_usec)
1783{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001784 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001785 /*
1786 * No networks are enabled; short-circuit request so
1787 * we don't wait timeout seconds before transitioning
1788 * to INACTIVE state.
1789 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001790 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1791 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001792 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1793 return;
1794 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001795
1796 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1798}
1799
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001800
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001801int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001802 struct wpa_bss *selected,
1803 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001804{
1805 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1806 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1807 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001808 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001809#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001810 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1811 wpa_s->p2p_in_provisioning) {
1812 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1813 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001814 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001815 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001816#endif /* CONFIG_P2P */
1817
1818#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001819 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 wpas_wps_cancel(wpa_s);
1821#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001822 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823 }
1824
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001825 wpa_msg(wpa_s, MSG_DEBUG,
1826 "Considering connect request: reassociate: %d selected: "
1827 MACSTR " bssid: " MACSTR " pending: " MACSTR
1828 " wpa_state: %s ssid=%p current_ssid=%p",
1829 wpa_s->reassociate, MAC2STR(selected->bssid),
1830 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1831 wpa_supplicant_state_txt(wpa_s->wpa_state),
1832 ssid, wpa_s->current_ssid);
1833
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834 /*
1835 * Do not trigger new association unless the BSSID has changed or if
1836 * reassociation is requested. If we are in process of associating with
1837 * the selected BSSID, do not trigger new attempt.
1838 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001839 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001840 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1841 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1842 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001843 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1844 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1845 0) ||
1846 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1847 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001848 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1849 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001850 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001851 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001852 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1853 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001854 wpa_supplicant_associate(wpa_s, selected, ssid);
1855 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001856 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1857 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001859
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001860 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001861}
1862
1863
1864static struct wpa_ssid *
1865wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1866{
Hai Shalomfdcde762020-04-02 11:19:20 -07001867 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001868 struct wpa_ssid *ssid;
1869
1870 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1871 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1872 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001873 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001875#ifndef CONFIG_IBSS_RSN
1876 if (ssid->mode == WPAS_MODE_IBSS &&
1877 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1878 WPA_KEY_MGMT_WPA_NONE))) {
1879 wpa_msg(wpa_s, MSG_INFO,
1880 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1881 wpa_ssid_txt(ssid->ssid,
1882 ssid->ssid_len));
1883 continue;
1884 }
1885#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001886 if (ssid->mode == WPAS_MODE_IBSS ||
1887 ssid->mode == WPAS_MODE_AP ||
1888 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001889 return ssid;
1890 }
1891 }
1892 return NULL;
1893}
1894
1895
1896/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1897 * on BSS added and BSS changed events */
1898static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001899 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001900{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001901 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001902
1903 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1904 return;
1905
Jouni Malinen87fd2792011-05-16 18:35:42 +03001906 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001907 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001908
Jouni Malinen87fd2792011-05-16 18:35:42 +03001909 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001910 if (ssid == NULL)
1911 continue;
1912
Jouni Malinen87fd2792011-05-16 18:35:42 +03001913 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001914 if (rsn == NULL)
1915 continue;
1916
Jouni Malinen87fd2792011-05-16 18:35:42 +03001917 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001918 }
1919
1920}
1921
1922
Hai Shalomfdcde762020-04-02 11:19:20 -07001923#ifndef CONFIG_NO_ROAMING
1924
1925static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1926{
1927 if (noise == WPA_INVALID_NOISE)
1928 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1929 DEFAULT_NOISE_FLOOR_2GHZ;
1930 return avg_signal - noise;
1931}
1932
1933
1934static unsigned int
1935wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1936 const struct wpa_bss *bss, int snr)
1937{
1938 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001939 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001940 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1941
Hai Shalomc1a21442022-02-04 13:43:00 -08001942 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq);
Hai Shalomfdcde762020-04-02 11:19:20 -07001943}
1944
Hai Shalomfdcde762020-04-02 11:19:20 -07001945
Hai Shalom899fcc72020-10-19 14:38:18 -07001946int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1947 struct wpa_bss *current_bss,
1948 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001949{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001950 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001951 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001952 int cur_level;
1953 unsigned int cur_est, sel_est;
1954 struct wpa_signal_info si;
1955 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001956 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001957
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001958 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001959 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001960 " freq=%d level=%d snr=%d est_throughput=%u",
1961 MAC2STR(current_bss->bssid),
1962 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001963 current_bss->snr, current_bss->est_throughput);
1964 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001965 " freq=%d level=%d snr=%d est_throughput=%u",
1966 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001967 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001968
1969 if (wpa_s->current_ssid->bssid_set &&
1970 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1971 0) {
1972 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1973 "has preferred BSSID");
1974 return 1;
1975 }
1976
Hai Shalomfdcde762020-04-02 11:19:20 -07001977 cur_level = current_bss->level;
1978 cur_est = current_bss->est_throughput;
1979 sel_est = selected->est_throughput;
1980
1981 /*
1982 * Try to poll the signal from the driver since this will allow to get
1983 * more accurate values. In some cases, there can be big differences
1984 * between the RSSI of the Probe Response frames of the AP we are
1985 * associated with and the Beacon frames we hear from the same AP after
1986 * association. This can happen, e.g., when there are two antennas that
1987 * hear the AP very differently. If the driver chooses to hear the
1988 * Probe Response frames during the scan on the "bad" antenna because
1989 * it wants to save power, but knows to choose the other antenna after
1990 * association, we will hear our AP with a low RSSI as part of the
1991 * scan even when we can hear it decently on the other antenna. To cope
1992 * with this, ask the driver to teach us how it hears the AP. Also, the
1993 * scan results may be a bit old, since we can very quickly get fresh
1994 * information about our currently associated AP.
1995 */
1996 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1997 (si.avg_beacon_signal || si.avg_signal)) {
1998 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1999 si.avg_signal;
2000 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2001 si.current_noise);
2002
2003 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2004 current_bss,
2005 cur_snr);
2006 wpa_dbg(wpa_s, MSG_DEBUG,
2007 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2008 cur_level, cur_snr, cur_est);
2009 }
2010
2011 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002012 wpa_dbg(wpa_s, MSG_DEBUG,
2013 "Allow reassociation - selected BSS has better estimated throughput");
2014 return 1;
2015 }
2016
Dmitry Shmidte4663042016-04-04 10:07:49 -07002017 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
2018
Hai Shalomfdcde762020-04-02 11:19:20 -07002019 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
2020 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002021 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2022 "signal level");
2023 return 0;
2024 }
2025
Hai Shalomfdcde762020-04-02 11:19:20 -07002026 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002027 wpa_dbg(wpa_s, MSG_DEBUG,
2028 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002029 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002030 }
2031
Hai Shalomfdcde762020-04-02 11:19:20 -07002032 if (cur_snr > GREAT_SNR) {
2033 wpa_dbg(wpa_s, MSG_DEBUG,
2034 "Skip roam - Current BSS has good SNR (%u > %u)",
2035 cur_snr, GREAT_SNR);
2036 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002037 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002038
Hai Shalomfdcde762020-04-02 11:19:20 -07002039 if (cur_level < -85) /* ..-86 dBm */
2040 min_diff = 1;
2041 else if (cur_level < -80) /* -85..-81 dBm */
2042 min_diff = 2;
2043 else if (cur_level < -75) /* -80..-76 dBm */
2044 min_diff = 3;
2045 else if (cur_level < -70) /* -75..-71 dBm */
2046 min_diff = 4;
2047 else if (cur_level < 0) /* -70..-1 dBm */
2048 min_diff = 5;
2049 else /* unspecified units (not in dBm) */
2050 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002051
Hai Shalomfdcde762020-04-02 11:19:20 -07002052 if (cur_est > sel_est * 1.5)
2053 min_diff += 10;
2054 else if (cur_est > sel_est * 1.2)
2055 min_diff += 5;
2056 else if (cur_est > sel_est * 1.1)
2057 min_diff += 2;
2058 else if (cur_est > sel_est)
2059 min_diff++;
2060 else if (sel_est > cur_est * 1.5)
2061 min_diff -= 10;
2062 else if (sel_est > cur_est * 1.2)
2063 min_diff -= 5;
2064 else if (sel_est > cur_est * 1.1)
2065 min_diff -= 2;
2066 else if (sel_est > cur_est)
2067 min_diff--;
2068
2069 if (to_5ghz)
2070 min_diff -= 2;
2071 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002072 if (diff < min_diff) {
2073 wpa_dbg(wpa_s, MSG_DEBUG,
2074 "Skip roam - too small difference in signal level (%d < %d)",
2075 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07002076 ret = 0;
2077 } else {
2078 wpa_dbg(wpa_s, MSG_DEBUG,
2079 "Allow reassociation due to difference in signal level (%d >= %d)",
2080 diff, min_diff);
2081 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002083 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2084 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2085 " sel_freq=%d sel_level=%d sel_est=%d",
2086 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2087 MAC2STR(current_bss->bssid),
2088 current_bss->freq, cur_level, cur_est,
2089 MAC2STR(selected->bssid),
2090 selected->freq, selected->level, sel_est);
2091 return ret;
2092}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002093
Hai Shalom899fcc72020-10-19 14:38:18 -07002094#endif /* CONFIG_NO_ROAMING */
2095
2096
2097static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2098 struct wpa_bss *selected,
2099 struct wpa_ssid *ssid)
2100{
2101 struct wpa_bss *current_bss = NULL;
2102
2103 if (wpa_s->reassociate)
2104 return 1; /* explicit request to reassociate */
2105 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2106 return 1; /* we are not associated; continue */
2107 if (wpa_s->current_ssid == NULL)
2108 return 1; /* unknown current SSID */
2109 if (wpa_s->current_ssid != ssid)
2110 return 1; /* different network block */
2111
2112 if (wpas_driver_bss_selection(wpa_s))
2113 return 0; /* Driver-based roaming */
2114
2115 if (wpa_s->current_ssid->ssid)
2116 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2117 wpa_s->current_ssid->ssid,
2118 wpa_s->current_ssid->ssid_len);
2119 if (!current_bss)
2120 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2121
2122 if (!current_bss)
2123 return 1; /* current BSS not seen in scan results */
2124
2125 if (current_bss == selected)
2126 return 0;
2127
2128 if (selected->last_update_idx > current_bss->last_update_idx)
2129 return 1; /* current BSS not seen in the last scan */
2130
2131#ifndef CONFIG_NO_ROAMING
2132 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2133 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002134#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002135 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002136#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002137}
2138
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002139
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002140/*
2141 * Return a negative value if no scan results could be fetched or if scan
2142 * results should not be shared with other virtual interfaces.
2143 * Return 0 if scan results were fetched and may be shared with other
2144 * interfaces.
2145 * Return 1 if scan results may be shared with other virtual interfaces but may
2146 * not trigger any operations.
2147 * Return 2 if the interface was removed and cannot be used.
2148 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002149static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002150 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002151 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002152{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002153 struct wpa_scan_results *scan_res = NULL;
2154 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002156#ifndef CONFIG_NO_RANDOM_POOL
2157 size_t i, num;
2158#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002159
2160#ifdef CONFIG_AP
2161 if (wpa_s->ap_iface)
2162 ap = 1;
2163#endif /* CONFIG_AP */
2164
2165 wpa_supplicant_notify_scanning(wpa_s, 0);
2166
2167 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2168 data ? &data->scan_info :
2169 NULL, 1);
2170 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002171 if (wpa_s->conf->ap_scan == 2 || ap ||
2172 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002173 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002174 if (!own_request)
2175 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002176 if (data && data->scan_info.external_scan)
2177 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002178 if (wpa_s->scan_res_fail_handler) {
2179 void (*handler)(struct wpa_supplicant *wpa_s);
2180
2181 handler = wpa_s->scan_res_fail_handler;
2182 wpa_s->scan_res_fail_handler = NULL;
2183 handler(wpa_s);
2184 } else {
2185 wpa_dbg(wpa_s, MSG_DEBUG,
2186 "Failed to get scan results - try scanning again");
2187 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2188 }
2189
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002190 ret = -1;
2191 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002192 }
2193
2194#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002195 num = scan_res->num;
2196 if (num > 10)
2197 num = 10;
2198 for (i = 0; i < num; i++) {
2199 u8 buf[5];
2200 struct wpa_scan_res *res = scan_res->res[i];
2201 buf[0] = res->bssid[5];
2202 buf[1] = res->qual & 0xff;
2203 buf[2] = res->noise & 0xff;
2204 buf[3] = res->level & 0xff;
2205 buf[4] = res->tsf & 0xff;
2206 random_add_randomness(buf, sizeof(buf));
2207 }
2208#endif /* CONFIG_NO_RANDOM_POOL */
2209
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002210 if (update_only) {
2211 ret = 1;
2212 goto scan_work_done;
2213 }
2214
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002215 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002216 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2218 struct wpa_scan_results *scan_res);
2219
2220 scan_res_handler = wpa_s->scan_res_handler;
2221 wpa_s->scan_res_handler = NULL;
2222 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002223 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002224 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002225 }
2226
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002227 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002228 wpa_s->own_scan_running,
2229 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002230 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002231 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2232 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002233 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2234 wpa_s->manual_scan_id);
2235 wpa_s->manual_scan_use_id = 0;
2236 } else {
2237 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2238 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002239 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002240
2241 wpas_notify_scan_done(wpa_s, 1);
2242
Hai Shalomfdcde762020-04-02 11:19:20 -07002243 if (ap) {
2244 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2245#ifdef CONFIG_AP
2246 if (wpa_s->ap_iface->scan_cb)
2247 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2248#endif /* CONFIG_AP */
2249 goto scan_work_done;
2250 }
2251
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002252 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002253 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 -07002254 wpa_scan_results_free(scan_res);
2255 return 0;
2256 }
2257
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002258 if (wnm_scan_process(wpa_s, 1) > 0)
2259 goto scan_work_done;
2260
Hai Shalomc1a21442022-02-04 13:43:00 -08002261 if (sme_proc_obss_scan(wpa_s) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002262 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263
Hai Shalom021b0b52019-04-10 11:17:58 -07002264 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002265 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2266 goto scan_work_done;
2267
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002268 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2269 goto scan_work_done;
2270
2271 if (autoscan_notify_scan(wpa_s, scan_res))
2272 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002273
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274 if (wpa_s->disconnected) {
2275 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002276 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002277 }
2278
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002279 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002280 bgscan_notify_scan(wpa_s, scan_res) == 1)
2281 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002282
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002283 wpas_wps_update_ap_info(wpa_s, scan_res);
2284
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002285 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2286 wpa_s->wpa_state < WPA_COMPLETED)
2287 goto scan_work_done;
2288
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002289 wpa_scan_results_free(scan_res);
2290
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002291 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002292 struct wpa_radio_work *work = wpa_s->scan_work;
2293 wpa_s->scan_work = NULL;
2294 radio_work_done(work);
2295 }
2296
Hai Shalomc3565922019-10-28 11:58:20 -07002297 os_free(wpa_s->last_scan_freqs);
2298 wpa_s->last_scan_freqs = NULL;
2299 wpa_s->num_last_scan_freqs = 0;
2300 if (own_request && data &&
2301 data->scan_info.freqs && data->scan_info.num_freqs) {
2302 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2303 data->scan_info.num_freqs);
2304 if (wpa_s->last_scan_freqs) {
2305 os_memcpy(wpa_s->last_scan_freqs,
2306 data->scan_info.freqs,
2307 sizeof(int) * data->scan_info.num_freqs);
2308 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2309 }
2310 }
2311
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002312 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002313
2314scan_work_done:
2315 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002316 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002317 struct wpa_radio_work *work = wpa_s->scan_work;
2318 wpa_s->scan_work = NULL;
2319 radio_work_done(work);
2320 }
2321 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002322}
2323
2324
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002325static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002326 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002327{
2328 struct wpa_bss *selected;
2329 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002330 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2331
2332 if (time_to_reenable > 0) {
2333 wpa_dbg(wpa_s, MSG_DEBUG,
2334 "Postpone network selection by %d seconds since all networks are disabled",
2335 time_to_reenable);
2336 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2337 eloop_register_timeout(time_to_reenable, 0,
2338 wpas_network_reenabled, wpa_s, NULL);
2339 return 0;
2340 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002341
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002342 if (wpa_s->p2p_mgmt)
2343 return 0; /* no normal connection on p2p_mgmt interface */
2344
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002345 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002346 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002347
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002348#ifdef CONFIG_MESH
2349 if (wpa_s->ifmsh) {
2350 wpa_msg(wpa_s, MSG_INFO,
2351 "Avoiding join because we already joined a mesh group");
2352 return 0;
2353 }
2354#endif /* CONFIG_MESH */
2355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002356 if (selected) {
2357 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002358 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002359 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002360 if (new_scan)
2361 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002362 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002363 }
2364
Hai Shalomc3565922019-10-28 11:58:20 -07002365 wpa_s->suitable_network++;
2366
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002367 if (ssid != wpa_s->current_ssid &&
2368 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2369 wpa_s->own_disconnect_req = 1;
2370 wpa_supplicant_deauthenticate(
2371 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2372 }
2373
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002374 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002375 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002376 return -1;
2377 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002378 if (new_scan)
2379 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002380 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002381 * Do not allow other virtual radios to trigger operations based
2382 * on these scan results since we do not want them to start
2383 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002384 */
2385 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002386 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002387 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002388 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2389 ssid = wpa_supplicant_pick_new_network(wpa_s);
2390 if (ssid) {
2391 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2392 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002393 if (new_scan)
2394 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002395 } else if (own_request) {
2396 /*
2397 * No SSID found. If SCAN results are as a result of
2398 * own scan request and not due to a scan request on
2399 * another shared interface, try another scan.
2400 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002401 int timeout_sec = wpa_s->scan_interval;
2402 int timeout_usec = 0;
2403#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002404 int res;
2405
2406 res = wpas_p2p_scan_no_go_seen(wpa_s);
2407 if (res == 2)
2408 return 2;
2409 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002410 return 0;
2411
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002412 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002413 wpa_s->show_group_started ||
2414 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002415 /*
2416 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002417 * state and during P2P join-a-group operation
2418 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002419 */
2420 timeout_sec = 0;
2421 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002422 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2423 timeout_usec);
2424 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002425 }
2426#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002427#ifdef CONFIG_INTERWORKING
2428 if (wpa_s->conf->auto_interworking &&
2429 wpa_s->conf->interworking &&
2430 wpa_s->conf->cred) {
2431 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2432 "start ANQP fetch since no matching "
2433 "networks found");
2434 wpa_s->network_select = 1;
2435 wpa_s->auto_network_select = 1;
2436 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002437 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002438 }
2439#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002440#ifdef CONFIG_WPS
2441 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2442 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2443 timeout_sec = 0;
2444 timeout_usec = 500000;
2445 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2446 timeout_usec);
2447 return 0;
2448 }
2449#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002450#ifdef CONFIG_OWE
2451 if (wpa_s->owe_transition_search) {
2452 wpa_dbg(wpa_s, MSG_DEBUG,
2453 "OWE: Use shorter wait during transition mode search");
2454 timeout_sec = 0;
2455 timeout_usec = 500000;
2456 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2457 timeout_usec);
2458 return 0;
2459 }
2460#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002461 if (wpa_supplicant_req_sched_scan(wpa_s))
2462 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2463 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002464
2465 wpa_msg_ctrl(wpa_s, MSG_INFO,
2466 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002467 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002468 }
2469 }
2470 return 0;
2471}
2472
2473
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002474static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2475 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002476{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002477 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002478 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002479
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002480 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002481 if (res == 2) {
2482 /*
2483 * Interface may have been removed, so must not dereference
2484 * wpa_s after this.
2485 */
2486 return 1;
2487 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002488
2489 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002490 /*
2491 * If no scan results could be fetched, then no need to
2492 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002493 * this scan. Similarly, if scan results started a new operation on this
2494 * interface, do not notify other interfaces to avoid concurrent
2495 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002496 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002497 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002498 }
2499
2500 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002501 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002502 * so, they get updated with this same scan info.
2503 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002504 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2505 radio_list) {
2506 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002507 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2508 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002509 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2510 res > 0);
2511 if (res < 0)
2512 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002513 }
2514 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002515
2516 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002517}
2518
2519#endif /* CONFIG_NO_SCAN_PROCESSING */
2520
2521
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002522int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2523{
2524#ifdef CONFIG_NO_SCAN_PROCESSING
2525 return -1;
2526#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002527 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002528
Dmitry Shmidt29333592017-01-09 12:27:11 -08002529 wpa_s->ignore_post_flush_scan_res = 0;
2530
Dmitry Shmidt41712582015-06-29 11:02:15 -07002531 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002532 return -1;
2533
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002534 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002535 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002536 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002537 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2538 return -1;
2539 }
2540
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002541 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002542#endif /* CONFIG_NO_SCAN_PROCESSING */
2543}
2544
Dmitry Shmidt04949592012-07-19 12:16:46 -07002545#ifdef CONFIG_WNM
2546
2547static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2548{
2549 struct wpa_supplicant *wpa_s = eloop_ctx;
2550
2551 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2552 return;
2553
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002554 if (!wpa_s->no_keep_alive) {
2555 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2556 MAC2STR(wpa_s->bssid));
2557 /* TODO: could skip this if normal data traffic has been sent */
2558 /* TODO: Consider using some more appropriate data frame for
2559 * this */
2560 if (wpa_s->l2)
2561 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2562 (u8 *) "", 0);
2563 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002564
2565#ifdef CONFIG_SME
2566 if (wpa_s->sme.bss_max_idle_period) {
2567 unsigned int msec;
2568 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2569 if (msec > 100)
2570 msec -= 100;
2571 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2572 wnm_bss_keep_alive, wpa_s, NULL);
2573 }
2574#endif /* CONFIG_SME */
2575}
2576
2577
2578static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2579 const u8 *ies, size_t ies_len)
2580{
2581 struct ieee802_11_elems elems;
2582
2583 if (ies == NULL)
2584 return;
2585
2586 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2587 return;
2588
2589#ifdef CONFIG_SME
2590 if (elems.bss_max_idle_period) {
2591 unsigned int msec;
2592 wpa_s->sme.bss_max_idle_period =
2593 WPA_GET_LE16(elems.bss_max_idle_period);
2594 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2595 "TU)%s", wpa_s->sme.bss_max_idle_period,
2596 (elems.bss_max_idle_period[2] & 0x01) ?
2597 " (protected keep-live required)" : "");
2598 if (wpa_s->sme.bss_max_idle_period == 0)
2599 wpa_s->sme.bss_max_idle_period = 1;
2600 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2601 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2602 /* msec times 1000 */
2603 msec = wpa_s->sme.bss_max_idle_period * 1024;
2604 if (msec > 100)
2605 msec -= 100;
2606 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2607 wnm_bss_keep_alive, wpa_s,
2608 NULL);
2609 }
2610 }
2611#endif /* CONFIG_SME */
2612}
2613
2614#endif /* CONFIG_WNM */
2615
2616
2617void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2618{
2619#ifdef CONFIG_WNM
2620 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2621#endif /* CONFIG_WNM */
2622}
2623
2624
Dmitry Shmidt051af732013-10-22 13:52:46 -07002625#ifdef CONFIG_INTERWORKING
2626
2627static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2628 size_t len)
2629{
2630 int res;
2631
2632 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2633 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2634 if (res) {
2635 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2636 }
2637
2638 return res;
2639}
2640
2641
2642static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2643 const u8 *ies, size_t ies_len)
2644{
2645 struct ieee802_11_elems elems;
2646
2647 if (ies == NULL)
2648 return;
2649
2650 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2651 return;
2652
2653 if (elems.qos_map_set) {
2654 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2655 elems.qos_map_set_len);
2656 }
2657}
2658
2659#endif /* CONFIG_INTERWORKING */
2660
2661
Hai Shalom74f70d42019-02-11 14:42:39 -08002662static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2663 const u8 *ies, size_t ies_len)
2664{
2665 struct ieee802_11_elems elems;
2666 const u8 *map_sub_elem, *pos;
2667 size_t len;
2668
Hai Shalomfdcde762020-04-02 11:19:20 -07002669 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002670
Hai Shalomfdcde762020-04-02 11:19:20 -07002671 if (!ies ||
2672 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2673 !elems.multi_ap || elems.multi_ap_len < 7)
2674 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002675
2676 pos = elems.multi_ap + 4;
2677 len = elems.multi_ap_len - 4;
2678
2679 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002680 if (!map_sub_elem || map_sub_elem[1] < 1)
2681 return;
2682
2683 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2684 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2685 MULTI_AP_FRONTHAUL_BSS);
2686 wpa_s->multi_ap_ie = 1;
2687}
2688
2689
2690static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2691{
2692 if (!wpa_s->current_ssid ||
2693 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2694 return;
2695
2696 if (!wpa_s->multi_ap_ie) {
2697 wpa_printf(MSG_INFO,
2698 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002699 goto fail;
2700 }
2701
Hai Shalomfdcde762020-04-02 11:19:20 -07002702 if (!wpa_s->multi_ap_backhaul) {
2703 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002704 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2705 wpa_printf(MSG_INFO,
2706 "WPS active, accepting fronthaul-only BSS");
2707 /* Don't set 4addr mode in this case, so just return */
2708 return;
2709 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002710 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2711 goto fail;
2712 }
2713
2714 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2715 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2716 goto fail;
2717 }
2718 wpa_s->enabled_4addr_mode = 1;
2719 return;
2720
2721fail:
2722 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2723}
2724
2725
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002726#ifdef CONFIG_FST
2727static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2728 const u8 *ie, size_t ie_len)
2729{
2730 struct mb_ies_info mb_ies;
2731
2732 if (!ie || !ie_len || !wpa_s->fst)
2733 return -ENOENT;
2734
2735 os_memset(&mb_ies, 0, sizeof(mb_ies));
2736
2737 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2738 size_t len;
2739
2740 len = 2 + ie[1];
2741 if (len > ie_len) {
2742 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2743 ie, ie_len);
2744 break;
2745 }
2746
2747 if (ie[0] == WLAN_EID_MULTI_BAND) {
2748 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2749 (unsigned int) len);
2750 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2751 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2752 mb_ies.nof_ies++;
2753 }
2754
2755 ie_len -= len;
2756 ie += len;
2757 }
2758
2759 if (mb_ies.nof_ies > 0) {
2760 wpabuf_free(wpa_s->received_mb_ies);
2761 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2762 return 0;
2763 }
2764
2765 return -ENOENT;
2766}
2767#endif /* CONFIG_FST */
2768
2769
Hai Shalomc1a21442022-02-04 13:43:00 -08002770static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
2771 union wpa_event_data *data)
2772{
2773 int sel;
2774 const u8 *p;
2775 int l, len;
2776 bool found = false;
2777 struct wpa_ie_data ie;
2778 struct wpa_ssid *ssid = wpa_s->current_ssid;
2779 struct wpa_bss *bss = wpa_s->current_bss;
2780 int pmf;
2781
2782 if (!ssid)
2783 return 0;
2784
2785 p = data->assoc_info.req_ies;
2786 l = data->assoc_info.req_ies_len;
2787
2788 while (p && l >= 2) {
2789 len = p[1] + 2;
2790 if (len > l) {
2791 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2792 p, l);
2793 break;
2794 }
2795 if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2796 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2797 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2798 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2799 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
2800 found = true;
2801 break;
2802 }
2803 l -= len;
2804 p += len;
2805 }
2806
2807 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2808 return 0;
2809
2810 wpa_hexdump(MSG_DEBUG,
2811 "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
2812 p, l);
2813
2814 /* Update proto from (Re)Association Request frame info */
2815 wpa_s->wpa_proto = ie.proto;
2816 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
2817 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
2818 !!(wpa_s->wpa_proto &
2819 (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
2820
2821 /* Update AKMP suite from (Re)Association Request frame info */
2822 sel = ie.key_mgmt;
2823 if (ssid->key_mgmt)
2824 sel &= ssid->key_mgmt;
2825
2826 wpa_dbg(wpa_s, MSG_DEBUG,
2827 "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
2828 ie.key_mgmt, ssid->key_mgmt, sel);
2829 if (ie.key_mgmt && !sel) {
2830 wpa_supplicant_deauthenticate(
2831 wpa_s, WLAN_REASON_AKMP_NOT_VALID);
2832 return -1;
2833 }
2834
Sunil Ravi89eba102022-09-13 21:04:37 -07002835 /*
2836 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
2837 * different AKM.
2838 */
2839 if (wpa_s->key_mgmt != ie.key_mgmt &&
2840 wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
2841 if (!ssid->psk_set) {
2842 wpa_dbg(wpa_s, MSG_INFO,
2843 "No PSK available for association");
2844 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE");
2845 return -1;
2846 }
2847
2848 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
2849 if (wpa_s->conf->key_mgmt_offload &&
2850 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
2851 wpa_drv_set_key(wpa_s, 0, NULL, 0, 0, NULL, 0, ssid->psk,
2852 PMK_LEN, KEY_FLAG_PMK))
2853 wpa_dbg(wpa_s, MSG_ERROR,
2854 "WPA: Cannot set PMK for key management offload");
2855 }
2856
Hai Shalomc1a21442022-02-04 13:43:00 -08002857 wpa_s->key_mgmt = ie.key_mgmt;
2858 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2859 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
2860 wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
2861 wpa_s->wpa_proto);
2862
2863 /* Update pairwise cipher from (Re)Association Request frame info */
2864 sel = ie.pairwise_cipher;
2865 if (ssid->pairwise_cipher)
2866 sel &= ssid->pairwise_cipher;
2867
2868 wpa_dbg(wpa_s, MSG_DEBUG,
2869 "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
2870 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2871 if (ie.pairwise_cipher && !sel) {
2872 wpa_supplicant_deauthenticate(
2873 wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
2874 return -1;
2875 }
2876
2877 wpa_s->pairwise_cipher = ie.pairwise_cipher;
2878 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2879 wpa_s->pairwise_cipher);
2880 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2881 wpa_cipher_txt(wpa_s->pairwise_cipher));
2882
2883 /* Update other parameters based on AP's WPA IE/RSNE, if available */
2884 if (!bss) {
2885 wpa_dbg(wpa_s, MSG_DEBUG,
2886 "WPA: current_bss == NULL - skip AP IE check");
2887 return 0;
2888 }
2889
2890 /* Update GTK and IGTK from AP's RSNE */
2891 found = false;
2892
2893 if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
2894 const u8 *bss_rsn;
2895
2896 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2897 if (bss_rsn) {
2898 p = bss_rsn;
2899 len = 2 + bss_rsn[1];
2900 found = true;
2901 }
2902 } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
2903 const u8 *bss_wpa;
2904
2905 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2906 if (bss_wpa) {
2907 p = bss_wpa;
2908 len = 2 + bss_wpa[1];
2909 found = true;
2910 }
2911 }
2912
2913 if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
2914 return 0;
2915
2916 pmf = wpas_get_ssid_pmf(wpa_s, ssid);
2917 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2918 pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
2919 /* AP does not support MFP, local configuration requires it */
2920 wpa_supplicant_deauthenticate(
2921 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2922 return -1;
2923 }
2924 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
2925 pmf == NO_MGMT_FRAME_PROTECTION) {
2926 /* AP requires MFP, local configuration disables it */
2927 wpa_supplicant_deauthenticate(
2928 wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
2929 return -1;
2930 }
2931
2932 /* Update PMF from local configuration now that MFP validation was done
2933 * above */
2934 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
2935
2936 /* Update GTK from AP's RSNE */
2937 sel = ie.group_cipher;
2938 if (ssid->group_cipher)
2939 sel &= ssid->group_cipher;
2940
2941 wpa_dbg(wpa_s, MSG_DEBUG,
2942 "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
2943 ie.group_cipher, ssid->group_cipher, sel);
2944 if (ie.group_cipher && !sel) {
2945 wpa_supplicant_deauthenticate(
2946 wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
2947 return -1;
2948 }
2949
2950 wpa_s->group_cipher = ie.group_cipher;
2951 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
2952 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
2953 wpa_cipher_txt(wpa_s->group_cipher));
2954
2955 /* Update IGTK from AP RSN IE */
2956 sel = ie.mgmt_group_cipher;
2957 if (ssid->group_mgmt_cipher)
2958 sel &= ssid->group_mgmt_cipher;
2959
2960 wpa_dbg(wpa_s, MSG_DEBUG,
2961 "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
2962 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
2963
2964 if (pmf == NO_MGMT_FRAME_PROTECTION ||
2965 !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
2966 wpa_dbg(wpa_s, MSG_DEBUG,
2967 "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
2968 ie.capabilities);
2969 ie.mgmt_group_cipher = 0;
2970 }
2971
2972 if (ie.mgmt_group_cipher && !sel) {
2973 wpa_supplicant_deauthenticate(
2974 wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
2975 return -1;
2976 }
2977
2978 wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
2979 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
2980 wpa_s->mgmt_group_cipher);
2981 if (wpa_s->mgmt_group_cipher)
2982 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
2983 wpa_cipher_txt(wpa_s->mgmt_group_cipher));
2984 else
2985 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
2986
2987 return 0;
2988}
2989
2990
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002991static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2992 union wpa_event_data *data)
2993{
Hai Shalomc3565922019-10-28 11:58:20 -07002994 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002995 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002996 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002997 bool bssid_known;
Vinayak Yadawad14709082022-03-17 14:25:11 +05302998#ifdef CONFIG_DRIVER_NL80211_BRCM
2999 struct wpa_ie_data ie;
3000#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003001
3002 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07003003 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003004 if (data->assoc_info.req_ies)
3005 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3006 data->assoc_info.req_ies_len);
3007 if (data->assoc_info.resp_ies) {
3008 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3009 data->assoc_info.resp_ies_len);
3010#ifdef CONFIG_TDLS
3011 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3012 data->assoc_info.resp_ies_len);
3013#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003014#ifdef CONFIG_WNM
3015 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3016 data->assoc_info.resp_ies_len);
3017#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003018#ifdef CONFIG_INTERWORKING
3019 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3020 data->assoc_info.resp_ies_len);
3021#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003022 if (wpa_s->hw_capab == CAPAB_VHT &&
3023 get_ie(data->assoc_info.resp_ies,
3024 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3025 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003026
3027 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3028 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003029 }
3030 if (data->assoc_info.beacon_ies)
3031 wpa_hexdump(MSG_DEBUG, "beacon_ies",
3032 data->assoc_info.beacon_ies,
3033 data->assoc_info.beacon_ies_len);
3034 if (data->assoc_info.freq)
3035 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3036 data->assoc_info.freq);
3037
Hai Shalom021b0b52019-04-10 11:17:58 -07003038 wpa_s->connection_set = 0;
3039 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3040 struct ieee802_11_elems req_elems, resp_elems;
3041
3042 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3043 data->assoc_info.req_ies_len,
3044 &req_elems, 0) != ParseFailed &&
3045 ieee802_11_parse_elems(data->assoc_info.resp_ies,
3046 data->assoc_info.resp_ies_len,
3047 &resp_elems, 0) != ParseFailed) {
3048 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07003049 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
3050 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07003051 wpa_s->connection_ht = req_elems.ht_capabilities &&
3052 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07003053 /* Do not include subset of VHT on 2.4 GHz vendor
3054 * extension in consideration for reporting VHT
3055 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07003056 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003057 resp_elems.vht_capabilities &&
3058 (!data->assoc_info.freq ||
3059 wpas_freq_to_band(data->assoc_info.freq) !=
3060 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07003061 wpa_s->connection_he = req_elems.he_capabilities &&
3062 resp_elems.he_capabilities;
Sunil Ravia04bd252022-05-02 22:54:18 -07003063 wpa_s->connection_eht = req_elems.eht_capabilities &&
3064 resp_elems.eht_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08003065
3066 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
3067 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
3068 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
3069 max_nss_rx_req : max_nss_rx_resp;
3070 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
3071 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
3072 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
3073 max_nss_tx_req : max_nss_tx_resp;
3074
3075 struct supported_chan_width sta_supported_chan_width =
3076 get_supported_channel_width(&req_elems);
3077 enum chan_width ap_operation_chan_width =
3078 get_operation_channel_width(&resp_elems);
Veerendranath Jakkam3fba9952022-07-02 03:00:08 +05303079 if (wpa_s->connection_vht || wpa_s->connection_he ||
3080 wpa_s->connection_eht) {
Kai Shi1e985032020-01-13 16:39:49 -08003081 wpa_s->connection_channel_bandwidth =
3082 get_sta_operation_chan_width(ap_operation_chan_width,
3083 sta_supported_chan_width);
3084 } else if (wpa_s->connection_ht) {
3085 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
3086 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
3087 } else {
3088 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
3089 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003090 }
3091 }
3092
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003093 p = data->assoc_info.req_ies;
3094 l = data->assoc_info.req_ies_len;
3095
3096 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3097 while (p && l >= 2) {
3098 len = p[1] + 2;
3099 if (len > l) {
3100 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3101 p, l);
3102 break;
3103 }
Hai Shalomc3565922019-10-28 11:58:20 -07003104 if (!found &&
3105 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3106 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3107 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3108 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3109 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003110 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3111 break;
3112 found = 1;
3113 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07003114 }
3115 if (!found_x && p[0] == WLAN_EID_RSNX) {
3116 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3117 break;
3118 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003119 }
3120 l -= len;
3121 p += len;
3122 }
3123 if (!found && data->assoc_info.req_ies)
3124 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003125 if (!found_x && data->assoc_info.req_ies)
3126 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003127
Vinayak Yadawad14709082022-03-17 14:25:11 +05303128#ifdef CONFIG_DRIVER_NL80211_BRCM
3129 /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed
3130 * to a different security type, update the current supplicant configuration to use the AKM
3131 * and pairwise suites from the assoc IE passed by the driver.
3132 */
3133 if (wpas_driver_bss_selection(wpa_s)) {
3134 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3135 /* Check if firmware has roamed to a different security network */
3136 if(wpa_s->key_mgmt != ie.key_mgmt) {
3137 wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE",
3138 ie.key_mgmt);
3139 wpa_s->key_mgmt = ie.key_mgmt;
3140 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3141
3142 if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) {
3143 /* Restore PMK as it can get overwritten if the previous
3144 * association was to 802.1X.
3145 */
3146 if ((!(wpa_s->drv_flags &
3147 WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) &&
3148 (wpa_s->current_ssid) &&
3149 (wpa_s->current_ssid->psk_set)) {
3150 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3151 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get "
3152 "BSSID");
3153 wpa_supplicant_deauthenticate(
3154 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3155 return -1;
3156 }
3157 wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk,
3158 PMK_LEN, NULL, bssid);
3159 }
3160 }
3161 }
3162 if(wpa_s->pairwise_cipher != ie.pairwise_cipher) {
3163 wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x "
3164 "from Assoc IE", ie.pairwise_cipher);
3165 wpa_s->pairwise_cipher = ie.pairwise_cipher;
3166 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3167 wpa_s->pairwise_cipher);
3168 }
3169 // TODO: Notify the framework about security type change b/230766005
3170 }
3171 }
3172#endif /* CONFIG_DRIVER_NL80211_BRCM */
3173
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003174#ifdef CONFIG_FILS
3175#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003176 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3177 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003178 (!data->assoc_info.resp_frame ||
3179 fils_process_assoc_resp(wpa_s->wpa,
3180 data->assoc_info.resp_frame,
3181 data->assoc_info.resp_frame_len) < 0)) {
3182 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3183 return -1;
3184 }
3185#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003186
3187 /* Additional processing for FILS when SME is in driver */
3188 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3189 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3190 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003191#endif /* CONFIG_FILS */
3192
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003193#ifdef CONFIG_OWE
3194 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07003195 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003196 owe_process_assoc_resp(wpa_s->wpa, bssid,
3197 data->assoc_info.resp_ies,
3198 data->assoc_info.resp_ies_len) < 0)) {
3199 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3200 return -1;
3201 }
3202#endif /* CONFIG_OWE */
3203
Hai Shalom021b0b52019-04-10 11:17:58 -07003204#ifdef CONFIG_DPP2
3205 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003206 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3207 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003208 struct ieee802_11_elems elems;
3209
3210 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3211 data->assoc_info.resp_ies_len,
3212 &elems, 0) == ParseFailed ||
3213 !elems.owe_dh)
3214 goto no_pfs;
3215 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3216 elems.owe_dh_len) < 0) {
3217 wpa_supplicant_deauthenticate(wpa_s,
3218 WLAN_REASON_UNSPECIFIED);
3219 return -1;
3220 }
3221
3222 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3223 }
3224no_pfs:
3225#endif /* CONFIG_DPP2 */
3226
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003227#ifdef CONFIG_IEEE80211R
3228#ifdef CONFIG_SME
3229 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003230 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003231 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3232 data->assoc_info.resp_ies,
3233 data->assoc_info.resp_ies_len,
3234 bssid) < 0) {
3235 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3236 "Reassociation Response failed");
3237 wpa_supplicant_deauthenticate(
3238 wpa_s, WLAN_REASON_INVALID_IE);
3239 return -1;
3240 }
3241 }
3242
3243 p = data->assoc_info.resp_ies;
3244 l = data->assoc_info.resp_ies_len;
3245
3246#ifdef CONFIG_WPS_STRICT
3247 if (p && wpa_s->current_ssid &&
3248 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3249 struct wpabuf *wps;
3250 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3251 if (wps == NULL) {
3252 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3253 "include WPS IE in (Re)Association Response");
3254 return -1;
3255 }
3256
3257 if (wps_validate_assoc_resp(wps) < 0) {
3258 wpabuf_free(wps);
3259 wpa_supplicant_deauthenticate(
3260 wpa_s, WLAN_REASON_INVALID_IE);
3261 return -1;
3262 }
3263 wpabuf_free(wps);
3264 }
3265#endif /* CONFIG_WPS_STRICT */
3266
3267 /* Go through the IEs and make a copy of the MDIE, if present. */
3268 while (p && l >= 2) {
3269 len = p[1] + 2;
3270 if (len > l) {
3271 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3272 p, l);
3273 break;
3274 }
3275 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3276 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3277 wpa_s->sme.ft_used = 1;
3278 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3279 MOBILITY_DOMAIN_ID_LEN);
3280 break;
3281 }
3282 l -= len;
3283 p += len;
3284 }
3285#endif /* CONFIG_SME */
Andy Kuoaba17c12022-04-14 16:05:31 +08003286#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303287 if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) ||
3288 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) ||
3289 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) ||
3290 (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) &&
Mir Ali677e7482020-11-12 19:49:02 +05303291 wpa_ft_is_completed(wpa_s->wpa)) {
3292 return 0;
3293 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003294#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003295
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003296 /* Process FT when SME is in the driver */
3297 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3298 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07003299 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07003300 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3301 data->assoc_info.resp_ies,
3302 data->assoc_info.resp_ies_len,
3303 bssid) < 0) {
3304 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3305 "Reassociation Response failed");
3306 wpa_supplicant_deauthenticate(
3307 wpa_s, WLAN_REASON_INVALID_IE);
3308 return -1;
3309 }
3310 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3311 }
3312
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003313 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3314 data->assoc_info.resp_ies_len);
3315#endif /* CONFIG_IEEE80211R */
3316
Hai Shalom899fcc72020-10-19 14:38:18 -07003317 if (bssid_known)
3318 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3319 data->assoc_info.resp_ies,
3320 data->assoc_info.resp_ies_len);
3321
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003322 /* WPA/RSN IE from Beacon/ProbeResp */
3323 p = data->assoc_info.beacon_ies;
3324 l = data->assoc_info.beacon_ies_len;
3325
3326 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3327 */
3328 wpa_found = rsn_found = 0;
3329 while (p && l >= 2) {
3330 len = p[1] + 2;
3331 if (len > l) {
3332 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3333 p, l);
3334 break;
3335 }
3336 if (!wpa_found &&
3337 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3338 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3339 wpa_found = 1;
3340 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3341 }
3342
3343 if (!rsn_found &&
3344 p[0] == WLAN_EID_RSN && p[1] >= 2) {
3345 rsn_found = 1;
3346 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3347 }
3348
Hai Shalomc3565922019-10-28 11:58:20 -07003349 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3350 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3351
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003352 l -= len;
3353 p += len;
3354 }
3355
3356 if (!wpa_found && data->assoc_info.beacon_ies)
3357 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003358 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003359 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003360 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3361 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003362 if (wpa_found || rsn_found)
3363 wpa_s->ap_ies_from_associnfo = 1;
3364
Jouni Malinen87fd2792011-05-16 18:35:42 +03003365 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3366 wpa_s->assoc_freq != data->assoc_info.freq) {
3367 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3368 "%u to %u MHz",
3369 wpa_s->assoc_freq, data->assoc_info.freq);
3370 wpa_supplicant_update_scan_results(wpa_s);
3371 }
3372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003373 wpa_s->assoc_freq = data->assoc_info.freq;
3374
Hai Shalomc1a21442022-02-04 13:43:00 -08003375 wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3376 data->assoc_info.resp_ies_len);
3377
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003378 return 0;
3379}
3380
3381
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003382static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3383{
Hai Shalomc3565922019-10-28 11:58:20 -07003384 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003385
3386 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3387 return -1;
3388
3389 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3390 return 0;
3391
3392 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3393 WPA_IE_VENDOR_TYPE);
3394 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003395 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003396
3397 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3398 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3399 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003400 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3401 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3402 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003403 return -1;
3404
3405 return 0;
3406}
3407
3408
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003409static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3410 union wpa_event_data *data)
3411{
3412#ifdef CONFIG_FST
3413 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3414 struct wpa_bss *bss = wpa_s->current_bss;
3415 const u8 *ieprb, *iebcn;
3416
3417 wpabuf_free(wpa_s->received_mb_ies);
3418 wpa_s->received_mb_ies = NULL;
3419
3420 if (ai &&
3421 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3422 wpa_printf(MSG_DEBUG,
3423 "FST: MB IEs updated from Association Response frame");
3424 return;
3425 }
3426
3427 if (ai &&
3428 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3429 wpa_printf(MSG_DEBUG,
3430 "FST: MB IEs updated from association event Beacon IEs");
3431 return;
3432 }
3433
3434 if (!bss)
3435 return;
3436
Hai Shalom60840252021-02-19 19:02:11 -08003437 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003438 iebcn = ieprb + bss->ie_len;
3439
3440 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3441 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3442 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3443 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3444#endif /* CONFIG_FST */
3445}
3446
3447
Sunil Ravi89eba102022-09-13 21:04:37 -07003448static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
3449{
3450 struct driver_sta_mlo_info mlo;
3451 int i;
3452
3453 mlo.valid_links = 0;
3454 if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
3455 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
3456 wpa_supplicant_deauthenticate(wpa_s,
3457 WLAN_REASON_DEAUTH_LEAVING);
3458 return -1;
3459 }
3460
3461 if (wpa_s->valid_links == mlo.valid_links) {
3462 bool match = true;
3463
3464 if (!mlo.valid_links)
3465 return 0;
3466
3467 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3468 if (!(mlo.valid_links & BIT(i)))
3469 continue;
3470
3471 if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr,
3472 ETH_ALEN) != 0 ||
3473 os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid,
3474 ETH_ALEN) != 0) {
3475 match = false;
3476 break;
3477 }
3478 }
3479
3480 if (match &&
3481 os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr,
3482 ETH_ALEN) == 0)
3483 return 0;
3484 }
3485
3486 wpa_s->valid_links = mlo.valid_links;
3487 os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
3488 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
3489 if (!(wpa_s->valid_links & BIT(i)))
3490 continue;
3491
3492 os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
3493 os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
3494 wpa_s->links[i].freq = mlo.links[i].freq;
3495 wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
3496 }
3497
3498 return 0;
3499}
3500
3501
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003502static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3503 union wpa_event_data *data)
3504{
3505 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003506 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003507 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003508#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3509 struct wpa_bss *bss;
3510#endif /* CONFIG_FILS || CONFIG_MBO */
Andy Kuoaba17c12022-04-14 16:05:31 +08003511#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303512 struct wpa_ie_data ie;
Andy Kuoaba17c12022-04-14 16:05:31 +08003513#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003514
3515#ifdef CONFIG_AP
3516 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003517 if (!data)
3518 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003519 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3520 data->assoc_info.addr,
3521 data->assoc_info.req_ies,
3522 data->assoc_info.req_ies_len,
3523 data->assoc_info.reassoc);
3524 return;
3525 }
3526#endif /* CONFIG_AP */
3527
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003528 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003529 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003530
Andy Kuoaba17c12022-04-14 16:05:31 +08003531#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +05303532 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3533 struct wpa_ft_ies parse;
3534 /* Check for FT reassociation is done by the driver */
3535#ifdef CONFIG_IEEE80211R
3536 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
Mir Alieaaf04e2021-06-07 12:17:29 +05303537 if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) {
Mir Ali677e7482020-11-12 19:49:02 +05303538 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3539 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3540 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3541 return;
3542 }
3543 if (parse.rsn_pmkid != NULL) {
3544 wpa_set_ft_completed(wpa_s->wpa);
3545 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3546 }
3547 }
3548#endif /* CONFIG_IEEE80211R */
3549 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003550#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Ali677e7482020-11-12 19:49:02 +05303551
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003552 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
Sunil Ravia04bd252022-05-02 22:54:18 -07003553
3554 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3555 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
3556 wpa_supplicant_deauthenticate(
3557 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3558 return;
3559 }
3560
Sunil Ravi89eba102022-09-13 21:04:37 -07003561 if (wpa_drv_get_mlo_info(wpa_s) < 0) {
3562 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
3563 wpa_supplicant_deauthenticate(wpa_s,
3564 WLAN_REASON_DEAUTH_LEAVING);
3565 return;
3566 }
3567
Sunil Ravia04bd252022-05-02 22:54:18 -07003568 if (ft_completed &&
3569 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
3570 wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
3571 MAC2STR(bssid));
3572 if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
3573 wpa_printf(MSG_ERROR,
3574 "Can't find target AP's information!");
3575 return;
3576 }
3577 wpa_supplicant_assoc_update_ie(wpa_s);
3578 }
3579
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003580 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3581 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003582 /*
3583 * FILS authentication can share the same mechanism to mark the
3584 * connection fully authenticated, so set ft_completed also based on
3585 * FILS result.
3586 */
3587 if (!ft_completed)
3588 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003589
Andy Kuoaba17c12022-04-14 16:05:31 +08003590#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303591 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
3592 /*
3593 * For driver based roaming, insert PSK during
3594 * the initial association
3595 */
3596 if (is_zero_ether_addr(wpa_s->bssid) &&
3597 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3598 /*
3599 * In case the driver wants to handle re-assocs,
3600 * pass it down the PMK.
3601 */
3602 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3603 wpa_sm_install_pmk(wpa_s->wpa);
3604 }
Mir Ali677e7482020-11-12 19:49:02 +05303605 }
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303606#endif
Andy Kuoaba17c12022-04-14 16:05:31 +08003607
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003608 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003609 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003610 if (os_reltime_initialized(&wpa_s->session_start)) {
3611 os_reltime_age(&wpa_s->session_start,
3612 &wpa_s->session_length);
3613 wpa_s->session_start.sec = 0;
3614 wpa_s->session_start.usec = 0;
3615 wpas_notify_session_length(wpa_s);
3616 } else {
3617 wpas_notify_auth_changed(wpa_s);
3618 os_get_reltime(&wpa_s->session_start);
3619 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003620 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3621 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003622 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003623 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003624 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3625 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003626 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003627
3628 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3629 wpa_clear_keys(wpa_s, bssid);
3630 }
3631 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003632 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003633 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3634 return;
3635 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003636 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003637
Hai Shalomc1a21442022-02-04 13:43:00 -08003638 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3639 data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
3640 return;
3641
Hai Shalomfdcde762020-04-02 11:19:20 -07003642 multi_ap_set_4addr_mode(wpa_s);
3643
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003644 if (wpa_s->conf->ap_scan == 1 &&
3645 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003646 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3647 wpa_msg(wpa_s, MSG_WARNING,
3648 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003649 }
3650
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003651 wpas_fst_update_mb_assoc(wpa_s, data);
3652
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003653#ifdef CONFIG_SME
3654 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3655 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003656 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003657#endif /* CONFIG_SME */
3658
3659 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3660 if (wpa_s->current_ssid) {
3661 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3662 * initialized before association, but for other modes,
3663 * initialize PC/SC here, if the current configuration needs
3664 * smartcard or SIM/USIM. */
3665 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3666 }
3667 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3668 if (wpa_s->l2)
3669 l2_packet_notify_auth_start(wpa_s->l2);
3670
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003671 already_authorized = data && data->assoc_info.authorized;
3672
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003673 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003674 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003675 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3676 * state machine may transit to AUTHENTICATING state based on obsolete
3677 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3678 * AUTHENTICATED without ever giving chance to EAP state machine to
3679 * reset the state.
3680 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003681 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003682 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3683 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003684 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003685 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3686 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3687 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003688 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003689 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003690 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003691 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003692 wpa_s->eapol_received = 0;
3693 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3694 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3695 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003696 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003697 if (wpa_s->current_ssid &&
3698 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003699 (wpa_s->drv_flags &
3700 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3701 /*
3702 * Set the key after having received joined-IBSS event
3703 * from the driver.
3704 */
3705 wpa_supplicant_set_wpa_none_key(wpa_s,
3706 wpa_s->current_ssid);
3707 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003708 wpa_supplicant_cancel_auth_timeout(wpa_s);
3709 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3710 } else if (!ft_completed) {
3711 /* Timeout for receiving the first EAPOL packet */
3712 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3713 }
3714 wpa_supplicant_cancel_scan(wpa_s);
3715
Hai Shalom5f92bc92019-04-18 11:54:11 -07003716 if (ft_completed) {
3717 /*
3718 * FT protocol completed - make sure EAPOL state machine ends
3719 * up in authenticated.
3720 */
3721 wpa_supplicant_cancel_auth_timeout(wpa_s);
3722 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003723 eapol_sm_notify_portValid(wpa_s->eapol, true);
3724 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003725 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3726 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +05303727 if (already_authorized) {
3728 /*
3729 * We are done; the driver will take care of RSN 4-way
3730 * handshake.
3731 */
3732 wpa_supplicant_cancel_auth_timeout(wpa_s);
3733 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3734 eapol_sm_notify_portValid(wpa_s->eapol, true);
3735 eapol_sm_notify_eap_success(wpa_s->eapol, true);
3736 } else {
3737 /* Update port, WPA_COMPLETED state from
3738 * EVENT_PORT_AUTHORIZED context when driver is done
3739 * with 4way handshake.
3740 */
3741 wpa_msg(wpa_s, MSG_INFO, "ASSOC INFO: wait for driver port "
3742 "authorized indication");
3743 }
Hai Shalom74f70d42019-02-11 14:42:39 -08003744 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003745 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3746 /*
3747 * The driver will take care of RSN 4-way handshake, so we need
3748 * to allow EAPOL supplicant to complete its work without
3749 * waiting for WPA supplicant.
3750 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003751 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003752 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003753#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +05303754 if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
3755 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3756 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x",
3757 wpa_s->key_mgmt);
3758 wpa_supplicant_deauthenticate(
3759 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3760 return;
3761 }
3762 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3763 wpa_s->assoc_freq = data->assoc_info.freq;
3764 wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid);
3765 }
Andy Kuoaba17c12022-04-14 16:05:31 +08003766#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
3767
Jouni Malinena05074c2012-12-21 21:35:35 +02003768 wpa_s->last_eapol_matches_bssid = 0;
3769
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003770#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003771 if (wpa_s->rsne_override_eapol) {
3772 wpa_printf(MSG_DEBUG,
3773 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3774 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3775 wpabuf_head(wpa_s->rsne_override_eapol),
3776 wpabuf_len(wpa_s->rsne_override_eapol));
3777 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003778 if (wpa_s->rsnxe_override_eapol) {
3779 wpa_printf(MSG_DEBUG,
3780 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3781 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3782 wpabuf_head(wpa_s->rsnxe_override_eapol),
3783 wpabuf_len(wpa_s->rsnxe_override_eapol));
3784 }
3785#endif /* CONFIG_TESTING_OPTIONS */
3786
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003787 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003788 struct os_reltime now, age;
3789 os_get_reltime(&now);
3790 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003791 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003792 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3793 0) {
3794 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3795 "frame that was received just before "
3796 "association notification");
3797 wpa_supplicant_rx_eapol(
3798 wpa_s, wpa_s->pending_eapol_rx_src,
3799 wpabuf_head(wpa_s->pending_eapol_rx),
Sunil8cd6f4d2022-06-28 18:40:46 +00003800 wpabuf_len(wpa_s->pending_eapol_rx),
3801 wpa_s->pending_eapol_encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003802 }
3803 wpabuf_free(wpa_s->pending_eapol_rx);
3804 wpa_s->pending_eapol_rx = NULL;
3805 }
3806
Hai Shalomfdcde762020-04-02 11:19:20 -07003807#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003808 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3809 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003810 wpa_s->current_ssid &&
3811 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003812 /* Set static WEP keys again */
3813 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3814 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003815#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003816
3817#ifdef CONFIG_IBSS_RSN
3818 if (wpa_s->current_ssid &&
3819 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3820 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3821 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3822 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003823 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003824 if (!wpa_s->ibss_rsn) {
3825 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3826 wpa_supplicant_deauthenticate(
3827 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3828 return;
3829 }
3830
3831 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3832 }
3833#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003834
3835 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003836
3837 if (data) {
3838 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3839 data->assoc_info.resp_ies_len,
3840 &data->assoc_info.wmm_params);
3841
3842 if (wpa_s->reassoc_same_bss)
3843 wmm_ac_restore_tspecs(wpa_s);
3844 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003845
Hai Shalomc3565922019-10-28 11:58:20 -07003846#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3847 bss = wpa_bss_get_bssid(wpa_s, bssid);
3848#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003849#ifdef CONFIG_FILS
3850 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003851 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3852
3853 if (fils_cache_id)
3854 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3855 }
3856#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003857
3858#ifdef CONFIG_MBO
3859 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3860#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003861
3862#ifdef CONFIG_DPP2
3863 wpa_s->dpp_pfs_fallback = 0;
3864#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003865}
3866
3867
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003868static int disconnect_reason_recoverable(u16 reason_code)
3869{
3870 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3871 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3872 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3873}
3874
3875
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003876static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003877 u16 reason_code,
3878 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003879{
3880 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003881
3882 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3883 /*
3884 * At least Host AP driver and a Prism3 card seemed to be
3885 * generating streams of disconnected events when configuring
3886 * IBSS for WPA-None. Ignore them for now.
3887 */
3888 return;
3889 }
3890
3891 bssid = wpa_s->bssid;
3892 if (is_zero_ether_addr(bssid))
3893 bssid = wpa_s->pending_bssid;
3894
3895 if (!is_zero_ether_addr(bssid) ||
3896 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3897 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3898 " reason=%d%s",
3899 MAC2STR(bssid), reason_code,
3900 locally_generated ? " locally_generated=1" : "");
3901 }
3902}
3903
3904
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003905static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3906 int locally_generated)
3907{
3908 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003909 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003910 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3911 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003912 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003913
3914 /*
3915 * It looks like connection was lost while trying to go through PSK
3916 * 4-way handshake. Filter out known disconnection cases that are caused
3917 * by something else than PSK mismatch to avoid confusing reports.
3918 */
3919
3920 if (locally_generated) {
3921 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3922 return 0;
3923 }
3924
3925 return 1;
3926}
3927
3928
Jouni Malinen2b89da82012-08-31 22:04:41 +03003929static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3930 u16 reason_code,
3931 int locally_generated)
3932{
3933 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003934 int authenticating;
3935 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003936 struct wpa_bss *fast_reconnect = NULL;
3937 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003938 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003939 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003940
3941 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3942 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3943
3944 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3945 /*
3946 * At least Host AP driver and a Prism3 card seemed to be
3947 * generating streams of disconnected events when configuring
3948 * IBSS for WPA-None. Ignore them for now.
3949 */
3950 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3951 "IBSS/WPA-None mode");
3952 return;
3953 }
3954
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003955 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3956 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3957 locally_generated)
3958 /*
3959 * Remove the inactive AP (which is probably out of range) from
3960 * the BSS list after marking disassociation. In particular
3961 * mac80211-based drivers use the
3962 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3963 * locally generated disconnection events for cases where the
3964 * AP does not reply anymore.
3965 */
3966 curr = wpa_s->current_bss;
3967
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003968 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003969 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3970 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003971 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3972 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003973 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003974#ifdef CONFIG_DPP2
3975 wpas_dpp_send_conn_status_result(wpa_s,
3976 DPP_STATUS_AUTH_FAILURE);
3977#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003978 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003979 if (!wpa_s->disconnected &&
3980 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003981 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003982 wpas_wps_searching(wpa_s) ||
3983 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003984 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003985 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003986 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003987 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003988 wpa_s->wpa_state);
3989 if (wpa_s->wpa_state == WPA_COMPLETED &&
3990 wpa_s->current_ssid &&
3991 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003992 (wpa_s->own_reconnect_req ||
3993 (!locally_generated &&
3994 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003995 /*
3996 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003997 * us, but could allow us to get back in. This is also
3998 * triggered for cases where local reconnection request
3999 * is used to force reassociation with the same BSS.
4000 * Try to reconnect to the same BSS without a full scan
4001 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004002 */
4003 fast_reconnect = wpa_s->current_bss;
4004 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07004005 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004006 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07004007 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004008 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4009 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07004010 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004011 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004012 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004013 "try to re-connect");
4014 wpa_s->reassociate = 0;
4015 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004016 if (!wpa_s->pno)
4017 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004018 }
4019 bssid = wpa_s->bssid;
4020 if (is_zero_ether_addr(bssid))
4021 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004022 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4023 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004024 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08004025 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4026
Dmitry Shmidt04949592012-07-19 12:16:46 -07004027 if (locally_generated)
4028 wpa_s->disconnect_reason = -reason_code;
4029 else
4030 wpa_s->disconnect_reason = reason_code;
4031 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004032 if (wpa_supplicant_dynamic_keys(wpa_s)) {
4033 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004034 wpa_clear_keys(wpa_s, wpa_s->bssid);
4035 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004036 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004037 wpa_supplicant_mark_disassoc(wpa_s);
4038
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004039 if (curr)
4040 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4041
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004042 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004043 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03004044 wpa_s->current_ssid = last_ssid;
4045 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004046
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004047 if (fast_reconnect &&
4048 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4049 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4050 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4051 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004052 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004053 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004054#ifndef CONFIG_NO_SCAN_PROCESSING
4055 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4056 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4057 fast_reconnect_ssid) < 0) {
4058 /* Recover through full scan */
4059 wpa_supplicant_req_scan(wpa_s, 0, 100000);
4060 }
4061#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004062 } else if (fast_reconnect) {
4063 /*
4064 * Could not reconnect to the same BSS due to network being
4065 * disabled. Use a new scan to match the alternative behavior
4066 * above, i.e., to continue automatic reconnection attempt in a
4067 * way that enforces disabled network rules.
4068 */
4069 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004070 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004071}
4072
4073
4074#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004075void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004076{
4077 struct wpa_supplicant *wpa_s = eloop_ctx;
4078
4079 if (!wpa_s->pending_mic_error_report)
4080 return;
4081
4082 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4083 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4084 wpa_s->pending_mic_error_report = 0;
4085}
4086#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4087
4088
4089static void
4090wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4091 union wpa_event_data *data)
4092{
4093 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004094 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004095
4096 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4097 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004098 os_get_reltime(&t);
4099 if ((wpa_s->last_michael_mic_error.sec &&
4100 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004101 wpa_s->pending_mic_error_report) {
4102 if (wpa_s->pending_mic_error_report) {
4103 /*
4104 * Send the pending MIC error report immediately since
4105 * we are going to start countermeasures and AP better
4106 * do the same.
4107 */
4108 wpa_sm_key_request(wpa_s->wpa, 1,
4109 wpa_s->pending_mic_error_pairwise);
4110 }
4111
4112 /* Send the new MIC error report immediately since we are going
4113 * to start countermeasures and AP better do the same.
4114 */
4115 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4116
4117 /* initialize countermeasures */
4118 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004119
Hai Shalom60840252021-02-19 19:02:11 -08004120 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004121
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004122 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4123
4124 /*
4125 * Need to wait for completion of request frame. We do not get
4126 * any callback for the message completion, so just wait a
4127 * short while and hope for the best. */
4128 os_sleep(0, 10000);
4129
4130 wpa_drv_set_countermeasures(wpa_s, 1);
4131 wpa_supplicant_deauthenticate(wpa_s,
4132 WLAN_REASON_MICHAEL_MIC_FAILURE);
4133 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4134 wpa_s, NULL);
4135 eloop_register_timeout(60, 0,
4136 wpa_supplicant_stop_countermeasures,
4137 wpa_s, NULL);
4138 /* TODO: mark the AP rejected for 60 second. STA is
4139 * allowed to associate with another AP.. */
4140 } else {
4141#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4142 if (wpa_s->mic_errors_seen) {
4143 /*
4144 * Reduce the effectiveness of Michael MIC error
4145 * reports as a means for attacking against TKIP if
4146 * more than one MIC failure is noticed with the same
4147 * PTK. We delay the transmission of the reports by a
4148 * random time between 0 and 60 seconds in order to
4149 * force the attacker wait 60 seconds before getting
4150 * the information on whether a frame resulted in a MIC
4151 * failure.
4152 */
4153 u8 rval[4];
4154 int sec;
4155
4156 if (os_get_random(rval, sizeof(rval)) < 0)
4157 sec = os_random() % 60;
4158 else
4159 sec = WPA_GET_BE32(rval) % 60;
4160 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4161 "report %d seconds", sec);
4162 wpa_s->pending_mic_error_report = 1;
4163 wpa_s->pending_mic_error_pairwise = pairwise;
4164 eloop_cancel_timeout(
4165 wpa_supplicant_delayed_mic_error_report,
4166 wpa_s, NULL);
4167 eloop_register_timeout(
4168 sec, os_random() % 1000000,
4169 wpa_supplicant_delayed_mic_error_report,
4170 wpa_s, NULL);
4171 } else {
4172 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4173 }
4174#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4175 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4176#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4177 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004178 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004179 wpa_s->mic_errors_seen++;
4180}
4181
4182
4183#ifdef CONFIG_TERMINATE_ONLASTIF
4184static int any_interfaces(struct wpa_supplicant *head)
4185{
4186 struct wpa_supplicant *wpa_s;
4187
4188 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4189 if (!wpa_s->interface_removed)
4190 return 1;
4191 return 0;
4192}
4193#endif /* CONFIG_TERMINATE_ONLASTIF */
4194
4195
4196static void
4197wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4198 union wpa_event_data *data)
4199{
4200 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4201 return;
4202
4203 switch (data->interface_status.ievent) {
4204 case EVENT_INTERFACE_ADDED:
4205 if (!wpa_s->interface_removed)
4206 break;
4207 wpa_s->interface_removed = 0;
4208 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4209 if (wpa_supplicant_driver_init(wpa_s) < 0) {
4210 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4211 "driver after interface was added");
4212 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004213
4214#ifdef CONFIG_P2P
4215 if (!wpa_s->global->p2p &&
4216 !wpa_s->global->p2p_disabled &&
4217 !wpa_s->conf->p2p_disabled &&
4218 (wpa_s->drv_flags &
4219 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4220 wpas_p2p_add_p2pdev_interface(
4221 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4222 wpa_printf(MSG_INFO,
4223 "P2P: Failed to enable P2P Device interface");
4224 /* Try to continue without. P2P will be disabled. */
4225 }
4226#endif /* CONFIG_P2P */
4227
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004228 break;
4229 case EVENT_INTERFACE_REMOVED:
4230 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4231 wpa_s->interface_removed = 1;
4232 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004233 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004234 l2_packet_deinit(wpa_s->l2);
4235 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004236
4237#ifdef CONFIG_P2P
4238 if (wpa_s->global->p2p &&
4239 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4240 (wpa_s->drv_flags &
4241 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4242 wpa_dbg(wpa_s, MSG_DEBUG,
4243 "Removing P2P Device interface");
4244 wpa_supplicant_remove_iface(
4245 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4246 0);
4247 wpa_s->global->p2p_init_wpa_s = NULL;
4248 }
4249#endif /* CONFIG_P2P */
4250
Dmitry Shmidte4663042016-04-04 10:07:49 -07004251#ifdef CONFIG_MATCH_IFACE
4252 if (wpa_s->matched) {
4253 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4254 break;
4255 }
4256#endif /* CONFIG_MATCH_IFACE */
4257
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004258#ifdef CONFIG_TERMINATE_ONLASTIF
4259 /* check if last interface */
4260 if (!any_interfaces(wpa_s->global->ifaces))
4261 eloop_terminate();
4262#endif /* CONFIG_TERMINATE_ONLASTIF */
4263 break;
4264 }
4265}
4266
4267
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004268#ifdef CONFIG_TDLS
4269static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4270 union wpa_event_data *data)
4271{
4272 if (data == NULL)
4273 return;
4274 switch (data->tdls.oper) {
4275 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004276 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
4277 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4278 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
4279 else
4280 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004281 break;
4282 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03004283 if (wpa_tdls_is_external_setup(wpa_s->wpa))
4284 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4285 data->tdls.reason_code);
4286 else
4287 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
4288 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004289 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07004290 case TDLS_REQUEST_DISCOVER:
4291 wpa_tdls_send_discovery_request(wpa_s->wpa,
4292 data->tdls.peer);
4293 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004294 }
4295}
4296#endif /* CONFIG_TDLS */
4297
4298
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004299#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004300static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4301 union wpa_event_data *data)
4302{
4303 if (data == NULL)
4304 return;
4305 switch (data->wnm.oper) {
4306 case WNM_OPER_SLEEP:
4307 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4308 "(action=%d, intval=%d)",
4309 data->wnm.sleep_action, data->wnm.sleep_intval);
4310 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004311 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004312 break;
4313 }
4314}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004315#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004316
4317
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004318#ifdef CONFIG_IEEE80211R
4319static void
4320wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
4321 union wpa_event_data *data)
4322{
4323 if (data == NULL)
4324 return;
4325
4326 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
4327 data->ft_ies.ies_len,
4328 data->ft_ies.ft_action,
4329 data->ft_ies.target_ap,
4330 data->ft_ies.ric_ies,
4331 data->ft_ies.ric_ies_len) < 0) {
4332 /* TODO: prevent MLME/driver from trying to associate? */
4333 }
4334}
4335#endif /* CONFIG_IEEE80211R */
4336
4337
4338#ifdef CONFIG_IBSS_RSN
4339static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4340 union wpa_event_data *data)
4341{
4342 struct wpa_ssid *ssid;
4343 if (wpa_s->wpa_state < WPA_ASSOCIATED)
4344 return;
4345 if (data == NULL)
4346 return;
4347 ssid = wpa_s->current_ssid;
4348 if (ssid == NULL)
4349 return;
4350 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4351 return;
4352
4353 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4354}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004355
4356
4357static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
4358 union wpa_event_data *data)
4359{
4360 struct wpa_ssid *ssid = wpa_s->current_ssid;
4361
4362 if (ssid == NULL)
4363 return;
4364
4365 /* check if the ssid is correctly configured as IBSS/RSN */
4366 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4367 return;
4368
4369 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
4370 data->rx_mgmt.frame_len);
4371}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004372#endif /* CONFIG_IBSS_RSN */
4373
4374
4375#ifdef CONFIG_IEEE80211R
4376static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4377 size_t len)
4378{
4379 const u8 *sta_addr, *target_ap_addr;
4380 u16 status;
4381
4382 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4383 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4384 return; /* only SME case supported for now */
4385 if (len < 1 + 2 * ETH_ALEN + 2)
4386 return;
4387 if (data[0] != 2)
4388 return; /* Only FT Action Response is supported for now */
4389 sta_addr = data + 1;
4390 target_ap_addr = data + 1 + ETH_ALEN;
4391 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4392 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4393 MACSTR " TargetAP " MACSTR " status %u",
4394 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4395
4396 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
4397 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4398 " in FT Action Response", MAC2STR(sta_addr));
4399 return;
4400 }
4401
4402 if (status) {
4403 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4404 "failure (status code %d)", status);
4405 /* TODO: report error to FT code(?) */
4406 return;
4407 }
4408
4409 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4410 len - (1 + 2 * ETH_ALEN + 2), 1,
4411 target_ap_addr, NULL, 0) < 0)
4412 return;
4413
4414#ifdef CONFIG_SME
4415 {
4416 struct wpa_bss *bss;
4417 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
4418 if (bss)
4419 wpa_s->sme.freq = bss->freq;
4420 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
4421 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
4422 WLAN_AUTH_FT);
4423 }
4424#endif /* CONFIG_SME */
4425}
4426#endif /* CONFIG_IEEE80211R */
4427
4428
4429static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
4430 struct unprot_deauth *e)
4431{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004432 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
4433 "dropped: " MACSTR " -> " MACSTR
4434 " (reason code %u)",
4435 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4436 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004437}
4438
4439
4440static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
4441 struct unprot_disassoc *e)
4442{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004443 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
4444 "dropped: " MACSTR " -> " MACSTR
4445 " (reason code %u)",
4446 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
4447 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004448}
4449
4450
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004451static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
4452 u16 reason_code, int locally_generated,
4453 const u8 *ie, size_t ie_len, int deauth)
4454{
4455#ifdef CONFIG_AP
4456 if (wpa_s->ap_iface && addr) {
4457 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
4458 return;
4459 }
4460
4461 if (wpa_s->ap_iface) {
4462 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
4463 return;
4464 }
4465#endif /* CONFIG_AP */
4466
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004467 if (!locally_generated)
4468 wpa_s->own_disconnect_req = 0;
4469
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004470 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
4471
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004472 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4473 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4474 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4475 eapol_sm_failed(wpa_s->eapol))) &&
4476 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004477 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004478
4479#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004480 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004481 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4482 locally_generated) > 0) {
4483 /*
4484 * The interface was removed, so cannot continue
4485 * processing any additional operations after this.
4486 */
4487 return;
4488 }
4489 }
4490#endif /* CONFIG_P2P */
4491
4492 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4493 locally_generated);
4494}
4495
4496
4497static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4498 struct disassoc_info *info)
4499{
4500 u16 reason_code = 0;
4501 int locally_generated = 0;
4502 const u8 *addr = NULL;
4503 const u8 *ie = NULL;
4504 size_t ie_len = 0;
4505
4506 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4507
4508 if (info) {
4509 addr = info->addr;
4510 ie = info->ie;
4511 ie_len = info->ie_len;
4512 reason_code = info->reason_code;
4513 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004514 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4515 reason2str(reason_code),
4516 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004517 if (addr)
4518 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4519 MAC2STR(addr));
4520 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4521 ie, ie_len);
4522 }
4523
4524#ifdef CONFIG_AP
4525 if (wpa_s->ap_iface && info && info->addr) {
4526 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4527 return;
4528 }
4529
4530 if (wpa_s->ap_iface) {
4531 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4532 return;
4533 }
4534#endif /* CONFIG_AP */
4535
4536#ifdef CONFIG_P2P
4537 if (info) {
4538 wpas_p2p_disassoc_notif(
4539 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4540 locally_generated);
4541 }
4542#endif /* CONFIG_P2P */
4543
4544 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4545 sme_event_disassoc(wpa_s, info);
4546
4547 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4548 ie, ie_len, 0);
4549}
4550
4551
4552static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4553 struct deauth_info *info)
4554{
4555 u16 reason_code = 0;
4556 int locally_generated = 0;
4557 const u8 *addr = NULL;
4558 const u8 *ie = NULL;
4559 size_t ie_len = 0;
4560
4561 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4562
4563 if (info) {
4564 addr = info->addr;
4565 ie = info->ie;
4566 ie_len = info->ie_len;
4567 reason_code = info->reason_code;
4568 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004569 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4570 reason_code, reason2str(reason_code),
4571 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004572 if (addr) {
4573 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4574 MAC2STR(addr));
4575 }
4576 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4577 ie, ie_len);
4578 }
4579
4580 wpa_reset_ft_completed(wpa_s->wpa);
4581
4582 wpas_event_disconnect(wpa_s, addr, reason_code,
4583 locally_generated, ie, ie_len, 1);
4584}
4585
4586
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004587static const char * reg_init_str(enum reg_change_initiator init)
4588{
4589 switch (init) {
4590 case REGDOM_SET_BY_CORE:
4591 return "CORE";
4592 case REGDOM_SET_BY_USER:
4593 return "USER";
4594 case REGDOM_SET_BY_DRIVER:
4595 return "DRIVER";
4596 case REGDOM_SET_BY_COUNTRY_IE:
4597 return "COUNTRY_IE";
4598 case REGDOM_BEACON_HINT:
4599 return "BEACON_HINT";
4600 }
4601 return "?";
4602}
4603
4604
4605static const char * reg_type_str(enum reg_type type)
4606{
4607 switch (type) {
4608 case REGDOM_TYPE_UNKNOWN:
4609 return "UNKNOWN";
4610 case REGDOM_TYPE_COUNTRY:
4611 return "COUNTRY";
4612 case REGDOM_TYPE_WORLD:
4613 return "WORLD";
4614 case REGDOM_TYPE_CUSTOM_WORLD:
4615 return "CUSTOM_WORLD";
4616 case REGDOM_TYPE_INTERSECTION:
4617 return "INTERSECTION";
4618 }
4619 return "?";
4620}
4621
4622
Hai Shalom74f70d42019-02-11 14:42:39 -08004623void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4624 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004625{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004626 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004627 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004628
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004629 /*
4630 * To allow backwards compatibility with higher level layers that
4631 * assumed the REGDOM_CHANGE event is sent over the initially added
4632 * interface. Find the highest parent of this interface and use it to
4633 * send the event.
4634 */
4635 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4636 ;
4637
Hai Shalom74f70d42019-02-11 14:42:39 -08004638 if (info) {
4639 wpa_msg(ifs, MSG_INFO,
4640 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4641 reg_init_str(info->initiator), reg_type_str(info->type),
4642 info->alpha2[0] ? " alpha2=" : "",
4643 info->alpha2[0] ? info->alpha2 : "");
4644 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004645
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004646 if (wpa_s->drv_priv == NULL)
4647 return; /* Ignore event during drv initialization */
4648
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004649 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4650 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004651 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4652 ifs->ifname);
4653 free_hw_features(ifs);
4654 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004655 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004656
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004657 /* Restart PNO/sched_scan with updated channel list */
4658 if (ifs->pno) {
4659 wpas_stop_pno(ifs);
4660 wpas_start_pno(ifs);
4661 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4662 wpa_dbg(ifs, MSG_DEBUG,
4663 "Channel list changed - restart sched_scan");
4664 wpas_scan_restart_sched_scan(ifs);
4665 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004666 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004667
4668 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004669}
4670
4671
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004672static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004673 const u8 *frame, size_t len, int freq,
4674 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004675{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004676 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004677 const u8 *payload;
4678 size_t plen;
4679 u8 category;
4680
4681 if (len < IEEE80211_HDRLEN + 2)
4682 return;
4683
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004684 mgmt = (const struct ieee80211_mgmt *) frame;
4685 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004686 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004687 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004688
4689 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4690 " Category=%u DataLen=%d freq=%d MHz",
4691 MAC2STR(mgmt->sa), category, (int) plen, freq);
4692
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004693 if (category == WLAN_ACTION_WMM) {
4694 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4695 return;
4696 }
4697
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004698#ifdef CONFIG_IEEE80211R
4699 if (category == WLAN_ACTION_FT) {
4700 ft_rx_action(wpa_s, payload, plen);
4701 return;
4702 }
4703#endif /* CONFIG_IEEE80211R */
4704
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004705#ifdef CONFIG_SME
4706 if (category == WLAN_ACTION_SA_QUERY) {
Hai Shalomc1a21442022-02-04 13:43:00 -08004707 sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004708 return;
4709 }
4710#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004711
4712#ifdef CONFIG_WNM
4713 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4714 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4715 return;
4716 }
4717#endif /* CONFIG_WNM */
4718
4719#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004720 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4721 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004722 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004723 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004724 payload, plen, freq) == 0)
4725 return;
4726#endif /* CONFIG_GAS */
4727
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004728#ifdef CONFIG_GAS_SERVER
4729 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4730 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4731 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4732 mgmt->u.action.category,
4733 payload, plen, freq) == 0)
4734 return;
4735#endif /* CONFIG_GAS_SERVER */
4736
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004737#ifdef CONFIG_TDLS
4738 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4739 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4740 wpa_dbg(wpa_s, MSG_DEBUG,
4741 "TDLS: Received Discovery Response from " MACSTR,
4742 MAC2STR(mgmt->sa));
4743 return;
4744 }
4745#endif /* CONFIG_TDLS */
4746
4747#ifdef CONFIG_INTERWORKING
4748 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4749 payload[0] == QOS_QOS_MAP_CONFIG) {
4750 const u8 *pos = payload + 1;
4751 size_t qlen = plen - 1;
4752 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4753 MACSTR, MAC2STR(mgmt->sa));
4754 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4755 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4756 pos[1] <= qlen - 2 && pos[1] >= 16)
4757 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4758 return;
4759 }
4760#endif /* CONFIG_INTERWORKING */
4761
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004762 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004763 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4764 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004765 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004766 payload + 1,
4767 plen - 1);
4768 return;
4769 }
4770
4771 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004772 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4773 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4774 return;
4775 }
4776
4777 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4778 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4779 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4780 payload + 1, plen - 1,
4781 rssi);
4782 return;
4783 }
4784
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004785#ifdef CONFIG_FST
4786 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4787 fst_rx_action(wpa_s->fst, mgmt, len);
4788 return;
4789 }
4790#endif /* CONFIG_FST */
4791
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004792#ifdef CONFIG_DPP
4793 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4794 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4795 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4796 payload[4] == DPP_OUI_TYPE) {
4797 payload++;
4798 plen--;
4799 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4800 return;
4801 }
4802#endif /* CONFIG_DPP */
4803
Hai Shalom899fcc72020-10-19 14:38:18 -07004804 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalomc1a21442022-02-04 13:43:00 -08004805 payload[0] == ROBUST_AV_SCS_RESP) {
4806 wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
4807 payload + 1, plen - 1);
4808 return;
4809 }
4810
4811 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004812 payload[0] == ROBUST_AV_MSCS_RESP) {
4813 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4814 payload + 1, plen - 1);
4815 return;
4816 }
4817
Hai Shalomc1a21442022-02-04 13:43:00 -08004818 if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
4819 WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
4820 wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
4821 payload + 4, plen - 4);
4822 return;
4823 }
4824
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004825 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4826 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004827 if (wpa_s->ifmsh)
4828 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004829}
4830
4831
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004832static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4833 union wpa_event_data *event)
4834{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004835 struct wpa_freq_range_list *list;
4836 char *str = NULL;
4837
4838 list = &event->freq_range;
4839
4840 if (list->num)
4841 str = freq_range_list_str(list);
4842 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4843 str ? str : "");
4844
4845#ifdef CONFIG_P2P
4846 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4847 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4848 __func__);
4849 } else {
4850 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004851
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004852 /*
4853 * The update channel flow will also take care of moving a GO
4854 * from the unsafe frequency if needed.
4855 */
4856 wpas_p2p_update_channel_list(wpa_s,
4857 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004858 }
4859#endif /* CONFIG_P2P */
4860
4861 os_free(str);
4862}
4863
4864
Roshan Pius3a1667e2018-07-03 15:17:14 -07004865static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004866{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004867 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4868 wpa_supplicant_cancel_auth_timeout(wpa_s);
4869 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004870 eapol_sm_notify_portValid(wpa_s->eapol, true);
4871 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004872 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004873 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004874}
4875
4876
4877static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4878 int freq)
4879{
4880 size_t i;
4881 int j;
4882
4883 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4884 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4885
4886 for (j = 0; j < mode->num_channels; j++) {
4887 const struct hostapd_channel_data *chan;
4888
4889 chan = &mode->channels[j];
4890 if (chan->freq == freq)
4891 return chan->dfs_cac_ms;
4892 }
4893 }
4894
4895 return 0;
4896}
4897
4898
4899static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4900 struct dfs_event *radar)
4901{
4902#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004903 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004904 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4905 } else
4906#endif /* NEED_AP_MLME && CONFIG_AP */
4907 {
4908 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4909
4910 cac_time /= 1000; /* convert from ms to sec */
4911 if (!cac_time)
4912 cac_time = 10 * 60; /* max timeout: 10 minutes */
4913
4914 /* Restart auth timeout: CAC time added to initial timeout */
4915 wpas_auth_timeout_restart(wpa_s, cac_time);
4916 }
4917}
4918
4919
4920static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4921 struct dfs_event *radar)
4922{
4923#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004924 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004925 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4926 } else
4927#endif /* NEED_AP_MLME && CONFIG_AP */
4928 {
4929 /* Restart auth timeout with original value after CAC is
4930 * finished */
4931 wpas_auth_timeout_restart(wpa_s, 0);
4932 }
4933}
4934
4935
4936static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4937 struct dfs_event *radar)
4938{
4939#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004940 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004941 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4942 } else
4943#endif /* NEED_AP_MLME && CONFIG_AP */
4944 {
4945 /* Restart auth timeout with original value after CAC is
4946 * aborted */
4947 wpas_auth_timeout_restart(wpa_s, 0);
4948 }
4949}
4950
4951
4952static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4953 union wpa_event_data *data)
4954{
4955 wpa_dbg(wpa_s, MSG_DEBUG,
4956 "Connection authorized by device, previous state %d",
4957 wpa_s->wpa_state);
4958
4959 wpa_supplicant_event_port_authorized(wpa_s);
4960
Hai Shalomc1a21442022-02-04 13:43:00 -08004961 wpa_s->last_eapol_matches_bssid = 1;
4962
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004963 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4964 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004965 data->assoc_info.ptk_kck_len,
4966 data->assoc_info.ptk_kek,
4967 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004968#ifdef CONFIG_FILS
4969 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4970 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4971 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4972
4973 /* Update ERP next sequence number */
4974 eapol_sm_update_erp_next_seq_num(
4975 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4976
4977 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4978 /* Add the new PMK and PMKID to the PMKSA cache */
4979 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4980 data->assoc_info.fils_pmk,
4981 data->assoc_info.fils_pmk_len,
4982 data->assoc_info.fils_pmkid,
4983 wpa_s->bssid, fils_cache_id);
4984 } else if (data->assoc_info.fils_pmkid) {
4985 /* Update the current PMKSA used for this connection */
4986 pmksa_cache_set_current(wpa_s->wpa,
4987 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004988 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004989 }
4990 }
4991#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004992}
4993
4994
Hai Shalom60840252021-02-19 19:02:11 -08004995static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4996{
4997 switch (code) {
4998 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
4999 return "";
5000 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5001 return "no_bss_found";
5002 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5003 return "auth_tx_fail";
5004 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5005 return "auth_no_ack_received";
5006 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5007 return "auth_no_resp_received";
5008 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5009 return "assoc_req_tx_fail";
5010 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5011 return "assoc_no_ack_received";
5012 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5013 return "assoc_no_resp_received";
5014 default:
5015 return "unknown_reason";
5016 }
5017}
5018
5019
Roshan Pius3a1667e2018-07-03 15:17:14 -07005020static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5021 union wpa_event_data *data)
5022{
5023 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005024#ifdef CONFIG_MBO
5025 struct wpa_bss *reject_bss;
5026#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005027
5028 if (!bssid || is_zero_ether_addr(bssid))
5029 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07005030#ifdef CONFIG_MBO
5031 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5032 reject_bss = wpa_s->current_bss;
5033 else
5034 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5035#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07005036
5037 if (data->assoc_reject.bssid)
5038 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005039 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005040 MAC2STR(data->assoc_reject.bssid),
5041 data->assoc_reject.status_code,
5042 data->assoc_reject.timed_out ? " timeout" : "",
5043 data->assoc_reject.timeout_reason ? "=" : "",
5044 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005045 data->assoc_reject.timeout_reason : "",
5046 data->assoc_reject.reason_code !=
5047 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5048 " qca_driver_reason=" : "",
5049 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005050 else
5051 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08005052 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07005053 data->assoc_reject.status_code,
5054 data->assoc_reject.timed_out ? " timeout" : "",
5055 data->assoc_reject.timeout_reason ? "=" : "",
5056 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08005057 data->assoc_reject.timeout_reason : "",
5058 data->assoc_reject.reason_code !=
5059 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5060 " qca_driver_reason=" : "",
5061 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07005062 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08005063 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
5064 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005065
5066#ifdef CONFIG_OWE
5067 if (data->assoc_reject.status_code ==
5068 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5069 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5070 wpa_s->current_ssid &&
5071 wpa_s->current_ssid->owe_group == 0 &&
5072 wpa_s->last_owe_group != 21) {
5073 struct wpa_ssid *ssid = wpa_s->current_ssid;
5074 struct wpa_bss *bss = wpa_s->current_bss;
5075
5076 if (!bss) {
5077 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5078 if (!bss) {
5079 wpas_connection_failed(wpa_s, bssid);
5080 wpa_supplicant_mark_disassoc(wpa_s);
5081 return;
5082 }
5083 }
5084 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5085 wpas_connect_work_done(wpa_s);
5086 wpa_supplicant_mark_disassoc(wpa_s);
5087 wpa_supplicant_connect(wpa_s, bss, ssid);
5088 return;
5089 }
5090#endif /* CONFIG_OWE */
5091
Hai Shalomfdcde762020-04-02 11:19:20 -07005092#ifdef CONFIG_DPP2
5093 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5094 * the status code defined in the DPP R2 tech spec.
5095 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5096 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005097 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07005098 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5099 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5100 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07005101 wpa_s->current_ssid->dpp_pfs == 0 &&
5102 (data->assoc_reject.status_code ==
5103 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5104 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5105 struct wpa_ssid *ssid = wpa_s->current_ssid;
5106 struct wpa_bss *bss = wpa_s->current_bss;
5107
5108 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5109 if (!bss)
5110 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5111 if (!bss || wpa_s->dpp_pfs_fallback) {
5112 wpa_printf(MSG_DEBUG,
5113 "DPP: Updated PFS policy for next try");
5114 wpas_connection_failed(wpa_s, bssid);
5115 wpa_supplicant_mark_disassoc(wpa_s);
5116 return;
5117 }
5118 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5119 wpa_s->dpp_pfs_fallback = 1;
5120 wpas_connect_work_done(wpa_s);
5121 wpa_supplicant_mark_disassoc(wpa_s);
5122 wpa_supplicant_connect(wpa_s, bss, ssid);
5123 return;
5124 }
5125#endif /* CONFIG_DPP2 */
5126
Hai Shalom74f70d42019-02-11 14:42:39 -08005127#ifdef CONFIG_MBO
5128 if (data->assoc_reject.status_code ==
5129 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07005130 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08005131 const u8 *rssi_rej;
5132
5133 rssi_rej = mbo_get_attr_from_ies(
5134 data->assoc_reject.resp_ies,
5135 data->assoc_reject.resp_ies_len,
5136 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5137 if (rssi_rej && rssi_rej[1] == 2) {
5138 wpa_printf(MSG_DEBUG,
5139 "OCE: RSSI-based association rejection from "
5140 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07005141 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08005142 rssi_rej[2], rssi_rej[3]);
5143 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07005144 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08005145 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07005146 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08005147 }
5148 }
5149#endif /* CONFIG_MBO */
5150
Roshan Pius3a1667e2018-07-03 15:17:14 -07005151 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5152 sme_event_assoc_reject(wpa_s, data);
5153 return;
5154 }
5155
5156 /* Driver-based SME cases */
5157
5158#ifdef CONFIG_SAE
5159 if (wpa_s->current_ssid &&
5160 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5161 !data->assoc_reject.timed_out) {
5162 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5163 wpa_sm_aborted_cached(wpa_s->wpa);
5164 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5165 }
5166#endif /* CONFIG_SAE */
5167
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005168#ifdef CONFIG_DPP
5169 if (wpa_s->current_ssid &&
5170 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5171 !data->assoc_reject.timed_out) {
5172 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5173 wpa_sm_aborted_cached(wpa_s->wpa);
5174 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5175 }
5176#endif /* CONFIG_DPP */
5177
Roshan Pius3a1667e2018-07-03 15:17:14 -07005178#ifdef CONFIG_FILS
5179 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07005180 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005181 fils_pmksa_cache_flush(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005182 eapol_sm_update_erp_next_seq_num(
5183 wpa_s->eapol,
5184 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07005185 fils_connection_failure(wpa_s);
5186 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005187#endif /* CONFIG_FILS */
5188
5189 wpas_connection_failed(wpa_s, bssid);
5190 wpa_supplicant_mark_disassoc(wpa_s);
5191}
5192
5193
Hai Shalomfdcde762020-04-02 11:19:20 -07005194static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5195 struct unprot_beacon *data)
5196{
5197 struct wpabuf *buf;
5198 int res;
5199
5200 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5201 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
5202 return;
5203 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5204 MAC2STR(data->sa));
5205
5206 buf = wpabuf_alloc(4);
5207 if (!buf)
5208 return;
5209
5210 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5211 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5212 wpabuf_put_u8(buf, 1); /* Dialog Token */
5213 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5214
5215 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5216 wpa_s->own_addr, wpa_s->bssid,
5217 wpabuf_head(buf), wpabuf_len(buf), 0);
5218 if (res < 0)
5219 wpa_printf(MSG_DEBUG,
5220 "Failed to send WNM-Notification Request frame");
5221
5222 wpabuf_free(buf);
5223}
5224
5225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005226void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
5227 union wpa_event_data *data)
5228{
5229 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005230 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07005231 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08005232#ifndef CONFIG_NO_STDOUT_DEBUG
5233 int level = MSG_DEBUG;
5234#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005235
5236 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5237 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005238 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005239 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005240 event != EVENT_SCHED_SCAN_STOPPED) {
5241 wpa_dbg(wpa_s, MSG_DEBUG,
5242 "Ignore event %s (%d) while interface is disabled",
5243 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005244 return;
5245 }
5246
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005247#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07005248 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005249 const struct ieee80211_hdr *hdr;
5250 u16 fc;
5251 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
5252 fc = le_to_host16(hdr->frame_control);
5253 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
5254 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
5255 level = MSG_EXCESSIVE;
5256 }
5257
5258 wpa_dbg(wpa_s, level, "Event %s (%d) received",
5259 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005260#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005261
5262 switch (event) {
5263 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005264#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08005265 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
5266 data->auth.ies_len))
5267 wpa_printf(MSG_DEBUG,
5268 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005269#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005270 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005271 wpa_s->auth_status_code = data->auth.status_code;
5272 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005273 break;
5274 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005275#ifdef CONFIG_TESTING_OPTIONS
5276 if (wpa_s->ignore_auth_resp) {
5277 wpa_printf(MSG_INFO,
5278 "EVENT_ASSOC - ignore_auth_resp active!");
5279 break;
5280 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005281 if (wpa_s->testing_resend_assoc) {
5282 wpa_printf(MSG_INFO,
5283 "EVENT_DEAUTH - testing_resend_assoc");
5284 break;
5285 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005286#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05305287 if (wpa_s->disconnected) {
5288 wpa_printf(MSG_INFO,
5289 "Ignore unexpected EVENT_ASSOC in disconnected state");
5290 break;
5291 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005292 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08005293 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005294 if (data &&
5295 (data->assoc_info.authorized ||
5296 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5297 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005298 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005299 if (data) {
5300 wpa_msg(wpa_s, MSG_INFO,
5301 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
5302 data->assoc_info.subnet_status);
5303 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005304 break;
5305 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005306 wpas_event_disassoc(wpa_s,
5307 data ? &data->disassoc_info : NULL);
5308 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005309 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005310#ifdef CONFIG_TESTING_OPTIONS
5311 if (wpa_s->ignore_auth_resp) {
5312 wpa_printf(MSG_INFO,
5313 "EVENT_DEAUTH - ignore_auth_resp active!");
5314 break;
5315 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005316 if (wpa_s->testing_resend_assoc) {
5317 wpa_printf(MSG_INFO,
5318 "EVENT_DEAUTH - testing_resend_assoc");
5319 break;
5320 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07005321#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005322 wpas_event_deauth(wpa_s,
5323 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005324 break;
5325 case EVENT_MICHAEL_MIC_FAILURE:
5326 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
5327 break;
5328#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005329 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005330 if (wpa_s->own_scan_requested ||
5331 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005332 struct os_reltime diff;
5333
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005334 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005335 os_reltime_sub(&wpa_s->scan_start_time,
5336 &wpa_s->scan_trigger_time, &diff);
5337 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
5338 diff.sec, diff.usec);
5339 wpa_s->own_scan_requested = 0;
5340 wpa_s->own_scan_running = 1;
5341 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
5342 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005343 wpa_msg_ctrl(wpa_s, MSG_INFO,
5344 WPA_EVENT_SCAN_STARTED "id=%u",
5345 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005346 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005347 wpa_msg_ctrl(wpa_s, MSG_INFO,
5348 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005349 }
5350 } else {
5351 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08005352 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005353 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005354 }
5355 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005356 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005357 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5358 wpa_s->scan_res_handler = NULL;
5359 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08005360 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005361 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
5362 break;
5363 }
5364
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005365 if (!(data && data->scan_info.external_scan) &&
5366 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005367 struct os_reltime now, diff;
5368 os_get_reltime(&now);
5369 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
5370 wpa_s->scan_start_time.sec = 0;
5371 wpa_s->scan_start_time.usec = 0;
5372 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
5373 diff.sec, diff.usec);
5374 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005375 if (wpa_supplicant_event_scan_results(wpa_s, data))
5376 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005377 if (!(data && data->scan_info.external_scan))
5378 wpa_s->own_scan_running = 0;
5379 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08005380 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005381 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005382 break;
5383#endif /* CONFIG_NO_SCAN_PROCESSING */
5384 case EVENT_ASSOCINFO:
5385 wpa_supplicant_event_associnfo(wpa_s, data);
5386 break;
5387 case EVENT_INTERFACE_STATUS:
5388 wpa_supplicant_event_interface_status(wpa_s, data);
5389 break;
5390 case EVENT_PMKID_CANDIDATE:
5391 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
5392 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005393#ifdef CONFIG_TDLS
5394 case EVENT_TDLS:
5395 wpa_supplicant_event_tdls(wpa_s, data);
5396 break;
5397#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005398#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005399 case EVENT_WNM:
5400 wpa_supplicant_event_wnm(wpa_s, data);
5401 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005402#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005403#ifdef CONFIG_IEEE80211R
5404 case EVENT_FT_RESPONSE:
5405 wpa_supplicant_event_ft_response(wpa_s, data);
5406 break;
5407#endif /* CONFIG_IEEE80211R */
5408#ifdef CONFIG_IBSS_RSN
5409 case EVENT_IBSS_RSN_START:
5410 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
5411 break;
5412#endif /* CONFIG_IBSS_RSN */
5413 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07005414 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005415 break;
5416 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005417 /* It is possible to get this event from earlier connection */
5418 if (wpa_s->current_ssid &&
5419 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5420 wpa_dbg(wpa_s, MSG_DEBUG,
5421 "Ignore AUTH_TIMED_OUT in mesh configuration");
5422 break;
5423 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005424 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5425 sme_event_auth_timed_out(wpa_s, data);
5426 break;
5427 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005428 /* It is possible to get this event from earlier connection */
5429 if (wpa_s->current_ssid &&
5430 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
5431 wpa_dbg(wpa_s, MSG_DEBUG,
5432 "Ignore ASSOC_TIMED_OUT in mesh configuration");
5433 break;
5434 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005435 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5436 sme_event_assoc_timed_out(wpa_s, data);
5437 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005438 case EVENT_TX_STATUS:
5439 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
5440 " type=%d stype=%d",
5441 MAC2STR(data->tx_status.dst),
5442 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08005443#ifdef CONFIG_PASN
5444 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5445 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
5446 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
5447 data->tx_status.data_len,
5448 data->tx_status.ack) == 0)
5449 break;
5450#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005451#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005452 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005453#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005454 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5455 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005456 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005457 wpa_s, data->tx_status.dst,
5458 data->tx_status.data,
5459 data->tx_status.data_len,
5460 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005461 OFFCHANNEL_SEND_ACTION_SUCCESS :
5462 OFFCHANNEL_SEND_ACTION_NO_ACK);
5463#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005464 break;
5465 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005466#endif /* CONFIG_AP */
5467#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005468 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005469 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005470 /*
5471 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005472 * interface in GO mode, or via standalone AP interface.
5473 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
5474 * except when the primary interface is used as a GO interface
5475 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005476 */
5477 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
5478 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005479 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005480 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005481 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005482 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005483 data->tx_status.data,
5484 data->tx_status.data_len,
5485 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005486 OFFCHANNEL_SEND_ACTION_SUCCESS :
5487 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005488 break;
5489 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005490#endif /* CONFIG_OFFCHANNEL */
5491#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005492 switch (data->tx_status.type) {
5493 case WLAN_FC_TYPE_MGMT:
5494 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5495 data->tx_status.data_len,
5496 data->tx_status.stype,
5497 data->tx_status.ack);
5498 break;
5499 case WLAN_FC_TYPE_DATA:
5500 ap_tx_status(wpa_s, data->tx_status.dst,
5501 data->tx_status.data,
5502 data->tx_status.data_len,
5503 data->tx_status.ack);
5504 break;
5505 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005506#endif /* CONFIG_AP */
5507 break;
5508#ifdef CONFIG_AP
5509 case EVENT_EAPOL_TX_STATUS:
5510 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5511 data->eapol_tx_status.data,
5512 data->eapol_tx_status.data_len,
5513 data->eapol_tx_status.ack);
5514 break;
5515 case EVENT_DRIVER_CLIENT_POLL_OK:
5516 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005517 break;
5518 case EVENT_RX_FROM_UNKNOWN:
5519 if (wpa_s->ap_iface == NULL)
5520 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005521 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5522 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005523 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005524#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005525
Sunil Ravi89eba102022-09-13 21:04:37 -07005526 case EVENT_LINK_CH_SWITCH_STARTED:
5527 case EVENT_LINK_CH_SWITCH:
5528 if (!data || !wpa_s->current_ssid ||
5529 !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
5530 break;
5531
5532 wpa_msg(wpa_s, MSG_INFO,
5533 "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5534 event == EVENT_LINK_CH_SWITCH ?
5535 WPA_EVENT_LINK_CHANNEL_SWITCH :
5536 WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
5537 data->ch_switch.freq,
5538 data->ch_switch.link_id,
5539 data->ch_switch.ht_enabled,
5540 data->ch_switch.ch_offset,
5541 channel_width_to_string(data->ch_switch.ch_width),
5542 data->ch_switch.cf1,
5543 data->ch_switch.cf2);
5544 if (event == EVENT_LINK_CH_SWITCH_STARTED)
5545 break;
5546
5547 wpa_s->links[data->ch_switch.link_id].freq =
5548 data->ch_switch.freq;
5549 if (wpa_s->links[data->ch_switch.link_id].bss &&
5550 wpa_s->links[data->ch_switch.link_id].bss->freq !=
5551 data->ch_switch.freq) {
5552 wpa_s->links[data->ch_switch.link_id].bss->freq =
5553 data->ch_switch.freq;
5554 notify_bss_changes(
5555 wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5556 wpa_s->links[data->ch_switch.link_id].bss);
5557 }
5558 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07005559 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005560 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005561 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005562 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005563
Hai Shalom81f62d82019-07-22 12:10:00 -07005564 wpa_msg(wpa_s, MSG_INFO,
5565 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5566 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5567 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005568 data->ch_switch.freq,
5569 data->ch_switch.ht_enabled,
5570 data->ch_switch.ch_offset,
5571 channel_width_to_string(data->ch_switch.ch_width),
5572 data->ch_switch.cf1,
5573 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005574 if (event == EVENT_CH_SWITCH_STARTED)
5575 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005576
Sunil Ravi65a724b2022-05-24 11:06:09 -07005577 if (wpa_s->assoc_freq && data->ch_switch.freq &&
5578 (int) wpa_s->assoc_freq != data->ch_switch.freq) {
5579 wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq);
5580 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005581 wpa_s->assoc_freq = data->ch_switch.freq;
5582 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005583 if (wpa_s->current_bss &&
5584 wpa_s->current_bss->freq != data->ch_switch.freq) {
5585 wpa_s->current_bss->freq = data->ch_switch.freq;
5586 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5587 wpa_s->current_bss);
5588 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005589
Hai Shalomfdcde762020-04-02 11:19:20 -07005590#ifdef CONFIG_SME
5591 switch (data->ch_switch.ch_offset) {
5592 case 1:
5593 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5594 break;
5595 case -1:
5596 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5597 break;
5598 default:
5599 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5600 break;
5601 }
5602#endif /* CONFIG_SME */
5603
Roshan Pius3a1667e2018-07-03 15:17:14 -07005604#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005605 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5606 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005607 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005608 wpa_s->current_ssid->mode ==
5609 WPAS_MODE_P2P_GROUP_FORMATION) {
5610 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5611 data->ch_switch.ht_enabled,
5612 data->ch_switch.ch_offset,
5613 data->ch_switch.ch_width,
5614 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005615 data->ch_switch.cf2,
5616 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005617 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005618#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005619
Hai Shalom899fcc72020-10-19 14:38:18 -07005620 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5621 sme_event_ch_switch(wpa_s);
5622
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005623 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005624 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005625 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005626#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005627#ifdef NEED_AP_MLME
5628 case EVENT_DFS_RADAR_DETECTED:
5629 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005630 wpas_ap_event_dfs_radar_detected(wpa_s,
5631 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005632 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005633 case EVENT_DFS_NOP_FINISHED:
5634 if (data)
5635 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5636 &data->dfs_event);
5637 break;
5638#endif /* NEED_AP_MLME */
5639#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005640 case EVENT_DFS_CAC_STARTED:
5641 if (data)
5642 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5643 break;
5644 case EVENT_DFS_CAC_FINISHED:
5645 if (data)
5646 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5647 break;
5648 case EVENT_DFS_CAC_ABORTED:
5649 if (data)
5650 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5651 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005652 case EVENT_RX_MGMT: {
5653 u16 fc, stype;
5654 const struct ieee80211_mgmt *mgmt;
5655
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005656#ifdef CONFIG_TESTING_OPTIONS
5657 if (wpa_s->ext_mgmt_frame_handling) {
5658 struct rx_mgmt *rx = &data->rx_mgmt;
5659 size_t hex_len = 2 * rx->frame_len + 1;
5660 char *hex = os_malloc(hex_len);
5661 if (hex) {
5662 wpa_snprintf_hex(hex, hex_len,
5663 rx->frame, rx->frame_len);
5664 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5665 rx->freq, rx->datarate, rx->ssi_signal,
5666 hex);
5667 os_free(hex);
5668 }
5669 break;
5670 }
5671#endif /* CONFIG_TESTING_OPTIONS */
5672
Dmitry Shmidt04949592012-07-19 12:16:46 -07005673 mgmt = (const struct ieee80211_mgmt *)
5674 data->rx_mgmt.frame;
5675 fc = le_to_host16(mgmt->frame_control);
5676 stype = WLAN_FC_GET_STYPE(fc);
5677
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005678#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005679 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005680#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005681#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005682 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005683 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005684 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005685 const u8 *ie;
5686 size_t ie_len;
5687
5688 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5689 ie_len = data->rx_mgmt.frame_len -
5690 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005691 wpas_p2p_probe_req_rx(
5692 wpa_s, src, mgmt->da,
5693 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005694 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005695 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005696 break;
5697 }
5698#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005699#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005700 if (wpa_s->current_ssid &&
5701 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5702 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005703 data->rx_mgmt.frame_len >= 30) {
5704 wpa_supplicant_event_ibss_auth(wpa_s, data);
5705 break;
5706 }
5707#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005708
5709 if (stype == WLAN_FC_STYPE_ACTION) {
5710 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005711 wpa_s, data->rx_mgmt.frame,
5712 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005713 data->rx_mgmt.freq,
5714 data->rx_mgmt.ssi_signal);
5715 break;
5716 }
5717
5718 if (wpa_s->ifmsh) {
5719 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005720 break;
5721 }
Hai Shalom60840252021-02-19 19:02:11 -08005722#ifdef CONFIG_PASN
5723 if (stype == WLAN_FC_STYPE_AUTH &&
5724 wpas_pasn_auth_rx(wpa_s, mgmt,
5725 data->rx_mgmt.frame_len) != -2)
5726 break;
5727#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005728
Roshan Pius3a1667e2018-07-03 15:17:14 -07005729#ifdef CONFIG_SAE
5730 if (stype == WLAN_FC_STYPE_AUTH &&
5731 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5732 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5733 sme_external_auth_mgmt_rx(
5734 wpa_s, data->rx_mgmt.frame,
5735 data->rx_mgmt.frame_len);
5736 break;
5737 }
5738#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005739 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5740 "management frame in non-AP mode");
5741 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005742#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005743 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005744
5745 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005746 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5747 const u8 *ie;
5748 size_t ie_len;
5749
5750 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5751 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005752
5753 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5754 mgmt->bssid, ie, ie_len,
5755 data->rx_mgmt.ssi_signal);
5756 }
5757
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005758 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005759#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005760 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005761 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005762 case EVENT_RX_PROBE_REQ:
5763 if (data->rx_probe_req.sa == NULL ||
5764 data->rx_probe_req.ie == NULL)
5765 break;
5766#ifdef CONFIG_AP
5767 if (wpa_s->ap_iface) {
5768 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5769 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005770 data->rx_probe_req.da,
5771 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005772 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005773 data->rx_probe_req.ie_len,
5774 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005775 break;
5776 }
5777#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005778 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005779 data->rx_probe_req.da,
5780 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005781 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005782 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005783 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005784 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005785 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005786 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005787#ifdef CONFIG_OFFCHANNEL
5788 offchannel_remain_on_channel_cb(
5789 wpa_s, data->remain_on_channel.freq,
5790 data->remain_on_channel.duration);
5791#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005792 wpas_p2p_remain_on_channel_cb(
5793 wpa_s, data->remain_on_channel.freq,
5794 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005795#ifdef CONFIG_DPP
5796 wpas_dpp_remain_on_channel_cb(
5797 wpa_s, data->remain_on_channel.freq,
5798 data->remain_on_channel.duration);
5799#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005800 break;
5801 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005802#ifdef CONFIG_OFFCHANNEL
5803 offchannel_cancel_remain_on_channel_cb(
5804 wpa_s, data->remain_on_channel.freq);
5805#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005806 wpas_p2p_cancel_remain_on_channel_cb(
5807 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005808#ifdef CONFIG_DPP
5809 wpas_dpp_cancel_remain_on_channel_cb(
5810 wpa_s, data->remain_on_channel.freq);
5811#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005812 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005813 case EVENT_EAPOL_RX:
5814 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5815 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00005816 data->eapol_rx.data_len,
5817 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005818 break;
5819 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005820 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5821 "above=%d signal=%d noise=%d txrate=%d",
5822 data->signal_change.above_threshold,
5823 data->signal_change.current_signal,
5824 data->signal_change.current_noise,
5825 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005826 wpa_bss_update_level(wpa_s->current_bss,
5827 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005828 bgscan_notify_signal_change(
5829 wpa_s, data->signal_change.above_threshold,
5830 data->signal_change.current_signal,
5831 data->signal_change.current_noise,
5832 data->signal_change.current_txrate);
5833 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005834 case EVENT_INTERFACE_MAC_CHANGED:
5835 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005836 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005837 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005838 case EVENT_INTERFACE_ENABLED:
5839 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5840 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomc1a21442022-02-04 13:43:00 -08005841 u8 addr[ETH_ALEN];
5842
Hai Shalomfdcde762020-04-02 11:19:20 -07005843 eloop_cancel_timeout(wpas_clear_disabled_interface,
5844 wpa_s, NULL);
Hai Shalomc1a21442022-02-04 13:43:00 -08005845 os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005846 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc1a21442022-02-04 13:43:00 -08005847 if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0)
5848 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
5849 else
5850 wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
Hai Shalomc3565922019-10-28 11:58:20 -07005851 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005852 if (wpa_s->p2p_mgmt) {
5853 wpa_supplicant_set_state(wpa_s,
5854 WPA_DISCONNECTED);
5855 break;
5856 }
5857
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005858#ifdef CONFIG_AP
5859 if (!wpa_s->ap_iface) {
5860 wpa_supplicant_set_state(wpa_s,
5861 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005862 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005863 wpa_supplicant_req_scan(wpa_s, 0, 0);
5864 } else
5865 wpa_supplicant_set_state(wpa_s,
5866 WPA_COMPLETED);
5867#else /* CONFIG_AP */
5868 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5869 wpa_supplicant_req_scan(wpa_s, 0, 0);
5870#endif /* CONFIG_AP */
5871 }
5872 break;
5873 case EVENT_INTERFACE_DISABLED:
5874 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005875#ifdef CONFIG_P2P
5876 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5877 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5878 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5879 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005880 * Mark interface disabled if this happens to end up not
5881 * being removed as a separate P2P group interface.
5882 */
5883 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5884 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005885 * The interface was externally disabled. Remove
5886 * it assuming an external entity will start a
5887 * new session if needed.
5888 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005889 if (wpa_s->current_ssid &&
5890 wpa_s->current_ssid->p2p_group)
5891 wpas_p2p_interface_unavailable(wpa_s);
5892 else
5893 wpas_p2p_disconnect(wpa_s);
5894 /*
5895 * wpa_s instance may have been freed, so must not use
5896 * it here anymore.
5897 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005898 break;
5899 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005900 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5901 p2p_in_progress(wpa_s->global->p2p) > 1) {
5902 /* This radio work will be cancelled, so clear P2P
5903 * state as well.
5904 */
5905 p2p_stop_find(wpa_s->global->p2p);
5906 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005907#endif /* CONFIG_P2P */
5908
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005909 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5910 /*
5911 * Indicate disconnection to keep ctrl_iface events
5912 * consistent.
5913 */
5914 wpa_supplicant_event_disassoc(
5915 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5916 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005917 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005918 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005919 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5920 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005921 clear_at.usec = 0;
5922 } else {
5923 struct os_reltime tmp;
5924
Hai Shalom60840252021-02-19 19:02:11 -08005925 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005926 tmp.usec = 0;
5927 os_reltime_sub(&tmp, &age, &clear_at);
5928 }
5929 eloop_register_timeout(clear_at.sec, clear_at.usec,
5930 wpas_clear_disabled_interface,
5931 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005932 radio_remove_works(wpa_s, NULL, 0);
5933
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005934 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5935 break;
5936 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005937 wpa_supplicant_update_channel_list(
5938 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005939 break;
5940 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005941 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005942 break;
5943 case EVENT_BEST_CHANNEL:
5944 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5945 "(%d %d %d)",
5946 data->best_chan.freq_24, data->best_chan.freq_5,
5947 data->best_chan.freq_overall);
5948 wpa_s->best_24_freq = data->best_chan.freq_24;
5949 wpa_s->best_5_freq = data->best_chan.freq_5;
5950 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005951 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5952 data->best_chan.freq_5,
5953 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005954 break;
5955 case EVENT_UNPROT_DEAUTH:
5956 wpa_supplicant_event_unprot_deauth(wpa_s,
5957 &data->unprot_deauth);
5958 break;
5959 case EVENT_UNPROT_DISASSOC:
5960 wpa_supplicant_event_unprot_disassoc(wpa_s,
5961 &data->unprot_disassoc);
5962 break;
5963 case EVENT_STATION_LOW_ACK:
5964#ifdef CONFIG_AP
5965 if (wpa_s->ap_iface && data)
5966 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5967 data->low_ack.addr);
5968#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005969#ifdef CONFIG_TDLS
5970 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005971 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5972 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005973#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005974 break;
5975 case EVENT_IBSS_PEER_LOST:
5976#ifdef CONFIG_IBSS_RSN
5977 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5978#endif /* CONFIG_IBSS_RSN */
5979 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005980 case EVENT_DRIVER_GTK_REKEY:
5981 if (os_memcmp(data->driver_gtk_rekey.bssid,
5982 wpa_s->bssid, ETH_ALEN))
5983 break;
5984 if (!wpa_s->wpa)
5985 break;
5986 wpa_sm_update_replay_ctr(wpa_s->wpa,
5987 data->driver_gtk_rekey.replay_ctr);
5988 break;
5989 case EVENT_SCHED_SCAN_STOPPED:
5990 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005991 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005992 wpa_supplicant_notify_scanning(wpa_s, 0);
5993
5994 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5995 break;
5996
5997 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005998 * If the driver stopped scanning without being requested to,
5999 * request a new scan to continue scanning for networks.
6000 */
6001 if (!wpa_s->sched_scan_stop_req &&
6002 wpa_s->wpa_state == WPA_SCANNING) {
6003 wpa_dbg(wpa_s, MSG_DEBUG,
6004 "Restart scanning after unexpected sched_scan stop event");
6005 wpa_supplicant_req_scan(wpa_s, 1, 0);
6006 break;
6007 }
6008
6009 wpa_s->sched_scan_stop_req = 0;
6010
6011 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08006012 * Start a new sched scan to continue searching for more SSIDs
6013 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006014 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07006015 if (wpa_s->sched_scan_timed_out) {
6016 wpa_supplicant_req_sched_scan(wpa_s);
6017 } else if (wpa_s->pno_sched_pending) {
6018 wpa_s->pno_sched_pending = 0;
6019 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07006020 } else if (resched) {
6021 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08006022 }
6023
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006024 break;
6025 case EVENT_WPS_BUTTON_PUSHED:
6026#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07006027 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006028#endif /* CONFIG_WPS */
6029 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006030 case EVENT_AVOID_FREQUENCIES:
6031 wpa_supplicant_notify_avoid_freq(wpa_s, data);
6032 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08006033 case EVENT_CONNECT_FAILED_REASON:
6034#ifdef CONFIG_AP
6035 if (!wpa_s->ap_iface || !data)
6036 break;
6037 hostapd_event_connect_failed_reason(
6038 wpa_s->ap_iface->bss[0],
6039 data->connect_failed_reason.addr,
6040 data->connect_failed_reason.code);
6041#endif /* CONFIG_AP */
6042 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006043 case EVENT_NEW_PEER_CANDIDATE:
6044#ifdef CONFIG_MESH
6045 if (!wpa_s->ifmsh || !data)
6046 break;
6047 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
6048 data->mesh_peer.ies,
6049 data->mesh_peer.ie_len);
6050#endif /* CONFIG_MESH */
6051 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006052 case EVENT_SURVEY:
6053#ifdef CONFIG_AP
6054 if (!wpa_s->ap_iface)
6055 break;
6056 hostapd_event_get_survey(wpa_s->ap_iface,
6057 &data->survey_results);
6058#endif /* CONFIG_AP */
6059 break;
6060 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08006061#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006062#ifdef CONFIG_ACS
6063 if (!wpa_s->ap_iface)
6064 break;
6065 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6066 &data->acs_selected_channels);
6067#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08006068#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006069 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006070 case EVENT_P2P_LO_STOP:
6071#ifdef CONFIG_P2P
6072 wpa_s->p2p_lo_started = 0;
6073 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6074 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6075 data->p2p_lo_stop.reason_code);
6076#endif /* CONFIG_P2P */
6077 break;
Paul Stewart092955c2017-02-06 09:13:09 -08006078 case EVENT_BEACON_LOSS:
6079 if (!wpa_s->current_bss || !wpa_s->current_ssid)
6080 break;
6081 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
6082 bgscan_notify_beacon_loss(wpa_s);
6083 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006084 case EVENT_EXTERNAL_AUTH:
6085#ifdef CONFIG_SAE
6086 if (!wpa_s->current_ssid) {
6087 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
6088 break;
6089 }
6090 sme_external_auth_trigger(wpa_s, data);
6091#endif /* CONFIG_SAE */
6092 break;
Sunil Ravi89eba102022-09-13 21:04:37 -07006093#ifdef CONFIG_PASN
6094 case EVENT_PASN_AUTH:
6095 wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6096 break;
6097#endif /* CONFIG_PASN */
Roshan Pius3a1667e2018-07-03 15:17:14 -07006098 case EVENT_PORT_AUTHORIZED:
6099 wpa_supplicant_event_port_authorized(wpa_s);
6100 break;
6101 case EVENT_STATION_OPMODE_CHANGED:
6102#ifdef CONFIG_AP
6103 if (!wpa_s->ap_iface || !data)
6104 break;
6105
6106 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
6107 data->sta_opmode.addr,
6108 data->sta_opmode.smps_mode,
6109 data->sta_opmode.chan_width,
6110 data->sta_opmode.rx_nss);
6111#endif /* CONFIG_AP */
6112 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07006113 case EVENT_UNPROT_BEACON:
6114 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6115 break;
Hai Shalomc1a21442022-02-04 13:43:00 -08006116 case EVENT_TX_WAIT_EXPIRE:
6117#ifdef CONFIG_DPP
6118 wpas_dpp_tx_wait_expire(wpa_s);
6119#endif /* CONFIG_DPP */
6120 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006121 default:
6122 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6123 break;
6124 }
6125}
Dmitry Shmidte4663042016-04-04 10:07:49 -07006126
6127
6128void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6129 union wpa_event_data *data)
6130{
6131 struct wpa_supplicant *wpa_s;
6132
6133 if (event != EVENT_INTERFACE_STATUS)
6134 return;
6135
6136 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6137 if (wpa_s && wpa_s->driver->get_ifindex) {
6138 unsigned int ifindex;
6139
6140 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6141 if (ifindex != data->interface_status.ifindex) {
6142 wpa_dbg(wpa_s, MSG_DEBUG,
6143 "interface status ifindex %d mismatch (%d)",
6144 ifindex, data->interface_status.ifindex);
6145 return;
6146 }
6147 }
6148#ifdef CONFIG_MATCH_IFACE
6149 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6150 struct wpa_interface *wpa_i;
6151
6152 wpa_i = wpa_supplicant_match_iface(
6153 ctx, data->interface_status.ifname);
6154 if (!wpa_i)
6155 return;
6156 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6157 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006158 }
6159#endif /* CONFIG_MATCH_IFACE */
6160
6161 if (wpa_s)
6162 wpa_supplicant_event(wpa_s, event, data);
6163}