blob: 85c7190251f9a2321a152a15bfacad4226673943 [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"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "crypto/random.h"
34#include "blacklist.h"
35#include "wpas_glue.h"
36#include "wps_supplicant.h"
37#include "ibss_rsn.h"
38#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080039#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "p2p_supplicant.h"
41#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070042#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "ap.h"
44#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080046#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070047#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080048#include "mesh.h"
49#include "mesh_mpm.h"
50#include "wmm_ac.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070051#include "dpp_supplicant.h"
Mir Ali677e7482020-11-12 19:49:02 +053052#include "rsn_supp/wpa_i.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070053
54
Hai Shalom39ba6fc2019-01-22 12:40:38 -080055#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
56
57
Dmitry Shmidt34af3062013-07-11 10:46:32 -070058#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070059static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080060 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070061#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080062
63
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070064int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070065{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080066 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070067
68 if (ssid == NULL || ssid->disabled_until.sec == 0)
69 return 0;
70
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080071 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070072 if (ssid->disabled_until.sec > now.sec)
73 return ssid->disabled_until.sec - now.sec;
74
75 wpas_clear_temp_disabled(wpa_s, ssid, 0);
76
77 return 0;
78}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070079
80
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080081#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070082/**
83 * wpas_reenabled_network_time - Time until first network is re-enabled
84 * @wpa_s: Pointer to wpa_supplicant data
85 * Returns: If all enabled networks are temporarily disabled, returns the time
86 * (in sec) until the first network is re-enabled. Otherwise returns 0.
87 *
88 * This function is used in case all enabled networks are temporarily disabled,
89 * in which case it returns the time (in sec) that the first network will be
90 * re-enabled. The function assumes that at least one network is enabled.
91 */
92static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
93{
94 struct wpa_ssid *ssid;
95 int disabled_for, res = 0;
96
97#ifdef CONFIG_INTERWORKING
98 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
99 wpa_s->conf->cred)
100 return 0;
101#endif /* CONFIG_INTERWORKING */
102
103 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
104 if (ssid->disabled)
105 continue;
106
107 disabled_for = wpas_temp_disabled(wpa_s, ssid);
108 if (!disabled_for)
109 return 0;
110
111 if (!res || disabled_for < res)
112 res = disabled_for;
113 }
114
115 return res;
116}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800117#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700118
119
120void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
121{
122 struct wpa_supplicant *wpa_s = eloop_ctx;
123
124 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
125 return;
126
127 wpa_dbg(wpa_s, MSG_DEBUG,
128 "Try to associate due to network getting re-enabled");
129 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
130 wpa_supplicant_cancel_sched_scan(wpa_s);
131 wpa_supplicant_req_scan(wpa_s, 0, 0);
132 }
133}
134
135
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800136static struct wpa_bss * wpa_supplicant_get_new_bss(
137 struct wpa_supplicant *wpa_s, const u8 *bssid)
138{
139 struct wpa_bss *bss = NULL;
140 struct wpa_ssid *ssid = wpa_s->current_ssid;
141
142 if (ssid->ssid_len > 0)
143 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
144 if (!bss)
145 bss = wpa_bss_get_bssid(wpa_s, bssid);
146
147 return bss;
148}
149
150
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700151static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
152{
153 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
154
155 if (!bss) {
156 wpa_supplicant_update_scan_results(wpa_s);
157
158 /* Get the BSS from the new scan results */
159 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
160 }
161
162 if (bss)
163 wpa_s->current_bss = bss;
164}
165
166
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
168{
169 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700170 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700171 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700172 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700174 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
175 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700176
177 if (wpa_s->current_ssid->ssid_len == 0)
178 return 0; /* current profile still in use */
179 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
180 if (res < 0) {
181 wpa_msg(wpa_s, MSG_INFO,
182 "Failed to read SSID from driver");
183 return 0; /* try to use current profile */
184 }
185 drv_ssid_len = res;
186
187 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
188 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
189 drv_ssid_len) == 0)
190 return 0; /* current profile still in use */
191
Hai Shalomfdcde762020-04-02 11:19:20 -0700192#ifdef CONFIG_OWE
193 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
194 wpa_s->current_bss &&
195 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
196 drv_ssid_len == wpa_s->current_bss->ssid_len &&
197 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
198 drv_ssid_len) == 0)
199 return 0; /* current profile still in use */
200#endif /* CONFIG_OWE */
201
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700202 wpa_msg(wpa_s, MSG_DEBUG,
203 "Driver-initiated BSS selection changed the SSID to %s",
204 wpa_ssid_txt(drv_ssid, drv_ssid_len));
205 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700206 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700207
208 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
209 "information");
210 ssid = wpa_supplicant_get_ssid(wpa_s);
211 if (ssid == NULL) {
212 wpa_msg(wpa_s, MSG_INFO,
213 "No network configuration found for the current AP");
214 return -1;
215 }
216
Dmitry Shmidt04949592012-07-19 12:16:46 -0700217 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700218 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
219 return -1;
220 }
221
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800222 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
223 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
224 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
225 return -1;
226 }
227
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700228 res = wpas_temp_disabled(wpa_s, ssid);
229 if (res > 0) {
230 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
231 "disabled for %d second(s)", res);
232 return -1;
233 }
234
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700235 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
236 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800237 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238 u8 wpa_ie[80];
239 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800240 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
241 wpa_ie, &wpa_ie_len) < 0)
242 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243 } else {
244 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
245 }
246
247 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
248 eapol_sm_invalidate_cached_session(wpa_s->eapol);
249 old_ssid = wpa_s->current_ssid;
250 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800251
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700252 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800253
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
255 wpa_supplicant_initiate_eapol(wpa_s);
256 if (old_ssid != wpa_s->current_ssid)
257 wpas_notify_network_changed(wpa_s);
258
259 return 0;
260}
261
262
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800263void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264{
265 struct wpa_supplicant *wpa_s = eloop_ctx;
266
267 if (wpa_s->countermeasures) {
268 wpa_s->countermeasures = 0;
269 wpa_drv_set_countermeasures(wpa_s, 0);
270 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800271
272 /*
273 * It is possible that the device is sched scanning, which means
274 * that a connection attempt will be done only when we receive
275 * scan results. However, in this case, it would be preferable
276 * to scan and connect immediately, so cancel the sched_scan and
277 * issue a regular scan flow.
278 */
279 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280 wpa_supplicant_req_scan(wpa_s, 0, 0);
281 }
282}
283
284
285void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
286{
287 int bssid_changed;
288
Dmitry Shmidt04949592012-07-19 12:16:46 -0700289 wnm_bss_keep_alive_deinit(wpa_s);
290
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291#ifdef CONFIG_IBSS_RSN
292 ibss_rsn_deinit(wpa_s->ibss_rsn);
293 wpa_s->ibss_rsn = NULL;
294#endif /* CONFIG_IBSS_RSN */
295
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700296#ifdef CONFIG_AP
297 wpa_supplicant_ap_deinit(wpa_s);
298#endif /* CONFIG_AP */
299
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700300#ifdef CONFIG_HS20
301 /* Clear possibly configured frame filters */
302 wpa_drv_configure_frame_filters(wpa_s, 0);
303#endif /* CONFIG_HS20 */
304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
306 return;
307
Hai Shalom74f70d42019-02-11 14:42:39 -0800308 if (os_reltime_initialized(&wpa_s->session_start)) {
309 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
310 wpa_s->session_start.sec = 0;
311 wpa_s->session_start.usec = 0;
312 wpas_notify_session_length(wpa_s);
313 }
314
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
316 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
317 os_memset(wpa_s->bssid, 0, ETH_ALEN);
318 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800319 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320 wpa_s->current_bss = NULL;
321 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700322
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323 if (bssid_changed)
324 wpas_notify_bssid_changed(wpa_s);
325
Hai Shalome21d4e82020-04-29 16:34:06 -0700326 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
327 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700328 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
329 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700330 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700331 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700332 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700334 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700335 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700336 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800337
338 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800339 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800340 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700341 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700342
343#ifdef CONFIG_TESTING_OPTIONS
344 wpa_s->last_tk_alg = WPA_ALG_NONE;
345 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
346#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700347 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800348
349 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
350 wpa_s->enabled_4addr_mode = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351}
352
353
354static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
355{
356 struct wpa_ie_data ie;
357 int pmksa_set = -1;
358 size_t i;
359
Hai Shalom899fcc72020-10-19 14:38:18 -0700360 /* Start with assumption of no PMKSA cache entry match */
361 pmksa_cache_clear_current(wpa_s->wpa);
362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
364 ie.pmkid == NULL)
365 return;
366
367 for (i = 0; i < ie.num_pmkid; i++) {
368 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
369 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700370 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700371 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800372 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373 break;
374 }
375 }
376
377 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
378 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
379}
380
381
382static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
383 union wpa_event_data *data)
384{
385 if (data == NULL) {
386 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
387 "event");
388 return;
389 }
390 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
391 " index=%d preauth=%d",
392 MAC2STR(data->pmkid_candidate.bssid),
393 data->pmkid_candidate.index,
394 data->pmkid_candidate.preauth);
395
396 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
397 data->pmkid_candidate.index,
398 data->pmkid_candidate.preauth);
399}
400
401
402static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
403{
404 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
405 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
406 return 0;
407
408#ifdef IEEE8021X_EAPOL
409 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
410 wpa_s->current_ssid &&
411 !(wpa_s->current_ssid->eapol_flags &
412 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
413 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
414 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
415 * plaintext or static WEP keys). */
416 return 0;
417 }
418#endif /* IEEE8021X_EAPOL */
419
420 return 1;
421}
422
423
424/**
425 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
426 * @wpa_s: pointer to wpa_supplicant data
427 * @ssid: Configuration data for the network
428 * Returns: 0 on success, -1 on failure
429 *
430 * This function is called when starting authentication with a network that is
431 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
432 */
433int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
434 struct wpa_ssid *ssid)
435{
436#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800437#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700438 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700439
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700440 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
441 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700442 return 0;
443
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700444 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700445 sim = 1;
446 aka = 1;
447 } else {
448 struct eap_method_type *eap = ssid->eap.eap_methods;
449 while (eap->vendor != EAP_VENDOR_IETF ||
450 eap->method != EAP_TYPE_NONE) {
451 if (eap->vendor == EAP_VENDOR_IETF) {
452 if (eap->method == EAP_TYPE_SIM)
453 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700454 else if (eap->method == EAP_TYPE_AKA ||
455 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700456 aka = 1;
457 }
458 eap++;
459 }
460 }
461
462 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
463 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700464 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
465 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
466 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467 aka = 0;
468
469 if (!sim && !aka) {
470 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
471 "use SIM, but neither EAP-SIM nor EAP-AKA are "
472 "enabled");
473 return 0;
474 }
475
476 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
477 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700479 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480 if (wpa_s->scard == NULL) {
481 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
482 "(pcsc-lite)");
483 return -1;
484 }
485 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
486 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800487#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488#endif /* IEEE8021X_EAPOL */
489
490 return 0;
491}
492
493
494#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700495
Hai Shalomfdcde762020-04-02 11:19:20 -0700496#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700497static int has_wep_key(struct wpa_ssid *ssid)
498{
499 int i;
500
501 for (i = 0; i < NUM_WEP_KEYS; i++) {
502 if (ssid->wep_key_len[i])
503 return 1;
504 }
505
506 return 0;
507}
Hai Shalomfdcde762020-04-02 11:19:20 -0700508#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700509
510
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700511static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700512 struct wpa_ssid *ssid)
513{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700514 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515
516 if (ssid->mixed_cell)
517 return 1;
518
519#ifdef CONFIG_WPS
520 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
521 return 1;
522#endif /* CONFIG_WPS */
523
Roshan Pius3a1667e2018-07-03 15:17:14 -0700524#ifdef CONFIG_OWE
525 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
526 return 1;
527#endif /* CONFIG_OWE */
528
Hai Shalomfdcde762020-04-02 11:19:20 -0700529#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700530 if (has_wep_key(ssid))
531 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700532#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700533
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534#ifdef IEEE8021X_EAPOL
535 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
536 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
537 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
538 privacy = 1;
539#endif /* IEEE8021X_EAPOL */
540
Jouni Malinen75ecf522011-06-27 15:19:46 -0700541 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
542 privacy = 1;
543
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800544 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
545 privacy = 1;
546
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700547 if (bss->caps & IEEE80211_CAP_PRIVACY)
548 return privacy;
549 return !privacy;
550}
551
552
553static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
554 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800555 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556{
557 struct wpa_ie_data ie;
558 int proto_match = 0;
559 const u8 *rsn_ie, *wpa_ie;
560 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700561#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700563#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564
565 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
566 if (ret >= 0)
567 return ret;
568
Hai Shalomfdcde762020-04-02 11:19:20 -0700569#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
571 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
572 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
573 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
574 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700575#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700577 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700578 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700579 proto_match++;
580
581 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800582 if (debug_print)
583 wpa_dbg(wpa_s, MSG_DEBUG,
584 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585 break;
586 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700587 if (!ie.has_pairwise)
588 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
589 if (!ie.has_group)
590 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591
Hai Shalomfdcde762020-04-02 11:19:20 -0700592#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593 if (wep_ok &&
594 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
595 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800596 if (debug_print)
597 wpa_dbg(wpa_s, MSG_DEBUG,
598 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700599 return 1;
600 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700601#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602
Roshan Pius3a1667e2018-07-03 15:17:14 -0700603 if (!(ie.proto & ssid->proto) &&
604 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800605 if (debug_print)
606 wpa_dbg(wpa_s, MSG_DEBUG,
607 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700608 break;
609 }
610
611 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800612 if (debug_print)
613 wpa_dbg(wpa_s, MSG_DEBUG,
614 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700615 break;
616 }
617
618 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800619 if (debug_print)
620 wpa_dbg(wpa_s, MSG_DEBUG,
621 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700622 break;
623 }
624
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700625 if (ssid->group_mgmt_cipher &&
626 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
627 if (debug_print)
628 wpa_dbg(wpa_s, MSG_DEBUG,
629 " skip RSN IE - group mgmt cipher mismatch");
630 break;
631 }
632
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800634 if (debug_print)
635 wpa_dbg(wpa_s, MSG_DEBUG,
636 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700637 break;
638 }
639
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700640 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800641 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800642 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800643 if (debug_print)
644 wpa_dbg(wpa_s, MSG_DEBUG,
645 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646 break;
647 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800648 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
649 wpas_get_ssid_pmf(wpa_s, ssid) ==
650 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800651 if (debug_print)
652 wpa_dbg(wpa_s, MSG_DEBUG,
653 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800654 break;
655 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800657 if (debug_print)
658 wpa_dbg(wpa_s, MSG_DEBUG,
659 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700660 return 1;
661 }
662
Roshan Pius3a1667e2018-07-03 15:17:14 -0700663 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
664 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800665 if (debug_print)
666 wpa_dbg(wpa_s, MSG_DEBUG,
667 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700668 return 0;
669 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700670
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700671 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700672 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
673 proto_match++;
674
675 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800676 if (debug_print)
677 wpa_dbg(wpa_s, MSG_DEBUG,
678 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679 break;
680 }
681
Hai Shalomfdcde762020-04-02 11:19:20 -0700682#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683 if (wep_ok &&
684 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
685 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800686 if (debug_print)
687 wpa_dbg(wpa_s, MSG_DEBUG,
688 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689 return 1;
690 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700691#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700692
693 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800694 if (debug_print)
695 wpa_dbg(wpa_s, MSG_DEBUG,
696 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700697 break;
698 }
699
700 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800701 if (debug_print)
702 wpa_dbg(wpa_s, MSG_DEBUG,
703 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700704 break;
705 }
706
707 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800708 if (debug_print)
709 wpa_dbg(wpa_s, MSG_DEBUG,
710 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700711 break;
712 }
713
714 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800715 if (debug_print)
716 wpa_dbg(wpa_s, MSG_DEBUG,
717 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700718 break;
719 }
720
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800721 if (debug_print)
722 wpa_dbg(wpa_s, MSG_DEBUG,
723 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 return 1;
725 }
726
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700727 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
728 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800729 if (debug_print)
730 wpa_dbg(wpa_s, MSG_DEBUG,
731 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700732 return 1;
733 }
734
Roshan Pius3a1667e2018-07-03 15:17:14 -0700735#ifdef CONFIG_OWE
736 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
737 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800738 if (wpa_s->owe_transition_select &&
739 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
740 ssid->owe_transition_bss_select_count + 1 <=
741 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
742 ssid->owe_transition_bss_select_count++;
743 if (debug_print)
744 wpa_dbg(wpa_s, MSG_DEBUG,
745 " skip OWE transition BSS (selection count %d does not exceed %d)",
746 ssid->owe_transition_bss_select_count,
747 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
748 wpa_s->owe_transition_search = 1;
749 return 0;
750 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700751 if (debug_print)
752 wpa_dbg(wpa_s, MSG_DEBUG,
753 " allow in OWE transition mode");
754 return 1;
755 }
756#endif /* CONFIG_OWE */
757
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700758 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
759 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800760 if (debug_print)
761 wpa_dbg(wpa_s, MSG_DEBUG,
762 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 return 0;
764 }
765
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800766 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
767 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800768 if (debug_print)
769 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800770 return 1;
771 }
772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800774 if (debug_print)
775 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776 return 1;
777 }
778
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800779 if (debug_print)
780 wpa_dbg(wpa_s, MSG_DEBUG,
781 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782
783 return 0;
784}
785
786
787static int freq_allowed(int *freqs, int freq)
788{
789 int i;
790
791 if (freqs == NULL)
792 return 1;
793
794 for (i = 0; freqs[i]; i++)
795 if (freqs[i] == freq)
796 return 1;
797 return 0;
798}
799
800
Hai Shalomfdcde762020-04-02 11:19:20 -0700801static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
802 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800803{
804 const struct hostapd_hw_modes *mode = NULL, *modes;
805 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
806 const u8 *rate_ie;
807 int i, j, k;
808
809 if (bss->freq == 0)
810 return 1; /* Cannot do matching without knowing band */
811
812 modes = wpa_s->hw.modes;
813 if (modes == NULL) {
814 /*
815 * The driver does not provide any additional information
816 * about the utilized hardware, so allow the connection attempt
817 * to continue.
818 */
819 return 1;
820 }
821
822 for (i = 0; i < wpa_s->hw.num_modes; i++) {
823 for (j = 0; j < modes[i].num_channels; j++) {
824 int freq = modes[i].channels[j].freq;
825 if (freq == bss->freq) {
826 if (mode &&
827 mode->mode == HOSTAPD_MODE_IEEE80211G)
828 break; /* do not allow 802.11b replace
829 * 802.11g */
830 mode = &modes[i];
831 break;
832 }
833 }
834 }
835
836 if (mode == NULL)
837 return 0;
838
839 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700840 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800841 if (rate_ie == NULL)
842 continue;
843
844 for (j = 2; j < rate_ie[1] + 2; j++) {
845 int flagged = !!(rate_ie[j] & 0x80);
846 int r = (rate_ie[j] & 0x7f) * 5;
847
848 /*
849 * IEEE Std 802.11n-2009 7.3.2.2:
850 * The new BSS Membership selector value is encoded
851 * like a legacy basic rate, but it is not a rate and
852 * only indicates if the BSS members are required to
853 * support the mandatory features of Clause 20 [HT PHY]
854 * in order to join the BSS.
855 */
856 if (flagged && ((rate_ie[j] & 0x7f) ==
857 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
858 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800859 if (debug_print)
860 wpa_dbg(wpa_s, MSG_DEBUG,
861 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800862 return 0;
863 }
864 continue;
865 }
866
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700867 /* There's also a VHT selector for 802.11ac */
868 if (flagged && ((rate_ie[j] & 0x7f) ==
869 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
870 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800871 if (debug_print)
872 wpa_dbg(wpa_s, MSG_DEBUG,
873 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700874 return 0;
875 }
876 continue;
877 }
878
Hai Shalomc3565922019-10-28 11:58:20 -0700879#ifdef CONFIG_SAE
880 if (flagged && ((rate_ie[j] & 0x7f) ==
881 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700882 if (wpa_s->conf->sae_pwe == 0 &&
883 !ssid->sae_password_id &&
884 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700885 if (debug_print)
886 wpa_dbg(wpa_s, MSG_DEBUG,
887 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800888#ifdef CONFIG_TESTING_OPTIONS
889 if (wpa_s->ignore_sae_h2e_only) {
890 wpa_dbg(wpa_s, MSG_DEBUG,
891 "TESTING: Ignore SAE H2E requirement mismatch");
892 continue;
893 }
894#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700895 return 0;
896 }
897 continue;
898 }
899#endif /* CONFIG_SAE */
900
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800901 if (!flagged)
902 continue;
903
904 /* check for legacy basic rates */
905 for (k = 0; k < mode->num_rates; k++) {
906 if (mode->rates[k] == r)
907 break;
908 }
909 if (k == mode->num_rates) {
910 /*
911 * IEEE Std 802.11-2007 7.3.2.2 demands that in
912 * order to join a BSS all required rates
913 * have to be supported by the hardware.
914 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800915 if (debug_print)
916 wpa_dbg(wpa_s, MSG_DEBUG,
917 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
918 r / 10, r % 10,
919 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800920 return 0;
921 }
922 }
923 }
924
925 return 1;
926}
927
928
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800929/*
930 * Test whether BSS is in an ESS.
931 * This is done differently in DMG (60 GHz) and non-DMG bands
932 */
933static int bss_is_ess(struct wpa_bss *bss)
934{
935 if (bss_is_dmg(bss)) {
936 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
937 IEEE80211_CAP_DMG_AP;
938 }
939
940 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
941 IEEE80211_CAP_ESS);
942}
943
944
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800945static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
946{
947 size_t i;
948
949 for (i = 0; i < ETH_ALEN; i++) {
950 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
951 return 0;
952 }
953 return 1;
954}
955
956
957static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
958{
959 size_t i;
960
961 for (i = 0; i < num; i++) {
962 const u8 *a = list + i * ETH_ALEN * 2;
963 const u8 *m = a + ETH_ALEN;
964
965 if (match_mac_mask(a, addr, m))
966 return 1;
967 }
968 return 0;
969}
970
971
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700972static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
973 const u8 **ret_ssid, size_t *ret_ssid_len)
974{
975#ifdef CONFIG_OWE
976 const u8 *owe, *pos, *end, *bssid;
977 u8 ssid_len;
978 struct wpa_bss *open_bss;
979
980 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
981 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
982 return;
983
984 pos = owe + 6;
985 end = owe + 2 + owe[1];
986
987 if (end - pos < ETH_ALEN + 1)
988 return;
989 bssid = pos;
990 pos += ETH_ALEN;
991 ssid_len = *pos++;
992 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
993 return;
994
995 /* Match the profile SSID against the OWE transition mode SSID on the
996 * open network. */
997 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
998 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
999 *ret_ssid = pos;
1000 *ret_ssid_len = ssid_len;
1001
Hai Shalomfdcde762020-04-02 11:19:20 -07001002 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1003 struct wpa_ssid *ssid;
1004
1005 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1006 if (wpas_network_disabled(wpa_s, ssid))
1007 continue;
1008 if (ssid->ssid_len == ssid_len &&
1009 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1010 /* OWE BSS in transition mode for a currently
1011 * enabled OWE network. */
1012 wpa_dbg(wpa_s, MSG_DEBUG,
1013 "OWE: transition mode OWE SSID for active OWE profile");
1014 bss->flags |= WPA_BSS_OWE_TRANSITION;
1015 break;
1016 }
1017 }
1018 }
1019
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001020 if (bss->ssid_len > 0)
1021 return;
1022
1023 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1024 if (!open_bss)
1025 return;
1026 if (ssid_len != open_bss->ssid_len ||
1027 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1028 wpa_dbg(wpa_s, MSG_DEBUG,
1029 "OWE: transition mode SSID mismatch: %s",
1030 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1031 return;
1032 }
1033
1034 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1035 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1036 wpa_dbg(wpa_s, MSG_DEBUG,
1037 "OWE: transition mode open BSS unexpected info");
1038 return;
1039 }
1040
1041 pos = owe + 6;
1042 end = owe + 2 + owe[1];
1043
1044 if (end - pos < ETH_ALEN + 1)
1045 return;
1046 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1047 wpa_dbg(wpa_s, MSG_DEBUG,
1048 "OWE: transition mode BSSID mismatch: " MACSTR,
1049 MAC2STR(pos));
1050 return;
1051 }
1052 pos += ETH_ALEN;
1053 ssid_len = *pos++;
1054 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1055 return;
1056 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1057 wpa_ssid_txt(pos, ssid_len));
1058 os_memcpy(bss->ssid, pos, ssid_len);
1059 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001060 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001061#endif /* CONFIG_OWE */
1062}
1063
1064
Hai Shalomfdcde762020-04-02 11:19:20 -07001065static int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
1066{
1067 int i, j;
1068
1069 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1070 return 0;
1071
1072 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1073 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1074
1075 for (i = 0; i < mode->num_channels; i++) {
1076 struct hostapd_channel_data *chan = &mode->channels[i];
1077
1078 if (chan->freq == freq)
1079 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1080 }
1081 }
1082
1083 return 1;
1084}
1085
1086
Hai Shalom899fcc72020-10-19 14:38:18 -07001087static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1088 const u8 *match_ssid, size_t match_ssid_len,
1089 struct wpa_bss *bss, int blacklist_count,
1090 bool debug_print);
1091
1092
1093#ifdef CONFIG_SAE_PK
1094static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1095 struct wpa_bss *orig_bss,
1096 struct wpa_ssid *ssid,
1097 const u8 *match_ssid,
1098 size_t match_ssid_len)
1099{
1100 struct wpa_bss *bss;
1101
1102 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1103 int count;
1104 const u8 *ie;
1105 u8 rsnxe_capa = 0;
1106
1107 if (bss == orig_bss)
1108 continue;
1109 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1110 if (ie && ie[1] >= 1)
1111 rsnxe_capa = ie[2];
1112 if (!(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)))
1113 continue;
1114
1115 /* TODO: Could be more thorough in checking what kind of
1116 * signal strength or throughput estimate would be acceptable
1117 * compared to the originally selected BSS. */
1118 if (bss->est_throughput < 2000)
1119 return false;
1120
1121 count = wpa_blacklist_is_blacklisted(wpa_s, bss->bssid);
1122 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1123 bss, count, 0))
1124 return true;
1125 }
1126
1127 return false;
1128}
1129#endif /* CONFIG_SAE_PK */
1130
1131
1132static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1133 const u8 *match_ssid, size_t match_ssid_len,
1134 struct wpa_bss *bss, int blacklist_count,
1135 bool debug_print)
1136{
1137 int res;
1138 bool wpa, check_ssid, osen, rsn_osen = false;
1139 struct wpa_ie_data data;
1140#ifdef CONFIG_MBO
1141 const u8 *assoc_disallow;
1142#endif /* CONFIG_MBO */
1143#ifdef CONFIG_SAE
1144 u8 rsnxe_capa = 0;
1145#endif /* CONFIG_SAE */
1146 const u8 *ie;
1147
1148 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1149 wpa = ie && ie[1];
1150 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1151 wpa |= ie && ie[1];
1152 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1153 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1154 rsn_osen = true;
1155 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1156 osen = ie != NULL;
1157
1158#ifdef CONFIG_SAE
1159 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1160 if (ie && ie[1] >= 1)
1161 rsnxe_capa = ie[2];
1162#endif /* CONFIG_SAE */
1163
1164 check_ssid = wpa || ssid->ssid_len > 0;
1165
1166 if (wpas_network_disabled(wpa_s, ssid)) {
1167 if (debug_print)
1168 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1169 return false;
1170 }
1171
1172 res = wpas_temp_disabled(wpa_s, ssid);
1173 if (res > 0) {
1174 if (debug_print)
1175 wpa_dbg(wpa_s, MSG_DEBUG,
1176 " skip - disabled temporarily for %d second(s)",
1177 res);
1178 return false;
1179 }
1180
1181#ifdef CONFIG_WPS
1182 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && blacklist_count) {
1183 if (debug_print)
1184 wpa_dbg(wpa_s, MSG_DEBUG,
1185 " skip - blacklisted (WPS)");
1186 return false;
1187 }
1188
1189 if (wpa && ssid->ssid_len == 0 &&
1190 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1191 check_ssid = false;
1192
1193 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1194 /* Only allow wildcard SSID match if an AP advertises active
1195 * WPS operation that matches our mode. */
1196 check_ssid = ssid->ssid_len > 0 ||
1197 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1198 }
1199#endif /* CONFIG_WPS */
1200
1201 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1202 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1203 check_ssid = false;
1204
1205 if (check_ssid &&
1206 (match_ssid_len != ssid->ssid_len ||
1207 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1208 if (debug_print)
1209 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1210 return false;
1211 }
1212
1213 if (ssid->bssid_set &&
1214 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1215 if (debug_print)
1216 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1217 return false;
1218 }
1219
1220 /* check blacklist */
1221 if (ssid->num_bssid_blacklist &&
1222 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1223 ssid->num_bssid_blacklist)) {
1224 if (debug_print)
1225 wpa_dbg(wpa_s, MSG_DEBUG,
1226 " skip - BSSID blacklisted");
1227 return false;
1228 }
1229
1230 /* if there is a whitelist, only accept those APs */
1231 if (ssid->num_bssid_whitelist &&
1232 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1233 ssid->num_bssid_whitelist)) {
1234 if (debug_print)
1235 wpa_dbg(wpa_s, MSG_DEBUG,
1236 " skip - BSSID not in whitelist");
1237 return false;
1238 }
1239
1240 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1241 return false;
1242
1243 if (!osen && !wpa &&
1244 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1245 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1246 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1247 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1248 if (debug_print)
1249 wpa_dbg(wpa_s, MSG_DEBUG,
1250 " skip - non-WPA network not allowed");
1251 return false;
1252 }
1253
1254#ifdef CONFIG_WEP
1255 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1256 if (debug_print)
1257 wpa_dbg(wpa_s, MSG_DEBUG,
1258 " skip - ignore WPA/WPA2 AP for WEP network block");
1259 return false;
1260 }
1261#endif /* CONFIG_WEP */
1262
1263 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1264 if (debug_print)
1265 wpa_dbg(wpa_s, MSG_DEBUG,
1266 " skip - non-OSEN network not allowed");
1267 return false;
1268 }
1269
1270 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1271 if (debug_print)
1272 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1273 return false;
1274 }
1275
1276 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1277 !bss_is_pbss(bss)) {
1278 if (debug_print)
1279 wpa_dbg(wpa_s, MSG_DEBUG,
1280 " skip - not ESS, PBSS, or MBSS");
1281 return false;
1282 }
1283
1284 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1285 if (debug_print)
1286 wpa_dbg(wpa_s, MSG_DEBUG,
1287 " skip - PBSS mismatch (ssid %d bss %d)",
1288 ssid->pbss, bss_is_pbss(bss));
1289 return false;
1290 }
1291
1292 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1293 if (debug_print)
1294 wpa_dbg(wpa_s, MSG_DEBUG,
1295 " skip - frequency not allowed");
1296 return false;
1297 }
1298
1299#ifdef CONFIG_MESH
1300 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1301 ssid->frequency != bss->freq) {
1302 if (debug_print)
1303 wpa_dbg(wpa_s, MSG_DEBUG,
1304 " skip - frequency not allowed (mesh)");
1305 return false;
1306 }
1307#endif /* CONFIG_MESH */
1308
1309 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1310 if (debug_print)
1311 wpa_dbg(wpa_s, MSG_DEBUG,
1312 " skip - rate sets do not match");
1313 return false;
1314 }
1315
1316#ifdef CONFIG_SAE
1317 if ((wpa_s->conf->sae_pwe == 1 || ssid->sae_password_id) &&
1318 wpa_s->conf->sae_pwe != 3 && wpa_key_mgmt_sae(ssid->key_mgmt) &&
1319 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1320 if (debug_print)
1321 wpa_dbg(wpa_s, MSG_DEBUG,
1322 " skip - SAE H2E required, but not supported by the AP");
1323 return false;
1324 }
1325#endif /* CONFIG_SAE */
1326
1327#ifdef CONFIG_SAE_PK
1328 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1329 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1330 if (debug_print)
1331 wpa_dbg(wpa_s, MSG_DEBUG,
1332 " skip - SAE-PK required, but not supported by the AP");
1333 return false;
1334 }
1335#endif /* CONFIG_SAE_PK */
1336
1337#ifndef CONFIG_IBSS_RSN
1338 if (ssid->mode == WPAS_MODE_IBSS &&
1339 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1340 if (debug_print)
1341 wpa_dbg(wpa_s, MSG_DEBUG,
1342 " skip - IBSS RSN not supported in the build");
1343 return false;
1344 }
1345#endif /* !CONFIG_IBSS_RSN */
1346
1347#ifdef CONFIG_P2P
1348 if (ssid->p2p_group &&
1349 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1350 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1351 if (debug_print)
1352 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1353 return false;
1354 }
1355
1356 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1357 struct wpabuf *p2p_ie;
1358 u8 dev_addr[ETH_ALEN];
1359
1360 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1361 if (!ie) {
1362 if (debug_print)
1363 wpa_dbg(wpa_s, MSG_DEBUG,
1364 " skip - no P2P element");
1365 return false;
1366 }
1367 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1368 if (!p2p_ie) {
1369 if (debug_print)
1370 wpa_dbg(wpa_s, MSG_DEBUG,
1371 " skip - could not fetch P2P element");
1372 return false;
1373 }
1374
1375 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1376 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1377 if (debug_print)
1378 wpa_dbg(wpa_s, MSG_DEBUG,
1379 " skip - no matching GO P2P Device Address in P2P element");
1380 wpabuf_free(p2p_ie);
1381 return false;
1382 }
1383 wpabuf_free(p2p_ie);
1384 }
1385
1386 /*
1387 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1388 * P2P Group Capability Bitmap and we are not in Group Formation with
1389 * that device.
1390 */
1391#endif /* CONFIG_P2P */
1392
1393 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1394 struct os_reltime diff;
1395
1396 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1397 if (debug_print)
1398 wpa_dbg(wpa_s, MSG_DEBUG,
1399 " skip - scan result not recent enough (%u.%06u seconds too old)",
1400 (unsigned int) diff.sec,
1401 (unsigned int) diff.usec);
1402 return false;
1403 }
1404#ifdef CONFIG_MBO
1405#ifdef CONFIG_TESTING_OPTIONS
1406 if (wpa_s->ignore_assoc_disallow)
1407 goto skip_assoc_disallow;
1408#endif /* CONFIG_TESTING_OPTIONS */
1409 assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1410 if (assoc_disallow && assoc_disallow[1] >= 1) {
1411 if (debug_print)
1412 wpa_dbg(wpa_s, MSG_DEBUG,
1413 " skip - MBO association disallowed (reason %u)",
1414 assoc_disallow[2]);
1415 return false;
1416 }
1417
1418 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1419 if (debug_print)
1420 wpa_dbg(wpa_s, MSG_DEBUG,
1421 " skip - AP temporarily disallowed");
1422 return false;
1423 }
1424#ifdef CONFIG_TESTING_OPTIONS
1425skip_assoc_disallow:
1426#endif /* CONFIG_TESTING_OPTIONS */
1427#endif /* CONFIG_MBO */
1428
1429#ifdef CONFIG_DPP
1430 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1431 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1432 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1433 !ssid->dpp_csign)) {
1434 if (debug_print)
1435 wpa_dbg(wpa_s, MSG_DEBUG,
1436 " skip - no PMKSA entry for DPP");
1437 return false;
1438 }
1439#endif /* CONFIG_DPP */
1440
1441#ifdef CONFIG_SAE_PK
1442 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1443 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1444 ((ssid->sae_password &&
1445 sae_pk_valid_password(ssid->sae_password)) ||
1446 (!ssid->sae_password && ssid->passphrase &&
1447 sae_pk_valid_password(ssid->passphrase))) &&
1448 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1449 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1450 match_ssid_len)) {
1451 if (debug_print)
1452 wpa_dbg(wpa_s, MSG_DEBUG,
1453 " skip - another acceptable BSS with SAE-PK in the same ESS");
1454 return false;
1455 }
1456#endif /* CONFIG_SAE_PK */
1457
1458 if (bss->ssid_len == 0) {
1459 if (debug_print)
1460 wpa_dbg(wpa_s, MSG_DEBUG,
1461 " skip - no SSID known for the BSS");
1462 return false;
1463 }
1464
1465 /* Matching configuration found */
1466 return true;
1467}
1468
1469
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001470struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1471 int i, struct wpa_bss *bss,
1472 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001473 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001474{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001475 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001476 const u8 *ie;
1477 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001478 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001479 const u8 *match_ssid;
1480 size_t match_ssid_len;
Hai Shalom899fcc72020-10-19 14:38:18 -07001481 int blacklist_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001483 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001484 wpa_ie_len = ie ? ie[1] : 0;
1485
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001486 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001487 rsn_ie_len = ie ? ie[1] : 0;
1488
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001489 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1490 osen = ie != NULL;
1491
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001492 if (debug_print) {
1493 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1494 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1495 i, MAC2STR(bss->bssid),
1496 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1497 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1498 bss->freq,
1499 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1500 " wps" : "",
1501 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1502 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1503 ? " p2p" : "",
1504 osen ? " osen=1" : "");
1505 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001506
Hai Shalom899fcc72020-10-19 14:38:18 -07001507 blacklist_count = wpa_blacklist_is_blacklisted(wpa_s, bss->bssid);
1508 if (blacklist_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001509 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001510 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001511 /*
1512 * When only a single network is enabled, we can
1513 * trigger blacklisting on the first failure. This
1514 * should not be done with multiple enabled networks to
1515 * avoid getting forced to move into a worse ESS on
1516 * single error if there are no other BSSes of the
1517 * current ESS.
1518 */
1519 limit = 0;
1520 }
Hai Shalom899fcc72020-10-19 14:38:18 -07001521 if (blacklist_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001522 if (debug_print) {
1523 wpa_dbg(wpa_s, MSG_DEBUG,
1524 " skip - blacklisted (count=%d limit=%d)",
Hai Shalom899fcc72020-10-19 14:38:18 -07001525 blacklist_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001526 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001527 return NULL;
1528 }
1529 }
1530
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001531 match_ssid = bss->ssid;
1532 match_ssid_len = bss->ssid_len;
1533 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1534
1535 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001536 if (debug_print)
1537 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001538 return NULL;
1539 }
1540
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001541 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001542 if (debug_print)
1543 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001544 return NULL;
1545 }
1546
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001547 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001548 if (debug_print)
1549 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001550 return NULL;
1551 }
1552
Hai Shalomfdcde762020-04-02 11:19:20 -07001553 if (disabled_freq(wpa_s, bss->freq)) {
1554 if (debug_print)
1555 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1556 return NULL;
1557 }
1558
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001559 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001560 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1561 bss, blacklist_count, debug_print))
1562 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001563 }
1564
1565 /* No matching configuration found */
1566 return NULL;
1567}
1568
1569
1570static struct wpa_bss *
1571wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001572 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001573 struct wpa_ssid **selected_ssid,
1574 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001576 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001577
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001578 if (wpa_s->current_ssid) {
1579 struct wpa_ssid *ssid;
1580
1581 wpa_dbg(wpa_s, MSG_DEBUG,
1582 "Scan results matching the currently selected network");
1583 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1584 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1585
1586 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1587 only_first_ssid, 0);
1588 if (ssid != wpa_s->current_ssid)
1589 continue;
1590 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1591 " freq=%d level=%d snr=%d est_throughput=%u",
1592 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1593 bss->snr, bss->est_throughput);
1594 }
1595 }
1596
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001597 if (only_first_ssid)
1598 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1599 group->id);
1600 else
1601 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1602 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001603
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001604 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1605 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001606
1607 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001608 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001609 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001610 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001611 if (!*selected_ssid)
1612 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001613 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001614 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001615 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001616 MAC2STR(bss->bssid),
1617 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1618 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001619 }
1620
1621 return NULL;
1622}
1623
1624
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001625struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1626 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001627{
1628 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001629 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001630 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001631 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001632
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001633 if (wpa_s->last_scan_res == NULL ||
1634 wpa_s->last_scan_res_used == 0)
1635 return NULL; /* no scan results from last update */
1636
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001637 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001638 /* check that next_ssid is still valid */
1639 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1640 if (ssid == wpa_s->next_ssid)
1641 break;
1642 }
1643 next_ssid = ssid;
1644 wpa_s->next_ssid = NULL;
1645 }
1646
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001648 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1649 if (next_ssid && next_ssid->priority ==
1650 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001651 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001652 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001653 if (selected)
1654 break;
1655 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001656 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001657 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001658 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001659 if (selected)
1660 break;
1661 }
1662
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001663 if (selected == NULL && wpa_s->blacklist &&
1664 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001665 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1666 "blacklist and try again");
1667 wpa_blacklist_clear(wpa_s);
1668 wpa_s->blacklist_cleared++;
1669 } else if (selected == NULL)
1670 break;
1671 }
1672
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001673 ssid = *selected_ssid;
1674 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1675 !ssid->passphrase && !ssid->ext_psk) {
1676 const char *field_name, *txt = NULL;
1677
1678 wpa_dbg(wpa_s, MSG_DEBUG,
1679 "PSK/passphrase not yet available for the selected network");
1680
1681 wpas_notify_network_request(wpa_s, ssid,
1682 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1683
1684 field_name = wpa_supplicant_ctrl_req_to_string(
1685 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1686 if (field_name == NULL)
1687 return NULL;
1688
1689 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1690
1691 selected = NULL;
1692 }
1693
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001694 return selected;
1695}
1696
1697
1698static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1699 int timeout_sec, int timeout_usec)
1700{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001701 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001702 /*
1703 * No networks are enabled; short-circuit request so
1704 * we don't wait timeout seconds before transitioning
1705 * to INACTIVE state.
1706 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001707 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1708 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001709 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1710 return;
1711 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001712
1713 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001714 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1715}
1716
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001717
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001718int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001719 struct wpa_bss *selected,
1720 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001721{
1722 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1723 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1724 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001725 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001726#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001727 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1728 wpa_s->p2p_in_provisioning) {
1729 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1730 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001731 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001732 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001733#endif /* CONFIG_P2P */
1734
1735#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001736 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001737 wpas_wps_cancel(wpa_s);
1738#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001739 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001740 }
1741
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001742 wpa_msg(wpa_s, MSG_DEBUG,
1743 "Considering connect request: reassociate: %d selected: "
1744 MACSTR " bssid: " MACSTR " pending: " MACSTR
1745 " wpa_state: %s ssid=%p current_ssid=%p",
1746 wpa_s->reassociate, MAC2STR(selected->bssid),
1747 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1748 wpa_supplicant_state_txt(wpa_s->wpa_state),
1749 ssid, wpa_s->current_ssid);
1750
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001751 /*
1752 * Do not trigger new association unless the BSSID has changed or if
1753 * reassociation is requested. If we are in process of associating with
1754 * the selected BSSID, do not trigger new attempt.
1755 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001756 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1758 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1759 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001760 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1761 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1762 0) ||
1763 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1764 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001765 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1766 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001767 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001768 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001769 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1770 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001771 wpa_supplicant_associate(wpa_s, selected, ssid);
1772 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001773 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1774 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001775 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001776
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001777 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778}
1779
1780
1781static struct wpa_ssid *
1782wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1783{
Hai Shalomfdcde762020-04-02 11:19:20 -07001784 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001785 struct wpa_ssid *ssid;
1786
1787 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1788 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1789 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001790 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001791 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001792#ifndef CONFIG_IBSS_RSN
1793 if (ssid->mode == WPAS_MODE_IBSS &&
1794 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1795 WPA_KEY_MGMT_WPA_NONE))) {
1796 wpa_msg(wpa_s, MSG_INFO,
1797 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1798 wpa_ssid_txt(ssid->ssid,
1799 ssid->ssid_len));
1800 continue;
1801 }
1802#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001803 if (ssid->mode == WPAS_MODE_IBSS ||
1804 ssid->mode == WPAS_MODE_AP ||
1805 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001806 return ssid;
1807 }
1808 }
1809 return NULL;
1810}
1811
1812
1813/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1814 * on BSS added and BSS changed events */
1815static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001816 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001818 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001819
1820 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1821 return;
1822
Jouni Malinen87fd2792011-05-16 18:35:42 +03001823 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001825
Jouni Malinen87fd2792011-05-16 18:35:42 +03001826 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827 if (ssid == NULL)
1828 continue;
1829
Jouni Malinen87fd2792011-05-16 18:35:42 +03001830 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001831 if (rsn == NULL)
1832 continue;
1833
Jouni Malinen87fd2792011-05-16 18:35:42 +03001834 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835 }
1836
1837}
1838
1839
Hai Shalomfdcde762020-04-02 11:19:20 -07001840#ifndef CONFIG_NO_ROAMING
1841
1842static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1843{
1844 if (noise == WPA_INVALID_NOISE)
1845 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1846 DEFAULT_NOISE_FLOOR_2GHZ;
1847 return avg_signal - noise;
1848}
1849
1850
1851static unsigned int
1852wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1853 const struct wpa_bss *bss, int snr)
1854{
1855 int rate = wpa_bss_get_max_rate(bss);
1856 const u8 *ies = (const void *) (bss + 1);
1857 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1858
1859 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr);
1860}
1861
Hai Shalomfdcde762020-04-02 11:19:20 -07001862
Hai Shalom899fcc72020-10-19 14:38:18 -07001863int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1864 struct wpa_bss *current_bss,
1865 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001866{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001867 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001868 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001869 int cur_level;
1870 unsigned int cur_est, sel_est;
1871 struct wpa_signal_info si;
1872 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001873 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001875 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001876 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001877 " freq=%d level=%d snr=%d est_throughput=%u",
1878 MAC2STR(current_bss->bssid),
1879 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001880 current_bss->snr, current_bss->est_throughput);
1881 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001882 " freq=%d level=%d snr=%d est_throughput=%u",
1883 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001884 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001885
1886 if (wpa_s->current_ssid->bssid_set &&
1887 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1888 0) {
1889 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1890 "has preferred BSSID");
1891 return 1;
1892 }
1893
Hai Shalomfdcde762020-04-02 11:19:20 -07001894 cur_level = current_bss->level;
1895 cur_est = current_bss->est_throughput;
1896 sel_est = selected->est_throughput;
1897
1898 /*
1899 * Try to poll the signal from the driver since this will allow to get
1900 * more accurate values. In some cases, there can be big differences
1901 * between the RSSI of the Probe Response frames of the AP we are
1902 * associated with and the Beacon frames we hear from the same AP after
1903 * association. This can happen, e.g., when there are two antennas that
1904 * hear the AP very differently. If the driver chooses to hear the
1905 * Probe Response frames during the scan on the "bad" antenna because
1906 * it wants to save power, but knows to choose the other antenna after
1907 * association, we will hear our AP with a low RSSI as part of the
1908 * scan even when we can hear it decently on the other antenna. To cope
1909 * with this, ask the driver to teach us how it hears the AP. Also, the
1910 * scan results may be a bit old, since we can very quickly get fresh
1911 * information about our currently associated AP.
1912 */
1913 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1914 (si.avg_beacon_signal || si.avg_signal)) {
1915 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1916 si.avg_signal;
1917 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
1918 si.current_noise);
1919
1920 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
1921 current_bss,
1922 cur_snr);
1923 wpa_dbg(wpa_s, MSG_DEBUG,
1924 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
1925 cur_level, cur_snr, cur_est);
1926 }
1927
1928 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001929 wpa_dbg(wpa_s, MSG_DEBUG,
1930 "Allow reassociation - selected BSS has better estimated throughput");
1931 return 1;
1932 }
1933
Dmitry Shmidte4663042016-04-04 10:07:49 -07001934 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1935
Hai Shalomfdcde762020-04-02 11:19:20 -07001936 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
1937 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001938 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1939 "signal level");
1940 return 0;
1941 }
1942
Hai Shalomfdcde762020-04-02 11:19:20 -07001943 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001944 wpa_dbg(wpa_s, MSG_DEBUG,
1945 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001946 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001947 }
1948
Hai Shalomfdcde762020-04-02 11:19:20 -07001949 if (cur_snr > GREAT_SNR) {
1950 wpa_dbg(wpa_s, MSG_DEBUG,
1951 "Skip roam - Current BSS has good SNR (%u > %u)",
1952 cur_snr, GREAT_SNR);
1953 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001954 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001955
Hai Shalomfdcde762020-04-02 11:19:20 -07001956 if (cur_level < -85) /* ..-86 dBm */
1957 min_diff = 1;
1958 else if (cur_level < -80) /* -85..-81 dBm */
1959 min_diff = 2;
1960 else if (cur_level < -75) /* -80..-76 dBm */
1961 min_diff = 3;
1962 else if (cur_level < -70) /* -75..-71 dBm */
1963 min_diff = 4;
1964 else if (cur_level < 0) /* -70..-1 dBm */
1965 min_diff = 5;
1966 else /* unspecified units (not in dBm) */
1967 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001968
Hai Shalomfdcde762020-04-02 11:19:20 -07001969 if (cur_est > sel_est * 1.5)
1970 min_diff += 10;
1971 else if (cur_est > sel_est * 1.2)
1972 min_diff += 5;
1973 else if (cur_est > sel_est * 1.1)
1974 min_diff += 2;
1975 else if (cur_est > sel_est)
1976 min_diff++;
1977 else if (sel_est > cur_est * 1.5)
1978 min_diff -= 10;
1979 else if (sel_est > cur_est * 1.2)
1980 min_diff -= 5;
1981 else if (sel_est > cur_est * 1.1)
1982 min_diff -= 2;
1983 else if (sel_est > cur_est)
1984 min_diff--;
1985
1986 if (to_5ghz)
1987 min_diff -= 2;
1988 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001989 if (diff < min_diff) {
1990 wpa_dbg(wpa_s, MSG_DEBUG,
1991 "Skip roam - too small difference in signal level (%d < %d)",
1992 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07001993 ret = 0;
1994 } else {
1995 wpa_dbg(wpa_s, MSG_DEBUG,
1996 "Allow reassociation due to difference in signal level (%d >= %d)",
1997 diff, min_diff);
1998 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001999 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002000 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2001 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2002 " sel_freq=%d sel_level=%d sel_est=%d",
2003 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2004 MAC2STR(current_bss->bssid),
2005 current_bss->freq, cur_level, cur_est,
2006 MAC2STR(selected->bssid),
2007 selected->freq, selected->level, sel_est);
2008 return ret;
2009}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002010
Hai Shalom899fcc72020-10-19 14:38:18 -07002011#endif /* CONFIG_NO_ROAMING */
2012
2013
2014static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2015 struct wpa_bss *selected,
2016 struct wpa_ssid *ssid)
2017{
2018 struct wpa_bss *current_bss = NULL;
2019
2020 if (wpa_s->reassociate)
2021 return 1; /* explicit request to reassociate */
2022 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2023 return 1; /* we are not associated; continue */
2024 if (wpa_s->current_ssid == NULL)
2025 return 1; /* unknown current SSID */
2026 if (wpa_s->current_ssid != ssid)
2027 return 1; /* different network block */
2028
2029 if (wpas_driver_bss_selection(wpa_s))
2030 return 0; /* Driver-based roaming */
2031
2032 if (wpa_s->current_ssid->ssid)
2033 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2034 wpa_s->current_ssid->ssid,
2035 wpa_s->current_ssid->ssid_len);
2036 if (!current_bss)
2037 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2038
2039 if (!current_bss)
2040 return 1; /* current BSS not seen in scan results */
2041
2042 if (current_bss == selected)
2043 return 0;
2044
2045 if (selected->last_update_idx > current_bss->last_update_idx)
2046 return 1; /* current BSS not seen in the last scan */
2047
2048#ifndef CONFIG_NO_ROAMING
2049 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2050 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002051#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002052 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002053#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002054}
2055
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002056
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002057/*
2058 * Return a negative value if no scan results could be fetched or if scan
2059 * results should not be shared with other virtual interfaces.
2060 * Return 0 if scan results were fetched and may be shared with other
2061 * interfaces.
2062 * Return 1 if scan results may be shared with other virtual interfaces but may
2063 * not trigger any operations.
2064 * Return 2 if the interface was removed and cannot be used.
2065 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002066static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002067 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002068 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002069{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002070 struct wpa_scan_results *scan_res = NULL;
2071 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002072 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002073#ifndef CONFIG_NO_RANDOM_POOL
2074 size_t i, num;
2075#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002076
2077#ifdef CONFIG_AP
2078 if (wpa_s->ap_iface)
2079 ap = 1;
2080#endif /* CONFIG_AP */
2081
2082 wpa_supplicant_notify_scanning(wpa_s, 0);
2083
2084 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2085 data ? &data->scan_info :
2086 NULL, 1);
2087 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002088 if (wpa_s->conf->ap_scan == 2 || ap ||
2089 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002090 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002091 if (!own_request)
2092 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002093 if (data && data->scan_info.external_scan)
2094 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002095 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
2096 "scanning again");
2097 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002098 ret = -1;
2099 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002100 }
2101
2102#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002103 num = scan_res->num;
2104 if (num > 10)
2105 num = 10;
2106 for (i = 0; i < num; i++) {
2107 u8 buf[5];
2108 struct wpa_scan_res *res = scan_res->res[i];
2109 buf[0] = res->bssid[5];
2110 buf[1] = res->qual & 0xff;
2111 buf[2] = res->noise & 0xff;
2112 buf[3] = res->level & 0xff;
2113 buf[4] = res->tsf & 0xff;
2114 random_add_randomness(buf, sizeof(buf));
2115 }
2116#endif /* CONFIG_NO_RANDOM_POOL */
2117
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002118 if (update_only) {
2119 ret = 1;
2120 goto scan_work_done;
2121 }
2122
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002123 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002124 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002125 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2126 struct wpa_scan_results *scan_res);
2127
2128 scan_res_handler = wpa_s->scan_res_handler;
2129 wpa_s->scan_res_handler = NULL;
2130 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002131 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002132 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002133 }
2134
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002135 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002136 wpa_s->own_scan_running,
2137 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002138 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002139 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2140 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002141 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2142 wpa_s->manual_scan_id);
2143 wpa_s->manual_scan_use_id = 0;
2144 } else {
2145 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2146 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002147 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002148
2149 wpas_notify_scan_done(wpa_s, 1);
2150
Hai Shalomfdcde762020-04-02 11:19:20 -07002151 if (ap) {
2152 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2153#ifdef CONFIG_AP
2154 if (wpa_s->ap_iface->scan_cb)
2155 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2156#endif /* CONFIG_AP */
2157 goto scan_work_done;
2158 }
2159
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002160 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002161 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 -07002162 wpa_scan_results_free(scan_res);
2163 return 0;
2164 }
2165
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002166 if (wnm_scan_process(wpa_s, 1) > 0)
2167 goto scan_work_done;
2168
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002169 if (sme_proc_obss_scan(wpa_s, scan_res) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002170 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002171
Hai Shalom021b0b52019-04-10 11:17:58 -07002172 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002173 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2174 goto scan_work_done;
2175
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002176 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2177 goto scan_work_done;
2178
2179 if (autoscan_notify_scan(wpa_s, scan_res))
2180 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002181
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002182 if (wpa_s->disconnected) {
2183 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002184 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002185 }
2186
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002187 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002188 bgscan_notify_scan(wpa_s, scan_res) == 1)
2189 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002190
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002191 wpas_wps_update_ap_info(wpa_s, scan_res);
2192
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002193 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2194 wpa_s->wpa_state < WPA_COMPLETED)
2195 goto scan_work_done;
2196
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002197 wpa_scan_results_free(scan_res);
2198
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002199 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002200 struct wpa_radio_work *work = wpa_s->scan_work;
2201 wpa_s->scan_work = NULL;
2202 radio_work_done(work);
2203 }
2204
Hai Shalomc3565922019-10-28 11:58:20 -07002205 os_free(wpa_s->last_scan_freqs);
2206 wpa_s->last_scan_freqs = NULL;
2207 wpa_s->num_last_scan_freqs = 0;
2208 if (own_request && data &&
2209 data->scan_info.freqs && data->scan_info.num_freqs) {
2210 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2211 data->scan_info.num_freqs);
2212 if (wpa_s->last_scan_freqs) {
2213 os_memcpy(wpa_s->last_scan_freqs,
2214 data->scan_info.freqs,
2215 sizeof(int) * data->scan_info.num_freqs);
2216 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2217 }
2218 }
2219
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002220 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002221
2222scan_work_done:
2223 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002224 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002225 struct wpa_radio_work *work = wpa_s->scan_work;
2226 wpa_s->scan_work = NULL;
2227 radio_work_done(work);
2228 }
2229 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002230}
2231
2232
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002233static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002234 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002235{
2236 struct wpa_bss *selected;
2237 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002238 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2239
2240 if (time_to_reenable > 0) {
2241 wpa_dbg(wpa_s, MSG_DEBUG,
2242 "Postpone network selection by %d seconds since all networks are disabled",
2243 time_to_reenable);
2244 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2245 eloop_register_timeout(time_to_reenable, 0,
2246 wpas_network_reenabled, wpa_s, NULL);
2247 return 0;
2248 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002249
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002250 if (wpa_s->p2p_mgmt)
2251 return 0; /* no normal connection on p2p_mgmt interface */
2252
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002253 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002254 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002255
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002256#ifdef CONFIG_MESH
2257 if (wpa_s->ifmsh) {
2258 wpa_msg(wpa_s, MSG_INFO,
2259 "Avoiding join because we already joined a mesh group");
2260 return 0;
2261 }
2262#endif /* CONFIG_MESH */
2263
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002264 if (selected) {
2265 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002266 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002267 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002268 if (new_scan)
2269 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002270 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002271 }
2272
Hai Shalomc3565922019-10-28 11:58:20 -07002273 wpa_s->suitable_network++;
2274
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002275 if (ssid != wpa_s->current_ssid &&
2276 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2277 wpa_s->own_disconnect_req = 1;
2278 wpa_supplicant_deauthenticate(
2279 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2280 }
2281
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002282 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002284 return -1;
2285 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002286 if (new_scan)
2287 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002288 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002289 * Do not allow other virtual radios to trigger operations based
2290 * on these scan results since we do not want them to start
2291 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002292 */
2293 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002294 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002295 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002296 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2297 ssid = wpa_supplicant_pick_new_network(wpa_s);
2298 if (ssid) {
2299 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2300 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002301 if (new_scan)
2302 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002303 } else if (own_request) {
2304 /*
2305 * No SSID found. If SCAN results are as a result of
2306 * own scan request and not due to a scan request on
2307 * another shared interface, try another scan.
2308 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002309 int timeout_sec = wpa_s->scan_interval;
2310 int timeout_usec = 0;
2311#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002312 int res;
2313
2314 res = wpas_p2p_scan_no_go_seen(wpa_s);
2315 if (res == 2)
2316 return 2;
2317 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002318 return 0;
2319
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002320 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002321 wpa_s->show_group_started ||
2322 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002323 /*
2324 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002325 * state and during P2P join-a-group operation
2326 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002327 */
2328 timeout_sec = 0;
2329 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002330 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2331 timeout_usec);
2332 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002333 }
2334#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002335#ifdef CONFIG_INTERWORKING
2336 if (wpa_s->conf->auto_interworking &&
2337 wpa_s->conf->interworking &&
2338 wpa_s->conf->cred) {
2339 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2340 "start ANQP fetch since no matching "
2341 "networks found");
2342 wpa_s->network_select = 1;
2343 wpa_s->auto_network_select = 1;
2344 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002345 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002346 }
2347#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002348#ifdef CONFIG_WPS
2349 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2350 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2351 timeout_sec = 0;
2352 timeout_usec = 500000;
2353 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2354 timeout_usec);
2355 return 0;
2356 }
2357#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002358#ifdef CONFIG_OWE
2359 if (wpa_s->owe_transition_search) {
2360 wpa_dbg(wpa_s, MSG_DEBUG,
2361 "OWE: Use shorter wait during transition mode search");
2362 timeout_sec = 0;
2363 timeout_usec = 500000;
2364 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2365 timeout_usec);
2366 return 0;
2367 }
2368#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002369 if (wpa_supplicant_req_sched_scan(wpa_s))
2370 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2371 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002372
2373 wpa_msg_ctrl(wpa_s, MSG_INFO,
2374 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002375 }
2376 }
2377 return 0;
2378}
2379
2380
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002381static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2382 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002383{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002385 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002386
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002387 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002388 if (res == 2) {
2389 /*
2390 * Interface may have been removed, so must not dereference
2391 * wpa_s after this.
2392 */
2393 return 1;
2394 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002395
2396 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002397 /*
2398 * If no scan results could be fetched, then no need to
2399 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002400 * this scan. Similarly, if scan results started a new operation on this
2401 * interface, do not notify other interfaces to avoid concurrent
2402 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002403 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002404 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002405 }
2406
2407 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002408 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002409 * so, they get updated with this same scan info.
2410 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002411 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2412 radio_list) {
2413 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002414 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2415 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002416 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2417 res > 0);
2418 if (res < 0)
2419 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002420 }
2421 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002422
2423 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002424}
2425
2426#endif /* CONFIG_NO_SCAN_PROCESSING */
2427
2428
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002429int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2430{
2431#ifdef CONFIG_NO_SCAN_PROCESSING
2432 return -1;
2433#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002434 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002435
Dmitry Shmidt29333592017-01-09 12:27:11 -08002436 wpa_s->ignore_post_flush_scan_res = 0;
2437
Dmitry Shmidt41712582015-06-29 11:02:15 -07002438 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002439 return -1;
2440
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002441 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002442 if (os_reltime_expired(&now, &wpa_s->last_scan,
2443 SCAN_RES_VALID_FOR_CONNECT)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002444 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2445 return -1;
2446 }
2447
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002448 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002449#endif /* CONFIG_NO_SCAN_PROCESSING */
2450}
2451
Dmitry Shmidt04949592012-07-19 12:16:46 -07002452#ifdef CONFIG_WNM
2453
2454static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2455{
2456 struct wpa_supplicant *wpa_s = eloop_ctx;
2457
2458 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2459 return;
2460
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002461 if (!wpa_s->no_keep_alive) {
2462 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2463 MAC2STR(wpa_s->bssid));
2464 /* TODO: could skip this if normal data traffic has been sent */
2465 /* TODO: Consider using some more appropriate data frame for
2466 * this */
2467 if (wpa_s->l2)
2468 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2469 (u8 *) "", 0);
2470 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002471
2472#ifdef CONFIG_SME
2473 if (wpa_s->sme.bss_max_idle_period) {
2474 unsigned int msec;
2475 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2476 if (msec > 100)
2477 msec -= 100;
2478 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2479 wnm_bss_keep_alive, wpa_s, NULL);
2480 }
2481#endif /* CONFIG_SME */
2482}
2483
2484
2485static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2486 const u8 *ies, size_t ies_len)
2487{
2488 struct ieee802_11_elems elems;
2489
2490 if (ies == NULL)
2491 return;
2492
2493 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2494 return;
2495
2496#ifdef CONFIG_SME
2497 if (elems.bss_max_idle_period) {
2498 unsigned int msec;
2499 wpa_s->sme.bss_max_idle_period =
2500 WPA_GET_LE16(elems.bss_max_idle_period);
2501 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2502 "TU)%s", wpa_s->sme.bss_max_idle_period,
2503 (elems.bss_max_idle_period[2] & 0x01) ?
2504 " (protected keep-live required)" : "");
2505 if (wpa_s->sme.bss_max_idle_period == 0)
2506 wpa_s->sme.bss_max_idle_period = 1;
2507 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2508 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2509 /* msec times 1000 */
2510 msec = wpa_s->sme.bss_max_idle_period * 1024;
2511 if (msec > 100)
2512 msec -= 100;
2513 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2514 wnm_bss_keep_alive, wpa_s,
2515 NULL);
2516 }
2517 }
2518#endif /* CONFIG_SME */
2519}
2520
2521#endif /* CONFIG_WNM */
2522
2523
2524void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2525{
2526#ifdef CONFIG_WNM
2527 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2528#endif /* CONFIG_WNM */
2529}
2530
2531
Dmitry Shmidt051af732013-10-22 13:52:46 -07002532#ifdef CONFIG_INTERWORKING
2533
2534static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2535 size_t len)
2536{
2537 int res;
2538
2539 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2540 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2541 if (res) {
2542 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2543 }
2544
2545 return res;
2546}
2547
2548
2549static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2550 const u8 *ies, size_t ies_len)
2551{
2552 struct ieee802_11_elems elems;
2553
2554 if (ies == NULL)
2555 return;
2556
2557 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2558 return;
2559
2560 if (elems.qos_map_set) {
2561 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2562 elems.qos_map_set_len);
2563 }
2564}
2565
2566#endif /* CONFIG_INTERWORKING */
2567
2568
Hai Shalom74f70d42019-02-11 14:42:39 -08002569static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2570 const u8 *ies, size_t ies_len)
2571{
2572 struct ieee802_11_elems elems;
2573 const u8 *map_sub_elem, *pos;
2574 size_t len;
2575
Hai Shalomfdcde762020-04-02 11:19:20 -07002576 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002577
Hai Shalomfdcde762020-04-02 11:19:20 -07002578 if (!ies ||
2579 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2580 !elems.multi_ap || elems.multi_ap_len < 7)
2581 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002582
2583 pos = elems.multi_ap + 4;
2584 len = elems.multi_ap_len - 4;
2585
2586 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002587 if (!map_sub_elem || map_sub_elem[1] < 1)
2588 return;
2589
2590 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2591 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2592 MULTI_AP_FRONTHAUL_BSS);
2593 wpa_s->multi_ap_ie = 1;
2594}
2595
2596
2597static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2598{
2599 if (!wpa_s->current_ssid ||
2600 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2601 return;
2602
2603 if (!wpa_s->multi_ap_ie) {
2604 wpa_printf(MSG_INFO,
2605 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002606 goto fail;
2607 }
2608
Hai Shalomfdcde762020-04-02 11:19:20 -07002609 if (!wpa_s->multi_ap_backhaul) {
2610 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002611 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2612 wpa_printf(MSG_INFO,
2613 "WPS active, accepting fronthaul-only BSS");
2614 /* Don't set 4addr mode in this case, so just return */
2615 return;
2616 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002617 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2618 goto fail;
2619 }
2620
2621 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2622 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2623 goto fail;
2624 }
2625 wpa_s->enabled_4addr_mode = 1;
2626 return;
2627
2628fail:
2629 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2630}
2631
2632
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002633#ifdef CONFIG_FST
2634static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2635 const u8 *ie, size_t ie_len)
2636{
2637 struct mb_ies_info mb_ies;
2638
2639 if (!ie || !ie_len || !wpa_s->fst)
2640 return -ENOENT;
2641
2642 os_memset(&mb_ies, 0, sizeof(mb_ies));
2643
2644 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2645 size_t len;
2646
2647 len = 2 + ie[1];
2648 if (len > ie_len) {
2649 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2650 ie, ie_len);
2651 break;
2652 }
2653
2654 if (ie[0] == WLAN_EID_MULTI_BAND) {
2655 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2656 (unsigned int) len);
2657 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2658 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2659 mb_ies.nof_ies++;
2660 }
2661
2662 ie_len -= len;
2663 ie += len;
2664 }
2665
2666 if (mb_ies.nof_ies > 0) {
2667 wpabuf_free(wpa_s->received_mb_ies);
2668 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2669 return 0;
2670 }
2671
2672 return -ENOENT;
2673}
2674#endif /* CONFIG_FST */
2675
2676
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002677static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2678 union wpa_event_data *data)
2679{
Hai Shalomc3565922019-10-28 11:58:20 -07002680 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002681 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002682 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002683 bool bssid_known;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002684
2685 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07002686 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002687 if (data->assoc_info.req_ies)
2688 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2689 data->assoc_info.req_ies_len);
2690 if (data->assoc_info.resp_ies) {
2691 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2692 data->assoc_info.resp_ies_len);
2693#ifdef CONFIG_TDLS
2694 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2695 data->assoc_info.resp_ies_len);
2696#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002697#ifdef CONFIG_WNM
2698 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2699 data->assoc_info.resp_ies_len);
2700#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002701#ifdef CONFIG_INTERWORKING
2702 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2703 data->assoc_info.resp_ies_len);
2704#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002705 if (wpa_s->hw_capab == CAPAB_VHT &&
2706 get_ie(data->assoc_info.resp_ies,
2707 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2708 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002709
2710 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2711 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002712 }
2713 if (data->assoc_info.beacon_ies)
2714 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2715 data->assoc_info.beacon_ies,
2716 data->assoc_info.beacon_ies_len);
2717 if (data->assoc_info.freq)
2718 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2719 data->assoc_info.freq);
2720
Hai Shalom021b0b52019-04-10 11:17:58 -07002721 wpa_s->connection_set = 0;
2722 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2723 struct ieee802_11_elems req_elems, resp_elems;
2724
2725 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2726 data->assoc_info.req_ies_len,
2727 &req_elems, 0) != ParseFailed &&
2728 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2729 data->assoc_info.resp_ies_len,
2730 &resp_elems, 0) != ParseFailed) {
2731 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07002732 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
2733 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07002734 wpa_s->connection_ht = req_elems.ht_capabilities &&
2735 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07002736 /* Do not include subset of VHT on 2.4 GHz vendor
2737 * extension in consideration for reporting VHT
2738 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07002739 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002740 resp_elems.vht_capabilities &&
2741 (!data->assoc_info.freq ||
2742 wpas_freq_to_band(data->assoc_info.freq) !=
2743 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07002744 wpa_s->connection_he = req_elems.he_capabilities &&
2745 resp_elems.he_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08002746
2747 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
2748 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
2749 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
2750 max_nss_rx_req : max_nss_rx_resp;
2751 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
2752 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
2753 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
2754 max_nss_tx_req : max_nss_tx_resp;
2755
2756 struct supported_chan_width sta_supported_chan_width =
2757 get_supported_channel_width(&req_elems);
2758 enum chan_width ap_operation_chan_width =
2759 get_operation_channel_width(&resp_elems);
2760 if (wpa_s->connection_vht || wpa_s->connection_he) {
2761 wpa_s->connection_channel_bandwidth =
2762 get_sta_operation_chan_width(ap_operation_chan_width,
2763 sta_supported_chan_width);
2764 } else if (wpa_s->connection_ht) {
2765 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
2766 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
2767 } else {
2768 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
2769 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002770 }
2771 }
2772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002773 p = data->assoc_info.req_ies;
2774 l = data->assoc_info.req_ies_len;
2775
2776 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2777 while (p && l >= 2) {
2778 len = p[1] + 2;
2779 if (len > l) {
2780 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2781 p, l);
2782 break;
2783 }
Hai Shalomc3565922019-10-28 11:58:20 -07002784 if (!found &&
2785 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2786 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2787 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2788 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2789 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002790 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2791 break;
2792 found = 1;
2793 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07002794 }
2795 if (!found_x && p[0] == WLAN_EID_RSNX) {
2796 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
2797 break;
2798 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002799 }
2800 l -= len;
2801 p += len;
2802 }
2803 if (!found && data->assoc_info.req_ies)
2804 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002805 if (!found_x && data->assoc_info.req_ies)
2806 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002807
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002808#ifdef CONFIG_FILS
2809#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002810 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2811 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002812 (!data->assoc_info.resp_frame ||
2813 fils_process_assoc_resp(wpa_s->wpa,
2814 data->assoc_info.resp_frame,
2815 data->assoc_info.resp_frame_len) < 0)) {
2816 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2817 return -1;
2818 }
2819#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002820
2821 /* Additional processing for FILS when SME is in driver */
2822 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2823 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2824 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002825#endif /* CONFIG_FILS */
2826
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002827#ifdef CONFIG_OWE
2828 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07002829 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002830 owe_process_assoc_resp(wpa_s->wpa, bssid,
2831 data->assoc_info.resp_ies,
2832 data->assoc_info.resp_ies_len) < 0)) {
2833 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2834 return -1;
2835 }
2836#endif /* CONFIG_OWE */
2837
Hai Shalom021b0b52019-04-10 11:17:58 -07002838#ifdef CONFIG_DPP2
2839 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002840 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
2841 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002842 struct ieee802_11_elems elems;
2843
2844 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2845 data->assoc_info.resp_ies_len,
2846 &elems, 0) == ParseFailed ||
2847 !elems.owe_dh)
2848 goto no_pfs;
2849 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2850 elems.owe_dh_len) < 0) {
2851 wpa_supplicant_deauthenticate(wpa_s,
2852 WLAN_REASON_UNSPECIFIED);
2853 return -1;
2854 }
2855
2856 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2857 }
2858no_pfs:
2859#endif /* CONFIG_DPP2 */
2860
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002861#ifdef CONFIG_IEEE80211R
2862#ifdef CONFIG_SME
2863 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002864 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002865 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2866 data->assoc_info.resp_ies,
2867 data->assoc_info.resp_ies_len,
2868 bssid) < 0) {
2869 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2870 "Reassociation Response failed");
2871 wpa_supplicant_deauthenticate(
2872 wpa_s, WLAN_REASON_INVALID_IE);
2873 return -1;
2874 }
2875 }
2876
2877 p = data->assoc_info.resp_ies;
2878 l = data->assoc_info.resp_ies_len;
2879
2880#ifdef CONFIG_WPS_STRICT
2881 if (p && wpa_s->current_ssid &&
2882 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2883 struct wpabuf *wps;
2884 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2885 if (wps == NULL) {
2886 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2887 "include WPS IE in (Re)Association Response");
2888 return -1;
2889 }
2890
2891 if (wps_validate_assoc_resp(wps) < 0) {
2892 wpabuf_free(wps);
2893 wpa_supplicant_deauthenticate(
2894 wpa_s, WLAN_REASON_INVALID_IE);
2895 return -1;
2896 }
2897 wpabuf_free(wps);
2898 }
2899#endif /* CONFIG_WPS_STRICT */
2900
2901 /* Go through the IEs and make a copy of the MDIE, if present. */
2902 while (p && l >= 2) {
2903 len = p[1] + 2;
2904 if (len > l) {
2905 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2906 p, l);
2907 break;
2908 }
2909 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2910 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2911 wpa_s->sme.ft_used = 1;
2912 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2913 MOBILITY_DOMAIN_ID_LEN);
2914 break;
2915 }
2916 l -= len;
2917 p += len;
2918 }
2919#endif /* CONFIG_SME */
Mir Ali677e7482020-11-12 19:49:02 +05302920#ifdef CONFIG_DRIVER_NL80211_BRCM
2921 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) &&
2922 wpa_ft_is_completed(wpa_s->wpa)) {
2923 return 0;
2924 }
2925#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002926
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002927 /* Process FT when SME is in the driver */
2928 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2929 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002930 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002931 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2932 data->assoc_info.resp_ies,
2933 data->assoc_info.resp_ies_len,
2934 bssid) < 0) {
2935 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2936 "Reassociation Response failed");
2937 wpa_supplicant_deauthenticate(
2938 wpa_s, WLAN_REASON_INVALID_IE);
2939 return -1;
2940 }
2941 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2942 }
2943
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002944 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2945 data->assoc_info.resp_ies_len);
2946#endif /* CONFIG_IEEE80211R */
2947
Hai Shalom899fcc72020-10-19 14:38:18 -07002948 if (bssid_known)
2949 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
2950 data->assoc_info.resp_ies,
2951 data->assoc_info.resp_ies_len);
2952
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002953 /* WPA/RSN IE from Beacon/ProbeResp */
2954 p = data->assoc_info.beacon_ies;
2955 l = data->assoc_info.beacon_ies_len;
2956
2957 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2958 */
2959 wpa_found = rsn_found = 0;
2960 while (p && l >= 2) {
2961 len = p[1] + 2;
2962 if (len > l) {
2963 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2964 p, l);
2965 break;
2966 }
2967 if (!wpa_found &&
2968 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2969 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2970 wpa_found = 1;
2971 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2972 }
2973
2974 if (!rsn_found &&
2975 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2976 rsn_found = 1;
2977 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2978 }
2979
Hai Shalomc3565922019-10-28 11:58:20 -07002980 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
2981 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
2982
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002983 l -= len;
2984 p += len;
2985 }
2986
2987 if (!wpa_found && data->assoc_info.beacon_ies)
2988 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002989 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002990 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002991 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
2992 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002993 if (wpa_found || rsn_found)
2994 wpa_s->ap_ies_from_associnfo = 1;
2995
Jouni Malinen87fd2792011-05-16 18:35:42 +03002996 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2997 wpa_s->assoc_freq != data->assoc_info.freq) {
2998 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2999 "%u to %u MHz",
3000 wpa_s->assoc_freq, data->assoc_info.freq);
3001 wpa_supplicant_update_scan_results(wpa_s);
3002 }
3003
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003004 wpa_s->assoc_freq = data->assoc_info.freq;
3005
3006 return 0;
3007}
3008
3009
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003010static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3011{
Hai Shalomc3565922019-10-28 11:58:20 -07003012 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003013
3014 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3015 return -1;
3016
3017 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3018 return 0;
3019
3020 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3021 WPA_IE_VENDOR_TYPE);
3022 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003023 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003024
3025 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3026 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3027 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003028 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3029 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3030 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003031 return -1;
3032
3033 return 0;
3034}
3035
3036
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003037static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3038 union wpa_event_data *data)
3039{
3040#ifdef CONFIG_FST
3041 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3042 struct wpa_bss *bss = wpa_s->current_bss;
3043 const u8 *ieprb, *iebcn;
3044
3045 wpabuf_free(wpa_s->received_mb_ies);
3046 wpa_s->received_mb_ies = NULL;
3047
3048 if (ai &&
3049 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3050 wpa_printf(MSG_DEBUG,
3051 "FST: MB IEs updated from Association Response frame");
3052 return;
3053 }
3054
3055 if (ai &&
3056 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3057 wpa_printf(MSG_DEBUG,
3058 "FST: MB IEs updated from association event Beacon IEs");
3059 return;
3060 }
3061
3062 if (!bss)
3063 return;
3064
3065 ieprb = (const u8 *) (bss + 1);
3066 iebcn = ieprb + bss->ie_len;
3067
3068 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3069 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3070 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3071 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3072#endif /* CONFIG_FST */
3073}
3074
3075
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003076static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3077 union wpa_event_data *data)
3078{
3079 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003080 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003081 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003082#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3083 struct wpa_bss *bss;
3084#endif /* CONFIG_FILS || CONFIG_MBO */
Mir Ali677e7482020-11-12 19:49:02 +05303085#ifdef CONFIG_DRIVER_NL80211_BRCM
3086 struct wpa_ie_data ie;
3087#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003088
3089#ifdef CONFIG_AP
3090 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003091 if (!data)
3092 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003093 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3094 data->assoc_info.addr,
3095 data->assoc_info.req_ies,
3096 data->assoc_info.req_ies_len,
3097 data->assoc_info.reassoc);
3098 return;
3099 }
3100#endif /* CONFIG_AP */
3101
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003102 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003103 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003104
Mir Ali677e7482020-11-12 19:49:02 +05303105#ifdef CONFIG_DRIVER_NL80211_BRCM
3106 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3107 struct wpa_ft_ies parse;
3108 /* Check for FT reassociation is done by the driver */
3109#ifdef CONFIG_IEEE80211R
3110 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
3111 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) && (wpa_s->key_mgmt == ie.key_mgmt)) {
3112 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3113 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3114 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3115 return;
3116 }
3117 if (parse.rsn_pmkid != NULL) {
3118 wpa_set_ft_completed(wpa_s->wpa);
3119 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3120 }
3121 }
3122#endif /* CONFIG_IEEE80211R */
3123 }
3124#endif /* CONFIG_DRIVER_NL80211_BRCM */
3125
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003126 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
3127 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3128 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003129 /*
3130 * FILS authentication can share the same mechanism to mark the
3131 * connection fully authenticated, so set ft_completed also based on
3132 * FILS result.
3133 */
3134 if (!ft_completed)
3135 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003136
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003137 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3138 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003139 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003140 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3141 return;
3142 }
3143
Mir Ali677e7482020-11-12 19:49:02 +05303144#ifdef CONFIG_DRIVER_NL80211_BRCM
3145 /* For driver based roaming, insert PSK during the initial association */
3146 if (is_zero_ether_addr(wpa_s->bssid) &&
3147 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3148 /* In case the driver wants to handle re-assocs, pass it down the PMK. */
3149 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3150 wpa_sm_install_pmk(wpa_s->wpa);
3151 }
3152#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003153 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003154 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003155 if (os_reltime_initialized(&wpa_s->session_start)) {
3156 os_reltime_age(&wpa_s->session_start,
3157 &wpa_s->session_length);
3158 wpa_s->session_start.sec = 0;
3159 wpa_s->session_start.usec = 0;
3160 wpas_notify_session_length(wpa_s);
3161 } else {
3162 wpas_notify_auth_changed(wpa_s);
3163 os_get_reltime(&wpa_s->session_start);
3164 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003165 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3166 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003167 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003168 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003169 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3170 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003171 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003172
3173 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3174 wpa_clear_keys(wpa_s, bssid);
3175 }
3176 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003177 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003178 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3179 return;
3180 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003181 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003182
Hai Shalomfdcde762020-04-02 11:19:20 -07003183 multi_ap_set_4addr_mode(wpa_s);
3184
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003185 if (wpa_s->conf->ap_scan == 1 &&
3186 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003187 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3188 wpa_msg(wpa_s, MSG_WARNING,
3189 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003190 }
3191
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003192 wpas_fst_update_mb_assoc(wpa_s, data);
3193
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003194#ifdef CONFIG_SME
3195 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3196 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003197 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003198#endif /* CONFIG_SME */
3199
3200 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3201 if (wpa_s->current_ssid) {
3202 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3203 * initialized before association, but for other modes,
3204 * initialize PC/SC here, if the current configuration needs
3205 * smartcard or SIM/USIM. */
3206 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3207 }
3208 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3209 if (wpa_s->l2)
3210 l2_packet_notify_auth_start(wpa_s->l2);
3211
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003212 already_authorized = data && data->assoc_info.authorized;
3213
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003214 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003215 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003216 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3217 * state machine may transit to AUTHENTICATING state based on obsolete
3218 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3219 * AUTHENTICATED without ever giving chance to EAP state machine to
3220 * reset the state.
3221 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003222 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003223 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3224 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003225 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003226 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3227 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3228 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003229 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003230 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003231 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003232 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003233 wpa_s->eapol_received = 0;
3234 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3235 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3236 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003237 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003238 if (wpa_s->current_ssid &&
3239 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003240 (wpa_s->drv_flags &
3241 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3242 /*
3243 * Set the key after having received joined-IBSS event
3244 * from the driver.
3245 */
3246 wpa_supplicant_set_wpa_none_key(wpa_s,
3247 wpa_s->current_ssid);
3248 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003249 wpa_supplicant_cancel_auth_timeout(wpa_s);
3250 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3251 } else if (!ft_completed) {
3252 /* Timeout for receiving the first EAPOL packet */
3253 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3254 }
3255 wpa_supplicant_cancel_scan(wpa_s);
3256
Hai Shalom5f92bc92019-04-18 11:54:11 -07003257 if (ft_completed) {
3258 /*
3259 * FT protocol completed - make sure EAPOL state machine ends
3260 * up in authenticated.
3261 */
3262 wpa_supplicant_cancel_auth_timeout(wpa_s);
3263 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003264 eapol_sm_notify_portValid(wpa_s->eapol, true);
3265 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003266 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3267 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003268 /*
3269 * We are done; the driver will take care of RSN 4-way
3270 * handshake.
3271 */
3272 wpa_supplicant_cancel_auth_timeout(wpa_s);
3273 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003274 eapol_sm_notify_portValid(wpa_s->eapol, true);
3275 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003276 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003277 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3278 /*
3279 * The driver will take care of RSN 4-way handshake, so we need
3280 * to allow EAPOL supplicant to complete its work without
3281 * waiting for WPA supplicant.
3282 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003283 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003284 }
3285
Jouni Malinena05074c2012-12-21 21:35:35 +02003286 wpa_s->last_eapol_matches_bssid = 0;
3287
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003288#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003289 if (wpa_s->rsne_override_eapol) {
3290 wpa_printf(MSG_DEBUG,
3291 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3292 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3293 wpabuf_head(wpa_s->rsne_override_eapol),
3294 wpabuf_len(wpa_s->rsne_override_eapol));
3295 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003296 if (wpa_s->rsnxe_override_eapol) {
3297 wpa_printf(MSG_DEBUG,
3298 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3299 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3300 wpabuf_head(wpa_s->rsnxe_override_eapol),
3301 wpabuf_len(wpa_s->rsnxe_override_eapol));
3302 }
3303#endif /* CONFIG_TESTING_OPTIONS */
3304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003305 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003306 struct os_reltime now, age;
3307 os_get_reltime(&now);
3308 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003309 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003310 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3311 0) {
3312 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3313 "frame that was received just before "
3314 "association notification");
3315 wpa_supplicant_rx_eapol(
3316 wpa_s, wpa_s->pending_eapol_rx_src,
3317 wpabuf_head(wpa_s->pending_eapol_rx),
3318 wpabuf_len(wpa_s->pending_eapol_rx));
3319 }
3320 wpabuf_free(wpa_s->pending_eapol_rx);
3321 wpa_s->pending_eapol_rx = NULL;
3322 }
3323
Hai Shalomfdcde762020-04-02 11:19:20 -07003324#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003325 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3326 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003327 wpa_s->current_ssid &&
3328 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003329 /* Set static WEP keys again */
3330 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3331 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003332#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003333
3334#ifdef CONFIG_IBSS_RSN
3335 if (wpa_s->current_ssid &&
3336 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3337 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3338 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3339 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003340 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003341 if (!wpa_s->ibss_rsn) {
3342 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3343 wpa_supplicant_deauthenticate(
3344 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3345 return;
3346 }
3347
3348 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3349 }
3350#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003351
3352 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003353
3354 if (data) {
3355 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3356 data->assoc_info.resp_ies_len,
3357 &data->assoc_info.wmm_params);
3358
3359 if (wpa_s->reassoc_same_bss)
3360 wmm_ac_restore_tspecs(wpa_s);
3361 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003362
Hai Shalomc3565922019-10-28 11:58:20 -07003363#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3364 bss = wpa_bss_get_bssid(wpa_s, bssid);
3365#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003366#ifdef CONFIG_FILS
3367 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003368 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3369
3370 if (fils_cache_id)
3371 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3372 }
3373#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003374
3375#ifdef CONFIG_MBO
3376 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3377#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003378
3379#ifdef CONFIG_DPP2
3380 wpa_s->dpp_pfs_fallback = 0;
3381#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003382}
3383
3384
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003385static int disconnect_reason_recoverable(u16 reason_code)
3386{
3387 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3388 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3389 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3390}
3391
3392
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003393static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003394 u16 reason_code,
3395 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003396{
3397 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003398
3399 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3400 /*
3401 * At least Host AP driver and a Prism3 card seemed to be
3402 * generating streams of disconnected events when configuring
3403 * IBSS for WPA-None. Ignore them for now.
3404 */
3405 return;
3406 }
3407
3408 bssid = wpa_s->bssid;
3409 if (is_zero_ether_addr(bssid))
3410 bssid = wpa_s->pending_bssid;
3411
3412 if (!is_zero_ether_addr(bssid) ||
3413 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3414 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3415 " reason=%d%s",
3416 MAC2STR(bssid), reason_code,
3417 locally_generated ? " locally_generated=1" : "");
3418 }
3419}
3420
3421
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003422static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3423 int locally_generated)
3424{
3425 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003426 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003427 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3428 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003429 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003430
3431 /*
3432 * It looks like connection was lost while trying to go through PSK
3433 * 4-way handshake. Filter out known disconnection cases that are caused
3434 * by something else than PSK mismatch to avoid confusing reports.
3435 */
3436
3437 if (locally_generated) {
3438 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3439 return 0;
3440 }
3441
3442 return 1;
3443}
3444
3445
Jouni Malinen2b89da82012-08-31 22:04:41 +03003446static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3447 u16 reason_code,
3448 int locally_generated)
3449{
3450 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003451 int authenticating;
3452 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003453 struct wpa_bss *fast_reconnect = NULL;
3454 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003455 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003456 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003457
3458 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3459 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3460
3461 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3462 /*
3463 * At least Host AP driver and a Prism3 card seemed to be
3464 * generating streams of disconnected events when configuring
3465 * IBSS for WPA-None. Ignore them for now.
3466 */
3467 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3468 "IBSS/WPA-None mode");
3469 return;
3470 }
3471
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003472 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3473 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3474 locally_generated)
3475 /*
3476 * Remove the inactive AP (which is probably out of range) from
3477 * the BSS list after marking disassociation. In particular
3478 * mac80211-based drivers use the
3479 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3480 * locally generated disconnection events for cases where the
3481 * AP does not reply anymore.
3482 */
3483 curr = wpa_s->current_bss;
3484
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003485 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003486 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3487 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003488 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3489 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003490 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003491#ifdef CONFIG_DPP2
3492 wpas_dpp_send_conn_status_result(wpa_s,
3493 DPP_STATUS_AUTH_FAILURE);
3494#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003495 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003496 if (!wpa_s->disconnected &&
3497 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003498 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003499 wpas_wps_searching(wpa_s) ||
3500 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003501 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003502 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003503 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003504 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003505 wpa_s->wpa_state);
3506 if (wpa_s->wpa_state == WPA_COMPLETED &&
3507 wpa_s->current_ssid &&
3508 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003509 (wpa_s->own_reconnect_req ||
3510 (!locally_generated &&
3511 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003512 /*
3513 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003514 * us, but could allow us to get back in. This is also
3515 * triggered for cases where local reconnection request
3516 * is used to force reassociation with the same BSS.
3517 * Try to reconnect to the same BSS without a full scan
3518 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003519 */
3520 fast_reconnect = wpa_s->current_bss;
3521 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003522 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003523 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003524 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003525 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3526 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003527 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003528 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003529 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003530 "try to re-connect");
3531 wpa_s->reassociate = 0;
3532 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003533 if (!wpa_s->pno)
3534 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003535 }
3536 bssid = wpa_s->bssid;
3537 if (is_zero_ether_addr(bssid))
3538 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003539 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3540 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003541 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003542 if (locally_generated)
3543 wpa_s->disconnect_reason = -reason_code;
3544 else
3545 wpa_s->disconnect_reason = reason_code;
3546 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003547 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3548 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003549 wpa_clear_keys(wpa_s, wpa_s->bssid);
3550 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003551 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003552 wpa_supplicant_mark_disassoc(wpa_s);
3553
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003554 if (curr)
3555 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3556
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003557 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003558 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003559 wpa_s->current_ssid = last_ssid;
3560 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003561
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003562 if (fast_reconnect &&
3563 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3564 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3565 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3566 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003567 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003568 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003569#ifndef CONFIG_NO_SCAN_PROCESSING
3570 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3571 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3572 fast_reconnect_ssid) < 0) {
3573 /* Recover through full scan */
3574 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3575 }
3576#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003577 } else if (fast_reconnect) {
3578 /*
3579 * Could not reconnect to the same BSS due to network being
3580 * disabled. Use a new scan to match the alternative behavior
3581 * above, i.e., to continue automatic reconnection attempt in a
3582 * way that enforces disabled network rules.
3583 */
3584 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003585 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003586}
3587
3588
3589#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003590void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003591{
3592 struct wpa_supplicant *wpa_s = eloop_ctx;
3593
3594 if (!wpa_s->pending_mic_error_report)
3595 return;
3596
3597 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3598 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3599 wpa_s->pending_mic_error_report = 0;
3600}
3601#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3602
3603
3604static void
3605wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3606 union wpa_event_data *data)
3607{
3608 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003609 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003610
3611 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3612 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003613 os_get_reltime(&t);
3614 if ((wpa_s->last_michael_mic_error.sec &&
3615 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003616 wpa_s->pending_mic_error_report) {
3617 if (wpa_s->pending_mic_error_report) {
3618 /*
3619 * Send the pending MIC error report immediately since
3620 * we are going to start countermeasures and AP better
3621 * do the same.
3622 */
3623 wpa_sm_key_request(wpa_s->wpa, 1,
3624 wpa_s->pending_mic_error_pairwise);
3625 }
3626
3627 /* Send the new MIC error report immediately since we are going
3628 * to start countermeasures and AP better do the same.
3629 */
3630 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3631
3632 /* initialize countermeasures */
3633 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003634
3635 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3636
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003637 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3638
3639 /*
3640 * Need to wait for completion of request frame. We do not get
3641 * any callback for the message completion, so just wait a
3642 * short while and hope for the best. */
3643 os_sleep(0, 10000);
3644
3645 wpa_drv_set_countermeasures(wpa_s, 1);
3646 wpa_supplicant_deauthenticate(wpa_s,
3647 WLAN_REASON_MICHAEL_MIC_FAILURE);
3648 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3649 wpa_s, NULL);
3650 eloop_register_timeout(60, 0,
3651 wpa_supplicant_stop_countermeasures,
3652 wpa_s, NULL);
3653 /* TODO: mark the AP rejected for 60 second. STA is
3654 * allowed to associate with another AP.. */
3655 } else {
3656#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3657 if (wpa_s->mic_errors_seen) {
3658 /*
3659 * Reduce the effectiveness of Michael MIC error
3660 * reports as a means for attacking against TKIP if
3661 * more than one MIC failure is noticed with the same
3662 * PTK. We delay the transmission of the reports by a
3663 * random time between 0 and 60 seconds in order to
3664 * force the attacker wait 60 seconds before getting
3665 * the information on whether a frame resulted in a MIC
3666 * failure.
3667 */
3668 u8 rval[4];
3669 int sec;
3670
3671 if (os_get_random(rval, sizeof(rval)) < 0)
3672 sec = os_random() % 60;
3673 else
3674 sec = WPA_GET_BE32(rval) % 60;
3675 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3676 "report %d seconds", sec);
3677 wpa_s->pending_mic_error_report = 1;
3678 wpa_s->pending_mic_error_pairwise = pairwise;
3679 eloop_cancel_timeout(
3680 wpa_supplicant_delayed_mic_error_report,
3681 wpa_s, NULL);
3682 eloop_register_timeout(
3683 sec, os_random() % 1000000,
3684 wpa_supplicant_delayed_mic_error_report,
3685 wpa_s, NULL);
3686 } else {
3687 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3688 }
3689#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3690 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3691#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3692 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003693 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003694 wpa_s->mic_errors_seen++;
3695}
3696
3697
3698#ifdef CONFIG_TERMINATE_ONLASTIF
3699static int any_interfaces(struct wpa_supplicant *head)
3700{
3701 struct wpa_supplicant *wpa_s;
3702
3703 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3704 if (!wpa_s->interface_removed)
3705 return 1;
3706 return 0;
3707}
3708#endif /* CONFIG_TERMINATE_ONLASTIF */
3709
3710
3711static void
3712wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3713 union wpa_event_data *data)
3714{
3715 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3716 return;
3717
3718 switch (data->interface_status.ievent) {
3719 case EVENT_INTERFACE_ADDED:
3720 if (!wpa_s->interface_removed)
3721 break;
3722 wpa_s->interface_removed = 0;
3723 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3724 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3725 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3726 "driver after interface was added");
3727 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003728
3729#ifdef CONFIG_P2P
3730 if (!wpa_s->global->p2p &&
3731 !wpa_s->global->p2p_disabled &&
3732 !wpa_s->conf->p2p_disabled &&
3733 (wpa_s->drv_flags &
3734 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3735 wpas_p2p_add_p2pdev_interface(
3736 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3737 wpa_printf(MSG_INFO,
3738 "P2P: Failed to enable P2P Device interface");
3739 /* Try to continue without. P2P will be disabled. */
3740 }
3741#endif /* CONFIG_P2P */
3742
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003743 break;
3744 case EVENT_INTERFACE_REMOVED:
3745 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3746 wpa_s->interface_removed = 1;
3747 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003748 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003749 l2_packet_deinit(wpa_s->l2);
3750 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003751
3752#ifdef CONFIG_P2P
3753 if (wpa_s->global->p2p &&
3754 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3755 (wpa_s->drv_flags &
3756 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3757 wpa_dbg(wpa_s, MSG_DEBUG,
3758 "Removing P2P Device interface");
3759 wpa_supplicant_remove_iface(
3760 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3761 0);
3762 wpa_s->global->p2p_init_wpa_s = NULL;
3763 }
3764#endif /* CONFIG_P2P */
3765
Dmitry Shmidte4663042016-04-04 10:07:49 -07003766#ifdef CONFIG_MATCH_IFACE
3767 if (wpa_s->matched) {
3768 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3769 break;
3770 }
3771#endif /* CONFIG_MATCH_IFACE */
3772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003773#ifdef CONFIG_TERMINATE_ONLASTIF
3774 /* check if last interface */
3775 if (!any_interfaces(wpa_s->global->ifaces))
3776 eloop_terminate();
3777#endif /* CONFIG_TERMINATE_ONLASTIF */
3778 break;
3779 }
3780}
3781
3782
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003783#ifdef CONFIG_TDLS
3784static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3785 union wpa_event_data *data)
3786{
3787 if (data == NULL)
3788 return;
3789 switch (data->tdls.oper) {
3790 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003791 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3792 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3793 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3794 else
3795 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003796 break;
3797 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003798 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3799 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3800 data->tdls.reason_code);
3801 else
3802 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3803 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003804 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003805 case TDLS_REQUEST_DISCOVER:
3806 wpa_tdls_send_discovery_request(wpa_s->wpa,
3807 data->tdls.peer);
3808 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003809 }
3810}
3811#endif /* CONFIG_TDLS */
3812
3813
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003814#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003815static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3816 union wpa_event_data *data)
3817{
3818 if (data == NULL)
3819 return;
3820 switch (data->wnm.oper) {
3821 case WNM_OPER_SLEEP:
3822 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3823 "(action=%d, intval=%d)",
3824 data->wnm.sleep_action, data->wnm.sleep_intval);
3825 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003826 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003827 break;
3828 }
3829}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003830#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003831
3832
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003833#ifdef CONFIG_IEEE80211R
3834static void
3835wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3836 union wpa_event_data *data)
3837{
3838 if (data == NULL)
3839 return;
3840
3841 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3842 data->ft_ies.ies_len,
3843 data->ft_ies.ft_action,
3844 data->ft_ies.target_ap,
3845 data->ft_ies.ric_ies,
3846 data->ft_ies.ric_ies_len) < 0) {
3847 /* TODO: prevent MLME/driver from trying to associate? */
3848 }
3849}
3850#endif /* CONFIG_IEEE80211R */
3851
3852
3853#ifdef CONFIG_IBSS_RSN
3854static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3855 union wpa_event_data *data)
3856{
3857 struct wpa_ssid *ssid;
3858 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3859 return;
3860 if (data == NULL)
3861 return;
3862 ssid = wpa_s->current_ssid;
3863 if (ssid == NULL)
3864 return;
3865 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3866 return;
3867
3868 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3869}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003870
3871
3872static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3873 union wpa_event_data *data)
3874{
3875 struct wpa_ssid *ssid = wpa_s->current_ssid;
3876
3877 if (ssid == NULL)
3878 return;
3879
3880 /* check if the ssid is correctly configured as IBSS/RSN */
3881 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3882 return;
3883
3884 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3885 data->rx_mgmt.frame_len);
3886}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003887#endif /* CONFIG_IBSS_RSN */
3888
3889
3890#ifdef CONFIG_IEEE80211R
3891static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3892 size_t len)
3893{
3894 const u8 *sta_addr, *target_ap_addr;
3895 u16 status;
3896
3897 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3898 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3899 return; /* only SME case supported for now */
3900 if (len < 1 + 2 * ETH_ALEN + 2)
3901 return;
3902 if (data[0] != 2)
3903 return; /* Only FT Action Response is supported for now */
3904 sta_addr = data + 1;
3905 target_ap_addr = data + 1 + ETH_ALEN;
3906 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3907 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3908 MACSTR " TargetAP " MACSTR " status %u",
3909 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3910
3911 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3912 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3913 " in FT Action Response", MAC2STR(sta_addr));
3914 return;
3915 }
3916
3917 if (status) {
3918 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3919 "failure (status code %d)", status);
3920 /* TODO: report error to FT code(?) */
3921 return;
3922 }
3923
3924 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3925 len - (1 + 2 * ETH_ALEN + 2), 1,
3926 target_ap_addr, NULL, 0) < 0)
3927 return;
3928
3929#ifdef CONFIG_SME
3930 {
3931 struct wpa_bss *bss;
3932 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3933 if (bss)
3934 wpa_s->sme.freq = bss->freq;
3935 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3936 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3937 WLAN_AUTH_FT);
3938 }
3939#endif /* CONFIG_SME */
3940}
3941#endif /* CONFIG_IEEE80211R */
3942
3943
3944static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3945 struct unprot_deauth *e)
3946{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003947 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3948 "dropped: " MACSTR " -> " MACSTR
3949 " (reason code %u)",
3950 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3951 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003952}
3953
3954
3955static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3956 struct unprot_disassoc *e)
3957{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003958 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3959 "dropped: " MACSTR " -> " MACSTR
3960 " (reason code %u)",
3961 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3962 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003963}
3964
3965
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003966static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3967 u16 reason_code, int locally_generated,
3968 const u8 *ie, size_t ie_len, int deauth)
3969{
3970#ifdef CONFIG_AP
3971 if (wpa_s->ap_iface && addr) {
3972 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3973 return;
3974 }
3975
3976 if (wpa_s->ap_iface) {
3977 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3978 return;
3979 }
3980#endif /* CONFIG_AP */
3981
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003982 if (!locally_generated)
3983 wpa_s->own_disconnect_req = 0;
3984
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003985 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3986
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003987 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3988 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3989 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3990 eapol_sm_failed(wpa_s->eapol))) &&
3991 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003992 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003993
3994#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003995 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003996 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3997 locally_generated) > 0) {
3998 /*
3999 * The interface was removed, so cannot continue
4000 * processing any additional operations after this.
4001 */
4002 return;
4003 }
4004 }
4005#endif /* CONFIG_P2P */
4006
4007 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4008 locally_generated);
4009}
4010
4011
4012static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4013 struct disassoc_info *info)
4014{
4015 u16 reason_code = 0;
4016 int locally_generated = 0;
4017 const u8 *addr = NULL;
4018 const u8 *ie = NULL;
4019 size_t ie_len = 0;
4020
4021 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4022
4023 if (info) {
4024 addr = info->addr;
4025 ie = info->ie;
4026 ie_len = info->ie_len;
4027 reason_code = info->reason_code;
4028 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004029 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4030 reason2str(reason_code),
4031 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004032 if (addr)
4033 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4034 MAC2STR(addr));
4035 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4036 ie, ie_len);
4037 }
4038
4039#ifdef CONFIG_AP
4040 if (wpa_s->ap_iface && info && info->addr) {
4041 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4042 return;
4043 }
4044
4045 if (wpa_s->ap_iface) {
4046 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4047 return;
4048 }
4049#endif /* CONFIG_AP */
4050
4051#ifdef CONFIG_P2P
4052 if (info) {
4053 wpas_p2p_disassoc_notif(
4054 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4055 locally_generated);
4056 }
4057#endif /* CONFIG_P2P */
4058
4059 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4060 sme_event_disassoc(wpa_s, info);
4061
4062 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4063 ie, ie_len, 0);
4064}
4065
4066
4067static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4068 struct deauth_info *info)
4069{
4070 u16 reason_code = 0;
4071 int locally_generated = 0;
4072 const u8 *addr = NULL;
4073 const u8 *ie = NULL;
4074 size_t ie_len = 0;
4075
4076 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4077
4078 if (info) {
4079 addr = info->addr;
4080 ie = info->ie;
4081 ie_len = info->ie_len;
4082 reason_code = info->reason_code;
4083 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004084 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4085 reason_code, reason2str(reason_code),
4086 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004087 if (addr) {
4088 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4089 MAC2STR(addr));
4090 }
4091 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4092 ie, ie_len);
4093 }
4094
4095 wpa_reset_ft_completed(wpa_s->wpa);
4096
4097 wpas_event_disconnect(wpa_s, addr, reason_code,
4098 locally_generated, ie, ie_len, 1);
4099}
4100
4101
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004102static const char * reg_init_str(enum reg_change_initiator init)
4103{
4104 switch (init) {
4105 case REGDOM_SET_BY_CORE:
4106 return "CORE";
4107 case REGDOM_SET_BY_USER:
4108 return "USER";
4109 case REGDOM_SET_BY_DRIVER:
4110 return "DRIVER";
4111 case REGDOM_SET_BY_COUNTRY_IE:
4112 return "COUNTRY_IE";
4113 case REGDOM_BEACON_HINT:
4114 return "BEACON_HINT";
4115 }
4116 return "?";
4117}
4118
4119
4120static const char * reg_type_str(enum reg_type type)
4121{
4122 switch (type) {
4123 case REGDOM_TYPE_UNKNOWN:
4124 return "UNKNOWN";
4125 case REGDOM_TYPE_COUNTRY:
4126 return "COUNTRY";
4127 case REGDOM_TYPE_WORLD:
4128 return "WORLD";
4129 case REGDOM_TYPE_CUSTOM_WORLD:
4130 return "CUSTOM_WORLD";
4131 case REGDOM_TYPE_INTERSECTION:
4132 return "INTERSECTION";
4133 }
4134 return "?";
4135}
4136
4137
Hai Shalom74f70d42019-02-11 14:42:39 -08004138void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4139 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004140{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004141 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004142 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004143
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004144 /*
4145 * To allow backwards compatibility with higher level layers that
4146 * assumed the REGDOM_CHANGE event is sent over the initially added
4147 * interface. Find the highest parent of this interface and use it to
4148 * send the event.
4149 */
4150 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4151 ;
4152
Hai Shalom74f70d42019-02-11 14:42:39 -08004153 if (info) {
4154 wpa_msg(ifs, MSG_INFO,
4155 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4156 reg_init_str(info->initiator), reg_type_str(info->type),
4157 info->alpha2[0] ? " alpha2=" : "",
4158 info->alpha2[0] ? info->alpha2 : "");
4159 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004160
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004161 if (wpa_s->drv_priv == NULL)
4162 return; /* Ignore event during drv initialization */
4163
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004164 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4165 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004166 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4167 ifs->ifname);
4168 free_hw_features(ifs);
4169 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004170 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004171
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004172 /* Restart PNO/sched_scan with updated channel list */
4173 if (ifs->pno) {
4174 wpas_stop_pno(ifs);
4175 wpas_start_pno(ifs);
4176 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4177 wpa_dbg(ifs, MSG_DEBUG,
4178 "Channel list changed - restart sched_scan");
4179 wpas_scan_restart_sched_scan(ifs);
4180 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004181 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004182
4183 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004184}
4185
4186
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004187static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004188 const u8 *frame, size_t len, int freq,
4189 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004190{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004191 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004192 const u8 *payload;
4193 size_t plen;
4194 u8 category;
4195
4196 if (len < IEEE80211_HDRLEN + 2)
4197 return;
4198
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004199 mgmt = (const struct ieee80211_mgmt *) frame;
4200 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004201 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004202 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004203
4204 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4205 " Category=%u DataLen=%d freq=%d MHz",
4206 MAC2STR(mgmt->sa), category, (int) plen, freq);
4207
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004208 if (category == WLAN_ACTION_WMM) {
4209 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4210 return;
4211 }
4212
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004213#ifdef CONFIG_IEEE80211R
4214 if (category == WLAN_ACTION_FT) {
4215 ft_rx_action(wpa_s, payload, plen);
4216 return;
4217 }
4218#endif /* CONFIG_IEEE80211R */
4219
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004220#ifdef CONFIG_SME
4221 if (category == WLAN_ACTION_SA_QUERY) {
4222 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
4223 return;
4224 }
4225#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004226
4227#ifdef CONFIG_WNM
4228 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4229 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4230 return;
4231 }
4232#endif /* CONFIG_WNM */
4233
4234#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004235 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4236 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004237 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004238 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004239 payload, plen, freq) == 0)
4240 return;
4241#endif /* CONFIG_GAS */
4242
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004243#ifdef CONFIG_GAS_SERVER
4244 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4245 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4246 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4247 mgmt->u.action.category,
4248 payload, plen, freq) == 0)
4249 return;
4250#endif /* CONFIG_GAS_SERVER */
4251
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004252#ifdef CONFIG_TDLS
4253 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4254 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4255 wpa_dbg(wpa_s, MSG_DEBUG,
4256 "TDLS: Received Discovery Response from " MACSTR,
4257 MAC2STR(mgmt->sa));
4258 return;
4259 }
4260#endif /* CONFIG_TDLS */
4261
4262#ifdef CONFIG_INTERWORKING
4263 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4264 payload[0] == QOS_QOS_MAP_CONFIG) {
4265 const u8 *pos = payload + 1;
4266 size_t qlen = plen - 1;
4267 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4268 MACSTR, MAC2STR(mgmt->sa));
4269 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4270 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4271 pos[1] <= qlen - 2 && pos[1] >= 16)
4272 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4273 return;
4274 }
4275#endif /* CONFIG_INTERWORKING */
4276
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004277 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004278 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4279 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004280 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004281 payload + 1,
4282 plen - 1);
4283 return;
4284 }
4285
4286 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004287 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4288 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4289 return;
4290 }
4291
4292 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4293 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4294 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4295 payload + 1, plen - 1,
4296 rssi);
4297 return;
4298 }
4299
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004300#ifdef CONFIG_FST
4301 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4302 fst_rx_action(wpa_s->fst, mgmt, len);
4303 return;
4304 }
4305#endif /* CONFIG_FST */
4306
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004307#ifdef CONFIG_DPP
4308 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4309 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4310 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4311 payload[4] == DPP_OUI_TYPE) {
4312 payload++;
4313 plen--;
4314 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4315 return;
4316 }
4317#endif /* CONFIG_DPP */
4318
Hai Shalom899fcc72020-10-19 14:38:18 -07004319 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
4320 payload[0] == ROBUST_AV_MSCS_RESP) {
4321 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4322 payload + 1, plen - 1);
4323 return;
4324 }
4325
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004326 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4327 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004328 if (wpa_s->ifmsh)
4329 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004330}
4331
4332
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004333static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4334 union wpa_event_data *event)
4335{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004336 struct wpa_freq_range_list *list;
4337 char *str = NULL;
4338
4339 list = &event->freq_range;
4340
4341 if (list->num)
4342 str = freq_range_list_str(list);
4343 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4344 str ? str : "");
4345
4346#ifdef CONFIG_P2P
4347 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4348 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4349 __func__);
4350 } else {
4351 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004352
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004353 /*
4354 * The update channel flow will also take care of moving a GO
4355 * from the unsafe frequency if needed.
4356 */
4357 wpas_p2p_update_channel_list(wpa_s,
4358 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004359 }
4360#endif /* CONFIG_P2P */
4361
4362 os_free(str);
4363}
4364
4365
Roshan Pius3a1667e2018-07-03 15:17:14 -07004366static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004367{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004368 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4369 wpa_supplicant_cancel_auth_timeout(wpa_s);
4370 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004371 eapol_sm_notify_portValid(wpa_s->eapol, true);
4372 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004373 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004374 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004375}
4376
4377
4378static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4379 int freq)
4380{
4381 size_t i;
4382 int j;
4383
4384 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4385 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4386
4387 for (j = 0; j < mode->num_channels; j++) {
4388 const struct hostapd_channel_data *chan;
4389
4390 chan = &mode->channels[j];
4391 if (chan->freq == freq)
4392 return chan->dfs_cac_ms;
4393 }
4394 }
4395
4396 return 0;
4397}
4398
4399
4400static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4401 struct dfs_event *radar)
4402{
4403#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004404 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004405 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4406 } else
4407#endif /* NEED_AP_MLME && CONFIG_AP */
4408 {
4409 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4410
4411 cac_time /= 1000; /* convert from ms to sec */
4412 if (!cac_time)
4413 cac_time = 10 * 60; /* max timeout: 10 minutes */
4414
4415 /* Restart auth timeout: CAC time added to initial timeout */
4416 wpas_auth_timeout_restart(wpa_s, cac_time);
4417 }
4418}
4419
4420
4421static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4422 struct dfs_event *radar)
4423{
4424#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004425 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004426 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4427 } else
4428#endif /* NEED_AP_MLME && CONFIG_AP */
4429 {
4430 /* Restart auth timeout with original value after CAC is
4431 * finished */
4432 wpas_auth_timeout_restart(wpa_s, 0);
4433 }
4434}
4435
4436
4437static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4438 struct dfs_event *radar)
4439{
4440#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004441 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004442 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4443 } else
4444#endif /* NEED_AP_MLME && CONFIG_AP */
4445 {
4446 /* Restart auth timeout with original value after CAC is
4447 * aborted */
4448 wpas_auth_timeout_restart(wpa_s, 0);
4449 }
4450}
4451
4452
4453static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4454 union wpa_event_data *data)
4455{
4456 wpa_dbg(wpa_s, MSG_DEBUG,
4457 "Connection authorized by device, previous state %d",
4458 wpa_s->wpa_state);
4459
4460 wpa_supplicant_event_port_authorized(wpa_s);
4461
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004462 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4463 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004464 data->assoc_info.ptk_kck_len,
4465 data->assoc_info.ptk_kek,
4466 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004467#ifdef CONFIG_FILS
4468 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4469 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4470 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4471
4472 /* Update ERP next sequence number */
4473 eapol_sm_update_erp_next_seq_num(
4474 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4475
4476 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4477 /* Add the new PMK and PMKID to the PMKSA cache */
4478 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4479 data->assoc_info.fils_pmk,
4480 data->assoc_info.fils_pmk_len,
4481 data->assoc_info.fils_pmkid,
4482 wpa_s->bssid, fils_cache_id);
4483 } else if (data->assoc_info.fils_pmkid) {
4484 /* Update the current PMKSA used for this connection */
4485 pmksa_cache_set_current(wpa_s->wpa,
4486 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004487 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004488 }
4489 }
4490#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004491}
4492
4493
Roshan Pius3a1667e2018-07-03 15:17:14 -07004494static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4495 union wpa_event_data *data)
4496{
4497 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004498#ifdef CONFIG_MBO
4499 struct wpa_bss *reject_bss;
4500#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004501
4502 if (!bssid || is_zero_ether_addr(bssid))
4503 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004504#ifdef CONFIG_MBO
4505 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4506 reject_bss = wpa_s->current_bss;
4507 else
4508 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4509#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004510
4511 if (data->assoc_reject.bssid)
4512 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4513 "bssid=" MACSTR " status_code=%u%s%s%s",
4514 MAC2STR(data->assoc_reject.bssid),
4515 data->assoc_reject.status_code,
4516 data->assoc_reject.timed_out ? " timeout" : "",
4517 data->assoc_reject.timeout_reason ? "=" : "",
4518 data->assoc_reject.timeout_reason ?
4519 data->assoc_reject.timeout_reason : "");
4520 else
4521 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4522 "status_code=%u%s%s%s",
4523 data->assoc_reject.status_code,
4524 data->assoc_reject.timed_out ? " timeout" : "",
4525 data->assoc_reject.timeout_reason ? "=" : "",
4526 data->assoc_reject.timeout_reason ?
4527 data->assoc_reject.timeout_reason : "");
4528 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravi972b2042020-08-14 10:50:48 -07004529 wpas_notify_assoc_status_code(wpa_s,
4530 bssid, data->assoc_reject.timed_out);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004531
4532#ifdef CONFIG_OWE
4533 if (data->assoc_reject.status_code ==
4534 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4535 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4536 wpa_s->current_ssid &&
4537 wpa_s->current_ssid->owe_group == 0 &&
4538 wpa_s->last_owe_group != 21) {
4539 struct wpa_ssid *ssid = wpa_s->current_ssid;
4540 struct wpa_bss *bss = wpa_s->current_bss;
4541
4542 if (!bss) {
4543 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4544 if (!bss) {
4545 wpas_connection_failed(wpa_s, bssid);
4546 wpa_supplicant_mark_disassoc(wpa_s);
4547 return;
4548 }
4549 }
4550 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4551 wpas_connect_work_done(wpa_s);
4552 wpa_supplicant_mark_disassoc(wpa_s);
4553 wpa_supplicant_connect(wpa_s, bss, ssid);
4554 return;
4555 }
4556#endif /* CONFIG_OWE */
4557
Hai Shalomfdcde762020-04-02 11:19:20 -07004558#ifdef CONFIG_DPP2
4559 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4560 * the status code defined in the DPP R2 tech spec.
4561 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4562 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004563 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004564 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4565 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4566 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004567 wpa_s->current_ssid->dpp_pfs == 0 &&
4568 (data->assoc_reject.status_code ==
4569 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4570 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4571 struct wpa_ssid *ssid = wpa_s->current_ssid;
4572 struct wpa_bss *bss = wpa_s->current_bss;
4573
4574 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4575 if (!bss)
4576 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4577 if (!bss || wpa_s->dpp_pfs_fallback) {
4578 wpa_printf(MSG_DEBUG,
4579 "DPP: Updated PFS policy for next try");
4580 wpas_connection_failed(wpa_s, bssid);
4581 wpa_supplicant_mark_disassoc(wpa_s);
4582 return;
4583 }
4584 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4585 wpa_s->dpp_pfs_fallback = 1;
4586 wpas_connect_work_done(wpa_s);
4587 wpa_supplicant_mark_disassoc(wpa_s);
4588 wpa_supplicant_connect(wpa_s, bss, ssid);
4589 return;
4590 }
4591#endif /* CONFIG_DPP2 */
4592
Hai Shalom74f70d42019-02-11 14:42:39 -08004593#ifdef CONFIG_MBO
4594 if (data->assoc_reject.status_code ==
4595 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004596 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004597 const u8 *rssi_rej;
4598
4599 rssi_rej = mbo_get_attr_from_ies(
4600 data->assoc_reject.resp_ies,
4601 data->assoc_reject.resp_ies_len,
4602 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4603 if (rssi_rej && rssi_rej[1] == 2) {
4604 wpa_printf(MSG_DEBUG,
4605 "OCE: RSSI-based association rejection from "
4606 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004607 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004608 rssi_rej[2], rssi_rej[3]);
4609 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004610 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004611 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004612 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004613 }
4614 }
4615#endif /* CONFIG_MBO */
4616
Roshan Pius3a1667e2018-07-03 15:17:14 -07004617 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4618 sme_event_assoc_reject(wpa_s, data);
4619 return;
4620 }
4621
4622 /* Driver-based SME cases */
4623
4624#ifdef CONFIG_SAE
4625 if (wpa_s->current_ssid &&
4626 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4627 !data->assoc_reject.timed_out) {
4628 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4629 wpa_sm_aborted_cached(wpa_s->wpa);
4630 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4631 }
4632#endif /* CONFIG_SAE */
4633
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004634#ifdef CONFIG_DPP
4635 if (wpa_s->current_ssid &&
4636 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4637 !data->assoc_reject.timed_out) {
4638 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4639 wpa_sm_aborted_cached(wpa_s->wpa);
4640 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4641 }
4642#endif /* CONFIG_DPP */
4643
Roshan Pius3a1667e2018-07-03 15:17:14 -07004644#ifdef CONFIG_FILS
4645 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004646 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004647 eapol_sm_update_erp_next_seq_num(
4648 wpa_s->eapol,
4649 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004650 fils_connection_failure(wpa_s);
4651 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004652#endif /* CONFIG_FILS */
4653
4654 wpas_connection_failed(wpa_s, bssid);
4655 wpa_supplicant_mark_disassoc(wpa_s);
4656}
4657
4658
Hai Shalomfdcde762020-04-02 11:19:20 -07004659static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
4660 struct unprot_beacon *data)
4661{
4662 struct wpabuf *buf;
4663 int res;
4664
4665 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
4666 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
4667 return;
4668 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
4669 MAC2STR(data->sa));
4670
4671 buf = wpabuf_alloc(4);
4672 if (!buf)
4673 return;
4674
4675 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
4676 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
4677 wpabuf_put_u8(buf, 1); /* Dialog Token */
4678 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
4679
4680 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
4681 wpa_s->own_addr, wpa_s->bssid,
4682 wpabuf_head(buf), wpabuf_len(buf), 0);
4683 if (res < 0)
4684 wpa_printf(MSG_DEBUG,
4685 "Failed to send WNM-Notification Request frame");
4686
4687 wpabuf_free(buf);
4688}
4689
4690
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004691void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4692 union wpa_event_data *data)
4693{
4694 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004695 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07004696 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08004697#ifndef CONFIG_NO_STDOUT_DEBUG
4698 int level = MSG_DEBUG;
4699#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004700
4701 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4702 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004703 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004704 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004705 event != EVENT_SCHED_SCAN_STOPPED) {
4706 wpa_dbg(wpa_s, MSG_DEBUG,
4707 "Ignore event %s (%d) while interface is disabled",
4708 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004709 return;
4710 }
4711
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004712#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07004713 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004714 const struct ieee80211_hdr *hdr;
4715 u16 fc;
4716 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4717 fc = le_to_host16(hdr->frame_control);
4718 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4719 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4720 level = MSG_EXCESSIVE;
4721 }
4722
4723 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4724 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004725#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004726
4727 switch (event) {
4728 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004729#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004730 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4731 data->auth.ies_len))
4732 wpa_printf(MSG_DEBUG,
4733 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004734#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004735 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004736 wpa_s->auth_status_code = data->auth.status_code;
4737 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004738 break;
4739 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004740#ifdef CONFIG_TESTING_OPTIONS
4741 if (wpa_s->ignore_auth_resp) {
4742 wpa_printf(MSG_INFO,
4743 "EVENT_ASSOC - ignore_auth_resp active!");
4744 break;
4745 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004746 if (wpa_s->testing_resend_assoc) {
4747 wpa_printf(MSG_INFO,
4748 "EVENT_DEAUTH - testing_resend_assoc");
4749 break;
4750 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004751#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004752 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004753 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004754 if (data &&
4755 (data->assoc_info.authorized ||
4756 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4757 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004758 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004759 if (data) {
4760 wpa_msg(wpa_s, MSG_INFO,
4761 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4762 data->assoc_info.subnet_status);
4763 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004764 break;
4765 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004766 wpas_event_disassoc(wpa_s,
4767 data ? &data->disassoc_info : NULL);
4768 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004769 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004770#ifdef CONFIG_TESTING_OPTIONS
4771 if (wpa_s->ignore_auth_resp) {
4772 wpa_printf(MSG_INFO,
4773 "EVENT_DEAUTH - ignore_auth_resp active!");
4774 break;
4775 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004776 if (wpa_s->testing_resend_assoc) {
4777 wpa_printf(MSG_INFO,
4778 "EVENT_DEAUTH - testing_resend_assoc");
4779 break;
4780 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004781#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004782 wpas_event_deauth(wpa_s,
4783 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004784 break;
4785 case EVENT_MICHAEL_MIC_FAILURE:
4786 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4787 break;
4788#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004789 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004790 if (wpa_s->own_scan_requested ||
4791 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004792 struct os_reltime diff;
4793
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004794 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004795 os_reltime_sub(&wpa_s->scan_start_time,
4796 &wpa_s->scan_trigger_time, &diff);
4797 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4798 diff.sec, diff.usec);
4799 wpa_s->own_scan_requested = 0;
4800 wpa_s->own_scan_running = 1;
4801 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4802 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004803 wpa_msg_ctrl(wpa_s, MSG_INFO,
4804 WPA_EVENT_SCAN_STARTED "id=%u",
4805 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004806 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004807 wpa_msg_ctrl(wpa_s, MSG_INFO,
4808 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004809 }
4810 } else {
4811 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004812 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004813 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004814 }
4815 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004816 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004817 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4818 wpa_s->scan_res_handler = NULL;
4819 wpa_s->own_scan_running = 0;
4820 wpa_s->radio->external_scan_running = 0;
4821 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4822 break;
4823 }
4824
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004825 if (!(data && data->scan_info.external_scan) &&
4826 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004827 struct os_reltime now, diff;
4828 os_get_reltime(&now);
4829 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4830 wpa_s->scan_start_time.sec = 0;
4831 wpa_s->scan_start_time.usec = 0;
4832 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4833 diff.sec, diff.usec);
4834 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004835 if (wpa_supplicant_event_scan_results(wpa_s, data))
4836 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004837 if (!(data && data->scan_info.external_scan))
4838 wpa_s->own_scan_running = 0;
4839 if (data && data->scan_info.nl_scan_event)
4840 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004841 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004842 break;
4843#endif /* CONFIG_NO_SCAN_PROCESSING */
4844 case EVENT_ASSOCINFO:
4845 wpa_supplicant_event_associnfo(wpa_s, data);
4846 break;
4847 case EVENT_INTERFACE_STATUS:
4848 wpa_supplicant_event_interface_status(wpa_s, data);
4849 break;
4850 case EVENT_PMKID_CANDIDATE:
4851 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4852 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004853#ifdef CONFIG_TDLS
4854 case EVENT_TDLS:
4855 wpa_supplicant_event_tdls(wpa_s, data);
4856 break;
4857#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004858#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004859 case EVENT_WNM:
4860 wpa_supplicant_event_wnm(wpa_s, data);
4861 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004862#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004863#ifdef CONFIG_IEEE80211R
4864 case EVENT_FT_RESPONSE:
4865 wpa_supplicant_event_ft_response(wpa_s, data);
4866 break;
4867#endif /* CONFIG_IEEE80211R */
4868#ifdef CONFIG_IBSS_RSN
4869 case EVENT_IBSS_RSN_START:
4870 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4871 break;
4872#endif /* CONFIG_IBSS_RSN */
4873 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004874 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004875 break;
4876 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004877 /* It is possible to get this event from earlier connection */
4878 if (wpa_s->current_ssid &&
4879 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4880 wpa_dbg(wpa_s, MSG_DEBUG,
4881 "Ignore AUTH_TIMED_OUT in mesh configuration");
4882 break;
4883 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004884 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4885 sme_event_auth_timed_out(wpa_s, data);
4886 break;
4887 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004888 /* It is possible to get this event from earlier connection */
4889 if (wpa_s->current_ssid &&
4890 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4891 wpa_dbg(wpa_s, MSG_DEBUG,
4892 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4893 break;
4894 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004895 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4896 sme_event_assoc_timed_out(wpa_s, data);
4897 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004898 case EVENT_TX_STATUS:
4899 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4900 " type=%d stype=%d",
4901 MAC2STR(data->tx_status.dst),
4902 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004903#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004904 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004905#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004906 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4907 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004908 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004909 wpa_s, data->tx_status.dst,
4910 data->tx_status.data,
4911 data->tx_status.data_len,
4912 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004913 OFFCHANNEL_SEND_ACTION_SUCCESS :
4914 OFFCHANNEL_SEND_ACTION_NO_ACK);
4915#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004916 break;
4917 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004918#endif /* CONFIG_AP */
4919#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004920 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004921 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004922 /*
4923 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004924 * interface in GO mode, or via standalone AP interface.
4925 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4926 * except when the primary interface is used as a GO interface
4927 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004928 */
4929 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4930 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004931 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004932 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004933 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004934 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004935 data->tx_status.data,
4936 data->tx_status.data_len,
4937 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004938 OFFCHANNEL_SEND_ACTION_SUCCESS :
4939 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004940 break;
4941 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004942#endif /* CONFIG_OFFCHANNEL */
4943#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004944 switch (data->tx_status.type) {
4945 case WLAN_FC_TYPE_MGMT:
4946 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4947 data->tx_status.data_len,
4948 data->tx_status.stype,
4949 data->tx_status.ack);
4950 break;
4951 case WLAN_FC_TYPE_DATA:
4952 ap_tx_status(wpa_s, data->tx_status.dst,
4953 data->tx_status.data,
4954 data->tx_status.data_len,
4955 data->tx_status.ack);
4956 break;
4957 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004958#endif /* CONFIG_AP */
4959 break;
4960#ifdef CONFIG_AP
4961 case EVENT_EAPOL_TX_STATUS:
4962 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4963 data->eapol_tx_status.data,
4964 data->eapol_tx_status.data_len,
4965 data->eapol_tx_status.ack);
4966 break;
4967 case EVENT_DRIVER_CLIENT_POLL_OK:
4968 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004969 break;
4970 case EVENT_RX_FROM_UNKNOWN:
4971 if (wpa_s->ap_iface == NULL)
4972 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004973 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4974 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004975 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004976#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07004977
4978 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07004979 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004980 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004981 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004982
Hai Shalom81f62d82019-07-22 12:10:00 -07004983 wpa_msg(wpa_s, MSG_INFO,
4984 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4985 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
4986 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004987 data->ch_switch.freq,
4988 data->ch_switch.ht_enabled,
4989 data->ch_switch.ch_offset,
4990 channel_width_to_string(data->ch_switch.ch_width),
4991 data->ch_switch.cf1,
4992 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07004993 if (event == EVENT_CH_SWITCH_STARTED)
4994 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004995
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004996 wpa_s->assoc_freq = data->ch_switch.freq;
4997 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4998
Hai Shalomfdcde762020-04-02 11:19:20 -07004999#ifdef CONFIG_SME
5000 switch (data->ch_switch.ch_offset) {
5001 case 1:
5002 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5003 break;
5004 case -1:
5005 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5006 break;
5007 default:
5008 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5009 break;
5010 }
5011#endif /* CONFIG_SME */
5012
Roshan Pius3a1667e2018-07-03 15:17:14 -07005013#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005014 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5015 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005016 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005017 wpa_s->current_ssid->mode ==
5018 WPAS_MODE_P2P_GROUP_FORMATION) {
5019 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5020 data->ch_switch.ht_enabled,
5021 data->ch_switch.ch_offset,
5022 data->ch_switch.ch_width,
5023 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005024 data->ch_switch.cf2,
5025 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005026 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005027#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005028
Hai Shalom899fcc72020-10-19 14:38:18 -07005029 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5030 sme_event_ch_switch(wpa_s);
5031
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005032 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005033 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005034 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005035#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005036#ifdef NEED_AP_MLME
5037 case EVENT_DFS_RADAR_DETECTED:
5038 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005039 wpas_ap_event_dfs_radar_detected(wpa_s,
5040 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005041 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005042 case EVENT_DFS_NOP_FINISHED:
5043 if (data)
5044 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5045 &data->dfs_event);
5046 break;
5047#endif /* NEED_AP_MLME */
5048#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005049 case EVENT_DFS_CAC_STARTED:
5050 if (data)
5051 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5052 break;
5053 case EVENT_DFS_CAC_FINISHED:
5054 if (data)
5055 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5056 break;
5057 case EVENT_DFS_CAC_ABORTED:
5058 if (data)
5059 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5060 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005061 case EVENT_RX_MGMT: {
5062 u16 fc, stype;
5063 const struct ieee80211_mgmt *mgmt;
5064
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005065#ifdef CONFIG_TESTING_OPTIONS
5066 if (wpa_s->ext_mgmt_frame_handling) {
5067 struct rx_mgmt *rx = &data->rx_mgmt;
5068 size_t hex_len = 2 * rx->frame_len + 1;
5069 char *hex = os_malloc(hex_len);
5070 if (hex) {
5071 wpa_snprintf_hex(hex, hex_len,
5072 rx->frame, rx->frame_len);
5073 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5074 rx->freq, rx->datarate, rx->ssi_signal,
5075 hex);
5076 os_free(hex);
5077 }
5078 break;
5079 }
5080#endif /* CONFIG_TESTING_OPTIONS */
5081
Dmitry Shmidt04949592012-07-19 12:16:46 -07005082 mgmt = (const struct ieee80211_mgmt *)
5083 data->rx_mgmt.frame;
5084 fc = le_to_host16(mgmt->frame_control);
5085 stype = WLAN_FC_GET_STYPE(fc);
5086
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005087#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005088 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005089#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005090#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005091 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005092 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005093 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005094 const u8 *ie;
5095 size_t ie_len;
5096
5097 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5098 ie_len = data->rx_mgmt.frame_len -
5099 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005100 wpas_p2p_probe_req_rx(
5101 wpa_s, src, mgmt->da,
5102 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005103 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005104 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005105 break;
5106 }
5107#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005108#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005109 if (wpa_s->current_ssid &&
5110 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5111 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005112 data->rx_mgmt.frame_len >= 30) {
5113 wpa_supplicant_event_ibss_auth(wpa_s, data);
5114 break;
5115 }
5116#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005117
5118 if (stype == WLAN_FC_STYPE_ACTION) {
5119 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005120 wpa_s, data->rx_mgmt.frame,
5121 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005122 data->rx_mgmt.freq,
5123 data->rx_mgmt.ssi_signal);
5124 break;
5125 }
5126
5127 if (wpa_s->ifmsh) {
5128 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005129 break;
5130 }
5131
Roshan Pius3a1667e2018-07-03 15:17:14 -07005132#ifdef CONFIG_SAE
5133 if (stype == WLAN_FC_STYPE_AUTH &&
5134 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5135 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5136 sme_external_auth_mgmt_rx(
5137 wpa_s, data->rx_mgmt.frame,
5138 data->rx_mgmt.frame_len);
5139 break;
5140 }
5141#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005142 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5143 "management frame in non-AP mode");
5144 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005145#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005146 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005147
5148 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005149 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5150 const u8 *ie;
5151 size_t ie_len;
5152
5153 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5154 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005155
5156 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5157 mgmt->bssid, ie, ie_len,
5158 data->rx_mgmt.ssi_signal);
5159 }
5160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005161 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005162#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005163 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005164 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005165 case EVENT_RX_PROBE_REQ:
5166 if (data->rx_probe_req.sa == NULL ||
5167 data->rx_probe_req.ie == NULL)
5168 break;
5169#ifdef CONFIG_AP
5170 if (wpa_s->ap_iface) {
5171 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5172 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005173 data->rx_probe_req.da,
5174 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005175 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005176 data->rx_probe_req.ie_len,
5177 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005178 break;
5179 }
5180#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005181 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005182 data->rx_probe_req.da,
5183 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005184 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005185 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005186 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005187 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005188 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005189 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005190#ifdef CONFIG_OFFCHANNEL
5191 offchannel_remain_on_channel_cb(
5192 wpa_s, data->remain_on_channel.freq,
5193 data->remain_on_channel.duration);
5194#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005195 wpas_p2p_remain_on_channel_cb(
5196 wpa_s, data->remain_on_channel.freq,
5197 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005198#ifdef CONFIG_DPP
5199 wpas_dpp_remain_on_channel_cb(
5200 wpa_s, data->remain_on_channel.freq,
5201 data->remain_on_channel.duration);
5202#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005203 break;
5204 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005205#ifdef CONFIG_OFFCHANNEL
5206 offchannel_cancel_remain_on_channel_cb(
5207 wpa_s, data->remain_on_channel.freq);
5208#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005209 wpas_p2p_cancel_remain_on_channel_cb(
5210 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005211#ifdef CONFIG_DPP
5212 wpas_dpp_cancel_remain_on_channel_cb(
5213 wpa_s, data->remain_on_channel.freq);
5214#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005215 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005216 case EVENT_EAPOL_RX:
5217 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5218 data->eapol_rx.data,
5219 data->eapol_rx.data_len);
5220 break;
5221 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005222 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5223 "above=%d signal=%d noise=%d txrate=%d",
5224 data->signal_change.above_threshold,
5225 data->signal_change.current_signal,
5226 data->signal_change.current_noise,
5227 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005228 wpa_bss_update_level(wpa_s->current_bss,
5229 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005230 bgscan_notify_signal_change(
5231 wpa_s, data->signal_change.above_threshold,
5232 data->signal_change.current_signal,
5233 data->signal_change.current_noise,
5234 data->signal_change.current_txrate);
5235 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005236 case EVENT_INTERFACE_MAC_CHANGED:
5237 wpa_supplicant_update_mac_addr(wpa_s);
5238 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005239 case EVENT_INTERFACE_ENABLED:
5240 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5241 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomfdcde762020-04-02 11:19:20 -07005242 eloop_cancel_timeout(wpas_clear_disabled_interface,
5243 wpa_s, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005244 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07005245 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005246 if (wpa_s->p2p_mgmt) {
5247 wpa_supplicant_set_state(wpa_s,
5248 WPA_DISCONNECTED);
5249 break;
5250 }
5251
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005252#ifdef CONFIG_AP
5253 if (!wpa_s->ap_iface) {
5254 wpa_supplicant_set_state(wpa_s,
5255 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005256 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005257 wpa_supplicant_req_scan(wpa_s, 0, 0);
5258 } else
5259 wpa_supplicant_set_state(wpa_s,
5260 WPA_COMPLETED);
5261#else /* CONFIG_AP */
5262 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5263 wpa_supplicant_req_scan(wpa_s, 0, 0);
5264#endif /* CONFIG_AP */
5265 }
5266 break;
5267 case EVENT_INTERFACE_DISABLED:
5268 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005269#ifdef CONFIG_P2P
5270 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5271 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5272 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5273 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005274 * Mark interface disabled if this happens to end up not
5275 * being removed as a separate P2P group interface.
5276 */
5277 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5278 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005279 * The interface was externally disabled. Remove
5280 * it assuming an external entity will start a
5281 * new session if needed.
5282 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005283 if (wpa_s->current_ssid &&
5284 wpa_s->current_ssid->p2p_group)
5285 wpas_p2p_interface_unavailable(wpa_s);
5286 else
5287 wpas_p2p_disconnect(wpa_s);
5288 /*
5289 * wpa_s instance may have been freed, so must not use
5290 * it here anymore.
5291 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005292 break;
5293 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005294 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5295 p2p_in_progress(wpa_s->global->p2p) > 1) {
5296 /* This radio work will be cancelled, so clear P2P
5297 * state as well.
5298 */
5299 p2p_stop_find(wpa_s->global->p2p);
5300 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005301#endif /* CONFIG_P2P */
5302
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005303 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5304 /*
5305 * Indicate disconnection to keep ctrl_iface events
5306 * consistent.
5307 */
5308 wpa_supplicant_event_disassoc(
5309 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5310 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005311 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005312 os_reltime_age(&wpa_s->last_scan, &age);
5313 if (age.sec >= SCAN_RES_VALID_FOR_CONNECT) {
5314 clear_at.sec = SCAN_RES_VALID_FOR_CONNECT;
5315 clear_at.usec = 0;
5316 } else {
5317 struct os_reltime tmp;
5318
5319 tmp.sec = SCAN_RES_VALID_FOR_CONNECT;
5320 tmp.usec = 0;
5321 os_reltime_sub(&tmp, &age, &clear_at);
5322 }
5323 eloop_register_timeout(clear_at.sec, clear_at.usec,
5324 wpas_clear_disabled_interface,
5325 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005326 radio_remove_works(wpa_s, NULL, 0);
5327
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005328 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5329 break;
5330 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005331 wpa_supplicant_update_channel_list(
5332 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005333 break;
5334 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005335 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005336 break;
5337 case EVENT_BEST_CHANNEL:
5338 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5339 "(%d %d %d)",
5340 data->best_chan.freq_24, data->best_chan.freq_5,
5341 data->best_chan.freq_overall);
5342 wpa_s->best_24_freq = data->best_chan.freq_24;
5343 wpa_s->best_5_freq = data->best_chan.freq_5;
5344 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005345 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5346 data->best_chan.freq_5,
5347 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005348 break;
5349 case EVENT_UNPROT_DEAUTH:
5350 wpa_supplicant_event_unprot_deauth(wpa_s,
5351 &data->unprot_deauth);
5352 break;
5353 case EVENT_UNPROT_DISASSOC:
5354 wpa_supplicant_event_unprot_disassoc(wpa_s,
5355 &data->unprot_disassoc);
5356 break;
5357 case EVENT_STATION_LOW_ACK:
5358#ifdef CONFIG_AP
5359 if (wpa_s->ap_iface && data)
5360 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5361 data->low_ack.addr);
5362#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005363#ifdef CONFIG_TDLS
5364 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005365 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5366 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005367#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005368 break;
5369 case EVENT_IBSS_PEER_LOST:
5370#ifdef CONFIG_IBSS_RSN
5371 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5372#endif /* CONFIG_IBSS_RSN */
5373 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005374 case EVENT_DRIVER_GTK_REKEY:
5375 if (os_memcmp(data->driver_gtk_rekey.bssid,
5376 wpa_s->bssid, ETH_ALEN))
5377 break;
5378 if (!wpa_s->wpa)
5379 break;
5380 wpa_sm_update_replay_ctr(wpa_s->wpa,
5381 data->driver_gtk_rekey.replay_ctr);
5382 break;
5383 case EVENT_SCHED_SCAN_STOPPED:
5384 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005385 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005386 wpa_supplicant_notify_scanning(wpa_s, 0);
5387
5388 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5389 break;
5390
5391 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005392 * If the driver stopped scanning without being requested to,
5393 * request a new scan to continue scanning for networks.
5394 */
5395 if (!wpa_s->sched_scan_stop_req &&
5396 wpa_s->wpa_state == WPA_SCANNING) {
5397 wpa_dbg(wpa_s, MSG_DEBUG,
5398 "Restart scanning after unexpected sched_scan stop event");
5399 wpa_supplicant_req_scan(wpa_s, 1, 0);
5400 break;
5401 }
5402
5403 wpa_s->sched_scan_stop_req = 0;
5404
5405 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005406 * Start a new sched scan to continue searching for more SSIDs
5407 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005408 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005409 if (wpa_s->sched_scan_timed_out) {
5410 wpa_supplicant_req_sched_scan(wpa_s);
5411 } else if (wpa_s->pno_sched_pending) {
5412 wpa_s->pno_sched_pending = 0;
5413 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005414 } else if (resched) {
5415 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005416 }
5417
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005418 break;
5419 case EVENT_WPS_BUTTON_PUSHED:
5420#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005421 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005422#endif /* CONFIG_WPS */
5423 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005424 case EVENT_AVOID_FREQUENCIES:
5425 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5426 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005427 case EVENT_CONNECT_FAILED_REASON:
5428#ifdef CONFIG_AP
5429 if (!wpa_s->ap_iface || !data)
5430 break;
5431 hostapd_event_connect_failed_reason(
5432 wpa_s->ap_iface->bss[0],
5433 data->connect_failed_reason.addr,
5434 data->connect_failed_reason.code);
5435#endif /* CONFIG_AP */
5436 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005437 case EVENT_NEW_PEER_CANDIDATE:
5438#ifdef CONFIG_MESH
5439 if (!wpa_s->ifmsh || !data)
5440 break;
5441 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5442 data->mesh_peer.ies,
5443 data->mesh_peer.ie_len);
5444#endif /* CONFIG_MESH */
5445 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005446 case EVENT_SURVEY:
5447#ifdef CONFIG_AP
5448 if (!wpa_s->ap_iface)
5449 break;
5450 hostapd_event_get_survey(wpa_s->ap_iface,
5451 &data->survey_results);
5452#endif /* CONFIG_AP */
5453 break;
5454 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005455#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005456#ifdef CONFIG_ACS
5457 if (!wpa_s->ap_iface)
5458 break;
5459 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5460 &data->acs_selected_channels);
5461#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005462#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005463 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005464 case EVENT_P2P_LO_STOP:
5465#ifdef CONFIG_P2P
5466 wpa_s->p2p_lo_started = 0;
5467 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5468 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5469 data->p2p_lo_stop.reason_code);
5470#endif /* CONFIG_P2P */
5471 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005472 case EVENT_BEACON_LOSS:
5473 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5474 break;
5475 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5476 bgscan_notify_beacon_loss(wpa_s);
5477 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005478 case EVENT_EXTERNAL_AUTH:
5479#ifdef CONFIG_SAE
5480 if (!wpa_s->current_ssid) {
5481 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5482 break;
5483 }
5484 sme_external_auth_trigger(wpa_s, data);
5485#endif /* CONFIG_SAE */
5486 break;
5487 case EVENT_PORT_AUTHORIZED:
5488 wpa_supplicant_event_port_authorized(wpa_s);
5489 break;
5490 case EVENT_STATION_OPMODE_CHANGED:
5491#ifdef CONFIG_AP
5492 if (!wpa_s->ap_iface || !data)
5493 break;
5494
5495 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5496 data->sta_opmode.addr,
5497 data->sta_opmode.smps_mode,
5498 data->sta_opmode.chan_width,
5499 data->sta_opmode.rx_nss);
5500#endif /* CONFIG_AP */
5501 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005502 case EVENT_UNPROT_BEACON:
5503 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5504 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005505 default:
5506 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5507 break;
5508 }
5509}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005510
5511
5512void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5513 union wpa_event_data *data)
5514{
5515 struct wpa_supplicant *wpa_s;
5516
5517 if (event != EVENT_INTERFACE_STATUS)
5518 return;
5519
5520 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5521 if (wpa_s && wpa_s->driver->get_ifindex) {
5522 unsigned int ifindex;
5523
5524 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5525 if (ifindex != data->interface_status.ifindex) {
5526 wpa_dbg(wpa_s, MSG_DEBUG,
5527 "interface status ifindex %d mismatch (%d)",
5528 ifindex, data->interface_status.ifindex);
5529 return;
5530 }
5531 }
5532#ifdef CONFIG_MATCH_IFACE
5533 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5534 struct wpa_interface *wpa_i;
5535
5536 wpa_i = wpa_supplicant_match_iface(
5537 ctx, data->interface_status.ifname);
5538 if (!wpa_i)
5539 return;
5540 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5541 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07005542 }
5543#endif /* CONFIG_MATCH_IFACE */
5544
5545 if (wpa_s)
5546 wpa_supplicant_event(wpa_s, event, data);
5547}