blob: 31659034652a9ba8db660c00a6482235c3ade741 [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);
Sunil Ravi07c17622021-01-11 12:00:53 -08002375 wpas_notify_network_not_found(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002376 }
2377 }
2378 return 0;
2379}
2380
2381
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002382static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2383 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002385 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002386 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002387
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002388 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002389 if (res == 2) {
2390 /*
2391 * Interface may have been removed, so must not dereference
2392 * wpa_s after this.
2393 */
2394 return 1;
2395 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002396
2397 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002398 /*
2399 * If no scan results could be fetched, then no need to
2400 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002401 * this scan. Similarly, if scan results started a new operation on this
2402 * interface, do not notify other interfaces to avoid concurrent
2403 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002404 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002405 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002406 }
2407
2408 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002409 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002410 * so, they get updated with this same scan info.
2411 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002412 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2413 radio_list) {
2414 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002415 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2416 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002417 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2418 res > 0);
2419 if (res < 0)
2420 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002421 }
2422 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002423
2424 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002425}
2426
2427#endif /* CONFIG_NO_SCAN_PROCESSING */
2428
2429
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002430int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2431{
2432#ifdef CONFIG_NO_SCAN_PROCESSING
2433 return -1;
2434#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002435 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002436
Dmitry Shmidt29333592017-01-09 12:27:11 -08002437 wpa_s->ignore_post_flush_scan_res = 0;
2438
Dmitry Shmidt41712582015-06-29 11:02:15 -07002439 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002440 return -1;
2441
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002442 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002443 if (os_reltime_expired(&now, &wpa_s->last_scan,
2444 SCAN_RES_VALID_FOR_CONNECT)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002445 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2446 return -1;
2447 }
2448
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002449 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002450#endif /* CONFIG_NO_SCAN_PROCESSING */
2451}
2452
Dmitry Shmidt04949592012-07-19 12:16:46 -07002453#ifdef CONFIG_WNM
2454
2455static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2456{
2457 struct wpa_supplicant *wpa_s = eloop_ctx;
2458
2459 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2460 return;
2461
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002462 if (!wpa_s->no_keep_alive) {
2463 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2464 MAC2STR(wpa_s->bssid));
2465 /* TODO: could skip this if normal data traffic has been sent */
2466 /* TODO: Consider using some more appropriate data frame for
2467 * this */
2468 if (wpa_s->l2)
2469 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2470 (u8 *) "", 0);
2471 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002472
2473#ifdef CONFIG_SME
2474 if (wpa_s->sme.bss_max_idle_period) {
2475 unsigned int msec;
2476 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2477 if (msec > 100)
2478 msec -= 100;
2479 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2480 wnm_bss_keep_alive, wpa_s, NULL);
2481 }
2482#endif /* CONFIG_SME */
2483}
2484
2485
2486static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2487 const u8 *ies, size_t ies_len)
2488{
2489 struct ieee802_11_elems elems;
2490
2491 if (ies == NULL)
2492 return;
2493
2494 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2495 return;
2496
2497#ifdef CONFIG_SME
2498 if (elems.bss_max_idle_period) {
2499 unsigned int msec;
2500 wpa_s->sme.bss_max_idle_period =
2501 WPA_GET_LE16(elems.bss_max_idle_period);
2502 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2503 "TU)%s", wpa_s->sme.bss_max_idle_period,
2504 (elems.bss_max_idle_period[2] & 0x01) ?
2505 " (protected keep-live required)" : "");
2506 if (wpa_s->sme.bss_max_idle_period == 0)
2507 wpa_s->sme.bss_max_idle_period = 1;
2508 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2509 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2510 /* msec times 1000 */
2511 msec = wpa_s->sme.bss_max_idle_period * 1024;
2512 if (msec > 100)
2513 msec -= 100;
2514 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2515 wnm_bss_keep_alive, wpa_s,
2516 NULL);
2517 }
2518 }
2519#endif /* CONFIG_SME */
2520}
2521
2522#endif /* CONFIG_WNM */
2523
2524
2525void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2526{
2527#ifdef CONFIG_WNM
2528 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2529#endif /* CONFIG_WNM */
2530}
2531
2532
Dmitry Shmidt051af732013-10-22 13:52:46 -07002533#ifdef CONFIG_INTERWORKING
2534
2535static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2536 size_t len)
2537{
2538 int res;
2539
2540 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2541 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2542 if (res) {
2543 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2544 }
2545
2546 return res;
2547}
2548
2549
2550static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2551 const u8 *ies, size_t ies_len)
2552{
2553 struct ieee802_11_elems elems;
2554
2555 if (ies == NULL)
2556 return;
2557
2558 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2559 return;
2560
2561 if (elems.qos_map_set) {
2562 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2563 elems.qos_map_set_len);
2564 }
2565}
2566
2567#endif /* CONFIG_INTERWORKING */
2568
2569
Hai Shalom74f70d42019-02-11 14:42:39 -08002570static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2571 const u8 *ies, size_t ies_len)
2572{
2573 struct ieee802_11_elems elems;
2574 const u8 *map_sub_elem, *pos;
2575 size_t len;
2576
Hai Shalomfdcde762020-04-02 11:19:20 -07002577 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002578
Hai Shalomfdcde762020-04-02 11:19:20 -07002579 if (!ies ||
2580 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2581 !elems.multi_ap || elems.multi_ap_len < 7)
2582 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002583
2584 pos = elems.multi_ap + 4;
2585 len = elems.multi_ap_len - 4;
2586
2587 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002588 if (!map_sub_elem || map_sub_elem[1] < 1)
2589 return;
2590
2591 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2592 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2593 MULTI_AP_FRONTHAUL_BSS);
2594 wpa_s->multi_ap_ie = 1;
2595}
2596
2597
2598static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2599{
2600 if (!wpa_s->current_ssid ||
2601 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2602 return;
2603
2604 if (!wpa_s->multi_ap_ie) {
2605 wpa_printf(MSG_INFO,
2606 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002607 goto fail;
2608 }
2609
Hai Shalomfdcde762020-04-02 11:19:20 -07002610 if (!wpa_s->multi_ap_backhaul) {
2611 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002612 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2613 wpa_printf(MSG_INFO,
2614 "WPS active, accepting fronthaul-only BSS");
2615 /* Don't set 4addr mode in this case, so just return */
2616 return;
2617 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002618 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2619 goto fail;
2620 }
2621
2622 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2623 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2624 goto fail;
2625 }
2626 wpa_s->enabled_4addr_mode = 1;
2627 return;
2628
2629fail:
2630 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2631}
2632
2633
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002634#ifdef CONFIG_FST
2635static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2636 const u8 *ie, size_t ie_len)
2637{
2638 struct mb_ies_info mb_ies;
2639
2640 if (!ie || !ie_len || !wpa_s->fst)
2641 return -ENOENT;
2642
2643 os_memset(&mb_ies, 0, sizeof(mb_ies));
2644
2645 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2646 size_t len;
2647
2648 len = 2 + ie[1];
2649 if (len > ie_len) {
2650 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2651 ie, ie_len);
2652 break;
2653 }
2654
2655 if (ie[0] == WLAN_EID_MULTI_BAND) {
2656 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2657 (unsigned int) len);
2658 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2659 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2660 mb_ies.nof_ies++;
2661 }
2662
2663 ie_len -= len;
2664 ie += len;
2665 }
2666
2667 if (mb_ies.nof_ies > 0) {
2668 wpabuf_free(wpa_s->received_mb_ies);
2669 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2670 return 0;
2671 }
2672
2673 return -ENOENT;
2674}
2675#endif /* CONFIG_FST */
2676
2677
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002678static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2679 union wpa_event_data *data)
2680{
Hai Shalomc3565922019-10-28 11:58:20 -07002681 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002682 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002683 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002684 bool bssid_known;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002685
2686 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07002687 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002688 if (data->assoc_info.req_ies)
2689 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2690 data->assoc_info.req_ies_len);
2691 if (data->assoc_info.resp_ies) {
2692 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2693 data->assoc_info.resp_ies_len);
2694#ifdef CONFIG_TDLS
2695 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2696 data->assoc_info.resp_ies_len);
2697#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002698#ifdef CONFIG_WNM
2699 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2700 data->assoc_info.resp_ies_len);
2701#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002702#ifdef CONFIG_INTERWORKING
2703 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2704 data->assoc_info.resp_ies_len);
2705#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002706 if (wpa_s->hw_capab == CAPAB_VHT &&
2707 get_ie(data->assoc_info.resp_ies,
2708 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2709 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002710
2711 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2712 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002713 }
2714 if (data->assoc_info.beacon_ies)
2715 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2716 data->assoc_info.beacon_ies,
2717 data->assoc_info.beacon_ies_len);
2718 if (data->assoc_info.freq)
2719 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2720 data->assoc_info.freq);
2721
Hai Shalom021b0b52019-04-10 11:17:58 -07002722 wpa_s->connection_set = 0;
2723 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2724 struct ieee802_11_elems req_elems, resp_elems;
2725
2726 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2727 data->assoc_info.req_ies_len,
2728 &req_elems, 0) != ParseFailed &&
2729 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2730 data->assoc_info.resp_ies_len,
2731 &resp_elems, 0) != ParseFailed) {
2732 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07002733 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
2734 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07002735 wpa_s->connection_ht = req_elems.ht_capabilities &&
2736 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07002737 /* Do not include subset of VHT on 2.4 GHz vendor
2738 * extension in consideration for reporting VHT
2739 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07002740 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002741 resp_elems.vht_capabilities &&
2742 (!data->assoc_info.freq ||
2743 wpas_freq_to_band(data->assoc_info.freq) !=
2744 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07002745 wpa_s->connection_he = req_elems.he_capabilities &&
2746 resp_elems.he_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08002747
2748 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
2749 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
2750 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
2751 max_nss_rx_req : max_nss_rx_resp;
2752 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
2753 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
2754 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
2755 max_nss_tx_req : max_nss_tx_resp;
2756
2757 struct supported_chan_width sta_supported_chan_width =
2758 get_supported_channel_width(&req_elems);
2759 enum chan_width ap_operation_chan_width =
2760 get_operation_channel_width(&resp_elems);
2761 if (wpa_s->connection_vht || wpa_s->connection_he) {
2762 wpa_s->connection_channel_bandwidth =
2763 get_sta_operation_chan_width(ap_operation_chan_width,
2764 sta_supported_chan_width);
2765 } else if (wpa_s->connection_ht) {
2766 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
2767 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
2768 } else {
2769 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
2770 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002771 }
2772 }
2773
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002774 p = data->assoc_info.req_ies;
2775 l = data->assoc_info.req_ies_len;
2776
2777 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2778 while (p && l >= 2) {
2779 len = p[1] + 2;
2780 if (len > l) {
2781 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2782 p, l);
2783 break;
2784 }
Hai Shalomc3565922019-10-28 11:58:20 -07002785 if (!found &&
2786 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2787 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2788 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2789 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2790 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002791 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2792 break;
2793 found = 1;
2794 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07002795 }
2796 if (!found_x && p[0] == WLAN_EID_RSNX) {
2797 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
2798 break;
2799 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002800 }
2801 l -= len;
2802 p += len;
2803 }
2804 if (!found && data->assoc_info.req_ies)
2805 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002806 if (!found_x && data->assoc_info.req_ies)
2807 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002808
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002809#ifdef CONFIG_FILS
2810#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002811 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2812 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002813 (!data->assoc_info.resp_frame ||
2814 fils_process_assoc_resp(wpa_s->wpa,
2815 data->assoc_info.resp_frame,
2816 data->assoc_info.resp_frame_len) < 0)) {
2817 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2818 return -1;
2819 }
2820#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002821
2822 /* Additional processing for FILS when SME is in driver */
2823 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2824 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2825 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002826#endif /* CONFIG_FILS */
2827
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002828#ifdef CONFIG_OWE
2829 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07002830 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002831 owe_process_assoc_resp(wpa_s->wpa, bssid,
2832 data->assoc_info.resp_ies,
2833 data->assoc_info.resp_ies_len) < 0)) {
2834 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2835 return -1;
2836 }
2837#endif /* CONFIG_OWE */
2838
Hai Shalom021b0b52019-04-10 11:17:58 -07002839#ifdef CONFIG_DPP2
2840 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002841 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
2842 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002843 struct ieee802_11_elems elems;
2844
2845 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2846 data->assoc_info.resp_ies_len,
2847 &elems, 0) == ParseFailed ||
2848 !elems.owe_dh)
2849 goto no_pfs;
2850 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2851 elems.owe_dh_len) < 0) {
2852 wpa_supplicant_deauthenticate(wpa_s,
2853 WLAN_REASON_UNSPECIFIED);
2854 return -1;
2855 }
2856
2857 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2858 }
2859no_pfs:
2860#endif /* CONFIG_DPP2 */
2861
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002862#ifdef CONFIG_IEEE80211R
2863#ifdef CONFIG_SME
2864 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002865 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002866 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2867 data->assoc_info.resp_ies,
2868 data->assoc_info.resp_ies_len,
2869 bssid) < 0) {
2870 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2871 "Reassociation Response failed");
2872 wpa_supplicant_deauthenticate(
2873 wpa_s, WLAN_REASON_INVALID_IE);
2874 return -1;
2875 }
2876 }
2877
2878 p = data->assoc_info.resp_ies;
2879 l = data->assoc_info.resp_ies_len;
2880
2881#ifdef CONFIG_WPS_STRICT
2882 if (p && wpa_s->current_ssid &&
2883 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2884 struct wpabuf *wps;
2885 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2886 if (wps == NULL) {
2887 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2888 "include WPS IE in (Re)Association Response");
2889 return -1;
2890 }
2891
2892 if (wps_validate_assoc_resp(wps) < 0) {
2893 wpabuf_free(wps);
2894 wpa_supplicant_deauthenticate(
2895 wpa_s, WLAN_REASON_INVALID_IE);
2896 return -1;
2897 }
2898 wpabuf_free(wps);
2899 }
2900#endif /* CONFIG_WPS_STRICT */
2901
2902 /* Go through the IEs and make a copy of the MDIE, if present. */
2903 while (p && l >= 2) {
2904 len = p[1] + 2;
2905 if (len > l) {
2906 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2907 p, l);
2908 break;
2909 }
2910 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2911 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2912 wpa_s->sme.ft_used = 1;
2913 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2914 MOBILITY_DOMAIN_ID_LEN);
2915 break;
2916 }
2917 l -= len;
2918 p += len;
2919 }
2920#endif /* CONFIG_SME */
Mir Ali677e7482020-11-12 19:49:02 +05302921#ifdef CONFIG_DRIVER_NL80211_BRCM
2922 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) &&
2923 wpa_ft_is_completed(wpa_s->wpa)) {
2924 return 0;
2925 }
2926#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002927
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002928 /* Process FT when SME is in the driver */
2929 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2930 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002931 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002932 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2933 data->assoc_info.resp_ies,
2934 data->assoc_info.resp_ies_len,
2935 bssid) < 0) {
2936 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2937 "Reassociation Response failed");
2938 wpa_supplicant_deauthenticate(
2939 wpa_s, WLAN_REASON_INVALID_IE);
2940 return -1;
2941 }
2942 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2943 }
2944
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002945 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2946 data->assoc_info.resp_ies_len);
2947#endif /* CONFIG_IEEE80211R */
2948
Hai Shalom899fcc72020-10-19 14:38:18 -07002949 if (bssid_known)
2950 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
2951 data->assoc_info.resp_ies,
2952 data->assoc_info.resp_ies_len);
2953
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002954 /* WPA/RSN IE from Beacon/ProbeResp */
2955 p = data->assoc_info.beacon_ies;
2956 l = data->assoc_info.beacon_ies_len;
2957
2958 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2959 */
2960 wpa_found = rsn_found = 0;
2961 while (p && l >= 2) {
2962 len = p[1] + 2;
2963 if (len > l) {
2964 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2965 p, l);
2966 break;
2967 }
2968 if (!wpa_found &&
2969 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2970 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2971 wpa_found = 1;
2972 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2973 }
2974
2975 if (!rsn_found &&
2976 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2977 rsn_found = 1;
2978 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2979 }
2980
Hai Shalomc3565922019-10-28 11:58:20 -07002981 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
2982 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
2983
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002984 l -= len;
2985 p += len;
2986 }
2987
2988 if (!wpa_found && data->assoc_info.beacon_ies)
2989 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002990 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002991 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002992 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
2993 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002994 if (wpa_found || rsn_found)
2995 wpa_s->ap_ies_from_associnfo = 1;
2996
Jouni Malinen87fd2792011-05-16 18:35:42 +03002997 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2998 wpa_s->assoc_freq != data->assoc_info.freq) {
2999 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
3000 "%u to %u MHz",
3001 wpa_s->assoc_freq, data->assoc_info.freq);
3002 wpa_supplicant_update_scan_results(wpa_s);
3003 }
3004
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003005 wpa_s->assoc_freq = data->assoc_info.freq;
3006
3007 return 0;
3008}
3009
3010
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003011static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3012{
Hai Shalomc3565922019-10-28 11:58:20 -07003013 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003014
3015 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3016 return -1;
3017
3018 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3019 return 0;
3020
3021 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3022 WPA_IE_VENDOR_TYPE);
3023 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003024 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003025
3026 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3027 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3028 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003029 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3030 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3031 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003032 return -1;
3033
3034 return 0;
3035}
3036
3037
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003038static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3039 union wpa_event_data *data)
3040{
3041#ifdef CONFIG_FST
3042 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3043 struct wpa_bss *bss = wpa_s->current_bss;
3044 const u8 *ieprb, *iebcn;
3045
3046 wpabuf_free(wpa_s->received_mb_ies);
3047 wpa_s->received_mb_ies = NULL;
3048
3049 if (ai &&
3050 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3051 wpa_printf(MSG_DEBUG,
3052 "FST: MB IEs updated from Association Response frame");
3053 return;
3054 }
3055
3056 if (ai &&
3057 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3058 wpa_printf(MSG_DEBUG,
3059 "FST: MB IEs updated from association event Beacon IEs");
3060 return;
3061 }
3062
3063 if (!bss)
3064 return;
3065
3066 ieprb = (const u8 *) (bss + 1);
3067 iebcn = ieprb + bss->ie_len;
3068
3069 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3070 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3071 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3072 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3073#endif /* CONFIG_FST */
3074}
3075
3076
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003077static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3078 union wpa_event_data *data)
3079{
3080 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003081 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003082 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003083#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3084 struct wpa_bss *bss;
3085#endif /* CONFIG_FILS || CONFIG_MBO */
Mir Ali677e7482020-11-12 19:49:02 +05303086#ifdef CONFIG_DRIVER_NL80211_BRCM
3087 struct wpa_ie_data ie;
3088#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003089
3090#ifdef CONFIG_AP
3091 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003092 if (!data)
3093 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003094 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3095 data->assoc_info.addr,
3096 data->assoc_info.req_ies,
3097 data->assoc_info.req_ies_len,
3098 data->assoc_info.reassoc);
3099 return;
3100 }
3101#endif /* CONFIG_AP */
3102
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003103 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003104 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003105
Mir Ali677e7482020-11-12 19:49:02 +05303106#ifdef CONFIG_DRIVER_NL80211_BRCM
3107 if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) {
3108 struct wpa_ft_ies parse;
3109 /* Check for FT reassociation is done by the driver */
3110#ifdef CONFIG_IEEE80211R
3111 int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt);
3112 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) && (wpa_s->key_mgmt == ie.key_mgmt)) {
3113 if (wpa_ft_parse_ies(data->assoc_info.resp_ies,
3114 data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) {
3115 wpa_printf(MSG_DEBUG, "Failed to parse FT IEs");
3116 return;
3117 }
3118 if (parse.rsn_pmkid != NULL) {
3119 wpa_set_ft_completed(wpa_s->wpa);
3120 wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver");
3121 }
3122 }
3123#endif /* CONFIG_IEEE80211R */
3124 }
3125#endif /* CONFIG_DRIVER_NL80211_BRCM */
3126
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003127 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
3128 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3129 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003130 /*
3131 * FILS authentication can share the same mechanism to mark the
3132 * connection fully authenticated, so set ft_completed also based on
3133 * FILS result.
3134 */
3135 if (!ft_completed)
3136 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003137
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003138 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3139 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003140 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003141 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3142 return;
3143 }
3144
Mir Ali677e7482020-11-12 19:49:02 +05303145#ifdef CONFIG_DRIVER_NL80211_BRCM
3146 /* For driver based roaming, insert PSK during the initial association */
3147 if (is_zero_ether_addr(wpa_s->bssid) &&
3148 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
3149 /* In case the driver wants to handle re-assocs, pass it down the PMK. */
3150 wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver");
3151 wpa_sm_install_pmk(wpa_s->wpa);
3152 }
3153#endif /* CONFIG_DRIVER_NL80211_BRCM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003155 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003156 if (os_reltime_initialized(&wpa_s->session_start)) {
3157 os_reltime_age(&wpa_s->session_start,
3158 &wpa_s->session_length);
3159 wpa_s->session_start.sec = 0;
3160 wpa_s->session_start.usec = 0;
3161 wpas_notify_session_length(wpa_s);
3162 } else {
3163 wpas_notify_auth_changed(wpa_s);
3164 os_get_reltime(&wpa_s->session_start);
3165 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003166 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3167 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003168 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003169 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003170 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3171 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003172 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003173
3174 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3175 wpa_clear_keys(wpa_s, bssid);
3176 }
3177 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003178 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003179 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3180 return;
3181 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003182 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003183
Hai Shalomfdcde762020-04-02 11:19:20 -07003184 multi_ap_set_4addr_mode(wpa_s);
3185
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003186 if (wpa_s->conf->ap_scan == 1 &&
3187 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003188 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3189 wpa_msg(wpa_s, MSG_WARNING,
3190 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003191 }
3192
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003193 wpas_fst_update_mb_assoc(wpa_s, data);
3194
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003195#ifdef CONFIG_SME
3196 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3197 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003198 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003199#endif /* CONFIG_SME */
3200
3201 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3202 if (wpa_s->current_ssid) {
3203 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3204 * initialized before association, but for other modes,
3205 * initialize PC/SC here, if the current configuration needs
3206 * smartcard or SIM/USIM. */
3207 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3208 }
3209 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3210 if (wpa_s->l2)
3211 l2_packet_notify_auth_start(wpa_s->l2);
3212
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003213 already_authorized = data && data->assoc_info.authorized;
3214
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003215 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003216 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003217 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3218 * state machine may transit to AUTHENTICATING state based on obsolete
3219 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3220 * AUTHENTICATED without ever giving chance to EAP state machine to
3221 * reset the state.
3222 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003223 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003224 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3225 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003226 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003227 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3228 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3229 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003230 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003231 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003232 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003233 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003234 wpa_s->eapol_received = 0;
3235 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3236 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3237 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003238 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003239 if (wpa_s->current_ssid &&
3240 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003241 (wpa_s->drv_flags &
3242 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3243 /*
3244 * Set the key after having received joined-IBSS event
3245 * from the driver.
3246 */
3247 wpa_supplicant_set_wpa_none_key(wpa_s,
3248 wpa_s->current_ssid);
3249 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003250 wpa_supplicant_cancel_auth_timeout(wpa_s);
3251 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3252 } else if (!ft_completed) {
3253 /* Timeout for receiving the first EAPOL packet */
3254 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3255 }
3256 wpa_supplicant_cancel_scan(wpa_s);
3257
Hai Shalom5f92bc92019-04-18 11:54:11 -07003258 if (ft_completed) {
3259 /*
3260 * FT protocol completed - make sure EAPOL state machine ends
3261 * up in authenticated.
3262 */
3263 wpa_supplicant_cancel_auth_timeout(wpa_s);
3264 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003265 eapol_sm_notify_portValid(wpa_s->eapol, true);
3266 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003267 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3268 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003269 /*
3270 * We are done; the driver will take care of RSN 4-way
3271 * handshake.
3272 */
3273 wpa_supplicant_cancel_auth_timeout(wpa_s);
3274 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003275 eapol_sm_notify_portValid(wpa_s->eapol, true);
3276 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003277 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003278 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3279 /*
3280 * The driver will take care of RSN 4-way handshake, so we need
3281 * to allow EAPOL supplicant to complete its work without
3282 * waiting for WPA supplicant.
3283 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003284 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003285 }
3286
Jouni Malinena05074c2012-12-21 21:35:35 +02003287 wpa_s->last_eapol_matches_bssid = 0;
3288
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003289#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003290 if (wpa_s->rsne_override_eapol) {
3291 wpa_printf(MSG_DEBUG,
3292 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3293 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3294 wpabuf_head(wpa_s->rsne_override_eapol),
3295 wpabuf_len(wpa_s->rsne_override_eapol));
3296 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003297 if (wpa_s->rsnxe_override_eapol) {
3298 wpa_printf(MSG_DEBUG,
3299 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3300 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3301 wpabuf_head(wpa_s->rsnxe_override_eapol),
3302 wpabuf_len(wpa_s->rsnxe_override_eapol));
3303 }
3304#endif /* CONFIG_TESTING_OPTIONS */
3305
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003306 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003307 struct os_reltime now, age;
3308 os_get_reltime(&now);
3309 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003310 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003311 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3312 0) {
3313 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3314 "frame that was received just before "
3315 "association notification");
3316 wpa_supplicant_rx_eapol(
3317 wpa_s, wpa_s->pending_eapol_rx_src,
3318 wpabuf_head(wpa_s->pending_eapol_rx),
3319 wpabuf_len(wpa_s->pending_eapol_rx));
3320 }
3321 wpabuf_free(wpa_s->pending_eapol_rx);
3322 wpa_s->pending_eapol_rx = NULL;
3323 }
3324
Hai Shalomfdcde762020-04-02 11:19:20 -07003325#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003326 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3327 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003328 wpa_s->current_ssid &&
3329 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003330 /* Set static WEP keys again */
3331 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3332 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003333#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003334
3335#ifdef CONFIG_IBSS_RSN
3336 if (wpa_s->current_ssid &&
3337 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3338 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3339 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3340 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003341 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003342 if (!wpa_s->ibss_rsn) {
3343 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3344 wpa_supplicant_deauthenticate(
3345 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3346 return;
3347 }
3348
3349 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3350 }
3351#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003352
3353 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003354
3355 if (data) {
3356 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3357 data->assoc_info.resp_ies_len,
3358 &data->assoc_info.wmm_params);
3359
3360 if (wpa_s->reassoc_same_bss)
3361 wmm_ac_restore_tspecs(wpa_s);
3362 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003363
Hai Shalomc3565922019-10-28 11:58:20 -07003364#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3365 bss = wpa_bss_get_bssid(wpa_s, bssid);
3366#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003367#ifdef CONFIG_FILS
3368 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003369 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3370
3371 if (fils_cache_id)
3372 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3373 }
3374#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003375
3376#ifdef CONFIG_MBO
3377 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3378#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003379
3380#ifdef CONFIG_DPP2
3381 wpa_s->dpp_pfs_fallback = 0;
3382#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003383}
3384
3385
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003386static int disconnect_reason_recoverable(u16 reason_code)
3387{
3388 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3389 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3390 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3391}
3392
3393
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003394static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003395 u16 reason_code,
3396 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003397{
3398 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003399
3400 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3401 /*
3402 * At least Host AP driver and a Prism3 card seemed to be
3403 * generating streams of disconnected events when configuring
3404 * IBSS for WPA-None. Ignore them for now.
3405 */
3406 return;
3407 }
3408
3409 bssid = wpa_s->bssid;
3410 if (is_zero_ether_addr(bssid))
3411 bssid = wpa_s->pending_bssid;
3412
3413 if (!is_zero_ether_addr(bssid) ||
3414 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3415 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3416 " reason=%d%s",
3417 MAC2STR(bssid), reason_code,
3418 locally_generated ? " locally_generated=1" : "");
3419 }
3420}
3421
3422
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003423static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3424 int locally_generated)
3425{
3426 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003427 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003428 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3429 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003430 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003431
3432 /*
3433 * It looks like connection was lost while trying to go through PSK
3434 * 4-way handshake. Filter out known disconnection cases that are caused
3435 * by something else than PSK mismatch to avoid confusing reports.
3436 */
3437
3438 if (locally_generated) {
3439 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3440 return 0;
3441 }
3442
3443 return 1;
3444}
3445
3446
Jouni Malinen2b89da82012-08-31 22:04:41 +03003447static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3448 u16 reason_code,
3449 int locally_generated)
3450{
3451 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003452 int authenticating;
3453 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003454 struct wpa_bss *fast_reconnect = NULL;
3455 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003456 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003457 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003458
3459 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3460 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3461
3462 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3463 /*
3464 * At least Host AP driver and a Prism3 card seemed to be
3465 * generating streams of disconnected events when configuring
3466 * IBSS for WPA-None. Ignore them for now.
3467 */
3468 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3469 "IBSS/WPA-None mode");
3470 return;
3471 }
3472
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003473 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3474 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3475 locally_generated)
3476 /*
3477 * Remove the inactive AP (which is probably out of range) from
3478 * the BSS list after marking disassociation. In particular
3479 * mac80211-based drivers use the
3480 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3481 * locally generated disconnection events for cases where the
3482 * AP does not reply anymore.
3483 */
3484 curr = wpa_s->current_bss;
3485
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003486 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003487 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3488 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003489 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3490 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003491 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003492#ifdef CONFIG_DPP2
3493 wpas_dpp_send_conn_status_result(wpa_s,
3494 DPP_STATUS_AUTH_FAILURE);
3495#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003496 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003497 if (!wpa_s->disconnected &&
3498 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003499 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003500 wpas_wps_searching(wpa_s) ||
3501 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003502 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003503 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003504 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003505 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003506 wpa_s->wpa_state);
3507 if (wpa_s->wpa_state == WPA_COMPLETED &&
3508 wpa_s->current_ssid &&
3509 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003510 (wpa_s->own_reconnect_req ||
3511 (!locally_generated &&
3512 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003513 /*
3514 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003515 * us, but could allow us to get back in. This is also
3516 * triggered for cases where local reconnection request
3517 * is used to force reassociation with the same BSS.
3518 * Try to reconnect to the same BSS without a full scan
3519 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003520 */
3521 fast_reconnect = wpa_s->current_bss;
3522 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003523 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003524 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003525 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003526 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3527 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003528 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003529 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003530 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003531 "try to re-connect");
3532 wpa_s->reassociate = 0;
3533 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003534 if (!wpa_s->pno)
3535 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003536 }
3537 bssid = wpa_s->bssid;
3538 if (is_zero_ether_addr(bssid))
3539 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003540 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3541 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003542 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003543 if (locally_generated)
3544 wpa_s->disconnect_reason = -reason_code;
3545 else
3546 wpa_s->disconnect_reason = reason_code;
3547 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003548 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3549 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003550 wpa_clear_keys(wpa_s, wpa_s->bssid);
3551 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003552 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003553 wpa_supplicant_mark_disassoc(wpa_s);
3554
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003555 if (curr)
3556 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3557
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003558 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003559 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003560 wpa_s->current_ssid = last_ssid;
3561 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003562
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003563 if (fast_reconnect &&
3564 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3565 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3566 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3567 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003568 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003569 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003570#ifndef CONFIG_NO_SCAN_PROCESSING
3571 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3572 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3573 fast_reconnect_ssid) < 0) {
3574 /* Recover through full scan */
3575 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3576 }
3577#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003578 } else if (fast_reconnect) {
3579 /*
3580 * Could not reconnect to the same BSS due to network being
3581 * disabled. Use a new scan to match the alternative behavior
3582 * above, i.e., to continue automatic reconnection attempt in a
3583 * way that enforces disabled network rules.
3584 */
3585 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003586 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003587}
3588
3589
3590#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003591void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003592{
3593 struct wpa_supplicant *wpa_s = eloop_ctx;
3594
3595 if (!wpa_s->pending_mic_error_report)
3596 return;
3597
3598 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3599 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3600 wpa_s->pending_mic_error_report = 0;
3601}
3602#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3603
3604
3605static void
3606wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3607 union wpa_event_data *data)
3608{
3609 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003610 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003611
3612 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3613 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003614 os_get_reltime(&t);
3615 if ((wpa_s->last_michael_mic_error.sec &&
3616 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003617 wpa_s->pending_mic_error_report) {
3618 if (wpa_s->pending_mic_error_report) {
3619 /*
3620 * Send the pending MIC error report immediately since
3621 * we are going to start countermeasures and AP better
3622 * do the same.
3623 */
3624 wpa_sm_key_request(wpa_s->wpa, 1,
3625 wpa_s->pending_mic_error_pairwise);
3626 }
3627
3628 /* Send the new MIC error report immediately since we are going
3629 * to start countermeasures and AP better do the same.
3630 */
3631 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3632
3633 /* initialize countermeasures */
3634 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003635
3636 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3637
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003638 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3639
3640 /*
3641 * Need to wait for completion of request frame. We do not get
3642 * any callback for the message completion, so just wait a
3643 * short while and hope for the best. */
3644 os_sleep(0, 10000);
3645
3646 wpa_drv_set_countermeasures(wpa_s, 1);
3647 wpa_supplicant_deauthenticate(wpa_s,
3648 WLAN_REASON_MICHAEL_MIC_FAILURE);
3649 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3650 wpa_s, NULL);
3651 eloop_register_timeout(60, 0,
3652 wpa_supplicant_stop_countermeasures,
3653 wpa_s, NULL);
3654 /* TODO: mark the AP rejected for 60 second. STA is
3655 * allowed to associate with another AP.. */
3656 } else {
3657#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3658 if (wpa_s->mic_errors_seen) {
3659 /*
3660 * Reduce the effectiveness of Michael MIC error
3661 * reports as a means for attacking against TKIP if
3662 * more than one MIC failure is noticed with the same
3663 * PTK. We delay the transmission of the reports by a
3664 * random time between 0 and 60 seconds in order to
3665 * force the attacker wait 60 seconds before getting
3666 * the information on whether a frame resulted in a MIC
3667 * failure.
3668 */
3669 u8 rval[4];
3670 int sec;
3671
3672 if (os_get_random(rval, sizeof(rval)) < 0)
3673 sec = os_random() % 60;
3674 else
3675 sec = WPA_GET_BE32(rval) % 60;
3676 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3677 "report %d seconds", sec);
3678 wpa_s->pending_mic_error_report = 1;
3679 wpa_s->pending_mic_error_pairwise = pairwise;
3680 eloop_cancel_timeout(
3681 wpa_supplicant_delayed_mic_error_report,
3682 wpa_s, NULL);
3683 eloop_register_timeout(
3684 sec, os_random() % 1000000,
3685 wpa_supplicant_delayed_mic_error_report,
3686 wpa_s, NULL);
3687 } else {
3688 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3689 }
3690#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3691 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3692#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3693 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003694 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003695 wpa_s->mic_errors_seen++;
3696}
3697
3698
3699#ifdef CONFIG_TERMINATE_ONLASTIF
3700static int any_interfaces(struct wpa_supplicant *head)
3701{
3702 struct wpa_supplicant *wpa_s;
3703
3704 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3705 if (!wpa_s->interface_removed)
3706 return 1;
3707 return 0;
3708}
3709#endif /* CONFIG_TERMINATE_ONLASTIF */
3710
3711
3712static void
3713wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3714 union wpa_event_data *data)
3715{
3716 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3717 return;
3718
3719 switch (data->interface_status.ievent) {
3720 case EVENT_INTERFACE_ADDED:
3721 if (!wpa_s->interface_removed)
3722 break;
3723 wpa_s->interface_removed = 0;
3724 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3725 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3726 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3727 "driver after interface was added");
3728 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003729
3730#ifdef CONFIG_P2P
3731 if (!wpa_s->global->p2p &&
3732 !wpa_s->global->p2p_disabled &&
3733 !wpa_s->conf->p2p_disabled &&
3734 (wpa_s->drv_flags &
3735 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3736 wpas_p2p_add_p2pdev_interface(
3737 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3738 wpa_printf(MSG_INFO,
3739 "P2P: Failed to enable P2P Device interface");
3740 /* Try to continue without. P2P will be disabled. */
3741 }
3742#endif /* CONFIG_P2P */
3743
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003744 break;
3745 case EVENT_INTERFACE_REMOVED:
3746 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3747 wpa_s->interface_removed = 1;
3748 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003749 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003750 l2_packet_deinit(wpa_s->l2);
3751 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003752
3753#ifdef CONFIG_P2P
3754 if (wpa_s->global->p2p &&
3755 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3756 (wpa_s->drv_flags &
3757 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3758 wpa_dbg(wpa_s, MSG_DEBUG,
3759 "Removing P2P Device interface");
3760 wpa_supplicant_remove_iface(
3761 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3762 0);
3763 wpa_s->global->p2p_init_wpa_s = NULL;
3764 }
3765#endif /* CONFIG_P2P */
3766
Dmitry Shmidte4663042016-04-04 10:07:49 -07003767#ifdef CONFIG_MATCH_IFACE
3768 if (wpa_s->matched) {
3769 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3770 break;
3771 }
3772#endif /* CONFIG_MATCH_IFACE */
3773
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003774#ifdef CONFIG_TERMINATE_ONLASTIF
3775 /* check if last interface */
3776 if (!any_interfaces(wpa_s->global->ifaces))
3777 eloop_terminate();
3778#endif /* CONFIG_TERMINATE_ONLASTIF */
3779 break;
3780 }
3781}
3782
3783
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003784#ifdef CONFIG_TDLS
3785static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3786 union wpa_event_data *data)
3787{
3788 if (data == NULL)
3789 return;
3790 switch (data->tdls.oper) {
3791 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003792 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3793 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3794 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3795 else
3796 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003797 break;
3798 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003799 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3800 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3801 data->tdls.reason_code);
3802 else
3803 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3804 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003805 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003806 case TDLS_REQUEST_DISCOVER:
3807 wpa_tdls_send_discovery_request(wpa_s->wpa,
3808 data->tdls.peer);
3809 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003810 }
3811}
3812#endif /* CONFIG_TDLS */
3813
3814
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003815#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003816static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3817 union wpa_event_data *data)
3818{
3819 if (data == NULL)
3820 return;
3821 switch (data->wnm.oper) {
3822 case WNM_OPER_SLEEP:
3823 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3824 "(action=%d, intval=%d)",
3825 data->wnm.sleep_action, data->wnm.sleep_intval);
3826 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003827 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003828 break;
3829 }
3830}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003831#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003832
3833
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003834#ifdef CONFIG_IEEE80211R
3835static void
3836wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3837 union wpa_event_data *data)
3838{
3839 if (data == NULL)
3840 return;
3841
3842 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3843 data->ft_ies.ies_len,
3844 data->ft_ies.ft_action,
3845 data->ft_ies.target_ap,
3846 data->ft_ies.ric_ies,
3847 data->ft_ies.ric_ies_len) < 0) {
3848 /* TODO: prevent MLME/driver from trying to associate? */
3849 }
3850}
3851#endif /* CONFIG_IEEE80211R */
3852
3853
3854#ifdef CONFIG_IBSS_RSN
3855static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3856 union wpa_event_data *data)
3857{
3858 struct wpa_ssid *ssid;
3859 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3860 return;
3861 if (data == NULL)
3862 return;
3863 ssid = wpa_s->current_ssid;
3864 if (ssid == NULL)
3865 return;
3866 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3867 return;
3868
3869 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3870}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003871
3872
3873static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3874 union wpa_event_data *data)
3875{
3876 struct wpa_ssid *ssid = wpa_s->current_ssid;
3877
3878 if (ssid == NULL)
3879 return;
3880
3881 /* check if the ssid is correctly configured as IBSS/RSN */
3882 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3883 return;
3884
3885 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3886 data->rx_mgmt.frame_len);
3887}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003888#endif /* CONFIG_IBSS_RSN */
3889
3890
3891#ifdef CONFIG_IEEE80211R
3892static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3893 size_t len)
3894{
3895 const u8 *sta_addr, *target_ap_addr;
3896 u16 status;
3897
3898 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3899 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3900 return; /* only SME case supported for now */
3901 if (len < 1 + 2 * ETH_ALEN + 2)
3902 return;
3903 if (data[0] != 2)
3904 return; /* Only FT Action Response is supported for now */
3905 sta_addr = data + 1;
3906 target_ap_addr = data + 1 + ETH_ALEN;
3907 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3908 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3909 MACSTR " TargetAP " MACSTR " status %u",
3910 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3911
3912 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3913 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3914 " in FT Action Response", MAC2STR(sta_addr));
3915 return;
3916 }
3917
3918 if (status) {
3919 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3920 "failure (status code %d)", status);
3921 /* TODO: report error to FT code(?) */
3922 return;
3923 }
3924
3925 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3926 len - (1 + 2 * ETH_ALEN + 2), 1,
3927 target_ap_addr, NULL, 0) < 0)
3928 return;
3929
3930#ifdef CONFIG_SME
3931 {
3932 struct wpa_bss *bss;
3933 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3934 if (bss)
3935 wpa_s->sme.freq = bss->freq;
3936 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3937 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3938 WLAN_AUTH_FT);
3939 }
3940#endif /* CONFIG_SME */
3941}
3942#endif /* CONFIG_IEEE80211R */
3943
3944
3945static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3946 struct unprot_deauth *e)
3947{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003948 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3949 "dropped: " MACSTR " -> " MACSTR
3950 " (reason code %u)",
3951 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3952 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003953}
3954
3955
3956static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3957 struct unprot_disassoc *e)
3958{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003959 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3960 "dropped: " MACSTR " -> " MACSTR
3961 " (reason code %u)",
3962 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3963 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003964}
3965
3966
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003967static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3968 u16 reason_code, int locally_generated,
3969 const u8 *ie, size_t ie_len, int deauth)
3970{
3971#ifdef CONFIG_AP
3972 if (wpa_s->ap_iface && addr) {
3973 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3974 return;
3975 }
3976
3977 if (wpa_s->ap_iface) {
3978 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3979 return;
3980 }
3981#endif /* CONFIG_AP */
3982
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003983 if (!locally_generated)
3984 wpa_s->own_disconnect_req = 0;
3985
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003986 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3987
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003988 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3989 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3990 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3991 eapol_sm_failed(wpa_s->eapol))) &&
3992 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003993 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003994
3995#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003996 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003997 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3998 locally_generated) > 0) {
3999 /*
4000 * The interface was removed, so cannot continue
4001 * processing any additional operations after this.
4002 */
4003 return;
4004 }
4005 }
4006#endif /* CONFIG_P2P */
4007
4008 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
4009 locally_generated);
4010}
4011
4012
4013static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
4014 struct disassoc_info *info)
4015{
4016 u16 reason_code = 0;
4017 int locally_generated = 0;
4018 const u8 *addr = NULL;
4019 const u8 *ie = NULL;
4020 size_t ie_len = 0;
4021
4022 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
4023
4024 if (info) {
4025 addr = info->addr;
4026 ie = info->ie;
4027 ie_len = info->ie_len;
4028 reason_code = info->reason_code;
4029 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004030 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
4031 reason2str(reason_code),
4032 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004033 if (addr)
4034 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4035 MAC2STR(addr));
4036 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
4037 ie, ie_len);
4038 }
4039
4040#ifdef CONFIG_AP
4041 if (wpa_s->ap_iface && info && info->addr) {
4042 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4043 return;
4044 }
4045
4046 if (wpa_s->ap_iface) {
4047 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4048 return;
4049 }
4050#endif /* CONFIG_AP */
4051
4052#ifdef CONFIG_P2P
4053 if (info) {
4054 wpas_p2p_disassoc_notif(
4055 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4056 locally_generated);
4057 }
4058#endif /* CONFIG_P2P */
4059
4060 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4061 sme_event_disassoc(wpa_s, info);
4062
4063 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4064 ie, ie_len, 0);
4065}
4066
4067
4068static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4069 struct deauth_info *info)
4070{
4071 u16 reason_code = 0;
4072 int locally_generated = 0;
4073 const u8 *addr = NULL;
4074 const u8 *ie = NULL;
4075 size_t ie_len = 0;
4076
4077 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4078
4079 if (info) {
4080 addr = info->addr;
4081 ie = info->ie;
4082 ie_len = info->ie_len;
4083 reason_code = info->reason_code;
4084 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004085 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4086 reason_code, reason2str(reason_code),
4087 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004088 if (addr) {
4089 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4090 MAC2STR(addr));
4091 }
4092 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4093 ie, ie_len);
4094 }
4095
4096 wpa_reset_ft_completed(wpa_s->wpa);
4097
4098 wpas_event_disconnect(wpa_s, addr, reason_code,
4099 locally_generated, ie, ie_len, 1);
4100}
4101
4102
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004103static const char * reg_init_str(enum reg_change_initiator init)
4104{
4105 switch (init) {
4106 case REGDOM_SET_BY_CORE:
4107 return "CORE";
4108 case REGDOM_SET_BY_USER:
4109 return "USER";
4110 case REGDOM_SET_BY_DRIVER:
4111 return "DRIVER";
4112 case REGDOM_SET_BY_COUNTRY_IE:
4113 return "COUNTRY_IE";
4114 case REGDOM_BEACON_HINT:
4115 return "BEACON_HINT";
4116 }
4117 return "?";
4118}
4119
4120
4121static const char * reg_type_str(enum reg_type type)
4122{
4123 switch (type) {
4124 case REGDOM_TYPE_UNKNOWN:
4125 return "UNKNOWN";
4126 case REGDOM_TYPE_COUNTRY:
4127 return "COUNTRY";
4128 case REGDOM_TYPE_WORLD:
4129 return "WORLD";
4130 case REGDOM_TYPE_CUSTOM_WORLD:
4131 return "CUSTOM_WORLD";
4132 case REGDOM_TYPE_INTERSECTION:
4133 return "INTERSECTION";
4134 }
4135 return "?";
4136}
4137
4138
Hai Shalom74f70d42019-02-11 14:42:39 -08004139void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4140 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004141{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004142 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004143 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004144
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004145 /*
4146 * To allow backwards compatibility with higher level layers that
4147 * assumed the REGDOM_CHANGE event is sent over the initially added
4148 * interface. Find the highest parent of this interface and use it to
4149 * send the event.
4150 */
4151 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4152 ;
4153
Hai Shalom74f70d42019-02-11 14:42:39 -08004154 if (info) {
4155 wpa_msg(ifs, MSG_INFO,
4156 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4157 reg_init_str(info->initiator), reg_type_str(info->type),
4158 info->alpha2[0] ? " alpha2=" : "",
4159 info->alpha2[0] ? info->alpha2 : "");
4160 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004161
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004162 if (wpa_s->drv_priv == NULL)
4163 return; /* Ignore event during drv initialization */
4164
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004165 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4166 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004167 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4168 ifs->ifname);
4169 free_hw_features(ifs);
4170 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004171 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004172
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004173 /* Restart PNO/sched_scan with updated channel list */
4174 if (ifs->pno) {
4175 wpas_stop_pno(ifs);
4176 wpas_start_pno(ifs);
4177 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4178 wpa_dbg(ifs, MSG_DEBUG,
4179 "Channel list changed - restart sched_scan");
4180 wpas_scan_restart_sched_scan(ifs);
4181 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004182 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004183
4184 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004185}
4186
4187
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004188static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004189 const u8 *frame, size_t len, int freq,
4190 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004191{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004192 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004193 const u8 *payload;
4194 size_t plen;
4195 u8 category;
4196
4197 if (len < IEEE80211_HDRLEN + 2)
4198 return;
4199
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004200 mgmt = (const struct ieee80211_mgmt *) frame;
4201 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004202 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004203 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004204
4205 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4206 " Category=%u DataLen=%d freq=%d MHz",
4207 MAC2STR(mgmt->sa), category, (int) plen, freq);
4208
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004209 if (category == WLAN_ACTION_WMM) {
4210 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4211 return;
4212 }
4213
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004214#ifdef CONFIG_IEEE80211R
4215 if (category == WLAN_ACTION_FT) {
4216 ft_rx_action(wpa_s, payload, plen);
4217 return;
4218 }
4219#endif /* CONFIG_IEEE80211R */
4220
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004221#ifdef CONFIG_SME
4222 if (category == WLAN_ACTION_SA_QUERY) {
4223 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
4224 return;
4225 }
4226#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004227
4228#ifdef CONFIG_WNM
4229 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4230 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4231 return;
4232 }
4233#endif /* CONFIG_WNM */
4234
4235#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004236 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4237 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004238 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004239 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004240 payload, plen, freq) == 0)
4241 return;
4242#endif /* CONFIG_GAS */
4243
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004244#ifdef CONFIG_GAS_SERVER
4245 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4246 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4247 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4248 mgmt->u.action.category,
4249 payload, plen, freq) == 0)
4250 return;
4251#endif /* CONFIG_GAS_SERVER */
4252
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004253#ifdef CONFIG_TDLS
4254 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4255 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4256 wpa_dbg(wpa_s, MSG_DEBUG,
4257 "TDLS: Received Discovery Response from " MACSTR,
4258 MAC2STR(mgmt->sa));
4259 return;
4260 }
4261#endif /* CONFIG_TDLS */
4262
4263#ifdef CONFIG_INTERWORKING
4264 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4265 payload[0] == QOS_QOS_MAP_CONFIG) {
4266 const u8 *pos = payload + 1;
4267 size_t qlen = plen - 1;
4268 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4269 MACSTR, MAC2STR(mgmt->sa));
4270 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4271 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4272 pos[1] <= qlen - 2 && pos[1] >= 16)
4273 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4274 return;
4275 }
4276#endif /* CONFIG_INTERWORKING */
4277
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004278 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004279 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4280 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004281 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004282 payload + 1,
4283 plen - 1);
4284 return;
4285 }
4286
4287 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004288 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4289 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4290 return;
4291 }
4292
4293 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4294 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4295 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4296 payload + 1, plen - 1,
4297 rssi);
4298 return;
4299 }
4300
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004301#ifdef CONFIG_FST
4302 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4303 fst_rx_action(wpa_s->fst, mgmt, len);
4304 return;
4305 }
4306#endif /* CONFIG_FST */
4307
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004308#ifdef CONFIG_DPP
4309 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4310 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4311 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4312 payload[4] == DPP_OUI_TYPE) {
4313 payload++;
4314 plen--;
4315 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4316 return;
4317 }
4318#endif /* CONFIG_DPP */
4319
Hai Shalom899fcc72020-10-19 14:38:18 -07004320 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
4321 payload[0] == ROBUST_AV_MSCS_RESP) {
4322 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4323 payload + 1, plen - 1);
4324 return;
4325 }
4326
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004327 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4328 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004329 if (wpa_s->ifmsh)
4330 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004331}
4332
4333
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004334static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4335 union wpa_event_data *event)
4336{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004337 struct wpa_freq_range_list *list;
4338 char *str = NULL;
4339
4340 list = &event->freq_range;
4341
4342 if (list->num)
4343 str = freq_range_list_str(list);
4344 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4345 str ? str : "");
4346
4347#ifdef CONFIG_P2P
4348 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4349 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4350 __func__);
4351 } else {
4352 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004353
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004354 /*
4355 * The update channel flow will also take care of moving a GO
4356 * from the unsafe frequency if needed.
4357 */
4358 wpas_p2p_update_channel_list(wpa_s,
4359 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004360 }
4361#endif /* CONFIG_P2P */
4362
4363 os_free(str);
4364}
4365
4366
Roshan Pius3a1667e2018-07-03 15:17:14 -07004367static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004368{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004369 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4370 wpa_supplicant_cancel_auth_timeout(wpa_s);
4371 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004372 eapol_sm_notify_portValid(wpa_s->eapol, true);
4373 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004374 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004375 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004376}
4377
4378
4379static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4380 int freq)
4381{
4382 size_t i;
4383 int j;
4384
4385 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4386 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4387
4388 for (j = 0; j < mode->num_channels; j++) {
4389 const struct hostapd_channel_data *chan;
4390
4391 chan = &mode->channels[j];
4392 if (chan->freq == freq)
4393 return chan->dfs_cac_ms;
4394 }
4395 }
4396
4397 return 0;
4398}
4399
4400
4401static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4402 struct dfs_event *radar)
4403{
4404#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004405 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004406 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4407 } else
4408#endif /* NEED_AP_MLME && CONFIG_AP */
4409 {
4410 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4411
4412 cac_time /= 1000; /* convert from ms to sec */
4413 if (!cac_time)
4414 cac_time = 10 * 60; /* max timeout: 10 minutes */
4415
4416 /* Restart auth timeout: CAC time added to initial timeout */
4417 wpas_auth_timeout_restart(wpa_s, cac_time);
4418 }
4419}
4420
4421
4422static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4423 struct dfs_event *radar)
4424{
4425#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004426 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004427 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4428 } else
4429#endif /* NEED_AP_MLME && CONFIG_AP */
4430 {
4431 /* Restart auth timeout with original value after CAC is
4432 * finished */
4433 wpas_auth_timeout_restart(wpa_s, 0);
4434 }
4435}
4436
4437
4438static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4439 struct dfs_event *radar)
4440{
4441#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004442 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004443 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4444 } else
4445#endif /* NEED_AP_MLME && CONFIG_AP */
4446 {
4447 /* Restart auth timeout with original value after CAC is
4448 * aborted */
4449 wpas_auth_timeout_restart(wpa_s, 0);
4450 }
4451}
4452
4453
4454static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4455 union wpa_event_data *data)
4456{
4457 wpa_dbg(wpa_s, MSG_DEBUG,
4458 "Connection authorized by device, previous state %d",
4459 wpa_s->wpa_state);
4460
4461 wpa_supplicant_event_port_authorized(wpa_s);
4462
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004463 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4464 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004465 data->assoc_info.ptk_kck_len,
4466 data->assoc_info.ptk_kek,
4467 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004468#ifdef CONFIG_FILS
4469 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4470 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4471 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4472
4473 /* Update ERP next sequence number */
4474 eapol_sm_update_erp_next_seq_num(
4475 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4476
4477 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4478 /* Add the new PMK and PMKID to the PMKSA cache */
4479 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4480 data->assoc_info.fils_pmk,
4481 data->assoc_info.fils_pmk_len,
4482 data->assoc_info.fils_pmkid,
4483 wpa_s->bssid, fils_cache_id);
4484 } else if (data->assoc_info.fils_pmkid) {
4485 /* Update the current PMKSA used for this connection */
4486 pmksa_cache_set_current(wpa_s->wpa,
4487 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004488 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004489 }
4490 }
4491#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004492}
4493
4494
Roshan Pius3a1667e2018-07-03 15:17:14 -07004495static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4496 union wpa_event_data *data)
4497{
4498 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004499#ifdef CONFIG_MBO
4500 struct wpa_bss *reject_bss;
4501#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004502
4503 if (!bssid || is_zero_ether_addr(bssid))
4504 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004505#ifdef CONFIG_MBO
4506 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4507 reject_bss = wpa_s->current_bss;
4508 else
4509 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4510#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004511
4512 if (data->assoc_reject.bssid)
4513 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4514 "bssid=" MACSTR " status_code=%u%s%s%s",
4515 MAC2STR(data->assoc_reject.bssid),
4516 data->assoc_reject.status_code,
4517 data->assoc_reject.timed_out ? " timeout" : "",
4518 data->assoc_reject.timeout_reason ? "=" : "",
4519 data->assoc_reject.timeout_reason ?
4520 data->assoc_reject.timeout_reason : "");
4521 else
4522 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4523 "status_code=%u%s%s%s",
4524 data->assoc_reject.status_code,
4525 data->assoc_reject.timed_out ? " timeout" : "",
4526 data->assoc_reject.timeout_reason ? "=" : "",
4527 data->assoc_reject.timeout_reason ?
4528 data->assoc_reject.timeout_reason : "");
4529 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravie06118e2021-01-03 08:39:46 -08004530 wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out,
4531 data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004532
4533#ifdef CONFIG_OWE
4534 if (data->assoc_reject.status_code ==
4535 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4536 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4537 wpa_s->current_ssid &&
4538 wpa_s->current_ssid->owe_group == 0 &&
4539 wpa_s->last_owe_group != 21) {
4540 struct wpa_ssid *ssid = wpa_s->current_ssid;
4541 struct wpa_bss *bss = wpa_s->current_bss;
4542
4543 if (!bss) {
4544 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4545 if (!bss) {
4546 wpas_connection_failed(wpa_s, bssid);
4547 wpa_supplicant_mark_disassoc(wpa_s);
4548 return;
4549 }
4550 }
4551 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4552 wpas_connect_work_done(wpa_s);
4553 wpa_supplicant_mark_disassoc(wpa_s);
4554 wpa_supplicant_connect(wpa_s, bss, ssid);
4555 return;
4556 }
4557#endif /* CONFIG_OWE */
4558
Hai Shalomfdcde762020-04-02 11:19:20 -07004559#ifdef CONFIG_DPP2
4560 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4561 * the status code defined in the DPP R2 tech spec.
4562 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4563 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004564 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004565 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4566 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4567 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004568 wpa_s->current_ssid->dpp_pfs == 0 &&
4569 (data->assoc_reject.status_code ==
4570 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4571 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4572 struct wpa_ssid *ssid = wpa_s->current_ssid;
4573 struct wpa_bss *bss = wpa_s->current_bss;
4574
4575 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4576 if (!bss)
4577 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4578 if (!bss || wpa_s->dpp_pfs_fallback) {
4579 wpa_printf(MSG_DEBUG,
4580 "DPP: Updated PFS policy for next try");
4581 wpas_connection_failed(wpa_s, bssid);
4582 wpa_supplicant_mark_disassoc(wpa_s);
4583 return;
4584 }
4585 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4586 wpa_s->dpp_pfs_fallback = 1;
4587 wpas_connect_work_done(wpa_s);
4588 wpa_supplicant_mark_disassoc(wpa_s);
4589 wpa_supplicant_connect(wpa_s, bss, ssid);
4590 return;
4591 }
4592#endif /* CONFIG_DPP2 */
4593
Hai Shalom74f70d42019-02-11 14:42:39 -08004594#ifdef CONFIG_MBO
4595 if (data->assoc_reject.status_code ==
4596 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004597 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004598 const u8 *rssi_rej;
4599
4600 rssi_rej = mbo_get_attr_from_ies(
4601 data->assoc_reject.resp_ies,
4602 data->assoc_reject.resp_ies_len,
4603 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4604 if (rssi_rej && rssi_rej[1] == 2) {
4605 wpa_printf(MSG_DEBUG,
4606 "OCE: RSSI-based association rejection from "
4607 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004608 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004609 rssi_rej[2], rssi_rej[3]);
4610 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004611 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004612 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004613 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004614 }
4615 }
4616#endif /* CONFIG_MBO */
4617
Roshan Pius3a1667e2018-07-03 15:17:14 -07004618 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4619 sme_event_assoc_reject(wpa_s, data);
4620 return;
4621 }
4622
4623 /* Driver-based SME cases */
4624
4625#ifdef CONFIG_SAE
4626 if (wpa_s->current_ssid &&
4627 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4628 !data->assoc_reject.timed_out) {
4629 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4630 wpa_sm_aborted_cached(wpa_s->wpa);
4631 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4632 }
4633#endif /* CONFIG_SAE */
4634
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004635#ifdef CONFIG_DPP
4636 if (wpa_s->current_ssid &&
4637 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4638 !data->assoc_reject.timed_out) {
4639 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4640 wpa_sm_aborted_cached(wpa_s->wpa);
4641 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4642 }
4643#endif /* CONFIG_DPP */
4644
Roshan Pius3a1667e2018-07-03 15:17:14 -07004645#ifdef CONFIG_FILS
4646 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004647 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004648 eapol_sm_update_erp_next_seq_num(
4649 wpa_s->eapol,
4650 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004651 fils_connection_failure(wpa_s);
4652 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004653#endif /* CONFIG_FILS */
4654
4655 wpas_connection_failed(wpa_s, bssid);
4656 wpa_supplicant_mark_disassoc(wpa_s);
4657}
4658
4659
Hai Shalomfdcde762020-04-02 11:19:20 -07004660static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
4661 struct unprot_beacon *data)
4662{
4663 struct wpabuf *buf;
4664 int res;
4665
4666 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
4667 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
4668 return;
4669 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
4670 MAC2STR(data->sa));
4671
4672 buf = wpabuf_alloc(4);
4673 if (!buf)
4674 return;
4675
4676 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
4677 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
4678 wpabuf_put_u8(buf, 1); /* Dialog Token */
4679 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
4680
4681 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
4682 wpa_s->own_addr, wpa_s->bssid,
4683 wpabuf_head(buf), wpabuf_len(buf), 0);
4684 if (res < 0)
4685 wpa_printf(MSG_DEBUG,
4686 "Failed to send WNM-Notification Request frame");
4687
4688 wpabuf_free(buf);
4689}
4690
4691
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004692void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4693 union wpa_event_data *data)
4694{
4695 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004696 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07004697 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08004698#ifndef CONFIG_NO_STDOUT_DEBUG
4699 int level = MSG_DEBUG;
4700#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004701
4702 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4703 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004704 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004705 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004706 event != EVENT_SCHED_SCAN_STOPPED) {
4707 wpa_dbg(wpa_s, MSG_DEBUG,
4708 "Ignore event %s (%d) while interface is disabled",
4709 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004710 return;
4711 }
4712
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004713#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07004714 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004715 const struct ieee80211_hdr *hdr;
4716 u16 fc;
4717 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4718 fc = le_to_host16(hdr->frame_control);
4719 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4720 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4721 level = MSG_EXCESSIVE;
4722 }
4723
4724 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4725 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004726#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004727
4728 switch (event) {
4729 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004730#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004731 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4732 data->auth.ies_len))
4733 wpa_printf(MSG_DEBUG,
4734 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004735#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004736 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004737 wpa_s->auth_status_code = data->auth.status_code;
4738 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004739 break;
4740 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004741#ifdef CONFIG_TESTING_OPTIONS
4742 if (wpa_s->ignore_auth_resp) {
4743 wpa_printf(MSG_INFO,
4744 "EVENT_ASSOC - ignore_auth_resp active!");
4745 break;
4746 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004747 if (wpa_s->testing_resend_assoc) {
4748 wpa_printf(MSG_INFO,
4749 "EVENT_DEAUTH - testing_resend_assoc");
4750 break;
4751 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004752#endif /* CONFIG_TESTING_OPTIONS */
Vamsi Krishna34812622020-12-03 22:15:29 +05304753 if (wpa_s->disconnected) {
4754 wpa_printf(MSG_INFO,
4755 "Ignore unexpected EVENT_ASSOC in disconnected state");
4756 break;
4757 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004758 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004759 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004760 if (data &&
4761 (data->assoc_info.authorized ||
4762 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4763 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004764 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004765 if (data) {
4766 wpa_msg(wpa_s, MSG_INFO,
4767 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4768 data->assoc_info.subnet_status);
4769 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004770 break;
4771 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004772 wpas_event_disassoc(wpa_s,
4773 data ? &data->disassoc_info : NULL);
4774 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004775 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004776#ifdef CONFIG_TESTING_OPTIONS
4777 if (wpa_s->ignore_auth_resp) {
4778 wpa_printf(MSG_INFO,
4779 "EVENT_DEAUTH - ignore_auth_resp active!");
4780 break;
4781 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004782 if (wpa_s->testing_resend_assoc) {
4783 wpa_printf(MSG_INFO,
4784 "EVENT_DEAUTH - testing_resend_assoc");
4785 break;
4786 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004787#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004788 wpas_event_deauth(wpa_s,
4789 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004790 break;
4791 case EVENT_MICHAEL_MIC_FAILURE:
4792 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4793 break;
4794#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004795 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004796 if (wpa_s->own_scan_requested ||
4797 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004798 struct os_reltime diff;
4799
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004800 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004801 os_reltime_sub(&wpa_s->scan_start_time,
4802 &wpa_s->scan_trigger_time, &diff);
4803 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4804 diff.sec, diff.usec);
4805 wpa_s->own_scan_requested = 0;
4806 wpa_s->own_scan_running = 1;
4807 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4808 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004809 wpa_msg_ctrl(wpa_s, MSG_INFO,
4810 WPA_EVENT_SCAN_STARTED "id=%u",
4811 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004812 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004813 wpa_msg_ctrl(wpa_s, MSG_INFO,
4814 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004815 }
4816 } else {
4817 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004818 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004819 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004820 }
4821 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004822 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004823 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4824 wpa_s->scan_res_handler = NULL;
4825 wpa_s->own_scan_running = 0;
4826 wpa_s->radio->external_scan_running = 0;
4827 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4828 break;
4829 }
4830
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004831 if (!(data && data->scan_info.external_scan) &&
4832 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004833 struct os_reltime now, diff;
4834 os_get_reltime(&now);
4835 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4836 wpa_s->scan_start_time.sec = 0;
4837 wpa_s->scan_start_time.usec = 0;
4838 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4839 diff.sec, diff.usec);
4840 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004841 if (wpa_supplicant_event_scan_results(wpa_s, data))
4842 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004843 if (!(data && data->scan_info.external_scan))
4844 wpa_s->own_scan_running = 0;
4845 if (data && data->scan_info.nl_scan_event)
4846 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004847 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004848 break;
4849#endif /* CONFIG_NO_SCAN_PROCESSING */
4850 case EVENT_ASSOCINFO:
4851 wpa_supplicant_event_associnfo(wpa_s, data);
4852 break;
4853 case EVENT_INTERFACE_STATUS:
4854 wpa_supplicant_event_interface_status(wpa_s, data);
4855 break;
4856 case EVENT_PMKID_CANDIDATE:
4857 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4858 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004859#ifdef CONFIG_TDLS
4860 case EVENT_TDLS:
4861 wpa_supplicant_event_tdls(wpa_s, data);
4862 break;
4863#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004864#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004865 case EVENT_WNM:
4866 wpa_supplicant_event_wnm(wpa_s, data);
4867 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004868#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004869#ifdef CONFIG_IEEE80211R
4870 case EVENT_FT_RESPONSE:
4871 wpa_supplicant_event_ft_response(wpa_s, data);
4872 break;
4873#endif /* CONFIG_IEEE80211R */
4874#ifdef CONFIG_IBSS_RSN
4875 case EVENT_IBSS_RSN_START:
4876 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4877 break;
4878#endif /* CONFIG_IBSS_RSN */
4879 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004880 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004881 break;
4882 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004883 /* It is possible to get this event from earlier connection */
4884 if (wpa_s->current_ssid &&
4885 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4886 wpa_dbg(wpa_s, MSG_DEBUG,
4887 "Ignore AUTH_TIMED_OUT in mesh configuration");
4888 break;
4889 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004890 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4891 sme_event_auth_timed_out(wpa_s, data);
4892 break;
4893 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004894 /* It is possible to get this event from earlier connection */
4895 if (wpa_s->current_ssid &&
4896 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4897 wpa_dbg(wpa_s, MSG_DEBUG,
4898 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4899 break;
4900 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004901 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4902 sme_event_assoc_timed_out(wpa_s, data);
4903 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004904 case EVENT_TX_STATUS:
4905 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4906 " type=%d stype=%d",
4907 MAC2STR(data->tx_status.dst),
4908 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004909#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004910 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004911#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004912 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4913 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004914 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004915 wpa_s, data->tx_status.dst,
4916 data->tx_status.data,
4917 data->tx_status.data_len,
4918 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004919 OFFCHANNEL_SEND_ACTION_SUCCESS :
4920 OFFCHANNEL_SEND_ACTION_NO_ACK);
4921#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004922 break;
4923 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004924#endif /* CONFIG_AP */
4925#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004926 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004927 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004928 /*
4929 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004930 * interface in GO mode, or via standalone AP interface.
4931 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4932 * except when the primary interface is used as a GO interface
4933 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004934 */
4935 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4936 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004937 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004938 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004939 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004940 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004941 data->tx_status.data,
4942 data->tx_status.data_len,
4943 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004944 OFFCHANNEL_SEND_ACTION_SUCCESS :
4945 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004946 break;
4947 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004948#endif /* CONFIG_OFFCHANNEL */
4949#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004950 switch (data->tx_status.type) {
4951 case WLAN_FC_TYPE_MGMT:
4952 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4953 data->tx_status.data_len,
4954 data->tx_status.stype,
4955 data->tx_status.ack);
4956 break;
4957 case WLAN_FC_TYPE_DATA:
4958 ap_tx_status(wpa_s, data->tx_status.dst,
4959 data->tx_status.data,
4960 data->tx_status.data_len,
4961 data->tx_status.ack);
4962 break;
4963 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004964#endif /* CONFIG_AP */
4965 break;
4966#ifdef CONFIG_AP
4967 case EVENT_EAPOL_TX_STATUS:
4968 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4969 data->eapol_tx_status.data,
4970 data->eapol_tx_status.data_len,
4971 data->eapol_tx_status.ack);
4972 break;
4973 case EVENT_DRIVER_CLIENT_POLL_OK:
4974 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004975 break;
4976 case EVENT_RX_FROM_UNKNOWN:
4977 if (wpa_s->ap_iface == NULL)
4978 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004979 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4980 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004981 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004982#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07004983
4984 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07004985 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004986 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004987 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004988
Hai Shalom81f62d82019-07-22 12:10:00 -07004989 wpa_msg(wpa_s, MSG_INFO,
4990 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4991 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
4992 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004993 data->ch_switch.freq,
4994 data->ch_switch.ht_enabled,
4995 data->ch_switch.ch_offset,
4996 channel_width_to_string(data->ch_switch.ch_width),
4997 data->ch_switch.cf1,
4998 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07004999 if (event == EVENT_CH_SWITCH_STARTED)
5000 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07005001
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005002 wpa_s->assoc_freq = data->ch_switch.freq;
5003 wpa_s->current_ssid->frequency = data->ch_switch.freq;
5004
Hai Shalomfdcde762020-04-02 11:19:20 -07005005#ifdef CONFIG_SME
5006 switch (data->ch_switch.ch_offset) {
5007 case 1:
5008 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
5009 break;
5010 case -1:
5011 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
5012 break;
5013 default:
5014 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
5015 break;
5016 }
5017#endif /* CONFIG_SME */
5018
Roshan Pius3a1667e2018-07-03 15:17:14 -07005019#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005020 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
5021 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08005022 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005023 wpa_s->current_ssid->mode ==
5024 WPAS_MODE_P2P_GROUP_FORMATION) {
5025 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
5026 data->ch_switch.ht_enabled,
5027 data->ch_switch.ch_offset,
5028 data->ch_switch.ch_width,
5029 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07005030 data->ch_switch.cf2,
5031 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005032 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07005033#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005034
Hai Shalom899fcc72020-10-19 14:38:18 -07005035 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5036 sme_event_ch_switch(wpa_s);
5037
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005038 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005039 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005040 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005041#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005042#ifdef NEED_AP_MLME
5043 case EVENT_DFS_RADAR_DETECTED:
5044 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07005045 wpas_ap_event_dfs_radar_detected(wpa_s,
5046 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005047 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005048 case EVENT_DFS_NOP_FINISHED:
5049 if (data)
5050 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5051 &data->dfs_event);
5052 break;
5053#endif /* NEED_AP_MLME */
5054#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005055 case EVENT_DFS_CAC_STARTED:
5056 if (data)
5057 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5058 break;
5059 case EVENT_DFS_CAC_FINISHED:
5060 if (data)
5061 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5062 break;
5063 case EVENT_DFS_CAC_ABORTED:
5064 if (data)
5065 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5066 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005067 case EVENT_RX_MGMT: {
5068 u16 fc, stype;
5069 const struct ieee80211_mgmt *mgmt;
5070
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005071#ifdef CONFIG_TESTING_OPTIONS
5072 if (wpa_s->ext_mgmt_frame_handling) {
5073 struct rx_mgmt *rx = &data->rx_mgmt;
5074 size_t hex_len = 2 * rx->frame_len + 1;
5075 char *hex = os_malloc(hex_len);
5076 if (hex) {
5077 wpa_snprintf_hex(hex, hex_len,
5078 rx->frame, rx->frame_len);
5079 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5080 rx->freq, rx->datarate, rx->ssi_signal,
5081 hex);
5082 os_free(hex);
5083 }
5084 break;
5085 }
5086#endif /* CONFIG_TESTING_OPTIONS */
5087
Dmitry Shmidt04949592012-07-19 12:16:46 -07005088 mgmt = (const struct ieee80211_mgmt *)
5089 data->rx_mgmt.frame;
5090 fc = le_to_host16(mgmt->frame_control);
5091 stype = WLAN_FC_GET_STYPE(fc);
5092
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005093#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005094 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005095#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005096#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005097 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005098 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005099 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005100 const u8 *ie;
5101 size_t ie_len;
5102
5103 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5104 ie_len = data->rx_mgmt.frame_len -
5105 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005106 wpas_p2p_probe_req_rx(
5107 wpa_s, src, mgmt->da,
5108 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005109 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005110 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005111 break;
5112 }
5113#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005114#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005115 if (wpa_s->current_ssid &&
5116 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5117 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005118 data->rx_mgmt.frame_len >= 30) {
5119 wpa_supplicant_event_ibss_auth(wpa_s, data);
5120 break;
5121 }
5122#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005123
5124 if (stype == WLAN_FC_STYPE_ACTION) {
5125 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005126 wpa_s, data->rx_mgmt.frame,
5127 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005128 data->rx_mgmt.freq,
5129 data->rx_mgmt.ssi_signal);
5130 break;
5131 }
5132
5133 if (wpa_s->ifmsh) {
5134 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005135 break;
5136 }
5137
Roshan Pius3a1667e2018-07-03 15:17:14 -07005138#ifdef CONFIG_SAE
5139 if (stype == WLAN_FC_STYPE_AUTH &&
5140 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5141 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5142 sme_external_auth_mgmt_rx(
5143 wpa_s, data->rx_mgmt.frame,
5144 data->rx_mgmt.frame_len);
5145 break;
5146 }
5147#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005148 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5149 "management frame in non-AP mode");
5150 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005151#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005152 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005153
5154 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005155 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5156 const u8 *ie;
5157 size_t ie_len;
5158
5159 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5160 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005161
5162 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5163 mgmt->bssid, ie, ie_len,
5164 data->rx_mgmt.ssi_signal);
5165 }
5166
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005167 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005168#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005169 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005170 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005171 case EVENT_RX_PROBE_REQ:
5172 if (data->rx_probe_req.sa == NULL ||
5173 data->rx_probe_req.ie == NULL)
5174 break;
5175#ifdef CONFIG_AP
5176 if (wpa_s->ap_iface) {
5177 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5178 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005179 data->rx_probe_req.da,
5180 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005181 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005182 data->rx_probe_req.ie_len,
5183 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005184 break;
5185 }
5186#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005187 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005188 data->rx_probe_req.da,
5189 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005190 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005191 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005192 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005193 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005194 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005195 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005196#ifdef CONFIG_OFFCHANNEL
5197 offchannel_remain_on_channel_cb(
5198 wpa_s, data->remain_on_channel.freq,
5199 data->remain_on_channel.duration);
5200#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005201 wpas_p2p_remain_on_channel_cb(
5202 wpa_s, data->remain_on_channel.freq,
5203 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005204#ifdef CONFIG_DPP
5205 wpas_dpp_remain_on_channel_cb(
5206 wpa_s, data->remain_on_channel.freq,
5207 data->remain_on_channel.duration);
5208#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005209 break;
5210 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005211#ifdef CONFIG_OFFCHANNEL
5212 offchannel_cancel_remain_on_channel_cb(
5213 wpa_s, data->remain_on_channel.freq);
5214#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005215 wpas_p2p_cancel_remain_on_channel_cb(
5216 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005217#ifdef CONFIG_DPP
5218 wpas_dpp_cancel_remain_on_channel_cb(
5219 wpa_s, data->remain_on_channel.freq);
5220#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005221 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005222 case EVENT_EAPOL_RX:
5223 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5224 data->eapol_rx.data,
5225 data->eapol_rx.data_len);
5226 break;
5227 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005228 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5229 "above=%d signal=%d noise=%d txrate=%d",
5230 data->signal_change.above_threshold,
5231 data->signal_change.current_signal,
5232 data->signal_change.current_noise,
5233 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005234 wpa_bss_update_level(wpa_s->current_bss,
5235 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005236 bgscan_notify_signal_change(
5237 wpa_s, data->signal_change.above_threshold,
5238 data->signal_change.current_signal,
5239 data->signal_change.current_noise,
5240 data->signal_change.current_txrate);
5241 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005242 case EVENT_INTERFACE_MAC_CHANGED:
5243 wpa_supplicant_update_mac_addr(wpa_s);
5244 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005245 case EVENT_INTERFACE_ENABLED:
5246 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5247 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomfdcde762020-04-02 11:19:20 -07005248 eloop_cancel_timeout(wpas_clear_disabled_interface,
5249 wpa_s, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005250 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07005251 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005252 if (wpa_s->p2p_mgmt) {
5253 wpa_supplicant_set_state(wpa_s,
5254 WPA_DISCONNECTED);
5255 break;
5256 }
5257
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005258#ifdef CONFIG_AP
5259 if (!wpa_s->ap_iface) {
5260 wpa_supplicant_set_state(wpa_s,
5261 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005262 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005263 wpa_supplicant_req_scan(wpa_s, 0, 0);
5264 } else
5265 wpa_supplicant_set_state(wpa_s,
5266 WPA_COMPLETED);
5267#else /* CONFIG_AP */
5268 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5269 wpa_supplicant_req_scan(wpa_s, 0, 0);
5270#endif /* CONFIG_AP */
5271 }
5272 break;
5273 case EVENT_INTERFACE_DISABLED:
5274 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005275#ifdef CONFIG_P2P
5276 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5277 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5278 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5279 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005280 * Mark interface disabled if this happens to end up not
5281 * being removed as a separate P2P group interface.
5282 */
5283 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5284 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005285 * The interface was externally disabled. Remove
5286 * it assuming an external entity will start a
5287 * new session if needed.
5288 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005289 if (wpa_s->current_ssid &&
5290 wpa_s->current_ssid->p2p_group)
5291 wpas_p2p_interface_unavailable(wpa_s);
5292 else
5293 wpas_p2p_disconnect(wpa_s);
5294 /*
5295 * wpa_s instance may have been freed, so must not use
5296 * it here anymore.
5297 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005298 break;
5299 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005300 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5301 p2p_in_progress(wpa_s->global->p2p) > 1) {
5302 /* This radio work will be cancelled, so clear P2P
5303 * state as well.
5304 */
5305 p2p_stop_find(wpa_s->global->p2p);
5306 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005307#endif /* CONFIG_P2P */
5308
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005309 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5310 /*
5311 * Indicate disconnection to keep ctrl_iface events
5312 * consistent.
5313 */
5314 wpa_supplicant_event_disassoc(
5315 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5316 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005317 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005318 os_reltime_age(&wpa_s->last_scan, &age);
5319 if (age.sec >= SCAN_RES_VALID_FOR_CONNECT) {
5320 clear_at.sec = SCAN_RES_VALID_FOR_CONNECT;
5321 clear_at.usec = 0;
5322 } else {
5323 struct os_reltime tmp;
5324
5325 tmp.sec = SCAN_RES_VALID_FOR_CONNECT;
5326 tmp.usec = 0;
5327 os_reltime_sub(&tmp, &age, &clear_at);
5328 }
5329 eloop_register_timeout(clear_at.sec, clear_at.usec,
5330 wpas_clear_disabled_interface,
5331 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005332 radio_remove_works(wpa_s, NULL, 0);
5333
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005334 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5335 break;
5336 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005337 wpa_supplicant_update_channel_list(
5338 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005339 break;
5340 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005341 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005342 break;
5343 case EVENT_BEST_CHANNEL:
5344 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5345 "(%d %d %d)",
5346 data->best_chan.freq_24, data->best_chan.freq_5,
5347 data->best_chan.freq_overall);
5348 wpa_s->best_24_freq = data->best_chan.freq_24;
5349 wpa_s->best_5_freq = data->best_chan.freq_5;
5350 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005351 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5352 data->best_chan.freq_5,
5353 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005354 break;
5355 case EVENT_UNPROT_DEAUTH:
5356 wpa_supplicant_event_unprot_deauth(wpa_s,
5357 &data->unprot_deauth);
5358 break;
5359 case EVENT_UNPROT_DISASSOC:
5360 wpa_supplicant_event_unprot_disassoc(wpa_s,
5361 &data->unprot_disassoc);
5362 break;
5363 case EVENT_STATION_LOW_ACK:
5364#ifdef CONFIG_AP
5365 if (wpa_s->ap_iface && data)
5366 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5367 data->low_ack.addr);
5368#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005369#ifdef CONFIG_TDLS
5370 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005371 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5372 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005373#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005374 break;
5375 case EVENT_IBSS_PEER_LOST:
5376#ifdef CONFIG_IBSS_RSN
5377 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5378#endif /* CONFIG_IBSS_RSN */
5379 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005380 case EVENT_DRIVER_GTK_REKEY:
5381 if (os_memcmp(data->driver_gtk_rekey.bssid,
5382 wpa_s->bssid, ETH_ALEN))
5383 break;
5384 if (!wpa_s->wpa)
5385 break;
5386 wpa_sm_update_replay_ctr(wpa_s->wpa,
5387 data->driver_gtk_rekey.replay_ctr);
5388 break;
5389 case EVENT_SCHED_SCAN_STOPPED:
5390 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005391 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005392 wpa_supplicant_notify_scanning(wpa_s, 0);
5393
5394 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5395 break;
5396
5397 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005398 * If the driver stopped scanning without being requested to,
5399 * request a new scan to continue scanning for networks.
5400 */
5401 if (!wpa_s->sched_scan_stop_req &&
5402 wpa_s->wpa_state == WPA_SCANNING) {
5403 wpa_dbg(wpa_s, MSG_DEBUG,
5404 "Restart scanning after unexpected sched_scan stop event");
5405 wpa_supplicant_req_scan(wpa_s, 1, 0);
5406 break;
5407 }
5408
5409 wpa_s->sched_scan_stop_req = 0;
5410
5411 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005412 * Start a new sched scan to continue searching for more SSIDs
5413 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005414 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005415 if (wpa_s->sched_scan_timed_out) {
5416 wpa_supplicant_req_sched_scan(wpa_s);
5417 } else if (wpa_s->pno_sched_pending) {
5418 wpa_s->pno_sched_pending = 0;
5419 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005420 } else if (resched) {
5421 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005422 }
5423
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005424 break;
5425 case EVENT_WPS_BUTTON_PUSHED:
5426#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005427 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005428#endif /* CONFIG_WPS */
5429 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005430 case EVENT_AVOID_FREQUENCIES:
5431 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5432 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005433 case EVENT_CONNECT_FAILED_REASON:
5434#ifdef CONFIG_AP
5435 if (!wpa_s->ap_iface || !data)
5436 break;
5437 hostapd_event_connect_failed_reason(
5438 wpa_s->ap_iface->bss[0],
5439 data->connect_failed_reason.addr,
5440 data->connect_failed_reason.code);
5441#endif /* CONFIG_AP */
5442 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005443 case EVENT_NEW_PEER_CANDIDATE:
5444#ifdef CONFIG_MESH
5445 if (!wpa_s->ifmsh || !data)
5446 break;
5447 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5448 data->mesh_peer.ies,
5449 data->mesh_peer.ie_len);
5450#endif /* CONFIG_MESH */
5451 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005452 case EVENT_SURVEY:
5453#ifdef CONFIG_AP
5454 if (!wpa_s->ap_iface)
5455 break;
5456 hostapd_event_get_survey(wpa_s->ap_iface,
5457 &data->survey_results);
5458#endif /* CONFIG_AP */
5459 break;
5460 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005461#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005462#ifdef CONFIG_ACS
5463 if (!wpa_s->ap_iface)
5464 break;
5465 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5466 &data->acs_selected_channels);
5467#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005468#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005469 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005470 case EVENT_P2P_LO_STOP:
5471#ifdef CONFIG_P2P
5472 wpa_s->p2p_lo_started = 0;
5473 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5474 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5475 data->p2p_lo_stop.reason_code);
5476#endif /* CONFIG_P2P */
5477 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005478 case EVENT_BEACON_LOSS:
5479 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5480 break;
5481 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5482 bgscan_notify_beacon_loss(wpa_s);
5483 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005484 case EVENT_EXTERNAL_AUTH:
5485#ifdef CONFIG_SAE
5486 if (!wpa_s->current_ssid) {
5487 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5488 break;
5489 }
5490 sme_external_auth_trigger(wpa_s, data);
5491#endif /* CONFIG_SAE */
5492 break;
5493 case EVENT_PORT_AUTHORIZED:
5494 wpa_supplicant_event_port_authorized(wpa_s);
5495 break;
5496 case EVENT_STATION_OPMODE_CHANGED:
5497#ifdef CONFIG_AP
5498 if (!wpa_s->ap_iface || !data)
5499 break;
5500
5501 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5502 data->sta_opmode.addr,
5503 data->sta_opmode.smps_mode,
5504 data->sta_opmode.chan_width,
5505 data->sta_opmode.rx_nss);
5506#endif /* CONFIG_AP */
5507 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005508 case EVENT_UNPROT_BEACON:
5509 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5510 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005511 default:
5512 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5513 break;
5514 }
5515}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005516
5517
5518void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5519 union wpa_event_data *data)
5520{
5521 struct wpa_supplicant *wpa_s;
5522
5523 if (event != EVENT_INTERFACE_STATUS)
5524 return;
5525
5526 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5527 if (wpa_s && wpa_s->driver->get_ifindex) {
5528 unsigned int ifindex;
5529
5530 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5531 if (ifindex != data->interface_status.ifindex) {
5532 wpa_dbg(wpa_s, MSG_DEBUG,
5533 "interface status ifindex %d mismatch (%d)",
5534 ifindex, data->interface_status.ifindex);
5535 return;
5536 }
5537 }
5538#ifdef CONFIG_MATCH_IFACE
5539 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5540 struct wpa_interface *wpa_i;
5541
5542 wpa_i = wpa_supplicant_match_iface(
5543 ctx, data->interface_status.ifname);
5544 if (!wpa_i)
5545 return;
5546 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5547 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07005548 }
5549#endif /* CONFIG_MATCH_IFACE */
5550
5551 if (wpa_s)
5552 wpa_supplicant_event(wpa_s, event, data);
5553}