blob: 15ef0f7cdbc14134c0eccf5e8be9f52a87959b28 [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");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800860#ifdef CONFIG_TESTING_OPTIONS
861 if (wpa_s->ignore_sae_h2e_only) {
862 wpa_dbg(wpa_s, MSG_DEBUG,
863 "TESTING: Ignore SAE H2E requirement mismatch");
864 continue;
865 }
866#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -0700867 return 0;
868 }
869 continue;
870 }
871#endif /* CONFIG_SAE */
872
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800873 if (!flagged)
874 continue;
875
876 /* check for legacy basic rates */
877 for (k = 0; k < mode->num_rates; k++) {
878 if (mode->rates[k] == r)
879 break;
880 }
881 if (k == mode->num_rates) {
882 /*
883 * IEEE Std 802.11-2007 7.3.2.2 demands that in
884 * order to join a BSS all required rates
885 * have to be supported by the hardware.
886 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800887 if (debug_print)
888 wpa_dbg(wpa_s, MSG_DEBUG,
889 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
890 r / 10, r % 10,
891 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800892 return 0;
893 }
894 }
895 }
896
897 return 1;
898}
899
900
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800901/*
902 * Test whether BSS is in an ESS.
903 * This is done differently in DMG (60 GHz) and non-DMG bands
904 */
905static int bss_is_ess(struct wpa_bss *bss)
906{
907 if (bss_is_dmg(bss)) {
908 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
909 IEEE80211_CAP_DMG_AP;
910 }
911
912 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
913 IEEE80211_CAP_ESS);
914}
915
916
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800917static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
918{
919 size_t i;
920
921 for (i = 0; i < ETH_ALEN; i++) {
922 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
923 return 0;
924 }
925 return 1;
926}
927
928
929static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
930{
931 size_t i;
932
933 for (i = 0; i < num; i++) {
934 const u8 *a = list + i * ETH_ALEN * 2;
935 const u8 *m = a + ETH_ALEN;
936
937 if (match_mac_mask(a, addr, m))
938 return 1;
939 }
940 return 0;
941}
942
943
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700944static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
945 const u8 **ret_ssid, size_t *ret_ssid_len)
946{
947#ifdef CONFIG_OWE
948 const u8 *owe, *pos, *end, *bssid;
949 u8 ssid_len;
950 struct wpa_bss *open_bss;
951
952 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
953 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
954 return;
955
956 pos = owe + 6;
957 end = owe + 2 + owe[1];
958
959 if (end - pos < ETH_ALEN + 1)
960 return;
961 bssid = pos;
962 pos += ETH_ALEN;
963 ssid_len = *pos++;
964 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
965 return;
966
967 /* Match the profile SSID against the OWE transition mode SSID on the
968 * open network. */
969 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
970 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
971 *ret_ssid = pos;
972 *ret_ssid_len = ssid_len;
973
974 if (bss->ssid_len > 0)
975 return;
976
977 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
978 if (!open_bss)
979 return;
980 if (ssid_len != open_bss->ssid_len ||
981 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
982 wpa_dbg(wpa_s, MSG_DEBUG,
983 "OWE: transition mode SSID mismatch: %s",
984 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
985 return;
986 }
987
988 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
989 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
990 wpa_dbg(wpa_s, MSG_DEBUG,
991 "OWE: transition mode open BSS unexpected info");
992 return;
993 }
994
995 pos = owe + 6;
996 end = owe + 2 + owe[1];
997
998 if (end - pos < ETH_ALEN + 1)
999 return;
1000 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
1001 wpa_dbg(wpa_s, MSG_DEBUG,
1002 "OWE: transition mode BSSID mismatch: " MACSTR,
1003 MAC2STR(pos));
1004 return;
1005 }
1006 pos += ETH_ALEN;
1007 ssid_len = *pos++;
1008 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1009 return;
1010 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1011 wpa_ssid_txt(pos, ssid_len));
1012 os_memcpy(bss->ssid, pos, ssid_len);
1013 bss->ssid_len = ssid_len;
1014#endif /* CONFIG_OWE */
1015}
1016
1017
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001018struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1019 int i, struct wpa_bss *bss,
1020 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001021 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001022{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001023 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001024 int wpa;
1025 struct wpa_blacklist *e;
1026 const u8 *ie;
1027 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001028 int osen, rsn_osen = 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001029#ifdef CONFIG_MBO
1030 const u8 *assoc_disallow;
1031#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001032 const u8 *match_ssid;
1033 size_t match_ssid_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001034 struct wpa_ie_data data;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001035
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001036 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037 wpa_ie_len = ie ? ie[1] : 0;
1038
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001039 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040 rsn_ie_len = ie ? ie[1] : 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001041 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1042 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1043 rsn_osen = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001044
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001045 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1046 osen = ie != NULL;
1047
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001048 if (debug_print) {
1049 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1050 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1051 i, MAC2STR(bss->bssid),
1052 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1053 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1054 bss->freq,
1055 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1056 " wps" : "",
1057 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1058 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1059 ? " p2p" : "",
1060 osen ? " osen=1" : "");
1061 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001062
1063 e = wpa_blacklist_get(wpa_s, bss->bssid);
1064 if (e) {
1065 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001066 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001067 /*
1068 * When only a single network is enabled, we can
1069 * trigger blacklisting on the first failure. This
1070 * should not be done with multiple enabled networks to
1071 * avoid getting forced to move into a worse ESS on
1072 * single error if there are no other BSSes of the
1073 * current ESS.
1074 */
1075 limit = 0;
1076 }
1077 if (e->count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001078 if (debug_print) {
1079 wpa_dbg(wpa_s, MSG_DEBUG,
1080 " skip - blacklisted (count=%d limit=%d)",
1081 e->count, limit);
1082 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 return NULL;
1084 }
1085 }
1086
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001087 match_ssid = bss->ssid;
1088 match_ssid_len = bss->ssid_len;
1089 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1090
1091 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001092 if (debug_print)
1093 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094 return NULL;
1095 }
1096
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001097 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001098 if (debug_print)
1099 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001100 return NULL;
1101 }
1102
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001103 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001104 if (debug_print)
1105 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001106 return NULL;
1107 }
1108
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
1110
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001111 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001112 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001113 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001114
Dmitry Shmidt04949592012-07-19 12:16:46 -07001115 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001116 if (debug_print)
1117 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118 continue;
1119 }
1120
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001121 res = wpas_temp_disabled(wpa_s, ssid);
1122 if (res > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001123 if (debug_print)
1124 wpa_dbg(wpa_s, MSG_DEBUG,
1125 " skip - disabled temporarily for %d second(s)",
1126 res);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001127 continue;
1128 }
1129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130#ifdef CONFIG_WPS
1131 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001132 if (debug_print)
1133 wpa_dbg(wpa_s, MSG_DEBUG,
1134 " skip - blacklisted (WPS)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135 continue;
1136 }
1137
1138 if (wpa && ssid->ssid_len == 0 &&
1139 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1140 check_ssid = 0;
1141
1142 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1143 /* Only allow wildcard SSID match if an AP
1144 * advertises active WPS operation that matches
1145 * with our mode. */
1146 check_ssid = 1;
1147 if (ssid->ssid_len == 0 &&
1148 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1149 check_ssid = 0;
1150 }
1151#endif /* CONFIG_WPS */
1152
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001153 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1154 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1155 check_ssid = 0;
1156
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157 if (check_ssid &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001158 (match_ssid_len != ssid->ssid_len ||
1159 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001160 if (debug_print)
1161 wpa_dbg(wpa_s, MSG_DEBUG,
1162 " skip - SSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001163 continue;
1164 }
1165
1166 if (ssid->bssid_set &&
1167 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001168 if (debug_print)
1169 wpa_dbg(wpa_s, MSG_DEBUG,
1170 " skip - BSSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001171 continue;
1172 }
1173
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001174 /* check blacklist */
1175 if (ssid->num_bssid_blacklist &&
1176 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1177 ssid->num_bssid_blacklist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001178 if (debug_print)
1179 wpa_dbg(wpa_s, MSG_DEBUG,
1180 " skip - BSSID blacklisted");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001181 continue;
1182 }
1183
1184 /* if there is a whitelist, only accept those APs */
1185 if (ssid->num_bssid_whitelist &&
1186 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1187 ssid->num_bssid_whitelist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001188 if (debug_print)
1189 wpa_dbg(wpa_s, MSG_DEBUG,
1190 " skip - BSSID not in whitelist");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001191 continue;
1192 }
1193
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001194 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss,
1195 debug_print))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001196 continue;
1197
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001198 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1200 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001201 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001203 if (debug_print)
1204 wpa_dbg(wpa_s, MSG_DEBUG,
1205 " skip - non-WPA network not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001206 continue;
1207 }
1208
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001209 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1210 has_wep_key(ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001211 if (debug_print)
1212 wpa_dbg(wpa_s, MSG_DEBUG,
1213 " skip - ignore WPA/WPA2 AP for WEP network block");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001214 continue;
1215 }
1216
Roshan Pius3a1667e2018-07-03 15:17:14 -07001217 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen &&
1218 !rsn_osen) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001219 if (debug_print)
1220 wpa_dbg(wpa_s, MSG_DEBUG,
1221 " skip - non-OSEN network not allowed");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001222 continue;
1223 }
1224
Jouni Malinen75ecf522011-06-27 15:19:46 -07001225 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001226 if (debug_print)
1227 wpa_dbg(wpa_s, MSG_DEBUG,
1228 " skip - privacy mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229 continue;
1230 }
1231
Hai Shalom81f62d82019-07-22 12:10:00 -07001232 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001233 !bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001234 if (debug_print)
1235 wpa_dbg(wpa_s, MSG_DEBUG,
1236 " skip - not ESS, PBSS, or MBSS");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001237 continue;
1238 }
1239
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001240 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001241 if (debug_print)
1242 wpa_dbg(wpa_s, MSG_DEBUG,
1243 " skip - PBSS mismatch (ssid %d bss %d)",
1244 ssid->pbss, bss_is_pbss(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 continue;
1246 }
1247
1248 if (!freq_allowed(ssid->freq_list, bss->freq)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001249 if (debug_print)
1250 wpa_dbg(wpa_s, MSG_DEBUG,
1251 " skip - frequency not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252 continue;
1253 }
1254
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001255#ifdef CONFIG_MESH
Hai Shalom81f62d82019-07-22 12:10:00 -07001256 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001257 ssid->frequency != bss->freq) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001258 if (debug_print)
1259 wpa_dbg(wpa_s, MSG_DEBUG,
1260 " skip - frequency not allowed (mesh)");
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001261 continue;
1262 }
1263#endif /* CONFIG_MESH */
1264
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001265 if (!rate_match(wpa_s, bss, debug_print)) {
1266 if (debug_print)
1267 wpa_dbg(wpa_s, MSG_DEBUG,
1268 " skip - rate sets do not match");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001269 continue;
1270 }
1271
Hai Shalomc3565922019-10-28 11:58:20 -07001272#ifdef CONFIG_SAE
1273 if (wpa_s->conf->sae_pwe == 1 &&
1274 wpa_key_mgmt_sae(ssid->key_mgmt) &&
1275 (!(ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX)) ||
1276 ie[1] < 1 ||
1277 !(ie[2] & BIT(WLAN_RSNX_CAPAB_SAE_H2E)))) {
1278 if (debug_print)
1279 wpa_dbg(wpa_s, MSG_DEBUG,
1280 " skip - SAE H2E required, but not supported by the AP");
1281 continue;
1282 }
1283#endif /* CONFIG_SAE */
1284
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001285#ifndef CONFIG_IBSS_RSN
1286 if (ssid->mode == WPAS_MODE_IBSS &&
1287 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1288 WPA_KEY_MGMT_WPA_NONE))) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001289 if (debug_print)
1290 wpa_dbg(wpa_s, MSG_DEBUG,
1291 " skip - IBSS RSN not supported in the build");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001292 continue;
1293 }
1294#endif /* !CONFIG_IBSS_RSN */
1295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001296#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001297 if (ssid->p2p_group &&
1298 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1299 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001300 if (debug_print)
1301 wpa_dbg(wpa_s, MSG_DEBUG,
1302 " skip - no P2P IE seen");
Dmitry Shmidt96571392013-10-14 12:54:46 -07001303 continue;
1304 }
1305
Dmitry Shmidt54605472013-11-08 11:10:19 -08001306 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1307 struct wpabuf *p2p_ie;
1308 u8 dev_addr[ETH_ALEN];
1309
1310 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1311 if (ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001312 if (debug_print)
1313 wpa_dbg(wpa_s, MSG_DEBUG,
1314 " skip - no P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001315 continue;
1316 }
1317 p2p_ie = wpa_bss_get_vendor_ie_multi(
1318 bss, P2P_IE_VENDOR_TYPE);
1319 if (p2p_ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001320 if (debug_print)
1321 wpa_dbg(wpa_s, MSG_DEBUG,
1322 " skip - could not fetch P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001323 continue;
1324 }
1325
1326 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1327 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1328 ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001329 if (debug_print)
1330 wpa_dbg(wpa_s, MSG_DEBUG,
1331 " skip - no matching GO P2P Device Address in P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001332 wpabuf_free(p2p_ie);
1333 continue;
1334 }
1335 wpabuf_free(p2p_ie);
1336 }
1337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001338 /*
1339 * TODO: skip the AP if its P2P IE has Group Formation
1340 * bit set in the P2P Group Capability Bitmap and we
1341 * are not in Group Formation with that device.
1342 */
1343#endif /* CONFIG_P2P */
1344
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001345 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1346 {
1347 struct os_reltime diff;
1348
1349 os_reltime_sub(&wpa_s->scan_min_time,
1350 &bss->last_update, &diff);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001351 if (debug_print)
1352 wpa_dbg(wpa_s, MSG_DEBUG,
1353 " skip - scan result not recent enough (%u.%06u seconds too old)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001354 (unsigned int) diff.sec,
1355 (unsigned int) diff.usec);
1356 continue;
1357 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001358#ifdef CONFIG_MBO
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001359#ifdef CONFIG_TESTING_OPTIONS
1360 if (wpa_s->ignore_assoc_disallow)
1361 goto skip_assoc_disallow;
1362#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001363 assoc_disallow = wpas_mbo_get_bss_attr(
1364 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1365 if (assoc_disallow && assoc_disallow[1] >= 1) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001366 if (debug_print)
1367 wpa_dbg(wpa_s, MSG_DEBUG,
1368 " skip - MBO association disallowed (reason %u)",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001369 assoc_disallow[2]);
1370 continue;
1371 }
1372
Hai Shalom74f70d42019-02-11 14:42:39 -08001373 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001374 if (debug_print)
1375 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom74f70d42019-02-11 14:42:39 -08001376 " skip - AP temporarily disallowed");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001377 continue;
1378 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001379#ifdef CONFIG_TESTING_OPTIONS
1380 skip_assoc_disallow:
1381#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001382#endif /* CONFIG_MBO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001383
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001384#ifdef CONFIG_DPP
1385 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1386 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1387 (!ssid->dpp_connector ||
1388 !ssid->dpp_netaccesskey ||
1389 !ssid->dpp_csign)) {
1390 if (debug_print)
1391 wpa_dbg(wpa_s, MSG_DEBUG,
1392 " skip - no PMKSA entry for DPP");
1393 continue;
1394 }
1395#endif /* CONFIG_DPP */
1396
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001397 /* Matching configuration found */
1398 return ssid;
1399 }
1400
1401 /* No matching configuration found */
1402 return NULL;
1403}
1404
1405
1406static struct wpa_bss *
1407wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001408 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001409 struct wpa_ssid **selected_ssid,
1410 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001411{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001412 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001413
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001414 if (wpa_s->current_ssid) {
1415 struct wpa_ssid *ssid;
1416
1417 wpa_dbg(wpa_s, MSG_DEBUG,
1418 "Scan results matching the currently selected network");
1419 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1420 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1421
1422 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1423 only_first_ssid, 0);
1424 if (ssid != wpa_s->current_ssid)
1425 continue;
1426 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1427 " freq=%d level=%d snr=%d est_throughput=%u",
1428 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1429 bss->snr, bss->est_throughput);
1430 }
1431 }
1432
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001433 if (only_first_ssid)
1434 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1435 group->id);
1436 else
1437 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1438 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001439
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001440 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1441 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001442
1443 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001444 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001445 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001446 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001447 if (!*selected_ssid)
1448 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001449 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1450 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001451 MAC2STR(bss->bssid),
1452 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1453 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001454 }
1455
1456 return NULL;
1457}
1458
1459
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001460struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1461 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462{
1463 struct wpa_bss *selected = NULL;
1464 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001465 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001466 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001467
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001468 if (wpa_s->last_scan_res == NULL ||
1469 wpa_s->last_scan_res_used == 0)
1470 return NULL; /* no scan results from last update */
1471
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001472 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001473 /* check that next_ssid is still valid */
1474 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1475 if (ssid == wpa_s->next_ssid)
1476 break;
1477 }
1478 next_ssid = ssid;
1479 wpa_s->next_ssid = NULL;
1480 }
1481
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001483 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1484 if (next_ssid && next_ssid->priority ==
1485 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001486 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001487 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001488 if (selected)
1489 break;
1490 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001491 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001492 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001493 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001494 if (selected)
1495 break;
1496 }
1497
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001498 if (selected == NULL && wpa_s->blacklist &&
1499 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001500 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1501 "blacklist and try again");
1502 wpa_blacklist_clear(wpa_s);
1503 wpa_s->blacklist_cleared++;
1504 } else if (selected == NULL)
1505 break;
1506 }
1507
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001508 ssid = *selected_ssid;
1509 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1510 !ssid->passphrase && !ssid->ext_psk) {
1511 const char *field_name, *txt = NULL;
1512
1513 wpa_dbg(wpa_s, MSG_DEBUG,
1514 "PSK/passphrase not yet available for the selected network");
1515
1516 wpas_notify_network_request(wpa_s, ssid,
1517 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1518
1519 field_name = wpa_supplicant_ctrl_req_to_string(
1520 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1521 if (field_name == NULL)
1522 return NULL;
1523
1524 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1525
1526 selected = NULL;
1527 }
1528
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001529 return selected;
1530}
1531
1532
1533static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1534 int timeout_sec, int timeout_usec)
1535{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001536 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537 /*
1538 * No networks are enabled; short-circuit request so
1539 * we don't wait timeout seconds before transitioning
1540 * to INACTIVE state.
1541 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001542 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1543 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001544 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1545 return;
1546 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001547
1548 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001549 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1550}
1551
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001552
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001553int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001554 struct wpa_bss *selected,
1555 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001556{
1557 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1558 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1559 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001560 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001561#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001562 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1563 wpa_s->p2p_in_provisioning) {
1564 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1565 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001566 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001567 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001568#endif /* CONFIG_P2P */
1569
1570#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001571 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001572 wpas_wps_cancel(wpa_s);
1573#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001574 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575 }
1576
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001577 wpa_msg(wpa_s, MSG_DEBUG,
1578 "Considering connect request: reassociate: %d selected: "
1579 MACSTR " bssid: " MACSTR " pending: " MACSTR
1580 " wpa_state: %s ssid=%p current_ssid=%p",
1581 wpa_s->reassociate, MAC2STR(selected->bssid),
1582 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1583 wpa_supplicant_state_txt(wpa_s->wpa_state),
1584 ssid, wpa_s->current_ssid);
1585
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001586 /*
1587 * Do not trigger new association unless the BSSID has changed or if
1588 * reassociation is requested. If we are in process of associating with
1589 * the selected BSSID, do not trigger new attempt.
1590 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001591 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001592 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1593 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1594 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001595 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1596 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1597 0) ||
1598 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1599 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001600 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1601 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001602 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001603 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001604 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1605 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001606 wpa_supplicant_associate(wpa_s, selected, ssid);
1607 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001608 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1609 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001610 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001611
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001612 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001613}
1614
1615
1616static struct wpa_ssid *
1617wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1618{
1619 int prio;
1620 struct wpa_ssid *ssid;
1621
1622 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1623 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1624 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001625 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001626 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001627#ifndef CONFIG_IBSS_RSN
1628 if (ssid->mode == WPAS_MODE_IBSS &&
1629 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1630 WPA_KEY_MGMT_WPA_NONE))) {
1631 wpa_msg(wpa_s, MSG_INFO,
1632 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1633 wpa_ssid_txt(ssid->ssid,
1634 ssid->ssid_len));
1635 continue;
1636 }
1637#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001638 if (ssid->mode == WPAS_MODE_IBSS ||
1639 ssid->mode == WPAS_MODE_AP ||
1640 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001641 return ssid;
1642 }
1643 }
1644 return NULL;
1645}
1646
1647
1648/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1649 * on BSS added and BSS changed events */
1650static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001651 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001652{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001653 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001654
1655 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1656 return;
1657
Jouni Malinen87fd2792011-05-16 18:35:42 +03001658 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001659 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660
Jouni Malinen87fd2792011-05-16 18:35:42 +03001661 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001662 if (ssid == NULL)
1663 continue;
1664
Jouni Malinen87fd2792011-05-16 18:35:42 +03001665 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001666 if (rsn == NULL)
1667 continue;
1668
Jouni Malinen87fd2792011-05-16 18:35:42 +03001669 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001670 }
1671
1672}
1673
1674
1675static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1676 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001677 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001678{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001679 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001680#ifndef CONFIG_NO_ROAMING
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001681 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001682 int to_5ghz;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001683 int cur_est, sel_est;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001684#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001685
1686 if (wpa_s->reassociate)
1687 return 1; /* explicit request to reassociate */
1688 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1689 return 1; /* we are not associated; continue */
1690 if (wpa_s->current_ssid == NULL)
1691 return 1; /* unknown current SSID */
1692 if (wpa_s->current_ssid != ssid)
1693 return 1; /* different network block */
1694
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001695 if (wpas_driver_bss_selection(wpa_s))
1696 return 0; /* Driver-based roaming */
1697
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001698 if (wpa_s->current_ssid->ssid)
1699 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1700 wpa_s->current_ssid->ssid,
1701 wpa_s->current_ssid->ssid_len);
1702 if (!current_bss)
1703 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001704
1705 if (!current_bss)
1706 return 1; /* current BSS not seen in scan results */
1707
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001708 if (current_bss == selected)
1709 return 0;
1710
1711 if (selected->last_update_idx > current_bss->last_update_idx)
1712 return 1; /* current BSS not seen in the last scan */
1713
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001714#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001716 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001717 " freq=%d level=%d snr=%d est_throughput=%u",
1718 MAC2STR(current_bss->bssid),
1719 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001720 current_bss->snr, current_bss->est_throughput);
1721 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001722 " freq=%d level=%d snr=%d est_throughput=%u",
1723 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001724 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001725
1726 if (wpa_s->current_ssid->bssid_set &&
1727 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1728 0) {
1729 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1730 "has preferred BSSID");
1731 return 1;
1732 }
1733
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001734 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1735 wpa_dbg(wpa_s, MSG_DEBUG,
1736 "Allow reassociation - selected BSS has better estimated throughput");
1737 return 1;
1738 }
1739
Dmitry Shmidte4663042016-04-04 10:07:49 -07001740 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1741
1742 if (current_bss->level < 0 &&
1743 current_bss->level > selected->level + to_5ghz * 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001744 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1745 "signal level");
1746 return 0;
1747 }
1748
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001749 if (current_bss->est_throughput > selected->est_throughput + 5000) {
1750 wpa_dbg(wpa_s, MSG_DEBUG,
1751 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001752 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001753 }
1754
1755 cur_est = current_bss->est_throughput;
1756 sel_est = selected->est_throughput;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 min_diff = 2;
1758 if (current_bss->level < 0) {
1759 if (current_bss->level < -85)
1760 min_diff = 1;
1761 else if (current_bss->level < -80)
1762 min_diff = 2;
1763 else if (current_bss->level < -75)
1764 min_diff = 3;
1765 else if (current_bss->level < -70)
1766 min_diff = 4;
1767 else
1768 min_diff = 5;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001769 if (cur_est > sel_est * 1.5)
1770 min_diff += 10;
1771 else if (cur_est > sel_est * 1.2)
1772 min_diff += 5;
1773 else if (cur_est > sel_est * 1.1)
1774 min_diff += 2;
1775 else if (cur_est > sel_est)
1776 min_diff++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001778 if (to_5ghz) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001779 int reduce = 2;
1780
Dmitry Shmidte4663042016-04-04 10:07:49 -07001781 /* Make it easier to move to 5 GHz band */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001782 if (sel_est > cur_est * 1.5)
1783 reduce = 5;
1784 else if (sel_est > cur_est * 1.2)
1785 reduce = 4;
1786 else if (sel_est > cur_est * 1.1)
1787 reduce = 3;
1788
1789 if (min_diff > reduce)
1790 min_diff -= reduce;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001791 else
1792 min_diff = 0;
1793 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001794 diff = abs(current_bss->level - selected->level);
1795 if (diff < min_diff) {
1796 wpa_dbg(wpa_s, MSG_DEBUG,
1797 "Skip roam - too small difference in signal level (%d < %d)",
1798 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001799 return 0;
1800 }
1801
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001802 wpa_dbg(wpa_s, MSG_DEBUG,
1803 "Allow reassociation due to difference in signal level (%d >= %d)",
1804 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001806#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001807 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001808#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001809}
1810
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001811
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001812/*
1813 * Return a negative value if no scan results could be fetched or if scan
1814 * results should not be shared with other virtual interfaces.
1815 * Return 0 if scan results were fetched and may be shared with other
1816 * interfaces.
1817 * Return 1 if scan results may be shared with other virtual interfaces but may
1818 * not trigger any operations.
1819 * Return 2 if the interface was removed and cannot be used.
1820 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001821static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001822 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001823 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001825 struct wpa_scan_results *scan_res = NULL;
1826 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001828#ifndef CONFIG_NO_RANDOM_POOL
1829 size_t i, num;
1830#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001831
1832#ifdef CONFIG_AP
1833 if (wpa_s->ap_iface)
1834 ap = 1;
1835#endif /* CONFIG_AP */
1836
1837 wpa_supplicant_notify_scanning(wpa_s, 0);
1838
1839 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1840 data ? &data->scan_info :
1841 NULL, 1);
1842 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001843 if (wpa_s->conf->ap_scan == 2 || ap ||
1844 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001846 if (!own_request)
1847 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001848 if (data && data->scan_info.external_scan)
1849 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1851 "scanning again");
1852 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001853 ret = -1;
1854 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001855 }
1856
1857#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858 num = scan_res->num;
1859 if (num > 10)
1860 num = 10;
1861 for (i = 0; i < num; i++) {
1862 u8 buf[5];
1863 struct wpa_scan_res *res = scan_res->res[i];
1864 buf[0] = res->bssid[5];
1865 buf[1] = res->qual & 0xff;
1866 buf[2] = res->noise & 0xff;
1867 buf[3] = res->level & 0xff;
1868 buf[4] = res->tsf & 0xff;
1869 random_add_randomness(buf, sizeof(buf));
1870 }
1871#endif /* CONFIG_NO_RANDOM_POOL */
1872
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001873 if (update_only) {
1874 ret = 1;
1875 goto scan_work_done;
1876 }
1877
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001878 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001879 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001880 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1881 struct wpa_scan_results *scan_res);
1882
1883 scan_res_handler = wpa_s->scan_res_handler;
1884 wpa_s->scan_res_handler = NULL;
1885 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001886 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001887 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001888 }
1889
1890 if (ap) {
1891 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1892#ifdef CONFIG_AP
1893 if (wpa_s->ap_iface->scan_cb)
1894 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1895#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001896 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001897 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001898
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001899 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001900 wpa_s->own_scan_running,
1901 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001902 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001903 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1904 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001905 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1906 wpa_s->manual_scan_id);
1907 wpa_s->manual_scan_use_id = 0;
1908 } else {
1909 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1910 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001911 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001912
1913 wpas_notify_scan_done(wpa_s, 1);
1914
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001915 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001916 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 -07001917 wpa_scan_results_free(scan_res);
1918 return 0;
1919 }
1920
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001921 if (wnm_scan_process(wpa_s, 1) > 0)
1922 goto scan_work_done;
1923
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001924 if (sme_proc_obss_scan(wpa_s, scan_res) > 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001925 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001926
Hai Shalom021b0b52019-04-10 11:17:58 -07001927 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08001928 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
1929 goto scan_work_done;
1930
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001931 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1932 goto scan_work_done;
1933
1934 if (autoscan_notify_scan(wpa_s, scan_res))
1935 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001936
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001937 if (wpa_s->disconnected) {
1938 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001939 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001940 }
1941
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001942 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001943 bgscan_notify_scan(wpa_s, scan_res) == 1)
1944 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001945
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001946 wpas_wps_update_ap_info(wpa_s, scan_res);
1947
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001948 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1949 wpa_s->wpa_state < WPA_COMPLETED)
1950 goto scan_work_done;
1951
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001952 wpa_scan_results_free(scan_res);
1953
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001954 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001955 struct wpa_radio_work *work = wpa_s->scan_work;
1956 wpa_s->scan_work = NULL;
1957 radio_work_done(work);
1958 }
1959
Hai Shalomc3565922019-10-28 11:58:20 -07001960 os_free(wpa_s->last_scan_freqs);
1961 wpa_s->last_scan_freqs = NULL;
1962 wpa_s->num_last_scan_freqs = 0;
1963 if (own_request && data &&
1964 data->scan_info.freqs && data->scan_info.num_freqs) {
1965 wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
1966 data->scan_info.num_freqs);
1967 if (wpa_s->last_scan_freqs) {
1968 os_memcpy(wpa_s->last_scan_freqs,
1969 data->scan_info.freqs,
1970 sizeof(int) * data->scan_info.num_freqs);
1971 wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
1972 }
1973 }
1974
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001975 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001976
1977scan_work_done:
1978 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001979 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001980 struct wpa_radio_work *work = wpa_s->scan_work;
1981 wpa_s->scan_work = NULL;
1982 radio_work_done(work);
1983 }
1984 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001985}
1986
1987
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001988static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001989 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001990{
1991 struct wpa_bss *selected;
1992 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001993 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1994
1995 if (time_to_reenable > 0) {
1996 wpa_dbg(wpa_s, MSG_DEBUG,
1997 "Postpone network selection by %d seconds since all networks are disabled",
1998 time_to_reenable);
1999 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2000 eloop_register_timeout(time_to_reenable, 0,
2001 wpas_network_reenabled, wpa_s, NULL);
2002 return 0;
2003 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002004
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002005 if (wpa_s->p2p_mgmt)
2006 return 0; /* no normal connection on p2p_mgmt interface */
2007
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002008 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002009 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002010
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002011#ifdef CONFIG_MESH
2012 if (wpa_s->ifmsh) {
2013 wpa_msg(wpa_s, MSG_INFO,
2014 "Avoiding join because we already joined a mesh group");
2015 return 0;
2016 }
2017#endif /* CONFIG_MESH */
2018
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002019 if (selected) {
2020 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07002021 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002022 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002023 if (new_scan)
2024 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002026 }
2027
Hai Shalomc3565922019-10-28 11:58:20 -07002028 wpa_s->suitable_network++;
2029
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002030 if (ssid != wpa_s->current_ssid &&
2031 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2032 wpa_s->own_disconnect_req = 1;
2033 wpa_supplicant_deauthenticate(
2034 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2035 }
2036
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002037 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002038 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002039 return -1;
2040 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002041 if (new_scan)
2042 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002043 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002044 * Do not allow other virtual radios to trigger operations based
2045 * on these scan results since we do not want them to start
2046 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002047 */
2048 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002049 } else {
Hai Shalomc3565922019-10-28 11:58:20 -07002050 wpa_s->no_suitable_network++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002051 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2052 ssid = wpa_supplicant_pick_new_network(wpa_s);
2053 if (ssid) {
2054 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2055 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002056 if (new_scan)
2057 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002058 } else if (own_request) {
2059 /*
2060 * No SSID found. If SCAN results are as a result of
2061 * own scan request and not due to a scan request on
2062 * another shared interface, try another scan.
2063 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002064 int timeout_sec = wpa_s->scan_interval;
2065 int timeout_usec = 0;
2066#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002067 int res;
2068
2069 res = wpas_p2p_scan_no_go_seen(wpa_s);
2070 if (res == 2)
2071 return 2;
2072 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002073 return 0;
2074
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002075 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002076 wpa_s->show_group_started ||
2077 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002078 /*
2079 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002080 * state and during P2P join-a-group operation
2081 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082 */
2083 timeout_sec = 0;
2084 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002085 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2086 timeout_usec);
2087 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088 }
2089#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002090#ifdef CONFIG_INTERWORKING
2091 if (wpa_s->conf->auto_interworking &&
2092 wpa_s->conf->interworking &&
2093 wpa_s->conf->cred) {
2094 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2095 "start ANQP fetch since no matching "
2096 "networks found");
2097 wpa_s->network_select = 1;
2098 wpa_s->auto_network_select = 1;
2099 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002100 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002101 }
2102#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002103#ifdef CONFIG_WPS
2104 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2105 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2106 timeout_sec = 0;
2107 timeout_usec = 500000;
2108 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2109 timeout_usec);
2110 return 0;
2111 }
2112#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002113#ifdef CONFIG_OWE
2114 if (wpa_s->owe_transition_search) {
2115 wpa_dbg(wpa_s, MSG_DEBUG,
2116 "OWE: Use shorter wait during transition mode search");
2117 timeout_sec = 0;
2118 timeout_usec = 500000;
2119 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2120 timeout_usec);
2121 return 0;
2122 }
2123#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002124 if (wpa_supplicant_req_sched_scan(wpa_s))
2125 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2126 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002127
2128 wpa_msg_ctrl(wpa_s, MSG_INFO,
2129 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002130 }
2131 }
2132 return 0;
2133}
2134
2135
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002136static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2137 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002138{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002139 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002140 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002141
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002142 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002143 if (res == 2) {
2144 /*
2145 * Interface may have been removed, so must not dereference
2146 * wpa_s after this.
2147 */
2148 return 1;
2149 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002150
2151 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002152 /*
2153 * If no scan results could be fetched, then no need to
2154 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002155 * this scan. Similarly, if scan results started a new operation on this
2156 * interface, do not notify other interfaces to avoid concurrent
2157 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002158 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002159 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160 }
2161
2162 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002163 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164 * so, they get updated with this same scan info.
2165 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002166 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2167 radio_list) {
2168 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002169 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2170 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002171 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2172 res > 0);
2173 if (res < 0)
2174 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002175 }
2176 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002177
2178 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002179}
2180
2181#endif /* CONFIG_NO_SCAN_PROCESSING */
2182
2183
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002184int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2185{
2186#ifdef CONFIG_NO_SCAN_PROCESSING
2187 return -1;
2188#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002189 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002190
Dmitry Shmidt29333592017-01-09 12:27:11 -08002191 wpa_s->ignore_post_flush_scan_res = 0;
2192
Dmitry Shmidt41712582015-06-29 11:02:15 -07002193 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002194 return -1;
2195
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002196 os_get_reltime(&now);
2197 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002198 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2199 return -1;
2200 }
2201
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002202 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002203#endif /* CONFIG_NO_SCAN_PROCESSING */
2204}
2205
Dmitry Shmidt04949592012-07-19 12:16:46 -07002206#ifdef CONFIG_WNM
2207
2208static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2209{
2210 struct wpa_supplicant *wpa_s = eloop_ctx;
2211
2212 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2213 return;
2214
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002215 if (!wpa_s->no_keep_alive) {
2216 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2217 MAC2STR(wpa_s->bssid));
2218 /* TODO: could skip this if normal data traffic has been sent */
2219 /* TODO: Consider using some more appropriate data frame for
2220 * this */
2221 if (wpa_s->l2)
2222 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2223 (u8 *) "", 0);
2224 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002225
2226#ifdef CONFIG_SME
2227 if (wpa_s->sme.bss_max_idle_period) {
2228 unsigned int msec;
2229 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2230 if (msec > 100)
2231 msec -= 100;
2232 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2233 wnm_bss_keep_alive, wpa_s, NULL);
2234 }
2235#endif /* CONFIG_SME */
2236}
2237
2238
2239static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2240 const u8 *ies, size_t ies_len)
2241{
2242 struct ieee802_11_elems elems;
2243
2244 if (ies == NULL)
2245 return;
2246
2247 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2248 return;
2249
2250#ifdef CONFIG_SME
2251 if (elems.bss_max_idle_period) {
2252 unsigned int msec;
2253 wpa_s->sme.bss_max_idle_period =
2254 WPA_GET_LE16(elems.bss_max_idle_period);
2255 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2256 "TU)%s", wpa_s->sme.bss_max_idle_period,
2257 (elems.bss_max_idle_period[2] & 0x01) ?
2258 " (protected keep-live required)" : "");
2259 if (wpa_s->sme.bss_max_idle_period == 0)
2260 wpa_s->sme.bss_max_idle_period = 1;
2261 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2262 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2263 /* msec times 1000 */
2264 msec = wpa_s->sme.bss_max_idle_period * 1024;
2265 if (msec > 100)
2266 msec -= 100;
2267 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2268 wnm_bss_keep_alive, wpa_s,
2269 NULL);
2270 }
2271 }
2272#endif /* CONFIG_SME */
2273}
2274
2275#endif /* CONFIG_WNM */
2276
2277
2278void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2279{
2280#ifdef CONFIG_WNM
2281 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2282#endif /* CONFIG_WNM */
2283}
2284
2285
Dmitry Shmidt051af732013-10-22 13:52:46 -07002286#ifdef CONFIG_INTERWORKING
2287
2288static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2289 size_t len)
2290{
2291 int res;
2292
2293 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2294 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2295 if (res) {
2296 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2297 }
2298
2299 return res;
2300}
2301
2302
2303static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2304 const u8 *ies, size_t ies_len)
2305{
2306 struct ieee802_11_elems elems;
2307
2308 if (ies == NULL)
2309 return;
2310
2311 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2312 return;
2313
2314 if (elems.qos_map_set) {
2315 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2316 elems.qos_map_set_len);
2317 }
2318}
2319
2320#endif /* CONFIG_INTERWORKING */
2321
2322
Hai Shalom74f70d42019-02-11 14:42:39 -08002323static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2324 const u8 *ies, size_t ies_len)
2325{
2326 struct ieee802_11_elems elems;
2327 const u8 *map_sub_elem, *pos;
2328 size_t len;
2329
2330 if (!wpa_s->current_ssid ||
2331 !wpa_s->current_ssid->multi_ap_backhaul_sta ||
2332 !ies ||
2333 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2334 return;
2335
2336 if (!elems.multi_ap || elems.multi_ap_len < 7) {
2337 wpa_printf(MSG_INFO, "AP doesn't support Multi-AP protocol");
2338 goto fail;
2339 }
2340
2341 pos = elems.multi_ap + 4;
2342 len = elems.multi_ap_len - 4;
2343
2344 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
2345 if (!map_sub_elem || map_sub_elem[1] < 1) {
2346 wpa_printf(MSG_INFO, "invalid Multi-AP sub elem type");
2347 goto fail;
2348 }
2349
2350 if (!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS)) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002351 if ((map_sub_elem[2] & MULTI_AP_FRONTHAUL_BSS) &&
2352 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2353 wpa_printf(MSG_INFO,
2354 "WPS active, accepting fronthaul-only BSS");
2355 /* Don't set 4addr mode in this case, so just return */
2356 return;
2357 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002358 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2359 goto fail;
2360 }
2361
2362 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2363 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2364 goto fail;
2365 }
2366 wpa_s->enabled_4addr_mode = 1;
2367 return;
2368
2369fail:
2370 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2371}
2372
2373
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002374#ifdef CONFIG_FST
2375static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2376 const u8 *ie, size_t ie_len)
2377{
2378 struct mb_ies_info mb_ies;
2379
2380 if (!ie || !ie_len || !wpa_s->fst)
2381 return -ENOENT;
2382
2383 os_memset(&mb_ies, 0, sizeof(mb_ies));
2384
2385 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2386 size_t len;
2387
2388 len = 2 + ie[1];
2389 if (len > ie_len) {
2390 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2391 ie, ie_len);
2392 break;
2393 }
2394
2395 if (ie[0] == WLAN_EID_MULTI_BAND) {
2396 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2397 (unsigned int) len);
2398 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2399 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2400 mb_ies.nof_ies++;
2401 }
2402
2403 ie_len -= len;
2404 ie += len;
2405 }
2406
2407 if (mb_ies.nof_ies > 0) {
2408 wpabuf_free(wpa_s->received_mb_ies);
2409 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2410 return 0;
2411 }
2412
2413 return -ENOENT;
2414}
2415#endif /* CONFIG_FST */
2416
2417
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2419 union wpa_event_data *data)
2420{
Hai Shalomc3565922019-10-28 11:58:20 -07002421 int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002422 const u8 *p;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002423#if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002424 u8 bssid[ETH_ALEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -07002425#endif /* CONFIG_IEEE80211R || CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002426
2427 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
2428 if (data->assoc_info.req_ies)
2429 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2430 data->assoc_info.req_ies_len);
2431 if (data->assoc_info.resp_ies) {
2432 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2433 data->assoc_info.resp_ies_len);
2434#ifdef CONFIG_TDLS
2435 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2436 data->assoc_info.resp_ies_len);
2437#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002438#ifdef CONFIG_WNM
2439 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2440 data->assoc_info.resp_ies_len);
2441#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002442#ifdef CONFIG_INTERWORKING
2443 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2444 data->assoc_info.resp_ies_len);
2445#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002446 if (wpa_s->hw_capab == CAPAB_VHT &&
2447 get_ie(data->assoc_info.resp_ies,
2448 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2449 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002450
2451 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2452 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002453 }
2454 if (data->assoc_info.beacon_ies)
2455 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2456 data->assoc_info.beacon_ies,
2457 data->assoc_info.beacon_ies_len);
2458 if (data->assoc_info.freq)
2459 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2460 data->assoc_info.freq);
2461
Hai Shalom021b0b52019-04-10 11:17:58 -07002462 wpa_s->connection_set = 0;
2463 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2464 struct ieee802_11_elems req_elems, resp_elems;
2465
2466 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2467 data->assoc_info.req_ies_len,
2468 &req_elems, 0) != ParseFailed &&
2469 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2470 data->assoc_info.resp_ies_len,
2471 &resp_elems, 0) != ParseFailed) {
2472 wpa_s->connection_set = 1;
2473 wpa_s->connection_ht = req_elems.ht_capabilities &&
2474 resp_elems.ht_capabilities;
2475 wpa_s->connection_vht = req_elems.vht_capabilities &&
2476 resp_elems.vht_capabilities;
2477 wpa_s->connection_he = req_elems.he_capabilities &&
2478 resp_elems.he_capabilities;
2479 }
2480 }
2481
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002482 p = data->assoc_info.req_ies;
2483 l = data->assoc_info.req_ies_len;
2484
2485 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2486 while (p && l >= 2) {
2487 len = p[1] + 2;
2488 if (len > l) {
2489 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2490 p, l);
2491 break;
2492 }
Hai Shalomc3565922019-10-28 11:58:20 -07002493 if (!found &&
2494 ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2495 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2496 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2497 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2498 (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002499 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2500 break;
2501 found = 1;
2502 wpa_find_assoc_pmkid(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07002503 }
2504 if (!found_x && p[0] == WLAN_EID_RSNX) {
2505 if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
2506 break;
2507 found_x = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002508 }
2509 l -= len;
2510 p += len;
2511 }
2512 if (!found && data->assoc_info.req_ies)
2513 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002514 if (!found_x && data->assoc_info.req_ies)
2515 wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002516
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002517#ifdef CONFIG_FILS
2518#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002519 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2520 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002521 (!data->assoc_info.resp_frame ||
2522 fils_process_assoc_resp(wpa_s->wpa,
2523 data->assoc_info.resp_frame,
2524 data->assoc_info.resp_frame_len) < 0)) {
2525 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2526 return -1;
2527 }
2528#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002529
2530 /* Additional processing for FILS when SME is in driver */
2531 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2532 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2533 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002534#endif /* CONFIG_FILS */
2535
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002536#ifdef CONFIG_OWE
2537 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
2538 (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2539 owe_process_assoc_resp(wpa_s->wpa, bssid,
2540 data->assoc_info.resp_ies,
2541 data->assoc_info.resp_ies_len) < 0)) {
2542 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2543 return -1;
2544 }
2545#endif /* CONFIG_OWE */
2546
Hai Shalom021b0b52019-04-10 11:17:58 -07002547#ifdef CONFIG_DPP2
2548 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
2549 if (wpa_s->key_mgmt == WPA_KEY_MGMT_DPP && wpa_s->dpp_pfs) {
2550 struct ieee802_11_elems elems;
2551
2552 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2553 data->assoc_info.resp_ies_len,
2554 &elems, 0) == ParseFailed ||
2555 !elems.owe_dh)
2556 goto no_pfs;
2557 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2558 elems.owe_dh_len) < 0) {
2559 wpa_supplicant_deauthenticate(wpa_s,
2560 WLAN_REASON_UNSPECIFIED);
2561 return -1;
2562 }
2563
2564 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2565 }
2566no_pfs:
2567#endif /* CONFIG_DPP2 */
2568
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002569#ifdef CONFIG_IEEE80211R
2570#ifdef CONFIG_SME
2571 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002572 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2573 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2574 data->assoc_info.resp_ies,
2575 data->assoc_info.resp_ies_len,
2576 bssid) < 0) {
2577 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2578 "Reassociation Response failed");
2579 wpa_supplicant_deauthenticate(
2580 wpa_s, WLAN_REASON_INVALID_IE);
2581 return -1;
2582 }
2583 }
2584
2585 p = data->assoc_info.resp_ies;
2586 l = data->assoc_info.resp_ies_len;
2587
2588#ifdef CONFIG_WPS_STRICT
2589 if (p && wpa_s->current_ssid &&
2590 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2591 struct wpabuf *wps;
2592 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2593 if (wps == NULL) {
2594 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2595 "include WPS IE in (Re)Association Response");
2596 return -1;
2597 }
2598
2599 if (wps_validate_assoc_resp(wps) < 0) {
2600 wpabuf_free(wps);
2601 wpa_supplicant_deauthenticate(
2602 wpa_s, WLAN_REASON_INVALID_IE);
2603 return -1;
2604 }
2605 wpabuf_free(wps);
2606 }
2607#endif /* CONFIG_WPS_STRICT */
2608
2609 /* Go through the IEs and make a copy of the MDIE, if present. */
2610 while (p && l >= 2) {
2611 len = p[1] + 2;
2612 if (len > l) {
2613 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2614 p, l);
2615 break;
2616 }
2617 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2618 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2619 wpa_s->sme.ft_used = 1;
2620 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2621 MOBILITY_DOMAIN_ID_LEN);
2622 break;
2623 }
2624 l -= len;
2625 p += len;
2626 }
2627#endif /* CONFIG_SME */
2628
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002629 /* Process FT when SME is in the driver */
2630 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2631 wpa_ft_is_completed(wpa_s->wpa)) {
2632 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2633 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2634 data->assoc_info.resp_ies,
2635 data->assoc_info.resp_ies_len,
2636 bssid) < 0) {
2637 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2638 "Reassociation Response failed");
2639 wpa_supplicant_deauthenticate(
2640 wpa_s, WLAN_REASON_INVALID_IE);
2641 return -1;
2642 }
2643 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2644 }
2645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002646 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2647 data->assoc_info.resp_ies_len);
2648#endif /* CONFIG_IEEE80211R */
2649
2650 /* WPA/RSN IE from Beacon/ProbeResp */
2651 p = data->assoc_info.beacon_ies;
2652 l = data->assoc_info.beacon_ies_len;
2653
2654 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2655 */
2656 wpa_found = rsn_found = 0;
2657 while (p && l >= 2) {
2658 len = p[1] + 2;
2659 if (len > l) {
2660 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2661 p, l);
2662 break;
2663 }
2664 if (!wpa_found &&
2665 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2666 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2667 wpa_found = 1;
2668 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2669 }
2670
2671 if (!rsn_found &&
2672 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2673 rsn_found = 1;
2674 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2675 }
2676
Hai Shalomc3565922019-10-28 11:58:20 -07002677 if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
2678 wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
2679
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002680 l -= len;
2681 p += len;
2682 }
2683
2684 if (!wpa_found && data->assoc_info.beacon_ies)
2685 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002686 if (!rsn_found && data->assoc_info.beacon_ies) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002687 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
Hai Shalomc3565922019-10-28 11:58:20 -07002688 wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
2689 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002690 if (wpa_found || rsn_found)
2691 wpa_s->ap_ies_from_associnfo = 1;
2692
Jouni Malinen87fd2792011-05-16 18:35:42 +03002693 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2694 wpa_s->assoc_freq != data->assoc_info.freq) {
2695 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2696 "%u to %u MHz",
2697 wpa_s->assoc_freq, data->assoc_info.freq);
2698 wpa_supplicant_update_scan_results(wpa_s);
2699 }
2700
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002701 wpa_s->assoc_freq = data->assoc_info.freq;
2702
2703 return 0;
2704}
2705
2706
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002707static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2708{
Hai Shalomc3565922019-10-28 11:58:20 -07002709 const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002710
2711 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2712 return -1;
2713
2714 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2715 return 0;
2716
2717 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2718 WPA_IE_VENDOR_TYPE);
2719 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
Hai Shalomc3565922019-10-28 11:58:20 -07002720 bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002721
2722 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2723 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2724 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
Hai Shalomc3565922019-10-28 11:58:20 -07002725 bss_rsn ? 2 + bss_rsn[1] : 0) ||
2726 wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
2727 bss_rsnx ? 2 + bss_rsnx[1] : 0))
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002728 return -1;
2729
2730 return 0;
2731}
2732
2733
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002734static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2735 union wpa_event_data *data)
2736{
2737#ifdef CONFIG_FST
2738 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2739 struct wpa_bss *bss = wpa_s->current_bss;
2740 const u8 *ieprb, *iebcn;
2741
2742 wpabuf_free(wpa_s->received_mb_ies);
2743 wpa_s->received_mb_ies = NULL;
2744
2745 if (ai &&
2746 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2747 wpa_printf(MSG_DEBUG,
2748 "FST: MB IEs updated from Association Response frame");
2749 return;
2750 }
2751
2752 if (ai &&
2753 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2754 wpa_printf(MSG_DEBUG,
2755 "FST: MB IEs updated from association event Beacon IEs");
2756 return;
2757 }
2758
2759 if (!bss)
2760 return;
2761
2762 ieprb = (const u8 *) (bss + 1);
2763 iebcn = ieprb + bss->ie_len;
2764
2765 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2766 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2767 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2768 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2769#endif /* CONFIG_FST */
2770}
2771
2772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002773static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2774 union wpa_event_data *data)
2775{
2776 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002777 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002778 int new_bss = 0;
Hai Shalomc3565922019-10-28 11:58:20 -07002779#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
2780 struct wpa_bss *bss;
2781#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002782
2783#ifdef CONFIG_AP
2784 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002785 if (!data)
2786 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002787 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2788 data->assoc_info.addr,
2789 data->assoc_info.req_ies,
2790 data->assoc_info.req_ies_len,
2791 data->assoc_info.reassoc);
2792 return;
2793 }
2794#endif /* CONFIG_AP */
2795
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002796 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2797
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002798 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2799 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2800 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002801 /*
2802 * FILS authentication can share the same mechanism to mark the
2803 * connection fully authenticated, so set ft_completed also based on
2804 * FILS result.
2805 */
2806 if (!ft_completed)
2807 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002808
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002809 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2810 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002811 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002812 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2813 return;
2814 }
2815
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002816 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002817 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08002818 if (os_reltime_initialized(&wpa_s->session_start)) {
2819 os_reltime_age(&wpa_s->session_start,
2820 &wpa_s->session_length);
2821 wpa_s->session_start.sec = 0;
2822 wpa_s->session_start.usec = 0;
2823 wpas_notify_session_length(wpa_s);
2824 } else {
2825 wpas_notify_auth_changed(wpa_s);
2826 os_get_reltime(&wpa_s->session_start);
2827 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002828 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2829 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002830 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002831 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002832 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2833 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002834 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002835
2836 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2837 wpa_clear_keys(wpa_s, bssid);
2838 }
2839 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002840 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002841 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2842 return;
2843 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002844 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002845
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002846 if (wpa_s->conf->ap_scan == 1 &&
2847 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002848 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2849 wpa_msg(wpa_s, MSG_WARNING,
2850 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002851 }
2852
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002853 wpas_fst_update_mb_assoc(wpa_s, data);
2854
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002855#ifdef CONFIG_SME
2856 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2857 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002858 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002859#endif /* CONFIG_SME */
2860
2861 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2862 if (wpa_s->current_ssid) {
2863 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2864 * initialized before association, but for other modes,
2865 * initialize PC/SC here, if the current configuration needs
2866 * smartcard or SIM/USIM. */
2867 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2868 }
2869 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2870 if (wpa_s->l2)
2871 l2_packet_notify_auth_start(wpa_s->l2);
2872
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002873 already_authorized = data && data->assoc_info.authorized;
2874
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002875 /*
2876 * Set portEnabled first to FALSE in order to get EAP state machine out
2877 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2878 * state machine may transit to AUTHENTICATING state based on obsolete
2879 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2880 * AUTHENTICATED without ever giving chance to EAP state machine to
2881 * reset the state.
2882 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002883 if (!ft_completed && !already_authorized) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002884 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2885 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2886 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002887 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
2888 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
2889 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Hai Shalomc3565922019-10-28 11:58:20 -07002890 already_authorized || wpa_s->drv_authorized_port)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002891 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2892 /* 802.1X::portControl = Auto */
2893 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2894 wpa_s->eapol_received = 0;
2895 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2896 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2897 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07002898 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002899 if (wpa_s->current_ssid &&
2900 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002901 (wpa_s->drv_flags &
2902 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2903 /*
2904 * Set the key after having received joined-IBSS event
2905 * from the driver.
2906 */
2907 wpa_supplicant_set_wpa_none_key(wpa_s,
2908 wpa_s->current_ssid);
2909 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002910 wpa_supplicant_cancel_auth_timeout(wpa_s);
2911 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2912 } else if (!ft_completed) {
2913 /* Timeout for receiving the first EAPOL packet */
2914 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2915 }
2916 wpa_supplicant_cancel_scan(wpa_s);
2917
Hai Shalom5f92bc92019-04-18 11:54:11 -07002918 if (ft_completed) {
2919 /*
2920 * FT protocol completed - make sure EAPOL state machine ends
2921 * up in authenticated.
2922 */
2923 wpa_supplicant_cancel_auth_timeout(wpa_s);
2924 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2925 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2926 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2927 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
2928 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002929 /*
2930 * We are done; the driver will take care of RSN 4-way
2931 * handshake.
2932 */
2933 wpa_supplicant_cancel_auth_timeout(wpa_s);
2934 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2935 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2936 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
Hai Shalom74f70d42019-02-11 14:42:39 -08002937 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002938 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2939 /*
2940 * The driver will take care of RSN 4-way handshake, so we need
2941 * to allow EAPOL supplicant to complete its work without
2942 * waiting for WPA supplicant.
2943 */
2944 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002945 }
2946
Jouni Malinena05074c2012-12-21 21:35:35 +02002947 wpa_s->last_eapol_matches_bssid = 0;
2948
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002949#ifdef CONFIG_TESTING_OPTIONS
2950 if (wpa_s->rsnxe_override_eapol) {
2951 wpa_printf(MSG_DEBUG,
2952 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
2953 wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
2954 wpabuf_head(wpa_s->rsnxe_override_eapol),
2955 wpabuf_len(wpa_s->rsnxe_override_eapol));
2956 }
2957#endif /* CONFIG_TESTING_OPTIONS */
2958
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002959 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002960 struct os_reltime now, age;
2961 os_get_reltime(&now);
2962 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08002963 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002964 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2965 0) {
2966 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2967 "frame that was received just before "
2968 "association notification");
2969 wpa_supplicant_rx_eapol(
2970 wpa_s, wpa_s->pending_eapol_rx_src,
2971 wpabuf_head(wpa_s->pending_eapol_rx),
2972 wpabuf_len(wpa_s->pending_eapol_rx));
2973 }
2974 wpabuf_free(wpa_s->pending_eapol_rx);
2975 wpa_s->pending_eapol_rx = NULL;
2976 }
2977
2978 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2979 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002980 wpa_s->current_ssid &&
2981 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002982 /* Set static WEP keys again */
2983 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2984 }
2985
2986#ifdef CONFIG_IBSS_RSN
2987 if (wpa_s->current_ssid &&
2988 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2989 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2990 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2991 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002992 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002993 if (!wpa_s->ibss_rsn) {
2994 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2995 wpa_supplicant_deauthenticate(
2996 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2997 return;
2998 }
2999
3000 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
3001 }
3002#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003003
3004 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003005
3006 if (data) {
3007 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
3008 data->assoc_info.resp_ies_len,
3009 &data->assoc_info.wmm_params);
3010
3011 if (wpa_s->reassoc_same_bss)
3012 wmm_ac_restore_tspecs(wpa_s);
3013 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003014
Hai Shalomc3565922019-10-28 11:58:20 -07003015#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3016 bss = wpa_bss_get_bssid(wpa_s, bssid);
3017#endif /* CONFIG_FILS || CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003018#ifdef CONFIG_FILS
3019 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003020 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3021
3022 if (fils_cache_id)
3023 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
3024 }
3025#endif /* CONFIG_FILS */
Hai Shalomc3565922019-10-28 11:58:20 -07003026
3027#ifdef CONFIG_MBO
3028 wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
3029#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003030}
3031
3032
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003033static int disconnect_reason_recoverable(u16 reason_code)
3034{
3035 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
3036 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
3037 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
3038}
3039
3040
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003041static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003042 u16 reason_code,
3043 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003044{
3045 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03003046
3047 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3048 /*
3049 * At least Host AP driver and a Prism3 card seemed to be
3050 * generating streams of disconnected events when configuring
3051 * IBSS for WPA-None. Ignore them for now.
3052 */
3053 return;
3054 }
3055
3056 bssid = wpa_s->bssid;
3057 if (is_zero_ether_addr(bssid))
3058 bssid = wpa_s->pending_bssid;
3059
3060 if (!is_zero_ether_addr(bssid) ||
3061 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3062 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
3063 " reason=%d%s",
3064 MAC2STR(bssid), reason_code,
3065 locally_generated ? " locally_generated=1" : "");
3066 }
3067}
3068
3069
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003070static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
3071 int locally_generated)
3072{
3073 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003074 !wpa_s->new_connection ||
Hai Shalomc3565922019-10-28 11:58:20 -07003075 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
3076 wpa_key_mgmt_sae(wpa_s->key_mgmt))
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003077 return 0; /* Not in initial 4-way handshake with PSK */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003078
3079 /*
3080 * It looks like connection was lost while trying to go through PSK
3081 * 4-way handshake. Filter out known disconnection cases that are caused
3082 * by something else than PSK mismatch to avoid confusing reports.
3083 */
3084
3085 if (locally_generated) {
3086 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3087 return 0;
3088 }
3089
3090 return 1;
3091}
3092
3093
Jouni Malinen2b89da82012-08-31 22:04:41 +03003094static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3095 u16 reason_code,
3096 int locally_generated)
3097{
3098 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003099 int authenticating;
3100 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003101 struct wpa_bss *fast_reconnect = NULL;
3102 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003103 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003104 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003105
3106 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3107 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3108
3109 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3110 /*
3111 * At least Host AP driver and a Prism3 card seemed to be
3112 * generating streams of disconnected events when configuring
3113 * IBSS for WPA-None. Ignore them for now.
3114 */
3115 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3116 "IBSS/WPA-None mode");
3117 return;
3118 }
3119
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003120 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3121 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3122 locally_generated)
3123 /*
3124 * Remove the inactive AP (which is probably out of range) from
3125 * the BSS list after marking disassociation. In particular
3126 * mac80211-based drivers use the
3127 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3128 * locally generated disconnection events for cases where the
3129 * AP does not reply anymore.
3130 */
3131 curr = wpa_s->current_bss;
3132
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003133 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003134 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3135 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003136 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3137 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003138 wpas_auth_failed(wpa_s, "WRONG_KEY");
Hai Shalomc3565922019-10-28 11:58:20 -07003139#ifdef CONFIG_DPP2
3140 wpas_dpp_send_conn_status_result(wpa_s,
3141 DPP_STATUS_AUTH_FAILURE);
3142#endif /* CONFIG_DPP2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003143 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003144 if (!wpa_s->disconnected &&
3145 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003146 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003147 wpas_wps_searching(wpa_s) ||
3148 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003149 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003150 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003151 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003152 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003153 wpa_s->wpa_state);
3154 if (wpa_s->wpa_state == WPA_COMPLETED &&
3155 wpa_s->current_ssid &&
3156 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003157 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003158 disconnect_reason_recoverable(reason_code)) {
3159 /*
3160 * It looks like the AP has dropped association with
3161 * us, but could allow us to get back in. Try to
3162 * reconnect to the same BSS without full scan to save
3163 * time for some common cases.
3164 */
3165 fast_reconnect = wpa_s->current_bss;
3166 fast_reconnect_ssid = wpa_s->current_ssid;
3167 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003168 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003169 else
3170 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3171 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003172 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003173 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003174 "try to re-connect");
3175 wpa_s->reassociate = 0;
3176 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003177 if (!wpa_s->pno)
3178 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003179 }
3180 bssid = wpa_s->bssid;
3181 if (is_zero_ether_addr(bssid))
3182 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003183 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3184 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003185 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003186 if (locally_generated)
3187 wpa_s->disconnect_reason = -reason_code;
3188 else
3189 wpa_s->disconnect_reason = reason_code;
3190 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003191 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3192 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003193 wpa_clear_keys(wpa_s, wpa_s->bssid);
3194 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003195 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003196 wpa_supplicant_mark_disassoc(wpa_s);
3197
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003198 if (curr)
3199 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3200
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003201 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003202 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003203 wpa_s->current_ssid = last_ssid;
3204 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003205
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003206 if (fast_reconnect &&
3207 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3208 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3209 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3210 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003211 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003212 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003213#ifndef CONFIG_NO_SCAN_PROCESSING
3214 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3215 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3216 fast_reconnect_ssid) < 0) {
3217 /* Recover through full scan */
3218 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3219 }
3220#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003221 } else if (fast_reconnect) {
3222 /*
3223 * Could not reconnect to the same BSS due to network being
3224 * disabled. Use a new scan to match the alternative behavior
3225 * above, i.e., to continue automatic reconnection attempt in a
3226 * way that enforces disabled network rules.
3227 */
3228 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003229 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003230}
3231
3232
3233#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003234void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003235{
3236 struct wpa_supplicant *wpa_s = eloop_ctx;
3237
3238 if (!wpa_s->pending_mic_error_report)
3239 return;
3240
3241 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3242 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3243 wpa_s->pending_mic_error_report = 0;
3244}
3245#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3246
3247
3248static void
3249wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3250 union wpa_event_data *data)
3251{
3252 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003253 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003254
3255 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3256 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003257 os_get_reltime(&t);
3258 if ((wpa_s->last_michael_mic_error.sec &&
3259 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003260 wpa_s->pending_mic_error_report) {
3261 if (wpa_s->pending_mic_error_report) {
3262 /*
3263 * Send the pending MIC error report immediately since
3264 * we are going to start countermeasures and AP better
3265 * do the same.
3266 */
3267 wpa_sm_key_request(wpa_s->wpa, 1,
3268 wpa_s->pending_mic_error_pairwise);
3269 }
3270
3271 /* Send the new MIC error report immediately since we are going
3272 * to start countermeasures and AP better do the same.
3273 */
3274 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3275
3276 /* initialize countermeasures */
3277 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003278
3279 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3280
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003281 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3282
3283 /*
3284 * Need to wait for completion of request frame. We do not get
3285 * any callback for the message completion, so just wait a
3286 * short while and hope for the best. */
3287 os_sleep(0, 10000);
3288
3289 wpa_drv_set_countermeasures(wpa_s, 1);
3290 wpa_supplicant_deauthenticate(wpa_s,
3291 WLAN_REASON_MICHAEL_MIC_FAILURE);
3292 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3293 wpa_s, NULL);
3294 eloop_register_timeout(60, 0,
3295 wpa_supplicant_stop_countermeasures,
3296 wpa_s, NULL);
3297 /* TODO: mark the AP rejected for 60 second. STA is
3298 * allowed to associate with another AP.. */
3299 } else {
3300#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3301 if (wpa_s->mic_errors_seen) {
3302 /*
3303 * Reduce the effectiveness of Michael MIC error
3304 * reports as a means for attacking against TKIP if
3305 * more than one MIC failure is noticed with the same
3306 * PTK. We delay the transmission of the reports by a
3307 * random time between 0 and 60 seconds in order to
3308 * force the attacker wait 60 seconds before getting
3309 * the information on whether a frame resulted in a MIC
3310 * failure.
3311 */
3312 u8 rval[4];
3313 int sec;
3314
3315 if (os_get_random(rval, sizeof(rval)) < 0)
3316 sec = os_random() % 60;
3317 else
3318 sec = WPA_GET_BE32(rval) % 60;
3319 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3320 "report %d seconds", sec);
3321 wpa_s->pending_mic_error_report = 1;
3322 wpa_s->pending_mic_error_pairwise = pairwise;
3323 eloop_cancel_timeout(
3324 wpa_supplicant_delayed_mic_error_report,
3325 wpa_s, NULL);
3326 eloop_register_timeout(
3327 sec, os_random() % 1000000,
3328 wpa_supplicant_delayed_mic_error_report,
3329 wpa_s, NULL);
3330 } else {
3331 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3332 }
3333#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3334 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3335#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3336 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003337 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003338 wpa_s->mic_errors_seen++;
3339}
3340
3341
3342#ifdef CONFIG_TERMINATE_ONLASTIF
3343static int any_interfaces(struct wpa_supplicant *head)
3344{
3345 struct wpa_supplicant *wpa_s;
3346
3347 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3348 if (!wpa_s->interface_removed)
3349 return 1;
3350 return 0;
3351}
3352#endif /* CONFIG_TERMINATE_ONLASTIF */
3353
3354
3355static void
3356wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3357 union wpa_event_data *data)
3358{
3359 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3360 return;
3361
3362 switch (data->interface_status.ievent) {
3363 case EVENT_INTERFACE_ADDED:
3364 if (!wpa_s->interface_removed)
3365 break;
3366 wpa_s->interface_removed = 0;
3367 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3368 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3369 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3370 "driver after interface was added");
3371 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003372
3373#ifdef CONFIG_P2P
3374 if (!wpa_s->global->p2p &&
3375 !wpa_s->global->p2p_disabled &&
3376 !wpa_s->conf->p2p_disabled &&
3377 (wpa_s->drv_flags &
3378 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3379 wpas_p2p_add_p2pdev_interface(
3380 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3381 wpa_printf(MSG_INFO,
3382 "P2P: Failed to enable P2P Device interface");
3383 /* Try to continue without. P2P will be disabled. */
3384 }
3385#endif /* CONFIG_P2P */
3386
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003387 break;
3388 case EVENT_INTERFACE_REMOVED:
3389 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3390 wpa_s->interface_removed = 1;
3391 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003392 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003393 l2_packet_deinit(wpa_s->l2);
3394 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003395
3396#ifdef CONFIG_P2P
3397 if (wpa_s->global->p2p &&
3398 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3399 (wpa_s->drv_flags &
3400 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3401 wpa_dbg(wpa_s, MSG_DEBUG,
3402 "Removing P2P Device interface");
3403 wpa_supplicant_remove_iface(
3404 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3405 0);
3406 wpa_s->global->p2p_init_wpa_s = NULL;
3407 }
3408#endif /* CONFIG_P2P */
3409
Dmitry Shmidte4663042016-04-04 10:07:49 -07003410#ifdef CONFIG_MATCH_IFACE
3411 if (wpa_s->matched) {
3412 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3413 break;
3414 }
3415#endif /* CONFIG_MATCH_IFACE */
3416
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003417#ifdef CONFIG_TERMINATE_ONLASTIF
3418 /* check if last interface */
3419 if (!any_interfaces(wpa_s->global->ifaces))
3420 eloop_terminate();
3421#endif /* CONFIG_TERMINATE_ONLASTIF */
3422 break;
3423 }
3424}
3425
3426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003427#ifdef CONFIG_TDLS
3428static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3429 union wpa_event_data *data)
3430{
3431 if (data == NULL)
3432 return;
3433 switch (data->tdls.oper) {
3434 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003435 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3436 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3437 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3438 else
3439 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003440 break;
3441 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003442 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3443 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3444 data->tdls.reason_code);
3445 else
3446 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3447 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003448 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003449 case TDLS_REQUEST_DISCOVER:
3450 wpa_tdls_send_discovery_request(wpa_s->wpa,
3451 data->tdls.peer);
3452 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003453 }
3454}
3455#endif /* CONFIG_TDLS */
3456
3457
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003458#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003459static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3460 union wpa_event_data *data)
3461{
3462 if (data == NULL)
3463 return;
3464 switch (data->wnm.oper) {
3465 case WNM_OPER_SLEEP:
3466 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3467 "(action=%d, intval=%d)",
3468 data->wnm.sleep_action, data->wnm.sleep_intval);
3469 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003470 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003471 break;
3472 }
3473}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003474#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003475
3476
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003477#ifdef CONFIG_IEEE80211R
3478static void
3479wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3480 union wpa_event_data *data)
3481{
3482 if (data == NULL)
3483 return;
3484
3485 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3486 data->ft_ies.ies_len,
3487 data->ft_ies.ft_action,
3488 data->ft_ies.target_ap,
3489 data->ft_ies.ric_ies,
3490 data->ft_ies.ric_ies_len) < 0) {
3491 /* TODO: prevent MLME/driver from trying to associate? */
3492 }
3493}
3494#endif /* CONFIG_IEEE80211R */
3495
3496
3497#ifdef CONFIG_IBSS_RSN
3498static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3499 union wpa_event_data *data)
3500{
3501 struct wpa_ssid *ssid;
3502 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3503 return;
3504 if (data == NULL)
3505 return;
3506 ssid = wpa_s->current_ssid;
3507 if (ssid == NULL)
3508 return;
3509 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3510 return;
3511
3512 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3513}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003514
3515
3516static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3517 union wpa_event_data *data)
3518{
3519 struct wpa_ssid *ssid = wpa_s->current_ssid;
3520
3521 if (ssid == NULL)
3522 return;
3523
3524 /* check if the ssid is correctly configured as IBSS/RSN */
3525 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3526 return;
3527
3528 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3529 data->rx_mgmt.frame_len);
3530}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003531#endif /* CONFIG_IBSS_RSN */
3532
3533
3534#ifdef CONFIG_IEEE80211R
3535static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3536 size_t len)
3537{
3538 const u8 *sta_addr, *target_ap_addr;
3539 u16 status;
3540
3541 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3542 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3543 return; /* only SME case supported for now */
3544 if (len < 1 + 2 * ETH_ALEN + 2)
3545 return;
3546 if (data[0] != 2)
3547 return; /* Only FT Action Response is supported for now */
3548 sta_addr = data + 1;
3549 target_ap_addr = data + 1 + ETH_ALEN;
3550 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3551 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3552 MACSTR " TargetAP " MACSTR " status %u",
3553 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3554
3555 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3556 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3557 " in FT Action Response", MAC2STR(sta_addr));
3558 return;
3559 }
3560
3561 if (status) {
3562 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3563 "failure (status code %d)", status);
3564 /* TODO: report error to FT code(?) */
3565 return;
3566 }
3567
3568 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3569 len - (1 + 2 * ETH_ALEN + 2), 1,
3570 target_ap_addr, NULL, 0) < 0)
3571 return;
3572
3573#ifdef CONFIG_SME
3574 {
3575 struct wpa_bss *bss;
3576 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3577 if (bss)
3578 wpa_s->sme.freq = bss->freq;
3579 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3580 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3581 WLAN_AUTH_FT);
3582 }
3583#endif /* CONFIG_SME */
3584}
3585#endif /* CONFIG_IEEE80211R */
3586
3587
3588static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3589 struct unprot_deauth *e)
3590{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003591 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3592 "dropped: " MACSTR " -> " MACSTR
3593 " (reason code %u)",
3594 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3595 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003596}
3597
3598
3599static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3600 struct unprot_disassoc *e)
3601{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003602 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3603 "dropped: " MACSTR " -> " MACSTR
3604 " (reason code %u)",
3605 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3606 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003607}
3608
3609
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003610static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3611 u16 reason_code, int locally_generated,
3612 const u8 *ie, size_t ie_len, int deauth)
3613{
3614#ifdef CONFIG_AP
3615 if (wpa_s->ap_iface && addr) {
3616 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3617 return;
3618 }
3619
3620 if (wpa_s->ap_iface) {
3621 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3622 return;
3623 }
3624#endif /* CONFIG_AP */
3625
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003626 if (!locally_generated)
3627 wpa_s->own_disconnect_req = 0;
3628
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003629 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3630
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003631 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3632 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3633 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3634 eapol_sm_failed(wpa_s->eapol))) &&
3635 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003636 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003637
3638#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003639 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003640 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3641 locally_generated) > 0) {
3642 /*
3643 * The interface was removed, so cannot continue
3644 * processing any additional operations after this.
3645 */
3646 return;
3647 }
3648 }
3649#endif /* CONFIG_P2P */
3650
3651 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3652 locally_generated);
3653}
3654
3655
3656static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3657 struct disassoc_info *info)
3658{
3659 u16 reason_code = 0;
3660 int locally_generated = 0;
3661 const u8 *addr = NULL;
3662 const u8 *ie = NULL;
3663 size_t ie_len = 0;
3664
3665 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3666
3667 if (info) {
3668 addr = info->addr;
3669 ie = info->ie;
3670 ie_len = info->ie_len;
3671 reason_code = info->reason_code;
3672 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07003673 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
3674 reason2str(reason_code),
3675 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003676 if (addr)
3677 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3678 MAC2STR(addr));
3679 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3680 ie, ie_len);
3681 }
3682
3683#ifdef CONFIG_AP
3684 if (wpa_s->ap_iface && info && info->addr) {
3685 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3686 return;
3687 }
3688
3689 if (wpa_s->ap_iface) {
3690 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3691 return;
3692 }
3693#endif /* CONFIG_AP */
3694
3695#ifdef CONFIG_P2P
3696 if (info) {
3697 wpas_p2p_disassoc_notif(
3698 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3699 locally_generated);
3700 }
3701#endif /* CONFIG_P2P */
3702
3703 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3704 sme_event_disassoc(wpa_s, info);
3705
3706 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3707 ie, ie_len, 0);
3708}
3709
3710
3711static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3712 struct deauth_info *info)
3713{
3714 u16 reason_code = 0;
3715 int locally_generated = 0;
3716 const u8 *addr = NULL;
3717 const u8 *ie = NULL;
3718 size_t ie_len = 0;
3719
3720 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3721
3722 if (info) {
3723 addr = info->addr;
3724 ie = info->ie;
3725 ie_len = info->ie_len;
3726 reason_code = info->reason_code;
3727 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07003728 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
3729 reason_code, reason2str(reason_code),
3730 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003731 if (addr) {
3732 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3733 MAC2STR(addr));
3734 }
3735 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3736 ie, ie_len);
3737 }
3738
3739 wpa_reset_ft_completed(wpa_s->wpa);
3740
3741 wpas_event_disconnect(wpa_s, addr, reason_code,
3742 locally_generated, ie, ie_len, 1);
3743}
3744
3745
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003746static const char * reg_init_str(enum reg_change_initiator init)
3747{
3748 switch (init) {
3749 case REGDOM_SET_BY_CORE:
3750 return "CORE";
3751 case REGDOM_SET_BY_USER:
3752 return "USER";
3753 case REGDOM_SET_BY_DRIVER:
3754 return "DRIVER";
3755 case REGDOM_SET_BY_COUNTRY_IE:
3756 return "COUNTRY_IE";
3757 case REGDOM_BEACON_HINT:
3758 return "BEACON_HINT";
3759 }
3760 return "?";
3761}
3762
3763
3764static const char * reg_type_str(enum reg_type type)
3765{
3766 switch (type) {
3767 case REGDOM_TYPE_UNKNOWN:
3768 return "UNKNOWN";
3769 case REGDOM_TYPE_COUNTRY:
3770 return "COUNTRY";
3771 case REGDOM_TYPE_WORLD:
3772 return "WORLD";
3773 case REGDOM_TYPE_CUSTOM_WORLD:
3774 return "CUSTOM_WORLD";
3775 case REGDOM_TYPE_INTERSECTION:
3776 return "INTERSECTION";
3777 }
3778 return "?";
3779}
3780
3781
Hai Shalom74f70d42019-02-11 14:42:39 -08003782void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
3783 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003784{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003785 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003786 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003787
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003788 /*
3789 * To allow backwards compatibility with higher level layers that
3790 * assumed the REGDOM_CHANGE event is sent over the initially added
3791 * interface. Find the highest parent of this interface and use it to
3792 * send the event.
3793 */
3794 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3795 ;
3796
Hai Shalom74f70d42019-02-11 14:42:39 -08003797 if (info) {
3798 wpa_msg(ifs, MSG_INFO,
3799 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3800 reg_init_str(info->initiator), reg_type_str(info->type),
3801 info->alpha2[0] ? " alpha2=" : "",
3802 info->alpha2[0] ? info->alpha2 : "");
3803 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003804
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003805 if (wpa_s->drv_priv == NULL)
3806 return; /* Ignore event during drv initialization */
3807
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003808 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3809 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003810 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3811 ifs->ifname);
3812 free_hw_features(ifs);
3813 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003814 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003815
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003816 /* Restart PNO/sched_scan with updated channel list */
3817 if (ifs->pno) {
3818 wpas_stop_pno(ifs);
3819 wpas_start_pno(ifs);
3820 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
3821 wpa_dbg(ifs, MSG_DEBUG,
3822 "Channel list changed - restart sched_scan");
3823 wpas_scan_restart_sched_scan(ifs);
3824 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003825 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003826
3827 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003828}
3829
3830
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003831static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003832 const u8 *frame, size_t len, int freq,
3833 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003834{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003835 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003836 const u8 *payload;
3837 size_t plen;
3838 u8 category;
3839
3840 if (len < IEEE80211_HDRLEN + 2)
3841 return;
3842
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003843 mgmt = (const struct ieee80211_mgmt *) frame;
3844 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003845 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003846 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003847
3848 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3849 " Category=%u DataLen=%d freq=%d MHz",
3850 MAC2STR(mgmt->sa), category, (int) plen, freq);
3851
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003852 if (category == WLAN_ACTION_WMM) {
3853 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3854 return;
3855 }
3856
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003857#ifdef CONFIG_IEEE80211R
3858 if (category == WLAN_ACTION_FT) {
3859 ft_rx_action(wpa_s, payload, plen);
3860 return;
3861 }
3862#endif /* CONFIG_IEEE80211R */
3863
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003864#ifdef CONFIG_SME
3865 if (category == WLAN_ACTION_SA_QUERY) {
3866 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3867 return;
3868 }
3869#endif /* CONFIG_SME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003870
3871#ifdef CONFIG_WNM
3872 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3873 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3874 return;
3875 }
3876#endif /* CONFIG_WNM */
3877
3878#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003879 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3880 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003881 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003882 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003883 payload, plen, freq) == 0)
3884 return;
3885#endif /* CONFIG_GAS */
3886
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003887#ifdef CONFIG_GAS_SERVER
3888 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3889 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3890 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
3891 mgmt->u.action.category,
3892 payload, plen, freq) == 0)
3893 return;
3894#endif /* CONFIG_GAS_SERVER */
3895
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003896#ifdef CONFIG_TDLS
3897 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3898 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3899 wpa_dbg(wpa_s, MSG_DEBUG,
3900 "TDLS: Received Discovery Response from " MACSTR,
3901 MAC2STR(mgmt->sa));
3902 return;
3903 }
3904#endif /* CONFIG_TDLS */
3905
3906#ifdef CONFIG_INTERWORKING
3907 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3908 payload[0] == QOS_QOS_MAP_CONFIG) {
3909 const u8 *pos = payload + 1;
3910 size_t qlen = plen - 1;
3911 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3912 MACSTR, MAC2STR(mgmt->sa));
3913 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3914 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3915 pos[1] <= qlen - 2 && pos[1] >= 16)
3916 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3917 return;
3918 }
3919#endif /* CONFIG_INTERWORKING */
3920
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003921 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003922 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
3923 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003924 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003925 payload + 1,
3926 plen - 1);
3927 return;
3928 }
3929
3930 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003931 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3932 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3933 return;
3934 }
3935
3936 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3937 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3938 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3939 payload + 1, plen - 1,
3940 rssi);
3941 return;
3942 }
3943
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003944#ifdef CONFIG_FST
3945 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3946 fst_rx_action(wpa_s->fst, mgmt, len);
3947 return;
3948 }
3949#endif /* CONFIG_FST */
3950
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003951#ifdef CONFIG_DPP
3952 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
3953 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
3954 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
3955 payload[4] == DPP_OUI_TYPE) {
3956 payload++;
3957 plen--;
3958 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
3959 return;
3960 }
3961#endif /* CONFIG_DPP */
3962
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003963 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3964 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003965 if (wpa_s->ifmsh)
3966 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003967}
3968
3969
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003970static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3971 union wpa_event_data *event)
3972{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003973 struct wpa_freq_range_list *list;
3974 char *str = NULL;
3975
3976 list = &event->freq_range;
3977
3978 if (list->num)
3979 str = freq_range_list_str(list);
3980 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3981 str ? str : "");
3982
3983#ifdef CONFIG_P2P
3984 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3985 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3986 __func__);
3987 } else {
3988 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003989
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003990 /*
3991 * The update channel flow will also take care of moving a GO
3992 * from the unsafe frequency if needed.
3993 */
3994 wpas_p2p_update_channel_list(wpa_s,
3995 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003996 }
3997#endif /* CONFIG_P2P */
3998
3999 os_free(str);
4000}
4001
4002
Roshan Pius3a1667e2018-07-03 15:17:14 -07004003static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004004{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004005 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
4006 wpa_supplicant_cancel_auth_timeout(wpa_s);
4007 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4008 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
4009 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
Hai Shalomc3565922019-10-28 11:58:20 -07004010 wpa_s->drv_authorized_port = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004011 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004012}
4013
4014
4015static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
4016 int freq)
4017{
4018 size_t i;
4019 int j;
4020
4021 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4022 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
4023
4024 for (j = 0; j < mode->num_channels; j++) {
4025 const struct hostapd_channel_data *chan;
4026
4027 chan = &mode->channels[j];
4028 if (chan->freq == freq)
4029 return chan->dfs_cac_ms;
4030 }
4031 }
4032
4033 return 0;
4034}
4035
4036
4037static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
4038 struct dfs_event *radar)
4039{
4040#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004041 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004042 wpas_ap_event_dfs_cac_started(wpa_s, radar);
4043 } else
4044#endif /* NEED_AP_MLME && CONFIG_AP */
4045 {
4046 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
4047
4048 cac_time /= 1000; /* convert from ms to sec */
4049 if (!cac_time)
4050 cac_time = 10 * 60; /* max timeout: 10 minutes */
4051
4052 /* Restart auth timeout: CAC time added to initial timeout */
4053 wpas_auth_timeout_restart(wpa_s, cac_time);
4054 }
4055}
4056
4057
4058static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
4059 struct dfs_event *radar)
4060{
4061#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004062 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004063 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
4064 } else
4065#endif /* NEED_AP_MLME && CONFIG_AP */
4066 {
4067 /* Restart auth timeout with original value after CAC is
4068 * finished */
4069 wpas_auth_timeout_restart(wpa_s, 0);
4070 }
4071}
4072
4073
4074static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4075 struct dfs_event *radar)
4076{
4077#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004078 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004079 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4080 } else
4081#endif /* NEED_AP_MLME && CONFIG_AP */
4082 {
4083 /* Restart auth timeout with original value after CAC is
4084 * aborted */
4085 wpas_auth_timeout_restart(wpa_s, 0);
4086 }
4087}
4088
4089
4090static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4091 union wpa_event_data *data)
4092{
4093 wpa_dbg(wpa_s, MSG_DEBUG,
4094 "Connection authorized by device, previous state %d",
4095 wpa_s->wpa_state);
4096
4097 wpa_supplicant_event_port_authorized(wpa_s);
4098
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004099 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4100 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004101 data->assoc_info.ptk_kck_len,
4102 data->assoc_info.ptk_kek,
4103 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004104#ifdef CONFIG_FILS
4105 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4106 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4107 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4108
4109 /* Update ERP next sequence number */
4110 eapol_sm_update_erp_next_seq_num(
4111 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4112
4113 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4114 /* Add the new PMK and PMKID to the PMKSA cache */
4115 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4116 data->assoc_info.fils_pmk,
4117 data->assoc_info.fils_pmk_len,
4118 data->assoc_info.fils_pmkid,
4119 wpa_s->bssid, fils_cache_id);
4120 } else if (data->assoc_info.fils_pmkid) {
4121 /* Update the current PMKSA used for this connection */
4122 pmksa_cache_set_current(wpa_s->wpa,
4123 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004124 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004125 }
4126 }
4127#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004128}
4129
4130
Roshan Pius3a1667e2018-07-03 15:17:14 -07004131static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4132 union wpa_event_data *data)
4133{
4134 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004135#ifdef CONFIG_MBO
4136 struct wpa_bss *reject_bss;
4137#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004138
4139 if (!bssid || is_zero_ether_addr(bssid))
4140 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004141#ifdef CONFIG_MBO
4142 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4143 reject_bss = wpa_s->current_bss;
4144 else
4145 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4146#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004147
4148 if (data->assoc_reject.bssid)
4149 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4150 "bssid=" MACSTR " status_code=%u%s%s%s",
4151 MAC2STR(data->assoc_reject.bssid),
4152 data->assoc_reject.status_code,
4153 data->assoc_reject.timed_out ? " timeout" : "",
4154 data->assoc_reject.timeout_reason ? "=" : "",
4155 data->assoc_reject.timeout_reason ?
4156 data->assoc_reject.timeout_reason : "");
4157 else
4158 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4159 "status_code=%u%s%s%s",
4160 data->assoc_reject.status_code,
4161 data->assoc_reject.timed_out ? " timeout" : "",
4162 data->assoc_reject.timeout_reason ? "=" : "",
4163 data->assoc_reject.timeout_reason ?
4164 data->assoc_reject.timeout_reason : "");
4165 wpa_s->assoc_status_code = data->assoc_reject.status_code;
4166 wpa_s->assoc_timed_out = data->assoc_reject.timed_out;
4167 wpas_notify_assoc_status_code(wpa_s);
4168
4169#ifdef CONFIG_OWE
4170 if (data->assoc_reject.status_code ==
4171 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4172 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4173 wpa_s->current_ssid &&
4174 wpa_s->current_ssid->owe_group == 0 &&
4175 wpa_s->last_owe_group != 21) {
4176 struct wpa_ssid *ssid = wpa_s->current_ssid;
4177 struct wpa_bss *bss = wpa_s->current_bss;
4178
4179 if (!bss) {
4180 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4181 if (!bss) {
4182 wpas_connection_failed(wpa_s, bssid);
4183 wpa_supplicant_mark_disassoc(wpa_s);
4184 return;
4185 }
4186 }
4187 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4188 wpas_connect_work_done(wpa_s);
4189 wpa_supplicant_mark_disassoc(wpa_s);
4190 wpa_supplicant_connect(wpa_s, bss, ssid);
4191 return;
4192 }
4193#endif /* CONFIG_OWE */
4194
Hai Shalom74f70d42019-02-11 14:42:39 -08004195#ifdef CONFIG_MBO
4196 if (data->assoc_reject.status_code ==
4197 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004198 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004199 const u8 *rssi_rej;
4200
4201 rssi_rej = mbo_get_attr_from_ies(
4202 data->assoc_reject.resp_ies,
4203 data->assoc_reject.resp_ies_len,
4204 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4205 if (rssi_rej && rssi_rej[1] == 2) {
4206 wpa_printf(MSG_DEBUG,
4207 "OCE: RSSI-based association rejection from "
4208 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004209 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004210 rssi_rej[2], rssi_rej[3]);
4211 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004212 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004213 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004214 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004215 }
4216 }
4217#endif /* CONFIG_MBO */
4218
Roshan Pius3a1667e2018-07-03 15:17:14 -07004219 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4220 sme_event_assoc_reject(wpa_s, data);
4221 return;
4222 }
4223
4224 /* Driver-based SME cases */
4225
4226#ifdef CONFIG_SAE
4227 if (wpa_s->current_ssid &&
4228 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4229 !data->assoc_reject.timed_out) {
4230 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4231 wpa_sm_aborted_cached(wpa_s->wpa);
4232 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4233 }
4234#endif /* CONFIG_SAE */
4235
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004236#ifdef CONFIG_DPP
4237 if (wpa_s->current_ssid &&
4238 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4239 !data->assoc_reject.timed_out) {
4240 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4241 wpa_sm_aborted_cached(wpa_s->wpa);
4242 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4243 }
4244#endif /* CONFIG_DPP */
4245
Roshan Pius3a1667e2018-07-03 15:17:14 -07004246#ifdef CONFIG_FILS
4247 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004248 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004249 eapol_sm_update_erp_next_seq_num(
4250 wpa_s->eapol,
4251 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004252 fils_connection_failure(wpa_s);
4253 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004254#endif /* CONFIG_FILS */
4255
4256 wpas_connection_failed(wpa_s, bssid);
4257 wpa_supplicant_mark_disassoc(wpa_s);
4258}
4259
4260
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004261void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4262 union wpa_event_data *data)
4263{
4264 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004265 int resched;
Hai Shalom74f70d42019-02-11 14:42:39 -08004266#ifndef CONFIG_NO_STDOUT_DEBUG
4267 int level = MSG_DEBUG;
4268#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004269
4270 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4271 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004272 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004273 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004274 event != EVENT_SCHED_SCAN_STOPPED) {
4275 wpa_dbg(wpa_s, MSG_DEBUG,
4276 "Ignore event %s (%d) while interface is disabled",
4277 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004278 return;
4279 }
4280
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004281#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07004282 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004283 const struct ieee80211_hdr *hdr;
4284 u16 fc;
4285 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4286 fc = le_to_host16(hdr->frame_control);
4287 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4288 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4289 level = MSG_EXCESSIVE;
4290 }
4291
4292 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4293 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004294#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004295
4296 switch (event) {
4297 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004298#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004299 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4300 data->auth.ies_len))
4301 wpa_printf(MSG_DEBUG,
4302 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004303#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004304 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004305 wpa_s->auth_status_code = data->auth.status_code;
4306 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004307 break;
4308 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004309#ifdef CONFIG_TESTING_OPTIONS
4310 if (wpa_s->ignore_auth_resp) {
4311 wpa_printf(MSG_INFO,
4312 "EVENT_ASSOC - ignore_auth_resp active!");
4313 break;
4314 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004315 if (wpa_s->testing_resend_assoc) {
4316 wpa_printf(MSG_INFO,
4317 "EVENT_DEAUTH - testing_resend_assoc");
4318 break;
4319 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004320#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004321 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004322 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004323 if (data &&
4324 (data->assoc_info.authorized ||
4325 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4326 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004327 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004328 if (data) {
4329 wpa_msg(wpa_s, MSG_INFO,
4330 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4331 data->assoc_info.subnet_status);
4332 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004333 break;
4334 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004335 wpas_event_disassoc(wpa_s,
4336 data ? &data->disassoc_info : NULL);
4337 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004338 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004339#ifdef CONFIG_TESTING_OPTIONS
4340 if (wpa_s->ignore_auth_resp) {
4341 wpa_printf(MSG_INFO,
4342 "EVENT_DEAUTH - ignore_auth_resp active!");
4343 break;
4344 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004345 if (wpa_s->testing_resend_assoc) {
4346 wpa_printf(MSG_INFO,
4347 "EVENT_DEAUTH - testing_resend_assoc");
4348 break;
4349 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004350#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004351 wpas_event_deauth(wpa_s,
4352 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004353 break;
4354 case EVENT_MICHAEL_MIC_FAILURE:
4355 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4356 break;
4357#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004358 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004359 if (wpa_s->own_scan_requested ||
4360 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004361 struct os_reltime diff;
4362
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004363 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004364 os_reltime_sub(&wpa_s->scan_start_time,
4365 &wpa_s->scan_trigger_time, &diff);
4366 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4367 diff.sec, diff.usec);
4368 wpa_s->own_scan_requested = 0;
4369 wpa_s->own_scan_running = 1;
4370 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4371 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004372 wpa_msg_ctrl(wpa_s, MSG_INFO,
4373 WPA_EVENT_SCAN_STARTED "id=%u",
4374 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004375 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004376 wpa_msg_ctrl(wpa_s, MSG_INFO,
4377 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004378 }
4379 } else {
4380 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004381 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004382 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004383 }
4384 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004385 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004386 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4387 wpa_s->scan_res_handler = NULL;
4388 wpa_s->own_scan_running = 0;
4389 wpa_s->radio->external_scan_running = 0;
4390 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4391 break;
4392 }
4393
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004394 if (!(data && data->scan_info.external_scan) &&
4395 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004396 struct os_reltime now, diff;
4397 os_get_reltime(&now);
4398 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4399 wpa_s->scan_start_time.sec = 0;
4400 wpa_s->scan_start_time.usec = 0;
4401 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4402 diff.sec, diff.usec);
4403 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004404 if (wpa_supplicant_event_scan_results(wpa_s, data))
4405 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004406 if (!(data && data->scan_info.external_scan))
4407 wpa_s->own_scan_running = 0;
4408 if (data && data->scan_info.nl_scan_event)
4409 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004410 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004411 break;
4412#endif /* CONFIG_NO_SCAN_PROCESSING */
4413 case EVENT_ASSOCINFO:
4414 wpa_supplicant_event_associnfo(wpa_s, data);
4415 break;
4416 case EVENT_INTERFACE_STATUS:
4417 wpa_supplicant_event_interface_status(wpa_s, data);
4418 break;
4419 case EVENT_PMKID_CANDIDATE:
4420 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4421 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004422#ifdef CONFIG_TDLS
4423 case EVENT_TDLS:
4424 wpa_supplicant_event_tdls(wpa_s, data);
4425 break;
4426#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004427#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004428 case EVENT_WNM:
4429 wpa_supplicant_event_wnm(wpa_s, data);
4430 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004431#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004432#ifdef CONFIG_IEEE80211R
4433 case EVENT_FT_RESPONSE:
4434 wpa_supplicant_event_ft_response(wpa_s, data);
4435 break;
4436#endif /* CONFIG_IEEE80211R */
4437#ifdef CONFIG_IBSS_RSN
4438 case EVENT_IBSS_RSN_START:
4439 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4440 break;
4441#endif /* CONFIG_IBSS_RSN */
4442 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004443 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004444 break;
4445 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004446 /* It is possible to get this event from earlier connection */
4447 if (wpa_s->current_ssid &&
4448 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4449 wpa_dbg(wpa_s, MSG_DEBUG,
4450 "Ignore AUTH_TIMED_OUT in mesh configuration");
4451 break;
4452 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004453 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4454 sme_event_auth_timed_out(wpa_s, data);
4455 break;
4456 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004457 /* It is possible to get this event from earlier connection */
4458 if (wpa_s->current_ssid &&
4459 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4460 wpa_dbg(wpa_s, MSG_DEBUG,
4461 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4462 break;
4463 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004464 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4465 sme_event_assoc_timed_out(wpa_s, data);
4466 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004467 case EVENT_TX_STATUS:
4468 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4469 " type=%d stype=%d",
4470 MAC2STR(data->tx_status.dst),
4471 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004472#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004473 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004474#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004475 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4476 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004477 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004478 wpa_s, data->tx_status.dst,
4479 data->tx_status.data,
4480 data->tx_status.data_len,
4481 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004482 OFFCHANNEL_SEND_ACTION_SUCCESS :
4483 OFFCHANNEL_SEND_ACTION_NO_ACK);
4484#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004485 break;
4486 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004487#endif /* CONFIG_AP */
4488#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004489 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004490 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004491 /*
4492 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004493 * interface in GO mode, or via standalone AP interface.
4494 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4495 * except when the primary interface is used as a GO interface
4496 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004497 */
4498 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4499 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004500 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004501 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004502 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004503 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004504 data->tx_status.data,
4505 data->tx_status.data_len,
4506 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004507 OFFCHANNEL_SEND_ACTION_SUCCESS :
4508 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004509 break;
4510 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004511#endif /* CONFIG_OFFCHANNEL */
4512#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004513 switch (data->tx_status.type) {
4514 case WLAN_FC_TYPE_MGMT:
4515 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4516 data->tx_status.data_len,
4517 data->tx_status.stype,
4518 data->tx_status.ack);
4519 break;
4520 case WLAN_FC_TYPE_DATA:
4521 ap_tx_status(wpa_s, data->tx_status.dst,
4522 data->tx_status.data,
4523 data->tx_status.data_len,
4524 data->tx_status.ack);
4525 break;
4526 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004527#endif /* CONFIG_AP */
4528 break;
4529#ifdef CONFIG_AP
4530 case EVENT_EAPOL_TX_STATUS:
4531 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4532 data->eapol_tx_status.data,
4533 data->eapol_tx_status.data_len,
4534 data->eapol_tx_status.ack);
4535 break;
4536 case EVENT_DRIVER_CLIENT_POLL_OK:
4537 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004538 break;
4539 case EVENT_RX_FROM_UNKNOWN:
4540 if (wpa_s->ap_iface == NULL)
4541 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004542 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4543 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004544 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004545#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07004546
4547 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07004548 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004549 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004550 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004551
Hai Shalom81f62d82019-07-22 12:10:00 -07004552 wpa_msg(wpa_s, MSG_INFO,
4553 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4554 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
4555 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004556 data->ch_switch.freq,
4557 data->ch_switch.ht_enabled,
4558 data->ch_switch.ch_offset,
4559 channel_width_to_string(data->ch_switch.ch_width),
4560 data->ch_switch.cf1,
4561 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07004562 if (event == EVENT_CH_SWITCH_STARTED)
4563 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004564
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004565 wpa_s->assoc_freq = data->ch_switch.freq;
4566 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4567
Roshan Pius3a1667e2018-07-03 15:17:14 -07004568#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004569 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4570 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08004571 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004572 wpa_s->current_ssid->mode ==
4573 WPAS_MODE_P2P_GROUP_FORMATION) {
4574 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4575 data->ch_switch.ht_enabled,
4576 data->ch_switch.ch_offset,
4577 data->ch_switch.ch_width,
4578 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07004579 data->ch_switch.cf2,
4580 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004581 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004582#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004583
Hai Shalom74f70d42019-02-11 14:42:39 -08004584 sme_event_ch_switch(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004585 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004586 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004587 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004588#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004589#ifdef NEED_AP_MLME
4590 case EVENT_DFS_RADAR_DETECTED:
4591 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004592 wpas_ap_event_dfs_radar_detected(wpa_s,
4593 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004594 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004595 case EVENT_DFS_NOP_FINISHED:
4596 if (data)
4597 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
4598 &data->dfs_event);
4599 break;
4600#endif /* NEED_AP_MLME */
4601#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004602 case EVENT_DFS_CAC_STARTED:
4603 if (data)
4604 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
4605 break;
4606 case EVENT_DFS_CAC_FINISHED:
4607 if (data)
4608 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
4609 break;
4610 case EVENT_DFS_CAC_ABORTED:
4611 if (data)
4612 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
4613 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004614 case EVENT_RX_MGMT: {
4615 u16 fc, stype;
4616 const struct ieee80211_mgmt *mgmt;
4617
Dmitry Shmidt818ea482014-03-10 13:15:21 -07004618#ifdef CONFIG_TESTING_OPTIONS
4619 if (wpa_s->ext_mgmt_frame_handling) {
4620 struct rx_mgmt *rx = &data->rx_mgmt;
4621 size_t hex_len = 2 * rx->frame_len + 1;
4622 char *hex = os_malloc(hex_len);
4623 if (hex) {
4624 wpa_snprintf_hex(hex, hex_len,
4625 rx->frame, rx->frame_len);
4626 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4627 rx->freq, rx->datarate, rx->ssi_signal,
4628 hex);
4629 os_free(hex);
4630 }
4631 break;
4632 }
4633#endif /* CONFIG_TESTING_OPTIONS */
4634
Dmitry Shmidt04949592012-07-19 12:16:46 -07004635 mgmt = (const struct ieee80211_mgmt *)
4636 data->rx_mgmt.frame;
4637 fc = le_to_host16(mgmt->frame_control);
4638 stype = WLAN_FC_GET_STYPE(fc);
4639
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004640#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004641 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004642#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004643#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004644 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004645 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004646 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07004647 const u8 *ie;
4648 size_t ie_len;
4649
4650 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4651 ie_len = data->rx_mgmt.frame_len -
4652 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004653 wpas_p2p_probe_req_rx(
4654 wpa_s, src, mgmt->da,
4655 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004656 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004657 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004658 break;
4659 }
4660#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004661#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004662 if (wpa_s->current_ssid &&
4663 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4664 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004665 data->rx_mgmt.frame_len >= 30) {
4666 wpa_supplicant_event_ibss_auth(wpa_s, data);
4667 break;
4668 }
4669#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004670
4671 if (stype == WLAN_FC_STYPE_ACTION) {
4672 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004673 wpa_s, data->rx_mgmt.frame,
4674 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004675 data->rx_mgmt.freq,
4676 data->rx_mgmt.ssi_signal);
4677 break;
4678 }
4679
4680 if (wpa_s->ifmsh) {
4681 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004682 break;
4683 }
4684
Roshan Pius3a1667e2018-07-03 15:17:14 -07004685#ifdef CONFIG_SAE
4686 if (stype == WLAN_FC_STYPE_AUTH &&
4687 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4688 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4689 sme_external_auth_mgmt_rx(
4690 wpa_s, data->rx_mgmt.frame,
4691 data->rx_mgmt.frame_len);
4692 break;
4693 }
4694#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004695 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
4696 "management frame in non-AP mode");
4697 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004698#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004699 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004700
4701 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004702 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4703 const u8 *ie;
4704 size_t ie_len;
4705
4706 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4707 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004708
4709 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
4710 mgmt->bssid, ie, ie_len,
4711 data->rx_mgmt.ssi_signal);
4712 }
4713
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004714 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004715#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004716 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004717 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004718 case EVENT_RX_PROBE_REQ:
4719 if (data->rx_probe_req.sa == NULL ||
4720 data->rx_probe_req.ie == NULL)
4721 break;
4722#ifdef CONFIG_AP
4723 if (wpa_s->ap_iface) {
4724 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
4725 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004726 data->rx_probe_req.da,
4727 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004728 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004729 data->rx_probe_req.ie_len,
4730 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004731 break;
4732 }
4733#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004734 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004735 data->rx_probe_req.da,
4736 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004737 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004738 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004739 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004740 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004741 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004742 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004743#ifdef CONFIG_OFFCHANNEL
4744 offchannel_remain_on_channel_cb(
4745 wpa_s, data->remain_on_channel.freq,
4746 data->remain_on_channel.duration);
4747#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004748 wpas_p2p_remain_on_channel_cb(
4749 wpa_s, data->remain_on_channel.freq,
4750 data->remain_on_channel.duration);
4751 break;
4752 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004753#ifdef CONFIG_OFFCHANNEL
4754 offchannel_cancel_remain_on_channel_cb(
4755 wpa_s, data->remain_on_channel.freq);
4756#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004757 wpas_p2p_cancel_remain_on_channel_cb(
4758 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004759#ifdef CONFIG_DPP
4760 wpas_dpp_cancel_remain_on_channel_cb(
4761 wpa_s, data->remain_on_channel.freq);
4762#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004763 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004764 case EVENT_EAPOL_RX:
4765 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
4766 data->eapol_rx.data,
4767 data->eapol_rx.data_len);
4768 break;
4769 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004770 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
4771 "above=%d signal=%d noise=%d txrate=%d",
4772 data->signal_change.above_threshold,
4773 data->signal_change.current_signal,
4774 data->signal_change.current_noise,
4775 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004776 wpa_bss_update_level(wpa_s->current_bss,
4777 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004778 bgscan_notify_signal_change(
4779 wpa_s, data->signal_change.above_threshold,
4780 data->signal_change.current_signal,
4781 data->signal_change.current_noise,
4782 data->signal_change.current_txrate);
4783 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004784 case EVENT_INTERFACE_MAC_CHANGED:
4785 wpa_supplicant_update_mac_addr(wpa_s);
4786 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004787 case EVENT_INTERFACE_ENABLED:
4788 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
4789 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004790 wpa_supplicant_update_mac_addr(wpa_s);
Hai Shalomc3565922019-10-28 11:58:20 -07004791 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004792 if (wpa_s->p2p_mgmt) {
4793 wpa_supplicant_set_state(wpa_s,
4794 WPA_DISCONNECTED);
4795 break;
4796 }
4797
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004798#ifdef CONFIG_AP
4799 if (!wpa_s->ap_iface) {
4800 wpa_supplicant_set_state(wpa_s,
4801 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004802 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004803 wpa_supplicant_req_scan(wpa_s, 0, 0);
4804 } else
4805 wpa_supplicant_set_state(wpa_s,
4806 WPA_COMPLETED);
4807#else /* CONFIG_AP */
4808 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
4809 wpa_supplicant_req_scan(wpa_s, 0, 0);
4810#endif /* CONFIG_AP */
4811 }
4812 break;
4813 case EVENT_INTERFACE_DISABLED:
4814 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004815#ifdef CONFIG_P2P
4816 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
4817 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
4818 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
4819 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004820 * Mark interface disabled if this happens to end up not
4821 * being removed as a separate P2P group interface.
4822 */
4823 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4824 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004825 * The interface was externally disabled. Remove
4826 * it assuming an external entity will start a
4827 * new session if needed.
4828 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004829 if (wpa_s->current_ssid &&
4830 wpa_s->current_ssid->p2p_group)
4831 wpas_p2p_interface_unavailable(wpa_s);
4832 else
4833 wpas_p2p_disconnect(wpa_s);
4834 /*
4835 * wpa_s instance may have been freed, so must not use
4836 * it here anymore.
4837 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004838 break;
4839 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004840 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
4841 p2p_in_progress(wpa_s->global->p2p) > 1) {
4842 /* This radio work will be cancelled, so clear P2P
4843 * state as well.
4844 */
4845 p2p_stop_find(wpa_s->global->p2p);
4846 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004847#endif /* CONFIG_P2P */
4848
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004849 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4850 /*
4851 * Indicate disconnection to keep ctrl_iface events
4852 * consistent.
4853 */
4854 wpa_supplicant_event_disassoc(
4855 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
4856 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004857 wpa_supplicant_mark_disassoc(wpa_s);
xshud0ee72f2018-11-08 14:37:01 -08004858 if (!wpa_s->conf->bss_no_flush_when_down)
4859 wpa_bss_flush(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08004860 radio_remove_works(wpa_s, NULL, 0);
4861
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004862 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4863 break;
4864 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004865 wpa_supplicant_update_channel_list(
4866 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004867 break;
4868 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004869 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004870 break;
4871 case EVENT_BEST_CHANNEL:
4872 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
4873 "(%d %d %d)",
4874 data->best_chan.freq_24, data->best_chan.freq_5,
4875 data->best_chan.freq_overall);
4876 wpa_s->best_24_freq = data->best_chan.freq_24;
4877 wpa_s->best_5_freq = data->best_chan.freq_5;
4878 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004879 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
4880 data->best_chan.freq_5,
4881 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004882 break;
4883 case EVENT_UNPROT_DEAUTH:
4884 wpa_supplicant_event_unprot_deauth(wpa_s,
4885 &data->unprot_deauth);
4886 break;
4887 case EVENT_UNPROT_DISASSOC:
4888 wpa_supplicant_event_unprot_disassoc(wpa_s,
4889 &data->unprot_disassoc);
4890 break;
4891 case EVENT_STATION_LOW_ACK:
4892#ifdef CONFIG_AP
4893 if (wpa_s->ap_iface && data)
4894 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
4895 data->low_ack.addr);
4896#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004897#ifdef CONFIG_TDLS
4898 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07004899 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
4900 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004901#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004902 break;
4903 case EVENT_IBSS_PEER_LOST:
4904#ifdef CONFIG_IBSS_RSN
4905 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
4906#endif /* CONFIG_IBSS_RSN */
4907 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004908 case EVENT_DRIVER_GTK_REKEY:
4909 if (os_memcmp(data->driver_gtk_rekey.bssid,
4910 wpa_s->bssid, ETH_ALEN))
4911 break;
4912 if (!wpa_s->wpa)
4913 break;
4914 wpa_sm_update_replay_ctr(wpa_s->wpa,
4915 data->driver_gtk_rekey.replay_ctr);
4916 break;
4917 case EVENT_SCHED_SCAN_STOPPED:
4918 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004919 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004920 wpa_supplicant_notify_scanning(wpa_s, 0);
4921
4922 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4923 break;
4924
4925 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004926 * If the driver stopped scanning without being requested to,
4927 * request a new scan to continue scanning for networks.
4928 */
4929 if (!wpa_s->sched_scan_stop_req &&
4930 wpa_s->wpa_state == WPA_SCANNING) {
4931 wpa_dbg(wpa_s, MSG_DEBUG,
4932 "Restart scanning after unexpected sched_scan stop event");
4933 wpa_supplicant_req_scan(wpa_s, 1, 0);
4934 break;
4935 }
4936
4937 wpa_s->sched_scan_stop_req = 0;
4938
4939 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08004940 * Start a new sched scan to continue searching for more SSIDs
4941 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004942 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07004943 if (wpa_s->sched_scan_timed_out) {
4944 wpa_supplicant_req_sched_scan(wpa_s);
4945 } else if (wpa_s->pno_sched_pending) {
4946 wpa_s->pno_sched_pending = 0;
4947 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004948 } else if (resched) {
4949 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08004950 }
4951
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004952 break;
4953 case EVENT_WPS_BUTTON_PUSHED:
4954#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07004955 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004956#endif /* CONFIG_WPS */
4957 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004958 case EVENT_AVOID_FREQUENCIES:
4959 wpa_supplicant_notify_avoid_freq(wpa_s, data);
4960 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004961 case EVENT_CONNECT_FAILED_REASON:
4962#ifdef CONFIG_AP
4963 if (!wpa_s->ap_iface || !data)
4964 break;
4965 hostapd_event_connect_failed_reason(
4966 wpa_s->ap_iface->bss[0],
4967 data->connect_failed_reason.addr,
4968 data->connect_failed_reason.code);
4969#endif /* CONFIG_AP */
4970 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004971 case EVENT_NEW_PEER_CANDIDATE:
4972#ifdef CONFIG_MESH
4973 if (!wpa_s->ifmsh || !data)
4974 break;
4975 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4976 data->mesh_peer.ies,
4977 data->mesh_peer.ie_len);
4978#endif /* CONFIG_MESH */
4979 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004980 case EVENT_SURVEY:
4981#ifdef CONFIG_AP
4982 if (!wpa_s->ap_iface)
4983 break;
4984 hostapd_event_get_survey(wpa_s->ap_iface,
4985 &data->survey_results);
4986#endif /* CONFIG_AP */
4987 break;
4988 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08004989#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004990#ifdef CONFIG_ACS
4991 if (!wpa_s->ap_iface)
4992 break;
4993 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4994 &data->acs_selected_channels);
4995#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08004996#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004997 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004998 case EVENT_P2P_LO_STOP:
4999#ifdef CONFIG_P2P
5000 wpa_s->p2p_lo_started = 0;
5001 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
5002 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
5003 data->p2p_lo_stop.reason_code);
5004#endif /* CONFIG_P2P */
5005 break;
Paul Stewart092955c2017-02-06 09:13:09 -08005006 case EVENT_BEACON_LOSS:
5007 if (!wpa_s->current_bss || !wpa_s->current_ssid)
5008 break;
5009 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
5010 bgscan_notify_beacon_loss(wpa_s);
5011 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07005012 case EVENT_EXTERNAL_AUTH:
5013#ifdef CONFIG_SAE
5014 if (!wpa_s->current_ssid) {
5015 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
5016 break;
5017 }
5018 sme_external_auth_trigger(wpa_s, data);
5019#endif /* CONFIG_SAE */
5020 break;
5021 case EVENT_PORT_AUTHORIZED:
5022 wpa_supplicant_event_port_authorized(wpa_s);
5023 break;
5024 case EVENT_STATION_OPMODE_CHANGED:
5025#ifdef CONFIG_AP
5026 if (!wpa_s->ap_iface || !data)
5027 break;
5028
5029 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
5030 data->sta_opmode.addr,
5031 data->sta_opmode.smps_mode,
5032 data->sta_opmode.chan_width,
5033 data->sta_opmode.rx_nss);
5034#endif /* CONFIG_AP */
5035 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005036 default:
5037 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
5038 break;
5039 }
5040}
Dmitry Shmidte4663042016-04-04 10:07:49 -07005041
5042
5043void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
5044 union wpa_event_data *data)
5045{
5046 struct wpa_supplicant *wpa_s;
5047
5048 if (event != EVENT_INTERFACE_STATUS)
5049 return;
5050
5051 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
5052 if (wpa_s && wpa_s->driver->get_ifindex) {
5053 unsigned int ifindex;
5054
5055 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
5056 if (ifindex != data->interface_status.ifindex) {
5057 wpa_dbg(wpa_s, MSG_DEBUG,
5058 "interface status ifindex %d mismatch (%d)",
5059 ifindex, data->interface_status.ifindex);
5060 return;
5061 }
5062 }
5063#ifdef CONFIG_MATCH_IFACE
5064 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
5065 struct wpa_interface *wpa_i;
5066
5067 wpa_i = wpa_supplicant_match_iface(
5068 ctx, data->interface_status.ifname);
5069 if (!wpa_i)
5070 return;
5071 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5072 os_free(wpa_i);
5073 if (wpa_s)
5074 wpa_s->matched = 1;
5075 }
5076#endif /* CONFIG_MATCH_IFACE */
5077
5078 if (wpa_s)
5079 wpa_supplicant_event(wpa_s, event, data);
5080}