blob: 471fc17e3ad7e7decda349b5704baf017736656c [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Hai Shalom021b0b52019-04-10 11:17:58 -07003 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "notify.h"
29#include "common/ieee802_11_defs.h"
30#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070031#include "common/gas_server.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070032#include "common/dpp.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "crypto/random.h"
34#include "blacklist.h"
35#include "wpas_glue.h"
36#include "wps_supplicant.h"
37#include "ibss_rsn.h"
38#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080039#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "p2p_supplicant.h"
41#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070042#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "ap.h"
44#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080046#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070047#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080048#include "mesh.h"
49#include "mesh_mpm.h"
50#include "wmm_ac.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070051#include "dpp_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070052
53
Hai Shalom39ba6fc2019-01-22 12:40:38 -080054#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
55
56
Dmitry Shmidt34af3062013-07-11 10:46:32 -070057#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070058static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080059 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070060#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080061
62
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070063int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070064{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080065 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066
67 if (ssid == NULL || ssid->disabled_until.sec == 0)
68 return 0;
69
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080070 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070071 if (ssid->disabled_until.sec > now.sec)
72 return ssid->disabled_until.sec - now.sec;
73
74 wpas_clear_temp_disabled(wpa_s, ssid, 0);
75
76 return 0;
77}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070078
79
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080080#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070081/**
82 * wpas_reenabled_network_time - Time until first network is re-enabled
83 * @wpa_s: Pointer to wpa_supplicant data
84 * Returns: If all enabled networks are temporarily disabled, returns the time
85 * (in sec) until the first network is re-enabled. Otherwise returns 0.
86 *
87 * This function is used in case all enabled networks are temporarily disabled,
88 * in which case it returns the time (in sec) that the first network will be
89 * re-enabled. The function assumes that at least one network is enabled.
90 */
91static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
92{
93 struct wpa_ssid *ssid;
94 int disabled_for, res = 0;
95
96#ifdef CONFIG_INTERWORKING
97 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
98 wpa_s->conf->cred)
99 return 0;
100#endif /* CONFIG_INTERWORKING */
101
102 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
103 if (ssid->disabled)
104 continue;
105
106 disabled_for = wpas_temp_disabled(wpa_s, ssid);
107 if (!disabled_for)
108 return 0;
109
110 if (!res || disabled_for < res)
111 res = disabled_for;
112 }
113
114 return res;
115}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800116#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700117
118
119void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
120{
121 struct wpa_supplicant *wpa_s = eloop_ctx;
122
123 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
124 return;
125
126 wpa_dbg(wpa_s, MSG_DEBUG,
127 "Try to associate due to network getting re-enabled");
128 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
129 wpa_supplicant_cancel_sched_scan(wpa_s);
130 wpa_supplicant_req_scan(wpa_s, 0, 0);
131 }
132}
133
134
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800135static struct wpa_bss * wpa_supplicant_get_new_bss(
136 struct wpa_supplicant *wpa_s, const u8 *bssid)
137{
138 struct wpa_bss *bss = NULL;
139 struct wpa_ssid *ssid = wpa_s->current_ssid;
140
141 if (ssid->ssid_len > 0)
142 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
143 if (!bss)
144 bss = wpa_bss_get_bssid(wpa_s, bssid);
145
146 return bss;
147}
148
149
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700150static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
151{
152 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
153
154 if (!bss) {
155 wpa_supplicant_update_scan_results(wpa_s);
156
157 /* Get the BSS from the new scan results */
158 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
159 }
160
161 if (bss)
162 wpa_s->current_bss = bss;
163}
164
165
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700166static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
167{
168 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700169 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700170 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700171 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700173 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
174 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700175
176 if (wpa_s->current_ssid->ssid_len == 0)
177 return 0; /* current profile still in use */
178 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
179 if (res < 0) {
180 wpa_msg(wpa_s, MSG_INFO,
181 "Failed to read SSID from driver");
182 return 0; /* try to use current profile */
183 }
184 drv_ssid_len = res;
185
186 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
187 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
188 drv_ssid_len) == 0)
189 return 0; /* current profile still in use */
190
191 wpa_msg(wpa_s, MSG_DEBUG,
192 "Driver-initiated BSS selection changed the SSID to %s",
193 wpa_ssid_txt(drv_ssid, drv_ssid_len));
194 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700195 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700196
197 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
198 "information");
199 ssid = wpa_supplicant_get_ssid(wpa_s);
200 if (ssid == NULL) {
201 wpa_msg(wpa_s, MSG_INFO,
202 "No network configuration found for the current AP");
203 return -1;
204 }
205
Dmitry Shmidt04949592012-07-19 12:16:46 -0700206 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700207 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
208 return -1;
209 }
210
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800211 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
212 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
213 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
214 return -1;
215 }
216
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700217 res = wpas_temp_disabled(wpa_s, ssid);
218 if (res > 0) {
219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
220 "disabled for %d second(s)", res);
221 return -1;
222 }
223
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
225 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800226 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227 u8 wpa_ie[80];
228 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800229 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
230 wpa_ie, &wpa_ie_len) < 0)
231 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700232 } else {
233 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
234 }
235
236 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
237 eapol_sm_invalidate_cached_session(wpa_s->eapol);
238 old_ssid = wpa_s->current_ssid;
239 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800240
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700241 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800242
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
244 wpa_supplicant_initiate_eapol(wpa_s);
245 if (old_ssid != wpa_s->current_ssid)
246 wpas_notify_network_changed(wpa_s);
247
248 return 0;
249}
250
251
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800252void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253{
254 struct wpa_supplicant *wpa_s = eloop_ctx;
255
256 if (wpa_s->countermeasures) {
257 wpa_s->countermeasures = 0;
258 wpa_drv_set_countermeasures(wpa_s, 0);
259 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800260
261 /*
262 * It is possible that the device is sched scanning, which means
263 * that a connection attempt will be done only when we receive
264 * scan results. However, in this case, it would be preferable
265 * to scan and connect immediately, so cancel the sched_scan and
266 * issue a regular scan flow.
267 */
268 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269 wpa_supplicant_req_scan(wpa_s, 0, 0);
270 }
271}
272
273
274void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
275{
276 int bssid_changed;
277
Dmitry Shmidt04949592012-07-19 12:16:46 -0700278 wnm_bss_keep_alive_deinit(wpa_s);
279
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280#ifdef CONFIG_IBSS_RSN
281 ibss_rsn_deinit(wpa_s->ibss_rsn);
282 wpa_s->ibss_rsn = NULL;
283#endif /* CONFIG_IBSS_RSN */
284
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700285#ifdef CONFIG_AP
286 wpa_supplicant_ap_deinit(wpa_s);
287#endif /* CONFIG_AP */
288
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700289#ifdef CONFIG_HS20
290 /* Clear possibly configured frame filters */
291 wpa_drv_configure_frame_filters(wpa_s, 0);
292#endif /* CONFIG_HS20 */
293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
295 return;
296
Hai Shalom74f70d42019-02-11 14:42:39 -0800297 if (os_reltime_initialized(&wpa_s->session_start)) {
298 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
299 wpa_s->session_start.sec = 0;
300 wpa_s->session_start.usec = 0;
301 wpas_notify_session_length(wpa_s);
302 }
303
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
305 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
306 os_memset(wpa_s->bssid, 0, ETH_ALEN);
307 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800308 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700309 wpa_s->current_bss = NULL;
310 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700311
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312 if (bssid_changed)
313 wpas_notify_bssid_changed(wpa_s);
314
315 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
316 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700317 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
318 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
319 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
321 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700322 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700323 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700324 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800325
326 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800327 wpa_s->wnmsleep_used = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800328 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700329
330#ifdef CONFIG_TESTING_OPTIONS
331 wpa_s->last_tk_alg = WPA_ALG_NONE;
332 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
333#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700334 wpa_s->ieee80211ac = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800335
336 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
337 wpa_s->enabled_4addr_mode = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338}
339
340
341static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
342{
343 struct wpa_ie_data ie;
344 int pmksa_set = -1;
345 size_t i;
346
347 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
348 ie.pmkid == NULL)
349 return;
350
351 for (i = 0; i < ie.num_pmkid; i++) {
352 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
353 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700354 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700355 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800356 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357 break;
358 }
359 }
360
361 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
362 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
363}
364
365
366static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
367 union wpa_event_data *data)
368{
369 if (data == NULL) {
370 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
371 "event");
372 return;
373 }
374 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
375 " index=%d preauth=%d",
376 MAC2STR(data->pmkid_candidate.bssid),
377 data->pmkid_candidate.index,
378 data->pmkid_candidate.preauth);
379
380 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
381 data->pmkid_candidate.index,
382 data->pmkid_candidate.preauth);
383}
384
385
386static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
387{
388 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
389 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
390 return 0;
391
392#ifdef IEEE8021X_EAPOL
393 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
394 wpa_s->current_ssid &&
395 !(wpa_s->current_ssid->eapol_flags &
396 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
397 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
398 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
399 * plaintext or static WEP keys). */
400 return 0;
401 }
402#endif /* IEEE8021X_EAPOL */
403
404 return 1;
405}
406
407
408/**
409 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
410 * @wpa_s: pointer to wpa_supplicant data
411 * @ssid: Configuration data for the network
412 * Returns: 0 on success, -1 on failure
413 *
414 * This function is called when starting authentication with a network that is
415 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
416 */
417int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
418 struct wpa_ssid *ssid)
419{
420#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800421#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700422 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700423
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700424 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
425 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426 return 0;
427
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700428 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700429 sim = 1;
430 aka = 1;
431 } else {
432 struct eap_method_type *eap = ssid->eap.eap_methods;
433 while (eap->vendor != EAP_VENDOR_IETF ||
434 eap->method != EAP_TYPE_NONE) {
435 if (eap->vendor == EAP_VENDOR_IETF) {
436 if (eap->method == EAP_TYPE_SIM)
437 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700438 else if (eap->method == EAP_TYPE_AKA ||
439 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 aka = 1;
441 }
442 eap++;
443 }
444 }
445
446 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
447 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700448 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
449 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
450 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 aka = 0;
452
453 if (!sim && !aka) {
454 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
455 "use SIM, but neither EAP-SIM nor EAP-AKA are "
456 "enabled");
457 return 0;
458 }
459
460 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
461 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700462
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700463 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700464 if (wpa_s->scard == NULL) {
465 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
466 "(pcsc-lite)");
467 return -1;
468 }
469 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
470 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800471#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700472#endif /* IEEE8021X_EAPOL */
473
474 return 0;
475}
476
477
478#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700479
480static int has_wep_key(struct wpa_ssid *ssid)
481{
482 int i;
483
484 for (i = 0; i < NUM_WEP_KEYS; i++) {
485 if (ssid->wep_key_len[i])
486 return 1;
487 }
488
489 return 0;
490}
491
492
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700493static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700494 struct wpa_ssid *ssid)
495{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700496 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700497
498 if (ssid->mixed_cell)
499 return 1;
500
501#ifdef CONFIG_WPS
502 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
503 return 1;
504#endif /* CONFIG_WPS */
505
Roshan Pius3a1667e2018-07-03 15:17:14 -0700506#ifdef CONFIG_OWE
507 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
508 return 1;
509#endif /* CONFIG_OWE */
510
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700511 if (has_wep_key(ssid))
512 privacy = 1;
513
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514#ifdef IEEE8021X_EAPOL
515 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
516 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
517 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
518 privacy = 1;
519#endif /* IEEE8021X_EAPOL */
520
Jouni Malinen75ecf522011-06-27 15:19:46 -0700521 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
522 privacy = 1;
523
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800524 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
525 privacy = 1;
526
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700527 if (bss->caps & IEEE80211_CAP_PRIVACY)
528 return privacy;
529 return !privacy;
530}
531
532
533static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
534 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800535 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536{
537 struct wpa_ie_data ie;
538 int proto_match = 0;
539 const u8 *rsn_ie, *wpa_ie;
540 int ret;
541 int wep_ok;
542
543 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
544 if (ret >= 0)
545 return ret;
546
547 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
548 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
549 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
550 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
551 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
552
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700553 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700554 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555 proto_match++;
556
557 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800558 if (debug_print)
559 wpa_dbg(wpa_s, MSG_DEBUG,
560 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700561 break;
562 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700563 if (!ie.has_pairwise)
564 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
565 if (!ie.has_group)
566 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567
568 if (wep_ok &&
569 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
570 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800571 if (debug_print)
572 wpa_dbg(wpa_s, MSG_DEBUG,
573 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574 return 1;
575 }
576
Roshan Pius3a1667e2018-07-03 15:17:14 -0700577 if (!(ie.proto & ssid->proto) &&
578 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800579 if (debug_print)
580 wpa_dbg(wpa_s, MSG_DEBUG,
581 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582 break;
583 }
584
585 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800586 if (debug_print)
587 wpa_dbg(wpa_s, MSG_DEBUG,
588 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 break;
590 }
591
592 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800593 if (debug_print)
594 wpa_dbg(wpa_s, MSG_DEBUG,
595 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596 break;
597 }
598
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700599 if (ssid->group_mgmt_cipher &&
600 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
601 if (debug_print)
602 wpa_dbg(wpa_s, MSG_DEBUG,
603 " skip RSN IE - group mgmt cipher mismatch");
604 break;
605 }
606
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700607 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800608 if (debug_print)
609 wpa_dbg(wpa_s, MSG_DEBUG,
610 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700611 break;
612 }
613
614#ifdef CONFIG_IEEE80211W
615 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800616 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800617 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800618 if (debug_print)
619 wpa_dbg(wpa_s, MSG_DEBUG,
620 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621 break;
622 }
623#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800624 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
625 wpas_get_ssid_pmf(wpa_s, ssid) ==
626 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800627 if (debug_print)
628 wpa_dbg(wpa_s, MSG_DEBUG,
629 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800630 break;
631 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800632#ifdef CONFIG_MBO
633 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
634 wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
635 wpas_get_ssid_pmf(wpa_s, ssid) !=
636 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800637 if (debug_print)
638 wpa_dbg(wpa_s, MSG_DEBUG,
639 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800640 break;
641 }
642#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800644 if (debug_print)
645 wpa_dbg(wpa_s, MSG_DEBUG,
646 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647 return 1;
648 }
649
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700650#ifdef CONFIG_IEEE80211W
Roshan Pius3a1667e2018-07-03 15:17:14 -0700651 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
652 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800653 if (debug_print)
654 wpa_dbg(wpa_s, MSG_DEBUG,
655 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700656 return 0;
657 }
658#endif /* CONFIG_IEEE80211W */
659
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700660 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
662 proto_match++;
663
664 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800665 if (debug_print)
666 wpa_dbg(wpa_s, MSG_DEBUG,
667 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 break;
669 }
670
671 if (wep_ok &&
672 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
673 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800674 if (debug_print)
675 wpa_dbg(wpa_s, MSG_DEBUG,
676 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677 return 1;
678 }
679
680 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800681 if (debug_print)
682 wpa_dbg(wpa_s, MSG_DEBUG,
683 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 break;
685 }
686
687 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800688 if (debug_print)
689 wpa_dbg(wpa_s, MSG_DEBUG,
690 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691 break;
692 }
693
694 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800695 if (debug_print)
696 wpa_dbg(wpa_s, MSG_DEBUG,
697 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698 break;
699 }
700
701 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800702 if (debug_print)
703 wpa_dbg(wpa_s, MSG_DEBUG,
704 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700705 break;
706 }
707
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800708 if (debug_print)
709 wpa_dbg(wpa_s, MSG_DEBUG,
710 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700711 return 1;
712 }
713
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700714 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
715 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800716 if (debug_print)
717 wpa_dbg(wpa_s, MSG_DEBUG,
718 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700719 return 1;
720 }
721
Roshan Pius3a1667e2018-07-03 15:17:14 -0700722#ifdef CONFIG_OWE
723 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
724 !wpa_ie && !rsn_ie) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800725 if (wpa_s->owe_transition_select &&
726 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
727 ssid->owe_transition_bss_select_count + 1 <=
728 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
729 ssid->owe_transition_bss_select_count++;
730 if (debug_print)
731 wpa_dbg(wpa_s, MSG_DEBUG,
732 " skip OWE transition BSS (selection count %d does not exceed %d)",
733 ssid->owe_transition_bss_select_count,
734 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
735 wpa_s->owe_transition_search = 1;
736 return 0;
737 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700738 if (debug_print)
739 wpa_dbg(wpa_s, MSG_DEBUG,
740 " allow in OWE transition mode");
741 return 1;
742 }
743#endif /* CONFIG_OWE */
744
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
746 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800747 if (debug_print)
748 wpa_dbg(wpa_s, MSG_DEBUG,
749 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700750 return 0;
751 }
752
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800753 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
754 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800755 if (debug_print)
756 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800757 return 1;
758 }
759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800761 if (debug_print)
762 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 return 1;
764 }
765
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800766 if (debug_print)
767 wpa_dbg(wpa_s, MSG_DEBUG,
768 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769
770 return 0;
771}
772
773
774static int freq_allowed(int *freqs, int freq)
775{
776 int i;
777
778 if (freqs == NULL)
779 return 1;
780
781 for (i = 0; freqs[i]; i++)
782 if (freqs[i] == freq)
783 return 1;
784 return 0;
785}
786
787
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800788static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
789 int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800790{
791 const struct hostapd_hw_modes *mode = NULL, *modes;
792 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
793 const u8 *rate_ie;
794 int i, j, k;
795
796 if (bss->freq == 0)
797 return 1; /* Cannot do matching without knowing band */
798
799 modes = wpa_s->hw.modes;
800 if (modes == NULL) {
801 /*
802 * The driver does not provide any additional information
803 * about the utilized hardware, so allow the connection attempt
804 * to continue.
805 */
806 return 1;
807 }
808
809 for (i = 0; i < wpa_s->hw.num_modes; i++) {
810 for (j = 0; j < modes[i].num_channels; j++) {
811 int freq = modes[i].channels[j].freq;
812 if (freq == bss->freq) {
813 if (mode &&
814 mode->mode == HOSTAPD_MODE_IEEE80211G)
815 break; /* do not allow 802.11b replace
816 * 802.11g */
817 mode = &modes[i];
818 break;
819 }
820 }
821 }
822
823 if (mode == NULL)
824 return 0;
825
826 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700827 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800828 if (rate_ie == NULL)
829 continue;
830
831 for (j = 2; j < rate_ie[1] + 2; j++) {
832 int flagged = !!(rate_ie[j] & 0x80);
833 int r = (rate_ie[j] & 0x7f) * 5;
834
835 /*
836 * IEEE Std 802.11n-2009 7.3.2.2:
837 * The new BSS Membership selector value is encoded
838 * like a legacy basic rate, but it is not a rate and
839 * only indicates if the BSS members are required to
840 * support the mandatory features of Clause 20 [HT PHY]
841 * in order to join the BSS.
842 */
843 if (flagged && ((rate_ie[j] & 0x7f) ==
844 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
845 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800846 if (debug_print)
847 wpa_dbg(wpa_s, MSG_DEBUG,
848 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800849 return 0;
850 }
851 continue;
852 }
853
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700854 /* There's also a VHT selector for 802.11ac */
855 if (flagged && ((rate_ie[j] & 0x7f) ==
856 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
857 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800858 if (debug_print)
859 wpa_dbg(wpa_s, MSG_DEBUG,
860 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700861 return 0;
862 }
863 continue;
864 }
865
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800866 if (!flagged)
867 continue;
868
869 /* check for legacy basic rates */
870 for (k = 0; k < mode->num_rates; k++) {
871 if (mode->rates[k] == r)
872 break;
873 }
874 if (k == mode->num_rates) {
875 /*
876 * IEEE Std 802.11-2007 7.3.2.2 demands that in
877 * order to join a BSS all required rates
878 * have to be supported by the hardware.
879 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800880 if (debug_print)
881 wpa_dbg(wpa_s, MSG_DEBUG,
882 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
883 r / 10, r % 10,
884 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800885 return 0;
886 }
887 }
888 }
889
890 return 1;
891}
892
893
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800894/*
895 * Test whether BSS is in an ESS.
896 * This is done differently in DMG (60 GHz) and non-DMG bands
897 */
898static int bss_is_ess(struct wpa_bss *bss)
899{
900 if (bss_is_dmg(bss)) {
901 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
902 IEEE80211_CAP_DMG_AP;
903 }
904
905 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
906 IEEE80211_CAP_ESS);
907}
908
909
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800910static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
911{
912 size_t i;
913
914 for (i = 0; i < ETH_ALEN; i++) {
915 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
916 return 0;
917 }
918 return 1;
919}
920
921
922static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
923{
924 size_t i;
925
926 for (i = 0; i < num; i++) {
927 const u8 *a = list + i * ETH_ALEN * 2;
928 const u8 *m = a + ETH_ALEN;
929
930 if (match_mac_mask(a, addr, m))
931 return 1;
932 }
933 return 0;
934}
935
936
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700937static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
938 const u8 **ret_ssid, size_t *ret_ssid_len)
939{
940#ifdef CONFIG_OWE
941 const u8 *owe, *pos, *end, *bssid;
942 u8 ssid_len;
943 struct wpa_bss *open_bss;
944
945 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
946 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
947 return;
948
949 pos = owe + 6;
950 end = owe + 2 + owe[1];
951
952 if (end - pos < ETH_ALEN + 1)
953 return;
954 bssid = pos;
955 pos += ETH_ALEN;
956 ssid_len = *pos++;
957 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
958 return;
959
960 /* Match the profile SSID against the OWE transition mode SSID on the
961 * open network. */
962 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
963 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
964 *ret_ssid = pos;
965 *ret_ssid_len = ssid_len;
966
967 if (bss->ssid_len > 0)
968 return;
969
970 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
971 if (!open_bss)
972 return;
973 if (ssid_len != open_bss->ssid_len ||
974 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
975 wpa_dbg(wpa_s, MSG_DEBUG,
976 "OWE: transition mode SSID mismatch: %s",
977 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
978 return;
979 }
980
981 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
982 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
983 wpa_dbg(wpa_s, MSG_DEBUG,
984 "OWE: transition mode open BSS unexpected info");
985 return;
986 }
987
988 pos = owe + 6;
989 end = owe + 2 + owe[1];
990
991 if (end - pos < ETH_ALEN + 1)
992 return;
993 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
994 wpa_dbg(wpa_s, MSG_DEBUG,
995 "OWE: transition mode BSSID mismatch: " MACSTR,
996 MAC2STR(pos));
997 return;
998 }
999 pos += ETH_ALEN;
1000 ssid_len = *pos++;
1001 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1002 return;
1003 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1004 wpa_ssid_txt(pos, ssid_len));
1005 os_memcpy(bss->ssid, pos, ssid_len);
1006 bss->ssid_len = ssid_len;
1007#endif /* CONFIG_OWE */
1008}
1009
1010
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001011struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1012 int i, struct wpa_bss *bss,
1013 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001014 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001015{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001016 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001017 int wpa;
1018 struct wpa_blacklist *e;
1019 const u8 *ie;
1020 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001021 int osen, rsn_osen = 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001022#ifdef CONFIG_MBO
1023 const u8 *assoc_disallow;
1024#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001025 const u8 *match_ssid;
1026 size_t match_ssid_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001027 struct wpa_ie_data data;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001028
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001029 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 wpa_ie_len = ie ? ie[1] : 0;
1031
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001032 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033 rsn_ie_len = ie ? ie[1] : 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001034 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1035 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1036 rsn_osen = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001038 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1039 osen = ie != NULL;
1040
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001041 if (debug_print) {
1042 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1043 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1044 i, MAC2STR(bss->bssid),
1045 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1046 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1047 bss->freq,
1048 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1049 " wps" : "",
1050 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1051 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1052 ? " p2p" : "",
1053 osen ? " osen=1" : "");
1054 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055
1056 e = wpa_blacklist_get(wpa_s, bss->bssid);
1057 if (e) {
1058 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001059 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001060 /*
1061 * When only a single network is enabled, we can
1062 * trigger blacklisting on the first failure. This
1063 * should not be done with multiple enabled networks to
1064 * avoid getting forced to move into a worse ESS on
1065 * single error if there are no other BSSes of the
1066 * current ESS.
1067 */
1068 limit = 0;
1069 }
1070 if (e->count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001071 if (debug_print) {
1072 wpa_dbg(wpa_s, MSG_DEBUG,
1073 " skip - blacklisted (count=%d limit=%d)",
1074 e->count, limit);
1075 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 return NULL;
1077 }
1078 }
1079
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001080 match_ssid = bss->ssid;
1081 match_ssid_len = bss->ssid_len;
1082 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1083
1084 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001085 if (debug_print)
1086 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 return NULL;
1088 }
1089
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001090 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001091 if (debug_print)
1092 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001093 return NULL;
1094 }
1095
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001096 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001097 if (debug_print)
1098 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001099 return NULL;
1100 }
1101
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
1103
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001104 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001106 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001107
Dmitry Shmidt04949592012-07-19 12:16:46 -07001108 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001109 if (debug_print)
1110 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111 continue;
1112 }
1113
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001114 res = wpas_temp_disabled(wpa_s, ssid);
1115 if (res > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001116 if (debug_print)
1117 wpa_dbg(wpa_s, MSG_DEBUG,
1118 " skip - disabled temporarily for %d second(s)",
1119 res);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001120 continue;
1121 }
1122
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123#ifdef CONFIG_WPS
1124 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001125 if (debug_print)
1126 wpa_dbg(wpa_s, MSG_DEBUG,
1127 " skip - blacklisted (WPS)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001128 continue;
1129 }
1130
1131 if (wpa && ssid->ssid_len == 0 &&
1132 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1133 check_ssid = 0;
1134
1135 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1136 /* Only allow wildcard SSID match if an AP
1137 * advertises active WPS operation that matches
1138 * with our mode. */
1139 check_ssid = 1;
1140 if (ssid->ssid_len == 0 &&
1141 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1142 check_ssid = 0;
1143 }
1144#endif /* CONFIG_WPS */
1145
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001146 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1147 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1148 check_ssid = 0;
1149
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150 if (check_ssid &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001151 (match_ssid_len != ssid->ssid_len ||
1152 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001153 if (debug_print)
1154 wpa_dbg(wpa_s, MSG_DEBUG,
1155 " skip - SSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156 continue;
1157 }
1158
1159 if (ssid->bssid_set &&
1160 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001161 if (debug_print)
1162 wpa_dbg(wpa_s, MSG_DEBUG,
1163 " skip - BSSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164 continue;
1165 }
1166
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001167 /* check blacklist */
1168 if (ssid->num_bssid_blacklist &&
1169 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1170 ssid->num_bssid_blacklist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001171 if (debug_print)
1172 wpa_dbg(wpa_s, MSG_DEBUG,
1173 " skip - BSSID blacklisted");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001174 continue;
1175 }
1176
1177 /* if there is a whitelist, only accept those APs */
1178 if (ssid->num_bssid_whitelist &&
1179 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1180 ssid->num_bssid_whitelist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001181 if (debug_print)
1182 wpa_dbg(wpa_s, MSG_DEBUG,
1183 " skip - BSSID not in whitelist");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001184 continue;
1185 }
1186
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001187 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss,
1188 debug_print))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189 continue;
1190
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001191 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1193 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001194 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001195 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001196 if (debug_print)
1197 wpa_dbg(wpa_s, MSG_DEBUG,
1198 " skip - non-WPA network not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 continue;
1200 }
1201
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001202 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1203 has_wep_key(ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001204 if (debug_print)
1205 wpa_dbg(wpa_s, MSG_DEBUG,
1206 " skip - ignore WPA/WPA2 AP for WEP network block");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001207 continue;
1208 }
1209
Roshan Pius3a1667e2018-07-03 15:17:14 -07001210 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen &&
1211 !rsn_osen) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001212 if (debug_print)
1213 wpa_dbg(wpa_s, MSG_DEBUG,
1214 " skip - non-OSEN network not allowed");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001215 continue;
1216 }
1217
Jouni Malinen75ecf522011-06-27 15:19:46 -07001218 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001219 if (debug_print)
1220 wpa_dbg(wpa_s, MSG_DEBUG,
1221 " skip - privacy mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 continue;
1223 }
1224
Hai Shalom81f62d82019-07-22 12:10:00 -07001225 if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001226 !bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001227 if (debug_print)
1228 wpa_dbg(wpa_s, MSG_DEBUG,
1229 " skip - not ESS, PBSS, or MBSS");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001230 continue;
1231 }
1232
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001233 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001234 if (debug_print)
1235 wpa_dbg(wpa_s, MSG_DEBUG,
1236 " skip - PBSS mismatch (ssid %d bss %d)",
1237 ssid->pbss, bss_is_pbss(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238 continue;
1239 }
1240
1241 if (!freq_allowed(ssid->freq_list, bss->freq)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001242 if (debug_print)
1243 wpa_dbg(wpa_s, MSG_DEBUG,
1244 " skip - frequency not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 continue;
1246 }
1247
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001248#ifdef CONFIG_MESH
Hai Shalom81f62d82019-07-22 12:10:00 -07001249 if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001250 ssid->frequency != bss->freq) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001251 if (debug_print)
1252 wpa_dbg(wpa_s, MSG_DEBUG,
1253 " skip - frequency not allowed (mesh)");
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001254 continue;
1255 }
1256#endif /* CONFIG_MESH */
1257
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001258 if (!rate_match(wpa_s, bss, debug_print)) {
1259 if (debug_print)
1260 wpa_dbg(wpa_s, MSG_DEBUG,
1261 " skip - rate sets do not match");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001262 continue;
1263 }
1264
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001265#ifndef CONFIG_IBSS_RSN
1266 if (ssid->mode == WPAS_MODE_IBSS &&
1267 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1268 WPA_KEY_MGMT_WPA_NONE))) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001269 if (debug_print)
1270 wpa_dbg(wpa_s, MSG_DEBUG,
1271 " skip - IBSS RSN not supported in the build");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001272 continue;
1273 }
1274#endif /* !CONFIG_IBSS_RSN */
1275
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001276#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001277 if (ssid->p2p_group &&
1278 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1279 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001280 if (debug_print)
1281 wpa_dbg(wpa_s, MSG_DEBUG,
1282 " skip - no P2P IE seen");
Dmitry Shmidt96571392013-10-14 12:54:46 -07001283 continue;
1284 }
1285
Dmitry Shmidt54605472013-11-08 11:10:19 -08001286 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1287 struct wpabuf *p2p_ie;
1288 u8 dev_addr[ETH_ALEN];
1289
1290 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1291 if (ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001292 if (debug_print)
1293 wpa_dbg(wpa_s, MSG_DEBUG,
1294 " skip - no P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001295 continue;
1296 }
1297 p2p_ie = wpa_bss_get_vendor_ie_multi(
1298 bss, P2P_IE_VENDOR_TYPE);
1299 if (p2p_ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001300 if (debug_print)
1301 wpa_dbg(wpa_s, MSG_DEBUG,
1302 " skip - could not fetch P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001303 continue;
1304 }
1305
1306 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1307 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1308 ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001309 if (debug_print)
1310 wpa_dbg(wpa_s, MSG_DEBUG,
1311 " skip - no matching GO P2P Device Address in P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001312 wpabuf_free(p2p_ie);
1313 continue;
1314 }
1315 wpabuf_free(p2p_ie);
1316 }
1317
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001318 /*
1319 * TODO: skip the AP if its P2P IE has Group Formation
1320 * bit set in the P2P Group Capability Bitmap and we
1321 * are not in Group Formation with that device.
1322 */
1323#endif /* CONFIG_P2P */
1324
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001325 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1326 {
1327 struct os_reltime diff;
1328
1329 os_reltime_sub(&wpa_s->scan_min_time,
1330 &bss->last_update, &diff);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001331 if (debug_print)
1332 wpa_dbg(wpa_s, MSG_DEBUG,
1333 " skip - scan result not recent enough (%u.%06u seconds too old)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001334 (unsigned int) diff.sec,
1335 (unsigned int) diff.usec);
1336 continue;
1337 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001338#ifdef CONFIG_MBO
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001339#ifdef CONFIG_TESTING_OPTIONS
1340 if (wpa_s->ignore_assoc_disallow)
1341 goto skip_assoc_disallow;
1342#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001343 assoc_disallow = wpas_mbo_get_bss_attr(
1344 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1345 if (assoc_disallow && assoc_disallow[1] >= 1) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001346 if (debug_print)
1347 wpa_dbg(wpa_s, MSG_DEBUG,
1348 " skip - MBO association disallowed (reason %u)",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001349 assoc_disallow[2]);
1350 continue;
1351 }
1352
Hai Shalom74f70d42019-02-11 14:42:39 -08001353 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001354 if (debug_print)
1355 wpa_dbg(wpa_s, MSG_DEBUG,
Hai Shalom74f70d42019-02-11 14:42:39 -08001356 " skip - AP temporarily disallowed");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001357 continue;
1358 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001359#ifdef CONFIG_TESTING_OPTIONS
1360 skip_assoc_disallow:
1361#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001362#endif /* CONFIG_MBO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001363
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001364#ifdef CONFIG_DPP
1365 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1366 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1367 (!ssid->dpp_connector ||
1368 !ssid->dpp_netaccesskey ||
1369 !ssid->dpp_csign)) {
1370 if (debug_print)
1371 wpa_dbg(wpa_s, MSG_DEBUG,
1372 " skip - no PMKSA entry for DPP");
1373 continue;
1374 }
1375#endif /* CONFIG_DPP */
1376
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001377 /* Matching configuration found */
1378 return ssid;
1379 }
1380
1381 /* No matching configuration found */
1382 return NULL;
1383}
1384
1385
1386static struct wpa_bss *
1387wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001388 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001389 struct wpa_ssid **selected_ssid,
1390 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001391{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001392 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001393
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001394 if (wpa_s->current_ssid) {
1395 struct wpa_ssid *ssid;
1396
1397 wpa_dbg(wpa_s, MSG_DEBUG,
1398 "Scan results matching the currently selected network");
1399 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1400 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1401
1402 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1403 only_first_ssid, 0);
1404 if (ssid != wpa_s->current_ssid)
1405 continue;
1406 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1407 " freq=%d level=%d snr=%d est_throughput=%u",
1408 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1409 bss->snr, bss->est_throughput);
1410 }
1411 }
1412
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001413 if (only_first_ssid)
1414 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1415 group->id);
1416 else
1417 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1418 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001419
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001420 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1421 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001422
1423 wpa_s->owe_transition_select = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001424 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001425 only_first_ssid, 1);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001426 wpa_s->owe_transition_select = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427 if (!*selected_ssid)
1428 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001429 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1430 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001431 MAC2STR(bss->bssid),
1432 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1433 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001434 }
1435
1436 return NULL;
1437}
1438
1439
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001440struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1441 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001442{
1443 struct wpa_bss *selected = NULL;
1444 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001445 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001446 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001447
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001448 if (wpa_s->last_scan_res == NULL ||
1449 wpa_s->last_scan_res_used == 0)
1450 return NULL; /* no scan results from last update */
1451
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001452 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001453 /* check that next_ssid is still valid */
1454 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1455 if (ssid == wpa_s->next_ssid)
1456 break;
1457 }
1458 next_ssid = ssid;
1459 wpa_s->next_ssid = NULL;
1460 }
1461
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001463 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1464 if (next_ssid && next_ssid->priority ==
1465 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001466 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001467 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001468 if (selected)
1469 break;
1470 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001471 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001472 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001473 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001474 if (selected)
1475 break;
1476 }
1477
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001478 if (selected == NULL && wpa_s->blacklist &&
1479 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001480 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1481 "blacklist and try again");
1482 wpa_blacklist_clear(wpa_s);
1483 wpa_s->blacklist_cleared++;
1484 } else if (selected == NULL)
1485 break;
1486 }
1487
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001488 ssid = *selected_ssid;
1489 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1490 !ssid->passphrase && !ssid->ext_psk) {
1491 const char *field_name, *txt = NULL;
1492
1493 wpa_dbg(wpa_s, MSG_DEBUG,
1494 "PSK/passphrase not yet available for the selected network");
1495
1496 wpas_notify_network_request(wpa_s, ssid,
1497 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1498
1499 field_name = wpa_supplicant_ctrl_req_to_string(
1500 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1501 if (field_name == NULL)
1502 return NULL;
1503
1504 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1505
1506 selected = NULL;
1507 }
1508
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001509 return selected;
1510}
1511
1512
1513static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1514 int timeout_sec, int timeout_usec)
1515{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001516 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001517 /*
1518 * No networks are enabled; short-circuit request so
1519 * we don't wait timeout seconds before transitioning
1520 * to INACTIVE state.
1521 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001522 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1523 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001524 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1525 return;
1526 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001527
1528 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001529 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1530}
1531
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001532
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001533int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001534 struct wpa_bss *selected,
1535 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001536{
1537 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1538 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1539 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001540 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001541#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001542 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1543 wpa_s->p2p_in_provisioning) {
1544 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1545 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001546 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001547 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001548#endif /* CONFIG_P2P */
1549
1550#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001551 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001552 wpas_wps_cancel(wpa_s);
1553#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001554 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001555 }
1556
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001557 wpa_msg(wpa_s, MSG_DEBUG,
1558 "Considering connect request: reassociate: %d selected: "
1559 MACSTR " bssid: " MACSTR " pending: " MACSTR
1560 " wpa_state: %s ssid=%p current_ssid=%p",
1561 wpa_s->reassociate, MAC2STR(selected->bssid),
1562 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1563 wpa_supplicant_state_txt(wpa_s->wpa_state),
1564 ssid, wpa_s->current_ssid);
1565
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001566 /*
1567 * Do not trigger new association unless the BSSID has changed or if
1568 * reassociation is requested. If we are in process of associating with
1569 * the selected BSSID, do not trigger new attempt.
1570 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001571 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001572 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1573 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1574 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001575 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1576 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1577 0) ||
1578 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1579 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001580 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1581 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001582 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001583 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001584 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1585 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001586 wpa_supplicant_associate(wpa_s, selected, ssid);
1587 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001588 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1589 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001590 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001591
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001592 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001593}
1594
1595
1596static struct wpa_ssid *
1597wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1598{
1599 int prio;
1600 struct wpa_ssid *ssid;
1601
1602 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1603 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1604 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001605 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001606 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001607#ifndef CONFIG_IBSS_RSN
1608 if (ssid->mode == WPAS_MODE_IBSS &&
1609 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1610 WPA_KEY_MGMT_WPA_NONE))) {
1611 wpa_msg(wpa_s, MSG_INFO,
1612 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1613 wpa_ssid_txt(ssid->ssid,
1614 ssid->ssid_len));
1615 continue;
1616 }
1617#endif /* !CONFIG_IBSS_RSN */
Hai Shalom81f62d82019-07-22 12:10:00 -07001618 if (ssid->mode == WPAS_MODE_IBSS ||
1619 ssid->mode == WPAS_MODE_AP ||
1620 ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621 return ssid;
1622 }
1623 }
1624 return NULL;
1625}
1626
1627
1628/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1629 * on BSS added and BSS changed events */
1630static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001631 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001632{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001633 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001634
1635 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1636 return;
1637
Jouni Malinen87fd2792011-05-16 18:35:42 +03001638 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001639 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001640
Jouni Malinen87fd2792011-05-16 18:35:42 +03001641 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001642 if (ssid == NULL)
1643 continue;
1644
Jouni Malinen87fd2792011-05-16 18:35:42 +03001645 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001646 if (rsn == NULL)
1647 continue;
1648
Jouni Malinen87fd2792011-05-16 18:35:42 +03001649 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001650 }
1651
1652}
1653
1654
1655static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1656 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001657 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001658{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001659 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001660#ifndef CONFIG_NO_ROAMING
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001661 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001662 int to_5ghz;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001663 int cur_est, sel_est;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001664#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001665
1666 if (wpa_s->reassociate)
1667 return 1; /* explicit request to reassociate */
1668 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1669 return 1; /* we are not associated; continue */
1670 if (wpa_s->current_ssid == NULL)
1671 return 1; /* unknown current SSID */
1672 if (wpa_s->current_ssid != ssid)
1673 return 1; /* different network block */
1674
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001675 if (wpas_driver_bss_selection(wpa_s))
1676 return 0; /* Driver-based roaming */
1677
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001678 if (wpa_s->current_ssid->ssid)
1679 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1680 wpa_s->current_ssid->ssid,
1681 wpa_s->current_ssid->ssid_len);
1682 if (!current_bss)
1683 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001684
1685 if (!current_bss)
1686 return 1; /* current BSS not seen in scan results */
1687
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001688 if (current_bss == selected)
1689 return 0;
1690
1691 if (selected->last_update_idx > current_bss->last_update_idx)
1692 return 1; /* current BSS not seen in the last scan */
1693
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001694#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001695 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001696 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001697 " freq=%d level=%d snr=%d est_throughput=%u",
1698 MAC2STR(current_bss->bssid),
1699 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001700 current_bss->snr, current_bss->est_throughput);
1701 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001702 " freq=%d level=%d snr=%d est_throughput=%u",
1703 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001704 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001705
1706 if (wpa_s->current_ssid->bssid_set &&
1707 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1708 0) {
1709 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1710 "has preferred BSSID");
1711 return 1;
1712 }
1713
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001714 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1715 wpa_dbg(wpa_s, MSG_DEBUG,
1716 "Allow reassociation - selected BSS has better estimated throughput");
1717 return 1;
1718 }
1719
Dmitry Shmidte4663042016-04-04 10:07:49 -07001720 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1721
1722 if (current_bss->level < 0 &&
1723 current_bss->level > selected->level + to_5ghz * 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001724 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1725 "signal level");
1726 return 0;
1727 }
1728
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001729 if (current_bss->est_throughput > selected->est_throughput + 5000) {
1730 wpa_dbg(wpa_s, MSG_DEBUG,
1731 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001732 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001733 }
1734
1735 cur_est = current_bss->est_throughput;
1736 sel_est = selected->est_throughput;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001737 min_diff = 2;
1738 if (current_bss->level < 0) {
1739 if (current_bss->level < -85)
1740 min_diff = 1;
1741 else if (current_bss->level < -80)
1742 min_diff = 2;
1743 else if (current_bss->level < -75)
1744 min_diff = 3;
1745 else if (current_bss->level < -70)
1746 min_diff = 4;
1747 else
1748 min_diff = 5;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001749 if (cur_est > sel_est * 1.5)
1750 min_diff += 10;
1751 else if (cur_est > sel_est * 1.2)
1752 min_diff += 5;
1753 else if (cur_est > sel_est * 1.1)
1754 min_diff += 2;
1755 else if (cur_est > sel_est)
1756 min_diff++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001758 if (to_5ghz) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001759 int reduce = 2;
1760
Dmitry Shmidte4663042016-04-04 10:07:49 -07001761 /* Make it easier to move to 5 GHz band */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001762 if (sel_est > cur_est * 1.5)
1763 reduce = 5;
1764 else if (sel_est > cur_est * 1.2)
1765 reduce = 4;
1766 else if (sel_est > cur_est * 1.1)
1767 reduce = 3;
1768
1769 if (min_diff > reduce)
1770 min_diff -= reduce;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001771 else
1772 min_diff = 0;
1773 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001774 diff = abs(current_bss->level - selected->level);
1775 if (diff < min_diff) {
1776 wpa_dbg(wpa_s, MSG_DEBUG,
1777 "Skip roam - too small difference in signal level (%d < %d)",
1778 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001779 return 0;
1780 }
1781
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001782 wpa_dbg(wpa_s, MSG_DEBUG,
1783 "Allow reassociation due to difference in signal level (%d >= %d)",
1784 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001785 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001786#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001787 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001788#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001789}
1790
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001791
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001792/*
1793 * Return a negative value if no scan results could be fetched or if scan
1794 * results should not be shared with other virtual interfaces.
1795 * Return 0 if scan results were fetched and may be shared with other
1796 * interfaces.
1797 * Return 1 if scan results may be shared with other virtual interfaces but may
1798 * not trigger any operations.
1799 * Return 2 if the interface was removed and cannot be used.
1800 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001801static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001802 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001803 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001804{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001805 struct wpa_scan_results *scan_res = NULL;
1806 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001807 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001808#ifndef CONFIG_NO_RANDOM_POOL
1809 size_t i, num;
1810#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001811
1812#ifdef CONFIG_AP
1813 if (wpa_s->ap_iface)
1814 ap = 1;
1815#endif /* CONFIG_AP */
1816
1817 wpa_supplicant_notify_scanning(wpa_s, 0);
1818
1819 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1820 data ? &data->scan_info :
1821 NULL, 1);
1822 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001823 if (wpa_s->conf->ap_scan == 2 || ap ||
1824 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001825 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001826 if (!own_request)
1827 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001828 if (data && data->scan_info.external_scan)
1829 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1831 "scanning again");
1832 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001833 ret = -1;
1834 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835 }
1836
1837#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 num = scan_res->num;
1839 if (num > 10)
1840 num = 10;
1841 for (i = 0; i < num; i++) {
1842 u8 buf[5];
1843 struct wpa_scan_res *res = scan_res->res[i];
1844 buf[0] = res->bssid[5];
1845 buf[1] = res->qual & 0xff;
1846 buf[2] = res->noise & 0xff;
1847 buf[3] = res->level & 0xff;
1848 buf[4] = res->tsf & 0xff;
1849 random_add_randomness(buf, sizeof(buf));
1850 }
1851#endif /* CONFIG_NO_RANDOM_POOL */
1852
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001853 if (update_only) {
1854 ret = 1;
1855 goto scan_work_done;
1856 }
1857
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001858 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001859 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001860 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1861 struct wpa_scan_results *scan_res);
1862
1863 scan_res_handler = wpa_s->scan_res_handler;
1864 wpa_s->scan_res_handler = NULL;
1865 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001866 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001867 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001868 }
1869
1870 if (ap) {
1871 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1872#ifdef CONFIG_AP
1873 if (wpa_s->ap_iface->scan_cb)
1874 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1875#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001876 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001877 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001878
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001879 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001880 wpa_s->own_scan_running,
1881 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001882 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001883 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1884 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001885 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1886 wpa_s->manual_scan_id);
1887 wpa_s->manual_scan_use_id = 0;
1888 } else {
1889 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1890 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001891 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001892
1893 wpas_notify_scan_done(wpa_s, 1);
1894
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001895 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001896 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 -07001897 wpa_scan_results_free(scan_res);
1898 return 0;
1899 }
1900
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001901 if (wnm_scan_process(wpa_s, 1) > 0)
1902 goto scan_work_done;
1903
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001904 if (sme_proc_obss_scan(wpa_s) > 0)
1905 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001906
Hai Shalom021b0b52019-04-10 11:17:58 -07001907 if (own_request && data &&
Dmitry Shmidt29333592017-01-09 12:27:11 -08001908 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
1909 goto scan_work_done;
1910
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001911 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1912 goto scan_work_done;
1913
1914 if (autoscan_notify_scan(wpa_s, scan_res))
1915 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001916
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001917 if (wpa_s->disconnected) {
1918 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001919 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001920 }
1921
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001922 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001923 bgscan_notify_scan(wpa_s, scan_res) == 1)
1924 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001925
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001926 wpas_wps_update_ap_info(wpa_s, scan_res);
1927
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001928 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1929 wpa_s->wpa_state < WPA_COMPLETED)
1930 goto scan_work_done;
1931
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001932 wpa_scan_results_free(scan_res);
1933
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001934 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001935 struct wpa_radio_work *work = wpa_s->scan_work;
1936 wpa_s->scan_work = NULL;
1937 radio_work_done(work);
1938 }
1939
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001940 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001941
1942scan_work_done:
1943 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001944 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001945 struct wpa_radio_work *work = wpa_s->scan_work;
1946 wpa_s->scan_work = NULL;
1947 radio_work_done(work);
1948 }
1949 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001950}
1951
1952
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001953static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001954 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001955{
1956 struct wpa_bss *selected;
1957 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001958 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1959
1960 if (time_to_reenable > 0) {
1961 wpa_dbg(wpa_s, MSG_DEBUG,
1962 "Postpone network selection by %d seconds since all networks are disabled",
1963 time_to_reenable);
1964 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1965 eloop_register_timeout(time_to_reenable, 0,
1966 wpas_network_reenabled, wpa_s, NULL);
1967 return 0;
1968 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001969
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001970 if (wpa_s->p2p_mgmt)
1971 return 0; /* no normal connection on p2p_mgmt interface */
1972
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001973 wpa_s->owe_transition_search = 0;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001974 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001975
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001976#ifdef CONFIG_MESH
1977 if (wpa_s->ifmsh) {
1978 wpa_msg(wpa_s, MSG_INFO,
1979 "Avoiding join because we already joined a mesh group");
1980 return 0;
1981 }
1982#endif /* CONFIG_MESH */
1983
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001984 if (selected) {
1985 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001986 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001987 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001988 if (new_scan)
1989 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001990 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001991 }
1992
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001993 if (ssid != wpa_s->current_ssid &&
1994 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1995 wpa_s->own_disconnect_req = 1;
1996 wpa_supplicant_deauthenticate(
1997 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1998 }
1999
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002000 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002001 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002002 return -1;
2003 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002004 if (new_scan)
2005 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002006 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002007 * Do not allow other virtual radios to trigger operations based
2008 * on these scan results since we do not want them to start
2009 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07002010 */
2011 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002012 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002013 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2014 ssid = wpa_supplicant_pick_new_network(wpa_s);
2015 if (ssid) {
2016 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2017 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002018 if (new_scan)
2019 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002020 } else if (own_request) {
2021 /*
2022 * No SSID found. If SCAN results are as a result of
2023 * own scan request and not due to a scan request on
2024 * another shared interface, try another scan.
2025 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002026 int timeout_sec = wpa_s->scan_interval;
2027 int timeout_usec = 0;
2028#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002029 int res;
2030
2031 res = wpas_p2p_scan_no_go_seen(wpa_s);
2032 if (res == 2)
2033 return 2;
2034 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002035 return 0;
2036
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002037 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002038 wpa_s->show_group_started ||
2039 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002040 /*
2041 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002042 * state and during P2P join-a-group operation
2043 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002044 */
2045 timeout_sec = 0;
2046 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002047 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2048 timeout_usec);
2049 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002050 }
2051#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002052#ifdef CONFIG_INTERWORKING
2053 if (wpa_s->conf->auto_interworking &&
2054 wpa_s->conf->interworking &&
2055 wpa_s->conf->cred) {
2056 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2057 "start ANQP fetch since no matching "
2058 "networks found");
2059 wpa_s->network_select = 1;
2060 wpa_s->auto_network_select = 1;
2061 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002062 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002063 }
2064#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002065#ifdef CONFIG_WPS
2066 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2067 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2068 timeout_sec = 0;
2069 timeout_usec = 500000;
2070 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2071 timeout_usec);
2072 return 0;
2073 }
2074#endif /* CONFIG_WPS */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002075#ifdef CONFIG_OWE
2076 if (wpa_s->owe_transition_search) {
2077 wpa_dbg(wpa_s, MSG_DEBUG,
2078 "OWE: Use shorter wait during transition mode search");
2079 timeout_sec = 0;
2080 timeout_usec = 500000;
2081 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2082 timeout_usec);
2083 return 0;
2084 }
2085#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002086 if (wpa_supplicant_req_sched_scan(wpa_s))
2087 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2088 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002089
2090 wpa_msg_ctrl(wpa_s, MSG_INFO,
2091 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002092 }
2093 }
2094 return 0;
2095}
2096
2097
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002098static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2099 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002100{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002101 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002102 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002103
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002104 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002105 if (res == 2) {
2106 /*
2107 * Interface may have been removed, so must not dereference
2108 * wpa_s after this.
2109 */
2110 return 1;
2111 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002112
2113 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002114 /*
2115 * If no scan results could be fetched, then no need to
2116 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002117 * this scan. Similarly, if scan results started a new operation on this
2118 * interface, do not notify other interfaces to avoid concurrent
2119 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002120 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002121 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002122 }
2123
2124 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002125 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126 * so, they get updated with this same scan info.
2127 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002128 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2129 radio_list) {
2130 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002131 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2132 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002133 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2134 res > 0);
2135 if (res < 0)
2136 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002137 }
2138 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002139
2140 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002141}
2142
2143#endif /* CONFIG_NO_SCAN_PROCESSING */
2144
2145
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002146int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2147{
2148#ifdef CONFIG_NO_SCAN_PROCESSING
2149 return -1;
2150#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002151 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002152
Dmitry Shmidt29333592017-01-09 12:27:11 -08002153 wpa_s->ignore_post_flush_scan_res = 0;
2154
Dmitry Shmidt41712582015-06-29 11:02:15 -07002155 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002156 return -1;
2157
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002158 os_get_reltime(&now);
2159 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002160 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2161 return -1;
2162 }
2163
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002164 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002165#endif /* CONFIG_NO_SCAN_PROCESSING */
2166}
2167
Dmitry Shmidt04949592012-07-19 12:16:46 -07002168#ifdef CONFIG_WNM
2169
2170static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2171{
2172 struct wpa_supplicant *wpa_s = eloop_ctx;
2173
2174 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2175 return;
2176
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002177 if (!wpa_s->no_keep_alive) {
2178 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2179 MAC2STR(wpa_s->bssid));
2180 /* TODO: could skip this if normal data traffic has been sent */
2181 /* TODO: Consider using some more appropriate data frame for
2182 * this */
2183 if (wpa_s->l2)
2184 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2185 (u8 *) "", 0);
2186 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002187
2188#ifdef CONFIG_SME
2189 if (wpa_s->sme.bss_max_idle_period) {
2190 unsigned int msec;
2191 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2192 if (msec > 100)
2193 msec -= 100;
2194 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2195 wnm_bss_keep_alive, wpa_s, NULL);
2196 }
2197#endif /* CONFIG_SME */
2198}
2199
2200
2201static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2202 const u8 *ies, size_t ies_len)
2203{
2204 struct ieee802_11_elems elems;
2205
2206 if (ies == NULL)
2207 return;
2208
2209 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2210 return;
2211
2212#ifdef CONFIG_SME
2213 if (elems.bss_max_idle_period) {
2214 unsigned int msec;
2215 wpa_s->sme.bss_max_idle_period =
2216 WPA_GET_LE16(elems.bss_max_idle_period);
2217 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2218 "TU)%s", wpa_s->sme.bss_max_idle_period,
2219 (elems.bss_max_idle_period[2] & 0x01) ?
2220 " (protected keep-live required)" : "");
2221 if (wpa_s->sme.bss_max_idle_period == 0)
2222 wpa_s->sme.bss_max_idle_period = 1;
2223 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2224 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2225 /* msec times 1000 */
2226 msec = wpa_s->sme.bss_max_idle_period * 1024;
2227 if (msec > 100)
2228 msec -= 100;
2229 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2230 wnm_bss_keep_alive, wpa_s,
2231 NULL);
2232 }
2233 }
2234#endif /* CONFIG_SME */
2235}
2236
2237#endif /* CONFIG_WNM */
2238
2239
2240void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2241{
2242#ifdef CONFIG_WNM
2243 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2244#endif /* CONFIG_WNM */
2245}
2246
2247
Dmitry Shmidt051af732013-10-22 13:52:46 -07002248#ifdef CONFIG_INTERWORKING
2249
2250static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2251 size_t len)
2252{
2253 int res;
2254
2255 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2256 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2257 if (res) {
2258 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2259 }
2260
2261 return res;
2262}
2263
2264
2265static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2266 const u8 *ies, size_t ies_len)
2267{
2268 struct ieee802_11_elems elems;
2269
2270 if (ies == NULL)
2271 return;
2272
2273 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2274 return;
2275
2276 if (elems.qos_map_set) {
2277 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2278 elems.qos_map_set_len);
2279 }
2280}
2281
2282#endif /* CONFIG_INTERWORKING */
2283
2284
Hai Shalom74f70d42019-02-11 14:42:39 -08002285static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2286 const u8 *ies, size_t ies_len)
2287{
2288 struct ieee802_11_elems elems;
2289 const u8 *map_sub_elem, *pos;
2290 size_t len;
2291
2292 if (!wpa_s->current_ssid ||
2293 !wpa_s->current_ssid->multi_ap_backhaul_sta ||
2294 !ies ||
2295 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2296 return;
2297
2298 if (!elems.multi_ap || elems.multi_ap_len < 7) {
2299 wpa_printf(MSG_INFO, "AP doesn't support Multi-AP protocol");
2300 goto fail;
2301 }
2302
2303 pos = elems.multi_ap + 4;
2304 len = elems.multi_ap_len - 4;
2305
2306 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
2307 if (!map_sub_elem || map_sub_elem[1] < 1) {
2308 wpa_printf(MSG_INFO, "invalid Multi-AP sub elem type");
2309 goto fail;
2310 }
2311
2312 if (!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS)) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002313 if ((map_sub_elem[2] & MULTI_AP_FRONTHAUL_BSS) &&
2314 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2315 wpa_printf(MSG_INFO,
2316 "WPS active, accepting fronthaul-only BSS");
2317 /* Don't set 4addr mode in this case, so just return */
2318 return;
2319 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002320 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2321 goto fail;
2322 }
2323
2324 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2325 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2326 goto fail;
2327 }
2328 wpa_s->enabled_4addr_mode = 1;
2329 return;
2330
2331fail:
2332 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2333}
2334
2335
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002336#ifdef CONFIG_FST
2337static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2338 const u8 *ie, size_t ie_len)
2339{
2340 struct mb_ies_info mb_ies;
2341
2342 if (!ie || !ie_len || !wpa_s->fst)
2343 return -ENOENT;
2344
2345 os_memset(&mb_ies, 0, sizeof(mb_ies));
2346
2347 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2348 size_t len;
2349
2350 len = 2 + ie[1];
2351 if (len > ie_len) {
2352 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2353 ie, ie_len);
2354 break;
2355 }
2356
2357 if (ie[0] == WLAN_EID_MULTI_BAND) {
2358 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2359 (unsigned int) len);
2360 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2361 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2362 mb_ies.nof_ies++;
2363 }
2364
2365 ie_len -= len;
2366 ie += len;
2367 }
2368
2369 if (mb_ies.nof_ies > 0) {
2370 wpabuf_free(wpa_s->received_mb_ies);
2371 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2372 return 0;
2373 }
2374
2375 return -ENOENT;
2376}
2377#endif /* CONFIG_FST */
2378
2379
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002380static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2381 union wpa_event_data *data)
2382{
2383 int l, len, found = 0, wpa_found, rsn_found;
2384 const u8 *p;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002385#if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002386 u8 bssid[ETH_ALEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -07002387#endif /* CONFIG_IEEE80211R || CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002388
2389 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
2390 if (data->assoc_info.req_ies)
2391 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2392 data->assoc_info.req_ies_len);
2393 if (data->assoc_info.resp_ies) {
2394 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2395 data->assoc_info.resp_ies_len);
2396#ifdef CONFIG_TDLS
2397 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2398 data->assoc_info.resp_ies_len);
2399#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002400#ifdef CONFIG_WNM
2401 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2402 data->assoc_info.resp_ies_len);
2403#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002404#ifdef CONFIG_INTERWORKING
2405 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2406 data->assoc_info.resp_ies_len);
2407#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002408 if (wpa_s->hw_capab == CAPAB_VHT &&
2409 get_ie(data->assoc_info.resp_ies,
2410 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2411 wpa_s->ieee80211ac = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08002412
2413 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2414 data->assoc_info.resp_ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002415 }
2416 if (data->assoc_info.beacon_ies)
2417 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2418 data->assoc_info.beacon_ies,
2419 data->assoc_info.beacon_ies_len);
2420 if (data->assoc_info.freq)
2421 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2422 data->assoc_info.freq);
2423
Hai Shalom021b0b52019-04-10 11:17:58 -07002424 wpa_s->connection_set = 0;
2425 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2426 struct ieee802_11_elems req_elems, resp_elems;
2427
2428 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2429 data->assoc_info.req_ies_len,
2430 &req_elems, 0) != ParseFailed &&
2431 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2432 data->assoc_info.resp_ies_len,
2433 &resp_elems, 0) != ParseFailed) {
2434 wpa_s->connection_set = 1;
2435 wpa_s->connection_ht = req_elems.ht_capabilities &&
2436 resp_elems.ht_capabilities;
2437 wpa_s->connection_vht = req_elems.vht_capabilities &&
2438 resp_elems.vht_capabilities;
2439 wpa_s->connection_he = req_elems.he_capabilities &&
2440 resp_elems.he_capabilities;
2441 }
2442 }
2443
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002444 p = data->assoc_info.req_ies;
2445 l = data->assoc_info.req_ies_len;
2446
2447 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2448 while (p && l >= 2) {
2449 len = p[1] + 2;
2450 if (len > l) {
2451 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2452 p, l);
2453 break;
2454 }
2455 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2456 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
Dmitry Shmidte4663042016-04-04 10:07:49 -07002457 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2458 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002459 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
2460 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2461 break;
2462 found = 1;
2463 wpa_find_assoc_pmkid(wpa_s);
2464 break;
2465 }
2466 l -= len;
2467 p += len;
2468 }
2469 if (!found && data->assoc_info.req_ies)
2470 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
2471
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002472#ifdef CONFIG_FILS
2473#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002474 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2475 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002476 (!data->assoc_info.resp_frame ||
2477 fils_process_assoc_resp(wpa_s->wpa,
2478 data->assoc_info.resp_frame,
2479 data->assoc_info.resp_frame_len) < 0)) {
2480 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2481 return -1;
2482 }
2483#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002484
2485 /* Additional processing for FILS when SME is in driver */
2486 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2487 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2488 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002489#endif /* CONFIG_FILS */
2490
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002491#ifdef CONFIG_OWE
2492 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
2493 (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2494 owe_process_assoc_resp(wpa_s->wpa, bssid,
2495 data->assoc_info.resp_ies,
2496 data->assoc_info.resp_ies_len) < 0)) {
2497 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2498 return -1;
2499 }
2500#endif /* CONFIG_OWE */
2501
Hai Shalom021b0b52019-04-10 11:17:58 -07002502#ifdef CONFIG_DPP2
2503 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
2504 if (wpa_s->key_mgmt == WPA_KEY_MGMT_DPP && wpa_s->dpp_pfs) {
2505 struct ieee802_11_elems elems;
2506
2507 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2508 data->assoc_info.resp_ies_len,
2509 &elems, 0) == ParseFailed ||
2510 !elems.owe_dh)
2511 goto no_pfs;
2512 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2513 elems.owe_dh_len) < 0) {
2514 wpa_supplicant_deauthenticate(wpa_s,
2515 WLAN_REASON_UNSPECIFIED);
2516 return -1;
2517 }
2518
2519 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2520 }
2521no_pfs:
2522#endif /* CONFIG_DPP2 */
2523
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002524#ifdef CONFIG_IEEE80211R
2525#ifdef CONFIG_SME
2526 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002527 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2528 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2529 data->assoc_info.resp_ies,
2530 data->assoc_info.resp_ies_len,
2531 bssid) < 0) {
2532 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2533 "Reassociation Response failed");
2534 wpa_supplicant_deauthenticate(
2535 wpa_s, WLAN_REASON_INVALID_IE);
2536 return -1;
2537 }
2538 }
2539
2540 p = data->assoc_info.resp_ies;
2541 l = data->assoc_info.resp_ies_len;
2542
2543#ifdef CONFIG_WPS_STRICT
2544 if (p && wpa_s->current_ssid &&
2545 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2546 struct wpabuf *wps;
2547 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2548 if (wps == NULL) {
2549 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2550 "include WPS IE in (Re)Association Response");
2551 return -1;
2552 }
2553
2554 if (wps_validate_assoc_resp(wps) < 0) {
2555 wpabuf_free(wps);
2556 wpa_supplicant_deauthenticate(
2557 wpa_s, WLAN_REASON_INVALID_IE);
2558 return -1;
2559 }
2560 wpabuf_free(wps);
2561 }
2562#endif /* CONFIG_WPS_STRICT */
2563
2564 /* Go through the IEs and make a copy of the MDIE, if present. */
2565 while (p && l >= 2) {
2566 len = p[1] + 2;
2567 if (len > l) {
2568 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2569 p, l);
2570 break;
2571 }
2572 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2573 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2574 wpa_s->sme.ft_used = 1;
2575 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2576 MOBILITY_DOMAIN_ID_LEN);
2577 break;
2578 }
2579 l -= len;
2580 p += len;
2581 }
2582#endif /* CONFIG_SME */
2583
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002584 /* Process FT when SME is in the driver */
2585 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2586 wpa_ft_is_completed(wpa_s->wpa)) {
2587 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2588 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2589 data->assoc_info.resp_ies,
2590 data->assoc_info.resp_ies_len,
2591 bssid) < 0) {
2592 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2593 "Reassociation Response failed");
2594 wpa_supplicant_deauthenticate(
2595 wpa_s, WLAN_REASON_INVALID_IE);
2596 return -1;
2597 }
2598 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2599 }
2600
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002601 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2602 data->assoc_info.resp_ies_len);
2603#endif /* CONFIG_IEEE80211R */
2604
2605 /* WPA/RSN IE from Beacon/ProbeResp */
2606 p = data->assoc_info.beacon_ies;
2607 l = data->assoc_info.beacon_ies_len;
2608
2609 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2610 */
2611 wpa_found = rsn_found = 0;
2612 while (p && l >= 2) {
2613 len = p[1] + 2;
2614 if (len > l) {
2615 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2616 p, l);
2617 break;
2618 }
2619 if (!wpa_found &&
2620 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2621 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2622 wpa_found = 1;
2623 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2624 }
2625
2626 if (!rsn_found &&
2627 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2628 rsn_found = 1;
2629 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2630 }
2631
2632 l -= len;
2633 p += len;
2634 }
2635
2636 if (!wpa_found && data->assoc_info.beacon_ies)
2637 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2638 if (!rsn_found && data->assoc_info.beacon_ies)
2639 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2640 if (wpa_found || rsn_found)
2641 wpa_s->ap_ies_from_associnfo = 1;
2642
Jouni Malinen87fd2792011-05-16 18:35:42 +03002643 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2644 wpa_s->assoc_freq != data->assoc_info.freq) {
2645 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2646 "%u to %u MHz",
2647 wpa_s->assoc_freq, data->assoc_info.freq);
2648 wpa_supplicant_update_scan_results(wpa_s);
2649 }
2650
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002651 wpa_s->assoc_freq = data->assoc_info.freq;
2652
2653 return 0;
2654}
2655
2656
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002657static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2658{
2659 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2660
2661 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2662 return -1;
2663
2664 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2665 return 0;
2666
2667 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2668 WPA_IE_VENDOR_TYPE);
2669 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2670
2671 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2672 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2673 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2674 bss_rsn ? 2 + bss_rsn[1] : 0))
2675 return -1;
2676
2677 return 0;
2678}
2679
2680
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002681static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2682 union wpa_event_data *data)
2683{
2684#ifdef CONFIG_FST
2685 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2686 struct wpa_bss *bss = wpa_s->current_bss;
2687 const u8 *ieprb, *iebcn;
2688
2689 wpabuf_free(wpa_s->received_mb_ies);
2690 wpa_s->received_mb_ies = NULL;
2691
2692 if (ai &&
2693 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2694 wpa_printf(MSG_DEBUG,
2695 "FST: MB IEs updated from Association Response frame");
2696 return;
2697 }
2698
2699 if (ai &&
2700 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2701 wpa_printf(MSG_DEBUG,
2702 "FST: MB IEs updated from association event Beacon IEs");
2703 return;
2704 }
2705
2706 if (!bss)
2707 return;
2708
2709 ieprb = (const u8 *) (bss + 1);
2710 iebcn = ieprb + bss->ie_len;
2711
2712 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2713 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2714 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2715 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2716#endif /* CONFIG_FST */
2717}
2718
2719
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002720static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2721 union wpa_event_data *data)
2722{
2723 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002724 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002725 int new_bss = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002726
2727#ifdef CONFIG_AP
2728 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002729 if (!data)
2730 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002731 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2732 data->assoc_info.addr,
2733 data->assoc_info.req_ies,
2734 data->assoc_info.req_ies_len,
2735 data->assoc_info.reassoc);
2736 return;
2737 }
2738#endif /* CONFIG_AP */
2739
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002740 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2741
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002742 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2743 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2744 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002745 /*
2746 * FILS authentication can share the same mechanism to mark the
2747 * connection fully authenticated, so set ft_completed also based on
2748 * FILS result.
2749 */
2750 if (!ft_completed)
2751 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002752
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002753 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2754 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002755 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002756 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2757 return;
2758 }
2759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002760 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002761 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08002762 if (os_reltime_initialized(&wpa_s->session_start)) {
2763 os_reltime_age(&wpa_s->session_start,
2764 &wpa_s->session_length);
2765 wpa_s->session_start.sec = 0;
2766 wpa_s->session_start.usec = 0;
2767 wpas_notify_session_length(wpa_s);
2768 } else {
2769 wpas_notify_auth_changed(wpa_s);
2770 os_get_reltime(&wpa_s->session_start);
2771 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002772 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2773 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002774 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002775 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2777 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002778 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002779
2780 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2781 wpa_clear_keys(wpa_s, bssid);
2782 }
2783 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002784 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002785 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2786 return;
2787 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002788 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002789
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002790 if (wpa_s->conf->ap_scan == 1 &&
2791 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002792 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2793 wpa_msg(wpa_s, MSG_WARNING,
2794 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002795 }
2796
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002797 wpas_fst_update_mb_assoc(wpa_s, data);
2798
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002799#ifdef CONFIG_SME
2800 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2801 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002802 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002803#endif /* CONFIG_SME */
2804
2805 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2806 if (wpa_s->current_ssid) {
2807 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2808 * initialized before association, but for other modes,
2809 * initialize PC/SC here, if the current configuration needs
2810 * smartcard or SIM/USIM. */
2811 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2812 }
2813 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2814 if (wpa_s->l2)
2815 l2_packet_notify_auth_start(wpa_s->l2);
2816
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002817 already_authorized = data && data->assoc_info.authorized;
2818
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002819 /*
2820 * Set portEnabled first to FALSE in order to get EAP state machine out
2821 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2822 * state machine may transit to AUTHENTICATING state based on obsolete
2823 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2824 * AUTHENTICATED without ever giving chance to EAP state machine to
2825 * reset the state.
2826 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002827 if (!ft_completed && !already_authorized) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002828 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2829 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2830 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002831 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
2832 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
2833 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002834 already_authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002835 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2836 /* 802.1X::portControl = Auto */
2837 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2838 wpa_s->eapol_received = 0;
2839 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2840 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2841 (wpa_s->current_ssid &&
Hai Shalom81f62d82019-07-22 12:10:00 -07002842 wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002843 if (wpa_s->current_ssid &&
2844 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002845 (wpa_s->drv_flags &
2846 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2847 /*
2848 * Set the key after having received joined-IBSS event
2849 * from the driver.
2850 */
2851 wpa_supplicant_set_wpa_none_key(wpa_s,
2852 wpa_s->current_ssid);
2853 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002854 wpa_supplicant_cancel_auth_timeout(wpa_s);
2855 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2856 } else if (!ft_completed) {
2857 /* Timeout for receiving the first EAPOL packet */
2858 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2859 }
2860 wpa_supplicant_cancel_scan(wpa_s);
2861
Hai Shalom5f92bc92019-04-18 11:54:11 -07002862 if (ft_completed) {
2863 /*
2864 * FT protocol completed - make sure EAPOL state machine ends
2865 * up in authenticated.
2866 */
2867 wpa_supplicant_cancel_auth_timeout(wpa_s);
2868 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2869 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2870 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2871 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
2872 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002873 /*
2874 * We are done; the driver will take care of RSN 4-way
2875 * handshake.
2876 */
2877 wpa_supplicant_cancel_auth_timeout(wpa_s);
2878 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2879 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2880 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
Hai Shalom74f70d42019-02-11 14:42:39 -08002881 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002882 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2883 /*
2884 * The driver will take care of RSN 4-way handshake, so we need
2885 * to allow EAPOL supplicant to complete its work without
2886 * waiting for WPA supplicant.
2887 */
2888 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002889 }
2890
Jouni Malinena05074c2012-12-21 21:35:35 +02002891 wpa_s->last_eapol_matches_bssid = 0;
2892
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002893 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002894 struct os_reltime now, age;
2895 os_get_reltime(&now);
2896 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08002897 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002898 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2899 0) {
2900 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2901 "frame that was received just before "
2902 "association notification");
2903 wpa_supplicant_rx_eapol(
2904 wpa_s, wpa_s->pending_eapol_rx_src,
2905 wpabuf_head(wpa_s->pending_eapol_rx),
2906 wpabuf_len(wpa_s->pending_eapol_rx));
2907 }
2908 wpabuf_free(wpa_s->pending_eapol_rx);
2909 wpa_s->pending_eapol_rx = NULL;
2910 }
2911
2912 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2913 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002914 wpa_s->current_ssid &&
2915 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002916 /* Set static WEP keys again */
2917 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2918 }
2919
2920#ifdef CONFIG_IBSS_RSN
2921 if (wpa_s->current_ssid &&
2922 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2923 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2924 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2925 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002926 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002927 if (!wpa_s->ibss_rsn) {
2928 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2929 wpa_supplicant_deauthenticate(
2930 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2931 return;
2932 }
2933
2934 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2935 }
2936#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002937
2938 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002939
2940 if (data) {
2941 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2942 data->assoc_info.resp_ies_len,
2943 &data->assoc_info.wmm_params);
2944
2945 if (wpa_s->reassoc_same_bss)
2946 wmm_ac_restore_tspecs(wpa_s);
2947 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002948
2949#ifdef CONFIG_FILS
2950 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
2951 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid);
2952 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
2953
2954 if (fils_cache_id)
2955 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
2956 }
2957#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002958}
2959
2960
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002961static int disconnect_reason_recoverable(u16 reason_code)
2962{
2963 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2964 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2965 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2966}
2967
2968
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002969static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002970 u16 reason_code,
2971 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002972{
2973 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002974
2975 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2976 /*
2977 * At least Host AP driver and a Prism3 card seemed to be
2978 * generating streams of disconnected events when configuring
2979 * IBSS for WPA-None. Ignore them for now.
2980 */
2981 return;
2982 }
2983
2984 bssid = wpa_s->bssid;
2985 if (is_zero_ether_addr(bssid))
2986 bssid = wpa_s->pending_bssid;
2987
2988 if (!is_zero_ether_addr(bssid) ||
2989 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2990 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2991 " reason=%d%s",
2992 MAC2STR(bssid), reason_code,
2993 locally_generated ? " locally_generated=1" : "");
2994 }
2995}
2996
2997
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002998static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2999 int locally_generated)
3000{
3001 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
3002 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
3003 return 0; /* Not in 4-way handshake with PSK */
3004
3005 /*
3006 * It looks like connection was lost while trying to go through PSK
3007 * 4-way handshake. Filter out known disconnection cases that are caused
3008 * by something else than PSK mismatch to avoid confusing reports.
3009 */
3010
3011 if (locally_generated) {
3012 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3013 return 0;
3014 }
3015
3016 return 1;
3017}
3018
3019
Jouni Malinen2b89da82012-08-31 22:04:41 +03003020static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3021 u16 reason_code,
3022 int locally_generated)
3023{
3024 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003025 int authenticating;
3026 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003027 struct wpa_bss *fast_reconnect = NULL;
3028 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003029 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003030 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003031
3032 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3033 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3034
3035 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3036 /*
3037 * At least Host AP driver and a Prism3 card seemed to be
3038 * generating streams of disconnected events when configuring
3039 * IBSS for WPA-None. Ignore them for now.
3040 */
3041 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3042 "IBSS/WPA-None mode");
3043 return;
3044 }
3045
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003046 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3047 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3048 locally_generated)
3049 /*
3050 * Remove the inactive AP (which is probably out of range) from
3051 * the BSS list after marking disassociation. In particular
3052 * mac80211-based drivers use the
3053 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3054 * locally generated disconnection events for cases where the
3055 * AP does not reply anymore.
3056 */
3057 curr = wpa_s->current_bss;
3058
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003059 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003060 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3061 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003062 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3063 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003064 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003065 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07003066 if (!wpa_s->disconnected &&
3067 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003068 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003069 wpas_wps_searching(wpa_s) ||
3070 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003071 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003072 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003073 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003074 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003075 wpa_s->wpa_state);
3076 if (wpa_s->wpa_state == WPA_COMPLETED &&
3077 wpa_s->current_ssid &&
3078 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003079 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003080 disconnect_reason_recoverable(reason_code)) {
3081 /*
3082 * It looks like the AP has dropped association with
3083 * us, but could allow us to get back in. Try to
3084 * reconnect to the same BSS without full scan to save
3085 * time for some common cases.
3086 */
3087 fast_reconnect = wpa_s->current_bss;
3088 fast_reconnect_ssid = wpa_s->current_ssid;
3089 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003090 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003091 else
3092 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3093 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003094 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003095 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003096 "try to re-connect");
3097 wpa_s->reassociate = 0;
3098 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003099 if (!wpa_s->pno)
3100 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003101 }
3102 bssid = wpa_s->bssid;
3103 if (is_zero_ether_addr(bssid))
3104 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003105 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3106 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003107 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003108 if (locally_generated)
3109 wpa_s->disconnect_reason = -reason_code;
3110 else
3111 wpa_s->disconnect_reason = reason_code;
3112 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003113 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3114 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003115 wpa_clear_keys(wpa_s, wpa_s->bssid);
3116 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003117 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003118 wpa_supplicant_mark_disassoc(wpa_s);
3119
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003120 if (curr)
3121 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3122
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003123 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003124 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03003125 wpa_s->current_ssid = last_ssid;
3126 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003127
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003128 if (fast_reconnect &&
3129 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3130 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3131 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3132 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003133 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003134 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003135#ifndef CONFIG_NO_SCAN_PROCESSING
3136 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3137 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3138 fast_reconnect_ssid) < 0) {
3139 /* Recover through full scan */
3140 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3141 }
3142#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003143 } else if (fast_reconnect) {
3144 /*
3145 * Could not reconnect to the same BSS due to network being
3146 * disabled. Use a new scan to match the alternative behavior
3147 * above, i.e., to continue automatic reconnection attempt in a
3148 * way that enforces disabled network rules.
3149 */
3150 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003151 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003152}
3153
3154
3155#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003156void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003157{
3158 struct wpa_supplicant *wpa_s = eloop_ctx;
3159
3160 if (!wpa_s->pending_mic_error_report)
3161 return;
3162
3163 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3164 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3165 wpa_s->pending_mic_error_report = 0;
3166}
3167#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3168
3169
3170static void
3171wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3172 union wpa_event_data *data)
3173{
3174 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003175 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003176
3177 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3178 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003179 os_get_reltime(&t);
3180 if ((wpa_s->last_michael_mic_error.sec &&
3181 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003182 wpa_s->pending_mic_error_report) {
3183 if (wpa_s->pending_mic_error_report) {
3184 /*
3185 * Send the pending MIC error report immediately since
3186 * we are going to start countermeasures and AP better
3187 * do the same.
3188 */
3189 wpa_sm_key_request(wpa_s->wpa, 1,
3190 wpa_s->pending_mic_error_pairwise);
3191 }
3192
3193 /* Send the new MIC error report immediately since we are going
3194 * to start countermeasures and AP better do the same.
3195 */
3196 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3197
3198 /* initialize countermeasures */
3199 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003200
3201 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003203 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3204
3205 /*
3206 * Need to wait for completion of request frame. We do not get
3207 * any callback for the message completion, so just wait a
3208 * short while and hope for the best. */
3209 os_sleep(0, 10000);
3210
3211 wpa_drv_set_countermeasures(wpa_s, 1);
3212 wpa_supplicant_deauthenticate(wpa_s,
3213 WLAN_REASON_MICHAEL_MIC_FAILURE);
3214 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3215 wpa_s, NULL);
3216 eloop_register_timeout(60, 0,
3217 wpa_supplicant_stop_countermeasures,
3218 wpa_s, NULL);
3219 /* TODO: mark the AP rejected for 60 second. STA is
3220 * allowed to associate with another AP.. */
3221 } else {
3222#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3223 if (wpa_s->mic_errors_seen) {
3224 /*
3225 * Reduce the effectiveness of Michael MIC error
3226 * reports as a means for attacking against TKIP if
3227 * more than one MIC failure is noticed with the same
3228 * PTK. We delay the transmission of the reports by a
3229 * random time between 0 and 60 seconds in order to
3230 * force the attacker wait 60 seconds before getting
3231 * the information on whether a frame resulted in a MIC
3232 * failure.
3233 */
3234 u8 rval[4];
3235 int sec;
3236
3237 if (os_get_random(rval, sizeof(rval)) < 0)
3238 sec = os_random() % 60;
3239 else
3240 sec = WPA_GET_BE32(rval) % 60;
3241 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3242 "report %d seconds", sec);
3243 wpa_s->pending_mic_error_report = 1;
3244 wpa_s->pending_mic_error_pairwise = pairwise;
3245 eloop_cancel_timeout(
3246 wpa_supplicant_delayed_mic_error_report,
3247 wpa_s, NULL);
3248 eloop_register_timeout(
3249 sec, os_random() % 1000000,
3250 wpa_supplicant_delayed_mic_error_report,
3251 wpa_s, NULL);
3252 } else {
3253 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3254 }
3255#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3256 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3257#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3258 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003259 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003260 wpa_s->mic_errors_seen++;
3261}
3262
3263
3264#ifdef CONFIG_TERMINATE_ONLASTIF
3265static int any_interfaces(struct wpa_supplicant *head)
3266{
3267 struct wpa_supplicant *wpa_s;
3268
3269 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3270 if (!wpa_s->interface_removed)
3271 return 1;
3272 return 0;
3273}
3274#endif /* CONFIG_TERMINATE_ONLASTIF */
3275
3276
3277static void
3278wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3279 union wpa_event_data *data)
3280{
3281 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3282 return;
3283
3284 switch (data->interface_status.ievent) {
3285 case EVENT_INTERFACE_ADDED:
3286 if (!wpa_s->interface_removed)
3287 break;
3288 wpa_s->interface_removed = 0;
3289 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3290 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3291 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3292 "driver after interface was added");
3293 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003294
3295#ifdef CONFIG_P2P
3296 if (!wpa_s->global->p2p &&
3297 !wpa_s->global->p2p_disabled &&
3298 !wpa_s->conf->p2p_disabled &&
3299 (wpa_s->drv_flags &
3300 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3301 wpas_p2p_add_p2pdev_interface(
3302 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3303 wpa_printf(MSG_INFO,
3304 "P2P: Failed to enable P2P Device interface");
3305 /* Try to continue without. P2P will be disabled. */
3306 }
3307#endif /* CONFIG_P2P */
3308
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003309 break;
3310 case EVENT_INTERFACE_REMOVED:
3311 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3312 wpa_s->interface_removed = 1;
3313 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003314 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003315 l2_packet_deinit(wpa_s->l2);
3316 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003317
3318#ifdef CONFIG_P2P
3319 if (wpa_s->global->p2p &&
3320 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3321 (wpa_s->drv_flags &
3322 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3323 wpa_dbg(wpa_s, MSG_DEBUG,
3324 "Removing P2P Device interface");
3325 wpa_supplicant_remove_iface(
3326 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3327 0);
3328 wpa_s->global->p2p_init_wpa_s = NULL;
3329 }
3330#endif /* CONFIG_P2P */
3331
Dmitry Shmidte4663042016-04-04 10:07:49 -07003332#ifdef CONFIG_MATCH_IFACE
3333 if (wpa_s->matched) {
3334 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3335 break;
3336 }
3337#endif /* CONFIG_MATCH_IFACE */
3338
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003339#ifdef CONFIG_TERMINATE_ONLASTIF
3340 /* check if last interface */
3341 if (!any_interfaces(wpa_s->global->ifaces))
3342 eloop_terminate();
3343#endif /* CONFIG_TERMINATE_ONLASTIF */
3344 break;
3345 }
3346}
3347
3348
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003349#ifdef CONFIG_TDLS
3350static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3351 union wpa_event_data *data)
3352{
3353 if (data == NULL)
3354 return;
3355 switch (data->tdls.oper) {
3356 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003357 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3358 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3359 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3360 else
3361 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003362 break;
3363 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003364 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3365 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3366 data->tdls.reason_code);
3367 else
3368 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3369 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003370 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003371 case TDLS_REQUEST_DISCOVER:
3372 wpa_tdls_send_discovery_request(wpa_s->wpa,
3373 data->tdls.peer);
3374 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003375 }
3376}
3377#endif /* CONFIG_TDLS */
3378
3379
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003380#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003381static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3382 union wpa_event_data *data)
3383{
3384 if (data == NULL)
3385 return;
3386 switch (data->wnm.oper) {
3387 case WNM_OPER_SLEEP:
3388 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3389 "(action=%d, intval=%d)",
3390 data->wnm.sleep_action, data->wnm.sleep_intval);
3391 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003392 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003393 break;
3394 }
3395}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003396#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003397
3398
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003399#ifdef CONFIG_IEEE80211R
3400static void
3401wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3402 union wpa_event_data *data)
3403{
3404 if (data == NULL)
3405 return;
3406
3407 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3408 data->ft_ies.ies_len,
3409 data->ft_ies.ft_action,
3410 data->ft_ies.target_ap,
3411 data->ft_ies.ric_ies,
3412 data->ft_ies.ric_ies_len) < 0) {
3413 /* TODO: prevent MLME/driver from trying to associate? */
3414 }
3415}
3416#endif /* CONFIG_IEEE80211R */
3417
3418
3419#ifdef CONFIG_IBSS_RSN
3420static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3421 union wpa_event_data *data)
3422{
3423 struct wpa_ssid *ssid;
3424 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3425 return;
3426 if (data == NULL)
3427 return;
3428 ssid = wpa_s->current_ssid;
3429 if (ssid == NULL)
3430 return;
3431 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3432 return;
3433
3434 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3435}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003436
3437
3438static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3439 union wpa_event_data *data)
3440{
3441 struct wpa_ssid *ssid = wpa_s->current_ssid;
3442
3443 if (ssid == NULL)
3444 return;
3445
3446 /* check if the ssid is correctly configured as IBSS/RSN */
3447 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3448 return;
3449
3450 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3451 data->rx_mgmt.frame_len);
3452}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003453#endif /* CONFIG_IBSS_RSN */
3454
3455
3456#ifdef CONFIG_IEEE80211R
3457static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3458 size_t len)
3459{
3460 const u8 *sta_addr, *target_ap_addr;
3461 u16 status;
3462
3463 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3464 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3465 return; /* only SME case supported for now */
3466 if (len < 1 + 2 * ETH_ALEN + 2)
3467 return;
3468 if (data[0] != 2)
3469 return; /* Only FT Action Response is supported for now */
3470 sta_addr = data + 1;
3471 target_ap_addr = data + 1 + ETH_ALEN;
3472 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3473 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3474 MACSTR " TargetAP " MACSTR " status %u",
3475 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3476
3477 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3478 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3479 " in FT Action Response", MAC2STR(sta_addr));
3480 return;
3481 }
3482
3483 if (status) {
3484 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3485 "failure (status code %d)", status);
3486 /* TODO: report error to FT code(?) */
3487 return;
3488 }
3489
3490 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3491 len - (1 + 2 * ETH_ALEN + 2), 1,
3492 target_ap_addr, NULL, 0) < 0)
3493 return;
3494
3495#ifdef CONFIG_SME
3496 {
3497 struct wpa_bss *bss;
3498 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3499 if (bss)
3500 wpa_s->sme.freq = bss->freq;
3501 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3502 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3503 WLAN_AUTH_FT);
3504 }
3505#endif /* CONFIG_SME */
3506}
3507#endif /* CONFIG_IEEE80211R */
3508
3509
3510static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3511 struct unprot_deauth *e)
3512{
3513#ifdef CONFIG_IEEE80211W
3514 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3515 "dropped: " MACSTR " -> " MACSTR
3516 " (reason code %u)",
3517 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3518 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3519#endif /* CONFIG_IEEE80211W */
3520}
3521
3522
3523static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3524 struct unprot_disassoc *e)
3525{
3526#ifdef CONFIG_IEEE80211W
3527 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3528 "dropped: " MACSTR " -> " MACSTR
3529 " (reason code %u)",
3530 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3531 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3532#endif /* CONFIG_IEEE80211W */
3533}
3534
3535
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003536static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3537 u16 reason_code, int locally_generated,
3538 const u8 *ie, size_t ie_len, int deauth)
3539{
3540#ifdef CONFIG_AP
3541 if (wpa_s->ap_iface && addr) {
3542 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3543 return;
3544 }
3545
3546 if (wpa_s->ap_iface) {
3547 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3548 return;
3549 }
3550#endif /* CONFIG_AP */
3551
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003552 if (!locally_generated)
3553 wpa_s->own_disconnect_req = 0;
3554
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003555 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3556
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003557 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3558 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3559 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3560 eapol_sm_failed(wpa_s->eapol))) &&
3561 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003562 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003563
3564#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003565 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003566 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3567 locally_generated) > 0) {
3568 /*
3569 * The interface was removed, so cannot continue
3570 * processing any additional operations after this.
3571 */
3572 return;
3573 }
3574 }
3575#endif /* CONFIG_P2P */
3576
3577 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3578 locally_generated);
3579}
3580
3581
3582static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3583 struct disassoc_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, "Disassociation 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;
Hai Shalom81f62d82019-07-22 12:10:00 -07003599 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
3600 reason2str(reason_code),
3601 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003602 if (addr)
3603 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3604 MAC2STR(addr));
3605 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3606 ie, ie_len);
3607 }
3608
3609#ifdef CONFIG_AP
3610 if (wpa_s->ap_iface && info && info->addr) {
3611 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3612 return;
3613 }
3614
3615 if (wpa_s->ap_iface) {
3616 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3617 return;
3618 }
3619#endif /* CONFIG_AP */
3620
3621#ifdef CONFIG_P2P
3622 if (info) {
3623 wpas_p2p_disassoc_notif(
3624 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3625 locally_generated);
3626 }
3627#endif /* CONFIG_P2P */
3628
3629 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3630 sme_event_disassoc(wpa_s, info);
3631
3632 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3633 ie, ie_len, 0);
3634}
3635
3636
3637static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3638 struct deauth_info *info)
3639{
3640 u16 reason_code = 0;
3641 int locally_generated = 0;
3642 const u8 *addr = NULL;
3643 const u8 *ie = NULL;
3644 size_t ie_len = 0;
3645
3646 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3647
3648 if (info) {
3649 addr = info->addr;
3650 ie = info->ie;
3651 ie_len = info->ie_len;
3652 reason_code = info->reason_code;
3653 locally_generated = info->locally_generated;
Hai Shalom81f62d82019-07-22 12:10:00 -07003654 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
3655 reason_code, reason2str(reason_code),
3656 locally_generated ? " locally_generated=1" : "");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003657 if (addr) {
3658 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3659 MAC2STR(addr));
3660 }
3661 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3662 ie, ie_len);
3663 }
3664
3665 wpa_reset_ft_completed(wpa_s->wpa);
3666
3667 wpas_event_disconnect(wpa_s, addr, reason_code,
3668 locally_generated, ie, ie_len, 1);
3669}
3670
3671
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003672static const char * reg_init_str(enum reg_change_initiator init)
3673{
3674 switch (init) {
3675 case REGDOM_SET_BY_CORE:
3676 return "CORE";
3677 case REGDOM_SET_BY_USER:
3678 return "USER";
3679 case REGDOM_SET_BY_DRIVER:
3680 return "DRIVER";
3681 case REGDOM_SET_BY_COUNTRY_IE:
3682 return "COUNTRY_IE";
3683 case REGDOM_BEACON_HINT:
3684 return "BEACON_HINT";
3685 }
3686 return "?";
3687}
3688
3689
3690static const char * reg_type_str(enum reg_type type)
3691{
3692 switch (type) {
3693 case REGDOM_TYPE_UNKNOWN:
3694 return "UNKNOWN";
3695 case REGDOM_TYPE_COUNTRY:
3696 return "COUNTRY";
3697 case REGDOM_TYPE_WORLD:
3698 return "WORLD";
3699 case REGDOM_TYPE_CUSTOM_WORLD:
3700 return "CUSTOM_WORLD";
3701 case REGDOM_TYPE_INTERSECTION:
3702 return "INTERSECTION";
3703 }
3704 return "?";
3705}
3706
3707
Hai Shalom74f70d42019-02-11 14:42:39 -08003708void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
3709 struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003710{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003711 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003712 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003713
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003714 /*
3715 * To allow backwards compatibility with higher level layers that
3716 * assumed the REGDOM_CHANGE event is sent over the initially added
3717 * interface. Find the highest parent of this interface and use it to
3718 * send the event.
3719 */
3720 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3721 ;
3722
Hai Shalom74f70d42019-02-11 14:42:39 -08003723 if (info) {
3724 wpa_msg(ifs, MSG_INFO,
3725 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3726 reg_init_str(info->initiator), reg_type_str(info->type),
3727 info->alpha2[0] ? " alpha2=" : "",
3728 info->alpha2[0] ? info->alpha2 : "");
3729 }
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003730
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003731 if (wpa_s->drv_priv == NULL)
3732 return; /* Ignore event during drv initialization */
3733
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003734 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3735 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003736 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3737 ifs->ifname);
3738 free_hw_features(ifs);
3739 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003740 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003741
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003742 /* Restart PNO/sched_scan with updated channel list */
3743 if (ifs->pno) {
3744 wpas_stop_pno(ifs);
3745 wpas_start_pno(ifs);
3746 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
3747 wpa_dbg(ifs, MSG_DEBUG,
3748 "Channel list changed - restart sched_scan");
3749 wpas_scan_restart_sched_scan(ifs);
3750 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003751 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003752
3753 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003754}
3755
3756
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003757static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003758 const u8 *frame, size_t len, int freq,
3759 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003760{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003761 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003762 const u8 *payload;
3763 size_t plen;
3764 u8 category;
3765
3766 if (len < IEEE80211_HDRLEN + 2)
3767 return;
3768
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003769 mgmt = (const struct ieee80211_mgmt *) frame;
3770 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003771 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003772 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003773
3774 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3775 " Category=%u DataLen=%d freq=%d MHz",
3776 MAC2STR(mgmt->sa), category, (int) plen, freq);
3777
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003778 if (category == WLAN_ACTION_WMM) {
3779 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3780 return;
3781 }
3782
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003783#ifdef CONFIG_IEEE80211R
3784 if (category == WLAN_ACTION_FT) {
3785 ft_rx_action(wpa_s, payload, plen);
3786 return;
3787 }
3788#endif /* CONFIG_IEEE80211R */
3789
3790#ifdef CONFIG_IEEE80211W
3791#ifdef CONFIG_SME
3792 if (category == WLAN_ACTION_SA_QUERY) {
3793 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3794 return;
3795 }
3796#endif /* CONFIG_SME */
3797#endif /* CONFIG_IEEE80211W */
3798
3799#ifdef CONFIG_WNM
3800 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3801 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3802 return;
3803 }
3804#endif /* CONFIG_WNM */
3805
3806#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003807 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3808 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003809 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003810 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003811 payload, plen, freq) == 0)
3812 return;
3813#endif /* CONFIG_GAS */
3814
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003815#ifdef CONFIG_GAS_SERVER
3816 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3817 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3818 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
3819 mgmt->u.action.category,
3820 payload, plen, freq) == 0)
3821 return;
3822#endif /* CONFIG_GAS_SERVER */
3823
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003824#ifdef CONFIG_TDLS
3825 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3826 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3827 wpa_dbg(wpa_s, MSG_DEBUG,
3828 "TDLS: Received Discovery Response from " MACSTR,
3829 MAC2STR(mgmt->sa));
3830 return;
3831 }
3832#endif /* CONFIG_TDLS */
3833
3834#ifdef CONFIG_INTERWORKING
3835 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3836 payload[0] == QOS_QOS_MAP_CONFIG) {
3837 const u8 *pos = payload + 1;
3838 size_t qlen = plen - 1;
3839 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3840 MACSTR, MAC2STR(mgmt->sa));
3841 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3842 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3843 pos[1] <= qlen - 2 && pos[1] >= 16)
3844 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3845 return;
3846 }
3847#endif /* CONFIG_INTERWORKING */
3848
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003849 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003850 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
3851 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003852 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003853 payload + 1,
3854 plen - 1);
3855 return;
3856 }
3857
3858 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003859 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3860 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3861 return;
3862 }
3863
3864 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3865 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3866 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3867 payload + 1, plen - 1,
3868 rssi);
3869 return;
3870 }
3871
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003872#ifdef CONFIG_FST
3873 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3874 fst_rx_action(wpa_s->fst, mgmt, len);
3875 return;
3876 }
3877#endif /* CONFIG_FST */
3878
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003879#ifdef CONFIG_DPP
3880 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
3881 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
3882 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
3883 payload[4] == DPP_OUI_TYPE) {
3884 payload++;
3885 plen--;
3886 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
3887 return;
3888 }
3889#endif /* CONFIG_DPP */
3890
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003891 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3892 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003893 if (wpa_s->ifmsh)
3894 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003895}
3896
3897
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003898static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3899 union wpa_event_data *event)
3900{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003901 struct wpa_freq_range_list *list;
3902 char *str = NULL;
3903
3904 list = &event->freq_range;
3905
3906 if (list->num)
3907 str = freq_range_list_str(list);
3908 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3909 str ? str : "");
3910
3911#ifdef CONFIG_P2P
3912 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3913 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3914 __func__);
3915 } else {
3916 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003917
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003918 /*
3919 * The update channel flow will also take care of moving a GO
3920 * from the unsafe frequency if needed.
3921 */
3922 wpas_p2p_update_channel_list(wpa_s,
3923 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003924 }
3925#endif /* CONFIG_P2P */
3926
3927 os_free(str);
3928}
3929
3930
Roshan Pius3a1667e2018-07-03 15:17:14 -07003931static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003932{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003933 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3934 wpa_supplicant_cancel_auth_timeout(wpa_s);
3935 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3936 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3937 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3938 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003939}
3940
3941
3942static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
3943 int freq)
3944{
3945 size_t i;
3946 int j;
3947
3948 for (i = 0; i < wpa_s->hw.num_modes; i++) {
3949 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
3950
3951 for (j = 0; j < mode->num_channels; j++) {
3952 const struct hostapd_channel_data *chan;
3953
3954 chan = &mode->channels[j];
3955 if (chan->freq == freq)
3956 return chan->dfs_cac_ms;
3957 }
3958 }
3959
3960 return 0;
3961}
3962
3963
3964static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
3965 struct dfs_event *radar)
3966{
3967#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08003968 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003969 wpas_ap_event_dfs_cac_started(wpa_s, radar);
3970 } else
3971#endif /* NEED_AP_MLME && CONFIG_AP */
3972 {
3973 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
3974
3975 cac_time /= 1000; /* convert from ms to sec */
3976 if (!cac_time)
3977 cac_time = 10 * 60; /* max timeout: 10 minutes */
3978
3979 /* Restart auth timeout: CAC time added to initial timeout */
3980 wpas_auth_timeout_restart(wpa_s, cac_time);
3981 }
3982}
3983
3984
3985static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
3986 struct dfs_event *radar)
3987{
3988#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08003989 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003990 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
3991 } else
3992#endif /* NEED_AP_MLME && CONFIG_AP */
3993 {
3994 /* Restart auth timeout with original value after CAC is
3995 * finished */
3996 wpas_auth_timeout_restart(wpa_s, 0);
3997 }
3998}
3999
4000
4001static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4002 struct dfs_event *radar)
4003{
4004#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
Hai Shalom74f70d42019-02-11 14:42:39 -08004005 if (wpa_s->ap_iface || wpa_s->ifmsh) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004006 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4007 } else
4008#endif /* NEED_AP_MLME && CONFIG_AP */
4009 {
4010 /* Restart auth timeout with original value after CAC is
4011 * aborted */
4012 wpas_auth_timeout_restart(wpa_s, 0);
4013 }
4014}
4015
4016
4017static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4018 union wpa_event_data *data)
4019{
4020 wpa_dbg(wpa_s, MSG_DEBUG,
4021 "Connection authorized by device, previous state %d",
4022 wpa_s->wpa_state);
4023
4024 wpa_supplicant_event_port_authorized(wpa_s);
4025
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004026 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4027 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004028 data->assoc_info.ptk_kck_len,
4029 data->assoc_info.ptk_kek,
4030 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004031#ifdef CONFIG_FILS
4032 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4033 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4034 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4035
4036 /* Update ERP next sequence number */
4037 eapol_sm_update_erp_next_seq_num(
4038 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4039
4040 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4041 /* Add the new PMK and PMKID to the PMKSA cache */
4042 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4043 data->assoc_info.fils_pmk,
4044 data->assoc_info.fils_pmk_len,
4045 data->assoc_info.fils_pmkid,
4046 wpa_s->bssid, fils_cache_id);
4047 } else if (data->assoc_info.fils_pmkid) {
4048 /* Update the current PMKSA used for this connection */
4049 pmksa_cache_set_current(wpa_s->wpa,
4050 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004051 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004052 }
4053 }
4054#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004055}
4056
4057
Roshan Pius3a1667e2018-07-03 15:17:14 -07004058static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4059 union wpa_event_data *data)
4060{
4061 const u8 *bssid = data->assoc_reject.bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004062#ifdef CONFIG_MBO
4063 struct wpa_bss *reject_bss;
4064#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004065
4066 if (!bssid || is_zero_ether_addr(bssid))
4067 bssid = wpa_s->pending_bssid;
Hai Shalom81f62d82019-07-22 12:10:00 -07004068#ifdef CONFIG_MBO
4069 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4070 reject_bss = wpa_s->current_bss;
4071 else
4072 reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
4073#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004074
4075 if (data->assoc_reject.bssid)
4076 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4077 "bssid=" MACSTR " status_code=%u%s%s%s",
4078 MAC2STR(data->assoc_reject.bssid),
4079 data->assoc_reject.status_code,
4080 data->assoc_reject.timed_out ? " timeout" : "",
4081 data->assoc_reject.timeout_reason ? "=" : "",
4082 data->assoc_reject.timeout_reason ?
4083 data->assoc_reject.timeout_reason : "");
4084 else
4085 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4086 "status_code=%u%s%s%s",
4087 data->assoc_reject.status_code,
4088 data->assoc_reject.timed_out ? " timeout" : "",
4089 data->assoc_reject.timeout_reason ? "=" : "",
4090 data->assoc_reject.timeout_reason ?
4091 data->assoc_reject.timeout_reason : "");
4092 wpa_s->assoc_status_code = data->assoc_reject.status_code;
4093 wpa_s->assoc_timed_out = data->assoc_reject.timed_out;
4094 wpas_notify_assoc_status_code(wpa_s);
4095
4096#ifdef CONFIG_OWE
4097 if (data->assoc_reject.status_code ==
4098 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4099 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4100 wpa_s->current_ssid &&
4101 wpa_s->current_ssid->owe_group == 0 &&
4102 wpa_s->last_owe_group != 21) {
4103 struct wpa_ssid *ssid = wpa_s->current_ssid;
4104 struct wpa_bss *bss = wpa_s->current_bss;
4105
4106 if (!bss) {
4107 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4108 if (!bss) {
4109 wpas_connection_failed(wpa_s, bssid);
4110 wpa_supplicant_mark_disassoc(wpa_s);
4111 return;
4112 }
4113 }
4114 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4115 wpas_connect_work_done(wpa_s);
4116 wpa_supplicant_mark_disassoc(wpa_s);
4117 wpa_supplicant_connect(wpa_s, bss, ssid);
4118 return;
4119 }
4120#endif /* CONFIG_OWE */
4121
Hai Shalom74f70d42019-02-11 14:42:39 -08004122#ifdef CONFIG_MBO
4123 if (data->assoc_reject.status_code ==
4124 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
Hai Shalom81f62d82019-07-22 12:10:00 -07004125 reject_bss && data->assoc_reject.resp_ies) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004126 const u8 *rssi_rej;
4127
4128 rssi_rej = mbo_get_attr_from_ies(
4129 data->assoc_reject.resp_ies,
4130 data->assoc_reject.resp_ies_len,
4131 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4132 if (rssi_rej && rssi_rej[1] == 2) {
4133 wpa_printf(MSG_DEBUG,
4134 "OCE: RSSI-based association rejection from "
4135 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
Hai Shalom81f62d82019-07-22 12:10:00 -07004136 MAC2STR(reject_bss->bssid),
Hai Shalom74f70d42019-02-11 14:42:39 -08004137 rssi_rej[2], rssi_rej[3]);
4138 wpa_bss_tmp_disallow(wpa_s,
Hai Shalom81f62d82019-07-22 12:10:00 -07004139 reject_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08004140 rssi_rej[3],
Hai Shalom81f62d82019-07-22 12:10:00 -07004141 rssi_rej[2] + reject_bss->level);
Hai Shalom74f70d42019-02-11 14:42:39 -08004142 }
4143 }
4144#endif /* CONFIG_MBO */
4145
Roshan Pius3a1667e2018-07-03 15:17:14 -07004146 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4147 sme_event_assoc_reject(wpa_s, data);
4148 return;
4149 }
4150
4151 /* Driver-based SME cases */
4152
4153#ifdef CONFIG_SAE
4154 if (wpa_s->current_ssid &&
4155 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4156 !data->assoc_reject.timed_out) {
4157 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4158 wpa_sm_aborted_cached(wpa_s->wpa);
4159 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4160 }
4161#endif /* CONFIG_SAE */
4162
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004163#ifdef CONFIG_DPP
4164 if (wpa_s->current_ssid &&
4165 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4166 !data->assoc_reject.timed_out) {
4167 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4168 wpa_sm_aborted_cached(wpa_s->wpa);
4169 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4170 }
4171#endif /* CONFIG_DPP */
4172
Roshan Pius3a1667e2018-07-03 15:17:14 -07004173#ifdef CONFIG_FILS
4174 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07004175 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004176 eapol_sm_update_erp_next_seq_num(
4177 wpa_s->eapol,
4178 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07004179 fils_connection_failure(wpa_s);
4180 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004181#endif /* CONFIG_FILS */
4182
4183 wpas_connection_failed(wpa_s, bssid);
4184 wpa_supplicant_mark_disassoc(wpa_s);
4185}
4186
4187
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004188void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4189 union wpa_event_data *data)
4190{
4191 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004192 int resched;
Hai Shalom74f70d42019-02-11 14:42:39 -08004193#ifndef CONFIG_NO_STDOUT_DEBUG
4194 int level = MSG_DEBUG;
4195#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004196
4197 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4198 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004199 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004200 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004201 event != EVENT_SCHED_SCAN_STOPPED) {
4202 wpa_dbg(wpa_s, MSG_DEBUG,
4203 "Ignore event %s (%d) while interface is disabled",
4204 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004205 return;
4206 }
4207
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004208#ifndef CONFIG_NO_STDOUT_DEBUG
Dmitry Shmidt04949592012-07-19 12:16:46 -07004209 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004210 const struct ieee80211_hdr *hdr;
4211 u16 fc;
4212 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4213 fc = le_to_host16(hdr->frame_control);
4214 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4215 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4216 level = MSG_EXCESSIVE;
4217 }
4218
4219 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4220 event_to_string(event), event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004221#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004222
4223 switch (event) {
4224 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004225#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004226 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4227 data->auth.ies_len))
4228 wpa_printf(MSG_DEBUG,
4229 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004230#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004231 sme_event_auth(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004232 wpa_s->auth_status_code = data->auth.status_code;
4233 wpas_notify_auth_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004234 break;
4235 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004236#ifdef CONFIG_TESTING_OPTIONS
4237 if (wpa_s->ignore_auth_resp) {
4238 wpa_printf(MSG_INFO,
4239 "EVENT_ASSOC - ignore_auth_resp active!");
4240 break;
4241 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004242 if (wpa_s->testing_resend_assoc) {
4243 wpa_printf(MSG_INFO,
4244 "EVENT_DEAUTH - testing_resend_assoc");
4245 break;
4246 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004247#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004248 wpa_supplicant_event_assoc(wpa_s, data);
Hai Shalom74f70d42019-02-11 14:42:39 -08004249 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004250 if (data &&
4251 (data->assoc_info.authorized ||
4252 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4253 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004254 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004255 if (data) {
4256 wpa_msg(wpa_s, MSG_INFO,
4257 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4258 data->assoc_info.subnet_status);
4259 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004260 break;
4261 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004262 wpas_event_disassoc(wpa_s,
4263 data ? &data->disassoc_info : NULL);
4264 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004265 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004266#ifdef CONFIG_TESTING_OPTIONS
4267 if (wpa_s->ignore_auth_resp) {
4268 wpa_printf(MSG_INFO,
4269 "EVENT_DEAUTH - ignore_auth_resp active!");
4270 break;
4271 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004272 if (wpa_s->testing_resend_assoc) {
4273 wpa_printf(MSG_INFO,
4274 "EVENT_DEAUTH - testing_resend_assoc");
4275 break;
4276 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004277#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004278 wpas_event_deauth(wpa_s,
4279 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004280 break;
4281 case EVENT_MICHAEL_MIC_FAILURE:
4282 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4283 break;
4284#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004285 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004286 if (wpa_s->own_scan_requested ||
4287 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004288 struct os_reltime diff;
4289
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004290 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004291 os_reltime_sub(&wpa_s->scan_start_time,
4292 &wpa_s->scan_trigger_time, &diff);
4293 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4294 diff.sec, diff.usec);
4295 wpa_s->own_scan_requested = 0;
4296 wpa_s->own_scan_running = 1;
4297 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4298 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004299 wpa_msg_ctrl(wpa_s, MSG_INFO,
4300 WPA_EVENT_SCAN_STARTED "id=%u",
4301 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004302 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004303 wpa_msg_ctrl(wpa_s, MSG_INFO,
4304 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004305 }
4306 } else {
4307 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004308 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004309 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004310 }
4311 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004312 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004313 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4314 wpa_s->scan_res_handler = NULL;
4315 wpa_s->own_scan_running = 0;
4316 wpa_s->radio->external_scan_running = 0;
4317 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4318 break;
4319 }
4320
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004321 if (!(data && data->scan_info.external_scan) &&
4322 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004323 struct os_reltime now, diff;
4324 os_get_reltime(&now);
4325 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4326 wpa_s->scan_start_time.sec = 0;
4327 wpa_s->scan_start_time.usec = 0;
4328 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4329 diff.sec, diff.usec);
4330 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004331 if (wpa_supplicant_event_scan_results(wpa_s, data))
4332 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004333 if (!(data && data->scan_info.external_scan))
4334 wpa_s->own_scan_running = 0;
4335 if (data && data->scan_info.nl_scan_event)
4336 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004337 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004338 break;
4339#endif /* CONFIG_NO_SCAN_PROCESSING */
4340 case EVENT_ASSOCINFO:
4341 wpa_supplicant_event_associnfo(wpa_s, data);
4342 break;
4343 case EVENT_INTERFACE_STATUS:
4344 wpa_supplicant_event_interface_status(wpa_s, data);
4345 break;
4346 case EVENT_PMKID_CANDIDATE:
4347 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4348 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004349#ifdef CONFIG_TDLS
4350 case EVENT_TDLS:
4351 wpa_supplicant_event_tdls(wpa_s, data);
4352 break;
4353#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004354#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004355 case EVENT_WNM:
4356 wpa_supplicant_event_wnm(wpa_s, data);
4357 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004358#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004359#ifdef CONFIG_IEEE80211R
4360 case EVENT_FT_RESPONSE:
4361 wpa_supplicant_event_ft_response(wpa_s, data);
4362 break;
4363#endif /* CONFIG_IEEE80211R */
4364#ifdef CONFIG_IBSS_RSN
4365 case EVENT_IBSS_RSN_START:
4366 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4367 break;
4368#endif /* CONFIG_IBSS_RSN */
4369 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004370 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004371 break;
4372 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004373 /* It is possible to get this event from earlier connection */
4374 if (wpa_s->current_ssid &&
4375 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4376 wpa_dbg(wpa_s, MSG_DEBUG,
4377 "Ignore AUTH_TIMED_OUT in mesh configuration");
4378 break;
4379 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004380 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4381 sme_event_auth_timed_out(wpa_s, data);
4382 break;
4383 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004384 /* It is possible to get this event from earlier connection */
4385 if (wpa_s->current_ssid &&
4386 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4387 wpa_dbg(wpa_s, MSG_DEBUG,
4388 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4389 break;
4390 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004391 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4392 sme_event_assoc_timed_out(wpa_s, data);
4393 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004394 case EVENT_TX_STATUS:
4395 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4396 " type=%d stype=%d",
4397 MAC2STR(data->tx_status.dst),
4398 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004399#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004400 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004401#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004402 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4403 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004404 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004405 wpa_s, data->tx_status.dst,
4406 data->tx_status.data,
4407 data->tx_status.data_len,
4408 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004409 OFFCHANNEL_SEND_ACTION_SUCCESS :
4410 OFFCHANNEL_SEND_ACTION_NO_ACK);
4411#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004412 break;
4413 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004414#endif /* CONFIG_AP */
4415#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004416 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004417 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004418 /*
4419 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004420 * interface in GO mode, or via standalone AP interface.
4421 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4422 * except when the primary interface is used as a GO interface
4423 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004424 */
4425 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4426 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004427 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004428 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004429 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004430 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004431 data->tx_status.data,
4432 data->tx_status.data_len,
4433 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004434 OFFCHANNEL_SEND_ACTION_SUCCESS :
4435 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004436 break;
4437 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004438#endif /* CONFIG_OFFCHANNEL */
4439#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004440 switch (data->tx_status.type) {
4441 case WLAN_FC_TYPE_MGMT:
4442 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4443 data->tx_status.data_len,
4444 data->tx_status.stype,
4445 data->tx_status.ack);
4446 break;
4447 case WLAN_FC_TYPE_DATA:
4448 ap_tx_status(wpa_s, data->tx_status.dst,
4449 data->tx_status.data,
4450 data->tx_status.data_len,
4451 data->tx_status.ack);
4452 break;
4453 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004454#endif /* CONFIG_AP */
4455 break;
4456#ifdef CONFIG_AP
4457 case EVENT_EAPOL_TX_STATUS:
4458 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4459 data->eapol_tx_status.data,
4460 data->eapol_tx_status.data_len,
4461 data->eapol_tx_status.ack);
4462 break;
4463 case EVENT_DRIVER_CLIENT_POLL_OK:
4464 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004465 break;
4466 case EVENT_RX_FROM_UNKNOWN:
4467 if (wpa_s->ap_iface == NULL)
4468 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004469 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4470 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004471 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004472#endif /* CONFIG_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07004473
4474 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07004475 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004476 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004477 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004478
Hai Shalom81f62d82019-07-22 12:10:00 -07004479 wpa_msg(wpa_s, MSG_INFO,
4480 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4481 event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
4482 WPA_EVENT_CHANNEL_SWITCH_STARTED,
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004483 data->ch_switch.freq,
4484 data->ch_switch.ht_enabled,
4485 data->ch_switch.ch_offset,
4486 channel_width_to_string(data->ch_switch.ch_width),
4487 data->ch_switch.cf1,
4488 data->ch_switch.cf2);
Hai Shalom81f62d82019-07-22 12:10:00 -07004489 if (event == EVENT_CH_SWITCH_STARTED)
4490 break;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004491
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004492 wpa_s->assoc_freq = data->ch_switch.freq;
4493 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4494
Roshan Pius3a1667e2018-07-03 15:17:14 -07004495#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004496 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4497 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
Hai Shalom74f70d42019-02-11 14:42:39 -08004498 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004499 wpa_s->current_ssid->mode ==
4500 WPAS_MODE_P2P_GROUP_FORMATION) {
4501 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4502 data->ch_switch.ht_enabled,
4503 data->ch_switch.ch_offset,
4504 data->ch_switch.ch_width,
4505 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07004506 data->ch_switch.cf2,
4507 1);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004508 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004509#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004510
Hai Shalom74f70d42019-02-11 14:42:39 -08004511#ifdef CONFIG_IEEE80211W
4512 sme_event_ch_switch(wpa_s);
4513#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004514 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004515 wnm_clear_coloc_intf_reporting(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004516 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004517#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004518#ifdef NEED_AP_MLME
4519 case EVENT_DFS_RADAR_DETECTED:
4520 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004521 wpas_ap_event_dfs_radar_detected(wpa_s,
4522 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004523 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004524 case EVENT_DFS_NOP_FINISHED:
4525 if (data)
4526 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
4527 &data->dfs_event);
4528 break;
4529#endif /* NEED_AP_MLME */
4530#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004531 case EVENT_DFS_CAC_STARTED:
4532 if (data)
4533 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
4534 break;
4535 case EVENT_DFS_CAC_FINISHED:
4536 if (data)
4537 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
4538 break;
4539 case EVENT_DFS_CAC_ABORTED:
4540 if (data)
4541 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
4542 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004543 case EVENT_RX_MGMT: {
4544 u16 fc, stype;
4545 const struct ieee80211_mgmt *mgmt;
4546
Dmitry Shmidt818ea482014-03-10 13:15:21 -07004547#ifdef CONFIG_TESTING_OPTIONS
4548 if (wpa_s->ext_mgmt_frame_handling) {
4549 struct rx_mgmt *rx = &data->rx_mgmt;
4550 size_t hex_len = 2 * rx->frame_len + 1;
4551 char *hex = os_malloc(hex_len);
4552 if (hex) {
4553 wpa_snprintf_hex(hex, hex_len,
4554 rx->frame, rx->frame_len);
4555 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4556 rx->freq, rx->datarate, rx->ssi_signal,
4557 hex);
4558 os_free(hex);
4559 }
4560 break;
4561 }
4562#endif /* CONFIG_TESTING_OPTIONS */
4563
Dmitry Shmidt04949592012-07-19 12:16:46 -07004564 mgmt = (const struct ieee80211_mgmt *)
4565 data->rx_mgmt.frame;
4566 fc = le_to_host16(mgmt->frame_control);
4567 stype = WLAN_FC_GET_STYPE(fc);
4568
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004569#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004570 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004571#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004572#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004573 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004574 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004575 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07004576 const u8 *ie;
4577 size_t ie_len;
4578
4579 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4580 ie_len = data->rx_mgmt.frame_len -
4581 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004582 wpas_p2p_probe_req_rx(
4583 wpa_s, src, mgmt->da,
4584 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004585 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004586 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004587 break;
4588 }
4589#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004590#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004591 if (wpa_s->current_ssid &&
4592 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4593 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004594 data->rx_mgmt.frame_len >= 30) {
4595 wpa_supplicant_event_ibss_auth(wpa_s, data);
4596 break;
4597 }
4598#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004599
4600 if (stype == WLAN_FC_STYPE_ACTION) {
4601 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004602 wpa_s, data->rx_mgmt.frame,
4603 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004604 data->rx_mgmt.freq,
4605 data->rx_mgmt.ssi_signal);
4606 break;
4607 }
4608
4609 if (wpa_s->ifmsh) {
4610 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004611 break;
4612 }
4613
Roshan Pius3a1667e2018-07-03 15:17:14 -07004614#ifdef CONFIG_SAE
4615 if (stype == WLAN_FC_STYPE_AUTH &&
4616 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4617 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4618 sme_external_auth_mgmt_rx(
4619 wpa_s, data->rx_mgmt.frame,
4620 data->rx_mgmt.frame_len);
4621 break;
4622 }
4623#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004624 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
4625 "management frame in non-AP mode");
4626 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004627#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004628 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004629
4630 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004631 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4632 const u8 *ie;
4633 size_t ie_len;
4634
4635 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4636 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004637
4638 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
4639 mgmt->bssid, ie, ie_len,
4640 data->rx_mgmt.ssi_signal);
4641 }
4642
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004643 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004644#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004645 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004646 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004647 case EVENT_RX_PROBE_REQ:
4648 if (data->rx_probe_req.sa == NULL ||
4649 data->rx_probe_req.ie == NULL)
4650 break;
4651#ifdef CONFIG_AP
4652 if (wpa_s->ap_iface) {
4653 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
4654 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004655 data->rx_probe_req.da,
4656 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004657 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004658 data->rx_probe_req.ie_len,
4659 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004660 break;
4661 }
4662#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004663 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004664 data->rx_probe_req.da,
4665 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004666 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004667 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004668 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004669 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004670 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004671 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004672#ifdef CONFIG_OFFCHANNEL
4673 offchannel_remain_on_channel_cb(
4674 wpa_s, data->remain_on_channel.freq,
4675 data->remain_on_channel.duration);
4676#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004677 wpas_p2p_remain_on_channel_cb(
4678 wpa_s, data->remain_on_channel.freq,
4679 data->remain_on_channel.duration);
4680 break;
4681 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004682#ifdef CONFIG_OFFCHANNEL
4683 offchannel_cancel_remain_on_channel_cb(
4684 wpa_s, data->remain_on_channel.freq);
4685#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004686 wpas_p2p_cancel_remain_on_channel_cb(
4687 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004688#ifdef CONFIG_DPP
4689 wpas_dpp_cancel_remain_on_channel_cb(
4690 wpa_s, data->remain_on_channel.freq);
4691#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004692 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004693 case EVENT_EAPOL_RX:
4694 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
4695 data->eapol_rx.data,
4696 data->eapol_rx.data_len);
4697 break;
4698 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004699 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
4700 "above=%d signal=%d noise=%d txrate=%d",
4701 data->signal_change.above_threshold,
4702 data->signal_change.current_signal,
4703 data->signal_change.current_noise,
4704 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004705 wpa_bss_update_level(wpa_s->current_bss,
4706 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004707 bgscan_notify_signal_change(
4708 wpa_s, data->signal_change.above_threshold,
4709 data->signal_change.current_signal,
4710 data->signal_change.current_noise,
4711 data->signal_change.current_txrate);
4712 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004713 case EVENT_INTERFACE_MAC_CHANGED:
4714 wpa_supplicant_update_mac_addr(wpa_s);
4715 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004716 case EVENT_INTERFACE_ENABLED:
4717 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
4718 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004719 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004720 if (wpa_s->p2p_mgmt) {
4721 wpa_supplicant_set_state(wpa_s,
4722 WPA_DISCONNECTED);
4723 break;
4724 }
4725
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004726#ifdef CONFIG_AP
4727 if (!wpa_s->ap_iface) {
4728 wpa_supplicant_set_state(wpa_s,
4729 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004730 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004731 wpa_supplicant_req_scan(wpa_s, 0, 0);
4732 } else
4733 wpa_supplicant_set_state(wpa_s,
4734 WPA_COMPLETED);
4735#else /* CONFIG_AP */
4736 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
4737 wpa_supplicant_req_scan(wpa_s, 0, 0);
4738#endif /* CONFIG_AP */
4739 }
4740 break;
4741 case EVENT_INTERFACE_DISABLED:
4742 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004743#ifdef CONFIG_P2P
4744 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
4745 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
4746 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
4747 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004748 * Mark interface disabled if this happens to end up not
4749 * being removed as a separate P2P group interface.
4750 */
4751 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4752 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004753 * The interface was externally disabled. Remove
4754 * it assuming an external entity will start a
4755 * new session if needed.
4756 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004757 if (wpa_s->current_ssid &&
4758 wpa_s->current_ssid->p2p_group)
4759 wpas_p2p_interface_unavailable(wpa_s);
4760 else
4761 wpas_p2p_disconnect(wpa_s);
4762 /*
4763 * wpa_s instance may have been freed, so must not use
4764 * it here anymore.
4765 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004766 break;
4767 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004768 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
4769 p2p_in_progress(wpa_s->global->p2p) > 1) {
4770 /* This radio work will be cancelled, so clear P2P
4771 * state as well.
4772 */
4773 p2p_stop_find(wpa_s->global->p2p);
4774 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004775#endif /* CONFIG_P2P */
4776
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004777 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4778 /*
4779 * Indicate disconnection to keep ctrl_iface events
4780 * consistent.
4781 */
4782 wpa_supplicant_event_disassoc(
4783 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
4784 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004785 wpa_supplicant_mark_disassoc(wpa_s);
xshud0ee72f2018-11-08 14:37:01 -08004786 if (!wpa_s->conf->bss_no_flush_when_down)
4787 wpa_bss_flush(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08004788 radio_remove_works(wpa_s, NULL, 0);
4789
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004790 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4791 break;
4792 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004793 wpa_supplicant_update_channel_list(
4794 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004795 break;
4796 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004797 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004798 break;
4799 case EVENT_BEST_CHANNEL:
4800 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
4801 "(%d %d %d)",
4802 data->best_chan.freq_24, data->best_chan.freq_5,
4803 data->best_chan.freq_overall);
4804 wpa_s->best_24_freq = data->best_chan.freq_24;
4805 wpa_s->best_5_freq = data->best_chan.freq_5;
4806 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004807 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
4808 data->best_chan.freq_5,
4809 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004810 break;
4811 case EVENT_UNPROT_DEAUTH:
4812 wpa_supplicant_event_unprot_deauth(wpa_s,
4813 &data->unprot_deauth);
4814 break;
4815 case EVENT_UNPROT_DISASSOC:
4816 wpa_supplicant_event_unprot_disassoc(wpa_s,
4817 &data->unprot_disassoc);
4818 break;
4819 case EVENT_STATION_LOW_ACK:
4820#ifdef CONFIG_AP
4821 if (wpa_s->ap_iface && data)
4822 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
4823 data->low_ack.addr);
4824#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004825#ifdef CONFIG_TDLS
4826 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07004827 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
4828 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004829#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004830 break;
4831 case EVENT_IBSS_PEER_LOST:
4832#ifdef CONFIG_IBSS_RSN
4833 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
4834#endif /* CONFIG_IBSS_RSN */
4835 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004836 case EVENT_DRIVER_GTK_REKEY:
4837 if (os_memcmp(data->driver_gtk_rekey.bssid,
4838 wpa_s->bssid, ETH_ALEN))
4839 break;
4840 if (!wpa_s->wpa)
4841 break;
4842 wpa_sm_update_replay_ctr(wpa_s->wpa,
4843 data->driver_gtk_rekey.replay_ctr);
4844 break;
4845 case EVENT_SCHED_SCAN_STOPPED:
4846 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004847 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004848 wpa_supplicant_notify_scanning(wpa_s, 0);
4849
4850 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4851 break;
4852
4853 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004854 * If the driver stopped scanning without being requested to,
4855 * request a new scan to continue scanning for networks.
4856 */
4857 if (!wpa_s->sched_scan_stop_req &&
4858 wpa_s->wpa_state == WPA_SCANNING) {
4859 wpa_dbg(wpa_s, MSG_DEBUG,
4860 "Restart scanning after unexpected sched_scan stop event");
4861 wpa_supplicant_req_scan(wpa_s, 1, 0);
4862 break;
4863 }
4864
4865 wpa_s->sched_scan_stop_req = 0;
4866
4867 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08004868 * Start a new sched scan to continue searching for more SSIDs
4869 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004870 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07004871 if (wpa_s->sched_scan_timed_out) {
4872 wpa_supplicant_req_sched_scan(wpa_s);
4873 } else if (wpa_s->pno_sched_pending) {
4874 wpa_s->pno_sched_pending = 0;
4875 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004876 } else if (resched) {
4877 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08004878 }
4879
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004880 break;
4881 case EVENT_WPS_BUTTON_PUSHED:
4882#ifdef CONFIG_WPS
Hai Shalom021b0b52019-04-10 11:17:58 -07004883 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004884#endif /* CONFIG_WPS */
4885 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004886 case EVENT_AVOID_FREQUENCIES:
4887 wpa_supplicant_notify_avoid_freq(wpa_s, data);
4888 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004889 case EVENT_CONNECT_FAILED_REASON:
4890#ifdef CONFIG_AP
4891 if (!wpa_s->ap_iface || !data)
4892 break;
4893 hostapd_event_connect_failed_reason(
4894 wpa_s->ap_iface->bss[0],
4895 data->connect_failed_reason.addr,
4896 data->connect_failed_reason.code);
4897#endif /* CONFIG_AP */
4898 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004899 case EVENT_NEW_PEER_CANDIDATE:
4900#ifdef CONFIG_MESH
4901 if (!wpa_s->ifmsh || !data)
4902 break;
4903 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4904 data->mesh_peer.ies,
4905 data->mesh_peer.ie_len);
4906#endif /* CONFIG_MESH */
4907 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004908 case EVENT_SURVEY:
4909#ifdef CONFIG_AP
4910 if (!wpa_s->ap_iface)
4911 break;
4912 hostapd_event_get_survey(wpa_s->ap_iface,
4913 &data->survey_results);
4914#endif /* CONFIG_AP */
4915 break;
4916 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08004917#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004918#ifdef CONFIG_ACS
4919 if (!wpa_s->ap_iface)
4920 break;
4921 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4922 &data->acs_selected_channels);
4923#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08004924#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004925 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004926 case EVENT_P2P_LO_STOP:
4927#ifdef CONFIG_P2P
4928 wpa_s->p2p_lo_started = 0;
4929 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
4930 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
4931 data->p2p_lo_stop.reason_code);
4932#endif /* CONFIG_P2P */
4933 break;
Paul Stewart092955c2017-02-06 09:13:09 -08004934 case EVENT_BEACON_LOSS:
4935 if (!wpa_s->current_bss || !wpa_s->current_ssid)
4936 break;
4937 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
4938 bgscan_notify_beacon_loss(wpa_s);
4939 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004940 case EVENT_EXTERNAL_AUTH:
4941#ifdef CONFIG_SAE
4942 if (!wpa_s->current_ssid) {
4943 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
4944 break;
4945 }
4946 sme_external_auth_trigger(wpa_s, data);
4947#endif /* CONFIG_SAE */
4948 break;
4949 case EVENT_PORT_AUTHORIZED:
4950 wpa_supplicant_event_port_authorized(wpa_s);
4951 break;
4952 case EVENT_STATION_OPMODE_CHANGED:
4953#ifdef CONFIG_AP
4954 if (!wpa_s->ap_iface || !data)
4955 break;
4956
4957 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
4958 data->sta_opmode.addr,
4959 data->sta_opmode.smps_mode,
4960 data->sta_opmode.chan_width,
4961 data->sta_opmode.rx_nss);
4962#endif /* CONFIG_AP */
4963 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004964 default:
4965 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4966 break;
4967 }
4968}
Dmitry Shmidte4663042016-04-04 10:07:49 -07004969
4970
4971void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
4972 union wpa_event_data *data)
4973{
4974 struct wpa_supplicant *wpa_s;
4975
4976 if (event != EVENT_INTERFACE_STATUS)
4977 return;
4978
4979 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
4980 if (wpa_s && wpa_s->driver->get_ifindex) {
4981 unsigned int ifindex;
4982
4983 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
4984 if (ifindex != data->interface_status.ifindex) {
4985 wpa_dbg(wpa_s, MSG_DEBUG,
4986 "interface status ifindex %d mismatch (%d)",
4987 ifindex, data->interface_status.ifindex);
4988 return;
4989 }
4990 }
4991#ifdef CONFIG_MATCH_IFACE
4992 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
4993 struct wpa_interface *wpa_i;
4994
4995 wpa_i = wpa_supplicant_match_iface(
4996 ctx, data->interface_status.ifname);
4997 if (!wpa_i)
4998 return;
4999 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
5000 os_free(wpa_i);
5001 if (wpa_s)
5002 wpa_s->matched = 1;
5003 }
5004#endif /* CONFIG_MATCH_IFACE */
5005
5006 if (wpa_s)
5007 wpa_supplicant_event(wpa_s, event, data);
5008}