blob: 7eb25ea636e54fe5c5cf097ac88bea764d449df1 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Paul Stewart092955c2017-02-06 09:13:09 -08003 * Copyright (c) 2003-2017, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "notify.h"
29#include "common/ieee802_11_defs.h"
30#include "common/ieee802_11_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070031#include "common/gas_server.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070032#include "crypto/random.h"
33#include "blacklist.h"
34#include "wpas_glue.h"
35#include "wps_supplicant.h"
36#include "ibss_rsn.h"
37#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080038#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070039#include "p2p_supplicant.h"
40#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070041#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "ap.h"
43#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080045#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070046#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080047#include "mesh.h"
48#include "mesh_mpm.h"
49#include "wmm_ac.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070050#include "dpp_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070051
52
Dmitry Shmidt34af3062013-07-11 10:46:32 -070053#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070054static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080055 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070056#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080057
58
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070059int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070060{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080061 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070062
63 if (ssid == NULL || ssid->disabled_until.sec == 0)
64 return 0;
65
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080066 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070067 if (ssid->disabled_until.sec > now.sec)
68 return ssid->disabled_until.sec - now.sec;
69
70 wpas_clear_temp_disabled(wpa_s, ssid, 0);
71
72 return 0;
73}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070074
75
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080076#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070077/**
78 * wpas_reenabled_network_time - Time until first network is re-enabled
79 * @wpa_s: Pointer to wpa_supplicant data
80 * Returns: If all enabled networks are temporarily disabled, returns the time
81 * (in sec) until the first network is re-enabled. Otherwise returns 0.
82 *
83 * This function is used in case all enabled networks are temporarily disabled,
84 * in which case it returns the time (in sec) that the first network will be
85 * re-enabled. The function assumes that at least one network is enabled.
86 */
87static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
88{
89 struct wpa_ssid *ssid;
90 int disabled_for, res = 0;
91
92#ifdef CONFIG_INTERWORKING
93 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
94 wpa_s->conf->cred)
95 return 0;
96#endif /* CONFIG_INTERWORKING */
97
98 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
99 if (ssid->disabled)
100 continue;
101
102 disabled_for = wpas_temp_disabled(wpa_s, ssid);
103 if (!disabled_for)
104 return 0;
105
106 if (!res || disabled_for < res)
107 res = disabled_for;
108 }
109
110 return res;
111}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800112#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700113
114
115void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
116{
117 struct wpa_supplicant *wpa_s = eloop_ctx;
118
119 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
120 return;
121
122 wpa_dbg(wpa_s, MSG_DEBUG,
123 "Try to associate due to network getting re-enabled");
124 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
125 wpa_supplicant_cancel_sched_scan(wpa_s);
126 wpa_supplicant_req_scan(wpa_s, 0, 0);
127 }
128}
129
130
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800131static struct wpa_bss * wpa_supplicant_get_new_bss(
132 struct wpa_supplicant *wpa_s, const u8 *bssid)
133{
134 struct wpa_bss *bss = NULL;
135 struct wpa_ssid *ssid = wpa_s->current_ssid;
136
137 if (ssid->ssid_len > 0)
138 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
139 if (!bss)
140 bss = wpa_bss_get_bssid(wpa_s, bssid);
141
142 return bss;
143}
144
145
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700146static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
147{
148 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
149
150 if (!bss) {
151 wpa_supplicant_update_scan_results(wpa_s);
152
153 /* Get the BSS from the new scan results */
154 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
155 }
156
157 if (bss)
158 wpa_s->current_bss = bss;
159}
160
161
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
163{
164 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700165 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700166 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700167 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700169 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
170 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700171
172 if (wpa_s->current_ssid->ssid_len == 0)
173 return 0; /* current profile still in use */
174 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
175 if (res < 0) {
176 wpa_msg(wpa_s, MSG_INFO,
177 "Failed to read SSID from driver");
178 return 0; /* try to use current profile */
179 }
180 drv_ssid_len = res;
181
182 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
183 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
184 drv_ssid_len) == 0)
185 return 0; /* current profile still in use */
186
187 wpa_msg(wpa_s, MSG_DEBUG,
188 "Driver-initiated BSS selection changed the SSID to %s",
189 wpa_ssid_txt(drv_ssid, drv_ssid_len));
190 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700191 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192
193 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
194 "information");
195 ssid = wpa_supplicant_get_ssid(wpa_s);
196 if (ssid == NULL) {
197 wpa_msg(wpa_s, MSG_INFO,
198 "No network configuration found for the current AP");
199 return -1;
200 }
201
Dmitry Shmidt04949592012-07-19 12:16:46 -0700202 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
204 return -1;
205 }
206
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800207 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
208 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
209 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
210 return -1;
211 }
212
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700213 res = wpas_temp_disabled(wpa_s, ssid);
214 if (res > 0) {
215 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
216 "disabled for %d second(s)", res);
217 return -1;
218 }
219
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
221 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800222 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700223 u8 wpa_ie[80];
224 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800225 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
226 wpa_ie, &wpa_ie_len) < 0)
227 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228 } else {
229 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
230 }
231
232 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
233 eapol_sm_invalidate_cached_session(wpa_s->eapol);
234 old_ssid = wpa_s->current_ssid;
235 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800236
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700237 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800238
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
240 wpa_supplicant_initiate_eapol(wpa_s);
241 if (old_ssid != wpa_s->current_ssid)
242 wpas_notify_network_changed(wpa_s);
243
244 return 0;
245}
246
247
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800248void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700249{
250 struct wpa_supplicant *wpa_s = eloop_ctx;
251
252 if (wpa_s->countermeasures) {
253 wpa_s->countermeasures = 0;
254 wpa_drv_set_countermeasures(wpa_s, 0);
255 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800256
257 /*
258 * It is possible that the device is sched scanning, which means
259 * that a connection attempt will be done only when we receive
260 * scan results. However, in this case, it would be preferable
261 * to scan and connect immediately, so cancel the sched_scan and
262 * issue a regular scan flow.
263 */
264 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 wpa_supplicant_req_scan(wpa_s, 0, 0);
266 }
267}
268
269
270void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
271{
272 int bssid_changed;
273
Dmitry Shmidt04949592012-07-19 12:16:46 -0700274 wnm_bss_keep_alive_deinit(wpa_s);
275
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700276#ifdef CONFIG_IBSS_RSN
277 ibss_rsn_deinit(wpa_s->ibss_rsn);
278 wpa_s->ibss_rsn = NULL;
279#endif /* CONFIG_IBSS_RSN */
280
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700281#ifdef CONFIG_AP
282 wpa_supplicant_ap_deinit(wpa_s);
283#endif /* CONFIG_AP */
284
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700285#ifdef CONFIG_HS20
286 /* Clear possibly configured frame filters */
287 wpa_drv_configure_frame_filters(wpa_s, 0);
288#endif /* CONFIG_HS20 */
289
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700290 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
291 return;
292
293 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
294 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
295 os_memset(wpa_s->bssid, 0, ETH_ALEN);
296 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800297 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298 wpa_s->current_bss = NULL;
299 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700300
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301 if (bssid_changed)
302 wpas_notify_bssid_changed(wpa_s);
303
304 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
305 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700306 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
307 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
308 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700309 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
310 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700311 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700312 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700313 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800314
315 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800316 wpa_s->wnmsleep_used = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700317
318#ifdef CONFIG_TESTING_OPTIONS
319 wpa_s->last_tk_alg = WPA_ALG_NONE;
320 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
321#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700322 wpa_s->ieee80211ac = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323}
324
325
326static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
327{
328 struct wpa_ie_data ie;
329 int pmksa_set = -1;
330 size_t i;
331
332 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
333 ie.pmkid == NULL)
334 return;
335
336 for (i = 0; i < ie.num_pmkid; i++) {
337 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
338 ie.pmkid + i * PMKID_LEN,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700339 NULL, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800341 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342 break;
343 }
344 }
345
346 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
347 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
348}
349
350
351static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
352 union wpa_event_data *data)
353{
354 if (data == NULL) {
355 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
356 "event");
357 return;
358 }
359 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
360 " index=%d preauth=%d",
361 MAC2STR(data->pmkid_candidate.bssid),
362 data->pmkid_candidate.index,
363 data->pmkid_candidate.preauth);
364
365 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
366 data->pmkid_candidate.index,
367 data->pmkid_candidate.preauth);
368}
369
370
371static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
372{
373 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
374 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
375 return 0;
376
377#ifdef IEEE8021X_EAPOL
378 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
379 wpa_s->current_ssid &&
380 !(wpa_s->current_ssid->eapol_flags &
381 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
382 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
383 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
384 * plaintext or static WEP keys). */
385 return 0;
386 }
387#endif /* IEEE8021X_EAPOL */
388
389 return 1;
390}
391
392
393/**
394 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
395 * @wpa_s: pointer to wpa_supplicant data
396 * @ssid: Configuration data for the network
397 * Returns: 0 on success, -1 on failure
398 *
399 * This function is called when starting authentication with a network that is
400 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
401 */
402int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
403 struct wpa_ssid *ssid)
404{
405#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800406#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700407 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700408
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700409 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
410 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 return 0;
412
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700413 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 sim = 1;
415 aka = 1;
416 } else {
417 struct eap_method_type *eap = ssid->eap.eap_methods;
418 while (eap->vendor != EAP_VENDOR_IETF ||
419 eap->method != EAP_TYPE_NONE) {
420 if (eap->vendor == EAP_VENDOR_IETF) {
421 if (eap->method == EAP_TYPE_SIM)
422 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700423 else if (eap->method == EAP_TYPE_AKA ||
424 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 aka = 1;
426 }
427 eap++;
428 }
429 }
430
431 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
432 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700433 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
434 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
435 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436 aka = 0;
437
438 if (!sim && !aka) {
439 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
440 "use SIM, but neither EAP-SIM nor EAP-AKA are "
441 "enabled");
442 return 0;
443 }
444
445 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
446 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700448 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700449 if (wpa_s->scard == NULL) {
450 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
451 "(pcsc-lite)");
452 return -1;
453 }
454 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
455 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800456#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457#endif /* IEEE8021X_EAPOL */
458
459 return 0;
460}
461
462
463#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700464
465static int has_wep_key(struct wpa_ssid *ssid)
466{
467 int i;
468
469 for (i = 0; i < NUM_WEP_KEYS; i++) {
470 if (ssid->wep_key_len[i])
471 return 1;
472 }
473
474 return 0;
475}
476
477
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700478static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479 struct wpa_ssid *ssid)
480{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700481 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482
483 if (ssid->mixed_cell)
484 return 1;
485
486#ifdef CONFIG_WPS
487 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
488 return 1;
489#endif /* CONFIG_WPS */
490
Roshan Pius3a1667e2018-07-03 15:17:14 -0700491#ifdef CONFIG_OWE
492 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
493 return 1;
494#endif /* CONFIG_OWE */
495
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700496 if (has_wep_key(ssid))
497 privacy = 1;
498
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700499#ifdef IEEE8021X_EAPOL
500 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
501 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
502 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
503 privacy = 1;
504#endif /* IEEE8021X_EAPOL */
505
Jouni Malinen75ecf522011-06-27 15:19:46 -0700506 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
507 privacy = 1;
508
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800509 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
510 privacy = 1;
511
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700512 if (bss->caps & IEEE80211_CAP_PRIVACY)
513 return privacy;
514 return !privacy;
515}
516
517
518static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
519 struct wpa_ssid *ssid,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800520 struct wpa_bss *bss, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521{
522 struct wpa_ie_data ie;
523 int proto_match = 0;
524 const u8 *rsn_ie, *wpa_ie;
525 int ret;
526 int wep_ok;
527
528 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
529 if (ret >= 0)
530 return ret;
531
532 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
533 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
534 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
535 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
536 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
537
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700538 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700539 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700540 proto_match++;
541
542 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800543 if (debug_print)
544 wpa_dbg(wpa_s, MSG_DEBUG,
545 " skip RSN IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546 break;
547 }
548
549 if (wep_ok &&
550 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
551 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800552 if (debug_print)
553 wpa_dbg(wpa_s, MSG_DEBUG,
554 " selected based on TSN in RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555 return 1;
556 }
557
Roshan Pius3a1667e2018-07-03 15:17:14 -0700558 if (!(ie.proto & ssid->proto) &&
559 !(ssid->proto & WPA_PROTO_OSEN)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800560 if (debug_print)
561 wpa_dbg(wpa_s, MSG_DEBUG,
562 " skip RSN IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563 break;
564 }
565
566 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800567 if (debug_print)
568 wpa_dbg(wpa_s, MSG_DEBUG,
569 " skip RSN IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570 break;
571 }
572
573 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800574 if (debug_print)
575 wpa_dbg(wpa_s, MSG_DEBUG,
576 " skip RSN IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577 break;
578 }
579
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700580 if (ssid->group_mgmt_cipher &&
581 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
582 if (debug_print)
583 wpa_dbg(wpa_s, MSG_DEBUG,
584 " skip RSN IE - group mgmt cipher mismatch");
585 break;
586 }
587
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700588 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800589 if (debug_print)
590 wpa_dbg(wpa_s, MSG_DEBUG,
591 " skip RSN IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 break;
593 }
594
595#ifdef CONFIG_IEEE80211W
596 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800597 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800598 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800599 if (debug_print)
600 wpa_dbg(wpa_s, MSG_DEBUG,
601 " skip RSN IE - no mgmt frame protection");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602 break;
603 }
604#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800605 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
606 wpas_get_ssid_pmf(wpa_s, ssid) ==
607 NO_MGMT_FRAME_PROTECTION) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800608 if (debug_print)
609 wpa_dbg(wpa_s, MSG_DEBUG,
610 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800611 break;
612 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800613#ifdef CONFIG_MBO
614 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
615 wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
616 wpas_get_ssid_pmf(wpa_s, ssid) !=
617 NO_MGMT_FRAME_PROTECTION) {
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 enabled on MBO AP");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800621 break;
622 }
623#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700624
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800625 if (debug_print)
626 wpa_dbg(wpa_s, MSG_DEBUG,
627 " selected based on RSN IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700628 return 1;
629 }
630
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700631#ifdef CONFIG_IEEE80211W
Roshan Pius3a1667e2018-07-03 15:17:14 -0700632 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
633 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800634 if (debug_print)
635 wpa_dbg(wpa_s, MSG_DEBUG,
636 " skip - MFP Required but network not MFP Capable");
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700637 return 0;
638 }
639#endif /* CONFIG_IEEE80211W */
640
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700641 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
643 proto_match++;
644
645 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800646 if (debug_print)
647 wpa_dbg(wpa_s, MSG_DEBUG,
648 " skip WPA IE - parse failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 break;
650 }
651
652 if (wep_ok &&
653 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
654 {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800655 if (debug_print)
656 wpa_dbg(wpa_s, MSG_DEBUG,
657 " selected based on TSN in WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658 return 1;
659 }
660
661 if (!(ie.proto & ssid->proto)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800662 if (debug_print)
663 wpa_dbg(wpa_s, MSG_DEBUG,
664 " skip WPA IE - proto mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665 break;
666 }
667
668 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800669 if (debug_print)
670 wpa_dbg(wpa_s, MSG_DEBUG,
671 " skip WPA IE - PTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700672 break;
673 }
674
675 if (!(ie.group_cipher & ssid->group_cipher)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800676 if (debug_print)
677 wpa_dbg(wpa_s, MSG_DEBUG,
678 " skip WPA IE - GTK cipher mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679 break;
680 }
681
682 if (!(ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800683 if (debug_print)
684 wpa_dbg(wpa_s, MSG_DEBUG,
685 " skip WPA IE - key mgmt mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686 break;
687 }
688
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800689 if (debug_print)
690 wpa_dbg(wpa_s, MSG_DEBUG,
691 " selected based on WPA IE");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700692 return 1;
693 }
694
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700695 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
696 !rsn_ie) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800697 if (debug_print)
698 wpa_dbg(wpa_s, MSG_DEBUG,
699 " allow for non-WPA IEEE 802.1X");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700700 return 1;
701 }
702
Roshan Pius3a1667e2018-07-03 15:17:14 -0700703#ifdef CONFIG_OWE
704 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
705 !wpa_ie && !rsn_ie) {
706 if (debug_print)
707 wpa_dbg(wpa_s, MSG_DEBUG,
708 " allow in OWE transition mode");
709 return 1;
710 }
711#endif /* CONFIG_OWE */
712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700713 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
714 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800715 if (debug_print)
716 wpa_dbg(wpa_s, MSG_DEBUG,
717 " skip - no WPA/RSN proto match");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700718 return 0;
719 }
720
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800721 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
722 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800723 if (debug_print)
724 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800725 return 1;
726 }
727
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800729 if (debug_print)
730 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700731 return 1;
732 }
733
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800734 if (debug_print)
735 wpa_dbg(wpa_s, MSG_DEBUG,
736 " reject due to mismatch with WPA/WPA2");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737
738 return 0;
739}
740
741
742static int freq_allowed(int *freqs, int freq)
743{
744 int i;
745
746 if (freqs == NULL)
747 return 1;
748
749 for (i = 0; freqs[i]; i++)
750 if (freqs[i] == freq)
751 return 1;
752 return 0;
753}
754
755
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800756static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
757 int debug_print)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800758{
759 const struct hostapd_hw_modes *mode = NULL, *modes;
760 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
761 const u8 *rate_ie;
762 int i, j, k;
763
764 if (bss->freq == 0)
765 return 1; /* Cannot do matching without knowing band */
766
767 modes = wpa_s->hw.modes;
768 if (modes == NULL) {
769 /*
770 * The driver does not provide any additional information
771 * about the utilized hardware, so allow the connection attempt
772 * to continue.
773 */
774 return 1;
775 }
776
777 for (i = 0; i < wpa_s->hw.num_modes; i++) {
778 for (j = 0; j < modes[i].num_channels; j++) {
779 int freq = modes[i].channels[j].freq;
780 if (freq == bss->freq) {
781 if (mode &&
782 mode->mode == HOSTAPD_MODE_IEEE80211G)
783 break; /* do not allow 802.11b replace
784 * 802.11g */
785 mode = &modes[i];
786 break;
787 }
788 }
789 }
790
791 if (mode == NULL)
792 return 0;
793
794 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700795 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800796 if (rate_ie == NULL)
797 continue;
798
799 for (j = 2; j < rate_ie[1] + 2; j++) {
800 int flagged = !!(rate_ie[j] & 0x80);
801 int r = (rate_ie[j] & 0x7f) * 5;
802
803 /*
804 * IEEE Std 802.11n-2009 7.3.2.2:
805 * The new BSS Membership selector value is encoded
806 * like a legacy basic rate, but it is not a rate and
807 * only indicates if the BSS members are required to
808 * support the mandatory features of Clause 20 [HT PHY]
809 * in order to join the BSS.
810 */
811 if (flagged && ((rate_ie[j] & 0x7f) ==
812 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
813 if (!ht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800814 if (debug_print)
815 wpa_dbg(wpa_s, MSG_DEBUG,
816 " hardware does not support HT PHY");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800817 return 0;
818 }
819 continue;
820 }
821
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700822 /* There's also a VHT selector for 802.11ac */
823 if (flagged && ((rate_ie[j] & 0x7f) ==
824 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
825 if (!vht_supported(mode)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800826 if (debug_print)
827 wpa_dbg(wpa_s, MSG_DEBUG,
828 " hardware does not support VHT PHY");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700829 return 0;
830 }
831 continue;
832 }
833
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800834 if (!flagged)
835 continue;
836
837 /* check for legacy basic rates */
838 for (k = 0; k < mode->num_rates; k++) {
839 if (mode->rates[k] == r)
840 break;
841 }
842 if (k == mode->num_rates) {
843 /*
844 * IEEE Std 802.11-2007 7.3.2.2 demands that in
845 * order to join a BSS all required rates
846 * have to be supported by the hardware.
847 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800848 if (debug_print)
849 wpa_dbg(wpa_s, MSG_DEBUG,
850 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
851 r / 10, r % 10,
852 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800853 return 0;
854 }
855 }
856 }
857
858 return 1;
859}
860
861
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800862/*
863 * Test whether BSS is in an ESS.
864 * This is done differently in DMG (60 GHz) and non-DMG bands
865 */
866static int bss_is_ess(struct wpa_bss *bss)
867{
868 if (bss_is_dmg(bss)) {
869 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
870 IEEE80211_CAP_DMG_AP;
871 }
872
873 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
874 IEEE80211_CAP_ESS);
875}
876
877
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800878static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
879{
880 size_t i;
881
882 for (i = 0; i < ETH_ALEN; i++) {
883 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
884 return 0;
885 }
886 return 1;
887}
888
889
890static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
891{
892 size_t i;
893
894 for (i = 0; i < num; i++) {
895 const u8 *a = list + i * ETH_ALEN * 2;
896 const u8 *m = a + ETH_ALEN;
897
898 if (match_mac_mask(a, addr, m))
899 return 1;
900 }
901 return 0;
902}
903
904
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700905static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
906 const u8 **ret_ssid, size_t *ret_ssid_len)
907{
908#ifdef CONFIG_OWE
909 const u8 *owe, *pos, *end, *bssid;
910 u8 ssid_len;
911 struct wpa_bss *open_bss;
912
913 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
914 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
915 return;
916
917 pos = owe + 6;
918 end = owe + 2 + owe[1];
919
920 if (end - pos < ETH_ALEN + 1)
921 return;
922 bssid = pos;
923 pos += ETH_ALEN;
924 ssid_len = *pos++;
925 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
926 return;
927
928 /* Match the profile SSID against the OWE transition mode SSID on the
929 * open network. */
930 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
931 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
932 *ret_ssid = pos;
933 *ret_ssid_len = ssid_len;
934
935 if (bss->ssid_len > 0)
936 return;
937
938 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
939 if (!open_bss)
940 return;
941 if (ssid_len != open_bss->ssid_len ||
942 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
943 wpa_dbg(wpa_s, MSG_DEBUG,
944 "OWE: transition mode SSID mismatch: %s",
945 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
946 return;
947 }
948
949 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
950 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
951 wpa_dbg(wpa_s, MSG_DEBUG,
952 "OWE: transition mode open BSS unexpected info");
953 return;
954 }
955
956 pos = owe + 6;
957 end = owe + 2 + owe[1];
958
959 if (end - pos < ETH_ALEN + 1)
960 return;
961 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
962 wpa_dbg(wpa_s, MSG_DEBUG,
963 "OWE: transition mode BSSID mismatch: " MACSTR,
964 MAC2STR(pos));
965 return;
966 }
967 pos += ETH_ALEN;
968 ssid_len = *pos++;
969 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
970 return;
971 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
972 wpa_ssid_txt(pos, ssid_len));
973 os_memcpy(bss->ssid, pos, ssid_len);
974 bss->ssid_len = ssid_len;
975#endif /* CONFIG_OWE */
976}
977
978
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800979struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
980 int i, struct wpa_bss *bss,
981 struct wpa_ssid *group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800982 int only_first_ssid, int debug_print)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700983{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700984 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985 int wpa;
986 struct wpa_blacklist *e;
987 const u8 *ie;
988 struct wpa_ssid *ssid;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700989 int osen, rsn_osen = 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800990#ifdef CONFIG_MBO
991 const u8 *assoc_disallow;
992#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700993 const u8 *match_ssid;
994 size_t match_ssid_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700995 struct wpa_ie_data data;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700997 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700998 wpa_ie_len = ie ? ie[1] : 0;
999
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001000 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001001 rsn_ie_len = ie ? ie[1] : 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001002 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1003 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1004 rsn_osen = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001006 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1007 osen = ie != NULL;
1008
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001009 if (debug_print) {
1010 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1011 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1012 i, MAC2STR(bss->bssid),
1013 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1014 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1015 bss->freq,
1016 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1017 " wps" : "",
1018 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1019 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1020 ? " p2p" : "",
1021 osen ? " osen=1" : "");
1022 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001023
1024 e = wpa_blacklist_get(wpa_s, bss->bssid);
1025 if (e) {
1026 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001027 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001028 /*
1029 * When only a single network is enabled, we can
1030 * trigger blacklisting on the first failure. This
1031 * should not be done with multiple enabled networks to
1032 * avoid getting forced to move into a worse ESS on
1033 * single error if there are no other BSSes of the
1034 * current ESS.
1035 */
1036 limit = 0;
1037 }
1038 if (e->count > limit) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001039 if (debug_print) {
1040 wpa_dbg(wpa_s, MSG_DEBUG,
1041 " skip - blacklisted (count=%d limit=%d)",
1042 e->count, limit);
1043 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001044 return NULL;
1045 }
1046 }
1047
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001048 match_ssid = bss->ssid;
1049 match_ssid_len = bss->ssid_len;
1050 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1051
1052 if (match_ssid_len == 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001053 if (debug_print)
1054 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055 return NULL;
1056 }
1057
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001058 if (disallowed_bssid(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001059 if (debug_print)
1060 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001061 return NULL;
1062 }
1063
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001064 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001065 if (debug_print)
1066 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001067 return NULL;
1068 }
1069
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
1071
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001072 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001074 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075
Dmitry Shmidt04949592012-07-19 12:16:46 -07001076 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001077 if (debug_print)
1078 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001079 continue;
1080 }
1081
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001082 res = wpas_temp_disabled(wpa_s, ssid);
1083 if (res > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001084 if (debug_print)
1085 wpa_dbg(wpa_s, MSG_DEBUG,
1086 " skip - disabled temporarily for %d second(s)",
1087 res);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001088 continue;
1089 }
1090
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091#ifdef CONFIG_WPS
1092 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001093 if (debug_print)
1094 wpa_dbg(wpa_s, MSG_DEBUG,
1095 " skip - blacklisted (WPS)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001096 continue;
1097 }
1098
1099 if (wpa && ssid->ssid_len == 0 &&
1100 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1101 check_ssid = 0;
1102
1103 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1104 /* Only allow wildcard SSID match if an AP
1105 * advertises active WPS operation that matches
1106 * with our mode. */
1107 check_ssid = 1;
1108 if (ssid->ssid_len == 0 &&
1109 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1110 check_ssid = 0;
1111 }
1112#endif /* CONFIG_WPS */
1113
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001114 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1115 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1116 check_ssid = 0;
1117
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118 if (check_ssid &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001119 (match_ssid_len != ssid->ssid_len ||
1120 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001121 if (debug_print)
1122 wpa_dbg(wpa_s, MSG_DEBUG,
1123 " skip - SSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001124 continue;
1125 }
1126
1127 if (ssid->bssid_set &&
1128 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001129 if (debug_print)
1130 wpa_dbg(wpa_s, MSG_DEBUG,
1131 " skip - BSSID mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132 continue;
1133 }
1134
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001135 /* check blacklist */
1136 if (ssid->num_bssid_blacklist &&
1137 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1138 ssid->num_bssid_blacklist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001139 if (debug_print)
1140 wpa_dbg(wpa_s, MSG_DEBUG,
1141 " skip - BSSID blacklisted");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001142 continue;
1143 }
1144
1145 /* if there is a whitelist, only accept those APs */
1146 if (ssid->num_bssid_whitelist &&
1147 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1148 ssid->num_bssid_whitelist)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001149 if (debug_print)
1150 wpa_dbg(wpa_s, MSG_DEBUG,
1151 " skip - BSSID not in whitelist");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001152 continue;
1153 }
1154
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001155 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss,
1156 debug_print))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157 continue;
1158
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001159 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001160 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1161 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001162 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001163 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001164 if (debug_print)
1165 wpa_dbg(wpa_s, MSG_DEBUG,
1166 " skip - non-WPA network not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001167 continue;
1168 }
1169
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001170 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1171 has_wep_key(ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001172 if (debug_print)
1173 wpa_dbg(wpa_s, MSG_DEBUG,
1174 " skip - ignore WPA/WPA2 AP for WEP network block");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001175 continue;
1176 }
1177
Roshan Pius3a1667e2018-07-03 15:17:14 -07001178 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen &&
1179 !rsn_osen) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001180 if (debug_print)
1181 wpa_dbg(wpa_s, MSG_DEBUG,
1182 " skip - non-OSEN network not allowed");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001183 continue;
1184 }
1185
Jouni Malinen75ecf522011-06-27 15:19:46 -07001186 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001187 if (debug_print)
1188 wpa_dbg(wpa_s, MSG_DEBUG,
1189 " skip - privacy mismatch");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001190 continue;
1191 }
1192
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001193 if (ssid->mode != IEEE80211_MODE_MESH && !bss_is_ess(bss) &&
1194 !bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001195 if (debug_print)
1196 wpa_dbg(wpa_s, MSG_DEBUG,
1197 " skip - not ESS, PBSS, or MBSS");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001198 continue;
1199 }
1200
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001201 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001202 if (debug_print)
1203 wpa_dbg(wpa_s, MSG_DEBUG,
1204 " skip - PBSS mismatch (ssid %d bss %d)",
1205 ssid->pbss, bss_is_pbss(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001206 continue;
1207 }
1208
1209 if (!freq_allowed(ssid->freq_list, bss->freq)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001210 if (debug_print)
1211 wpa_dbg(wpa_s, MSG_DEBUG,
1212 " skip - frequency not allowed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001213 continue;
1214 }
1215
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001216#ifdef CONFIG_MESH
1217 if (ssid->mode == IEEE80211_MODE_MESH && ssid->frequency > 0 &&
1218 ssid->frequency != bss->freq) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001219 if (debug_print)
1220 wpa_dbg(wpa_s, MSG_DEBUG,
1221 " skip - frequency not allowed (mesh)");
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001222 continue;
1223 }
1224#endif /* CONFIG_MESH */
1225
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001226 if (!rate_match(wpa_s, bss, debug_print)) {
1227 if (debug_print)
1228 wpa_dbg(wpa_s, MSG_DEBUG,
1229 " skip - rate sets do not match");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001230 continue;
1231 }
1232
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001233#ifndef CONFIG_IBSS_RSN
1234 if (ssid->mode == WPAS_MODE_IBSS &&
1235 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1236 WPA_KEY_MGMT_WPA_NONE))) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001237 if (debug_print)
1238 wpa_dbg(wpa_s, MSG_DEBUG,
1239 " skip - IBSS RSN not supported in the build");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001240 continue;
1241 }
1242#endif /* !CONFIG_IBSS_RSN */
1243
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001245 if (ssid->p2p_group &&
1246 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1247 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001248 if (debug_print)
1249 wpa_dbg(wpa_s, MSG_DEBUG,
1250 " skip - no P2P IE seen");
Dmitry Shmidt96571392013-10-14 12:54:46 -07001251 continue;
1252 }
1253
Dmitry Shmidt54605472013-11-08 11:10:19 -08001254 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1255 struct wpabuf *p2p_ie;
1256 u8 dev_addr[ETH_ALEN];
1257
1258 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1259 if (ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001260 if (debug_print)
1261 wpa_dbg(wpa_s, MSG_DEBUG,
1262 " skip - no P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001263 continue;
1264 }
1265 p2p_ie = wpa_bss_get_vendor_ie_multi(
1266 bss, P2P_IE_VENDOR_TYPE);
1267 if (p2p_ie == NULL) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001268 if (debug_print)
1269 wpa_dbg(wpa_s, MSG_DEBUG,
1270 " skip - could not fetch P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001271 continue;
1272 }
1273
1274 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1275 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1276 ETH_ALEN) != 0) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001277 if (debug_print)
1278 wpa_dbg(wpa_s, MSG_DEBUG,
1279 " skip - no matching GO P2P Device Address in P2P element");
Dmitry Shmidt54605472013-11-08 11:10:19 -08001280 wpabuf_free(p2p_ie);
1281 continue;
1282 }
1283 wpabuf_free(p2p_ie);
1284 }
1285
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001286 /*
1287 * TODO: skip the AP if its P2P IE has Group Formation
1288 * bit set in the P2P Group Capability Bitmap and we
1289 * are not in Group Formation with that device.
1290 */
1291#endif /* CONFIG_P2P */
1292
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001293 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1294 {
1295 struct os_reltime diff;
1296
1297 os_reltime_sub(&wpa_s->scan_min_time,
1298 &bss->last_update, &diff);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001299 if (debug_print)
1300 wpa_dbg(wpa_s, MSG_DEBUG,
1301 " skip - scan result not recent enough (%u.%06u seconds too old)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001302 (unsigned int) diff.sec,
1303 (unsigned int) diff.usec);
1304 continue;
1305 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001306#ifdef CONFIG_MBO
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001307#ifdef CONFIG_TESTING_OPTIONS
1308 if (wpa_s->ignore_assoc_disallow)
1309 goto skip_assoc_disallow;
1310#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001311 assoc_disallow = wpas_mbo_get_bss_attr(
1312 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1313 if (assoc_disallow && assoc_disallow[1] >= 1) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001314 if (debug_print)
1315 wpa_dbg(wpa_s, MSG_DEBUG,
1316 " skip - MBO association disallowed (reason %u)",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001317 assoc_disallow[2]);
1318 continue;
1319 }
1320
1321 if (wpa_is_bss_tmp_disallowed(wpa_s, bss->bssid)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001322 if (debug_print)
1323 wpa_dbg(wpa_s, MSG_DEBUG,
1324 " skip - MBO retry delay has not passed yet");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001325 continue;
1326 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001327#ifdef CONFIG_TESTING_OPTIONS
1328 skip_assoc_disallow:
1329#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001330#endif /* CONFIG_MBO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001331
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001332#ifdef CONFIG_DPP
1333 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1334 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1335 (!ssid->dpp_connector ||
1336 !ssid->dpp_netaccesskey ||
1337 !ssid->dpp_csign)) {
1338 if (debug_print)
1339 wpa_dbg(wpa_s, MSG_DEBUG,
1340 " skip - no PMKSA entry for DPP");
1341 continue;
1342 }
1343#endif /* CONFIG_DPP */
1344
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 /* Matching configuration found */
1346 return ssid;
1347 }
1348
1349 /* No matching configuration found */
1350 return NULL;
1351}
1352
1353
1354static struct wpa_bss *
1355wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001356 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001357 struct wpa_ssid **selected_ssid,
1358 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001359{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001360 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001361
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001362 if (wpa_s->current_ssid) {
1363 struct wpa_ssid *ssid;
1364
1365 wpa_dbg(wpa_s, MSG_DEBUG,
1366 "Scan results matching the currently selected network");
1367 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1368 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1369
1370 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1371 only_first_ssid, 0);
1372 if (ssid != wpa_s->current_ssid)
1373 continue;
1374 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1375 " freq=%d level=%d snr=%d est_throughput=%u",
1376 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1377 bss->snr, bss->est_throughput);
1378 }
1379 }
1380
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001381 if (only_first_ssid)
1382 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1383 group->id);
1384 else
1385 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1386 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001387
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001388 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1389 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001390 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001391 only_first_ssid, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001392 if (!*selected_ssid)
1393 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001394 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1395 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001396 MAC2STR(bss->bssid),
1397 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1398 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399 }
1400
1401 return NULL;
1402}
1403
1404
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001405struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1406 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001407{
1408 struct wpa_bss *selected = NULL;
1409 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001410 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001411 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001412
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001413 if (wpa_s->last_scan_res == NULL ||
1414 wpa_s->last_scan_res_used == 0)
1415 return NULL; /* no scan results from last update */
1416
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001417 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001418 /* check that next_ssid is still valid */
1419 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1420 if (ssid == wpa_s->next_ssid)
1421 break;
1422 }
1423 next_ssid = ssid;
1424 wpa_s->next_ssid = NULL;
1425 }
1426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001428 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1429 if (next_ssid && next_ssid->priority ==
1430 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001431 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001432 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001433 if (selected)
1434 break;
1435 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001436 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001437 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001438 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001439 if (selected)
1440 break;
1441 }
1442
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001443 if (selected == NULL && wpa_s->blacklist &&
1444 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001445 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1446 "blacklist and try again");
1447 wpa_blacklist_clear(wpa_s);
1448 wpa_s->blacklist_cleared++;
1449 } else if (selected == NULL)
1450 break;
1451 }
1452
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001453 ssid = *selected_ssid;
1454 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1455 !ssid->passphrase && !ssid->ext_psk) {
1456 const char *field_name, *txt = NULL;
1457
1458 wpa_dbg(wpa_s, MSG_DEBUG,
1459 "PSK/passphrase not yet available for the selected network");
1460
1461 wpas_notify_network_request(wpa_s, ssid,
1462 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1463
1464 field_name = wpa_supplicant_ctrl_req_to_string(
1465 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1466 if (field_name == NULL)
1467 return NULL;
1468
1469 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1470
1471 selected = NULL;
1472 }
1473
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001474 return selected;
1475}
1476
1477
1478static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1479 int timeout_sec, int timeout_usec)
1480{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001481 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482 /*
1483 * No networks are enabled; short-circuit request so
1484 * we don't wait timeout seconds before transitioning
1485 * to INACTIVE state.
1486 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001487 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1488 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001489 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1490 return;
1491 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001492
1493 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001494 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1495}
1496
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001497
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001498int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001499 struct wpa_bss *selected,
1500 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001501{
1502 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1503 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1504 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001505 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001506#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001507 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1508 wpa_s->p2p_in_provisioning) {
1509 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1510 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001511 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001512 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513#endif /* CONFIG_P2P */
1514
1515#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001516 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001517 wpas_wps_cancel(wpa_s);
1518#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001519 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001520 }
1521
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001522 wpa_msg(wpa_s, MSG_DEBUG,
1523 "Considering connect request: reassociate: %d selected: "
1524 MACSTR " bssid: " MACSTR " pending: " MACSTR
1525 " wpa_state: %s ssid=%p current_ssid=%p",
1526 wpa_s->reassociate, MAC2STR(selected->bssid),
1527 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1528 wpa_supplicant_state_txt(wpa_s->wpa_state),
1529 ssid, wpa_s->current_ssid);
1530
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531 /*
1532 * Do not trigger new association unless the BSSID has changed or if
1533 * reassociation is requested. If we are in process of associating with
1534 * the selected BSSID, do not trigger new attempt.
1535 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001536 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1538 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1539 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001540 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1541 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1542 0) ||
1543 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1544 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001545 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1546 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001547 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001548 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001549 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1550 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001551 wpa_supplicant_associate(wpa_s, selected, ssid);
1552 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001553 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1554 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001555 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001556
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001557 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001558}
1559
1560
1561static struct wpa_ssid *
1562wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1563{
1564 int prio;
1565 struct wpa_ssid *ssid;
1566
1567 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1568 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1569 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001570 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001571 continue;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001572#ifndef CONFIG_IBSS_RSN
1573 if (ssid->mode == WPAS_MODE_IBSS &&
1574 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1575 WPA_KEY_MGMT_WPA_NONE))) {
1576 wpa_msg(wpa_s, MSG_INFO,
1577 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1578 wpa_ssid_txt(ssid->ssid,
1579 ssid->ssid_len));
1580 continue;
1581 }
1582#endif /* !CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001583 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001584 ssid->mode == IEEE80211_MODE_AP ||
1585 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001586 return ssid;
1587 }
1588 }
1589 return NULL;
1590}
1591
1592
1593/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1594 * on BSS added and BSS changed events */
1595static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001596 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001597{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001598 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001599
1600 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1601 return;
1602
Jouni Malinen87fd2792011-05-16 18:35:42 +03001603 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001604 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001605
Jouni Malinen87fd2792011-05-16 18:35:42 +03001606 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001607 if (ssid == NULL)
1608 continue;
1609
Jouni Malinen87fd2792011-05-16 18:35:42 +03001610 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001611 if (rsn == NULL)
1612 continue;
1613
Jouni Malinen87fd2792011-05-16 18:35:42 +03001614 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001615 }
1616
1617}
1618
1619
1620static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1621 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001622 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001624 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001625#ifndef CONFIG_NO_ROAMING
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001626 int min_diff, diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001627 int to_5ghz;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001628 int cur_est, sel_est;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001629#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001630
1631 if (wpa_s->reassociate)
1632 return 1; /* explicit request to reassociate */
1633 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1634 return 1; /* we are not associated; continue */
1635 if (wpa_s->current_ssid == NULL)
1636 return 1; /* unknown current SSID */
1637 if (wpa_s->current_ssid != ssid)
1638 return 1; /* different network block */
1639
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001640 if (wpas_driver_bss_selection(wpa_s))
1641 return 0; /* Driver-based roaming */
1642
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001643 if (wpa_s->current_ssid->ssid)
1644 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1645 wpa_s->current_ssid->ssid,
1646 wpa_s->current_ssid->ssid_len);
1647 if (!current_bss)
1648 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001649
1650 if (!current_bss)
1651 return 1; /* current BSS not seen in scan results */
1652
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001653 if (current_bss == selected)
1654 return 0;
1655
1656 if (selected->last_update_idx > current_bss->last_update_idx)
1657 return 1; /* current BSS not seen in the last scan */
1658
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001659#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001661 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001662 " freq=%d level=%d snr=%d est_throughput=%u",
1663 MAC2STR(current_bss->bssid),
1664 current_bss->freq, current_bss->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001665 current_bss->snr, current_bss->est_throughput);
1666 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001667 " freq=%d level=%d snr=%d est_throughput=%u",
1668 MAC2STR(selected->bssid), selected->freq, selected->level,
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001669 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001670
1671 if (wpa_s->current_ssid->bssid_set &&
1672 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1673 0) {
1674 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1675 "has preferred BSSID");
1676 return 1;
1677 }
1678
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001679 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1680 wpa_dbg(wpa_s, MSG_DEBUG,
1681 "Allow reassociation - selected BSS has better estimated throughput");
1682 return 1;
1683 }
1684
Dmitry Shmidte4663042016-04-04 10:07:49 -07001685 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1686
1687 if (current_bss->level < 0 &&
1688 current_bss->level > selected->level + to_5ghz * 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001689 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1690 "signal level");
1691 return 0;
1692 }
1693
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001694 if (current_bss->est_throughput > selected->est_throughput + 5000) {
1695 wpa_dbg(wpa_s, MSG_DEBUG,
1696 "Skip roam - Current BSS has better estimated throughput");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001697 return 0;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001698 }
1699
1700 cur_est = current_bss->est_throughput;
1701 sel_est = selected->est_throughput;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001702 min_diff = 2;
1703 if (current_bss->level < 0) {
1704 if (current_bss->level < -85)
1705 min_diff = 1;
1706 else if (current_bss->level < -80)
1707 min_diff = 2;
1708 else if (current_bss->level < -75)
1709 min_diff = 3;
1710 else if (current_bss->level < -70)
1711 min_diff = 4;
1712 else
1713 min_diff = 5;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001714 if (cur_est > sel_est * 1.5)
1715 min_diff += 10;
1716 else if (cur_est > sel_est * 1.2)
1717 min_diff += 5;
1718 else if (cur_est > sel_est * 1.1)
1719 min_diff += 2;
1720 else if (cur_est > sel_est)
1721 min_diff++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001722 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001723 if (to_5ghz) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001724 int reduce = 2;
1725
Dmitry Shmidte4663042016-04-04 10:07:49 -07001726 /* Make it easier to move to 5 GHz band */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001727 if (sel_est > cur_est * 1.5)
1728 reduce = 5;
1729 else if (sel_est > cur_est * 1.2)
1730 reduce = 4;
1731 else if (sel_est > cur_est * 1.1)
1732 reduce = 3;
1733
1734 if (min_diff > reduce)
1735 min_diff -= reduce;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001736 else
1737 min_diff = 0;
1738 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001739 diff = abs(current_bss->level - selected->level);
1740 if (diff < min_diff) {
1741 wpa_dbg(wpa_s, MSG_DEBUG,
1742 "Skip roam - too small difference in signal level (%d < %d)",
1743 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001744 return 0;
1745 }
1746
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001747 wpa_dbg(wpa_s, MSG_DEBUG,
1748 "Allow reassociation due to difference in signal level (%d >= %d)",
1749 diff, min_diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001750 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001751#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001752 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001753#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001754}
1755
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001756
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001757/*
1758 * Return a negative value if no scan results could be fetched or if scan
1759 * results should not be shared with other virtual interfaces.
1760 * Return 0 if scan results were fetched and may be shared with other
1761 * interfaces.
1762 * Return 1 if scan results may be shared with other virtual interfaces but may
1763 * not trigger any operations.
1764 * Return 2 if the interface was removed and cannot be used.
1765 */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001766static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001767 union wpa_event_data *data,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001768 int own_request, int update_only)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001769{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001770 struct wpa_scan_results *scan_res = NULL;
1771 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001772 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001773#ifndef CONFIG_NO_RANDOM_POOL
1774 size_t i, num;
1775#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001776
1777#ifdef CONFIG_AP
1778 if (wpa_s->ap_iface)
1779 ap = 1;
1780#endif /* CONFIG_AP */
1781
1782 wpa_supplicant_notify_scanning(wpa_s, 0);
1783
1784 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1785 data ? &data->scan_info :
1786 NULL, 1);
1787 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001788 if (wpa_s->conf->ap_scan == 2 || ap ||
1789 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001790 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001791 if (!own_request)
1792 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001793 if (data && data->scan_info.external_scan)
1794 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001795 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1796 "scanning again");
1797 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001798 ret = -1;
1799 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001800 }
1801
1802#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001803 num = scan_res->num;
1804 if (num > 10)
1805 num = 10;
1806 for (i = 0; i < num; i++) {
1807 u8 buf[5];
1808 struct wpa_scan_res *res = scan_res->res[i];
1809 buf[0] = res->bssid[5];
1810 buf[1] = res->qual & 0xff;
1811 buf[2] = res->noise & 0xff;
1812 buf[3] = res->level & 0xff;
1813 buf[4] = res->tsf & 0xff;
1814 random_add_randomness(buf, sizeof(buf));
1815 }
1816#endif /* CONFIG_NO_RANDOM_POOL */
1817
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001818 if (update_only) {
1819 ret = 1;
1820 goto scan_work_done;
1821 }
1822
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001823 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001824 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001825 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1826 struct wpa_scan_results *scan_res);
1827
1828 scan_res_handler = wpa_s->scan_res_handler;
1829 wpa_s->scan_res_handler = NULL;
1830 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001831 ret = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001832 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001833 }
1834
1835 if (ap) {
1836 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1837#ifdef CONFIG_AP
1838 if (wpa_s->ap_iface->scan_cb)
1839 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1840#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001841 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001842 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001843
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001844 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001845 wpa_s->own_scan_running,
1846 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001847 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001848 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1849 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001850 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1851 wpa_s->manual_scan_id);
1852 wpa_s->manual_scan_use_id = 0;
1853 } else {
1854 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1855 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001856 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001857
1858 wpas_notify_scan_done(wpa_s, 1);
1859
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001860 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001861 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 -07001862 wpa_scan_results_free(scan_res);
1863 return 0;
1864 }
1865
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001866 if (wnm_scan_process(wpa_s, 1) > 0)
1867 goto scan_work_done;
1868
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001869 if (sme_proc_obss_scan(wpa_s) > 0)
1870 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001871
Dmitry Shmidt29333592017-01-09 12:27:11 -08001872 if (own_request &&
1873 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
1874 goto scan_work_done;
1875
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001876 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1877 goto scan_work_done;
1878
1879 if (autoscan_notify_scan(wpa_s, scan_res))
1880 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001881
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001882 if (wpa_s->disconnected) {
1883 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001884 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001885 }
1886
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001887 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001888 bgscan_notify_scan(wpa_s, scan_res) == 1)
1889 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001890
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001891 wpas_wps_update_ap_info(wpa_s, scan_res);
1892
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001893 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1894 wpa_s->wpa_state < WPA_COMPLETED)
1895 goto scan_work_done;
1896
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001897 wpa_scan_results_free(scan_res);
1898
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001899 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001900 struct wpa_radio_work *work = wpa_s->scan_work;
1901 wpa_s->scan_work = NULL;
1902 radio_work_done(work);
1903 }
1904
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001905 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001906
1907scan_work_done:
1908 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001909 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001910 struct wpa_radio_work *work = wpa_s->scan_work;
1911 wpa_s->scan_work = NULL;
1912 radio_work_done(work);
1913 }
1914 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001915}
1916
1917
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001918static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001919 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001920{
1921 struct wpa_bss *selected;
1922 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001923 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1924
1925 if (time_to_reenable > 0) {
1926 wpa_dbg(wpa_s, MSG_DEBUG,
1927 "Postpone network selection by %d seconds since all networks are disabled",
1928 time_to_reenable);
1929 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1930 eloop_register_timeout(time_to_reenable, 0,
1931 wpas_network_reenabled, wpa_s, NULL);
1932 return 0;
1933 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001934
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001935 if (wpa_s->p2p_mgmt)
1936 return 0; /* no normal connection on p2p_mgmt interface */
1937
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001938 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001939
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001940#ifdef CONFIG_MESH
1941 if (wpa_s->ifmsh) {
1942 wpa_msg(wpa_s, MSG_INFO,
1943 "Avoiding join because we already joined a mesh group");
1944 return 0;
1945 }
1946#endif /* CONFIG_MESH */
1947
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001948 if (selected) {
1949 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001950 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001951 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001952 if (new_scan)
1953 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001954 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001955 }
1956
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001957 if (ssid != wpa_s->current_ssid &&
1958 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1959 wpa_s->own_disconnect_req = 1;
1960 wpa_supplicant_deauthenticate(
1961 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1962 }
1963
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001964 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001965 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001966 return -1;
1967 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001968 if (new_scan)
1969 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001970 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001971 * Do not allow other virtual radios to trigger operations based
1972 * on these scan results since we do not want them to start
1973 * other associations at the same time.
Jouni Malinen89ca7022012-09-14 13:03:12 -07001974 */
1975 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001976 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001977 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1978 ssid = wpa_supplicant_pick_new_network(wpa_s);
1979 if (ssid) {
1980 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1981 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001982 if (new_scan)
1983 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001984 } else if (own_request) {
1985 /*
1986 * No SSID found. If SCAN results are as a result of
1987 * own scan request and not due to a scan request on
1988 * another shared interface, try another scan.
1989 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001990 int timeout_sec = wpa_s->scan_interval;
1991 int timeout_usec = 0;
1992#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001993 int res;
1994
1995 res = wpas_p2p_scan_no_go_seen(wpa_s);
1996 if (res == 2)
1997 return 2;
1998 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001999 return 0;
2000
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002001 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07002002 wpa_s->show_group_started ||
2003 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002004 /*
2005 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08002006 * state and during P2P join-a-group operation
2007 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002008 */
2009 timeout_sec = 0;
2010 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002011 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2012 timeout_usec);
2013 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002014 }
2015#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002016#ifdef CONFIG_INTERWORKING
2017 if (wpa_s->conf->auto_interworking &&
2018 wpa_s->conf->interworking &&
2019 wpa_s->conf->cred) {
2020 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2021 "start ANQP fetch since no matching "
2022 "networks found");
2023 wpa_s->network_select = 1;
2024 wpa_s->auto_network_select = 1;
2025 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07002026 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002027 }
2028#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002029#ifdef CONFIG_WPS
2030 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2031 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2032 timeout_sec = 0;
2033 timeout_usec = 500000;
2034 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2035 timeout_usec);
2036 return 0;
2037 }
2038#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002039 if (wpa_supplicant_req_sched_scan(wpa_s))
2040 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2041 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07002042
2043 wpa_msg_ctrl(wpa_s, MSG_INFO,
2044 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002045 }
2046 }
2047 return 0;
2048}
2049
2050
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002051static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2052 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002053{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002054 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002055 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002056
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002057 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002058 if (res == 2) {
2059 /*
2060 * Interface may have been removed, so must not dereference
2061 * wpa_s after this.
2062 */
2063 return 1;
2064 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002065
2066 if (res < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002067 /*
2068 * If no scan results could be fetched, then no need to
2069 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07002070 * this scan. Similarly, if scan results started a new operation on this
2071 * interface, do not notify other interfaces to avoid concurrent
2072 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002073 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002074 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075 }
2076
2077 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002078 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002079 * so, they get updated with this same scan info.
2080 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002081 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2082 radio_list) {
2083 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002084 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2085 "sibling", ifs->ifname);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002086 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2087 res > 0);
2088 if (res < 0)
2089 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002090 }
2091 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002092
2093 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002094}
2095
2096#endif /* CONFIG_NO_SCAN_PROCESSING */
2097
2098
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002099int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2100{
2101#ifdef CONFIG_NO_SCAN_PROCESSING
2102 return -1;
2103#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002104 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002105
Dmitry Shmidt29333592017-01-09 12:27:11 -08002106 wpa_s->ignore_post_flush_scan_res = 0;
2107
Dmitry Shmidt41712582015-06-29 11:02:15 -07002108 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002109 return -1;
2110
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002111 os_get_reltime(&now);
2112 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002113 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2114 return -1;
2115 }
2116
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002117 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002118#endif /* CONFIG_NO_SCAN_PROCESSING */
2119}
2120
Dmitry Shmidt04949592012-07-19 12:16:46 -07002121#ifdef CONFIG_WNM
2122
2123static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2124{
2125 struct wpa_supplicant *wpa_s = eloop_ctx;
2126
2127 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2128 return;
2129
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002130 if (!wpa_s->no_keep_alive) {
2131 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2132 MAC2STR(wpa_s->bssid));
2133 /* TODO: could skip this if normal data traffic has been sent */
2134 /* TODO: Consider using some more appropriate data frame for
2135 * this */
2136 if (wpa_s->l2)
2137 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2138 (u8 *) "", 0);
2139 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002140
2141#ifdef CONFIG_SME
2142 if (wpa_s->sme.bss_max_idle_period) {
2143 unsigned int msec;
2144 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2145 if (msec > 100)
2146 msec -= 100;
2147 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2148 wnm_bss_keep_alive, wpa_s, NULL);
2149 }
2150#endif /* CONFIG_SME */
2151}
2152
2153
2154static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2155 const u8 *ies, size_t ies_len)
2156{
2157 struct ieee802_11_elems elems;
2158
2159 if (ies == NULL)
2160 return;
2161
2162 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2163 return;
2164
2165#ifdef CONFIG_SME
2166 if (elems.bss_max_idle_period) {
2167 unsigned int msec;
2168 wpa_s->sme.bss_max_idle_period =
2169 WPA_GET_LE16(elems.bss_max_idle_period);
2170 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2171 "TU)%s", wpa_s->sme.bss_max_idle_period,
2172 (elems.bss_max_idle_period[2] & 0x01) ?
2173 " (protected keep-live required)" : "");
2174 if (wpa_s->sme.bss_max_idle_period == 0)
2175 wpa_s->sme.bss_max_idle_period = 1;
2176 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2177 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2178 /* msec times 1000 */
2179 msec = wpa_s->sme.bss_max_idle_period * 1024;
2180 if (msec > 100)
2181 msec -= 100;
2182 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2183 wnm_bss_keep_alive, wpa_s,
2184 NULL);
2185 }
2186 }
2187#endif /* CONFIG_SME */
2188}
2189
2190#endif /* CONFIG_WNM */
2191
2192
2193void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2194{
2195#ifdef CONFIG_WNM
2196 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2197#endif /* CONFIG_WNM */
2198}
2199
2200
Dmitry Shmidt051af732013-10-22 13:52:46 -07002201#ifdef CONFIG_INTERWORKING
2202
2203static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2204 size_t len)
2205{
2206 int res;
2207
2208 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2209 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2210 if (res) {
2211 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2212 }
2213
2214 return res;
2215}
2216
2217
2218static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2219 const u8 *ies, size_t ies_len)
2220{
2221 struct ieee802_11_elems elems;
2222
2223 if (ies == NULL)
2224 return;
2225
2226 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2227 return;
2228
2229 if (elems.qos_map_set) {
2230 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2231 elems.qos_map_set_len);
2232 }
2233}
2234
2235#endif /* CONFIG_INTERWORKING */
2236
2237
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002238#ifdef CONFIG_FST
2239static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2240 const u8 *ie, size_t ie_len)
2241{
2242 struct mb_ies_info mb_ies;
2243
2244 if (!ie || !ie_len || !wpa_s->fst)
2245 return -ENOENT;
2246
2247 os_memset(&mb_ies, 0, sizeof(mb_ies));
2248
2249 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2250 size_t len;
2251
2252 len = 2 + ie[1];
2253 if (len > ie_len) {
2254 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2255 ie, ie_len);
2256 break;
2257 }
2258
2259 if (ie[0] == WLAN_EID_MULTI_BAND) {
2260 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2261 (unsigned int) len);
2262 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2263 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2264 mb_ies.nof_ies++;
2265 }
2266
2267 ie_len -= len;
2268 ie += len;
2269 }
2270
2271 if (mb_ies.nof_ies > 0) {
2272 wpabuf_free(wpa_s->received_mb_ies);
2273 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2274 return 0;
2275 }
2276
2277 return -ENOENT;
2278}
2279#endif /* CONFIG_FST */
2280
2281
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002282static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2283 union wpa_event_data *data)
2284{
2285 int l, len, found = 0, wpa_found, rsn_found;
2286 const u8 *p;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002287#if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002288 u8 bssid[ETH_ALEN];
Roshan Pius3a1667e2018-07-03 15:17:14 -07002289#endif /* CONFIG_IEEE80211R || CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002290
2291 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
2292 if (data->assoc_info.req_ies)
2293 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2294 data->assoc_info.req_ies_len);
2295 if (data->assoc_info.resp_ies) {
2296 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2297 data->assoc_info.resp_ies_len);
2298#ifdef CONFIG_TDLS
2299 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2300 data->assoc_info.resp_ies_len);
2301#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002302#ifdef CONFIG_WNM
2303 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2304 data->assoc_info.resp_ies_len);
2305#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002306#ifdef CONFIG_INTERWORKING
2307 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2308 data->assoc_info.resp_ies_len);
2309#endif /* CONFIG_INTERWORKING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002310 if (wpa_s->hw_capab == CAPAB_VHT &&
2311 get_ie(data->assoc_info.resp_ies,
2312 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2313 wpa_s->ieee80211ac = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002314 }
2315 if (data->assoc_info.beacon_ies)
2316 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2317 data->assoc_info.beacon_ies,
2318 data->assoc_info.beacon_ies_len);
2319 if (data->assoc_info.freq)
2320 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2321 data->assoc_info.freq);
2322
2323 p = data->assoc_info.req_ies;
2324 l = data->assoc_info.req_ies_len;
2325
2326 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2327 while (p && l >= 2) {
2328 len = p[1] + 2;
2329 if (len > l) {
2330 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2331 p, l);
2332 break;
2333 }
2334 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2335 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
Dmitry Shmidte4663042016-04-04 10:07:49 -07002336 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2337 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002338 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
2339 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2340 break;
2341 found = 1;
2342 wpa_find_assoc_pmkid(wpa_s);
2343 break;
2344 }
2345 l -= len;
2346 p += len;
2347 }
2348 if (!found && data->assoc_info.req_ies)
2349 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
2350
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002351#ifdef CONFIG_FILS
2352#ifdef CONFIG_SME
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002353 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2354 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002355 (!data->assoc_info.resp_frame ||
2356 fils_process_assoc_resp(wpa_s->wpa,
2357 data->assoc_info.resp_frame,
2358 data->assoc_info.resp_frame_len) < 0)) {
2359 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2360 return -1;
2361 }
2362#endif /* CONFIG_SME */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002363
2364 /* Additional processing for FILS when SME is in driver */
2365 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2366 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2367 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002368#endif /* CONFIG_FILS */
2369
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002370#ifdef CONFIG_OWE
2371 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
2372 (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2373 owe_process_assoc_resp(wpa_s->wpa, bssid,
2374 data->assoc_info.resp_ies,
2375 data->assoc_info.resp_ies_len) < 0)) {
2376 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2377 return -1;
2378 }
2379#endif /* CONFIG_OWE */
2380
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002381#ifdef CONFIG_IEEE80211R
2382#ifdef CONFIG_SME
2383 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2385 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2386 data->assoc_info.resp_ies,
2387 data->assoc_info.resp_ies_len,
2388 bssid) < 0) {
2389 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2390 "Reassociation Response failed");
2391 wpa_supplicant_deauthenticate(
2392 wpa_s, WLAN_REASON_INVALID_IE);
2393 return -1;
2394 }
2395 }
2396
2397 p = data->assoc_info.resp_ies;
2398 l = data->assoc_info.resp_ies_len;
2399
2400#ifdef CONFIG_WPS_STRICT
2401 if (p && wpa_s->current_ssid &&
2402 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2403 struct wpabuf *wps;
2404 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2405 if (wps == NULL) {
2406 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2407 "include WPS IE in (Re)Association Response");
2408 return -1;
2409 }
2410
2411 if (wps_validate_assoc_resp(wps) < 0) {
2412 wpabuf_free(wps);
2413 wpa_supplicant_deauthenticate(
2414 wpa_s, WLAN_REASON_INVALID_IE);
2415 return -1;
2416 }
2417 wpabuf_free(wps);
2418 }
2419#endif /* CONFIG_WPS_STRICT */
2420
2421 /* Go through the IEs and make a copy of the MDIE, if present. */
2422 while (p && l >= 2) {
2423 len = p[1] + 2;
2424 if (len > l) {
2425 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2426 p, l);
2427 break;
2428 }
2429 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2430 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2431 wpa_s->sme.ft_used = 1;
2432 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2433 MOBILITY_DOMAIN_ID_LEN);
2434 break;
2435 }
2436 l -= len;
2437 p += len;
2438 }
2439#endif /* CONFIG_SME */
2440
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002441 /* Process FT when SME is in the driver */
2442 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2443 wpa_ft_is_completed(wpa_s->wpa)) {
2444 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2445 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2446 data->assoc_info.resp_ies,
2447 data->assoc_info.resp_ies_len,
2448 bssid) < 0) {
2449 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2450 "Reassociation Response failed");
2451 wpa_supplicant_deauthenticate(
2452 wpa_s, WLAN_REASON_INVALID_IE);
2453 return -1;
2454 }
2455 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2456 }
2457
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002458 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2459 data->assoc_info.resp_ies_len);
2460#endif /* CONFIG_IEEE80211R */
2461
2462 /* WPA/RSN IE from Beacon/ProbeResp */
2463 p = data->assoc_info.beacon_ies;
2464 l = data->assoc_info.beacon_ies_len;
2465
2466 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2467 */
2468 wpa_found = rsn_found = 0;
2469 while (p && l >= 2) {
2470 len = p[1] + 2;
2471 if (len > l) {
2472 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2473 p, l);
2474 break;
2475 }
2476 if (!wpa_found &&
2477 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2478 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2479 wpa_found = 1;
2480 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2481 }
2482
2483 if (!rsn_found &&
2484 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2485 rsn_found = 1;
2486 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2487 }
2488
2489 l -= len;
2490 p += len;
2491 }
2492
2493 if (!wpa_found && data->assoc_info.beacon_ies)
2494 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2495 if (!rsn_found && data->assoc_info.beacon_ies)
2496 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2497 if (wpa_found || rsn_found)
2498 wpa_s->ap_ies_from_associnfo = 1;
2499
Jouni Malinen87fd2792011-05-16 18:35:42 +03002500 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2501 wpa_s->assoc_freq != data->assoc_info.freq) {
2502 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2503 "%u to %u MHz",
2504 wpa_s->assoc_freq, data->assoc_info.freq);
2505 wpa_supplicant_update_scan_results(wpa_s);
2506 }
2507
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002508 wpa_s->assoc_freq = data->assoc_info.freq;
2509
2510 return 0;
2511}
2512
2513
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002514static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2515{
2516 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2517
2518 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2519 return -1;
2520
2521 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2522 return 0;
2523
2524 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2525 WPA_IE_VENDOR_TYPE);
2526 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2527
2528 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2529 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2530 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2531 bss_rsn ? 2 + bss_rsn[1] : 0))
2532 return -1;
2533
2534 return 0;
2535}
2536
2537
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002538static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2539 union wpa_event_data *data)
2540{
2541#ifdef CONFIG_FST
2542 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2543 struct wpa_bss *bss = wpa_s->current_bss;
2544 const u8 *ieprb, *iebcn;
2545
2546 wpabuf_free(wpa_s->received_mb_ies);
2547 wpa_s->received_mb_ies = NULL;
2548
2549 if (ai &&
2550 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2551 wpa_printf(MSG_DEBUG,
2552 "FST: MB IEs updated from Association Response frame");
2553 return;
2554 }
2555
2556 if (ai &&
2557 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2558 wpa_printf(MSG_DEBUG,
2559 "FST: MB IEs updated from association event Beacon IEs");
2560 return;
2561 }
2562
2563 if (!bss)
2564 return;
2565
2566 ieprb = (const u8 *) (bss + 1);
2567 iebcn = ieprb + bss->ie_len;
2568
2569 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2570 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2571 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2572 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2573#endif /* CONFIG_FST */
2574}
2575
2576
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002577static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2578 union wpa_event_data *data)
2579{
2580 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002581 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002582 int new_bss = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002583
2584#ifdef CONFIG_AP
2585 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002586 if (!data)
2587 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002588 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2589 data->assoc_info.addr,
2590 data->assoc_info.req_ies,
2591 data->assoc_info.req_ies_len,
2592 data->assoc_info.reassoc);
2593 return;
2594 }
2595#endif /* CONFIG_AP */
2596
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002597 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2598
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002599 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2600 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2601 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002602 /*
2603 * FILS authentication can share the same mechanism to mark the
2604 * connection fully authenticated, so set ft_completed also based on
2605 * FILS result.
2606 */
2607 if (!ft_completed)
2608 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002609
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002610 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2611 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002612 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002613 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2614 return;
2615 }
2616
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002617 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002618 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002619 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2620 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002621 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002622 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002623 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2624 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002625 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002626
2627 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2628 wpa_clear_keys(wpa_s, bssid);
2629 }
2630 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002631 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002632 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2633 return;
2634 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002635 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002636
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002637 if (wpa_s->conf->ap_scan == 1 &&
2638 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002639 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2640 wpa_msg(wpa_s, MSG_WARNING,
2641 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002642 }
2643
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002644 wpas_fst_update_mb_assoc(wpa_s, data);
2645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002646#ifdef CONFIG_SME
2647 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2648 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002649 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002650#endif /* CONFIG_SME */
2651
2652 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2653 if (wpa_s->current_ssid) {
2654 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2655 * initialized before association, but for other modes,
2656 * initialize PC/SC here, if the current configuration needs
2657 * smartcard or SIM/USIM. */
2658 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2659 }
2660 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2661 if (wpa_s->l2)
2662 l2_packet_notify_auth_start(wpa_s->l2);
2663
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002664 already_authorized = data && data->assoc_info.authorized;
2665
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002666 /*
2667 * Set portEnabled first to FALSE in order to get EAP state machine out
2668 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2669 * state machine may transit to AUTHENTICATING state based on obsolete
2670 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2671 * AUTHENTICATED without ever giving chance to EAP state machine to
2672 * reset the state.
2673 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002674 if (!ft_completed && !already_authorized) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002675 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2676 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2677 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002678 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
2679 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
2680 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002681 already_authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002682 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2683 /* 802.1X::portControl = Auto */
2684 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2685 wpa_s->eapol_received = 0;
2686 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2687 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2688 (wpa_s->current_ssid &&
2689 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002690 if (wpa_s->current_ssid &&
2691 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002692 (wpa_s->drv_flags &
2693 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2694 /*
2695 * Set the key after having received joined-IBSS event
2696 * from the driver.
2697 */
2698 wpa_supplicant_set_wpa_none_key(wpa_s,
2699 wpa_s->current_ssid);
2700 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002701 wpa_supplicant_cancel_auth_timeout(wpa_s);
2702 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2703 } else if (!ft_completed) {
2704 /* Timeout for receiving the first EAPOL packet */
2705 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2706 }
2707 wpa_supplicant_cancel_scan(wpa_s);
2708
2709 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2710 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2711 /*
2712 * We are done; the driver will take care of RSN 4-way
2713 * handshake.
2714 */
2715 wpa_supplicant_cancel_auth_timeout(wpa_s);
2716 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2717 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2718 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2719 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2720 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2721 /*
2722 * The driver will take care of RSN 4-way handshake, so we need
2723 * to allow EAPOL supplicant to complete its work without
2724 * waiting for WPA supplicant.
2725 */
2726 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2727 } else if (ft_completed) {
2728 /*
2729 * FT protocol completed - make sure EAPOL state machine ends
2730 * up in authenticated.
2731 */
2732 wpa_supplicant_cancel_auth_timeout(wpa_s);
2733 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2734 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2735 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2736 }
2737
Jouni Malinena05074c2012-12-21 21:35:35 +02002738 wpa_s->last_eapol_matches_bssid = 0;
2739
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002740 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002741 struct os_reltime now, age;
2742 os_get_reltime(&now);
2743 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Paul Stewart092955c2017-02-06 09:13:09 -08002744 if (age.sec == 0 && age.usec < 200000 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002745 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2746 0) {
2747 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2748 "frame that was received just before "
2749 "association notification");
2750 wpa_supplicant_rx_eapol(
2751 wpa_s, wpa_s->pending_eapol_rx_src,
2752 wpabuf_head(wpa_s->pending_eapol_rx),
2753 wpabuf_len(wpa_s->pending_eapol_rx));
2754 }
2755 wpabuf_free(wpa_s->pending_eapol_rx);
2756 wpa_s->pending_eapol_rx = NULL;
2757 }
2758
2759 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2760 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002761 wpa_s->current_ssid &&
2762 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002763 /* Set static WEP keys again */
2764 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2765 }
2766
2767#ifdef CONFIG_IBSS_RSN
2768 if (wpa_s->current_ssid &&
2769 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2770 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2771 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2772 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002773 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002774 if (!wpa_s->ibss_rsn) {
2775 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2776 wpa_supplicant_deauthenticate(
2777 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2778 return;
2779 }
2780
2781 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2782 }
2783#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002784
2785 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002786
2787 if (data) {
2788 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2789 data->assoc_info.resp_ies_len,
2790 &data->assoc_info.wmm_params);
2791
2792 if (wpa_s->reassoc_same_bss)
2793 wmm_ac_restore_tspecs(wpa_s);
2794 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002795
2796#ifdef CONFIG_FILS
2797 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
2798 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid);
2799 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
2800
2801 if (fils_cache_id)
2802 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
2803 }
2804#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002805}
2806
2807
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002808static int disconnect_reason_recoverable(u16 reason_code)
2809{
2810 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2811 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2812 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2813}
2814
2815
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002816static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002817 u16 reason_code,
2818 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002819{
2820 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002821
2822 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2823 /*
2824 * At least Host AP driver and a Prism3 card seemed to be
2825 * generating streams of disconnected events when configuring
2826 * IBSS for WPA-None. Ignore them for now.
2827 */
2828 return;
2829 }
2830
2831 bssid = wpa_s->bssid;
2832 if (is_zero_ether_addr(bssid))
2833 bssid = wpa_s->pending_bssid;
2834
2835 if (!is_zero_ether_addr(bssid) ||
2836 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2837 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2838 " reason=%d%s",
2839 MAC2STR(bssid), reason_code,
2840 locally_generated ? " locally_generated=1" : "");
2841 }
2842}
2843
2844
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002845static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2846 int locally_generated)
2847{
2848 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2849 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2850 return 0; /* Not in 4-way handshake with PSK */
2851
2852 /*
2853 * It looks like connection was lost while trying to go through PSK
2854 * 4-way handshake. Filter out known disconnection cases that are caused
2855 * by something else than PSK mismatch to avoid confusing reports.
2856 */
2857
2858 if (locally_generated) {
2859 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2860 return 0;
2861 }
2862
2863 return 1;
2864}
2865
2866
Jouni Malinen2b89da82012-08-31 22:04:41 +03002867static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2868 u16 reason_code,
2869 int locally_generated)
2870{
2871 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002872 int authenticating;
2873 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002874 struct wpa_bss *fast_reconnect = NULL;
2875 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002876 struct wpa_ssid *last_ssid;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002877 struct wpa_bss *curr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878
2879 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2880 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2881
2882 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2883 /*
2884 * At least Host AP driver and a Prism3 card seemed to be
2885 * generating streams of disconnected events when configuring
2886 * IBSS for WPA-None. Ignore them for now.
2887 */
2888 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2889 "IBSS/WPA-None mode");
2890 return;
2891 }
2892
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002893 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2894 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
2895 locally_generated)
2896 /*
2897 * Remove the inactive AP (which is probably out of range) from
2898 * the BSS list after marking disassociation. In particular
2899 * mac80211-based drivers use the
2900 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2901 * locally generated disconnection events for cases where the
2902 * AP does not reply anymore.
2903 */
2904 curr = wpa_s->current_bss;
2905
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002906 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002907 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2908 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002909 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2910 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002911 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002912 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002913 if (!wpa_s->disconnected &&
2914 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002915 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002916 wpas_wps_searching(wpa_s) ||
2917 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002918 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002919 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002920 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002921 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002922 wpa_s->wpa_state);
2923 if (wpa_s->wpa_state == WPA_COMPLETED &&
2924 wpa_s->current_ssid &&
2925 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002926 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002927 disconnect_reason_recoverable(reason_code)) {
2928 /*
2929 * It looks like the AP has dropped association with
2930 * us, but could allow us to get back in. Try to
2931 * reconnect to the same BSS without full scan to save
2932 * time for some common cases.
2933 */
2934 fast_reconnect = wpa_s->current_bss;
2935 fast_reconnect_ssid = wpa_s->current_ssid;
2936 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002937 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002938 else
2939 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2940 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002941 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002942 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002943 "try to re-connect");
2944 wpa_s->reassociate = 0;
2945 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002946 if (!wpa_s->pno)
2947 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002948 }
2949 bssid = wpa_s->bssid;
2950 if (is_zero_ether_addr(bssid))
2951 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002952 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2953 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002954 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002955 if (locally_generated)
2956 wpa_s->disconnect_reason = -reason_code;
2957 else
2958 wpa_s->disconnect_reason = reason_code;
2959 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002960 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2961 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002962 wpa_clear_keys(wpa_s, wpa_s->bssid);
2963 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002964 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002965 wpa_supplicant_mark_disassoc(wpa_s);
2966
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002967 if (curr)
2968 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
2969
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002970 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002971 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002972 wpa_s->current_ssid = last_ssid;
2973 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002974
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002975 if (fast_reconnect &&
2976 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2977 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2978 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2979 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002980 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
2981 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect->bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002982#ifndef CONFIG_NO_SCAN_PROCESSING
2983 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2984 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2985 fast_reconnect_ssid) < 0) {
2986 /* Recover through full scan */
2987 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2988 }
2989#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002990 } else if (fast_reconnect) {
2991 /*
2992 * Could not reconnect to the same BSS due to network being
2993 * disabled. Use a new scan to match the alternative behavior
2994 * above, i.e., to continue automatic reconnection attempt in a
2995 * way that enforces disabled network rules.
2996 */
2997 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002998 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002999}
3000
3001
3002#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003003void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003004{
3005 struct wpa_supplicant *wpa_s = eloop_ctx;
3006
3007 if (!wpa_s->pending_mic_error_report)
3008 return;
3009
3010 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3011 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3012 wpa_s->pending_mic_error_report = 0;
3013}
3014#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3015
3016
3017static void
3018wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3019 union wpa_event_data *data)
3020{
3021 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003022 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003023
3024 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3025 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003026 os_get_reltime(&t);
3027 if ((wpa_s->last_michael_mic_error.sec &&
3028 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003029 wpa_s->pending_mic_error_report) {
3030 if (wpa_s->pending_mic_error_report) {
3031 /*
3032 * Send the pending MIC error report immediately since
3033 * we are going to start countermeasures and AP better
3034 * do the same.
3035 */
3036 wpa_sm_key_request(wpa_s->wpa, 1,
3037 wpa_s->pending_mic_error_pairwise);
3038 }
3039
3040 /* Send the new MIC error report immediately since we are going
3041 * to start countermeasures and AP better do the same.
3042 */
3043 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3044
3045 /* initialize countermeasures */
3046 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003047
3048 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3049
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003050 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3051
3052 /*
3053 * Need to wait for completion of request frame. We do not get
3054 * any callback for the message completion, so just wait a
3055 * short while and hope for the best. */
3056 os_sleep(0, 10000);
3057
3058 wpa_drv_set_countermeasures(wpa_s, 1);
3059 wpa_supplicant_deauthenticate(wpa_s,
3060 WLAN_REASON_MICHAEL_MIC_FAILURE);
3061 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3062 wpa_s, NULL);
3063 eloop_register_timeout(60, 0,
3064 wpa_supplicant_stop_countermeasures,
3065 wpa_s, NULL);
3066 /* TODO: mark the AP rejected for 60 second. STA is
3067 * allowed to associate with another AP.. */
3068 } else {
3069#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3070 if (wpa_s->mic_errors_seen) {
3071 /*
3072 * Reduce the effectiveness of Michael MIC error
3073 * reports as a means for attacking against TKIP if
3074 * more than one MIC failure is noticed with the same
3075 * PTK. We delay the transmission of the reports by a
3076 * random time between 0 and 60 seconds in order to
3077 * force the attacker wait 60 seconds before getting
3078 * the information on whether a frame resulted in a MIC
3079 * failure.
3080 */
3081 u8 rval[4];
3082 int sec;
3083
3084 if (os_get_random(rval, sizeof(rval)) < 0)
3085 sec = os_random() % 60;
3086 else
3087 sec = WPA_GET_BE32(rval) % 60;
3088 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3089 "report %d seconds", sec);
3090 wpa_s->pending_mic_error_report = 1;
3091 wpa_s->pending_mic_error_pairwise = pairwise;
3092 eloop_cancel_timeout(
3093 wpa_supplicant_delayed_mic_error_report,
3094 wpa_s, NULL);
3095 eloop_register_timeout(
3096 sec, os_random() % 1000000,
3097 wpa_supplicant_delayed_mic_error_report,
3098 wpa_s, NULL);
3099 } else {
3100 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3101 }
3102#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3103 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3104#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3105 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003106 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003107 wpa_s->mic_errors_seen++;
3108}
3109
3110
3111#ifdef CONFIG_TERMINATE_ONLASTIF
3112static int any_interfaces(struct wpa_supplicant *head)
3113{
3114 struct wpa_supplicant *wpa_s;
3115
3116 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3117 if (!wpa_s->interface_removed)
3118 return 1;
3119 return 0;
3120}
3121#endif /* CONFIG_TERMINATE_ONLASTIF */
3122
3123
3124static void
3125wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3126 union wpa_event_data *data)
3127{
3128 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3129 return;
3130
3131 switch (data->interface_status.ievent) {
3132 case EVENT_INTERFACE_ADDED:
3133 if (!wpa_s->interface_removed)
3134 break;
3135 wpa_s->interface_removed = 0;
3136 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3137 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3138 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3139 "driver after interface was added");
3140 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003141
3142#ifdef CONFIG_P2P
3143 if (!wpa_s->global->p2p &&
3144 !wpa_s->global->p2p_disabled &&
3145 !wpa_s->conf->p2p_disabled &&
3146 (wpa_s->drv_flags &
3147 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3148 wpas_p2p_add_p2pdev_interface(
3149 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3150 wpa_printf(MSG_INFO,
3151 "P2P: Failed to enable P2P Device interface");
3152 /* Try to continue without. P2P will be disabled. */
3153 }
3154#endif /* CONFIG_P2P */
3155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003156 break;
3157 case EVENT_INTERFACE_REMOVED:
3158 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3159 wpa_s->interface_removed = 1;
3160 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003161 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003162 l2_packet_deinit(wpa_s->l2);
3163 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003164
3165#ifdef CONFIG_P2P
3166 if (wpa_s->global->p2p &&
3167 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3168 (wpa_s->drv_flags &
3169 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3170 wpa_dbg(wpa_s, MSG_DEBUG,
3171 "Removing P2P Device interface");
3172 wpa_supplicant_remove_iface(
3173 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3174 0);
3175 wpa_s->global->p2p_init_wpa_s = NULL;
3176 }
3177#endif /* CONFIG_P2P */
3178
Dmitry Shmidte4663042016-04-04 10:07:49 -07003179#ifdef CONFIG_MATCH_IFACE
3180 if (wpa_s->matched) {
3181 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3182 break;
3183 }
3184#endif /* CONFIG_MATCH_IFACE */
3185
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003186#ifdef CONFIG_TERMINATE_ONLASTIF
3187 /* check if last interface */
3188 if (!any_interfaces(wpa_s->global->ifaces))
3189 eloop_terminate();
3190#endif /* CONFIG_TERMINATE_ONLASTIF */
3191 break;
3192 }
3193}
3194
3195
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003196#ifdef CONFIG_TDLS
3197static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3198 union wpa_event_data *data)
3199{
3200 if (data == NULL)
3201 return;
3202 switch (data->tdls.oper) {
3203 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003204 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3205 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3206 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3207 else
3208 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003209 break;
3210 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03003211 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3212 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3213 data->tdls.reason_code);
3214 else
3215 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3216 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003217 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07003218 case TDLS_REQUEST_DISCOVER:
3219 wpa_tdls_send_discovery_request(wpa_s->wpa,
3220 data->tdls.peer);
3221 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003222 }
3223}
3224#endif /* CONFIG_TDLS */
3225
3226
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003227#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003228static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3229 union wpa_event_data *data)
3230{
3231 if (data == NULL)
3232 return;
3233 switch (data->wnm.oper) {
3234 case WNM_OPER_SLEEP:
3235 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3236 "(action=%d, intval=%d)",
3237 data->wnm.sleep_action, data->wnm.sleep_intval);
3238 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003239 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003240 break;
3241 }
3242}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003243#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003244
3245
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003246#ifdef CONFIG_IEEE80211R
3247static void
3248wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3249 union wpa_event_data *data)
3250{
3251 if (data == NULL)
3252 return;
3253
3254 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3255 data->ft_ies.ies_len,
3256 data->ft_ies.ft_action,
3257 data->ft_ies.target_ap,
3258 data->ft_ies.ric_ies,
3259 data->ft_ies.ric_ies_len) < 0) {
3260 /* TODO: prevent MLME/driver from trying to associate? */
3261 }
3262}
3263#endif /* CONFIG_IEEE80211R */
3264
3265
3266#ifdef CONFIG_IBSS_RSN
3267static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3268 union wpa_event_data *data)
3269{
3270 struct wpa_ssid *ssid;
3271 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3272 return;
3273 if (data == NULL)
3274 return;
3275 ssid = wpa_s->current_ssid;
3276 if (ssid == NULL)
3277 return;
3278 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3279 return;
3280
3281 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3282}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003283
3284
3285static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3286 union wpa_event_data *data)
3287{
3288 struct wpa_ssid *ssid = wpa_s->current_ssid;
3289
3290 if (ssid == NULL)
3291 return;
3292
3293 /* check if the ssid is correctly configured as IBSS/RSN */
3294 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3295 return;
3296
3297 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3298 data->rx_mgmt.frame_len);
3299}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003300#endif /* CONFIG_IBSS_RSN */
3301
3302
3303#ifdef CONFIG_IEEE80211R
3304static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3305 size_t len)
3306{
3307 const u8 *sta_addr, *target_ap_addr;
3308 u16 status;
3309
3310 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3311 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3312 return; /* only SME case supported for now */
3313 if (len < 1 + 2 * ETH_ALEN + 2)
3314 return;
3315 if (data[0] != 2)
3316 return; /* Only FT Action Response is supported for now */
3317 sta_addr = data + 1;
3318 target_ap_addr = data + 1 + ETH_ALEN;
3319 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3320 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3321 MACSTR " TargetAP " MACSTR " status %u",
3322 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3323
3324 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3325 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3326 " in FT Action Response", MAC2STR(sta_addr));
3327 return;
3328 }
3329
3330 if (status) {
3331 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3332 "failure (status code %d)", status);
3333 /* TODO: report error to FT code(?) */
3334 return;
3335 }
3336
3337 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3338 len - (1 + 2 * ETH_ALEN + 2), 1,
3339 target_ap_addr, NULL, 0) < 0)
3340 return;
3341
3342#ifdef CONFIG_SME
3343 {
3344 struct wpa_bss *bss;
3345 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3346 if (bss)
3347 wpa_s->sme.freq = bss->freq;
3348 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3349 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3350 WLAN_AUTH_FT);
3351 }
3352#endif /* CONFIG_SME */
3353}
3354#endif /* CONFIG_IEEE80211R */
3355
3356
3357static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3358 struct unprot_deauth *e)
3359{
3360#ifdef CONFIG_IEEE80211W
3361 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3362 "dropped: " MACSTR " -> " MACSTR
3363 " (reason code %u)",
3364 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3365 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3366#endif /* CONFIG_IEEE80211W */
3367}
3368
3369
3370static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3371 struct unprot_disassoc *e)
3372{
3373#ifdef CONFIG_IEEE80211W
3374 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3375 "dropped: " MACSTR " -> " MACSTR
3376 " (reason code %u)",
3377 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3378 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3379#endif /* CONFIG_IEEE80211W */
3380}
3381
3382
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003383static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3384 u16 reason_code, int locally_generated,
3385 const u8 *ie, size_t ie_len, int deauth)
3386{
3387#ifdef CONFIG_AP
3388 if (wpa_s->ap_iface && addr) {
3389 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3390 return;
3391 }
3392
3393 if (wpa_s->ap_iface) {
3394 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3395 return;
3396 }
3397#endif /* CONFIG_AP */
3398
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003399 if (!locally_generated)
3400 wpa_s->own_disconnect_req = 0;
3401
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003402 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3403
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003404 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3405 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3406 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3407 eapol_sm_failed(wpa_s->eapol))) &&
3408 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003409 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003410
3411#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003412 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003413 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3414 locally_generated) > 0) {
3415 /*
3416 * The interface was removed, so cannot continue
3417 * processing any additional operations after this.
3418 */
3419 return;
3420 }
3421 }
3422#endif /* CONFIG_P2P */
3423
3424 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3425 locally_generated);
3426}
3427
3428
3429static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3430 struct disassoc_info *info)
3431{
3432 u16 reason_code = 0;
3433 int locally_generated = 0;
3434 const u8 *addr = NULL;
3435 const u8 *ie = NULL;
3436 size_t ie_len = 0;
3437
3438 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3439
3440 if (info) {
3441 addr = info->addr;
3442 ie = info->ie;
3443 ie_len = info->ie_len;
3444 reason_code = info->reason_code;
3445 locally_generated = info->locally_generated;
3446 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
3447 locally_generated ? " (locally generated)" : "");
3448 if (addr)
3449 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3450 MAC2STR(addr));
3451 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3452 ie, ie_len);
3453 }
3454
3455#ifdef CONFIG_AP
3456 if (wpa_s->ap_iface && info && info->addr) {
3457 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3458 return;
3459 }
3460
3461 if (wpa_s->ap_iface) {
3462 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3463 return;
3464 }
3465#endif /* CONFIG_AP */
3466
3467#ifdef CONFIG_P2P
3468 if (info) {
3469 wpas_p2p_disassoc_notif(
3470 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3471 locally_generated);
3472 }
3473#endif /* CONFIG_P2P */
3474
3475 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3476 sme_event_disassoc(wpa_s, info);
3477
3478 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3479 ie, ie_len, 0);
3480}
3481
3482
3483static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3484 struct deauth_info *info)
3485{
3486 u16 reason_code = 0;
3487 int locally_generated = 0;
3488 const u8 *addr = NULL;
3489 const u8 *ie = NULL;
3490 size_t ie_len = 0;
3491
3492 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3493
3494 if (info) {
3495 addr = info->addr;
3496 ie = info->ie;
3497 ie_len = info->ie_len;
3498 reason_code = info->reason_code;
3499 locally_generated = info->locally_generated;
3500 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3501 reason_code,
3502 locally_generated ? " (locally generated)" : "");
3503 if (addr) {
3504 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3505 MAC2STR(addr));
3506 }
3507 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3508 ie, ie_len);
3509 }
3510
3511 wpa_reset_ft_completed(wpa_s->wpa);
3512
3513 wpas_event_disconnect(wpa_s, addr, reason_code,
3514 locally_generated, ie, ie_len, 1);
3515}
3516
3517
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003518static const char * reg_init_str(enum reg_change_initiator init)
3519{
3520 switch (init) {
3521 case REGDOM_SET_BY_CORE:
3522 return "CORE";
3523 case REGDOM_SET_BY_USER:
3524 return "USER";
3525 case REGDOM_SET_BY_DRIVER:
3526 return "DRIVER";
3527 case REGDOM_SET_BY_COUNTRY_IE:
3528 return "COUNTRY_IE";
3529 case REGDOM_BEACON_HINT:
3530 return "BEACON_HINT";
3531 }
3532 return "?";
3533}
3534
3535
3536static const char * reg_type_str(enum reg_type type)
3537{
3538 switch (type) {
3539 case REGDOM_TYPE_UNKNOWN:
3540 return "UNKNOWN";
3541 case REGDOM_TYPE_COUNTRY:
3542 return "COUNTRY";
3543 case REGDOM_TYPE_WORLD:
3544 return "WORLD";
3545 case REGDOM_TYPE_CUSTOM_WORLD:
3546 return "CUSTOM_WORLD";
3547 case REGDOM_TYPE_INTERSECTION:
3548 return "INTERSECTION";
3549 }
3550 return "?";
3551}
3552
3553
3554static void wpa_supplicant_update_channel_list(
3555 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003556{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003557 struct wpa_supplicant *ifs;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003558 u8 dfs_domain;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003559
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003560 /*
3561 * To allow backwards compatibility with higher level layers that
3562 * assumed the REGDOM_CHANGE event is sent over the initially added
3563 * interface. Find the highest parent of this interface and use it to
3564 * send the event.
3565 */
3566 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3567 ;
3568
3569 wpa_msg(ifs, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
Dmitry Shmidtc2817022014-07-02 10:32:10 -07003570 reg_init_str(info->initiator), reg_type_str(info->type),
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003571 info->alpha2[0] ? " alpha2=" : "",
3572 info->alpha2[0] ? info->alpha2 : "");
3573
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003574 if (wpa_s->drv_priv == NULL)
3575 return; /* Ignore event during drv initialization */
3576
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003577 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3578 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003579 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3580 ifs->ifname);
3581 free_hw_features(ifs);
3582 ifs->hw.modes = wpa_drv_get_hw_feature_data(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003583 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003584
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003585 /* Restart PNO/sched_scan with updated channel list */
3586 if (ifs->pno) {
3587 wpas_stop_pno(ifs);
3588 wpas_start_pno(ifs);
3589 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
3590 wpa_dbg(ifs, MSG_DEBUG,
3591 "Channel list changed - restart sched_scan");
3592 wpas_scan_restart_sched_scan(ifs);
3593 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003594 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003595
3596 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003597}
3598
3599
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003600static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003601 const u8 *frame, size_t len, int freq,
3602 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003603{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003604 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003605 const u8 *payload;
3606 size_t plen;
3607 u8 category;
3608
3609 if (len < IEEE80211_HDRLEN + 2)
3610 return;
3611
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003612 mgmt = (const struct ieee80211_mgmt *) frame;
3613 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003614 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003615 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003616
3617 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3618 " Category=%u DataLen=%d freq=%d MHz",
3619 MAC2STR(mgmt->sa), category, (int) plen, freq);
3620
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003621 if (category == WLAN_ACTION_WMM) {
3622 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3623 return;
3624 }
3625
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003626#ifdef CONFIG_IEEE80211R
3627 if (category == WLAN_ACTION_FT) {
3628 ft_rx_action(wpa_s, payload, plen);
3629 return;
3630 }
3631#endif /* CONFIG_IEEE80211R */
3632
3633#ifdef CONFIG_IEEE80211W
3634#ifdef CONFIG_SME
3635 if (category == WLAN_ACTION_SA_QUERY) {
3636 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3637 return;
3638 }
3639#endif /* CONFIG_SME */
3640#endif /* CONFIG_IEEE80211W */
3641
3642#ifdef CONFIG_WNM
3643 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3644 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3645 return;
3646 }
3647#endif /* CONFIG_WNM */
3648
3649#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003650 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3651 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003652 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003653 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003654 payload, plen, freq) == 0)
3655 return;
3656#endif /* CONFIG_GAS */
3657
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003658#ifdef CONFIG_GAS_SERVER
3659 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3660 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3661 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
3662 mgmt->u.action.category,
3663 payload, plen, freq) == 0)
3664 return;
3665#endif /* CONFIG_GAS_SERVER */
3666
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003667#ifdef CONFIG_TDLS
3668 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3669 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3670 wpa_dbg(wpa_s, MSG_DEBUG,
3671 "TDLS: Received Discovery Response from " MACSTR,
3672 MAC2STR(mgmt->sa));
3673 return;
3674 }
3675#endif /* CONFIG_TDLS */
3676
3677#ifdef CONFIG_INTERWORKING
3678 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3679 payload[0] == QOS_QOS_MAP_CONFIG) {
3680 const u8 *pos = payload + 1;
3681 size_t qlen = plen - 1;
3682 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3683 MACSTR, MAC2STR(mgmt->sa));
3684 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3685 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3686 pos[1] <= qlen - 2 && pos[1] >= 16)
3687 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3688 return;
3689 }
3690#endif /* CONFIG_INTERWORKING */
3691
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003692 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003693 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
3694 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003695 mgmt->da,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003696 payload + 1,
3697 plen - 1);
3698 return;
3699 }
3700
3701 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003702 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3703 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3704 return;
3705 }
3706
3707 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3708 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3709 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3710 payload + 1, plen - 1,
3711 rssi);
3712 return;
3713 }
3714
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003715#ifdef CONFIG_FST
3716 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3717 fst_rx_action(wpa_s->fst, mgmt, len);
3718 return;
3719 }
3720#endif /* CONFIG_FST */
3721
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003722#ifdef CONFIG_DPP
3723 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
3724 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
3725 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
3726 payload[4] == DPP_OUI_TYPE) {
3727 payload++;
3728 plen--;
3729 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
3730 return;
3731 }
3732#endif /* CONFIG_DPP */
3733
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003734 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3735 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003736 if (wpa_s->ifmsh)
3737 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003738}
3739
3740
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003741static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3742 union wpa_event_data *event)
3743{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003744 struct wpa_freq_range_list *list;
3745 char *str = NULL;
3746
3747 list = &event->freq_range;
3748
3749 if (list->num)
3750 str = freq_range_list_str(list);
3751 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3752 str ? str : "");
3753
3754#ifdef CONFIG_P2P
3755 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3756 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3757 __func__);
3758 } else {
3759 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003760
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003761 /*
3762 * The update channel flow will also take care of moving a GO
3763 * from the unsafe frequency if needed.
3764 */
3765 wpas_p2p_update_channel_list(wpa_s,
3766 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003767 }
3768#endif /* CONFIG_P2P */
3769
3770 os_free(str);
3771}
3772
3773
Roshan Pius3a1667e2018-07-03 15:17:14 -07003774static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003775{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003776 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3777 wpa_supplicant_cancel_auth_timeout(wpa_s);
3778 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3779 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3780 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3781 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003782}
3783
3784
3785static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
3786 int freq)
3787{
3788 size_t i;
3789 int j;
3790
3791 for (i = 0; i < wpa_s->hw.num_modes; i++) {
3792 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
3793
3794 for (j = 0; j < mode->num_channels; j++) {
3795 const struct hostapd_channel_data *chan;
3796
3797 chan = &mode->channels[j];
3798 if (chan->freq == freq)
3799 return chan->dfs_cac_ms;
3800 }
3801 }
3802
3803 return 0;
3804}
3805
3806
3807static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
3808 struct dfs_event *radar)
3809{
3810#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3811 if (wpa_s->ap_iface) {
3812 wpas_ap_event_dfs_cac_started(wpa_s, radar);
3813 } else
3814#endif /* NEED_AP_MLME && CONFIG_AP */
3815 {
3816 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
3817
3818 cac_time /= 1000; /* convert from ms to sec */
3819 if (!cac_time)
3820 cac_time = 10 * 60; /* max timeout: 10 minutes */
3821
3822 /* Restart auth timeout: CAC time added to initial timeout */
3823 wpas_auth_timeout_restart(wpa_s, cac_time);
3824 }
3825}
3826
3827
3828static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
3829 struct dfs_event *radar)
3830{
3831#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3832 if (wpa_s->ap_iface) {
3833 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
3834 } else
3835#endif /* NEED_AP_MLME && CONFIG_AP */
3836 {
3837 /* Restart auth timeout with original value after CAC is
3838 * finished */
3839 wpas_auth_timeout_restart(wpa_s, 0);
3840 }
3841}
3842
3843
3844static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
3845 struct dfs_event *radar)
3846{
3847#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3848 if (wpa_s->ap_iface) {
3849 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
3850 } else
3851#endif /* NEED_AP_MLME && CONFIG_AP */
3852 {
3853 /* Restart auth timeout with original value after CAC is
3854 * aborted */
3855 wpas_auth_timeout_restart(wpa_s, 0);
3856 }
3857}
3858
3859
3860static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3861 union wpa_event_data *data)
3862{
3863 wpa_dbg(wpa_s, MSG_DEBUG,
3864 "Connection authorized by device, previous state %d",
3865 wpa_s->wpa_state);
3866
3867 wpa_supplicant_event_port_authorized(wpa_s);
3868
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003869 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3870 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003871 data->assoc_info.ptk_kck_len,
3872 data->assoc_info.ptk_kek,
3873 data->assoc_info.ptk_kek_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003874#ifdef CONFIG_FILS
3875 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
3876 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
3877 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
3878
3879 /* Update ERP next sequence number */
3880 eapol_sm_update_erp_next_seq_num(
3881 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
3882
3883 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
3884 /* Add the new PMK and PMKID to the PMKSA cache */
3885 wpa_sm_pmksa_cache_add(wpa_s->wpa,
3886 data->assoc_info.fils_pmk,
3887 data->assoc_info.fils_pmk_len,
3888 data->assoc_info.fils_pmkid,
3889 wpa_s->bssid, fils_cache_id);
3890 } else if (data->assoc_info.fils_pmkid) {
3891 /* Update the current PMKSA used for this connection */
3892 pmksa_cache_set_current(wpa_s->wpa,
3893 data->assoc_info.fils_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003894 NULL, NULL, 0, NULL, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003895 }
3896 }
3897#endif /* CONFIG_FILS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003898}
3899
3900
Roshan Pius3a1667e2018-07-03 15:17:14 -07003901static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
3902 union wpa_event_data *data)
3903{
3904 const u8 *bssid = data->assoc_reject.bssid;
3905
3906 if (!bssid || is_zero_ether_addr(bssid))
3907 bssid = wpa_s->pending_bssid;
3908
3909 if (data->assoc_reject.bssid)
3910 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3911 "bssid=" MACSTR " status_code=%u%s%s%s",
3912 MAC2STR(data->assoc_reject.bssid),
3913 data->assoc_reject.status_code,
3914 data->assoc_reject.timed_out ? " timeout" : "",
3915 data->assoc_reject.timeout_reason ? "=" : "",
3916 data->assoc_reject.timeout_reason ?
3917 data->assoc_reject.timeout_reason : "");
3918 else
3919 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3920 "status_code=%u%s%s%s",
3921 data->assoc_reject.status_code,
3922 data->assoc_reject.timed_out ? " timeout" : "",
3923 data->assoc_reject.timeout_reason ? "=" : "",
3924 data->assoc_reject.timeout_reason ?
3925 data->assoc_reject.timeout_reason : "");
3926 wpa_s->assoc_status_code = data->assoc_reject.status_code;
3927 wpa_s->assoc_timed_out = data->assoc_reject.timed_out;
3928 wpas_notify_assoc_status_code(wpa_s);
3929
3930#ifdef CONFIG_OWE
3931 if (data->assoc_reject.status_code ==
3932 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
3933 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
3934 wpa_s->current_ssid &&
3935 wpa_s->current_ssid->owe_group == 0 &&
3936 wpa_s->last_owe_group != 21) {
3937 struct wpa_ssid *ssid = wpa_s->current_ssid;
3938 struct wpa_bss *bss = wpa_s->current_bss;
3939
3940 if (!bss) {
3941 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
3942 if (!bss) {
3943 wpas_connection_failed(wpa_s, bssid);
3944 wpa_supplicant_mark_disassoc(wpa_s);
3945 return;
3946 }
3947 }
3948 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
3949 wpas_connect_work_done(wpa_s);
3950 wpa_supplicant_mark_disassoc(wpa_s);
3951 wpa_supplicant_connect(wpa_s, bss, ssid);
3952 return;
3953 }
3954#endif /* CONFIG_OWE */
3955
3956 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
3957 sme_event_assoc_reject(wpa_s, data);
3958 return;
3959 }
3960
3961 /* Driver-based SME cases */
3962
3963#ifdef CONFIG_SAE
3964 if (wpa_s->current_ssid &&
3965 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
3966 !data->assoc_reject.timed_out) {
3967 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
3968 wpa_sm_aborted_cached(wpa_s->wpa);
3969 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
3970 }
3971#endif /* CONFIG_SAE */
3972
3973#ifdef CONFIG_FILS
3974 /* Update ERP next sequence number */
Hai Shalomce48b4a2018-09-05 11:41:35 -07003975 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003976 eapol_sm_update_erp_next_seq_num(
3977 wpa_s->eapol,
3978 data->assoc_reject.fils_erp_next_seq_num);
Hai Shalomce48b4a2018-09-05 11:41:35 -07003979 fils_connection_failure(wpa_s);
3980 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003981#endif /* CONFIG_FILS */
3982
3983 wpas_connection_failed(wpa_s, bssid);
3984 wpa_supplicant_mark_disassoc(wpa_s);
3985}
3986
3987
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003988void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3989 union wpa_event_data *data)
3990{
3991 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07003992 int resched;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003993
3994 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3995 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003996 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08003997 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003998 event != EVENT_SCHED_SCAN_STOPPED) {
3999 wpa_dbg(wpa_s, MSG_DEBUG,
4000 "Ignore event %s (%d) while interface is disabled",
4001 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004002 return;
4003 }
4004
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004005#ifndef CONFIG_NO_STDOUT_DEBUG
4006{
4007 int level = MSG_DEBUG;
4008
Dmitry Shmidt04949592012-07-19 12:16:46 -07004009 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004010 const struct ieee80211_hdr *hdr;
4011 u16 fc;
4012 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4013 fc = le_to_host16(hdr->frame_control);
4014 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4015 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4016 level = MSG_EXCESSIVE;
4017 }
4018
4019 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4020 event_to_string(event), event);
4021}
4022#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004023
4024 switch (event) {
4025 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004026#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08004027 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4028 data->auth.ies_len))
4029 wpa_printf(MSG_DEBUG,
4030 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004031#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004032 sme_event_auth(wpa_s, data);
4033 break;
4034 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004035#ifdef CONFIG_TESTING_OPTIONS
4036 if (wpa_s->ignore_auth_resp) {
4037 wpa_printf(MSG_INFO,
4038 "EVENT_ASSOC - ignore_auth_resp active!");
4039 break;
4040 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004041 if (wpa_s->testing_resend_assoc) {
4042 wpa_printf(MSG_INFO,
4043 "EVENT_DEAUTH - testing_resend_assoc");
4044 break;
4045 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004046#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004047 wpa_supplicant_event_assoc(wpa_s, data);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004048 if (data &&
4049 (data->assoc_info.authorized ||
4050 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4051 wpa_fils_is_completed(wpa_s->wpa))))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004052 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08004053 if (data) {
4054 wpa_msg(wpa_s, MSG_INFO,
4055 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4056 data->assoc_info.subnet_status);
4057 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004058 break;
4059 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004060 wpas_event_disassoc(wpa_s,
4061 data ? &data->disassoc_info : NULL);
4062 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004063 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004064#ifdef CONFIG_TESTING_OPTIONS
4065 if (wpa_s->ignore_auth_resp) {
4066 wpa_printf(MSG_INFO,
4067 "EVENT_DEAUTH - ignore_auth_resp active!");
4068 break;
4069 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004070 if (wpa_s->testing_resend_assoc) {
4071 wpa_printf(MSG_INFO,
4072 "EVENT_DEAUTH - testing_resend_assoc");
4073 break;
4074 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004075#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004076 wpas_event_deauth(wpa_s,
4077 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004078 break;
4079 case EVENT_MICHAEL_MIC_FAILURE:
4080 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4081 break;
4082#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004083 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004084 if (wpa_s->own_scan_requested ||
4085 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004086 struct os_reltime diff;
4087
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004088 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004089 os_reltime_sub(&wpa_s->scan_start_time,
4090 &wpa_s->scan_trigger_time, &diff);
4091 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4092 diff.sec, diff.usec);
4093 wpa_s->own_scan_requested = 0;
4094 wpa_s->own_scan_running = 1;
4095 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4096 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004097 wpa_msg_ctrl(wpa_s, MSG_INFO,
4098 WPA_EVENT_SCAN_STARTED "id=%u",
4099 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004100 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004101 wpa_msg_ctrl(wpa_s, MSG_INFO,
4102 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004103 }
4104 } else {
4105 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004106 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004107 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004108 }
4109 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004110 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004111 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4112 wpa_s->scan_res_handler = NULL;
4113 wpa_s->own_scan_running = 0;
4114 wpa_s->radio->external_scan_running = 0;
4115 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4116 break;
4117 }
4118
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004119 if (!(data && data->scan_info.external_scan) &&
4120 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004121 struct os_reltime now, diff;
4122 os_get_reltime(&now);
4123 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4124 wpa_s->scan_start_time.sec = 0;
4125 wpa_s->scan_start_time.usec = 0;
4126 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4127 diff.sec, diff.usec);
4128 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004129 if (wpa_supplicant_event_scan_results(wpa_s, data))
4130 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004131 if (!(data && data->scan_info.external_scan))
4132 wpa_s->own_scan_running = 0;
4133 if (data && data->scan_info.nl_scan_event)
4134 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004135 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004136 break;
4137#endif /* CONFIG_NO_SCAN_PROCESSING */
4138 case EVENT_ASSOCINFO:
4139 wpa_supplicant_event_associnfo(wpa_s, data);
4140 break;
4141 case EVENT_INTERFACE_STATUS:
4142 wpa_supplicant_event_interface_status(wpa_s, data);
4143 break;
4144 case EVENT_PMKID_CANDIDATE:
4145 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4146 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004147#ifdef CONFIG_TDLS
4148 case EVENT_TDLS:
4149 wpa_supplicant_event_tdls(wpa_s, data);
4150 break;
4151#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004152#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004153 case EVENT_WNM:
4154 wpa_supplicant_event_wnm(wpa_s, data);
4155 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004156#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004157#ifdef CONFIG_IEEE80211R
4158 case EVENT_FT_RESPONSE:
4159 wpa_supplicant_event_ft_response(wpa_s, data);
4160 break;
4161#endif /* CONFIG_IEEE80211R */
4162#ifdef CONFIG_IBSS_RSN
4163 case EVENT_IBSS_RSN_START:
4164 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4165 break;
4166#endif /* CONFIG_IBSS_RSN */
4167 case EVENT_ASSOC_REJECT:
Roshan Pius3a1667e2018-07-03 15:17:14 -07004168 wpas_event_assoc_reject(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004169 break;
4170 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004171 /* It is possible to get this event from earlier connection */
4172 if (wpa_s->current_ssid &&
4173 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4174 wpa_dbg(wpa_s, MSG_DEBUG,
4175 "Ignore AUTH_TIMED_OUT in mesh configuration");
4176 break;
4177 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004178 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4179 sme_event_auth_timed_out(wpa_s, data);
4180 break;
4181 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004182 /* It is possible to get this event from earlier connection */
4183 if (wpa_s->current_ssid &&
4184 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4185 wpa_dbg(wpa_s, MSG_DEBUG,
4186 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4187 break;
4188 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004189 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4190 sme_event_assoc_timed_out(wpa_s, data);
4191 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004192 case EVENT_TX_STATUS:
4193 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4194 " type=%d stype=%d",
4195 MAC2STR(data->tx_status.dst),
4196 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004197#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004198 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004199#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004200 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4201 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004202 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004203 wpa_s, data->tx_status.dst,
4204 data->tx_status.data,
4205 data->tx_status.data_len,
4206 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004207 OFFCHANNEL_SEND_ACTION_SUCCESS :
4208 OFFCHANNEL_SEND_ACTION_NO_ACK);
4209#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004210 break;
4211 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004212#endif /* CONFIG_AP */
4213#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004214 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004215 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004216 /*
4217 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004218 * interface in GO mode, or via standalone AP interface.
4219 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4220 * except when the primary interface is used as a GO interface
4221 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004222 */
4223 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4224 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004225 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004226 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004227 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004228 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004229 data->tx_status.data,
4230 data->tx_status.data_len,
4231 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004232 OFFCHANNEL_SEND_ACTION_SUCCESS :
4233 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004234 break;
4235 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004236#endif /* CONFIG_OFFCHANNEL */
4237#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004238 switch (data->tx_status.type) {
4239 case WLAN_FC_TYPE_MGMT:
4240 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4241 data->tx_status.data_len,
4242 data->tx_status.stype,
4243 data->tx_status.ack);
4244 break;
4245 case WLAN_FC_TYPE_DATA:
4246 ap_tx_status(wpa_s, data->tx_status.dst,
4247 data->tx_status.data,
4248 data->tx_status.data_len,
4249 data->tx_status.ack);
4250 break;
4251 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004252#endif /* CONFIG_AP */
4253 break;
4254#ifdef CONFIG_AP
4255 case EVENT_EAPOL_TX_STATUS:
4256 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4257 data->eapol_tx_status.data,
4258 data->eapol_tx_status.data_len,
4259 data->eapol_tx_status.ack);
4260 break;
4261 case EVENT_DRIVER_CLIENT_POLL_OK:
4262 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004263 break;
4264 case EVENT_RX_FROM_UNKNOWN:
4265 if (wpa_s->ap_iface == NULL)
4266 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004267 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4268 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004269 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004270#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004271 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004272 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004273 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004274
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004275 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
4276 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4277 data->ch_switch.freq,
4278 data->ch_switch.ht_enabled,
4279 data->ch_switch.ch_offset,
4280 channel_width_to_string(data->ch_switch.ch_width),
4281 data->ch_switch.cf1,
4282 data->ch_switch.cf2);
4283
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004284 wpa_s->assoc_freq = data->ch_switch.freq;
4285 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4286
Roshan Pius3a1667e2018-07-03 15:17:14 -07004287#ifdef CONFIG_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004288 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4289 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
4290 wpa_s->current_ssid->mode ==
4291 WPAS_MODE_P2P_GROUP_FORMATION) {
4292 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4293 data->ch_switch.ht_enabled,
4294 data->ch_switch.ch_offset,
4295 data->ch_switch.ch_width,
4296 data->ch_switch.cf1,
4297 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004298 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07004299#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004300
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004301 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004302 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004303#ifdef CONFIG_AP
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004304#ifdef NEED_AP_MLME
4305 case EVENT_DFS_RADAR_DETECTED:
4306 if (data)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004307 wpas_ap_event_dfs_radar_detected(wpa_s,
4308 &data->dfs_event);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004309 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004310 case EVENT_DFS_NOP_FINISHED:
4311 if (data)
4312 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
4313 &data->dfs_event);
4314 break;
4315#endif /* NEED_AP_MLME */
4316#endif /* CONFIG_AP */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004317 case EVENT_DFS_CAC_STARTED:
4318 if (data)
4319 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
4320 break;
4321 case EVENT_DFS_CAC_FINISHED:
4322 if (data)
4323 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
4324 break;
4325 case EVENT_DFS_CAC_ABORTED:
4326 if (data)
4327 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
4328 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004329 case EVENT_RX_MGMT: {
4330 u16 fc, stype;
4331 const struct ieee80211_mgmt *mgmt;
4332
Dmitry Shmidt818ea482014-03-10 13:15:21 -07004333#ifdef CONFIG_TESTING_OPTIONS
4334 if (wpa_s->ext_mgmt_frame_handling) {
4335 struct rx_mgmt *rx = &data->rx_mgmt;
4336 size_t hex_len = 2 * rx->frame_len + 1;
4337 char *hex = os_malloc(hex_len);
4338 if (hex) {
4339 wpa_snprintf_hex(hex, hex_len,
4340 rx->frame, rx->frame_len);
4341 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4342 rx->freq, rx->datarate, rx->ssi_signal,
4343 hex);
4344 os_free(hex);
4345 }
4346 break;
4347 }
4348#endif /* CONFIG_TESTING_OPTIONS */
4349
Dmitry Shmidt04949592012-07-19 12:16:46 -07004350 mgmt = (const struct ieee80211_mgmt *)
4351 data->rx_mgmt.frame;
4352 fc = le_to_host16(mgmt->frame_control);
4353 stype = WLAN_FC_GET_STYPE(fc);
4354
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004355#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004356 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004357#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004358#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004359 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004360 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004361 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07004362 const u8 *ie;
4363 size_t ie_len;
4364
4365 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4366 ie_len = data->rx_mgmt.frame_len -
4367 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004368 wpas_p2p_probe_req_rx(
4369 wpa_s, src, mgmt->da,
4370 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004371 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004372 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004373 break;
4374 }
4375#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004376#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004377 if (wpa_s->current_ssid &&
4378 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4379 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004380 data->rx_mgmt.frame_len >= 30) {
4381 wpa_supplicant_event_ibss_auth(wpa_s, data);
4382 break;
4383 }
4384#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004385
4386 if (stype == WLAN_FC_STYPE_ACTION) {
4387 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07004388 wpa_s, data->rx_mgmt.frame,
4389 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004390 data->rx_mgmt.freq,
4391 data->rx_mgmt.ssi_signal);
4392 break;
4393 }
4394
4395 if (wpa_s->ifmsh) {
4396 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004397 break;
4398 }
4399
Roshan Pius3a1667e2018-07-03 15:17:14 -07004400#ifdef CONFIG_SAE
4401 if (stype == WLAN_FC_STYPE_AUTH &&
4402 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4403 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4404 sme_external_auth_mgmt_rx(
4405 wpa_s, data->rx_mgmt.frame,
4406 data->rx_mgmt.frame_len);
4407 break;
4408 }
4409#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004410 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
4411 "management frame in non-AP mode");
4412 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004413#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004414 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004415
4416 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07004417 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4418 const u8 *ie;
4419 size_t ie_len;
4420
4421 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4422 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004423
4424 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
4425 mgmt->bssid, ie, ie_len,
4426 data->rx_mgmt.ssi_signal);
4427 }
4428
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004429 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004430#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004431 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004432 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004433 case EVENT_RX_PROBE_REQ:
4434 if (data->rx_probe_req.sa == NULL ||
4435 data->rx_probe_req.ie == NULL)
4436 break;
4437#ifdef CONFIG_AP
4438 if (wpa_s->ap_iface) {
4439 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
4440 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004441 data->rx_probe_req.da,
4442 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004443 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004444 data->rx_probe_req.ie_len,
4445 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004446 break;
4447 }
4448#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004449 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004450 data->rx_probe_req.da,
4451 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004452 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004453 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07004454 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004455 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004456 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004457 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004458#ifdef CONFIG_OFFCHANNEL
4459 offchannel_remain_on_channel_cb(
4460 wpa_s, data->remain_on_channel.freq,
4461 data->remain_on_channel.duration);
4462#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004463 wpas_p2p_remain_on_channel_cb(
4464 wpa_s, data->remain_on_channel.freq,
4465 data->remain_on_channel.duration);
4466 break;
4467 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004468#ifdef CONFIG_OFFCHANNEL
4469 offchannel_cancel_remain_on_channel_cb(
4470 wpa_s, data->remain_on_channel.freq);
4471#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004472 wpas_p2p_cancel_remain_on_channel_cb(
4473 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004474#ifdef CONFIG_DPP
4475 wpas_dpp_cancel_remain_on_channel_cb(
4476 wpa_s, data->remain_on_channel.freq);
4477#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004478 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004479 case EVENT_EAPOL_RX:
4480 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
4481 data->eapol_rx.data,
4482 data->eapol_rx.data_len);
4483 break;
4484 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004485 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
4486 "above=%d signal=%d noise=%d txrate=%d",
4487 data->signal_change.above_threshold,
4488 data->signal_change.current_signal,
4489 data->signal_change.current_noise,
4490 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004491 wpa_bss_update_level(wpa_s->current_bss,
4492 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004493 bgscan_notify_signal_change(
4494 wpa_s, data->signal_change.above_threshold,
4495 data->signal_change.current_signal,
4496 data->signal_change.current_noise,
4497 data->signal_change.current_txrate);
4498 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004499 case EVENT_INTERFACE_MAC_CHANGED:
4500 wpa_supplicant_update_mac_addr(wpa_s);
4501 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004502 case EVENT_INTERFACE_ENABLED:
4503 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
4504 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004505 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004506 if (wpa_s->p2p_mgmt) {
4507 wpa_supplicant_set_state(wpa_s,
4508 WPA_DISCONNECTED);
4509 break;
4510 }
4511
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004512#ifdef CONFIG_AP
4513 if (!wpa_s->ap_iface) {
4514 wpa_supplicant_set_state(wpa_s,
4515 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004516 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004517 wpa_supplicant_req_scan(wpa_s, 0, 0);
4518 } else
4519 wpa_supplicant_set_state(wpa_s,
4520 WPA_COMPLETED);
4521#else /* CONFIG_AP */
4522 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
4523 wpa_supplicant_req_scan(wpa_s, 0, 0);
4524#endif /* CONFIG_AP */
4525 }
4526 break;
4527 case EVENT_INTERFACE_DISABLED:
4528 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004529#ifdef CONFIG_P2P
4530 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
4531 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
4532 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
4533 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004534 * Mark interface disabled if this happens to end up not
4535 * being removed as a separate P2P group interface.
4536 */
4537 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4538 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004539 * The interface was externally disabled. Remove
4540 * it assuming an external entity will start a
4541 * new session if needed.
4542 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004543 if (wpa_s->current_ssid &&
4544 wpa_s->current_ssid->p2p_group)
4545 wpas_p2p_interface_unavailable(wpa_s);
4546 else
4547 wpas_p2p_disconnect(wpa_s);
4548 /*
4549 * wpa_s instance may have been freed, so must not use
4550 * it here anymore.
4551 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004552 break;
4553 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07004554 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
4555 p2p_in_progress(wpa_s->global->p2p) > 1) {
4556 /* This radio work will be cancelled, so clear P2P
4557 * state as well.
4558 */
4559 p2p_stop_find(wpa_s->global->p2p);
4560 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08004561#endif /* CONFIG_P2P */
4562
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004563 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4564 /*
4565 * Indicate disconnection to keep ctrl_iface events
4566 * consistent.
4567 */
4568 wpa_supplicant_event_disassoc(
4569 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
4570 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004571 wpa_supplicant_mark_disassoc(wpa_s);
xshud0ee72f2018-11-08 14:37:01 -08004572 if (!wpa_s->conf->bss_no_flush_when_down)
4573 wpa_bss_flush(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08004574 radio_remove_works(wpa_s, NULL, 0);
4575
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004576 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4577 break;
4578 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07004579 wpa_supplicant_update_channel_list(
4580 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004581 break;
4582 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004583 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004584 break;
4585 case EVENT_BEST_CHANNEL:
4586 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
4587 "(%d %d %d)",
4588 data->best_chan.freq_24, data->best_chan.freq_5,
4589 data->best_chan.freq_overall);
4590 wpa_s->best_24_freq = data->best_chan.freq_24;
4591 wpa_s->best_5_freq = data->best_chan.freq_5;
4592 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004593 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
4594 data->best_chan.freq_5,
4595 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004596 break;
4597 case EVENT_UNPROT_DEAUTH:
4598 wpa_supplicant_event_unprot_deauth(wpa_s,
4599 &data->unprot_deauth);
4600 break;
4601 case EVENT_UNPROT_DISASSOC:
4602 wpa_supplicant_event_unprot_disassoc(wpa_s,
4603 &data->unprot_disassoc);
4604 break;
4605 case EVENT_STATION_LOW_ACK:
4606#ifdef CONFIG_AP
4607 if (wpa_s->ap_iface && data)
4608 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
4609 data->low_ack.addr);
4610#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004611#ifdef CONFIG_TDLS
4612 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07004613 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
4614 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004615#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004616 break;
4617 case EVENT_IBSS_PEER_LOST:
4618#ifdef CONFIG_IBSS_RSN
4619 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
4620#endif /* CONFIG_IBSS_RSN */
4621 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004622 case EVENT_DRIVER_GTK_REKEY:
4623 if (os_memcmp(data->driver_gtk_rekey.bssid,
4624 wpa_s->bssid, ETH_ALEN))
4625 break;
4626 if (!wpa_s->wpa)
4627 break;
4628 wpa_sm_update_replay_ctr(wpa_s->wpa,
4629 data->driver_gtk_rekey.replay_ctr);
4630 break;
4631 case EVENT_SCHED_SCAN_STOPPED:
4632 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004633 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004634 wpa_supplicant_notify_scanning(wpa_s, 0);
4635
4636 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4637 break;
4638
4639 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004640 * If the driver stopped scanning without being requested to,
4641 * request a new scan to continue scanning for networks.
4642 */
4643 if (!wpa_s->sched_scan_stop_req &&
4644 wpa_s->wpa_state == WPA_SCANNING) {
4645 wpa_dbg(wpa_s, MSG_DEBUG,
4646 "Restart scanning after unexpected sched_scan stop event");
4647 wpa_supplicant_req_scan(wpa_s, 1, 0);
4648 break;
4649 }
4650
4651 wpa_s->sched_scan_stop_req = 0;
4652
4653 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08004654 * Start a new sched scan to continue searching for more SSIDs
4655 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004656 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07004657 if (wpa_s->sched_scan_timed_out) {
4658 wpa_supplicant_req_sched_scan(wpa_s);
4659 } else if (wpa_s->pno_sched_pending) {
4660 wpa_s->pno_sched_pending = 0;
4661 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004662 } else if (resched) {
4663 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08004664 }
4665
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004666 break;
4667 case EVENT_WPS_BUTTON_PUSHED:
4668#ifdef CONFIG_WPS
4669 wpas_wps_start_pbc(wpa_s, NULL, 0);
4670#endif /* CONFIG_WPS */
4671 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004672 case EVENT_AVOID_FREQUENCIES:
4673 wpa_supplicant_notify_avoid_freq(wpa_s, data);
4674 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004675 case EVENT_CONNECT_FAILED_REASON:
4676#ifdef CONFIG_AP
4677 if (!wpa_s->ap_iface || !data)
4678 break;
4679 hostapd_event_connect_failed_reason(
4680 wpa_s->ap_iface->bss[0],
4681 data->connect_failed_reason.addr,
4682 data->connect_failed_reason.code);
4683#endif /* CONFIG_AP */
4684 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004685 case EVENT_NEW_PEER_CANDIDATE:
4686#ifdef CONFIG_MESH
4687 if (!wpa_s->ifmsh || !data)
4688 break;
4689 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4690 data->mesh_peer.ies,
4691 data->mesh_peer.ie_len);
4692#endif /* CONFIG_MESH */
4693 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004694 case EVENT_SURVEY:
4695#ifdef CONFIG_AP
4696 if (!wpa_s->ap_iface)
4697 break;
4698 hostapd_event_get_survey(wpa_s->ap_iface,
4699 &data->survey_results);
4700#endif /* CONFIG_AP */
4701 break;
4702 case EVENT_ACS_CHANNEL_SELECTED:
Paul Stewart092955c2017-02-06 09:13:09 -08004703#ifdef CONFIG_AP
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004704#ifdef CONFIG_ACS
4705 if (!wpa_s->ap_iface)
4706 break;
4707 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4708 &data->acs_selected_channels);
4709#endif /* CONFIG_ACS */
Paul Stewart092955c2017-02-06 09:13:09 -08004710#endif /* CONFIG_AP */
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004711 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004712 case EVENT_P2P_LO_STOP:
4713#ifdef CONFIG_P2P
4714 wpa_s->p2p_lo_started = 0;
4715 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
4716 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
4717 data->p2p_lo_stop.reason_code);
4718#endif /* CONFIG_P2P */
4719 break;
Paul Stewart092955c2017-02-06 09:13:09 -08004720 case EVENT_BEACON_LOSS:
4721 if (!wpa_s->current_bss || !wpa_s->current_ssid)
4722 break;
4723 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
4724 bgscan_notify_beacon_loss(wpa_s);
4725 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004726 case EVENT_EXTERNAL_AUTH:
4727#ifdef CONFIG_SAE
4728 if (!wpa_s->current_ssid) {
4729 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
4730 break;
4731 }
4732 sme_external_auth_trigger(wpa_s, data);
4733#endif /* CONFIG_SAE */
4734 break;
4735 case EVENT_PORT_AUTHORIZED:
4736 wpa_supplicant_event_port_authorized(wpa_s);
4737 break;
4738 case EVENT_STATION_OPMODE_CHANGED:
4739#ifdef CONFIG_AP
4740 if (!wpa_s->ap_iface || !data)
4741 break;
4742
4743 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
4744 data->sta_opmode.addr,
4745 data->sta_opmode.smps_mode,
4746 data->sta_opmode.chan_width,
4747 data->sta_opmode.rx_nss);
4748#endif /* CONFIG_AP */
4749 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004750 default:
4751 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4752 break;
4753 }
4754}
Dmitry Shmidte4663042016-04-04 10:07:49 -07004755
4756
4757void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
4758 union wpa_event_data *data)
4759{
4760 struct wpa_supplicant *wpa_s;
4761
4762 if (event != EVENT_INTERFACE_STATUS)
4763 return;
4764
4765 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
4766 if (wpa_s && wpa_s->driver->get_ifindex) {
4767 unsigned int ifindex;
4768
4769 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
4770 if (ifindex != data->interface_status.ifindex) {
4771 wpa_dbg(wpa_s, MSG_DEBUG,
4772 "interface status ifindex %d mismatch (%d)",
4773 ifindex, data->interface_status.ifindex);
4774 return;
4775 }
4776 }
4777#ifdef CONFIG_MATCH_IFACE
4778 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
4779 struct wpa_interface *wpa_i;
4780
4781 wpa_i = wpa_supplicant_match_iface(
4782 ctx, data->interface_status.ifname);
4783 if (!wpa_i)
4784 return;
4785 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
4786 os_free(wpa_i);
4787 if (wpa_s)
4788 wpa_s->matched = 1;
4789 }
4790#endif /* CONFIG_MATCH_IFACE */
4791
4792 if (wpa_s)
4793 wpa_supplicant_event(wpa_s, event, data);
4794}