blob: 9c4f9f51991cc8430840498b87abeaa1e6122bdd [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Hai Shalom021b0b52019-04-10 11:17:58 -07003 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "notify.h"
29#include "common/ieee802_11_defs.h"
30#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070031#include "common/gas_server.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070032#include "common/dpp.h"
Hai Shalom60840252021-02-19 19:02:11 -080033#include "common/ptksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "crypto/random.h"
Hai Shalom60840252021-02-19 19:02:11 -080035#include "bssid_ignore.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "wpas_glue.h"
37#include "wps_supplicant.h"
38#include "ibss_rsn.h"
39#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080040#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "p2p_supplicant.h"
42#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070043#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044#include "ap.h"
45#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080047#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080049#include "mesh.h"
50#include "mesh_mpm.h"
51#include "wmm_ac.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070052#include "dpp_supplicant.h"
Mir Ali677e7482020-11-12 19:49:02 +053053#include "rsn_supp/wpa_i.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070054
55
Hai Shalom39ba6fc2019-01-22 12:40:38 -080056#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
57
58
Dmitry Shmidt34af3062013-07-11 10:46:32 -070059#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070060static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080061 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070062#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080063
64
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070065int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080067 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070068
69 if (ssid == NULL || ssid->disabled_until.sec == 0)
70 return 0;
71
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080072 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070073 if (ssid->disabled_until.sec > now.sec)
74 return ssid->disabled_until.sec - now.sec;
75
76 wpas_clear_temp_disabled(wpa_s, ssid, 0);
77
78 return 0;
79}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080
81
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080082#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070083/**
84 * wpas_reenabled_network_time - Time until first network is re-enabled
85 * @wpa_s: Pointer to wpa_supplicant data
86 * Returns: If all enabled networks are temporarily disabled, returns the time
87 * (in sec) until the first network is re-enabled. Otherwise returns 0.
88 *
89 * This function is used in case all enabled networks are temporarily disabled,
90 * in which case it returns the time (in sec) that the first network will be
91 * re-enabled. The function assumes that at least one network is enabled.
92 */
93static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
94{
95 struct wpa_ssid *ssid;
96 int disabled_for, res = 0;
97
98#ifdef CONFIG_INTERWORKING
99 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
100 wpa_s->conf->cred)
101 return 0;
102#endif /* CONFIG_INTERWORKING */
103
104 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
105 if (ssid->disabled)
106 continue;
107
108 disabled_for = wpas_temp_disabled(wpa_s, ssid);
109 if (!disabled_for)
110 return 0;
111
112 if (!res || disabled_for < res)
113 res = disabled_for;
114 }
115
116 return res;
117}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800118#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700119
120
121void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
122{
123 struct wpa_supplicant *wpa_s = eloop_ctx;
124
125 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
126 return;
127
128 wpa_dbg(wpa_s, MSG_DEBUG,
129 "Try to associate due to network getting re-enabled");
130 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
131 wpa_supplicant_cancel_sched_scan(wpa_s);
132 wpa_supplicant_req_scan(wpa_s, 0, 0);
133 }
134}
135
136
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800137static struct wpa_bss * wpa_supplicant_get_new_bss(
138 struct wpa_supplicant *wpa_s, const u8 *bssid)
139{
140 struct wpa_bss *bss = NULL;
141 struct wpa_ssid *ssid = wpa_s->current_ssid;
142
143 if (ssid->ssid_len > 0)
144 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
145 if (!bss)
146 bss = wpa_bss_get_bssid(wpa_s, bssid);
147
148 return bss;
149}
150
151
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700152static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
153{
154 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
155
156 if (!bss) {
157 wpa_supplicant_update_scan_results(wpa_s);
158
159 /* Get the BSS from the new scan results */
160 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
161 }
162
163 if (bss)
164 wpa_s->current_bss = bss;
165}
166
167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
169{
170 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700171 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700172 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700173 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700175 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
176 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700177
178 if (wpa_s->current_ssid->ssid_len == 0)
179 return 0; /* current profile still in use */
180 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
181 if (res < 0) {
182 wpa_msg(wpa_s, MSG_INFO,
183 "Failed to read SSID from driver");
184 return 0; /* try to use current profile */
185 }
186 drv_ssid_len = res;
187
188 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
189 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
190 drv_ssid_len) == 0)
191 return 0; /* current profile still in use */
192
Hai Shalomfdcde762020-04-02 11:19:20 -0700193#ifdef CONFIG_OWE
194 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
195 wpa_s->current_bss &&
196 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
197 drv_ssid_len == wpa_s->current_bss->ssid_len &&
198 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
199 drv_ssid_len) == 0)
200 return 0; /* current profile still in use */
201#endif /* CONFIG_OWE */
202
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700203 wpa_msg(wpa_s, MSG_DEBUG,
204 "Driver-initiated BSS selection changed the SSID to %s",
205 wpa_ssid_txt(drv_ssid, drv_ssid_len));
206 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700207 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208
209 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
210 "information");
211 ssid = wpa_supplicant_get_ssid(wpa_s);
212 if (ssid == NULL) {
213 wpa_msg(wpa_s, MSG_INFO,
214 "No network configuration found for the current AP");
215 return -1;
216 }
217
Dmitry Shmidt04949592012-07-19 12:16:46 -0700218 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
220 return -1;
221 }
222
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800223 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
224 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
225 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
226 return -1;
227 }
228
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700229 res = wpas_temp_disabled(wpa_s, ssid);
230 if (res > 0) {
231 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
232 "disabled for %d second(s)", res);
233 return -1;
234 }
235
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700236 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
237 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800238 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239 u8 wpa_ie[80];
240 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800241 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
242 wpa_ie, &wpa_ie_len) < 0)
243 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700244 } else {
245 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
246 }
247
248 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
249 eapol_sm_invalidate_cached_session(wpa_s->eapol);
250 old_ssid = wpa_s->current_ssid;
251 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800252
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700253 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700255 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
256 wpa_supplicant_initiate_eapol(wpa_s);
257 if (old_ssid != wpa_s->current_ssid)
258 wpas_notify_network_changed(wpa_s);
259
260 return 0;
261}
262
263
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265{
266 struct wpa_supplicant *wpa_s = eloop_ctx;
267
268 if (wpa_s->countermeasures) {
269 wpa_s->countermeasures = 0;
270 wpa_drv_set_countermeasures(wpa_s, 0);
271 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800272
273 /*
274 * It is possible that the device is sched scanning, which means
275 * that a connection attempt will be done only when we receive
276 * scan results. However, in this case, it would be preferable
277 * to scan and connect immediately, so cancel the sched_scan and
278 * issue a regular scan flow.
279 */
280 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281 wpa_supplicant_req_scan(wpa_s, 0, 0);
282 }
283}
284
285
286void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
287{
288 int bssid_changed;
289
Dmitry Shmidt04949592012-07-19 12:16:46 -0700290 wnm_bss_keep_alive_deinit(wpa_s);
291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292#ifdef CONFIG_IBSS_RSN
293 ibss_rsn_deinit(wpa_s->ibss_rsn);
294 wpa_s->ibss_rsn = NULL;
295#endif /* CONFIG_IBSS_RSN */
296
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700297#ifdef CONFIG_AP
298 wpa_supplicant_ap_deinit(wpa_s);
299#endif /* CONFIG_AP */
300
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700301#ifdef CONFIG_HS20
302 /* Clear possibly configured frame filters */
303 wpa_drv_configure_frame_filters(wpa_s, 0);
304#endif /* CONFIG_HS20 */
305
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700306 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
307 return;
308
Hai Shalom74f70d42019-02-11 14:42:39 -0800309 if (os_reltime_initialized(&wpa_s->session_start)) {
310 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
311 wpa_s->session_start.sec = 0;
312 wpa_s->session_start.usec = 0;
313 wpas_notify_session_length(wpa_s);
314 }
315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
317 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
318 os_memset(wpa_s->bssid, 0, ETH_ALEN);
319 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800320 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321 wpa_s->current_bss = NULL;
322 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700323
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 if (bssid_changed)
325 wpas_notify_bssid_changed(wpa_s);
326
Hai Shalome21d4e82020-04-29 16:34:06 -0700327 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
328 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700329 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
330 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700331 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700332 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700333 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700334 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700335 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700336 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700337 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800338
339 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800340 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800341 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700342 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700343
344#ifdef CONFIG_TESTING_OPTIONS
345 wpa_s->last_tk_alg = WPA_ALG_NONE;
346 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
347#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700348 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800349
350 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
351 wpa_s->enabled_4addr_mode = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352}
353
354
355static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
356{
357 struct wpa_ie_data ie;
358 int pmksa_set = -1;
359 size_t i;
360
Hai Shalom899fcc72020-10-19 14:38:18 -0700361 /* Start with assumption of no PMKSA cache entry match */
362 pmksa_cache_clear_current(wpa_s->wpa);
363
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
365 ie.pmkid == NULL)
366 return;
367
368 for (i = 0; i < ie.num_pmkid; i++) {
369 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
370 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700371 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700372 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800373 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700374 break;
375 }
376 }
377
378 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
379 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
380}
381
382
383static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
384 union wpa_event_data *data)
385{
386 if (data == NULL) {
387 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
388 "event");
389 return;
390 }
391 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
392 " index=%d preauth=%d",
393 MAC2STR(data->pmkid_candidate.bssid),
394 data->pmkid_candidate.index,
395 data->pmkid_candidate.preauth);
396
397 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
398 data->pmkid_candidate.index,
399 data->pmkid_candidate.preauth);
400}
401
402
403static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
404{
405 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
406 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
407 return 0;
408
409#ifdef IEEE8021X_EAPOL
410 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
411 wpa_s->current_ssid &&
412 !(wpa_s->current_ssid->eapol_flags &
413 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
414 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
415 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
416 * plaintext or static WEP keys). */
417 return 0;
418 }
419#endif /* IEEE8021X_EAPOL */
420
421 return 1;
422}
423
424
425/**
426 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
427 * @wpa_s: pointer to wpa_supplicant data
428 * @ssid: Configuration data for the network
429 * Returns: 0 on success, -1 on failure
430 *
431 * This function is called when starting authentication with a network that is
432 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
433 */
434int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
435 struct wpa_ssid *ssid)
436{
437#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800438#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700439 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700441 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
442 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700443 return 0;
444
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700445 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 sim = 1;
447 aka = 1;
448 } else {
449 struct eap_method_type *eap = ssid->eap.eap_methods;
450 while (eap->vendor != EAP_VENDOR_IETF ||
451 eap->method != EAP_TYPE_NONE) {
452 if (eap->vendor == EAP_VENDOR_IETF) {
453 if (eap->method == EAP_TYPE_SIM)
454 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700455 else if (eap->method == EAP_TYPE_AKA ||
456 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 aka = 1;
458 }
459 eap++;
460 }
461 }
462
463 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
464 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700465 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
466 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
467 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700468 aka = 0;
469
470 if (!sim && !aka) {
471 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
472 "use SIM, but neither EAP-SIM nor EAP-AKA are "
473 "enabled");
474 return 0;
475 }
476
477 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
478 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700480 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700481 if (wpa_s->scard == NULL) {
482 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
483 "(pcsc-lite)");
484 return -1;
485 }
486 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
487 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800488#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700489#endif /* IEEE8021X_EAPOL */
490
491 return 0;
492}
493
494
495#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700496
Hai Shalomfdcde762020-04-02 11:19:20 -0700497#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700498static int has_wep_key(struct wpa_ssid *ssid)
499{
500 int i;
501
502 for (i = 0; i < NUM_WEP_KEYS; i++) {
503 if (ssid->wep_key_len[i])
504 return 1;
505 }
506
507 return 0;
508}
Hai Shalomfdcde762020-04-02 11:19:20 -0700509#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700510
511
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700512static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700513 struct wpa_ssid *ssid)
514{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700515 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516
517 if (ssid->mixed_cell)
518 return 1;
519
520#ifdef CONFIG_WPS
521 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
522 return 1;
523#endif /* CONFIG_WPS */
524
Roshan Pius3a1667e2018-07-03 15:17:14 -0700525#ifdef CONFIG_OWE
526 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
527 return 1;
528#endif /* CONFIG_OWE */
529
Hai Shalomfdcde762020-04-02 11:19:20 -0700530#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700531 if (has_wep_key(ssid))
532 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700533#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700534
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535#ifdef IEEE8021X_EAPOL
536 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
537 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
538 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
539 privacy = 1;
540#endif /* IEEE8021X_EAPOL */
541
Jouni Malinen75ecf522011-06-27 15:19:46 -0700542 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
543 privacy = 1;
544
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800545 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
546 privacy = 1;
547
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700548 if (bss->caps & IEEE80211_CAP_PRIVACY)
549 return privacy;
550 return !privacy;
551}
552
553
554static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
555 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800556 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700557{
558 struct wpa_ie_data ie;
559 int proto_match = 0;
560 const u8 *rsn_ie, *wpa_ie;
561 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700562#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700564#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700565
566 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
567 if (ret >= 0)
568 return ret;
569
Hai Shalomfdcde762020-04-02 11:19:20 -0700570#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700571 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
572 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
573 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
574 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
575 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700576#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700578 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700579 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580 proto_match++;
581
582 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800583 if (debug_print)
584 wpa_dbg(wpa_s, MSG_DEBUG,
585 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700586 break;
587 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700588 if (!ie.has_pairwise)
589 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
590 if (!ie.has_group)
591 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592
Hai Shalomfdcde762020-04-02 11:19:20 -0700593#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700594 if (wep_ok &&
595 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
596 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800597 if (debug_print)
598 wpa_dbg(wpa_s, MSG_DEBUG,
599 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700600 return 1;
601 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700602#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700603
Roshan Pius3a1667e2018-07-03 15:17:14 -0700604 if (!(ie.proto & ssid->proto) &&
605 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800606 if (debug_print)
607 wpa_dbg(wpa_s, MSG_DEBUG,
608 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 break;
610 }
611
612 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800613 if (debug_print)
614 wpa_dbg(wpa_s, MSG_DEBUG,
615 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616 break;
617 }
618
619 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800620 if (debug_print)
621 wpa_dbg(wpa_s, MSG_DEBUG,
622 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700623 break;
624 }
625
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700626 if (ssid->group_mgmt_cipher &&
627 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
628 if (debug_print)
629 wpa_dbg(wpa_s, MSG_DEBUG,
630 " skip RSN IE - group mgmt cipher mismatch");
631 break;
632 }
633
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700634 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800635 if (debug_print)
636 wpa_dbg(wpa_s, MSG_DEBUG,
637 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638 break;
639 }
640
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700641 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800642 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800643 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800644 if (debug_print)
645 wpa_dbg(wpa_s, MSG_DEBUG,
646 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647 break;
648 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800649 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
650 wpas_get_ssid_pmf(wpa_s, ssid) ==
651 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800652 if (debug_print)
653 wpa_dbg(wpa_s, MSG_DEBUG,
654 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800655 break;
656 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700657
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800658 if (debug_print)
659 wpa_dbg(wpa_s, MSG_DEBUG,
660 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 return 1;
662 }
663
Roshan Pius3a1667e2018-07-03 15:17:14 -0700664 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
665 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800666 if (debug_print)
667 wpa_dbg(wpa_s, MSG_DEBUG,
668 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700669 return 0;
670 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700671
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700672 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
674 proto_match++;
675
676 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800677 if (debug_print)
678 wpa_dbg(wpa_s, MSG_DEBUG,
679 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680 break;
681 }
682
Hai Shalomfdcde762020-04-02 11:19:20 -0700683#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 if (wep_ok &&
685 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
686 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800687 if (debug_print)
688 wpa_dbg(wpa_s, MSG_DEBUG,
689 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690 return 1;
691 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700692#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693
694 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800695 if (debug_print)
696 wpa_dbg(wpa_s, MSG_DEBUG,
697 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698 break;
699 }
700
701 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800702 if (debug_print)
703 wpa_dbg(wpa_s, MSG_DEBUG,
704 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700705 break;
706 }
707
708 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800709 if (debug_print)
710 wpa_dbg(wpa_s, MSG_DEBUG,
711 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712 break;
713 }
714
715 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800716 if (debug_print)
717 wpa_dbg(wpa_s, MSG_DEBUG,
718 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719 break;
720 }
721
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800722 if (debug_print)
723 wpa_dbg(wpa_s, MSG_DEBUG,
724 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725 return 1;
726 }
727
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700728 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
729 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800730 if (debug_print)
731 wpa_dbg(wpa_s, MSG_DEBUG,
732 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700733 return 1;
734 }
735
Roshan Pius3a1667e2018-07-03 15:17:14 -0700736#ifdef CONFIG_OWE
737 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
738 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800739 if (wpa_s->owe_transition_select &&
740 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
741 ssid->owe_transition_bss_select_count + 1 <=
742 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
743 ssid->owe_transition_bss_select_count++;
744 if (debug_print)
745 wpa_dbg(wpa_s, MSG_DEBUG,
746 " skip OWE transition BSS (selection count %d does not exceed %d)",
747 ssid->owe_transition_bss_select_count,
748 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
749 wpa_s->owe_transition_search = 1;
750 return 0;
751 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700752 if (debug_print)
753 wpa_dbg(wpa_s, MSG_DEBUG,
754 " allow in OWE transition mode");
755 return 1;
756 }
757#endif /* CONFIG_OWE */
758
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
760 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800761 if (debug_print)
762 wpa_dbg(wpa_s, MSG_DEBUG,
763 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764 return 0;
765 }
766
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800767 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
768 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800769 if (debug_print)
770 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800771 return 1;
772 }
773
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800775 if (debug_print)
776 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700777 return 1;
778 }
779
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800780 if (debug_print)
781 wpa_dbg(wpa_s, MSG_DEBUG,
782 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700783
784 return 0;
785}
786
787
788static int freq_allowed(int *freqs, int freq)
789{
790 int i;
791
792 if (freqs == NULL)
793 return 1;
794
795 for (i = 0; freqs[i]; i++)
796 if (freqs[i] == freq)
797 return 1;
798 return 0;
799}
800
801
Hai Shalomfdcde762020-04-02 11:19:20 -0700802static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
803 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800804{
805 const struct hostapd_hw_modes *mode = NULL, *modes;
806 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
807 const u8 *rate_ie;
808 int i, j, k;
809
810 if (bss->freq == 0)
811 return 1; /* Cannot do matching without knowing band */
812
813 modes = wpa_s->hw.modes;
814 if (modes == NULL) {
815 /*
816 * The driver does not provide any additional information
817 * about the utilized hardware, so allow the connection attempt
818 * to continue.
819 */
820 return 1;
821 }
822
823 for (i = 0; i < wpa_s->hw.num_modes; i++) {
824 for (j = 0; j < modes[i].num_channels; j++) {
825 int freq = modes[i].channels[j].freq;
826 if (freq == bss->freq) {
827 if (mode &&
828 mode->mode == HOSTAPD_MODE_IEEE80211G)
829 break; /* do not allow 802.11b replace
830 * 802.11g */
831 mode = &modes[i];
832 break;
833 }
834 }
835 }
836
837 if (mode == NULL)
838 return 0;
839
840 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700841 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800842 if (rate_ie == NULL)
843 continue;
844
845 for (j = 2; j < rate_ie[1] + 2; j++) {
846 int flagged = !!(rate_ie[j] & 0x80);
847 int r = (rate_ie[j] & 0x7f) * 5;
848
849 /*
850 * IEEE Std 802.11n-2009 7.3.2.2:
851 * The new BSS Membership selector value is encoded
852 * like a legacy basic rate, but it is not a rate and
853 * only indicates if the BSS members are required to
854 * support the mandatory features of Clause 20 [HT PHY]
855 * in order to join the BSS.
856 */
857 if (flagged && ((rate_ie[j] & 0x7f) ==
858 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
859 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800860 if (debug_print)
861 wpa_dbg(wpa_s, MSG_DEBUG,
862 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800863 return 0;
864 }
865 continue;
866 }
867
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700868 /* There's also a VHT selector for 802.11ac */
869 if (flagged && ((rate_ie[j] & 0x7f) ==
870 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
871 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800872 if (debug_print)
873 wpa_dbg(wpa_s, MSG_DEBUG,
874 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700875 return 0;
876 }
877 continue;
878 }
879
Hai Shalomc3565922019-10-28 11:58:20 -0700880#ifdef CONFIG_SAE
881 if (flagged && ((rate_ie[j] & 0x7f) ==
882 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700883 if (wpa_s->conf->sae_pwe == 0 &&
884 !ssid->sae_password_id &&
885 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700886 if (debug_print)
887 wpa_dbg(wpa_s, MSG_DEBUG,
888 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800889#ifdef CONFIG_TESTING_OPTIONS
890 if (wpa_s->ignore_sae_h2e_only) {
891 wpa_dbg(wpa_s, MSG_DEBUG,
892 "TESTING: Ignore SAE H2E requirement mismatch");
893 continue;
894 }
895#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700896 return 0;
897 }
898 continue;
899 }
900#endif /* CONFIG_SAE */
901
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800902 if (!flagged)
903 continue;
904
905 /* check for legacy basic rates */
906 for (k = 0; k < mode->num_rates; k++) {
907 if (mode->rates[k] == r)
908 break;
909 }
910 if (k == mode->num_rates) {
911 /*
912 * IEEE Std 802.11-2007 7.3.2.2 demands that in
913 * order to join a BSS all required rates
914 * have to be supported by the hardware.
915 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800916 if (debug_print)
917 wpa_dbg(wpa_s, MSG_DEBUG,
918 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
919 r / 10, r % 10,
920 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800921 return 0;
922 }
923 }
924 }
925
926 return 1;
927}
928
929
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800930/*
931 * Test whether BSS is in an ESS.
932 * This is done differently in DMG (60 GHz) and non-DMG bands
933 */
934static int bss_is_ess(struct wpa_bss *bss)
935{
936 if (bss_is_dmg(bss)) {
937 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
938 IEEE80211_CAP_DMG_AP;
939 }
940
941 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
942 IEEE80211_CAP_ESS);
943}
944
945
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800946static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
947{
948 size_t i;
949
950 for (i = 0; i < ETH_ALEN; i++) {
951 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
952 return 0;
953 }
954 return 1;
955}
956
957
958static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
959{
960 size_t i;
961
962 for (i = 0; i < num; i++) {
963 const u8 *a = list + i * ETH_ALEN * 2;
964 const u8 *m = a + ETH_ALEN;
965
966 if (match_mac_mask(a, addr, m))
967 return 1;
968 }
969 return 0;
970}
971
972
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700973static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
974 const u8 **ret_ssid, size_t *ret_ssid_len)
975{
976#ifdef CONFIG_OWE
977 const u8 *owe, *pos, *end, *bssid;
978 u8 ssid_len;
979 struct wpa_bss *open_bss;
980
981 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
982 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
983 return;
984
985 pos = owe + 6;
986 end = owe + 2 + owe[1];
987
988 if (end - pos < ETH_ALEN + 1)
989 return;
990 bssid = pos;
991 pos += ETH_ALEN;
992 ssid_len = *pos++;
993 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
994 return;
995
996 /* Match the profile SSID against the OWE transition mode SSID on the
997 * open network. */
998 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
999 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
1000 *ret_ssid = pos;
1001 *ret_ssid_len = ssid_len;
1002
Hai Shalomfdcde762020-04-02 11:19:20 -07001003 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1004 struct wpa_ssid *ssid;
1005
1006 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1007 if (wpas_network_disabled(wpa_s, ssid))
1008 continue;
1009 if (ssid->ssid_len == ssid_len &&
1010 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1011 /* OWE BSS in transition mode for a currently
1012 * enabled OWE network. */
1013 wpa_dbg(wpa_s, MSG_DEBUG,
1014 "OWE: transition mode OWE SSID for active OWE profile");
1015 bss->flags |= WPA_BSS_OWE_TRANSITION;
1016 break;
1017 }
1018 }
1019 }
1020
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001021 if (bss->ssid_len > 0)
1022 return;
1023
1024 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1025 if (!open_bss)
1026 return;
1027 if (ssid_len != open_bss->ssid_len ||
1028 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1029 wpa_dbg(wpa_s, MSG_DEBUG,
1030 "OWE: transition mode SSID mismatch: %s",
1031 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1032 return;
1033 }
1034
1035 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1036 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1037 wpa_dbg(wpa_s, MSG_DEBUG,
1038 "OWE: transition mode open BSS unexpected info");
1039 return;
1040 }
1041
1042 pos = owe + 6;
1043 end = owe + 2 + owe[1];
1044
1045 if (end - pos < ETH_ALEN + 1)
1046 return;
1047 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1048 wpa_dbg(wpa_s, MSG_DEBUG,
1049 "OWE: transition mode BSSID mismatch: " MACSTR,
1050 MAC2STR(pos));
1051 return;
1052 }
1053 pos += ETH_ALEN;
1054 ssid_len = *pos++;
1055 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1056 return;
1057 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1058 wpa_ssid_txt(pos, ssid_len));
1059 os_memcpy(bss->ssid, pos, ssid_len);
1060 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001061 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001062#endif /* CONFIG_OWE */
1063}
1064
1065
Sunil Ravi26978f32021-04-30 15:19:18 -07001066int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
Hai Shalomfdcde762020-04-02 11:19:20 -07001067{
1068 int i, j;
1069
1070 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1071 return 0;
1072
1073 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1074 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1075
1076 for (i = 0; i < mode->num_channels; i++) {
1077 struct hostapd_channel_data *chan = &mode->channels[i];
1078
1079 if (chan->freq == freq)
1080 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1081 }
1082 }
1083
1084 return 1;
1085}
1086
1087
Hai Shalom899fcc72020-10-19 14:38:18 -07001088static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1089 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001090 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001091 bool debug_print);
1092
1093
1094#ifdef CONFIG_SAE_PK
1095static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1096 struct wpa_bss *orig_bss,
1097 struct wpa_ssid *ssid,
1098 const u8 *match_ssid,
1099 size_t match_ssid_len)
1100{
1101 struct wpa_bss *bss;
1102
1103 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1104 int count;
1105 const u8 *ie;
1106 u8 rsnxe_capa = 0;
1107
1108 if (bss == orig_bss)
1109 continue;
1110 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1111 if (ie && ie[1] >= 1)
1112 rsnxe_capa = ie[2];
1113 if (!(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)))
1114 continue;
1115
1116 /* TODO: Could be more thorough in checking what kind of
1117 * signal strength or throughput estimate would be acceptable
1118 * compared to the originally selected BSS. */
1119 if (bss->est_throughput < 2000)
1120 return false;
1121
Hai Shalom60840252021-02-19 19:02:11 -08001122 count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
Hai Shalom899fcc72020-10-19 14:38:18 -07001123 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1124 bss, count, 0))
1125 return true;
1126 }
1127
1128 return false;
1129}
1130#endif /* CONFIG_SAE_PK */
1131
1132
1133static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1134 const u8 *match_ssid, size_t match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001135 struct wpa_bss *bss, int bssid_ignore_count,
Hai Shalom899fcc72020-10-19 14:38:18 -07001136 bool debug_print)
1137{
1138 int res;
1139 bool wpa, check_ssid, osen, rsn_osen = false;
1140 struct wpa_ie_data data;
1141#ifdef CONFIG_MBO
1142 const u8 *assoc_disallow;
1143#endif /* CONFIG_MBO */
1144#ifdef CONFIG_SAE
1145 u8 rsnxe_capa = 0;
1146#endif /* CONFIG_SAE */
1147 const u8 *ie;
1148
1149 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1150 wpa = ie && ie[1];
1151 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1152 wpa |= ie && ie[1];
1153 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1154 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1155 rsn_osen = true;
1156 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1157 osen = ie != NULL;
1158
1159#ifdef CONFIG_SAE
1160 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1161 if (ie && ie[1] >= 1)
1162 rsnxe_capa = ie[2];
1163#endif /* CONFIG_SAE */
1164
1165 check_ssid = wpa || ssid->ssid_len > 0;
1166
1167 if (wpas_network_disabled(wpa_s, ssid)) {
1168 if (debug_print)
1169 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1170 return false;
1171 }
1172
1173 res = wpas_temp_disabled(wpa_s, ssid);
1174 if (res > 0) {
1175 if (debug_print)
1176 wpa_dbg(wpa_s, MSG_DEBUG,
1177 " skip - disabled temporarily for %d second(s)",
1178 res);
1179 return false;
1180 }
1181
1182#ifdef CONFIG_WPS
Hai Shalom60840252021-02-19 19:02:11 -08001183 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001184 if (debug_print)
1185 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001186 " skip - BSSID ignored (WPS)");
Hai Shalom899fcc72020-10-19 14:38:18 -07001187 return false;
1188 }
1189
1190 if (wpa && ssid->ssid_len == 0 &&
1191 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1192 check_ssid = false;
1193
1194 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1195 /* Only allow wildcard SSID match if an AP advertises active
1196 * WPS operation that matches our mode. */
1197 check_ssid = ssid->ssid_len > 0 ||
1198 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1199 }
1200#endif /* CONFIG_WPS */
1201
1202 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1203 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1204 check_ssid = false;
1205
1206 if (check_ssid &&
1207 (match_ssid_len != ssid->ssid_len ||
1208 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1209 if (debug_print)
1210 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1211 return false;
1212 }
1213
1214 if (ssid->bssid_set &&
1215 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1216 if (debug_print)
1217 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1218 return false;
1219 }
1220
Hai Shalom60840252021-02-19 19:02:11 -08001221 /* check the list of BSSIDs to ignore */
1222 if (ssid->num_bssid_ignore &&
1223 addr_in_list(bss->bssid, ssid->bssid_ignore,
1224 ssid->num_bssid_ignore)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001225 if (debug_print)
1226 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001227 " skip - BSSID configured to be ignored");
Hai Shalom899fcc72020-10-19 14:38:18 -07001228 return false;
1229 }
1230
Hai Shalom60840252021-02-19 19:02:11 -08001231 /* if there is a list of accepted BSSIDs, only accept those APs */
1232 if (ssid->num_bssid_accept &&
1233 !addr_in_list(bss->bssid, ssid->bssid_accept,
1234 ssid->num_bssid_accept)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001235 if (debug_print)
1236 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001237 " skip - BSSID not in list of accepted values");
Hai Shalom899fcc72020-10-19 14:38:18 -07001238 return false;
1239 }
1240
1241 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1242 return false;
1243
1244 if (!osen && !wpa &&
1245 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1246 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1247 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1248 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1249 if (debug_print)
1250 wpa_dbg(wpa_s, MSG_DEBUG,
1251 " skip - non-WPA network not allowed");
1252 return false;
1253 }
1254
1255#ifdef CONFIG_WEP
1256 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1257 if (debug_print)
1258 wpa_dbg(wpa_s, MSG_DEBUG,
1259 " skip - ignore WPA/WPA2 AP for WEP network block");
1260 return false;
1261 }
1262#endif /* CONFIG_WEP */
1263
1264 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1265 if (debug_print)
1266 wpa_dbg(wpa_s, MSG_DEBUG,
1267 " skip - non-OSEN network not allowed");
1268 return false;
1269 }
1270
1271 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1272 if (debug_print)
1273 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1274 return false;
1275 }
1276
1277 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1278 !bss_is_pbss(bss)) {
1279 if (debug_print)
1280 wpa_dbg(wpa_s, MSG_DEBUG,
1281 " skip - not ESS, PBSS, or MBSS");
1282 return false;
1283 }
1284
1285 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1286 if (debug_print)
1287 wpa_dbg(wpa_s, MSG_DEBUG,
1288 " skip - PBSS mismatch (ssid %d bss %d)",
1289 ssid->pbss, bss_is_pbss(bss));
1290 return false;
1291 }
1292
1293 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1294 if (debug_print)
1295 wpa_dbg(wpa_s, MSG_DEBUG,
1296 " skip - frequency not allowed");
1297 return false;
1298 }
1299
1300#ifdef CONFIG_MESH
1301 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1302 ssid->frequency != bss->freq) {
1303 if (debug_print)
1304 wpa_dbg(wpa_s, MSG_DEBUG,
1305 " skip - frequency not allowed (mesh)");
1306 return false;
1307 }
1308#endif /* CONFIG_MESH */
1309
1310 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1311 if (debug_print)
1312 wpa_dbg(wpa_s, MSG_DEBUG,
1313 " skip - rate sets do not match");
1314 return false;
1315 }
1316
1317#ifdef CONFIG_SAE
1318 if ((wpa_s->conf->sae_pwe == 1 || ssid->sae_password_id) &&
1319 wpa_s->conf->sae_pwe != 3 && wpa_key_mgmt_sae(ssid->key_mgmt) &&
1320 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1321 if (debug_print)
1322 wpa_dbg(wpa_s, MSG_DEBUG,
1323 " skip - SAE H2E required, but not supported by the AP");
1324 return false;
1325 }
1326#endif /* CONFIG_SAE */
1327
1328#ifdef CONFIG_SAE_PK
1329 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1330 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1331 if (debug_print)
1332 wpa_dbg(wpa_s, MSG_DEBUG,
1333 " skip - SAE-PK required, but not supported by the AP");
1334 return false;
1335 }
1336#endif /* CONFIG_SAE_PK */
1337
1338#ifndef CONFIG_IBSS_RSN
1339 if (ssid->mode == WPAS_MODE_IBSS &&
1340 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1341 if (debug_print)
1342 wpa_dbg(wpa_s, MSG_DEBUG,
1343 " skip - IBSS RSN not supported in the build");
1344 return false;
1345 }
1346#endif /* !CONFIG_IBSS_RSN */
1347
1348#ifdef CONFIG_P2P
1349 if (ssid->p2p_group &&
1350 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1351 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1352 if (debug_print)
1353 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1354 return false;
1355 }
1356
1357 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1358 struct wpabuf *p2p_ie;
1359 u8 dev_addr[ETH_ALEN];
1360
1361 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1362 if (!ie) {
1363 if (debug_print)
1364 wpa_dbg(wpa_s, MSG_DEBUG,
1365 " skip - no P2P element");
1366 return false;
1367 }
1368 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1369 if (!p2p_ie) {
1370 if (debug_print)
1371 wpa_dbg(wpa_s, MSG_DEBUG,
1372 " skip - could not fetch P2P element");
1373 return false;
1374 }
1375
1376 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1377 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1378 if (debug_print)
1379 wpa_dbg(wpa_s, MSG_DEBUG,
1380 " skip - no matching GO P2P Device Address in P2P element");
1381 wpabuf_free(p2p_ie);
1382 return false;
1383 }
1384 wpabuf_free(p2p_ie);
1385 }
1386
1387 /*
1388 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1389 * P2P Group Capability Bitmap and we are not in Group Formation with
1390 * that device.
1391 */
1392#endif /* CONFIG_P2P */
1393
1394 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1395 struct os_reltime diff;
1396
1397 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1398 if (debug_print)
1399 wpa_dbg(wpa_s, MSG_DEBUG,
1400 " skip - scan result not recent enough (%u.%06u seconds too old)",
1401 (unsigned int) diff.sec,
1402 (unsigned int) diff.usec);
1403 return false;
1404 }
1405#ifdef CONFIG_MBO
1406#ifdef CONFIG_TESTING_OPTIONS
1407 if (wpa_s->ignore_assoc_disallow)
1408 goto skip_assoc_disallow;
1409#endif /* CONFIG_TESTING_OPTIONS */
1410 assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1411 if (assoc_disallow && assoc_disallow[1] >= 1) {
1412 if (debug_print)
1413 wpa_dbg(wpa_s, MSG_DEBUG,
1414 " skip - MBO association disallowed (reason %u)",
1415 assoc_disallow[2]);
1416 return false;
1417 }
1418
1419 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1420 if (debug_print)
1421 wpa_dbg(wpa_s, MSG_DEBUG,
1422 " skip - AP temporarily disallowed");
1423 return false;
1424 }
1425#ifdef CONFIG_TESTING_OPTIONS
1426skip_assoc_disallow:
1427#endif /* CONFIG_TESTING_OPTIONS */
1428#endif /* CONFIG_MBO */
1429
1430#ifdef CONFIG_DPP
1431 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1432 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1433 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1434 !ssid->dpp_csign)) {
1435 if (debug_print)
1436 wpa_dbg(wpa_s, MSG_DEBUG,
1437 " skip - no PMKSA entry for DPP");
1438 return false;
1439 }
1440#endif /* CONFIG_DPP */
1441
1442#ifdef CONFIG_SAE_PK
1443 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1444 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1445 ((ssid->sae_password &&
1446 sae_pk_valid_password(ssid->sae_password)) ||
1447 (!ssid->sae_password && ssid->passphrase &&
1448 sae_pk_valid_password(ssid->passphrase))) &&
1449 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1450 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1451 match_ssid_len)) {
1452 if (debug_print)
1453 wpa_dbg(wpa_s, MSG_DEBUG,
1454 " skip - another acceptable BSS with SAE-PK in the same ESS");
1455 return false;
1456 }
1457#endif /* CONFIG_SAE_PK */
1458
1459 if (bss->ssid_len == 0) {
1460 if (debug_print)
1461 wpa_dbg(wpa_s, MSG_DEBUG,
1462 " skip - no SSID known for the BSS");
1463 return false;
1464 }
1465
1466 /* Matching configuration found */
1467 return true;
1468}
1469
1470
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001471struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1472 int i, struct wpa_bss *bss,
1473 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001474 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001475{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001476 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001477 const u8 *ie;
1478 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001479 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001480 const u8 *match_ssid;
1481 size_t match_ssid_len;
Hai Shalom60840252021-02-19 19:02:11 -08001482 int bssid_ignore_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001483
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001484 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001485 wpa_ie_len = ie ? ie[1] : 0;
1486
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001487 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001488 rsn_ie_len = ie ? ie[1] : 0;
1489
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001490 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1491 osen = ie != NULL;
1492
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001493 if (debug_print) {
1494 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1495 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1496 i, MAC2STR(bss->bssid),
1497 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1498 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1499 bss->freq,
1500 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1501 " wps" : "",
1502 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1503 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1504 ? " p2p" : "",
1505 osen ? " osen=1" : "");
1506 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001507
Hai Shalom60840252021-02-19 19:02:11 -08001508 bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1509 if (bssid_ignore_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001510 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001511 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001512 /*
1513 * When only a single network is enabled, we can
Hai Shalom60840252021-02-19 19:02:11 -08001514 * trigger BSSID ignoring on the first failure. This
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001515 * should not be done with multiple enabled networks to
1516 * avoid getting forced to move into a worse ESS on
1517 * single error if there are no other BSSes of the
1518 * current ESS.
1519 */
1520 limit = 0;
1521 }
Hai Shalom60840252021-02-19 19:02:11 -08001522 if (bssid_ignore_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001523 if (debug_print) {
1524 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom60840252021-02-19 19:02:11 -08001525 " skip - BSSID ignored (count=%d limit=%d)",
1526 bssid_ignore_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001527 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528 return NULL;
1529 }
1530 }
1531
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001532 match_ssid = bss->ssid;
1533 match_ssid_len = bss->ssid_len;
1534 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1535
1536 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001537 if (debug_print)
1538 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001539 return NULL;
1540 }
1541
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001542 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001543 if (debug_print)
1544 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001545 return NULL;
1546 }
1547
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001548 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001549 if (debug_print)
1550 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001551 return NULL;
1552 }
1553
Hai Shalomfdcde762020-04-02 11:19:20 -07001554 if (disabled_freq(wpa_s, bss->freq)) {
1555 if (debug_print)
1556 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1557 return NULL;
1558 }
1559
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001560 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001561 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
Hai Shalom60840252021-02-19 19:02:11 -08001562 bss, bssid_ignore_count, debug_print))
Hai Shalom899fcc72020-10-19 14:38:18 -07001563 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001564 }
1565
1566 /* No matching configuration found */
1567 return NULL;
1568}
1569
1570
1571static struct wpa_bss *
1572wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001573 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001574 struct wpa_ssid **selected_ssid,
1575 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001576{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001577 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001578
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001579 if (wpa_s->current_ssid) {
1580 struct wpa_ssid *ssid;
1581
1582 wpa_dbg(wpa_s, MSG_DEBUG,
1583 "Scan results matching the currently selected network");
1584 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1585 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1586
1587 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1588 only_first_ssid, 0);
1589 if (ssid != wpa_s->current_ssid)
1590 continue;
1591 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1592 " freq=%d level=%d snr=%d est_throughput=%u",
1593 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1594 bss->snr, bss->est_throughput);
1595 }
1596 }
1597
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001598 if (only_first_ssid)
1599 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1600 group->id);
1601 else
1602 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1603 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001604
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001605 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1606 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001607
1608 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001609 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001610 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001611 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001612 if (!*selected_ssid)
1613 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001614 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001615 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001616 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001617 MAC2STR(bss->bssid),
1618 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1619 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001620 }
1621
1622 return NULL;
1623}
1624
1625
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001626struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1627 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001628{
1629 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001630 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001631 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001632 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001633
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001634 if (wpa_s->last_scan_res == NULL ||
1635 wpa_s->last_scan_res_used == 0)
1636 return NULL; /* no scan results from last update */
1637
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001638 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001639 /* check that next_ssid is still valid */
1640 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1641 if (ssid == wpa_s->next_ssid)
1642 break;
1643 }
1644 next_ssid = ssid;
1645 wpa_s->next_ssid = NULL;
1646 }
1647
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001648 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001649 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1650 if (next_ssid && next_ssid->priority ==
1651 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001652 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001653 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001654 if (selected)
1655 break;
1656 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001657 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001658 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001659 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660 if (selected)
1661 break;
1662 }
1663
Hai Shalom60840252021-02-19 19:02:11 -08001664 if (selected == NULL && wpa_s->bssid_ignore &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001665 !wpa_s->countermeasures) {
Hai Shalom60840252021-02-19 19:02:11 -08001666 wpa_dbg(wpa_s, MSG_DEBUG,
1667 "No APs found - clear BSSID ignore list and try again");
1668 wpa_bssid_ignore_clear(wpa_s);
1669 wpa_s->bssid_ignore_cleared = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001670 } else if (selected == NULL)
1671 break;
1672 }
1673
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001674 ssid = *selected_ssid;
1675 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1676 !ssid->passphrase && !ssid->ext_psk) {
1677 const char *field_name, *txt = NULL;
1678
1679 wpa_dbg(wpa_s, MSG_DEBUG,
1680 "PSK/passphrase not yet available for the selected network");
1681
1682 wpas_notify_network_request(wpa_s, ssid,
1683 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1684
1685 field_name = wpa_supplicant_ctrl_req_to_string(
1686 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1687 if (field_name == NULL)
1688 return NULL;
1689
1690 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1691
1692 selected = NULL;
1693 }
1694
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001695 return selected;
1696}
1697
1698
1699static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1700 int timeout_sec, int timeout_usec)
1701{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001702 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001703 /*
1704 * No networks are enabled; short-circuit request so
1705 * we don't wait timeout seconds before transitioning
1706 * to INACTIVE state.
1707 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001708 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1709 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001710 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1711 return;
1712 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001713
1714 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1716}
1717
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001718
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001719int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001720 struct wpa_bss *selected,
1721 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001722{
1723 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1724 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1725 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001726 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001727#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001728 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1729 wpa_s->p2p_in_provisioning) {
1730 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1731 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001732 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001733 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001734#endif /* CONFIG_P2P */
1735
1736#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001737 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001738 wpas_wps_cancel(wpa_s);
1739#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001740 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001741 }
1742
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001743 wpa_msg(wpa_s, MSG_DEBUG,
1744 "Considering connect request: reassociate: %d selected: "
1745 MACSTR " bssid: " MACSTR " pending: " MACSTR
1746 " wpa_state: %s ssid=%p current_ssid=%p",
1747 wpa_s->reassociate, MAC2STR(selected->bssid),
1748 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1749 wpa_supplicant_state_txt(wpa_s->wpa_state),
1750 ssid, wpa_s->current_ssid);
1751
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001752 /*
1753 * Do not trigger new association unless the BSSID has changed or if
1754 * reassociation is requested. If we are in process of associating with
1755 * the selected BSSID, do not trigger new attempt.
1756 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001757 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001758 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1759 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1760 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001761 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1762 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1763 0) ||
1764 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1765 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001766 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1767 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001768 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001769 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001770 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1771 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001772 wpa_supplicant_associate(wpa_s, selected, ssid);
1773 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001774 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1775 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001776 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001777
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001778 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001779}
1780
1781
1782static struct wpa_ssid *
1783wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1784{
Hai Shalomfdcde762020-04-02 11:19:20 -07001785 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001786 struct wpa_ssid *ssid;
1787
1788 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1789 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1790 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001791 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001792 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001793#ifndef CONFIG_IBSS_RSN
1794 if (ssid->mode == WPAS_MODE_IBSS &&
1795 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1796 WPA_KEY_MGMT_WPA_NONE))) {
1797 wpa_msg(wpa_s, MSG_INFO,
1798 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1799 wpa_ssid_txt(ssid->ssid,
1800 ssid->ssid_len));
1801 continue;
1802 }
1803#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001804 if (ssid->mode == WPAS_MODE_IBSS ||
1805 ssid->mode == WPAS_MODE_AP ||
1806 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001807 return ssid;
1808 }
1809 }
1810 return NULL;
1811}
1812
1813
1814/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1815 * on BSS added and BSS changed events */
1816static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001817 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001818{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001819 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820
1821 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1822 return;
1823
Jouni Malinen87fd2792011-05-16 18:35:42 +03001824 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001825 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001826
Jouni Malinen87fd2792011-05-16 18:35:42 +03001827 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001828 if (ssid == NULL)
1829 continue;
1830
Jouni Malinen87fd2792011-05-16 18:35:42 +03001831 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001832 if (rsn == NULL)
1833 continue;
1834
Jouni Malinen87fd2792011-05-16 18:35:42 +03001835 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001836 }
1837
1838}
1839
1840
Hai Shalomfdcde762020-04-02 11:19:20 -07001841#ifndef CONFIG_NO_ROAMING
1842
1843static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1844{
1845 if (noise == WPA_INVALID_NOISE)
1846 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1847 DEFAULT_NOISE_FLOOR_2GHZ;
1848 return avg_signal - noise;
1849}
1850
1851
1852static unsigned int
1853wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1854 const struct wpa_bss *bss, int snr)
1855{
1856 int rate = wpa_bss_get_max_rate(bss);
Hai Shalom60840252021-02-19 19:02:11 -08001857 const u8 *ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -07001858 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1859
1860 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr);
1861}
1862
Hai Shalomfdcde762020-04-02 11:19:20 -07001863
Hai Shalom899fcc72020-10-19 14:38:18 -07001864int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1865 struct wpa_bss *current_bss,
1866 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001867{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001868 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001869 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001870 int cur_level;
1871 unsigned int cur_est, sel_est;
1872 struct wpa_signal_info si;
1873 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001874 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001875
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001876 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001877 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001878 " freq=%d level=%d snr=%d est_throughput=%u",
1879 MAC2STR(current_bss->bssid),
1880 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001881 current_bss->snr, current_bss->est_throughput);
1882 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001883 " freq=%d level=%d snr=%d est_throughput=%u",
1884 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001885 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001886
1887 if (wpa_s->current_ssid->bssid_set &&
1888 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1889 0) {
1890 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1891 "has preferred BSSID");
1892 return 1;
1893 }
1894
Hai Shalomfdcde762020-04-02 11:19:20 -07001895 cur_level = current_bss->level;
1896 cur_est = current_bss->est_throughput;
1897 sel_est = selected->est_throughput;
1898
1899 /*
1900 * Try to poll the signal from the driver since this will allow to get
1901 * more accurate values. In some cases, there can be big differences
1902 * between the RSSI of the Probe Response frames of the AP we are
1903 * associated with and the Beacon frames we hear from the same AP after
1904 * association. This can happen, e.g., when there are two antennas that
1905 * hear the AP very differently. If the driver chooses to hear the
1906 * Probe Response frames during the scan on the "bad" antenna because
1907 * it wants to save power, but knows to choose the other antenna after
1908 * association, we will hear our AP with a low RSSI as part of the
1909 * scan even when we can hear it decently on the other antenna. To cope
1910 * with this, ask the driver to teach us how it hears the AP. Also, the
1911 * scan results may be a bit old, since we can very quickly get fresh
1912 * information about our currently associated AP.
1913 */
1914 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1915 (si.avg_beacon_signal || si.avg_signal)) {
1916 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1917 si.avg_signal;
1918 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
1919 si.current_noise);
1920
1921 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
1922 current_bss,
1923 cur_snr);
1924 wpa_dbg(wpa_s, MSG_DEBUG,
1925 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
1926 cur_level, cur_snr, cur_est);
1927 }
1928
1929 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001930 wpa_dbg(wpa_s, MSG_DEBUG,
1931 "Allow reassociation - selected BSS has better estimated throughput");
1932 return 1;
1933 }
1934
Dmitry Shmidte4663042016-04-04 10:07:49 -07001935 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1936
Hai Shalomfdcde762020-04-02 11:19:20 -07001937 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
1938 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001939 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1940 "signal level");
1941 return 0;
1942 }
1943
Hai Shalomfdcde762020-04-02 11:19:20 -07001944 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001945 wpa_dbg(wpa_s, MSG_DEBUG,
1946 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001947 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001948 }
1949
Hai Shalomfdcde762020-04-02 11:19:20 -07001950 if (cur_snr > GREAT_SNR) {
1951 wpa_dbg(wpa_s, MSG_DEBUG,
1952 "Skip roam - Current BSS has good SNR (%u > %u)",
1953 cur_snr, GREAT_SNR);
1954 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001955 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001956
Hai Shalomfdcde762020-04-02 11:19:20 -07001957 if (cur_level < -85) /* ..-86 dBm */
1958 min_diff = 1;
1959 else if (cur_level < -80) /* -85..-81 dBm */
1960 min_diff = 2;
1961 else if (cur_level < -75) /* -80..-76 dBm */
1962 min_diff = 3;
1963 else if (cur_level < -70) /* -75..-71 dBm */
1964 min_diff = 4;
1965 else if (cur_level < 0) /* -70..-1 dBm */
1966 min_diff = 5;
1967 else /* unspecified units (not in dBm) */
1968 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001969
Hai Shalomfdcde762020-04-02 11:19:20 -07001970 if (cur_est > sel_est * 1.5)
1971 min_diff += 10;
1972 else if (cur_est > sel_est * 1.2)
1973 min_diff += 5;
1974 else if (cur_est > sel_est * 1.1)
1975 min_diff += 2;
1976 else if (cur_est > sel_est)
1977 min_diff++;
1978 else if (sel_est > cur_est * 1.5)
1979 min_diff -= 10;
1980 else if (sel_est > cur_est * 1.2)
1981 min_diff -= 5;
1982 else if (sel_est > cur_est * 1.1)
1983 min_diff -= 2;
1984 else if (sel_est > cur_est)
1985 min_diff--;
1986
1987 if (to_5ghz)
1988 min_diff -= 2;
1989 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001990 if (diff < min_diff) {
1991 wpa_dbg(wpa_s, MSG_DEBUG,
1992 "Skip roam - too small difference in signal level (%d < %d)",
1993 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07001994 ret = 0;
1995 } else {
1996 wpa_dbg(wpa_s, MSG_DEBUG,
1997 "Allow reassociation due to difference in signal level (%d >= %d)",
1998 diff, min_diff);
1999 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002000 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002001 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2002 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2003 " sel_freq=%d sel_level=%d sel_est=%d",
2004 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2005 MAC2STR(current_bss->bssid),
2006 current_bss->freq, cur_level, cur_est,
2007 MAC2STR(selected->bssid),
2008 selected->freq, selected->level, sel_est);
2009 return ret;
2010}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002011
Hai Shalom899fcc72020-10-19 14:38:18 -07002012#endif /* CONFIG_NO_ROAMING */
2013
2014
2015static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2016 struct wpa_bss *selected,
2017 struct wpa_ssid *ssid)
2018{
2019 struct wpa_bss *current_bss = NULL;
2020
2021 if (wpa_s->reassociate)
2022 return 1; /* explicit request to reassociate */
2023 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2024 return 1; /* we are not associated; continue */
2025 if (wpa_s->current_ssid == NULL)
2026 return 1; /* unknown current SSID */
2027 if (wpa_s->current_ssid != ssid)
2028 return 1; /* different network block */
2029
2030 if (wpas_driver_bss_selection(wpa_s))
2031 return 0; /* Driver-based roaming */
2032
2033 if (wpa_s->current_ssid->ssid)
2034 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2035 wpa_s->current_ssid->ssid,
2036 wpa_s->current_ssid->ssid_len);
2037 if (!current_bss)
2038 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2039
2040 if (!current_bss)
2041 return 1; /* current BSS not seen in scan results */
2042
2043 if (current_bss == selected)
2044 return 0;
2045
2046 if (selected->last_update_idx > current_bss->last_update_idx)
2047 return 1; /* current BSS not seen in the last scan */
2048
2049#ifndef CONFIG_NO_ROAMING
2050 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2051 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002052#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002053 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002054#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002055}
2056
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002057
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002058/*
2059 * Return a negative value if no scan results could be fetched or if scan
2060 * results should not be shared with other virtual interfaces.
2061 * Return 0 if scan results were fetched and may be shared with other
2062 * interfaces.
2063 * Return 1 if scan results may be shared with other virtual interfaces but may
2064 * not trigger any operations.
2065 * Return 2 if the interface was removed and cannot be used.
2066 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002067static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002068 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002069 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002070{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002071 struct wpa_scan_results *scan_res = NULL;
2072 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002073 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002074#ifndef CONFIG_NO_RANDOM_POOL
2075 size_t i, num;
2076#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077
2078#ifdef CONFIG_AP
2079 if (wpa_s->ap_iface)
2080 ap = 1;
2081#endif /* CONFIG_AP */
2082
2083 wpa_supplicant_notify_scanning(wpa_s, 0);
2084
2085 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2086 data ? &data->scan_info :
2087 NULL, 1);
2088 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002089 if (wpa_s->conf->ap_scan == 2 || ap ||
2090 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002091 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002092 if (!own_request)
2093 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002094 if (data && data->scan_info.external_scan)
2095 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002096 if (wpa_s->scan_res_fail_handler) {
2097 void (*handler)(struct wpa_supplicant *wpa_s);
2098
2099 handler = wpa_s->scan_res_fail_handler;
2100 wpa_s->scan_res_fail_handler = NULL;
2101 handler(wpa_s);
2102 } else {
2103 wpa_dbg(wpa_s, MSG_DEBUG,
2104 "Failed to get scan results - try scanning again");
2105 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2106 }
2107
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002108 ret = -1;
2109 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002110 }
2111
2112#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002113 num = scan_res->num;
2114 if (num > 10)
2115 num = 10;
2116 for (i = 0; i < num; i++) {
2117 u8 buf[5];
2118 struct wpa_scan_res *res = scan_res->res[i];
2119 buf[0] = res->bssid[5];
2120 buf[1] = res->qual & 0xff;
2121 buf[2] = res->noise & 0xff;
2122 buf[3] = res->level & 0xff;
2123 buf[4] = res->tsf & 0xff;
2124 random_add_randomness(buf, sizeof(buf));
2125 }
2126#endif /* CONFIG_NO_RANDOM_POOL */
2127
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002128 if (update_only) {
2129 ret = 1;
2130 goto scan_work_done;
2131 }
2132
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002133 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002134 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002135 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2136 struct wpa_scan_results *scan_res);
2137
2138 scan_res_handler = wpa_s->scan_res_handler;
2139 wpa_s->scan_res_handler = NULL;
2140 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002141 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002142 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002143 }
2144
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002145 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002146 wpa_s->own_scan_running,
2147 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002148 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002149 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2150 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002151 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2152 wpa_s->manual_scan_id);
2153 wpa_s->manual_scan_use_id = 0;
2154 } else {
2155 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2156 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002157 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002158
2159 wpas_notify_scan_done(wpa_s, 1);
2160
Hai Shalomfdcde762020-04-02 11:19:20 -07002161 if (ap) {
2162 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2163#ifdef CONFIG_AP
2164 if (wpa_s->ap_iface->scan_cb)
2165 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2166#endif /* CONFIG_AP */
2167 goto scan_work_done;
2168 }
2169
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002170 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002171 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 -07002172 wpa_scan_results_free(scan_res);
2173 return 0;
2174 }
2175
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002176 if (wnm_scan_process(wpa_s, 1) > 0)
2177 goto scan_work_done;
2178
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002179 if (sme_proc_obss_scan(wpa_s, scan_res) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002180 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002181
Hai Shalom021b0b52019-04-10 11:17:58 -07002182 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002183 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2184 goto scan_work_done;
2185
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002186 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2187 goto scan_work_done;
2188
2189 if (autoscan_notify_scan(wpa_s, scan_res))
2190 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002191
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002192 if (wpa_s->disconnected) {
2193 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002194 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002195 }
2196
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002197 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002198 bgscan_notify_scan(wpa_s, scan_res) == 1)
2199 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002200
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002201 wpas_wps_update_ap_info(wpa_s, scan_res);
2202
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002203 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2204 wpa_s->wpa_state < WPA_COMPLETED)
2205 goto scan_work_done;
2206
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002207 wpa_scan_results_free(scan_res);
2208
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002209 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002210 struct wpa_radio_work *work = wpa_s->scan_work;
2211 wpa_s->scan_work = NULL;
2212 radio_work_done(work);
2213 }
2214
Hai Shalomc3565922019-10-28 11:58:20 -07002215 os_free(wpa_s->last_scan_freqs);
2216 wpa_s->last_scan_freqs = NULL;
2217 wpa_s->num_last_scan_freqs = 0;
2218 if (own_request && data &&
2219 data->scan_info.freqs && data->scan_info.num_freqs) {
2220 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2221 data->scan_info.num_freqs);
2222 if (wpa_s->last_scan_freqs) {
2223 os_memcpy(wpa_s->last_scan_freqs,
2224 data->scan_info.freqs,
2225 sizeof(int) * data->scan_info.num_freqs);
2226 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2227 }
2228 }
2229
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002230 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002231
2232scan_work_done:
2233 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002234 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002235 struct wpa_radio_work *work = wpa_s->scan_work;
2236 wpa_s->scan_work = NULL;
2237 radio_work_done(work);
2238 }
2239 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002240}
2241
2242
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002243static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002244 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002245{
2246 struct wpa_bss *selected;
2247 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002248 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2249
2250 if (time_to_reenable > 0) {
2251 wpa_dbg(wpa_s, MSG_DEBUG,
2252 "Postpone network selection by %d seconds since all networks are disabled",
2253 time_to_reenable);
2254 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2255 eloop_register_timeout(time_to_reenable, 0,
2256 wpas_network_reenabled, wpa_s, NULL);
2257 return 0;
2258 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002259
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002260 if (wpa_s->p2p_mgmt)
2261 return 0; /* no normal connection on p2p_mgmt interface */
2262
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002263 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002264 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002265
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002266#ifdef CONFIG_MESH
2267 if (wpa_s->ifmsh) {
2268 wpa_msg(wpa_s, MSG_INFO,
2269 "Avoiding join because we already joined a mesh group");
2270 return 0;
2271 }
2272#endif /* CONFIG_MESH */
2273
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274 if (selected) {
2275 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002276 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002277 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002278 if (new_scan)
2279 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002280 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002281 }
2282
Hai Shalomc3565922019-10-28 11:58:20 -07002283 wpa_s->suitable_network++;
2284
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002285 if (ssid != wpa_s->current_ssid &&
2286 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2287 wpa_s->own_disconnect_req = 1;
2288 wpa_supplicant_deauthenticate(
2289 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2290 }
2291
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002292 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002293 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002294 return -1;
2295 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002296 if (new_scan)
2297 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002298 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002299 * Do not allow other virtual radios to trigger operations based
2300 * on these scan results since we do not want them to start
2301 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002302 */
2303 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002304 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002305 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2307 ssid = wpa_supplicant_pick_new_network(wpa_s);
2308 if (ssid) {
2309 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2310 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002311 if (new_scan)
2312 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002313 } else if (own_request) {
2314 /*
2315 * No SSID found. If SCAN results are as a result of
2316 * own scan request and not due to a scan request on
2317 * another shared interface, try another scan.
2318 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002319 int timeout_sec = wpa_s->scan_interval;
2320 int timeout_usec = 0;
2321#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002322 int res;
2323
2324 res = wpas_p2p_scan_no_go_seen(wpa_s);
2325 if (res == 2)
2326 return 2;
2327 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002328 return 0;
2329
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002330 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002331 wpa_s->show_group_started ||
2332 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002333 /*
2334 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002335 * state and during P2P join-a-group operation
2336 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002337 */
2338 timeout_sec = 0;
2339 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002340 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2341 timeout_usec);
2342 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002343 }
2344#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002345#ifdef CONFIG_INTERWORKING
2346 if (wpa_s->conf->auto_interworking &&
2347 wpa_s->conf->interworking &&
2348 wpa_s->conf->cred) {
2349 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2350 "start ANQP fetch since no matching "
2351 "networks found");
2352 wpa_s->network_select = 1;
2353 wpa_s->auto_network_select = 1;
2354 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002355 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002356 }
2357#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002358#ifdef CONFIG_WPS
2359 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2360 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2361 timeout_sec = 0;
2362 timeout_usec = 500000;
2363 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2364 timeout_usec);
2365 return 0;
2366 }
2367#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002368#ifdef CONFIG_OWE
2369 if (wpa_s->owe_transition_search) {
2370 wpa_dbg(wpa_s, MSG_DEBUG,
2371 "OWE: Use shorter wait during transition mode search");
2372 timeout_sec = 0;
2373 timeout_usec = 500000;
2374 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2375 timeout_usec);
2376 return 0;
2377 }
2378#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002379 if (wpa_supplicant_req_sched_scan(wpa_s))
2380 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2381 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002382
2383 wpa_msg_ctrl(wpa_s, MSG_INFO,
2384 WPA_EVENT_NETWORK_NOT_FOUND);
Sunil Ravi07c17622021-01-11 12:00:53 -08002385 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002386 }
2387 }
2388 return 0;
2389}
2390
2391
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002392static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2393 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002394{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002395 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002396 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002397
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002398 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002399 if (res == 2) {
2400 /*
2401 * Interface may have been removed, so must not dereference
2402 * wpa_s after this.
2403 */
2404 return 1;
2405 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002406
2407 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002408 /*
2409 * If no scan results could be fetched, then no need to
2410 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002411 * this scan. Similarly, if scan results started a new operation on this
2412 * interface, do not notify other interfaces to avoid concurrent
2413 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002414 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002415 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002416 }
2417
2418 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002419 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002420 * so, they get updated with this same scan info.
2421 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002422 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2423 radio_list) {
2424 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002425 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2426 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002427 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2428 res > 0);
2429 if (res < 0)
2430 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002431 }
2432 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002433
2434 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002435}
2436
2437#endif /* CONFIG_NO_SCAN_PROCESSING */
2438
2439
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002440int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2441{
2442#ifdef CONFIG_NO_SCAN_PROCESSING
2443 return -1;
2444#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002445 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002446
Dmitry Shmidt29333592017-01-09 12:27:11 -08002447 wpa_s->ignore_post_flush_scan_res = 0;
2448
Dmitry Shmidt41712582015-06-29 11:02:15 -07002449 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002450 return -1;
2451
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002452 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002453 if (os_reltime_expired(&now, &wpa_s->last_scan,
Hai Shalom60840252021-02-19 19:02:11 -08002454 wpa_s->conf->scan_res_valid_for_connect)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002455 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2456 return -1;
2457 }
2458
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002459 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002460#endif /* CONFIG_NO_SCAN_PROCESSING */
2461}
2462
Dmitry Shmidt04949592012-07-19 12:16:46 -07002463#ifdef CONFIG_WNM
2464
2465static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2466{
2467 struct wpa_supplicant *wpa_s = eloop_ctx;
2468
2469 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2470 return;
2471
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002472 if (!wpa_s->no_keep_alive) {
2473 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2474 MAC2STR(wpa_s->bssid));
2475 /* TODO: could skip this if normal data traffic has been sent */
2476 /* TODO: Consider using some more appropriate data frame for
2477 * this */
2478 if (wpa_s->l2)
2479 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2480 (u8 *) "", 0);
2481 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002482
2483#ifdef CONFIG_SME
2484 if (wpa_s->sme.bss_max_idle_period) {
2485 unsigned int msec;
2486 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2487 if (msec > 100)
2488 msec -= 100;
2489 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2490 wnm_bss_keep_alive, wpa_s, NULL);
2491 }
2492#endif /* CONFIG_SME */
2493}
2494
2495
2496static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2497 const u8 *ies, size_t ies_len)
2498{
2499 struct ieee802_11_elems elems;
2500
2501 if (ies == NULL)
2502 return;
2503
2504 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2505 return;
2506
2507#ifdef CONFIG_SME
2508 if (elems.bss_max_idle_period) {
2509 unsigned int msec;
2510 wpa_s->sme.bss_max_idle_period =
2511 WPA_GET_LE16(elems.bss_max_idle_period);
2512 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2513 "TU)%s", wpa_s->sme.bss_max_idle_period,
2514 (elems.bss_max_idle_period[2] & 0x01) ?
2515 " (protected keep-live required)" : "");
2516 if (wpa_s->sme.bss_max_idle_period == 0)
2517 wpa_s->sme.bss_max_idle_period = 1;
2518 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2519 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2520 /* msec times 1000 */
2521 msec = wpa_s->sme.bss_max_idle_period * 1024;
2522 if (msec > 100)
2523 msec -= 100;
2524 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2525 wnm_bss_keep_alive, wpa_s,
2526 NULL);
2527 }
2528 }
2529#endif /* CONFIG_SME */
2530}
2531
2532#endif /* CONFIG_WNM */
2533
2534
2535void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2536{
2537#ifdef CONFIG_WNM
2538 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2539#endif /* CONFIG_WNM */
2540}
2541
2542
Dmitry Shmidt051af732013-10-22 13:52:46 -07002543#ifdef CONFIG_INTERWORKING
2544
2545static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2546 size_t len)
2547{
2548 int res;
2549
2550 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2551 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2552 if (res) {
2553 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2554 }
2555
2556 return res;
2557}
2558
2559
2560static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2561 const u8 *ies, size_t ies_len)
2562{
2563 struct ieee802_11_elems elems;
2564
2565 if (ies == NULL)
2566 return;
2567
2568 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2569 return;
2570
2571 if (elems.qos_map_set) {
2572 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2573 elems.qos_map_set_len);
2574 }
2575}
2576
2577#endif /* CONFIG_INTERWORKING */
2578
2579
Hai Shalom74f70d42019-02-11 14:42:39 -08002580static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2581 const u8 *ies, size_t ies_len)
2582{
2583 struct ieee802_11_elems elems;
2584 const u8 *map_sub_elem, *pos;
2585 size_t len;
2586
Hai Shalomfdcde762020-04-02 11:19:20 -07002587 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002588
Hai Shalomfdcde762020-04-02 11:19:20 -07002589 if (!ies ||
2590 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2591 !elems.multi_ap || elems.multi_ap_len < 7)
2592 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002593
2594 pos = elems.multi_ap + 4;
2595 len = elems.multi_ap_len - 4;
2596
2597 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002598 if (!map_sub_elem || map_sub_elem[1] < 1)
2599 return;
2600
2601 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2602 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2603 MULTI_AP_FRONTHAUL_BSS);
2604 wpa_s->multi_ap_ie = 1;
2605}
2606
2607
2608static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2609{
2610 if (!wpa_s->current_ssid ||
2611 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2612 return;
2613
2614 if (!wpa_s->multi_ap_ie) {
2615 wpa_printf(MSG_INFO,
2616 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002617 goto fail;
2618 }
2619
Hai Shalomfdcde762020-04-02 11:19:20 -07002620 if (!wpa_s->multi_ap_backhaul) {
2621 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002622 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2623 wpa_printf(MSG_INFO,
2624 "WPS active, accepting fronthaul-only BSS");
2625 /* Don't set 4addr mode in this case, so just return */
2626 return;
2627 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002628 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2629 goto fail;
2630 }
2631
2632 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2633 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2634 goto fail;
2635 }
2636 wpa_s->enabled_4addr_mode = 1;
2637 return;
2638
2639fail:
2640 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2641}
2642
2643
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002644#ifdef CONFIG_FST
2645static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2646 const u8 *ie, size_t ie_len)
2647{
2648 struct mb_ies_info mb_ies;
2649
2650 if (!ie || !ie_len || !wpa_s->fst)
2651 return -ENOENT;
2652
2653 os_memset(&mb_ies, 0, sizeof(mb_ies));
2654
2655 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2656 size_t len;
2657
2658 len = 2 + ie[1];
2659 if (len > ie_len) {
2660 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2661 ie, ie_len);
2662 break;
2663 }
2664
2665 if (ie[0] == WLAN_EID_MULTI_BAND) {
2666 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2667 (unsigned int) len);
2668 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2669 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2670 mb_ies.nof_ies++;
2671 }
2672
2673 ie_len -= len;
2674 ie += len;
2675 }
2676
2677 if (mb_ies.nof_ies > 0) {
2678 wpabuf_free(wpa_s->received_mb_ies);
2679 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2680 return 0;
2681 }
2682
2683 return -ENOENT;
2684}
2685#endif /* CONFIG_FST */
2686
2687
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002688static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2689 union wpa_event_data *data)
2690{
Hai Shalomc3565922019-10-28 11:58:20 -07002691 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002692 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002693 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002694 bool bssid_known;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002695
2696 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07002697 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002698 if (data->assoc_info.req_ies)
2699 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2700 data->assoc_info.req_ies_len);
2701 if (data->assoc_info.resp_ies) {
2702 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2703 data->assoc_info.resp_ies_len);
2704#ifdef CONFIG_TDLS
2705 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2706 data->assoc_info.resp_ies_len);
2707#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002708#ifdef CONFIG_WNM
2709 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2710 data->assoc_info.resp_ies_len);
2711#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002712#ifdef CONFIG_INTERWORKING
2713 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2714 data->assoc_info.resp_ies_len);
2715#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002716 if (wpa_s->hw_capab == CAPAB_VHT &&
2717 get_ie(data->assoc_info.resp_ies,
2718 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2719 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002720
2721 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2722 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002723 }
2724 if (data->assoc_info.beacon_ies)
2725 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2726 data->assoc_info.beacon_ies,
2727 data->assoc_info.beacon_ies_len);
2728 if (data->assoc_info.freq)
2729 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2730 data->assoc_info.freq);
2731
Hai Shalom021b0b52019-04-10 11:17:58 -07002732 wpa_s->connection_set = 0;
2733 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2734 struct ieee802_11_elems req_elems, resp_elems;
2735
2736 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2737 data->assoc_info.req_ies_len,
2738 &req_elems, 0) != ParseFailed &&
2739 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2740 data->assoc_info.resp_ies_len,
2741 &resp_elems, 0) != ParseFailed) {
2742 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07002743 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
2744 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07002745 wpa_s->connection_ht = req_elems.ht_capabilities &&
2746 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07002747 /* Do not include subset of VHT on 2.4 GHz vendor
2748 * extension in consideration for reporting VHT
2749 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07002750 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002751 resp_elems.vht_capabilities &&
2752 (!data->assoc_info.freq ||
2753 wpas_freq_to_band(data->assoc_info.freq) !=
2754 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07002755 wpa_s->connection_he = req_elems.he_capabilities &&
2756 resp_elems.he_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08002757
2758 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
2759 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
2760 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
2761 max_nss_rx_req : max_nss_rx_resp;
2762 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
2763 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
2764 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
2765 max_nss_tx_req : max_nss_tx_resp;
2766
2767 struct supported_chan_width sta_supported_chan_width =
2768 get_supported_channel_width(&req_elems);
2769 enum chan_width ap_operation_chan_width =
2770 get_operation_channel_width(&resp_elems);
2771 if (wpa_s->connection_vht || wpa_s->connection_he) {
2772 wpa_s->connection_channel_bandwidth =
2773 get_sta_operation_chan_width(ap_operation_chan_width,
2774 sta_supported_chan_width);
2775 } else if (wpa_s->connection_ht) {
2776 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
2777 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
2778 } else {
2779 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
2780 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002781 }
2782 }
2783
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002784 p = data->assoc_info.req_ies;
2785 l = data->assoc_info.req_ies_len;
2786
2787 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
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 }
Hai Shalomc3565922019-10-28 11:58:20 -07002795 if (!found &&
2796 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2797 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2798 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2799 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2800 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002801 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2802 break;
2803 found = 1;
2804 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07002805 }
2806 if (!found_x && p[0] == WLAN_EID_RSNX) {
2807 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
2808 break;
2809 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002810 }
2811 l -= len;
2812 p += len;
2813 }
2814 if (!found && data->assoc_info.req_ies)
2815 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002816 if (!found_x && data->assoc_info.req_ies)
2817 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002818
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002819#ifdef CONFIG_FILS
2820#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002821 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2822 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002823 (!data->assoc_info.resp_frame ||
2824 fils_process_assoc_resp(wpa_s->wpa,
2825 data->assoc_info.resp_frame,
2826 data->assoc_info.resp_frame_len) < 0)) {
2827 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2828 return -1;
2829 }
2830#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002831
2832 /* Additional processing for FILS when SME is in driver */
2833 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2834 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2835 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002836#endif /* CONFIG_FILS */
2837
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002838#ifdef CONFIG_OWE
2839 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07002840 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002841 owe_process_assoc_resp(wpa_s->wpa, bssid,
2842 data->assoc_info.resp_ies,
2843 data->assoc_info.resp_ies_len) < 0)) {
2844 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2845 return -1;
2846 }
2847#endif /* CONFIG_OWE */
2848
Hai Shalom021b0b52019-04-10 11:17:58 -07002849#ifdef CONFIG_DPP2
2850 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002851 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
2852 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002853 struct ieee802_11_elems elems;
2854
2855 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2856 data->assoc_info.resp_ies_len,
2857 &elems, 0) == ParseFailed ||
2858 !elems.owe_dh)
2859 goto no_pfs;
2860 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2861 elems.owe_dh_len) < 0) {
2862 wpa_supplicant_deauthenticate(wpa_s,
2863 WLAN_REASON_UNSPECIFIED);
2864 return -1;
2865 }
2866
2867 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2868 }
2869no_pfs:
2870#endif /* CONFIG_DPP2 */
2871
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002872#ifdef CONFIG_IEEE80211R
2873#ifdef CONFIG_SME
2874 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002875 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002876 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2877 data->assoc_info.resp_ies,
2878 data->assoc_info.resp_ies_len,
2879 bssid) < 0) {
2880 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2881 "Reassociation Response failed");
2882 wpa_supplicant_deauthenticate(
2883 wpa_s, WLAN_REASON_INVALID_IE);
2884 return -1;
2885 }
2886 }
2887
2888 p = data->assoc_info.resp_ies;
2889 l = data->assoc_info.resp_ies_len;
2890
2891#ifdef CONFIG_WPS_STRICT
2892 if (p && wpa_s->current_ssid &&
2893 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2894 struct wpabuf *wps;
2895 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2896 if (wps == NULL) {
2897 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2898 "include WPS IE in (Re)Association Response");
2899 return -1;
2900 }
2901
2902 if (wps_validate_assoc_resp(wps) < 0) {
2903 wpabuf_free(wps);
2904 wpa_supplicant_deauthenticate(
2905 wpa_s, WLAN_REASON_INVALID_IE);
2906 return -1;
2907 }
2908 wpabuf_free(wps);
2909 }
2910#endif /* CONFIG_WPS_STRICT */
2911
2912 /* Go through the IEs and make a copy of the MDIE, if present. */
2913 while (p && l >= 2) {
2914 len = p[1] + 2;
2915 if (len > l) {
2916 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2917 p, l);
2918 break;
2919 }
2920 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2921 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2922 wpa_s->sme.ft_used = 1;
2923 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2924 MOBILITY_DOMAIN_ID_LEN);
2925 break;
2926 }
2927 l -= len;
2928 p += len;
2929 }
2930#endif /* CONFIG_SME */
Mir Ali677e7482020-11-12 19:49:02 +05302931#ifdef CONFIG_DRIVER_NL80211_BRCM
2932 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) &&
2933 wpa_ft_is_completed(wpa_s->wpa)) {
2934 return 0;
2935 }
2936#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002937
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002938 /* Process FT when SME is in the driver */
2939 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2940 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002941 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002942 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2943 data->assoc_info.resp_ies,
2944 data->assoc_info.resp_ies_len,
2945 bssid) < 0) {
2946 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2947 "Reassociation Response failed");
2948 wpa_supplicant_deauthenticate(
2949 wpa_s, WLAN_REASON_INVALID_IE);
2950 return -1;
2951 }
2952 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2953 }
2954
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002955 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2956 data->assoc_info.resp_ies_len);
2957#endif /* CONFIG_IEEE80211R */
2958
Hai Shalom899fcc72020-10-19 14:38:18 -07002959 if (bssid_known)
2960 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
2961 data->assoc_info.resp_ies,
2962 data->assoc_info.resp_ies_len);
2963
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002964 /* WPA/RSN IE from Beacon/ProbeResp */
2965 p = data->assoc_info.beacon_ies;
2966 l = data->assoc_info.beacon_ies_len;
2967
2968 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2969 */
2970 wpa_found = rsn_found = 0;
2971 while (p && l >= 2) {
2972 len = p[1] + 2;
2973 if (len > l) {
2974 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2975 p, l);
2976 break;
2977 }
2978 if (!wpa_found &&
2979 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2980 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2981 wpa_found = 1;
2982 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2983 }
2984
2985 if (!rsn_found &&
2986 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2987 rsn_found = 1;
2988 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2989 }
2990
Hai Shalomc3565922019-10-28 11:58:20 -07002991 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
2992 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
2993
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002994 l -= len;
2995 p += len;
2996 }
2997
2998 if (!wpa_found && data->assoc_info.beacon_ies)
2999 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003000 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003001 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07003002 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3003 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003004 if (wpa_found || rsn_found)
3005 wpa_s->ap_ies_from_associnfo = 1;
3006
Jouni Malinen87fd2792011-05-16 18:35:42 +03003007 if (wpa_s->assoc_freq && data->assoc_info.freq &&
3008 wpa_s->assoc_freq != data->assoc_info.freq) {
3009 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3010 "%u to %u MHz",
3011 wpa_s->assoc_freq, data->assoc_info.freq);
3012 wpa_supplicant_update_scan_results(wpa_s);
3013 }
3014
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003015 wpa_s->assoc_freq = data->assoc_info.freq;
3016
3017 return 0;
3018}
3019
3020
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003021static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3022{
Hai Shalomc3565922019-10-28 11:58:20 -07003023 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003024
3025 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3026 return -1;
3027
3028 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3029 return 0;
3030
3031 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3032 WPA_IE_VENDOR_TYPE);
3033 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003034 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003035
3036 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3037 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3038 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003039 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3040 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3041 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003042 return -1;
3043
3044 return 0;
3045}
3046
3047
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003048static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3049 union wpa_event_data *data)
3050{
3051#ifdef CONFIG_FST
3052 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3053 struct wpa_bss *bss = wpa_s->current_bss;
3054 const u8 *ieprb, *iebcn;
3055
3056 wpabuf_free(wpa_s->received_mb_ies);
3057 wpa_s->received_mb_ies = NULL;
3058
3059 if (ai &&
3060 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3061 wpa_printf(MSG_DEBUG,
3062 "FST: MB IEs updated from Association Response frame");
3063 return;
3064 }
3065
3066 if (ai &&
3067 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3068 wpa_printf(MSG_DEBUG,
3069 "FST: MB IEs updated from association event Beacon IEs");
3070 return;
3071 }
3072
3073 if (!bss)
3074 return;
3075
Hai Shalom60840252021-02-19 19:02:11 -08003076 ieprb = wpa_bss_ie_ptr(bss);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003077 iebcn = ieprb + bss->ie_len;
3078
3079 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3080 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3081 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3082 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3083#endif /* CONFIG_FST */
3084}
3085
3086
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003087static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3088 union wpa_event_data *data)
3089{
3090 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003091 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003092 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003093#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3094 struct wpa_bss *bss;
3095#endif /* CONFIG_FILS || CONFIG_MBO */
Mir Ali677e7482020-11-12 19:49:02 +05303096#ifdef CONFIG_DRIVER_NL80211_BRCM
3097 struct wpa_ie_data ie;
3098#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003099
3100#ifdef CONFIG_AP
3101 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003102 if (!data)
3103 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003104 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3105 data->assoc_info.addr,
3106 data->assoc_info.req_ies,
3107 data->assoc_info.req_ies_len,
3108 data->assoc_info.reassoc);
3109 return;
3110 }
3111#endif /* CONFIG_AP */
3112
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003113 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003114 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003115
Mir Ali677e7482020-11-12 19:49:02 +05303116#ifdef CONFIG_DRIVER_NL80211_BRCM
3117 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3118 struct wpa_ft_ies parse;
3119 /* Check for FT reassociation is done by the driver */
3120#ifdef CONFIG_IEEE80211R
3121 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
3122 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) && (wpa_s->key_mgmt == ie.key_mgmt)) {
3123 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3124 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3125 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3126 return;
3127 }
3128 if (parse.rsn_pmkid != NULL) {
3129 wpa_set_ft_completed(wpa_s->wpa);
3130 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3131 }
3132 }
3133#endif /* CONFIG_IEEE80211R */
3134 }
3135#endif /* CONFIG_DRIVER_NL80211_BRCM */
3136
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003137 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
3138 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3139 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003140 /*
3141 * FILS authentication can share the same mechanism to mark the
3142 * connection fully authenticated, so set ft_completed also based on
3143 * FILS result.
3144 */
3145 if (!ft_completed)
3146 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003147
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003148 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3149 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003150 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003151 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3152 return;
3153 }
3154
Mir Ali677e7482020-11-12 19:49:02 +05303155#ifdef CONFIG_DRIVER_NL80211_BRCM
3156 /* For driver based roaming, insert PSK during the initial association */
3157 if (is_zero_ether_addr(wpa_s->bssid) &&
3158 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3159 /* In case the driver wants to handle re-assocs, pass it down the PMK. */
3160 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3161 wpa_sm_install_pmk(wpa_s->wpa);
3162 }
3163#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003164 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003165 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003166 if (os_reltime_initialized(&wpa_s->session_start)) {
3167 os_reltime_age(&wpa_s->session_start,
3168 &wpa_s->session_length);
3169 wpa_s->session_start.sec = 0;
3170 wpa_s->session_start.usec = 0;
3171 wpas_notify_session_length(wpa_s);
3172 } else {
3173 wpas_notify_auth_changed(wpa_s);
3174 os_get_reltime(&wpa_s->session_start);
3175 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003176 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3177 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003178 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003179 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003180 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3181 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003182 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003183
3184 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3185 wpa_clear_keys(wpa_s, bssid);
3186 }
3187 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003188 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003189 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3190 return;
3191 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003192 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003193
Hai Shalomfdcde762020-04-02 11:19:20 -07003194 multi_ap_set_4addr_mode(wpa_s);
3195
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003196 if (wpa_s->conf->ap_scan == 1 &&
3197 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003198 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3199 wpa_msg(wpa_s, MSG_WARNING,
3200 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003201 }
3202
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003203 wpas_fst_update_mb_assoc(wpa_s, data);
3204
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003205#ifdef CONFIG_SME
3206 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3207 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003208 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003209#endif /* CONFIG_SME */
3210
3211 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3212 if (wpa_s->current_ssid) {
3213 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3214 * initialized before association, but for other modes,
3215 * initialize PC/SC here, if the current configuration needs
3216 * smartcard or SIM/USIM. */
3217 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3218 }
3219 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3220 if (wpa_s->l2)
3221 l2_packet_notify_auth_start(wpa_s->l2);
3222
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003223 already_authorized = data && data->assoc_info.authorized;
3224
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003225 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003226 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003227 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3228 * state machine may transit to AUTHENTICATING state based on obsolete
3229 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3230 * AUTHENTICATED without ever giving chance to EAP state machine to
3231 * reset the state.
3232 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003233 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003234 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3235 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003236 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003237 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3238 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3239 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003240 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003241 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003242 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003243 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003244 wpa_s->eapol_received = 0;
3245 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3246 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3247 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003248 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003249 if (wpa_s->current_ssid &&
3250 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003251 (wpa_s->drv_flags &
3252 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3253 /*
3254 * Set the key after having received joined-IBSS event
3255 * from the driver.
3256 */
3257 wpa_supplicant_set_wpa_none_key(wpa_s,
3258 wpa_s->current_ssid);
3259 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003260 wpa_supplicant_cancel_auth_timeout(wpa_s);
3261 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3262 } else if (!ft_completed) {
3263 /* Timeout for receiving the first EAPOL packet */
3264 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3265 }
3266 wpa_supplicant_cancel_scan(wpa_s);
3267
Hai Shalom5f92bc92019-04-18 11:54:11 -07003268 if (ft_completed) {
3269 /*
3270 * FT protocol completed - make sure EAPOL state machine ends
3271 * up in authenticated.
3272 */
3273 wpa_supplicant_cancel_auth_timeout(wpa_s);
3274 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003275 eapol_sm_notify_portValid(wpa_s->eapol, true);
3276 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003277 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3278 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003279 /*
3280 * We are done; the driver will take care of RSN 4-way
3281 * handshake.
3282 */
3283 wpa_supplicant_cancel_auth_timeout(wpa_s);
3284 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003285 eapol_sm_notify_portValid(wpa_s->eapol, true);
3286 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003287 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003288 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3289 /*
3290 * The driver will take care of RSN 4-way handshake, so we need
3291 * to allow EAPOL supplicant to complete its work without
3292 * waiting for WPA supplicant.
3293 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003294 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003295 }
3296
Jouni Malinena05074c2012-12-21 21:35:35 +02003297 wpa_s->last_eapol_matches_bssid = 0;
3298
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003299#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003300 if (wpa_s->rsne_override_eapol) {
3301 wpa_printf(MSG_DEBUG,
3302 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3303 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3304 wpabuf_head(wpa_s->rsne_override_eapol),
3305 wpabuf_len(wpa_s->rsne_override_eapol));
3306 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003307 if (wpa_s->rsnxe_override_eapol) {
3308 wpa_printf(MSG_DEBUG,
3309 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3310 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3311 wpabuf_head(wpa_s->rsnxe_override_eapol),
3312 wpabuf_len(wpa_s->rsnxe_override_eapol));
3313 }
3314#endif /* CONFIG_TESTING_OPTIONS */
3315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003316 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003317 struct os_reltime now, age;
3318 os_get_reltime(&now);
3319 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003320 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003321 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3322 0) {
3323 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3324 "frame that was received just before "
3325 "association notification");
3326 wpa_supplicant_rx_eapol(
3327 wpa_s, wpa_s->pending_eapol_rx_src,
3328 wpabuf_head(wpa_s->pending_eapol_rx),
3329 wpabuf_len(wpa_s->pending_eapol_rx));
3330 }
3331 wpabuf_free(wpa_s->pending_eapol_rx);
3332 wpa_s->pending_eapol_rx = NULL;
3333 }
3334
Hai Shalomfdcde762020-04-02 11:19:20 -07003335#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003336 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3337 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003338 wpa_s->current_ssid &&
3339 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003340 /* Set static WEP keys again */
3341 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3342 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003343#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003344
3345#ifdef CONFIG_IBSS_RSN
3346 if (wpa_s->current_ssid &&
3347 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3348 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3349 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3350 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003351 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003352 if (!wpa_s->ibss_rsn) {
3353 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3354 wpa_supplicant_deauthenticate(
3355 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3356 return;
3357 }
3358
3359 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3360 }
3361#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003362
3363 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003364
3365 if (data) {
3366 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3367 data->assoc_info.resp_ies_len,
3368 &data->assoc_info.wmm_params);
3369
3370 if (wpa_s->reassoc_same_bss)
3371 wmm_ac_restore_tspecs(wpa_s);
3372 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003373
Hai Shalomc3565922019-10-28 11:58:20 -07003374#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3375 bss = wpa_bss_get_bssid(wpa_s, bssid);
3376#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003377#ifdef CONFIG_FILS
3378 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003379 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3380
3381 if (fils_cache_id)
3382 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3383 }
3384#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003385
3386#ifdef CONFIG_MBO
3387 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3388#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003389
3390#ifdef CONFIG_DPP2
3391 wpa_s->dpp_pfs_fallback = 0;
3392#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003393}
3394
3395
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003396static int disconnect_reason_recoverable(u16 reason_code)
3397{
3398 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3399 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3400 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3401}
3402
3403
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003404static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003405 u16 reason_code,
3406 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003407{
3408 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003409
3410 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3411 /*
3412 * At least Host AP driver and a Prism3 card seemed to be
3413 * generating streams of disconnected events when configuring
3414 * IBSS for WPA-None. Ignore them for now.
3415 */
3416 return;
3417 }
3418
3419 bssid = wpa_s->bssid;
3420 if (is_zero_ether_addr(bssid))
3421 bssid = wpa_s->pending_bssid;
3422
3423 if (!is_zero_ether_addr(bssid) ||
3424 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3425 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3426 " reason=%d%s",
3427 MAC2STR(bssid), reason_code,
3428 locally_generated ? " locally_generated=1" : "");
3429 }
3430}
3431
3432
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003433static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3434 int locally_generated)
3435{
3436 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003437 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003438 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3439 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003440 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003441
3442 /*
3443 * It looks like connection was lost while trying to go through PSK
3444 * 4-way handshake. Filter out known disconnection cases that are caused
3445 * by something else than PSK mismatch to avoid confusing reports.
3446 */
3447
3448 if (locally_generated) {
3449 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3450 return 0;
3451 }
3452
3453 return 1;
3454}
3455
3456
Jouni Malinen2b89da82012-08-31 22:04:41 +03003457static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3458 u16 reason_code,
3459 int locally_generated)
3460{
3461 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003462 int authenticating;
3463 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003464 struct wpa_bss *fast_reconnect = NULL;
3465 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003466 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003467 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003468
3469 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3470 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3471
3472 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3473 /*
3474 * At least Host AP driver and a Prism3 card seemed to be
3475 * generating streams of disconnected events when configuring
3476 * IBSS for WPA-None. Ignore them for now.
3477 */
3478 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3479 "IBSS/WPA-None mode");
3480 return;
3481 }
3482
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003483 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3484 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3485 locally_generated)
3486 /*
3487 * Remove the inactive AP (which is probably out of range) from
3488 * the BSS list after marking disassociation. In particular
3489 * mac80211-based drivers use the
3490 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3491 * locally generated disconnection events for cases where the
3492 * AP does not reply anymore.
3493 */
3494 curr = wpa_s->current_bss;
3495
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003496 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003497 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3498 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003499 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3500 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003501 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003502#ifdef CONFIG_DPP2
3503 wpas_dpp_send_conn_status_result(wpa_s,
3504 DPP_STATUS_AUTH_FAILURE);
3505#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003506 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003507 if (!wpa_s->disconnected &&
3508 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003509 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003510 wpas_wps_searching(wpa_s) ||
3511 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003512 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003513 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003514 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003515 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003516 wpa_s->wpa_state);
3517 if (wpa_s->wpa_state == WPA_COMPLETED &&
3518 wpa_s->current_ssid &&
3519 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003520 (wpa_s->own_reconnect_req ||
3521 (!locally_generated &&
3522 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003523 /*
3524 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003525 * us, but could allow us to get back in. This is also
3526 * triggered for cases where local reconnection request
3527 * is used to force reassociation with the same BSS.
3528 * Try to reconnect to the same BSS without a full scan
3529 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003530 */
3531 fast_reconnect = wpa_s->current_bss;
3532 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003533 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003534 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003535 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003536 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3537 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003538 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003539 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003540 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003541 "try to re-connect");
3542 wpa_s->reassociate = 0;
3543 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003544 if (!wpa_s->pno)
3545 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003546 }
3547 bssid = wpa_s->bssid;
3548 if (is_zero_ether_addr(bssid))
3549 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003550 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3551 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003552 wpa_sm_notify_disassoc(wpa_s->wpa);
Hai Shalom60840252021-02-19 19:02:11 -08003553 ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
3554
Dmitry Shmidt04949592012-07-19 12:16:46 -07003555 if (locally_generated)
3556 wpa_s->disconnect_reason = -reason_code;
3557 else
3558 wpa_s->disconnect_reason = reason_code;
3559 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003560 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3561 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003562 wpa_clear_keys(wpa_s, wpa_s->bssid);
3563 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003564 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003565 wpa_supplicant_mark_disassoc(wpa_s);
3566
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003567 if (curr)
3568 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3569
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003570 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003571 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003572 wpa_s->current_ssid = last_ssid;
3573 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003574
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003575 if (fast_reconnect &&
3576 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3577 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3578 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3579 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003580 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003581 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003582#ifndef CONFIG_NO_SCAN_PROCESSING
3583 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3584 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3585 fast_reconnect_ssid) < 0) {
3586 /* Recover through full scan */
3587 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3588 }
3589#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003590 } else if (fast_reconnect) {
3591 /*
3592 * Could not reconnect to the same BSS due to network being
3593 * disabled. Use a new scan to match the alternative behavior
3594 * above, i.e., to continue automatic reconnection attempt in a
3595 * way that enforces disabled network rules.
3596 */
3597 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003598 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003599}
3600
3601
3602#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003603void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003604{
3605 struct wpa_supplicant *wpa_s = eloop_ctx;
3606
3607 if (!wpa_s->pending_mic_error_report)
3608 return;
3609
3610 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3611 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3612 wpa_s->pending_mic_error_report = 0;
3613}
3614#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3615
3616
3617static void
3618wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3619 union wpa_event_data *data)
3620{
3621 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003622 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003623
3624 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3625 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003626 os_get_reltime(&t);
3627 if ((wpa_s->last_michael_mic_error.sec &&
3628 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003629 wpa_s->pending_mic_error_report) {
3630 if (wpa_s->pending_mic_error_report) {
3631 /*
3632 * Send the pending MIC error report immediately since
3633 * we are going to start countermeasures and AP better
3634 * do the same.
3635 */
3636 wpa_sm_key_request(wpa_s->wpa, 1,
3637 wpa_s->pending_mic_error_pairwise);
3638 }
3639
3640 /* Send the new MIC error report immediately since we are going
3641 * to start countermeasures and AP better do the same.
3642 */
3643 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3644
3645 /* initialize countermeasures */
3646 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003647
Hai Shalom60840252021-02-19 19:02:11 -08003648 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003649
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003650 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3651
3652 /*
3653 * Need to wait for completion of request frame. We do not get
3654 * any callback for the message completion, so just wait a
3655 * short while and hope for the best. */
3656 os_sleep(0, 10000);
3657
3658 wpa_drv_set_countermeasures(wpa_s, 1);
3659 wpa_supplicant_deauthenticate(wpa_s,
3660 WLAN_REASON_MICHAEL_MIC_FAILURE);
3661 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3662 wpa_s, NULL);
3663 eloop_register_timeout(60, 0,
3664 wpa_supplicant_stop_countermeasures,
3665 wpa_s, NULL);
3666 /* TODO: mark the AP rejected for 60 second. STA is
3667 * allowed to associate with another AP.. */
3668 } else {
3669#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3670 if (wpa_s->mic_errors_seen) {
3671 /*
3672 * Reduce the effectiveness of Michael MIC error
3673 * reports as a means for attacking against TKIP if
3674 * more than one MIC failure is noticed with the same
3675 * PTK. We delay the transmission of the reports by a
3676 * random time between 0 and 60 seconds in order to
3677 * force the attacker wait 60 seconds before getting
3678 * the information on whether a frame resulted in a MIC
3679 * failure.
3680 */
3681 u8 rval[4];
3682 int sec;
3683
3684 if (os_get_random(rval, sizeof(rval)) < 0)
3685 sec = os_random() % 60;
3686 else
3687 sec = WPA_GET_BE32(rval) % 60;
3688 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3689 "report %d seconds", sec);
3690 wpa_s->pending_mic_error_report = 1;
3691 wpa_s->pending_mic_error_pairwise = pairwise;
3692 eloop_cancel_timeout(
3693 wpa_supplicant_delayed_mic_error_report,
3694 wpa_s, NULL);
3695 eloop_register_timeout(
3696 sec, os_random() % 1000000,
3697 wpa_supplicant_delayed_mic_error_report,
3698 wpa_s, NULL);
3699 } else {
3700 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3701 }
3702#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3703 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3704#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3705 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003706 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003707 wpa_s->mic_errors_seen++;
3708}
3709
3710
3711#ifdef CONFIG_TERMINATE_ONLASTIF
3712static int any_interfaces(struct wpa_supplicant *head)
3713{
3714 struct wpa_supplicant *wpa_s;
3715
3716 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3717 if (!wpa_s->interface_removed)
3718 return 1;
3719 return 0;
3720}
3721#endif /* CONFIG_TERMINATE_ONLASTIF */
3722
3723
3724static void
3725wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3726 union wpa_event_data *data)
3727{
3728 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3729 return;
3730
3731 switch (data->interface_status.ievent) {
3732 case EVENT_INTERFACE_ADDED:
3733 if (!wpa_s->interface_removed)
3734 break;
3735 wpa_s->interface_removed = 0;
3736 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3737 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3738 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3739 "driver after interface was added");
3740 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003741
3742#ifdef CONFIG_P2P
3743 if (!wpa_s->global->p2p &&
3744 !wpa_s->global->p2p_disabled &&
3745 !wpa_s->conf->p2p_disabled &&
3746 (wpa_s->drv_flags &
3747 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3748 wpas_p2p_add_p2pdev_interface(
3749 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3750 wpa_printf(MSG_INFO,
3751 "P2P: Failed to enable P2P Device interface");
3752 /* Try to continue without. P2P will be disabled. */
3753 }
3754#endif /* CONFIG_P2P */
3755
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003756 break;
3757 case EVENT_INTERFACE_REMOVED:
3758 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3759 wpa_s->interface_removed = 1;
3760 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003761 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003762 l2_packet_deinit(wpa_s->l2);
3763 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003764
3765#ifdef CONFIG_P2P
3766 if (wpa_s->global->p2p &&
3767 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3768 (wpa_s->drv_flags &
3769 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3770 wpa_dbg(wpa_s, MSG_DEBUG,
3771 "Removing P2P Device interface");
3772 wpa_supplicant_remove_iface(
3773 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3774 0);
3775 wpa_s->global->p2p_init_wpa_s = NULL;
3776 }
3777#endif /* CONFIG_P2P */
3778
Dmitry Shmidte4663042016-04-04 10:07:49 -07003779#ifdef CONFIG_MATCH_IFACE
3780 if (wpa_s->matched) {
3781 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3782 break;
3783 }
3784#endif /* CONFIG_MATCH_IFACE */
3785
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003786#ifdef CONFIG_TERMINATE_ONLASTIF
3787 /* check if last interface */
3788 if (!any_interfaces(wpa_s->global->ifaces))
3789 eloop_terminate();
3790#endif /* CONFIG_TERMINATE_ONLASTIF */
3791 break;
3792 }
3793}
3794
3795
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003796#ifdef CONFIG_TDLS
3797static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3798 union wpa_event_data *data)
3799{
3800 if (data == NULL)
3801 return;
3802 switch (data->tdls.oper) {
3803 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003804 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3805 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3806 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3807 else
3808 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003809 break;
3810 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003811 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3812 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3813 data->tdls.reason_code);
3814 else
3815 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3816 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003817 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003818 case TDLS_REQUEST_DISCOVER:
3819 wpa_tdls_send_discovery_request(wpa_s->wpa,
3820 data->tdls.peer);
3821 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003822 }
3823}
3824#endif /* CONFIG_TDLS */
3825
3826
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003827#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003828static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3829 union wpa_event_data *data)
3830{
3831 if (data == NULL)
3832 return;
3833 switch (data->wnm.oper) {
3834 case WNM_OPER_SLEEP:
3835 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3836 "(action=%d, intval=%d)",
3837 data->wnm.sleep_action, data->wnm.sleep_intval);
3838 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003839 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003840 break;
3841 }
3842}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003843#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003844
3845
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003846#ifdef CONFIG_IEEE80211R
3847static void
3848wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3849 union wpa_event_data *data)
3850{
3851 if (data == NULL)
3852 return;
3853
3854 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3855 data->ft_ies.ies_len,
3856 data->ft_ies.ft_action,
3857 data->ft_ies.target_ap,
3858 data->ft_ies.ric_ies,
3859 data->ft_ies.ric_ies_len) < 0) {
3860 /* TODO: prevent MLME/driver from trying to associate? */
3861 }
3862}
3863#endif /* CONFIG_IEEE80211R */
3864
3865
3866#ifdef CONFIG_IBSS_RSN
3867static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3868 union wpa_event_data *data)
3869{
3870 struct wpa_ssid *ssid;
3871 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3872 return;
3873 if (data == NULL)
3874 return;
3875 ssid = wpa_s->current_ssid;
3876 if (ssid == NULL)
3877 return;
3878 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3879 return;
3880
3881 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3882}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003883
3884
3885static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3886 union wpa_event_data *data)
3887{
3888 struct wpa_ssid *ssid = wpa_s->current_ssid;
3889
3890 if (ssid == NULL)
3891 return;
3892
3893 /* check if the ssid is correctly configured as IBSS/RSN */
3894 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3895 return;
3896
3897 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3898 data->rx_mgmt.frame_len);
3899}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003900#endif /* CONFIG_IBSS_RSN */
3901
3902
3903#ifdef CONFIG_IEEE80211R
3904static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3905 size_t len)
3906{
3907 const u8 *sta_addr, *target_ap_addr;
3908 u16 status;
3909
3910 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3911 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3912 return; /* only SME case supported for now */
3913 if (len < 1 + 2 * ETH_ALEN + 2)
3914 return;
3915 if (data[0] != 2)
3916 return; /* Only FT Action Response is supported for now */
3917 sta_addr = data + 1;
3918 target_ap_addr = data + 1 + ETH_ALEN;
3919 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3920 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3921 MACSTR " TargetAP " MACSTR " status %u",
3922 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3923
3924 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3925 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3926 " in FT Action Response", MAC2STR(sta_addr));
3927 return;
3928 }
3929
3930 if (status) {
3931 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3932 "failure (status code %d)", status);
3933 /* TODO: report error to FT code(?) */
3934 return;
3935 }
3936
3937 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3938 len - (1 + 2 * ETH_ALEN + 2), 1,
3939 target_ap_addr, NULL, 0) < 0)
3940 return;
3941
3942#ifdef CONFIG_SME
3943 {
3944 struct wpa_bss *bss;
3945 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3946 if (bss)
3947 wpa_s->sme.freq = bss->freq;
3948 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3949 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3950 WLAN_AUTH_FT);
3951 }
3952#endif /* CONFIG_SME */
3953}
3954#endif /* CONFIG_IEEE80211R */
3955
3956
3957static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3958 struct unprot_deauth *e)
3959{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003960 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3961 "dropped: " MACSTR " -> " MACSTR
3962 " (reason code %u)",
3963 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3964 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003965}
3966
3967
3968static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3969 struct unprot_disassoc *e)
3970{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003971 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3972 "dropped: " MACSTR " -> " MACSTR
3973 " (reason code %u)",
3974 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3975 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003976}
3977
3978
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003979static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3980 u16 reason_code, int locally_generated,
3981 const u8 *ie, size_t ie_len, int deauth)
3982{
3983#ifdef CONFIG_AP
3984 if (wpa_s->ap_iface && addr) {
3985 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3986 return;
3987 }
3988
3989 if (wpa_s->ap_iface) {
3990 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3991 return;
3992 }
3993#endif /* CONFIG_AP */
3994
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003995 if (!locally_generated)
3996 wpa_s->own_disconnect_req = 0;
3997
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003998 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3999
Dmitry Shmidt344abd32014-01-14 13:17:00 -08004000 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
4001 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4002 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
4003 eapol_sm_failed(wpa_s->eapol))) &&
4004 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004005 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004006
4007#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07004008 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004009 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
4010 locally_generated) > 0) {
4011 /*
4012 * The interface was removed, so cannot continue
4013 * processing any additional operations after this.
4014 */
4015 return;
4016 }
4017 }
4018#endif /* CONFIG_P2P */
4019
4020 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4021 locally_generated);
4022}
4023
4024
4025static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4026 struct disassoc_info *info)
4027{
4028 u16 reason_code = 0;
4029 int locally_generated = 0;
4030 const u8 *addr = NULL;
4031 const u8 *ie = NULL;
4032 size_t ie_len = 0;
4033
4034 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4035
4036 if (info) {
4037 addr = info->addr;
4038 ie = info->ie;
4039 ie_len = info->ie_len;
4040 reason_code = info->reason_code;
4041 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004042 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4043 reason2str(reason_code),
4044 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004045 if (addr)
4046 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4047 MAC2STR(addr));
4048 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4049 ie, ie_len);
4050 }
4051
4052#ifdef CONFIG_AP
4053 if (wpa_s->ap_iface && info && info->addr) {
4054 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4055 return;
4056 }
4057
4058 if (wpa_s->ap_iface) {
4059 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4060 return;
4061 }
4062#endif /* CONFIG_AP */
4063
4064#ifdef CONFIG_P2P
4065 if (info) {
4066 wpas_p2p_disassoc_notif(
4067 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4068 locally_generated);
4069 }
4070#endif /* CONFIG_P2P */
4071
4072 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4073 sme_event_disassoc(wpa_s, info);
4074
4075 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4076 ie, ie_len, 0);
4077}
4078
4079
4080static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4081 struct deauth_info *info)
4082{
4083 u16 reason_code = 0;
4084 int locally_generated = 0;
4085 const u8 *addr = NULL;
4086 const u8 *ie = NULL;
4087 size_t ie_len = 0;
4088
4089 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4090
4091 if (info) {
4092 addr = info->addr;
4093 ie = info->ie;
4094 ie_len = info->ie_len;
4095 reason_code = info->reason_code;
4096 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004097 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4098 reason_code, reason2str(reason_code),
4099 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004100 if (addr) {
4101 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4102 MAC2STR(addr));
4103 }
4104 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4105 ie, ie_len);
4106 }
4107
4108 wpa_reset_ft_completed(wpa_s->wpa);
4109
4110 wpas_event_disconnect(wpa_s, addr, reason_code,
4111 locally_generated, ie, ie_len, 1);
4112}
4113
4114
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004115static const char * reg_init_str(enum reg_change_initiator init)
4116{
4117 switch (init) {
4118 case REGDOM_SET_BY_CORE:
4119 return "CORE";
4120 case REGDOM_SET_BY_USER:
4121 return "USER";
4122 case REGDOM_SET_BY_DRIVER:
4123 return "DRIVER";
4124 case REGDOM_SET_BY_COUNTRY_IE:
4125 return "COUNTRY_IE";
4126 case REGDOM_BEACON_HINT:
4127 return "BEACON_HINT";
4128 }
4129 return "?";
4130}
4131
4132
4133static const char * reg_type_str(enum reg_type type)
4134{
4135 switch (type) {
4136 case REGDOM_TYPE_UNKNOWN:
4137 return "UNKNOWN";
4138 case REGDOM_TYPE_COUNTRY:
4139 return "COUNTRY";
4140 case REGDOM_TYPE_WORLD:
4141 return "WORLD";
4142 case REGDOM_TYPE_CUSTOM_WORLD:
4143 return "CUSTOM_WORLD";
4144 case REGDOM_TYPE_INTERSECTION:
4145 return "INTERSECTION";
4146 }
4147 return "?";
4148}
4149
4150
Hai Shalom74f70d42019-02-11 14:42:39 -08004151void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4152 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004153{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004154 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004155 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004156
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004157 /*
4158 * To allow backwards compatibility with higher level layers that
4159 * assumed the REGDOM_CHANGE event is sent over the initially added
4160 * interface. Find the highest parent of this interface and use it to
4161 * send the event.
4162 */
4163 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4164 ;
4165
Hai Shalom74f70d42019-02-11 14:42:39 -08004166 if (info) {
4167 wpa_msg(ifs, MSG_INFO,
4168 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4169 reg_init_str(info->initiator), reg_type_str(info->type),
4170 info->alpha2[0] ? " alpha2=" : "",
4171 info->alpha2[0] ? info->alpha2 : "");
4172 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004173
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004174 if (wpa_s->drv_priv == NULL)
4175 return; /* Ignore event during drv initialization */
4176
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004177 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4178 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004179 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4180 ifs->ifname);
4181 free_hw_features(ifs);
4182 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004183 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004184
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004185 /* Restart PNO/sched_scan with updated channel list */
4186 if (ifs->pno) {
4187 wpas_stop_pno(ifs);
4188 wpas_start_pno(ifs);
4189 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4190 wpa_dbg(ifs, MSG_DEBUG,
4191 "Channel list changed - restart sched_scan");
4192 wpas_scan_restart_sched_scan(ifs);
4193 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004194 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004195
4196 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004197}
4198
4199
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004200static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004201 const u8 *frame, size_t len, int freq,
4202 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004203{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004204 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004205 const u8 *payload;
4206 size_t plen;
4207 u8 category;
4208
4209 if (len < IEEE80211_HDRLEN + 2)
4210 return;
4211
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004212 mgmt = (const struct ieee80211_mgmt *) frame;
4213 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004214 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004215 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004216
4217 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4218 " Category=%u DataLen=%d freq=%d MHz",
4219 MAC2STR(mgmt->sa), category, (int) plen, freq);
4220
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004221 if (category == WLAN_ACTION_WMM) {
4222 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4223 return;
4224 }
4225
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004226#ifdef CONFIG_IEEE80211R
4227 if (category == WLAN_ACTION_FT) {
4228 ft_rx_action(wpa_s, payload, plen);
4229 return;
4230 }
4231#endif /* CONFIG_IEEE80211R */
4232
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004233#ifdef CONFIG_SME
4234 if (category == WLAN_ACTION_SA_QUERY) {
4235 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
4236 return;
4237 }
4238#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004239
4240#ifdef CONFIG_WNM
4241 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4242 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4243 return;
4244 }
4245#endif /* CONFIG_WNM */
4246
4247#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004248 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4249 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004250 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004251 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004252 payload, plen, freq) == 0)
4253 return;
4254#endif /* CONFIG_GAS */
4255
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004256#ifdef CONFIG_GAS_SERVER
4257 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4258 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4259 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4260 mgmt->u.action.category,
4261 payload, plen, freq) == 0)
4262 return;
4263#endif /* CONFIG_GAS_SERVER */
4264
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004265#ifdef CONFIG_TDLS
4266 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4267 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4268 wpa_dbg(wpa_s, MSG_DEBUG,
4269 "TDLS: Received Discovery Response from " MACSTR,
4270 MAC2STR(mgmt->sa));
4271 return;
4272 }
4273#endif /* CONFIG_TDLS */
4274
4275#ifdef CONFIG_INTERWORKING
4276 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4277 payload[0] == QOS_QOS_MAP_CONFIG) {
4278 const u8 *pos = payload + 1;
4279 size_t qlen = plen - 1;
4280 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4281 MACSTR, MAC2STR(mgmt->sa));
4282 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4283 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4284 pos[1] <= qlen - 2 && pos[1] >= 16)
4285 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4286 return;
4287 }
4288#endif /* CONFIG_INTERWORKING */
4289
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004290 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004291 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4292 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004293 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004294 payload + 1,
4295 plen - 1);
4296 return;
4297 }
4298
4299 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004300 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4301 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4302 return;
4303 }
4304
4305 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4306 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4307 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4308 payload + 1, plen - 1,
4309 rssi);
4310 return;
4311 }
4312
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004313#ifdef CONFIG_FST
4314 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4315 fst_rx_action(wpa_s->fst, mgmt, len);
4316 return;
4317 }
4318#endif /* CONFIG_FST */
4319
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004320#ifdef CONFIG_DPP
4321 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4322 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4323 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4324 payload[4] == DPP_OUI_TYPE) {
4325 payload++;
4326 plen--;
4327 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4328 return;
4329 }
4330#endif /* CONFIG_DPP */
4331
Hai Shalom899fcc72020-10-19 14:38:18 -07004332 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
4333 payload[0] == ROBUST_AV_MSCS_RESP) {
4334 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4335 payload + 1, plen - 1);
4336 return;
4337 }
4338
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004339 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4340 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004341 if (wpa_s->ifmsh)
4342 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004343}
4344
4345
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004346static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4347 union wpa_event_data *event)
4348{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004349 struct wpa_freq_range_list *list;
4350 char *str = NULL;
4351
4352 list = &event->freq_range;
4353
4354 if (list->num)
4355 str = freq_range_list_str(list);
4356 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4357 str ? str : "");
4358
4359#ifdef CONFIG_P2P
4360 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4361 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4362 __func__);
4363 } else {
4364 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004365
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004366 /*
4367 * The update channel flow will also take care of moving a GO
4368 * from the unsafe frequency if needed.
4369 */
4370 wpas_p2p_update_channel_list(wpa_s,
4371 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004372 }
4373#endif /* CONFIG_P2P */
4374
4375 os_free(str);
4376}
4377
4378
Roshan Pius3a1667e2018-07-03 15:17:14 -07004379static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004380{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004381 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4382 wpa_supplicant_cancel_auth_timeout(wpa_s);
4383 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004384 eapol_sm_notify_portValid(wpa_s->eapol, true);
4385 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004386 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004387 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004388}
4389
4390
4391static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4392 int freq)
4393{
4394 size_t i;
4395 int j;
4396
4397 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4398 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4399
4400 for (j = 0; j < mode->num_channels; j++) {
4401 const struct hostapd_channel_data *chan;
4402
4403 chan = &mode->channels[j];
4404 if (chan->freq == freq)
4405 return chan->dfs_cac_ms;
4406 }
4407 }
4408
4409 return 0;
4410}
4411
4412
4413static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4414 struct dfs_event *radar)
4415{
4416#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004417 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004418 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4419 } else
4420#endif /* NEED_AP_MLME && CONFIG_AP */
4421 {
4422 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4423
4424 cac_time /= 1000; /* convert from ms to sec */
4425 if (!cac_time)
4426 cac_time = 10 * 60; /* max timeout: 10 minutes */
4427
4428 /* Restart auth timeout: CAC time added to initial timeout */
4429 wpas_auth_timeout_restart(wpa_s, cac_time);
4430 }
4431}
4432
4433
4434static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4435 struct dfs_event *radar)
4436{
4437#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004438 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004439 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4440 } else
4441#endif /* NEED_AP_MLME && CONFIG_AP */
4442 {
4443 /* Restart auth timeout with original value after CAC is
4444 * finished */
4445 wpas_auth_timeout_restart(wpa_s, 0);
4446 }
4447}
4448
4449
4450static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4451 struct dfs_event *radar)
4452{
4453#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004454 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004455 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4456 } else
4457#endif /* NEED_AP_MLME && CONFIG_AP */
4458 {
4459 /* Restart auth timeout with original value after CAC is
4460 * aborted */
4461 wpas_auth_timeout_restart(wpa_s, 0);
4462 }
4463}
4464
4465
4466static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4467 union wpa_event_data *data)
4468{
4469 wpa_dbg(wpa_s, MSG_DEBUG,
4470 "Connection authorized by device, previous state %d",
4471 wpa_s->wpa_state);
4472
4473 wpa_supplicant_event_port_authorized(wpa_s);
4474
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004475 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4476 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004477 data->assoc_info.ptk_kck_len,
4478 data->assoc_info.ptk_kek,
4479 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004480#ifdef CONFIG_FILS
4481 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4482 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4483 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4484
4485 /* Update ERP next sequence number */
4486 eapol_sm_update_erp_next_seq_num(
4487 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4488
4489 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4490 /* Add the new PMK and PMKID to the PMKSA cache */
4491 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4492 data->assoc_info.fils_pmk,
4493 data->assoc_info.fils_pmk_len,
4494 data->assoc_info.fils_pmkid,
4495 wpa_s->bssid, fils_cache_id);
4496 } else if (data->assoc_info.fils_pmkid) {
4497 /* Update the current PMKSA used for this connection */
4498 pmksa_cache_set_current(wpa_s->wpa,
4499 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004500 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004501 }
4502 }
4503#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004504}
4505
4506
Hai Shalom60840252021-02-19 19:02:11 -08004507static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
4508{
4509 switch (code) {
4510 case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
4511 return "";
4512 case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
4513 return "no_bss_found";
4514 case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
4515 return "auth_tx_fail";
4516 case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
4517 return "auth_no_ack_received";
4518 case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
4519 return "auth_no_resp_received";
4520 case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
4521 return "assoc_req_tx_fail";
4522 case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
4523 return "assoc_no_ack_received";
4524 case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
4525 return "assoc_no_resp_received";
4526 default:
4527 return "unknown_reason";
4528 }
4529}
4530
4531
Roshan Pius3a1667e2018-07-03 15:17:14 -07004532static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4533 union wpa_event_data *data)
4534{
4535 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004536#ifdef CONFIG_MBO
4537 struct wpa_bss *reject_bss;
4538#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004539
4540 if (!bssid || is_zero_ether_addr(bssid))
4541 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004542#ifdef CONFIG_MBO
4543 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4544 reject_bss = wpa_s->current_bss;
4545 else
4546 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4547#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004548
4549 if (data->assoc_reject.bssid)
4550 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004551 "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004552 MAC2STR(data->assoc_reject.bssid),
4553 data->assoc_reject.status_code,
4554 data->assoc_reject.timed_out ? " timeout" : "",
4555 data->assoc_reject.timeout_reason ? "=" : "",
4556 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004557 data->assoc_reject.timeout_reason : "",
4558 data->assoc_reject.reason_code !=
4559 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4560 " qca_driver_reason=" : "",
4561 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004562 else
4563 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Hai Shalom60840252021-02-19 19:02:11 -08004564 "status_code=%u%s%s%s%s%s",
Roshan Pius3a1667e2018-07-03 15:17:14 -07004565 data->assoc_reject.status_code,
4566 data->assoc_reject.timed_out ? " timeout" : "",
4567 data->assoc_reject.timeout_reason ? "=" : "",
4568 data->assoc_reject.timeout_reason ?
Hai Shalom60840252021-02-19 19:02:11 -08004569 data->assoc_reject.timeout_reason : "",
4570 data->assoc_reject.reason_code !=
4571 STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
4572 " qca_driver_reason=" : "",
4573 connect_fail_reason(data->assoc_reject.reason_code));
Roshan Pius3a1667e2018-07-03 15:17:14 -07004574 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08004575 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
4576 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004577
4578#ifdef CONFIG_OWE
4579 if (data->assoc_reject.status_code ==
4580 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4581 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4582 wpa_s->current_ssid &&
4583 wpa_s->current_ssid->owe_group == 0 &&
4584 wpa_s->last_owe_group != 21) {
4585 struct wpa_ssid *ssid = wpa_s->current_ssid;
4586 struct wpa_bss *bss = wpa_s->current_bss;
4587
4588 if (!bss) {
4589 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4590 if (!bss) {
4591 wpas_connection_failed(wpa_s, bssid);
4592 wpa_supplicant_mark_disassoc(wpa_s);
4593 return;
4594 }
4595 }
4596 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4597 wpas_connect_work_done(wpa_s);
4598 wpa_supplicant_mark_disassoc(wpa_s);
4599 wpa_supplicant_connect(wpa_s, bss, ssid);
4600 return;
4601 }
4602#endif /* CONFIG_OWE */
4603
Hai Shalomfdcde762020-04-02 11:19:20 -07004604#ifdef CONFIG_DPP2
4605 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4606 * the status code defined in the DPP R2 tech spec.
4607 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4608 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004609 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004610 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4611 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4612 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004613 wpa_s->current_ssid->dpp_pfs == 0 &&
4614 (data->assoc_reject.status_code ==
4615 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4616 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4617 struct wpa_ssid *ssid = wpa_s->current_ssid;
4618 struct wpa_bss *bss = wpa_s->current_bss;
4619
4620 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4621 if (!bss)
4622 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4623 if (!bss || wpa_s->dpp_pfs_fallback) {
4624 wpa_printf(MSG_DEBUG,
4625 "DPP: Updated PFS policy for next try");
4626 wpas_connection_failed(wpa_s, bssid);
4627 wpa_supplicant_mark_disassoc(wpa_s);
4628 return;
4629 }
4630 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4631 wpa_s->dpp_pfs_fallback = 1;
4632 wpas_connect_work_done(wpa_s);
4633 wpa_supplicant_mark_disassoc(wpa_s);
4634 wpa_supplicant_connect(wpa_s, bss, ssid);
4635 return;
4636 }
4637#endif /* CONFIG_DPP2 */
4638
Hai Shalom74f70d42019-02-11 14:42:39 -08004639#ifdef CONFIG_MBO
4640 if (data->assoc_reject.status_code ==
4641 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004642 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004643 const u8 *rssi_rej;
4644
4645 rssi_rej = mbo_get_attr_from_ies(
4646 data->assoc_reject.resp_ies,
4647 data->assoc_reject.resp_ies_len,
4648 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4649 if (rssi_rej && rssi_rej[1] == 2) {
4650 wpa_printf(MSG_DEBUG,
4651 "OCE: RSSI-based association rejection from "
4652 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004653 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004654 rssi_rej[2], rssi_rej[3]);
4655 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004656 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004657 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004658 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004659 }
4660 }
4661#endif /* CONFIG_MBO */
4662
Roshan Pius3a1667e2018-07-03 15:17:14 -07004663 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4664 sme_event_assoc_reject(wpa_s, data);
4665 return;
4666 }
4667
4668 /* Driver-based SME cases */
4669
4670#ifdef CONFIG_SAE
4671 if (wpa_s->current_ssid &&
4672 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4673 !data->assoc_reject.timed_out) {
4674 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4675 wpa_sm_aborted_cached(wpa_s->wpa);
4676 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4677 }
4678#endif /* CONFIG_SAE */
4679
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004680#ifdef CONFIG_DPP
4681 if (wpa_s->current_ssid &&
4682 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4683 !data->assoc_reject.timed_out) {
4684 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4685 wpa_sm_aborted_cached(wpa_s->wpa);
4686 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4687 }
4688#endif /* CONFIG_DPP */
4689
Roshan Pius3a1667e2018-07-03 15:17:14 -07004690#ifdef CONFIG_FILS
4691 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004692 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004693 eapol_sm_update_erp_next_seq_num(
4694 wpa_s->eapol,
4695 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004696 fils_connection_failure(wpa_s);
4697 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004698#endif /* CONFIG_FILS */
4699
4700 wpas_connection_failed(wpa_s, bssid);
4701 wpa_supplicant_mark_disassoc(wpa_s);
4702}
4703
4704
Hai Shalomfdcde762020-04-02 11:19:20 -07004705static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
4706 struct unprot_beacon *data)
4707{
4708 struct wpabuf *buf;
4709 int res;
4710
4711 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
4712 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
4713 return;
4714 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
4715 MAC2STR(data->sa));
4716
4717 buf = wpabuf_alloc(4);
4718 if (!buf)
4719 return;
4720
4721 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
4722 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
4723 wpabuf_put_u8(buf, 1); /* Dialog Token */
4724 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
4725
4726 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
4727 wpa_s->own_addr, wpa_s->bssid,
4728 wpabuf_head(buf), wpabuf_len(buf), 0);
4729 if (res < 0)
4730 wpa_printf(MSG_DEBUG,
4731 "Failed to send WNM-Notification Request frame");
4732
4733 wpabuf_free(buf);
4734}
4735
4736
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004737void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4738 union wpa_event_data *data)
4739{
4740 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004741 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07004742 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08004743#ifndef CONFIG_NO_STDOUT_DEBUG
4744 int level = MSG_DEBUG;
4745#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004746
4747 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4748 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004749 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004750 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004751 event != EVENT_SCHED_SCAN_STOPPED) {
4752 wpa_dbg(wpa_s, MSG_DEBUG,
4753 "Ignore event %s (%d) while interface is disabled",
4754 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004755 return;
4756 }
4757
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004758#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07004759 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004760 const struct ieee80211_hdr *hdr;
4761 u16 fc;
4762 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4763 fc = le_to_host16(hdr->frame_control);
4764 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4765 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4766 level = MSG_EXCESSIVE;
4767 }
4768
4769 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4770 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004771#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004772
4773 switch (event) {
4774 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004775#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004776 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4777 data->auth.ies_len))
4778 wpa_printf(MSG_DEBUG,
4779 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004780#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004781 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004782 wpa_s->auth_status_code = data->auth.status_code;
4783 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004784 break;
4785 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004786#ifdef CONFIG_TESTING_OPTIONS
4787 if (wpa_s->ignore_auth_resp) {
4788 wpa_printf(MSG_INFO,
4789 "EVENT_ASSOC - ignore_auth_resp active!");
4790 break;
4791 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004792 if (wpa_s->testing_resend_assoc) {
4793 wpa_printf(MSG_INFO,
4794 "EVENT_DEAUTH - testing_resend_assoc");
4795 break;
4796 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004797#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05304798 if (wpa_s->disconnected) {
4799 wpa_printf(MSG_INFO,
4800 "Ignore unexpected EVENT_ASSOC in disconnected state");
4801 break;
4802 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004803 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004804 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004805 if (data &&
4806 (data->assoc_info.authorized ||
4807 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4808 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004809 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004810 if (data) {
4811 wpa_msg(wpa_s, MSG_INFO,
4812 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4813 data->assoc_info.subnet_status);
4814 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004815 break;
4816 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004817 wpas_event_disassoc(wpa_s,
4818 data ? &data->disassoc_info : NULL);
4819 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004820 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004821#ifdef CONFIG_TESTING_OPTIONS
4822 if (wpa_s->ignore_auth_resp) {
4823 wpa_printf(MSG_INFO,
4824 "EVENT_DEAUTH - ignore_auth_resp active!");
4825 break;
4826 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004827 if (wpa_s->testing_resend_assoc) {
4828 wpa_printf(MSG_INFO,
4829 "EVENT_DEAUTH - testing_resend_assoc");
4830 break;
4831 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004832#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004833 wpas_event_deauth(wpa_s,
4834 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004835 break;
4836 case EVENT_MICHAEL_MIC_FAILURE:
4837 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4838 break;
4839#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004840 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004841 if (wpa_s->own_scan_requested ||
4842 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004843 struct os_reltime diff;
4844
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004845 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004846 os_reltime_sub(&wpa_s->scan_start_time,
4847 &wpa_s->scan_trigger_time, &diff);
4848 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4849 diff.sec, diff.usec);
4850 wpa_s->own_scan_requested = 0;
4851 wpa_s->own_scan_running = 1;
4852 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4853 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004854 wpa_msg_ctrl(wpa_s, MSG_INFO,
4855 WPA_EVENT_SCAN_STARTED "id=%u",
4856 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004857 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004858 wpa_msg_ctrl(wpa_s, MSG_INFO,
4859 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004860 }
4861 } else {
4862 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Hai Shalom60840252021-02-19 19:02:11 -08004863 wpa_s->radio->external_scan_req_interface = wpa_s;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004864 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004865 }
4866 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004867 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004868 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4869 wpa_s->scan_res_handler = NULL;
4870 wpa_s->own_scan_running = 0;
Hai Shalom60840252021-02-19 19:02:11 -08004871 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004872 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4873 break;
4874 }
4875
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004876 if (!(data && data->scan_info.external_scan) &&
4877 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004878 struct os_reltime now, diff;
4879 os_get_reltime(&now);
4880 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4881 wpa_s->scan_start_time.sec = 0;
4882 wpa_s->scan_start_time.usec = 0;
4883 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4884 diff.sec, diff.usec);
4885 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004886 if (wpa_supplicant_event_scan_results(wpa_s, data))
4887 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004888 if (!(data && data->scan_info.external_scan))
4889 wpa_s->own_scan_running = 0;
4890 if (data && data->scan_info.nl_scan_event)
Hai Shalom60840252021-02-19 19:02:11 -08004891 wpa_s->radio->external_scan_req_interface = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004892 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004893 break;
4894#endif /* CONFIG_NO_SCAN_PROCESSING */
4895 case EVENT_ASSOCINFO:
4896 wpa_supplicant_event_associnfo(wpa_s, data);
4897 break;
4898 case EVENT_INTERFACE_STATUS:
4899 wpa_supplicant_event_interface_status(wpa_s, data);
4900 break;
4901 case EVENT_PMKID_CANDIDATE:
4902 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4903 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004904#ifdef CONFIG_TDLS
4905 case EVENT_TDLS:
4906 wpa_supplicant_event_tdls(wpa_s, data);
4907 break;
4908#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004909#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004910 case EVENT_WNM:
4911 wpa_supplicant_event_wnm(wpa_s, data);
4912 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004913#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004914#ifdef CONFIG_IEEE80211R
4915 case EVENT_FT_RESPONSE:
4916 wpa_supplicant_event_ft_response(wpa_s, data);
4917 break;
4918#endif /* CONFIG_IEEE80211R */
4919#ifdef CONFIG_IBSS_RSN
4920 case EVENT_IBSS_RSN_START:
4921 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4922 break;
4923#endif /* CONFIG_IBSS_RSN */
4924 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004925 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004926 break;
4927 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004928 /* It is possible to get this event from earlier connection */
4929 if (wpa_s->current_ssid &&
4930 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4931 wpa_dbg(wpa_s, MSG_DEBUG,
4932 "Ignore AUTH_TIMED_OUT in mesh configuration");
4933 break;
4934 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004935 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4936 sme_event_auth_timed_out(wpa_s, data);
4937 break;
4938 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004939 /* It is possible to get this event from earlier connection */
4940 if (wpa_s->current_ssid &&
4941 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4942 wpa_dbg(wpa_s, MSG_DEBUG,
4943 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4944 break;
4945 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004946 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4947 sme_event_assoc_timed_out(wpa_s, data);
4948 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004949 case EVENT_TX_STATUS:
4950 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4951 " type=%d stype=%d",
4952 MAC2STR(data->tx_status.dst),
4953 data->tx_status.type, data->tx_status.stype);
Hai Shalom60840252021-02-19 19:02:11 -08004954#ifdef CONFIG_PASN
4955 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4956 data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
4957 wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
4958 data->tx_status.data_len,
4959 data->tx_status.ack) == 0)
4960 break;
4961#endif /* CONFIG_PASN */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004962#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004963 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004964#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004965 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4966 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004967 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004968 wpa_s, data->tx_status.dst,
4969 data->tx_status.data,
4970 data->tx_status.data_len,
4971 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004972 OFFCHANNEL_SEND_ACTION_SUCCESS :
4973 OFFCHANNEL_SEND_ACTION_NO_ACK);
4974#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004975 break;
4976 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004977#endif /* CONFIG_AP */
4978#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004979 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004980 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004981 /*
4982 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004983 * interface in GO mode, or via standalone AP interface.
4984 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4985 * except when the primary interface is used as a GO interface
4986 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004987 */
4988 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4989 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004990 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004991 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004992 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004993 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004994 data->tx_status.data,
4995 data->tx_status.data_len,
4996 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004997 OFFCHANNEL_SEND_ACTION_SUCCESS :
4998 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004999 break;
5000 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005001#endif /* CONFIG_OFFCHANNEL */
5002#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005003 switch (data->tx_status.type) {
5004 case WLAN_FC_TYPE_MGMT:
5005 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
5006 data->tx_status.data_len,
5007 data->tx_status.stype,
5008 data->tx_status.ack);
5009 break;
5010 case WLAN_FC_TYPE_DATA:
5011 ap_tx_status(wpa_s, data->tx_status.dst,
5012 data->tx_status.data,
5013 data->tx_status.data_len,
5014 data->tx_status.ack);
5015 break;
5016 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005017#endif /* CONFIG_AP */
5018 break;
5019#ifdef CONFIG_AP
5020 case EVENT_EAPOL_TX_STATUS:
5021 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
5022 data->eapol_tx_status.data,
5023 data->eapol_tx_status.data_len,
5024 data->eapol_tx_status.ack);
5025 break;
5026 case EVENT_DRIVER_CLIENT_POLL_OK:
5027 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005028 break;
5029 case EVENT_RX_FROM_UNKNOWN:
5030 if (wpa_s->ap_iface == NULL)
5031 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005032 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
5033 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005034 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005035#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07005036
5037 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07005038 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005039 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005040 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005041
Hai Shalom81f62d82019-07-22 12:10:00 -07005042 wpa_msg(wpa_s, MSG_INFO,
5043 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
5044 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
5045 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005046 data->ch_switch.freq,
5047 data->ch_switch.ht_enabled,
5048 data->ch_switch.ch_offset,
5049 channel_width_to_string(data->ch_switch.ch_width),
5050 data->ch_switch.cf1,
5051 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07005052 if (event == EVENT_CH_SWITCH_STARTED)
5053 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005054
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005055 wpa_s->assoc_freq = data->ch_switch.freq;
5056 wpa_s->current_ssid->frequency = data->ch_switch.freq;
Hai Shalom60840252021-02-19 19:02:11 -08005057 if (wpa_s->current_bss &&
5058 wpa_s->current_bss->freq != data->ch_switch.freq) {
5059 wpa_s->current_bss->freq = data->ch_switch.freq;
5060 notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
5061 wpa_s->current_bss);
5062 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005063
Hai Shalomfdcde762020-04-02 11:19:20 -07005064#ifdef CONFIG_SME
5065 switch (data->ch_switch.ch_offset) {
5066 case 1:
5067 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5068 break;
5069 case -1:
5070 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5071 break;
5072 default:
5073 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5074 break;
5075 }
5076#endif /* CONFIG_SME */
5077
Roshan Pius3a1667e2018-07-03 15:17:14 -07005078#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005079 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5080 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005081 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005082 wpa_s->current_ssid->mode ==
5083 WPAS_MODE_P2P_GROUP_FORMATION) {
5084 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5085 data->ch_switch.ht_enabled,
5086 data->ch_switch.ch_offset,
5087 data->ch_switch.ch_width,
5088 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005089 data->ch_switch.cf2,
5090 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005091 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005092#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005093
Hai Shalom899fcc72020-10-19 14:38:18 -07005094 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5095 sme_event_ch_switch(wpa_s);
5096
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005097 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005098 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005099 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005100#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005101#ifdef NEED_AP_MLME
5102 case EVENT_DFS_RADAR_DETECTED:
5103 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005104 wpas_ap_event_dfs_radar_detected(wpa_s,
5105 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005106 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005107 case EVENT_DFS_NOP_FINISHED:
5108 if (data)
5109 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5110 &data->dfs_event);
5111 break;
5112#endif /* NEED_AP_MLME */
5113#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005114 case EVENT_DFS_CAC_STARTED:
5115 if (data)
5116 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5117 break;
5118 case EVENT_DFS_CAC_FINISHED:
5119 if (data)
5120 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5121 break;
5122 case EVENT_DFS_CAC_ABORTED:
5123 if (data)
5124 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5125 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005126 case EVENT_RX_MGMT: {
5127 u16 fc, stype;
5128 const struct ieee80211_mgmt *mgmt;
5129
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005130#ifdef CONFIG_TESTING_OPTIONS
5131 if (wpa_s->ext_mgmt_frame_handling) {
5132 struct rx_mgmt *rx = &data->rx_mgmt;
5133 size_t hex_len = 2 * rx->frame_len + 1;
5134 char *hex = os_malloc(hex_len);
5135 if (hex) {
5136 wpa_snprintf_hex(hex, hex_len,
5137 rx->frame, rx->frame_len);
5138 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5139 rx->freq, rx->datarate, rx->ssi_signal,
5140 hex);
5141 os_free(hex);
5142 }
5143 break;
5144 }
5145#endif /* CONFIG_TESTING_OPTIONS */
5146
Dmitry Shmidt04949592012-07-19 12:16:46 -07005147 mgmt = (const struct ieee80211_mgmt *)
5148 data->rx_mgmt.frame;
5149 fc = le_to_host16(mgmt->frame_control);
5150 stype = WLAN_FC_GET_STYPE(fc);
5151
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005152#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005153 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005154#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005155#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005156 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005157 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005158 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005159 const u8 *ie;
5160 size_t ie_len;
5161
5162 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5163 ie_len = data->rx_mgmt.frame_len -
5164 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005165 wpas_p2p_probe_req_rx(
5166 wpa_s, src, mgmt->da,
5167 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005168 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005169 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005170 break;
5171 }
5172#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005173#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005174 if (wpa_s->current_ssid &&
5175 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5176 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005177 data->rx_mgmt.frame_len >= 30) {
5178 wpa_supplicant_event_ibss_auth(wpa_s, data);
5179 break;
5180 }
5181#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005182
5183 if (stype == WLAN_FC_STYPE_ACTION) {
5184 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005185 wpa_s, data->rx_mgmt.frame,
5186 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005187 data->rx_mgmt.freq,
5188 data->rx_mgmt.ssi_signal);
5189 break;
5190 }
5191
5192 if (wpa_s->ifmsh) {
5193 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005194 break;
5195 }
Hai Shalom60840252021-02-19 19:02:11 -08005196#ifdef CONFIG_PASN
5197 if (stype == WLAN_FC_STYPE_AUTH &&
5198 wpas_pasn_auth_rx(wpa_s, mgmt,
5199 data->rx_mgmt.frame_len) != -2)
5200 break;
5201#endif /* CONFIG_PASN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005202
Roshan Pius3a1667e2018-07-03 15:17:14 -07005203#ifdef CONFIG_SAE
5204 if (stype == WLAN_FC_STYPE_AUTH &&
5205 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5206 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5207 sme_external_auth_mgmt_rx(
5208 wpa_s, data->rx_mgmt.frame,
5209 data->rx_mgmt.frame_len);
5210 break;
5211 }
5212#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005213 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5214 "management frame in non-AP mode");
5215 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005216#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005217 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005218
5219 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005220 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5221 const u8 *ie;
5222 size_t ie_len;
5223
5224 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5225 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005226
5227 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5228 mgmt->bssid, ie, ie_len,
5229 data->rx_mgmt.ssi_signal);
5230 }
5231
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005232 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005233#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005234 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005235 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005236 case EVENT_RX_PROBE_REQ:
5237 if (data->rx_probe_req.sa == NULL ||
5238 data->rx_probe_req.ie == NULL)
5239 break;
5240#ifdef CONFIG_AP
5241 if (wpa_s->ap_iface) {
5242 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5243 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005244 data->rx_probe_req.da,
5245 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005246 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005247 data->rx_probe_req.ie_len,
5248 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005249 break;
5250 }
5251#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005252 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005253 data->rx_probe_req.da,
5254 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005255 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005256 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005257 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005258 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005259 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005260 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005261#ifdef CONFIG_OFFCHANNEL
5262 offchannel_remain_on_channel_cb(
5263 wpa_s, data->remain_on_channel.freq,
5264 data->remain_on_channel.duration);
5265#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005266 wpas_p2p_remain_on_channel_cb(
5267 wpa_s, data->remain_on_channel.freq,
5268 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005269#ifdef CONFIG_DPP
5270 wpas_dpp_remain_on_channel_cb(
5271 wpa_s, data->remain_on_channel.freq,
5272 data->remain_on_channel.duration);
5273#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005274 break;
5275 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005276#ifdef CONFIG_OFFCHANNEL
5277 offchannel_cancel_remain_on_channel_cb(
5278 wpa_s, data->remain_on_channel.freq);
5279#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005280 wpas_p2p_cancel_remain_on_channel_cb(
5281 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005282#ifdef CONFIG_DPP
5283 wpas_dpp_cancel_remain_on_channel_cb(
5284 wpa_s, data->remain_on_channel.freq);
5285#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005286 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005287 case EVENT_EAPOL_RX:
5288 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5289 data->eapol_rx.data,
5290 data->eapol_rx.data_len);
5291 break;
5292 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005293 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5294 "above=%d signal=%d noise=%d txrate=%d",
5295 data->signal_change.above_threshold,
5296 data->signal_change.current_signal,
5297 data->signal_change.current_noise,
5298 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005299 wpa_bss_update_level(wpa_s->current_bss,
5300 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005301 bgscan_notify_signal_change(
5302 wpa_s, data->signal_change.above_threshold,
5303 data->signal_change.current_signal,
5304 data->signal_change.current_noise,
5305 data->signal_change.current_txrate);
5306 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005307 case EVENT_INTERFACE_MAC_CHANGED:
5308 wpa_supplicant_update_mac_addr(wpa_s);
5309 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005310 case EVENT_INTERFACE_ENABLED:
5311 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5312 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomfdcde762020-04-02 11:19:20 -07005313 eloop_cancel_timeout(wpas_clear_disabled_interface,
5314 wpa_s, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005315 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07005316 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005317 if (wpa_s->p2p_mgmt) {
5318 wpa_supplicant_set_state(wpa_s,
5319 WPA_DISCONNECTED);
5320 break;
5321 }
5322
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005323#ifdef CONFIG_AP
5324 if (!wpa_s->ap_iface) {
5325 wpa_supplicant_set_state(wpa_s,
5326 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005327 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005328 wpa_supplicant_req_scan(wpa_s, 0, 0);
5329 } else
5330 wpa_supplicant_set_state(wpa_s,
5331 WPA_COMPLETED);
5332#else /* CONFIG_AP */
5333 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5334 wpa_supplicant_req_scan(wpa_s, 0, 0);
5335#endif /* CONFIG_AP */
5336 }
5337 break;
5338 case EVENT_INTERFACE_DISABLED:
5339 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005340#ifdef CONFIG_P2P
5341 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5342 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5343 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5344 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005345 * Mark interface disabled if this happens to end up not
5346 * being removed as a separate P2P group interface.
5347 */
5348 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5349 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005350 * The interface was externally disabled. Remove
5351 * it assuming an external entity will start a
5352 * new session if needed.
5353 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005354 if (wpa_s->current_ssid &&
5355 wpa_s->current_ssid->p2p_group)
5356 wpas_p2p_interface_unavailable(wpa_s);
5357 else
5358 wpas_p2p_disconnect(wpa_s);
5359 /*
5360 * wpa_s instance may have been freed, so must not use
5361 * it here anymore.
5362 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005363 break;
5364 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005365 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5366 p2p_in_progress(wpa_s->global->p2p) > 1) {
5367 /* This radio work will be cancelled, so clear P2P
5368 * state as well.
5369 */
5370 p2p_stop_find(wpa_s->global->p2p);
5371 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005372#endif /* CONFIG_P2P */
5373
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005374 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5375 /*
5376 * Indicate disconnection to keep ctrl_iface events
5377 * consistent.
5378 */
5379 wpa_supplicant_event_disassoc(
5380 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5381 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005382 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005383 os_reltime_age(&wpa_s->last_scan, &age);
Hai Shalom60840252021-02-19 19:02:11 -08005384 if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
5385 clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005386 clear_at.usec = 0;
5387 } else {
5388 struct os_reltime tmp;
5389
Hai Shalom60840252021-02-19 19:02:11 -08005390 tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
Hai Shalomfdcde762020-04-02 11:19:20 -07005391 tmp.usec = 0;
5392 os_reltime_sub(&tmp, &age, &clear_at);
5393 }
5394 eloop_register_timeout(clear_at.sec, clear_at.usec,
5395 wpas_clear_disabled_interface,
5396 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005397 radio_remove_works(wpa_s, NULL, 0);
5398
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005399 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5400 break;
5401 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005402 wpa_supplicant_update_channel_list(
5403 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005404 break;
5405 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005406 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005407 break;
5408 case EVENT_BEST_CHANNEL:
5409 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5410 "(%d %d %d)",
5411 data->best_chan.freq_24, data->best_chan.freq_5,
5412 data->best_chan.freq_overall);
5413 wpa_s->best_24_freq = data->best_chan.freq_24;
5414 wpa_s->best_5_freq = data->best_chan.freq_5;
5415 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005416 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5417 data->best_chan.freq_5,
5418 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005419 break;
5420 case EVENT_UNPROT_DEAUTH:
5421 wpa_supplicant_event_unprot_deauth(wpa_s,
5422 &data->unprot_deauth);
5423 break;
5424 case EVENT_UNPROT_DISASSOC:
5425 wpa_supplicant_event_unprot_disassoc(wpa_s,
5426 &data->unprot_disassoc);
5427 break;
5428 case EVENT_STATION_LOW_ACK:
5429#ifdef CONFIG_AP
5430 if (wpa_s->ap_iface && data)
5431 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5432 data->low_ack.addr);
5433#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005434#ifdef CONFIG_TDLS
5435 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005436 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5437 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005438#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005439 break;
5440 case EVENT_IBSS_PEER_LOST:
5441#ifdef CONFIG_IBSS_RSN
5442 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5443#endif /* CONFIG_IBSS_RSN */
5444 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005445 case EVENT_DRIVER_GTK_REKEY:
5446 if (os_memcmp(data->driver_gtk_rekey.bssid,
5447 wpa_s->bssid, ETH_ALEN))
5448 break;
5449 if (!wpa_s->wpa)
5450 break;
5451 wpa_sm_update_replay_ctr(wpa_s->wpa,
5452 data->driver_gtk_rekey.replay_ctr);
5453 break;
5454 case EVENT_SCHED_SCAN_STOPPED:
5455 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005456 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005457 wpa_supplicant_notify_scanning(wpa_s, 0);
5458
5459 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5460 break;
5461
5462 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005463 * If the driver stopped scanning without being requested to,
5464 * request a new scan to continue scanning for networks.
5465 */
5466 if (!wpa_s->sched_scan_stop_req &&
5467 wpa_s->wpa_state == WPA_SCANNING) {
5468 wpa_dbg(wpa_s, MSG_DEBUG,
5469 "Restart scanning after unexpected sched_scan stop event");
5470 wpa_supplicant_req_scan(wpa_s, 1, 0);
5471 break;
5472 }
5473
5474 wpa_s->sched_scan_stop_req = 0;
5475
5476 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005477 * Start a new sched scan to continue searching for more SSIDs
5478 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005479 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005480 if (wpa_s->sched_scan_timed_out) {
5481 wpa_supplicant_req_sched_scan(wpa_s);
5482 } else if (wpa_s->pno_sched_pending) {
5483 wpa_s->pno_sched_pending = 0;
5484 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005485 } else if (resched) {
5486 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005487 }
5488
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005489 break;
5490 case EVENT_WPS_BUTTON_PUSHED:
5491#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005492 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005493#endif /* CONFIG_WPS */
5494 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005495 case EVENT_AVOID_FREQUENCIES:
5496 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5497 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005498 case EVENT_CONNECT_FAILED_REASON:
5499#ifdef CONFIG_AP
5500 if (!wpa_s->ap_iface || !data)
5501 break;
5502 hostapd_event_connect_failed_reason(
5503 wpa_s->ap_iface->bss[0],
5504 data->connect_failed_reason.addr,
5505 data->connect_failed_reason.code);
5506#endif /* CONFIG_AP */
5507 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005508 case EVENT_NEW_PEER_CANDIDATE:
5509#ifdef CONFIG_MESH
5510 if (!wpa_s->ifmsh || !data)
5511 break;
5512 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5513 data->mesh_peer.ies,
5514 data->mesh_peer.ie_len);
5515#endif /* CONFIG_MESH */
5516 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005517 case EVENT_SURVEY:
5518#ifdef CONFIG_AP
5519 if (!wpa_s->ap_iface)
5520 break;
5521 hostapd_event_get_survey(wpa_s->ap_iface,
5522 &data->survey_results);
5523#endif /* CONFIG_AP */
5524 break;
5525 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005526#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005527#ifdef CONFIG_ACS
5528 if (!wpa_s->ap_iface)
5529 break;
5530 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5531 &data->acs_selected_channels);
5532#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005533#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005534 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005535 case EVENT_P2P_LO_STOP:
5536#ifdef CONFIG_P2P
5537 wpa_s->p2p_lo_started = 0;
5538 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5539 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5540 data->p2p_lo_stop.reason_code);
5541#endif /* CONFIG_P2P */
5542 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005543 case EVENT_BEACON_LOSS:
5544 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5545 break;
5546 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5547 bgscan_notify_beacon_loss(wpa_s);
5548 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005549 case EVENT_EXTERNAL_AUTH:
5550#ifdef CONFIG_SAE
5551 if (!wpa_s->current_ssid) {
5552 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5553 break;
5554 }
5555 sme_external_auth_trigger(wpa_s, data);
5556#endif /* CONFIG_SAE */
5557 break;
5558 case EVENT_PORT_AUTHORIZED:
5559 wpa_supplicant_event_port_authorized(wpa_s);
5560 break;
5561 case EVENT_STATION_OPMODE_CHANGED:
5562#ifdef CONFIG_AP
5563 if (!wpa_s->ap_iface || !data)
5564 break;
5565
5566 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5567 data->sta_opmode.addr,
5568 data->sta_opmode.smps_mode,
5569 data->sta_opmode.chan_width,
5570 data->sta_opmode.rx_nss);
5571#endif /* CONFIG_AP */
5572 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005573 case EVENT_UNPROT_BEACON:
5574 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5575 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005576 default:
5577 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5578 break;
5579 }
5580}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005581
5582
5583void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5584 union wpa_event_data *data)
5585{
5586 struct wpa_supplicant *wpa_s;
5587
5588 if (event != EVENT_INTERFACE_STATUS)
5589 return;
5590
5591 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5592 if (wpa_s && wpa_s->driver->get_ifindex) {
5593 unsigned int ifindex;
5594
5595 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5596 if (ifindex != data->interface_status.ifindex) {
5597 wpa_dbg(wpa_s, MSG_DEBUG,
5598 "interface status ifindex %d mismatch (%d)",
5599 ifindex, data->interface_status.ifindex);
5600 return;
5601 }
5602 }
5603#ifdef CONFIG_MATCH_IFACE
5604 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5605 struct wpa_interface *wpa_i;
5606
5607 wpa_i = wpa_supplicant_match_iface(
5608 ctx, data->interface_status.ifname);
5609 if (!wpa_i)
5610 return;
5611 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5612 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07005613 }
5614#endif /* CONFIG_MATCH_IFACE */
5615
5616 if (wpa_s)
5617 wpa_supplicant_event(wpa_s, event, data);
5618}