blob: d08deb40355b50118f97314e5a6b6c870123bab6 [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
359 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
360 ie.pmkid == NULL)
361 return;
362
363 for (i = 0; i < ie.num_pmkid; i++) {
364 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
365 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700366 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700367 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800368 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700369 break;
370 }
371 }
372
373 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
374 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
375}
376
377
378static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
379 union wpa_event_data *data)
380{
381 if (data == NULL) {
382 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
383 "event");
384 return;
385 }
386 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
387 " index=%d preauth=%d",
388 MAC2STR(data->pmkid_candidate.bssid),
389 data->pmkid_candidate.index,
390 data->pmkid_candidate.preauth);
391
392 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
393 data->pmkid_candidate.index,
394 data->pmkid_candidate.preauth);
395}
396
397
398static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
399{
400 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
401 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
402 return 0;
403
404#ifdef IEEE8021X_EAPOL
405 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
406 wpa_s->current_ssid &&
407 !(wpa_s->current_ssid->eapol_flags &
408 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
409 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
410 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
411 * plaintext or static WEP keys). */
412 return 0;
413 }
414#endif /* IEEE8021X_EAPOL */
415
416 return 1;
417}
418
419
420/**
421 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
422 * @wpa_s: pointer to wpa_supplicant data
423 * @ssid: Configuration data for the network
424 * Returns: 0 on success, -1 on failure
425 *
426 * This function is called when starting authentication with a network that is
427 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
428 */
429int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
430 struct wpa_ssid *ssid)
431{
432#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800433#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700434 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700435
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700436 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
437 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438 return 0;
439
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700440 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441 sim = 1;
442 aka = 1;
443 } else {
444 struct eap_method_type *eap = ssid->eap.eap_methods;
445 while (eap->vendor != EAP_VENDOR_IETF ||
446 eap->method != EAP_TYPE_NONE) {
447 if (eap->vendor == EAP_VENDOR_IETF) {
448 if (eap->method == EAP_TYPE_SIM)
449 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700450 else if (eap->method == EAP_TYPE_AKA ||
451 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700452 aka = 1;
453 }
454 eap++;
455 }
456 }
457
458 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
459 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700460 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
461 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
462 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463 aka = 0;
464
465 if (!sim && !aka) {
466 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
467 "use SIM, but neither EAP-SIM nor EAP-AKA are "
468 "enabled");
469 return 0;
470 }
471
472 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
473 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700475 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700476 if (wpa_s->scard == NULL) {
477 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
478 "(pcsc-lite)");
479 return -1;
480 }
481 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
482 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800483#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700484#endif /* IEEE8021X_EAPOL */
485
486 return 0;
487}
488
489
490#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700491
Hai Shalomfdcde762020-04-02 11:19:20 -0700492#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700493static int has_wep_key(struct wpa_ssid *ssid)
494{
495 int i;
496
497 for (i = 0; i < NUM_WEP_KEYS; i++) {
498 if (ssid->wep_key_len[i])
499 return 1;
500 }
501
502 return 0;
503}
Hai Shalomfdcde762020-04-02 11:19:20 -0700504#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700505
506
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700507static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700508 struct wpa_ssid *ssid)
509{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700510 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511
512 if (ssid->mixed_cell)
513 return 1;
514
515#ifdef CONFIG_WPS
516 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
517 return 1;
518#endif /* CONFIG_WPS */
519
Roshan Pius3a1667e2018-07-03 15:17:14 -0700520#ifdef CONFIG_OWE
521 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
522 return 1;
523#endif /* CONFIG_OWE */
524
Hai Shalomfdcde762020-04-02 11:19:20 -0700525#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700526 if (has_wep_key(ssid))
527 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700528#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700529
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700530#ifdef IEEE8021X_EAPOL
531 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
532 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
533 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
534 privacy = 1;
535#endif /* IEEE8021X_EAPOL */
536
Jouni Malinen75ecf522011-06-27 15:19:46 -0700537 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
538 privacy = 1;
539
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800540 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
541 privacy = 1;
542
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543 if (bss->caps & IEEE80211_CAP_PRIVACY)
544 return privacy;
545 return !privacy;
546}
547
548
549static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
550 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800551 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552{
553 struct wpa_ie_data ie;
554 int proto_match = 0;
555 const u8 *rsn_ie, *wpa_ie;
556 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -0700557#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558 int wep_ok;
Hai Shalomfdcde762020-04-02 11:19:20 -0700559#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560
561 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
562 if (ret >= 0)
563 return ret;
564
Hai Shalomfdcde762020-04-02 11:19:20 -0700565#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700566 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
567 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
568 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
569 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
570 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
Hai Shalomfdcde762020-04-02 11:19:20 -0700571#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700572
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700573 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700574 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575 proto_match++;
576
577 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800578 if (debug_print)
579 wpa_dbg(wpa_s, MSG_DEBUG,
580 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700581 break;
582 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700583 if (!ie.has_pairwise)
584 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
585 if (!ie.has_group)
586 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700587
Hai Shalomfdcde762020-04-02 11:19:20 -0700588#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 if (wep_ok &&
590 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
591 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800592 if (debug_print)
593 wpa_dbg(wpa_s, MSG_DEBUG,
594 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700595 return 1;
596 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700597#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598
Roshan Pius3a1667e2018-07-03 15:17:14 -0700599 if (!(ie.proto & ssid->proto) &&
600 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800601 if (debug_print)
602 wpa_dbg(wpa_s, MSG_DEBUG,
603 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700604 break;
605 }
606
607 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800608 if (debug_print)
609 wpa_dbg(wpa_s, MSG_DEBUG,
610 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700611 break;
612 }
613
614 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800615 if (debug_print)
616 wpa_dbg(wpa_s, MSG_DEBUG,
617 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700618 break;
619 }
620
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700621 if (ssid->group_mgmt_cipher &&
622 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
623 if (debug_print)
624 wpa_dbg(wpa_s, MSG_DEBUG,
625 " skip RSN IE - group mgmt cipher mismatch");
626 break;
627 }
628
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700629 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800630 if (debug_print)
631 wpa_dbg(wpa_s, MSG_DEBUG,
632 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633 break;
634 }
635
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800637 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800638 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800639 if (debug_print)
640 wpa_dbg(wpa_s, MSG_DEBUG,
641 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642 break;
643 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800644 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
645 wpas_get_ssid_pmf(wpa_s, ssid) ==
646 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800647 if (debug_print)
648 wpa_dbg(wpa_s, MSG_DEBUG,
649 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800650 break;
651 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800653 if (debug_print)
654 wpa_dbg(wpa_s, MSG_DEBUG,
655 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 return 1;
657 }
658
Roshan Pius3a1667e2018-07-03 15:17:14 -0700659 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
660 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800661 if (debug_print)
662 wpa_dbg(wpa_s, MSG_DEBUG,
663 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700664 return 0;
665 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700666
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700667 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
669 proto_match++;
670
671 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800672 if (debug_print)
673 wpa_dbg(wpa_s, MSG_DEBUG,
674 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700675 break;
676 }
677
Hai Shalomfdcde762020-04-02 11:19:20 -0700678#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679 if (wep_ok &&
680 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
681 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800682 if (debug_print)
683 wpa_dbg(wpa_s, MSG_DEBUG,
684 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700685 return 1;
686 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700687#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700688
689 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800690 if (debug_print)
691 wpa_dbg(wpa_s, MSG_DEBUG,
692 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693 break;
694 }
695
696 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800697 if (debug_print)
698 wpa_dbg(wpa_s, MSG_DEBUG,
699 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700 break;
701 }
702
703 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800704 if (debug_print)
705 wpa_dbg(wpa_s, MSG_DEBUG,
706 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707 break;
708 }
709
710 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800711 if (debug_print)
712 wpa_dbg(wpa_s, MSG_DEBUG,
713 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700714 break;
715 }
716
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800717 if (debug_print)
718 wpa_dbg(wpa_s, MSG_DEBUG,
719 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720 return 1;
721 }
722
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700723 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
724 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800725 if (debug_print)
726 wpa_dbg(wpa_s, MSG_DEBUG,
727 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700728 return 1;
729 }
730
Roshan Pius3a1667e2018-07-03 15:17:14 -0700731#ifdef CONFIG_OWE
732 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
733 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800734 if (wpa_s->owe_transition_select &&
735 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
736 ssid->owe_transition_bss_select_count + 1 <=
737 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
738 ssid->owe_transition_bss_select_count++;
739 if (debug_print)
740 wpa_dbg(wpa_s, MSG_DEBUG,
741 " skip OWE transition BSS (selection count %d does not exceed %d)",
742 ssid->owe_transition_bss_select_count,
743 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
744 wpa_s->owe_transition_search = 1;
745 return 0;
746 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700747 if (debug_print)
748 wpa_dbg(wpa_s, MSG_DEBUG,
749 " allow in OWE transition mode");
750 return 1;
751 }
752#endif /* CONFIG_OWE */
753
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
755 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800756 if (debug_print)
757 wpa_dbg(wpa_s, MSG_DEBUG,
758 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759 return 0;
760 }
761
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800762 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
763 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800764 if (debug_print)
765 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800766 return 1;
767 }
768
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800770 if (debug_print)
771 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700772 return 1;
773 }
774
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800775 if (debug_print)
776 wpa_dbg(wpa_s, MSG_DEBUG,
777 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778
779 return 0;
780}
781
782
783static int freq_allowed(int *freqs, int freq)
784{
785 int i;
786
787 if (freqs == NULL)
788 return 1;
789
790 for (i = 0; freqs[i]; i++)
791 if (freqs[i] == freq)
792 return 1;
793 return 0;
794}
795
796
Hai Shalomfdcde762020-04-02 11:19:20 -0700797static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
798 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800799{
800 const struct hostapd_hw_modes *mode = NULL, *modes;
801 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
802 const u8 *rate_ie;
803 int i, j, k;
804
805 if (bss->freq == 0)
806 return 1; /* Cannot do matching without knowing band */
807
808 modes = wpa_s->hw.modes;
809 if (modes == NULL) {
810 /*
811 * The driver does not provide any additional information
812 * about the utilized hardware, so allow the connection attempt
813 * to continue.
814 */
815 return 1;
816 }
817
818 for (i = 0; i < wpa_s->hw.num_modes; i++) {
819 for (j = 0; j < modes[i].num_channels; j++) {
820 int freq = modes[i].channels[j].freq;
821 if (freq == bss->freq) {
822 if (mode &&
823 mode->mode == HOSTAPD_MODE_IEEE80211G)
824 break; /* do not allow 802.11b replace
825 * 802.11g */
826 mode = &modes[i];
827 break;
828 }
829 }
830 }
831
832 if (mode == NULL)
833 return 0;
834
835 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700836 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800837 if (rate_ie == NULL)
838 continue;
839
840 for (j = 2; j < rate_ie[1] + 2; j++) {
841 int flagged = !!(rate_ie[j] & 0x80);
842 int r = (rate_ie[j] & 0x7f) * 5;
843
844 /*
845 * IEEE Std 802.11n-2009 7.3.2.2:
846 * The new BSS Membership selector value is encoded
847 * like a legacy basic rate, but it is not a rate and
848 * only indicates if the BSS members are required to
849 * support the mandatory features of Clause 20 [HT PHY]
850 * in order to join the BSS.
851 */
852 if (flagged && ((rate_ie[j] & 0x7f) ==
853 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
854 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800855 if (debug_print)
856 wpa_dbg(wpa_s, MSG_DEBUG,
857 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800858 return 0;
859 }
860 continue;
861 }
862
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700863 /* There's also a VHT selector for 802.11ac */
864 if (flagged && ((rate_ie[j] & 0x7f) ==
865 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
866 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800867 if (debug_print)
868 wpa_dbg(wpa_s, MSG_DEBUG,
869 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700870 return 0;
871 }
872 continue;
873 }
874
Hai Shalomc3565922019-10-28 11:58:20 -0700875#ifdef CONFIG_SAE
876 if (flagged && ((rate_ie[j] & 0x7f) ==
877 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700878 if (wpa_s->conf->sae_pwe == 0 &&
879 !ssid->sae_password_id &&
880 wpa_key_mgmt_sae(ssid->key_mgmt)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700881 if (debug_print)
882 wpa_dbg(wpa_s, MSG_DEBUG,
883 " SAE H2E disabled");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800884#ifdef CONFIG_TESTING_OPTIONS
885 if (wpa_s->ignore_sae_h2e_only) {
886 wpa_dbg(wpa_s, MSG_DEBUG,
887 "TESTING: Ignore SAE H2E requirement mismatch");
888 continue;
889 }
890#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700891 return 0;
892 }
893 continue;
894 }
895#endif /* CONFIG_SAE */
896
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800897 if (!flagged)
898 continue;
899
900 /* check for legacy basic rates */
901 for (k = 0; k < mode->num_rates; k++) {
902 if (mode->rates[k] == r)
903 break;
904 }
905 if (k == mode->num_rates) {
906 /*
907 * IEEE Std 802.11-2007 7.3.2.2 demands that in
908 * order to join a BSS all required rates
909 * have to be supported by the hardware.
910 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800911 if (debug_print)
912 wpa_dbg(wpa_s, MSG_DEBUG,
913 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
914 r / 10, r % 10,
915 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800916 return 0;
917 }
918 }
919 }
920
921 return 1;
922}
923
924
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800925/*
926 * Test whether BSS is in an ESS.
927 * This is done differently in DMG (60 GHz) and non-DMG bands
928 */
929static int bss_is_ess(struct wpa_bss *bss)
930{
931 if (bss_is_dmg(bss)) {
932 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
933 IEEE80211_CAP_DMG_AP;
934 }
935
936 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
937 IEEE80211_CAP_ESS);
938}
939
940
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800941static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
942{
943 size_t i;
944
945 for (i = 0; i < ETH_ALEN; i++) {
946 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
947 return 0;
948 }
949 return 1;
950}
951
952
953static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
954{
955 size_t i;
956
957 for (i = 0; i < num; i++) {
958 const u8 *a = list + i * ETH_ALEN * 2;
959 const u8 *m = a + ETH_ALEN;
960
961 if (match_mac_mask(a, addr, m))
962 return 1;
963 }
964 return 0;
965}
966
967
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700968static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
969 const u8 **ret_ssid, size_t *ret_ssid_len)
970{
971#ifdef CONFIG_OWE
972 const u8 *owe, *pos, *end, *bssid;
973 u8 ssid_len;
974 struct wpa_bss *open_bss;
975
976 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
977 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
978 return;
979
980 pos = owe + 6;
981 end = owe + 2 + owe[1];
982
983 if (end - pos < ETH_ALEN + 1)
984 return;
985 bssid = pos;
986 pos += ETH_ALEN;
987 ssid_len = *pos++;
988 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
989 return;
990
991 /* Match the profile SSID against the OWE transition mode SSID on the
992 * open network. */
993 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
994 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
995 *ret_ssid = pos;
996 *ret_ssid_len = ssid_len;
997
Hai Shalomfdcde762020-04-02 11:19:20 -0700998 if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
999 struct wpa_ssid *ssid;
1000
1001 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1002 if (wpas_network_disabled(wpa_s, ssid))
1003 continue;
1004 if (ssid->ssid_len == ssid_len &&
1005 os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1006 /* OWE BSS in transition mode for a currently
1007 * enabled OWE network. */
1008 wpa_dbg(wpa_s, MSG_DEBUG,
1009 "OWE: transition mode OWE SSID for active OWE profile");
1010 bss->flags |= WPA_BSS_OWE_TRANSITION;
1011 break;
1012 }
1013 }
1014 }
1015
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001016 if (bss->ssid_len > 0)
1017 return;
1018
1019 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1020 if (!open_bss)
1021 return;
1022 if (ssid_len != open_bss->ssid_len ||
1023 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
1024 wpa_dbg(wpa_s, MSG_DEBUG,
1025 "OWE: transition mode SSID mismatch: %s",
1026 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
1027 return;
1028 }
1029
1030 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
1031 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
1032 wpa_dbg(wpa_s, MSG_DEBUG,
1033 "OWE: transition mode open BSS unexpected info");
1034 return;
1035 }
1036
1037 pos = owe + 6;
1038 end = owe + 2 + owe[1];
1039
1040 if (end - pos < ETH_ALEN + 1)
1041 return;
1042 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1043 wpa_dbg(wpa_s, MSG_DEBUG,
1044 "OWE: transition mode BSSID mismatch: " MACSTR,
1045 MAC2STR(pos));
1046 return;
1047 }
1048 pos += ETH_ALEN;
1049 ssid_len = *pos++;
1050 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1051 return;
1052 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1053 wpa_ssid_txt(pos, ssid_len));
1054 os_memcpy(bss->ssid, pos, ssid_len);
1055 bss->ssid_len = ssid_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001056 bss->flags |= WPA_BSS_OWE_TRANSITION;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001057#endif /* CONFIG_OWE */
1058}
1059
1060
Hai Shalomfdcde762020-04-02 11:19:20 -07001061static int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
1062{
1063 int i, j;
1064
1065 if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1066 return 0;
1067
1068 for (j = 0; j < wpa_s->hw.num_modes; j++) {
1069 struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1070
1071 for (i = 0; i < mode->num_channels; i++) {
1072 struct hostapd_channel_data *chan = &mode->channels[i];
1073
1074 if (chan->freq == freq)
1075 return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1076 }
1077 }
1078
1079 return 1;
1080}
1081
1082
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001083struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1084 int i, struct wpa_bss *bss,
1085 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001086 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001088 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001089 int wpa;
1090 struct wpa_blacklist *e;
1091 const u8 *ie;
1092 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001093 int osen, rsn_osen = 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001094#ifdef CONFIG_MBO
1095 const u8 *assoc_disallow;
1096#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001097 const u8 *match_ssid;
1098 size_t match_ssid_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001099 struct wpa_ie_data data;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001100
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001101 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102 wpa_ie_len = ie ? ie[1] : 0;
1103
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001104 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105 rsn_ie_len = ie ? ie[1] : 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001106 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1107 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1108 rsn_osen = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001110 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1111 osen = ie != NULL;
1112
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001113 if (debug_print) {
1114 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1115 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1116 i, MAC2STR(bss->bssid),
1117 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1118 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1119 bss->freq,
1120 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1121 " wps" : "",
1122 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1123 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1124 ? " p2p" : "",
1125 osen ? " osen=1" : "");
1126 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127
1128 e = wpa_blacklist_get(wpa_s, bss->bssid);
1129 if (e) {
1130 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001131 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132 /*
1133 * When only a single network is enabled, we can
1134 * trigger blacklisting on the first failure. This
1135 * should not be done with multiple enabled networks to
1136 * avoid getting forced to move into a worse ESS on
1137 * single error if there are no other BSSes of the
1138 * current ESS.
1139 */
1140 limit = 0;
1141 }
1142 if (e->count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001143 if (debug_print) {
1144 wpa_dbg(wpa_s, MSG_DEBUG,
1145 " skip - blacklisted (count=%d limit=%d)",
1146 e->count, limit);
1147 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001148 return NULL;
1149 }
1150 }
1151
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001152 match_ssid = bss->ssid;
1153 match_ssid_len = bss->ssid_len;
1154 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1155
1156 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001157 if (debug_print)
1158 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001159 return NULL;
1160 }
1161
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001162 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001163 if (debug_print)
1164 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001165 return NULL;
1166 }
1167
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001168 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001169 if (debug_print)
1170 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001171 return NULL;
1172 }
1173
Hai Shalomfdcde762020-04-02 11:19:20 -07001174 if (disabled_freq(wpa_s, bss->freq)) {
1175 if (debug_print)
1176 wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled");
1177 return NULL;
1178 }
1179
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001180 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
1181
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001182 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001184 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001185
Dmitry Shmidt04949592012-07-19 12:16:46 -07001186 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001187 if (debug_print)
1188 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189 continue;
1190 }
1191
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001192 res = wpas_temp_disabled(wpa_s, ssid);
1193 if (res > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001194 if (debug_print)
1195 wpa_dbg(wpa_s, MSG_DEBUG,
1196 " skip - disabled temporarily for %d second(s)",
1197 res);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001198 continue;
1199 }
1200
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001201#ifdef CONFIG_WPS
1202 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001203 if (debug_print)
1204 wpa_dbg(wpa_s, MSG_DEBUG,
1205 " skip - blacklisted (WPS)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001206 continue;
1207 }
1208
1209 if (wpa && ssid->ssid_len == 0 &&
1210 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1211 check_ssid = 0;
1212
1213 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1214 /* Only allow wildcard SSID match if an AP
1215 * advertises active WPS operation that matches
1216 * with our mode. */
1217 check_ssid = 1;
1218 if (ssid->ssid_len == 0 &&
1219 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1220 check_ssid = 0;
1221 }
1222#endif /* CONFIG_WPS */
1223
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001224 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1225 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1226 check_ssid = 0;
1227
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001228 if (check_ssid &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001229 (match_ssid_len != ssid->ssid_len ||
1230 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001231 if (debug_print)
1232 wpa_dbg(wpa_s, MSG_DEBUG,
1233 " skip - SSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 continue;
1235 }
1236
1237 if (ssid->bssid_set &&
1238 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001239 if (debug_print)
1240 wpa_dbg(wpa_s, MSG_DEBUG,
1241 " skip - BSSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001242 continue;
1243 }
1244
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001245 /* check blacklist */
1246 if (ssid->num_bssid_blacklist &&
1247 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1248 ssid->num_bssid_blacklist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001249 if (debug_print)
1250 wpa_dbg(wpa_s, MSG_DEBUG,
1251 " skip - BSSID blacklisted");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001252 continue;
1253 }
1254
1255 /* if there is a whitelist, only accept those APs */
1256 if (ssid->num_bssid_whitelist &&
1257 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1258 ssid->num_bssid_whitelist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001259 if (debug_print)
1260 wpa_dbg(wpa_s, MSG_DEBUG,
1261 " skip - BSSID not in whitelist");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001262 continue;
1263 }
1264
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001265 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss,
1266 debug_print))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267 continue;
1268
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001269 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1271 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001272 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001273 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001274 if (debug_print)
1275 wpa_dbg(wpa_s, MSG_DEBUG,
1276 " skip - non-WPA network not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001277 continue;
1278 }
1279
Hai Shalomfdcde762020-04-02 11:19:20 -07001280#ifdef CONFIG_WEP
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001281 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1282 has_wep_key(ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001283 if (debug_print)
1284 wpa_dbg(wpa_s, MSG_DEBUG,
1285 " skip - ignore WPA/WPA2 AP for WEP network block");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001286 continue;
1287 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001288#endif /* CONFIG_WEP */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001289
Roshan Pius3a1667e2018-07-03 15:17:14 -07001290 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen &&
1291 !rsn_osen) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001292 if (debug_print)
1293 wpa_dbg(wpa_s, MSG_DEBUG,
1294 " skip - non-OSEN network not allowed");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001295 continue;
1296 }
1297
Jouni Malinen75ecf522011-06-27 15:19:46 -07001298 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001299 if (debug_print)
1300 wpa_dbg(wpa_s, MSG_DEBUG,
1301 " skip - privacy mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001302 continue;
1303 }
1304
Hai Shalom81f62d82019-07-22 12:10:00 -07001305 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001306 !bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001307 if (debug_print)
1308 wpa_dbg(wpa_s, MSG_DEBUG,
1309 " skip - not ESS, PBSS, or MBSS");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001310 continue;
1311 }
1312
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001313 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001314 if (debug_print)
1315 wpa_dbg(wpa_s, MSG_DEBUG,
1316 " skip - PBSS mismatch (ssid %d bss %d)",
1317 ssid->pbss, bss_is_pbss(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001318 continue;
1319 }
1320
1321 if (!freq_allowed(ssid->freq_list, bss->freq)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001322 if (debug_print)
1323 wpa_dbg(wpa_s, MSG_DEBUG,
1324 " skip - frequency not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001325 continue;
1326 }
1327
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001328#ifdef CONFIG_MESH
Hai Shalom81f62d82019-07-22 12:10:00 -07001329 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001330 ssid->frequency != bss->freq) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001331 if (debug_print)
1332 wpa_dbg(wpa_s, MSG_DEBUG,
1333 " skip - frequency not allowed (mesh)");
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001334 continue;
1335 }
1336#endif /* CONFIG_MESH */
1337
Hai Shalomfdcde762020-04-02 11:19:20 -07001338 if (!rate_match(wpa_s, ssid, bss, debug_print)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001339 if (debug_print)
1340 wpa_dbg(wpa_s, MSG_DEBUG,
1341 " skip - rate sets do not match");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001342 continue;
1343 }
1344
Hai Shalomc3565922019-10-28 11:58:20 -07001345#ifdef CONFIG_SAE
Hai Shalomfdcde762020-04-02 11:19:20 -07001346 if ((wpa_s->conf->sae_pwe == 1 || ssid->sae_password_id) &&
1347 wpa_s->conf->sae_pwe != 3 &&
Hai Shalomc3565922019-10-28 11:58:20 -07001348 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1349 (!(ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX)) ||
1350 ie[1] < 1 ||
1351 !(ie[2] & BIT(WLAN_RSNX_CAPAB_SAE_H2E)))) {
1352 if (debug_print)
1353 wpa_dbg(wpa_s, MSG_DEBUG,
1354 " skip - SAE H2E required, but not supported by the AP");
1355 continue;
1356 }
1357#endif /* CONFIG_SAE */
1358
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001359#ifndef CONFIG_IBSS_RSN
1360 if (ssid->mode == WPAS_MODE_IBSS &&
1361 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1362 WPA_KEY_MGMT_WPA_NONE))) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001363 if (debug_print)
1364 wpa_dbg(wpa_s, MSG_DEBUG,
1365 " skip - IBSS RSN not supported in the build");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001366 continue;
1367 }
1368#endif /* !CONFIG_IBSS_RSN */
1369
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001370#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001371 if (ssid->p2p_group &&
1372 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1373 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001374 if (debug_print)
1375 wpa_dbg(wpa_s, MSG_DEBUG,
1376 " skip - no P2P IE seen");
Dmitry Shmidt96571392013-10-14 12:54:46 -07001377 continue;
1378 }
1379
Dmitry Shmidt54605472013-11-08 11:10:19 -08001380 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1381 struct wpabuf *p2p_ie;
1382 u8 dev_addr[ETH_ALEN];
1383
1384 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1385 if (ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001386 if (debug_print)
1387 wpa_dbg(wpa_s, MSG_DEBUG,
1388 " skip - no P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001389 continue;
1390 }
1391 p2p_ie = wpa_bss_get_vendor_ie_multi(
1392 bss, P2P_IE_VENDOR_TYPE);
1393 if (p2p_ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001394 if (debug_print)
1395 wpa_dbg(wpa_s, MSG_DEBUG,
1396 " skip - could not fetch P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001397 continue;
1398 }
1399
1400 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1401 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1402 ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001403 if (debug_print)
1404 wpa_dbg(wpa_s, MSG_DEBUG,
1405 " skip - no matching GO P2P Device Address in P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001406 wpabuf_free(p2p_ie);
1407 continue;
1408 }
1409 wpabuf_free(p2p_ie);
1410 }
1411
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001412 /*
1413 * TODO: skip the AP if its P2P IE has Group Formation
1414 * bit set in the P2P Group Capability Bitmap and we
1415 * are not in Group Formation with that device.
1416 */
1417#endif /* CONFIG_P2P */
1418
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001419 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1420 {
1421 struct os_reltime diff;
1422
1423 os_reltime_sub(&wpa_s->scan_min_time,
1424 &bss->last_update, &diff);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001425 if (debug_print)
1426 wpa_dbg(wpa_s, MSG_DEBUG,
1427 " skip - scan result not recent enough (%u.%06u seconds too old)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001428 (unsigned int) diff.sec,
1429 (unsigned int) diff.usec);
1430 continue;
1431 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001432#ifdef CONFIG_MBO
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001433#ifdef CONFIG_TESTING_OPTIONS
1434 if (wpa_s->ignore_assoc_disallow)
1435 goto skip_assoc_disallow;
1436#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001437 assoc_disallow = wpas_mbo_get_bss_attr(
1438 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1439 if (assoc_disallow && assoc_disallow[1] >= 1) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001440 if (debug_print)
1441 wpa_dbg(wpa_s, MSG_DEBUG,
1442 " skip - MBO association disallowed (reason %u)",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001443 assoc_disallow[2]);
1444 continue;
1445 }
1446
Hai Shalom74f70d42019-02-11 14:42:39 -08001447 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001448 if (debug_print)
1449 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom74f70d42019-02-11 14:42:39 -08001450 " skip - AP temporarily disallowed");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001451 continue;
1452 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001453#ifdef CONFIG_TESTING_OPTIONS
1454 skip_assoc_disallow:
1455#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001456#endif /* CONFIG_MBO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001457
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001458#ifdef CONFIG_DPP
1459 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1460 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1461 (!ssid->dpp_connector ||
1462 !ssid->dpp_netaccesskey ||
1463 !ssid->dpp_csign)) {
1464 if (debug_print)
1465 wpa_dbg(wpa_s, MSG_DEBUG,
1466 " skip - no PMKSA entry for DPP");
1467 continue;
1468 }
1469#endif /* CONFIG_DPP */
1470
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001471 /* Matching configuration found */
1472 return ssid;
1473 }
1474
1475 /* No matching configuration found */
1476 return NULL;
1477}
1478
1479
1480static struct wpa_bss *
1481wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001483 struct wpa_ssid **selected_ssid,
1484 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001485{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001486 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001487
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001488 if (wpa_s->current_ssid) {
1489 struct wpa_ssid *ssid;
1490
1491 wpa_dbg(wpa_s, MSG_DEBUG,
1492 "Scan results matching the currently selected network");
1493 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1494 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1495
1496 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1497 only_first_ssid, 0);
1498 if (ssid != wpa_s->current_ssid)
1499 continue;
1500 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1501 " freq=%d level=%d snr=%d est_throughput=%u",
1502 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1503 bss->snr, bss->est_throughput);
1504 }
1505 }
1506
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001507 if (only_first_ssid)
1508 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1509 group->id);
1510 else
1511 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1512 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001514 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1515 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001516
1517 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001518 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001519 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001520 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001521 if (!*selected_ssid)
1522 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -07001523 wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001524 " ssid='%s'",
Hai Shalomfdcde762020-04-02 11:19:20 -07001525 bss == wpa_s->current_bss ? "current ": "",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001526 MAC2STR(bss->bssid),
1527 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1528 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001529 }
1530
1531 return NULL;
1532}
1533
1534
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001535struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1536 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537{
1538 struct wpa_bss *selected = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07001539 size_t prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001540 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001541 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001542
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001543 if (wpa_s->last_scan_res == NULL ||
1544 wpa_s->last_scan_res_used == 0)
1545 return NULL; /* no scan results from last update */
1546
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001547 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001548 /* check that next_ssid is still valid */
1549 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1550 if (ssid == wpa_s->next_ssid)
1551 break;
1552 }
1553 next_ssid = ssid;
1554 wpa_s->next_ssid = NULL;
1555 }
1556
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001557 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001558 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1559 if (next_ssid && next_ssid->priority ==
1560 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001561 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001562 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001563 if (selected)
1564 break;
1565 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001566 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001567 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001568 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001569 if (selected)
1570 break;
1571 }
1572
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001573 if (selected == NULL && wpa_s->blacklist &&
1574 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1576 "blacklist and try again");
1577 wpa_blacklist_clear(wpa_s);
1578 wpa_s->blacklist_cleared++;
1579 } else if (selected == NULL)
1580 break;
1581 }
1582
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001583 ssid = *selected_ssid;
1584 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1585 !ssid->passphrase && !ssid->ext_psk) {
1586 const char *field_name, *txt = NULL;
1587
1588 wpa_dbg(wpa_s, MSG_DEBUG,
1589 "PSK/passphrase not yet available for the selected network");
1590
1591 wpas_notify_network_request(wpa_s, ssid,
1592 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1593
1594 field_name = wpa_supplicant_ctrl_req_to_string(
1595 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1596 if (field_name == NULL)
1597 return NULL;
1598
1599 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1600
1601 selected = NULL;
1602 }
1603
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001604 return selected;
1605}
1606
1607
1608static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1609 int timeout_sec, int timeout_usec)
1610{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001611 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001612 /*
1613 * No networks are enabled; short-circuit request so
1614 * we don't wait timeout seconds before transitioning
1615 * to INACTIVE state.
1616 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001617 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1618 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001619 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1620 return;
1621 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001622
1623 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001624 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1625}
1626
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001627
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001628int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001629 struct wpa_bss *selected,
1630 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001631{
1632 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1633 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1634 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001635 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001636#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001637 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1638 wpa_s->p2p_in_provisioning) {
1639 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1640 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001641 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001642 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001643#endif /* CONFIG_P2P */
1644
1645#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001646 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647 wpas_wps_cancel(wpa_s);
1648#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001649 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001650 }
1651
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001652 wpa_msg(wpa_s, MSG_DEBUG,
1653 "Considering connect request: reassociate: %d selected: "
1654 MACSTR " bssid: " MACSTR " pending: " MACSTR
1655 " wpa_state: %s ssid=%p current_ssid=%p",
1656 wpa_s->reassociate, MAC2STR(selected->bssid),
1657 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1658 wpa_supplicant_state_txt(wpa_s->wpa_state),
1659 ssid, wpa_s->current_ssid);
1660
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001661 /*
1662 * Do not trigger new association unless the BSSID has changed or if
1663 * reassociation is requested. If we are in process of associating with
1664 * the selected BSSID, do not trigger new attempt.
1665 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001666 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001667 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1668 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1669 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001670 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1671 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1672 0) ||
1673 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1674 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1676 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001677 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001678 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001679 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1680 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001681 wpa_supplicant_associate(wpa_s, selected, ssid);
1682 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001683 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1684 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001685 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001686
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001687 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001688}
1689
1690
1691static struct wpa_ssid *
1692wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1693{
Hai Shalomfdcde762020-04-02 11:19:20 -07001694 size_t prio;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001695 struct wpa_ssid *ssid;
1696
1697 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1698 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1699 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001700 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001701 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001702#ifndef CONFIG_IBSS_RSN
1703 if (ssid->mode == WPAS_MODE_IBSS &&
1704 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1705 WPA_KEY_MGMT_WPA_NONE))) {
1706 wpa_msg(wpa_s, MSG_INFO,
1707 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1708 wpa_ssid_txt(ssid->ssid,
1709 ssid->ssid_len));
1710 continue;
1711 }
1712#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001713 if (ssid->mode == WPAS_MODE_IBSS ||
1714 ssid->mode == WPAS_MODE_AP ||
1715 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001716 return ssid;
1717 }
1718 }
1719 return NULL;
1720}
1721
1722
1723/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1724 * on BSS added and BSS changed events */
1725static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001726 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001727{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001728 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001729
1730 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1731 return;
1732
Jouni Malinen87fd2792011-05-16 18:35:42 +03001733 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001734 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001735
Jouni Malinen87fd2792011-05-16 18:35:42 +03001736 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001737 if (ssid == NULL)
1738 continue;
1739
Jouni Malinen87fd2792011-05-16 18:35:42 +03001740 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001741 if (rsn == NULL)
1742 continue;
1743
Jouni Malinen87fd2792011-05-16 18:35:42 +03001744 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001745 }
1746
1747}
1748
1749
Hai Shalomfdcde762020-04-02 11:19:20 -07001750#ifndef CONFIG_NO_ROAMING
1751
1752static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
1753{
1754 if (noise == WPA_INVALID_NOISE)
1755 noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ :
1756 DEFAULT_NOISE_FLOOR_2GHZ;
1757 return avg_signal - noise;
1758}
1759
1760
1761static unsigned int
1762wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
1763 const struct wpa_bss *bss, int snr)
1764{
1765 int rate = wpa_bss_get_max_rate(bss);
1766 const u8 *ies = (const void *) (bss + 1);
1767 size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
1768
1769 return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr);
1770}
1771
1772#endif /* CONFIG_NO_ROAMING */
1773
1774
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001775static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1776 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001777 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001779 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001780#ifndef CONFIG_NO_ROAMING
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001781 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001782 int to_5ghz;
Hai Shalomfdcde762020-04-02 11:19:20 -07001783 int cur_level;
1784 unsigned int cur_est, sel_est;
1785 struct wpa_signal_info si;
1786 int cur_snr = 0;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001787#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001788
1789 if (wpa_s->reassociate)
1790 return 1; /* explicit request to reassociate */
1791 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1792 return 1; /* we are not associated; continue */
1793 if (wpa_s->current_ssid == NULL)
1794 return 1; /* unknown current SSID */
1795 if (wpa_s->current_ssid != ssid)
1796 return 1; /* different network block */
1797
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001798 if (wpas_driver_bss_selection(wpa_s))
1799 return 0; /* Driver-based roaming */
1800
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001801 if (wpa_s->current_ssid->ssid)
1802 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1803 wpa_s->current_ssid->ssid,
1804 wpa_s->current_ssid->ssid_len);
1805 if (!current_bss)
1806 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001807
1808 if (!current_bss)
1809 return 1; /* current BSS not seen in scan results */
1810
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001811 if (current_bss == selected)
1812 return 0;
1813
1814 if (selected->last_update_idx > current_bss->last_update_idx)
1815 return 1; /* current BSS not seen in the last scan */
1816
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001817#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001818 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001819 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001820 " freq=%d level=%d snr=%d est_throughput=%u",
1821 MAC2STR(current_bss->bssid),
1822 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001823 current_bss->snr, current_bss->est_throughput);
1824 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001825 " freq=%d level=%d snr=%d est_throughput=%u",
1826 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001827 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001828
1829 if (wpa_s->current_ssid->bssid_set &&
1830 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1831 0) {
1832 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1833 "has preferred BSSID");
1834 return 1;
1835 }
1836
Hai Shalomfdcde762020-04-02 11:19:20 -07001837 cur_level = current_bss->level;
1838 cur_est = current_bss->est_throughput;
1839 sel_est = selected->est_throughput;
1840
1841 /*
1842 * Try to poll the signal from the driver since this will allow to get
1843 * more accurate values. In some cases, there can be big differences
1844 * between the RSSI of the Probe Response frames of the AP we are
1845 * associated with and the Beacon frames we hear from the same AP after
1846 * association. This can happen, e.g., when there are two antennas that
1847 * hear the AP very differently. If the driver chooses to hear the
1848 * Probe Response frames during the scan on the "bad" antenna because
1849 * it wants to save power, but knows to choose the other antenna after
1850 * association, we will hear our AP with a low RSSI as part of the
1851 * scan even when we can hear it decently on the other antenna. To cope
1852 * with this, ask the driver to teach us how it hears the AP. Also, the
1853 * scan results may be a bit old, since we can very quickly get fresh
1854 * information about our currently associated AP.
1855 */
1856 if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
1857 (si.avg_beacon_signal || si.avg_signal)) {
1858 cur_level = si.avg_beacon_signal ? si.avg_beacon_signal :
1859 si.avg_signal;
1860 cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
1861 si.current_noise);
1862
1863 cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
1864 current_bss,
1865 cur_snr);
1866 wpa_dbg(wpa_s, MSG_DEBUG,
1867 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
1868 cur_level, cur_snr, cur_est);
1869 }
1870
1871 if (sel_est > cur_est + 5000) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001872 wpa_dbg(wpa_s, MSG_DEBUG,
1873 "Allow reassociation - selected BSS has better estimated throughput");
1874 return 1;
1875 }
1876
Dmitry Shmidte4663042016-04-04 10:07:49 -07001877 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1878
Hai Shalomfdcde762020-04-02 11:19:20 -07001879 if (cur_level < 0 && cur_level > selected->level + to_5ghz * 2 &&
1880 sel_est < cur_est * 1.2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001881 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1882 "signal level");
1883 return 0;
1884 }
1885
Hai Shalomfdcde762020-04-02 11:19:20 -07001886 if (cur_est > sel_est + 5000) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001887 wpa_dbg(wpa_s, MSG_DEBUG,
1888 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001889 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001890 }
1891
Hai Shalomfdcde762020-04-02 11:19:20 -07001892 if (cur_snr > GREAT_SNR) {
1893 wpa_dbg(wpa_s, MSG_DEBUG,
1894 "Skip roam - Current BSS has good SNR (%u > %u)",
1895 cur_snr, GREAT_SNR);
1896 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001897 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001898
Hai Shalomfdcde762020-04-02 11:19:20 -07001899 if (cur_level < -85) /* ..-86 dBm */
1900 min_diff = 1;
1901 else if (cur_level < -80) /* -85..-81 dBm */
1902 min_diff = 2;
1903 else if (cur_level < -75) /* -80..-76 dBm */
1904 min_diff = 3;
1905 else if (cur_level < -70) /* -75..-71 dBm */
1906 min_diff = 4;
1907 else if (cur_level < 0) /* -70..-1 dBm */
1908 min_diff = 5;
1909 else /* unspecified units (not in dBm) */
1910 min_diff = 2;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001911
Hai Shalomfdcde762020-04-02 11:19:20 -07001912 if (cur_est > sel_est * 1.5)
1913 min_diff += 10;
1914 else if (cur_est > sel_est * 1.2)
1915 min_diff += 5;
1916 else if (cur_est > sel_est * 1.1)
1917 min_diff += 2;
1918 else if (cur_est > sel_est)
1919 min_diff++;
1920 else if (sel_est > cur_est * 1.5)
1921 min_diff -= 10;
1922 else if (sel_est > cur_est * 1.2)
1923 min_diff -= 5;
1924 else if (sel_est > cur_est * 1.1)
1925 min_diff -= 2;
1926 else if (sel_est > cur_est)
1927 min_diff--;
1928
1929 if (to_5ghz)
1930 min_diff -= 2;
1931 diff = selected->level - cur_level;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001932 if (diff < min_diff) {
1933 wpa_dbg(wpa_s, MSG_DEBUG,
1934 "Skip roam - too small difference in signal level (%d < %d)",
1935 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001936 return 0;
1937 }
1938
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001939 wpa_dbg(wpa_s, MSG_DEBUG,
1940 "Allow reassociation due to difference in signal level (%d >= %d)",
1941 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001942 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001943#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001944 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001945#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001946}
1947
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001948
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001949/*
1950 * Return a negative value if no scan results could be fetched or if scan
1951 * results should not be shared with other virtual interfaces.
1952 * Return 0 if scan results were fetched and may be shared with other
1953 * interfaces.
1954 * Return 1 if scan results may be shared with other virtual interfaces but may
1955 * not trigger any operations.
1956 * Return 2 if the interface was removed and cannot be used.
1957 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001958static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001959 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001960 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001961{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001962 struct wpa_scan_results *scan_res = NULL;
1963 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001964 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001965#ifndef CONFIG_NO_RANDOM_POOL
1966 size_t i, num;
1967#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001968
1969#ifdef CONFIG_AP
1970 if (wpa_s->ap_iface)
1971 ap = 1;
1972#endif /* CONFIG_AP */
1973
1974 wpa_supplicant_notify_scanning(wpa_s, 0);
1975
1976 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1977 data ? &data->scan_info :
1978 NULL, 1);
1979 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001980 if (wpa_s->conf->ap_scan == 2 || ap ||
1981 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001982 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001983 if (!own_request)
1984 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001985 if (data && data->scan_info.external_scan)
1986 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001987 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1988 "scanning again");
1989 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001990 ret = -1;
1991 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001992 }
1993
1994#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001995 num = scan_res->num;
1996 if (num > 10)
1997 num = 10;
1998 for (i = 0; i < num; i++) {
1999 u8 buf[5];
2000 struct wpa_scan_res *res = scan_res->res[i];
2001 buf[0] = res->bssid[5];
2002 buf[1] = res->qual & 0xff;
2003 buf[2] = res->noise & 0xff;
2004 buf[3] = res->level & 0xff;
2005 buf[4] = res->tsf & 0xff;
2006 random_add_randomness(buf, sizeof(buf));
2007 }
2008#endif /* CONFIG_NO_RANDOM_POOL */
2009
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002010 if (update_only) {
2011 ret = 1;
2012 goto scan_work_done;
2013 }
2014
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002015 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002016 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002017 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2018 struct wpa_scan_results *scan_res);
2019
2020 scan_res_handler = wpa_s->scan_res_handler;
2021 wpa_s->scan_res_handler = NULL;
2022 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002023 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002024 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025 }
2026
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002027 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002028 wpa_s->own_scan_running,
2029 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002030 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002031 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2032 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002033 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2034 wpa_s->manual_scan_id);
2035 wpa_s->manual_scan_use_id = 0;
2036 } else {
2037 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2038 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002039 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002040
2041 wpas_notify_scan_done(wpa_s, 1);
2042
Hai Shalomfdcde762020-04-02 11:19:20 -07002043 if (ap) {
2044 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2045#ifdef CONFIG_AP
2046 if (wpa_s->ap_iface->scan_cb)
2047 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2048#endif /* CONFIG_AP */
2049 goto scan_work_done;
2050 }
2051
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002052 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002053 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 -07002054 wpa_scan_results_free(scan_res);
2055 return 0;
2056 }
2057
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002058 if (wnm_scan_process(wpa_s, 1) > 0)
2059 goto scan_work_done;
2060
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002061 if (sme_proc_obss_scan(wpa_s, scan_res) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002062 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002063
Hai Shalom021b0b52019-04-10 11:17:58 -07002064 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08002065 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2066 goto scan_work_done;
2067
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002068 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2069 goto scan_work_done;
2070
2071 if (autoscan_notify_scan(wpa_s, scan_res))
2072 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002073
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002074 if (wpa_s->disconnected) {
2075 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002076 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077 }
2078
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002079 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002080 bgscan_notify_scan(wpa_s, scan_res) == 1)
2081 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002083 wpas_wps_update_ap_info(wpa_s, scan_res);
2084
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002085 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2086 wpa_s->wpa_state < WPA_COMPLETED)
2087 goto scan_work_done;
2088
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002089 wpa_scan_results_free(scan_res);
2090
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002091 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002092 struct wpa_radio_work *work = wpa_s->scan_work;
2093 wpa_s->scan_work = NULL;
2094 radio_work_done(work);
2095 }
2096
Hai Shalomc3565922019-10-28 11:58:20 -07002097 os_free(wpa_s->last_scan_freqs);
2098 wpa_s->last_scan_freqs = NULL;
2099 wpa_s->num_last_scan_freqs = 0;
2100 if (own_request && data &&
2101 data->scan_info.freqs && data->scan_info.num_freqs) {
2102 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2103 data->scan_info.num_freqs);
2104 if (wpa_s->last_scan_freqs) {
2105 os_memcpy(wpa_s->last_scan_freqs,
2106 data->scan_info.freqs,
2107 sizeof(int) * data->scan_info.num_freqs);
2108 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2109 }
2110 }
2111
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002112 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002113
2114scan_work_done:
2115 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002116 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002117 struct wpa_radio_work *work = wpa_s->scan_work;
2118 wpa_s->scan_work = NULL;
2119 radio_work_done(work);
2120 }
2121 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002122}
2123
2124
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002125static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002126 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002127{
2128 struct wpa_bss *selected;
2129 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002130 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2131
2132 if (time_to_reenable > 0) {
2133 wpa_dbg(wpa_s, MSG_DEBUG,
2134 "Postpone network selection by %d seconds since all networks are disabled",
2135 time_to_reenable);
2136 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2137 eloop_register_timeout(time_to_reenable, 0,
2138 wpas_network_reenabled, wpa_s, NULL);
2139 return 0;
2140 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002141
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002142 if (wpa_s->p2p_mgmt)
2143 return 0; /* no normal connection on p2p_mgmt interface */
2144
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002145 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002146 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002147
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002148#ifdef CONFIG_MESH
2149 if (wpa_s->ifmsh) {
2150 wpa_msg(wpa_s, MSG_INFO,
2151 "Avoiding join because we already joined a mesh group");
2152 return 0;
2153 }
2154#endif /* CONFIG_MESH */
2155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002156 if (selected) {
2157 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002158 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002159 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002160 if (new_scan)
2161 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002163 }
2164
Hai Shalomc3565922019-10-28 11:58:20 -07002165 wpa_s->suitable_network++;
2166
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002167 if (ssid != wpa_s->current_ssid &&
2168 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2169 wpa_s->own_disconnect_req = 1;
2170 wpa_supplicant_deauthenticate(
2171 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2172 }
2173
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002174 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002175 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002176 return -1;
2177 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002178 if (new_scan)
2179 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002180 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002181 * Do not allow other virtual radios to trigger operations based
2182 * on these scan results since we do not want them to start
2183 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002184 */
2185 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002187 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002188 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2189 ssid = wpa_supplicant_pick_new_network(wpa_s);
2190 if (ssid) {
2191 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2192 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002193 if (new_scan)
2194 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002195 } else if (own_request) {
2196 /*
2197 * No SSID found. If SCAN results are as a result of
2198 * own scan request and not due to a scan request on
2199 * another shared interface, try another scan.
2200 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002201 int timeout_sec = wpa_s->scan_interval;
2202 int timeout_usec = 0;
2203#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002204 int res;
2205
2206 res = wpas_p2p_scan_no_go_seen(wpa_s);
2207 if (res == 2)
2208 return 2;
2209 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002210 return 0;
2211
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002212 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002213 wpa_s->show_group_started ||
2214 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002215 /*
2216 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002217 * state and during P2P join-a-group operation
2218 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002219 */
2220 timeout_sec = 0;
2221 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002222 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2223 timeout_usec);
2224 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002225 }
2226#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002227#ifdef CONFIG_INTERWORKING
2228 if (wpa_s->conf->auto_interworking &&
2229 wpa_s->conf->interworking &&
2230 wpa_s->conf->cred) {
2231 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2232 "start ANQP fetch since no matching "
2233 "networks found");
2234 wpa_s->network_select = 1;
2235 wpa_s->auto_network_select = 1;
2236 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002237 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002238 }
2239#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002240#ifdef CONFIG_WPS
2241 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2242 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2243 timeout_sec = 0;
2244 timeout_usec = 500000;
2245 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2246 timeout_usec);
2247 return 0;
2248 }
2249#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002250#ifdef CONFIG_OWE
2251 if (wpa_s->owe_transition_search) {
2252 wpa_dbg(wpa_s, MSG_DEBUG,
2253 "OWE: Use shorter wait during transition mode search");
2254 timeout_sec = 0;
2255 timeout_usec = 500000;
2256 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2257 timeout_usec);
2258 return 0;
2259 }
2260#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002261 if (wpa_supplicant_req_sched_scan(wpa_s))
2262 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2263 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002264
2265 wpa_msg_ctrl(wpa_s, MSG_INFO,
2266 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002267 }
2268 }
2269 return 0;
2270}
2271
2272
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002273static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2274 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002275{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002276 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002277 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002278
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002279 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002280 if (res == 2) {
2281 /*
2282 * Interface may have been removed, so must not dereference
2283 * wpa_s after this.
2284 */
2285 return 1;
2286 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002287
2288 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002289 /*
2290 * If no scan results could be fetched, then no need to
2291 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002292 * this scan. Similarly, if scan results started a new operation on this
2293 * interface, do not notify other interfaces to avoid concurrent
2294 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002295 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002296 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002297 }
2298
2299 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002300 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002301 * so, they get updated with this same scan info.
2302 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002303 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2304 radio_list) {
2305 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2307 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002308 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2309 res > 0);
2310 if (res < 0)
2311 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002312 }
2313 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002314
2315 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002316}
2317
2318#endif /* CONFIG_NO_SCAN_PROCESSING */
2319
2320
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002321int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2322{
2323#ifdef CONFIG_NO_SCAN_PROCESSING
2324 return -1;
2325#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002326 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002327
Dmitry Shmidt29333592017-01-09 12:27:11 -08002328 wpa_s->ignore_post_flush_scan_res = 0;
2329
Dmitry Shmidt41712582015-06-29 11:02:15 -07002330 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002331 return -1;
2332
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002333 os_get_reltime(&now);
Hai Shalomfdcde762020-04-02 11:19:20 -07002334 if (os_reltime_expired(&now, &wpa_s->last_scan,
2335 SCAN_RES_VALID_FOR_CONNECT)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002336 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2337 return -1;
2338 }
2339
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002340 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002341#endif /* CONFIG_NO_SCAN_PROCESSING */
2342}
2343
Dmitry Shmidt04949592012-07-19 12:16:46 -07002344#ifdef CONFIG_WNM
2345
2346static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2347{
2348 struct wpa_supplicant *wpa_s = eloop_ctx;
2349
2350 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2351 return;
2352
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002353 if (!wpa_s->no_keep_alive) {
2354 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2355 MAC2STR(wpa_s->bssid));
2356 /* TODO: could skip this if normal data traffic has been sent */
2357 /* TODO: Consider using some more appropriate data frame for
2358 * this */
2359 if (wpa_s->l2)
2360 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2361 (u8 *) "", 0);
2362 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002363
2364#ifdef CONFIG_SME
2365 if (wpa_s->sme.bss_max_idle_period) {
2366 unsigned int msec;
2367 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2368 if (msec > 100)
2369 msec -= 100;
2370 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2371 wnm_bss_keep_alive, wpa_s, NULL);
2372 }
2373#endif /* CONFIG_SME */
2374}
2375
2376
2377static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2378 const u8 *ies, size_t ies_len)
2379{
2380 struct ieee802_11_elems elems;
2381
2382 if (ies == NULL)
2383 return;
2384
2385 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2386 return;
2387
2388#ifdef CONFIG_SME
2389 if (elems.bss_max_idle_period) {
2390 unsigned int msec;
2391 wpa_s->sme.bss_max_idle_period =
2392 WPA_GET_LE16(elems.bss_max_idle_period);
2393 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2394 "TU)%s", wpa_s->sme.bss_max_idle_period,
2395 (elems.bss_max_idle_period[2] & 0x01) ?
2396 " (protected keep-live required)" : "");
2397 if (wpa_s->sme.bss_max_idle_period == 0)
2398 wpa_s->sme.bss_max_idle_period = 1;
2399 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2400 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2401 /* msec times 1000 */
2402 msec = wpa_s->sme.bss_max_idle_period * 1024;
2403 if (msec > 100)
2404 msec -= 100;
2405 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2406 wnm_bss_keep_alive, wpa_s,
2407 NULL);
2408 }
2409 }
2410#endif /* CONFIG_SME */
2411}
2412
2413#endif /* CONFIG_WNM */
2414
2415
2416void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2417{
2418#ifdef CONFIG_WNM
2419 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2420#endif /* CONFIG_WNM */
2421}
2422
2423
Dmitry Shmidt051af732013-10-22 13:52:46 -07002424#ifdef CONFIG_INTERWORKING
2425
2426static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2427 size_t len)
2428{
2429 int res;
2430
2431 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2432 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2433 if (res) {
2434 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2435 }
2436
2437 return res;
2438}
2439
2440
2441static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2442 const u8 *ies, size_t ies_len)
2443{
2444 struct ieee802_11_elems elems;
2445
2446 if (ies == NULL)
2447 return;
2448
2449 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2450 return;
2451
2452 if (elems.qos_map_set) {
2453 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2454 elems.qos_map_set_len);
2455 }
2456}
2457
2458#endif /* CONFIG_INTERWORKING */
2459
2460
Hai Shalom74f70d42019-02-11 14:42:39 -08002461static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2462 const u8 *ies, size_t ies_len)
2463{
2464 struct ieee802_11_elems elems;
2465 const u8 *map_sub_elem, *pos;
2466 size_t len;
2467
Hai Shalomfdcde762020-04-02 11:19:20 -07002468 wpa_s->multi_ap_ie = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08002469
Hai Shalomfdcde762020-04-02 11:19:20 -07002470 if (!ies ||
2471 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
2472 !elems.multi_ap || elems.multi_ap_len < 7)
2473 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08002474
2475 pos = elems.multi_ap + 4;
2476 len = elems.multi_ap_len - 4;
2477
2478 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
Hai Shalomfdcde762020-04-02 11:19:20 -07002479 if (!map_sub_elem || map_sub_elem[1] < 1)
2480 return;
2481
2482 wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS);
2483 wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] &
2484 MULTI_AP_FRONTHAUL_BSS);
2485 wpa_s->multi_ap_ie = 1;
2486}
2487
2488
2489static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
2490{
2491 if (!wpa_s->current_ssid ||
2492 !wpa_s->current_ssid->multi_ap_backhaul_sta)
2493 return;
2494
2495 if (!wpa_s->multi_ap_ie) {
2496 wpa_printf(MSG_INFO,
2497 "AP does not include valid Multi-AP element");
Hai Shalom74f70d42019-02-11 14:42:39 -08002498 goto fail;
2499 }
2500
Hai Shalomfdcde762020-04-02 11:19:20 -07002501 if (!wpa_s->multi_ap_backhaul) {
2502 if (wpa_s->multi_ap_fronthaul &&
Hai Shalom021b0b52019-04-10 11:17:58 -07002503 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2504 wpa_printf(MSG_INFO,
2505 "WPS active, accepting fronthaul-only BSS");
2506 /* Don't set 4addr mode in this case, so just return */
2507 return;
2508 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002509 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2510 goto fail;
2511 }
2512
2513 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2514 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2515 goto fail;
2516 }
2517 wpa_s->enabled_4addr_mode = 1;
2518 return;
2519
2520fail:
2521 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2522}
2523
2524
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002525#ifdef CONFIG_FST
2526static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2527 const u8 *ie, size_t ie_len)
2528{
2529 struct mb_ies_info mb_ies;
2530
2531 if (!ie || !ie_len || !wpa_s->fst)
2532 return -ENOENT;
2533
2534 os_memset(&mb_ies, 0, sizeof(mb_ies));
2535
2536 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2537 size_t len;
2538
2539 len = 2 + ie[1];
2540 if (len > ie_len) {
2541 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2542 ie, ie_len);
2543 break;
2544 }
2545
2546 if (ie[0] == WLAN_EID_MULTI_BAND) {
2547 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2548 (unsigned int) len);
2549 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2550 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2551 mb_ies.nof_ies++;
2552 }
2553
2554 ie_len -= len;
2555 ie += len;
2556 }
2557
2558 if (mb_ies.nof_ies > 0) {
2559 wpabuf_free(wpa_s->received_mb_ies);
2560 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2561 return 0;
2562 }
2563
2564 return -ENOENT;
2565}
2566#endif /* CONFIG_FST */
2567
2568
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002569static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2570 union wpa_event_data *data)
2571{
Hai Shalomc3565922019-10-28 11:58:20 -07002572 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002573 const u8 *p;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002574#if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002575 u8 bssid[ETH_ALEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -07002576#endif /* CONFIG_IEEE80211R || CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002577
2578 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
2579 if (data->assoc_info.req_ies)
2580 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2581 data->assoc_info.req_ies_len);
2582 if (data->assoc_info.resp_ies) {
2583 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2584 data->assoc_info.resp_ies_len);
2585#ifdef CONFIG_TDLS
2586 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2587 data->assoc_info.resp_ies_len);
2588#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002589#ifdef CONFIG_WNM
2590 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2591 data->assoc_info.resp_ies_len);
2592#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002593#ifdef CONFIG_INTERWORKING
2594 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2595 data->assoc_info.resp_ies_len);
2596#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002597 if (wpa_s->hw_capab == CAPAB_VHT &&
2598 get_ie(data->assoc_info.resp_ies,
2599 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2600 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002601
2602 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2603 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002604 }
2605 if (data->assoc_info.beacon_ies)
2606 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2607 data->assoc_info.beacon_ies,
2608 data->assoc_info.beacon_ies_len);
2609 if (data->assoc_info.freq)
2610 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2611 data->assoc_info.freq);
2612
Hai Shalom021b0b52019-04-10 11:17:58 -07002613 wpa_s->connection_set = 0;
2614 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2615 struct ieee802_11_elems req_elems, resp_elems;
2616
2617 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2618 data->assoc_info.req_ies_len,
2619 &req_elems, 0) != ParseFailed &&
2620 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2621 data->assoc_info.resp_ies_len,
2622 &resp_elems, 0) != ParseFailed) {
2623 wpa_s->connection_set = 1;
Kai Shi4fa8e772020-08-12 19:02:21 -07002624 wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) ||
2625 supp_rates_11b_only(&resp_elems);
Hai Shalom021b0b52019-04-10 11:17:58 -07002626 wpa_s->connection_ht = req_elems.ht_capabilities &&
2627 resp_elems.ht_capabilities;
Hai Shalomfdcde762020-04-02 11:19:20 -07002628 /* Do not include subset of VHT on 2.4 GHz vendor
2629 * extension in consideration for reporting VHT
2630 * association. */
Hai Shalom021b0b52019-04-10 11:17:58 -07002631 wpa_s->connection_vht = req_elems.vht_capabilities &&
Hai Shalomfdcde762020-04-02 11:19:20 -07002632 resp_elems.vht_capabilities &&
2633 (!data->assoc_info.freq ||
2634 wpas_freq_to_band(data->assoc_info.freq) !=
2635 BAND_2_4_GHZ);
Hai Shalom021b0b52019-04-10 11:17:58 -07002636 wpa_s->connection_he = req_elems.he_capabilities &&
2637 resp_elems.he_capabilities;
Kai Shi1e985032020-01-13 16:39:49 -08002638
2639 int max_nss_rx_req = get_max_nss_capability(&req_elems, 1);
2640 int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1);
2641 wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ?
2642 max_nss_rx_req : max_nss_rx_resp;
2643 int max_nss_tx_req = get_max_nss_capability(&req_elems, 0);
2644 int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0);
2645 wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ?
2646 max_nss_tx_req : max_nss_tx_resp;
2647
2648 struct supported_chan_width sta_supported_chan_width =
2649 get_supported_channel_width(&req_elems);
2650 enum chan_width ap_operation_chan_width =
2651 get_operation_channel_width(&resp_elems);
2652 if (wpa_s->connection_vht || wpa_s->connection_he) {
2653 wpa_s->connection_channel_bandwidth =
2654 get_sta_operation_chan_width(ap_operation_chan_width,
2655 sta_supported_chan_width);
2656 } else if (wpa_s->connection_ht) {
2657 wpa_s->connection_channel_bandwidth = (ap_operation_chan_width
2658 == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20;
2659 } else {
2660 wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20;
2661 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002662 }
2663 }
2664
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002665 p = data->assoc_info.req_ies;
2666 l = data->assoc_info.req_ies_len;
2667
2668 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2669 while (p && l >= 2) {
2670 len = p[1] + 2;
2671 if (len > l) {
2672 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2673 p, l);
2674 break;
2675 }
Hai Shalomc3565922019-10-28 11:58:20 -07002676 if (!found &&
2677 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2678 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2679 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2680 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2681 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002682 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2683 break;
2684 found = 1;
2685 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07002686 }
2687 if (!found_x && p[0] == WLAN_EID_RSNX) {
2688 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
2689 break;
2690 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002691 }
2692 l -= len;
2693 p += len;
2694 }
2695 if (!found && data->assoc_info.req_ies)
2696 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002697 if (!found_x && data->assoc_info.req_ies)
2698 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002700#ifdef CONFIG_FILS
2701#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002702 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2703 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002704 (!data->assoc_info.resp_frame ||
2705 fils_process_assoc_resp(wpa_s->wpa,
2706 data->assoc_info.resp_frame,
2707 data->assoc_info.resp_frame_len) < 0)) {
2708 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2709 return -1;
2710 }
2711#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002712
2713 /* Additional processing for FILS when SME is in driver */
2714 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2715 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2716 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002717#endif /* CONFIG_FILS */
2718
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002719#ifdef CONFIG_OWE
2720 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
2721 (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2722 owe_process_assoc_resp(wpa_s->wpa, bssid,
2723 data->assoc_info.resp_ies,
2724 data->assoc_info.resp_ies_len) < 0)) {
2725 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2726 return -1;
2727 }
2728#endif /* CONFIG_OWE */
2729
Hai Shalom021b0b52019-04-10 11:17:58 -07002730#ifdef CONFIG_DPP2
2731 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002732 if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
2733 wpa_s->dpp_pfs) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002734 struct ieee802_11_elems elems;
2735
2736 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2737 data->assoc_info.resp_ies_len,
2738 &elems, 0) == ParseFailed ||
2739 !elems.owe_dh)
2740 goto no_pfs;
2741 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2742 elems.owe_dh_len) < 0) {
2743 wpa_supplicant_deauthenticate(wpa_s,
2744 WLAN_REASON_UNSPECIFIED);
2745 return -1;
2746 }
2747
2748 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2749 }
2750no_pfs:
2751#endif /* CONFIG_DPP2 */
2752
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002753#ifdef CONFIG_IEEE80211R
2754#ifdef CONFIG_SME
2755 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002756 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2757 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2758 data->assoc_info.resp_ies,
2759 data->assoc_info.resp_ies_len,
2760 bssid) < 0) {
2761 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2762 "Reassociation Response failed");
2763 wpa_supplicant_deauthenticate(
2764 wpa_s, WLAN_REASON_INVALID_IE);
2765 return -1;
2766 }
2767 }
2768
2769 p = data->assoc_info.resp_ies;
2770 l = data->assoc_info.resp_ies_len;
2771
2772#ifdef CONFIG_WPS_STRICT
2773 if (p && wpa_s->current_ssid &&
2774 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2775 struct wpabuf *wps;
2776 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2777 if (wps == NULL) {
2778 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2779 "include WPS IE in (Re)Association Response");
2780 return -1;
2781 }
2782
2783 if (wps_validate_assoc_resp(wps) < 0) {
2784 wpabuf_free(wps);
2785 wpa_supplicant_deauthenticate(
2786 wpa_s, WLAN_REASON_INVALID_IE);
2787 return -1;
2788 }
2789 wpabuf_free(wps);
2790 }
2791#endif /* CONFIG_WPS_STRICT */
2792
2793 /* Go through the IEs and make a copy of the MDIE, if present. */
2794 while (p && l >= 2) {
2795 len = p[1] + 2;
2796 if (len > l) {
2797 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2798 p, l);
2799 break;
2800 }
2801 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2802 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2803 wpa_s->sme.ft_used = 1;
2804 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2805 MOBILITY_DOMAIN_ID_LEN);
2806 break;
2807 }
2808 l -= len;
2809 p += len;
2810 }
2811#endif /* CONFIG_SME */
2812
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002813 /* Process FT when SME is in the driver */
2814 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2815 wpa_ft_is_completed(wpa_s->wpa)) {
2816 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2817 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2818 data->assoc_info.resp_ies,
2819 data->assoc_info.resp_ies_len,
2820 bssid) < 0) {
2821 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2822 "Reassociation Response failed");
2823 wpa_supplicant_deauthenticate(
2824 wpa_s, WLAN_REASON_INVALID_IE);
2825 return -1;
2826 }
2827 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2828 }
2829
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002830 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2831 data->assoc_info.resp_ies_len);
2832#endif /* CONFIG_IEEE80211R */
2833
2834 /* WPA/RSN IE from Beacon/ProbeResp */
2835 p = data->assoc_info.beacon_ies;
2836 l = data->assoc_info.beacon_ies_len;
2837
2838 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2839 */
2840 wpa_found = rsn_found = 0;
2841 while (p && l >= 2) {
2842 len = p[1] + 2;
2843 if (len > l) {
2844 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2845 p, l);
2846 break;
2847 }
2848 if (!wpa_found &&
2849 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2850 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2851 wpa_found = 1;
2852 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2853 }
2854
2855 if (!rsn_found &&
2856 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2857 rsn_found = 1;
2858 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2859 }
2860
Hai Shalomc3565922019-10-28 11:58:20 -07002861 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
2862 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
2863
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002864 l -= len;
2865 p += len;
2866 }
2867
2868 if (!wpa_found && data->assoc_info.beacon_ies)
2869 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002870 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002871 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002872 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
2873 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002874 if (wpa_found || rsn_found)
2875 wpa_s->ap_ies_from_associnfo = 1;
2876
Jouni Malinen87fd2792011-05-16 18:35:42 +03002877 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2878 wpa_s->assoc_freq != data->assoc_info.freq) {
2879 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2880 "%u to %u MHz",
2881 wpa_s->assoc_freq, data->assoc_info.freq);
2882 wpa_supplicant_update_scan_results(wpa_s);
2883 }
2884
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002885 wpa_s->assoc_freq = data->assoc_info.freq;
2886
2887 return 0;
2888}
2889
2890
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002891static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2892{
Hai Shalomc3565922019-10-28 11:58:20 -07002893 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002894
2895 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2896 return -1;
2897
2898 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2899 return 0;
2900
2901 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2902 WPA_IE_VENDOR_TYPE);
2903 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07002904 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002905
2906 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2907 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2908 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07002909 bss_rsn ? 2 + bss_rsn[1] : 0) ||
2910 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
2911 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002912 return -1;
2913
2914 return 0;
2915}
2916
2917
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002918static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2919 union wpa_event_data *data)
2920{
2921#ifdef CONFIG_FST
2922 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2923 struct wpa_bss *bss = wpa_s->current_bss;
2924 const u8 *ieprb, *iebcn;
2925
2926 wpabuf_free(wpa_s->received_mb_ies);
2927 wpa_s->received_mb_ies = NULL;
2928
2929 if (ai &&
2930 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2931 wpa_printf(MSG_DEBUG,
2932 "FST: MB IEs updated from Association Response frame");
2933 return;
2934 }
2935
2936 if (ai &&
2937 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2938 wpa_printf(MSG_DEBUG,
2939 "FST: MB IEs updated from association event Beacon IEs");
2940 return;
2941 }
2942
2943 if (!bss)
2944 return;
2945
2946 ieprb = (const u8 *) (bss + 1);
2947 iebcn = ieprb + bss->ie_len;
2948
2949 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2950 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2951 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2952 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2953#endif /* CONFIG_FST */
2954}
2955
2956
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002957static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2958 union wpa_event_data *data)
2959{
2960 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002961 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002962 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07002963#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
2964 struct wpa_bss *bss;
2965#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002966
2967#ifdef CONFIG_AP
2968 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002969 if (!data)
2970 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002971 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2972 data->assoc_info.addr,
2973 data->assoc_info.req_ies,
2974 data->assoc_info.req_ies_len,
2975 data->assoc_info.reassoc);
2976 return;
2977 }
2978#endif /* CONFIG_AP */
2979
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002980 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07002981 wpa_s->own_reconnect_req = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002982
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002983 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2984 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2985 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002986 /*
2987 * FILS authentication can share the same mechanism to mark the
2988 * connection fully authenticated, so set ft_completed also based on
2989 * FILS result.
2990 */
2991 if (!ft_completed)
2992 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002993
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002994 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2995 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002996 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002997 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2998 return;
2999 }
3000
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003001 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003002 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003003 if (os_reltime_initialized(&wpa_s->session_start)) {
3004 os_reltime_age(&wpa_s->session_start,
3005 &wpa_s->session_length);
3006 wpa_s->session_start.sec = 0;
3007 wpa_s->session_start.usec = 0;
3008 wpas_notify_session_length(wpa_s);
3009 } else {
3010 wpas_notify_auth_changed(wpa_s);
3011 os_get_reltime(&wpa_s->session_start);
3012 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003013 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
3014 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003015 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003016 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003017 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
3018 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003019 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003020
3021 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
3022 wpa_clear_keys(wpa_s, bssid);
3023 }
3024 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003025 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003026 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3027 return;
3028 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003029 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003030
Hai Shalomfdcde762020-04-02 11:19:20 -07003031 multi_ap_set_4addr_mode(wpa_s);
3032
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003033 if (wpa_s->conf->ap_scan == 1 &&
3034 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07003035 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
3036 wpa_msg(wpa_s, MSG_WARNING,
3037 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003038 }
3039
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003040 wpas_fst_update_mb_assoc(wpa_s, data);
3041
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003042#ifdef CONFIG_SME
3043 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
3044 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07003045 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003046#endif /* CONFIG_SME */
3047
3048 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
3049 if (wpa_s->current_ssid) {
3050 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3051 * initialized before association, but for other modes,
3052 * initialize PC/SC here, if the current configuration needs
3053 * smartcard or SIM/USIM. */
3054 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
3055 }
3056 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3057 if (wpa_s->l2)
3058 l2_packet_notify_auth_start(wpa_s->l2);
3059
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003060 already_authorized = data && data->assoc_info.authorized;
3061
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003062 /*
Hai Shalome21d4e82020-04-29 16:34:06 -07003063 * Set portEnabled first to false in order to get EAP state machine out
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003064 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3065 * state machine may transit to AUTHENTICATING state based on obsolete
3066 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3067 * AUTHENTICATED without ever giving chance to EAP state machine to
3068 * reset the state.
3069 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003070 if (!ft_completed && !already_authorized) {
Hai Shalome21d4e82020-04-29 16:34:06 -07003071 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
3072 eapol_sm_notify_portValid(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003074 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3075 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
3076 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07003077 already_authorized || wpa_s->drv_authorized_port)
Hai Shalome21d4e82020-04-29 16:34:06 -07003078 eapol_sm_notify_eap_success(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003079 /* 802.1X::portControl = Auto */
Hai Shalome21d4e82020-04-29 16:34:06 -07003080 eapol_sm_notify_portEnabled(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003081 wpa_s->eapol_received = 0;
3082 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3083 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
3084 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07003085 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07003086 if (wpa_s->current_ssid &&
3087 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003088 (wpa_s->drv_flags &
3089 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
3090 /*
3091 * Set the key after having received joined-IBSS event
3092 * from the driver.
3093 */
3094 wpa_supplicant_set_wpa_none_key(wpa_s,
3095 wpa_s->current_ssid);
3096 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003097 wpa_supplicant_cancel_auth_timeout(wpa_s);
3098 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3099 } else if (!ft_completed) {
3100 /* Timeout for receiving the first EAPOL packet */
3101 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
3102 }
3103 wpa_supplicant_cancel_scan(wpa_s);
3104
Hai Shalom5f92bc92019-04-18 11:54:11 -07003105 if (ft_completed) {
3106 /*
3107 * FT protocol completed - make sure EAPOL state machine ends
3108 * up in authenticated.
3109 */
3110 wpa_supplicant_cancel_auth_timeout(wpa_s);
3111 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003112 eapol_sm_notify_portValid(wpa_s->eapol, true);
3113 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom5f92bc92019-04-18 11:54:11 -07003114 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
3115 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003116 /*
3117 * We are done; the driver will take care of RSN 4-way
3118 * handshake.
3119 */
3120 wpa_supplicant_cancel_auth_timeout(wpa_s);
3121 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07003122 eapol_sm_notify_portValid(wpa_s->eapol, true);
3123 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalom74f70d42019-02-11 14:42:39 -08003124 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003125 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
3126 /*
3127 * The driver will take care of RSN 4-way handshake, so we need
3128 * to allow EAPOL supplicant to complete its work without
3129 * waiting for WPA supplicant.
3130 */
Hai Shalome21d4e82020-04-29 16:34:06 -07003131 eapol_sm_notify_portValid(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003132 }
3133
Jouni Malinena05074c2012-12-21 21:35:35 +02003134 wpa_s->last_eapol_matches_bssid = 0;
3135
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003136#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -07003137 if (wpa_s->rsne_override_eapol) {
3138 wpa_printf(MSG_DEBUG,
3139 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3140 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
3141 wpabuf_head(wpa_s->rsne_override_eapol),
3142 wpabuf_len(wpa_s->rsne_override_eapol));
3143 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003144 if (wpa_s->rsnxe_override_eapol) {
3145 wpa_printf(MSG_DEBUG,
3146 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3147 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
3148 wpabuf_head(wpa_s->rsnxe_override_eapol),
3149 wpabuf_len(wpa_s->rsnxe_override_eapol));
3150 }
3151#endif /* CONFIG_TESTING_OPTIONS */
3152
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003153 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003154 struct os_reltime now, age;
3155 os_get_reltime(&now);
3156 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08003157 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003158 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
3159 0) {
3160 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
3161 "frame that was received just before "
3162 "association notification");
3163 wpa_supplicant_rx_eapol(
3164 wpa_s, wpa_s->pending_eapol_rx_src,
3165 wpabuf_head(wpa_s->pending_eapol_rx),
3166 wpabuf_len(wpa_s->pending_eapol_rx));
3167 }
3168 wpabuf_free(wpa_s->pending_eapol_rx);
3169 wpa_s->pending_eapol_rx = NULL;
3170 }
3171
Hai Shalomfdcde762020-04-02 11:19:20 -07003172#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003173 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3174 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003175 wpa_s->current_ssid &&
3176 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003177 /* Set static WEP keys again */
3178 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
3179 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003180#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003181
3182#ifdef CONFIG_IBSS_RSN
3183 if (wpa_s->current_ssid &&
3184 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3185 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3186 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
3187 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003188 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003189 if (!wpa_s->ibss_rsn) {
3190 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
3191 wpa_supplicant_deauthenticate(
3192 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3193 return;
3194 }
3195
3196 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3197 }
3198#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003199
3200 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003201
3202 if (data) {
3203 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3204 data->assoc_info.resp_ies_len,
3205 &data->assoc_info.wmm_params);
3206
3207 if (wpa_s->reassoc_same_bss)
3208 wmm_ac_restore_tspecs(wpa_s);
3209 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003210
Hai Shalomc3565922019-10-28 11:58:20 -07003211#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3212 bss = wpa_bss_get_bssid(wpa_s, bssid);
3213#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003214#ifdef CONFIG_FILS
3215 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003216 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3217
3218 if (fils_cache_id)
3219 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3220 }
3221#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003222
3223#ifdef CONFIG_MBO
3224 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3225#endif /* CONFIG_MBO */
Hai Shalomfdcde762020-04-02 11:19:20 -07003226
3227#ifdef CONFIG_DPP2
3228 wpa_s->dpp_pfs_fallback = 0;
3229#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003230}
3231
3232
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003233static int disconnect_reason_recoverable(u16 reason_code)
3234{
3235 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3236 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3237 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3238}
3239
3240
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003241static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003242 u16 reason_code,
3243 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003244{
3245 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003246
3247 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3248 /*
3249 * At least Host AP driver and a Prism3 card seemed to be
3250 * generating streams of disconnected events when configuring
3251 * IBSS for WPA-None. Ignore them for now.
3252 */
3253 return;
3254 }
3255
3256 bssid = wpa_s->bssid;
3257 if (is_zero_ether_addr(bssid))
3258 bssid = wpa_s->pending_bssid;
3259
3260 if (!is_zero_ether_addr(bssid) ||
3261 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3262 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3263 " reason=%d%s",
3264 MAC2STR(bssid), reason_code,
3265 locally_generated ? " locally_generated=1" : "");
3266 }
3267}
3268
3269
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003270static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3271 int locally_generated)
3272{
3273 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003274 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003275 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3276 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003277 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003278
3279 /*
3280 * It looks like connection was lost while trying to go through PSK
3281 * 4-way handshake. Filter out known disconnection cases that are caused
3282 * by something else than PSK mismatch to avoid confusing reports.
3283 */
3284
3285 if (locally_generated) {
3286 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3287 return 0;
3288 }
3289
3290 return 1;
3291}
3292
3293
Jouni Malinen2b89da82012-08-31 22:04:41 +03003294static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3295 u16 reason_code,
3296 int locally_generated)
3297{
3298 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003299 int authenticating;
3300 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003301 struct wpa_bss *fast_reconnect = NULL;
3302 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003303 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003304 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003305
3306 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3307 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3308
3309 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3310 /*
3311 * At least Host AP driver and a Prism3 card seemed to be
3312 * generating streams of disconnected events when configuring
3313 * IBSS for WPA-None. Ignore them for now.
3314 */
3315 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3316 "IBSS/WPA-None mode");
3317 return;
3318 }
3319
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003320 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3321 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3322 locally_generated)
3323 /*
3324 * Remove the inactive AP (which is probably out of range) from
3325 * the BSS list after marking disassociation. In particular
3326 * mac80211-based drivers use the
3327 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3328 * locally generated disconnection events for cases where the
3329 * AP does not reply anymore.
3330 */
3331 curr = wpa_s->current_bss;
3332
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003333 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003334 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3335 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003336 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3337 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003338 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003339#ifdef CONFIG_DPP2
3340 wpas_dpp_send_conn_status_result(wpa_s,
3341 DPP_STATUS_AUTH_FAILURE);
3342#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003343 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003344 if (!wpa_s->disconnected &&
3345 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003346 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003347 wpas_wps_searching(wpa_s) ||
3348 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003349 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003350 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003351 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003352 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003353 wpa_s->wpa_state);
3354 if (wpa_s->wpa_state == WPA_COMPLETED &&
3355 wpa_s->current_ssid &&
3356 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Hai Shalomfdcde762020-04-02 11:19:20 -07003357 (wpa_s->own_reconnect_req ||
3358 (!locally_generated &&
3359 disconnect_reason_recoverable(reason_code)))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003360 /*
3361 * It looks like the AP has dropped association with
Hai Shalomfdcde762020-04-02 11:19:20 -07003362 * us, but could allow us to get back in. This is also
3363 * triggered for cases where local reconnection request
3364 * is used to force reassociation with the same BSS.
3365 * Try to reconnect to the same BSS without a full scan
3366 * to save time for some common cases.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003367 */
3368 fast_reconnect = wpa_s->current_bss;
3369 fast_reconnect_ssid = wpa_s->current_ssid;
Hai Shalomfdcde762020-04-02 11:19:20 -07003370 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003371 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Hai Shalomfdcde762020-04-02 11:19:20 -07003372 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003373 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3374 "immediate scan");
Hai Shalomfdcde762020-04-02 11:19:20 -07003375 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003376 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003377 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003378 "try to re-connect");
3379 wpa_s->reassociate = 0;
3380 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003381 if (!wpa_s->pno)
3382 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003383 }
3384 bssid = wpa_s->bssid;
3385 if (is_zero_ether_addr(bssid))
3386 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003387 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3388 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003389 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003390 if (locally_generated)
3391 wpa_s->disconnect_reason = -reason_code;
3392 else
3393 wpa_s->disconnect_reason = reason_code;
3394 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003395 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3396 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003397 wpa_clear_keys(wpa_s, wpa_s->bssid);
3398 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003399 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003400 wpa_supplicant_mark_disassoc(wpa_s);
3401
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003402 if (curr)
3403 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3404
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003405 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003406 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003407 wpa_s->current_ssid = last_ssid;
3408 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003409
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003410 if (fast_reconnect &&
3411 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3412 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3413 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3414 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003415 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003416 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003417#ifndef CONFIG_NO_SCAN_PROCESSING
3418 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3419 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3420 fast_reconnect_ssid) < 0) {
3421 /* Recover through full scan */
3422 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3423 }
3424#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003425 } else if (fast_reconnect) {
3426 /*
3427 * Could not reconnect to the same BSS due to network being
3428 * disabled. Use a new scan to match the alternative behavior
3429 * above, i.e., to continue automatic reconnection attempt in a
3430 * way that enforces disabled network rules.
3431 */
3432 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003433 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003434}
3435
3436
3437#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003438void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003439{
3440 struct wpa_supplicant *wpa_s = eloop_ctx;
3441
3442 if (!wpa_s->pending_mic_error_report)
3443 return;
3444
3445 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3446 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3447 wpa_s->pending_mic_error_report = 0;
3448}
3449#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3450
3451
3452static void
3453wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3454 union wpa_event_data *data)
3455{
3456 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003457 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003458
3459 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3460 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003461 os_get_reltime(&t);
3462 if ((wpa_s->last_michael_mic_error.sec &&
3463 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003464 wpa_s->pending_mic_error_report) {
3465 if (wpa_s->pending_mic_error_report) {
3466 /*
3467 * Send the pending MIC error report immediately since
3468 * we are going to start countermeasures and AP better
3469 * do the same.
3470 */
3471 wpa_sm_key_request(wpa_s->wpa, 1,
3472 wpa_s->pending_mic_error_pairwise);
3473 }
3474
3475 /* Send the new MIC error report immediately since we are going
3476 * to start countermeasures and AP better do the same.
3477 */
3478 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3479
3480 /* initialize countermeasures */
3481 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003482
3483 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3484
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003485 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3486
3487 /*
3488 * Need to wait for completion of request frame. We do not get
3489 * any callback for the message completion, so just wait a
3490 * short while and hope for the best. */
3491 os_sleep(0, 10000);
3492
3493 wpa_drv_set_countermeasures(wpa_s, 1);
3494 wpa_supplicant_deauthenticate(wpa_s,
3495 WLAN_REASON_MICHAEL_MIC_FAILURE);
3496 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3497 wpa_s, NULL);
3498 eloop_register_timeout(60, 0,
3499 wpa_supplicant_stop_countermeasures,
3500 wpa_s, NULL);
3501 /* TODO: mark the AP rejected for 60 second. STA is
3502 * allowed to associate with another AP.. */
3503 } else {
3504#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3505 if (wpa_s->mic_errors_seen) {
3506 /*
3507 * Reduce the effectiveness of Michael MIC error
3508 * reports as a means for attacking against TKIP if
3509 * more than one MIC failure is noticed with the same
3510 * PTK. We delay the transmission of the reports by a
3511 * random time between 0 and 60 seconds in order to
3512 * force the attacker wait 60 seconds before getting
3513 * the information on whether a frame resulted in a MIC
3514 * failure.
3515 */
3516 u8 rval[4];
3517 int sec;
3518
3519 if (os_get_random(rval, sizeof(rval)) < 0)
3520 sec = os_random() % 60;
3521 else
3522 sec = WPA_GET_BE32(rval) % 60;
3523 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3524 "report %d seconds", sec);
3525 wpa_s->pending_mic_error_report = 1;
3526 wpa_s->pending_mic_error_pairwise = pairwise;
3527 eloop_cancel_timeout(
3528 wpa_supplicant_delayed_mic_error_report,
3529 wpa_s, NULL);
3530 eloop_register_timeout(
3531 sec, os_random() % 1000000,
3532 wpa_supplicant_delayed_mic_error_report,
3533 wpa_s, NULL);
3534 } else {
3535 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3536 }
3537#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3538 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3539#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3540 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003541 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003542 wpa_s->mic_errors_seen++;
3543}
3544
3545
3546#ifdef CONFIG_TERMINATE_ONLASTIF
3547static int any_interfaces(struct wpa_supplicant *head)
3548{
3549 struct wpa_supplicant *wpa_s;
3550
3551 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3552 if (!wpa_s->interface_removed)
3553 return 1;
3554 return 0;
3555}
3556#endif /* CONFIG_TERMINATE_ONLASTIF */
3557
3558
3559static void
3560wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3561 union wpa_event_data *data)
3562{
3563 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3564 return;
3565
3566 switch (data->interface_status.ievent) {
3567 case EVENT_INTERFACE_ADDED:
3568 if (!wpa_s->interface_removed)
3569 break;
3570 wpa_s->interface_removed = 0;
3571 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3572 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3573 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3574 "driver after interface was added");
3575 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003576
3577#ifdef CONFIG_P2P
3578 if (!wpa_s->global->p2p &&
3579 !wpa_s->global->p2p_disabled &&
3580 !wpa_s->conf->p2p_disabled &&
3581 (wpa_s->drv_flags &
3582 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3583 wpas_p2p_add_p2pdev_interface(
3584 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3585 wpa_printf(MSG_INFO,
3586 "P2P: Failed to enable P2P Device interface");
3587 /* Try to continue without. P2P will be disabled. */
3588 }
3589#endif /* CONFIG_P2P */
3590
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003591 break;
3592 case EVENT_INTERFACE_REMOVED:
3593 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3594 wpa_s->interface_removed = 1;
3595 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003596 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003597 l2_packet_deinit(wpa_s->l2);
3598 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003599
3600#ifdef CONFIG_P2P
3601 if (wpa_s->global->p2p &&
3602 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3603 (wpa_s->drv_flags &
3604 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3605 wpa_dbg(wpa_s, MSG_DEBUG,
3606 "Removing P2P Device interface");
3607 wpa_supplicant_remove_iface(
3608 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3609 0);
3610 wpa_s->global->p2p_init_wpa_s = NULL;
3611 }
3612#endif /* CONFIG_P2P */
3613
Dmitry Shmidte4663042016-04-04 10:07:49 -07003614#ifdef CONFIG_MATCH_IFACE
3615 if (wpa_s->matched) {
3616 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3617 break;
3618 }
3619#endif /* CONFIG_MATCH_IFACE */
3620
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003621#ifdef CONFIG_TERMINATE_ONLASTIF
3622 /* check if last interface */
3623 if (!any_interfaces(wpa_s->global->ifaces))
3624 eloop_terminate();
3625#endif /* CONFIG_TERMINATE_ONLASTIF */
3626 break;
3627 }
3628}
3629
3630
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003631#ifdef CONFIG_TDLS
3632static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3633 union wpa_event_data *data)
3634{
3635 if (data == NULL)
3636 return;
3637 switch (data->tdls.oper) {
3638 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003639 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3640 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3641 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3642 else
3643 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003644 break;
3645 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003646 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3647 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3648 data->tdls.reason_code);
3649 else
3650 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3651 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003652 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003653 case TDLS_REQUEST_DISCOVER:
3654 wpa_tdls_send_discovery_request(wpa_s->wpa,
3655 data->tdls.peer);
3656 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003657 }
3658}
3659#endif /* CONFIG_TDLS */
3660
3661
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003662#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003663static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3664 union wpa_event_data *data)
3665{
3666 if (data == NULL)
3667 return;
3668 switch (data->wnm.oper) {
3669 case WNM_OPER_SLEEP:
3670 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3671 "(action=%d, intval=%d)",
3672 data->wnm.sleep_action, data->wnm.sleep_intval);
3673 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003674 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003675 break;
3676 }
3677}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003678#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003679
3680
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003681#ifdef CONFIG_IEEE80211R
3682static void
3683wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3684 union wpa_event_data *data)
3685{
3686 if (data == NULL)
3687 return;
3688
3689 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3690 data->ft_ies.ies_len,
3691 data->ft_ies.ft_action,
3692 data->ft_ies.target_ap,
3693 data->ft_ies.ric_ies,
3694 data->ft_ies.ric_ies_len) < 0) {
3695 /* TODO: prevent MLME/driver from trying to associate? */
3696 }
3697}
3698#endif /* CONFIG_IEEE80211R */
3699
3700
3701#ifdef CONFIG_IBSS_RSN
3702static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3703 union wpa_event_data *data)
3704{
3705 struct wpa_ssid *ssid;
3706 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3707 return;
3708 if (data == NULL)
3709 return;
3710 ssid = wpa_s->current_ssid;
3711 if (ssid == NULL)
3712 return;
3713 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3714 return;
3715
3716 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3717}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003718
3719
3720static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3721 union wpa_event_data *data)
3722{
3723 struct wpa_ssid *ssid = wpa_s->current_ssid;
3724
3725 if (ssid == NULL)
3726 return;
3727
3728 /* check if the ssid is correctly configured as IBSS/RSN */
3729 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3730 return;
3731
3732 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3733 data->rx_mgmt.frame_len);
3734}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003735#endif /* CONFIG_IBSS_RSN */
3736
3737
3738#ifdef CONFIG_IEEE80211R
3739static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3740 size_t len)
3741{
3742 const u8 *sta_addr, *target_ap_addr;
3743 u16 status;
3744
3745 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3746 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3747 return; /* only SME case supported for now */
3748 if (len < 1 + 2 * ETH_ALEN + 2)
3749 return;
3750 if (data[0] != 2)
3751 return; /* Only FT Action Response is supported for now */
3752 sta_addr = data + 1;
3753 target_ap_addr = data + 1 + ETH_ALEN;
3754 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3755 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3756 MACSTR " TargetAP " MACSTR " status %u",
3757 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3758
3759 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3760 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3761 " in FT Action Response", MAC2STR(sta_addr));
3762 return;
3763 }
3764
3765 if (status) {
3766 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3767 "failure (status code %d)", status);
3768 /* TODO: report error to FT code(?) */
3769 return;
3770 }
3771
3772 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3773 len - (1 + 2 * ETH_ALEN + 2), 1,
3774 target_ap_addr, NULL, 0) < 0)
3775 return;
3776
3777#ifdef CONFIG_SME
3778 {
3779 struct wpa_bss *bss;
3780 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3781 if (bss)
3782 wpa_s->sme.freq = bss->freq;
3783 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3784 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3785 WLAN_AUTH_FT);
3786 }
3787#endif /* CONFIG_SME */
3788}
3789#endif /* CONFIG_IEEE80211R */
3790
3791
3792static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3793 struct unprot_deauth *e)
3794{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003795 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3796 "dropped: " MACSTR " -> " MACSTR
3797 " (reason code %u)",
3798 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3799 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003800}
3801
3802
3803static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3804 struct unprot_disassoc *e)
3805{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003806 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3807 "dropped: " MACSTR " -> " MACSTR
3808 " (reason code %u)",
3809 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3810 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003811}
3812
3813
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003814static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3815 u16 reason_code, int locally_generated,
3816 const u8 *ie, size_t ie_len, int deauth)
3817{
3818#ifdef CONFIG_AP
3819 if (wpa_s->ap_iface && addr) {
3820 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3821 return;
3822 }
3823
3824 if (wpa_s->ap_iface) {
3825 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3826 return;
3827 }
3828#endif /* CONFIG_AP */
3829
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003830 if (!locally_generated)
3831 wpa_s->own_disconnect_req = 0;
3832
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003833 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3834
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003835 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3836 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3837 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3838 eapol_sm_failed(wpa_s->eapol))) &&
3839 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003840 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003841
3842#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003843 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003844 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3845 locally_generated) > 0) {
3846 /*
3847 * The interface was removed, so cannot continue
3848 * processing any additional operations after this.
3849 */
3850 return;
3851 }
3852 }
3853#endif /* CONFIG_P2P */
3854
3855 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3856 locally_generated);
3857}
3858
3859
3860static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3861 struct disassoc_info *info)
3862{
3863 u16 reason_code = 0;
3864 int locally_generated = 0;
3865 const u8 *addr = NULL;
3866 const u8 *ie = NULL;
3867 size_t ie_len = 0;
3868
3869 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3870
3871 if (info) {
3872 addr = info->addr;
3873 ie = info->ie;
3874 ie_len = info->ie_len;
3875 reason_code = info->reason_code;
3876 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07003877 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
3878 reason2str(reason_code),
3879 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003880 if (addr)
3881 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3882 MAC2STR(addr));
3883 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3884 ie, ie_len);
3885 }
3886
3887#ifdef CONFIG_AP
3888 if (wpa_s->ap_iface && info && info->addr) {
3889 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3890 return;
3891 }
3892
3893 if (wpa_s->ap_iface) {
3894 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3895 return;
3896 }
3897#endif /* CONFIG_AP */
3898
3899#ifdef CONFIG_P2P
3900 if (info) {
3901 wpas_p2p_disassoc_notif(
3902 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3903 locally_generated);
3904 }
3905#endif /* CONFIG_P2P */
3906
3907 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3908 sme_event_disassoc(wpa_s, info);
3909
3910 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3911 ie, ie_len, 0);
3912}
3913
3914
3915static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3916 struct deauth_info *info)
3917{
3918 u16 reason_code = 0;
3919 int locally_generated = 0;
3920 const u8 *addr = NULL;
3921 const u8 *ie = NULL;
3922 size_t ie_len = 0;
3923
3924 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3925
3926 if (info) {
3927 addr = info->addr;
3928 ie = info->ie;
3929 ie_len = info->ie_len;
3930 reason_code = info->reason_code;
3931 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07003932 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
3933 reason_code, reason2str(reason_code),
3934 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003935 if (addr) {
3936 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3937 MAC2STR(addr));
3938 }
3939 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3940 ie, ie_len);
3941 }
3942
3943 wpa_reset_ft_completed(wpa_s->wpa);
3944
3945 wpas_event_disconnect(wpa_s, addr, reason_code,
3946 locally_generated, ie, ie_len, 1);
3947}
3948
3949
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003950static const char * reg_init_str(enum reg_change_initiator init)
3951{
3952 switch (init) {
3953 case REGDOM_SET_BY_CORE:
3954 return "CORE";
3955 case REGDOM_SET_BY_USER:
3956 return "USER";
3957 case REGDOM_SET_BY_DRIVER:
3958 return "DRIVER";
3959 case REGDOM_SET_BY_COUNTRY_IE:
3960 return "COUNTRY_IE";
3961 case REGDOM_BEACON_HINT:
3962 return "BEACON_HINT";
3963 }
3964 return "?";
3965}
3966
3967
3968static const char * reg_type_str(enum reg_type type)
3969{
3970 switch (type) {
3971 case REGDOM_TYPE_UNKNOWN:
3972 return "UNKNOWN";
3973 case REGDOM_TYPE_COUNTRY:
3974 return "COUNTRY";
3975 case REGDOM_TYPE_WORLD:
3976 return "WORLD";
3977 case REGDOM_TYPE_CUSTOM_WORLD:
3978 return "CUSTOM_WORLD";
3979 case REGDOM_TYPE_INTERSECTION:
3980 return "INTERSECTION";
3981 }
3982 return "?";
3983}
3984
3985
Hai Shalom74f70d42019-02-11 14:42:39 -08003986void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
3987 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003988{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003989 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003990 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003991
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003992 /*
3993 * To allow backwards compatibility with higher level layers that
3994 * assumed the REGDOM_CHANGE event is sent over the initially added
3995 * interface. Find the highest parent of this interface and use it to
3996 * send the event.
3997 */
3998 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3999 ;
4000
Hai Shalom74f70d42019-02-11 14:42:39 -08004001 if (info) {
4002 wpa_msg(ifs, MSG_INFO,
4003 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
4004 reg_init_str(info->initiator), reg_type_str(info->type),
4005 info->alpha2[0] ? " alpha2=" : "",
4006 info->alpha2[0] ? info->alpha2 : "");
4007 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004008
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004009 if (wpa_s->drv_priv == NULL)
4010 return; /* Ignore event during drv initialization */
4011
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004012 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
4013 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004014 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
4015 ifs->ifname);
4016 free_hw_features(ifs);
4017 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004018 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004019
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004020 /* Restart PNO/sched_scan with updated channel list */
4021 if (ifs->pno) {
4022 wpas_stop_pno(ifs);
4023 wpas_start_pno(ifs);
4024 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
4025 wpa_dbg(ifs, MSG_DEBUG,
4026 "Channel list changed - restart sched_scan");
4027 wpas_scan_restart_sched_scan(ifs);
4028 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07004029 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004030
4031 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004032}
4033
4034
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004035static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004036 const u8 *frame, size_t len, int freq,
4037 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004038{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004039 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004040 const u8 *payload;
4041 size_t plen;
4042 u8 category;
4043
4044 if (len < IEEE80211_HDRLEN + 2)
4045 return;
4046
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004047 mgmt = (const struct ieee80211_mgmt *) frame;
4048 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004049 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004050 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004051
4052 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
4053 " Category=%u DataLen=%d freq=%d MHz",
4054 MAC2STR(mgmt->sa), category, (int) plen, freq);
4055
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004056 if (category == WLAN_ACTION_WMM) {
4057 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
4058 return;
4059 }
4060
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004061#ifdef CONFIG_IEEE80211R
4062 if (category == WLAN_ACTION_FT) {
4063 ft_rx_action(wpa_s, payload, plen);
4064 return;
4065 }
4066#endif /* CONFIG_IEEE80211R */
4067
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004068#ifdef CONFIG_SME
4069 if (category == WLAN_ACTION_SA_QUERY) {
4070 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
4071 return;
4072 }
4073#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004074
4075#ifdef CONFIG_WNM
4076 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
4077 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
4078 return;
4079 }
4080#endif /* CONFIG_WNM */
4081
4082#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08004083 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4084 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004085 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08004086 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004087 payload, plen, freq) == 0)
4088 return;
4089#endif /* CONFIG_GAS */
4090
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004091#ifdef CONFIG_GAS_SERVER
4092 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
4093 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
4094 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
4095 mgmt->u.action.category,
4096 payload, plen, freq) == 0)
4097 return;
4098#endif /* CONFIG_GAS_SERVER */
4099
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004100#ifdef CONFIG_TDLS
4101 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
4102 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
4103 wpa_dbg(wpa_s, MSG_DEBUG,
4104 "TDLS: Received Discovery Response from " MACSTR,
4105 MAC2STR(mgmt->sa));
4106 return;
4107 }
4108#endif /* CONFIG_TDLS */
4109
4110#ifdef CONFIG_INTERWORKING
4111 if (category == WLAN_ACTION_QOS && plen >= 1 &&
4112 payload[0] == QOS_QOS_MAP_CONFIG) {
4113 const u8 *pos = payload + 1;
4114 size_t qlen = plen - 1;
4115 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
4116 MACSTR, MAC2STR(mgmt->sa));
4117 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
4118 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
4119 pos[1] <= qlen - 2 && pos[1] >= 16)
4120 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
4121 return;
4122 }
4123#endif /* CONFIG_INTERWORKING */
4124
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004125 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004126 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
4127 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004128 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004129 payload + 1,
4130 plen - 1);
4131 return;
4132 }
4133
4134 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004135 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
4136 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
4137 return;
4138 }
4139
4140 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
4141 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
4142 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
4143 payload + 1, plen - 1,
4144 rssi);
4145 return;
4146 }
4147
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004148#ifdef CONFIG_FST
4149 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
4150 fst_rx_action(wpa_s->fst, mgmt, len);
4151 return;
4152 }
4153#endif /* CONFIG_FST */
4154
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004155#ifdef CONFIG_DPP
4156 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
4157 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
4158 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
4159 payload[4] == DPP_OUI_TYPE) {
4160 payload++;
4161 plen--;
4162 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
4163 return;
4164 }
4165#endif /* CONFIG_DPP */
4166
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004167 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
4168 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004169 if (wpa_s->ifmsh)
4170 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004171}
4172
4173
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004174static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
4175 union wpa_event_data *event)
4176{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004177 struct wpa_freq_range_list *list;
4178 char *str = NULL;
4179
4180 list = &event->freq_range;
4181
4182 if (list->num)
4183 str = freq_range_list_str(list);
4184 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
4185 str ? str : "");
4186
4187#ifdef CONFIG_P2P
4188 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
4189 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
4190 __func__);
4191 } else {
4192 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004193
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004194 /*
4195 * The update channel flow will also take care of moving a GO
4196 * from the unsafe frequency if needed.
4197 */
4198 wpas_p2p_update_channel_list(wpa_s,
4199 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004200 }
4201#endif /* CONFIG_P2P */
4202
4203 os_free(str);
4204}
4205
4206
Roshan Pius3a1667e2018-07-03 15:17:14 -07004207static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004208{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004209 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4210 wpa_supplicant_cancel_auth_timeout(wpa_s);
4211 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
Hai Shalome21d4e82020-04-29 16:34:06 -07004212 eapol_sm_notify_portValid(wpa_s->eapol, true);
4213 eapol_sm_notify_eap_success(wpa_s->eapol, true);
Hai Shalomc3565922019-10-28 11:58:20 -07004214 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004215 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004216}
4217
4218
4219static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4220 int freq)
4221{
4222 size_t i;
4223 int j;
4224
4225 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4226 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4227
4228 for (j = 0; j < mode->num_channels; j++) {
4229 const struct hostapd_channel_data *chan;
4230
4231 chan = &mode->channels[j];
4232 if (chan->freq == freq)
4233 return chan->dfs_cac_ms;
4234 }
4235 }
4236
4237 return 0;
4238}
4239
4240
4241static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4242 struct dfs_event *radar)
4243{
4244#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004245 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004246 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4247 } else
4248#endif /* NEED_AP_MLME && CONFIG_AP */
4249 {
4250 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4251
4252 cac_time /= 1000; /* convert from ms to sec */
4253 if (!cac_time)
4254 cac_time = 10 * 60; /* max timeout: 10 minutes */
4255
4256 /* Restart auth timeout: CAC time added to initial timeout */
4257 wpas_auth_timeout_restart(wpa_s, cac_time);
4258 }
4259}
4260
4261
4262static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4263 struct dfs_event *radar)
4264{
4265#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004266 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004267 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4268 } else
4269#endif /* NEED_AP_MLME && CONFIG_AP */
4270 {
4271 /* Restart auth timeout with original value after CAC is
4272 * finished */
4273 wpas_auth_timeout_restart(wpa_s, 0);
4274 }
4275}
4276
4277
4278static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4279 struct dfs_event *radar)
4280{
4281#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004282 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004283 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4284 } else
4285#endif /* NEED_AP_MLME && CONFIG_AP */
4286 {
4287 /* Restart auth timeout with original value after CAC is
4288 * aborted */
4289 wpas_auth_timeout_restart(wpa_s, 0);
4290 }
4291}
4292
4293
4294static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4295 union wpa_event_data *data)
4296{
4297 wpa_dbg(wpa_s, MSG_DEBUG,
4298 "Connection authorized by device, previous state %d",
4299 wpa_s->wpa_state);
4300
4301 wpa_supplicant_event_port_authorized(wpa_s);
4302
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004303 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4304 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004305 data->assoc_info.ptk_kck_len,
4306 data->assoc_info.ptk_kek,
4307 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004308#ifdef CONFIG_FILS
4309 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4310 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4311 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4312
4313 /* Update ERP next sequence number */
4314 eapol_sm_update_erp_next_seq_num(
4315 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4316
4317 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4318 /* Add the new PMK and PMKID to the PMKSA cache */
4319 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4320 data->assoc_info.fils_pmk,
4321 data->assoc_info.fils_pmk_len,
4322 data->assoc_info.fils_pmkid,
4323 wpa_s->bssid, fils_cache_id);
4324 } else if (data->assoc_info.fils_pmkid) {
4325 /* Update the current PMKSA used for this connection */
4326 pmksa_cache_set_current(wpa_s->wpa,
4327 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004328 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004329 }
4330 }
4331#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004332}
4333
4334
Roshan Pius3a1667e2018-07-03 15:17:14 -07004335static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4336 union wpa_event_data *data)
4337{
4338 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004339#ifdef CONFIG_MBO
4340 struct wpa_bss *reject_bss;
4341#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004342
4343 if (!bssid || is_zero_ether_addr(bssid))
4344 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004345#ifdef CONFIG_MBO
4346 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4347 reject_bss = wpa_s->current_bss;
4348 else
4349 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4350#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004351
4352 if (data->assoc_reject.bssid)
4353 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4354 "bssid=" MACSTR " status_code=%u%s%s%s",
4355 MAC2STR(data->assoc_reject.bssid),
4356 data->assoc_reject.status_code,
4357 data->assoc_reject.timed_out ? " timeout" : "",
4358 data->assoc_reject.timeout_reason ? "=" : "",
4359 data->assoc_reject.timeout_reason ?
4360 data->assoc_reject.timeout_reason : "");
4361 else
4362 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4363 "status_code=%u%s%s%s",
4364 data->assoc_reject.status_code,
4365 data->assoc_reject.timed_out ? " timeout" : "",
4366 data->assoc_reject.timeout_reason ? "=" : "",
4367 data->assoc_reject.timeout_reason ?
4368 data->assoc_reject.timeout_reason : "");
4369 wpa_s->assoc_status_code = data->assoc_reject.status_code;
4370 wpa_s->assoc_timed_out = data->assoc_reject.timed_out;
4371 wpas_notify_assoc_status_code(wpa_s);
4372
4373#ifdef CONFIG_OWE
4374 if (data->assoc_reject.status_code ==
4375 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4376 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4377 wpa_s->current_ssid &&
4378 wpa_s->current_ssid->owe_group == 0 &&
4379 wpa_s->last_owe_group != 21) {
4380 struct wpa_ssid *ssid = wpa_s->current_ssid;
4381 struct wpa_bss *bss = wpa_s->current_bss;
4382
4383 if (!bss) {
4384 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4385 if (!bss) {
4386 wpas_connection_failed(wpa_s, bssid);
4387 wpa_supplicant_mark_disassoc(wpa_s);
4388 return;
4389 }
4390 }
4391 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4392 wpas_connect_work_done(wpa_s);
4393 wpa_supplicant_mark_disassoc(wpa_s);
4394 wpa_supplicant_connect(wpa_s, bss, ssid);
4395 return;
4396 }
4397#endif /* CONFIG_OWE */
4398
Hai Shalomfdcde762020-04-02 11:19:20 -07004399#ifdef CONFIG_DPP2
4400 /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
4401 * the status code defined in the DPP R2 tech spec.
4402 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
4403 * interoperability workaround with older hostapd implementation. */
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004404 if (DPP_VERSION > 1 && wpa_s->current_ssid &&
Hai Shalomfdcde762020-04-02 11:19:20 -07004405 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4406 wpa_s->current_ssid->dpp_pfs == 0 &&
4407 (data->assoc_reject.status_code ==
4408 WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
4409 data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
4410 struct wpa_ssid *ssid = wpa_s->current_ssid;
4411 struct wpa_bss *bss = wpa_s->current_bss;
4412
4413 wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
4414 if (!bss)
4415 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4416 if (!bss || wpa_s->dpp_pfs_fallback) {
4417 wpa_printf(MSG_DEBUG,
4418 "DPP: Updated PFS policy for next try");
4419 wpas_connection_failed(wpa_s, bssid);
4420 wpa_supplicant_mark_disassoc(wpa_s);
4421 return;
4422 }
4423 wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
4424 wpa_s->dpp_pfs_fallback = 1;
4425 wpas_connect_work_done(wpa_s);
4426 wpa_supplicant_mark_disassoc(wpa_s);
4427 wpa_supplicant_connect(wpa_s, bss, ssid);
4428 return;
4429 }
4430#endif /* CONFIG_DPP2 */
4431
Hai Shalom74f70d42019-02-11 14:42:39 -08004432#ifdef CONFIG_MBO
4433 if (data->assoc_reject.status_code ==
4434 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004435 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004436 const u8 *rssi_rej;
4437
4438 rssi_rej = mbo_get_attr_from_ies(
4439 data->assoc_reject.resp_ies,
4440 data->assoc_reject.resp_ies_len,
4441 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4442 if (rssi_rej && rssi_rej[1] == 2) {
4443 wpa_printf(MSG_DEBUG,
4444 "OCE: RSSI-based association rejection from "
4445 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004446 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004447 rssi_rej[2], rssi_rej[3]);
4448 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004449 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004450 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004451 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004452 }
4453 }
4454#endif /* CONFIG_MBO */
4455
Roshan Pius3a1667e2018-07-03 15:17:14 -07004456 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4457 sme_event_assoc_reject(wpa_s, data);
4458 return;
4459 }
4460
4461 /* Driver-based SME cases */
4462
4463#ifdef CONFIG_SAE
4464 if (wpa_s->current_ssid &&
4465 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4466 !data->assoc_reject.timed_out) {
4467 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4468 wpa_sm_aborted_cached(wpa_s->wpa);
4469 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4470 }
4471#endif /* CONFIG_SAE */
4472
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004473#ifdef CONFIG_DPP
4474 if (wpa_s->current_ssid &&
4475 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4476 !data->assoc_reject.timed_out) {
4477 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4478 wpa_sm_aborted_cached(wpa_s->wpa);
4479 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4480 }
4481#endif /* CONFIG_DPP */
4482
Roshan Pius3a1667e2018-07-03 15:17:14 -07004483#ifdef CONFIG_FILS
4484 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004485 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004486 eapol_sm_update_erp_next_seq_num(
4487 wpa_s->eapol,
4488 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004489 fils_connection_failure(wpa_s);
4490 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004491#endif /* CONFIG_FILS */
4492
4493 wpas_connection_failed(wpa_s, bssid);
4494 wpa_supplicant_mark_disassoc(wpa_s);
4495}
4496
4497
Hai Shalomfdcde762020-04-02 11:19:20 -07004498static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
4499 struct unprot_beacon *data)
4500{
4501 struct wpabuf *buf;
4502 int res;
4503
4504 if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
4505 os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0)
4506 return;
4507 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
4508 MAC2STR(data->sa));
4509
4510 buf = wpabuf_alloc(4);
4511 if (!buf)
4512 return;
4513
4514 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
4515 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
4516 wpabuf_put_u8(buf, 1); /* Dialog Token */
4517 wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
4518
4519 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
4520 wpa_s->own_addr, wpa_s->bssid,
4521 wpabuf_head(buf), wpabuf_len(buf), 0);
4522 if (res < 0)
4523 wpa_printf(MSG_DEBUG,
4524 "Failed to send WNM-Notification Request frame");
4525
4526 wpabuf_free(buf);
4527}
4528
4529
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004530void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4531 union wpa_event_data *data)
4532{
4533 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004534 int resched;
Hai Shalomfdcde762020-04-02 11:19:20 -07004535 struct os_reltime age, clear_at;
Hai Shalom74f70d42019-02-11 14:42:39 -08004536#ifndef CONFIG_NO_STDOUT_DEBUG
4537 int level = MSG_DEBUG;
4538#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004539
4540 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4541 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004542 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004543 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004544 event != EVENT_SCHED_SCAN_STOPPED) {
4545 wpa_dbg(wpa_s, MSG_DEBUG,
4546 "Ignore event %s (%d) while interface is disabled",
4547 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004548 return;
4549 }
4550
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004551#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07004552 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004553 const struct ieee80211_hdr *hdr;
4554 u16 fc;
4555 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4556 fc = le_to_host16(hdr->frame_control);
4557 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4558 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4559 level = MSG_EXCESSIVE;
4560 }
4561
4562 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4563 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004564#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004565
4566 switch (event) {
4567 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004568#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004569 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4570 data->auth.ies_len))
4571 wpa_printf(MSG_DEBUG,
4572 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004573#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004574 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004575 wpa_s->auth_status_code = data->auth.status_code;
4576 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004577 break;
4578 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004579#ifdef CONFIG_TESTING_OPTIONS
4580 if (wpa_s->ignore_auth_resp) {
4581 wpa_printf(MSG_INFO,
4582 "EVENT_ASSOC - ignore_auth_resp active!");
4583 break;
4584 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004585 if (wpa_s->testing_resend_assoc) {
4586 wpa_printf(MSG_INFO,
4587 "EVENT_DEAUTH - testing_resend_assoc");
4588 break;
4589 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004590#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004591 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004592 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004593 if (data &&
4594 (data->assoc_info.authorized ||
4595 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4596 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004597 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004598 if (data) {
4599 wpa_msg(wpa_s, MSG_INFO,
4600 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4601 data->assoc_info.subnet_status);
4602 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004603 break;
4604 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004605 wpas_event_disassoc(wpa_s,
4606 data ? &data->disassoc_info : NULL);
4607 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004608 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004609#ifdef CONFIG_TESTING_OPTIONS
4610 if (wpa_s->ignore_auth_resp) {
4611 wpa_printf(MSG_INFO,
4612 "EVENT_DEAUTH - ignore_auth_resp active!");
4613 break;
4614 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004615 if (wpa_s->testing_resend_assoc) {
4616 wpa_printf(MSG_INFO,
4617 "EVENT_DEAUTH - testing_resend_assoc");
4618 break;
4619 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004620#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004621 wpas_event_deauth(wpa_s,
4622 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004623 break;
4624 case EVENT_MICHAEL_MIC_FAILURE:
4625 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4626 break;
4627#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004628 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004629 if (wpa_s->own_scan_requested ||
4630 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004631 struct os_reltime diff;
4632
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004633 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004634 os_reltime_sub(&wpa_s->scan_start_time,
4635 &wpa_s->scan_trigger_time, &diff);
4636 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4637 diff.sec, diff.usec);
4638 wpa_s->own_scan_requested = 0;
4639 wpa_s->own_scan_running = 1;
4640 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4641 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004642 wpa_msg_ctrl(wpa_s, MSG_INFO,
4643 WPA_EVENT_SCAN_STARTED "id=%u",
4644 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004645 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004646 wpa_msg_ctrl(wpa_s, MSG_INFO,
4647 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004648 }
4649 } else {
4650 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004651 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004652 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004653 }
4654 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004655 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004656 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4657 wpa_s->scan_res_handler = NULL;
4658 wpa_s->own_scan_running = 0;
4659 wpa_s->radio->external_scan_running = 0;
4660 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4661 break;
4662 }
4663
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004664 if (!(data && data->scan_info.external_scan) &&
4665 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004666 struct os_reltime now, diff;
4667 os_get_reltime(&now);
4668 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4669 wpa_s->scan_start_time.sec = 0;
4670 wpa_s->scan_start_time.usec = 0;
4671 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4672 diff.sec, diff.usec);
4673 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004674 if (wpa_supplicant_event_scan_results(wpa_s, data))
4675 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004676 if (!(data && data->scan_info.external_scan))
4677 wpa_s->own_scan_running = 0;
4678 if (data && data->scan_info.nl_scan_event)
4679 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004680 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004681 break;
4682#endif /* CONFIG_NO_SCAN_PROCESSING */
4683 case EVENT_ASSOCINFO:
4684 wpa_supplicant_event_associnfo(wpa_s, data);
4685 break;
4686 case EVENT_INTERFACE_STATUS:
4687 wpa_supplicant_event_interface_status(wpa_s, data);
4688 break;
4689 case EVENT_PMKID_CANDIDATE:
4690 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4691 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004692#ifdef CONFIG_TDLS
4693 case EVENT_TDLS:
4694 wpa_supplicant_event_tdls(wpa_s, data);
4695 break;
4696#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004697#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004698 case EVENT_WNM:
4699 wpa_supplicant_event_wnm(wpa_s, data);
4700 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004701#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004702#ifdef CONFIG_IEEE80211R
4703 case EVENT_FT_RESPONSE:
4704 wpa_supplicant_event_ft_response(wpa_s, data);
4705 break;
4706#endif /* CONFIG_IEEE80211R */
4707#ifdef CONFIG_IBSS_RSN
4708 case EVENT_IBSS_RSN_START:
4709 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4710 break;
4711#endif /* CONFIG_IBSS_RSN */
4712 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004713 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004714 break;
4715 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004716 /* It is possible to get this event from earlier connection */
4717 if (wpa_s->current_ssid &&
4718 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4719 wpa_dbg(wpa_s, MSG_DEBUG,
4720 "Ignore AUTH_TIMED_OUT in mesh configuration");
4721 break;
4722 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004723 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4724 sme_event_auth_timed_out(wpa_s, data);
4725 break;
4726 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004727 /* It is possible to get this event from earlier connection */
4728 if (wpa_s->current_ssid &&
4729 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4730 wpa_dbg(wpa_s, MSG_DEBUG,
4731 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4732 break;
4733 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004734 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4735 sme_event_assoc_timed_out(wpa_s, data);
4736 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004737 case EVENT_TX_STATUS:
4738 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4739 " type=%d stype=%d",
4740 MAC2STR(data->tx_status.dst),
4741 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004742#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004743 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004744#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004745 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4746 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004747 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004748 wpa_s, data->tx_status.dst,
4749 data->tx_status.data,
4750 data->tx_status.data_len,
4751 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004752 OFFCHANNEL_SEND_ACTION_SUCCESS :
4753 OFFCHANNEL_SEND_ACTION_NO_ACK);
4754#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004755 break;
4756 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004757#endif /* CONFIG_AP */
4758#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004759 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004760 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004761 /*
4762 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004763 * interface in GO mode, or via standalone AP interface.
4764 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4765 * except when the primary interface is used as a GO interface
4766 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004767 */
4768 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4769 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004770 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004771 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004772 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004773 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004774 data->tx_status.data,
4775 data->tx_status.data_len,
4776 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004777 OFFCHANNEL_SEND_ACTION_SUCCESS :
4778 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004779 break;
4780 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004781#endif /* CONFIG_OFFCHANNEL */
4782#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004783 switch (data->tx_status.type) {
4784 case WLAN_FC_TYPE_MGMT:
4785 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4786 data->tx_status.data_len,
4787 data->tx_status.stype,
4788 data->tx_status.ack);
4789 break;
4790 case WLAN_FC_TYPE_DATA:
4791 ap_tx_status(wpa_s, data->tx_status.dst,
4792 data->tx_status.data,
4793 data->tx_status.data_len,
4794 data->tx_status.ack);
4795 break;
4796 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004797#endif /* CONFIG_AP */
4798 break;
4799#ifdef CONFIG_AP
4800 case EVENT_EAPOL_TX_STATUS:
4801 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4802 data->eapol_tx_status.data,
4803 data->eapol_tx_status.data_len,
4804 data->eapol_tx_status.ack);
4805 break;
4806 case EVENT_DRIVER_CLIENT_POLL_OK:
4807 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004808 break;
4809 case EVENT_RX_FROM_UNKNOWN:
4810 if (wpa_s->ap_iface == NULL)
4811 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004812 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4813 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004814 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004815#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07004816
4817 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07004818 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004819 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004820 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004821
Hai Shalom81f62d82019-07-22 12:10:00 -07004822 wpa_msg(wpa_s, MSG_INFO,
4823 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4824 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
4825 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004826 data->ch_switch.freq,
4827 data->ch_switch.ht_enabled,
4828 data->ch_switch.ch_offset,
4829 channel_width_to_string(data->ch_switch.ch_width),
4830 data->ch_switch.cf1,
4831 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07004832 if (event == EVENT_CH_SWITCH_STARTED)
4833 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004834
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004835 wpa_s->assoc_freq = data->ch_switch.freq;
4836 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4837
Hai Shalomfdcde762020-04-02 11:19:20 -07004838#ifdef CONFIG_SME
4839 switch (data->ch_switch.ch_offset) {
4840 case 1:
4841 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
4842 break;
4843 case -1:
4844 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
4845 break;
4846 default:
4847 wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
4848 break;
4849 }
4850#endif /* CONFIG_SME */
4851
Roshan Pius3a1667e2018-07-03 15:17:14 -07004852#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004853 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4854 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08004855 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004856 wpa_s->current_ssid->mode ==
4857 WPAS_MODE_P2P_GROUP_FORMATION) {
4858 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4859 data->ch_switch.ht_enabled,
4860 data->ch_switch.ch_offset,
4861 data->ch_switch.ch_width,
4862 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07004863 data->ch_switch.cf2,
4864 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004865 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004866#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004867
Hai Shalom74f70d42019-02-11 14:42:39 -08004868 sme_event_ch_switch(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004869 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004870 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004871 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004872#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004873#ifdef NEED_AP_MLME
4874 case EVENT_DFS_RADAR_DETECTED:
4875 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004876 wpas_ap_event_dfs_radar_detected(wpa_s,
4877 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004878 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004879 case EVENT_DFS_NOP_FINISHED:
4880 if (data)
4881 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
4882 &data->dfs_event);
4883 break;
4884#endif /* NEED_AP_MLME */
4885#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004886 case EVENT_DFS_CAC_STARTED:
4887 if (data)
4888 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
4889 break;
4890 case EVENT_DFS_CAC_FINISHED:
4891 if (data)
4892 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
4893 break;
4894 case EVENT_DFS_CAC_ABORTED:
4895 if (data)
4896 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
4897 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004898 case EVENT_RX_MGMT: {
4899 u16 fc, stype;
4900 const struct ieee80211_mgmt *mgmt;
4901
Dmitry Shmidt818ea482014-03-10 13:15:21 -07004902#ifdef CONFIG_TESTING_OPTIONS
4903 if (wpa_s->ext_mgmt_frame_handling) {
4904 struct rx_mgmt *rx = &data->rx_mgmt;
4905 size_t hex_len = 2 * rx->frame_len + 1;
4906 char *hex = os_malloc(hex_len);
4907 if (hex) {
4908 wpa_snprintf_hex(hex, hex_len,
4909 rx->frame, rx->frame_len);
4910 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4911 rx->freq, rx->datarate, rx->ssi_signal,
4912 hex);
4913 os_free(hex);
4914 }
4915 break;
4916 }
4917#endif /* CONFIG_TESTING_OPTIONS */
4918
Dmitry Shmidt04949592012-07-19 12:16:46 -07004919 mgmt = (const struct ieee80211_mgmt *)
4920 data->rx_mgmt.frame;
4921 fc = le_to_host16(mgmt->frame_control);
4922 stype = WLAN_FC_GET_STYPE(fc);
4923
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004924#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004925 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004926#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004927#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004928 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004929 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004930 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07004931 const u8 *ie;
4932 size_t ie_len;
4933
4934 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4935 ie_len = data->rx_mgmt.frame_len -
4936 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004937 wpas_p2p_probe_req_rx(
4938 wpa_s, src, mgmt->da,
4939 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004940 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004941 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004942 break;
4943 }
4944#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004945#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004946 if (wpa_s->current_ssid &&
4947 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4948 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004949 data->rx_mgmt.frame_len >= 30) {
4950 wpa_supplicant_event_ibss_auth(wpa_s, data);
4951 break;
4952 }
4953#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004954
4955 if (stype == WLAN_FC_STYPE_ACTION) {
4956 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004957 wpa_s, data->rx_mgmt.frame,
4958 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004959 data->rx_mgmt.freq,
4960 data->rx_mgmt.ssi_signal);
4961 break;
4962 }
4963
4964 if (wpa_s->ifmsh) {
4965 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004966 break;
4967 }
4968
Roshan Pius3a1667e2018-07-03 15:17:14 -07004969#ifdef CONFIG_SAE
4970 if (stype == WLAN_FC_STYPE_AUTH &&
4971 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4972 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4973 sme_external_auth_mgmt_rx(
4974 wpa_s, data->rx_mgmt.frame,
4975 data->rx_mgmt.frame_len);
4976 break;
4977 }
4978#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004979 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
4980 "management frame in non-AP mode");
4981 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004982#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004983 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004984
4985 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004986 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4987 const u8 *ie;
4988 size_t ie_len;
4989
4990 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4991 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004992
4993 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
4994 mgmt->bssid, ie, ie_len,
4995 data->rx_mgmt.ssi_signal);
4996 }
4997
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004998 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004999#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005000 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005001 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005002 case EVENT_RX_PROBE_REQ:
5003 if (data->rx_probe_req.sa == NULL ||
5004 data->rx_probe_req.ie == NULL)
5005 break;
5006#ifdef CONFIG_AP
5007 if (wpa_s->ap_iface) {
5008 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
5009 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005010 data->rx_probe_req.da,
5011 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005012 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005013 data->rx_probe_req.ie_len,
5014 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005015 break;
5016 }
5017#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005018 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005019 data->rx_probe_req.da,
5020 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005021 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005022 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005023 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005024 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005025 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005026 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005027#ifdef CONFIG_OFFCHANNEL
5028 offchannel_remain_on_channel_cb(
5029 wpa_s, data->remain_on_channel.freq,
5030 data->remain_on_channel.duration);
5031#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005032 wpas_p2p_remain_on_channel_cb(
5033 wpa_s, data->remain_on_channel.freq,
5034 data->remain_on_channel.duration);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07005035#ifdef CONFIG_DPP
5036 wpas_dpp_remain_on_channel_cb(
5037 wpa_s, data->remain_on_channel.freq,
5038 data->remain_on_channel.duration);
5039#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005040 break;
5041 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005042#ifdef CONFIG_OFFCHANNEL
5043 offchannel_cancel_remain_on_channel_cb(
5044 wpa_s, data->remain_on_channel.freq);
5045#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005046 wpas_p2p_cancel_remain_on_channel_cb(
5047 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005048#ifdef CONFIG_DPP
5049 wpas_dpp_cancel_remain_on_channel_cb(
5050 wpa_s, data->remain_on_channel.freq);
5051#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005052 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005053 case EVENT_EAPOL_RX:
5054 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
5055 data->eapol_rx.data,
5056 data->eapol_rx.data_len);
5057 break;
5058 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005059 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
5060 "above=%d signal=%d noise=%d txrate=%d",
5061 data->signal_change.above_threshold,
5062 data->signal_change.current_signal,
5063 data->signal_change.current_noise,
5064 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005065 wpa_bss_update_level(wpa_s->current_bss,
5066 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005067 bgscan_notify_signal_change(
5068 wpa_s, data->signal_change.above_threshold,
5069 data->signal_change.current_signal,
5070 data->signal_change.current_noise,
5071 data->signal_change.current_txrate);
5072 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005073 case EVENT_INTERFACE_MAC_CHANGED:
5074 wpa_supplicant_update_mac_addr(wpa_s);
5075 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005076 case EVENT_INTERFACE_ENABLED:
5077 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
5078 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Hai Shalomfdcde762020-04-02 11:19:20 -07005079 eloop_cancel_timeout(wpas_clear_disabled_interface,
5080 wpa_s, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005081 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07005082 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005083 if (wpa_s->p2p_mgmt) {
5084 wpa_supplicant_set_state(wpa_s,
5085 WPA_DISCONNECTED);
5086 break;
5087 }
5088
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005089#ifdef CONFIG_AP
5090 if (!wpa_s->ap_iface) {
5091 wpa_supplicant_set_state(wpa_s,
5092 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005093 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005094 wpa_supplicant_req_scan(wpa_s, 0, 0);
5095 } else
5096 wpa_supplicant_set_state(wpa_s,
5097 WPA_COMPLETED);
5098#else /* CONFIG_AP */
5099 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5100 wpa_supplicant_req_scan(wpa_s, 0, 0);
5101#endif /* CONFIG_AP */
5102 }
5103 break;
5104 case EVENT_INTERFACE_DISABLED:
5105 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005106#ifdef CONFIG_P2P
5107 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
5108 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
5109 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
5110 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005111 * Mark interface disabled if this happens to end up not
5112 * being removed as a separate P2P group interface.
5113 */
5114 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5115 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005116 * The interface was externally disabled. Remove
5117 * it assuming an external entity will start a
5118 * new session if needed.
5119 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08005120 if (wpa_s->current_ssid &&
5121 wpa_s->current_ssid->p2p_group)
5122 wpas_p2p_interface_unavailable(wpa_s);
5123 else
5124 wpas_p2p_disconnect(wpa_s);
5125 /*
5126 * wpa_s instance may have been freed, so must not use
5127 * it here anymore.
5128 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005129 break;
5130 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005131 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
5132 p2p_in_progress(wpa_s->global->p2p) > 1) {
5133 /* This radio work will be cancelled, so clear P2P
5134 * state as well.
5135 */
5136 p2p_stop_find(wpa_s->global->p2p);
5137 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005138#endif /* CONFIG_P2P */
5139
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005140 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5141 /*
5142 * Indicate disconnection to keep ctrl_iface events
5143 * consistent.
5144 */
5145 wpa_supplicant_event_disassoc(
5146 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
5147 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005148 wpa_supplicant_mark_disassoc(wpa_s);
Hai Shalomfdcde762020-04-02 11:19:20 -07005149 os_reltime_age(&wpa_s->last_scan, &age);
5150 if (age.sec >= SCAN_RES_VALID_FOR_CONNECT) {
5151 clear_at.sec = SCAN_RES_VALID_FOR_CONNECT;
5152 clear_at.usec = 0;
5153 } else {
5154 struct os_reltime tmp;
5155
5156 tmp.sec = SCAN_RES_VALID_FOR_CONNECT;
5157 tmp.usec = 0;
5158 os_reltime_sub(&tmp, &age, &clear_at);
5159 }
5160 eloop_register_timeout(clear_at.sec, clear_at.usec,
5161 wpas_clear_disabled_interface,
5162 wpa_s, NULL);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005163 radio_remove_works(wpa_s, NULL, 0);
5164
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005165 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
5166 break;
5167 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07005168 wpa_supplicant_update_channel_list(
5169 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005170 break;
5171 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005172 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005173 break;
5174 case EVENT_BEST_CHANNEL:
5175 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
5176 "(%d %d %d)",
5177 data->best_chan.freq_24, data->best_chan.freq_5,
5178 data->best_chan.freq_overall);
5179 wpa_s->best_24_freq = data->best_chan.freq_24;
5180 wpa_s->best_5_freq = data->best_chan.freq_5;
5181 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005182 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
5183 data->best_chan.freq_5,
5184 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005185 break;
5186 case EVENT_UNPROT_DEAUTH:
5187 wpa_supplicant_event_unprot_deauth(wpa_s,
5188 &data->unprot_deauth);
5189 break;
5190 case EVENT_UNPROT_DISASSOC:
5191 wpa_supplicant_event_unprot_disassoc(wpa_s,
5192 &data->unprot_disassoc);
5193 break;
5194 case EVENT_STATION_LOW_ACK:
5195#ifdef CONFIG_AP
5196 if (wpa_s->ap_iface && data)
5197 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
5198 data->low_ack.addr);
5199#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005200#ifdef CONFIG_TDLS
5201 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005202 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
5203 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005204#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005205 break;
5206 case EVENT_IBSS_PEER_LOST:
5207#ifdef CONFIG_IBSS_RSN
5208 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
5209#endif /* CONFIG_IBSS_RSN */
5210 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005211 case EVENT_DRIVER_GTK_REKEY:
5212 if (os_memcmp(data->driver_gtk_rekey.bssid,
5213 wpa_s->bssid, ETH_ALEN))
5214 break;
5215 if (!wpa_s->wpa)
5216 break;
5217 wpa_sm_update_replay_ctr(wpa_s->wpa,
5218 data->driver_gtk_rekey.replay_ctr);
5219 break;
5220 case EVENT_SCHED_SCAN_STOPPED:
5221 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005222 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005223 wpa_supplicant_notify_scanning(wpa_s, 0);
5224
5225 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5226 break;
5227
5228 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005229 * If the driver stopped scanning without being requested to,
5230 * request a new scan to continue scanning for networks.
5231 */
5232 if (!wpa_s->sched_scan_stop_req &&
5233 wpa_s->wpa_state == WPA_SCANNING) {
5234 wpa_dbg(wpa_s, MSG_DEBUG,
5235 "Restart scanning after unexpected sched_scan stop event");
5236 wpa_supplicant_req_scan(wpa_s, 1, 0);
5237 break;
5238 }
5239
5240 wpa_s->sched_scan_stop_req = 0;
5241
5242 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08005243 * Start a new sched scan to continue searching for more SSIDs
5244 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005245 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07005246 if (wpa_s->sched_scan_timed_out) {
5247 wpa_supplicant_req_sched_scan(wpa_s);
5248 } else if (wpa_s->pno_sched_pending) {
5249 wpa_s->pno_sched_pending = 0;
5250 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07005251 } else if (resched) {
5252 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08005253 }
5254
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005255 break;
5256 case EVENT_WPS_BUTTON_PUSHED:
5257#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07005258 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005259#endif /* CONFIG_WPS */
5260 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08005261 case EVENT_AVOID_FREQUENCIES:
5262 wpa_supplicant_notify_avoid_freq(wpa_s, data);
5263 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005264 case EVENT_CONNECT_FAILED_REASON:
5265#ifdef CONFIG_AP
5266 if (!wpa_s->ap_iface || !data)
5267 break;
5268 hostapd_event_connect_failed_reason(
5269 wpa_s->ap_iface->bss[0],
5270 data->connect_failed_reason.addr,
5271 data->connect_failed_reason.code);
5272#endif /* CONFIG_AP */
5273 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005274 case EVENT_NEW_PEER_CANDIDATE:
5275#ifdef CONFIG_MESH
5276 if (!wpa_s->ifmsh || !data)
5277 break;
5278 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
5279 data->mesh_peer.ies,
5280 data->mesh_peer.ie_len);
5281#endif /* CONFIG_MESH */
5282 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005283 case EVENT_SURVEY:
5284#ifdef CONFIG_AP
5285 if (!wpa_s->ap_iface)
5286 break;
5287 hostapd_event_get_survey(wpa_s->ap_iface,
5288 &data->survey_results);
5289#endif /* CONFIG_AP */
5290 break;
5291 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08005292#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005293#ifdef CONFIG_ACS
5294 if (!wpa_s->ap_iface)
5295 break;
5296 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
5297 &data->acs_selected_channels);
5298#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08005299#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08005300 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07005301 case EVENT_P2P_LO_STOP:
5302#ifdef CONFIG_P2P
5303 wpa_s->p2p_lo_started = 0;
5304 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5305 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5306 data->p2p_lo_stop.reason_code);
5307#endif /* CONFIG_P2P */
5308 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005309 case EVENT_BEACON_LOSS:
5310 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5311 break;
5312 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5313 bgscan_notify_beacon_loss(wpa_s);
5314 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005315 case EVENT_EXTERNAL_AUTH:
5316#ifdef CONFIG_SAE
5317 if (!wpa_s->current_ssid) {
5318 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5319 break;
5320 }
5321 sme_external_auth_trigger(wpa_s, data);
5322#endif /* CONFIG_SAE */
5323 break;
5324 case EVENT_PORT_AUTHORIZED:
5325 wpa_supplicant_event_port_authorized(wpa_s);
5326 break;
5327 case EVENT_STATION_OPMODE_CHANGED:
5328#ifdef CONFIG_AP
5329 if (!wpa_s->ap_iface || !data)
5330 break;
5331
5332 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5333 data->sta_opmode.addr,
5334 data->sta_opmode.smps_mode,
5335 data->sta_opmode.chan_width,
5336 data->sta_opmode.rx_nss);
5337#endif /* CONFIG_AP */
5338 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07005339 case EVENT_UNPROT_BEACON:
5340 wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
5341 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005342 default:
5343 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5344 break;
5345 }
5346}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005347
5348
5349void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5350 union wpa_event_data *data)
5351{
5352 struct wpa_supplicant *wpa_s;
5353
5354 if (event != EVENT_INTERFACE_STATUS)
5355 return;
5356
5357 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5358 if (wpa_s && wpa_s->driver->get_ifindex) {
5359 unsigned int ifindex;
5360
5361 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5362 if (ifindex != data->interface_status.ifindex) {
5363 wpa_dbg(wpa_s, MSG_DEBUG,
5364 "interface status ifindex %d mismatch (%d)",
5365 ifindex, data->interface_status.ifindex);
5366 return;
5367 }
5368 }
5369#ifdef CONFIG_MATCH_IFACE
5370 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5371 struct wpa_interface *wpa_i;
5372
5373 wpa_i = wpa_supplicant_match_iface(
5374 ctx, data->interface_status.ifname);
5375 if (!wpa_i)
5376 return;
5377 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5378 os_free(wpa_i);
5379 if (wpa_s)
5380 wpa_s->matched = 1;
5381 }
5382#endif /* CONFIG_MATCH_IFACE */
5383
5384 if (wpa_s)
5385 wpa_supplicant_event(wpa_s, event, data);
5386}