blob: fd4511d16e989ba2bf0def7b40bd2e56aa93da39 [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"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070052
53
Hai Shalom39ba6fc2019-01-22 12:40:38 -080054#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
55
56
Dmitry Shmidt34af3062013-07-11 10:46:32 -070057#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070058static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080059 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070060#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080061
62
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070063int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070064{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080065 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066
67 if (ssid == NULL || ssid->disabled_until.sec == 0)
68 return 0;
69
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080070 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070071 if (ssid->disabled_until.sec > now.sec)
72 return ssid->disabled_until.sec - now.sec;
73
74 wpas_clear_temp_disabled(wpa_s, ssid, 0);
75
76 return 0;
77}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070078
79
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080080#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070081/**
82 * wpas_reenabled_network_time - Time until first network is re-enabled
83 * @wpa_s: Pointer to wpa_supplicant data
84 * Returns: If all enabled networks are temporarily disabled, returns the time
85 * (in sec) until the first network is re-enabled. Otherwise returns 0.
86 *
87 * This function is used in case all enabled networks are temporarily disabled,
88 * in which case it returns the time (in sec) that the first network will be
89 * re-enabled. The function assumes that at least one network is enabled.
90 */
91static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
92{
93 struct wpa_ssid *ssid;
94 int disabled_for, res = 0;
95
96#ifdef CONFIG_INTERWORKING
97 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
98 wpa_s->conf->cred)
99 return 0;
100#endif /* CONFIG_INTERWORKING */
101
102 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
103 if (ssid->disabled)
104 continue;
105
106 disabled_for = wpas_temp_disabled(wpa_s, ssid);
107 if (!disabled_for)
108 return 0;
109
110 if (!res || disabled_for < res)
111 res = disabled_for;
112 }
113
114 return res;
115}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800116#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700117
118
119void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
120{
121 struct wpa_supplicant *wpa_s = eloop_ctx;
122
123 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
124 return;
125
126 wpa_dbg(wpa_s, MSG_DEBUG,
127 "Try to associate due to network getting re-enabled");
128 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
129 wpa_supplicant_cancel_sched_scan(wpa_s);
130 wpa_supplicant_req_scan(wpa_s, 0, 0);
131 }
132}
133
134
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800135static struct wpa_bss * wpa_supplicant_get_new_bss(
136 struct wpa_supplicant *wpa_s, const u8 *bssid)
137{
138 struct wpa_bss *bss = NULL;
139 struct wpa_ssid *ssid = wpa_s->current_ssid;
140
141 if (ssid->ssid_len > 0)
142 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
143 if (!bss)
144 bss = wpa_bss_get_bssid(wpa_s, bssid);
145
146 return bss;
147}
148
149
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700150static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
151{
152 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
153
154 if (!bss) {
155 wpa_supplicant_update_scan_results(wpa_s);
156
157 /* Get the BSS from the new scan results */
158 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
159 }
160
161 if (bss)
162 wpa_s->current_bss = bss;
163}
164
165
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700166static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
167{
168 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700169 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700170 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700171 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700173 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
174 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700175
176 if (wpa_s->current_ssid->ssid_len == 0)
177 return 0; /* current profile still in use */
178 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
179 if (res < 0) {
180 wpa_msg(wpa_s, MSG_INFO,
181 "Failed to read SSID from driver");
182 return 0; /* try to use current profile */
183 }
184 drv_ssid_len = res;
185
186 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
187 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
188 drv_ssid_len) == 0)
189 return 0; /* current profile still in use */
190
Hai Shalomfdcde762020-04-02 11:19:20 -0700191#ifdef CONFIG_OWE
192 if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
193 wpa_s->current_bss &&
194 (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
195 drv_ssid_len == wpa_s->current_bss->ssid_len &&
196 os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
197 drv_ssid_len) == 0)
198 return 0; /* current profile still in use */
199#endif /* CONFIG_OWE */
200
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700201 wpa_msg(wpa_s, MSG_DEBUG,
202 "Driver-initiated BSS selection changed the SSID to %s",
203 wpa_ssid_txt(drv_ssid, drv_ssid_len));
204 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700205 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700206
207 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
208 "information");
209 ssid = wpa_supplicant_get_ssid(wpa_s);
210 if (ssid == NULL) {
211 wpa_msg(wpa_s, MSG_INFO,
212 "No network configuration found for the current AP");
213 return -1;
214 }
215
Dmitry Shmidt04949592012-07-19 12:16:46 -0700216 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700217 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
218 return -1;
219 }
220
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800221 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
222 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
223 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
224 return -1;
225 }
226
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700227 res = wpas_temp_disabled(wpa_s, ssid);
228 if (res > 0) {
229 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
230 "disabled for %d second(s)", res);
231 return -1;
232 }
233
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700234 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
235 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800236 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237 u8 wpa_ie[80];
238 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800239 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
240 wpa_ie, &wpa_ie_len) < 0)
241 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242 } else {
243 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
244 }
245
246 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
247 eapol_sm_invalidate_cached_session(wpa_s->eapol);
248 old_ssid = wpa_s->current_ssid;
249 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800250
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700251 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800252
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
254 wpa_supplicant_initiate_eapol(wpa_s);
255 if (old_ssid != wpa_s->current_ssid)
256 wpas_notify_network_changed(wpa_s);
257
258 return 0;
259}
260
261
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800262void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700263{
264 struct wpa_supplicant *wpa_s = eloop_ctx;
265
266 if (wpa_s->countermeasures) {
267 wpa_s->countermeasures = 0;
268 wpa_drv_set_countermeasures(wpa_s, 0);
269 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800270
271 /*
272 * It is possible that the device is sched scanning, which means
273 * that a connection attempt will be done only when we receive
274 * scan results. However, in this case, it would be preferable
275 * to scan and connect immediately, so cancel the sched_scan and
276 * issue a regular scan flow.
277 */
278 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700279 wpa_supplicant_req_scan(wpa_s, 0, 0);
280 }
281}
282
283
284void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
285{
286 int bssid_changed;
287
Dmitry Shmidt04949592012-07-19 12:16:46 -0700288 wnm_bss_keep_alive_deinit(wpa_s);
289
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700290#ifdef CONFIG_IBSS_RSN
291 ibss_rsn_deinit(wpa_s->ibss_rsn);
292 wpa_s->ibss_rsn = NULL;
293#endif /* CONFIG_IBSS_RSN */
294
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700295#ifdef CONFIG_AP
296 wpa_supplicant_ap_deinit(wpa_s);
297#endif /* CONFIG_AP */
298
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700299#ifdef CONFIG_HS20
300 /* Clear possibly configured frame filters */
301 wpa_drv_configure_frame_filters(wpa_s, 0);
302#endif /* CONFIG_HS20 */
303
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
305 return;
306
Hai Shalom74f70d42019-02-11 14:42:39 -0800307 if (os_reltime_initialized(&wpa_s->session_start)) {
308 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
309 wpa_s->session_start.sec = 0;
310 wpa_s->session_start.usec = 0;
311 wpas_notify_session_length(wpa_s);
312 }
313
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
315 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
316 os_memset(wpa_s->bssid, 0, ETH_ALEN);
317 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800318 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 wpa_s->current_bss = NULL;
320 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700321
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700322 if (bssid_changed)
323 wpas_notify_bssid_changed(wpa_s);
324
Hai Shalome21d4e82020-04-29 16:34:06 -0700325 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
326 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700327 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
328 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700329 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -0700330 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Hai Shalomc3565922019-10-28 11:58:20 -0700331 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700333 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700334 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700335 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800336
337 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800338 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800339 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700340 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700341
342#ifdef CONFIG_TESTING_OPTIONS
343 wpa_s->last_tk_alg = WPA_ALG_NONE;
344 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
345#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700346 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800347
348 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
349 wpa_s->enabled_4addr_mode = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700350}
351
352
353static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
354{
355 struct wpa_ie_data ie;
356 int pmksa_set = -1;
357 size_t i;
358
Hai Shalom899fcc72020-10-19 14:38:18 -0700359 /* Start with assumption of no PMKSA cache entry match */
360 pmksa_cache_clear_current(wpa_s->wpa);
361
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700362 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
363 ie.pmkid == NULL)
364 return;
365
366 for (i = 0; i < ie.num_pmkid; i++) {
367 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
368 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700369 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700370 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800371 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700372 break;
373 }
374 }
375
376 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
377 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
378}
379
380
381static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
382 union wpa_event_data *data)
383{
384 if (data == NULL) {
385 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
386 "event");
387 return;
388 }
389 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
390 " index=%d preauth=%d",
391 MAC2STR(data->pmkid_candidate.bssid),
392 data->pmkid_candidate.index,
393 data->pmkid_candidate.preauth);
394
395 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
396 data->pmkid_candidate.index,
397 data->pmkid_candidate.preauth);
398}
399
400
401static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
402{
403 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
404 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
405 return 0;
406
407#ifdef IEEE8021X_EAPOL
408 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
409 wpa_s->current_ssid &&
410 !(wpa_s->current_ssid->eapol_flags &
411 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
412 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
413 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
414 * plaintext or static WEP keys). */
415 return 0;
416 }
417#endif /* IEEE8021X_EAPOL */
418
419 return 1;
420}
421
422
423/**
424 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
425 * @wpa_s: pointer to wpa_supplicant data
426 * @ssid: Configuration data for the network
427 * Returns: 0 on success, -1 on failure
428 *
429 * This function is called when starting authentication with a network that is
430 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
431 */
432int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
433 struct wpa_ssid *ssid)
434{
435#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800436#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700437 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700439 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
440 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441 return 0;
442
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700443 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444 sim = 1;
445 aka = 1;
446 } else {
447 struct eap_method_type *eap = ssid->eap.eap_methods;
448 while (eap->vendor != EAP_VENDOR_IETF ||
449 eap->method != EAP_TYPE_NONE) {
450 if (eap->vendor == EAP_VENDOR_IETF) {
451 if (eap->method == EAP_TYPE_SIM)
452 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700453 else if (eap->method == EAP_TYPE_AKA ||
454 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700455 aka = 1;
456 }
457 eap++;
458 }
459 }
460
461 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
462 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700463 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
464 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
465 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 aka = 0;
467
468 if (!sim && !aka) {
469 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
470 "use SIM, but neither EAP-SIM nor EAP-AKA are "
471 "enabled");
472 return 0;
473 }
474
475 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
476 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700478 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479 if (wpa_s->scard == NULL) {
480 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
481 "(pcsc-lite)");
482 return -1;
483 }
484 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
485 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800486#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487#endif /* IEEE8021X_EAPOL */
488
489 return 0;
490}
491
492
493#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700494
Hai Shalomfdcde762020-04-02 11:19:20 -0700495#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700496static int has_wep_key(struct wpa_ssid *ssid)
497{
498 int i;
499
500 for (i = 0; i < NUM_WEP_KEYS; i++) {
501 if (ssid->wep_key_len[i])
502 return 1;
503 }
504
505 return 0;
506}
Hai Shalomfdcde762020-04-02 11:19:20 -0700507#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700508
509
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700510static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511 struct wpa_ssid *ssid)
512{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700513 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514
515 if (ssid->mixed_cell)
516 return 1;
517
518#ifdef CONFIG_WPS
519 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
520 return 1;
521#endif /* CONFIG_WPS */
522
Roshan Pius3a1667e2018-07-03 15:17:14 -0700523#ifdef CONFIG_OWE
524 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
525 return 1;
526#endif /* CONFIG_OWE */
527
Hai Shalomfdcde762020-04-02 11:19:20 -0700528#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700529 if (has_wep_key(ssid))
530 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700531#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700532
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700533#ifdef IEEE8021X_EAPOL
534 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
535 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
536 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
537 privacy = 1;
538#endif /* IEEE8021X_EAPOL */
539
Jouni Malinen75ecf522011-06-27 15:19:46 -0700540 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
541 privacy = 1;
542
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800543 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
544 privacy = 1;
545
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546 if (bss->caps & IEEE80211_CAP_PRIVACY)
547 return privacy;
548 return !privacy;
549}
550
551
552static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
553 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800554 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555{
556 struct wpa_ie_data ie;
557 int proto_match = 0;
558 const u8 *rsn_ie, *wpa_ie;
559 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700560#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700561 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700562#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563
564 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
565 if (ret >= 0)
566 return ret;
567
Hai Shalomfdcde762020-04-02 11:19:20 -0700568#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700569 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
570 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
571 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
572 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
573 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700574#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700576 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700577 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700578 proto_match++;
579
580 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800581 if (debug_print)
582 wpa_dbg(wpa_s, MSG_DEBUG,
583 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 break;
585 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700586 if (!ie.has_pairwise)
587 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
588 if (!ie.has_group)
589 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700590
Hai Shalomfdcde762020-04-02 11:19:20 -0700591#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 if (wep_ok &&
593 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
594 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800595 if (debug_print)
596 wpa_dbg(wpa_s, MSG_DEBUG,
597 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598 return 1;
599 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700600#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700601
Roshan Pius3a1667e2018-07-03 15:17:14 -0700602 if (!(ie.proto & ssid->proto) &&
603 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800604 if (debug_print)
605 wpa_dbg(wpa_s, MSG_DEBUG,
606 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700607 break;
608 }
609
610 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800611 if (debug_print)
612 wpa_dbg(wpa_s, MSG_DEBUG,
613 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614 break;
615 }
616
617 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800618 if (debug_print)
619 wpa_dbg(wpa_s, MSG_DEBUG,
620 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621 break;
622 }
623
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700624 if (ssid->group_mgmt_cipher &&
625 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
626 if (debug_print)
627 wpa_dbg(wpa_s, MSG_DEBUG,
628 " skip RSN IE - group mgmt cipher mismatch");
629 break;
630 }
631
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700632 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800633 if (debug_print)
634 wpa_dbg(wpa_s, MSG_DEBUG,
635 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636 break;
637 }
638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800640 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800641 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800642 if (debug_print)
643 wpa_dbg(wpa_s, MSG_DEBUG,
644 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645 break;
646 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800647 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
648 wpas_get_ssid_pmf(wpa_s, ssid) ==
649 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800650 if (debug_print)
651 wpa_dbg(wpa_s, MSG_DEBUG,
652 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800653 break;
654 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700655
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800656 if (debug_print)
657 wpa_dbg(wpa_s, MSG_DEBUG,
658 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700659 return 1;
660 }
661
Roshan Pius3a1667e2018-07-03 15:17:14 -0700662 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
663 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800664 if (debug_print)
665 wpa_dbg(wpa_s, MSG_DEBUG,
666 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700667 return 0;
668 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700669
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700670 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
672 proto_match++;
673
674 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800675 if (debug_print)
676 wpa_dbg(wpa_s, MSG_DEBUG,
677 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678 break;
679 }
680
Hai Shalomfdcde762020-04-02 11:19:20 -0700681#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682 if (wep_ok &&
683 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
684 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800685 if (debug_print)
686 wpa_dbg(wpa_s, MSG_DEBUG,
687 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700688 return 1;
689 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700690#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691
692 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800693 if (debug_print)
694 wpa_dbg(wpa_s, MSG_DEBUG,
695 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696 break;
697 }
698
699 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800700 if (debug_print)
701 wpa_dbg(wpa_s, MSG_DEBUG,
702 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 break;
704 }
705
706 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800707 if (debug_print)
708 wpa_dbg(wpa_s, MSG_DEBUG,
709 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710 break;
711 }
712
713 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800714 if (debug_print)
715 wpa_dbg(wpa_s, MSG_DEBUG,
716 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 break;
718 }
719
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800720 if (debug_print)
721 wpa_dbg(wpa_s, MSG_DEBUG,
722 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723 return 1;
724 }
725
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700726 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
727 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800728 if (debug_print)
729 wpa_dbg(wpa_s, MSG_DEBUG,
730 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700731 return 1;
732 }
733
Roshan Pius3a1667e2018-07-03 15:17:14 -0700734#ifdef CONFIG_OWE
735 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
736 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800737 if (wpa_s->owe_transition_select &&
738 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
739 ssid->owe_transition_bss_select_count + 1 <=
740 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
741 ssid->owe_transition_bss_select_count++;
742 if (debug_print)
743 wpa_dbg(wpa_s, MSG_DEBUG,
744 " skip OWE transition BSS (selection count %d does not exceed %d)",
745 ssid->owe_transition_bss_select_count,
746 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
747 wpa_s->owe_transition_search = 1;
748 return 0;
749 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700750 if (debug_print)
751 wpa_dbg(wpa_s, MSG_DEBUG,
752 " allow in OWE transition mode");
753 return 1;
754 }
755#endif /* CONFIG_OWE */
756
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
758 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800759 if (debug_print)
760 wpa_dbg(wpa_s, MSG_DEBUG,
761 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 return 0;
763 }
764
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800765 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
766 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800767 if (debug_print)
768 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800769 return 1;
770 }
771
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700772 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800773 if (debug_print)
774 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775 return 1;
776 }
777
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800778 if (debug_print)
779 wpa_dbg(wpa_s, MSG_DEBUG,
780 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781
782 return 0;
783}
784
785
786static int freq_allowed(int *freqs, int freq)
787{
788 int i;
789
790 if (freqs == NULL)
791 return 1;
792
793 for (i = 0; freqs[i]; i++)
794 if (freqs[i] == freq)
795 return 1;
796 return 0;
797}
798
799
Hai Shalomfdcde762020-04-02 11:19:20 -0700800static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
801 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800802{
803 const struct hostapd_hw_modes *mode = NULL, *modes;
804 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
805 const u8 *rate_ie;
806 int i, j, k;
807
808 if (bss->freq == 0)
809 return 1; /* Cannot do matching without knowing band */
810
811 modes = wpa_s->hw.modes;
812 if (modes == NULL) {
813 /*
814 * The driver does not provide any additional information
815 * about the utilized hardware, so allow the connection attempt
816 * to continue.
817 */
818 return 1;
819 }
820
821 for (i = 0; i < wpa_s->hw.num_modes; i++) {
822 for (j = 0; j < modes[i].num_channels; j++) {
823 int freq = modes[i].channels[j].freq;
824 if (freq == bss->freq) {
825 if (mode &&
826 mode->mode == HOSTAPD_MODE_IEEE80211G)
827 break; /* do not allow 802.11b replace
828 * 802.11g */
829 mode = &modes[i];
830 break;
831 }
832 }
833 }
834
835 if (mode == NULL)
836 return 0;
837
838 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700839 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800840 if (rate_ie == NULL)
841 continue;
842
843 for (j = 2; j < rate_ie[1] + 2; j++) {
844 int flagged = !!(rate_ie[j] & 0x80);
845 int r = (rate_ie[j] & 0x7f) * 5;
846
847 /*
848 * IEEE Std 802.11n-2009 7.3.2.2:
849 * The new BSS Membership selector value is encoded
850 * like a legacy basic rate, but it is not a rate and
851 * only indicates if the BSS members are required to
852 * support the mandatory features of Clause 20 [HT PHY]
853 * in order to join the BSS.
854 */
855 if (flagged && ((rate_ie[j] & 0x7f) ==
856 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
857 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800858 if (debug_print)
859 wpa_dbg(wpa_s, MSG_DEBUG,
860 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800861 return 0;
862 }
863 continue;
864 }
865
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700866 /* There's also a VHT selector for 802.11ac */
867 if (flagged && ((rate_ie[j] & 0x7f) ==
868 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
869 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800870 if (debug_print)
871 wpa_dbg(wpa_s, MSG_DEBUG,
872 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700873 return 0;
874 }
875 continue;
876 }
877
Hai Shalomc3565922019-10-28 11:58:20 -0700878#ifdef CONFIG_SAE
879 if (flagged && ((rate_ie[j] & 0x7f) ==
880 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700881 if (wpa_s->conf->sae_pwe == 0 &&
882 !ssid->sae_password_id &&
883 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700884 if (debug_print)
885 wpa_dbg(wpa_s, MSG_DEBUG,
886 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800887#ifdef CONFIG_TESTING_OPTIONS
888 if (wpa_s->ignore_sae_h2e_only) {
889 wpa_dbg(wpa_s, MSG_DEBUG,
890 "TESTING: Ignore SAE H2E requirement mismatch");
891 continue;
892 }
893#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700894 return 0;
895 }
896 continue;
897 }
898#endif /* CONFIG_SAE */
899
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800900 if (!flagged)
901 continue;
902
903 /* check for legacy basic rates */
904 for (k = 0; k < mode->num_rates; k++) {
905 if (mode->rates[k] == r)
906 break;
907 }
908 if (k == mode->num_rates) {
909 /*
910 * IEEE Std 802.11-2007 7.3.2.2 demands that in
911 * order to join a BSS all required rates
912 * have to be supported by the hardware.
913 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800914 if (debug_print)
915 wpa_dbg(wpa_s, MSG_DEBUG,
916 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
917 r / 10, r % 10,
918 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800919 return 0;
920 }
921 }
922 }
923
924 return 1;
925}
926
927
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800928/*
929 * Test whether BSS is in an ESS.
930 * This is done differently in DMG (60 GHz) and non-DMG bands
931 */
932static int bss_is_ess(struct wpa_bss *bss)
933{
934 if (bss_is_dmg(bss)) {
935 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
936 IEEE80211_CAP_DMG_AP;
937 }
938
939 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
940 IEEE80211_CAP_ESS);
941}
942
943
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800944static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
945{
946 size_t i;
947
948 for (i = 0; i < ETH_ALEN; i++) {
949 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
950 return 0;
951 }
952 return 1;
953}
954
955
956static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
957{
958 size_t i;
959
960 for (i = 0; i < num; i++) {
961 const u8 *a = list + i * ETH_ALEN * 2;
962 const u8 *m = a + ETH_ALEN;
963
964 if (match_mac_mask(a, addr, m))
965 return 1;
966 }
967 return 0;
968}
969
970
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700971static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
972 const u8 **ret_ssid, size_t *ret_ssid_len)
973{
974#ifdef CONFIG_OWE
975 const u8 *owe, *pos, *end, *bssid;
976 u8 ssid_len;
977 struct wpa_bss *open_bss;
978
979 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
980 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
981 return;
982
983 pos = owe + 6;
984 end = owe + 2 + owe[1];
985
986 if (end - pos < ETH_ALEN + 1)
987 return;
988 bssid = pos;
989 pos += ETH_ALEN;
990 ssid_len = *pos++;
991 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
992 return;
993
994 /* Match the profile SSID against the OWE transition mode SSID on the
995 * open network. */
996 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
997 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
998 *ret_ssid = pos;
999 *ret_ssid_len = ssid_len;
1000
Hai Shalomfdcde762020-04-02 11:19:20 -07001001 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1002 struct wpa_ssid *ssid;
1003
1004 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1005 if (wpas_network_disabled(wpa_s, ssid))
1006 continue;
1007 if (ssid->ssid_len == ssid_len &&
1008 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1009 /* OWE BSS in transition mode for a currently
1010 * enabled OWE network. */
1011 wpa_dbg(wpa_s, MSG_DEBUG,
1012 "OWE: transition mode OWE SSID for active OWE profile");
1013 bss->flags |= WPA_BSS_OWE_TRANSITION;
1014 break;
1015 }
1016 }
1017 }
1018
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001019 if (bss->ssid_len > 0)
1020 return;
1021
1022 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1023 if (!open_bss)
1024 return;
1025 if (ssid_len != open_bss->ssid_len ||
1026 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1027 wpa_dbg(wpa_s, MSG_DEBUG,
1028 "OWE: transition mode SSID mismatch: %s",
1029 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1030 return;
1031 }
1032
1033 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1034 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1035 wpa_dbg(wpa_s, MSG_DEBUG,
1036 "OWE: transition mode open BSS unexpected info");
1037 return;
1038 }
1039
1040 pos = owe + 6;
1041 end = owe + 2 + owe[1];
1042
1043 if (end - pos < ETH_ALEN + 1)
1044 return;
1045 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1046 wpa_dbg(wpa_s, MSG_DEBUG,
1047 "OWE: transition mode BSSID mismatch: " MACSTR,
1048 MAC2STR(pos));
1049 return;
1050 }
1051 pos += ETH_ALEN;
1052 ssid_len = *pos++;
1053 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1054 return;
1055 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1056 wpa_ssid_txt(pos, ssid_len));
1057 os_memcpy(bss->ssid, pos, ssid_len);
1058 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001059 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001060#endif /* CONFIG_OWE */
1061}
1062
1063
Hai Shalomfdcde762020-04-02 11:19:20 -07001064static int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
1065{
1066 int i, j;
1067
1068 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1069 return 0;
1070
1071 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1072 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1073
1074 for (i = 0; i < mode->num_channels; i++) {
1075 struct hostapd_channel_data *chan = &mode->channels[i];
1076
1077 if (chan->freq == freq)
1078 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1079 }
1080 }
1081
1082 return 1;
1083}
1084
1085
Hai Shalom899fcc72020-10-19 14:38:18 -07001086static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1087 const u8 *match_ssid, size_t match_ssid_len,
1088 struct wpa_bss *bss, int blacklist_count,
1089 bool debug_print);
1090
1091
1092#ifdef CONFIG_SAE_PK
1093static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1094 struct wpa_bss *orig_bss,
1095 struct wpa_ssid *ssid,
1096 const u8 *match_ssid,
1097 size_t match_ssid_len)
1098{
1099 struct wpa_bss *bss;
1100
1101 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1102 int count;
1103 const u8 *ie;
1104 u8 rsnxe_capa = 0;
1105
1106 if (bss == orig_bss)
1107 continue;
1108 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1109 if (ie && ie[1] >= 1)
1110 rsnxe_capa = ie[2];
1111 if (!(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)))
1112 continue;
1113
1114 /* TODO: Could be more thorough in checking what kind of
1115 * signal strength or throughput estimate would be acceptable
1116 * compared to the originally selected BSS. */
1117 if (bss->est_throughput < 2000)
1118 return false;
1119
1120 count = wpa_blacklist_is_blacklisted(wpa_s, bss->bssid);
1121 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1122 bss, count, 0))
1123 return true;
1124 }
1125
1126 return false;
1127}
1128#endif /* CONFIG_SAE_PK */
1129
1130
1131static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1132 const u8 *match_ssid, size_t match_ssid_len,
1133 struct wpa_bss *bss, int blacklist_count,
1134 bool debug_print)
1135{
1136 int res;
1137 bool wpa, check_ssid, osen, rsn_osen = false;
1138 struct wpa_ie_data data;
1139#ifdef CONFIG_MBO
1140 const u8 *assoc_disallow;
1141#endif /* CONFIG_MBO */
1142#ifdef CONFIG_SAE
1143 u8 rsnxe_capa = 0;
1144#endif /* CONFIG_SAE */
1145 const u8 *ie;
1146
1147 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1148 wpa = ie && ie[1];
1149 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1150 wpa |= ie && ie[1];
1151 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1152 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1153 rsn_osen = true;
1154 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1155 osen = ie != NULL;
1156
1157#ifdef CONFIG_SAE
1158 ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1159 if (ie && ie[1] >= 1)
1160 rsnxe_capa = ie[2];
1161#endif /* CONFIG_SAE */
1162
1163 check_ssid = wpa || ssid->ssid_len > 0;
1164
1165 if (wpas_network_disabled(wpa_s, ssid)) {
1166 if (debug_print)
1167 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1168 return false;
1169 }
1170
1171 res = wpas_temp_disabled(wpa_s, ssid);
1172 if (res > 0) {
1173 if (debug_print)
1174 wpa_dbg(wpa_s, MSG_DEBUG,
1175 " skip - disabled temporarily for %d second(s)",
1176 res);
1177 return false;
1178 }
1179
1180#ifdef CONFIG_WPS
1181 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && blacklist_count) {
1182 if (debug_print)
1183 wpa_dbg(wpa_s, MSG_DEBUG,
1184 " skip - blacklisted (WPS)");
1185 return false;
1186 }
1187
1188 if (wpa && ssid->ssid_len == 0 &&
1189 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1190 check_ssid = false;
1191
1192 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1193 /* Only allow wildcard SSID match if an AP advertises active
1194 * WPS operation that matches our mode. */
1195 check_ssid = ssid->ssid_len > 0 ||
1196 !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1197 }
1198#endif /* CONFIG_WPS */
1199
1200 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1201 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1202 check_ssid = false;
1203
1204 if (check_ssid &&
1205 (match_ssid_len != ssid->ssid_len ||
1206 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1207 if (debug_print)
1208 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
1209 return false;
1210 }
1211
1212 if (ssid->bssid_set &&
1213 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1214 if (debug_print)
1215 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
1216 return false;
1217 }
1218
1219 /* check blacklist */
1220 if (ssid->num_bssid_blacklist &&
1221 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1222 ssid->num_bssid_blacklist)) {
1223 if (debug_print)
1224 wpa_dbg(wpa_s, MSG_DEBUG,
1225 " skip - BSSID blacklisted");
1226 return false;
1227 }
1228
1229 /* if there is a whitelist, only accept those APs */
1230 if (ssid->num_bssid_whitelist &&
1231 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1232 ssid->num_bssid_whitelist)) {
1233 if (debug_print)
1234 wpa_dbg(wpa_s, MSG_DEBUG,
1235 " skip - BSSID not in whitelist");
1236 return false;
1237 }
1238
1239 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1240 return false;
1241
1242 if (!osen && !wpa &&
1243 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1244 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1245 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1246 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1247 if (debug_print)
1248 wpa_dbg(wpa_s, MSG_DEBUG,
1249 " skip - non-WPA network not allowed");
1250 return false;
1251 }
1252
1253#ifdef CONFIG_WEP
1254 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1255 if (debug_print)
1256 wpa_dbg(wpa_s, MSG_DEBUG,
1257 " skip - ignore WPA/WPA2 AP for WEP network block");
1258 return false;
1259 }
1260#endif /* CONFIG_WEP */
1261
1262 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1263 if (debug_print)
1264 wpa_dbg(wpa_s, MSG_DEBUG,
1265 " skip - non-OSEN network not allowed");
1266 return false;
1267 }
1268
1269 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1270 if (debug_print)
1271 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch");
1272 return false;
1273 }
1274
1275 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1276 !bss_is_pbss(bss)) {
1277 if (debug_print)
1278 wpa_dbg(wpa_s, MSG_DEBUG,
1279 " skip - not ESS, PBSS, or MBSS");
1280 return false;
1281 }
1282
1283 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1284 if (debug_print)
1285 wpa_dbg(wpa_s, MSG_DEBUG,
1286 " skip - PBSS mismatch (ssid %d bss %d)",
1287 ssid->pbss, bss_is_pbss(bss));
1288 return false;
1289 }
1290
1291 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1292 if (debug_print)
1293 wpa_dbg(wpa_s, MSG_DEBUG,
1294 " skip - frequency not allowed");
1295 return false;
1296 }
1297
1298#ifdef CONFIG_MESH
1299 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1300 ssid->frequency != bss->freq) {
1301 if (debug_print)
1302 wpa_dbg(wpa_s, MSG_DEBUG,
1303 " skip - frequency not allowed (mesh)");
1304 return false;
1305 }
1306#endif /* CONFIG_MESH */
1307
1308 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1309 if (debug_print)
1310 wpa_dbg(wpa_s, MSG_DEBUG,
1311 " skip - rate sets do not match");
1312 return false;
1313 }
1314
1315#ifdef CONFIG_SAE
1316 if ((wpa_s->conf->sae_pwe == 1 || ssid->sae_password_id) &&
1317 wpa_s->conf->sae_pwe != 3 && wpa_key_mgmt_sae(ssid->key_mgmt) &&
1318 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1319 if (debug_print)
1320 wpa_dbg(wpa_s, MSG_DEBUG,
1321 " skip - SAE H2E required, but not supported by the AP");
1322 return false;
1323 }
1324#endif /* CONFIG_SAE */
1325
1326#ifdef CONFIG_SAE_PK
1327 if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1328 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1329 if (debug_print)
1330 wpa_dbg(wpa_s, MSG_DEBUG,
1331 " skip - SAE-PK required, but not supported by the AP");
1332 return false;
1333 }
1334#endif /* CONFIG_SAE_PK */
1335
1336#ifndef CONFIG_IBSS_RSN
1337 if (ssid->mode == WPAS_MODE_IBSS &&
1338 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1339 if (debug_print)
1340 wpa_dbg(wpa_s, MSG_DEBUG,
1341 " skip - IBSS RSN not supported in the build");
1342 return false;
1343 }
1344#endif /* !CONFIG_IBSS_RSN */
1345
1346#ifdef CONFIG_P2P
1347 if (ssid->p2p_group &&
1348 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1349 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1350 if (debug_print)
1351 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1352 return false;
1353 }
1354
1355 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1356 struct wpabuf *p2p_ie;
1357 u8 dev_addr[ETH_ALEN];
1358
1359 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1360 if (!ie) {
1361 if (debug_print)
1362 wpa_dbg(wpa_s, MSG_DEBUG,
1363 " skip - no P2P element");
1364 return false;
1365 }
1366 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1367 if (!p2p_ie) {
1368 if (debug_print)
1369 wpa_dbg(wpa_s, MSG_DEBUG,
1370 " skip - could not fetch P2P element");
1371 return false;
1372 }
1373
1374 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1375 os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) {
1376 if (debug_print)
1377 wpa_dbg(wpa_s, MSG_DEBUG,
1378 " skip - no matching GO P2P Device Address in P2P element");
1379 wpabuf_free(p2p_ie);
1380 return false;
1381 }
1382 wpabuf_free(p2p_ie);
1383 }
1384
1385 /*
1386 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1387 * P2P Group Capability Bitmap and we are not in Group Formation with
1388 * that device.
1389 */
1390#endif /* CONFIG_P2P */
1391
1392 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1393 struct os_reltime diff;
1394
1395 os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1396 if (debug_print)
1397 wpa_dbg(wpa_s, MSG_DEBUG,
1398 " skip - scan result not recent enough (%u.%06u seconds too old)",
1399 (unsigned int) diff.sec,
1400 (unsigned int) diff.usec);
1401 return false;
1402 }
1403#ifdef CONFIG_MBO
1404#ifdef CONFIG_TESTING_OPTIONS
1405 if (wpa_s->ignore_assoc_disallow)
1406 goto skip_assoc_disallow;
1407#endif /* CONFIG_TESTING_OPTIONS */
1408 assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1409 if (assoc_disallow && assoc_disallow[1] >= 1) {
1410 if (debug_print)
1411 wpa_dbg(wpa_s, MSG_DEBUG,
1412 " skip - MBO association disallowed (reason %u)",
1413 assoc_disallow[2]);
1414 return false;
1415 }
1416
1417 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1418 if (debug_print)
1419 wpa_dbg(wpa_s, MSG_DEBUG,
1420 " skip - AP temporarily disallowed");
1421 return false;
1422 }
1423#ifdef CONFIG_TESTING_OPTIONS
1424skip_assoc_disallow:
1425#endif /* CONFIG_TESTING_OPTIONS */
1426#endif /* CONFIG_MBO */
1427
1428#ifdef CONFIG_DPP
1429 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1430 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1431 (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1432 !ssid->dpp_csign)) {
1433 if (debug_print)
1434 wpa_dbg(wpa_s, MSG_DEBUG,
1435 " skip - no PMKSA entry for DPP");
1436 return false;
1437 }
1438#endif /* CONFIG_DPP */
1439
1440#ifdef CONFIG_SAE_PK
1441 if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1442 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1443 ((ssid->sae_password &&
1444 sae_pk_valid_password(ssid->sae_password)) ||
1445 (!ssid->sae_password && ssid->passphrase &&
1446 sae_pk_valid_password(ssid->passphrase))) &&
1447 !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1448 sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1449 match_ssid_len)) {
1450 if (debug_print)
1451 wpa_dbg(wpa_s, MSG_DEBUG,
1452 " skip - another acceptable BSS with SAE-PK in the same ESS");
1453 return false;
1454 }
1455#endif /* CONFIG_SAE_PK */
1456
1457 if (bss->ssid_len == 0) {
1458 if (debug_print)
1459 wpa_dbg(wpa_s, MSG_DEBUG,
1460 " skip - no SSID known for the BSS");
1461 return false;
1462 }
1463
1464 /* Matching configuration found */
1465 return true;
1466}
1467
1468
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001469struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1470 int i, struct wpa_bss *bss,
1471 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001472 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001473{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001474 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001475 const u8 *ie;
1476 struct wpa_ssid *ssid;
Hai Shalom899fcc72020-10-19 14:38:18 -07001477 int osen;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001478 const u8 *match_ssid;
1479 size_t match_ssid_len;
Hai Shalom899fcc72020-10-19 14:38:18 -07001480 int blacklist_count;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001481
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001482 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001483 wpa_ie_len = ie ? ie[1] : 0;
1484
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001485 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001486 rsn_ie_len = ie ? ie[1] : 0;
1487
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001488 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1489 osen = ie != NULL;
1490
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001491 if (debug_print) {
1492 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1493 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1494 i, MAC2STR(bss->bssid),
1495 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1496 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1497 bss->freq,
1498 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1499 " wps" : "",
1500 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1501 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1502 ? " p2p" : "",
1503 osen ? " osen=1" : "");
1504 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001505
Hai Shalom899fcc72020-10-19 14:38:18 -07001506 blacklist_count = wpa_blacklist_is_blacklisted(wpa_s, bss->bssid);
1507 if (blacklist_count) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001508 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001509 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001510 /*
1511 * When only a single network is enabled, we can
1512 * trigger blacklisting on the first failure. This
1513 * should not be done with multiple enabled networks to
1514 * avoid getting forced to move into a worse ESS on
1515 * single error if there are no other BSSes of the
1516 * current ESS.
1517 */
1518 limit = 0;
1519 }
Hai Shalom899fcc72020-10-19 14:38:18 -07001520 if (blacklist_count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001521 if (debug_print) {
1522 wpa_dbg(wpa_s, MSG_DEBUG,
1523 " skip - blacklisted (count=%d limit=%d)",
Hai Shalom899fcc72020-10-19 14:38:18 -07001524 blacklist_count, limit);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001525 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001526 return NULL;
1527 }
1528 }
1529
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001530 match_ssid = bss->ssid;
1531 match_ssid_len = bss->ssid_len;
1532 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1533
1534 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001535 if (debug_print)
1536 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537 return NULL;
1538 }
1539
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001540 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001541 if (debug_print)
1542 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001543 return NULL;
1544 }
1545
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001546 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001547 if (debug_print)
1548 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001549 return NULL;
1550 }
1551
Hai Shalomfdcde762020-04-02 11:19:20 -07001552 if (disabled_freq(wpa_s, bss->freq)) {
1553 if (debug_print)
1554 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1555 return NULL;
1556 }
1557
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001558 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001559 if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1560 bss, blacklist_count, debug_print))
1561 return ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001562 }
1563
1564 /* No matching configuration found */
1565 return NULL;
1566}
1567
1568
1569static struct wpa_bss *
1570wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001571 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001572 struct wpa_ssid **selected_ssid,
1573 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001574{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001575 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001576
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001577 if (wpa_s->current_ssid) {
1578 struct wpa_ssid *ssid;
1579
1580 wpa_dbg(wpa_s, MSG_DEBUG,
1581 "Scan results matching the currently selected network");
1582 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1583 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1584
1585 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1586 only_first_ssid, 0);
1587 if (ssid != wpa_s->current_ssid)
1588 continue;
1589 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1590 " freq=%d level=%d snr=%d est_throughput=%u",
1591 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1592 bss->snr, bss->est_throughput);
1593 }
1594 }
1595
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001596 if (only_first_ssid)
1597 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1598 group->id);
1599 else
1600 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1601 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001602
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001603 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1604 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001605
1606 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001607 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001608 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001609 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001610 if (!*selected_ssid)
1611 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001612 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001613 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001614 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001615 MAC2STR(bss->bssid),
1616 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1617 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001618 }
1619
1620 return NULL;
1621}
1622
1623
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001624struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1625 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001626{
1627 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001628 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001629 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001630 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001631
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001632 if (wpa_s->last_scan_res == NULL ||
1633 wpa_s->last_scan_res_used == 0)
1634 return NULL; /* no scan results from last update */
1635
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001636 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001637 /* check that next_ssid is still valid */
1638 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1639 if (ssid == wpa_s->next_ssid)
1640 break;
1641 }
1642 next_ssid = ssid;
1643 wpa_s->next_ssid = NULL;
1644 }
1645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001646 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001647 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1648 if (next_ssid && next_ssid->priority ==
1649 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001650 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001651 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001652 if (selected)
1653 break;
1654 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001656 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001657 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001658 if (selected)
1659 break;
1660 }
1661
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001662 if (selected == NULL && wpa_s->blacklist &&
1663 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001664 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1665 "blacklist and try again");
1666 wpa_blacklist_clear(wpa_s);
1667 wpa_s->blacklist_cleared++;
1668 } else if (selected == NULL)
1669 break;
1670 }
1671
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001672 ssid = *selected_ssid;
1673 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1674 !ssid->passphrase && !ssid->ext_psk) {
1675 const char *field_name, *txt = NULL;
1676
1677 wpa_dbg(wpa_s, MSG_DEBUG,
1678 "PSK/passphrase not yet available for the selected network");
1679
1680 wpas_notify_network_request(wpa_s, ssid,
1681 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1682
1683 field_name = wpa_supplicant_ctrl_req_to_string(
1684 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1685 if (field_name == NULL)
1686 return NULL;
1687
1688 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1689
1690 selected = NULL;
1691 }
1692
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001693 return selected;
1694}
1695
1696
1697static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1698 int timeout_sec, int timeout_usec)
1699{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001700 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001701 /*
1702 * No networks are enabled; short-circuit request so
1703 * we don't wait timeout seconds before transitioning
1704 * to INACTIVE state.
1705 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001706 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1707 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001708 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1709 return;
1710 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001711
1712 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001713 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1714}
1715
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001716
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001717int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001718 struct wpa_bss *selected,
1719 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001720{
1721 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1722 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1723 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001724 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001725#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001726 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1727 wpa_s->p2p_in_provisioning) {
1728 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1729 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001730 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001731 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001732#endif /* CONFIG_P2P */
1733
1734#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001735 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001736 wpas_wps_cancel(wpa_s);
1737#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001738 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001739 }
1740
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001741 wpa_msg(wpa_s, MSG_DEBUG,
1742 "Considering connect request: reassociate: %d selected: "
1743 MACSTR " bssid: " MACSTR " pending: " MACSTR
1744 " wpa_state: %s ssid=%p current_ssid=%p",
1745 wpa_s->reassociate, MAC2STR(selected->bssid),
1746 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1747 wpa_supplicant_state_txt(wpa_s->wpa_state),
1748 ssid, wpa_s->current_ssid);
1749
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001750 /*
1751 * Do not trigger new association unless the BSSID has changed or if
1752 * reassociation is requested. If we are in process of associating with
1753 * the selected BSSID, do not trigger new attempt.
1754 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001755 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1757 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1758 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001759 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1760 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1761 0) ||
1762 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1763 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1765 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001766 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001767 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001768 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1769 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001770 wpa_supplicant_associate(wpa_s, selected, ssid);
1771 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001772 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1773 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001774 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001775
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001776 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777}
1778
1779
1780static struct wpa_ssid *
1781wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1782{
Hai Shalomfdcde762020-04-02 11:19:20 -07001783 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001784 struct wpa_ssid *ssid;
1785
1786 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1787 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1788 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001789 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001790 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001791#ifndef CONFIG_IBSS_RSN
1792 if (ssid->mode == WPAS_MODE_IBSS &&
1793 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1794 WPA_KEY_MGMT_WPA_NONE))) {
1795 wpa_msg(wpa_s, MSG_INFO,
1796 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1797 wpa_ssid_txt(ssid->ssid,
1798 ssid->ssid_len));
1799 continue;
1800 }
1801#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001802 if (ssid->mode == WPAS_MODE_IBSS ||
1803 ssid->mode == WPAS_MODE_AP ||
1804 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805 return ssid;
1806 }
1807 }
1808 return NULL;
1809}
1810
1811
1812/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1813 * on BSS added and BSS changed events */
1814static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001815 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001816{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001817 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001818
1819 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1820 return;
1821
Jouni Malinen87fd2792011-05-16 18:35:42 +03001822 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824
Jouni Malinen87fd2792011-05-16 18:35:42 +03001825 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001826 if (ssid == NULL)
1827 continue;
1828
Jouni Malinen87fd2792011-05-16 18:35:42 +03001829 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 if (rsn == NULL)
1831 continue;
1832
Jouni Malinen87fd2792011-05-16 18:35:42 +03001833 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834 }
1835
1836}
1837
1838
Hai Shalomfdcde762020-04-02 11:19:20 -07001839#ifndef CONFIG_NO_ROAMING
1840
1841static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1842{
1843 if (noise == WPA_INVALID_NOISE)
1844 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1845 DEFAULT_NOISE_FLOOR_2GHZ;
1846 return avg_signal - noise;
1847}
1848
1849
1850static unsigned int
1851wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1852 const struct wpa_bss *bss, int snr)
1853{
1854 int rate = wpa_bss_get_max_rate(bss);
1855 const u8 *ies = (const void *) (bss + 1);
1856 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1857
1858 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr);
1859}
1860
Hai Shalomfdcde762020-04-02 11:19:20 -07001861
Hai Shalom899fcc72020-10-19 14:38:18 -07001862int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
1863 struct wpa_bss *current_bss,
1864 struct wpa_bss *selected)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865{
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001866 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001867 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001868 int cur_level;
1869 unsigned int cur_est, sel_est;
1870 struct wpa_signal_info si;
1871 int cur_snr = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07001872 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001873
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001875 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001876 " freq=%d level=%d snr=%d est_throughput=%u",
1877 MAC2STR(current_bss->bssid),
1878 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001879 current_bss->snr, current_bss->est_throughput);
1880 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001881 " freq=%d level=%d snr=%d est_throughput=%u",
1882 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001883 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001884
1885 if (wpa_s->current_ssid->bssid_set &&
1886 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1887 0) {
1888 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1889 "has preferred BSSID");
1890 return 1;
1891 }
1892
Hai Shalomfdcde762020-04-02 11:19:20 -07001893 cur_level = current_bss->level;
1894 cur_est = current_bss->est_throughput;
1895 sel_est = selected->est_throughput;
1896
1897 /*
1898 * Try to poll the signal from the driver since this will allow to get
1899 * more accurate values. In some cases, there can be big differences
1900 * between the RSSI of the Probe Response frames of the AP we are
1901 * associated with and the Beacon frames we hear from the same AP after
1902 * association. This can happen, e.g., when there are two antennas that
1903 * hear the AP very differently. If the driver chooses to hear the
1904 * Probe Response frames during the scan on the "bad" antenna because
1905 * it wants to save power, but knows to choose the other antenna after
1906 * association, we will hear our AP with a low RSSI as part of the
1907 * scan even when we can hear it decently on the other antenna. To cope
1908 * with this, ask the driver to teach us how it hears the AP. Also, the
1909 * scan results may be a bit old, since we can very quickly get fresh
1910 * information about our currently associated AP.
1911 */
1912 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1913 (si.avg_beacon_signal || si.avg_signal)) {
1914 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1915 si.avg_signal;
1916 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
1917 si.current_noise);
1918
1919 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
1920 current_bss,
1921 cur_snr);
1922 wpa_dbg(wpa_s, MSG_DEBUG,
1923 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
1924 cur_level, cur_snr, cur_est);
1925 }
1926
1927 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001928 wpa_dbg(wpa_s, MSG_DEBUG,
1929 "Allow reassociation - selected BSS has better estimated throughput");
1930 return 1;
1931 }
1932
Dmitry Shmidte4663042016-04-04 10:07:49 -07001933 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1934
Hai Shalomfdcde762020-04-02 11:19:20 -07001935 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
1936 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001937 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1938 "signal level");
1939 return 0;
1940 }
1941
Hai Shalomfdcde762020-04-02 11:19:20 -07001942 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001943 wpa_dbg(wpa_s, MSG_DEBUG,
1944 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001945 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001946 }
1947
Hai Shalomfdcde762020-04-02 11:19:20 -07001948 if (cur_snr > GREAT_SNR) {
1949 wpa_dbg(wpa_s, MSG_DEBUG,
1950 "Skip roam - Current BSS has good SNR (%u > %u)",
1951 cur_snr, GREAT_SNR);
1952 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001953 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001954
Hai Shalomfdcde762020-04-02 11:19:20 -07001955 if (cur_level < -85) /* ..-86 dBm */
1956 min_diff = 1;
1957 else if (cur_level < -80) /* -85..-81 dBm */
1958 min_diff = 2;
1959 else if (cur_level < -75) /* -80..-76 dBm */
1960 min_diff = 3;
1961 else if (cur_level < -70) /* -75..-71 dBm */
1962 min_diff = 4;
1963 else if (cur_level < 0) /* -70..-1 dBm */
1964 min_diff = 5;
1965 else /* unspecified units (not in dBm) */
1966 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001967
Hai Shalomfdcde762020-04-02 11:19:20 -07001968 if (cur_est > sel_est * 1.5)
1969 min_diff += 10;
1970 else if (cur_est > sel_est * 1.2)
1971 min_diff += 5;
1972 else if (cur_est > sel_est * 1.1)
1973 min_diff += 2;
1974 else if (cur_est > sel_est)
1975 min_diff++;
1976 else if (sel_est > cur_est * 1.5)
1977 min_diff -= 10;
1978 else if (sel_est > cur_est * 1.2)
1979 min_diff -= 5;
1980 else if (sel_est > cur_est * 1.1)
1981 min_diff -= 2;
1982 else if (sel_est > cur_est)
1983 min_diff--;
1984
1985 if (to_5ghz)
1986 min_diff -= 2;
1987 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001988 if (diff < min_diff) {
1989 wpa_dbg(wpa_s, MSG_DEBUG,
1990 "Skip roam - too small difference in signal level (%d < %d)",
1991 diff, min_diff);
Hai Shalom899fcc72020-10-19 14:38:18 -07001992 ret = 0;
1993 } else {
1994 wpa_dbg(wpa_s, MSG_DEBUG,
1995 "Allow reassociation due to difference in signal level (%d >= %d)",
1996 diff, min_diff);
1997 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001998 }
Hai Shalom899fcc72020-10-19 14:38:18 -07001999 wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2000 " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2001 " sel_freq=%d sel_level=%d sel_est=%d",
2002 ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2003 MAC2STR(current_bss->bssid),
2004 current_bss->freq, cur_level, cur_est,
2005 MAC2STR(selected->bssid),
2006 selected->freq, selected->level, sel_est);
2007 return ret;
2008}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002009
Hai Shalom899fcc72020-10-19 14:38:18 -07002010#endif /* CONFIG_NO_ROAMING */
2011
2012
2013static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2014 struct wpa_bss *selected,
2015 struct wpa_ssid *ssid)
2016{
2017 struct wpa_bss *current_bss = NULL;
2018
2019 if (wpa_s->reassociate)
2020 return 1; /* explicit request to reassociate */
2021 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2022 return 1; /* we are not associated; continue */
2023 if (wpa_s->current_ssid == NULL)
2024 return 1; /* unknown current SSID */
2025 if (wpa_s->current_ssid != ssid)
2026 return 1; /* different network block */
2027
2028 if (wpas_driver_bss_selection(wpa_s))
2029 return 0; /* Driver-based roaming */
2030
2031 if (wpa_s->current_ssid->ssid)
2032 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
2033 wpa_s->current_ssid->ssid,
2034 wpa_s->current_ssid->ssid_len);
2035 if (!current_bss)
2036 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
2037
2038 if (!current_bss)
2039 return 1; /* current BSS not seen in scan results */
2040
2041 if (current_bss == selected)
2042 return 0;
2043
2044 if (selected->last_update_idx > current_bss->last_update_idx)
2045 return 1; /* current BSS not seen in the last scan */
2046
2047#ifndef CONFIG_NO_ROAMING
2048 return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2049 selected);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002050#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07002051 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002052#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002053}
2054
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002055
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002056/*
2057 * Return a negative value if no scan results could be fetched or if scan
2058 * results should not be shared with other virtual interfaces.
2059 * Return 0 if scan results were fetched and may be shared with other
2060 * interfaces.
2061 * Return 1 if scan results may be shared with other virtual interfaces but may
2062 * not trigger any operations.
2063 * Return 2 if the interface was removed and cannot be used.
2064 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08002065static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002066 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002067 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002068{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002069 struct wpa_scan_results *scan_res = NULL;
2070 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002071 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07002072#ifndef CONFIG_NO_RANDOM_POOL
2073 size_t i, num;
2074#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075
2076#ifdef CONFIG_AP
2077 if (wpa_s->ap_iface)
2078 ap = 1;
2079#endif /* CONFIG_AP */
2080
2081 wpa_supplicant_notify_scanning(wpa_s, 0);
2082
2083 scan_res = wpa_supplicant_get_scan_results(wpa_s,
2084 data ? &data->scan_info :
2085 NULL, 1);
2086 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002087 if (wpa_s->conf->ap_scan == 2 || ap ||
2088 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002089 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002090 if (!own_request)
2091 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002092 if (data && data->scan_info.external_scan)
2093 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002094 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
2095 "scanning again");
2096 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002097 ret = -1;
2098 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002099 }
2100
2101#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002102 num = scan_res->num;
2103 if (num > 10)
2104 num = 10;
2105 for (i = 0; i < num; i++) {
2106 u8 buf[5];
2107 struct wpa_scan_res *res = scan_res->res[i];
2108 buf[0] = res->bssid[5];
2109 buf[1] = res->qual & 0xff;
2110 buf[2] = res->noise & 0xff;
2111 buf[3] = res->level & 0xff;
2112 buf[4] = res->tsf & 0xff;
2113 random_add_randomness(buf, sizeof(buf));
2114 }
2115#endif /* CONFIG_NO_RANDOM_POOL */
2116
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002117 if (update_only) {
2118 ret = 1;
2119 goto scan_work_done;
2120 }
2121
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002122 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002123 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002124 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2125 struct wpa_scan_results *scan_res);
2126
2127 scan_res_handler = wpa_s->scan_res_handler;
2128 wpa_s->scan_res_handler = NULL;
2129 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002130 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002131 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132 }
2133
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002134 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002135 wpa_s->own_scan_running,
2136 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002137 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002138 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2139 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002140 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2141 wpa_s->manual_scan_id);
2142 wpa_s->manual_scan_use_id = 0;
2143 } else {
2144 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2145 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002146 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002147
2148 wpas_notify_scan_done(wpa_s, 1);
2149
Hai Shalomfdcde762020-04-02 11:19:20 -07002150 if (ap) {
2151 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2152#ifdef CONFIG_AP
2153 if (wpa_s->ap_iface->scan_cb)
2154 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2155#endif /* CONFIG_AP */
2156 goto scan_work_done;
2157 }
2158
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002159 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002160 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 -07002161 wpa_scan_results_free(scan_res);
2162 return 0;
2163 }
2164
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002165 if (wnm_scan_process(wpa_s, 1) > 0)
2166 goto scan_work_done;
2167
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002168 if (sme_proc_obss_scan(wpa_s, scan_res) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002169 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002170
Hai Shalom021b0b52019-04-10 11:17:58 -07002171 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002172 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2173 goto scan_work_done;
2174
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002175 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2176 goto scan_work_done;
2177
2178 if (autoscan_notify_scan(wpa_s, scan_res))
2179 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002181 if (wpa_s->disconnected) {
2182 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002183 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002184 }
2185
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002186 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002187 bgscan_notify_scan(wpa_s, scan_res) == 1)
2188 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002189
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002190 wpas_wps_update_ap_info(wpa_s, scan_res);
2191
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002192 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2193 wpa_s->wpa_state < WPA_COMPLETED)
2194 goto scan_work_done;
2195
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002196 wpa_scan_results_free(scan_res);
2197
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002198 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002199 struct wpa_radio_work *work = wpa_s->scan_work;
2200 wpa_s->scan_work = NULL;
2201 radio_work_done(work);
2202 }
2203
Hai Shalomc3565922019-10-28 11:58:20 -07002204 os_free(wpa_s->last_scan_freqs);
2205 wpa_s->last_scan_freqs = NULL;
2206 wpa_s->num_last_scan_freqs = 0;
2207 if (own_request && data &&
2208 data->scan_info.freqs && data->scan_info.num_freqs) {
2209 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2210 data->scan_info.num_freqs);
2211 if (wpa_s->last_scan_freqs) {
2212 os_memcpy(wpa_s->last_scan_freqs,
2213 data->scan_info.freqs,
2214 sizeof(int) * data->scan_info.num_freqs);
2215 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2216 }
2217 }
2218
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002219 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002220
2221scan_work_done:
2222 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002223 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002224 struct wpa_radio_work *work = wpa_s->scan_work;
2225 wpa_s->scan_work = NULL;
2226 radio_work_done(work);
2227 }
2228 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002229}
2230
2231
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002232static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002233 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002234{
2235 struct wpa_bss *selected;
2236 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002237 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2238
2239 if (time_to_reenable > 0) {
2240 wpa_dbg(wpa_s, MSG_DEBUG,
2241 "Postpone network selection by %d seconds since all networks are disabled",
2242 time_to_reenable);
2243 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2244 eloop_register_timeout(time_to_reenable, 0,
2245 wpas_network_reenabled, wpa_s, NULL);
2246 return 0;
2247 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002248
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002249 if (wpa_s->p2p_mgmt)
2250 return 0; /* no normal connection on p2p_mgmt interface */
2251
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002252 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002253 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002254
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002255#ifdef CONFIG_MESH
2256 if (wpa_s->ifmsh) {
2257 wpa_msg(wpa_s, MSG_INFO,
2258 "Avoiding join because we already joined a mesh group");
2259 return 0;
2260 }
2261#endif /* CONFIG_MESH */
2262
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263 if (selected) {
2264 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002265 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002266 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002267 if (new_scan)
2268 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002269 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002270 }
2271
Hai Shalomc3565922019-10-28 11:58:20 -07002272 wpa_s->suitable_network++;
2273
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002274 if (ssid != wpa_s->current_ssid &&
2275 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2276 wpa_s->own_disconnect_req = 1;
2277 wpa_supplicant_deauthenticate(
2278 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2279 }
2280
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002281 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002282 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002283 return -1;
2284 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002285 if (new_scan)
2286 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002287 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002288 * Do not allow other virtual radios to trigger operations based
2289 * on these scan results since we do not want them to start
2290 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002291 */
2292 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002293 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002294 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002295 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2296 ssid = wpa_supplicant_pick_new_network(wpa_s);
2297 if (ssid) {
2298 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2299 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002300 if (new_scan)
2301 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002302 } else if (own_request) {
2303 /*
2304 * No SSID found. If SCAN results are as a result of
2305 * own scan request and not due to a scan request on
2306 * another shared interface, try another scan.
2307 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 int timeout_sec = wpa_s->scan_interval;
2309 int timeout_usec = 0;
2310#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002311 int res;
2312
2313 res = wpas_p2p_scan_no_go_seen(wpa_s);
2314 if (res == 2)
2315 return 2;
2316 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002317 return 0;
2318
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002319 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002320 wpa_s->show_group_started ||
2321 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002322 /*
2323 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002324 * state and during P2P join-a-group operation
2325 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002326 */
2327 timeout_sec = 0;
2328 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002329 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2330 timeout_usec);
2331 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002332 }
2333#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002334#ifdef CONFIG_INTERWORKING
2335 if (wpa_s->conf->auto_interworking &&
2336 wpa_s->conf->interworking &&
2337 wpa_s->conf->cred) {
2338 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2339 "start ANQP fetch since no matching "
2340 "networks found");
2341 wpa_s->network_select = 1;
2342 wpa_s->auto_network_select = 1;
2343 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002344 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002345 }
2346#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002347#ifdef CONFIG_WPS
2348 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2349 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2350 timeout_sec = 0;
2351 timeout_usec = 500000;
2352 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2353 timeout_usec);
2354 return 0;
2355 }
2356#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002357#ifdef CONFIG_OWE
2358 if (wpa_s->owe_transition_search) {
2359 wpa_dbg(wpa_s, MSG_DEBUG,
2360 "OWE: Use shorter wait during transition mode search");
2361 timeout_sec = 0;
2362 timeout_usec = 500000;
2363 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2364 timeout_usec);
2365 return 0;
2366 }
2367#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002368 if (wpa_supplicant_req_sched_scan(wpa_s))
2369 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2370 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002371
2372 wpa_msg_ctrl(wpa_s, MSG_INFO,
2373 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002374 }
2375 }
2376 return 0;
2377}
2378
2379
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002380static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2381 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002382{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002383 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002384 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002385
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002386 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002387 if (res == 2) {
2388 /*
2389 * Interface may have been removed, so must not dereference
2390 * wpa_s after this.
2391 */
2392 return 1;
2393 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002394
2395 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002396 /*
2397 * If no scan results could be fetched, then no need to
2398 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002399 * this scan. Similarly, if scan results started a new operation on this
2400 * interface, do not notify other interfaces to avoid concurrent
2401 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002402 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002403 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002404 }
2405
2406 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002407 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002408 * so, they get updated with this same scan info.
2409 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002410 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2411 radio_list) {
2412 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002413 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2414 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002415 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2416 res > 0);
2417 if (res < 0)
2418 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002419 }
2420 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002421
2422 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002423}
2424
2425#endif /* CONFIG_NO_SCAN_PROCESSING */
2426
2427
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002428int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2429{
2430#ifdef CONFIG_NO_SCAN_PROCESSING
2431 return -1;
2432#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002433 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002434
Dmitry Shmidt29333592017-01-09 12:27:11 -08002435 wpa_s->ignore_post_flush_scan_res = 0;
2436
Dmitry Shmidt41712582015-06-29 11:02:15 -07002437 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002438 return -1;
2439
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002440 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002441 if (os_reltime_expired(&now, &wpa_s->last_scan,
2442 SCAN_RES_VALID_FOR_CONNECT)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002443 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2444 return -1;
2445 }
2446
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002447 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002448#endif /* CONFIG_NO_SCAN_PROCESSING */
2449}
2450
Dmitry Shmidt04949592012-07-19 12:16:46 -07002451#ifdef CONFIG_WNM
2452
2453static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2454{
2455 struct wpa_supplicant *wpa_s = eloop_ctx;
2456
2457 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2458 return;
2459
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002460 if (!wpa_s->no_keep_alive) {
2461 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2462 MAC2STR(wpa_s->bssid));
2463 /* TODO: could skip this if normal data traffic has been sent */
2464 /* TODO: Consider using some more appropriate data frame for
2465 * this */
2466 if (wpa_s->l2)
2467 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2468 (u8 *) "", 0);
2469 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002470
2471#ifdef CONFIG_SME
2472 if (wpa_s->sme.bss_max_idle_period) {
2473 unsigned int msec;
2474 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2475 if (msec > 100)
2476 msec -= 100;
2477 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2478 wnm_bss_keep_alive, wpa_s, NULL);
2479 }
2480#endif /* CONFIG_SME */
2481}
2482
2483
2484static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2485 const u8 *ies, size_t ies_len)
2486{
2487 struct ieee802_11_elems elems;
2488
2489 if (ies == NULL)
2490 return;
2491
2492 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2493 return;
2494
2495#ifdef CONFIG_SME
2496 if (elems.bss_max_idle_period) {
2497 unsigned int msec;
2498 wpa_s->sme.bss_max_idle_period =
2499 WPA_GET_LE16(elems.bss_max_idle_period);
2500 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2501 "TU)%s", wpa_s->sme.bss_max_idle_period,
2502 (elems.bss_max_idle_period[2] & 0x01) ?
2503 " (protected keep-live required)" : "");
2504 if (wpa_s->sme.bss_max_idle_period == 0)
2505 wpa_s->sme.bss_max_idle_period = 1;
2506 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2507 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2508 /* msec times 1000 */
2509 msec = wpa_s->sme.bss_max_idle_period * 1024;
2510 if (msec > 100)
2511 msec -= 100;
2512 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2513 wnm_bss_keep_alive, wpa_s,
2514 NULL);
2515 }
2516 }
2517#endif /* CONFIG_SME */
2518}
2519
2520#endif /* CONFIG_WNM */
2521
2522
2523void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2524{
2525#ifdef CONFIG_WNM
2526 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2527#endif /* CONFIG_WNM */
2528}
2529
2530
Dmitry Shmidt051af732013-10-22 13:52:46 -07002531#ifdef CONFIG_INTERWORKING
2532
2533static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2534 size_t len)
2535{
2536 int res;
2537
2538 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2539 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2540 if (res) {
2541 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2542 }
2543
2544 return res;
2545}
2546
2547
2548static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2549 const u8 *ies, size_t ies_len)
2550{
2551 struct ieee802_11_elems elems;
2552
2553 if (ies == NULL)
2554 return;
2555
2556 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2557 return;
2558
2559 if (elems.qos_map_set) {
2560 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2561 elems.qos_map_set_len);
2562 }
2563}
2564
2565#endif /* CONFIG_INTERWORKING */
2566
2567
Hai Shalom74f70d42019-02-11 14:42:39 -08002568static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2569 const u8 *ies, size_t ies_len)
2570{
2571 struct ieee802_11_elems elems;
2572 const u8 *map_sub_elem, *pos;
2573 size_t len;
2574
Hai Shalomfdcde762020-04-02 11:19:20 -07002575 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002576
Hai Shalomfdcde762020-04-02 11:19:20 -07002577 if (!ies ||
2578 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2579 !elems.multi_ap || elems.multi_ap_len < 7)
2580 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002581
2582 pos = elems.multi_ap + 4;
2583 len = elems.multi_ap_len - 4;
2584
2585 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002586 if (!map_sub_elem || map_sub_elem[1] < 1)
2587 return;
2588
2589 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2590 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2591 MULTI_AP_FRONTHAUL_BSS);
2592 wpa_s->multi_ap_ie = 1;
2593}
2594
2595
2596static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2597{
2598 if (!wpa_s->current_ssid ||
2599 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2600 return;
2601
2602 if (!wpa_s->multi_ap_ie) {
2603 wpa_printf(MSG_INFO,
2604 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002605 goto fail;
2606 }
2607
Hai Shalomfdcde762020-04-02 11:19:20 -07002608 if (!wpa_s->multi_ap_backhaul) {
2609 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002610 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2611 wpa_printf(MSG_INFO,
2612 "WPS active, accepting fronthaul-only BSS");
2613 /* Don't set 4addr mode in this case, so just return */
2614 return;
2615 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002616 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2617 goto fail;
2618 }
2619
2620 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2621 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2622 goto fail;
2623 }
2624 wpa_s->enabled_4addr_mode = 1;
2625 return;
2626
2627fail:
2628 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2629}
2630
2631
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002632#ifdef CONFIG_FST
2633static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2634 const u8 *ie, size_t ie_len)
2635{
2636 struct mb_ies_info mb_ies;
2637
2638 if (!ie || !ie_len || !wpa_s->fst)
2639 return -ENOENT;
2640
2641 os_memset(&mb_ies, 0, sizeof(mb_ies));
2642
2643 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2644 size_t len;
2645
2646 len = 2 + ie[1];
2647 if (len > ie_len) {
2648 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2649 ie, ie_len);
2650 break;
2651 }
2652
2653 if (ie[0] == WLAN_EID_MULTI_BAND) {
2654 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2655 (unsigned int) len);
2656 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2657 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2658 mb_ies.nof_ies++;
2659 }
2660
2661 ie_len -= len;
2662 ie += len;
2663 }
2664
2665 if (mb_ies.nof_ies > 0) {
2666 wpabuf_free(wpa_s->received_mb_ies);
2667 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2668 return 0;
2669 }
2670
2671 return -ENOENT;
2672}
2673#endif /* CONFIG_FST */
2674
2675
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002676static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2677 union wpa_event_data *data)
2678{
Hai Shalomc3565922019-10-28 11:58:20 -07002679 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002680 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002681 u8 bssid[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07002682 bool bssid_known;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002683
2684 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
Hai Shalom899fcc72020-10-19 14:38:18 -07002685 bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002686 if (data->assoc_info.req_ies)
2687 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2688 data->assoc_info.req_ies_len);
2689 if (data->assoc_info.resp_ies) {
2690 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2691 data->assoc_info.resp_ies_len);
2692#ifdef CONFIG_TDLS
2693 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2694 data->assoc_info.resp_ies_len);
2695#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002696#ifdef CONFIG_WNM
2697 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2698 data->assoc_info.resp_ies_len);
2699#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002700#ifdef CONFIG_INTERWORKING
2701 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2702 data->assoc_info.resp_ies_len);
2703#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002704 if (wpa_s->hw_capab == CAPAB_VHT &&
2705 get_ie(data->assoc_info.resp_ies,
2706 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2707 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002708
2709 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2710 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002711 }
2712 if (data->assoc_info.beacon_ies)
2713 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2714 data->assoc_info.beacon_ies,
2715 data->assoc_info.beacon_ies_len);
2716 if (data->assoc_info.freq)
2717 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2718 data->assoc_info.freq);
2719
Hai Shalom021b0b52019-04-10 11:17:58 -07002720 wpa_s->connection_set = 0;
2721 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2722 struct ieee802_11_elems req_elems, resp_elems;
2723
2724 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2725 data->assoc_info.req_ies_len,
2726 &req_elems, 0) != ParseFailed &&
2727 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2728 data->assoc_info.resp_ies_len,
2729 &resp_elems, 0) != ParseFailed) {
2730 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07002731 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
2732 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07002733 wpa_s->connection_ht = req_elems.ht_capabilities &&
2734 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07002735 /* Do not include subset of VHT on 2.4 GHz vendor
2736 * extension in consideration for reporting VHT
2737 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07002738 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002739 resp_elems.vht_capabilities &&
2740 (!data->assoc_info.freq ||
2741 wpas_freq_to_band(data->assoc_info.freq) !=
2742 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07002743 wpa_s->connection_he = req_elems.he_capabilities &&
2744 resp_elems.he_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08002745
2746 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
2747 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
2748 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
2749 max_nss_rx_req : max_nss_rx_resp;
2750 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
2751 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
2752 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
2753 max_nss_tx_req : max_nss_tx_resp;
2754
2755 struct supported_chan_width sta_supported_chan_width =
2756 get_supported_channel_width(&req_elems);
2757 enum chan_width ap_operation_chan_width =
2758 get_operation_channel_width(&resp_elems);
2759 if (wpa_s->connection_vht || wpa_s->connection_he) {
2760 wpa_s->connection_channel_bandwidth =
2761 get_sta_operation_chan_width(ap_operation_chan_width,
2762 sta_supported_chan_width);
2763 } else if (wpa_s->connection_ht) {
2764 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
2765 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
2766 } else {
2767 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
2768 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002769 }
2770 }
2771
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002772 p = data->assoc_info.req_ies;
2773 l = data->assoc_info.req_ies_len;
2774
2775 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2776 while (p && l >= 2) {
2777 len = p[1] + 2;
2778 if (len > l) {
2779 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2780 p, l);
2781 break;
2782 }
Hai Shalomc3565922019-10-28 11:58:20 -07002783 if (!found &&
2784 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2785 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2786 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2787 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2788 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002789 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2790 break;
2791 found = 1;
2792 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07002793 }
2794 if (!found_x && p[0] == WLAN_EID_RSNX) {
2795 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
2796 break;
2797 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002798 }
2799 l -= len;
2800 p += len;
2801 }
2802 if (!found && data->assoc_info.req_ies)
2803 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002804 if (!found_x && data->assoc_info.req_ies)
2805 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002806
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002807#ifdef CONFIG_FILS
2808#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002809 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2810 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002811 (!data->assoc_info.resp_frame ||
2812 fils_process_assoc_resp(wpa_s->wpa,
2813 data->assoc_info.resp_frame,
2814 data->assoc_info.resp_frame_len) < 0)) {
2815 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2816 return -1;
2817 }
2818#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002819
2820 /* Additional processing for FILS when SME is in driver */
2821 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2822 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2823 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002824#endif /* CONFIG_FILS */
2825
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002826#ifdef CONFIG_OWE
2827 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
Hai Shalom899fcc72020-10-19 14:38:18 -07002828 (!bssid_known ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002829 owe_process_assoc_resp(wpa_s->wpa, bssid,
2830 data->assoc_info.resp_ies,
2831 data->assoc_info.resp_ies_len) < 0)) {
2832 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2833 return -1;
2834 }
2835#endif /* CONFIG_OWE */
2836
Hai Shalom021b0b52019-04-10 11:17:58 -07002837#ifdef CONFIG_DPP2
2838 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002839 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
2840 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002841 struct ieee802_11_elems elems;
2842
2843 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2844 data->assoc_info.resp_ies_len,
2845 &elems, 0) == ParseFailed ||
2846 !elems.owe_dh)
2847 goto no_pfs;
2848 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2849 elems.owe_dh_len) < 0) {
2850 wpa_supplicant_deauthenticate(wpa_s,
2851 WLAN_REASON_UNSPECIFIED);
2852 return -1;
2853 }
2854
2855 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2856 }
2857no_pfs:
2858#endif /* CONFIG_DPP2 */
2859
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002860#ifdef CONFIG_IEEE80211R
2861#ifdef CONFIG_SME
2862 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002863 if (!bssid_known ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002864 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2865 data->assoc_info.resp_ies,
2866 data->assoc_info.resp_ies_len,
2867 bssid) < 0) {
2868 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2869 "Reassociation Response failed");
2870 wpa_supplicant_deauthenticate(
2871 wpa_s, WLAN_REASON_INVALID_IE);
2872 return -1;
2873 }
2874 }
2875
2876 p = data->assoc_info.resp_ies;
2877 l = data->assoc_info.resp_ies_len;
2878
2879#ifdef CONFIG_WPS_STRICT
2880 if (p && wpa_s->current_ssid &&
2881 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2882 struct wpabuf *wps;
2883 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2884 if (wps == NULL) {
2885 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2886 "include WPS IE in (Re)Association Response");
2887 return -1;
2888 }
2889
2890 if (wps_validate_assoc_resp(wps) < 0) {
2891 wpabuf_free(wps);
2892 wpa_supplicant_deauthenticate(
2893 wpa_s, WLAN_REASON_INVALID_IE);
2894 return -1;
2895 }
2896 wpabuf_free(wps);
2897 }
2898#endif /* CONFIG_WPS_STRICT */
2899
2900 /* Go through the IEs and make a copy of the MDIE, if present. */
2901 while (p && l >= 2) {
2902 len = p[1] + 2;
2903 if (len > l) {
2904 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2905 p, l);
2906 break;
2907 }
2908 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2909 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2910 wpa_s->sme.ft_used = 1;
2911 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2912 MOBILITY_DOMAIN_ID_LEN);
2913 break;
2914 }
2915 l -= len;
2916 p += len;
2917 }
2918#endif /* CONFIG_SME */
2919
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002920 /* Process FT when SME is in the driver */
2921 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2922 wpa_ft_is_completed(wpa_s->wpa)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002923 if (!bssid_known ||
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002924 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2925 data->assoc_info.resp_ies,
2926 data->assoc_info.resp_ies_len,
2927 bssid) < 0) {
2928 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2929 "Reassociation Response failed");
2930 wpa_supplicant_deauthenticate(
2931 wpa_s, WLAN_REASON_INVALID_IE);
2932 return -1;
2933 }
2934 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2935 }
2936
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002937 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2938 data->assoc_info.resp_ies_len);
2939#endif /* CONFIG_IEEE80211R */
2940
Hai Shalom899fcc72020-10-19 14:38:18 -07002941 if (bssid_known)
2942 wpas_handle_assoc_resp_mscs(wpa_s, bssid,
2943 data->assoc_info.resp_ies,
2944 data->assoc_info.resp_ies_len);
2945
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002946 /* WPA/RSN IE from Beacon/ProbeResp */
2947 p = data->assoc_info.beacon_ies;
2948 l = data->assoc_info.beacon_ies_len;
2949
2950 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2951 */
2952 wpa_found = rsn_found = 0;
2953 while (p && l >= 2) {
2954 len = p[1] + 2;
2955 if (len > l) {
2956 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2957 p, l);
2958 break;
2959 }
2960 if (!wpa_found &&
2961 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2962 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2963 wpa_found = 1;
2964 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2965 }
2966
2967 if (!rsn_found &&
2968 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2969 rsn_found = 1;
2970 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2971 }
2972
Hai Shalomc3565922019-10-28 11:58:20 -07002973 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
2974 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
2975
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002976 l -= len;
2977 p += len;
2978 }
2979
2980 if (!wpa_found && data->assoc_info.beacon_ies)
2981 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002982 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002983 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002984 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
2985 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002986 if (wpa_found || rsn_found)
2987 wpa_s->ap_ies_from_associnfo = 1;
2988
Jouni Malinen87fd2792011-05-16 18:35:42 +03002989 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2990 wpa_s->assoc_freq != data->assoc_info.freq) {
2991 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2992 "%u to %u MHz",
2993 wpa_s->assoc_freq, data->assoc_info.freq);
2994 wpa_supplicant_update_scan_results(wpa_s);
2995 }
2996
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002997 wpa_s->assoc_freq = data->assoc_info.freq;
2998
2999 return 0;
3000}
3001
3002
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003003static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3004{
Hai Shalomc3565922019-10-28 11:58:20 -07003005 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003006
3007 if (!wpa_s->current_bss || !wpa_s->current_ssid)
3008 return -1;
3009
3010 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3011 return 0;
3012
3013 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3014 WPA_IE_VENDOR_TYPE);
3015 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07003016 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003017
3018 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3019 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3020 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07003021 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3022 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3023 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003024 return -1;
3025
3026 return 0;
3027}
3028
3029
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003030static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3031 union wpa_event_data *data)
3032{
3033#ifdef CONFIG_FST
3034 struct assoc_info *ai = data ? &data->assoc_info : NULL;
3035 struct wpa_bss *bss = wpa_s->current_bss;
3036 const u8 *ieprb, *iebcn;
3037
3038 wpabuf_free(wpa_s->received_mb_ies);
3039 wpa_s->received_mb_ies = NULL;
3040
3041 if (ai &&
3042 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3043 wpa_printf(MSG_DEBUG,
3044 "FST: MB IEs updated from Association Response frame");
3045 return;
3046 }
3047
3048 if (ai &&
3049 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3050 wpa_printf(MSG_DEBUG,
3051 "FST: MB IEs updated from association event Beacon IEs");
3052 return;
3053 }
3054
3055 if (!bss)
3056 return;
3057
3058 ieprb = (const u8 *) (bss + 1);
3059 iebcn = ieprb + bss->ie_len;
3060
3061 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3062 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3063 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3064 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3065#endif /* CONFIG_FST */
3066}
3067
3068
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003069static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
3070 union wpa_event_data *data)
3071{
3072 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003073 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003074 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07003075#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3076 struct wpa_bss *bss;
3077#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003078
3079#ifdef CONFIG_AP
3080 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003081 if (!data)
3082 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003083 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
3084 data->assoc_info.addr,
3085 data->assoc_info.req_ies,
3086 data->assoc_info.req_ies_len,
3087 data->assoc_info.reassoc);
3088 return;
3089 }
3090#endif /* CONFIG_AP */
3091
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003092 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07003093 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003094
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003095 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
3096 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
3097 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003098 /*
3099 * FILS authentication can share the same mechanism to mark the
3100 * connection fully authenticated, so set ft_completed also based on
3101 * FILS result.
3102 */
3103 if (!ft_completed)
3104 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003105
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003106 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
3107 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003108 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003109 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3110 return;
3111 }
3112
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003113 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003114 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003115 if (os_reltime_initialized(&wpa_s->session_start)) {
3116 os_reltime_age(&wpa_s->session_start,
3117 &wpa_s->session_length);
3118 wpa_s->session_start.sec = 0;
3119 wpa_s->session_start.usec = 0;
3120 wpas_notify_session_length(wpa_s);
3121 } else {
3122 wpas_notify_auth_changed(wpa_s);
3123 os_get_reltime(&wpa_s->session_start);
3124 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003125 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3126 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003127 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003128 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003129 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3130 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003131 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003132
3133 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3134 wpa_clear_keys(wpa_s, bssid);
3135 }
3136 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003137 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003138 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3139 return;
3140 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003141 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003142
Hai Shalomfdcde762020-04-02 11:19:20 -07003143 multi_ap_set_4addr_mode(wpa_s);
3144
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003145 if (wpa_s->conf->ap_scan == 1 &&
3146 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003147 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3148 wpa_msg(wpa_s, MSG_WARNING,
3149 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003150 }
3151
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003152 wpas_fst_update_mb_assoc(wpa_s, data);
3153
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154#ifdef CONFIG_SME
3155 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3156 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003157 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003158#endif /* CONFIG_SME */
3159
3160 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3161 if (wpa_s->current_ssid) {
3162 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3163 * initialized before association, but for other modes,
3164 * initialize PC/SC here, if the current configuration needs
3165 * smartcard or SIM/USIM. */
3166 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3167 }
3168 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3169 if (wpa_s->l2)
3170 l2_packet_notify_auth_start(wpa_s->l2);
3171
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003172 already_authorized = data && data->assoc_info.authorized;
3173
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003174 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003175 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003176 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3177 * state machine may transit to AUTHENTICATING state based on obsolete
3178 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3179 * AUTHENTICATED without ever giving chance to EAP state machine to
3180 * reset the state.
3181 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003182 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003183 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3184 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003185 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003186 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3187 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3188 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003189 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003190 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003191 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003192 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003193 wpa_s->eapol_received = 0;
3194 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3195 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3196 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003197 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003198 if (wpa_s->current_ssid &&
3199 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003200 (wpa_s->drv_flags &
3201 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3202 /*
3203 * Set the key after having received joined-IBSS event
3204 * from the driver.
3205 */
3206 wpa_supplicant_set_wpa_none_key(wpa_s,
3207 wpa_s->current_ssid);
3208 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003209 wpa_supplicant_cancel_auth_timeout(wpa_s);
3210 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3211 } else if (!ft_completed) {
3212 /* Timeout for receiving the first EAPOL packet */
3213 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3214 }
3215 wpa_supplicant_cancel_scan(wpa_s);
3216
Hai Shalom5f92bc92019-04-18 11:54:11 -07003217 if (ft_completed) {
3218 /*
3219 * FT protocol completed - make sure EAPOL state machine ends
3220 * up in authenticated.
3221 */
3222 wpa_supplicant_cancel_auth_timeout(wpa_s);
3223 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003224 eapol_sm_notify_portValid(wpa_s->eapol, true);
3225 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003226 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3227 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003228 /*
3229 * We are done; the driver will take care of RSN 4-way
3230 * handshake.
3231 */
3232 wpa_supplicant_cancel_auth_timeout(wpa_s);
3233 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003234 eapol_sm_notify_portValid(wpa_s->eapol, true);
3235 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003236 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003237 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3238 /*
3239 * The driver will take care of RSN 4-way handshake, so we need
3240 * to allow EAPOL supplicant to complete its work without
3241 * waiting for WPA supplicant.
3242 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003243 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003244 }
3245
Jouni Malinena05074c2012-12-21 21:35:35 +02003246 wpa_s->last_eapol_matches_bssid = 0;
3247
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003248#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003249 if (wpa_s->rsne_override_eapol) {
3250 wpa_printf(MSG_DEBUG,
3251 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3252 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3253 wpabuf_head(wpa_s->rsne_override_eapol),
3254 wpabuf_len(wpa_s->rsne_override_eapol));
3255 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003256 if (wpa_s->rsnxe_override_eapol) {
3257 wpa_printf(MSG_DEBUG,
3258 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3259 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3260 wpabuf_head(wpa_s->rsnxe_override_eapol),
3261 wpabuf_len(wpa_s->rsnxe_override_eapol));
3262 }
3263#endif /* CONFIG_TESTING_OPTIONS */
3264
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003265 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003266 struct os_reltime now, age;
3267 os_get_reltime(&now);
3268 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003269 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003270 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3271 0) {
3272 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3273 "frame that was received just before "
3274 "association notification");
3275 wpa_supplicant_rx_eapol(
3276 wpa_s, wpa_s->pending_eapol_rx_src,
3277 wpabuf_head(wpa_s->pending_eapol_rx),
3278 wpabuf_len(wpa_s->pending_eapol_rx));
3279 }
3280 wpabuf_free(wpa_s->pending_eapol_rx);
3281 wpa_s->pending_eapol_rx = NULL;
3282 }
3283
Hai Shalomfdcde762020-04-02 11:19:20 -07003284#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003285 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3286 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003287 wpa_s->current_ssid &&
3288 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003289 /* Set static WEP keys again */
3290 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3291 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003292#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003293
3294#ifdef CONFIG_IBSS_RSN
3295 if (wpa_s->current_ssid &&
3296 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3297 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3298 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3299 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003300 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003301 if (!wpa_s->ibss_rsn) {
3302 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3303 wpa_supplicant_deauthenticate(
3304 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3305 return;
3306 }
3307
3308 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3309 }
3310#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003311
3312 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003313
3314 if (data) {
3315 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3316 data->assoc_info.resp_ies_len,
3317 &data->assoc_info.wmm_params);
3318
3319 if (wpa_s->reassoc_same_bss)
3320 wmm_ac_restore_tspecs(wpa_s);
3321 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003322
Hai Shalomc3565922019-10-28 11:58:20 -07003323#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3324 bss = wpa_bss_get_bssid(wpa_s, bssid);
3325#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003326#ifdef CONFIG_FILS
3327 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003328 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3329
3330 if (fils_cache_id)
3331 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3332 }
3333#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003334
3335#ifdef CONFIG_MBO
3336 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3337#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003338
3339#ifdef CONFIG_DPP2
3340 wpa_s->dpp_pfs_fallback = 0;
3341#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003342}
3343
3344
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003345static int disconnect_reason_recoverable(u16 reason_code)
3346{
3347 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3348 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3349 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3350}
3351
3352
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003353static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003354 u16 reason_code,
3355 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003356{
3357 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003358
3359 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3360 /*
3361 * At least Host AP driver and a Prism3 card seemed to be
3362 * generating streams of disconnected events when configuring
3363 * IBSS for WPA-None. Ignore them for now.
3364 */
3365 return;
3366 }
3367
3368 bssid = wpa_s->bssid;
3369 if (is_zero_ether_addr(bssid))
3370 bssid = wpa_s->pending_bssid;
3371
3372 if (!is_zero_ether_addr(bssid) ||
3373 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3374 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3375 " reason=%d%s",
3376 MAC2STR(bssid), reason_code,
3377 locally_generated ? " locally_generated=1" : "");
3378 }
3379}
3380
3381
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003382static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3383 int locally_generated)
3384{
3385 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003386 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003387 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3388 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003389 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003390
3391 /*
3392 * It looks like connection was lost while trying to go through PSK
3393 * 4-way handshake. Filter out known disconnection cases that are caused
3394 * by something else than PSK mismatch to avoid confusing reports.
3395 */
3396
3397 if (locally_generated) {
3398 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3399 return 0;
3400 }
3401
3402 return 1;
3403}
3404
3405
Jouni Malinen2b89da82012-08-31 22:04:41 +03003406static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3407 u16 reason_code,
3408 int locally_generated)
3409{
3410 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003411 int authenticating;
3412 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003413 struct wpa_bss *fast_reconnect = NULL;
3414 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003415 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003416 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003417
3418 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3419 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3420
3421 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3422 /*
3423 * At least Host AP driver and a Prism3 card seemed to be
3424 * generating streams of disconnected events when configuring
3425 * IBSS for WPA-None. Ignore them for now.
3426 */
3427 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3428 "IBSS/WPA-None mode");
3429 return;
3430 }
3431
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003432 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3433 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3434 locally_generated)
3435 /*
3436 * Remove the inactive AP (which is probably out of range) from
3437 * the BSS list after marking disassociation. In particular
3438 * mac80211-based drivers use the
3439 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3440 * locally generated disconnection events for cases where the
3441 * AP does not reply anymore.
3442 */
3443 curr = wpa_s->current_bss;
3444
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003445 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003446 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3447 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003448 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3449 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003450 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003451#ifdef CONFIG_DPP2
3452 wpas_dpp_send_conn_status_result(wpa_s,
3453 DPP_STATUS_AUTH_FAILURE);
3454#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003455 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003456 if (!wpa_s->disconnected &&
3457 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003458 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003459 wpas_wps_searching(wpa_s) ||
3460 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003461 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003462 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003463 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003464 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003465 wpa_s->wpa_state);
3466 if (wpa_s->wpa_state == WPA_COMPLETED &&
3467 wpa_s->current_ssid &&
3468 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003469 (wpa_s->own_reconnect_req ||
3470 (!locally_generated &&
3471 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003472 /*
3473 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003474 * us, but could allow us to get back in. This is also
3475 * triggered for cases where local reconnection request
3476 * is used to force reassociation with the same BSS.
3477 * Try to reconnect to the same BSS without a full scan
3478 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003479 */
3480 fast_reconnect = wpa_s->current_bss;
3481 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003482 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003483 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003484 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003485 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3486 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003487 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003488 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003489 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003490 "try to re-connect");
3491 wpa_s->reassociate = 0;
3492 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003493 if (!wpa_s->pno)
3494 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003495 }
3496 bssid = wpa_s->bssid;
3497 if (is_zero_ether_addr(bssid))
3498 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003499 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3500 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003501 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003502 if (locally_generated)
3503 wpa_s->disconnect_reason = -reason_code;
3504 else
3505 wpa_s->disconnect_reason = reason_code;
3506 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003507 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3508 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003509 wpa_clear_keys(wpa_s, wpa_s->bssid);
3510 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003511 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003512 wpa_supplicant_mark_disassoc(wpa_s);
3513
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003514 if (curr)
3515 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3516
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003517 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003518 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003519 wpa_s->current_ssid = last_ssid;
3520 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003521
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003522 if (fast_reconnect &&
3523 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3524 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3525 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3526 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003527 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003528 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003529#ifndef CONFIG_NO_SCAN_PROCESSING
3530 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3531 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3532 fast_reconnect_ssid) < 0) {
3533 /* Recover through full scan */
3534 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3535 }
3536#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003537 } else if (fast_reconnect) {
3538 /*
3539 * Could not reconnect to the same BSS due to network being
3540 * disabled. Use a new scan to match the alternative behavior
3541 * above, i.e., to continue automatic reconnection attempt in a
3542 * way that enforces disabled network rules.
3543 */
3544 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003545 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003546}
3547
3548
3549#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003550void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003551{
3552 struct wpa_supplicant *wpa_s = eloop_ctx;
3553
3554 if (!wpa_s->pending_mic_error_report)
3555 return;
3556
3557 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3558 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3559 wpa_s->pending_mic_error_report = 0;
3560}
3561#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3562
3563
3564static void
3565wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3566 union wpa_event_data *data)
3567{
3568 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003569 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003570
3571 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3572 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003573 os_get_reltime(&t);
3574 if ((wpa_s->last_michael_mic_error.sec &&
3575 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003576 wpa_s->pending_mic_error_report) {
3577 if (wpa_s->pending_mic_error_report) {
3578 /*
3579 * Send the pending MIC error report immediately since
3580 * we are going to start countermeasures and AP better
3581 * do the same.
3582 */
3583 wpa_sm_key_request(wpa_s->wpa, 1,
3584 wpa_s->pending_mic_error_pairwise);
3585 }
3586
3587 /* Send the new MIC error report immediately since we are going
3588 * to start countermeasures and AP better do the same.
3589 */
3590 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3591
3592 /* initialize countermeasures */
3593 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003594
3595 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3596
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003597 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3598
3599 /*
3600 * Need to wait for completion of request frame. We do not get
3601 * any callback for the message completion, so just wait a
3602 * short while and hope for the best. */
3603 os_sleep(0, 10000);
3604
3605 wpa_drv_set_countermeasures(wpa_s, 1);
3606 wpa_supplicant_deauthenticate(wpa_s,
3607 WLAN_REASON_MICHAEL_MIC_FAILURE);
3608 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3609 wpa_s, NULL);
3610 eloop_register_timeout(60, 0,
3611 wpa_supplicant_stop_countermeasures,
3612 wpa_s, NULL);
3613 /* TODO: mark the AP rejected for 60 second. STA is
3614 * allowed to associate with another AP.. */
3615 } else {
3616#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3617 if (wpa_s->mic_errors_seen) {
3618 /*
3619 * Reduce the effectiveness of Michael MIC error
3620 * reports as a means for attacking against TKIP if
3621 * more than one MIC failure is noticed with the same
3622 * PTK. We delay the transmission of the reports by a
3623 * random time between 0 and 60 seconds in order to
3624 * force the attacker wait 60 seconds before getting
3625 * the information on whether a frame resulted in a MIC
3626 * failure.
3627 */
3628 u8 rval[4];
3629 int sec;
3630
3631 if (os_get_random(rval, sizeof(rval)) < 0)
3632 sec = os_random() % 60;
3633 else
3634 sec = WPA_GET_BE32(rval) % 60;
3635 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3636 "report %d seconds", sec);
3637 wpa_s->pending_mic_error_report = 1;
3638 wpa_s->pending_mic_error_pairwise = pairwise;
3639 eloop_cancel_timeout(
3640 wpa_supplicant_delayed_mic_error_report,
3641 wpa_s, NULL);
3642 eloop_register_timeout(
3643 sec, os_random() % 1000000,
3644 wpa_supplicant_delayed_mic_error_report,
3645 wpa_s, NULL);
3646 } else {
3647 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3648 }
3649#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3650 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3651#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3652 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003653 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003654 wpa_s->mic_errors_seen++;
3655}
3656
3657
3658#ifdef CONFIG_TERMINATE_ONLASTIF
3659static int any_interfaces(struct wpa_supplicant *head)
3660{
3661 struct wpa_supplicant *wpa_s;
3662
3663 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3664 if (!wpa_s->interface_removed)
3665 return 1;
3666 return 0;
3667}
3668#endif /* CONFIG_TERMINATE_ONLASTIF */
3669
3670
3671static void
3672wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3673 union wpa_event_data *data)
3674{
3675 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3676 return;
3677
3678 switch (data->interface_status.ievent) {
3679 case EVENT_INTERFACE_ADDED:
3680 if (!wpa_s->interface_removed)
3681 break;
3682 wpa_s->interface_removed = 0;
3683 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3684 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3685 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3686 "driver after interface was added");
3687 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003688
3689#ifdef CONFIG_P2P
3690 if (!wpa_s->global->p2p &&
3691 !wpa_s->global->p2p_disabled &&
3692 !wpa_s->conf->p2p_disabled &&
3693 (wpa_s->drv_flags &
3694 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3695 wpas_p2p_add_p2pdev_interface(
3696 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3697 wpa_printf(MSG_INFO,
3698 "P2P: Failed to enable P2P Device interface");
3699 /* Try to continue without. P2P will be disabled. */
3700 }
3701#endif /* CONFIG_P2P */
3702
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003703 break;
3704 case EVENT_INTERFACE_REMOVED:
3705 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3706 wpa_s->interface_removed = 1;
3707 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003708 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003709 l2_packet_deinit(wpa_s->l2);
3710 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003711
3712#ifdef CONFIG_P2P
3713 if (wpa_s->global->p2p &&
3714 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3715 (wpa_s->drv_flags &
3716 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3717 wpa_dbg(wpa_s, MSG_DEBUG,
3718 "Removing P2P Device interface");
3719 wpa_supplicant_remove_iface(
3720 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3721 0);
3722 wpa_s->global->p2p_init_wpa_s = NULL;
3723 }
3724#endif /* CONFIG_P2P */
3725
Dmitry Shmidte4663042016-04-04 10:07:49 -07003726#ifdef CONFIG_MATCH_IFACE
3727 if (wpa_s->matched) {
3728 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3729 break;
3730 }
3731#endif /* CONFIG_MATCH_IFACE */
3732
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003733#ifdef CONFIG_TERMINATE_ONLASTIF
3734 /* check if last interface */
3735 if (!any_interfaces(wpa_s->global->ifaces))
3736 eloop_terminate();
3737#endif /* CONFIG_TERMINATE_ONLASTIF */
3738 break;
3739 }
3740}
3741
3742
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003743#ifdef CONFIG_TDLS
3744static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3745 union wpa_event_data *data)
3746{
3747 if (data == NULL)
3748 return;
3749 switch (data->tdls.oper) {
3750 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003751 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3752 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3753 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3754 else
3755 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003756 break;
3757 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003758 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3759 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3760 data->tdls.reason_code);
3761 else
3762 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3763 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003764 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003765 case TDLS_REQUEST_DISCOVER:
3766 wpa_tdls_send_discovery_request(wpa_s->wpa,
3767 data->tdls.peer);
3768 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003769 }
3770}
3771#endif /* CONFIG_TDLS */
3772
3773
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003774#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003775static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3776 union wpa_event_data *data)
3777{
3778 if (data == NULL)
3779 return;
3780 switch (data->wnm.oper) {
3781 case WNM_OPER_SLEEP:
3782 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3783 "(action=%d, intval=%d)",
3784 data->wnm.sleep_action, data->wnm.sleep_intval);
3785 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003786 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003787 break;
3788 }
3789}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003790#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003791
3792
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003793#ifdef CONFIG_IEEE80211R
3794static void
3795wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3796 union wpa_event_data *data)
3797{
3798 if (data == NULL)
3799 return;
3800
3801 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3802 data->ft_ies.ies_len,
3803 data->ft_ies.ft_action,
3804 data->ft_ies.target_ap,
3805 data->ft_ies.ric_ies,
3806 data->ft_ies.ric_ies_len) < 0) {
3807 /* TODO: prevent MLME/driver from trying to associate? */
3808 }
3809}
3810#endif /* CONFIG_IEEE80211R */
3811
3812
3813#ifdef CONFIG_IBSS_RSN
3814static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3815 union wpa_event_data *data)
3816{
3817 struct wpa_ssid *ssid;
3818 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3819 return;
3820 if (data == NULL)
3821 return;
3822 ssid = wpa_s->current_ssid;
3823 if (ssid == NULL)
3824 return;
3825 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3826 return;
3827
3828 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3829}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003830
3831
3832static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3833 union wpa_event_data *data)
3834{
3835 struct wpa_ssid *ssid = wpa_s->current_ssid;
3836
3837 if (ssid == NULL)
3838 return;
3839
3840 /* check if the ssid is correctly configured as IBSS/RSN */
3841 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3842 return;
3843
3844 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3845 data->rx_mgmt.frame_len);
3846}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003847#endif /* CONFIG_IBSS_RSN */
3848
3849
3850#ifdef CONFIG_IEEE80211R
3851static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3852 size_t len)
3853{
3854 const u8 *sta_addr, *target_ap_addr;
3855 u16 status;
3856
3857 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3858 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3859 return; /* only SME case supported for now */
3860 if (len < 1 + 2 * ETH_ALEN + 2)
3861 return;
3862 if (data[0] != 2)
3863 return; /* Only FT Action Response is supported for now */
3864 sta_addr = data + 1;
3865 target_ap_addr = data + 1 + ETH_ALEN;
3866 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3867 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3868 MACSTR " TargetAP " MACSTR " status %u",
3869 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3870
3871 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3872 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3873 " in FT Action Response", MAC2STR(sta_addr));
3874 return;
3875 }
3876
3877 if (status) {
3878 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3879 "failure (status code %d)", status);
3880 /* TODO: report error to FT code(?) */
3881 return;
3882 }
3883
3884 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3885 len - (1 + 2 * ETH_ALEN + 2), 1,
3886 target_ap_addr, NULL, 0) < 0)
3887 return;
3888
3889#ifdef CONFIG_SME
3890 {
3891 struct wpa_bss *bss;
3892 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3893 if (bss)
3894 wpa_s->sme.freq = bss->freq;
3895 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3896 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3897 WLAN_AUTH_FT);
3898 }
3899#endif /* CONFIG_SME */
3900}
3901#endif /* CONFIG_IEEE80211R */
3902
3903
3904static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3905 struct unprot_deauth *e)
3906{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003907 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3908 "dropped: " MACSTR " -> " MACSTR
3909 " (reason code %u)",
3910 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3911 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003912}
3913
3914
3915static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3916 struct unprot_disassoc *e)
3917{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003918 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3919 "dropped: " MACSTR " -> " MACSTR
3920 " (reason code %u)",
3921 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3922 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003923}
3924
3925
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003926static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3927 u16 reason_code, int locally_generated,
3928 const u8 *ie, size_t ie_len, int deauth)
3929{
3930#ifdef CONFIG_AP
3931 if (wpa_s->ap_iface && addr) {
3932 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3933 return;
3934 }
3935
3936 if (wpa_s->ap_iface) {
3937 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3938 return;
3939 }
3940#endif /* CONFIG_AP */
3941
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003942 if (!locally_generated)
3943 wpa_s->own_disconnect_req = 0;
3944
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003945 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3946
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003947 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3948 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3949 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3950 eapol_sm_failed(wpa_s->eapol))) &&
3951 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003952 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003953
3954#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003955 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003956 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3957 locally_generated) > 0) {
3958 /*
3959 * The interface was removed, so cannot continue
3960 * processing any additional operations after this.
3961 */
3962 return;
3963 }
3964 }
3965#endif /* CONFIG_P2P */
3966
3967 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3968 locally_generated);
3969}
3970
3971
3972static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3973 struct disassoc_info *info)
3974{
3975 u16 reason_code = 0;
3976 int locally_generated = 0;
3977 const u8 *addr = NULL;
3978 const u8 *ie = NULL;
3979 size_t ie_len = 0;
3980
3981 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3982
3983 if (info) {
3984 addr = info->addr;
3985 ie = info->ie;
3986 ie_len = info->ie_len;
3987 reason_code = info->reason_code;
3988 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07003989 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
3990 reason2str(reason_code),
3991 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003992 if (addr)
3993 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3994 MAC2STR(addr));
3995 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3996 ie, ie_len);
3997 }
3998
3999#ifdef CONFIG_AP
4000 if (wpa_s->ap_iface && info && info->addr) {
4001 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
4002 return;
4003 }
4004
4005 if (wpa_s->ap_iface) {
4006 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
4007 return;
4008 }
4009#endif /* CONFIG_AP */
4010
4011#ifdef CONFIG_P2P
4012 if (info) {
4013 wpas_p2p_disassoc_notif(
4014 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
4015 locally_generated);
4016 }
4017#endif /* CONFIG_P2P */
4018
4019 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4020 sme_event_disassoc(wpa_s, info);
4021
4022 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
4023 ie, ie_len, 0);
4024}
4025
4026
4027static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
4028 struct deauth_info *info)
4029{
4030 u16 reason_code = 0;
4031 int locally_generated = 0;
4032 const u8 *addr = NULL;
4033 const u8 *ie = NULL;
4034 size_t ie_len = 0;
4035
4036 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
4037
4038 if (info) {
4039 addr = info->addr;
4040 ie = info->ie;
4041 ie_len = info->ie_len;
4042 reason_code = info->reason_code;
4043 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07004044 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
4045 reason_code, reason2str(reason_code),
4046 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004047 if (addr) {
4048 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
4049 MAC2STR(addr));
4050 }
4051 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
4052 ie, ie_len);
4053 }
4054
4055 wpa_reset_ft_completed(wpa_s->wpa);
4056
4057 wpas_event_disconnect(wpa_s, addr, reason_code,
4058 locally_generated, ie, ie_len, 1);
4059}
4060
4061
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004062static const char * reg_init_str(enum reg_change_initiator init)
4063{
4064 switch (init) {
4065 case REGDOM_SET_BY_CORE:
4066 return "CORE";
4067 case REGDOM_SET_BY_USER:
4068 return "USER";
4069 case REGDOM_SET_BY_DRIVER:
4070 return "DRIVER";
4071 case REGDOM_SET_BY_COUNTRY_IE:
4072 return "COUNTRY_IE";
4073 case REGDOM_BEACON_HINT:
4074 return "BEACON_HINT";
4075 }
4076 return "?";
4077}
4078
4079
4080static const char * reg_type_str(enum reg_type type)
4081{
4082 switch (type) {
4083 case REGDOM_TYPE_UNKNOWN:
4084 return "UNKNOWN";
4085 case REGDOM_TYPE_COUNTRY:
4086 return "COUNTRY";
4087 case REGDOM_TYPE_WORLD:
4088 return "WORLD";
4089 case REGDOM_TYPE_CUSTOM_WORLD:
4090 return "CUSTOM_WORLD";
4091 case REGDOM_TYPE_INTERSECTION:
4092 return "INTERSECTION";
4093 }
4094 return "?";
4095}
4096
4097
Hai Shalom74f70d42019-02-11 14:42:39 -08004098void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
4099 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004100{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004101 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004102 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004103
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004104 /*
4105 * To allow backwards compatibility with higher level layers that
4106 * assumed the REGDOM_CHANGE event is sent over the initially added
4107 * interface. Find the highest parent of this interface and use it to
4108 * send the event.
4109 */
4110 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
4111 ;
4112
Hai Shalom74f70d42019-02-11 14:42:39 -08004113 if (info) {
4114 wpa_msg(ifs, MSG_INFO,
4115 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4116 reg_init_str(info->initiator), reg_type_str(info->type),
4117 info->alpha2[0] ? " alpha2=" : "",
4118 info->alpha2[0] ? info->alpha2 : "");
4119 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004120
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004121 if (wpa_s->drv_priv == NULL)
4122 return; /* Ignore event during drv initialization */
4123
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004124 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4125 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004126 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4127 ifs->ifname);
4128 free_hw_features(ifs);
4129 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004130 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004131
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004132 /* Restart PNO/sched_scan with updated channel list */
4133 if (ifs->pno) {
4134 wpas_stop_pno(ifs);
4135 wpas_start_pno(ifs);
4136 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4137 wpa_dbg(ifs, MSG_DEBUG,
4138 "Channel list changed - restart sched_scan");
4139 wpas_scan_restart_sched_scan(ifs);
4140 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004141 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004142
4143 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004144}
4145
4146
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004147static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004148 const u8 *frame, size_t len, int freq,
4149 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004150{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004151 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004152 const u8 *payload;
4153 size_t plen;
4154 u8 category;
4155
4156 if (len < IEEE80211_HDRLEN + 2)
4157 return;
4158
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004159 mgmt = (const struct ieee80211_mgmt *) frame;
4160 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004161 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004162 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004163
4164 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4165 " Category=%u DataLen=%d freq=%d MHz",
4166 MAC2STR(mgmt->sa), category, (int) plen, freq);
4167
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004168 if (category == WLAN_ACTION_WMM) {
4169 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4170 return;
4171 }
4172
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004173#ifdef CONFIG_IEEE80211R
4174 if (category == WLAN_ACTION_FT) {
4175 ft_rx_action(wpa_s, payload, plen);
4176 return;
4177 }
4178#endif /* CONFIG_IEEE80211R */
4179
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004180#ifdef CONFIG_SME
4181 if (category == WLAN_ACTION_SA_QUERY) {
4182 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
4183 return;
4184 }
4185#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004186
4187#ifdef CONFIG_WNM
4188 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4189 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4190 return;
4191 }
4192#endif /* CONFIG_WNM */
4193
4194#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004195 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4196 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004197 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004198 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004199 payload, plen, freq) == 0)
4200 return;
4201#endif /* CONFIG_GAS */
4202
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004203#ifdef CONFIG_GAS_SERVER
4204 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4205 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4206 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4207 mgmt->u.action.category,
4208 payload, plen, freq) == 0)
4209 return;
4210#endif /* CONFIG_GAS_SERVER */
4211
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004212#ifdef CONFIG_TDLS
4213 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4214 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4215 wpa_dbg(wpa_s, MSG_DEBUG,
4216 "TDLS: Received Discovery Response from " MACSTR,
4217 MAC2STR(mgmt->sa));
4218 return;
4219 }
4220#endif /* CONFIG_TDLS */
4221
4222#ifdef CONFIG_INTERWORKING
4223 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4224 payload[0] == QOS_QOS_MAP_CONFIG) {
4225 const u8 *pos = payload + 1;
4226 size_t qlen = plen - 1;
4227 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4228 MACSTR, MAC2STR(mgmt->sa));
4229 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4230 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4231 pos[1] <= qlen - 2 && pos[1] >= 16)
4232 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4233 return;
4234 }
4235#endif /* CONFIG_INTERWORKING */
4236
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004237 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004238 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4239 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004240 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004241 payload + 1,
4242 plen - 1);
4243 return;
4244 }
4245
4246 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004247 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4248 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4249 return;
4250 }
4251
4252 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4253 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4254 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4255 payload + 1, plen - 1,
4256 rssi);
4257 return;
4258 }
4259
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004260#ifdef CONFIG_FST
4261 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4262 fst_rx_action(wpa_s->fst, mgmt, len);
4263 return;
4264 }
4265#endif /* CONFIG_FST */
4266
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004267#ifdef CONFIG_DPP
4268 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4269 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4270 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4271 payload[4] == DPP_OUI_TYPE) {
4272 payload++;
4273 plen--;
4274 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4275 return;
4276 }
4277#endif /* CONFIG_DPP */
4278
Hai Shalom899fcc72020-10-19 14:38:18 -07004279 if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
4280 payload[0] == ROBUST_AV_MSCS_RESP) {
4281 wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
4282 payload + 1, plen - 1);
4283 return;
4284 }
4285
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004286 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4287 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004288 if (wpa_s->ifmsh)
4289 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004290}
4291
4292
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004293static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4294 union wpa_event_data *event)
4295{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004296 struct wpa_freq_range_list *list;
4297 char *str = NULL;
4298
4299 list = &event->freq_range;
4300
4301 if (list->num)
4302 str = freq_range_list_str(list);
4303 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4304 str ? str : "");
4305
4306#ifdef CONFIG_P2P
4307 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4308 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4309 __func__);
4310 } else {
4311 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004312
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004313 /*
4314 * The update channel flow will also take care of moving a GO
4315 * from the unsafe frequency if needed.
4316 */
4317 wpas_p2p_update_channel_list(wpa_s,
4318 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004319 }
4320#endif /* CONFIG_P2P */
4321
4322 os_free(str);
4323}
4324
4325
Roshan Pius3a1667e2018-07-03 15:17:14 -07004326static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004327{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004328 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4329 wpa_supplicant_cancel_auth_timeout(wpa_s);
4330 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004331 eapol_sm_notify_portValid(wpa_s->eapol, true);
4332 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004333 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004334 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004335}
4336
4337
4338static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4339 int freq)
4340{
4341 size_t i;
4342 int j;
4343
4344 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4345 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4346
4347 for (j = 0; j < mode->num_channels; j++) {
4348 const struct hostapd_channel_data *chan;
4349
4350 chan = &mode->channels[j];
4351 if (chan->freq == freq)
4352 return chan->dfs_cac_ms;
4353 }
4354 }
4355
4356 return 0;
4357}
4358
4359
4360static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4361 struct dfs_event *radar)
4362{
4363#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004364 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004365 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4366 } else
4367#endif /* NEED_AP_MLME && CONFIG_AP */
4368 {
4369 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4370
4371 cac_time /= 1000; /* convert from ms to sec */
4372 if (!cac_time)
4373 cac_time = 10 * 60; /* max timeout: 10 minutes */
4374
4375 /* Restart auth timeout: CAC time added to initial timeout */
4376 wpas_auth_timeout_restart(wpa_s, cac_time);
4377 }
4378}
4379
4380
4381static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4382 struct dfs_event *radar)
4383{
4384#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004385 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004386 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4387 } else
4388#endif /* NEED_AP_MLME && CONFIG_AP */
4389 {
4390 /* Restart auth timeout with original value after CAC is
4391 * finished */
4392 wpas_auth_timeout_restart(wpa_s, 0);
4393 }
4394}
4395
4396
4397static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4398 struct dfs_event *radar)
4399{
4400#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004401 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004402 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4403 } else
4404#endif /* NEED_AP_MLME && CONFIG_AP */
4405 {
4406 /* Restart auth timeout with original value after CAC is
4407 * aborted */
4408 wpas_auth_timeout_restart(wpa_s, 0);
4409 }
4410}
4411
4412
4413static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4414 union wpa_event_data *data)
4415{
4416 wpa_dbg(wpa_s, MSG_DEBUG,
4417 "Connection authorized by device, previous state %d",
4418 wpa_s->wpa_state);
4419
4420 wpa_supplicant_event_port_authorized(wpa_s);
4421
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004422 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4423 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004424 data->assoc_info.ptk_kck_len,
4425 data->assoc_info.ptk_kek,
4426 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004427#ifdef CONFIG_FILS
4428 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4429 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4430 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4431
4432 /* Update ERP next sequence number */
4433 eapol_sm_update_erp_next_seq_num(
4434 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4435
4436 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4437 /* Add the new PMK and PMKID to the PMKSA cache */
4438 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4439 data->assoc_info.fils_pmk,
4440 data->assoc_info.fils_pmk_len,
4441 data->assoc_info.fils_pmkid,
4442 wpa_s->bssid, fils_cache_id);
4443 } else if (data->assoc_info.fils_pmkid) {
4444 /* Update the current PMKSA used for this connection */
4445 pmksa_cache_set_current(wpa_s->wpa,
4446 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004447 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004448 }
4449 }
4450#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004451}
4452
4453
Roshan Pius3a1667e2018-07-03 15:17:14 -07004454static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4455 union wpa_event_data *data)
4456{
4457 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004458#ifdef CONFIG_MBO
4459 struct wpa_bss *reject_bss;
4460#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004461
4462 if (!bssid || is_zero_ether_addr(bssid))
4463 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004464#ifdef CONFIG_MBO
4465 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4466 reject_bss = wpa_s->current_bss;
4467 else
4468 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4469#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004470
4471 if (data->assoc_reject.bssid)
4472 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4473 "bssid=" MACSTR " status_code=%u%s%s%s",
4474 MAC2STR(data->assoc_reject.bssid),
4475 data->assoc_reject.status_code,
4476 data->assoc_reject.timed_out ? " timeout" : "",
4477 data->assoc_reject.timeout_reason ? "=" : "",
4478 data->assoc_reject.timeout_reason ?
4479 data->assoc_reject.timeout_reason : "");
4480 else
4481 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4482 "status_code=%u%s%s%s",
4483 data->assoc_reject.status_code,
4484 data->assoc_reject.timed_out ? " timeout" : "",
4485 data->assoc_reject.timeout_reason ? "=" : "",
4486 data->assoc_reject.timeout_reason ?
4487 data->assoc_reject.timeout_reason : "");
4488 wpa_s->assoc_status_code = data->assoc_reject.status_code;
Sunil Ravi972b2042020-08-14 10:50:48 -07004489 wpas_notify_assoc_status_code(wpa_s,
4490 bssid, data->assoc_reject.timed_out);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004491
4492#ifdef CONFIG_OWE
4493 if (data->assoc_reject.status_code ==
4494 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4495 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4496 wpa_s->current_ssid &&
4497 wpa_s->current_ssid->owe_group == 0 &&
4498 wpa_s->last_owe_group != 21) {
4499 struct wpa_ssid *ssid = wpa_s->current_ssid;
4500 struct wpa_bss *bss = wpa_s->current_bss;
4501
4502 if (!bss) {
4503 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4504 if (!bss) {
4505 wpas_connection_failed(wpa_s, bssid);
4506 wpa_supplicant_mark_disassoc(wpa_s);
4507 return;
4508 }
4509 }
4510 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4511 wpas_connect_work_done(wpa_s);
4512 wpa_supplicant_mark_disassoc(wpa_s);
4513 wpa_supplicant_connect(wpa_s, bss, ssid);
4514 return;
4515 }
4516#endif /* CONFIG_OWE */
4517
Hai Shalomfdcde762020-04-02 11:19:20 -07004518#ifdef CONFIG_DPP2
4519 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4520 * the status code defined in the DPP R2 tech spec.
4521 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4522 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004523 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalom899fcc72020-10-19 14:38:18 -07004524 (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
4525 ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
4526 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004527 wpa_s->current_ssid->dpp_pfs == 0 &&
4528 (data->assoc_reject.status_code ==
4529 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4530 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4531 struct wpa_ssid *ssid = wpa_s->current_ssid;
4532 struct wpa_bss *bss = wpa_s->current_bss;
4533
4534 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4535 if (!bss)
4536 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4537 if (!bss || wpa_s->dpp_pfs_fallback) {
4538 wpa_printf(MSG_DEBUG,
4539 "DPP: Updated PFS policy for next try");
4540 wpas_connection_failed(wpa_s, bssid);
4541 wpa_supplicant_mark_disassoc(wpa_s);
4542 return;
4543 }
4544 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4545 wpa_s->dpp_pfs_fallback = 1;
4546 wpas_connect_work_done(wpa_s);
4547 wpa_supplicant_mark_disassoc(wpa_s);
4548 wpa_supplicant_connect(wpa_s, bss, ssid);
4549 return;
4550 }
4551#endif /* CONFIG_DPP2 */
4552
Hai Shalom74f70d42019-02-11 14:42:39 -08004553#ifdef CONFIG_MBO
4554 if (data->assoc_reject.status_code ==
4555 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004556 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004557 const u8 *rssi_rej;
4558
4559 rssi_rej = mbo_get_attr_from_ies(
4560 data->assoc_reject.resp_ies,
4561 data->assoc_reject.resp_ies_len,
4562 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4563 if (rssi_rej && rssi_rej[1] == 2) {
4564 wpa_printf(MSG_DEBUG,
4565 "OCE: RSSI-based association rejection from "
4566 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004567 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004568 rssi_rej[2], rssi_rej[3]);
4569 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004570 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004571 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004572 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004573 }
4574 }
4575#endif /* CONFIG_MBO */
4576
Roshan Pius3a1667e2018-07-03 15:17:14 -07004577 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4578 sme_event_assoc_reject(wpa_s, data);
4579 return;
4580 }
4581
4582 /* Driver-based SME cases */
4583
4584#ifdef CONFIG_SAE
4585 if (wpa_s->current_ssid &&
4586 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4587 !data->assoc_reject.timed_out) {
4588 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4589 wpa_sm_aborted_cached(wpa_s->wpa);
4590 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4591 }
4592#endif /* CONFIG_SAE */
4593
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004594#ifdef CONFIG_DPP
4595 if (wpa_s->current_ssid &&
4596 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4597 !data->assoc_reject.timed_out) {
4598 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4599 wpa_sm_aborted_cached(wpa_s->wpa);
4600 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4601 }
4602#endif /* CONFIG_DPP */
4603
Roshan Pius3a1667e2018-07-03 15:17:14 -07004604#ifdef CONFIG_FILS
4605 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004606 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004607 eapol_sm_update_erp_next_seq_num(
4608 wpa_s->eapol,
4609 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004610 fils_connection_failure(wpa_s);
4611 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004612#endif /* CONFIG_FILS */
4613
4614 wpas_connection_failed(wpa_s, bssid);
4615 wpa_supplicant_mark_disassoc(wpa_s);
4616}
4617
4618
Hai Shalomfdcde762020-04-02 11:19:20 -07004619static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
4620 struct unprot_beacon *data)
4621{
4622 struct wpabuf *buf;
4623 int res;
4624
4625 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
4626 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
4627 return;
4628 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
4629 MAC2STR(data->sa));
4630
4631 buf = wpabuf_alloc(4);
4632 if (!buf)
4633 return;
4634
4635 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
4636 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
4637 wpabuf_put_u8(buf, 1); /* Dialog Token */
4638 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
4639
4640 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
4641 wpa_s->own_addr, wpa_s->bssid,
4642 wpabuf_head(buf), wpabuf_len(buf), 0);
4643 if (res < 0)
4644 wpa_printf(MSG_DEBUG,
4645 "Failed to send WNM-Notification Request frame");
4646
4647 wpabuf_free(buf);
4648}
4649
4650
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004651void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4652 union wpa_event_data *data)
4653{
4654 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004655 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07004656 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08004657#ifndef CONFIG_NO_STDOUT_DEBUG
4658 int level = MSG_DEBUG;
4659#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004660
4661 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4662 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004663 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004664 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004665 event != EVENT_SCHED_SCAN_STOPPED) {
4666 wpa_dbg(wpa_s, MSG_DEBUG,
4667 "Ignore event %s (%d) while interface is disabled",
4668 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004669 return;
4670 }
4671
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004672#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07004673 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004674 const struct ieee80211_hdr *hdr;
4675 u16 fc;
4676 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4677 fc = le_to_host16(hdr->frame_control);
4678 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4679 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4680 level = MSG_EXCESSIVE;
4681 }
4682
4683 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4684 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004685#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004686
4687 switch (event) {
4688 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004689#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004690 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4691 data->auth.ies_len))
4692 wpa_printf(MSG_DEBUG,
4693 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004694#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004695 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004696 wpa_s->auth_status_code = data->auth.status_code;
4697 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004698 break;
4699 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004700#ifdef CONFIG_TESTING_OPTIONS
4701 if (wpa_s->ignore_auth_resp) {
4702 wpa_printf(MSG_INFO,
4703 "EVENT_ASSOC - ignore_auth_resp active!");
4704 break;
4705 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004706 if (wpa_s->testing_resend_assoc) {
4707 wpa_printf(MSG_INFO,
4708 "EVENT_DEAUTH - testing_resend_assoc");
4709 break;
4710 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004711#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004712 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004713 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004714 if (data &&
4715 (data->assoc_info.authorized ||
4716 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4717 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004718 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004719 if (data) {
4720 wpa_msg(wpa_s, MSG_INFO,
4721 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4722 data->assoc_info.subnet_status);
4723 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004724 break;
4725 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004726 wpas_event_disassoc(wpa_s,
4727 data ? &data->disassoc_info : NULL);
4728 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004729 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004730#ifdef CONFIG_TESTING_OPTIONS
4731 if (wpa_s->ignore_auth_resp) {
4732 wpa_printf(MSG_INFO,
4733 "EVENT_DEAUTH - ignore_auth_resp active!");
4734 break;
4735 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004736 if (wpa_s->testing_resend_assoc) {
4737 wpa_printf(MSG_INFO,
4738 "EVENT_DEAUTH - testing_resend_assoc");
4739 break;
4740 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004741#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004742 wpas_event_deauth(wpa_s,
4743 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004744 break;
4745 case EVENT_MICHAEL_MIC_FAILURE:
4746 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4747 break;
4748#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004749 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004750 if (wpa_s->own_scan_requested ||
4751 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004752 struct os_reltime diff;
4753
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004754 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004755 os_reltime_sub(&wpa_s->scan_start_time,
4756 &wpa_s->scan_trigger_time, &diff);
4757 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4758 diff.sec, diff.usec);
4759 wpa_s->own_scan_requested = 0;
4760 wpa_s->own_scan_running = 1;
4761 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4762 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004763 wpa_msg_ctrl(wpa_s, MSG_INFO,
4764 WPA_EVENT_SCAN_STARTED "id=%u",
4765 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004766 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004767 wpa_msg_ctrl(wpa_s, MSG_INFO,
4768 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004769 }
4770 } else {
4771 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004772 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004773 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004774 }
4775 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004776 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004777 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4778 wpa_s->scan_res_handler = NULL;
4779 wpa_s->own_scan_running = 0;
4780 wpa_s->radio->external_scan_running = 0;
4781 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4782 break;
4783 }
4784
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004785 if (!(data && data->scan_info.external_scan) &&
4786 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004787 struct os_reltime now, diff;
4788 os_get_reltime(&now);
4789 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4790 wpa_s->scan_start_time.sec = 0;
4791 wpa_s->scan_start_time.usec = 0;
4792 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4793 diff.sec, diff.usec);
4794 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004795 if (wpa_supplicant_event_scan_results(wpa_s, data))
4796 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004797 if (!(data && data->scan_info.external_scan))
4798 wpa_s->own_scan_running = 0;
4799 if (data && data->scan_info.nl_scan_event)
4800 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004801 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004802 break;
4803#endif /* CONFIG_NO_SCAN_PROCESSING */
4804 case EVENT_ASSOCINFO:
4805 wpa_supplicant_event_associnfo(wpa_s, data);
4806 break;
4807 case EVENT_INTERFACE_STATUS:
4808 wpa_supplicant_event_interface_status(wpa_s, data);
4809 break;
4810 case EVENT_PMKID_CANDIDATE:
4811 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4812 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004813#ifdef CONFIG_TDLS
4814 case EVENT_TDLS:
4815 wpa_supplicant_event_tdls(wpa_s, data);
4816 break;
4817#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004818#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004819 case EVENT_WNM:
4820 wpa_supplicant_event_wnm(wpa_s, data);
4821 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004822#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004823#ifdef CONFIG_IEEE80211R
4824 case EVENT_FT_RESPONSE:
4825 wpa_supplicant_event_ft_response(wpa_s, data);
4826 break;
4827#endif /* CONFIG_IEEE80211R */
4828#ifdef CONFIG_IBSS_RSN
4829 case EVENT_IBSS_RSN_START:
4830 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4831 break;
4832#endif /* CONFIG_IBSS_RSN */
4833 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004834 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004835 break;
4836 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004837 /* It is possible to get this event from earlier connection */
4838 if (wpa_s->current_ssid &&
4839 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4840 wpa_dbg(wpa_s, MSG_DEBUG,
4841 "Ignore AUTH_TIMED_OUT in mesh configuration");
4842 break;
4843 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004844 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4845 sme_event_auth_timed_out(wpa_s, data);
4846 break;
4847 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004848 /* It is possible to get this event from earlier connection */
4849 if (wpa_s->current_ssid &&
4850 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4851 wpa_dbg(wpa_s, MSG_DEBUG,
4852 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4853 break;
4854 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004855 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4856 sme_event_assoc_timed_out(wpa_s, data);
4857 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004858 case EVENT_TX_STATUS:
4859 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4860 " type=%d stype=%d",
4861 MAC2STR(data->tx_status.dst),
4862 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004863#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004864 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004865#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004866 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4867 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004868 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004869 wpa_s, data->tx_status.dst,
4870 data->tx_status.data,
4871 data->tx_status.data_len,
4872 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004873 OFFCHANNEL_SEND_ACTION_SUCCESS :
4874 OFFCHANNEL_SEND_ACTION_NO_ACK);
4875#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004876 break;
4877 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004878#endif /* CONFIG_AP */
4879#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004880 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004881 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004882 /*
4883 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004884 * interface in GO mode, or via standalone AP interface.
4885 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4886 * except when the primary interface is used as a GO interface
4887 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004888 */
4889 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4890 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004891 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004892 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004893 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004894 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004895 data->tx_status.data,
4896 data->tx_status.data_len,
4897 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004898 OFFCHANNEL_SEND_ACTION_SUCCESS :
4899 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004900 break;
4901 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004902#endif /* CONFIG_OFFCHANNEL */
4903#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004904 switch (data->tx_status.type) {
4905 case WLAN_FC_TYPE_MGMT:
4906 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4907 data->tx_status.data_len,
4908 data->tx_status.stype,
4909 data->tx_status.ack);
4910 break;
4911 case WLAN_FC_TYPE_DATA:
4912 ap_tx_status(wpa_s, data->tx_status.dst,
4913 data->tx_status.data,
4914 data->tx_status.data_len,
4915 data->tx_status.ack);
4916 break;
4917 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004918#endif /* CONFIG_AP */
4919 break;
4920#ifdef CONFIG_AP
4921 case EVENT_EAPOL_TX_STATUS:
4922 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4923 data->eapol_tx_status.data,
4924 data->eapol_tx_status.data_len,
4925 data->eapol_tx_status.ack);
4926 break;
4927 case EVENT_DRIVER_CLIENT_POLL_OK:
4928 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004929 break;
4930 case EVENT_RX_FROM_UNKNOWN:
4931 if (wpa_s->ap_iface == NULL)
4932 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004933 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4934 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004935 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004936#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07004937
4938 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07004939 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004940 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004941 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004942
Hai Shalom81f62d82019-07-22 12:10:00 -07004943 wpa_msg(wpa_s, MSG_INFO,
4944 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4945 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
4946 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004947 data->ch_switch.freq,
4948 data->ch_switch.ht_enabled,
4949 data->ch_switch.ch_offset,
4950 channel_width_to_string(data->ch_switch.ch_width),
4951 data->ch_switch.cf1,
4952 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07004953 if (event == EVENT_CH_SWITCH_STARTED)
4954 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004955
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004956 wpa_s->assoc_freq = data->ch_switch.freq;
4957 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4958
Hai Shalomfdcde762020-04-02 11:19:20 -07004959#ifdef CONFIG_SME
4960 switch (data->ch_switch.ch_offset) {
4961 case 1:
4962 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
4963 break;
4964 case -1:
4965 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
4966 break;
4967 default:
4968 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
4969 break;
4970 }
4971#endif /* CONFIG_SME */
4972
Roshan Pius3a1667e2018-07-03 15:17:14 -07004973#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004974 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4975 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08004976 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004977 wpa_s->current_ssid->mode ==
4978 WPAS_MODE_P2P_GROUP_FORMATION) {
4979 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4980 data->ch_switch.ht_enabled,
4981 data->ch_switch.ch_offset,
4982 data->ch_switch.ch_width,
4983 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07004984 data->ch_switch.cf2,
4985 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004986 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004987#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004988
Hai Shalom899fcc72020-10-19 14:38:18 -07004989 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4990 sme_event_ch_switch(wpa_s);
4991
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004992 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004993 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004994 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004995#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004996#ifdef NEED_AP_MLME
4997 case EVENT_DFS_RADAR_DETECTED:
4998 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004999 wpas_ap_event_dfs_radar_detected(wpa_s,
5000 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005001 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005002 case EVENT_DFS_NOP_FINISHED:
5003 if (data)
5004 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
5005 &data->dfs_event);
5006 break;
5007#endif /* NEED_AP_MLME */
5008#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005009 case EVENT_DFS_CAC_STARTED:
5010 if (data)
5011 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
5012 break;
5013 case EVENT_DFS_CAC_FINISHED:
5014 if (data)
5015 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
5016 break;
5017 case EVENT_DFS_CAC_ABORTED:
5018 if (data)
5019 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
5020 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005021 case EVENT_RX_MGMT: {
5022 u16 fc, stype;
5023 const struct ieee80211_mgmt *mgmt;
5024
Dmitry Shmidt818ea482014-03-10 13:15:21 -07005025#ifdef CONFIG_TESTING_OPTIONS
5026 if (wpa_s->ext_mgmt_frame_handling) {
5027 struct rx_mgmt *rx = &data->rx_mgmt;
5028 size_t hex_len = 2 * rx->frame_len + 1;
5029 char *hex = os_malloc(hex_len);
5030 if (hex) {
5031 wpa_snprintf_hex(hex, hex_len,
5032 rx->frame, rx->frame_len);
5033 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
5034 rx->freq, rx->datarate, rx->ssi_signal,
5035 hex);
5036 os_free(hex);
5037 }
5038 break;
5039 }
5040#endif /* CONFIG_TESTING_OPTIONS */
5041
Dmitry Shmidt04949592012-07-19 12:16:46 -07005042 mgmt = (const struct ieee80211_mgmt *)
5043 data->rx_mgmt.frame;
5044 fc = le_to_host16(mgmt->frame_control);
5045 stype = WLAN_FC_GET_STYPE(fc);
5046
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005047#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005048 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005049#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005050#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005051 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005052 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005053 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07005054 const u8 *ie;
5055 size_t ie_len;
5056
5057 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5058 ie_len = data->rx_mgmt.frame_len -
5059 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005060 wpas_p2p_probe_req_rx(
5061 wpa_s, src, mgmt->da,
5062 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005063 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005064 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005065 break;
5066 }
5067#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005068#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005069 if (wpa_s->current_ssid &&
5070 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
5071 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005072 data->rx_mgmt.frame_len >= 30) {
5073 wpa_supplicant_event_ibss_auth(wpa_s, data);
5074 break;
5075 }
5076#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005077
5078 if (stype == WLAN_FC_STYPE_ACTION) {
5079 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07005080 wpa_s, data->rx_mgmt.frame,
5081 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005082 data->rx_mgmt.freq,
5083 data->rx_mgmt.ssi_signal);
5084 break;
5085 }
5086
5087 if (wpa_s->ifmsh) {
5088 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005089 break;
5090 }
5091
Roshan Pius3a1667e2018-07-03 15:17:14 -07005092#ifdef CONFIG_SAE
5093 if (stype == WLAN_FC_STYPE_AUTH &&
5094 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
5095 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5096 sme_external_auth_mgmt_rx(
5097 wpa_s, data->rx_mgmt.frame,
5098 data->rx_mgmt.frame_len);
5099 break;
5100 }
5101#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005102 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
5103 "management frame in non-AP mode");
5104 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005105#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005106 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005107
5108 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07005109 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
5110 const u8 *ie;
5111 size_t ie_len;
5112
5113 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
5114 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005115
5116 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
5117 mgmt->bssid, ie, ie_len,
5118 data->rx_mgmt.ssi_signal);
5119 }
5120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005121 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005122#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005123 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005124 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005125 case EVENT_RX_PROBE_REQ:
5126 if (data->rx_probe_req.sa == NULL ||
5127 data->rx_probe_req.ie == NULL)
5128 break;
5129#ifdef CONFIG_AP
5130 if (wpa_s->ap_iface) {
5131 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5132 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005133 data->rx_probe_req.da,
5134 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005135 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005136 data->rx_probe_req.ie_len,
5137 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005138 break;
5139 }
5140#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005141 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005142 data->rx_probe_req.da,
5143 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005144 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005145 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005146 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005147 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005148 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005149 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005150#ifdef CONFIG_OFFCHANNEL
5151 offchannel_remain_on_channel_cb(
5152 wpa_s, data->remain_on_channel.freq,
5153 data->remain_on_channel.duration);
5154#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005155 wpas_p2p_remain_on_channel_cb(
5156 wpa_s, data->remain_on_channel.freq,
5157 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005158#ifdef CONFIG_DPP
5159 wpas_dpp_remain_on_channel_cb(
5160 wpa_s, data->remain_on_channel.freq,
5161 data->remain_on_channel.duration);
5162#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005163 break;
5164 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005165#ifdef CONFIG_OFFCHANNEL
5166 offchannel_cancel_remain_on_channel_cb(
5167 wpa_s, data->remain_on_channel.freq);
5168#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005169 wpas_p2p_cancel_remain_on_channel_cb(
5170 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005171#ifdef CONFIG_DPP
5172 wpas_dpp_cancel_remain_on_channel_cb(
5173 wpa_s, data->remain_on_channel.freq);
5174#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005175 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005176 case EVENT_EAPOL_RX:
5177 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5178 data->eapol_rx.data,
5179 data->eapol_rx.data_len);
5180 break;
5181 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005182 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5183 "above=%d signal=%d noise=%d txrate=%d",
5184 data->signal_change.above_threshold,
5185 data->signal_change.current_signal,
5186 data->signal_change.current_noise,
5187 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005188 wpa_bss_update_level(wpa_s->current_bss,
5189 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005190 bgscan_notify_signal_change(
5191 wpa_s, data->signal_change.above_threshold,
5192 data->signal_change.current_signal,
5193 data->signal_change.current_noise,
5194 data->signal_change.current_txrate);
5195 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005196 case EVENT_INTERFACE_MAC_CHANGED:
5197 wpa_supplicant_update_mac_addr(wpa_s);
5198 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005199 case EVENT_INTERFACE_ENABLED:
5200 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5201 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomfdcde762020-04-02 11:19:20 -07005202 eloop_cancel_timeout(wpas_clear_disabled_interface,
5203 wpa_s, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005204 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07005205 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005206 if (wpa_s->p2p_mgmt) {
5207 wpa_supplicant_set_state(wpa_s,
5208 WPA_DISCONNECTED);
5209 break;
5210 }
5211
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005212#ifdef CONFIG_AP
5213 if (!wpa_s->ap_iface) {
5214 wpa_supplicant_set_state(wpa_s,
5215 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005216 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005217 wpa_supplicant_req_scan(wpa_s, 0, 0);
5218 } else
5219 wpa_supplicant_set_state(wpa_s,
5220 WPA_COMPLETED);
5221#else /* CONFIG_AP */
5222 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5223 wpa_supplicant_req_scan(wpa_s, 0, 0);
5224#endif /* CONFIG_AP */
5225 }
5226 break;
5227 case EVENT_INTERFACE_DISABLED:
5228 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005229#ifdef CONFIG_P2P
5230 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5231 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5232 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5233 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005234 * Mark interface disabled if this happens to end up not
5235 * being removed as a separate P2P group interface.
5236 */
5237 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5238 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005239 * The interface was externally disabled. Remove
5240 * it assuming an external entity will start a
5241 * new session if needed.
5242 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005243 if (wpa_s->current_ssid &&
5244 wpa_s->current_ssid->p2p_group)
5245 wpas_p2p_interface_unavailable(wpa_s);
5246 else
5247 wpas_p2p_disconnect(wpa_s);
5248 /*
5249 * wpa_s instance may have been freed, so must not use
5250 * it here anymore.
5251 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005252 break;
5253 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005254 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5255 p2p_in_progress(wpa_s->global->p2p) > 1) {
5256 /* This radio work will be cancelled, so clear P2P
5257 * state as well.
5258 */
5259 p2p_stop_find(wpa_s->global->p2p);
5260 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005261#endif /* CONFIG_P2P */
5262
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005263 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5264 /*
5265 * Indicate disconnection to keep ctrl_iface events
5266 * consistent.
5267 */
5268 wpa_supplicant_event_disassoc(
5269 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5270 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005271 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005272 os_reltime_age(&wpa_s->last_scan, &age);
5273 if (age.sec >= SCAN_RES_VALID_FOR_CONNECT) {
5274 clear_at.sec = SCAN_RES_VALID_FOR_CONNECT;
5275 clear_at.usec = 0;
5276 } else {
5277 struct os_reltime tmp;
5278
5279 tmp.sec = SCAN_RES_VALID_FOR_CONNECT;
5280 tmp.usec = 0;
5281 os_reltime_sub(&tmp, &age, &clear_at);
5282 }
5283 eloop_register_timeout(clear_at.sec, clear_at.usec,
5284 wpas_clear_disabled_interface,
5285 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005286 radio_remove_works(wpa_s, NULL, 0);
5287
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005288 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5289 break;
5290 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005291 wpa_supplicant_update_channel_list(
5292 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005293 break;
5294 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005295 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005296 break;
5297 case EVENT_BEST_CHANNEL:
5298 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5299 "(%d %d %d)",
5300 data->best_chan.freq_24, data->best_chan.freq_5,
5301 data->best_chan.freq_overall);
5302 wpa_s->best_24_freq = data->best_chan.freq_24;
5303 wpa_s->best_5_freq = data->best_chan.freq_5;
5304 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005305 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5306 data->best_chan.freq_5,
5307 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005308 break;
5309 case EVENT_UNPROT_DEAUTH:
5310 wpa_supplicant_event_unprot_deauth(wpa_s,
5311 &data->unprot_deauth);
5312 break;
5313 case EVENT_UNPROT_DISASSOC:
5314 wpa_supplicant_event_unprot_disassoc(wpa_s,
5315 &data->unprot_disassoc);
5316 break;
5317 case EVENT_STATION_LOW_ACK:
5318#ifdef CONFIG_AP
5319 if (wpa_s->ap_iface && data)
5320 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5321 data->low_ack.addr);
5322#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005323#ifdef CONFIG_TDLS
5324 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005325 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5326 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005327#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005328 break;
5329 case EVENT_IBSS_PEER_LOST:
5330#ifdef CONFIG_IBSS_RSN
5331 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5332#endif /* CONFIG_IBSS_RSN */
5333 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005334 case EVENT_DRIVER_GTK_REKEY:
5335 if (os_memcmp(data->driver_gtk_rekey.bssid,
5336 wpa_s->bssid, ETH_ALEN))
5337 break;
5338 if (!wpa_s->wpa)
5339 break;
5340 wpa_sm_update_replay_ctr(wpa_s->wpa,
5341 data->driver_gtk_rekey.replay_ctr);
5342 break;
5343 case EVENT_SCHED_SCAN_STOPPED:
5344 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005345 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005346 wpa_supplicant_notify_scanning(wpa_s, 0);
5347
5348 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5349 break;
5350
5351 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005352 * If the driver stopped scanning without being requested to,
5353 * request a new scan to continue scanning for networks.
5354 */
5355 if (!wpa_s->sched_scan_stop_req &&
5356 wpa_s->wpa_state == WPA_SCANNING) {
5357 wpa_dbg(wpa_s, MSG_DEBUG,
5358 "Restart scanning after unexpected sched_scan stop event");
5359 wpa_supplicant_req_scan(wpa_s, 1, 0);
5360 break;
5361 }
5362
5363 wpa_s->sched_scan_stop_req = 0;
5364
5365 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005366 * Start a new sched scan to continue searching for more SSIDs
5367 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005368 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005369 if (wpa_s->sched_scan_timed_out) {
5370 wpa_supplicant_req_sched_scan(wpa_s);
5371 } else if (wpa_s->pno_sched_pending) {
5372 wpa_s->pno_sched_pending = 0;
5373 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005374 } else if (resched) {
5375 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005376 }
5377
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005378 break;
5379 case EVENT_WPS_BUTTON_PUSHED:
5380#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005381 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005382#endif /* CONFIG_WPS */
5383 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005384 case EVENT_AVOID_FREQUENCIES:
5385 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5386 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005387 case EVENT_CONNECT_FAILED_REASON:
5388#ifdef CONFIG_AP
5389 if (!wpa_s->ap_iface || !data)
5390 break;
5391 hostapd_event_connect_failed_reason(
5392 wpa_s->ap_iface->bss[0],
5393 data->connect_failed_reason.addr,
5394 data->connect_failed_reason.code);
5395#endif /* CONFIG_AP */
5396 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005397 case EVENT_NEW_PEER_CANDIDATE:
5398#ifdef CONFIG_MESH
5399 if (!wpa_s->ifmsh || !data)
5400 break;
5401 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5402 data->mesh_peer.ies,
5403 data->mesh_peer.ie_len);
5404#endif /* CONFIG_MESH */
5405 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005406 case EVENT_SURVEY:
5407#ifdef CONFIG_AP
5408 if (!wpa_s->ap_iface)
5409 break;
5410 hostapd_event_get_survey(wpa_s->ap_iface,
5411 &data->survey_results);
5412#endif /* CONFIG_AP */
5413 break;
5414 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005415#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005416#ifdef CONFIG_ACS
5417 if (!wpa_s->ap_iface)
5418 break;
5419 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5420 &data->acs_selected_channels);
5421#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005422#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005423 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005424 case EVENT_P2P_LO_STOP:
5425#ifdef CONFIG_P2P
5426 wpa_s->p2p_lo_started = 0;
5427 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5428 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5429 data->p2p_lo_stop.reason_code);
5430#endif /* CONFIG_P2P */
5431 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005432 case EVENT_BEACON_LOSS:
5433 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5434 break;
5435 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5436 bgscan_notify_beacon_loss(wpa_s);
5437 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005438 case EVENT_EXTERNAL_AUTH:
5439#ifdef CONFIG_SAE
5440 if (!wpa_s->current_ssid) {
5441 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5442 break;
5443 }
5444 sme_external_auth_trigger(wpa_s, data);
5445#endif /* CONFIG_SAE */
5446 break;
5447 case EVENT_PORT_AUTHORIZED:
5448 wpa_supplicant_event_port_authorized(wpa_s);
5449 break;
5450 case EVENT_STATION_OPMODE_CHANGED:
5451#ifdef CONFIG_AP
5452 if (!wpa_s->ap_iface || !data)
5453 break;
5454
5455 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5456 data->sta_opmode.addr,
5457 data->sta_opmode.smps_mode,
5458 data->sta_opmode.chan_width,
5459 data->sta_opmode.rx_nss);
5460#endif /* CONFIG_AP */
5461 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005462 case EVENT_UNPROT_BEACON:
5463 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5464 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005465 default:
5466 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5467 break;
5468 }
5469}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005470
5471
5472void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5473 union wpa_event_data *data)
5474{
5475 struct wpa_supplicant *wpa_s;
5476
5477 if (event != EVENT_INTERFACE_STATUS)
5478 return;
5479
5480 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5481 if (wpa_s && wpa_s->driver->get_ifindex) {
5482 unsigned int ifindex;
5483
5484 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5485 if (ifindex != data->interface_status.ifindex) {
5486 wpa_dbg(wpa_s, MSG_DEBUG,
5487 "interface status ifindex %d mismatch (%d)",
5488 ifindex, data->interface_status.ifindex);
5489 return;
5490 }
5491 }
5492#ifdef CONFIG_MATCH_IFACE
5493 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5494 struct wpa_interface *wpa_i;
5495
5496 wpa_i = wpa_supplicant_match_iface(
5497 ctx, data->interface_status.ifname);
5498 if (!wpa_i)
5499 return;
5500 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5501 os_free(wpa_i);
Dmitry Shmidte4663042016-04-04 10:07:49 -07005502 }
5503#endif /* CONFIG_MATCH_IFACE */
5504
5505 if (wpa_s)
5506 wpa_supplicant_event(wpa_s, event, data);
5507}