blob: 139402e77e855c2b9fe38e57bc6b9654dd57129c [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
191 wpa_msg(wpa_s, MSG_DEBUG,
192 "Driver-initiated BSS selection changed the SSID to %s",
193 wpa_ssid_txt(drv_ssid, drv_ssid_len));
194 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700195 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700196
197 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
198 "information");
199 ssid = wpa_supplicant_get_ssid(wpa_s);
200 if (ssid == NULL) {
201 wpa_msg(wpa_s, MSG_INFO,
202 "No network configuration found for the current AP");
203 return -1;
204 }
205
Dmitry Shmidt04949592012-07-19 12:16:46 -0700206 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700207 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
208 return -1;
209 }
210
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800211 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
212 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
213 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
214 return -1;
215 }
216
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700217 res = wpas_temp_disabled(wpa_s, ssid);
218 if (res > 0) {
219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
220 "disabled for %d second(s)", res);
221 return -1;
222 }
223
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
225 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800226 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227 u8 wpa_ie[80];
228 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800229 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
230 wpa_ie, &wpa_ie_len) < 0)
231 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700232 } else {
233 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
234 }
235
236 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
237 eapol_sm_invalidate_cached_session(wpa_s->eapol);
238 old_ssid = wpa_s->current_ssid;
239 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800240
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700241 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800242
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
244 wpa_supplicant_initiate_eapol(wpa_s);
245 if (old_ssid != wpa_s->current_ssid)
246 wpas_notify_network_changed(wpa_s);
247
248 return 0;
249}
250
251
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800252void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253{
254 struct wpa_supplicant *wpa_s = eloop_ctx;
255
256 if (wpa_s->countermeasures) {
257 wpa_s->countermeasures = 0;
258 wpa_drv_set_countermeasures(wpa_s, 0);
259 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800260
261 /*
262 * It is possible that the device is sched scanning, which means
263 * that a connection attempt will be done only when we receive
264 * scan results. However, in this case, it would be preferable
265 * to scan and connect immediately, so cancel the sched_scan and
266 * issue a regular scan flow.
267 */
268 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269 wpa_supplicant_req_scan(wpa_s, 0, 0);
270 }
271}
272
273
274void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
275{
276 int bssid_changed;
277
Dmitry Shmidt04949592012-07-19 12:16:46 -0700278 wnm_bss_keep_alive_deinit(wpa_s);
279
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280#ifdef CONFIG_IBSS_RSN
281 ibss_rsn_deinit(wpa_s->ibss_rsn);
282 wpa_s->ibss_rsn = NULL;
283#endif /* CONFIG_IBSS_RSN */
284
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700285#ifdef CONFIG_AP
286 wpa_supplicant_ap_deinit(wpa_s);
287#endif /* CONFIG_AP */
288
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700289#ifdef CONFIG_HS20
290 /* Clear possibly configured frame filters */
291 wpa_drv_configure_frame_filters(wpa_s, 0);
292#endif /* CONFIG_HS20 */
293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
295 return;
296
Hai Shalom74f70d42019-02-11 14:42:39 -0800297 if (os_reltime_initialized(&wpa_s->session_start)) {
298 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
299 wpa_s->session_start.sec = 0;
300 wpa_s->session_start.usec = 0;
301 wpas_notify_session_length(wpa_s);
302 }
303
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
305 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
306 os_memset(wpa_s->bssid, 0, ETH_ALEN);
307 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800308 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700309 wpa_s->current_bss = NULL;
310 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700311
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312 if (bssid_changed)
313 wpas_notify_bssid_changed(wpa_s);
314
315 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
316 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700317 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
318 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
Hai Shalomc3565922019-10-28 11:58:20 -0700319 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
Hai Shalomc3565922019-10-28 11:58:20 -0700321 wpa_s->drv_authorized_port = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700322 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700323 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700324 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700325 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800326
327 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800328 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800329 wnm_clear_coloc_intf_reporting(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -0700330 wpa_s->disable_mbo_oce = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700331
332#ifdef CONFIG_TESTING_OPTIONS
333 wpa_s->last_tk_alg = WPA_ALG_NONE;
334 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
335#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700336 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800337
338 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
339 wpa_s->enabled_4addr_mode = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340}
341
342
343static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
344{
345 struct wpa_ie_data ie;
346 int pmksa_set = -1;
347 size_t i;
348
349 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
350 ie.pmkid == NULL)
351 return;
352
353 for (i = 0; i < ie.num_pmkid; i++) {
354 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
355 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700356 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800358 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359 break;
360 }
361 }
362
363 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
364 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
365}
366
367
368static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
369 union wpa_event_data *data)
370{
371 if (data == NULL) {
372 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
373 "event");
374 return;
375 }
376 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
377 " index=%d preauth=%d",
378 MAC2STR(data->pmkid_candidate.bssid),
379 data->pmkid_candidate.index,
380 data->pmkid_candidate.preauth);
381
382 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
383 data->pmkid_candidate.index,
384 data->pmkid_candidate.preauth);
385}
386
387
388static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
389{
390 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
391 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
392 return 0;
393
394#ifdef IEEE8021X_EAPOL
395 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
396 wpa_s->current_ssid &&
397 !(wpa_s->current_ssid->eapol_flags &
398 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
399 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
400 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
401 * plaintext or static WEP keys). */
402 return 0;
403 }
404#endif /* IEEE8021X_EAPOL */
405
406 return 1;
407}
408
409
410/**
411 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
412 * @wpa_s: pointer to wpa_supplicant data
413 * @ssid: Configuration data for the network
414 * Returns: 0 on success, -1 on failure
415 *
416 * This function is called when starting authentication with a network that is
417 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
418 */
419int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
420 struct wpa_ssid *ssid)
421{
422#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800423#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700424 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700426 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
427 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700428 return 0;
429
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700430 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 sim = 1;
432 aka = 1;
433 } else {
434 struct eap_method_type *eap = ssid->eap.eap_methods;
435 while (eap->vendor != EAP_VENDOR_IETF ||
436 eap->method != EAP_TYPE_NONE) {
437 if (eap->vendor == EAP_VENDOR_IETF) {
438 if (eap->method == EAP_TYPE_SIM)
439 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700440 else if (eap->method == EAP_TYPE_AKA ||
441 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700442 aka = 1;
443 }
444 eap++;
445 }
446 }
447
448 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
449 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700450 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
451 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
452 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453 aka = 0;
454
455 if (!sim && !aka) {
456 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
457 "use SIM, but neither EAP-SIM nor EAP-AKA are "
458 "enabled");
459 return 0;
460 }
461
462 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
463 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700464
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700465 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 if (wpa_s->scard == NULL) {
467 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
468 "(pcsc-lite)");
469 return -1;
470 }
471 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
472 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800473#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474#endif /* IEEE8021X_EAPOL */
475
476 return 0;
477}
478
479
480#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700481
482static int has_wep_key(struct wpa_ssid *ssid)
483{
484 int i;
485
486 for (i = 0; i < NUM_WEP_KEYS; i++) {
487 if (ssid->wep_key_len[i])
488 return 1;
489 }
490
491 return 0;
492}
493
494
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700495static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700496 struct wpa_ssid *ssid)
497{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700498 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700499
500 if (ssid->mixed_cell)
501 return 1;
502
503#ifdef CONFIG_WPS
504 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
505 return 1;
506#endif /* CONFIG_WPS */
507
Roshan Pius3a1667e2018-07-03 15:17:14 -0700508#ifdef CONFIG_OWE
509 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
510 return 1;
511#endif /* CONFIG_OWE */
512
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700513 if (has_wep_key(ssid))
514 privacy = 1;
515
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516#ifdef IEEE8021X_EAPOL
517 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
518 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
519 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
520 privacy = 1;
521#endif /* IEEE8021X_EAPOL */
522
Jouni Malinen75ecf522011-06-27 15:19:46 -0700523 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
524 privacy = 1;
525
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800526 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
527 privacy = 1;
528
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 if (bss->caps & IEEE80211_CAP_PRIVACY)
530 return privacy;
531 return !privacy;
532}
533
534
535static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
536 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800537 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538{
539 struct wpa_ie_data ie;
540 int proto_match = 0;
541 const u8 *rsn_ie, *wpa_ie;
542 int ret;
543 int wep_ok;
544
545 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
546 if (ret >= 0)
547 return ret;
548
549 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
550 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
551 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
552 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
553 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
554
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700555 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700556 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700557 proto_match++;
558
559 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800560 if (debug_print)
561 wpa_dbg(wpa_s, MSG_DEBUG,
562 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563 break;
564 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700565 if (!ie.has_pairwise)
566 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
567 if (!ie.has_group)
568 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700569
570 if (wep_ok &&
571 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
572 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800573 if (debug_print)
574 wpa_dbg(wpa_s, MSG_DEBUG,
575 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576 return 1;
577 }
578
Roshan Pius3a1667e2018-07-03 15:17:14 -0700579 if (!(ie.proto & ssid->proto) &&
580 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800581 if (debug_print)
582 wpa_dbg(wpa_s, MSG_DEBUG,
583 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 break;
585 }
586
587 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800588 if (debug_print)
589 wpa_dbg(wpa_s, MSG_DEBUG,
590 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591 break;
592 }
593
594 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800595 if (debug_print)
596 wpa_dbg(wpa_s, MSG_DEBUG,
597 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598 break;
599 }
600
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700601 if (ssid->group_mgmt_cipher &&
602 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
603 if (debug_print)
604 wpa_dbg(wpa_s, MSG_DEBUG,
605 " skip RSN IE - group mgmt cipher mismatch");
606 break;
607 }
608
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800610 if (debug_print)
611 wpa_dbg(wpa_s, MSG_DEBUG,
612 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700613 break;
614 }
615
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800617 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800618 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800619 if (debug_print)
620 wpa_dbg(wpa_s, MSG_DEBUG,
621 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700622 break;
623 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800624 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
625 wpas_get_ssid_pmf(wpa_s, ssid) ==
626 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800627 if (debug_print)
628 wpa_dbg(wpa_s, MSG_DEBUG,
629 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800630 break;
631 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700632
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800633 if (debug_print)
634 wpa_dbg(wpa_s, MSG_DEBUG,
635 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636 return 1;
637 }
638
Roshan Pius3a1667e2018-07-03 15:17:14 -0700639 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
640 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800641 if (debug_print)
642 wpa_dbg(wpa_s, MSG_DEBUG,
643 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700644 return 0;
645 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700646
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700647 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700648 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
649 proto_match++;
650
651 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800652 if (debug_print)
653 wpa_dbg(wpa_s, MSG_DEBUG,
654 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700655 break;
656 }
657
658 if (wep_ok &&
659 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
660 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800661 if (debug_print)
662 wpa_dbg(wpa_s, MSG_DEBUG,
663 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664 return 1;
665 }
666
667 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800668 if (debug_print)
669 wpa_dbg(wpa_s, MSG_DEBUG,
670 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671 break;
672 }
673
674 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800675 if (debug_print)
676 wpa_dbg(wpa_s, MSG_DEBUG,
677 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678 break;
679 }
680
681 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800682 if (debug_print)
683 wpa_dbg(wpa_s, MSG_DEBUG,
684 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700685 break;
686 }
687
688 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800689 if (debug_print)
690 wpa_dbg(wpa_s, MSG_DEBUG,
691 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700692 break;
693 }
694
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800695 if (debug_print)
696 wpa_dbg(wpa_s, MSG_DEBUG,
697 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698 return 1;
699 }
700
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700701 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
702 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800703 if (debug_print)
704 wpa_dbg(wpa_s, MSG_DEBUG,
705 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700706 return 1;
707 }
708
Roshan Pius3a1667e2018-07-03 15:17:14 -0700709#ifdef CONFIG_OWE
710 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
711 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800712 if (wpa_s->owe_transition_select &&
713 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
714 ssid->owe_transition_bss_select_count + 1 <=
715 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
716 ssid->owe_transition_bss_select_count++;
717 if (debug_print)
718 wpa_dbg(wpa_s, MSG_DEBUG,
719 " skip OWE transition BSS (selection count %d does not exceed %d)",
720 ssid->owe_transition_bss_select_count,
721 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
722 wpa_s->owe_transition_search = 1;
723 return 0;
724 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700725 if (debug_print)
726 wpa_dbg(wpa_s, MSG_DEBUG,
727 " allow in OWE transition mode");
728 return 1;
729 }
730#endif /* CONFIG_OWE */
731
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700732 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
733 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800734 if (debug_print)
735 wpa_dbg(wpa_s, MSG_DEBUG,
736 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737 return 0;
738 }
739
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800740 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
741 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800742 if (debug_print)
743 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800744 return 1;
745 }
746
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800748 if (debug_print)
749 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700750 return 1;
751 }
752
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800753 if (debug_print)
754 wpa_dbg(wpa_s, MSG_DEBUG,
755 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700756
757 return 0;
758}
759
760
761static int freq_allowed(int *freqs, int freq)
762{
763 int i;
764
765 if (freqs == NULL)
766 return 1;
767
768 for (i = 0; freqs[i]; i++)
769 if (freqs[i] == freq)
770 return 1;
771 return 0;
772}
773
774
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800775static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
776 int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800777{
778 const struct hostapd_hw_modes *mode = NULL, *modes;
779 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
780 const u8 *rate_ie;
781 int i, j, k;
782
783 if (bss->freq == 0)
784 return 1; /* Cannot do matching without knowing band */
785
786 modes = wpa_s->hw.modes;
787 if (modes == NULL) {
788 /*
789 * The driver does not provide any additional information
790 * about the utilized hardware, so allow the connection attempt
791 * to continue.
792 */
793 return 1;
794 }
795
796 for (i = 0; i < wpa_s->hw.num_modes; i++) {
797 for (j = 0; j < modes[i].num_channels; j++) {
798 int freq = modes[i].channels[j].freq;
799 if (freq == bss->freq) {
800 if (mode &&
801 mode->mode == HOSTAPD_MODE_IEEE80211G)
802 break; /* do not allow 802.11b replace
803 * 802.11g */
804 mode = &modes[i];
805 break;
806 }
807 }
808 }
809
810 if (mode == NULL)
811 return 0;
812
813 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700814 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800815 if (rate_ie == NULL)
816 continue;
817
818 for (j = 2; j < rate_ie[1] + 2; j++) {
819 int flagged = !!(rate_ie[j] & 0x80);
820 int r = (rate_ie[j] & 0x7f) * 5;
821
822 /*
823 * IEEE Std 802.11n-2009 7.3.2.2:
824 * The new BSS Membership selector value is encoded
825 * like a legacy basic rate, but it is not a rate and
826 * only indicates if the BSS members are required to
827 * support the mandatory features of Clause 20 [HT PHY]
828 * in order to join the BSS.
829 */
830 if (flagged && ((rate_ie[j] & 0x7f) ==
831 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
832 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800833 if (debug_print)
834 wpa_dbg(wpa_s, MSG_DEBUG,
835 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800836 return 0;
837 }
838 continue;
839 }
840
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700841 /* There's also a VHT selector for 802.11ac */
842 if (flagged && ((rate_ie[j] & 0x7f) ==
843 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
844 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800845 if (debug_print)
846 wpa_dbg(wpa_s, MSG_DEBUG,
847 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700848 return 0;
849 }
850 continue;
851 }
852
Hai Shalomc3565922019-10-28 11:58:20 -0700853#ifdef CONFIG_SAE
854 if (flagged && ((rate_ie[j] & 0x7f) ==
855 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
856 if (wpa_s->conf->sae_pwe == 0) {
857 if (debug_print)
858 wpa_dbg(wpa_s, MSG_DEBUG,
859 " SAE H2E disabled");
860 return 0;
861 }
862 continue;
863 }
864#endif /* CONFIG_SAE */
865
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800866 if (!flagged)
867 continue;
868
869 /* check for legacy basic rates */
870 for (k = 0; k < mode->num_rates; k++) {
871 if (mode->rates[k] == r)
872 break;
873 }
874 if (k == mode->num_rates) {
875 /*
876 * IEEE Std 802.11-2007 7.3.2.2 demands that in
877 * order to join a BSS all required rates
878 * have to be supported by the hardware.
879 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800880 if (debug_print)
881 wpa_dbg(wpa_s, MSG_DEBUG,
882 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
883 r / 10, r % 10,
884 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800885 return 0;
886 }
887 }
888 }
889
890 return 1;
891}
892
893
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800894/*
895 * Test whether BSS is in an ESS.
896 * This is done differently in DMG (60 GHz) and non-DMG bands
897 */
898static int bss_is_ess(struct wpa_bss *bss)
899{
900 if (bss_is_dmg(bss)) {
901 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
902 IEEE80211_CAP_DMG_AP;
903 }
904
905 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
906 IEEE80211_CAP_ESS);
907}
908
909
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800910static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
911{
912 size_t i;
913
914 for (i = 0; i < ETH_ALEN; i++) {
915 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
916 return 0;
917 }
918 return 1;
919}
920
921
922static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
923{
924 size_t i;
925
926 for (i = 0; i < num; i++) {
927 const u8 *a = list + i * ETH_ALEN * 2;
928 const u8 *m = a + ETH_ALEN;
929
930 if (match_mac_mask(a, addr, m))
931 return 1;
932 }
933 return 0;
934}
935
936
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700937static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
938 const u8 **ret_ssid, size_t *ret_ssid_len)
939{
940#ifdef CONFIG_OWE
941 const u8 *owe, *pos, *end, *bssid;
942 u8 ssid_len;
943 struct wpa_bss *open_bss;
944
945 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
946 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
947 return;
948
949 pos = owe + 6;
950 end = owe + 2 + owe[1];
951
952 if (end - pos < ETH_ALEN + 1)
953 return;
954 bssid = pos;
955 pos += ETH_ALEN;
956 ssid_len = *pos++;
957 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
958 return;
959
960 /* Match the profile SSID against the OWE transition mode SSID on the
961 * open network. */
962 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
963 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
964 *ret_ssid = pos;
965 *ret_ssid_len = ssid_len;
966
967 if (bss->ssid_len > 0)
968 return;
969
970 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
971 if (!open_bss)
972 return;
973 if (ssid_len != open_bss->ssid_len ||
974 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
975 wpa_dbg(wpa_s, MSG_DEBUG,
976 "OWE: transition mode SSID mismatch: %s",
977 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
978 return;
979 }
980
981 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
982 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
983 wpa_dbg(wpa_s, MSG_DEBUG,
984 "OWE: transition mode open BSS unexpected info");
985 return;
986 }
987
988 pos = owe + 6;
989 end = owe + 2 + owe[1];
990
991 if (end - pos < ETH_ALEN + 1)
992 return;
993 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
994 wpa_dbg(wpa_s, MSG_DEBUG,
995 "OWE: transition mode BSSID mismatch: " MACSTR,
996 MAC2STR(pos));
997 return;
998 }
999 pos += ETH_ALEN;
1000 ssid_len = *pos++;
1001 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1002 return;
1003 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1004 wpa_ssid_txt(pos, ssid_len));
1005 os_memcpy(bss->ssid, pos, ssid_len);
1006 bss->ssid_len = ssid_len;
1007#endif /* CONFIG_OWE */
1008}
1009
1010
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001011struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1012 int i, struct wpa_bss *bss,
1013 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001014 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001015{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001016 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001017 int wpa;
1018 struct wpa_blacklist *e;
1019 const u8 *ie;
1020 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001021 int osen, rsn_osen = 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001022#ifdef CONFIG_MBO
1023 const u8 *assoc_disallow;
1024#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001025 const u8 *match_ssid;
1026 size_t match_ssid_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001027 struct wpa_ie_data data;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001028
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001029 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 wpa_ie_len = ie ? ie[1] : 0;
1031
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001032 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033 rsn_ie_len = ie ? ie[1] : 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001034 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1035 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1036 rsn_osen = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001038 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1039 osen = ie != NULL;
1040
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001041 if (debug_print) {
1042 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1043 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1044 i, MAC2STR(bss->bssid),
1045 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1046 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1047 bss->freq,
1048 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1049 " wps" : "",
1050 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1051 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1052 ? " p2p" : "",
1053 osen ? " osen=1" : "");
1054 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055
1056 e = wpa_blacklist_get(wpa_s, bss->bssid);
1057 if (e) {
1058 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001059 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001060 /*
1061 * When only a single network is enabled, we can
1062 * trigger blacklisting on the first failure. This
1063 * should not be done with multiple enabled networks to
1064 * avoid getting forced to move into a worse ESS on
1065 * single error if there are no other BSSes of the
1066 * current ESS.
1067 */
1068 limit = 0;
1069 }
1070 if (e->count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001071 if (debug_print) {
1072 wpa_dbg(wpa_s, MSG_DEBUG,
1073 " skip - blacklisted (count=%d limit=%d)",
1074 e->count, limit);
1075 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 return NULL;
1077 }
1078 }
1079
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001080 match_ssid = bss->ssid;
1081 match_ssid_len = bss->ssid_len;
1082 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1083
1084 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001085 if (debug_print)
1086 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 return NULL;
1088 }
1089
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001090 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001091 if (debug_print)
1092 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001093 return NULL;
1094 }
1095
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001096 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001097 if (debug_print)
1098 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001099 return NULL;
1100 }
1101
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
1103
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001104 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001106 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001107
Dmitry Shmidt04949592012-07-19 12:16:46 -07001108 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001109 if (debug_print)
1110 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111 continue;
1112 }
1113
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001114 res = wpas_temp_disabled(wpa_s, ssid);
1115 if (res > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001116 if (debug_print)
1117 wpa_dbg(wpa_s, MSG_DEBUG,
1118 " skip - disabled temporarily for %d second(s)",
1119 res);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001120 continue;
1121 }
1122
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123#ifdef CONFIG_WPS
1124 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001125 if (debug_print)
1126 wpa_dbg(wpa_s, MSG_DEBUG,
1127 " skip - blacklisted (WPS)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001128 continue;
1129 }
1130
1131 if (wpa && ssid->ssid_len == 0 &&
1132 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1133 check_ssid = 0;
1134
1135 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1136 /* Only allow wildcard SSID match if an AP
1137 * advertises active WPS operation that matches
1138 * with our mode. */
1139 check_ssid = 1;
1140 if (ssid->ssid_len == 0 &&
1141 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1142 check_ssid = 0;
1143 }
1144#endif /* CONFIG_WPS */
1145
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001146 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1147 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1148 check_ssid = 0;
1149
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150 if (check_ssid &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001151 (match_ssid_len != ssid->ssid_len ||
1152 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001153 if (debug_print)
1154 wpa_dbg(wpa_s, MSG_DEBUG,
1155 " skip - SSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156 continue;
1157 }
1158
1159 if (ssid->bssid_set &&
1160 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001161 if (debug_print)
1162 wpa_dbg(wpa_s, MSG_DEBUG,
1163 " skip - BSSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164 continue;
1165 }
1166
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001167 /* check blacklist */
1168 if (ssid->num_bssid_blacklist &&
1169 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1170 ssid->num_bssid_blacklist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001171 if (debug_print)
1172 wpa_dbg(wpa_s, MSG_DEBUG,
1173 " skip - BSSID blacklisted");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001174 continue;
1175 }
1176
1177 /* if there is a whitelist, only accept those APs */
1178 if (ssid->num_bssid_whitelist &&
1179 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1180 ssid->num_bssid_whitelist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001181 if (debug_print)
1182 wpa_dbg(wpa_s, MSG_DEBUG,
1183 " skip - BSSID not in whitelist");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001184 continue;
1185 }
1186
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001187 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss,
1188 debug_print))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189 continue;
1190
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001191 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1193 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001194 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001195 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001196 if (debug_print)
1197 wpa_dbg(wpa_s, MSG_DEBUG,
1198 " skip - non-WPA network not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 continue;
1200 }
1201
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001202 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1203 has_wep_key(ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001204 if (debug_print)
1205 wpa_dbg(wpa_s, MSG_DEBUG,
1206 " skip - ignore WPA/WPA2 AP for WEP network block");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001207 continue;
1208 }
1209
Roshan Pius3a1667e2018-07-03 15:17:14 -07001210 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen &&
1211 !rsn_osen) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001212 if (debug_print)
1213 wpa_dbg(wpa_s, MSG_DEBUG,
1214 " skip - non-OSEN network not allowed");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001215 continue;
1216 }
1217
Jouni Malinen75ecf522011-06-27 15:19:46 -07001218 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001219 if (debug_print)
1220 wpa_dbg(wpa_s, MSG_DEBUG,
1221 " skip - privacy mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 continue;
1223 }
1224
Hai Shalom81f62d82019-07-22 12:10:00 -07001225 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001226 !bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001227 if (debug_print)
1228 wpa_dbg(wpa_s, MSG_DEBUG,
1229 " skip - not ESS, PBSS, or MBSS");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001230 continue;
1231 }
1232
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001233 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001234 if (debug_print)
1235 wpa_dbg(wpa_s, MSG_DEBUG,
1236 " skip - PBSS mismatch (ssid %d bss %d)",
1237 ssid->pbss, bss_is_pbss(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238 continue;
1239 }
1240
1241 if (!freq_allowed(ssid->freq_list, bss->freq)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001242 if (debug_print)
1243 wpa_dbg(wpa_s, MSG_DEBUG,
1244 " skip - frequency not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 continue;
1246 }
1247
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001248#ifdef CONFIG_MESH
Hai Shalom81f62d82019-07-22 12:10:00 -07001249 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001250 ssid->frequency != bss->freq) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001251 if (debug_print)
1252 wpa_dbg(wpa_s, MSG_DEBUG,
1253 " skip - frequency not allowed (mesh)");
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001254 continue;
1255 }
1256#endif /* CONFIG_MESH */
1257
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001258 if (!rate_match(wpa_s, bss, debug_print)) {
1259 if (debug_print)
1260 wpa_dbg(wpa_s, MSG_DEBUG,
1261 " skip - rate sets do not match");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001262 continue;
1263 }
1264
Hai Shalomc3565922019-10-28 11:58:20 -07001265#ifdef CONFIG_SAE
1266 if (wpa_s->conf->sae_pwe == 1 &&
1267 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1268 (!(ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX)) ||
1269 ie[1] < 1 ||
1270 !(ie[2] & BIT(WLAN_RSNX_CAPAB_SAE_H2E)))) {
1271 if (debug_print)
1272 wpa_dbg(wpa_s, MSG_DEBUG,
1273 " skip - SAE H2E required, but not supported by the AP");
1274 continue;
1275 }
1276#endif /* CONFIG_SAE */
1277
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001278#ifndef CONFIG_IBSS_RSN
1279 if (ssid->mode == WPAS_MODE_IBSS &&
1280 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1281 WPA_KEY_MGMT_WPA_NONE))) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001282 if (debug_print)
1283 wpa_dbg(wpa_s, MSG_DEBUG,
1284 " skip - IBSS RSN not supported in the build");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001285 continue;
1286 }
1287#endif /* !CONFIG_IBSS_RSN */
1288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001290 if (ssid->p2p_group &&
1291 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1292 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001293 if (debug_print)
1294 wpa_dbg(wpa_s, MSG_DEBUG,
1295 " skip - no P2P IE seen");
Dmitry Shmidt96571392013-10-14 12:54:46 -07001296 continue;
1297 }
1298
Dmitry Shmidt54605472013-11-08 11:10:19 -08001299 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1300 struct wpabuf *p2p_ie;
1301 u8 dev_addr[ETH_ALEN];
1302
1303 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1304 if (ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001305 if (debug_print)
1306 wpa_dbg(wpa_s, MSG_DEBUG,
1307 " skip - no P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001308 continue;
1309 }
1310 p2p_ie = wpa_bss_get_vendor_ie_multi(
1311 bss, P2P_IE_VENDOR_TYPE);
1312 if (p2p_ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001313 if (debug_print)
1314 wpa_dbg(wpa_s, MSG_DEBUG,
1315 " skip - could not fetch P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001316 continue;
1317 }
1318
1319 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1320 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1321 ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001322 if (debug_print)
1323 wpa_dbg(wpa_s, MSG_DEBUG,
1324 " skip - no matching GO P2P Device Address in P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001325 wpabuf_free(p2p_ie);
1326 continue;
1327 }
1328 wpabuf_free(p2p_ie);
1329 }
1330
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001331 /*
1332 * TODO: skip the AP if its P2P IE has Group Formation
1333 * bit set in the P2P Group Capability Bitmap and we
1334 * are not in Group Formation with that device.
1335 */
1336#endif /* CONFIG_P2P */
1337
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001338 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1339 {
1340 struct os_reltime diff;
1341
1342 os_reltime_sub(&wpa_s->scan_min_time,
1343 &bss->last_update, &diff);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001344 if (debug_print)
1345 wpa_dbg(wpa_s, MSG_DEBUG,
1346 " skip - scan result not recent enough (%u.%06u seconds too old)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001347 (unsigned int) diff.sec,
1348 (unsigned int) diff.usec);
1349 continue;
1350 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001351#ifdef CONFIG_MBO
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001352#ifdef CONFIG_TESTING_OPTIONS
1353 if (wpa_s->ignore_assoc_disallow)
1354 goto skip_assoc_disallow;
1355#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001356 assoc_disallow = wpas_mbo_get_bss_attr(
1357 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1358 if (assoc_disallow && assoc_disallow[1] >= 1) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001359 if (debug_print)
1360 wpa_dbg(wpa_s, MSG_DEBUG,
1361 " skip - MBO association disallowed (reason %u)",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001362 assoc_disallow[2]);
1363 continue;
1364 }
1365
Hai Shalom74f70d42019-02-11 14:42:39 -08001366 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001367 if (debug_print)
1368 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom74f70d42019-02-11 14:42:39 -08001369 " skip - AP temporarily disallowed");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001370 continue;
1371 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001372#ifdef CONFIG_TESTING_OPTIONS
1373 skip_assoc_disallow:
1374#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001375#endif /* CONFIG_MBO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001376
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001377#ifdef CONFIG_DPP
1378 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1379 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1380 (!ssid->dpp_connector ||
1381 !ssid->dpp_netaccesskey ||
1382 !ssid->dpp_csign)) {
1383 if (debug_print)
1384 wpa_dbg(wpa_s, MSG_DEBUG,
1385 " skip - no PMKSA entry for DPP");
1386 continue;
1387 }
1388#endif /* CONFIG_DPP */
1389
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001390 /* Matching configuration found */
1391 return ssid;
1392 }
1393
1394 /* No matching configuration found */
1395 return NULL;
1396}
1397
1398
1399static struct wpa_bss *
1400wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001401 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001402 struct wpa_ssid **selected_ssid,
1403 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001404{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001405 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001406
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001407 if (wpa_s->current_ssid) {
1408 struct wpa_ssid *ssid;
1409
1410 wpa_dbg(wpa_s, MSG_DEBUG,
1411 "Scan results matching the currently selected network");
1412 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1413 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1414
1415 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1416 only_first_ssid, 0);
1417 if (ssid != wpa_s->current_ssid)
1418 continue;
1419 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1420 " freq=%d level=%d snr=%d est_throughput=%u",
1421 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1422 bss->snr, bss->est_throughput);
1423 }
1424 }
1425
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001426 if (only_first_ssid)
1427 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1428 group->id);
1429 else
1430 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1431 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001432
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001433 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1434 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001435
1436 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001437 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001438 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001439 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001440 if (!*selected_ssid)
1441 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001442 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1443 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001444 MAC2STR(bss->bssid),
1445 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1446 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001447 }
1448
1449 return NULL;
1450}
1451
1452
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001453struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1454 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001455{
1456 struct wpa_bss *selected = NULL;
1457 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001458 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001459 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001460
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001461 if (wpa_s->last_scan_res == NULL ||
1462 wpa_s->last_scan_res_used == 0)
1463 return NULL; /* no scan results from last update */
1464
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001465 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001466 /* check that next_ssid is still valid */
1467 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1468 if (ssid == wpa_s->next_ssid)
1469 break;
1470 }
1471 next_ssid = ssid;
1472 wpa_s->next_ssid = NULL;
1473 }
1474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001475 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001476 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1477 if (next_ssid && next_ssid->priority ==
1478 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001479 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001480 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001481 if (selected)
1482 break;
1483 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001484 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001485 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001486 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001487 if (selected)
1488 break;
1489 }
1490
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001491 if (selected == NULL && wpa_s->blacklist &&
1492 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001493 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1494 "blacklist and try again");
1495 wpa_blacklist_clear(wpa_s);
1496 wpa_s->blacklist_cleared++;
1497 } else if (selected == NULL)
1498 break;
1499 }
1500
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001501 ssid = *selected_ssid;
1502 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1503 !ssid->passphrase && !ssid->ext_psk) {
1504 const char *field_name, *txt = NULL;
1505
1506 wpa_dbg(wpa_s, MSG_DEBUG,
1507 "PSK/passphrase not yet available for the selected network");
1508
1509 wpas_notify_network_request(wpa_s, ssid,
1510 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1511
1512 field_name = wpa_supplicant_ctrl_req_to_string(
1513 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1514 if (field_name == NULL)
1515 return NULL;
1516
1517 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1518
1519 selected = NULL;
1520 }
1521
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001522 return selected;
1523}
1524
1525
1526static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1527 int timeout_sec, int timeout_usec)
1528{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001529 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001530 /*
1531 * No networks are enabled; short-circuit request so
1532 * we don't wait timeout seconds before transitioning
1533 * to INACTIVE state.
1534 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001535 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1536 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1538 return;
1539 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001540
1541 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001542 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1543}
1544
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001545
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001546int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001547 struct wpa_bss *selected,
1548 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001549{
1550 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1551 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1552 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001553 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001554#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001555 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1556 wpa_s->p2p_in_provisioning) {
1557 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1558 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001559 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001560 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001561#endif /* CONFIG_P2P */
1562
1563#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001564 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565 wpas_wps_cancel(wpa_s);
1566#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001567 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001568 }
1569
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001570 wpa_msg(wpa_s, MSG_DEBUG,
1571 "Considering connect request: reassociate: %d selected: "
1572 MACSTR " bssid: " MACSTR " pending: " MACSTR
1573 " wpa_state: %s ssid=%p current_ssid=%p",
1574 wpa_s->reassociate, MAC2STR(selected->bssid),
1575 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1576 wpa_supplicant_state_txt(wpa_s->wpa_state),
1577 ssid, wpa_s->current_ssid);
1578
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001579 /*
1580 * Do not trigger new association unless the BSSID has changed or if
1581 * reassociation is requested. If we are in process of associating with
1582 * the selected BSSID, do not trigger new attempt.
1583 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001584 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001585 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1586 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1587 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001588 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1589 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1590 0) ||
1591 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1592 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001593 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1594 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001595 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001596 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001597 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1598 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001599 wpa_supplicant_associate(wpa_s, selected, ssid);
1600 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001601 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1602 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001603 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001604
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001605 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001606}
1607
1608
1609static struct wpa_ssid *
1610wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1611{
1612 int prio;
1613 struct wpa_ssid *ssid;
1614
1615 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1616 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1617 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001618 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001619 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001620#ifndef CONFIG_IBSS_RSN
1621 if (ssid->mode == WPAS_MODE_IBSS &&
1622 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1623 WPA_KEY_MGMT_WPA_NONE))) {
1624 wpa_msg(wpa_s, MSG_INFO,
1625 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1626 wpa_ssid_txt(ssid->ssid,
1627 ssid->ssid_len));
1628 continue;
1629 }
1630#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001631 if (ssid->mode == WPAS_MODE_IBSS ||
1632 ssid->mode == WPAS_MODE_AP ||
1633 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001634 return ssid;
1635 }
1636 }
1637 return NULL;
1638}
1639
1640
1641/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1642 * on BSS added and BSS changed events */
1643static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001644 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001645{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001646 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647
1648 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1649 return;
1650
Jouni Malinen87fd2792011-05-16 18:35:42 +03001651 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001652 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001653
Jouni Malinen87fd2792011-05-16 18:35:42 +03001654 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655 if (ssid == NULL)
1656 continue;
1657
Jouni Malinen87fd2792011-05-16 18:35:42 +03001658 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001659 if (rsn == NULL)
1660 continue;
1661
Jouni Malinen87fd2792011-05-16 18:35:42 +03001662 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001663 }
1664
1665}
1666
1667
1668static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1669 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001670 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001671{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001672 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001673#ifndef CONFIG_NO_ROAMING
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001674 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001675 int to_5ghz;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001676 int cur_est, sel_est;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001677#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001678
1679 if (wpa_s->reassociate)
1680 return 1; /* explicit request to reassociate */
1681 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1682 return 1; /* we are not associated; continue */
1683 if (wpa_s->current_ssid == NULL)
1684 return 1; /* unknown current SSID */
1685 if (wpa_s->current_ssid != ssid)
1686 return 1; /* different network block */
1687
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001688 if (wpas_driver_bss_selection(wpa_s))
1689 return 0; /* Driver-based roaming */
1690
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001691 if (wpa_s->current_ssid->ssid)
1692 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1693 wpa_s->current_ssid->ssid,
1694 wpa_s->current_ssid->ssid_len);
1695 if (!current_bss)
1696 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697
1698 if (!current_bss)
1699 return 1; /* current BSS not seen in scan results */
1700
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001701 if (current_bss == selected)
1702 return 0;
1703
1704 if (selected->last_update_idx > current_bss->last_update_idx)
1705 return 1; /* current BSS not seen in the last scan */
1706
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001707#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001708 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001709 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001710 " freq=%d level=%d snr=%d est_throughput=%u",
1711 MAC2STR(current_bss->bssid),
1712 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001713 current_bss->snr, current_bss->est_throughput);
1714 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001715 " freq=%d level=%d snr=%d est_throughput=%u",
1716 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001717 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001718
1719 if (wpa_s->current_ssid->bssid_set &&
1720 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1721 0) {
1722 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1723 "has preferred BSSID");
1724 return 1;
1725 }
1726
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001727 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1728 wpa_dbg(wpa_s, MSG_DEBUG,
1729 "Allow reassociation - selected BSS has better estimated throughput");
1730 return 1;
1731 }
1732
Dmitry Shmidte4663042016-04-04 10:07:49 -07001733 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1734
1735 if (current_bss->level < 0 &&
1736 current_bss->level > selected->level + to_5ghz * 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001737 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1738 "signal level");
1739 return 0;
1740 }
1741
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001742 if (current_bss->est_throughput > selected->est_throughput + 5000) {
1743 wpa_dbg(wpa_s, MSG_DEBUG,
1744 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001745 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001746 }
1747
1748 cur_est = current_bss->est_throughput;
1749 sel_est = selected->est_throughput;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001750 min_diff = 2;
1751 if (current_bss->level < 0) {
1752 if (current_bss->level < -85)
1753 min_diff = 1;
1754 else if (current_bss->level < -80)
1755 min_diff = 2;
1756 else if (current_bss->level < -75)
1757 min_diff = 3;
1758 else if (current_bss->level < -70)
1759 min_diff = 4;
1760 else
1761 min_diff = 5;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001762 if (cur_est > sel_est * 1.5)
1763 min_diff += 10;
1764 else if (cur_est > sel_est * 1.2)
1765 min_diff += 5;
1766 else if (cur_est > sel_est * 1.1)
1767 min_diff += 2;
1768 else if (cur_est > sel_est)
1769 min_diff++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001770 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001771 if (to_5ghz) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001772 int reduce = 2;
1773
Dmitry Shmidte4663042016-04-04 10:07:49 -07001774 /* Make it easier to move to 5 GHz band */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001775 if (sel_est > cur_est * 1.5)
1776 reduce = 5;
1777 else if (sel_est > cur_est * 1.2)
1778 reduce = 4;
1779 else if (sel_est > cur_est * 1.1)
1780 reduce = 3;
1781
1782 if (min_diff > reduce)
1783 min_diff -= reduce;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001784 else
1785 min_diff = 0;
1786 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001787 diff = abs(current_bss->level - selected->level);
1788 if (diff < min_diff) {
1789 wpa_dbg(wpa_s, MSG_DEBUG,
1790 "Skip roam - too small difference in signal level (%d < %d)",
1791 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001792 return 0;
1793 }
1794
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001795 wpa_dbg(wpa_s, MSG_DEBUG,
1796 "Allow reassociation due to difference in signal level (%d >= %d)",
1797 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001798 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001799#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001800 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001801#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001802}
1803
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001804
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001805/*
1806 * Return a negative value if no scan results could be fetched or if scan
1807 * results should not be shared with other virtual interfaces.
1808 * Return 0 if scan results were fetched and may be shared with other
1809 * interfaces.
1810 * Return 1 if scan results may be shared with other virtual interfaces but may
1811 * not trigger any operations.
1812 * Return 2 if the interface was removed and cannot be used.
1813 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001814static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001815 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001816 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001818 struct wpa_scan_results *scan_res = NULL;
1819 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001821#ifndef CONFIG_NO_RANDOM_POOL
1822 size_t i, num;
1823#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824
1825#ifdef CONFIG_AP
1826 if (wpa_s->ap_iface)
1827 ap = 1;
1828#endif /* CONFIG_AP */
1829
1830 wpa_supplicant_notify_scanning(wpa_s, 0);
1831
1832 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1833 data ? &data->scan_info :
1834 NULL, 1);
1835 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001836 if (wpa_s->conf->ap_scan == 2 || ap ||
1837 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001839 if (!own_request)
1840 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001841 if (data && data->scan_info.external_scan)
1842 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001843 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1844 "scanning again");
1845 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001846 ret = -1;
1847 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001848 }
1849
1850#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001851 num = scan_res->num;
1852 if (num > 10)
1853 num = 10;
1854 for (i = 0; i < num; i++) {
1855 u8 buf[5];
1856 struct wpa_scan_res *res = scan_res->res[i];
1857 buf[0] = res->bssid[5];
1858 buf[1] = res->qual & 0xff;
1859 buf[2] = res->noise & 0xff;
1860 buf[3] = res->level & 0xff;
1861 buf[4] = res->tsf & 0xff;
1862 random_add_randomness(buf, sizeof(buf));
1863 }
1864#endif /* CONFIG_NO_RANDOM_POOL */
1865
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001866 if (update_only) {
1867 ret = 1;
1868 goto scan_work_done;
1869 }
1870
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001871 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001872 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001873 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1874 struct wpa_scan_results *scan_res);
1875
1876 scan_res_handler = wpa_s->scan_res_handler;
1877 wpa_s->scan_res_handler = NULL;
1878 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001879 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001880 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001881 }
1882
1883 if (ap) {
1884 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1885#ifdef CONFIG_AP
1886 if (wpa_s->ap_iface->scan_cb)
1887 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1888#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001889 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001890 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001891
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001892 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001893 wpa_s->own_scan_running,
1894 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001895 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001896 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1897 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001898 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1899 wpa_s->manual_scan_id);
1900 wpa_s->manual_scan_use_id = 0;
1901 } else {
1902 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1903 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001904 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001905
1906 wpas_notify_scan_done(wpa_s, 1);
1907
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001908 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001909 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 -07001910 wpa_scan_results_free(scan_res);
1911 return 0;
1912 }
1913
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001914 if (wnm_scan_process(wpa_s, 1) > 0)
1915 goto scan_work_done;
1916
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001917 if (sme_proc_obss_scan(wpa_s) > 0)
1918 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001919
Hai Shalom021b0b52019-04-10 11:17:58 -07001920 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08001921 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
1922 goto scan_work_done;
1923
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001924 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1925 goto scan_work_done;
1926
1927 if (autoscan_notify_scan(wpa_s, scan_res))
1928 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001929
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001930 if (wpa_s->disconnected) {
1931 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001932 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001933 }
1934
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001935 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001936 bgscan_notify_scan(wpa_s, scan_res) == 1)
1937 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001938
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001939 wpas_wps_update_ap_info(wpa_s, scan_res);
1940
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001941 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1942 wpa_s->wpa_state < WPA_COMPLETED)
1943 goto scan_work_done;
1944
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001945 wpa_scan_results_free(scan_res);
1946
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001947 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001948 struct wpa_radio_work *work = wpa_s->scan_work;
1949 wpa_s->scan_work = NULL;
1950 radio_work_done(work);
1951 }
1952
Hai Shalomc3565922019-10-28 11:58:20 -07001953 os_free(wpa_s->last_scan_freqs);
1954 wpa_s->last_scan_freqs = NULL;
1955 wpa_s->num_last_scan_freqs = 0;
1956 if (own_request && data &&
1957 data->scan_info.freqs && data->scan_info.num_freqs) {
1958 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
1959 data->scan_info.num_freqs);
1960 if (wpa_s->last_scan_freqs) {
1961 os_memcpy(wpa_s->last_scan_freqs,
1962 data->scan_info.freqs,
1963 sizeof(int) * data->scan_info.num_freqs);
1964 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
1965 }
1966 }
1967
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001968 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001969
1970scan_work_done:
1971 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001972 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001973 struct wpa_radio_work *work = wpa_s->scan_work;
1974 wpa_s->scan_work = NULL;
1975 radio_work_done(work);
1976 }
1977 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001978}
1979
1980
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001981static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001982 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001983{
1984 struct wpa_bss *selected;
1985 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001986 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1987
1988 if (time_to_reenable > 0) {
1989 wpa_dbg(wpa_s, MSG_DEBUG,
1990 "Postpone network selection by %d seconds since all networks are disabled",
1991 time_to_reenable);
1992 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1993 eloop_register_timeout(time_to_reenable, 0,
1994 wpas_network_reenabled, wpa_s, NULL);
1995 return 0;
1996 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001997
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001998 if (wpa_s->p2p_mgmt)
1999 return 0; /* no normal connection on p2p_mgmt interface */
2000
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002001 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002002 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002003
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002004#ifdef CONFIG_MESH
2005 if (wpa_s->ifmsh) {
2006 wpa_msg(wpa_s, MSG_INFO,
2007 "Avoiding join because we already joined a mesh group");
2008 return 0;
2009 }
2010#endif /* CONFIG_MESH */
2011
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002012 if (selected) {
2013 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002014 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002015 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002016 if (new_scan)
2017 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002018 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002019 }
2020
Hai Shalomc3565922019-10-28 11:58:20 -07002021 wpa_s->suitable_network++;
2022
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002023 if (ssid != wpa_s->current_ssid &&
2024 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2025 wpa_s->own_disconnect_req = 1;
2026 wpa_supplicant_deauthenticate(
2027 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2028 }
2029
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002030 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002031 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002032 return -1;
2033 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002034 if (new_scan)
2035 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002036 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002037 * Do not allow other virtual radios to trigger operations based
2038 * on these scan results since we do not want them to start
2039 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002040 */
2041 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002042 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002043 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002044 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2045 ssid = wpa_supplicant_pick_new_network(wpa_s);
2046 if (ssid) {
2047 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2048 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002049 if (new_scan)
2050 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002051 } else if (own_request) {
2052 /*
2053 * No SSID found. If SCAN results are as a result of
2054 * own scan request and not due to a scan request on
2055 * another shared interface, try another scan.
2056 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002057 int timeout_sec = wpa_s->scan_interval;
2058 int timeout_usec = 0;
2059#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002060 int res;
2061
2062 res = wpas_p2p_scan_no_go_seen(wpa_s);
2063 if (res == 2)
2064 return 2;
2065 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002066 return 0;
2067
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002068 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002069 wpa_s->show_group_started ||
2070 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002071 /*
2072 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002073 * state and during P2P join-a-group operation
2074 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075 */
2076 timeout_sec = 0;
2077 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002078 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2079 timeout_usec);
2080 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002081 }
2082#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002083#ifdef CONFIG_INTERWORKING
2084 if (wpa_s->conf->auto_interworking &&
2085 wpa_s->conf->interworking &&
2086 wpa_s->conf->cred) {
2087 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2088 "start ANQP fetch since no matching "
2089 "networks found");
2090 wpa_s->network_select = 1;
2091 wpa_s->auto_network_select = 1;
2092 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002093 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002094 }
2095#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002096#ifdef CONFIG_WPS
2097 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2098 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2099 timeout_sec = 0;
2100 timeout_usec = 500000;
2101 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2102 timeout_usec);
2103 return 0;
2104 }
2105#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002106#ifdef CONFIG_OWE
2107 if (wpa_s->owe_transition_search) {
2108 wpa_dbg(wpa_s, MSG_DEBUG,
2109 "OWE: Use shorter wait during transition mode search");
2110 timeout_sec = 0;
2111 timeout_usec = 500000;
2112 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2113 timeout_usec);
2114 return 0;
2115 }
2116#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002117 if (wpa_supplicant_req_sched_scan(wpa_s))
2118 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2119 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002120
2121 wpa_msg_ctrl(wpa_s, MSG_INFO,
2122 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002123 }
2124 }
2125 return 0;
2126}
2127
2128
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002129static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2130 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002131{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002133 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002134
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002135 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002136 if (res == 2) {
2137 /*
2138 * Interface may have been removed, so must not dereference
2139 * wpa_s after this.
2140 */
2141 return 1;
2142 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002143
2144 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002145 /*
2146 * If no scan results could be fetched, then no need to
2147 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002148 * this scan. Similarly, if scan results started a new operation on this
2149 * interface, do not notify other interfaces to avoid concurrent
2150 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002151 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002152 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002153 }
2154
2155 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002156 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002157 * so, they get updated with this same scan info.
2158 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002159 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2160 radio_list) {
2161 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2163 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002164 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2165 res > 0);
2166 if (res < 0)
2167 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002168 }
2169 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002170
2171 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172}
2173
2174#endif /* CONFIG_NO_SCAN_PROCESSING */
2175
2176
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002177int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2178{
2179#ifdef CONFIG_NO_SCAN_PROCESSING
2180 return -1;
2181#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002182 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002183
Dmitry Shmidt29333592017-01-09 12:27:11 -08002184 wpa_s->ignore_post_flush_scan_res = 0;
2185
Dmitry Shmidt41712582015-06-29 11:02:15 -07002186 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002187 return -1;
2188
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002189 os_get_reltime(&now);
2190 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002191 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2192 return -1;
2193 }
2194
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002195 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002196#endif /* CONFIG_NO_SCAN_PROCESSING */
2197}
2198
Dmitry Shmidt04949592012-07-19 12:16:46 -07002199#ifdef CONFIG_WNM
2200
2201static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2202{
2203 struct wpa_supplicant *wpa_s = eloop_ctx;
2204
2205 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2206 return;
2207
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002208 if (!wpa_s->no_keep_alive) {
2209 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2210 MAC2STR(wpa_s->bssid));
2211 /* TODO: could skip this if normal data traffic has been sent */
2212 /* TODO: Consider using some more appropriate data frame for
2213 * this */
2214 if (wpa_s->l2)
2215 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2216 (u8 *) "", 0);
2217 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002218
2219#ifdef CONFIG_SME
2220 if (wpa_s->sme.bss_max_idle_period) {
2221 unsigned int msec;
2222 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2223 if (msec > 100)
2224 msec -= 100;
2225 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2226 wnm_bss_keep_alive, wpa_s, NULL);
2227 }
2228#endif /* CONFIG_SME */
2229}
2230
2231
2232static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2233 const u8 *ies, size_t ies_len)
2234{
2235 struct ieee802_11_elems elems;
2236
2237 if (ies == NULL)
2238 return;
2239
2240 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2241 return;
2242
2243#ifdef CONFIG_SME
2244 if (elems.bss_max_idle_period) {
2245 unsigned int msec;
2246 wpa_s->sme.bss_max_idle_period =
2247 WPA_GET_LE16(elems.bss_max_idle_period);
2248 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2249 "TU)%s", wpa_s->sme.bss_max_idle_period,
2250 (elems.bss_max_idle_period[2] & 0x01) ?
2251 " (protected keep-live required)" : "");
2252 if (wpa_s->sme.bss_max_idle_period == 0)
2253 wpa_s->sme.bss_max_idle_period = 1;
2254 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2255 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2256 /* msec times 1000 */
2257 msec = wpa_s->sme.bss_max_idle_period * 1024;
2258 if (msec > 100)
2259 msec -= 100;
2260 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2261 wnm_bss_keep_alive, wpa_s,
2262 NULL);
2263 }
2264 }
2265#endif /* CONFIG_SME */
2266}
2267
2268#endif /* CONFIG_WNM */
2269
2270
2271void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2272{
2273#ifdef CONFIG_WNM
2274 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2275#endif /* CONFIG_WNM */
2276}
2277
2278
Dmitry Shmidt051af732013-10-22 13:52:46 -07002279#ifdef CONFIG_INTERWORKING
2280
2281static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2282 size_t len)
2283{
2284 int res;
2285
2286 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2287 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2288 if (res) {
2289 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2290 }
2291
2292 return res;
2293}
2294
2295
2296static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2297 const u8 *ies, size_t ies_len)
2298{
2299 struct ieee802_11_elems elems;
2300
2301 if (ies == NULL)
2302 return;
2303
2304 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2305 return;
2306
2307 if (elems.qos_map_set) {
2308 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2309 elems.qos_map_set_len);
2310 }
2311}
2312
2313#endif /* CONFIG_INTERWORKING */
2314
2315
Hai Shalom74f70d42019-02-11 14:42:39 -08002316static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2317 const u8 *ies, size_t ies_len)
2318{
2319 struct ieee802_11_elems elems;
2320 const u8 *map_sub_elem, *pos;
2321 size_t len;
2322
2323 if (!wpa_s->current_ssid ||
2324 !wpa_s->current_ssid->multi_ap_backhaul_sta ||
2325 !ies ||
2326 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2327 return;
2328
2329 if (!elems.multi_ap || elems.multi_ap_len < 7) {
2330 wpa_printf(MSG_INFO, "AP doesn't support Multi-AP protocol");
2331 goto fail;
2332 }
2333
2334 pos = elems.multi_ap + 4;
2335 len = elems.multi_ap_len - 4;
2336
2337 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
2338 if (!map_sub_elem || map_sub_elem[1] < 1) {
2339 wpa_printf(MSG_INFO, "invalid Multi-AP sub elem type");
2340 goto fail;
2341 }
2342
2343 if (!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS)) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002344 if ((map_sub_elem[2] & MULTI_AP_FRONTHAUL_BSS) &&
2345 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2346 wpa_printf(MSG_INFO,
2347 "WPS active, accepting fronthaul-only BSS");
2348 /* Don't set 4addr mode in this case, so just return */
2349 return;
2350 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002351 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2352 goto fail;
2353 }
2354
2355 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2356 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2357 goto fail;
2358 }
2359 wpa_s->enabled_4addr_mode = 1;
2360 return;
2361
2362fail:
2363 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2364}
2365
2366
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002367#ifdef CONFIG_FST
2368static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2369 const u8 *ie, size_t ie_len)
2370{
2371 struct mb_ies_info mb_ies;
2372
2373 if (!ie || !ie_len || !wpa_s->fst)
2374 return -ENOENT;
2375
2376 os_memset(&mb_ies, 0, sizeof(mb_ies));
2377
2378 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2379 size_t len;
2380
2381 len = 2 + ie[1];
2382 if (len > ie_len) {
2383 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2384 ie, ie_len);
2385 break;
2386 }
2387
2388 if (ie[0] == WLAN_EID_MULTI_BAND) {
2389 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2390 (unsigned int) len);
2391 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2392 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2393 mb_ies.nof_ies++;
2394 }
2395
2396 ie_len -= len;
2397 ie += len;
2398 }
2399
2400 if (mb_ies.nof_ies > 0) {
2401 wpabuf_free(wpa_s->received_mb_ies);
2402 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2403 return 0;
2404 }
2405
2406 return -ENOENT;
2407}
2408#endif /* CONFIG_FST */
2409
2410
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002411static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2412 union wpa_event_data *data)
2413{
Hai Shalomc3565922019-10-28 11:58:20 -07002414 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002415 const u8 *p;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002416#if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002417 u8 bssid[ETH_ALEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -07002418#endif /* CONFIG_IEEE80211R || CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002419
2420 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
2421 if (data->assoc_info.req_ies)
2422 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2423 data->assoc_info.req_ies_len);
2424 if (data->assoc_info.resp_ies) {
2425 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2426 data->assoc_info.resp_ies_len);
2427#ifdef CONFIG_TDLS
2428 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2429 data->assoc_info.resp_ies_len);
2430#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002431#ifdef CONFIG_WNM
2432 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2433 data->assoc_info.resp_ies_len);
2434#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002435#ifdef CONFIG_INTERWORKING
2436 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2437 data->assoc_info.resp_ies_len);
2438#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002439 if (wpa_s->hw_capab == CAPAB_VHT &&
2440 get_ie(data->assoc_info.resp_ies,
2441 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2442 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002443
2444 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2445 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002446 }
2447 if (data->assoc_info.beacon_ies)
2448 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2449 data->assoc_info.beacon_ies,
2450 data->assoc_info.beacon_ies_len);
2451 if (data->assoc_info.freq)
2452 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2453 data->assoc_info.freq);
2454
Hai Shalom021b0b52019-04-10 11:17:58 -07002455 wpa_s->connection_set = 0;
2456 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2457 struct ieee802_11_elems req_elems, resp_elems;
2458
2459 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2460 data->assoc_info.req_ies_len,
2461 &req_elems, 0) != ParseFailed &&
2462 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2463 data->assoc_info.resp_ies_len,
2464 &resp_elems, 0) != ParseFailed) {
2465 wpa_s->connection_set = 1;
2466 wpa_s->connection_ht = req_elems.ht_capabilities &&
2467 resp_elems.ht_capabilities;
2468 wpa_s->connection_vht = req_elems.vht_capabilities &&
2469 resp_elems.vht_capabilities;
2470 wpa_s->connection_he = req_elems.he_capabilities &&
2471 resp_elems.he_capabilities;
2472 }
2473 }
2474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002475 p = data->assoc_info.req_ies;
2476 l = data->assoc_info.req_ies_len;
2477
2478 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2479 while (p && l >= 2) {
2480 len = p[1] + 2;
2481 if (len > l) {
2482 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2483 p, l);
2484 break;
2485 }
Hai Shalomc3565922019-10-28 11:58:20 -07002486 if (!found &&
2487 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2488 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2489 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2490 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2491 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002492 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2493 break;
2494 found = 1;
2495 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07002496 }
2497 if (!found_x && p[0] == WLAN_EID_RSNX) {
2498 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
2499 break;
2500 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002501 }
2502 l -= len;
2503 p += len;
2504 }
2505 if (!found && data->assoc_info.req_ies)
2506 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002507 if (!found_x && data->assoc_info.req_ies)
2508 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002509
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002510#ifdef CONFIG_FILS
2511#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002512 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2513 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002514 (!data->assoc_info.resp_frame ||
2515 fils_process_assoc_resp(wpa_s->wpa,
2516 data->assoc_info.resp_frame,
2517 data->assoc_info.resp_frame_len) < 0)) {
2518 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2519 return -1;
2520 }
2521#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002522
2523 /* Additional processing for FILS when SME is in driver */
2524 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2525 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2526 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002527#endif /* CONFIG_FILS */
2528
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002529#ifdef CONFIG_OWE
2530 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
2531 (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2532 owe_process_assoc_resp(wpa_s->wpa, bssid,
2533 data->assoc_info.resp_ies,
2534 data->assoc_info.resp_ies_len) < 0)) {
2535 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2536 return -1;
2537 }
2538#endif /* CONFIG_OWE */
2539
Hai Shalom021b0b52019-04-10 11:17:58 -07002540#ifdef CONFIG_DPP2
2541 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
2542 if (wpa_s->key_mgmt == WPA_KEY_MGMT_DPP && wpa_s->dpp_pfs) {
2543 struct ieee802_11_elems elems;
2544
2545 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2546 data->assoc_info.resp_ies_len,
2547 &elems, 0) == ParseFailed ||
2548 !elems.owe_dh)
2549 goto no_pfs;
2550 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2551 elems.owe_dh_len) < 0) {
2552 wpa_supplicant_deauthenticate(wpa_s,
2553 WLAN_REASON_UNSPECIFIED);
2554 return -1;
2555 }
2556
2557 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2558 }
2559no_pfs:
2560#endif /* CONFIG_DPP2 */
2561
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002562#ifdef CONFIG_IEEE80211R
2563#ifdef CONFIG_SME
2564 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002565 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2566 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2567 data->assoc_info.resp_ies,
2568 data->assoc_info.resp_ies_len,
2569 bssid) < 0) {
2570 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2571 "Reassociation Response failed");
2572 wpa_supplicant_deauthenticate(
2573 wpa_s, WLAN_REASON_INVALID_IE);
2574 return -1;
2575 }
2576 }
2577
2578 p = data->assoc_info.resp_ies;
2579 l = data->assoc_info.resp_ies_len;
2580
2581#ifdef CONFIG_WPS_STRICT
2582 if (p && wpa_s->current_ssid &&
2583 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2584 struct wpabuf *wps;
2585 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2586 if (wps == NULL) {
2587 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2588 "include WPS IE in (Re)Association Response");
2589 return -1;
2590 }
2591
2592 if (wps_validate_assoc_resp(wps) < 0) {
2593 wpabuf_free(wps);
2594 wpa_supplicant_deauthenticate(
2595 wpa_s, WLAN_REASON_INVALID_IE);
2596 return -1;
2597 }
2598 wpabuf_free(wps);
2599 }
2600#endif /* CONFIG_WPS_STRICT */
2601
2602 /* Go through the IEs and make a copy of the MDIE, if present. */
2603 while (p && l >= 2) {
2604 len = p[1] + 2;
2605 if (len > l) {
2606 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2607 p, l);
2608 break;
2609 }
2610 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2611 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2612 wpa_s->sme.ft_used = 1;
2613 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2614 MOBILITY_DOMAIN_ID_LEN);
2615 break;
2616 }
2617 l -= len;
2618 p += len;
2619 }
2620#endif /* CONFIG_SME */
2621
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002622 /* Process FT when SME is in the driver */
2623 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2624 wpa_ft_is_completed(wpa_s->wpa)) {
2625 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2626 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2627 data->assoc_info.resp_ies,
2628 data->assoc_info.resp_ies_len,
2629 bssid) < 0) {
2630 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2631 "Reassociation Response failed");
2632 wpa_supplicant_deauthenticate(
2633 wpa_s, WLAN_REASON_INVALID_IE);
2634 return -1;
2635 }
2636 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2637 }
2638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002639 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2640 data->assoc_info.resp_ies_len);
2641#endif /* CONFIG_IEEE80211R */
2642
2643 /* WPA/RSN IE from Beacon/ProbeResp */
2644 p = data->assoc_info.beacon_ies;
2645 l = data->assoc_info.beacon_ies_len;
2646
2647 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2648 */
2649 wpa_found = rsn_found = 0;
2650 while (p && l >= 2) {
2651 len = p[1] + 2;
2652 if (len > l) {
2653 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2654 p, l);
2655 break;
2656 }
2657 if (!wpa_found &&
2658 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2659 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2660 wpa_found = 1;
2661 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2662 }
2663
2664 if (!rsn_found &&
2665 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2666 rsn_found = 1;
2667 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2668 }
2669
Hai Shalomc3565922019-10-28 11:58:20 -07002670 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
2671 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
2672
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002673 l -= len;
2674 p += len;
2675 }
2676
2677 if (!wpa_found && data->assoc_info.beacon_ies)
2678 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002679 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002680 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002681 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
2682 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002683 if (wpa_found || rsn_found)
2684 wpa_s->ap_ies_from_associnfo = 1;
2685
Jouni Malinen87fd2792011-05-16 18:35:42 +03002686 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2687 wpa_s->assoc_freq != data->assoc_info.freq) {
2688 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2689 "%u to %u MHz",
2690 wpa_s->assoc_freq, data->assoc_info.freq);
2691 wpa_supplicant_update_scan_results(wpa_s);
2692 }
2693
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002694 wpa_s->assoc_freq = data->assoc_info.freq;
2695
2696 return 0;
2697}
2698
2699
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002700static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2701{
Hai Shalomc3565922019-10-28 11:58:20 -07002702 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002703
2704 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2705 return -1;
2706
2707 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2708 return 0;
2709
2710 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2711 WPA_IE_VENDOR_TYPE);
2712 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07002713 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002714
2715 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2716 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2717 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07002718 bss_rsn ? 2 + bss_rsn[1] : 0) ||
2719 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
2720 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002721 return -1;
2722
2723 return 0;
2724}
2725
2726
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002727static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2728 union wpa_event_data *data)
2729{
2730#ifdef CONFIG_FST
2731 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2732 struct wpa_bss *bss = wpa_s->current_bss;
2733 const u8 *ieprb, *iebcn;
2734
2735 wpabuf_free(wpa_s->received_mb_ies);
2736 wpa_s->received_mb_ies = NULL;
2737
2738 if (ai &&
2739 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2740 wpa_printf(MSG_DEBUG,
2741 "FST: MB IEs updated from Association Response frame");
2742 return;
2743 }
2744
2745 if (ai &&
2746 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2747 wpa_printf(MSG_DEBUG,
2748 "FST: MB IEs updated from association event Beacon IEs");
2749 return;
2750 }
2751
2752 if (!bss)
2753 return;
2754
2755 ieprb = (const u8 *) (bss + 1);
2756 iebcn = ieprb + bss->ie_len;
2757
2758 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2759 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2760 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2761 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2762#endif /* CONFIG_FST */
2763}
2764
2765
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002766static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2767 union wpa_event_data *data)
2768{
2769 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002770 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002771 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07002772#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
2773 struct wpa_bss *bss;
2774#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002775
2776#ifdef CONFIG_AP
2777 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002778 if (!data)
2779 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002780 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2781 data->assoc_info.addr,
2782 data->assoc_info.req_ies,
2783 data->assoc_info.req_ies_len,
2784 data->assoc_info.reassoc);
2785 return;
2786 }
2787#endif /* CONFIG_AP */
2788
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002789 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2790
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002791 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2792 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2793 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002794 /*
2795 * FILS authentication can share the same mechanism to mark the
2796 * connection fully authenticated, so set ft_completed also based on
2797 * FILS result.
2798 */
2799 if (!ft_completed)
2800 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002801
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002802 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2803 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002804 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002805 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2806 return;
2807 }
2808
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002809 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002810 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08002811 if (os_reltime_initialized(&wpa_s->session_start)) {
2812 os_reltime_age(&wpa_s->session_start,
2813 &wpa_s->session_length);
2814 wpa_s->session_start.sec = 0;
2815 wpa_s->session_start.usec = 0;
2816 wpas_notify_session_length(wpa_s);
2817 } else {
2818 wpas_notify_auth_changed(wpa_s);
2819 os_get_reltime(&wpa_s->session_start);
2820 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002821 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2822 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002823 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002824 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002825 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2826 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002827 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002828
2829 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2830 wpa_clear_keys(wpa_s, bssid);
2831 }
2832 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002833 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002834 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2835 return;
2836 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002837 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002838
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002839 if (wpa_s->conf->ap_scan == 1 &&
2840 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002841 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2842 wpa_msg(wpa_s, MSG_WARNING,
2843 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002844 }
2845
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002846 wpas_fst_update_mb_assoc(wpa_s, data);
2847
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002848#ifdef CONFIG_SME
2849 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2850 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002851 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002852#endif /* CONFIG_SME */
2853
2854 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2855 if (wpa_s->current_ssid) {
2856 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2857 * initialized before association, but for other modes,
2858 * initialize PC/SC here, if the current configuration needs
2859 * smartcard or SIM/USIM. */
2860 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2861 }
2862 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2863 if (wpa_s->l2)
2864 l2_packet_notify_auth_start(wpa_s->l2);
2865
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002866 already_authorized = data && data->assoc_info.authorized;
2867
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002868 /*
2869 * Set portEnabled first to FALSE in order to get EAP state machine out
2870 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2871 * state machine may transit to AUTHENTICATING state based on obsolete
2872 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2873 * AUTHENTICATED without ever giving chance to EAP state machine to
2874 * reset the state.
2875 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002876 if (!ft_completed && !already_authorized) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002877 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2878 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2879 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002880 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
2881 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
2882 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07002883 already_authorized || wpa_s->drv_authorized_port)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002884 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2885 /* 802.1X::portControl = Auto */
2886 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2887 wpa_s->eapol_received = 0;
2888 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2889 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2890 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07002891 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002892 if (wpa_s->current_ssid &&
2893 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002894 (wpa_s->drv_flags &
2895 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2896 /*
2897 * Set the key after having received joined-IBSS event
2898 * from the driver.
2899 */
2900 wpa_supplicant_set_wpa_none_key(wpa_s,
2901 wpa_s->current_ssid);
2902 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002903 wpa_supplicant_cancel_auth_timeout(wpa_s);
2904 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2905 } else if (!ft_completed) {
2906 /* Timeout for receiving the first EAPOL packet */
2907 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2908 }
2909 wpa_supplicant_cancel_scan(wpa_s);
2910
Hai Shalom5f92bc92019-04-18 11:54:11 -07002911 if (ft_completed) {
2912 /*
2913 * FT protocol completed - make sure EAPOL state machine ends
2914 * up in authenticated.
2915 */
2916 wpa_supplicant_cancel_auth_timeout(wpa_s);
2917 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2918 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2919 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2920 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
2921 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002922 /*
2923 * We are done; the driver will take care of RSN 4-way
2924 * handshake.
2925 */
2926 wpa_supplicant_cancel_auth_timeout(wpa_s);
2927 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2928 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2929 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
Hai Shalom74f70d42019-02-11 14:42:39 -08002930 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002931 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2932 /*
2933 * The driver will take care of RSN 4-way handshake, so we need
2934 * to allow EAPOL supplicant to complete its work without
2935 * waiting for WPA supplicant.
2936 */
2937 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002938 }
2939
Jouni Malinena05074c2012-12-21 21:35:35 +02002940 wpa_s->last_eapol_matches_bssid = 0;
2941
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002942 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002943 struct os_reltime now, age;
2944 os_get_reltime(&now);
2945 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08002946 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002947 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2948 0) {
2949 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2950 "frame that was received just before "
2951 "association notification");
2952 wpa_supplicant_rx_eapol(
2953 wpa_s, wpa_s->pending_eapol_rx_src,
2954 wpabuf_head(wpa_s->pending_eapol_rx),
2955 wpabuf_len(wpa_s->pending_eapol_rx));
2956 }
2957 wpabuf_free(wpa_s->pending_eapol_rx);
2958 wpa_s->pending_eapol_rx = NULL;
2959 }
2960
2961 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2962 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002963 wpa_s->current_ssid &&
2964 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002965 /* Set static WEP keys again */
2966 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2967 }
2968
2969#ifdef CONFIG_IBSS_RSN
2970 if (wpa_s->current_ssid &&
2971 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2972 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2973 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2974 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002975 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002976 if (!wpa_s->ibss_rsn) {
2977 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2978 wpa_supplicant_deauthenticate(
2979 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2980 return;
2981 }
2982
2983 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2984 }
2985#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002986
2987 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002988
2989 if (data) {
2990 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2991 data->assoc_info.resp_ies_len,
2992 &data->assoc_info.wmm_params);
2993
2994 if (wpa_s->reassoc_same_bss)
2995 wmm_ac_restore_tspecs(wpa_s);
2996 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002997
Hai Shalomc3565922019-10-28 11:58:20 -07002998#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
2999 bss = wpa_bss_get_bssid(wpa_s, bssid);
3000#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003001#ifdef CONFIG_FILS
3002 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003003 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3004
3005 if (fils_cache_id)
3006 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3007 }
3008#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003009
3010#ifdef CONFIG_MBO
3011 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3012#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003013}
3014
3015
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003016static int disconnect_reason_recoverable(u16 reason_code)
3017{
3018 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3019 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3020 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3021}
3022
3023
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003024static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003025 u16 reason_code,
3026 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003027{
3028 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003029
3030 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3031 /*
3032 * At least Host AP driver and a Prism3 card seemed to be
3033 * generating streams of disconnected events when configuring
3034 * IBSS for WPA-None. Ignore them for now.
3035 */
3036 return;
3037 }
3038
3039 bssid = wpa_s->bssid;
3040 if (is_zero_ether_addr(bssid))
3041 bssid = wpa_s->pending_bssid;
3042
3043 if (!is_zero_ether_addr(bssid) ||
3044 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3045 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3046 " reason=%d%s",
3047 MAC2STR(bssid), reason_code,
3048 locally_generated ? " locally_generated=1" : "");
3049 }
3050}
3051
3052
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003053static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3054 int locally_generated)
3055{
3056 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Hai Shalomc3565922019-10-28 11:58:20 -07003057 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3058 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003059 return 0; /* Not in 4-way handshake with PSK */
3060
3061 /*
3062 * It looks like connection was lost while trying to go through PSK
3063 * 4-way handshake. Filter out known disconnection cases that are caused
3064 * by something else than PSK mismatch to avoid confusing reports.
3065 */
3066
3067 if (locally_generated) {
3068 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3069 return 0;
3070 }
3071
3072 return 1;
3073}
3074
3075
Jouni Malinen2b89da82012-08-31 22:04:41 +03003076static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3077 u16 reason_code,
3078 int locally_generated)
3079{
3080 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003081 int authenticating;
3082 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003083 struct wpa_bss *fast_reconnect = NULL;
3084 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003085 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003086 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003087
3088 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3089 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3090
3091 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3092 /*
3093 * At least Host AP driver and a Prism3 card seemed to be
3094 * generating streams of disconnected events when configuring
3095 * IBSS for WPA-None. Ignore them for now.
3096 */
3097 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3098 "IBSS/WPA-None mode");
3099 return;
3100 }
3101
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003102 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3103 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3104 locally_generated)
3105 /*
3106 * Remove the inactive AP (which is probably out of range) from
3107 * the BSS list after marking disassociation. In particular
3108 * mac80211-based drivers use the
3109 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3110 * locally generated disconnection events for cases where the
3111 * AP does not reply anymore.
3112 */
3113 curr = wpa_s->current_bss;
3114
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003115 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003116 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3117 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003118 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3119 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003120 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003121#ifdef CONFIG_DPP2
3122 wpas_dpp_send_conn_status_result(wpa_s,
3123 DPP_STATUS_AUTH_FAILURE);
3124#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003125 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003126 if (!wpa_s->disconnected &&
3127 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003128 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003129 wpas_wps_searching(wpa_s) ||
3130 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003131 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003132 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003133 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003134 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003135 wpa_s->wpa_state);
3136 if (wpa_s->wpa_state == WPA_COMPLETED &&
3137 wpa_s->current_ssid &&
3138 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003139 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003140 disconnect_reason_recoverable(reason_code)) {
3141 /*
3142 * It looks like the AP has dropped association with
3143 * us, but could allow us to get back in. Try to
3144 * reconnect to the same BSS without full scan to save
3145 * time for some common cases.
3146 */
3147 fast_reconnect = wpa_s->current_bss;
3148 fast_reconnect_ssid = wpa_s->current_ssid;
3149 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003150 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003151 else
3152 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3153 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003155 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003156 "try to re-connect");
3157 wpa_s->reassociate = 0;
3158 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003159 if (!wpa_s->pno)
3160 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003161 }
3162 bssid = wpa_s->bssid;
3163 if (is_zero_ether_addr(bssid))
3164 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003165 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3166 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003167 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003168 if (locally_generated)
3169 wpa_s->disconnect_reason = -reason_code;
3170 else
3171 wpa_s->disconnect_reason = reason_code;
3172 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003173 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3174 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003175 wpa_clear_keys(wpa_s, wpa_s->bssid);
3176 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003177 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003178 wpa_supplicant_mark_disassoc(wpa_s);
3179
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003180 if (curr)
3181 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3182
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003183 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003184 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003185 wpa_s->current_ssid = last_ssid;
3186 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003187
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003188 if (fast_reconnect &&
3189 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3190 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3191 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3192 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003193 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003194 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003195#ifndef CONFIG_NO_SCAN_PROCESSING
3196 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3197 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3198 fast_reconnect_ssid) < 0) {
3199 /* Recover through full scan */
3200 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3201 }
3202#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003203 } else if (fast_reconnect) {
3204 /*
3205 * Could not reconnect to the same BSS due to network being
3206 * disabled. Use a new scan to match the alternative behavior
3207 * above, i.e., to continue automatic reconnection attempt in a
3208 * way that enforces disabled network rules.
3209 */
3210 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003211 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003212}
3213
3214
3215#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003216void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003217{
3218 struct wpa_supplicant *wpa_s = eloop_ctx;
3219
3220 if (!wpa_s->pending_mic_error_report)
3221 return;
3222
3223 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3224 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3225 wpa_s->pending_mic_error_report = 0;
3226}
3227#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3228
3229
3230static void
3231wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3232 union wpa_event_data *data)
3233{
3234 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003235 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003236
3237 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3238 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003239 os_get_reltime(&t);
3240 if ((wpa_s->last_michael_mic_error.sec &&
3241 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003242 wpa_s->pending_mic_error_report) {
3243 if (wpa_s->pending_mic_error_report) {
3244 /*
3245 * Send the pending MIC error report immediately since
3246 * we are going to start countermeasures and AP better
3247 * do the same.
3248 */
3249 wpa_sm_key_request(wpa_s->wpa, 1,
3250 wpa_s->pending_mic_error_pairwise);
3251 }
3252
3253 /* Send the new MIC error report immediately since we are going
3254 * to start countermeasures and AP better do the same.
3255 */
3256 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3257
3258 /* initialize countermeasures */
3259 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003260
3261 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3262
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003263 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3264
3265 /*
3266 * Need to wait for completion of request frame. We do not get
3267 * any callback for the message completion, so just wait a
3268 * short while and hope for the best. */
3269 os_sleep(0, 10000);
3270
3271 wpa_drv_set_countermeasures(wpa_s, 1);
3272 wpa_supplicant_deauthenticate(wpa_s,
3273 WLAN_REASON_MICHAEL_MIC_FAILURE);
3274 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3275 wpa_s, NULL);
3276 eloop_register_timeout(60, 0,
3277 wpa_supplicant_stop_countermeasures,
3278 wpa_s, NULL);
3279 /* TODO: mark the AP rejected for 60 second. STA is
3280 * allowed to associate with another AP.. */
3281 } else {
3282#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3283 if (wpa_s->mic_errors_seen) {
3284 /*
3285 * Reduce the effectiveness of Michael MIC error
3286 * reports as a means for attacking against TKIP if
3287 * more than one MIC failure is noticed with the same
3288 * PTK. We delay the transmission of the reports by a
3289 * random time between 0 and 60 seconds in order to
3290 * force the attacker wait 60 seconds before getting
3291 * the information on whether a frame resulted in a MIC
3292 * failure.
3293 */
3294 u8 rval[4];
3295 int sec;
3296
3297 if (os_get_random(rval, sizeof(rval)) < 0)
3298 sec = os_random() % 60;
3299 else
3300 sec = WPA_GET_BE32(rval) % 60;
3301 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3302 "report %d seconds", sec);
3303 wpa_s->pending_mic_error_report = 1;
3304 wpa_s->pending_mic_error_pairwise = pairwise;
3305 eloop_cancel_timeout(
3306 wpa_supplicant_delayed_mic_error_report,
3307 wpa_s, NULL);
3308 eloop_register_timeout(
3309 sec, os_random() % 1000000,
3310 wpa_supplicant_delayed_mic_error_report,
3311 wpa_s, NULL);
3312 } else {
3313 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3314 }
3315#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3316 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3317#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3318 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003319 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003320 wpa_s->mic_errors_seen++;
3321}
3322
3323
3324#ifdef CONFIG_TERMINATE_ONLASTIF
3325static int any_interfaces(struct wpa_supplicant *head)
3326{
3327 struct wpa_supplicant *wpa_s;
3328
3329 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3330 if (!wpa_s->interface_removed)
3331 return 1;
3332 return 0;
3333}
3334#endif /* CONFIG_TERMINATE_ONLASTIF */
3335
3336
3337static void
3338wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3339 union wpa_event_data *data)
3340{
3341 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3342 return;
3343
3344 switch (data->interface_status.ievent) {
3345 case EVENT_INTERFACE_ADDED:
3346 if (!wpa_s->interface_removed)
3347 break;
3348 wpa_s->interface_removed = 0;
3349 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3350 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3351 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3352 "driver after interface was added");
3353 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003354
3355#ifdef CONFIG_P2P
3356 if (!wpa_s->global->p2p &&
3357 !wpa_s->global->p2p_disabled &&
3358 !wpa_s->conf->p2p_disabled &&
3359 (wpa_s->drv_flags &
3360 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3361 wpas_p2p_add_p2pdev_interface(
3362 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3363 wpa_printf(MSG_INFO,
3364 "P2P: Failed to enable P2P Device interface");
3365 /* Try to continue without. P2P will be disabled. */
3366 }
3367#endif /* CONFIG_P2P */
3368
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003369 break;
3370 case EVENT_INTERFACE_REMOVED:
3371 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3372 wpa_s->interface_removed = 1;
3373 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003374 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003375 l2_packet_deinit(wpa_s->l2);
3376 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003377
3378#ifdef CONFIG_P2P
3379 if (wpa_s->global->p2p &&
3380 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3381 (wpa_s->drv_flags &
3382 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3383 wpa_dbg(wpa_s, MSG_DEBUG,
3384 "Removing P2P Device interface");
3385 wpa_supplicant_remove_iface(
3386 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3387 0);
3388 wpa_s->global->p2p_init_wpa_s = NULL;
3389 }
3390#endif /* CONFIG_P2P */
3391
Dmitry Shmidte4663042016-04-04 10:07:49 -07003392#ifdef CONFIG_MATCH_IFACE
3393 if (wpa_s->matched) {
3394 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3395 break;
3396 }
3397#endif /* CONFIG_MATCH_IFACE */
3398
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003399#ifdef CONFIG_TERMINATE_ONLASTIF
3400 /* check if last interface */
3401 if (!any_interfaces(wpa_s->global->ifaces))
3402 eloop_terminate();
3403#endif /* CONFIG_TERMINATE_ONLASTIF */
3404 break;
3405 }
3406}
3407
3408
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003409#ifdef CONFIG_TDLS
3410static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3411 union wpa_event_data *data)
3412{
3413 if (data == NULL)
3414 return;
3415 switch (data->tdls.oper) {
3416 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003417 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3418 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3419 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3420 else
3421 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003422 break;
3423 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003424 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3425 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3426 data->tdls.reason_code);
3427 else
3428 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3429 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003430 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003431 case TDLS_REQUEST_DISCOVER:
3432 wpa_tdls_send_discovery_request(wpa_s->wpa,
3433 data->tdls.peer);
3434 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003435 }
3436}
3437#endif /* CONFIG_TDLS */
3438
3439
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003440#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003441static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3442 union wpa_event_data *data)
3443{
3444 if (data == NULL)
3445 return;
3446 switch (data->wnm.oper) {
3447 case WNM_OPER_SLEEP:
3448 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3449 "(action=%d, intval=%d)",
3450 data->wnm.sleep_action, data->wnm.sleep_intval);
3451 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003452 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003453 break;
3454 }
3455}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003456#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003457
3458
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003459#ifdef CONFIG_IEEE80211R
3460static void
3461wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3462 union wpa_event_data *data)
3463{
3464 if (data == NULL)
3465 return;
3466
3467 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3468 data->ft_ies.ies_len,
3469 data->ft_ies.ft_action,
3470 data->ft_ies.target_ap,
3471 data->ft_ies.ric_ies,
3472 data->ft_ies.ric_ies_len) < 0) {
3473 /* TODO: prevent MLME/driver from trying to associate? */
3474 }
3475}
3476#endif /* CONFIG_IEEE80211R */
3477
3478
3479#ifdef CONFIG_IBSS_RSN
3480static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3481 union wpa_event_data *data)
3482{
3483 struct wpa_ssid *ssid;
3484 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3485 return;
3486 if (data == NULL)
3487 return;
3488 ssid = wpa_s->current_ssid;
3489 if (ssid == NULL)
3490 return;
3491 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3492 return;
3493
3494 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3495}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003496
3497
3498static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3499 union wpa_event_data *data)
3500{
3501 struct wpa_ssid *ssid = wpa_s->current_ssid;
3502
3503 if (ssid == NULL)
3504 return;
3505
3506 /* check if the ssid is correctly configured as IBSS/RSN */
3507 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3508 return;
3509
3510 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3511 data->rx_mgmt.frame_len);
3512}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003513#endif /* CONFIG_IBSS_RSN */
3514
3515
3516#ifdef CONFIG_IEEE80211R
3517static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3518 size_t len)
3519{
3520 const u8 *sta_addr, *target_ap_addr;
3521 u16 status;
3522
3523 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3524 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3525 return; /* only SME case supported for now */
3526 if (len < 1 + 2 * ETH_ALEN + 2)
3527 return;
3528 if (data[0] != 2)
3529 return; /* Only FT Action Response is supported for now */
3530 sta_addr = data + 1;
3531 target_ap_addr = data + 1 + ETH_ALEN;
3532 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3533 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3534 MACSTR " TargetAP " MACSTR " status %u",
3535 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3536
3537 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3538 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3539 " in FT Action Response", MAC2STR(sta_addr));
3540 return;
3541 }
3542
3543 if (status) {
3544 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3545 "failure (status code %d)", status);
3546 /* TODO: report error to FT code(?) */
3547 return;
3548 }
3549
3550 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3551 len - (1 + 2 * ETH_ALEN + 2), 1,
3552 target_ap_addr, NULL, 0) < 0)
3553 return;
3554
3555#ifdef CONFIG_SME
3556 {
3557 struct wpa_bss *bss;
3558 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3559 if (bss)
3560 wpa_s->sme.freq = bss->freq;
3561 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3562 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3563 WLAN_AUTH_FT);
3564 }
3565#endif /* CONFIG_SME */
3566}
3567#endif /* CONFIG_IEEE80211R */
3568
3569
3570static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3571 struct unprot_deauth *e)
3572{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003573 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3574 "dropped: " MACSTR " -> " MACSTR
3575 " (reason code %u)",
3576 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3577 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003578}
3579
3580
3581static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3582 struct unprot_disassoc *e)
3583{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003584 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3585 "dropped: " MACSTR " -> " MACSTR
3586 " (reason code %u)",
3587 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3588 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003589}
3590
3591
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003592static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3593 u16 reason_code, int locally_generated,
3594 const u8 *ie, size_t ie_len, int deauth)
3595{
3596#ifdef CONFIG_AP
3597 if (wpa_s->ap_iface && addr) {
3598 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3599 return;
3600 }
3601
3602 if (wpa_s->ap_iface) {
3603 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3604 return;
3605 }
3606#endif /* CONFIG_AP */
3607
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003608 if (!locally_generated)
3609 wpa_s->own_disconnect_req = 0;
3610
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003611 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3612
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003613 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3614 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3615 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3616 eapol_sm_failed(wpa_s->eapol))) &&
3617 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003618 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003619
3620#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003621 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003622 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3623 locally_generated) > 0) {
3624 /*
3625 * The interface was removed, so cannot continue
3626 * processing any additional operations after this.
3627 */
3628 return;
3629 }
3630 }
3631#endif /* CONFIG_P2P */
3632
3633 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3634 locally_generated);
3635}
3636
3637
3638static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3639 struct disassoc_info *info)
3640{
3641 u16 reason_code = 0;
3642 int locally_generated = 0;
3643 const u8 *addr = NULL;
3644 const u8 *ie = NULL;
3645 size_t ie_len = 0;
3646
3647 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3648
3649 if (info) {
3650 addr = info->addr;
3651 ie = info->ie;
3652 ie_len = info->ie_len;
3653 reason_code = info->reason_code;
3654 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07003655 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
3656 reason2str(reason_code),
3657 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003658 if (addr)
3659 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3660 MAC2STR(addr));
3661 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3662 ie, ie_len);
3663 }
3664
3665#ifdef CONFIG_AP
3666 if (wpa_s->ap_iface && info && info->addr) {
3667 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3668 return;
3669 }
3670
3671 if (wpa_s->ap_iface) {
3672 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3673 return;
3674 }
3675#endif /* CONFIG_AP */
3676
3677#ifdef CONFIG_P2P
3678 if (info) {
3679 wpas_p2p_disassoc_notif(
3680 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3681 locally_generated);
3682 }
3683#endif /* CONFIG_P2P */
3684
3685 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3686 sme_event_disassoc(wpa_s, info);
3687
3688 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3689 ie, ie_len, 0);
3690}
3691
3692
3693static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3694 struct deauth_info *info)
3695{
3696 u16 reason_code = 0;
3697 int locally_generated = 0;
3698 const u8 *addr = NULL;
3699 const u8 *ie = NULL;
3700 size_t ie_len = 0;
3701
3702 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3703
3704 if (info) {
3705 addr = info->addr;
3706 ie = info->ie;
3707 ie_len = info->ie_len;
3708 reason_code = info->reason_code;
3709 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07003710 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
3711 reason_code, reason2str(reason_code),
3712 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003713 if (addr) {
3714 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3715 MAC2STR(addr));
3716 }
3717 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3718 ie, ie_len);
3719 }
3720
3721 wpa_reset_ft_completed(wpa_s->wpa);
3722
3723 wpas_event_disconnect(wpa_s, addr, reason_code,
3724 locally_generated, ie, ie_len, 1);
3725}
3726
3727
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003728static const char * reg_init_str(enum reg_change_initiator init)
3729{
3730 switch (init) {
3731 case REGDOM_SET_BY_CORE:
3732 return "CORE";
3733 case REGDOM_SET_BY_USER:
3734 return "USER";
3735 case REGDOM_SET_BY_DRIVER:
3736 return "DRIVER";
3737 case REGDOM_SET_BY_COUNTRY_IE:
3738 return "COUNTRY_IE";
3739 case REGDOM_BEACON_HINT:
3740 return "BEACON_HINT";
3741 }
3742 return "?";
3743}
3744
3745
3746static const char * reg_type_str(enum reg_type type)
3747{
3748 switch (type) {
3749 case REGDOM_TYPE_UNKNOWN:
3750 return "UNKNOWN";
3751 case REGDOM_TYPE_COUNTRY:
3752 return "COUNTRY";
3753 case REGDOM_TYPE_WORLD:
3754 return "WORLD";
3755 case REGDOM_TYPE_CUSTOM_WORLD:
3756 return "CUSTOM_WORLD";
3757 case REGDOM_TYPE_INTERSECTION:
3758 return "INTERSECTION";
3759 }
3760 return "?";
3761}
3762
3763
Hai Shalom74f70d42019-02-11 14:42:39 -08003764void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
3765 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003766{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003767 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003768 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003769
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003770 /*
3771 * To allow backwards compatibility with higher level layers that
3772 * assumed the REGDOM_CHANGE event is sent over the initially added
3773 * interface. Find the highest parent of this interface and use it to
3774 * send the event.
3775 */
3776 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3777 ;
3778
Hai Shalom74f70d42019-02-11 14:42:39 -08003779 if (info) {
3780 wpa_msg(ifs, MSG_INFO,
3781 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3782 reg_init_str(info->initiator), reg_type_str(info->type),
3783 info->alpha2[0] ? " alpha2=" : "",
3784 info->alpha2[0] ? info->alpha2 : "");
3785 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003786
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003787 if (wpa_s->drv_priv == NULL)
3788 return; /* Ignore event during drv initialization */
3789
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003790 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3791 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003792 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3793 ifs->ifname);
3794 free_hw_features(ifs);
3795 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003796 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003797
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003798 /* Restart PNO/sched_scan with updated channel list */
3799 if (ifs->pno) {
3800 wpas_stop_pno(ifs);
3801 wpas_start_pno(ifs);
3802 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
3803 wpa_dbg(ifs, MSG_DEBUG,
3804 "Channel list changed - restart sched_scan");
3805 wpas_scan_restart_sched_scan(ifs);
3806 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003807 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003808
3809 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003810}
3811
3812
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003813static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003814 const u8 *frame, size_t len, int freq,
3815 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003816{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003817 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003818 const u8 *payload;
3819 size_t plen;
3820 u8 category;
3821
3822 if (len < IEEE80211_HDRLEN + 2)
3823 return;
3824
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003825 mgmt = (const struct ieee80211_mgmt *) frame;
3826 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003827 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003828 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003829
3830 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3831 " Category=%u DataLen=%d freq=%d MHz",
3832 MAC2STR(mgmt->sa), category, (int) plen, freq);
3833
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003834 if (category == WLAN_ACTION_WMM) {
3835 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3836 return;
3837 }
3838
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003839#ifdef CONFIG_IEEE80211R
3840 if (category == WLAN_ACTION_FT) {
3841 ft_rx_action(wpa_s, payload, plen);
3842 return;
3843 }
3844#endif /* CONFIG_IEEE80211R */
3845
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003846#ifdef CONFIG_SME
3847 if (category == WLAN_ACTION_SA_QUERY) {
3848 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3849 return;
3850 }
3851#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003852
3853#ifdef CONFIG_WNM
3854 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3855 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3856 return;
3857 }
3858#endif /* CONFIG_WNM */
3859
3860#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003861 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3862 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003863 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003864 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003865 payload, plen, freq) == 0)
3866 return;
3867#endif /* CONFIG_GAS */
3868
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003869#ifdef CONFIG_GAS_SERVER
3870 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3871 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3872 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
3873 mgmt->u.action.category,
3874 payload, plen, freq) == 0)
3875 return;
3876#endif /* CONFIG_GAS_SERVER */
3877
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003878#ifdef CONFIG_TDLS
3879 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3880 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3881 wpa_dbg(wpa_s, MSG_DEBUG,
3882 "TDLS: Received Discovery Response from " MACSTR,
3883 MAC2STR(mgmt->sa));
3884 return;
3885 }
3886#endif /* CONFIG_TDLS */
3887
3888#ifdef CONFIG_INTERWORKING
3889 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3890 payload[0] == QOS_QOS_MAP_CONFIG) {
3891 const u8 *pos = payload + 1;
3892 size_t qlen = plen - 1;
3893 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3894 MACSTR, MAC2STR(mgmt->sa));
3895 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3896 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3897 pos[1] <= qlen - 2 && pos[1] >= 16)
3898 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3899 return;
3900 }
3901#endif /* CONFIG_INTERWORKING */
3902
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003903 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003904 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
3905 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003906 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003907 payload + 1,
3908 plen - 1);
3909 return;
3910 }
3911
3912 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003913 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3914 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3915 return;
3916 }
3917
3918 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3919 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3920 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3921 payload + 1, plen - 1,
3922 rssi);
3923 return;
3924 }
3925
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003926#ifdef CONFIG_FST
3927 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3928 fst_rx_action(wpa_s->fst, mgmt, len);
3929 return;
3930 }
3931#endif /* CONFIG_FST */
3932
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003933#ifdef CONFIG_DPP
3934 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
3935 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
3936 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
3937 payload[4] == DPP_OUI_TYPE) {
3938 payload++;
3939 plen--;
3940 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
3941 return;
3942 }
3943#endif /* CONFIG_DPP */
3944
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003945 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3946 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003947 if (wpa_s->ifmsh)
3948 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003949}
3950
3951
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003952static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3953 union wpa_event_data *event)
3954{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003955 struct wpa_freq_range_list *list;
3956 char *str = NULL;
3957
3958 list = &event->freq_range;
3959
3960 if (list->num)
3961 str = freq_range_list_str(list);
3962 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3963 str ? str : "");
3964
3965#ifdef CONFIG_P2P
3966 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3967 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3968 __func__);
3969 } else {
3970 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003971
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003972 /*
3973 * The update channel flow will also take care of moving a GO
3974 * from the unsafe frequency if needed.
3975 */
3976 wpas_p2p_update_channel_list(wpa_s,
3977 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003978 }
3979#endif /* CONFIG_P2P */
3980
3981 os_free(str);
3982}
3983
3984
Roshan Pius3a1667e2018-07-03 15:17:14 -07003985static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003986{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003987 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3988 wpa_supplicant_cancel_auth_timeout(wpa_s);
3989 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3990 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3991 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
Hai Shalomc3565922019-10-28 11:58:20 -07003992 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003993 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003994}
3995
3996
3997static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
3998 int freq)
3999{
4000 size_t i;
4001 int j;
4002
4003 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4004 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4005
4006 for (j = 0; j < mode->num_channels; j++) {
4007 const struct hostapd_channel_data *chan;
4008
4009 chan = &mode->channels[j];
4010 if (chan->freq == freq)
4011 return chan->dfs_cac_ms;
4012 }
4013 }
4014
4015 return 0;
4016}
4017
4018
4019static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4020 struct dfs_event *radar)
4021{
4022#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004023 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004024 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4025 } else
4026#endif /* NEED_AP_MLME && CONFIG_AP */
4027 {
4028 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4029
4030 cac_time /= 1000; /* convert from ms to sec */
4031 if (!cac_time)
4032 cac_time = 10 * 60; /* max timeout: 10 minutes */
4033
4034 /* Restart auth timeout: CAC time added to initial timeout */
4035 wpas_auth_timeout_restart(wpa_s, cac_time);
4036 }
4037}
4038
4039
4040static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4041 struct dfs_event *radar)
4042{
4043#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004044 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004045 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4046 } else
4047#endif /* NEED_AP_MLME && CONFIG_AP */
4048 {
4049 /* Restart auth timeout with original value after CAC is
4050 * finished */
4051 wpas_auth_timeout_restart(wpa_s, 0);
4052 }
4053}
4054
4055
4056static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4057 struct dfs_event *radar)
4058{
4059#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004060 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004061 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4062 } else
4063#endif /* NEED_AP_MLME && CONFIG_AP */
4064 {
4065 /* Restart auth timeout with original value after CAC is
4066 * aborted */
4067 wpas_auth_timeout_restart(wpa_s, 0);
4068 }
4069}
4070
4071
4072static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4073 union wpa_event_data *data)
4074{
4075 wpa_dbg(wpa_s, MSG_DEBUG,
4076 "Connection authorized by device, previous state %d",
4077 wpa_s->wpa_state);
4078
4079 wpa_supplicant_event_port_authorized(wpa_s);
4080
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004081 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4082 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004083 data->assoc_info.ptk_kck_len,
4084 data->assoc_info.ptk_kek,
4085 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004086#ifdef CONFIG_FILS
4087 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4088 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4089 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4090
4091 /* Update ERP next sequence number */
4092 eapol_sm_update_erp_next_seq_num(
4093 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4094
4095 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4096 /* Add the new PMK and PMKID to the PMKSA cache */
4097 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4098 data->assoc_info.fils_pmk,
4099 data->assoc_info.fils_pmk_len,
4100 data->assoc_info.fils_pmkid,
4101 wpa_s->bssid, fils_cache_id);
4102 } else if (data->assoc_info.fils_pmkid) {
4103 /* Update the current PMKSA used for this connection */
4104 pmksa_cache_set_current(wpa_s->wpa,
4105 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004106 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004107 }
4108 }
4109#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004110}
4111
4112
Roshan Pius3a1667e2018-07-03 15:17:14 -07004113static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4114 union wpa_event_data *data)
4115{
4116 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004117#ifdef CONFIG_MBO
4118 struct wpa_bss *reject_bss;
4119#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004120
4121 if (!bssid || is_zero_ether_addr(bssid))
4122 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004123#ifdef CONFIG_MBO
4124 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4125 reject_bss = wpa_s->current_bss;
4126 else
4127 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4128#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004129
4130 if (data->assoc_reject.bssid)
4131 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4132 "bssid=" MACSTR " status_code=%u%s%s%s",
4133 MAC2STR(data->assoc_reject.bssid),
4134 data->assoc_reject.status_code,
4135 data->assoc_reject.timed_out ? " timeout" : "",
4136 data->assoc_reject.timeout_reason ? "=" : "",
4137 data->assoc_reject.timeout_reason ?
4138 data->assoc_reject.timeout_reason : "");
4139 else
4140 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4141 "status_code=%u%s%s%s",
4142 data->assoc_reject.status_code,
4143 data->assoc_reject.timed_out ? " timeout" : "",
4144 data->assoc_reject.timeout_reason ? "=" : "",
4145 data->assoc_reject.timeout_reason ?
4146 data->assoc_reject.timeout_reason : "");
4147 wpa_s->assoc_status_code = data->assoc_reject.status_code;
4148 wpa_s->assoc_timed_out = data->assoc_reject.timed_out;
4149 wpas_notify_assoc_status_code(wpa_s);
4150
4151#ifdef CONFIG_OWE
4152 if (data->assoc_reject.status_code ==
4153 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4154 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4155 wpa_s->current_ssid &&
4156 wpa_s->current_ssid->owe_group == 0 &&
4157 wpa_s->last_owe_group != 21) {
4158 struct wpa_ssid *ssid = wpa_s->current_ssid;
4159 struct wpa_bss *bss = wpa_s->current_bss;
4160
4161 if (!bss) {
4162 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4163 if (!bss) {
4164 wpas_connection_failed(wpa_s, bssid);
4165 wpa_supplicant_mark_disassoc(wpa_s);
4166 return;
4167 }
4168 }
4169 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4170 wpas_connect_work_done(wpa_s);
4171 wpa_supplicant_mark_disassoc(wpa_s);
4172 wpa_supplicant_connect(wpa_s, bss, ssid);
4173 return;
4174 }
4175#endif /* CONFIG_OWE */
4176
Hai Shalom74f70d42019-02-11 14:42:39 -08004177#ifdef CONFIG_MBO
4178 if (data->assoc_reject.status_code ==
4179 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004180 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004181 const u8 *rssi_rej;
4182
4183 rssi_rej = mbo_get_attr_from_ies(
4184 data->assoc_reject.resp_ies,
4185 data->assoc_reject.resp_ies_len,
4186 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4187 if (rssi_rej && rssi_rej[1] == 2) {
4188 wpa_printf(MSG_DEBUG,
4189 "OCE: RSSI-based association rejection from "
4190 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004191 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004192 rssi_rej[2], rssi_rej[3]);
4193 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004194 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004195 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004196 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004197 }
4198 }
4199#endif /* CONFIG_MBO */
4200
Roshan Pius3a1667e2018-07-03 15:17:14 -07004201 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4202 sme_event_assoc_reject(wpa_s, data);
4203 return;
4204 }
4205
4206 /* Driver-based SME cases */
4207
4208#ifdef CONFIG_SAE
4209 if (wpa_s->current_ssid &&
4210 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4211 !data->assoc_reject.timed_out) {
4212 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4213 wpa_sm_aborted_cached(wpa_s->wpa);
4214 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4215 }
4216#endif /* CONFIG_SAE */
4217
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004218#ifdef CONFIG_DPP
4219 if (wpa_s->current_ssid &&
4220 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4221 !data->assoc_reject.timed_out) {
4222 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4223 wpa_sm_aborted_cached(wpa_s->wpa);
4224 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4225 }
4226#endif /* CONFIG_DPP */
4227
Roshan Pius3a1667e2018-07-03 15:17:14 -07004228#ifdef CONFIG_FILS
4229 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004230 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004231 eapol_sm_update_erp_next_seq_num(
4232 wpa_s->eapol,
4233 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004234 fils_connection_failure(wpa_s);
4235 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004236#endif /* CONFIG_FILS */
4237
4238 wpas_connection_failed(wpa_s, bssid);
4239 wpa_supplicant_mark_disassoc(wpa_s);
4240}
4241
4242
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004243void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4244 union wpa_event_data *data)
4245{
4246 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004247 int resched;
Hai Shalom74f70d42019-02-11 14:42:39 -08004248#ifndef CONFIG_NO_STDOUT_DEBUG
4249 int level = MSG_DEBUG;
4250#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004251
4252 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4253 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004254 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004255 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004256 event != EVENT_SCHED_SCAN_STOPPED) {
4257 wpa_dbg(wpa_s, MSG_DEBUG,
4258 "Ignore event %s (%d) while interface is disabled",
4259 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004260 return;
4261 }
4262
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004263#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07004264 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004265 const struct ieee80211_hdr *hdr;
4266 u16 fc;
4267 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4268 fc = le_to_host16(hdr->frame_control);
4269 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4270 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4271 level = MSG_EXCESSIVE;
4272 }
4273
4274 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4275 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004276#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004277
4278 switch (event) {
4279 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004280#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004281 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4282 data->auth.ies_len))
4283 wpa_printf(MSG_DEBUG,
4284 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004285#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004286 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004287 wpa_s->auth_status_code = data->auth.status_code;
4288 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004289 break;
4290 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004291#ifdef CONFIG_TESTING_OPTIONS
4292 if (wpa_s->ignore_auth_resp) {
4293 wpa_printf(MSG_INFO,
4294 "EVENT_ASSOC - ignore_auth_resp active!");
4295 break;
4296 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004297 if (wpa_s->testing_resend_assoc) {
4298 wpa_printf(MSG_INFO,
4299 "EVENT_DEAUTH - testing_resend_assoc");
4300 break;
4301 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004302#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004303 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004304 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004305 if (data &&
4306 (data->assoc_info.authorized ||
4307 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4308 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004309 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004310 if (data) {
4311 wpa_msg(wpa_s, MSG_INFO,
4312 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4313 data->assoc_info.subnet_status);
4314 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004315 break;
4316 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004317 wpas_event_disassoc(wpa_s,
4318 data ? &data->disassoc_info : NULL);
4319 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004320 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004321#ifdef CONFIG_TESTING_OPTIONS
4322 if (wpa_s->ignore_auth_resp) {
4323 wpa_printf(MSG_INFO,
4324 "EVENT_DEAUTH - ignore_auth_resp active!");
4325 break;
4326 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004327 if (wpa_s->testing_resend_assoc) {
4328 wpa_printf(MSG_INFO,
4329 "EVENT_DEAUTH - testing_resend_assoc");
4330 break;
4331 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004332#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004333 wpas_event_deauth(wpa_s,
4334 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004335 break;
4336 case EVENT_MICHAEL_MIC_FAILURE:
4337 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4338 break;
4339#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004340 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004341 if (wpa_s->own_scan_requested ||
4342 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004343 struct os_reltime diff;
4344
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004345 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004346 os_reltime_sub(&wpa_s->scan_start_time,
4347 &wpa_s->scan_trigger_time, &diff);
4348 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4349 diff.sec, diff.usec);
4350 wpa_s->own_scan_requested = 0;
4351 wpa_s->own_scan_running = 1;
4352 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4353 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004354 wpa_msg_ctrl(wpa_s, MSG_INFO,
4355 WPA_EVENT_SCAN_STARTED "id=%u",
4356 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004357 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004358 wpa_msg_ctrl(wpa_s, MSG_INFO,
4359 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004360 }
4361 } else {
4362 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004363 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004364 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004365 }
4366 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004367 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004368 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4369 wpa_s->scan_res_handler = NULL;
4370 wpa_s->own_scan_running = 0;
4371 wpa_s->radio->external_scan_running = 0;
4372 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4373 break;
4374 }
4375
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004376 if (!(data && data->scan_info.external_scan) &&
4377 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004378 struct os_reltime now, diff;
4379 os_get_reltime(&now);
4380 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4381 wpa_s->scan_start_time.sec = 0;
4382 wpa_s->scan_start_time.usec = 0;
4383 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4384 diff.sec, diff.usec);
4385 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004386 if (wpa_supplicant_event_scan_results(wpa_s, data))
4387 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004388 if (!(data && data->scan_info.external_scan))
4389 wpa_s->own_scan_running = 0;
4390 if (data && data->scan_info.nl_scan_event)
4391 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004392 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004393 break;
4394#endif /* CONFIG_NO_SCAN_PROCESSING */
4395 case EVENT_ASSOCINFO:
4396 wpa_supplicant_event_associnfo(wpa_s, data);
4397 break;
4398 case EVENT_INTERFACE_STATUS:
4399 wpa_supplicant_event_interface_status(wpa_s, data);
4400 break;
4401 case EVENT_PMKID_CANDIDATE:
4402 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4403 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004404#ifdef CONFIG_TDLS
4405 case EVENT_TDLS:
4406 wpa_supplicant_event_tdls(wpa_s, data);
4407 break;
4408#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004409#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004410 case EVENT_WNM:
4411 wpa_supplicant_event_wnm(wpa_s, data);
4412 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004413#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004414#ifdef CONFIG_IEEE80211R
4415 case EVENT_FT_RESPONSE:
4416 wpa_supplicant_event_ft_response(wpa_s, data);
4417 break;
4418#endif /* CONFIG_IEEE80211R */
4419#ifdef CONFIG_IBSS_RSN
4420 case EVENT_IBSS_RSN_START:
4421 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4422 break;
4423#endif /* CONFIG_IBSS_RSN */
4424 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004425 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004426 break;
4427 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004428 /* It is possible to get this event from earlier connection */
4429 if (wpa_s->current_ssid &&
4430 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4431 wpa_dbg(wpa_s, MSG_DEBUG,
4432 "Ignore AUTH_TIMED_OUT in mesh configuration");
4433 break;
4434 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004435 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4436 sme_event_auth_timed_out(wpa_s, data);
4437 break;
4438 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004439 /* It is possible to get this event from earlier connection */
4440 if (wpa_s->current_ssid &&
4441 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4442 wpa_dbg(wpa_s, MSG_DEBUG,
4443 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4444 break;
4445 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004446 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4447 sme_event_assoc_timed_out(wpa_s, data);
4448 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004449 case EVENT_TX_STATUS:
4450 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4451 " type=%d stype=%d",
4452 MAC2STR(data->tx_status.dst),
4453 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004454#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004455 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004456#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004457 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4458 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004459 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004460 wpa_s, data->tx_status.dst,
4461 data->tx_status.data,
4462 data->tx_status.data_len,
4463 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004464 OFFCHANNEL_SEND_ACTION_SUCCESS :
4465 OFFCHANNEL_SEND_ACTION_NO_ACK);
4466#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004467 break;
4468 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004469#endif /* CONFIG_AP */
4470#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004471 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004472 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004473 /*
4474 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004475 * interface in GO mode, or via standalone AP interface.
4476 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4477 * except when the primary interface is used as a GO interface
4478 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004479 */
4480 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4481 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004482 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004483 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004484 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004485 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004486 data->tx_status.data,
4487 data->tx_status.data_len,
4488 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004489 OFFCHANNEL_SEND_ACTION_SUCCESS :
4490 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004491 break;
4492 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004493#endif /* CONFIG_OFFCHANNEL */
4494#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004495 switch (data->tx_status.type) {
4496 case WLAN_FC_TYPE_MGMT:
4497 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4498 data->tx_status.data_len,
4499 data->tx_status.stype,
4500 data->tx_status.ack);
4501 break;
4502 case WLAN_FC_TYPE_DATA:
4503 ap_tx_status(wpa_s, data->tx_status.dst,
4504 data->tx_status.data,
4505 data->tx_status.data_len,
4506 data->tx_status.ack);
4507 break;
4508 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004509#endif /* CONFIG_AP */
4510 break;
4511#ifdef CONFIG_AP
4512 case EVENT_EAPOL_TX_STATUS:
4513 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4514 data->eapol_tx_status.data,
4515 data->eapol_tx_status.data_len,
4516 data->eapol_tx_status.ack);
4517 break;
4518 case EVENT_DRIVER_CLIENT_POLL_OK:
4519 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004520 break;
4521 case EVENT_RX_FROM_UNKNOWN:
4522 if (wpa_s->ap_iface == NULL)
4523 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004524 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4525 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004526 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004527#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07004528
4529 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07004530 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004531 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004532 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004533
Hai Shalom81f62d82019-07-22 12:10:00 -07004534 wpa_msg(wpa_s, MSG_INFO,
4535 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4536 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
4537 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004538 data->ch_switch.freq,
4539 data->ch_switch.ht_enabled,
4540 data->ch_switch.ch_offset,
4541 channel_width_to_string(data->ch_switch.ch_width),
4542 data->ch_switch.cf1,
4543 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07004544 if (event == EVENT_CH_SWITCH_STARTED)
4545 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004546
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004547 wpa_s->assoc_freq = data->ch_switch.freq;
4548 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4549
Roshan Pius3a1667e2018-07-03 15:17:14 -07004550#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004551 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4552 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08004553 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004554 wpa_s->current_ssid->mode ==
4555 WPAS_MODE_P2P_GROUP_FORMATION) {
4556 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4557 data->ch_switch.ht_enabled,
4558 data->ch_switch.ch_offset,
4559 data->ch_switch.ch_width,
4560 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07004561 data->ch_switch.cf2,
4562 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004563 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004564#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004565
Hai Shalom74f70d42019-02-11 14:42:39 -08004566 sme_event_ch_switch(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004567 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004568 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004569 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004570#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004571#ifdef NEED_AP_MLME
4572 case EVENT_DFS_RADAR_DETECTED:
4573 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004574 wpas_ap_event_dfs_radar_detected(wpa_s,
4575 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004576 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004577 case EVENT_DFS_NOP_FINISHED:
4578 if (data)
4579 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
4580 &data->dfs_event);
4581 break;
4582#endif /* NEED_AP_MLME */
4583#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004584 case EVENT_DFS_CAC_STARTED:
4585 if (data)
4586 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
4587 break;
4588 case EVENT_DFS_CAC_FINISHED:
4589 if (data)
4590 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
4591 break;
4592 case EVENT_DFS_CAC_ABORTED:
4593 if (data)
4594 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
4595 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004596 case EVENT_RX_MGMT: {
4597 u16 fc, stype;
4598 const struct ieee80211_mgmt *mgmt;
4599
Dmitry Shmidt818ea482014-03-10 13:15:21 -07004600#ifdef CONFIG_TESTING_OPTIONS
4601 if (wpa_s->ext_mgmt_frame_handling) {
4602 struct rx_mgmt *rx = &data->rx_mgmt;
4603 size_t hex_len = 2 * rx->frame_len + 1;
4604 char *hex = os_malloc(hex_len);
4605 if (hex) {
4606 wpa_snprintf_hex(hex, hex_len,
4607 rx->frame, rx->frame_len);
4608 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4609 rx->freq, rx->datarate, rx->ssi_signal,
4610 hex);
4611 os_free(hex);
4612 }
4613 break;
4614 }
4615#endif /* CONFIG_TESTING_OPTIONS */
4616
Dmitry Shmidt04949592012-07-19 12:16:46 -07004617 mgmt = (const struct ieee80211_mgmt *)
4618 data->rx_mgmt.frame;
4619 fc = le_to_host16(mgmt->frame_control);
4620 stype = WLAN_FC_GET_STYPE(fc);
4621
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004622#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004623 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004624#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004625#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004626 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004627 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004628 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07004629 const u8 *ie;
4630 size_t ie_len;
4631
4632 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4633 ie_len = data->rx_mgmt.frame_len -
4634 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004635 wpas_p2p_probe_req_rx(
4636 wpa_s, src, mgmt->da,
4637 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004638 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004639 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004640 break;
4641 }
4642#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004643#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004644 if (wpa_s->current_ssid &&
4645 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4646 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004647 data->rx_mgmt.frame_len >= 30) {
4648 wpa_supplicant_event_ibss_auth(wpa_s, data);
4649 break;
4650 }
4651#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004652
4653 if (stype == WLAN_FC_STYPE_ACTION) {
4654 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004655 wpa_s, data->rx_mgmt.frame,
4656 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004657 data->rx_mgmt.freq,
4658 data->rx_mgmt.ssi_signal);
4659 break;
4660 }
4661
4662 if (wpa_s->ifmsh) {
4663 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004664 break;
4665 }
4666
Roshan Pius3a1667e2018-07-03 15:17:14 -07004667#ifdef CONFIG_SAE
4668 if (stype == WLAN_FC_STYPE_AUTH &&
4669 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4670 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4671 sme_external_auth_mgmt_rx(
4672 wpa_s, data->rx_mgmt.frame,
4673 data->rx_mgmt.frame_len);
4674 break;
4675 }
4676#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004677 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
4678 "management frame in non-AP mode");
4679 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004680#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004681 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004682
4683 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004684 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4685 const u8 *ie;
4686 size_t ie_len;
4687
4688 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4689 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004690
4691 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
4692 mgmt->bssid, ie, ie_len,
4693 data->rx_mgmt.ssi_signal);
4694 }
4695
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004696 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004697#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004698 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004699 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004700 case EVENT_RX_PROBE_REQ:
4701 if (data->rx_probe_req.sa == NULL ||
4702 data->rx_probe_req.ie == NULL)
4703 break;
4704#ifdef CONFIG_AP
4705 if (wpa_s->ap_iface) {
4706 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
4707 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004708 data->rx_probe_req.da,
4709 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004710 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004711 data->rx_probe_req.ie_len,
4712 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004713 break;
4714 }
4715#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004716 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004717 data->rx_probe_req.da,
4718 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004719 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004720 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004721 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004722 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004723 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004724 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004725#ifdef CONFIG_OFFCHANNEL
4726 offchannel_remain_on_channel_cb(
4727 wpa_s, data->remain_on_channel.freq,
4728 data->remain_on_channel.duration);
4729#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004730 wpas_p2p_remain_on_channel_cb(
4731 wpa_s, data->remain_on_channel.freq,
4732 data->remain_on_channel.duration);
4733 break;
4734 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004735#ifdef CONFIG_OFFCHANNEL
4736 offchannel_cancel_remain_on_channel_cb(
4737 wpa_s, data->remain_on_channel.freq);
4738#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004739 wpas_p2p_cancel_remain_on_channel_cb(
4740 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004741#ifdef CONFIG_DPP
4742 wpas_dpp_cancel_remain_on_channel_cb(
4743 wpa_s, data->remain_on_channel.freq);
4744#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004745 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004746 case EVENT_EAPOL_RX:
4747 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
4748 data->eapol_rx.data,
4749 data->eapol_rx.data_len);
4750 break;
4751 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004752 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
4753 "above=%d signal=%d noise=%d txrate=%d",
4754 data->signal_change.above_threshold,
4755 data->signal_change.current_signal,
4756 data->signal_change.current_noise,
4757 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004758 wpa_bss_update_level(wpa_s->current_bss,
4759 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004760 bgscan_notify_signal_change(
4761 wpa_s, data->signal_change.above_threshold,
4762 data->signal_change.current_signal,
4763 data->signal_change.current_noise,
4764 data->signal_change.current_txrate);
4765 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004766 case EVENT_INTERFACE_MAC_CHANGED:
4767 wpa_supplicant_update_mac_addr(wpa_s);
4768 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004769 case EVENT_INTERFACE_ENABLED:
4770 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
4771 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004772 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004773 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004774 if (wpa_s->p2p_mgmt) {
4775 wpa_supplicant_set_state(wpa_s,
4776 WPA_DISCONNECTED);
4777 break;
4778 }
4779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004780#ifdef CONFIG_AP
4781 if (!wpa_s->ap_iface) {
4782 wpa_supplicant_set_state(wpa_s,
4783 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004784 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004785 wpa_supplicant_req_scan(wpa_s, 0, 0);
4786 } else
4787 wpa_supplicant_set_state(wpa_s,
4788 WPA_COMPLETED);
4789#else /* CONFIG_AP */
4790 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
4791 wpa_supplicant_req_scan(wpa_s, 0, 0);
4792#endif /* CONFIG_AP */
4793 }
4794 break;
4795 case EVENT_INTERFACE_DISABLED:
4796 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004797#ifdef CONFIG_P2P
4798 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
4799 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
4800 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
4801 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004802 * Mark interface disabled if this happens to end up not
4803 * being removed as a separate P2P group interface.
4804 */
4805 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4806 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004807 * The interface was externally disabled. Remove
4808 * it assuming an external entity will start a
4809 * new session if needed.
4810 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004811 if (wpa_s->current_ssid &&
4812 wpa_s->current_ssid->p2p_group)
4813 wpas_p2p_interface_unavailable(wpa_s);
4814 else
4815 wpas_p2p_disconnect(wpa_s);
4816 /*
4817 * wpa_s instance may have been freed, so must not use
4818 * it here anymore.
4819 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004820 break;
4821 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004822 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
4823 p2p_in_progress(wpa_s->global->p2p) > 1) {
4824 /* This radio work will be cancelled, so clear P2P
4825 * state as well.
4826 */
4827 p2p_stop_find(wpa_s->global->p2p);
4828 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004829#endif /* CONFIG_P2P */
4830
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004831 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4832 /*
4833 * Indicate disconnection to keep ctrl_iface events
4834 * consistent.
4835 */
4836 wpa_supplicant_event_disassoc(
4837 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
4838 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004839 wpa_supplicant_mark_disassoc(wpa_s);
xshud0ee72f2018-11-08 14:37:01 -08004840 if (!wpa_s->conf->bss_no_flush_when_down)
4841 wpa_bss_flush(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08004842 radio_remove_works(wpa_s, NULL, 0);
4843
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004844 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4845 break;
4846 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004847 wpa_supplicant_update_channel_list(
4848 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004849 break;
4850 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004851 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004852 break;
4853 case EVENT_BEST_CHANNEL:
4854 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
4855 "(%d %d %d)",
4856 data->best_chan.freq_24, data->best_chan.freq_5,
4857 data->best_chan.freq_overall);
4858 wpa_s->best_24_freq = data->best_chan.freq_24;
4859 wpa_s->best_5_freq = data->best_chan.freq_5;
4860 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004861 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
4862 data->best_chan.freq_5,
4863 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004864 break;
4865 case EVENT_UNPROT_DEAUTH:
4866 wpa_supplicant_event_unprot_deauth(wpa_s,
4867 &data->unprot_deauth);
4868 break;
4869 case EVENT_UNPROT_DISASSOC:
4870 wpa_supplicant_event_unprot_disassoc(wpa_s,
4871 &data->unprot_disassoc);
4872 break;
4873 case EVENT_STATION_LOW_ACK:
4874#ifdef CONFIG_AP
4875 if (wpa_s->ap_iface && data)
4876 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
4877 data->low_ack.addr);
4878#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004879#ifdef CONFIG_TDLS
4880 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07004881 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
4882 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004883#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004884 break;
4885 case EVENT_IBSS_PEER_LOST:
4886#ifdef CONFIG_IBSS_RSN
4887 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
4888#endif /* CONFIG_IBSS_RSN */
4889 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004890 case EVENT_DRIVER_GTK_REKEY:
4891 if (os_memcmp(data->driver_gtk_rekey.bssid,
4892 wpa_s->bssid, ETH_ALEN))
4893 break;
4894 if (!wpa_s->wpa)
4895 break;
4896 wpa_sm_update_replay_ctr(wpa_s->wpa,
4897 data->driver_gtk_rekey.replay_ctr);
4898 break;
4899 case EVENT_SCHED_SCAN_STOPPED:
4900 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004901 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004902 wpa_supplicant_notify_scanning(wpa_s, 0);
4903
4904 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4905 break;
4906
4907 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004908 * If the driver stopped scanning without being requested to,
4909 * request a new scan to continue scanning for networks.
4910 */
4911 if (!wpa_s->sched_scan_stop_req &&
4912 wpa_s->wpa_state == WPA_SCANNING) {
4913 wpa_dbg(wpa_s, MSG_DEBUG,
4914 "Restart scanning after unexpected sched_scan stop event");
4915 wpa_supplicant_req_scan(wpa_s, 1, 0);
4916 break;
4917 }
4918
4919 wpa_s->sched_scan_stop_req = 0;
4920
4921 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08004922 * Start a new sched scan to continue searching for more SSIDs
4923 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004924 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07004925 if (wpa_s->sched_scan_timed_out) {
4926 wpa_supplicant_req_sched_scan(wpa_s);
4927 } else if (wpa_s->pno_sched_pending) {
4928 wpa_s->pno_sched_pending = 0;
4929 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004930 } else if (resched) {
4931 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08004932 }
4933
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004934 break;
4935 case EVENT_WPS_BUTTON_PUSHED:
4936#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07004937 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004938#endif /* CONFIG_WPS */
4939 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004940 case EVENT_AVOID_FREQUENCIES:
4941 wpa_supplicant_notify_avoid_freq(wpa_s, data);
4942 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004943 case EVENT_CONNECT_FAILED_REASON:
4944#ifdef CONFIG_AP
4945 if (!wpa_s->ap_iface || !data)
4946 break;
4947 hostapd_event_connect_failed_reason(
4948 wpa_s->ap_iface->bss[0],
4949 data->connect_failed_reason.addr,
4950 data->connect_failed_reason.code);
4951#endif /* CONFIG_AP */
4952 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004953 case EVENT_NEW_PEER_CANDIDATE:
4954#ifdef CONFIG_MESH
4955 if (!wpa_s->ifmsh || !data)
4956 break;
4957 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4958 data->mesh_peer.ies,
4959 data->mesh_peer.ie_len);
4960#endif /* CONFIG_MESH */
4961 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004962 case EVENT_SURVEY:
4963#ifdef CONFIG_AP
4964 if (!wpa_s->ap_iface)
4965 break;
4966 hostapd_event_get_survey(wpa_s->ap_iface,
4967 &data->survey_results);
4968#endif /* CONFIG_AP */
4969 break;
4970 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08004971#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004972#ifdef CONFIG_ACS
4973 if (!wpa_s->ap_iface)
4974 break;
4975 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4976 &data->acs_selected_channels);
4977#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08004978#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004979 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004980 case EVENT_P2P_LO_STOP:
4981#ifdef CONFIG_P2P
4982 wpa_s->p2p_lo_started = 0;
4983 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
4984 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
4985 data->p2p_lo_stop.reason_code);
4986#endif /* CONFIG_P2P */
4987 break;
Paul Stewart092955c2017-02-06 09:13:09 -08004988 case EVENT_BEACON_LOSS:
4989 if (!wpa_s->current_bss || !wpa_s->current_ssid)
4990 break;
4991 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
4992 bgscan_notify_beacon_loss(wpa_s);
4993 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004994 case EVENT_EXTERNAL_AUTH:
4995#ifdef CONFIG_SAE
4996 if (!wpa_s->current_ssid) {
4997 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
4998 break;
4999 }
5000 sme_external_auth_trigger(wpa_s, data);
5001#endif /* CONFIG_SAE */
5002 break;
5003 case EVENT_PORT_AUTHORIZED:
5004 wpa_supplicant_event_port_authorized(wpa_s);
5005 break;
5006 case EVENT_STATION_OPMODE_CHANGED:
5007#ifdef CONFIG_AP
5008 if (!wpa_s->ap_iface || !data)
5009 break;
5010
5011 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5012 data->sta_opmode.addr,
5013 data->sta_opmode.smps_mode,
5014 data->sta_opmode.chan_width,
5015 data->sta_opmode.rx_nss);
5016#endif /* CONFIG_AP */
5017 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005018 default:
5019 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5020 break;
5021 }
5022}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005023
5024
5025void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5026 union wpa_event_data *data)
5027{
5028 struct wpa_supplicant *wpa_s;
5029
5030 if (event != EVENT_INTERFACE_STATUS)
5031 return;
5032
5033 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5034 if (wpa_s && wpa_s->driver->get_ifindex) {
5035 unsigned int ifindex;
5036
5037 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5038 if (ifindex != data->interface_status.ifindex) {
5039 wpa_dbg(wpa_s, MSG_DEBUG,
5040 "interface status ifindex %d mismatch (%d)",
5041 ifindex, data->interface_status.ifindex);
5042 return;
5043 }
5044 }
5045#ifdef CONFIG_MATCH_IFACE
5046 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5047 struct wpa_interface *wpa_i;
5048
5049 wpa_i = wpa_supplicant_match_iface(
5050 ctx, data->interface_status.ifname);
5051 if (!wpa_i)
5052 return;
5053 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5054 os_free(wpa_i);
5055 if (wpa_s)
5056 wpa_s->matched = 1;
5057 }
5058#endif /* CONFIG_MATCH_IFACE */
5059
5060 if (wpa_s)
5061 wpa_supplicant_event(wpa_s, event, data);
5062}