blob: ef28ffeab3c0bf5884574bd9edb9e56227507b5e [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Paul Stewart092955c2017-02-06 09:13:09 -08003 * Copyright (c) 2003-2017, 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"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070032#include "crypto/random.h"
33#include "blacklist.h"
34#include "wpas_glue.h"
35#include "wps_supplicant.h"
36#include "ibss_rsn.h"
37#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080038#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070039#include "p2p_supplicant.h"
40#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070041#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "ap.h"
43#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080045#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070046#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080047#include "mesh.h"
48#include "mesh_mpm.h"
49#include "wmm_ac.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070050#include "dpp_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070051
52
Hai Shalom39ba6fc2019-01-22 12:40:38 -080053#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
54
55
Dmitry Shmidt34af3062013-07-11 10:46:32 -070056#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070057static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080058 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070059#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080060
61
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070062int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070063{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080064 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070065
66 if (ssid == NULL || ssid->disabled_until.sec == 0)
67 return 0;
68
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080069 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070070 if (ssid->disabled_until.sec > now.sec)
71 return ssid->disabled_until.sec - now.sec;
72
73 wpas_clear_temp_disabled(wpa_s, ssid, 0);
74
75 return 0;
76}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070077
78
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080079#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070080/**
81 * wpas_reenabled_network_time - Time until first network is re-enabled
82 * @wpa_s: Pointer to wpa_supplicant data
83 * Returns: If all enabled networks are temporarily disabled, returns the time
84 * (in sec) until the first network is re-enabled. Otherwise returns 0.
85 *
86 * This function is used in case all enabled networks are temporarily disabled,
87 * in which case it returns the time (in sec) that the first network will be
88 * re-enabled. The function assumes that at least one network is enabled.
89 */
90static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
91{
92 struct wpa_ssid *ssid;
93 int disabled_for, res = 0;
94
95#ifdef CONFIG_INTERWORKING
96 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
97 wpa_s->conf->cred)
98 return 0;
99#endif /* CONFIG_INTERWORKING */
100
101 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
102 if (ssid->disabled)
103 continue;
104
105 disabled_for = wpas_temp_disabled(wpa_s, ssid);
106 if (!disabled_for)
107 return 0;
108
109 if (!res || disabled_for < res)
110 res = disabled_for;
111 }
112
113 return res;
114}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800115#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700116
117
118void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
119{
120 struct wpa_supplicant *wpa_s = eloop_ctx;
121
122 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
123 return;
124
125 wpa_dbg(wpa_s, MSG_DEBUG,
126 "Try to associate due to network getting re-enabled");
127 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
128 wpa_supplicant_cancel_sched_scan(wpa_s);
129 wpa_supplicant_req_scan(wpa_s, 0, 0);
130 }
131}
132
133
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800134static struct wpa_bss * wpa_supplicant_get_new_bss(
135 struct wpa_supplicant *wpa_s, const u8 *bssid)
136{
137 struct wpa_bss *bss = NULL;
138 struct wpa_ssid *ssid = wpa_s->current_ssid;
139
140 if (ssid->ssid_len > 0)
141 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
142 if (!bss)
143 bss = wpa_bss_get_bssid(wpa_s, bssid);
144
145 return bss;
146}
147
148
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700149static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
150{
151 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
152
153 if (!bss) {
154 wpa_supplicant_update_scan_results(wpa_s);
155
156 /* Get the BSS from the new scan results */
157 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
158 }
159
160 if (bss)
161 wpa_s->current_bss = bss;
162}
163
164
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700165static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
166{
167 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700168 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700169 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700170 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700172 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
173 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700174
175 if (wpa_s->current_ssid->ssid_len == 0)
176 return 0; /* current profile still in use */
177 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
178 if (res < 0) {
179 wpa_msg(wpa_s, MSG_INFO,
180 "Failed to read SSID from driver");
181 return 0; /* try to use current profile */
182 }
183 drv_ssid_len = res;
184
185 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
186 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
187 drv_ssid_len) == 0)
188 return 0; /* current profile still in use */
189
190 wpa_msg(wpa_s, MSG_DEBUG,
191 "Driver-initiated BSS selection changed the SSID to %s",
192 wpa_ssid_txt(drv_ssid, drv_ssid_len));
193 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700194 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700195
196 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
197 "information");
198 ssid = wpa_supplicant_get_ssid(wpa_s);
199 if (ssid == NULL) {
200 wpa_msg(wpa_s, MSG_INFO,
201 "No network configuration found for the current AP");
202 return -1;
203 }
204
Dmitry Shmidt04949592012-07-19 12:16:46 -0700205 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700206 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
207 return -1;
208 }
209
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800210 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
211 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
212 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
213 return -1;
214 }
215
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700216 res = wpas_temp_disabled(wpa_s, ssid);
217 if (res > 0) {
218 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
219 "disabled for %d second(s)", res);
220 return -1;
221 }
222
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700223 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
224 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800225 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226 u8 wpa_ie[80];
227 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800228 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
229 wpa_ie, &wpa_ie_len) < 0)
230 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700231 } else {
232 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
233 }
234
235 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
236 eapol_sm_invalidate_cached_session(wpa_s->eapol);
237 old_ssid = wpa_s->current_ssid;
238 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800239
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700240 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800241
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
243 wpa_supplicant_initiate_eapol(wpa_s);
244 if (old_ssid != wpa_s->current_ssid)
245 wpas_notify_network_changed(wpa_s);
246
247 return 0;
248}
249
250
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800251void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700252{
253 struct wpa_supplicant *wpa_s = eloop_ctx;
254
255 if (wpa_s->countermeasures) {
256 wpa_s->countermeasures = 0;
257 wpa_drv_set_countermeasures(wpa_s, 0);
258 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800259
260 /*
261 * It is possible that the device is sched scanning, which means
262 * that a connection attempt will be done only when we receive
263 * scan results. However, in this case, it would be preferable
264 * to scan and connect immediately, so cancel the sched_scan and
265 * issue a regular scan flow.
266 */
267 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268 wpa_supplicant_req_scan(wpa_s, 0, 0);
269 }
270}
271
272
273void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
274{
275 int bssid_changed;
276
Dmitry Shmidt04949592012-07-19 12:16:46 -0700277 wnm_bss_keep_alive_deinit(wpa_s);
278
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700279#ifdef CONFIG_IBSS_RSN
280 ibss_rsn_deinit(wpa_s->ibss_rsn);
281 wpa_s->ibss_rsn = NULL;
282#endif /* CONFIG_IBSS_RSN */
283
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700284#ifdef CONFIG_AP
285 wpa_supplicant_ap_deinit(wpa_s);
286#endif /* CONFIG_AP */
287
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700288#ifdef CONFIG_HS20
289 /* Clear possibly configured frame filters */
290 wpa_drv_configure_frame_filters(wpa_s, 0);
291#endif /* CONFIG_HS20 */
292
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700293 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
294 return;
295
296 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
297 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
298 os_memset(wpa_s->bssid, 0, ETH_ALEN);
299 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800300 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301 wpa_s->current_bss = NULL;
302 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700303
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 if (bssid_changed)
305 wpas_notify_bssid_changed(wpa_s);
306
307 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
308 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700309 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
310 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
311 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
313 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700314 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700315 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700316 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800317
318 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800319 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800320 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700321
322#ifdef CONFIG_TESTING_OPTIONS
323 wpa_s->last_tk_alg = WPA_ALG_NONE;
324 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
325#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700326 wpa_s->ieee80211ac = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700327}
328
329
330static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
331{
332 struct wpa_ie_data ie;
333 int pmksa_set = -1;
334 size_t i;
335
336 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
337 ie.pmkid == NULL)
338 return;
339
340 for (i = 0; i < ie.num_pmkid; i++) {
341 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
342 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700343 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800345 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700346 break;
347 }
348 }
349
350 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
351 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
352}
353
354
355static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
356 union wpa_event_data *data)
357{
358 if (data == NULL) {
359 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
360 "event");
361 return;
362 }
363 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
364 " index=%d preauth=%d",
365 MAC2STR(data->pmkid_candidate.bssid),
366 data->pmkid_candidate.index,
367 data->pmkid_candidate.preauth);
368
369 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
370 data->pmkid_candidate.index,
371 data->pmkid_candidate.preauth);
372}
373
374
375static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
376{
377 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
378 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
379 return 0;
380
381#ifdef IEEE8021X_EAPOL
382 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
383 wpa_s->current_ssid &&
384 !(wpa_s->current_ssid->eapol_flags &
385 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
386 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
387 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
388 * plaintext or static WEP keys). */
389 return 0;
390 }
391#endif /* IEEE8021X_EAPOL */
392
393 return 1;
394}
395
396
397/**
398 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
399 * @wpa_s: pointer to wpa_supplicant data
400 * @ssid: Configuration data for the network
401 * Returns: 0 on success, -1 on failure
402 *
403 * This function is called when starting authentication with a network that is
404 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
405 */
406int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
407 struct wpa_ssid *ssid)
408{
409#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800410#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700411 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700412
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700413 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
414 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415 return 0;
416
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700417 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700418 sim = 1;
419 aka = 1;
420 } else {
421 struct eap_method_type *eap = ssid->eap.eap_methods;
422 while (eap->vendor != EAP_VENDOR_IETF ||
423 eap->method != EAP_TYPE_NONE) {
424 if (eap->vendor == EAP_VENDOR_IETF) {
425 if (eap->method == EAP_TYPE_SIM)
426 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700427 else if (eap->method == EAP_TYPE_AKA ||
428 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700429 aka = 1;
430 }
431 eap++;
432 }
433 }
434
435 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
436 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700437 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
438 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
439 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 aka = 0;
441
442 if (!sim && !aka) {
443 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
444 "use SIM, but neither EAP-SIM nor EAP-AKA are "
445 "enabled");
446 return 0;
447 }
448
449 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
450 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700452 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453 if (wpa_s->scard == NULL) {
454 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
455 "(pcsc-lite)");
456 return -1;
457 }
458 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
459 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800460#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700461#endif /* IEEE8021X_EAPOL */
462
463 return 0;
464}
465
466
467#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700468
469static int has_wep_key(struct wpa_ssid *ssid)
470{
471 int i;
472
473 for (i = 0; i < NUM_WEP_KEYS; i++) {
474 if (ssid->wep_key_len[i])
475 return 1;
476 }
477
478 return 0;
479}
480
481
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700482static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700483 struct wpa_ssid *ssid)
484{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700485 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700486
487 if (ssid->mixed_cell)
488 return 1;
489
490#ifdef CONFIG_WPS
491 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
492 return 1;
493#endif /* CONFIG_WPS */
494
Roshan Pius3a1667e2018-07-03 15:17:14 -0700495#ifdef CONFIG_OWE
496 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
497 return 1;
498#endif /* CONFIG_OWE */
499
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700500 if (has_wep_key(ssid))
501 privacy = 1;
502
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700503#ifdef IEEE8021X_EAPOL
504 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
505 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
506 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
507 privacy = 1;
508#endif /* IEEE8021X_EAPOL */
509
Jouni Malinen75ecf522011-06-27 15:19:46 -0700510 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
511 privacy = 1;
512
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800513 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
514 privacy = 1;
515
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516 if (bss->caps & IEEE80211_CAP_PRIVACY)
517 return privacy;
518 return !privacy;
519}
520
521
522static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
523 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800524 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700525{
526 struct wpa_ie_data ie;
527 int proto_match = 0;
528 const u8 *rsn_ie, *wpa_ie;
529 int ret;
530 int wep_ok;
531
532 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
533 if (ret >= 0)
534 return ret;
535
536 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
537 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
538 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
539 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
540 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
541
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700542 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700543 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544 proto_match++;
545
546 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800547 if (debug_print)
548 wpa_dbg(wpa_s, MSG_DEBUG,
549 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700550 break;
551 }
552
553 if (wep_ok &&
554 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
555 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800556 if (debug_print)
557 wpa_dbg(wpa_s, MSG_DEBUG,
558 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700559 return 1;
560 }
561
Roshan Pius3a1667e2018-07-03 15:17:14 -0700562 if (!(ie.proto & ssid->proto) &&
563 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800564 if (debug_print)
565 wpa_dbg(wpa_s, MSG_DEBUG,
566 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567 break;
568 }
569
570 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800571 if (debug_print)
572 wpa_dbg(wpa_s, MSG_DEBUG,
573 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574 break;
575 }
576
577 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800578 if (debug_print)
579 wpa_dbg(wpa_s, MSG_DEBUG,
580 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700581 break;
582 }
583
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700584 if (ssid->group_mgmt_cipher &&
585 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
586 if (debug_print)
587 wpa_dbg(wpa_s, MSG_DEBUG,
588 " skip RSN IE - group mgmt cipher mismatch");
589 break;
590 }
591
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800593 if (debug_print)
594 wpa_dbg(wpa_s, MSG_DEBUG,
595 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596 break;
597 }
598
599#ifdef CONFIG_IEEE80211W
600 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800601 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800602 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800603 if (debug_print)
604 wpa_dbg(wpa_s, MSG_DEBUG,
605 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700606 break;
607 }
608#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800609 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
610 wpas_get_ssid_pmf(wpa_s, ssid) ==
611 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800612 if (debug_print)
613 wpa_dbg(wpa_s, MSG_DEBUG,
614 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800615 break;
616 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800617#ifdef CONFIG_MBO
618 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
619 wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
620 wpas_get_ssid_pmf(wpa_s, ssid) !=
621 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800622 if (debug_print)
623 wpa_dbg(wpa_s, MSG_DEBUG,
624 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800625 break;
626 }
627#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700628
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800629 if (debug_print)
630 wpa_dbg(wpa_s, MSG_DEBUG,
631 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700632 return 1;
633 }
634
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700635#ifdef CONFIG_IEEE80211W
Roshan Pius3a1667e2018-07-03 15:17:14 -0700636 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
637 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800638 if (debug_print)
639 wpa_dbg(wpa_s, MSG_DEBUG,
640 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700641 return 0;
642 }
643#endif /* CONFIG_IEEE80211W */
644
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700645 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
647 proto_match++;
648
649 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800650 if (debug_print)
651 wpa_dbg(wpa_s, MSG_DEBUG,
652 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700653 break;
654 }
655
656 if (wep_ok &&
657 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
658 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800659 if (debug_print)
660 wpa_dbg(wpa_s, MSG_DEBUG,
661 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 return 1;
663 }
664
665 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800666 if (debug_print)
667 wpa_dbg(wpa_s, MSG_DEBUG,
668 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700669 break;
670 }
671
672 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800673 if (debug_print)
674 wpa_dbg(wpa_s, MSG_DEBUG,
675 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700676 break;
677 }
678
679 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800680 if (debug_print)
681 wpa_dbg(wpa_s, MSG_DEBUG,
682 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683 break;
684 }
685
686 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800687 if (debug_print)
688 wpa_dbg(wpa_s, MSG_DEBUG,
689 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690 break;
691 }
692
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800693 if (debug_print)
694 wpa_dbg(wpa_s, MSG_DEBUG,
695 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696 return 1;
697 }
698
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700699 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
700 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800701 if (debug_print)
702 wpa_dbg(wpa_s, MSG_DEBUG,
703 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700704 return 1;
705 }
706
Roshan Pius3a1667e2018-07-03 15:17:14 -0700707#ifdef CONFIG_OWE
708 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
709 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800710 if (wpa_s->owe_transition_select &&
711 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
712 ssid->owe_transition_bss_select_count + 1 <=
713 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
714 ssid->owe_transition_bss_select_count++;
715 if (debug_print)
716 wpa_dbg(wpa_s, MSG_DEBUG,
717 " skip OWE transition BSS (selection count %d does not exceed %d)",
718 ssid->owe_transition_bss_select_count,
719 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
720 wpa_s->owe_transition_search = 1;
721 return 0;
722 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700723 if (debug_print)
724 wpa_dbg(wpa_s, MSG_DEBUG,
725 " allow in OWE transition mode");
726 return 1;
727 }
728#endif /* CONFIG_OWE */
729
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
731 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800732 if (debug_print)
733 wpa_dbg(wpa_s, MSG_DEBUG,
734 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700735 return 0;
736 }
737
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800738 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
739 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800740 if (debug_print)
741 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800742 return 1;
743 }
744
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800746 if (debug_print)
747 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748 return 1;
749 }
750
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800751 if (debug_print)
752 wpa_dbg(wpa_s, MSG_DEBUG,
753 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754
755 return 0;
756}
757
758
759static int freq_allowed(int *freqs, int freq)
760{
761 int i;
762
763 if (freqs == NULL)
764 return 1;
765
766 for (i = 0; freqs[i]; i++)
767 if (freqs[i] == freq)
768 return 1;
769 return 0;
770}
771
772
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800773static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
774 int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800775{
776 const struct hostapd_hw_modes *mode = NULL, *modes;
777 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
778 const u8 *rate_ie;
779 int i, j, k;
780
781 if (bss->freq == 0)
782 return 1; /* Cannot do matching without knowing band */
783
784 modes = wpa_s->hw.modes;
785 if (modes == NULL) {
786 /*
787 * The driver does not provide any additional information
788 * about the utilized hardware, so allow the connection attempt
789 * to continue.
790 */
791 return 1;
792 }
793
794 for (i = 0; i < wpa_s->hw.num_modes; i++) {
795 for (j = 0; j < modes[i].num_channels; j++) {
796 int freq = modes[i].channels[j].freq;
797 if (freq == bss->freq) {
798 if (mode &&
799 mode->mode == HOSTAPD_MODE_IEEE80211G)
800 break; /* do not allow 802.11b replace
801 * 802.11g */
802 mode = &modes[i];
803 break;
804 }
805 }
806 }
807
808 if (mode == NULL)
809 return 0;
810
811 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700812 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800813 if (rate_ie == NULL)
814 continue;
815
816 for (j = 2; j < rate_ie[1] + 2; j++) {
817 int flagged = !!(rate_ie[j] & 0x80);
818 int r = (rate_ie[j] & 0x7f) * 5;
819
820 /*
821 * IEEE Std 802.11n-2009 7.3.2.2:
822 * The new BSS Membership selector value is encoded
823 * like a legacy basic rate, but it is not a rate and
824 * only indicates if the BSS members are required to
825 * support the mandatory features of Clause 20 [HT PHY]
826 * in order to join the BSS.
827 */
828 if (flagged && ((rate_ie[j] & 0x7f) ==
829 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
830 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800831 if (debug_print)
832 wpa_dbg(wpa_s, MSG_DEBUG,
833 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800834 return 0;
835 }
836 continue;
837 }
838
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700839 /* There's also a VHT selector for 802.11ac */
840 if (flagged && ((rate_ie[j] & 0x7f) ==
841 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
842 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800843 if (debug_print)
844 wpa_dbg(wpa_s, MSG_DEBUG,
845 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700846 return 0;
847 }
848 continue;
849 }
850
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800851 if (!flagged)
852 continue;
853
854 /* check for legacy basic rates */
855 for (k = 0; k < mode->num_rates; k++) {
856 if (mode->rates[k] == r)
857 break;
858 }
859 if (k == mode->num_rates) {
860 /*
861 * IEEE Std 802.11-2007 7.3.2.2 demands that in
862 * order to join a BSS all required rates
863 * have to be supported by the hardware.
864 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800865 if (debug_print)
866 wpa_dbg(wpa_s, MSG_DEBUG,
867 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
868 r / 10, r % 10,
869 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800870 return 0;
871 }
872 }
873 }
874
875 return 1;
876}
877
878
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800879/*
880 * Test whether BSS is in an ESS.
881 * This is done differently in DMG (60 GHz) and non-DMG bands
882 */
883static int bss_is_ess(struct wpa_bss *bss)
884{
885 if (bss_is_dmg(bss)) {
886 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
887 IEEE80211_CAP_DMG_AP;
888 }
889
890 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
891 IEEE80211_CAP_ESS);
892}
893
894
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800895static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
896{
897 size_t i;
898
899 for (i = 0; i < ETH_ALEN; i++) {
900 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
901 return 0;
902 }
903 return 1;
904}
905
906
907static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
908{
909 size_t i;
910
911 for (i = 0; i < num; i++) {
912 const u8 *a = list + i * ETH_ALEN * 2;
913 const u8 *m = a + ETH_ALEN;
914
915 if (match_mac_mask(a, addr, m))
916 return 1;
917 }
918 return 0;
919}
920
921
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700922static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
923 const u8 **ret_ssid, size_t *ret_ssid_len)
924{
925#ifdef CONFIG_OWE
926 const u8 *owe, *pos, *end, *bssid;
927 u8 ssid_len;
928 struct wpa_bss *open_bss;
929
930 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
931 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
932 return;
933
934 pos = owe + 6;
935 end = owe + 2 + owe[1];
936
937 if (end - pos < ETH_ALEN + 1)
938 return;
939 bssid = pos;
940 pos += ETH_ALEN;
941 ssid_len = *pos++;
942 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
943 return;
944
945 /* Match the profile SSID against the OWE transition mode SSID on the
946 * open network. */
947 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
948 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
949 *ret_ssid = pos;
950 *ret_ssid_len = ssid_len;
951
952 if (bss->ssid_len > 0)
953 return;
954
955 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
956 if (!open_bss)
957 return;
958 if (ssid_len != open_bss->ssid_len ||
959 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
960 wpa_dbg(wpa_s, MSG_DEBUG,
961 "OWE: transition mode SSID mismatch: %s",
962 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
963 return;
964 }
965
966 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
967 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
968 wpa_dbg(wpa_s, MSG_DEBUG,
969 "OWE: transition mode open BSS unexpected info");
970 return;
971 }
972
973 pos = owe + 6;
974 end = owe + 2 + owe[1];
975
976 if (end - pos < ETH_ALEN + 1)
977 return;
978 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
979 wpa_dbg(wpa_s, MSG_DEBUG,
980 "OWE: transition mode BSSID mismatch: " MACSTR,
981 MAC2STR(pos));
982 return;
983 }
984 pos += ETH_ALEN;
985 ssid_len = *pos++;
986 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
987 return;
988 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
989 wpa_ssid_txt(pos, ssid_len));
990 os_memcpy(bss->ssid, pos, ssid_len);
991 bss->ssid_len = ssid_len;
992#endif /* CONFIG_OWE */
993}
994
995
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800996struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
997 int i, struct wpa_bss *bss,
998 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800999 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001001 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002 int wpa;
1003 struct wpa_blacklist *e;
1004 const u8 *ie;
1005 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001006 int osen, rsn_osen = 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001007#ifdef CONFIG_MBO
1008 const u8 *assoc_disallow;
1009#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001010 const u8 *match_ssid;
1011 size_t match_ssid_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001012 struct wpa_ie_data data;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001014 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001015 wpa_ie_len = ie ? ie[1] : 0;
1016
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001017 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001018 rsn_ie_len = ie ? ie[1] : 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001019 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1020 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1021 rsn_osen = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001022
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001023 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1024 osen = ie != NULL;
1025
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001026 if (debug_print) {
1027 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1028 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1029 i, MAC2STR(bss->bssid),
1030 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1031 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1032 bss->freq,
1033 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1034 " wps" : "",
1035 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1036 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1037 ? " p2p" : "",
1038 osen ? " osen=1" : "");
1039 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040
1041 e = wpa_blacklist_get(wpa_s, bss->bssid);
1042 if (e) {
1043 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001044 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001045 /*
1046 * When only a single network is enabled, we can
1047 * trigger blacklisting on the first failure. This
1048 * should not be done with multiple enabled networks to
1049 * avoid getting forced to move into a worse ESS on
1050 * single error if there are no other BSSes of the
1051 * current ESS.
1052 */
1053 limit = 0;
1054 }
1055 if (e->count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001056 if (debug_print) {
1057 wpa_dbg(wpa_s, MSG_DEBUG,
1058 " skip - blacklisted (count=%d limit=%d)",
1059 e->count, limit);
1060 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061 return NULL;
1062 }
1063 }
1064
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001065 match_ssid = bss->ssid;
1066 match_ssid_len = bss->ssid_len;
1067 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1068
1069 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001070 if (debug_print)
1071 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001072 return NULL;
1073 }
1074
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001075 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001076 if (debug_print)
1077 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001078 return NULL;
1079 }
1080
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001081 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001082 if (debug_print)
1083 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001084 return NULL;
1085 }
1086
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
1088
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001089 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001090 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001091 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001092
Dmitry Shmidt04949592012-07-19 12:16:46 -07001093 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001094 if (debug_print)
1095 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001096 continue;
1097 }
1098
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001099 res = wpas_temp_disabled(wpa_s, ssid);
1100 if (res > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001101 if (debug_print)
1102 wpa_dbg(wpa_s, MSG_DEBUG,
1103 " skip - disabled temporarily for %d second(s)",
1104 res);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001105 continue;
1106 }
1107
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001108#ifdef CONFIG_WPS
1109 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001110 if (debug_print)
1111 wpa_dbg(wpa_s, MSG_DEBUG,
1112 " skip - blacklisted (WPS)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113 continue;
1114 }
1115
1116 if (wpa && ssid->ssid_len == 0 &&
1117 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1118 check_ssid = 0;
1119
1120 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1121 /* Only allow wildcard SSID match if an AP
1122 * advertises active WPS operation that matches
1123 * with our mode. */
1124 check_ssid = 1;
1125 if (ssid->ssid_len == 0 &&
1126 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1127 check_ssid = 0;
1128 }
1129#endif /* CONFIG_WPS */
1130
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001131 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1132 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1133 check_ssid = 0;
1134
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135 if (check_ssid &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001136 (match_ssid_len != ssid->ssid_len ||
1137 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001138 if (debug_print)
1139 wpa_dbg(wpa_s, MSG_DEBUG,
1140 " skip - SSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001141 continue;
1142 }
1143
1144 if (ssid->bssid_set &&
1145 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001146 if (debug_print)
1147 wpa_dbg(wpa_s, MSG_DEBUG,
1148 " skip - BSSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001149 continue;
1150 }
1151
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001152 /* check blacklist */
1153 if (ssid->num_bssid_blacklist &&
1154 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1155 ssid->num_bssid_blacklist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001156 if (debug_print)
1157 wpa_dbg(wpa_s, MSG_DEBUG,
1158 " skip - BSSID blacklisted");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001159 continue;
1160 }
1161
1162 /* if there is a whitelist, only accept those APs */
1163 if (ssid->num_bssid_whitelist &&
1164 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1165 ssid->num_bssid_whitelist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001166 if (debug_print)
1167 wpa_dbg(wpa_s, MSG_DEBUG,
1168 " skip - BSSID not in whitelist");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001169 continue;
1170 }
1171
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001172 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss,
1173 debug_print))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001174 continue;
1175
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001176 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001177 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1178 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001179 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001180 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001181 if (debug_print)
1182 wpa_dbg(wpa_s, MSG_DEBUG,
1183 " skip - non-WPA network not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 continue;
1185 }
1186
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001187 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1188 has_wep_key(ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001189 if (debug_print)
1190 wpa_dbg(wpa_s, MSG_DEBUG,
1191 " skip - ignore WPA/WPA2 AP for WEP network block");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001192 continue;
1193 }
1194
Roshan Pius3a1667e2018-07-03 15:17:14 -07001195 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen &&
1196 !rsn_osen) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001197 if (debug_print)
1198 wpa_dbg(wpa_s, MSG_DEBUG,
1199 " skip - non-OSEN network not allowed");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001200 continue;
1201 }
1202
Jouni Malinen75ecf522011-06-27 15:19:46 -07001203 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001204 if (debug_print)
1205 wpa_dbg(wpa_s, MSG_DEBUG,
1206 " skip - privacy mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207 continue;
1208 }
1209
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001210 if (ssid->mode != IEEE80211_MODE_MESH && !bss_is_ess(bss) &&
1211 !bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001212 if (debug_print)
1213 wpa_dbg(wpa_s, MSG_DEBUG,
1214 " skip - not ESS, PBSS, or MBSS");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001215 continue;
1216 }
1217
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001218 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001219 if (debug_print)
1220 wpa_dbg(wpa_s, MSG_DEBUG,
1221 " skip - PBSS mismatch (ssid %d bss %d)",
1222 ssid->pbss, bss_is_pbss(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223 continue;
1224 }
1225
1226 if (!freq_allowed(ssid->freq_list, bss->freq)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001227 if (debug_print)
1228 wpa_dbg(wpa_s, MSG_DEBUG,
1229 " skip - frequency not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230 continue;
1231 }
1232
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001233#ifdef CONFIG_MESH
1234 if (ssid->mode == IEEE80211_MODE_MESH && ssid->frequency > 0 &&
1235 ssid->frequency != bss->freq) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001236 if (debug_print)
1237 wpa_dbg(wpa_s, MSG_DEBUG,
1238 " skip - frequency not allowed (mesh)");
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001239 continue;
1240 }
1241#endif /* CONFIG_MESH */
1242
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001243 if (!rate_match(wpa_s, bss, debug_print)) {
1244 if (debug_print)
1245 wpa_dbg(wpa_s, MSG_DEBUG,
1246 " skip - rate sets do not match");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001247 continue;
1248 }
1249
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001250#ifndef CONFIG_IBSS_RSN
1251 if (ssid->mode == WPAS_MODE_IBSS &&
1252 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1253 WPA_KEY_MGMT_WPA_NONE))) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001254 if (debug_print)
1255 wpa_dbg(wpa_s, MSG_DEBUG,
1256 " skip - IBSS RSN not supported in the build");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001257 continue;
1258 }
1259#endif /* !CONFIG_IBSS_RSN */
1260
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001261#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001262 if (ssid->p2p_group &&
1263 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1264 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001265 if (debug_print)
1266 wpa_dbg(wpa_s, MSG_DEBUG,
1267 " skip - no P2P IE seen");
Dmitry Shmidt96571392013-10-14 12:54:46 -07001268 continue;
1269 }
1270
Dmitry Shmidt54605472013-11-08 11:10:19 -08001271 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1272 struct wpabuf *p2p_ie;
1273 u8 dev_addr[ETH_ALEN];
1274
1275 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1276 if (ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001277 if (debug_print)
1278 wpa_dbg(wpa_s, MSG_DEBUG,
1279 " skip - no P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001280 continue;
1281 }
1282 p2p_ie = wpa_bss_get_vendor_ie_multi(
1283 bss, P2P_IE_VENDOR_TYPE);
1284 if (p2p_ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001285 if (debug_print)
1286 wpa_dbg(wpa_s, MSG_DEBUG,
1287 " skip - could not fetch P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001288 continue;
1289 }
1290
1291 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1292 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1293 ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001294 if (debug_print)
1295 wpa_dbg(wpa_s, MSG_DEBUG,
1296 " skip - no matching GO P2P Device Address in P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001297 wpabuf_free(p2p_ie);
1298 continue;
1299 }
1300 wpabuf_free(p2p_ie);
1301 }
1302
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001303 /*
1304 * TODO: skip the AP if its P2P IE has Group Formation
1305 * bit set in the P2P Group Capability Bitmap and we
1306 * are not in Group Formation with that device.
1307 */
1308#endif /* CONFIG_P2P */
1309
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001310 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1311 {
1312 struct os_reltime diff;
1313
1314 os_reltime_sub(&wpa_s->scan_min_time,
1315 &bss->last_update, &diff);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001316 if (debug_print)
1317 wpa_dbg(wpa_s, MSG_DEBUG,
1318 " skip - scan result not recent enough (%u.%06u seconds too old)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001319 (unsigned int) diff.sec,
1320 (unsigned int) diff.usec);
1321 continue;
1322 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001323#ifdef CONFIG_MBO
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001324#ifdef CONFIG_TESTING_OPTIONS
1325 if (wpa_s->ignore_assoc_disallow)
1326 goto skip_assoc_disallow;
1327#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001328 assoc_disallow = wpas_mbo_get_bss_attr(
1329 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1330 if (assoc_disallow && assoc_disallow[1] >= 1) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001331 if (debug_print)
1332 wpa_dbg(wpa_s, MSG_DEBUG,
1333 " skip - MBO association disallowed (reason %u)",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001334 assoc_disallow[2]);
1335 continue;
1336 }
1337
1338 if (wpa_is_bss_tmp_disallowed(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001339 if (debug_print)
1340 wpa_dbg(wpa_s, MSG_DEBUG,
1341 " skip - MBO retry delay has not passed yet");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001342 continue;
1343 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001344#ifdef CONFIG_TESTING_OPTIONS
1345 skip_assoc_disallow:
1346#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001347#endif /* CONFIG_MBO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001348
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001349#ifdef CONFIG_DPP
1350 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1351 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1352 (!ssid->dpp_connector ||
1353 !ssid->dpp_netaccesskey ||
1354 !ssid->dpp_csign)) {
1355 if (debug_print)
1356 wpa_dbg(wpa_s, MSG_DEBUG,
1357 " skip - no PMKSA entry for DPP");
1358 continue;
1359 }
1360#endif /* CONFIG_DPP */
1361
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001362 /* Matching configuration found */
1363 return ssid;
1364 }
1365
1366 /* No matching configuration found */
1367 return NULL;
1368}
1369
1370
1371static struct wpa_bss *
1372wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001373 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001374 struct wpa_ssid **selected_ssid,
1375 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001376{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001377 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001378
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001379 if (wpa_s->current_ssid) {
1380 struct wpa_ssid *ssid;
1381
1382 wpa_dbg(wpa_s, MSG_DEBUG,
1383 "Scan results matching the currently selected network");
1384 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1385 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1386
1387 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1388 only_first_ssid, 0);
1389 if (ssid != wpa_s->current_ssid)
1390 continue;
1391 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1392 " freq=%d level=%d snr=%d est_throughput=%u",
1393 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1394 bss->snr, bss->est_throughput);
1395 }
1396 }
1397
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001398 if (only_first_ssid)
1399 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1400 group->id);
1401 else
1402 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1403 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001404
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001405 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1406 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001407
1408 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001409 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001410 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001411 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001412 if (!*selected_ssid)
1413 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1415 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001416 MAC2STR(bss->bssid),
1417 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1418 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001419 }
1420
1421 return NULL;
1422}
1423
1424
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001425struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1426 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427{
1428 struct wpa_bss *selected = NULL;
1429 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001430 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001431 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001432
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001433 if (wpa_s->last_scan_res == NULL ||
1434 wpa_s->last_scan_res_used == 0)
1435 return NULL; /* no scan results from last update */
1436
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001437 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001438 /* check that next_ssid is still valid */
1439 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1440 if (ssid == wpa_s->next_ssid)
1441 break;
1442 }
1443 next_ssid = ssid;
1444 wpa_s->next_ssid = NULL;
1445 }
1446
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001447 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001448 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1449 if (next_ssid && next_ssid->priority ==
1450 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001451 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001452 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001453 if (selected)
1454 break;
1455 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001456 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001457 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001458 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001459 if (selected)
1460 break;
1461 }
1462
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001463 if (selected == NULL && wpa_s->blacklist &&
1464 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001465 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1466 "blacklist and try again");
1467 wpa_blacklist_clear(wpa_s);
1468 wpa_s->blacklist_cleared++;
1469 } else if (selected == NULL)
1470 break;
1471 }
1472
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001473 ssid = *selected_ssid;
1474 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1475 !ssid->passphrase && !ssid->ext_psk) {
1476 const char *field_name, *txt = NULL;
1477
1478 wpa_dbg(wpa_s, MSG_DEBUG,
1479 "PSK/passphrase not yet available for the selected network");
1480
1481 wpas_notify_network_request(wpa_s, ssid,
1482 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1483
1484 field_name = wpa_supplicant_ctrl_req_to_string(
1485 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1486 if (field_name == NULL)
1487 return NULL;
1488
1489 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1490
1491 selected = NULL;
1492 }
1493
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001494 return selected;
1495}
1496
1497
1498static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1499 int timeout_sec, int timeout_usec)
1500{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001501 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001502 /*
1503 * No networks are enabled; short-circuit request so
1504 * we don't wait timeout seconds before transitioning
1505 * to INACTIVE state.
1506 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001507 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1508 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001509 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1510 return;
1511 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001512
1513 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001514 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1515}
1516
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001517
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001518int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001519 struct wpa_bss *selected,
1520 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001521{
1522 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1523 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1524 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001525 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001526#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001527 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1528 wpa_s->p2p_in_provisioning) {
1529 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1530 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001531 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001532 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001533#endif /* CONFIG_P2P */
1534
1535#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001536 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537 wpas_wps_cancel(wpa_s);
1538#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001539 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001540 }
1541
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001542 wpa_msg(wpa_s, MSG_DEBUG,
1543 "Considering connect request: reassociate: %d selected: "
1544 MACSTR " bssid: " MACSTR " pending: " MACSTR
1545 " wpa_state: %s ssid=%p current_ssid=%p",
1546 wpa_s->reassociate, MAC2STR(selected->bssid),
1547 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1548 wpa_supplicant_state_txt(wpa_s->wpa_state),
1549 ssid, wpa_s->current_ssid);
1550
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001551 /*
1552 * Do not trigger new association unless the BSSID has changed or if
1553 * reassociation is requested. If we are in process of associating with
1554 * the selected BSSID, do not trigger new attempt.
1555 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001556 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001557 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1558 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1559 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001560 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1561 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1562 0) ||
1563 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1564 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1566 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001567 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001568 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001569 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1570 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001571 wpa_supplicant_associate(wpa_s, selected, ssid);
1572 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001573 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1574 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001576
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001577 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001578}
1579
1580
1581static struct wpa_ssid *
1582wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1583{
1584 int prio;
1585 struct wpa_ssid *ssid;
1586
1587 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1588 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1589 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001590 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001591 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001592#ifndef CONFIG_IBSS_RSN
1593 if (ssid->mode == WPAS_MODE_IBSS &&
1594 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1595 WPA_KEY_MGMT_WPA_NONE))) {
1596 wpa_msg(wpa_s, MSG_INFO,
1597 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1598 wpa_ssid_txt(ssid->ssid,
1599 ssid->ssid_len));
1600 continue;
1601 }
1602#endif /* !CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001603 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001604 ssid->mode == IEEE80211_MODE_AP ||
1605 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001606 return ssid;
1607 }
1608 }
1609 return NULL;
1610}
1611
1612
1613/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1614 * on BSS added and BSS changed events */
1615static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001616 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001617{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001618 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001619
1620 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1621 return;
1622
Jouni Malinen87fd2792011-05-16 18:35:42 +03001623 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001624 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001625
Jouni Malinen87fd2792011-05-16 18:35:42 +03001626 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001627 if (ssid == NULL)
1628 continue;
1629
Jouni Malinen87fd2792011-05-16 18:35:42 +03001630 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001631 if (rsn == NULL)
1632 continue;
1633
Jouni Malinen87fd2792011-05-16 18:35:42 +03001634 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635 }
1636
1637}
1638
1639
1640static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1641 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001642 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001643{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001644 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001645#ifndef CONFIG_NO_ROAMING
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001646 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001647 int to_5ghz;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001648 int cur_est, sel_est;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001649#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001650
1651 if (wpa_s->reassociate)
1652 return 1; /* explicit request to reassociate */
1653 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1654 return 1; /* we are not associated; continue */
1655 if (wpa_s->current_ssid == NULL)
1656 return 1; /* unknown current SSID */
1657 if (wpa_s->current_ssid != ssid)
1658 return 1; /* different network block */
1659
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001660 if (wpas_driver_bss_selection(wpa_s))
1661 return 0; /* Driver-based roaming */
1662
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001663 if (wpa_s->current_ssid->ssid)
1664 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1665 wpa_s->current_ssid->ssid,
1666 wpa_s->current_ssid->ssid_len);
1667 if (!current_bss)
1668 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001669
1670 if (!current_bss)
1671 return 1; /* current BSS not seen in scan results */
1672
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001673 if (current_bss == selected)
1674 return 0;
1675
1676 if (selected->last_update_idx > current_bss->last_update_idx)
1677 return 1; /* current BSS not seen in the last scan */
1678
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001679#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001681 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001682 " freq=%d level=%d snr=%d est_throughput=%u",
1683 MAC2STR(current_bss->bssid),
1684 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001685 current_bss->snr, current_bss->est_throughput);
1686 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001687 " freq=%d level=%d snr=%d est_throughput=%u",
1688 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001689 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001690
1691 if (wpa_s->current_ssid->bssid_set &&
1692 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1693 0) {
1694 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1695 "has preferred BSSID");
1696 return 1;
1697 }
1698
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001699 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1700 wpa_dbg(wpa_s, MSG_DEBUG,
1701 "Allow reassociation - selected BSS has better estimated throughput");
1702 return 1;
1703 }
1704
Dmitry Shmidte4663042016-04-04 10:07:49 -07001705 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1706
1707 if (current_bss->level < 0 &&
1708 current_bss->level > selected->level + to_5ghz * 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001709 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1710 "signal level");
1711 return 0;
1712 }
1713
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001714 if (current_bss->est_throughput > selected->est_throughput + 5000) {
1715 wpa_dbg(wpa_s, MSG_DEBUG,
1716 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001717 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001718 }
1719
1720 cur_est = current_bss->est_throughput;
1721 sel_est = selected->est_throughput;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001722 min_diff = 2;
1723 if (current_bss->level < 0) {
1724 if (current_bss->level < -85)
1725 min_diff = 1;
1726 else if (current_bss->level < -80)
1727 min_diff = 2;
1728 else if (current_bss->level < -75)
1729 min_diff = 3;
1730 else if (current_bss->level < -70)
1731 min_diff = 4;
1732 else
1733 min_diff = 5;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001734 if (cur_est > sel_est * 1.5)
1735 min_diff += 10;
1736 else if (cur_est > sel_est * 1.2)
1737 min_diff += 5;
1738 else if (cur_est > sel_est * 1.1)
1739 min_diff += 2;
1740 else if (cur_est > sel_est)
1741 min_diff++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001742 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001743 if (to_5ghz) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001744 int reduce = 2;
1745
Dmitry Shmidte4663042016-04-04 10:07:49 -07001746 /* Make it easier to move to 5 GHz band */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001747 if (sel_est > cur_est * 1.5)
1748 reduce = 5;
1749 else if (sel_est > cur_est * 1.2)
1750 reduce = 4;
1751 else if (sel_est > cur_est * 1.1)
1752 reduce = 3;
1753
1754 if (min_diff > reduce)
1755 min_diff -= reduce;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001756 else
1757 min_diff = 0;
1758 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001759 diff = abs(current_bss->level - selected->level);
1760 if (diff < min_diff) {
1761 wpa_dbg(wpa_s, MSG_DEBUG,
1762 "Skip roam - too small difference in signal level (%d < %d)",
1763 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764 return 0;
1765 }
1766
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001767 wpa_dbg(wpa_s, MSG_DEBUG,
1768 "Allow reassociation due to difference in signal level (%d >= %d)",
1769 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001770 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001771#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001772 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001773#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001774}
1775
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001776
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001777/*
1778 * Return a negative value if no scan results could be fetched or if scan
1779 * results should not be shared with other virtual interfaces.
1780 * Return 0 if scan results were fetched and may be shared with other
1781 * interfaces.
1782 * Return 1 if scan results may be shared with other virtual interfaces but may
1783 * not trigger any operations.
1784 * Return 2 if the interface was removed and cannot be used.
1785 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001786static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001787 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001788 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001789{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001790 struct wpa_scan_results *scan_res = NULL;
1791 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001792 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001793#ifndef CONFIG_NO_RANDOM_POOL
1794 size_t i, num;
1795#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001796
1797#ifdef CONFIG_AP
1798 if (wpa_s->ap_iface)
1799 ap = 1;
1800#endif /* CONFIG_AP */
1801
1802 wpa_supplicant_notify_scanning(wpa_s, 0);
1803
1804 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1805 data ? &data->scan_info :
1806 NULL, 1);
1807 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001808 if (wpa_s->conf->ap_scan == 2 || ap ||
1809 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001811 if (!own_request)
1812 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001813 if (data && data->scan_info.external_scan)
1814 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001815 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1816 "scanning again");
1817 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001818 ret = -1;
1819 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 }
1821
1822#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823 num = scan_res->num;
1824 if (num > 10)
1825 num = 10;
1826 for (i = 0; i < num; i++) {
1827 u8 buf[5];
1828 struct wpa_scan_res *res = scan_res->res[i];
1829 buf[0] = res->bssid[5];
1830 buf[1] = res->qual & 0xff;
1831 buf[2] = res->noise & 0xff;
1832 buf[3] = res->level & 0xff;
1833 buf[4] = res->tsf & 0xff;
1834 random_add_randomness(buf, sizeof(buf));
1835 }
1836#endif /* CONFIG_NO_RANDOM_POOL */
1837
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001838 if (update_only) {
1839 ret = 1;
1840 goto scan_work_done;
1841 }
1842
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001843 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001844 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1846 struct wpa_scan_results *scan_res);
1847
1848 scan_res_handler = wpa_s->scan_res_handler;
1849 wpa_s->scan_res_handler = NULL;
1850 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001851 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001852 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001853 }
1854
1855 if (ap) {
1856 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1857#ifdef CONFIG_AP
1858 if (wpa_s->ap_iface->scan_cb)
1859 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1860#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001861 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001862 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001863
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001864 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001865 wpa_s->own_scan_running,
1866 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001867 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001868 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1869 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001870 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1871 wpa_s->manual_scan_id);
1872 wpa_s->manual_scan_use_id = 0;
1873 } else {
1874 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1875 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001876 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001877
1878 wpas_notify_scan_done(wpa_s, 1);
1879
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001880 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001881 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 -07001882 wpa_scan_results_free(scan_res);
1883 return 0;
1884 }
1885
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001886 if (wnm_scan_process(wpa_s, 1) > 0)
1887 goto scan_work_done;
1888
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001889 if (sme_proc_obss_scan(wpa_s) > 0)
1890 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001891
Dmitry Shmidt29333592017-01-09 12:27:11 -08001892 if (own_request &&
1893 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
1894 goto scan_work_done;
1895
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001896 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1897 goto scan_work_done;
1898
1899 if (autoscan_notify_scan(wpa_s, scan_res))
1900 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001901
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001902 if (wpa_s->disconnected) {
1903 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001904 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001905 }
1906
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001907 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001908 bgscan_notify_scan(wpa_s, scan_res) == 1)
1909 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001910
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001911 wpas_wps_update_ap_info(wpa_s, scan_res);
1912
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001913 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1914 wpa_s->wpa_state < WPA_COMPLETED)
1915 goto scan_work_done;
1916
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001917 wpa_scan_results_free(scan_res);
1918
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001919 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001920 struct wpa_radio_work *work = wpa_s->scan_work;
1921 wpa_s->scan_work = NULL;
1922 radio_work_done(work);
1923 }
1924
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001925 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001926
1927scan_work_done:
1928 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001929 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001930 struct wpa_radio_work *work = wpa_s->scan_work;
1931 wpa_s->scan_work = NULL;
1932 radio_work_done(work);
1933 }
1934 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001935}
1936
1937
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001938static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001939 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001940{
1941 struct wpa_bss *selected;
1942 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001943 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1944
1945 if (time_to_reenable > 0) {
1946 wpa_dbg(wpa_s, MSG_DEBUG,
1947 "Postpone network selection by %d seconds since all networks are disabled",
1948 time_to_reenable);
1949 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1950 eloop_register_timeout(time_to_reenable, 0,
1951 wpas_network_reenabled, wpa_s, NULL);
1952 return 0;
1953 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001954
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001955 if (wpa_s->p2p_mgmt)
1956 return 0; /* no normal connection on p2p_mgmt interface */
1957
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001958 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001959 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001960
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001961#ifdef CONFIG_MESH
1962 if (wpa_s->ifmsh) {
1963 wpa_msg(wpa_s, MSG_INFO,
1964 "Avoiding join because we already joined a mesh group");
1965 return 0;
1966 }
1967#endif /* CONFIG_MESH */
1968
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001969 if (selected) {
1970 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001971 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001972 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001973 if (new_scan)
1974 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001975 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001976 }
1977
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001978 if (ssid != wpa_s->current_ssid &&
1979 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1980 wpa_s->own_disconnect_req = 1;
1981 wpa_supplicant_deauthenticate(
1982 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1983 }
1984
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001985 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001986 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001987 return -1;
1988 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001989 if (new_scan)
1990 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001991 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001992 * Do not allow other virtual radios to trigger operations based
1993 * on these scan results since we do not want them to start
1994 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07001995 */
1996 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001997 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001998 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1999 ssid = wpa_supplicant_pick_new_network(wpa_s);
2000 if (ssid) {
2001 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2002 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002003 if (new_scan)
2004 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002005 } else if (own_request) {
2006 /*
2007 * No SSID found. If SCAN results are as a result of
2008 * own scan request and not due to a scan request on
2009 * another shared interface, try another scan.
2010 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002011 int timeout_sec = wpa_s->scan_interval;
2012 int timeout_usec = 0;
2013#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002014 int res;
2015
2016 res = wpas_p2p_scan_no_go_seen(wpa_s);
2017 if (res == 2)
2018 return 2;
2019 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002020 return 0;
2021
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002022 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002023 wpa_s->show_group_started ||
2024 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025 /*
2026 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002027 * state and during P2P join-a-group operation
2028 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002029 */
2030 timeout_sec = 0;
2031 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002032 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2033 timeout_usec);
2034 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002035 }
2036#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002037#ifdef CONFIG_INTERWORKING
2038 if (wpa_s->conf->auto_interworking &&
2039 wpa_s->conf->interworking &&
2040 wpa_s->conf->cred) {
2041 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2042 "start ANQP fetch since no matching "
2043 "networks found");
2044 wpa_s->network_select = 1;
2045 wpa_s->auto_network_select = 1;
2046 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002047 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002048 }
2049#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002050#ifdef CONFIG_WPS
2051 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2052 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2053 timeout_sec = 0;
2054 timeout_usec = 500000;
2055 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2056 timeout_usec);
2057 return 0;
2058 }
2059#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002060#ifdef CONFIG_OWE
2061 if (wpa_s->owe_transition_search) {
2062 wpa_dbg(wpa_s, MSG_DEBUG,
2063 "OWE: Use shorter wait during transition mode search");
2064 timeout_sec = 0;
2065 timeout_usec = 500000;
2066 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2067 timeout_usec);
2068 return 0;
2069 }
2070#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002071 if (wpa_supplicant_req_sched_scan(wpa_s))
2072 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2073 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002074
2075 wpa_msg_ctrl(wpa_s, MSG_INFO,
2076 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077 }
2078 }
2079 return 0;
2080}
2081
2082
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002083static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2084 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002085{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002086 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002087 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002088
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002089 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002090 if (res == 2) {
2091 /*
2092 * Interface may have been removed, so must not dereference
2093 * wpa_s after this.
2094 */
2095 return 1;
2096 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002097
2098 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002099 /*
2100 * If no scan results could be fetched, then no need to
2101 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002102 * this scan. Similarly, if scan results started a new operation on this
2103 * interface, do not notify other interfaces to avoid concurrent
2104 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002105 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002106 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002107 }
2108
2109 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002110 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002111 * so, they get updated with this same scan info.
2112 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002113 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2114 radio_list) {
2115 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002116 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2117 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002118 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2119 res > 0);
2120 if (res < 0)
2121 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002122 }
2123 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002124
2125 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126}
2127
2128#endif /* CONFIG_NO_SCAN_PROCESSING */
2129
2130
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002131int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2132{
2133#ifdef CONFIG_NO_SCAN_PROCESSING
2134 return -1;
2135#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002136 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002137
Dmitry Shmidt29333592017-01-09 12:27:11 -08002138 wpa_s->ignore_post_flush_scan_res = 0;
2139
Dmitry Shmidt41712582015-06-29 11:02:15 -07002140 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002141 return -1;
2142
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002143 os_get_reltime(&now);
2144 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002145 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2146 return -1;
2147 }
2148
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002149 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002150#endif /* CONFIG_NO_SCAN_PROCESSING */
2151}
2152
Dmitry Shmidt04949592012-07-19 12:16:46 -07002153#ifdef CONFIG_WNM
2154
2155static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2156{
2157 struct wpa_supplicant *wpa_s = eloop_ctx;
2158
2159 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2160 return;
2161
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002162 if (!wpa_s->no_keep_alive) {
2163 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2164 MAC2STR(wpa_s->bssid));
2165 /* TODO: could skip this if normal data traffic has been sent */
2166 /* TODO: Consider using some more appropriate data frame for
2167 * this */
2168 if (wpa_s->l2)
2169 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2170 (u8 *) "", 0);
2171 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002172
2173#ifdef CONFIG_SME
2174 if (wpa_s->sme.bss_max_idle_period) {
2175 unsigned int msec;
2176 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2177 if (msec > 100)
2178 msec -= 100;
2179 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2180 wnm_bss_keep_alive, wpa_s, NULL);
2181 }
2182#endif /* CONFIG_SME */
2183}
2184
2185
2186static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2187 const u8 *ies, size_t ies_len)
2188{
2189 struct ieee802_11_elems elems;
2190
2191 if (ies == NULL)
2192 return;
2193
2194 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2195 return;
2196
2197#ifdef CONFIG_SME
2198 if (elems.bss_max_idle_period) {
2199 unsigned int msec;
2200 wpa_s->sme.bss_max_idle_period =
2201 WPA_GET_LE16(elems.bss_max_idle_period);
2202 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2203 "TU)%s", wpa_s->sme.bss_max_idle_period,
2204 (elems.bss_max_idle_period[2] & 0x01) ?
2205 " (protected keep-live required)" : "");
2206 if (wpa_s->sme.bss_max_idle_period == 0)
2207 wpa_s->sme.bss_max_idle_period = 1;
2208 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2209 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2210 /* msec times 1000 */
2211 msec = wpa_s->sme.bss_max_idle_period * 1024;
2212 if (msec > 100)
2213 msec -= 100;
2214 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2215 wnm_bss_keep_alive, wpa_s,
2216 NULL);
2217 }
2218 }
2219#endif /* CONFIG_SME */
2220}
2221
2222#endif /* CONFIG_WNM */
2223
2224
2225void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2226{
2227#ifdef CONFIG_WNM
2228 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2229#endif /* CONFIG_WNM */
2230}
2231
2232
Dmitry Shmidt051af732013-10-22 13:52:46 -07002233#ifdef CONFIG_INTERWORKING
2234
2235static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2236 size_t len)
2237{
2238 int res;
2239
2240 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2241 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2242 if (res) {
2243 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2244 }
2245
2246 return res;
2247}
2248
2249
2250static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2251 const u8 *ies, size_t ies_len)
2252{
2253 struct ieee802_11_elems elems;
2254
2255 if (ies == NULL)
2256 return;
2257
2258 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2259 return;
2260
2261 if (elems.qos_map_set) {
2262 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2263 elems.qos_map_set_len);
2264 }
2265}
2266
2267#endif /* CONFIG_INTERWORKING */
2268
2269
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002270#ifdef CONFIG_FST
2271static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2272 const u8 *ie, size_t ie_len)
2273{
2274 struct mb_ies_info mb_ies;
2275
2276 if (!ie || !ie_len || !wpa_s->fst)
2277 return -ENOENT;
2278
2279 os_memset(&mb_ies, 0, sizeof(mb_ies));
2280
2281 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2282 size_t len;
2283
2284 len = 2 + ie[1];
2285 if (len > ie_len) {
2286 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2287 ie, ie_len);
2288 break;
2289 }
2290
2291 if (ie[0] == WLAN_EID_MULTI_BAND) {
2292 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2293 (unsigned int) len);
2294 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2295 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2296 mb_ies.nof_ies++;
2297 }
2298
2299 ie_len -= len;
2300 ie += len;
2301 }
2302
2303 if (mb_ies.nof_ies > 0) {
2304 wpabuf_free(wpa_s->received_mb_ies);
2305 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2306 return 0;
2307 }
2308
2309 return -ENOENT;
2310}
2311#endif /* CONFIG_FST */
2312
2313
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002314static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2315 union wpa_event_data *data)
2316{
2317 int l, len, found = 0, wpa_found, rsn_found;
2318 const u8 *p;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002319#if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002320 u8 bssid[ETH_ALEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -07002321#endif /* CONFIG_IEEE80211R || CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002322
2323 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
2324 if (data->assoc_info.req_ies)
2325 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2326 data->assoc_info.req_ies_len);
2327 if (data->assoc_info.resp_ies) {
2328 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2329 data->assoc_info.resp_ies_len);
2330#ifdef CONFIG_TDLS
2331 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2332 data->assoc_info.resp_ies_len);
2333#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002334#ifdef CONFIG_WNM
2335 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2336 data->assoc_info.resp_ies_len);
2337#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002338#ifdef CONFIG_INTERWORKING
2339 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2340 data->assoc_info.resp_ies_len);
2341#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002342 if (wpa_s->hw_capab == CAPAB_VHT &&
2343 get_ie(data->assoc_info.resp_ies,
2344 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2345 wpa_s->ieee80211ac = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002346 }
2347 if (data->assoc_info.beacon_ies)
2348 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2349 data->assoc_info.beacon_ies,
2350 data->assoc_info.beacon_ies_len);
2351 if (data->assoc_info.freq)
2352 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2353 data->assoc_info.freq);
2354
2355 p = data->assoc_info.req_ies;
2356 l = data->assoc_info.req_ies_len;
2357
2358 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2359 while (p && l >= 2) {
2360 len = p[1] + 2;
2361 if (len > l) {
2362 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2363 p, l);
2364 break;
2365 }
2366 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2367 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
Dmitry Shmidte4663042016-04-04 10:07:49 -07002368 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2369 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002370 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
2371 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2372 break;
2373 found = 1;
2374 wpa_find_assoc_pmkid(wpa_s);
2375 break;
2376 }
2377 l -= len;
2378 p += len;
2379 }
2380 if (!found && data->assoc_info.req_ies)
2381 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
2382
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002383#ifdef CONFIG_FILS
2384#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002385 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2386 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002387 (!data->assoc_info.resp_frame ||
2388 fils_process_assoc_resp(wpa_s->wpa,
2389 data->assoc_info.resp_frame,
2390 data->assoc_info.resp_frame_len) < 0)) {
2391 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2392 return -1;
2393 }
2394#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002395
2396 /* Additional processing for FILS when SME is in driver */
2397 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2398 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2399 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002400#endif /* CONFIG_FILS */
2401
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002402#ifdef CONFIG_OWE
2403 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
2404 (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2405 owe_process_assoc_resp(wpa_s->wpa, bssid,
2406 data->assoc_info.resp_ies,
2407 data->assoc_info.resp_ies_len) < 0)) {
2408 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2409 return -1;
2410 }
2411#endif /* CONFIG_OWE */
2412
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002413#ifdef CONFIG_IEEE80211R
2414#ifdef CONFIG_SME
2415 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002416 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2417 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2418 data->assoc_info.resp_ies,
2419 data->assoc_info.resp_ies_len,
2420 bssid) < 0) {
2421 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2422 "Reassociation Response failed");
2423 wpa_supplicant_deauthenticate(
2424 wpa_s, WLAN_REASON_INVALID_IE);
2425 return -1;
2426 }
2427 }
2428
2429 p = data->assoc_info.resp_ies;
2430 l = data->assoc_info.resp_ies_len;
2431
2432#ifdef CONFIG_WPS_STRICT
2433 if (p && wpa_s->current_ssid &&
2434 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2435 struct wpabuf *wps;
2436 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2437 if (wps == NULL) {
2438 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2439 "include WPS IE in (Re)Association Response");
2440 return -1;
2441 }
2442
2443 if (wps_validate_assoc_resp(wps) < 0) {
2444 wpabuf_free(wps);
2445 wpa_supplicant_deauthenticate(
2446 wpa_s, WLAN_REASON_INVALID_IE);
2447 return -1;
2448 }
2449 wpabuf_free(wps);
2450 }
2451#endif /* CONFIG_WPS_STRICT */
2452
2453 /* Go through the IEs and make a copy of the MDIE, if present. */
2454 while (p && l >= 2) {
2455 len = p[1] + 2;
2456 if (len > l) {
2457 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2458 p, l);
2459 break;
2460 }
2461 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2462 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2463 wpa_s->sme.ft_used = 1;
2464 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2465 MOBILITY_DOMAIN_ID_LEN);
2466 break;
2467 }
2468 l -= len;
2469 p += len;
2470 }
2471#endif /* CONFIG_SME */
2472
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002473 /* Process FT when SME is in the driver */
2474 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2475 wpa_ft_is_completed(wpa_s->wpa)) {
2476 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2477 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2478 data->assoc_info.resp_ies,
2479 data->assoc_info.resp_ies_len,
2480 bssid) < 0) {
2481 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2482 "Reassociation Response failed");
2483 wpa_supplicant_deauthenticate(
2484 wpa_s, WLAN_REASON_INVALID_IE);
2485 return -1;
2486 }
2487 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2488 }
2489
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002490 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2491 data->assoc_info.resp_ies_len);
2492#endif /* CONFIG_IEEE80211R */
2493
2494 /* WPA/RSN IE from Beacon/ProbeResp */
2495 p = data->assoc_info.beacon_ies;
2496 l = data->assoc_info.beacon_ies_len;
2497
2498 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2499 */
2500 wpa_found = rsn_found = 0;
2501 while (p && l >= 2) {
2502 len = p[1] + 2;
2503 if (len > l) {
2504 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2505 p, l);
2506 break;
2507 }
2508 if (!wpa_found &&
2509 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2510 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2511 wpa_found = 1;
2512 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2513 }
2514
2515 if (!rsn_found &&
2516 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2517 rsn_found = 1;
2518 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2519 }
2520
2521 l -= len;
2522 p += len;
2523 }
2524
2525 if (!wpa_found && data->assoc_info.beacon_ies)
2526 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2527 if (!rsn_found && data->assoc_info.beacon_ies)
2528 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2529 if (wpa_found || rsn_found)
2530 wpa_s->ap_ies_from_associnfo = 1;
2531
Jouni Malinen87fd2792011-05-16 18:35:42 +03002532 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2533 wpa_s->assoc_freq != data->assoc_info.freq) {
2534 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2535 "%u to %u MHz",
2536 wpa_s->assoc_freq, data->assoc_info.freq);
2537 wpa_supplicant_update_scan_results(wpa_s);
2538 }
2539
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002540 wpa_s->assoc_freq = data->assoc_info.freq;
2541
2542 return 0;
2543}
2544
2545
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002546static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2547{
2548 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2549
2550 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2551 return -1;
2552
2553 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2554 return 0;
2555
2556 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2557 WPA_IE_VENDOR_TYPE);
2558 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2559
2560 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2561 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2562 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2563 bss_rsn ? 2 + bss_rsn[1] : 0))
2564 return -1;
2565
2566 return 0;
2567}
2568
2569
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002570static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2571 union wpa_event_data *data)
2572{
2573#ifdef CONFIG_FST
2574 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2575 struct wpa_bss *bss = wpa_s->current_bss;
2576 const u8 *ieprb, *iebcn;
2577
2578 wpabuf_free(wpa_s->received_mb_ies);
2579 wpa_s->received_mb_ies = NULL;
2580
2581 if (ai &&
2582 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2583 wpa_printf(MSG_DEBUG,
2584 "FST: MB IEs updated from Association Response frame");
2585 return;
2586 }
2587
2588 if (ai &&
2589 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2590 wpa_printf(MSG_DEBUG,
2591 "FST: MB IEs updated from association event Beacon IEs");
2592 return;
2593 }
2594
2595 if (!bss)
2596 return;
2597
2598 ieprb = (const u8 *) (bss + 1);
2599 iebcn = ieprb + bss->ie_len;
2600
2601 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2602 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2603 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2604 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2605#endif /* CONFIG_FST */
2606}
2607
2608
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002609static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2610 union wpa_event_data *data)
2611{
2612 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002613 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002614 int new_bss = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002615
2616#ifdef CONFIG_AP
2617 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002618 if (!data)
2619 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002620 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2621 data->assoc_info.addr,
2622 data->assoc_info.req_ies,
2623 data->assoc_info.req_ies_len,
2624 data->assoc_info.reassoc);
2625 return;
2626 }
2627#endif /* CONFIG_AP */
2628
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002629 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2630
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002631 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2632 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2633 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002634 /*
2635 * FILS authentication can share the same mechanism to mark the
2636 * connection fully authenticated, so set ft_completed also based on
2637 * FILS result.
2638 */
2639 if (!ft_completed)
2640 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002641
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002642 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2643 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002644 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002645 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2646 return;
2647 }
2648
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002649 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002650 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002651 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2652 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002653 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002654 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002655 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2656 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002657 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002658
2659 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2660 wpa_clear_keys(wpa_s, bssid);
2661 }
2662 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002663 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002664 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2665 return;
2666 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002667 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002668
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002669 if (wpa_s->conf->ap_scan == 1 &&
2670 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002671 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2672 wpa_msg(wpa_s, MSG_WARNING,
2673 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002674 }
2675
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002676 wpas_fst_update_mb_assoc(wpa_s, data);
2677
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002678#ifdef CONFIG_SME
2679 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2680 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002681 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002682#endif /* CONFIG_SME */
2683
2684 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2685 if (wpa_s->current_ssid) {
2686 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2687 * initialized before association, but for other modes,
2688 * initialize PC/SC here, if the current configuration needs
2689 * smartcard or SIM/USIM. */
2690 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2691 }
2692 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2693 if (wpa_s->l2)
2694 l2_packet_notify_auth_start(wpa_s->l2);
2695
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002696 already_authorized = data && data->assoc_info.authorized;
2697
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002698 /*
2699 * Set portEnabled first to FALSE in order to get EAP state machine out
2700 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2701 * state machine may transit to AUTHENTICATING state based on obsolete
2702 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2703 * AUTHENTICATED without ever giving chance to EAP state machine to
2704 * reset the state.
2705 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002706 if (!ft_completed && !already_authorized) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002707 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2708 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2709 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002710 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
2711 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
2712 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002713 already_authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002714 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2715 /* 802.1X::portControl = Auto */
2716 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2717 wpa_s->eapol_received = 0;
2718 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2719 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2720 (wpa_s->current_ssid &&
2721 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002722 if (wpa_s->current_ssid &&
2723 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002724 (wpa_s->drv_flags &
2725 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2726 /*
2727 * Set the key after having received joined-IBSS event
2728 * from the driver.
2729 */
2730 wpa_supplicant_set_wpa_none_key(wpa_s,
2731 wpa_s->current_ssid);
2732 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733 wpa_supplicant_cancel_auth_timeout(wpa_s);
2734 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2735 } else if (!ft_completed) {
2736 /* Timeout for receiving the first EAPOL packet */
2737 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2738 }
2739 wpa_supplicant_cancel_scan(wpa_s);
2740
2741 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2742 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2743 /*
2744 * We are done; the driver will take care of RSN 4-way
2745 * handshake.
2746 */
2747 wpa_supplicant_cancel_auth_timeout(wpa_s);
2748 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2749 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2750 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2751 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2752 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2753 /*
2754 * The driver will take care of RSN 4-way handshake, so we need
2755 * to allow EAPOL supplicant to complete its work without
2756 * waiting for WPA supplicant.
2757 */
2758 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2759 } else if (ft_completed) {
2760 /*
2761 * FT protocol completed - make sure EAPOL state machine ends
2762 * up in authenticated.
2763 */
2764 wpa_supplicant_cancel_auth_timeout(wpa_s);
2765 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2766 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2767 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2768 }
2769
Jouni Malinena05074c2012-12-21 21:35:35 +02002770 wpa_s->last_eapol_matches_bssid = 0;
2771
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002772 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002773 struct os_reltime now, age;
2774 os_get_reltime(&now);
2775 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08002776 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002777 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2778 0) {
2779 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2780 "frame that was received just before "
2781 "association notification");
2782 wpa_supplicant_rx_eapol(
2783 wpa_s, wpa_s->pending_eapol_rx_src,
2784 wpabuf_head(wpa_s->pending_eapol_rx),
2785 wpabuf_len(wpa_s->pending_eapol_rx));
2786 }
2787 wpabuf_free(wpa_s->pending_eapol_rx);
2788 wpa_s->pending_eapol_rx = NULL;
2789 }
2790
2791 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2792 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002793 wpa_s->current_ssid &&
2794 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002795 /* Set static WEP keys again */
2796 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2797 }
2798
2799#ifdef CONFIG_IBSS_RSN
2800 if (wpa_s->current_ssid &&
2801 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2802 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2803 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2804 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002805 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002806 if (!wpa_s->ibss_rsn) {
2807 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2808 wpa_supplicant_deauthenticate(
2809 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2810 return;
2811 }
2812
2813 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2814 }
2815#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002816
2817 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002818
2819 if (data) {
2820 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2821 data->assoc_info.resp_ies_len,
2822 &data->assoc_info.wmm_params);
2823
2824 if (wpa_s->reassoc_same_bss)
2825 wmm_ac_restore_tspecs(wpa_s);
2826 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002827
2828#ifdef CONFIG_FILS
2829 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
2830 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid);
2831 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
2832
2833 if (fils_cache_id)
2834 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
2835 }
2836#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002837}
2838
2839
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002840static int disconnect_reason_recoverable(u16 reason_code)
2841{
2842 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2843 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2844 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2845}
2846
2847
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002848static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002849 u16 reason_code,
2850 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002851{
2852 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002853
2854 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2855 /*
2856 * At least Host AP driver and a Prism3 card seemed to be
2857 * generating streams of disconnected events when configuring
2858 * IBSS for WPA-None. Ignore them for now.
2859 */
2860 return;
2861 }
2862
2863 bssid = wpa_s->bssid;
2864 if (is_zero_ether_addr(bssid))
2865 bssid = wpa_s->pending_bssid;
2866
2867 if (!is_zero_ether_addr(bssid) ||
2868 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2869 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2870 " reason=%d%s",
2871 MAC2STR(bssid), reason_code,
2872 locally_generated ? " locally_generated=1" : "");
2873 }
2874}
2875
2876
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002877static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2878 int locally_generated)
2879{
2880 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2881 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2882 return 0; /* Not in 4-way handshake with PSK */
2883
2884 /*
2885 * It looks like connection was lost while trying to go through PSK
2886 * 4-way handshake. Filter out known disconnection cases that are caused
2887 * by something else than PSK mismatch to avoid confusing reports.
2888 */
2889
2890 if (locally_generated) {
2891 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2892 return 0;
2893 }
2894
2895 return 1;
2896}
2897
2898
Jouni Malinen2b89da82012-08-31 22:04:41 +03002899static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2900 u16 reason_code,
2901 int locally_generated)
2902{
2903 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904 int authenticating;
2905 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002906 struct wpa_bss *fast_reconnect = NULL;
2907 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002908 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002909 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002910
2911 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2912 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2913
2914 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2915 /*
2916 * At least Host AP driver and a Prism3 card seemed to be
2917 * generating streams of disconnected events when configuring
2918 * IBSS for WPA-None. Ignore them for now.
2919 */
2920 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2921 "IBSS/WPA-None mode");
2922 return;
2923 }
2924
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002925 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2926 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
2927 locally_generated)
2928 /*
2929 * Remove the inactive AP (which is probably out of range) from
2930 * the BSS list after marking disassociation. In particular
2931 * mac80211-based drivers use the
2932 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2933 * locally generated disconnection events for cases where the
2934 * AP does not reply anymore.
2935 */
2936 curr = wpa_s->current_bss;
2937
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002938 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002939 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2940 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002941 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2942 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002943 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002944 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002945 if (!wpa_s->disconnected &&
2946 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002947 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002948 wpas_wps_searching(wpa_s) ||
2949 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002950 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002951 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002952 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002953 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002954 wpa_s->wpa_state);
2955 if (wpa_s->wpa_state == WPA_COMPLETED &&
2956 wpa_s->current_ssid &&
2957 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002958 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002959 disconnect_reason_recoverable(reason_code)) {
2960 /*
2961 * It looks like the AP has dropped association with
2962 * us, but could allow us to get back in. Try to
2963 * reconnect to the same BSS without full scan to save
2964 * time for some common cases.
2965 */
2966 fast_reconnect = wpa_s->current_bss;
2967 fast_reconnect_ssid = wpa_s->current_ssid;
2968 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002969 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002970 else
2971 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2972 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002973 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002974 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002975 "try to re-connect");
2976 wpa_s->reassociate = 0;
2977 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002978 if (!wpa_s->pno)
2979 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002980 }
2981 bssid = wpa_s->bssid;
2982 if (is_zero_ether_addr(bssid))
2983 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002984 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2985 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002986 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002987 if (locally_generated)
2988 wpa_s->disconnect_reason = -reason_code;
2989 else
2990 wpa_s->disconnect_reason = reason_code;
2991 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002992 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2993 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002994 wpa_clear_keys(wpa_s, wpa_s->bssid);
2995 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002996 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002997 wpa_supplicant_mark_disassoc(wpa_s);
2998
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002999 if (curr)
3000 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3001
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003002 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003003 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003004 wpa_s->current_ssid = last_ssid;
3005 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003006
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003007 if (fast_reconnect &&
3008 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3009 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3010 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3011 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003012 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
3013 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect->bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003014#ifndef CONFIG_NO_SCAN_PROCESSING
3015 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3016 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3017 fast_reconnect_ssid) < 0) {
3018 /* Recover through full scan */
3019 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3020 }
3021#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003022 } else if (fast_reconnect) {
3023 /*
3024 * Could not reconnect to the same BSS due to network being
3025 * disabled. Use a new scan to match the alternative behavior
3026 * above, i.e., to continue automatic reconnection attempt in a
3027 * way that enforces disabled network rules.
3028 */
3029 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003030 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003031}
3032
3033
3034#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003035void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003036{
3037 struct wpa_supplicant *wpa_s = eloop_ctx;
3038
3039 if (!wpa_s->pending_mic_error_report)
3040 return;
3041
3042 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3043 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3044 wpa_s->pending_mic_error_report = 0;
3045}
3046#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3047
3048
3049static void
3050wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3051 union wpa_event_data *data)
3052{
3053 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003054 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003055
3056 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3057 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003058 os_get_reltime(&t);
3059 if ((wpa_s->last_michael_mic_error.sec &&
3060 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003061 wpa_s->pending_mic_error_report) {
3062 if (wpa_s->pending_mic_error_report) {
3063 /*
3064 * Send the pending MIC error report immediately since
3065 * we are going to start countermeasures and AP better
3066 * do the same.
3067 */
3068 wpa_sm_key_request(wpa_s->wpa, 1,
3069 wpa_s->pending_mic_error_pairwise);
3070 }
3071
3072 /* Send the new MIC error report immediately since we are going
3073 * to start countermeasures and AP better do the same.
3074 */
3075 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3076
3077 /* initialize countermeasures */
3078 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003079
3080 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3081
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003082 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3083
3084 /*
3085 * Need to wait for completion of request frame. We do not get
3086 * any callback for the message completion, so just wait a
3087 * short while and hope for the best. */
3088 os_sleep(0, 10000);
3089
3090 wpa_drv_set_countermeasures(wpa_s, 1);
3091 wpa_supplicant_deauthenticate(wpa_s,
3092 WLAN_REASON_MICHAEL_MIC_FAILURE);
3093 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3094 wpa_s, NULL);
3095 eloop_register_timeout(60, 0,
3096 wpa_supplicant_stop_countermeasures,
3097 wpa_s, NULL);
3098 /* TODO: mark the AP rejected for 60 second. STA is
3099 * allowed to associate with another AP.. */
3100 } else {
3101#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3102 if (wpa_s->mic_errors_seen) {
3103 /*
3104 * Reduce the effectiveness of Michael MIC error
3105 * reports as a means for attacking against TKIP if
3106 * more than one MIC failure is noticed with the same
3107 * PTK. We delay the transmission of the reports by a
3108 * random time between 0 and 60 seconds in order to
3109 * force the attacker wait 60 seconds before getting
3110 * the information on whether a frame resulted in a MIC
3111 * failure.
3112 */
3113 u8 rval[4];
3114 int sec;
3115
3116 if (os_get_random(rval, sizeof(rval)) < 0)
3117 sec = os_random() % 60;
3118 else
3119 sec = WPA_GET_BE32(rval) % 60;
3120 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3121 "report %d seconds", sec);
3122 wpa_s->pending_mic_error_report = 1;
3123 wpa_s->pending_mic_error_pairwise = pairwise;
3124 eloop_cancel_timeout(
3125 wpa_supplicant_delayed_mic_error_report,
3126 wpa_s, NULL);
3127 eloop_register_timeout(
3128 sec, os_random() % 1000000,
3129 wpa_supplicant_delayed_mic_error_report,
3130 wpa_s, NULL);
3131 } else {
3132 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3133 }
3134#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3135 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3136#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3137 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003138 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003139 wpa_s->mic_errors_seen++;
3140}
3141
3142
3143#ifdef CONFIG_TERMINATE_ONLASTIF
3144static int any_interfaces(struct wpa_supplicant *head)
3145{
3146 struct wpa_supplicant *wpa_s;
3147
3148 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3149 if (!wpa_s->interface_removed)
3150 return 1;
3151 return 0;
3152}
3153#endif /* CONFIG_TERMINATE_ONLASTIF */
3154
3155
3156static void
3157wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3158 union wpa_event_data *data)
3159{
3160 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3161 return;
3162
3163 switch (data->interface_status.ievent) {
3164 case EVENT_INTERFACE_ADDED:
3165 if (!wpa_s->interface_removed)
3166 break;
3167 wpa_s->interface_removed = 0;
3168 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3169 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3170 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3171 "driver after interface was added");
3172 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003173
3174#ifdef CONFIG_P2P
3175 if (!wpa_s->global->p2p &&
3176 !wpa_s->global->p2p_disabled &&
3177 !wpa_s->conf->p2p_disabled &&
3178 (wpa_s->drv_flags &
3179 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3180 wpas_p2p_add_p2pdev_interface(
3181 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3182 wpa_printf(MSG_INFO,
3183 "P2P: Failed to enable P2P Device interface");
3184 /* Try to continue without. P2P will be disabled. */
3185 }
3186#endif /* CONFIG_P2P */
3187
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003188 break;
3189 case EVENT_INTERFACE_REMOVED:
3190 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3191 wpa_s->interface_removed = 1;
3192 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003193 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003194 l2_packet_deinit(wpa_s->l2);
3195 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003196
3197#ifdef CONFIG_P2P
3198 if (wpa_s->global->p2p &&
3199 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3200 (wpa_s->drv_flags &
3201 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3202 wpa_dbg(wpa_s, MSG_DEBUG,
3203 "Removing P2P Device interface");
3204 wpa_supplicant_remove_iface(
3205 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3206 0);
3207 wpa_s->global->p2p_init_wpa_s = NULL;
3208 }
3209#endif /* CONFIG_P2P */
3210
Dmitry Shmidte4663042016-04-04 10:07:49 -07003211#ifdef CONFIG_MATCH_IFACE
3212 if (wpa_s->matched) {
3213 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3214 break;
3215 }
3216#endif /* CONFIG_MATCH_IFACE */
3217
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003218#ifdef CONFIG_TERMINATE_ONLASTIF
3219 /* check if last interface */
3220 if (!any_interfaces(wpa_s->global->ifaces))
3221 eloop_terminate();
3222#endif /* CONFIG_TERMINATE_ONLASTIF */
3223 break;
3224 }
3225}
3226
3227
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003228#ifdef CONFIG_TDLS
3229static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3230 union wpa_event_data *data)
3231{
3232 if (data == NULL)
3233 return;
3234 switch (data->tdls.oper) {
3235 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003236 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3237 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3238 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3239 else
3240 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003241 break;
3242 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003243 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3244 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3245 data->tdls.reason_code);
3246 else
3247 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3248 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003249 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003250 case TDLS_REQUEST_DISCOVER:
3251 wpa_tdls_send_discovery_request(wpa_s->wpa,
3252 data->tdls.peer);
3253 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003254 }
3255}
3256#endif /* CONFIG_TDLS */
3257
3258
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003259#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003260static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3261 union wpa_event_data *data)
3262{
3263 if (data == NULL)
3264 return;
3265 switch (data->wnm.oper) {
3266 case WNM_OPER_SLEEP:
3267 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3268 "(action=%d, intval=%d)",
3269 data->wnm.sleep_action, data->wnm.sleep_intval);
3270 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003271 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003272 break;
3273 }
3274}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003275#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003276
3277
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003278#ifdef CONFIG_IEEE80211R
3279static void
3280wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3281 union wpa_event_data *data)
3282{
3283 if (data == NULL)
3284 return;
3285
3286 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3287 data->ft_ies.ies_len,
3288 data->ft_ies.ft_action,
3289 data->ft_ies.target_ap,
3290 data->ft_ies.ric_ies,
3291 data->ft_ies.ric_ies_len) < 0) {
3292 /* TODO: prevent MLME/driver from trying to associate? */
3293 }
3294}
3295#endif /* CONFIG_IEEE80211R */
3296
3297
3298#ifdef CONFIG_IBSS_RSN
3299static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3300 union wpa_event_data *data)
3301{
3302 struct wpa_ssid *ssid;
3303 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3304 return;
3305 if (data == NULL)
3306 return;
3307 ssid = wpa_s->current_ssid;
3308 if (ssid == NULL)
3309 return;
3310 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3311 return;
3312
3313 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3314}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003315
3316
3317static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3318 union wpa_event_data *data)
3319{
3320 struct wpa_ssid *ssid = wpa_s->current_ssid;
3321
3322 if (ssid == NULL)
3323 return;
3324
3325 /* check if the ssid is correctly configured as IBSS/RSN */
3326 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3327 return;
3328
3329 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3330 data->rx_mgmt.frame_len);
3331}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003332#endif /* CONFIG_IBSS_RSN */
3333
3334
3335#ifdef CONFIG_IEEE80211R
3336static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3337 size_t len)
3338{
3339 const u8 *sta_addr, *target_ap_addr;
3340 u16 status;
3341
3342 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3343 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3344 return; /* only SME case supported for now */
3345 if (len < 1 + 2 * ETH_ALEN + 2)
3346 return;
3347 if (data[0] != 2)
3348 return; /* Only FT Action Response is supported for now */
3349 sta_addr = data + 1;
3350 target_ap_addr = data + 1 + ETH_ALEN;
3351 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3352 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3353 MACSTR " TargetAP " MACSTR " status %u",
3354 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3355
3356 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3357 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3358 " in FT Action Response", MAC2STR(sta_addr));
3359 return;
3360 }
3361
3362 if (status) {
3363 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3364 "failure (status code %d)", status);
3365 /* TODO: report error to FT code(?) */
3366 return;
3367 }
3368
3369 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3370 len - (1 + 2 * ETH_ALEN + 2), 1,
3371 target_ap_addr, NULL, 0) < 0)
3372 return;
3373
3374#ifdef CONFIG_SME
3375 {
3376 struct wpa_bss *bss;
3377 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3378 if (bss)
3379 wpa_s->sme.freq = bss->freq;
3380 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3381 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3382 WLAN_AUTH_FT);
3383 }
3384#endif /* CONFIG_SME */
3385}
3386#endif /* CONFIG_IEEE80211R */
3387
3388
3389static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3390 struct unprot_deauth *e)
3391{
3392#ifdef CONFIG_IEEE80211W
3393 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3394 "dropped: " MACSTR " -> " MACSTR
3395 " (reason code %u)",
3396 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3397 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3398#endif /* CONFIG_IEEE80211W */
3399}
3400
3401
3402static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3403 struct unprot_disassoc *e)
3404{
3405#ifdef CONFIG_IEEE80211W
3406 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3407 "dropped: " MACSTR " -> " MACSTR
3408 " (reason code %u)",
3409 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3410 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3411#endif /* CONFIG_IEEE80211W */
3412}
3413
3414
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003415static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3416 u16 reason_code, int locally_generated,
3417 const u8 *ie, size_t ie_len, int deauth)
3418{
3419#ifdef CONFIG_AP
3420 if (wpa_s->ap_iface && addr) {
3421 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3422 return;
3423 }
3424
3425 if (wpa_s->ap_iface) {
3426 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3427 return;
3428 }
3429#endif /* CONFIG_AP */
3430
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003431 if (!locally_generated)
3432 wpa_s->own_disconnect_req = 0;
3433
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003434 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3435
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003436 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3437 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3438 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3439 eapol_sm_failed(wpa_s->eapol))) &&
3440 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003441 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003442
3443#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003444 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003445 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3446 locally_generated) > 0) {
3447 /*
3448 * The interface was removed, so cannot continue
3449 * processing any additional operations after this.
3450 */
3451 return;
3452 }
3453 }
3454#endif /* CONFIG_P2P */
3455
3456 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3457 locally_generated);
3458}
3459
3460
3461static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3462 struct disassoc_info *info)
3463{
3464 u16 reason_code = 0;
3465 int locally_generated = 0;
3466 const u8 *addr = NULL;
3467 const u8 *ie = NULL;
3468 size_t ie_len = 0;
3469
3470 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3471
3472 if (info) {
3473 addr = info->addr;
3474 ie = info->ie;
3475 ie_len = info->ie_len;
3476 reason_code = info->reason_code;
3477 locally_generated = info->locally_generated;
3478 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
3479 locally_generated ? " (locally generated)" : "");
3480 if (addr)
3481 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3482 MAC2STR(addr));
3483 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3484 ie, ie_len);
3485 }
3486
3487#ifdef CONFIG_AP
3488 if (wpa_s->ap_iface && info && info->addr) {
3489 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3490 return;
3491 }
3492
3493 if (wpa_s->ap_iface) {
3494 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3495 return;
3496 }
3497#endif /* CONFIG_AP */
3498
3499#ifdef CONFIG_P2P
3500 if (info) {
3501 wpas_p2p_disassoc_notif(
3502 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3503 locally_generated);
3504 }
3505#endif /* CONFIG_P2P */
3506
3507 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3508 sme_event_disassoc(wpa_s, info);
3509
3510 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3511 ie, ie_len, 0);
3512}
3513
3514
3515static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3516 struct deauth_info *info)
3517{
3518 u16 reason_code = 0;
3519 int locally_generated = 0;
3520 const u8 *addr = NULL;
3521 const u8 *ie = NULL;
3522 size_t ie_len = 0;
3523
3524 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3525
3526 if (info) {
3527 addr = info->addr;
3528 ie = info->ie;
3529 ie_len = info->ie_len;
3530 reason_code = info->reason_code;
3531 locally_generated = info->locally_generated;
3532 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3533 reason_code,
3534 locally_generated ? " (locally generated)" : "");
3535 if (addr) {
3536 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3537 MAC2STR(addr));
3538 }
3539 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3540 ie, ie_len);
3541 }
3542
3543 wpa_reset_ft_completed(wpa_s->wpa);
3544
3545 wpas_event_disconnect(wpa_s, addr, reason_code,
3546 locally_generated, ie, ie_len, 1);
3547}
3548
3549
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003550static const char * reg_init_str(enum reg_change_initiator init)
3551{
3552 switch (init) {
3553 case REGDOM_SET_BY_CORE:
3554 return "CORE";
3555 case REGDOM_SET_BY_USER:
3556 return "USER";
3557 case REGDOM_SET_BY_DRIVER:
3558 return "DRIVER";
3559 case REGDOM_SET_BY_COUNTRY_IE:
3560 return "COUNTRY_IE";
3561 case REGDOM_BEACON_HINT:
3562 return "BEACON_HINT";
3563 }
3564 return "?";
3565}
3566
3567
3568static const char * reg_type_str(enum reg_type type)
3569{
3570 switch (type) {
3571 case REGDOM_TYPE_UNKNOWN:
3572 return "UNKNOWN";
3573 case REGDOM_TYPE_COUNTRY:
3574 return "COUNTRY";
3575 case REGDOM_TYPE_WORLD:
3576 return "WORLD";
3577 case REGDOM_TYPE_CUSTOM_WORLD:
3578 return "CUSTOM_WORLD";
3579 case REGDOM_TYPE_INTERSECTION:
3580 return "INTERSECTION";
3581 }
3582 return "?";
3583}
3584
3585
3586static void wpa_supplicant_update_channel_list(
3587 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003588{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003589 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003590 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003591
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003592 /*
3593 * To allow backwards compatibility with higher level layers that
3594 * assumed the REGDOM_CHANGE event is sent over the initially added
3595 * interface. Find the highest parent of this interface and use it to
3596 * send the event.
3597 */
3598 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3599 ;
3600
3601 wpa_msg(ifs, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
Dmitry Shmidtc2817022014-07-02 10:32:10 -07003602 reg_init_str(info->initiator), reg_type_str(info->type),
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003603 info->alpha2[0] ? " alpha2=" : "",
3604 info->alpha2[0] ? info->alpha2 : "");
3605
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003606 if (wpa_s->drv_priv == NULL)
3607 return; /* Ignore event during drv initialization */
3608
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003609 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3610 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003611 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3612 ifs->ifname);
3613 free_hw_features(ifs);
3614 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003615 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003616
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003617 /* Restart PNO/sched_scan with updated channel list */
3618 if (ifs->pno) {
3619 wpas_stop_pno(ifs);
3620 wpas_start_pno(ifs);
3621 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
3622 wpa_dbg(ifs, MSG_DEBUG,
3623 "Channel list changed - restart sched_scan");
3624 wpas_scan_restart_sched_scan(ifs);
3625 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003626 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003627
3628 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003629}
3630
3631
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003632static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003633 const u8 *frame, size_t len, int freq,
3634 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003635{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003636 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003637 const u8 *payload;
3638 size_t plen;
3639 u8 category;
3640
3641 if (len < IEEE80211_HDRLEN + 2)
3642 return;
3643
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003644 mgmt = (const struct ieee80211_mgmt *) frame;
3645 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003646 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003647 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003648
3649 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3650 " Category=%u DataLen=%d freq=%d MHz",
3651 MAC2STR(mgmt->sa), category, (int) plen, freq);
3652
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003653 if (category == WLAN_ACTION_WMM) {
3654 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3655 return;
3656 }
3657
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003658#ifdef CONFIG_IEEE80211R
3659 if (category == WLAN_ACTION_FT) {
3660 ft_rx_action(wpa_s, payload, plen);
3661 return;
3662 }
3663#endif /* CONFIG_IEEE80211R */
3664
3665#ifdef CONFIG_IEEE80211W
3666#ifdef CONFIG_SME
3667 if (category == WLAN_ACTION_SA_QUERY) {
3668 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3669 return;
3670 }
3671#endif /* CONFIG_SME */
3672#endif /* CONFIG_IEEE80211W */
3673
3674#ifdef CONFIG_WNM
3675 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3676 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3677 return;
3678 }
3679#endif /* CONFIG_WNM */
3680
3681#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003682 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3683 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003684 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003685 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003686 payload, plen, freq) == 0)
3687 return;
3688#endif /* CONFIG_GAS */
3689
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003690#ifdef CONFIG_GAS_SERVER
3691 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3692 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3693 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
3694 mgmt->u.action.category,
3695 payload, plen, freq) == 0)
3696 return;
3697#endif /* CONFIG_GAS_SERVER */
3698
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003699#ifdef CONFIG_TDLS
3700 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3701 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3702 wpa_dbg(wpa_s, MSG_DEBUG,
3703 "TDLS: Received Discovery Response from " MACSTR,
3704 MAC2STR(mgmt->sa));
3705 return;
3706 }
3707#endif /* CONFIG_TDLS */
3708
3709#ifdef CONFIG_INTERWORKING
3710 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3711 payload[0] == QOS_QOS_MAP_CONFIG) {
3712 const u8 *pos = payload + 1;
3713 size_t qlen = plen - 1;
3714 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3715 MACSTR, MAC2STR(mgmt->sa));
3716 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3717 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3718 pos[1] <= qlen - 2 && pos[1] >= 16)
3719 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3720 return;
3721 }
3722#endif /* CONFIG_INTERWORKING */
3723
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003724 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003725 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
3726 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003727 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003728 payload + 1,
3729 plen - 1);
3730 return;
3731 }
3732
3733 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003734 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3735 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3736 return;
3737 }
3738
3739 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3740 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3741 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3742 payload + 1, plen - 1,
3743 rssi);
3744 return;
3745 }
3746
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003747#ifdef CONFIG_FST
3748 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3749 fst_rx_action(wpa_s->fst, mgmt, len);
3750 return;
3751 }
3752#endif /* CONFIG_FST */
3753
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003754#ifdef CONFIG_DPP
3755 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
3756 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
3757 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
3758 payload[4] == DPP_OUI_TYPE) {
3759 payload++;
3760 plen--;
3761 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
3762 return;
3763 }
3764#endif /* CONFIG_DPP */
3765
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003766 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3767 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003768 if (wpa_s->ifmsh)
3769 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003770}
3771
3772
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003773static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3774 union wpa_event_data *event)
3775{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003776 struct wpa_freq_range_list *list;
3777 char *str = NULL;
3778
3779 list = &event->freq_range;
3780
3781 if (list->num)
3782 str = freq_range_list_str(list);
3783 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3784 str ? str : "");
3785
3786#ifdef CONFIG_P2P
3787 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3788 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3789 __func__);
3790 } else {
3791 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003792
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003793 /*
3794 * The update channel flow will also take care of moving a GO
3795 * from the unsafe frequency if needed.
3796 */
3797 wpas_p2p_update_channel_list(wpa_s,
3798 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003799 }
3800#endif /* CONFIG_P2P */
3801
3802 os_free(str);
3803}
3804
3805
Roshan Pius3a1667e2018-07-03 15:17:14 -07003806static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003807{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003808 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3809 wpa_supplicant_cancel_auth_timeout(wpa_s);
3810 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3811 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3812 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3813 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003814}
3815
3816
3817static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
3818 int freq)
3819{
3820 size_t i;
3821 int j;
3822
3823 for (i = 0; i < wpa_s->hw.num_modes; i++) {
3824 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
3825
3826 for (j = 0; j < mode->num_channels; j++) {
3827 const struct hostapd_channel_data *chan;
3828
3829 chan = &mode->channels[j];
3830 if (chan->freq == freq)
3831 return chan->dfs_cac_ms;
3832 }
3833 }
3834
3835 return 0;
3836}
3837
3838
3839static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
3840 struct dfs_event *radar)
3841{
3842#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3843 if (wpa_s->ap_iface) {
3844 wpas_ap_event_dfs_cac_started(wpa_s, radar);
3845 } else
3846#endif /* NEED_AP_MLME && CONFIG_AP */
3847 {
3848 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
3849
3850 cac_time /= 1000; /* convert from ms to sec */
3851 if (!cac_time)
3852 cac_time = 10 * 60; /* max timeout: 10 minutes */
3853
3854 /* Restart auth timeout: CAC time added to initial timeout */
3855 wpas_auth_timeout_restart(wpa_s, cac_time);
3856 }
3857}
3858
3859
3860static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
3861 struct dfs_event *radar)
3862{
3863#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3864 if (wpa_s->ap_iface) {
3865 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
3866 } else
3867#endif /* NEED_AP_MLME && CONFIG_AP */
3868 {
3869 /* Restart auth timeout with original value after CAC is
3870 * finished */
3871 wpas_auth_timeout_restart(wpa_s, 0);
3872 }
3873}
3874
3875
3876static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
3877 struct dfs_event *radar)
3878{
3879#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3880 if (wpa_s->ap_iface) {
3881 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
3882 } else
3883#endif /* NEED_AP_MLME && CONFIG_AP */
3884 {
3885 /* Restart auth timeout with original value after CAC is
3886 * aborted */
3887 wpas_auth_timeout_restart(wpa_s, 0);
3888 }
3889}
3890
3891
3892static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3893 union wpa_event_data *data)
3894{
3895 wpa_dbg(wpa_s, MSG_DEBUG,
3896 "Connection authorized by device, previous state %d",
3897 wpa_s->wpa_state);
3898
3899 wpa_supplicant_event_port_authorized(wpa_s);
3900
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003901 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3902 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003903 data->assoc_info.ptk_kck_len,
3904 data->assoc_info.ptk_kek,
3905 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003906#ifdef CONFIG_FILS
3907 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
3908 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
3909 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3910
3911 /* Update ERP next sequence number */
3912 eapol_sm_update_erp_next_seq_num(
3913 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
3914
3915 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
3916 /* Add the new PMK and PMKID to the PMKSA cache */
3917 wpa_sm_pmksa_cache_add(wpa_s->wpa,
3918 data->assoc_info.fils_pmk,
3919 data->assoc_info.fils_pmk_len,
3920 data->assoc_info.fils_pmkid,
3921 wpa_s->bssid, fils_cache_id);
3922 } else if (data->assoc_info.fils_pmkid) {
3923 /* Update the current PMKSA used for this connection */
3924 pmksa_cache_set_current(wpa_s->wpa,
3925 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003926 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003927 }
3928 }
3929#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003930}
3931
3932
Roshan Pius3a1667e2018-07-03 15:17:14 -07003933static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
3934 union wpa_event_data *data)
3935{
3936 const u8 *bssid = data->assoc_reject.bssid;
3937
3938 if (!bssid || is_zero_ether_addr(bssid))
3939 bssid = wpa_s->pending_bssid;
3940
3941 if (data->assoc_reject.bssid)
3942 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3943 "bssid=" MACSTR " status_code=%u%s%s%s",
3944 MAC2STR(data->assoc_reject.bssid),
3945 data->assoc_reject.status_code,
3946 data->assoc_reject.timed_out ? " timeout" : "",
3947 data->assoc_reject.timeout_reason ? "=" : "",
3948 data->assoc_reject.timeout_reason ?
3949 data->assoc_reject.timeout_reason : "");
3950 else
3951 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3952 "status_code=%u%s%s%s",
3953 data->assoc_reject.status_code,
3954 data->assoc_reject.timed_out ? " timeout" : "",
3955 data->assoc_reject.timeout_reason ? "=" : "",
3956 data->assoc_reject.timeout_reason ?
3957 data->assoc_reject.timeout_reason : "");
3958 wpa_s->assoc_status_code = data->assoc_reject.status_code;
3959 wpa_s->assoc_timed_out = data->assoc_reject.timed_out;
3960 wpas_notify_assoc_status_code(wpa_s);
3961
3962#ifdef CONFIG_OWE
3963 if (data->assoc_reject.status_code ==
3964 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
3965 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
3966 wpa_s->current_ssid &&
3967 wpa_s->current_ssid->owe_group == 0 &&
3968 wpa_s->last_owe_group != 21) {
3969 struct wpa_ssid *ssid = wpa_s->current_ssid;
3970 struct wpa_bss *bss = wpa_s->current_bss;
3971
3972 if (!bss) {
3973 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
3974 if (!bss) {
3975 wpas_connection_failed(wpa_s, bssid);
3976 wpa_supplicant_mark_disassoc(wpa_s);
3977 return;
3978 }
3979 }
3980 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
3981 wpas_connect_work_done(wpa_s);
3982 wpa_supplicant_mark_disassoc(wpa_s);
3983 wpa_supplicant_connect(wpa_s, bss, ssid);
3984 return;
3985 }
3986#endif /* CONFIG_OWE */
3987
3988 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
3989 sme_event_assoc_reject(wpa_s, data);
3990 return;
3991 }
3992
3993 /* Driver-based SME cases */
3994
3995#ifdef CONFIG_SAE
3996 if (wpa_s->current_ssid &&
3997 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
3998 !data->assoc_reject.timed_out) {
3999 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4000 wpa_sm_aborted_cached(wpa_s->wpa);
4001 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4002 }
4003#endif /* CONFIG_SAE */
4004
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004005#ifdef CONFIG_DPP
4006 if (wpa_s->current_ssid &&
4007 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4008 !data->assoc_reject.timed_out) {
4009 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4010 wpa_sm_aborted_cached(wpa_s->wpa);
4011 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4012 }
4013#endif /* CONFIG_DPP */
4014
Roshan Pius3a1667e2018-07-03 15:17:14 -07004015#ifdef CONFIG_FILS
4016 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004017 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004018 eapol_sm_update_erp_next_seq_num(
4019 wpa_s->eapol,
4020 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004021 fils_connection_failure(wpa_s);
4022 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004023#endif /* CONFIG_FILS */
4024
4025 wpas_connection_failed(wpa_s, bssid);
4026 wpa_supplicant_mark_disassoc(wpa_s);
4027}
4028
4029
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004030void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4031 union wpa_event_data *data)
4032{
4033 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004034 int resched;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004035
4036 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4037 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004038 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004039 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004040 event != EVENT_SCHED_SCAN_STOPPED) {
4041 wpa_dbg(wpa_s, MSG_DEBUG,
4042 "Ignore event %s (%d) while interface is disabled",
4043 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004044 return;
4045 }
4046
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004047#ifndef CONFIG_NO_STDOUT_DEBUG
4048{
4049 int level = MSG_DEBUG;
4050
Dmitry Shmidt04949592012-07-19 12:16:46 -07004051 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004052 const struct ieee80211_hdr *hdr;
4053 u16 fc;
4054 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4055 fc = le_to_host16(hdr->frame_control);
4056 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4057 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4058 level = MSG_EXCESSIVE;
4059 }
4060
4061 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4062 event_to_string(event), event);
4063}
4064#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004065
4066 switch (event) {
4067 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004068#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004069 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4070 data->auth.ies_len))
4071 wpa_printf(MSG_DEBUG,
4072 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004073#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004074 sme_event_auth(wpa_s, data);
4075 break;
4076 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004077#ifdef CONFIG_TESTING_OPTIONS
4078 if (wpa_s->ignore_auth_resp) {
4079 wpa_printf(MSG_INFO,
4080 "EVENT_ASSOC - ignore_auth_resp active!");
4081 break;
4082 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004083 if (wpa_s->testing_resend_assoc) {
4084 wpa_printf(MSG_INFO,
4085 "EVENT_DEAUTH - testing_resend_assoc");
4086 break;
4087 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004088#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004089 wpa_supplicant_event_assoc(wpa_s, data);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004090 if (data &&
4091 (data->assoc_info.authorized ||
4092 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4093 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004094 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004095 if (data) {
4096 wpa_msg(wpa_s, MSG_INFO,
4097 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4098 data->assoc_info.subnet_status);
4099 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004100 break;
4101 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004102 wpas_event_disassoc(wpa_s,
4103 data ? &data->disassoc_info : NULL);
4104 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004105 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004106#ifdef CONFIG_TESTING_OPTIONS
4107 if (wpa_s->ignore_auth_resp) {
4108 wpa_printf(MSG_INFO,
4109 "EVENT_DEAUTH - ignore_auth_resp active!");
4110 break;
4111 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004112 if (wpa_s->testing_resend_assoc) {
4113 wpa_printf(MSG_INFO,
4114 "EVENT_DEAUTH - testing_resend_assoc");
4115 break;
4116 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004117#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004118 wpas_event_deauth(wpa_s,
4119 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004120 break;
4121 case EVENT_MICHAEL_MIC_FAILURE:
4122 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4123 break;
4124#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004125 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004126 if (wpa_s->own_scan_requested ||
4127 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004128 struct os_reltime diff;
4129
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004130 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004131 os_reltime_sub(&wpa_s->scan_start_time,
4132 &wpa_s->scan_trigger_time, &diff);
4133 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4134 diff.sec, diff.usec);
4135 wpa_s->own_scan_requested = 0;
4136 wpa_s->own_scan_running = 1;
4137 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4138 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004139 wpa_msg_ctrl(wpa_s, MSG_INFO,
4140 WPA_EVENT_SCAN_STARTED "id=%u",
4141 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004142 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004143 wpa_msg_ctrl(wpa_s, MSG_INFO,
4144 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004145 }
4146 } else {
4147 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004148 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004149 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004150 }
4151 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004152 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004153 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4154 wpa_s->scan_res_handler = NULL;
4155 wpa_s->own_scan_running = 0;
4156 wpa_s->radio->external_scan_running = 0;
4157 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4158 break;
4159 }
4160
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004161 if (!(data && data->scan_info.external_scan) &&
4162 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004163 struct os_reltime now, diff;
4164 os_get_reltime(&now);
4165 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4166 wpa_s->scan_start_time.sec = 0;
4167 wpa_s->scan_start_time.usec = 0;
4168 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4169 diff.sec, diff.usec);
4170 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004171 if (wpa_supplicant_event_scan_results(wpa_s, data))
4172 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004173 if (!(data && data->scan_info.external_scan))
4174 wpa_s->own_scan_running = 0;
4175 if (data && data->scan_info.nl_scan_event)
4176 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004177 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004178 break;
4179#endif /* CONFIG_NO_SCAN_PROCESSING */
4180 case EVENT_ASSOCINFO:
4181 wpa_supplicant_event_associnfo(wpa_s, data);
4182 break;
4183 case EVENT_INTERFACE_STATUS:
4184 wpa_supplicant_event_interface_status(wpa_s, data);
4185 break;
4186 case EVENT_PMKID_CANDIDATE:
4187 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4188 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004189#ifdef CONFIG_TDLS
4190 case EVENT_TDLS:
4191 wpa_supplicant_event_tdls(wpa_s, data);
4192 break;
4193#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004194#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004195 case EVENT_WNM:
4196 wpa_supplicant_event_wnm(wpa_s, data);
4197 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004198#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004199#ifdef CONFIG_IEEE80211R
4200 case EVENT_FT_RESPONSE:
4201 wpa_supplicant_event_ft_response(wpa_s, data);
4202 break;
4203#endif /* CONFIG_IEEE80211R */
4204#ifdef CONFIG_IBSS_RSN
4205 case EVENT_IBSS_RSN_START:
4206 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4207 break;
4208#endif /* CONFIG_IBSS_RSN */
4209 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004210 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004211 break;
4212 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004213 /* It is possible to get this event from earlier connection */
4214 if (wpa_s->current_ssid &&
4215 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4216 wpa_dbg(wpa_s, MSG_DEBUG,
4217 "Ignore AUTH_TIMED_OUT in mesh configuration");
4218 break;
4219 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004220 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4221 sme_event_auth_timed_out(wpa_s, data);
4222 break;
4223 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004224 /* It is possible to get this event from earlier connection */
4225 if (wpa_s->current_ssid &&
4226 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4227 wpa_dbg(wpa_s, MSG_DEBUG,
4228 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4229 break;
4230 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004231 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4232 sme_event_assoc_timed_out(wpa_s, data);
4233 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004234 case EVENT_TX_STATUS:
4235 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4236 " type=%d stype=%d",
4237 MAC2STR(data->tx_status.dst),
4238 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004239#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004240 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004241#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004242 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4243 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004244 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004245 wpa_s, data->tx_status.dst,
4246 data->tx_status.data,
4247 data->tx_status.data_len,
4248 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004249 OFFCHANNEL_SEND_ACTION_SUCCESS :
4250 OFFCHANNEL_SEND_ACTION_NO_ACK);
4251#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252 break;
4253 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004254#endif /* CONFIG_AP */
4255#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004256 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004257 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004258 /*
4259 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004260 * interface in GO mode, or via standalone AP interface.
4261 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4262 * except when the primary interface is used as a GO interface
4263 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004264 */
4265 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4266 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004267 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004268 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004269 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004270 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004271 data->tx_status.data,
4272 data->tx_status.data_len,
4273 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004274 OFFCHANNEL_SEND_ACTION_SUCCESS :
4275 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004276 break;
4277 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004278#endif /* CONFIG_OFFCHANNEL */
4279#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004280 switch (data->tx_status.type) {
4281 case WLAN_FC_TYPE_MGMT:
4282 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4283 data->tx_status.data_len,
4284 data->tx_status.stype,
4285 data->tx_status.ack);
4286 break;
4287 case WLAN_FC_TYPE_DATA:
4288 ap_tx_status(wpa_s, data->tx_status.dst,
4289 data->tx_status.data,
4290 data->tx_status.data_len,
4291 data->tx_status.ack);
4292 break;
4293 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004294#endif /* CONFIG_AP */
4295 break;
4296#ifdef CONFIG_AP
4297 case EVENT_EAPOL_TX_STATUS:
4298 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4299 data->eapol_tx_status.data,
4300 data->eapol_tx_status.data_len,
4301 data->eapol_tx_status.ack);
4302 break;
4303 case EVENT_DRIVER_CLIENT_POLL_OK:
4304 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004305 break;
4306 case EVENT_RX_FROM_UNKNOWN:
4307 if (wpa_s->ap_iface == NULL)
4308 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004309 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4310 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004311 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004312#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004313 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004314 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004315 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004316
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004317 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
4318 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4319 data->ch_switch.freq,
4320 data->ch_switch.ht_enabled,
4321 data->ch_switch.ch_offset,
4322 channel_width_to_string(data->ch_switch.ch_width),
4323 data->ch_switch.cf1,
4324 data->ch_switch.cf2);
4325
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004326 wpa_s->assoc_freq = data->ch_switch.freq;
4327 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4328
Roshan Pius3a1667e2018-07-03 15:17:14 -07004329#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004330 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4331 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
4332 wpa_s->current_ssid->mode ==
4333 WPAS_MODE_P2P_GROUP_FORMATION) {
4334 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4335 data->ch_switch.ht_enabled,
4336 data->ch_switch.ch_offset,
4337 data->ch_switch.ch_width,
4338 data->ch_switch.cf1,
4339 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004340 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004341#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004342
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004343 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004344 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004345 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004346#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004347#ifdef NEED_AP_MLME
4348 case EVENT_DFS_RADAR_DETECTED:
4349 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004350 wpas_ap_event_dfs_radar_detected(wpa_s,
4351 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004352 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004353 case EVENT_DFS_NOP_FINISHED:
4354 if (data)
4355 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
4356 &data->dfs_event);
4357 break;
4358#endif /* NEED_AP_MLME */
4359#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004360 case EVENT_DFS_CAC_STARTED:
4361 if (data)
4362 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
4363 break;
4364 case EVENT_DFS_CAC_FINISHED:
4365 if (data)
4366 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
4367 break;
4368 case EVENT_DFS_CAC_ABORTED:
4369 if (data)
4370 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
4371 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004372 case EVENT_RX_MGMT: {
4373 u16 fc, stype;
4374 const struct ieee80211_mgmt *mgmt;
4375
Dmitry Shmidt818ea482014-03-10 13:15:21 -07004376#ifdef CONFIG_TESTING_OPTIONS
4377 if (wpa_s->ext_mgmt_frame_handling) {
4378 struct rx_mgmt *rx = &data->rx_mgmt;
4379 size_t hex_len = 2 * rx->frame_len + 1;
4380 char *hex = os_malloc(hex_len);
4381 if (hex) {
4382 wpa_snprintf_hex(hex, hex_len,
4383 rx->frame, rx->frame_len);
4384 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4385 rx->freq, rx->datarate, rx->ssi_signal,
4386 hex);
4387 os_free(hex);
4388 }
4389 break;
4390 }
4391#endif /* CONFIG_TESTING_OPTIONS */
4392
Dmitry Shmidt04949592012-07-19 12:16:46 -07004393 mgmt = (const struct ieee80211_mgmt *)
4394 data->rx_mgmt.frame;
4395 fc = le_to_host16(mgmt->frame_control);
4396 stype = WLAN_FC_GET_STYPE(fc);
4397
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004398#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004399 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004400#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004401#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004402 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004403 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004404 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07004405 const u8 *ie;
4406 size_t ie_len;
4407
4408 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4409 ie_len = data->rx_mgmt.frame_len -
4410 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004411 wpas_p2p_probe_req_rx(
4412 wpa_s, src, mgmt->da,
4413 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004414 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004415 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004416 break;
4417 }
4418#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004419#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004420 if (wpa_s->current_ssid &&
4421 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4422 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004423 data->rx_mgmt.frame_len >= 30) {
4424 wpa_supplicant_event_ibss_auth(wpa_s, data);
4425 break;
4426 }
4427#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004428
4429 if (stype == WLAN_FC_STYPE_ACTION) {
4430 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004431 wpa_s, data->rx_mgmt.frame,
4432 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004433 data->rx_mgmt.freq,
4434 data->rx_mgmt.ssi_signal);
4435 break;
4436 }
4437
4438 if (wpa_s->ifmsh) {
4439 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004440 break;
4441 }
4442
Roshan Pius3a1667e2018-07-03 15:17:14 -07004443#ifdef CONFIG_SAE
4444 if (stype == WLAN_FC_STYPE_AUTH &&
4445 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4446 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4447 sme_external_auth_mgmt_rx(
4448 wpa_s, data->rx_mgmt.frame,
4449 data->rx_mgmt.frame_len);
4450 break;
4451 }
4452#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004453 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
4454 "management frame in non-AP mode");
4455 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004456#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004457 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004458
4459 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004460 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4461 const u8 *ie;
4462 size_t ie_len;
4463
4464 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4465 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004466
4467 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
4468 mgmt->bssid, ie, ie_len,
4469 data->rx_mgmt.ssi_signal);
4470 }
4471
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004472 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004473#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004474 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004475 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004476 case EVENT_RX_PROBE_REQ:
4477 if (data->rx_probe_req.sa == NULL ||
4478 data->rx_probe_req.ie == NULL)
4479 break;
4480#ifdef CONFIG_AP
4481 if (wpa_s->ap_iface) {
4482 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
4483 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004484 data->rx_probe_req.da,
4485 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004486 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004487 data->rx_probe_req.ie_len,
4488 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004489 break;
4490 }
4491#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004492 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004493 data->rx_probe_req.da,
4494 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004495 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004496 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004497 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004498 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004499 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004500 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004501#ifdef CONFIG_OFFCHANNEL
4502 offchannel_remain_on_channel_cb(
4503 wpa_s, data->remain_on_channel.freq,
4504 data->remain_on_channel.duration);
4505#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004506 wpas_p2p_remain_on_channel_cb(
4507 wpa_s, data->remain_on_channel.freq,
4508 data->remain_on_channel.duration);
4509 break;
4510 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004511#ifdef CONFIG_OFFCHANNEL
4512 offchannel_cancel_remain_on_channel_cb(
4513 wpa_s, data->remain_on_channel.freq);
4514#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004515 wpas_p2p_cancel_remain_on_channel_cb(
4516 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004517#ifdef CONFIG_DPP
4518 wpas_dpp_cancel_remain_on_channel_cb(
4519 wpa_s, data->remain_on_channel.freq);
4520#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004521 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004522 case EVENT_EAPOL_RX:
4523 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
4524 data->eapol_rx.data,
4525 data->eapol_rx.data_len);
4526 break;
4527 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004528 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
4529 "above=%d signal=%d noise=%d txrate=%d",
4530 data->signal_change.above_threshold,
4531 data->signal_change.current_signal,
4532 data->signal_change.current_noise,
4533 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004534 wpa_bss_update_level(wpa_s->current_bss,
4535 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004536 bgscan_notify_signal_change(
4537 wpa_s, data->signal_change.above_threshold,
4538 data->signal_change.current_signal,
4539 data->signal_change.current_noise,
4540 data->signal_change.current_txrate);
4541 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004542 case EVENT_INTERFACE_MAC_CHANGED:
4543 wpa_supplicant_update_mac_addr(wpa_s);
4544 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004545 case EVENT_INTERFACE_ENABLED:
4546 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
4547 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004548 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004549 if (wpa_s->p2p_mgmt) {
4550 wpa_supplicant_set_state(wpa_s,
4551 WPA_DISCONNECTED);
4552 break;
4553 }
4554
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004555#ifdef CONFIG_AP
4556 if (!wpa_s->ap_iface) {
4557 wpa_supplicant_set_state(wpa_s,
4558 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004559 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004560 wpa_supplicant_req_scan(wpa_s, 0, 0);
4561 } else
4562 wpa_supplicant_set_state(wpa_s,
4563 WPA_COMPLETED);
4564#else /* CONFIG_AP */
4565 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
4566 wpa_supplicant_req_scan(wpa_s, 0, 0);
4567#endif /* CONFIG_AP */
4568 }
4569 break;
4570 case EVENT_INTERFACE_DISABLED:
4571 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004572#ifdef CONFIG_P2P
4573 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
4574 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
4575 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
4576 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004577 * Mark interface disabled if this happens to end up not
4578 * being removed as a separate P2P group interface.
4579 */
4580 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4581 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004582 * The interface was externally disabled. Remove
4583 * it assuming an external entity will start a
4584 * new session if needed.
4585 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004586 if (wpa_s->current_ssid &&
4587 wpa_s->current_ssid->p2p_group)
4588 wpas_p2p_interface_unavailable(wpa_s);
4589 else
4590 wpas_p2p_disconnect(wpa_s);
4591 /*
4592 * wpa_s instance may have been freed, so must not use
4593 * it here anymore.
4594 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004595 break;
4596 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004597 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
4598 p2p_in_progress(wpa_s->global->p2p) > 1) {
4599 /* This radio work will be cancelled, so clear P2P
4600 * state as well.
4601 */
4602 p2p_stop_find(wpa_s->global->p2p);
4603 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004604#endif /* CONFIG_P2P */
4605
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004606 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4607 /*
4608 * Indicate disconnection to keep ctrl_iface events
4609 * consistent.
4610 */
4611 wpa_supplicant_event_disassoc(
4612 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
4613 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004614 wpa_supplicant_mark_disassoc(wpa_s);
xshud0ee72f2018-11-08 14:37:01 -08004615 if (!wpa_s->conf->bss_no_flush_when_down)
4616 wpa_bss_flush(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08004617 radio_remove_works(wpa_s, NULL, 0);
4618
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004619 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4620 break;
4621 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004622 wpa_supplicant_update_channel_list(
4623 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004624 break;
4625 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004626 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004627 break;
4628 case EVENT_BEST_CHANNEL:
4629 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
4630 "(%d %d %d)",
4631 data->best_chan.freq_24, data->best_chan.freq_5,
4632 data->best_chan.freq_overall);
4633 wpa_s->best_24_freq = data->best_chan.freq_24;
4634 wpa_s->best_5_freq = data->best_chan.freq_5;
4635 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004636 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
4637 data->best_chan.freq_5,
4638 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004639 break;
4640 case EVENT_UNPROT_DEAUTH:
4641 wpa_supplicant_event_unprot_deauth(wpa_s,
4642 &data->unprot_deauth);
4643 break;
4644 case EVENT_UNPROT_DISASSOC:
4645 wpa_supplicant_event_unprot_disassoc(wpa_s,
4646 &data->unprot_disassoc);
4647 break;
4648 case EVENT_STATION_LOW_ACK:
4649#ifdef CONFIG_AP
4650 if (wpa_s->ap_iface && data)
4651 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
4652 data->low_ack.addr);
4653#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004654#ifdef CONFIG_TDLS
4655 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07004656 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
4657 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004658#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004659 break;
4660 case EVENT_IBSS_PEER_LOST:
4661#ifdef CONFIG_IBSS_RSN
4662 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
4663#endif /* CONFIG_IBSS_RSN */
4664 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004665 case EVENT_DRIVER_GTK_REKEY:
4666 if (os_memcmp(data->driver_gtk_rekey.bssid,
4667 wpa_s->bssid, ETH_ALEN))
4668 break;
4669 if (!wpa_s->wpa)
4670 break;
4671 wpa_sm_update_replay_ctr(wpa_s->wpa,
4672 data->driver_gtk_rekey.replay_ctr);
4673 break;
4674 case EVENT_SCHED_SCAN_STOPPED:
4675 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004676 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004677 wpa_supplicant_notify_scanning(wpa_s, 0);
4678
4679 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4680 break;
4681
4682 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004683 * If the driver stopped scanning without being requested to,
4684 * request a new scan to continue scanning for networks.
4685 */
4686 if (!wpa_s->sched_scan_stop_req &&
4687 wpa_s->wpa_state == WPA_SCANNING) {
4688 wpa_dbg(wpa_s, MSG_DEBUG,
4689 "Restart scanning after unexpected sched_scan stop event");
4690 wpa_supplicant_req_scan(wpa_s, 1, 0);
4691 break;
4692 }
4693
4694 wpa_s->sched_scan_stop_req = 0;
4695
4696 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08004697 * Start a new sched scan to continue searching for more SSIDs
4698 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004699 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07004700 if (wpa_s->sched_scan_timed_out) {
4701 wpa_supplicant_req_sched_scan(wpa_s);
4702 } else if (wpa_s->pno_sched_pending) {
4703 wpa_s->pno_sched_pending = 0;
4704 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004705 } else if (resched) {
4706 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08004707 }
4708
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004709 break;
4710 case EVENT_WPS_BUTTON_PUSHED:
4711#ifdef CONFIG_WPS
4712 wpas_wps_start_pbc(wpa_s, NULL, 0);
4713#endif /* CONFIG_WPS */
4714 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004715 case EVENT_AVOID_FREQUENCIES:
4716 wpa_supplicant_notify_avoid_freq(wpa_s, data);
4717 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004718 case EVENT_CONNECT_FAILED_REASON:
4719#ifdef CONFIG_AP
4720 if (!wpa_s->ap_iface || !data)
4721 break;
4722 hostapd_event_connect_failed_reason(
4723 wpa_s->ap_iface->bss[0],
4724 data->connect_failed_reason.addr,
4725 data->connect_failed_reason.code);
4726#endif /* CONFIG_AP */
4727 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004728 case EVENT_NEW_PEER_CANDIDATE:
4729#ifdef CONFIG_MESH
4730 if (!wpa_s->ifmsh || !data)
4731 break;
4732 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4733 data->mesh_peer.ies,
4734 data->mesh_peer.ie_len);
4735#endif /* CONFIG_MESH */
4736 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004737 case EVENT_SURVEY:
4738#ifdef CONFIG_AP
4739 if (!wpa_s->ap_iface)
4740 break;
4741 hostapd_event_get_survey(wpa_s->ap_iface,
4742 &data->survey_results);
4743#endif /* CONFIG_AP */
4744 break;
4745 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08004746#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004747#ifdef CONFIG_ACS
4748 if (!wpa_s->ap_iface)
4749 break;
4750 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4751 &data->acs_selected_channels);
4752#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08004753#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004754 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004755 case EVENT_P2P_LO_STOP:
4756#ifdef CONFIG_P2P
4757 wpa_s->p2p_lo_started = 0;
4758 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
4759 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
4760 data->p2p_lo_stop.reason_code);
4761#endif /* CONFIG_P2P */
4762 break;
Paul Stewart092955c2017-02-06 09:13:09 -08004763 case EVENT_BEACON_LOSS:
4764 if (!wpa_s->current_bss || !wpa_s->current_ssid)
4765 break;
4766 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
4767 bgscan_notify_beacon_loss(wpa_s);
4768 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004769 case EVENT_EXTERNAL_AUTH:
4770#ifdef CONFIG_SAE
4771 if (!wpa_s->current_ssid) {
4772 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
4773 break;
4774 }
4775 sme_external_auth_trigger(wpa_s, data);
4776#endif /* CONFIG_SAE */
4777 break;
4778 case EVENT_PORT_AUTHORIZED:
4779 wpa_supplicant_event_port_authorized(wpa_s);
4780 break;
4781 case EVENT_STATION_OPMODE_CHANGED:
4782#ifdef CONFIG_AP
4783 if (!wpa_s->ap_iface || !data)
4784 break;
4785
4786 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
4787 data->sta_opmode.addr,
4788 data->sta_opmode.smps_mode,
4789 data->sta_opmode.chan_width,
4790 data->sta_opmode.rx_nss);
4791#endif /* CONFIG_AP */
4792 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004793 default:
4794 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4795 break;
4796 }
4797}
Dmitry Shmidte4663042016-04-04 10:07:49 -07004798
4799
4800void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
4801 union wpa_event_data *data)
4802{
4803 struct wpa_supplicant *wpa_s;
4804
4805 if (event != EVENT_INTERFACE_STATUS)
4806 return;
4807
4808 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
4809 if (wpa_s && wpa_s->driver->get_ifindex) {
4810 unsigned int ifindex;
4811
4812 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
4813 if (ifindex != data->interface_status.ifindex) {
4814 wpa_dbg(wpa_s, MSG_DEBUG,
4815 "interface status ifindex %d mismatch (%d)",
4816 ifindex, data->interface_status.ifindex);
4817 return;
4818 }
4819 }
4820#ifdef CONFIG_MATCH_IFACE
4821 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
4822 struct wpa_interface *wpa_i;
4823
4824 wpa_i = wpa_supplicant_match_iface(
4825 ctx, data->interface_status.ifname);
4826 if (!wpa_i)
4827 return;
4828 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
4829 os_free(wpa_i);
4830 if (wpa_s)
4831 wpa_s->matched = 1;
4832 }
4833#endif /* CONFIG_MATCH_IFACE */
4834
4835 if (wpa_s)
4836 wpa_supplicant_event(wpa_s, event, data);
4837}