blob: 8ede2bb4cc852de246a3b194b0dc4407821c995f [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
Hai Shalom74f70d42019-02-11 14:42:39 -0800296 if (os_reltime_initialized(&wpa_s->session_start)) {
297 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
298 wpa_s->session_start.sec = 0;
299 wpa_s->session_start.usec = 0;
300 wpas_notify_session_length(wpa_s);
301 }
302
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
304 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
305 os_memset(wpa_s->bssid, 0, ETH_ALEN);
306 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800307 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308 wpa_s->current_bss = NULL;
309 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700310
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311 if (bssid_changed)
312 wpas_notify_bssid_changed(wpa_s);
313
314 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
315 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700316 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
317 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
318 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
320 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700321 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700322 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700323 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800324
325 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800326 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800327 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700328
329#ifdef CONFIG_TESTING_OPTIONS
330 wpa_s->last_tk_alg = WPA_ALG_NONE;
331 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
332#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700333 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800334
335 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
336 wpa_s->enabled_4addr_mode = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337}
338
339
340static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
341{
342 struct wpa_ie_data ie;
343 int pmksa_set = -1;
344 size_t i;
345
346 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
347 ie.pmkid == NULL)
348 return;
349
350 for (i = 0; i < ie.num_pmkid; i++) {
351 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
352 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700353 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800355 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700356 break;
357 }
358 }
359
360 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
361 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
362}
363
364
365static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
366 union wpa_event_data *data)
367{
368 if (data == NULL) {
369 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
370 "event");
371 return;
372 }
373 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
374 " index=%d preauth=%d",
375 MAC2STR(data->pmkid_candidate.bssid),
376 data->pmkid_candidate.index,
377 data->pmkid_candidate.preauth);
378
379 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
380 data->pmkid_candidate.index,
381 data->pmkid_candidate.preauth);
382}
383
384
385static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
386{
387 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
388 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
389 return 0;
390
391#ifdef IEEE8021X_EAPOL
392 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
393 wpa_s->current_ssid &&
394 !(wpa_s->current_ssid->eapol_flags &
395 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
396 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
397 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
398 * plaintext or static WEP keys). */
399 return 0;
400 }
401#endif /* IEEE8021X_EAPOL */
402
403 return 1;
404}
405
406
407/**
408 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
409 * @wpa_s: pointer to wpa_supplicant data
410 * @ssid: Configuration data for the network
411 * Returns: 0 on success, -1 on failure
412 *
413 * This function is called when starting authentication with a network that is
414 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
415 */
416int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
417 struct wpa_ssid *ssid)
418{
419#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800420#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700421 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700423 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
424 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 return 0;
426
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700427 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700428 sim = 1;
429 aka = 1;
430 } else {
431 struct eap_method_type *eap = ssid->eap.eap_methods;
432 while (eap->vendor != EAP_VENDOR_IETF ||
433 eap->method != EAP_TYPE_NONE) {
434 if (eap->vendor == EAP_VENDOR_IETF) {
435 if (eap->method == EAP_TYPE_SIM)
436 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700437 else if (eap->method == EAP_TYPE_AKA ||
438 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700439 aka = 1;
440 }
441 eap++;
442 }
443 }
444
445 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
446 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700447 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
448 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
449 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700450 aka = 0;
451
452 if (!sim && !aka) {
453 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
454 "use SIM, but neither EAP-SIM nor EAP-AKA are "
455 "enabled");
456 return 0;
457 }
458
459 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
460 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700461
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700462 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463 if (wpa_s->scard == NULL) {
464 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
465 "(pcsc-lite)");
466 return -1;
467 }
468 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
469 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800470#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700471#endif /* IEEE8021X_EAPOL */
472
473 return 0;
474}
475
476
477#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700478
479static int has_wep_key(struct wpa_ssid *ssid)
480{
481 int i;
482
483 for (i = 0; i < NUM_WEP_KEYS; i++) {
484 if (ssid->wep_key_len[i])
485 return 1;
486 }
487
488 return 0;
489}
490
491
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700492static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 struct wpa_ssid *ssid)
494{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700495 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700496
497 if (ssid->mixed_cell)
498 return 1;
499
500#ifdef CONFIG_WPS
501 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
502 return 1;
503#endif /* CONFIG_WPS */
504
Roshan Pius3a1667e2018-07-03 15:17:14 -0700505#ifdef CONFIG_OWE
506 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
507 return 1;
508#endif /* CONFIG_OWE */
509
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700510 if (has_wep_key(ssid))
511 privacy = 1;
512
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700513#ifdef IEEE8021X_EAPOL
514 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
515 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
516 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
517 privacy = 1;
518#endif /* IEEE8021X_EAPOL */
519
Jouni Malinen75ecf522011-06-27 15:19:46 -0700520 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
521 privacy = 1;
522
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800523 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
524 privacy = 1;
525
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700526 if (bss->caps & IEEE80211_CAP_PRIVACY)
527 return privacy;
528 return !privacy;
529}
530
531
532static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
533 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800534 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535{
536 struct wpa_ie_data ie;
537 int proto_match = 0;
538 const u8 *rsn_ie, *wpa_ie;
539 int ret;
540 int wep_ok;
541
542 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
543 if (ret >= 0)
544 return ret;
545
546 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
547 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
548 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
549 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
550 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
551
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700552 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700553 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554 proto_match++;
555
556 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800557 if (debug_print)
558 wpa_dbg(wpa_s, MSG_DEBUG,
559 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560 break;
561 }
562
563 if (wep_ok &&
564 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
565 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800566 if (debug_print)
567 wpa_dbg(wpa_s, MSG_DEBUG,
568 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700569 return 1;
570 }
571
Roshan Pius3a1667e2018-07-03 15:17:14 -0700572 if (!(ie.proto & ssid->proto) &&
573 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800574 if (debug_print)
575 wpa_dbg(wpa_s, MSG_DEBUG,
576 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577 break;
578 }
579
580 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800581 if (debug_print)
582 wpa_dbg(wpa_s, MSG_DEBUG,
583 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 break;
585 }
586
587 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800588 if (debug_print)
589 wpa_dbg(wpa_s, MSG_DEBUG,
590 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591 break;
592 }
593
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700594 if (ssid->group_mgmt_cipher &&
595 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
596 if (debug_print)
597 wpa_dbg(wpa_s, MSG_DEBUG,
598 " skip RSN IE - group mgmt cipher mismatch");
599 break;
600 }
601
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800603 if (debug_print)
604 wpa_dbg(wpa_s, MSG_DEBUG,
605 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700606 break;
607 }
608
609#ifdef CONFIG_IEEE80211W
610 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800611 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800612 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800613 if (debug_print)
614 wpa_dbg(wpa_s, MSG_DEBUG,
615 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616 break;
617 }
618#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800619 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
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 but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800625 break;
626 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800627#ifdef CONFIG_MBO
628 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
629 wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
630 wpas_get_ssid_pmf(wpa_s, ssid) !=
631 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800632 if (debug_print)
633 wpa_dbg(wpa_s, MSG_DEBUG,
634 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800635 break;
636 }
637#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800639 if (debug_print)
640 wpa_dbg(wpa_s, MSG_DEBUG,
641 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642 return 1;
643 }
644
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700645#ifdef CONFIG_IEEE80211W
Roshan Pius3a1667e2018-07-03 15:17:14 -0700646 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
647 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800648 if (debug_print)
649 wpa_dbg(wpa_s, MSG_DEBUG,
650 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700651 return 0;
652 }
653#endif /* CONFIG_IEEE80211W */
654
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700655 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
657 proto_match++;
658
659 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800660 if (debug_print)
661 wpa_dbg(wpa_s, MSG_DEBUG,
662 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663 break;
664 }
665
666 if (wep_ok &&
667 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
668 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800669 if (debug_print)
670 wpa_dbg(wpa_s, MSG_DEBUG,
671 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700672 return 1;
673 }
674
675 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800676 if (debug_print)
677 wpa_dbg(wpa_s, MSG_DEBUG,
678 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679 break;
680 }
681
682 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800683 if (debug_print)
684 wpa_dbg(wpa_s, MSG_DEBUG,
685 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686 break;
687 }
688
689 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800690 if (debug_print)
691 wpa_dbg(wpa_s, MSG_DEBUG,
692 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693 break;
694 }
695
696 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800697 if (debug_print)
698 wpa_dbg(wpa_s, MSG_DEBUG,
699 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700 break;
701 }
702
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800703 if (debug_print)
704 wpa_dbg(wpa_s, MSG_DEBUG,
705 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 return 1;
707 }
708
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700709 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
710 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800711 if (debug_print)
712 wpa_dbg(wpa_s, MSG_DEBUG,
713 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700714 return 1;
715 }
716
Roshan Pius3a1667e2018-07-03 15:17:14 -0700717#ifdef CONFIG_OWE
718 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
719 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800720 if (wpa_s->owe_transition_select &&
721 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
722 ssid->owe_transition_bss_select_count + 1 <=
723 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
724 ssid->owe_transition_bss_select_count++;
725 if (debug_print)
726 wpa_dbg(wpa_s, MSG_DEBUG,
727 " skip OWE transition BSS (selection count %d does not exceed %d)",
728 ssid->owe_transition_bss_select_count,
729 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
730 wpa_s->owe_transition_search = 1;
731 return 0;
732 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700733 if (debug_print)
734 wpa_dbg(wpa_s, MSG_DEBUG,
735 " allow in OWE transition mode");
736 return 1;
737 }
738#endif /* CONFIG_OWE */
739
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
741 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800742 if (debug_print)
743 wpa_dbg(wpa_s, MSG_DEBUG,
744 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745 return 0;
746 }
747
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800748 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
749 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800750 if (debug_print)
751 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800752 return 1;
753 }
754
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700755 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800756 if (debug_print)
757 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700758 return 1;
759 }
760
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800761 if (debug_print)
762 wpa_dbg(wpa_s, MSG_DEBUG,
763 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764
765 return 0;
766}
767
768
769static int freq_allowed(int *freqs, int freq)
770{
771 int i;
772
773 if (freqs == NULL)
774 return 1;
775
776 for (i = 0; freqs[i]; i++)
777 if (freqs[i] == freq)
778 return 1;
779 return 0;
780}
781
782
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800783static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
784 int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800785{
786 const struct hostapd_hw_modes *mode = NULL, *modes;
787 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
788 const u8 *rate_ie;
789 int i, j, k;
790
791 if (bss->freq == 0)
792 return 1; /* Cannot do matching without knowing band */
793
794 modes = wpa_s->hw.modes;
795 if (modes == NULL) {
796 /*
797 * The driver does not provide any additional information
798 * about the utilized hardware, so allow the connection attempt
799 * to continue.
800 */
801 return 1;
802 }
803
804 for (i = 0; i < wpa_s->hw.num_modes; i++) {
805 for (j = 0; j < modes[i].num_channels; j++) {
806 int freq = modes[i].channels[j].freq;
807 if (freq == bss->freq) {
808 if (mode &&
809 mode->mode == HOSTAPD_MODE_IEEE80211G)
810 break; /* do not allow 802.11b replace
811 * 802.11g */
812 mode = &modes[i];
813 break;
814 }
815 }
816 }
817
818 if (mode == NULL)
819 return 0;
820
821 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700822 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800823 if (rate_ie == NULL)
824 continue;
825
826 for (j = 2; j < rate_ie[1] + 2; j++) {
827 int flagged = !!(rate_ie[j] & 0x80);
828 int r = (rate_ie[j] & 0x7f) * 5;
829
830 /*
831 * IEEE Std 802.11n-2009 7.3.2.2:
832 * The new BSS Membership selector value is encoded
833 * like a legacy basic rate, but it is not a rate and
834 * only indicates if the BSS members are required to
835 * support the mandatory features of Clause 20 [HT PHY]
836 * in order to join the BSS.
837 */
838 if (flagged && ((rate_ie[j] & 0x7f) ==
839 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
840 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800841 if (debug_print)
842 wpa_dbg(wpa_s, MSG_DEBUG,
843 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800844 return 0;
845 }
846 continue;
847 }
848
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700849 /* There's also a VHT selector for 802.11ac */
850 if (flagged && ((rate_ie[j] & 0x7f) ==
851 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
852 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800853 if (debug_print)
854 wpa_dbg(wpa_s, MSG_DEBUG,
855 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700856 return 0;
857 }
858 continue;
859 }
860
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800861 if (!flagged)
862 continue;
863
864 /* check for legacy basic rates */
865 for (k = 0; k < mode->num_rates; k++) {
866 if (mode->rates[k] == r)
867 break;
868 }
869 if (k == mode->num_rates) {
870 /*
871 * IEEE Std 802.11-2007 7.3.2.2 demands that in
872 * order to join a BSS all required rates
873 * have to be supported by the hardware.
874 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800875 if (debug_print)
876 wpa_dbg(wpa_s, MSG_DEBUG,
877 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
878 r / 10, r % 10,
879 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800880 return 0;
881 }
882 }
883 }
884
885 return 1;
886}
887
888
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800889/*
890 * Test whether BSS is in an ESS.
891 * This is done differently in DMG (60 GHz) and non-DMG bands
892 */
893static int bss_is_ess(struct wpa_bss *bss)
894{
895 if (bss_is_dmg(bss)) {
896 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
897 IEEE80211_CAP_DMG_AP;
898 }
899
900 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
901 IEEE80211_CAP_ESS);
902}
903
904
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800905static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
906{
907 size_t i;
908
909 for (i = 0; i < ETH_ALEN; i++) {
910 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
911 return 0;
912 }
913 return 1;
914}
915
916
917static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
918{
919 size_t i;
920
921 for (i = 0; i < num; i++) {
922 const u8 *a = list + i * ETH_ALEN * 2;
923 const u8 *m = a + ETH_ALEN;
924
925 if (match_mac_mask(a, addr, m))
926 return 1;
927 }
928 return 0;
929}
930
931
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700932static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
933 const u8 **ret_ssid, size_t *ret_ssid_len)
934{
935#ifdef CONFIG_OWE
936 const u8 *owe, *pos, *end, *bssid;
937 u8 ssid_len;
938 struct wpa_bss *open_bss;
939
940 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
941 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
942 return;
943
944 pos = owe + 6;
945 end = owe + 2 + owe[1];
946
947 if (end - pos < ETH_ALEN + 1)
948 return;
949 bssid = pos;
950 pos += ETH_ALEN;
951 ssid_len = *pos++;
952 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
953 return;
954
955 /* Match the profile SSID against the OWE transition mode SSID on the
956 * open network. */
957 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
958 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
959 *ret_ssid = pos;
960 *ret_ssid_len = ssid_len;
961
962 if (bss->ssid_len > 0)
963 return;
964
965 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
966 if (!open_bss)
967 return;
968 if (ssid_len != open_bss->ssid_len ||
969 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
970 wpa_dbg(wpa_s, MSG_DEBUG,
971 "OWE: transition mode SSID mismatch: %s",
972 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
973 return;
974 }
975
976 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
977 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
978 wpa_dbg(wpa_s, MSG_DEBUG,
979 "OWE: transition mode open BSS unexpected info");
980 return;
981 }
982
983 pos = owe + 6;
984 end = owe + 2 + owe[1];
985
986 if (end - pos < ETH_ALEN + 1)
987 return;
988 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
989 wpa_dbg(wpa_s, MSG_DEBUG,
990 "OWE: transition mode BSSID mismatch: " MACSTR,
991 MAC2STR(pos));
992 return;
993 }
994 pos += ETH_ALEN;
995 ssid_len = *pos++;
996 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
997 return;
998 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
999 wpa_ssid_txt(pos, ssid_len));
1000 os_memcpy(bss->ssid, pos, ssid_len);
1001 bss->ssid_len = ssid_len;
1002#endif /* CONFIG_OWE */
1003}
1004
1005
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001006struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1007 int i, struct wpa_bss *bss,
1008 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001009 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001010{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001011 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 int wpa;
1013 struct wpa_blacklist *e;
1014 const u8 *ie;
1015 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001016 int osen, rsn_osen = 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001017#ifdef CONFIG_MBO
1018 const u8 *assoc_disallow;
1019#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001020 const u8 *match_ssid;
1021 size_t match_ssid_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001022 struct wpa_ie_data data;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001023
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001024 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025 wpa_ie_len = ie ? ie[1] : 0;
1026
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001027 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001028 rsn_ie_len = ie ? ie[1] : 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001029 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1030 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1031 rsn_osen = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001032
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001033 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1034 osen = ie != NULL;
1035
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001036 if (debug_print) {
1037 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1038 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1039 i, MAC2STR(bss->bssid),
1040 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1041 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1042 bss->freq,
1043 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1044 " wps" : "",
1045 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1046 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1047 ? " p2p" : "",
1048 osen ? " osen=1" : "");
1049 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050
1051 e = wpa_blacklist_get(wpa_s, bss->bssid);
1052 if (e) {
1053 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001054 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055 /*
1056 * When only a single network is enabled, we can
1057 * trigger blacklisting on the first failure. This
1058 * should not be done with multiple enabled networks to
1059 * avoid getting forced to move into a worse ESS on
1060 * single error if there are no other BSSes of the
1061 * current ESS.
1062 */
1063 limit = 0;
1064 }
1065 if (e->count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001066 if (debug_print) {
1067 wpa_dbg(wpa_s, MSG_DEBUG,
1068 " skip - blacklisted (count=%d limit=%d)",
1069 e->count, limit);
1070 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071 return NULL;
1072 }
1073 }
1074
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001075 match_ssid = bss->ssid;
1076 match_ssid_len = bss->ssid_len;
1077 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1078
1079 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001080 if (debug_print)
1081 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001082 return NULL;
1083 }
1084
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001085 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001086 if (debug_print)
1087 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001088 return NULL;
1089 }
1090
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001091 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001092 if (debug_print)
1093 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001094 return NULL;
1095 }
1096
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001097 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
1098
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001099 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001100 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001101 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102
Dmitry Shmidt04949592012-07-19 12:16:46 -07001103 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001104 if (debug_print)
1105 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001106 continue;
1107 }
1108
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001109 res = wpas_temp_disabled(wpa_s, ssid);
1110 if (res > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001111 if (debug_print)
1112 wpa_dbg(wpa_s, MSG_DEBUG,
1113 " skip - disabled temporarily for %d second(s)",
1114 res);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001115 continue;
1116 }
1117
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118#ifdef CONFIG_WPS
1119 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001120 if (debug_print)
1121 wpa_dbg(wpa_s, MSG_DEBUG,
1122 " skip - blacklisted (WPS)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123 continue;
1124 }
1125
1126 if (wpa && ssid->ssid_len == 0 &&
1127 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1128 check_ssid = 0;
1129
1130 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1131 /* Only allow wildcard SSID match if an AP
1132 * advertises active WPS operation that matches
1133 * with our mode. */
1134 check_ssid = 1;
1135 if (ssid->ssid_len == 0 &&
1136 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1137 check_ssid = 0;
1138 }
1139#endif /* CONFIG_WPS */
1140
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001141 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1142 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1143 check_ssid = 0;
1144
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145 if (check_ssid &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001146 (match_ssid_len != ssid->ssid_len ||
1147 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001148 if (debug_print)
1149 wpa_dbg(wpa_s, MSG_DEBUG,
1150 " skip - SSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001151 continue;
1152 }
1153
1154 if (ssid->bssid_set &&
1155 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001156 if (debug_print)
1157 wpa_dbg(wpa_s, MSG_DEBUG,
1158 " skip - BSSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001159 continue;
1160 }
1161
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001162 /* check blacklist */
1163 if (ssid->num_bssid_blacklist &&
1164 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1165 ssid->num_bssid_blacklist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001166 if (debug_print)
1167 wpa_dbg(wpa_s, MSG_DEBUG,
1168 " skip - BSSID blacklisted");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001169 continue;
1170 }
1171
1172 /* if there is a whitelist, only accept those APs */
1173 if (ssid->num_bssid_whitelist &&
1174 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1175 ssid->num_bssid_whitelist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001176 if (debug_print)
1177 wpa_dbg(wpa_s, MSG_DEBUG,
1178 " skip - BSSID not in whitelist");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001179 continue;
1180 }
1181
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001182 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss,
1183 debug_print))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 continue;
1185
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001186 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1188 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001189 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001190 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001191 if (debug_print)
1192 wpa_dbg(wpa_s, MSG_DEBUG,
1193 " skip - non-WPA network not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001194 continue;
1195 }
1196
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001197 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1198 has_wep_key(ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001199 if (debug_print)
1200 wpa_dbg(wpa_s, MSG_DEBUG,
1201 " skip - ignore WPA/WPA2 AP for WEP network block");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001202 continue;
1203 }
1204
Roshan Pius3a1667e2018-07-03 15:17:14 -07001205 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen &&
1206 !rsn_osen) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001207 if (debug_print)
1208 wpa_dbg(wpa_s, MSG_DEBUG,
1209 " skip - non-OSEN network not allowed");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001210 continue;
1211 }
1212
Jouni Malinen75ecf522011-06-27 15:19:46 -07001213 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001214 if (debug_print)
1215 wpa_dbg(wpa_s, MSG_DEBUG,
1216 " skip - privacy mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217 continue;
1218 }
1219
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001220 if (ssid->mode != IEEE80211_MODE_MESH && !bss_is_ess(bss) &&
1221 !bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001222 if (debug_print)
1223 wpa_dbg(wpa_s, MSG_DEBUG,
1224 " skip - not ESS, PBSS, or MBSS");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001225 continue;
1226 }
1227
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001228 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001229 if (debug_print)
1230 wpa_dbg(wpa_s, MSG_DEBUG,
1231 " skip - PBSS mismatch (ssid %d bss %d)",
1232 ssid->pbss, bss_is_pbss(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001233 continue;
1234 }
1235
1236 if (!freq_allowed(ssid->freq_list, bss->freq)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001237 if (debug_print)
1238 wpa_dbg(wpa_s, MSG_DEBUG,
1239 " skip - frequency not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001240 continue;
1241 }
1242
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001243#ifdef CONFIG_MESH
1244 if (ssid->mode == IEEE80211_MODE_MESH && ssid->frequency > 0 &&
1245 ssid->frequency != bss->freq) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001246 if (debug_print)
1247 wpa_dbg(wpa_s, MSG_DEBUG,
1248 " skip - frequency not allowed (mesh)");
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001249 continue;
1250 }
1251#endif /* CONFIG_MESH */
1252
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001253 if (!rate_match(wpa_s, bss, debug_print)) {
1254 if (debug_print)
1255 wpa_dbg(wpa_s, MSG_DEBUG,
1256 " skip - rate sets do not match");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001257 continue;
1258 }
1259
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001260#ifndef CONFIG_IBSS_RSN
1261 if (ssid->mode == WPAS_MODE_IBSS &&
1262 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1263 WPA_KEY_MGMT_WPA_NONE))) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001264 if (debug_print)
1265 wpa_dbg(wpa_s, MSG_DEBUG,
1266 " skip - IBSS RSN not supported in the build");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001267 continue;
1268 }
1269#endif /* !CONFIG_IBSS_RSN */
1270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001272 if (ssid->p2p_group &&
1273 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1274 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001275 if (debug_print)
1276 wpa_dbg(wpa_s, MSG_DEBUG,
1277 " skip - no P2P IE seen");
Dmitry Shmidt96571392013-10-14 12:54:46 -07001278 continue;
1279 }
1280
Dmitry Shmidt54605472013-11-08 11:10:19 -08001281 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1282 struct wpabuf *p2p_ie;
1283 u8 dev_addr[ETH_ALEN];
1284
1285 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1286 if (ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001287 if (debug_print)
1288 wpa_dbg(wpa_s, MSG_DEBUG,
1289 " skip - no P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001290 continue;
1291 }
1292 p2p_ie = wpa_bss_get_vendor_ie_multi(
1293 bss, P2P_IE_VENDOR_TYPE);
1294 if (p2p_ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001295 if (debug_print)
1296 wpa_dbg(wpa_s, MSG_DEBUG,
1297 " skip - could not fetch P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001298 continue;
1299 }
1300
1301 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1302 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1303 ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001304 if (debug_print)
1305 wpa_dbg(wpa_s, MSG_DEBUG,
1306 " skip - no matching GO P2P Device Address in P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001307 wpabuf_free(p2p_ie);
1308 continue;
1309 }
1310 wpabuf_free(p2p_ie);
1311 }
1312
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001313 /*
1314 * TODO: skip the AP if its P2P IE has Group Formation
1315 * bit set in the P2P Group Capability Bitmap and we
1316 * are not in Group Formation with that device.
1317 */
1318#endif /* CONFIG_P2P */
1319
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001320 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1321 {
1322 struct os_reltime diff;
1323
1324 os_reltime_sub(&wpa_s->scan_min_time,
1325 &bss->last_update, &diff);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001326 if (debug_print)
1327 wpa_dbg(wpa_s, MSG_DEBUG,
1328 " skip - scan result not recent enough (%u.%06u seconds too old)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001329 (unsigned int) diff.sec,
1330 (unsigned int) diff.usec);
1331 continue;
1332 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001333#ifdef CONFIG_MBO
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001334#ifdef CONFIG_TESTING_OPTIONS
1335 if (wpa_s->ignore_assoc_disallow)
1336 goto skip_assoc_disallow;
1337#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001338 assoc_disallow = wpas_mbo_get_bss_attr(
1339 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1340 if (assoc_disallow && assoc_disallow[1] >= 1) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001341 if (debug_print)
1342 wpa_dbg(wpa_s, MSG_DEBUG,
1343 " skip - MBO association disallowed (reason %u)",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001344 assoc_disallow[2]);
1345 continue;
1346 }
1347
Hai Shalom74f70d42019-02-11 14:42:39 -08001348 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001349 if (debug_print)
1350 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom74f70d42019-02-11 14:42:39 -08001351 " skip - AP temporarily disallowed");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001352 continue;
1353 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001354#ifdef CONFIG_TESTING_OPTIONS
1355 skip_assoc_disallow:
1356#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001357#endif /* CONFIG_MBO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001358
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001359#ifdef CONFIG_DPP
1360 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1361 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1362 (!ssid->dpp_connector ||
1363 !ssid->dpp_netaccesskey ||
1364 !ssid->dpp_csign)) {
1365 if (debug_print)
1366 wpa_dbg(wpa_s, MSG_DEBUG,
1367 " skip - no PMKSA entry for DPP");
1368 continue;
1369 }
1370#endif /* CONFIG_DPP */
1371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001372 /* Matching configuration found */
1373 return ssid;
1374 }
1375
1376 /* No matching configuration found */
1377 return NULL;
1378}
1379
1380
1381static struct wpa_bss *
1382wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001383 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001384 struct wpa_ssid **selected_ssid,
1385 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001387 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001388
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001389 if (wpa_s->current_ssid) {
1390 struct wpa_ssid *ssid;
1391
1392 wpa_dbg(wpa_s, MSG_DEBUG,
1393 "Scan results matching the currently selected network");
1394 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1395 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1396
1397 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1398 only_first_ssid, 0);
1399 if (ssid != wpa_s->current_ssid)
1400 continue;
1401 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1402 " freq=%d level=%d snr=%d est_throughput=%u",
1403 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1404 bss->snr, bss->est_throughput);
1405 }
1406 }
1407
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001408 if (only_first_ssid)
1409 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1410 group->id);
1411 else
1412 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1413 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001415 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1416 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001417
1418 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001419 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001420 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001421 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001422 if (!*selected_ssid)
1423 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001424 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1425 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001426 MAC2STR(bss->bssid),
1427 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1428 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001429 }
1430
1431 return NULL;
1432}
1433
1434
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001435struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1436 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001437{
1438 struct wpa_bss *selected = NULL;
1439 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001440 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001441 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001442
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001443 if (wpa_s->last_scan_res == NULL ||
1444 wpa_s->last_scan_res_used == 0)
1445 return NULL; /* no scan results from last update */
1446
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001447 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001448 /* check that next_ssid is still valid */
1449 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1450 if (ssid == wpa_s->next_ssid)
1451 break;
1452 }
1453 next_ssid = ssid;
1454 wpa_s->next_ssid = NULL;
1455 }
1456
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001458 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1459 if (next_ssid && next_ssid->priority ==
1460 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001461 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001462 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001463 if (selected)
1464 break;
1465 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001466 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001467 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001468 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001469 if (selected)
1470 break;
1471 }
1472
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001473 if (selected == NULL && wpa_s->blacklist &&
1474 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001475 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1476 "blacklist and try again");
1477 wpa_blacklist_clear(wpa_s);
1478 wpa_s->blacklist_cleared++;
1479 } else if (selected == NULL)
1480 break;
1481 }
1482
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001483 ssid = *selected_ssid;
1484 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1485 !ssid->passphrase && !ssid->ext_psk) {
1486 const char *field_name, *txt = NULL;
1487
1488 wpa_dbg(wpa_s, MSG_DEBUG,
1489 "PSK/passphrase not yet available for the selected network");
1490
1491 wpas_notify_network_request(wpa_s, ssid,
1492 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1493
1494 field_name = wpa_supplicant_ctrl_req_to_string(
1495 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1496 if (field_name == NULL)
1497 return NULL;
1498
1499 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1500
1501 selected = NULL;
1502 }
1503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001504 return selected;
1505}
1506
1507
1508static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1509 int timeout_sec, int timeout_usec)
1510{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001511 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001512 /*
1513 * No networks are enabled; short-circuit request so
1514 * we don't wait timeout seconds before transitioning
1515 * to INACTIVE state.
1516 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001517 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1518 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001519 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1520 return;
1521 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001522
1523 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001524 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1525}
1526
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001527
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001528int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001529 struct wpa_bss *selected,
1530 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531{
1532 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1533 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1534 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001535 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001536#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001537 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1538 wpa_s->p2p_in_provisioning) {
1539 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1540 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001541 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001542 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001543#endif /* CONFIG_P2P */
1544
1545#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001546 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001547 wpas_wps_cancel(wpa_s);
1548#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001549 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001550 }
1551
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001552 wpa_msg(wpa_s, MSG_DEBUG,
1553 "Considering connect request: reassociate: %d selected: "
1554 MACSTR " bssid: " MACSTR " pending: " MACSTR
1555 " wpa_state: %s ssid=%p current_ssid=%p",
1556 wpa_s->reassociate, MAC2STR(selected->bssid),
1557 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1558 wpa_supplicant_state_txt(wpa_s->wpa_state),
1559 ssid, wpa_s->current_ssid);
1560
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001561 /*
1562 * Do not trigger new association unless the BSSID has changed or if
1563 * reassociation is requested. If we are in process of associating with
1564 * the selected BSSID, do not trigger new attempt.
1565 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001566 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001567 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1568 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1569 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001570 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1571 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1572 0) ||
1573 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1574 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1576 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001577 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001578 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001579 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1580 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001581 wpa_supplicant_associate(wpa_s, selected, ssid);
1582 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001583 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1584 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001585 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001586
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001587 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001588}
1589
1590
1591static struct wpa_ssid *
1592wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1593{
1594 int prio;
1595 struct wpa_ssid *ssid;
1596
1597 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1598 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1599 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001600 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001601 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001602#ifndef CONFIG_IBSS_RSN
1603 if (ssid->mode == WPAS_MODE_IBSS &&
1604 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1605 WPA_KEY_MGMT_WPA_NONE))) {
1606 wpa_msg(wpa_s, MSG_INFO,
1607 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1608 wpa_ssid_txt(ssid->ssid,
1609 ssid->ssid_len));
1610 continue;
1611 }
1612#endif /* !CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001613 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001614 ssid->mode == IEEE80211_MODE_AP ||
1615 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001616 return ssid;
1617 }
1618 }
1619 return NULL;
1620}
1621
1622
1623/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1624 * on BSS added and BSS changed events */
1625static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001626 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001627{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001628 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001629
1630 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1631 return;
1632
Jouni Malinen87fd2792011-05-16 18:35:42 +03001633 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001634 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635
Jouni Malinen87fd2792011-05-16 18:35:42 +03001636 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001637 if (ssid == NULL)
1638 continue;
1639
Jouni Malinen87fd2792011-05-16 18:35:42 +03001640 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001641 if (rsn == NULL)
1642 continue;
1643
Jouni Malinen87fd2792011-05-16 18:35:42 +03001644 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001645 }
1646
1647}
1648
1649
1650static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1651 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001652 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001653{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001654 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001655#ifndef CONFIG_NO_ROAMING
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001656 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001657 int to_5ghz;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001658 int cur_est, sel_est;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001659#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660
1661 if (wpa_s->reassociate)
1662 return 1; /* explicit request to reassociate */
1663 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1664 return 1; /* we are not associated; continue */
1665 if (wpa_s->current_ssid == NULL)
1666 return 1; /* unknown current SSID */
1667 if (wpa_s->current_ssid != ssid)
1668 return 1; /* different network block */
1669
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001670 if (wpas_driver_bss_selection(wpa_s))
1671 return 0; /* Driver-based roaming */
1672
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001673 if (wpa_s->current_ssid->ssid)
1674 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1675 wpa_s->current_ssid->ssid,
1676 wpa_s->current_ssid->ssid_len);
1677 if (!current_bss)
1678 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679
1680 if (!current_bss)
1681 return 1; /* current BSS not seen in scan results */
1682
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001683 if (current_bss == selected)
1684 return 0;
1685
1686 if (selected->last_update_idx > current_bss->last_update_idx)
1687 return 1; /* current BSS not seen in the last scan */
1688
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001689#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001690 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001691 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001692 " freq=%d level=%d snr=%d est_throughput=%u",
1693 MAC2STR(current_bss->bssid),
1694 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001695 current_bss->snr, current_bss->est_throughput);
1696 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001697 " freq=%d level=%d snr=%d est_throughput=%u",
1698 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001699 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001700
1701 if (wpa_s->current_ssid->bssid_set &&
1702 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1703 0) {
1704 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1705 "has preferred BSSID");
1706 return 1;
1707 }
1708
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001709 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1710 wpa_dbg(wpa_s, MSG_DEBUG,
1711 "Allow reassociation - selected BSS has better estimated throughput");
1712 return 1;
1713 }
1714
Dmitry Shmidte4663042016-04-04 10:07:49 -07001715 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1716
1717 if (current_bss->level < 0 &&
1718 current_bss->level > selected->level + to_5ghz * 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001719 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1720 "signal level");
1721 return 0;
1722 }
1723
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001724 if (current_bss->est_throughput > selected->est_throughput + 5000) {
1725 wpa_dbg(wpa_s, MSG_DEBUG,
1726 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001727 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001728 }
1729
1730 cur_est = current_bss->est_throughput;
1731 sel_est = selected->est_throughput;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001732 min_diff = 2;
1733 if (current_bss->level < 0) {
1734 if (current_bss->level < -85)
1735 min_diff = 1;
1736 else if (current_bss->level < -80)
1737 min_diff = 2;
1738 else if (current_bss->level < -75)
1739 min_diff = 3;
1740 else if (current_bss->level < -70)
1741 min_diff = 4;
1742 else
1743 min_diff = 5;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001744 if (cur_est > sel_est * 1.5)
1745 min_diff += 10;
1746 else if (cur_est > sel_est * 1.2)
1747 min_diff += 5;
1748 else if (cur_est > sel_est * 1.1)
1749 min_diff += 2;
1750 else if (cur_est > sel_est)
1751 min_diff++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001752 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001753 if (to_5ghz) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001754 int reduce = 2;
1755
Dmitry Shmidte4663042016-04-04 10:07:49 -07001756 /* Make it easier to move to 5 GHz band */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001757 if (sel_est > cur_est * 1.5)
1758 reduce = 5;
1759 else if (sel_est > cur_est * 1.2)
1760 reduce = 4;
1761 else if (sel_est > cur_est * 1.1)
1762 reduce = 3;
1763
1764 if (min_diff > reduce)
1765 min_diff -= reduce;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001766 else
1767 min_diff = 0;
1768 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001769 diff = abs(current_bss->level - selected->level);
1770 if (diff < min_diff) {
1771 wpa_dbg(wpa_s, MSG_DEBUG,
1772 "Skip roam - too small difference in signal level (%d < %d)",
1773 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001774 return 0;
1775 }
1776
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001777 wpa_dbg(wpa_s, MSG_DEBUG,
1778 "Allow reassociation due to difference in signal level (%d >= %d)",
1779 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001780 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001781#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001782 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001783#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001784}
1785
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001786
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001787/*
1788 * Return a negative value if no scan results could be fetched or if scan
1789 * results should not be shared with other virtual interfaces.
1790 * Return 0 if scan results were fetched and may be shared with other
1791 * interfaces.
1792 * Return 1 if scan results may be shared with other virtual interfaces but may
1793 * not trigger any operations.
1794 * Return 2 if the interface was removed and cannot be used.
1795 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001796static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001797 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001798 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001799{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001800 struct wpa_scan_results *scan_res = NULL;
1801 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001802 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001803#ifndef CONFIG_NO_RANDOM_POOL
1804 size_t i, num;
1805#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001806
1807#ifdef CONFIG_AP
1808 if (wpa_s->ap_iface)
1809 ap = 1;
1810#endif /* CONFIG_AP */
1811
1812 wpa_supplicant_notify_scanning(wpa_s, 0);
1813
1814 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1815 data ? &data->scan_info :
1816 NULL, 1);
1817 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001818 if (wpa_s->conf->ap_scan == 2 || ap ||
1819 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001821 if (!own_request)
1822 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001823 if (data && data->scan_info.external_scan)
1824 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001825 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1826 "scanning again");
1827 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001828 ret = -1;
1829 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 }
1831
1832#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001833 num = scan_res->num;
1834 if (num > 10)
1835 num = 10;
1836 for (i = 0; i < num; i++) {
1837 u8 buf[5];
1838 struct wpa_scan_res *res = scan_res->res[i];
1839 buf[0] = res->bssid[5];
1840 buf[1] = res->qual & 0xff;
1841 buf[2] = res->noise & 0xff;
1842 buf[3] = res->level & 0xff;
1843 buf[4] = res->tsf & 0xff;
1844 random_add_randomness(buf, sizeof(buf));
1845 }
1846#endif /* CONFIG_NO_RANDOM_POOL */
1847
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001848 if (update_only) {
1849 ret = 1;
1850 goto scan_work_done;
1851 }
1852
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001853 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001854 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001855 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1856 struct wpa_scan_results *scan_res);
1857
1858 scan_res_handler = wpa_s->scan_res_handler;
1859 wpa_s->scan_res_handler = NULL;
1860 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001861 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001862 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001863 }
1864
1865 if (ap) {
1866 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1867#ifdef CONFIG_AP
1868 if (wpa_s->ap_iface->scan_cb)
1869 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1870#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001871 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001872 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001873
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001874 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001875 wpa_s->own_scan_running,
1876 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001877 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001878 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1879 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001880 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1881 wpa_s->manual_scan_id);
1882 wpa_s->manual_scan_use_id = 0;
1883 } else {
1884 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1885 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001886 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001887
1888 wpas_notify_scan_done(wpa_s, 1);
1889
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001890 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001891 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 -07001892 wpa_scan_results_free(scan_res);
1893 return 0;
1894 }
1895
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001896 if (wnm_scan_process(wpa_s, 1) > 0)
1897 goto scan_work_done;
1898
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001899 if (sme_proc_obss_scan(wpa_s) > 0)
1900 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001901
Dmitry Shmidt29333592017-01-09 12:27:11 -08001902 if (own_request &&
1903 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
1904 goto scan_work_done;
1905
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001906 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1907 goto scan_work_done;
1908
1909 if (autoscan_notify_scan(wpa_s, scan_res))
1910 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001911
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001912 if (wpa_s->disconnected) {
1913 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001914 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001915 }
1916
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001917 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001918 bgscan_notify_scan(wpa_s, scan_res) == 1)
1919 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001920
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001921 wpas_wps_update_ap_info(wpa_s, scan_res);
1922
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001923 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1924 wpa_s->wpa_state < WPA_COMPLETED)
1925 goto scan_work_done;
1926
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001927 wpa_scan_results_free(scan_res);
1928
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
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001935 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001936
1937scan_work_done:
1938 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001939 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001940 struct wpa_radio_work *work = wpa_s->scan_work;
1941 wpa_s->scan_work = NULL;
1942 radio_work_done(work);
1943 }
1944 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001945}
1946
1947
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001948static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001949 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001950{
1951 struct wpa_bss *selected;
1952 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001953 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1954
1955 if (time_to_reenable > 0) {
1956 wpa_dbg(wpa_s, MSG_DEBUG,
1957 "Postpone network selection by %d seconds since all networks are disabled",
1958 time_to_reenable);
1959 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1960 eloop_register_timeout(time_to_reenable, 0,
1961 wpas_network_reenabled, wpa_s, NULL);
1962 return 0;
1963 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001964
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001965 if (wpa_s->p2p_mgmt)
1966 return 0; /* no normal connection on p2p_mgmt interface */
1967
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001968 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001969 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001970
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001971#ifdef CONFIG_MESH
1972 if (wpa_s->ifmsh) {
1973 wpa_msg(wpa_s, MSG_INFO,
1974 "Avoiding join because we already joined a mesh group");
1975 return 0;
1976 }
1977#endif /* CONFIG_MESH */
1978
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001979 if (selected) {
1980 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001981 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001982 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001983 if (new_scan)
1984 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001985 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001986 }
1987
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001988 if (ssid != wpa_s->current_ssid &&
1989 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1990 wpa_s->own_disconnect_req = 1;
1991 wpa_supplicant_deauthenticate(
1992 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1993 }
1994
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001995 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001996 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001997 return -1;
1998 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001999 if (new_scan)
2000 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002001 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002002 * Do not allow other virtual radios to trigger operations based
2003 * on these scan results since we do not want them to start
2004 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002005 */
2006 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002007 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002008 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2009 ssid = wpa_supplicant_pick_new_network(wpa_s);
2010 if (ssid) {
2011 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2012 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002013 if (new_scan)
2014 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002015 } else if (own_request) {
2016 /*
2017 * No SSID found. If SCAN results are as a result of
2018 * own scan request and not due to a scan request on
2019 * another shared interface, try another scan.
2020 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002021 int timeout_sec = wpa_s->scan_interval;
2022 int timeout_usec = 0;
2023#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002024 int res;
2025
2026 res = wpas_p2p_scan_no_go_seen(wpa_s);
2027 if (res == 2)
2028 return 2;
2029 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002030 return 0;
2031
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002032 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002033 wpa_s->show_group_started ||
2034 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002035 /*
2036 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002037 * state and during P2P join-a-group operation
2038 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002039 */
2040 timeout_sec = 0;
2041 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002042 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2043 timeout_usec);
2044 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002045 }
2046#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002047#ifdef CONFIG_INTERWORKING
2048 if (wpa_s->conf->auto_interworking &&
2049 wpa_s->conf->interworking &&
2050 wpa_s->conf->cred) {
2051 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2052 "start ANQP fetch since no matching "
2053 "networks found");
2054 wpa_s->network_select = 1;
2055 wpa_s->auto_network_select = 1;
2056 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002057 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002058 }
2059#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002060#ifdef CONFIG_WPS
2061 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2062 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2063 timeout_sec = 0;
2064 timeout_usec = 500000;
2065 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2066 timeout_usec);
2067 return 0;
2068 }
2069#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002070#ifdef CONFIG_OWE
2071 if (wpa_s->owe_transition_search) {
2072 wpa_dbg(wpa_s, MSG_DEBUG,
2073 "OWE: Use shorter wait during transition mode search");
2074 timeout_sec = 0;
2075 timeout_usec = 500000;
2076 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2077 timeout_usec);
2078 return 0;
2079 }
2080#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002081 if (wpa_supplicant_req_sched_scan(wpa_s))
2082 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2083 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002084
2085 wpa_msg_ctrl(wpa_s, MSG_INFO,
2086 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002087 }
2088 }
2089 return 0;
2090}
2091
2092
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002093static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2094 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002095{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002096 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002097 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002098
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002099 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002100 if (res == 2) {
2101 /*
2102 * Interface may have been removed, so must not dereference
2103 * wpa_s after this.
2104 */
2105 return 1;
2106 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002107
2108 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002109 /*
2110 * If no scan results could be fetched, then no need to
2111 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002112 * this scan. Similarly, if scan results started a new operation on this
2113 * interface, do not notify other interfaces to avoid concurrent
2114 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002115 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002116 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002117 }
2118
2119 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002120 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002121 * so, they get updated with this same scan info.
2122 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002123 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2124 radio_list) {
2125 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2127 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002128 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2129 res > 0);
2130 if (res < 0)
2131 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132 }
2133 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002134
2135 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002136}
2137
2138#endif /* CONFIG_NO_SCAN_PROCESSING */
2139
2140
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002141int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2142{
2143#ifdef CONFIG_NO_SCAN_PROCESSING
2144 return -1;
2145#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002146 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002147
Dmitry Shmidt29333592017-01-09 12:27:11 -08002148 wpa_s->ignore_post_flush_scan_res = 0;
2149
Dmitry Shmidt41712582015-06-29 11:02:15 -07002150 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002151 return -1;
2152
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002153 os_get_reltime(&now);
2154 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002155 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2156 return -1;
2157 }
2158
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002159 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002160#endif /* CONFIG_NO_SCAN_PROCESSING */
2161}
2162
Dmitry Shmidt04949592012-07-19 12:16:46 -07002163#ifdef CONFIG_WNM
2164
2165static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2166{
2167 struct wpa_supplicant *wpa_s = eloop_ctx;
2168
2169 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2170 return;
2171
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002172 if (!wpa_s->no_keep_alive) {
2173 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2174 MAC2STR(wpa_s->bssid));
2175 /* TODO: could skip this if normal data traffic has been sent */
2176 /* TODO: Consider using some more appropriate data frame for
2177 * this */
2178 if (wpa_s->l2)
2179 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2180 (u8 *) "", 0);
2181 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002182
2183#ifdef CONFIG_SME
2184 if (wpa_s->sme.bss_max_idle_period) {
2185 unsigned int msec;
2186 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2187 if (msec > 100)
2188 msec -= 100;
2189 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2190 wnm_bss_keep_alive, wpa_s, NULL);
2191 }
2192#endif /* CONFIG_SME */
2193}
2194
2195
2196static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2197 const u8 *ies, size_t ies_len)
2198{
2199 struct ieee802_11_elems elems;
2200
2201 if (ies == NULL)
2202 return;
2203
2204 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2205 return;
2206
2207#ifdef CONFIG_SME
2208 if (elems.bss_max_idle_period) {
2209 unsigned int msec;
2210 wpa_s->sme.bss_max_idle_period =
2211 WPA_GET_LE16(elems.bss_max_idle_period);
2212 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2213 "TU)%s", wpa_s->sme.bss_max_idle_period,
2214 (elems.bss_max_idle_period[2] & 0x01) ?
2215 " (protected keep-live required)" : "");
2216 if (wpa_s->sme.bss_max_idle_period == 0)
2217 wpa_s->sme.bss_max_idle_period = 1;
2218 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2219 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2220 /* msec times 1000 */
2221 msec = wpa_s->sme.bss_max_idle_period * 1024;
2222 if (msec > 100)
2223 msec -= 100;
2224 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2225 wnm_bss_keep_alive, wpa_s,
2226 NULL);
2227 }
2228 }
2229#endif /* CONFIG_SME */
2230}
2231
2232#endif /* CONFIG_WNM */
2233
2234
2235void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2236{
2237#ifdef CONFIG_WNM
2238 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2239#endif /* CONFIG_WNM */
2240}
2241
2242
Dmitry Shmidt051af732013-10-22 13:52:46 -07002243#ifdef CONFIG_INTERWORKING
2244
2245static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2246 size_t len)
2247{
2248 int res;
2249
2250 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2251 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2252 if (res) {
2253 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2254 }
2255
2256 return res;
2257}
2258
2259
2260static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2261 const u8 *ies, size_t ies_len)
2262{
2263 struct ieee802_11_elems elems;
2264
2265 if (ies == NULL)
2266 return;
2267
2268 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2269 return;
2270
2271 if (elems.qos_map_set) {
2272 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2273 elems.qos_map_set_len);
2274 }
2275}
2276
2277#endif /* CONFIG_INTERWORKING */
2278
2279
Hai Shalom74f70d42019-02-11 14:42:39 -08002280static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2281 const u8 *ies, size_t ies_len)
2282{
2283 struct ieee802_11_elems elems;
2284 const u8 *map_sub_elem, *pos;
2285 size_t len;
2286
2287 if (!wpa_s->current_ssid ||
2288 !wpa_s->current_ssid->multi_ap_backhaul_sta ||
2289 !ies ||
2290 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2291 return;
2292
2293 if (!elems.multi_ap || elems.multi_ap_len < 7) {
2294 wpa_printf(MSG_INFO, "AP doesn't support Multi-AP protocol");
2295 goto fail;
2296 }
2297
2298 pos = elems.multi_ap + 4;
2299 len = elems.multi_ap_len - 4;
2300
2301 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
2302 if (!map_sub_elem || map_sub_elem[1] < 1) {
2303 wpa_printf(MSG_INFO, "invalid Multi-AP sub elem type");
2304 goto fail;
2305 }
2306
2307 if (!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS)) {
2308 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2309 goto fail;
2310 }
2311
2312 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2313 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2314 goto fail;
2315 }
2316 wpa_s->enabled_4addr_mode = 1;
2317 return;
2318
2319fail:
2320 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2321}
2322
2323
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002324#ifdef CONFIG_FST
2325static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2326 const u8 *ie, size_t ie_len)
2327{
2328 struct mb_ies_info mb_ies;
2329
2330 if (!ie || !ie_len || !wpa_s->fst)
2331 return -ENOENT;
2332
2333 os_memset(&mb_ies, 0, sizeof(mb_ies));
2334
2335 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2336 size_t len;
2337
2338 len = 2 + ie[1];
2339 if (len > ie_len) {
2340 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2341 ie, ie_len);
2342 break;
2343 }
2344
2345 if (ie[0] == WLAN_EID_MULTI_BAND) {
2346 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2347 (unsigned int) len);
2348 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2349 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2350 mb_ies.nof_ies++;
2351 }
2352
2353 ie_len -= len;
2354 ie += len;
2355 }
2356
2357 if (mb_ies.nof_ies > 0) {
2358 wpabuf_free(wpa_s->received_mb_ies);
2359 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2360 return 0;
2361 }
2362
2363 return -ENOENT;
2364}
2365#endif /* CONFIG_FST */
2366
2367
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002368static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2369 union wpa_event_data *data)
2370{
2371 int l, len, found = 0, wpa_found, rsn_found;
2372 const u8 *p;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002373#if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002374 u8 bssid[ETH_ALEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -07002375#endif /* CONFIG_IEEE80211R || CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002376
2377 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
2378 if (data->assoc_info.req_ies)
2379 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2380 data->assoc_info.req_ies_len);
2381 if (data->assoc_info.resp_ies) {
2382 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2383 data->assoc_info.resp_ies_len);
2384#ifdef CONFIG_TDLS
2385 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2386 data->assoc_info.resp_ies_len);
2387#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002388#ifdef CONFIG_WNM
2389 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2390 data->assoc_info.resp_ies_len);
2391#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002392#ifdef CONFIG_INTERWORKING
2393 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2394 data->assoc_info.resp_ies_len);
2395#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002396 if (wpa_s->hw_capab == CAPAB_VHT &&
2397 get_ie(data->assoc_info.resp_ies,
2398 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2399 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002400
2401 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2402 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002403 }
2404 if (data->assoc_info.beacon_ies)
2405 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2406 data->assoc_info.beacon_ies,
2407 data->assoc_info.beacon_ies_len);
2408 if (data->assoc_info.freq)
2409 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2410 data->assoc_info.freq);
2411
2412 p = data->assoc_info.req_ies;
2413 l = data->assoc_info.req_ies_len;
2414
2415 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2416 while (p && l >= 2) {
2417 len = p[1] + 2;
2418 if (len > l) {
2419 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2420 p, l);
2421 break;
2422 }
2423 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2424 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
Dmitry Shmidte4663042016-04-04 10:07:49 -07002425 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2426 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002427 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
2428 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2429 break;
2430 found = 1;
2431 wpa_find_assoc_pmkid(wpa_s);
2432 break;
2433 }
2434 l -= len;
2435 p += len;
2436 }
2437 if (!found && data->assoc_info.req_ies)
2438 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
2439
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002440#ifdef CONFIG_FILS
2441#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002442 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2443 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002444 (!data->assoc_info.resp_frame ||
2445 fils_process_assoc_resp(wpa_s->wpa,
2446 data->assoc_info.resp_frame,
2447 data->assoc_info.resp_frame_len) < 0)) {
2448 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2449 return -1;
2450 }
2451#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002452
2453 /* Additional processing for FILS when SME is in driver */
2454 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2455 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2456 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002457#endif /* CONFIG_FILS */
2458
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002459#ifdef CONFIG_OWE
2460 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
2461 (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2462 owe_process_assoc_resp(wpa_s->wpa, bssid,
2463 data->assoc_info.resp_ies,
2464 data->assoc_info.resp_ies_len) < 0)) {
2465 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2466 return -1;
2467 }
2468#endif /* CONFIG_OWE */
2469
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002470#ifdef CONFIG_IEEE80211R
2471#ifdef CONFIG_SME
2472 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002473 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2474 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2475 data->assoc_info.resp_ies,
2476 data->assoc_info.resp_ies_len,
2477 bssid) < 0) {
2478 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2479 "Reassociation Response failed");
2480 wpa_supplicant_deauthenticate(
2481 wpa_s, WLAN_REASON_INVALID_IE);
2482 return -1;
2483 }
2484 }
2485
2486 p = data->assoc_info.resp_ies;
2487 l = data->assoc_info.resp_ies_len;
2488
2489#ifdef CONFIG_WPS_STRICT
2490 if (p && wpa_s->current_ssid &&
2491 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2492 struct wpabuf *wps;
2493 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2494 if (wps == NULL) {
2495 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2496 "include WPS IE in (Re)Association Response");
2497 return -1;
2498 }
2499
2500 if (wps_validate_assoc_resp(wps) < 0) {
2501 wpabuf_free(wps);
2502 wpa_supplicant_deauthenticate(
2503 wpa_s, WLAN_REASON_INVALID_IE);
2504 return -1;
2505 }
2506 wpabuf_free(wps);
2507 }
2508#endif /* CONFIG_WPS_STRICT */
2509
2510 /* Go through the IEs and make a copy of the MDIE, if present. */
2511 while (p && l >= 2) {
2512 len = p[1] + 2;
2513 if (len > l) {
2514 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2515 p, l);
2516 break;
2517 }
2518 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2519 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2520 wpa_s->sme.ft_used = 1;
2521 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2522 MOBILITY_DOMAIN_ID_LEN);
2523 break;
2524 }
2525 l -= len;
2526 p += len;
2527 }
2528#endif /* CONFIG_SME */
2529
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002530 /* Process FT when SME is in the driver */
2531 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2532 wpa_ft_is_completed(wpa_s->wpa)) {
2533 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2534 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2535 data->assoc_info.resp_ies,
2536 data->assoc_info.resp_ies_len,
2537 bssid) < 0) {
2538 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2539 "Reassociation Response failed");
2540 wpa_supplicant_deauthenticate(
2541 wpa_s, WLAN_REASON_INVALID_IE);
2542 return -1;
2543 }
2544 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2545 }
2546
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002547 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2548 data->assoc_info.resp_ies_len);
2549#endif /* CONFIG_IEEE80211R */
2550
2551 /* WPA/RSN IE from Beacon/ProbeResp */
2552 p = data->assoc_info.beacon_ies;
2553 l = data->assoc_info.beacon_ies_len;
2554
2555 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2556 */
2557 wpa_found = rsn_found = 0;
2558 while (p && l >= 2) {
2559 len = p[1] + 2;
2560 if (len > l) {
2561 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2562 p, l);
2563 break;
2564 }
2565 if (!wpa_found &&
2566 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2567 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2568 wpa_found = 1;
2569 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2570 }
2571
2572 if (!rsn_found &&
2573 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2574 rsn_found = 1;
2575 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2576 }
2577
2578 l -= len;
2579 p += len;
2580 }
2581
2582 if (!wpa_found && data->assoc_info.beacon_ies)
2583 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2584 if (!rsn_found && data->assoc_info.beacon_ies)
2585 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2586 if (wpa_found || rsn_found)
2587 wpa_s->ap_ies_from_associnfo = 1;
2588
Jouni Malinen87fd2792011-05-16 18:35:42 +03002589 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2590 wpa_s->assoc_freq != data->assoc_info.freq) {
2591 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2592 "%u to %u MHz",
2593 wpa_s->assoc_freq, data->assoc_info.freq);
2594 wpa_supplicant_update_scan_results(wpa_s);
2595 }
2596
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002597 wpa_s->assoc_freq = data->assoc_info.freq;
2598
2599 return 0;
2600}
2601
2602
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002603static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2604{
2605 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2606
2607 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2608 return -1;
2609
2610 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2611 return 0;
2612
2613 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2614 WPA_IE_VENDOR_TYPE);
2615 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2616
2617 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2618 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2619 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2620 bss_rsn ? 2 + bss_rsn[1] : 0))
2621 return -1;
2622
2623 return 0;
2624}
2625
2626
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002627static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2628 union wpa_event_data *data)
2629{
2630#ifdef CONFIG_FST
2631 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2632 struct wpa_bss *bss = wpa_s->current_bss;
2633 const u8 *ieprb, *iebcn;
2634
2635 wpabuf_free(wpa_s->received_mb_ies);
2636 wpa_s->received_mb_ies = NULL;
2637
2638 if (ai &&
2639 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2640 wpa_printf(MSG_DEBUG,
2641 "FST: MB IEs updated from Association Response frame");
2642 return;
2643 }
2644
2645 if (ai &&
2646 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2647 wpa_printf(MSG_DEBUG,
2648 "FST: MB IEs updated from association event Beacon IEs");
2649 return;
2650 }
2651
2652 if (!bss)
2653 return;
2654
2655 ieprb = (const u8 *) (bss + 1);
2656 iebcn = ieprb + bss->ie_len;
2657
2658 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2659 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2660 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2661 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2662#endif /* CONFIG_FST */
2663}
2664
2665
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002666static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2667 union wpa_event_data *data)
2668{
2669 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002670 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002671 int new_bss = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002672
2673#ifdef CONFIG_AP
2674 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002675 if (!data)
2676 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002677 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2678 data->assoc_info.addr,
2679 data->assoc_info.req_ies,
2680 data->assoc_info.req_ies_len,
2681 data->assoc_info.reassoc);
2682 return;
2683 }
2684#endif /* CONFIG_AP */
2685
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002686 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2687
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002688 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2689 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2690 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002691 /*
2692 * FILS authentication can share the same mechanism to mark the
2693 * connection fully authenticated, so set ft_completed also based on
2694 * FILS result.
2695 */
2696 if (!ft_completed)
2697 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002698
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002699 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2700 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002701 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002702 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2703 return;
2704 }
2705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002706 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002707 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08002708 if (os_reltime_initialized(&wpa_s->session_start)) {
2709 os_reltime_age(&wpa_s->session_start,
2710 &wpa_s->session_length);
2711 wpa_s->session_start.sec = 0;
2712 wpa_s->session_start.usec = 0;
2713 wpas_notify_session_length(wpa_s);
2714 } else {
2715 wpas_notify_auth_changed(wpa_s);
2716 os_get_reltime(&wpa_s->session_start);
2717 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002718 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2719 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002720 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002721 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002722 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2723 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002724 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002725
2726 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2727 wpa_clear_keys(wpa_s, bssid);
2728 }
2729 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002730 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002731 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2732 return;
2733 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002734 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002735
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002736 if (wpa_s->conf->ap_scan == 1 &&
2737 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002738 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2739 wpa_msg(wpa_s, MSG_WARNING,
2740 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002741 }
2742
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002743 wpas_fst_update_mb_assoc(wpa_s, data);
2744
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002745#ifdef CONFIG_SME
2746 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2747 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002748 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002749#endif /* CONFIG_SME */
2750
2751 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2752 if (wpa_s->current_ssid) {
2753 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2754 * initialized before association, but for other modes,
2755 * initialize PC/SC here, if the current configuration needs
2756 * smartcard or SIM/USIM. */
2757 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2758 }
2759 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2760 if (wpa_s->l2)
2761 l2_packet_notify_auth_start(wpa_s->l2);
2762
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002763 already_authorized = data && data->assoc_info.authorized;
2764
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002765 /*
2766 * Set portEnabled first to FALSE in order to get EAP state machine out
2767 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2768 * state machine may transit to AUTHENTICATING state based on obsolete
2769 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2770 * AUTHENTICATED without ever giving chance to EAP state machine to
2771 * reset the state.
2772 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002773 if (!ft_completed && !already_authorized) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002774 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2775 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2776 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002777 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
2778 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
2779 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002780 already_authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002781 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2782 /* 802.1X::portControl = Auto */
2783 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2784 wpa_s->eapol_received = 0;
2785 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2786 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2787 (wpa_s->current_ssid &&
2788 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002789 if (wpa_s->current_ssid &&
2790 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002791 (wpa_s->drv_flags &
2792 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2793 /*
2794 * Set the key after having received joined-IBSS event
2795 * from the driver.
2796 */
2797 wpa_supplicant_set_wpa_none_key(wpa_s,
2798 wpa_s->current_ssid);
2799 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002800 wpa_supplicant_cancel_auth_timeout(wpa_s);
2801 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2802 } else if (!ft_completed) {
2803 /* Timeout for receiving the first EAPOL packet */
2804 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2805 }
2806 wpa_supplicant_cancel_scan(wpa_s);
2807
Hai Shalom74f70d42019-02-11 14:42:39 -08002808 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002809 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2810 /*
2811 * We are done; the driver will take care of RSN 4-way
2812 * handshake.
2813 */
2814 wpa_supplicant_cancel_auth_timeout(wpa_s);
2815 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2816 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2817 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
Hai Shalom74f70d42019-02-11 14:42:39 -08002818 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002819 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2820 /*
2821 * The driver will take care of RSN 4-way handshake, so we need
2822 * to allow EAPOL supplicant to complete its work without
2823 * waiting for WPA supplicant.
2824 */
2825 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2826 } else if (ft_completed) {
2827 /*
2828 * FT protocol completed - make sure EAPOL state machine ends
2829 * up in authenticated.
2830 */
2831 wpa_supplicant_cancel_auth_timeout(wpa_s);
2832 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2833 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2834 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2835 }
2836
Jouni Malinena05074c2012-12-21 21:35:35 +02002837 wpa_s->last_eapol_matches_bssid = 0;
2838
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002839 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002840 struct os_reltime now, age;
2841 os_get_reltime(&now);
2842 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08002843 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002844 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2845 0) {
2846 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2847 "frame that was received just before "
2848 "association notification");
2849 wpa_supplicant_rx_eapol(
2850 wpa_s, wpa_s->pending_eapol_rx_src,
2851 wpabuf_head(wpa_s->pending_eapol_rx),
2852 wpabuf_len(wpa_s->pending_eapol_rx));
2853 }
2854 wpabuf_free(wpa_s->pending_eapol_rx);
2855 wpa_s->pending_eapol_rx = NULL;
2856 }
2857
2858 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2859 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002860 wpa_s->current_ssid &&
2861 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002862 /* Set static WEP keys again */
2863 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2864 }
2865
2866#ifdef CONFIG_IBSS_RSN
2867 if (wpa_s->current_ssid &&
2868 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2869 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2870 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2871 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002872 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002873 if (!wpa_s->ibss_rsn) {
2874 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2875 wpa_supplicant_deauthenticate(
2876 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2877 return;
2878 }
2879
2880 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2881 }
2882#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002883
2884 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002885
2886 if (data) {
2887 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2888 data->assoc_info.resp_ies_len,
2889 &data->assoc_info.wmm_params);
2890
2891 if (wpa_s->reassoc_same_bss)
2892 wmm_ac_restore_tspecs(wpa_s);
2893 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002894
2895#ifdef CONFIG_FILS
2896 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
2897 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid);
2898 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
2899
2900 if (fils_cache_id)
2901 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
2902 }
2903#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904}
2905
2906
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002907static int disconnect_reason_recoverable(u16 reason_code)
2908{
2909 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2910 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2911 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2912}
2913
2914
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002915static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002916 u16 reason_code,
2917 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002918{
2919 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002920
2921 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2922 /*
2923 * At least Host AP driver and a Prism3 card seemed to be
2924 * generating streams of disconnected events when configuring
2925 * IBSS for WPA-None. Ignore them for now.
2926 */
2927 return;
2928 }
2929
2930 bssid = wpa_s->bssid;
2931 if (is_zero_ether_addr(bssid))
2932 bssid = wpa_s->pending_bssid;
2933
2934 if (!is_zero_ether_addr(bssid) ||
2935 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2936 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2937 " reason=%d%s",
2938 MAC2STR(bssid), reason_code,
2939 locally_generated ? " locally_generated=1" : "");
2940 }
2941}
2942
2943
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002944static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2945 int locally_generated)
2946{
2947 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2948 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2949 return 0; /* Not in 4-way handshake with PSK */
2950
2951 /*
2952 * It looks like connection was lost while trying to go through PSK
2953 * 4-way handshake. Filter out known disconnection cases that are caused
2954 * by something else than PSK mismatch to avoid confusing reports.
2955 */
2956
2957 if (locally_generated) {
2958 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2959 return 0;
2960 }
2961
2962 return 1;
2963}
2964
2965
Jouni Malinen2b89da82012-08-31 22:04:41 +03002966static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2967 u16 reason_code,
2968 int locally_generated)
2969{
2970 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002971 int authenticating;
2972 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002973 struct wpa_bss *fast_reconnect = NULL;
2974 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002975 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002976 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002977
2978 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2979 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2980
2981 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2982 /*
2983 * At least Host AP driver and a Prism3 card seemed to be
2984 * generating streams of disconnected events when configuring
2985 * IBSS for WPA-None. Ignore them for now.
2986 */
2987 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2988 "IBSS/WPA-None mode");
2989 return;
2990 }
2991
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002992 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2993 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
2994 locally_generated)
2995 /*
2996 * Remove the inactive AP (which is probably out of range) from
2997 * the BSS list after marking disassociation. In particular
2998 * mac80211-based drivers use the
2999 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3000 * locally generated disconnection events for cases where the
3001 * AP does not reply anymore.
3002 */
3003 curr = wpa_s->current_bss;
3004
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003005 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003006 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3007 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003008 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3009 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003010 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003011 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003012 if (!wpa_s->disconnected &&
3013 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003014 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003015 wpas_wps_searching(wpa_s) ||
3016 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003017 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003018 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003019 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003020 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003021 wpa_s->wpa_state);
3022 if (wpa_s->wpa_state == WPA_COMPLETED &&
3023 wpa_s->current_ssid &&
3024 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003025 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003026 disconnect_reason_recoverable(reason_code)) {
3027 /*
3028 * It looks like the AP has dropped association with
3029 * us, but could allow us to get back in. Try to
3030 * reconnect to the same BSS without full scan to save
3031 * time for some common cases.
3032 */
3033 fast_reconnect = wpa_s->current_bss;
3034 fast_reconnect_ssid = wpa_s->current_ssid;
3035 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003036 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003037 else
3038 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3039 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003040 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003041 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003042 "try to re-connect");
3043 wpa_s->reassociate = 0;
3044 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003045 if (!wpa_s->pno)
3046 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003047 }
3048 bssid = wpa_s->bssid;
3049 if (is_zero_ether_addr(bssid))
3050 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003051 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3052 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003053 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003054 if (locally_generated)
3055 wpa_s->disconnect_reason = -reason_code;
3056 else
3057 wpa_s->disconnect_reason = reason_code;
3058 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003059 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3060 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003061 wpa_clear_keys(wpa_s, wpa_s->bssid);
3062 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003063 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003064 wpa_supplicant_mark_disassoc(wpa_s);
3065
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003066 if (curr)
3067 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3068
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003069 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003070 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003071 wpa_s->current_ssid = last_ssid;
3072 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003073
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003074 if (fast_reconnect &&
3075 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3076 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3077 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3078 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003079 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003080 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003081#ifndef CONFIG_NO_SCAN_PROCESSING
3082 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3083 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3084 fast_reconnect_ssid) < 0) {
3085 /* Recover through full scan */
3086 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3087 }
3088#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003089 } else if (fast_reconnect) {
3090 /*
3091 * Could not reconnect to the same BSS due to network being
3092 * disabled. Use a new scan to match the alternative behavior
3093 * above, i.e., to continue automatic reconnection attempt in a
3094 * way that enforces disabled network rules.
3095 */
3096 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003097 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003098}
3099
3100
3101#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003102void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003103{
3104 struct wpa_supplicant *wpa_s = eloop_ctx;
3105
3106 if (!wpa_s->pending_mic_error_report)
3107 return;
3108
3109 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3110 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3111 wpa_s->pending_mic_error_report = 0;
3112}
3113#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3114
3115
3116static void
3117wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3118 union wpa_event_data *data)
3119{
3120 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003121 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003122
3123 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3124 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003125 os_get_reltime(&t);
3126 if ((wpa_s->last_michael_mic_error.sec &&
3127 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003128 wpa_s->pending_mic_error_report) {
3129 if (wpa_s->pending_mic_error_report) {
3130 /*
3131 * Send the pending MIC error report immediately since
3132 * we are going to start countermeasures and AP better
3133 * do the same.
3134 */
3135 wpa_sm_key_request(wpa_s->wpa, 1,
3136 wpa_s->pending_mic_error_pairwise);
3137 }
3138
3139 /* Send the new MIC error report immediately since we are going
3140 * to start countermeasures and AP better do the same.
3141 */
3142 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3143
3144 /* initialize countermeasures */
3145 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003146
3147 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3148
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003149 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3150
3151 /*
3152 * Need to wait for completion of request frame. We do not get
3153 * any callback for the message completion, so just wait a
3154 * short while and hope for the best. */
3155 os_sleep(0, 10000);
3156
3157 wpa_drv_set_countermeasures(wpa_s, 1);
3158 wpa_supplicant_deauthenticate(wpa_s,
3159 WLAN_REASON_MICHAEL_MIC_FAILURE);
3160 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3161 wpa_s, NULL);
3162 eloop_register_timeout(60, 0,
3163 wpa_supplicant_stop_countermeasures,
3164 wpa_s, NULL);
3165 /* TODO: mark the AP rejected for 60 second. STA is
3166 * allowed to associate with another AP.. */
3167 } else {
3168#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3169 if (wpa_s->mic_errors_seen) {
3170 /*
3171 * Reduce the effectiveness of Michael MIC error
3172 * reports as a means for attacking against TKIP if
3173 * more than one MIC failure is noticed with the same
3174 * PTK. We delay the transmission of the reports by a
3175 * random time between 0 and 60 seconds in order to
3176 * force the attacker wait 60 seconds before getting
3177 * the information on whether a frame resulted in a MIC
3178 * failure.
3179 */
3180 u8 rval[4];
3181 int sec;
3182
3183 if (os_get_random(rval, sizeof(rval)) < 0)
3184 sec = os_random() % 60;
3185 else
3186 sec = WPA_GET_BE32(rval) % 60;
3187 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3188 "report %d seconds", sec);
3189 wpa_s->pending_mic_error_report = 1;
3190 wpa_s->pending_mic_error_pairwise = pairwise;
3191 eloop_cancel_timeout(
3192 wpa_supplicant_delayed_mic_error_report,
3193 wpa_s, NULL);
3194 eloop_register_timeout(
3195 sec, os_random() % 1000000,
3196 wpa_supplicant_delayed_mic_error_report,
3197 wpa_s, NULL);
3198 } else {
3199 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3200 }
3201#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3202 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3203#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3204 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003205 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003206 wpa_s->mic_errors_seen++;
3207}
3208
3209
3210#ifdef CONFIG_TERMINATE_ONLASTIF
3211static int any_interfaces(struct wpa_supplicant *head)
3212{
3213 struct wpa_supplicant *wpa_s;
3214
3215 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3216 if (!wpa_s->interface_removed)
3217 return 1;
3218 return 0;
3219}
3220#endif /* CONFIG_TERMINATE_ONLASTIF */
3221
3222
3223static void
3224wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3225 union wpa_event_data *data)
3226{
3227 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3228 return;
3229
3230 switch (data->interface_status.ievent) {
3231 case EVENT_INTERFACE_ADDED:
3232 if (!wpa_s->interface_removed)
3233 break;
3234 wpa_s->interface_removed = 0;
3235 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3236 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3237 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3238 "driver after interface was added");
3239 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003240
3241#ifdef CONFIG_P2P
3242 if (!wpa_s->global->p2p &&
3243 !wpa_s->global->p2p_disabled &&
3244 !wpa_s->conf->p2p_disabled &&
3245 (wpa_s->drv_flags &
3246 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3247 wpas_p2p_add_p2pdev_interface(
3248 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3249 wpa_printf(MSG_INFO,
3250 "P2P: Failed to enable P2P Device interface");
3251 /* Try to continue without. P2P will be disabled. */
3252 }
3253#endif /* CONFIG_P2P */
3254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003255 break;
3256 case EVENT_INTERFACE_REMOVED:
3257 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3258 wpa_s->interface_removed = 1;
3259 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003260 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003261 l2_packet_deinit(wpa_s->l2);
3262 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003263
3264#ifdef CONFIG_P2P
3265 if (wpa_s->global->p2p &&
3266 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3267 (wpa_s->drv_flags &
3268 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3269 wpa_dbg(wpa_s, MSG_DEBUG,
3270 "Removing P2P Device interface");
3271 wpa_supplicant_remove_iface(
3272 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3273 0);
3274 wpa_s->global->p2p_init_wpa_s = NULL;
3275 }
3276#endif /* CONFIG_P2P */
3277
Dmitry Shmidte4663042016-04-04 10:07:49 -07003278#ifdef CONFIG_MATCH_IFACE
3279 if (wpa_s->matched) {
3280 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3281 break;
3282 }
3283#endif /* CONFIG_MATCH_IFACE */
3284
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003285#ifdef CONFIG_TERMINATE_ONLASTIF
3286 /* check if last interface */
3287 if (!any_interfaces(wpa_s->global->ifaces))
3288 eloop_terminate();
3289#endif /* CONFIG_TERMINATE_ONLASTIF */
3290 break;
3291 }
3292}
3293
3294
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003295#ifdef CONFIG_TDLS
3296static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3297 union wpa_event_data *data)
3298{
3299 if (data == NULL)
3300 return;
3301 switch (data->tdls.oper) {
3302 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003303 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3304 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3305 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3306 else
3307 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003308 break;
3309 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003310 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3311 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3312 data->tdls.reason_code);
3313 else
3314 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3315 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003316 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003317 case TDLS_REQUEST_DISCOVER:
3318 wpa_tdls_send_discovery_request(wpa_s->wpa,
3319 data->tdls.peer);
3320 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003321 }
3322}
3323#endif /* CONFIG_TDLS */
3324
3325
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003326#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003327static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3328 union wpa_event_data *data)
3329{
3330 if (data == NULL)
3331 return;
3332 switch (data->wnm.oper) {
3333 case WNM_OPER_SLEEP:
3334 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3335 "(action=%d, intval=%d)",
3336 data->wnm.sleep_action, data->wnm.sleep_intval);
3337 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003338 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003339 break;
3340 }
3341}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003342#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003343
3344
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003345#ifdef CONFIG_IEEE80211R
3346static void
3347wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3348 union wpa_event_data *data)
3349{
3350 if (data == NULL)
3351 return;
3352
3353 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3354 data->ft_ies.ies_len,
3355 data->ft_ies.ft_action,
3356 data->ft_ies.target_ap,
3357 data->ft_ies.ric_ies,
3358 data->ft_ies.ric_ies_len) < 0) {
3359 /* TODO: prevent MLME/driver from trying to associate? */
3360 }
3361}
3362#endif /* CONFIG_IEEE80211R */
3363
3364
3365#ifdef CONFIG_IBSS_RSN
3366static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3367 union wpa_event_data *data)
3368{
3369 struct wpa_ssid *ssid;
3370 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3371 return;
3372 if (data == NULL)
3373 return;
3374 ssid = wpa_s->current_ssid;
3375 if (ssid == NULL)
3376 return;
3377 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3378 return;
3379
3380 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3381}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003382
3383
3384static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3385 union wpa_event_data *data)
3386{
3387 struct wpa_ssid *ssid = wpa_s->current_ssid;
3388
3389 if (ssid == NULL)
3390 return;
3391
3392 /* check if the ssid is correctly configured as IBSS/RSN */
3393 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3394 return;
3395
3396 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3397 data->rx_mgmt.frame_len);
3398}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003399#endif /* CONFIG_IBSS_RSN */
3400
3401
3402#ifdef CONFIG_IEEE80211R
3403static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3404 size_t len)
3405{
3406 const u8 *sta_addr, *target_ap_addr;
3407 u16 status;
3408
3409 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3410 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3411 return; /* only SME case supported for now */
3412 if (len < 1 + 2 * ETH_ALEN + 2)
3413 return;
3414 if (data[0] != 2)
3415 return; /* Only FT Action Response is supported for now */
3416 sta_addr = data + 1;
3417 target_ap_addr = data + 1 + ETH_ALEN;
3418 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3419 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3420 MACSTR " TargetAP " MACSTR " status %u",
3421 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3422
3423 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3424 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3425 " in FT Action Response", MAC2STR(sta_addr));
3426 return;
3427 }
3428
3429 if (status) {
3430 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3431 "failure (status code %d)", status);
3432 /* TODO: report error to FT code(?) */
3433 return;
3434 }
3435
3436 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3437 len - (1 + 2 * ETH_ALEN + 2), 1,
3438 target_ap_addr, NULL, 0) < 0)
3439 return;
3440
3441#ifdef CONFIG_SME
3442 {
3443 struct wpa_bss *bss;
3444 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3445 if (bss)
3446 wpa_s->sme.freq = bss->freq;
3447 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3448 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3449 WLAN_AUTH_FT);
3450 }
3451#endif /* CONFIG_SME */
3452}
3453#endif /* CONFIG_IEEE80211R */
3454
3455
3456static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3457 struct unprot_deauth *e)
3458{
3459#ifdef CONFIG_IEEE80211W
3460 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3461 "dropped: " MACSTR " -> " MACSTR
3462 " (reason code %u)",
3463 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3464 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3465#endif /* CONFIG_IEEE80211W */
3466}
3467
3468
3469static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3470 struct unprot_disassoc *e)
3471{
3472#ifdef CONFIG_IEEE80211W
3473 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3474 "dropped: " MACSTR " -> " MACSTR
3475 " (reason code %u)",
3476 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3477 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3478#endif /* CONFIG_IEEE80211W */
3479}
3480
3481
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003482static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3483 u16 reason_code, int locally_generated,
3484 const u8 *ie, size_t ie_len, int deauth)
3485{
3486#ifdef CONFIG_AP
3487 if (wpa_s->ap_iface && addr) {
3488 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3489 return;
3490 }
3491
3492 if (wpa_s->ap_iface) {
3493 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3494 return;
3495 }
3496#endif /* CONFIG_AP */
3497
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003498 if (!locally_generated)
3499 wpa_s->own_disconnect_req = 0;
3500
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003501 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3502
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003503 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3504 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3505 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3506 eapol_sm_failed(wpa_s->eapol))) &&
3507 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003508 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003509
3510#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003511 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003512 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3513 locally_generated) > 0) {
3514 /*
3515 * The interface was removed, so cannot continue
3516 * processing any additional operations after this.
3517 */
3518 return;
3519 }
3520 }
3521#endif /* CONFIG_P2P */
3522
3523 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3524 locally_generated);
3525}
3526
3527
3528static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3529 struct disassoc_info *info)
3530{
3531 u16 reason_code = 0;
3532 int locally_generated = 0;
3533 const u8 *addr = NULL;
3534 const u8 *ie = NULL;
3535 size_t ie_len = 0;
3536
3537 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3538
3539 if (info) {
3540 addr = info->addr;
3541 ie = info->ie;
3542 ie_len = info->ie_len;
3543 reason_code = info->reason_code;
3544 locally_generated = info->locally_generated;
3545 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
3546 locally_generated ? " (locally generated)" : "");
3547 if (addr)
3548 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3549 MAC2STR(addr));
3550 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3551 ie, ie_len);
3552 }
3553
3554#ifdef CONFIG_AP
3555 if (wpa_s->ap_iface && info && info->addr) {
3556 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3557 return;
3558 }
3559
3560 if (wpa_s->ap_iface) {
3561 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3562 return;
3563 }
3564#endif /* CONFIG_AP */
3565
3566#ifdef CONFIG_P2P
3567 if (info) {
3568 wpas_p2p_disassoc_notif(
3569 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3570 locally_generated);
3571 }
3572#endif /* CONFIG_P2P */
3573
3574 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3575 sme_event_disassoc(wpa_s, info);
3576
3577 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3578 ie, ie_len, 0);
3579}
3580
3581
3582static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3583 struct deauth_info *info)
3584{
3585 u16 reason_code = 0;
3586 int locally_generated = 0;
3587 const u8 *addr = NULL;
3588 const u8 *ie = NULL;
3589 size_t ie_len = 0;
3590
3591 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3592
3593 if (info) {
3594 addr = info->addr;
3595 ie = info->ie;
3596 ie_len = info->ie_len;
3597 reason_code = info->reason_code;
3598 locally_generated = info->locally_generated;
3599 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3600 reason_code,
3601 locally_generated ? " (locally generated)" : "");
3602 if (addr) {
3603 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3604 MAC2STR(addr));
3605 }
3606 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3607 ie, ie_len);
3608 }
3609
3610 wpa_reset_ft_completed(wpa_s->wpa);
3611
3612 wpas_event_disconnect(wpa_s, addr, reason_code,
3613 locally_generated, ie, ie_len, 1);
3614}
3615
3616
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003617static const char * reg_init_str(enum reg_change_initiator init)
3618{
3619 switch (init) {
3620 case REGDOM_SET_BY_CORE:
3621 return "CORE";
3622 case REGDOM_SET_BY_USER:
3623 return "USER";
3624 case REGDOM_SET_BY_DRIVER:
3625 return "DRIVER";
3626 case REGDOM_SET_BY_COUNTRY_IE:
3627 return "COUNTRY_IE";
3628 case REGDOM_BEACON_HINT:
3629 return "BEACON_HINT";
3630 }
3631 return "?";
3632}
3633
3634
3635static const char * reg_type_str(enum reg_type type)
3636{
3637 switch (type) {
3638 case REGDOM_TYPE_UNKNOWN:
3639 return "UNKNOWN";
3640 case REGDOM_TYPE_COUNTRY:
3641 return "COUNTRY";
3642 case REGDOM_TYPE_WORLD:
3643 return "WORLD";
3644 case REGDOM_TYPE_CUSTOM_WORLD:
3645 return "CUSTOM_WORLD";
3646 case REGDOM_TYPE_INTERSECTION:
3647 return "INTERSECTION";
3648 }
3649 return "?";
3650}
3651
3652
Hai Shalom74f70d42019-02-11 14:42:39 -08003653void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
3654 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003655{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003656 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003657 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003658
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003659 /*
3660 * To allow backwards compatibility with higher level layers that
3661 * assumed the REGDOM_CHANGE event is sent over the initially added
3662 * interface. Find the highest parent of this interface and use it to
3663 * send the event.
3664 */
3665 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3666 ;
3667
Hai Shalom74f70d42019-02-11 14:42:39 -08003668 if (info) {
3669 wpa_msg(ifs, MSG_INFO,
3670 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3671 reg_init_str(info->initiator), reg_type_str(info->type),
3672 info->alpha2[0] ? " alpha2=" : "",
3673 info->alpha2[0] ? info->alpha2 : "");
3674 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003675
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003676 if (wpa_s->drv_priv == NULL)
3677 return; /* Ignore event during drv initialization */
3678
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003679 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3680 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003681 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3682 ifs->ifname);
3683 free_hw_features(ifs);
3684 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003685 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003686
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003687 /* Restart PNO/sched_scan with updated channel list */
3688 if (ifs->pno) {
3689 wpas_stop_pno(ifs);
3690 wpas_start_pno(ifs);
3691 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
3692 wpa_dbg(ifs, MSG_DEBUG,
3693 "Channel list changed - restart sched_scan");
3694 wpas_scan_restart_sched_scan(ifs);
3695 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003696 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003697
3698 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003699}
3700
3701
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003702static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003703 const u8 *frame, size_t len, int freq,
3704 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003705{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003706 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003707 const u8 *payload;
3708 size_t plen;
3709 u8 category;
3710
3711 if (len < IEEE80211_HDRLEN + 2)
3712 return;
3713
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003714 mgmt = (const struct ieee80211_mgmt *) frame;
3715 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003716 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003717 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003718
3719 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3720 " Category=%u DataLen=%d freq=%d MHz",
3721 MAC2STR(mgmt->sa), category, (int) plen, freq);
3722
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003723 if (category == WLAN_ACTION_WMM) {
3724 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3725 return;
3726 }
3727
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003728#ifdef CONFIG_IEEE80211R
3729 if (category == WLAN_ACTION_FT) {
3730 ft_rx_action(wpa_s, payload, plen);
3731 return;
3732 }
3733#endif /* CONFIG_IEEE80211R */
3734
3735#ifdef CONFIG_IEEE80211W
3736#ifdef CONFIG_SME
3737 if (category == WLAN_ACTION_SA_QUERY) {
3738 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3739 return;
3740 }
3741#endif /* CONFIG_SME */
3742#endif /* CONFIG_IEEE80211W */
3743
3744#ifdef CONFIG_WNM
3745 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3746 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3747 return;
3748 }
3749#endif /* CONFIG_WNM */
3750
3751#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003752 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3753 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003754 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003755 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003756 payload, plen, freq) == 0)
3757 return;
3758#endif /* CONFIG_GAS */
3759
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003760#ifdef CONFIG_GAS_SERVER
3761 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3762 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3763 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
3764 mgmt->u.action.category,
3765 payload, plen, freq) == 0)
3766 return;
3767#endif /* CONFIG_GAS_SERVER */
3768
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003769#ifdef CONFIG_TDLS
3770 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3771 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3772 wpa_dbg(wpa_s, MSG_DEBUG,
3773 "TDLS: Received Discovery Response from " MACSTR,
3774 MAC2STR(mgmt->sa));
3775 return;
3776 }
3777#endif /* CONFIG_TDLS */
3778
3779#ifdef CONFIG_INTERWORKING
3780 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3781 payload[0] == QOS_QOS_MAP_CONFIG) {
3782 const u8 *pos = payload + 1;
3783 size_t qlen = plen - 1;
3784 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3785 MACSTR, MAC2STR(mgmt->sa));
3786 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3787 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3788 pos[1] <= qlen - 2 && pos[1] >= 16)
3789 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3790 return;
3791 }
3792#endif /* CONFIG_INTERWORKING */
3793
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003794 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003795 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
3796 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003797 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003798 payload + 1,
3799 plen - 1);
3800 return;
3801 }
3802
3803 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003804 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3805 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3806 return;
3807 }
3808
3809 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3810 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3811 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3812 payload + 1, plen - 1,
3813 rssi);
3814 return;
3815 }
3816
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003817#ifdef CONFIG_FST
3818 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3819 fst_rx_action(wpa_s->fst, mgmt, len);
3820 return;
3821 }
3822#endif /* CONFIG_FST */
3823
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003824#ifdef CONFIG_DPP
3825 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
3826 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
3827 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
3828 payload[4] == DPP_OUI_TYPE) {
3829 payload++;
3830 plen--;
3831 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
3832 return;
3833 }
3834#endif /* CONFIG_DPP */
3835
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003836 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3837 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003838 if (wpa_s->ifmsh)
3839 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003840}
3841
3842
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003843static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3844 union wpa_event_data *event)
3845{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003846 struct wpa_freq_range_list *list;
3847 char *str = NULL;
3848
3849 list = &event->freq_range;
3850
3851 if (list->num)
3852 str = freq_range_list_str(list);
3853 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3854 str ? str : "");
3855
3856#ifdef CONFIG_P2P
3857 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3858 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3859 __func__);
3860 } else {
3861 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003862
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003863 /*
3864 * The update channel flow will also take care of moving a GO
3865 * from the unsafe frequency if needed.
3866 */
3867 wpas_p2p_update_channel_list(wpa_s,
3868 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003869 }
3870#endif /* CONFIG_P2P */
3871
3872 os_free(str);
3873}
3874
3875
Roshan Pius3a1667e2018-07-03 15:17:14 -07003876static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003877{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003878 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3879 wpa_supplicant_cancel_auth_timeout(wpa_s);
3880 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3881 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3882 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3883 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003884}
3885
3886
3887static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
3888 int freq)
3889{
3890 size_t i;
3891 int j;
3892
3893 for (i = 0; i < wpa_s->hw.num_modes; i++) {
3894 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
3895
3896 for (j = 0; j < mode->num_channels; j++) {
3897 const struct hostapd_channel_data *chan;
3898
3899 chan = &mode->channels[j];
3900 if (chan->freq == freq)
3901 return chan->dfs_cac_ms;
3902 }
3903 }
3904
3905 return 0;
3906}
3907
3908
3909static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
3910 struct dfs_event *radar)
3911{
3912#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08003913 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003914 wpas_ap_event_dfs_cac_started(wpa_s, radar);
3915 } else
3916#endif /* NEED_AP_MLME && CONFIG_AP */
3917 {
3918 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
3919
3920 cac_time /= 1000; /* convert from ms to sec */
3921 if (!cac_time)
3922 cac_time = 10 * 60; /* max timeout: 10 minutes */
3923
3924 /* Restart auth timeout: CAC time added to initial timeout */
3925 wpas_auth_timeout_restart(wpa_s, cac_time);
3926 }
3927}
3928
3929
3930static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
3931 struct dfs_event *radar)
3932{
3933#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08003934 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003935 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
3936 } else
3937#endif /* NEED_AP_MLME && CONFIG_AP */
3938 {
3939 /* Restart auth timeout with original value after CAC is
3940 * finished */
3941 wpas_auth_timeout_restart(wpa_s, 0);
3942 }
3943}
3944
3945
3946static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
3947 struct dfs_event *radar)
3948{
3949#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08003950 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003951 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
3952 } else
3953#endif /* NEED_AP_MLME && CONFIG_AP */
3954 {
3955 /* Restart auth timeout with original value after CAC is
3956 * aborted */
3957 wpas_auth_timeout_restart(wpa_s, 0);
3958 }
3959}
3960
3961
3962static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3963 union wpa_event_data *data)
3964{
3965 wpa_dbg(wpa_s, MSG_DEBUG,
3966 "Connection authorized by device, previous state %d",
3967 wpa_s->wpa_state);
3968
3969 wpa_supplicant_event_port_authorized(wpa_s);
3970
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003971 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3972 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003973 data->assoc_info.ptk_kck_len,
3974 data->assoc_info.ptk_kek,
3975 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003976#ifdef CONFIG_FILS
3977 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
3978 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
3979 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3980
3981 /* Update ERP next sequence number */
3982 eapol_sm_update_erp_next_seq_num(
3983 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
3984
3985 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
3986 /* Add the new PMK and PMKID to the PMKSA cache */
3987 wpa_sm_pmksa_cache_add(wpa_s->wpa,
3988 data->assoc_info.fils_pmk,
3989 data->assoc_info.fils_pmk_len,
3990 data->assoc_info.fils_pmkid,
3991 wpa_s->bssid, fils_cache_id);
3992 } else if (data->assoc_info.fils_pmkid) {
3993 /* Update the current PMKSA used for this connection */
3994 pmksa_cache_set_current(wpa_s->wpa,
3995 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003996 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003997 }
3998 }
3999#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004000}
4001
4002
Roshan Pius3a1667e2018-07-03 15:17:14 -07004003static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4004 union wpa_event_data *data)
4005{
4006 const u8 *bssid = data->assoc_reject.bssid;
4007
4008 if (!bssid || is_zero_ether_addr(bssid))
4009 bssid = wpa_s->pending_bssid;
4010
4011 if (data->assoc_reject.bssid)
4012 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4013 "bssid=" MACSTR " status_code=%u%s%s%s",
4014 MAC2STR(data->assoc_reject.bssid),
4015 data->assoc_reject.status_code,
4016 data->assoc_reject.timed_out ? " timeout" : "",
4017 data->assoc_reject.timeout_reason ? "=" : "",
4018 data->assoc_reject.timeout_reason ?
4019 data->assoc_reject.timeout_reason : "");
4020 else
4021 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4022 "status_code=%u%s%s%s",
4023 data->assoc_reject.status_code,
4024 data->assoc_reject.timed_out ? " timeout" : "",
4025 data->assoc_reject.timeout_reason ? "=" : "",
4026 data->assoc_reject.timeout_reason ?
4027 data->assoc_reject.timeout_reason : "");
4028 wpa_s->assoc_status_code = data->assoc_reject.status_code;
4029 wpa_s->assoc_timed_out = data->assoc_reject.timed_out;
4030 wpas_notify_assoc_status_code(wpa_s);
4031
4032#ifdef CONFIG_OWE
4033 if (data->assoc_reject.status_code ==
4034 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4035 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4036 wpa_s->current_ssid &&
4037 wpa_s->current_ssid->owe_group == 0 &&
4038 wpa_s->last_owe_group != 21) {
4039 struct wpa_ssid *ssid = wpa_s->current_ssid;
4040 struct wpa_bss *bss = wpa_s->current_bss;
4041
4042 if (!bss) {
4043 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4044 if (!bss) {
4045 wpas_connection_failed(wpa_s, bssid);
4046 wpa_supplicant_mark_disassoc(wpa_s);
4047 return;
4048 }
4049 }
4050 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4051 wpas_connect_work_done(wpa_s);
4052 wpa_supplicant_mark_disassoc(wpa_s);
4053 wpa_supplicant_connect(wpa_s, bss, ssid);
4054 return;
4055 }
4056#endif /* CONFIG_OWE */
4057
Hai Shalom74f70d42019-02-11 14:42:39 -08004058#ifdef CONFIG_MBO
4059 if (data->assoc_reject.status_code ==
4060 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
4061 wpa_s->current_bss && data->assoc_reject.bssid &&
4062 data->assoc_reject.resp_ies) {
4063 const u8 *rssi_rej;
4064
4065 rssi_rej = mbo_get_attr_from_ies(
4066 data->assoc_reject.resp_ies,
4067 data->assoc_reject.resp_ies_len,
4068 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4069 if (rssi_rej && rssi_rej[1] == 2) {
4070 wpa_printf(MSG_DEBUG,
4071 "OCE: RSSI-based association rejection from "
4072 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
4073 MAC2STR(data->assoc_reject.bssid),
4074 rssi_rej[2], rssi_rej[3]);
4075 wpa_bss_tmp_disallow(wpa_s,
4076 data->assoc_reject.bssid,
4077 rssi_rej[3],
4078 rssi_rej[2] +
4079 wpa_s->current_bss->level);
4080 }
4081 }
4082#endif /* CONFIG_MBO */
4083
Roshan Pius3a1667e2018-07-03 15:17:14 -07004084 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4085 sme_event_assoc_reject(wpa_s, data);
4086 return;
4087 }
4088
4089 /* Driver-based SME cases */
4090
4091#ifdef CONFIG_SAE
4092 if (wpa_s->current_ssid &&
4093 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4094 !data->assoc_reject.timed_out) {
4095 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4096 wpa_sm_aborted_cached(wpa_s->wpa);
4097 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4098 }
4099#endif /* CONFIG_SAE */
4100
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004101#ifdef CONFIG_DPP
4102 if (wpa_s->current_ssid &&
4103 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4104 !data->assoc_reject.timed_out) {
4105 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4106 wpa_sm_aborted_cached(wpa_s->wpa);
4107 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4108 }
4109#endif /* CONFIG_DPP */
4110
Roshan Pius3a1667e2018-07-03 15:17:14 -07004111#ifdef CONFIG_FILS
4112 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004113 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004114 eapol_sm_update_erp_next_seq_num(
4115 wpa_s->eapol,
4116 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004117 fils_connection_failure(wpa_s);
4118 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004119#endif /* CONFIG_FILS */
4120
4121 wpas_connection_failed(wpa_s, bssid);
4122 wpa_supplicant_mark_disassoc(wpa_s);
4123}
4124
4125
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004126void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4127 union wpa_event_data *data)
4128{
4129 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004130 int resched;
Hai Shalom74f70d42019-02-11 14:42:39 -08004131#ifndef CONFIG_NO_STDOUT_DEBUG
4132 int level = MSG_DEBUG;
4133#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004134
4135 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4136 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004137 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004138 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004139 event != EVENT_SCHED_SCAN_STOPPED) {
4140 wpa_dbg(wpa_s, MSG_DEBUG,
4141 "Ignore event %s (%d) while interface is disabled",
4142 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004143 return;
4144 }
4145
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004146#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07004147 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004148 const struct ieee80211_hdr *hdr;
4149 u16 fc;
4150 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4151 fc = le_to_host16(hdr->frame_control);
4152 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4153 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4154 level = MSG_EXCESSIVE;
4155 }
4156
4157 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4158 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004159#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004160
4161 switch (event) {
4162 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004163#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004164 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4165 data->auth.ies_len))
4166 wpa_printf(MSG_DEBUG,
4167 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004168#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004169 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004170 wpa_s->auth_status_code = data->auth.status_code;
4171 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004172 break;
4173 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004174#ifdef CONFIG_TESTING_OPTIONS
4175 if (wpa_s->ignore_auth_resp) {
4176 wpa_printf(MSG_INFO,
4177 "EVENT_ASSOC - ignore_auth_resp active!");
4178 break;
4179 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004180 if (wpa_s->testing_resend_assoc) {
4181 wpa_printf(MSG_INFO,
4182 "EVENT_DEAUTH - testing_resend_assoc");
4183 break;
4184 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004185#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004186 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004187 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004188 if (data &&
4189 (data->assoc_info.authorized ||
4190 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4191 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004192 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004193 if (data) {
4194 wpa_msg(wpa_s, MSG_INFO,
4195 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4196 data->assoc_info.subnet_status);
4197 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004198 break;
4199 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004200 wpas_event_disassoc(wpa_s,
4201 data ? &data->disassoc_info : NULL);
4202 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004203 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004204#ifdef CONFIG_TESTING_OPTIONS
4205 if (wpa_s->ignore_auth_resp) {
4206 wpa_printf(MSG_INFO,
4207 "EVENT_DEAUTH - ignore_auth_resp active!");
4208 break;
4209 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004210 if (wpa_s->testing_resend_assoc) {
4211 wpa_printf(MSG_INFO,
4212 "EVENT_DEAUTH - testing_resend_assoc");
4213 break;
4214 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004215#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004216 wpas_event_deauth(wpa_s,
4217 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004218 break;
4219 case EVENT_MICHAEL_MIC_FAILURE:
4220 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4221 break;
4222#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004223 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004224 if (wpa_s->own_scan_requested ||
4225 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004226 struct os_reltime diff;
4227
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004228 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004229 os_reltime_sub(&wpa_s->scan_start_time,
4230 &wpa_s->scan_trigger_time, &diff);
4231 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4232 diff.sec, diff.usec);
4233 wpa_s->own_scan_requested = 0;
4234 wpa_s->own_scan_running = 1;
4235 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4236 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004237 wpa_msg_ctrl(wpa_s, MSG_INFO,
4238 WPA_EVENT_SCAN_STARTED "id=%u",
4239 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004240 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004241 wpa_msg_ctrl(wpa_s, MSG_INFO,
4242 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004243 }
4244 } else {
4245 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004246 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004247 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004248 }
4249 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004250 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004251 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4252 wpa_s->scan_res_handler = NULL;
4253 wpa_s->own_scan_running = 0;
4254 wpa_s->radio->external_scan_running = 0;
4255 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4256 break;
4257 }
4258
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004259 if (!(data && data->scan_info.external_scan) &&
4260 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004261 struct os_reltime now, diff;
4262 os_get_reltime(&now);
4263 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4264 wpa_s->scan_start_time.sec = 0;
4265 wpa_s->scan_start_time.usec = 0;
4266 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4267 diff.sec, diff.usec);
4268 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004269 if (wpa_supplicant_event_scan_results(wpa_s, data))
4270 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004271 if (!(data && data->scan_info.external_scan))
4272 wpa_s->own_scan_running = 0;
4273 if (data && data->scan_info.nl_scan_event)
4274 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004275 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004276 break;
4277#endif /* CONFIG_NO_SCAN_PROCESSING */
4278 case EVENT_ASSOCINFO:
4279 wpa_supplicant_event_associnfo(wpa_s, data);
4280 break;
4281 case EVENT_INTERFACE_STATUS:
4282 wpa_supplicant_event_interface_status(wpa_s, data);
4283 break;
4284 case EVENT_PMKID_CANDIDATE:
4285 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4286 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004287#ifdef CONFIG_TDLS
4288 case EVENT_TDLS:
4289 wpa_supplicant_event_tdls(wpa_s, data);
4290 break;
4291#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004292#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004293 case EVENT_WNM:
4294 wpa_supplicant_event_wnm(wpa_s, data);
4295 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004296#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004297#ifdef CONFIG_IEEE80211R
4298 case EVENT_FT_RESPONSE:
4299 wpa_supplicant_event_ft_response(wpa_s, data);
4300 break;
4301#endif /* CONFIG_IEEE80211R */
4302#ifdef CONFIG_IBSS_RSN
4303 case EVENT_IBSS_RSN_START:
4304 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4305 break;
4306#endif /* CONFIG_IBSS_RSN */
4307 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004308 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004309 break;
4310 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004311 /* It is possible to get this event from earlier connection */
4312 if (wpa_s->current_ssid &&
4313 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4314 wpa_dbg(wpa_s, MSG_DEBUG,
4315 "Ignore AUTH_TIMED_OUT in mesh configuration");
4316 break;
4317 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004318 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4319 sme_event_auth_timed_out(wpa_s, data);
4320 break;
4321 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004322 /* It is possible to get this event from earlier connection */
4323 if (wpa_s->current_ssid &&
4324 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4325 wpa_dbg(wpa_s, MSG_DEBUG,
4326 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4327 break;
4328 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004329 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4330 sme_event_assoc_timed_out(wpa_s, data);
4331 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004332 case EVENT_TX_STATUS:
4333 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4334 " type=%d stype=%d",
4335 MAC2STR(data->tx_status.dst),
4336 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004337#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004338 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004339#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004340 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4341 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004342 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004343 wpa_s, data->tx_status.dst,
4344 data->tx_status.data,
4345 data->tx_status.data_len,
4346 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004347 OFFCHANNEL_SEND_ACTION_SUCCESS :
4348 OFFCHANNEL_SEND_ACTION_NO_ACK);
4349#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004350 break;
4351 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004352#endif /* CONFIG_AP */
4353#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004354 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004355 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004356 /*
4357 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004358 * interface in GO mode, or via standalone AP interface.
4359 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4360 * except when the primary interface is used as a GO interface
4361 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004362 */
4363 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4364 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004365 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004366 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004367 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004368 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004369 data->tx_status.data,
4370 data->tx_status.data_len,
4371 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004372 OFFCHANNEL_SEND_ACTION_SUCCESS :
4373 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004374 break;
4375 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004376#endif /* CONFIG_OFFCHANNEL */
4377#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004378 switch (data->tx_status.type) {
4379 case WLAN_FC_TYPE_MGMT:
4380 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4381 data->tx_status.data_len,
4382 data->tx_status.stype,
4383 data->tx_status.ack);
4384 break;
4385 case WLAN_FC_TYPE_DATA:
4386 ap_tx_status(wpa_s, data->tx_status.dst,
4387 data->tx_status.data,
4388 data->tx_status.data_len,
4389 data->tx_status.ack);
4390 break;
4391 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004392#endif /* CONFIG_AP */
4393 break;
4394#ifdef CONFIG_AP
4395 case EVENT_EAPOL_TX_STATUS:
4396 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4397 data->eapol_tx_status.data,
4398 data->eapol_tx_status.data_len,
4399 data->eapol_tx_status.ack);
4400 break;
4401 case EVENT_DRIVER_CLIENT_POLL_OK:
4402 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004403 break;
4404 case EVENT_RX_FROM_UNKNOWN:
4405 if (wpa_s->ap_iface == NULL)
4406 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004407 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4408 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004409 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004410#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004411 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004412 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004413 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004414
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004415 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
4416 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4417 data->ch_switch.freq,
4418 data->ch_switch.ht_enabled,
4419 data->ch_switch.ch_offset,
4420 channel_width_to_string(data->ch_switch.ch_width),
4421 data->ch_switch.cf1,
4422 data->ch_switch.cf2);
4423
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004424 wpa_s->assoc_freq = data->ch_switch.freq;
4425 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4426
Roshan Pius3a1667e2018-07-03 15:17:14 -07004427#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004428 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4429 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08004430 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004431 wpa_s->current_ssid->mode ==
4432 WPAS_MODE_P2P_GROUP_FORMATION) {
4433 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4434 data->ch_switch.ht_enabled,
4435 data->ch_switch.ch_offset,
4436 data->ch_switch.ch_width,
4437 data->ch_switch.cf1,
4438 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004439 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004440#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004441
Hai Shalom74f70d42019-02-11 14:42:39 -08004442#ifdef CONFIG_IEEE80211W
4443 sme_event_ch_switch(wpa_s);
4444#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004445 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004446 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004447 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004448#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004449#ifdef NEED_AP_MLME
4450 case EVENT_DFS_RADAR_DETECTED:
4451 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004452 wpas_ap_event_dfs_radar_detected(wpa_s,
4453 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004454 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004455 case EVENT_DFS_NOP_FINISHED:
4456 if (data)
4457 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
4458 &data->dfs_event);
4459 break;
4460#endif /* NEED_AP_MLME */
4461#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004462 case EVENT_DFS_CAC_STARTED:
4463 if (data)
4464 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
4465 break;
4466 case EVENT_DFS_CAC_FINISHED:
4467 if (data)
4468 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
4469 break;
4470 case EVENT_DFS_CAC_ABORTED:
4471 if (data)
4472 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
4473 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004474 case EVENT_RX_MGMT: {
4475 u16 fc, stype;
4476 const struct ieee80211_mgmt *mgmt;
4477
Dmitry Shmidt818ea482014-03-10 13:15:21 -07004478#ifdef CONFIG_TESTING_OPTIONS
4479 if (wpa_s->ext_mgmt_frame_handling) {
4480 struct rx_mgmt *rx = &data->rx_mgmt;
4481 size_t hex_len = 2 * rx->frame_len + 1;
4482 char *hex = os_malloc(hex_len);
4483 if (hex) {
4484 wpa_snprintf_hex(hex, hex_len,
4485 rx->frame, rx->frame_len);
4486 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4487 rx->freq, rx->datarate, rx->ssi_signal,
4488 hex);
4489 os_free(hex);
4490 }
4491 break;
4492 }
4493#endif /* CONFIG_TESTING_OPTIONS */
4494
Dmitry Shmidt04949592012-07-19 12:16:46 -07004495 mgmt = (const struct ieee80211_mgmt *)
4496 data->rx_mgmt.frame;
4497 fc = le_to_host16(mgmt->frame_control);
4498 stype = WLAN_FC_GET_STYPE(fc);
4499
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004500#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004501 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004502#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004503#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004504 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004505 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004506 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07004507 const u8 *ie;
4508 size_t ie_len;
4509
4510 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4511 ie_len = data->rx_mgmt.frame_len -
4512 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004513 wpas_p2p_probe_req_rx(
4514 wpa_s, src, mgmt->da,
4515 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004516 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004517 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004518 break;
4519 }
4520#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004521#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004522 if (wpa_s->current_ssid &&
4523 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4524 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004525 data->rx_mgmt.frame_len >= 30) {
4526 wpa_supplicant_event_ibss_auth(wpa_s, data);
4527 break;
4528 }
4529#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004530
4531 if (stype == WLAN_FC_STYPE_ACTION) {
4532 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004533 wpa_s, data->rx_mgmt.frame,
4534 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004535 data->rx_mgmt.freq,
4536 data->rx_mgmt.ssi_signal);
4537 break;
4538 }
4539
4540 if (wpa_s->ifmsh) {
4541 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004542 break;
4543 }
4544
Roshan Pius3a1667e2018-07-03 15:17:14 -07004545#ifdef CONFIG_SAE
4546 if (stype == WLAN_FC_STYPE_AUTH &&
4547 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4548 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4549 sme_external_auth_mgmt_rx(
4550 wpa_s, data->rx_mgmt.frame,
4551 data->rx_mgmt.frame_len);
4552 break;
4553 }
4554#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004555 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
4556 "management frame in non-AP mode");
4557 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004558#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004559 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004560
4561 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004562 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4563 const u8 *ie;
4564 size_t ie_len;
4565
4566 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4567 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004568
4569 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
4570 mgmt->bssid, ie, ie_len,
4571 data->rx_mgmt.ssi_signal);
4572 }
4573
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004574 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004575#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004576 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004577 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004578 case EVENT_RX_PROBE_REQ:
4579 if (data->rx_probe_req.sa == NULL ||
4580 data->rx_probe_req.ie == NULL)
4581 break;
4582#ifdef CONFIG_AP
4583 if (wpa_s->ap_iface) {
4584 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
4585 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004586 data->rx_probe_req.da,
4587 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004588 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004589 data->rx_probe_req.ie_len,
4590 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004591 break;
4592 }
4593#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004594 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004595 data->rx_probe_req.da,
4596 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004597 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004598 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004599 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004600 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004601 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004602 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004603#ifdef CONFIG_OFFCHANNEL
4604 offchannel_remain_on_channel_cb(
4605 wpa_s, data->remain_on_channel.freq,
4606 data->remain_on_channel.duration);
4607#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004608 wpas_p2p_remain_on_channel_cb(
4609 wpa_s, data->remain_on_channel.freq,
4610 data->remain_on_channel.duration);
4611 break;
4612 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004613#ifdef CONFIG_OFFCHANNEL
4614 offchannel_cancel_remain_on_channel_cb(
4615 wpa_s, data->remain_on_channel.freq);
4616#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004617 wpas_p2p_cancel_remain_on_channel_cb(
4618 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004619#ifdef CONFIG_DPP
4620 wpas_dpp_cancel_remain_on_channel_cb(
4621 wpa_s, data->remain_on_channel.freq);
4622#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004623 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004624 case EVENT_EAPOL_RX:
4625 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
4626 data->eapol_rx.data,
4627 data->eapol_rx.data_len);
4628 break;
4629 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004630 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
4631 "above=%d signal=%d noise=%d txrate=%d",
4632 data->signal_change.above_threshold,
4633 data->signal_change.current_signal,
4634 data->signal_change.current_noise,
4635 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004636 wpa_bss_update_level(wpa_s->current_bss,
4637 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004638 bgscan_notify_signal_change(
4639 wpa_s, data->signal_change.above_threshold,
4640 data->signal_change.current_signal,
4641 data->signal_change.current_noise,
4642 data->signal_change.current_txrate);
4643 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004644 case EVENT_INTERFACE_MAC_CHANGED:
4645 wpa_supplicant_update_mac_addr(wpa_s);
4646 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004647 case EVENT_INTERFACE_ENABLED:
4648 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
4649 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004650 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004651 if (wpa_s->p2p_mgmt) {
4652 wpa_supplicant_set_state(wpa_s,
4653 WPA_DISCONNECTED);
4654 break;
4655 }
4656
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004657#ifdef CONFIG_AP
4658 if (!wpa_s->ap_iface) {
4659 wpa_supplicant_set_state(wpa_s,
4660 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004661 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004662 wpa_supplicant_req_scan(wpa_s, 0, 0);
4663 } else
4664 wpa_supplicant_set_state(wpa_s,
4665 WPA_COMPLETED);
4666#else /* CONFIG_AP */
4667 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
4668 wpa_supplicant_req_scan(wpa_s, 0, 0);
4669#endif /* CONFIG_AP */
4670 }
4671 break;
4672 case EVENT_INTERFACE_DISABLED:
4673 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004674#ifdef CONFIG_P2P
4675 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
4676 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
4677 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
4678 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004679 * Mark interface disabled if this happens to end up not
4680 * being removed as a separate P2P group interface.
4681 */
4682 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4683 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004684 * The interface was externally disabled. Remove
4685 * it assuming an external entity will start a
4686 * new session if needed.
4687 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004688 if (wpa_s->current_ssid &&
4689 wpa_s->current_ssid->p2p_group)
4690 wpas_p2p_interface_unavailable(wpa_s);
4691 else
4692 wpas_p2p_disconnect(wpa_s);
4693 /*
4694 * wpa_s instance may have been freed, so must not use
4695 * it here anymore.
4696 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004697 break;
4698 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004699 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
4700 p2p_in_progress(wpa_s->global->p2p) > 1) {
4701 /* This radio work will be cancelled, so clear P2P
4702 * state as well.
4703 */
4704 p2p_stop_find(wpa_s->global->p2p);
4705 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004706#endif /* CONFIG_P2P */
4707
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004708 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4709 /*
4710 * Indicate disconnection to keep ctrl_iface events
4711 * consistent.
4712 */
4713 wpa_supplicant_event_disassoc(
4714 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
4715 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004716 wpa_supplicant_mark_disassoc(wpa_s);
xshud0ee72f2018-11-08 14:37:01 -08004717 if (!wpa_s->conf->bss_no_flush_when_down)
4718 wpa_bss_flush(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08004719 radio_remove_works(wpa_s, NULL, 0);
4720
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004721 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4722 break;
4723 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004724 wpa_supplicant_update_channel_list(
4725 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004726 break;
4727 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004728 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004729 break;
4730 case EVENT_BEST_CHANNEL:
4731 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
4732 "(%d %d %d)",
4733 data->best_chan.freq_24, data->best_chan.freq_5,
4734 data->best_chan.freq_overall);
4735 wpa_s->best_24_freq = data->best_chan.freq_24;
4736 wpa_s->best_5_freq = data->best_chan.freq_5;
4737 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004738 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
4739 data->best_chan.freq_5,
4740 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004741 break;
4742 case EVENT_UNPROT_DEAUTH:
4743 wpa_supplicant_event_unprot_deauth(wpa_s,
4744 &data->unprot_deauth);
4745 break;
4746 case EVENT_UNPROT_DISASSOC:
4747 wpa_supplicant_event_unprot_disassoc(wpa_s,
4748 &data->unprot_disassoc);
4749 break;
4750 case EVENT_STATION_LOW_ACK:
4751#ifdef CONFIG_AP
4752 if (wpa_s->ap_iface && data)
4753 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
4754 data->low_ack.addr);
4755#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004756#ifdef CONFIG_TDLS
4757 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07004758 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
4759 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004760#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004761 break;
4762 case EVENT_IBSS_PEER_LOST:
4763#ifdef CONFIG_IBSS_RSN
4764 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
4765#endif /* CONFIG_IBSS_RSN */
4766 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004767 case EVENT_DRIVER_GTK_REKEY:
4768 if (os_memcmp(data->driver_gtk_rekey.bssid,
4769 wpa_s->bssid, ETH_ALEN))
4770 break;
4771 if (!wpa_s->wpa)
4772 break;
4773 wpa_sm_update_replay_ctr(wpa_s->wpa,
4774 data->driver_gtk_rekey.replay_ctr);
4775 break;
4776 case EVENT_SCHED_SCAN_STOPPED:
4777 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004778 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004779 wpa_supplicant_notify_scanning(wpa_s, 0);
4780
4781 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4782 break;
4783
4784 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004785 * If the driver stopped scanning without being requested to,
4786 * request a new scan to continue scanning for networks.
4787 */
4788 if (!wpa_s->sched_scan_stop_req &&
4789 wpa_s->wpa_state == WPA_SCANNING) {
4790 wpa_dbg(wpa_s, MSG_DEBUG,
4791 "Restart scanning after unexpected sched_scan stop event");
4792 wpa_supplicant_req_scan(wpa_s, 1, 0);
4793 break;
4794 }
4795
4796 wpa_s->sched_scan_stop_req = 0;
4797
4798 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08004799 * Start a new sched scan to continue searching for more SSIDs
4800 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004801 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07004802 if (wpa_s->sched_scan_timed_out) {
4803 wpa_supplicant_req_sched_scan(wpa_s);
4804 } else if (wpa_s->pno_sched_pending) {
4805 wpa_s->pno_sched_pending = 0;
4806 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004807 } else if (resched) {
4808 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08004809 }
4810
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004811 break;
4812 case EVENT_WPS_BUTTON_PUSHED:
4813#ifdef CONFIG_WPS
4814 wpas_wps_start_pbc(wpa_s, NULL, 0);
4815#endif /* CONFIG_WPS */
4816 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004817 case EVENT_AVOID_FREQUENCIES:
4818 wpa_supplicant_notify_avoid_freq(wpa_s, data);
4819 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004820 case EVENT_CONNECT_FAILED_REASON:
4821#ifdef CONFIG_AP
4822 if (!wpa_s->ap_iface || !data)
4823 break;
4824 hostapd_event_connect_failed_reason(
4825 wpa_s->ap_iface->bss[0],
4826 data->connect_failed_reason.addr,
4827 data->connect_failed_reason.code);
4828#endif /* CONFIG_AP */
4829 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004830 case EVENT_NEW_PEER_CANDIDATE:
4831#ifdef CONFIG_MESH
4832 if (!wpa_s->ifmsh || !data)
4833 break;
4834 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4835 data->mesh_peer.ies,
4836 data->mesh_peer.ie_len);
4837#endif /* CONFIG_MESH */
4838 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004839 case EVENT_SURVEY:
4840#ifdef CONFIG_AP
4841 if (!wpa_s->ap_iface)
4842 break;
4843 hostapd_event_get_survey(wpa_s->ap_iface,
4844 &data->survey_results);
4845#endif /* CONFIG_AP */
4846 break;
4847 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08004848#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004849#ifdef CONFIG_ACS
4850 if (!wpa_s->ap_iface)
4851 break;
4852 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4853 &data->acs_selected_channels);
4854#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08004855#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004856 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004857 case EVENT_P2P_LO_STOP:
4858#ifdef CONFIG_P2P
4859 wpa_s->p2p_lo_started = 0;
4860 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
4861 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
4862 data->p2p_lo_stop.reason_code);
4863#endif /* CONFIG_P2P */
4864 break;
Paul Stewart092955c2017-02-06 09:13:09 -08004865 case EVENT_BEACON_LOSS:
4866 if (!wpa_s->current_bss || !wpa_s->current_ssid)
4867 break;
4868 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
4869 bgscan_notify_beacon_loss(wpa_s);
4870 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004871 case EVENT_EXTERNAL_AUTH:
4872#ifdef CONFIG_SAE
4873 if (!wpa_s->current_ssid) {
4874 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
4875 break;
4876 }
4877 sme_external_auth_trigger(wpa_s, data);
4878#endif /* CONFIG_SAE */
4879 break;
4880 case EVENT_PORT_AUTHORIZED:
4881 wpa_supplicant_event_port_authorized(wpa_s);
4882 break;
4883 case EVENT_STATION_OPMODE_CHANGED:
4884#ifdef CONFIG_AP
4885 if (!wpa_s->ap_iface || !data)
4886 break;
4887
4888 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
4889 data->sta_opmode.addr,
4890 data->sta_opmode.smps_mode,
4891 data->sta_opmode.chan_width,
4892 data->sta_opmode.rx_nss);
4893#endif /* CONFIG_AP */
4894 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004895 default:
4896 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4897 break;
4898 }
4899}
Dmitry Shmidte4663042016-04-04 10:07:49 -07004900
4901
4902void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
4903 union wpa_event_data *data)
4904{
4905 struct wpa_supplicant *wpa_s;
4906
4907 if (event != EVENT_INTERFACE_STATUS)
4908 return;
4909
4910 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
4911 if (wpa_s && wpa_s->driver->get_ifindex) {
4912 unsigned int ifindex;
4913
4914 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
4915 if (ifindex != data->interface_status.ifindex) {
4916 wpa_dbg(wpa_s, MSG_DEBUG,
4917 "interface status ifindex %d mismatch (%d)",
4918 ifindex, data->interface_status.ifindex);
4919 return;
4920 }
4921 }
4922#ifdef CONFIG_MATCH_IFACE
4923 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
4924 struct wpa_interface *wpa_i;
4925
4926 wpa_i = wpa_supplicant_match_iface(
4927 ctx, data->interface_status.ifname);
4928 if (!wpa_i)
4929 return;
4930 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
4931 os_free(wpa_i);
4932 if (wpa_s)
4933 wpa_s->matched = 1;
4934 }
4935#endif /* CONFIG_MATCH_IFACE */
4936
4937 if (wpa_s)
4938 wpa_supplicant_event(wpa_s, event, data);
4939}