blob: 6f8fc8117f1a2a288a8cf505fec72a319a103a7a [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2003-2015, 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"
31#include "crypto/random.h"
32#include "blacklist.h"
33#include "wpas_glue.h"
34#include "wps_supplicant.h"
35#include "ibss_rsn.h"
36#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080037#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#include "p2p_supplicant.h"
39#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070040#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "ap.h"
42#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080044#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070045#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080046#include "mesh.h"
47#include "mesh_mpm.h"
48#include "wmm_ac.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070049
50
Dmitry Shmidt34af3062013-07-11 10:46:32 -070051#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070052static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080053 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070054#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080055
56
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070057static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
58 struct wpa_ssid *ssid)
59{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080060 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070061
62 if (ssid == NULL || ssid->disabled_until.sec == 0)
63 return 0;
64
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080065 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066 if (ssid->disabled_until.sec > now.sec)
67 return ssid->disabled_until.sec - now.sec;
68
69 wpas_clear_temp_disabled(wpa_s, ssid, 0);
70
71 return 0;
72}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070073
74
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080075#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070076/**
77 * wpas_reenabled_network_time - Time until first network is re-enabled
78 * @wpa_s: Pointer to wpa_supplicant data
79 * Returns: If all enabled networks are temporarily disabled, returns the time
80 * (in sec) until the first network is re-enabled. Otherwise returns 0.
81 *
82 * This function is used in case all enabled networks are temporarily disabled,
83 * in which case it returns the time (in sec) that the first network will be
84 * re-enabled. The function assumes that at least one network is enabled.
85 */
86static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
87{
88 struct wpa_ssid *ssid;
89 int disabled_for, res = 0;
90
91#ifdef CONFIG_INTERWORKING
92 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
93 wpa_s->conf->cred)
94 return 0;
95#endif /* CONFIG_INTERWORKING */
96
97 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
98 if (ssid->disabled)
99 continue;
100
101 disabled_for = wpas_temp_disabled(wpa_s, ssid);
102 if (!disabled_for)
103 return 0;
104
105 if (!res || disabled_for < res)
106 res = disabled_for;
107 }
108
109 return res;
110}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800111#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700112
113
114void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
115{
116 struct wpa_supplicant *wpa_s = eloop_ctx;
117
118 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
119 return;
120
121 wpa_dbg(wpa_s, MSG_DEBUG,
122 "Try to associate due to network getting re-enabled");
123 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
124 wpa_supplicant_cancel_sched_scan(wpa_s);
125 wpa_supplicant_req_scan(wpa_s, 0, 0);
126 }
127}
128
129
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800130static struct wpa_bss * wpa_supplicant_get_new_bss(
131 struct wpa_supplicant *wpa_s, const u8 *bssid)
132{
133 struct wpa_bss *bss = NULL;
134 struct wpa_ssid *ssid = wpa_s->current_ssid;
135
136 if (ssid->ssid_len > 0)
137 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
138 if (!bss)
139 bss = wpa_bss_get_bssid(wpa_s, bssid);
140
141 return bss;
142}
143
144
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700145static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
146{
147 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
148
149 if (!bss) {
150 wpa_supplicant_update_scan_results(wpa_s);
151
152 /* Get the BSS from the new scan results */
153 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
154 }
155
156 if (bss)
157 wpa_s->current_bss = bss;
158}
159
160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
162{
163 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700164 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700165 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700166 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700168 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
169 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700170
171 if (wpa_s->current_ssid->ssid_len == 0)
172 return 0; /* current profile still in use */
173 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
174 if (res < 0) {
175 wpa_msg(wpa_s, MSG_INFO,
176 "Failed to read SSID from driver");
177 return 0; /* try to use current profile */
178 }
179 drv_ssid_len = res;
180
181 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
182 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
183 drv_ssid_len) == 0)
184 return 0; /* current profile still in use */
185
186 wpa_msg(wpa_s, MSG_DEBUG,
187 "Driver-initiated BSS selection changed the SSID to %s",
188 wpa_ssid_txt(drv_ssid, drv_ssid_len));
189 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700190 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191
192 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
193 "information");
194 ssid = wpa_supplicant_get_ssid(wpa_s);
195 if (ssid == NULL) {
196 wpa_msg(wpa_s, MSG_INFO,
197 "No network configuration found for the current AP");
198 return -1;
199 }
200
Dmitry Shmidt04949592012-07-19 12:16:46 -0700201 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
203 return -1;
204 }
205
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800206 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
207 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
208 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
209 return -1;
210 }
211
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700212 res = wpas_temp_disabled(wpa_s, ssid);
213 if (res > 0) {
214 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
215 "disabled for %d second(s)", res);
216 return -1;
217 }
218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
220 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800221 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 u8 wpa_ie[80];
223 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800224 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
225 wpa_ie, &wpa_ie_len) < 0)
226 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227 } else {
228 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
229 }
230
231 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
232 eapol_sm_invalidate_cached_session(wpa_s->eapol);
233 old_ssid = wpa_s->current_ssid;
234 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800235
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700236 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800237
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
239 wpa_supplicant_initiate_eapol(wpa_s);
240 if (old_ssid != wpa_s->current_ssid)
241 wpas_notify_network_changed(wpa_s);
242
243 return 0;
244}
245
246
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800247void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248{
249 struct wpa_supplicant *wpa_s = eloop_ctx;
250
251 if (wpa_s->countermeasures) {
252 wpa_s->countermeasures = 0;
253 wpa_drv_set_countermeasures(wpa_s, 0);
254 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800255
256 /*
257 * It is possible that the device is sched scanning, which means
258 * that a connection attempt will be done only when we receive
259 * scan results. However, in this case, it would be preferable
260 * to scan and connect immediately, so cancel the sched_scan and
261 * issue a regular scan flow.
262 */
263 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264 wpa_supplicant_req_scan(wpa_s, 0, 0);
265 }
266}
267
268
269void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
270{
271 int bssid_changed;
272
Dmitry Shmidt04949592012-07-19 12:16:46 -0700273 wnm_bss_keep_alive_deinit(wpa_s);
274
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275#ifdef CONFIG_IBSS_RSN
276 ibss_rsn_deinit(wpa_s->ibss_rsn);
277 wpa_s->ibss_rsn = NULL;
278#endif /* CONFIG_IBSS_RSN */
279
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700280#ifdef CONFIG_AP
281 wpa_supplicant_ap_deinit(wpa_s);
282#endif /* CONFIG_AP */
283
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700284#ifdef CONFIG_HS20
285 /* Clear possibly configured frame filters */
286 wpa_drv_configure_frame_filters(wpa_s, 0);
287#endif /* CONFIG_HS20 */
288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
290 return;
291
292 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
293 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
294 os_memset(wpa_s->bssid, 0, ETH_ALEN);
295 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800296 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297 wpa_s->current_bss = NULL;
298 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700299
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300 if (bssid_changed)
301 wpas_notify_bssid_changed(wpa_s);
302
303 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
304 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
305 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
306 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
307 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700308 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700309 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700310 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800311
312 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800313 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314}
315
316
317static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
318{
319 struct wpa_ie_data ie;
320 int pmksa_set = -1;
321 size_t i;
322
323 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
324 ie.pmkid == NULL)
325 return;
326
327 for (i = 0; i < ie.num_pmkid; i++) {
328 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
329 ie.pmkid + i * PMKID_LEN,
330 NULL, NULL, 0);
331 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800332 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333 break;
334 }
335 }
336
337 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
338 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
339}
340
341
342static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
343 union wpa_event_data *data)
344{
345 if (data == NULL) {
346 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
347 "event");
348 return;
349 }
350 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
351 " index=%d preauth=%d",
352 MAC2STR(data->pmkid_candidate.bssid),
353 data->pmkid_candidate.index,
354 data->pmkid_candidate.preauth);
355
356 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
357 data->pmkid_candidate.index,
358 data->pmkid_candidate.preauth);
359}
360
361
362static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
363{
364 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
365 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
366 return 0;
367
368#ifdef IEEE8021X_EAPOL
369 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
370 wpa_s->current_ssid &&
371 !(wpa_s->current_ssid->eapol_flags &
372 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
373 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
374 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
375 * plaintext or static WEP keys). */
376 return 0;
377 }
378#endif /* IEEE8021X_EAPOL */
379
380 return 1;
381}
382
383
384/**
385 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
386 * @wpa_s: pointer to wpa_supplicant data
387 * @ssid: Configuration data for the network
388 * Returns: 0 on success, -1 on failure
389 *
390 * This function is called when starting authentication with a network that is
391 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
392 */
393int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
394 struct wpa_ssid *ssid)
395{
396#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800397#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700398 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700399
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700400 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
401 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700402 return 0;
403
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700404 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405 sim = 1;
406 aka = 1;
407 } else {
408 struct eap_method_type *eap = ssid->eap.eap_methods;
409 while (eap->vendor != EAP_VENDOR_IETF ||
410 eap->method != EAP_TYPE_NONE) {
411 if (eap->vendor == EAP_VENDOR_IETF) {
412 if (eap->method == EAP_TYPE_SIM)
413 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700414 else if (eap->method == EAP_TYPE_AKA ||
415 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416 aka = 1;
417 }
418 eap++;
419 }
420 }
421
422 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
423 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700424 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
425 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
426 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427 aka = 0;
428
429 if (!sim && !aka) {
430 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
431 "use SIM, but neither EAP-SIM nor EAP-AKA are "
432 "enabled");
433 return 0;
434 }
435
436 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
437 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700439 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 if (wpa_s->scard == NULL) {
441 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
442 "(pcsc-lite)");
443 return -1;
444 }
445 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
446 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800447#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700448#endif /* IEEE8021X_EAPOL */
449
450 return 0;
451}
452
453
454#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700455
456static int has_wep_key(struct wpa_ssid *ssid)
457{
458 int i;
459
460 for (i = 0; i < NUM_WEP_KEYS; i++) {
461 if (ssid->wep_key_len[i])
462 return 1;
463 }
464
465 return 0;
466}
467
468
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700469static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470 struct wpa_ssid *ssid)
471{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700472 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473
474 if (ssid->mixed_cell)
475 return 1;
476
477#ifdef CONFIG_WPS
478 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
479 return 1;
480#endif /* CONFIG_WPS */
481
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700482 if (has_wep_key(ssid))
483 privacy = 1;
484
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485#ifdef IEEE8021X_EAPOL
486 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
487 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
488 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
489 privacy = 1;
490#endif /* IEEE8021X_EAPOL */
491
Jouni Malinen75ecf522011-06-27 15:19:46 -0700492 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
493 privacy = 1;
494
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800495 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
496 privacy = 1;
497
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498 if (bss->caps & IEEE80211_CAP_PRIVACY)
499 return privacy;
500 return !privacy;
501}
502
503
504static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
505 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700506 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507{
508 struct wpa_ie_data ie;
509 int proto_match = 0;
510 const u8 *rsn_ie, *wpa_ie;
511 int ret;
512 int wep_ok;
513
514 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
515 if (ret >= 0)
516 return ret;
517
518 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
519 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
520 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
521 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
522 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
523
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700524 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700525 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
526 proto_match++;
527
528 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
529 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
530 "failed");
531 break;
532 }
533
534 if (wep_ok &&
535 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
536 {
537 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
538 "in RSN IE");
539 return 1;
540 }
541
542 if (!(ie.proto & ssid->proto)) {
543 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
544 "mismatch");
545 break;
546 }
547
548 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
549 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
550 "cipher mismatch");
551 break;
552 }
553
554 if (!(ie.group_cipher & ssid->group_cipher)) {
555 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
556 "cipher mismatch");
557 break;
558 }
559
560 if (!(ie.key_mgmt & ssid->key_mgmt)) {
561 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
562 "mismatch");
563 break;
564 }
565
566#ifdef CONFIG_IEEE80211W
567 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800568 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800569 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
571 "frame protection");
572 break;
573 }
574#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800575 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
576 wpas_get_ssid_pmf(wpa_s, ssid) ==
577 NO_MGMT_FRAME_PROTECTION) {
578 wpa_dbg(wpa_s, MSG_DEBUG,
579 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
580 break;
581 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800582#ifdef CONFIG_MBO
583 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
584 wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
585 wpas_get_ssid_pmf(wpa_s, ssid) !=
586 NO_MGMT_FRAME_PROTECTION) {
587 wpa_dbg(wpa_s, MSG_DEBUG,
588 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
589 break;
590 }
591#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592
593 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
594 return 1;
595 }
596
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700597#ifdef CONFIG_IEEE80211W
598 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED) {
599 wpa_dbg(wpa_s, MSG_DEBUG,
600 " skip - MFP Required but network not MFP Capable");
601 return 0;
602 }
603#endif /* CONFIG_IEEE80211W */
604
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700605 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700606 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
607 proto_match++;
608
609 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
610 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
611 "failed");
612 break;
613 }
614
615 if (wep_ok &&
616 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
617 {
618 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
619 "in WPA IE");
620 return 1;
621 }
622
623 if (!(ie.proto & ssid->proto)) {
624 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
625 "mismatch");
626 break;
627 }
628
629 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
630 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
631 "cipher mismatch");
632 break;
633 }
634
635 if (!(ie.group_cipher & ssid->group_cipher)) {
636 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
637 "cipher mismatch");
638 break;
639 }
640
641 if (!(ie.key_mgmt & ssid->key_mgmt)) {
642 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
643 "mismatch");
644 break;
645 }
646
647 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
648 return 1;
649 }
650
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700651 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
652 !rsn_ie) {
653 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
654 return 1;
655 }
656
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700657 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
658 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
659 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
660 return 0;
661 }
662
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800663 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
664 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
665 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
666 return 1;
667 }
668
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700669 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
670 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
671 return 1;
672 }
673
674 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
675 "WPA/WPA2");
676
677 return 0;
678}
679
680
681static int freq_allowed(int *freqs, int freq)
682{
683 int i;
684
685 if (freqs == NULL)
686 return 1;
687
688 for (i = 0; freqs[i]; i++)
689 if (freqs[i] == freq)
690 return 1;
691 return 0;
692}
693
694
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700695static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800696{
697 const struct hostapd_hw_modes *mode = NULL, *modes;
698 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
699 const u8 *rate_ie;
700 int i, j, k;
701
702 if (bss->freq == 0)
703 return 1; /* Cannot do matching without knowing band */
704
705 modes = wpa_s->hw.modes;
706 if (modes == NULL) {
707 /*
708 * The driver does not provide any additional information
709 * about the utilized hardware, so allow the connection attempt
710 * to continue.
711 */
712 return 1;
713 }
714
715 for (i = 0; i < wpa_s->hw.num_modes; i++) {
716 for (j = 0; j < modes[i].num_channels; j++) {
717 int freq = modes[i].channels[j].freq;
718 if (freq == bss->freq) {
719 if (mode &&
720 mode->mode == HOSTAPD_MODE_IEEE80211G)
721 break; /* do not allow 802.11b replace
722 * 802.11g */
723 mode = &modes[i];
724 break;
725 }
726 }
727 }
728
729 if (mode == NULL)
730 return 0;
731
732 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700733 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800734 if (rate_ie == NULL)
735 continue;
736
737 for (j = 2; j < rate_ie[1] + 2; j++) {
738 int flagged = !!(rate_ie[j] & 0x80);
739 int r = (rate_ie[j] & 0x7f) * 5;
740
741 /*
742 * IEEE Std 802.11n-2009 7.3.2.2:
743 * The new BSS Membership selector value is encoded
744 * like a legacy basic rate, but it is not a rate and
745 * only indicates if the BSS members are required to
746 * support the mandatory features of Clause 20 [HT PHY]
747 * in order to join the BSS.
748 */
749 if (flagged && ((rate_ie[j] & 0x7f) ==
750 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
751 if (!ht_supported(mode)) {
752 wpa_dbg(wpa_s, MSG_DEBUG,
753 " hardware does not support "
754 "HT PHY");
755 return 0;
756 }
757 continue;
758 }
759
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700760 /* There's also a VHT selector for 802.11ac */
761 if (flagged && ((rate_ie[j] & 0x7f) ==
762 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
763 if (!vht_supported(mode)) {
764 wpa_dbg(wpa_s, MSG_DEBUG,
765 " hardware does not support "
766 "VHT PHY");
767 return 0;
768 }
769 continue;
770 }
771
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800772 if (!flagged)
773 continue;
774
775 /* check for legacy basic rates */
776 for (k = 0; k < mode->num_rates; k++) {
777 if (mode->rates[k] == r)
778 break;
779 }
780 if (k == mode->num_rates) {
781 /*
782 * IEEE Std 802.11-2007 7.3.2.2 demands that in
783 * order to join a BSS all required rates
784 * have to be supported by the hardware.
785 */
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -0700786 wpa_dbg(wpa_s, MSG_DEBUG,
787 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
788 r / 10, r % 10,
789 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800790 return 0;
791 }
792 }
793 }
794
795 return 1;
796}
797
798
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800799/*
800 * Test whether BSS is in an ESS.
801 * This is done differently in DMG (60 GHz) and non-DMG bands
802 */
803static int bss_is_ess(struct wpa_bss *bss)
804{
805 if (bss_is_dmg(bss)) {
806 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
807 IEEE80211_CAP_DMG_AP;
808 }
809
810 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
811 IEEE80211_CAP_ESS);
812}
813
814
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800815static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
816{
817 size_t i;
818
819 for (i = 0; i < ETH_ALEN; i++) {
820 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
821 return 0;
822 }
823 return 1;
824}
825
826
827static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
828{
829 size_t i;
830
831 for (i = 0; i < num; i++) {
832 const u8 *a = list + i * ETH_ALEN * 2;
833 const u8 *m = a + ETH_ALEN;
834
835 if (match_mac_mask(a, addr, m))
836 return 1;
837 }
838 return 0;
839}
840
841
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800842struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
843 int i, struct wpa_bss *bss,
844 struct wpa_ssid *group,
845 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700847 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700848 int wpa;
849 struct wpa_blacklist *e;
850 const u8 *ie;
851 struct wpa_ssid *ssid;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800852 int osen;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800853#ifdef CONFIG_MBO
854 const u8 *assoc_disallow;
855#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700857 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858 wpa_ie_len = ie ? ie[1] : 0;
859
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700860 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700861 rsn_ie_len = ie ? ie[1] : 0;
862
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800863 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
864 osen = ie != NULL;
865
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800867 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700868 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800869 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700870 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
871 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
872 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800873 " p2p" : "",
874 osen ? " osen=1" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700875
876 e = wpa_blacklist_get(wpa_s, bss->bssid);
877 if (e) {
878 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700879 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880 /*
881 * When only a single network is enabled, we can
882 * trigger blacklisting on the first failure. This
883 * should not be done with multiple enabled networks to
884 * avoid getting forced to move into a worse ESS on
885 * single error if there are no other BSSes of the
886 * current ESS.
887 */
888 limit = 0;
889 }
890 if (e->count > limit) {
891 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
892 "(count=%d limit=%d)", e->count, limit);
893 return NULL;
894 }
895 }
896
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700897 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
899 return NULL;
900 }
901
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800902 if (disallowed_bssid(wpa_s, bss->bssid)) {
903 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
904 return NULL;
905 }
906
907 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
908 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
909 return NULL;
910 }
911
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
913
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800914 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700915 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700916 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917
Dmitry Shmidt04949592012-07-19 12:16:46 -0700918 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700919 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
920 continue;
921 }
922
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700923 res = wpas_temp_disabled(wpa_s, ssid);
924 if (res > 0) {
925 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
926 "temporarily for %d second(s)", res);
927 continue;
928 }
929
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700930#ifdef CONFIG_WPS
931 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
932 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
933 "(WPS)");
934 continue;
935 }
936
937 if (wpa && ssid->ssid_len == 0 &&
938 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
939 check_ssid = 0;
940
941 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
942 /* Only allow wildcard SSID match if an AP
943 * advertises active WPS operation that matches
944 * with our mode. */
945 check_ssid = 1;
946 if (ssid->ssid_len == 0 &&
947 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
948 check_ssid = 0;
949 }
950#endif /* CONFIG_WPS */
951
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800952 if (ssid->bssid_set && ssid->ssid_len == 0 &&
953 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
954 check_ssid = 0;
955
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700956 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700957 (bss->ssid_len != ssid->ssid_len ||
958 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700959 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
960 continue;
961 }
962
963 if (ssid->bssid_set &&
964 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
965 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
966 continue;
967 }
968
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800969 /* check blacklist */
970 if (ssid->num_bssid_blacklist &&
971 addr_in_list(bss->bssid, ssid->bssid_blacklist,
972 ssid->num_bssid_blacklist)) {
973 wpa_dbg(wpa_s, MSG_DEBUG,
974 " skip - BSSID blacklisted");
975 continue;
976 }
977
978 /* if there is a whitelist, only accept those APs */
979 if (ssid->num_bssid_whitelist &&
980 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
981 ssid->num_bssid_whitelist)) {
982 wpa_dbg(wpa_s, MSG_DEBUG,
983 " skip - BSSID not in whitelist");
984 continue;
985 }
986
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700987 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
988 continue;
989
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800990 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700991 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
992 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
993 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
994 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
995 "not allowed");
996 continue;
997 }
998
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700999 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1000 has_wep_key(ssid)) {
1001 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
1002 continue;
1003 }
1004
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001005 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
1006 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
1007 "not allowed");
1008 continue;
1009 }
1010
Jouni Malinen75ecf522011-06-27 15:19:46 -07001011 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
1013 "mismatch");
1014 continue;
1015 }
1016
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001017 if (ssid->mode != IEEE80211_MODE_MESH && !bss_is_ess(bss) &&
1018 !bss_is_pbss(bss)) {
1019 wpa_dbg(wpa_s, MSG_DEBUG,
1020 " skip - not ESS, PBSS, or MBSS");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001021 continue;
1022 }
1023
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001024 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001025 wpa_dbg(wpa_s, MSG_DEBUG, " skip - PBSS mismatch (ssid %d bss %d)",
1026 ssid->pbss, bss_is_pbss(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001027 continue;
1028 }
1029
1030 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1031 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
1032 "allowed");
1033 continue;
1034 }
1035
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001036#ifdef CONFIG_MESH
1037 if (ssid->mode == IEEE80211_MODE_MESH && ssid->frequency > 0 &&
1038 ssid->frequency != bss->freq) {
1039 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not allowed (mesh)");
1040 continue;
1041 }
1042#endif /* CONFIG_MESH */
1043
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001044 if (!rate_match(wpa_s, bss)) {
1045 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1046 "not match");
1047 continue;
1048 }
1049
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001051 if (ssid->p2p_group &&
1052 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1053 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1054 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1055 continue;
1056 }
1057
Dmitry Shmidt54605472013-11-08 11:10:19 -08001058 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1059 struct wpabuf *p2p_ie;
1060 u8 dev_addr[ETH_ALEN];
1061
1062 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1063 if (ie == NULL) {
1064 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1065 continue;
1066 }
1067 p2p_ie = wpa_bss_get_vendor_ie_multi(
1068 bss, P2P_IE_VENDOR_TYPE);
1069 if (p2p_ie == NULL) {
1070 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1071 continue;
1072 }
1073
1074 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1075 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1076 ETH_ALEN) != 0) {
1077 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1078 wpabuf_free(p2p_ie);
1079 continue;
1080 }
1081 wpabuf_free(p2p_ie);
1082 }
1083
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084 /*
1085 * TODO: skip the AP if its P2P IE has Group Formation
1086 * bit set in the P2P Group Capability Bitmap and we
1087 * are not in Group Formation with that device.
1088 */
1089#endif /* CONFIG_P2P */
1090
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001091 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1092 {
1093 struct os_reltime diff;
1094
1095 os_reltime_sub(&wpa_s->scan_min_time,
1096 &bss->last_update, &diff);
1097 wpa_dbg(wpa_s, MSG_DEBUG,
1098 " skip - scan result not recent enough (%u.%06u seconds too old)",
1099 (unsigned int) diff.sec,
1100 (unsigned int) diff.usec);
1101 continue;
1102 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001103#ifdef CONFIG_MBO
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001104#ifdef CONFIG_TESTING_OPTIONS
1105 if (wpa_s->ignore_assoc_disallow)
1106 goto skip_assoc_disallow;
1107#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001108 assoc_disallow = wpas_mbo_get_bss_attr(
1109 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1110 if (assoc_disallow && assoc_disallow[1] >= 1) {
1111 wpa_dbg(wpa_s, MSG_DEBUG,
1112 " skip - MBO association disallowed (reason %u)",
1113 assoc_disallow[2]);
1114 continue;
1115 }
1116
1117 if (wpa_is_bss_tmp_disallowed(wpa_s, bss->bssid)) {
1118 wpa_dbg(wpa_s, MSG_DEBUG,
1119 " skip - MBO retry delay has not passed yet");
1120 continue;
1121 }
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001122#ifdef CONFIG_TESTING_OPTIONS
1123 skip_assoc_disallow:
1124#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001125#endif /* CONFIG_MBO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001126
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127 /* Matching configuration found */
1128 return ssid;
1129 }
1130
1131 /* No matching configuration found */
1132 return NULL;
1133}
1134
1135
1136static struct wpa_bss *
1137wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001138 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001139 struct wpa_ssid **selected_ssid,
1140 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001141{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001142 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001143
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001144 if (only_first_ssid)
1145 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1146 group->id);
1147 else
1148 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1149 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001151 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1152 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001153 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1154 only_first_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001155 if (!*selected_ssid)
1156 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1158 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001159 MAC2STR(bss->bssid),
1160 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1161 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001162 }
1163
1164 return NULL;
1165}
1166
1167
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001168struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1169 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001170{
1171 struct wpa_bss *selected = NULL;
1172 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001173 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001174 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001175
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001176 if (wpa_s->last_scan_res == NULL ||
1177 wpa_s->last_scan_res_used == 0)
1178 return NULL; /* no scan results from last update */
1179
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001180 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001181 /* check that next_ssid is still valid */
1182 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1183 if (ssid == wpa_s->next_ssid)
1184 break;
1185 }
1186 next_ssid = ssid;
1187 wpa_s->next_ssid = NULL;
1188 }
1189
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001190 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001191 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1192 if (next_ssid && next_ssid->priority ==
1193 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001194 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001195 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001196 if (selected)
1197 break;
1198 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001200 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001201 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202 if (selected)
1203 break;
1204 }
1205
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001206 if (selected == NULL && wpa_s->blacklist &&
1207 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001208 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1209 "blacklist and try again");
1210 wpa_blacklist_clear(wpa_s);
1211 wpa_s->blacklist_cleared++;
1212 } else if (selected == NULL)
1213 break;
1214 }
1215
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001216 ssid = *selected_ssid;
1217 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1218 !ssid->passphrase && !ssid->ext_psk) {
1219 const char *field_name, *txt = NULL;
1220
1221 wpa_dbg(wpa_s, MSG_DEBUG,
1222 "PSK/passphrase not yet available for the selected network");
1223
1224 wpas_notify_network_request(wpa_s, ssid,
1225 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1226
1227 field_name = wpa_supplicant_ctrl_req_to_string(
1228 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1229 if (field_name == NULL)
1230 return NULL;
1231
1232 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1233
1234 selected = NULL;
1235 }
1236
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237 return selected;
1238}
1239
1240
1241static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1242 int timeout_sec, int timeout_usec)
1243{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001244 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 /*
1246 * No networks are enabled; short-circuit request so
1247 * we don't wait timeout seconds before transitioning
1248 * to INACTIVE state.
1249 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001250 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1251 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1253 return;
1254 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001255
1256 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001257 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1258}
1259
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001260
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001261int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001262 struct wpa_bss *selected,
1263 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001264{
1265 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1266 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1267 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001268 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001269#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001270 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1271 wpa_s->p2p_in_provisioning) {
1272 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1273 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001274 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001275 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001276#endif /* CONFIG_P2P */
1277
1278#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001279 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001280 wpas_wps_cancel(wpa_s);
1281#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001282 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001283 }
1284
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001285 wpa_msg(wpa_s, MSG_DEBUG,
1286 "Considering connect request: reassociate: %d selected: "
1287 MACSTR " bssid: " MACSTR " pending: " MACSTR
1288 " wpa_state: %s ssid=%p current_ssid=%p",
1289 wpa_s->reassociate, MAC2STR(selected->bssid),
1290 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1291 wpa_supplicant_state_txt(wpa_s->wpa_state),
1292 ssid, wpa_s->current_ssid);
1293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294 /*
1295 * Do not trigger new association unless the BSSID has changed or if
1296 * reassociation is requested. If we are in process of associating with
1297 * the selected BSSID, do not trigger new attempt.
1298 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001299 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1301 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1302 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001303 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1304 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1305 0) ||
1306 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1307 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1309 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001310 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001311 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001312 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1313 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001314 wpa_supplicant_associate(wpa_s, selected, ssid);
1315 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001316 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1317 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001318 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001319
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001320 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001321}
1322
1323
1324static struct wpa_ssid *
1325wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1326{
1327 int prio;
1328 struct wpa_ssid *ssid;
1329
1330 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1331 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1332 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001333 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001334 continue;
1335 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001336 ssid->mode == IEEE80211_MODE_AP ||
1337 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001338 return ssid;
1339 }
1340 }
1341 return NULL;
1342}
1343
1344
1345/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1346 * on BSS added and BSS changed events */
1347static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001348 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001349{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001350 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001351
1352 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1353 return;
1354
Jouni Malinen87fd2792011-05-16 18:35:42 +03001355 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001356 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001357
Jouni Malinen87fd2792011-05-16 18:35:42 +03001358 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001359 if (ssid == NULL)
1360 continue;
1361
Jouni Malinen87fd2792011-05-16 18:35:42 +03001362 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001363 if (rsn == NULL)
1364 continue;
1365
Jouni Malinen87fd2792011-05-16 18:35:42 +03001366 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001367 }
1368
1369}
1370
1371
1372static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1373 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001374 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001376 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001377#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001378 int min_diff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001379 int to_5ghz;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001380#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001381
1382 if (wpa_s->reassociate)
1383 return 1; /* explicit request to reassociate */
1384 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1385 return 1; /* we are not associated; continue */
1386 if (wpa_s->current_ssid == NULL)
1387 return 1; /* unknown current SSID */
1388 if (wpa_s->current_ssid != ssid)
1389 return 1; /* different network block */
1390
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001391 if (wpas_driver_bss_selection(wpa_s))
1392 return 0; /* Driver-based roaming */
1393
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001394 if (wpa_s->current_ssid->ssid)
1395 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1396 wpa_s->current_ssid->ssid,
1397 wpa_s->current_ssid->ssid_len);
1398 if (!current_bss)
1399 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001400
1401 if (!current_bss)
1402 return 1; /* current BSS not seen in scan results */
1403
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001404 if (current_bss == selected)
1405 return 0;
1406
1407 if (selected->last_update_idx > current_bss->last_update_idx)
1408 return 1; /* current BSS not seen in the last scan */
1409
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001410#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001411 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001412 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1413 " level=%d snr=%d est_throughput=%u",
1414 MAC2STR(current_bss->bssid), current_bss->level,
1415 current_bss->snr, current_bss->est_throughput);
1416 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1417 " level=%d snr=%d est_throughput=%u",
1418 MAC2STR(selected->bssid), selected->level,
1419 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001420
1421 if (wpa_s->current_ssid->bssid_set &&
1422 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1423 0) {
1424 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1425 "has preferred BSSID");
1426 return 1;
1427 }
1428
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001429 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1430 wpa_dbg(wpa_s, MSG_DEBUG,
1431 "Allow reassociation - selected BSS has better estimated throughput");
1432 return 1;
1433 }
1434
Dmitry Shmidte4663042016-04-04 10:07:49 -07001435 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1436
1437 if (current_bss->level < 0 &&
1438 current_bss->level > selected->level + to_5ghz * 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001439 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1440 "signal level");
1441 return 0;
1442 }
1443
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001444 min_diff = 2;
1445 if (current_bss->level < 0) {
1446 if (current_bss->level < -85)
1447 min_diff = 1;
1448 else if (current_bss->level < -80)
1449 min_diff = 2;
1450 else if (current_bss->level < -75)
1451 min_diff = 3;
1452 else if (current_bss->level < -70)
1453 min_diff = 4;
1454 else
1455 min_diff = 5;
1456 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001457 if (to_5ghz) {
1458 /* Make it easier to move to 5 GHz band */
1459 if (min_diff > 2)
1460 min_diff -= 2;
1461 else
1462 min_diff = 0;
1463 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001464 if (abs(current_bss->level - selected->level) < min_diff) {
1465 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1466 "in signal level");
1467 return 0;
1468 }
1469
1470 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001471#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001472 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001473#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001474}
1475
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001476
Jouni Malinen89ca7022012-09-14 13:03:12 -07001477/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001478 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001479static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001480 union wpa_event_data *data,
1481 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001483 struct wpa_scan_results *scan_res = NULL;
1484 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001485 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001486#ifndef CONFIG_NO_RANDOM_POOL
1487 size_t i, num;
1488#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001489
1490#ifdef CONFIG_AP
1491 if (wpa_s->ap_iface)
1492 ap = 1;
1493#endif /* CONFIG_AP */
1494
1495 wpa_supplicant_notify_scanning(wpa_s, 0);
1496
1497 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1498 data ? &data->scan_info :
1499 NULL, 1);
1500 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001501 if (wpa_s->conf->ap_scan == 2 || ap ||
1502 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001503 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001504 if (!own_request)
1505 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001506 if (data && data->scan_info.external_scan)
1507 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001508 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1509 "scanning again");
1510 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001511 ret = -1;
1512 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513 }
1514
1515#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001516 num = scan_res->num;
1517 if (num > 10)
1518 num = 10;
1519 for (i = 0; i < num; i++) {
1520 u8 buf[5];
1521 struct wpa_scan_res *res = scan_res->res[i];
1522 buf[0] = res->bssid[5];
1523 buf[1] = res->qual & 0xff;
1524 buf[2] = res->noise & 0xff;
1525 buf[3] = res->level & 0xff;
1526 buf[4] = res->tsf & 0xff;
1527 random_add_randomness(buf, sizeof(buf));
1528 }
1529#endif /* CONFIG_NO_RANDOM_POOL */
1530
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001531 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001532 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001533 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1534 struct wpa_scan_results *scan_res);
1535
1536 scan_res_handler = wpa_s->scan_res_handler;
1537 wpa_s->scan_res_handler = NULL;
1538 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001539 ret = -2;
1540 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001541 }
1542
1543 if (ap) {
1544 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1545#ifdef CONFIG_AP
1546 if (wpa_s->ap_iface->scan_cb)
1547 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1548#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001549 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001550 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001551
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001552 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001553 wpa_s->own_scan_running,
1554 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001555 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001556 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1557 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001558 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1559 wpa_s->manual_scan_id);
1560 wpa_s->manual_scan_use_id = 0;
1561 } else {
1562 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1563 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001564 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565
1566 wpas_notify_scan_done(wpa_s, 1);
1567
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001568 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001569 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 -07001570 wpa_scan_results_free(scan_res);
1571 return 0;
1572 }
1573
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001574 if (wnm_scan_process(wpa_s, 1) > 0)
1575 goto scan_work_done;
1576
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001577 if (sme_proc_obss_scan(wpa_s) > 0)
1578 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001579
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001580 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1581 goto scan_work_done;
1582
1583 if (autoscan_notify_scan(wpa_s, scan_res))
1584 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001585
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001586 if (wpa_s->disconnected) {
1587 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001588 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001589 }
1590
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001591 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001592 bgscan_notify_scan(wpa_s, scan_res) == 1)
1593 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001594
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001595 wpas_wps_update_ap_info(wpa_s, scan_res);
1596
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001597 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1598 wpa_s->wpa_state < WPA_COMPLETED)
1599 goto scan_work_done;
1600
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001601 wpa_scan_results_free(scan_res);
1602
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001603 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001604 struct wpa_radio_work *work = wpa_s->scan_work;
1605 wpa_s->scan_work = NULL;
1606 radio_work_done(work);
1607 }
1608
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001609 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001610
1611scan_work_done:
1612 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001613 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001614 struct wpa_radio_work *work = wpa_s->scan_work;
1615 wpa_s->scan_work = NULL;
1616 radio_work_done(work);
1617 }
1618 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001619}
1620
1621
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001622static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001623 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001624{
1625 struct wpa_bss *selected;
1626 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001627 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1628
1629 if (time_to_reenable > 0) {
1630 wpa_dbg(wpa_s, MSG_DEBUG,
1631 "Postpone network selection by %d seconds since all networks are disabled",
1632 time_to_reenable);
1633 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1634 eloop_register_timeout(time_to_reenable, 0,
1635 wpas_network_reenabled, wpa_s, NULL);
1636 return 0;
1637 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001638
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001639 if (wpa_s->p2p_mgmt)
1640 return 0; /* no normal connection on p2p_mgmt interface */
1641
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001642 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001643
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001644#ifdef CONFIG_MESH
1645 if (wpa_s->ifmsh) {
1646 wpa_msg(wpa_s, MSG_INFO,
1647 "Avoiding join because we already joined a mesh group");
1648 return 0;
1649 }
1650#endif /* CONFIG_MESH */
1651
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001652 if (selected) {
1653 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001654 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001655 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001656 if (new_scan)
1657 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001658 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001659 }
1660
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001661 if (ssid != wpa_s->current_ssid &&
1662 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1663 wpa_s->own_disconnect_req = 1;
1664 wpa_supplicant_deauthenticate(
1665 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1666 }
1667
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001668 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001669 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001670 return -1;
1671 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001672 if (new_scan)
1673 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001674 /*
1675 * Do not notify other virtual radios of scan results since we do not
1676 * want them to start other associations at the same time.
1677 */
1678 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1681 ssid = wpa_supplicant_pick_new_network(wpa_s);
1682 if (ssid) {
1683 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1684 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001685 if (new_scan)
1686 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001687 } else if (own_request) {
1688 /*
1689 * No SSID found. If SCAN results are as a result of
1690 * own scan request and not due to a scan request on
1691 * another shared interface, try another scan.
1692 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001693 int timeout_sec = wpa_s->scan_interval;
1694 int timeout_usec = 0;
1695#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001696 int res;
1697
1698 res = wpas_p2p_scan_no_go_seen(wpa_s);
1699 if (res == 2)
1700 return 2;
1701 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001702 return 0;
1703
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001704 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07001705 wpa_s->show_group_started ||
1706 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001707 /*
1708 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001709 * state and during P2P join-a-group operation
1710 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001711 */
1712 timeout_sec = 0;
1713 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001714 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1715 timeout_usec);
1716 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001717 }
1718#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001719#ifdef CONFIG_INTERWORKING
1720 if (wpa_s->conf->auto_interworking &&
1721 wpa_s->conf->interworking &&
1722 wpa_s->conf->cred) {
1723 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1724 "start ANQP fetch since no matching "
1725 "networks found");
1726 wpa_s->network_select = 1;
1727 wpa_s->auto_network_select = 1;
1728 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001729 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001730 }
1731#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001732#ifdef CONFIG_WPS
1733 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1734 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1735 timeout_sec = 0;
1736 timeout_usec = 500000;
1737 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1738 timeout_usec);
1739 return 0;
1740 }
1741#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001742 if (wpa_supplicant_req_sched_scan(wpa_s))
1743 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1744 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07001745
1746 wpa_msg_ctrl(wpa_s, MSG_INFO,
1747 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001748 }
1749 }
1750 return 0;
1751}
1752
1753
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001754static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1755 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001758 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001759
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001760 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1761 if (res == 2) {
1762 /*
1763 * Interface may have been removed, so must not dereference
1764 * wpa_s after this.
1765 */
1766 return 1;
1767 }
1768 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001769 /*
1770 * If no scan results could be fetched, then no need to
1771 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001772 * this scan. Similarly, if scan results started a new operation on this
1773 * interface, do not notify other interfaces to avoid concurrent
1774 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001775 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001776 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777 }
1778
1779 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001780 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001781 * so, they get updated with this same scan info.
1782 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001783 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1784 radio_list) {
1785 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001786 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1787 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001788 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001789 }
1790 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001791
1792 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001793}
1794
1795#endif /* CONFIG_NO_SCAN_PROCESSING */
1796
1797
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001798int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1799{
1800#ifdef CONFIG_NO_SCAN_PROCESSING
1801 return -1;
1802#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001803 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001804
Dmitry Shmidt41712582015-06-29 11:02:15 -07001805 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001806 return -1;
1807
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001808 os_get_reltime(&now);
1809 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001810 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1811 return -1;
1812 }
1813
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001814 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001815#endif /* CONFIG_NO_SCAN_PROCESSING */
1816}
1817
Dmitry Shmidt04949592012-07-19 12:16:46 -07001818#ifdef CONFIG_WNM
1819
1820static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1821{
1822 struct wpa_supplicant *wpa_s = eloop_ctx;
1823
1824 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1825 return;
1826
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001827 if (!wpa_s->no_keep_alive) {
1828 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1829 MAC2STR(wpa_s->bssid));
1830 /* TODO: could skip this if normal data traffic has been sent */
1831 /* TODO: Consider using some more appropriate data frame for
1832 * this */
1833 if (wpa_s->l2)
1834 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1835 (u8 *) "", 0);
1836 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001837
1838#ifdef CONFIG_SME
1839 if (wpa_s->sme.bss_max_idle_period) {
1840 unsigned int msec;
1841 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1842 if (msec > 100)
1843 msec -= 100;
1844 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1845 wnm_bss_keep_alive, wpa_s, NULL);
1846 }
1847#endif /* CONFIG_SME */
1848}
1849
1850
1851static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1852 const u8 *ies, size_t ies_len)
1853{
1854 struct ieee802_11_elems elems;
1855
1856 if (ies == NULL)
1857 return;
1858
1859 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1860 return;
1861
1862#ifdef CONFIG_SME
1863 if (elems.bss_max_idle_period) {
1864 unsigned int msec;
1865 wpa_s->sme.bss_max_idle_period =
1866 WPA_GET_LE16(elems.bss_max_idle_period);
1867 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1868 "TU)%s", wpa_s->sme.bss_max_idle_period,
1869 (elems.bss_max_idle_period[2] & 0x01) ?
1870 " (protected keep-live required)" : "");
1871 if (wpa_s->sme.bss_max_idle_period == 0)
1872 wpa_s->sme.bss_max_idle_period = 1;
1873 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1874 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1875 /* msec times 1000 */
1876 msec = wpa_s->sme.bss_max_idle_period * 1024;
1877 if (msec > 100)
1878 msec -= 100;
1879 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1880 wnm_bss_keep_alive, wpa_s,
1881 NULL);
1882 }
1883 }
1884#endif /* CONFIG_SME */
1885}
1886
1887#endif /* CONFIG_WNM */
1888
1889
1890void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1891{
1892#ifdef CONFIG_WNM
1893 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1894#endif /* CONFIG_WNM */
1895}
1896
1897
Dmitry Shmidt051af732013-10-22 13:52:46 -07001898#ifdef CONFIG_INTERWORKING
1899
1900static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1901 size_t len)
1902{
1903 int res;
1904
1905 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1906 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1907 if (res) {
1908 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1909 }
1910
1911 return res;
1912}
1913
1914
1915static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1916 const u8 *ies, size_t ies_len)
1917{
1918 struct ieee802_11_elems elems;
1919
1920 if (ies == NULL)
1921 return;
1922
1923 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1924 return;
1925
1926 if (elems.qos_map_set) {
1927 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1928 elems.qos_map_set_len);
1929 }
1930}
1931
1932#endif /* CONFIG_INTERWORKING */
1933
1934
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001935#ifdef CONFIG_FST
1936static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
1937 const u8 *ie, size_t ie_len)
1938{
1939 struct mb_ies_info mb_ies;
1940
1941 if (!ie || !ie_len || !wpa_s->fst)
1942 return -ENOENT;
1943
1944 os_memset(&mb_ies, 0, sizeof(mb_ies));
1945
1946 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
1947 size_t len;
1948
1949 len = 2 + ie[1];
1950 if (len > ie_len) {
1951 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
1952 ie, ie_len);
1953 break;
1954 }
1955
1956 if (ie[0] == WLAN_EID_MULTI_BAND) {
1957 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
1958 (unsigned int) len);
1959 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
1960 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
1961 mb_ies.nof_ies++;
1962 }
1963
1964 ie_len -= len;
1965 ie += len;
1966 }
1967
1968 if (mb_ies.nof_ies > 0) {
1969 wpabuf_free(wpa_s->received_mb_ies);
1970 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
1971 return 0;
1972 }
1973
1974 return -ENOENT;
1975}
1976#endif /* CONFIG_FST */
1977
1978
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001979static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1980 union wpa_event_data *data)
1981{
1982 int l, len, found = 0, wpa_found, rsn_found;
1983 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001984#ifdef CONFIG_IEEE80211R
1985 u8 bssid[ETH_ALEN];
1986#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001987
1988 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1989 if (data->assoc_info.req_ies)
1990 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1991 data->assoc_info.req_ies_len);
1992 if (data->assoc_info.resp_ies) {
1993 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1994 data->assoc_info.resp_ies_len);
1995#ifdef CONFIG_TDLS
1996 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1997 data->assoc_info.resp_ies_len);
1998#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001999#ifdef CONFIG_WNM
2000 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2001 data->assoc_info.resp_ies_len);
2002#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07002003#ifdef CONFIG_INTERWORKING
2004 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2005 data->assoc_info.resp_ies_len);
2006#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002007 }
2008 if (data->assoc_info.beacon_ies)
2009 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2010 data->assoc_info.beacon_ies,
2011 data->assoc_info.beacon_ies_len);
2012 if (data->assoc_info.freq)
2013 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2014 data->assoc_info.freq);
2015
2016 p = data->assoc_info.req_ies;
2017 l = data->assoc_info.req_ies_len;
2018
2019 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2020 while (p && l >= 2) {
2021 len = p[1] + 2;
2022 if (len > l) {
2023 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2024 p, l);
2025 break;
2026 }
2027 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2028 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
Dmitry Shmidte4663042016-04-04 10:07:49 -07002029 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2030 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002031 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
2032 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2033 break;
2034 found = 1;
2035 wpa_find_assoc_pmkid(wpa_s);
2036 break;
2037 }
2038 l -= len;
2039 p += len;
2040 }
2041 if (!found && data->assoc_info.req_ies)
2042 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
2043
2044#ifdef CONFIG_IEEE80211R
2045#ifdef CONFIG_SME
2046 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002047 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2048 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2049 data->assoc_info.resp_ies,
2050 data->assoc_info.resp_ies_len,
2051 bssid) < 0) {
2052 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2053 "Reassociation Response failed");
2054 wpa_supplicant_deauthenticate(
2055 wpa_s, WLAN_REASON_INVALID_IE);
2056 return -1;
2057 }
2058 }
2059
2060 p = data->assoc_info.resp_ies;
2061 l = data->assoc_info.resp_ies_len;
2062
2063#ifdef CONFIG_WPS_STRICT
2064 if (p && wpa_s->current_ssid &&
2065 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2066 struct wpabuf *wps;
2067 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2068 if (wps == NULL) {
2069 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2070 "include WPS IE in (Re)Association Response");
2071 return -1;
2072 }
2073
2074 if (wps_validate_assoc_resp(wps) < 0) {
2075 wpabuf_free(wps);
2076 wpa_supplicant_deauthenticate(
2077 wpa_s, WLAN_REASON_INVALID_IE);
2078 return -1;
2079 }
2080 wpabuf_free(wps);
2081 }
2082#endif /* CONFIG_WPS_STRICT */
2083
2084 /* Go through the IEs and make a copy of the MDIE, if present. */
2085 while (p && l >= 2) {
2086 len = p[1] + 2;
2087 if (len > l) {
2088 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2089 p, l);
2090 break;
2091 }
2092 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2093 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2094 wpa_s->sme.ft_used = 1;
2095 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2096 MOBILITY_DOMAIN_ID_LEN);
2097 break;
2098 }
2099 l -= len;
2100 p += len;
2101 }
2102#endif /* CONFIG_SME */
2103
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002104 /* Process FT when SME is in the driver */
2105 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2106 wpa_ft_is_completed(wpa_s->wpa)) {
2107 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2108 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2109 data->assoc_info.resp_ies,
2110 data->assoc_info.resp_ies_len,
2111 bssid) < 0) {
2112 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2113 "Reassociation Response failed");
2114 wpa_supplicant_deauthenticate(
2115 wpa_s, WLAN_REASON_INVALID_IE);
2116 return -1;
2117 }
2118 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2119 }
2120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002121 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2122 data->assoc_info.resp_ies_len);
2123#endif /* CONFIG_IEEE80211R */
2124
2125 /* WPA/RSN IE from Beacon/ProbeResp */
2126 p = data->assoc_info.beacon_ies;
2127 l = data->assoc_info.beacon_ies_len;
2128
2129 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2130 */
2131 wpa_found = rsn_found = 0;
2132 while (p && l >= 2) {
2133 len = p[1] + 2;
2134 if (len > l) {
2135 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2136 p, l);
2137 break;
2138 }
2139 if (!wpa_found &&
2140 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2141 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2142 wpa_found = 1;
2143 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2144 }
2145
2146 if (!rsn_found &&
2147 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2148 rsn_found = 1;
2149 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2150 }
2151
2152 l -= len;
2153 p += len;
2154 }
2155
2156 if (!wpa_found && data->assoc_info.beacon_ies)
2157 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2158 if (!rsn_found && data->assoc_info.beacon_ies)
2159 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2160 if (wpa_found || rsn_found)
2161 wpa_s->ap_ies_from_associnfo = 1;
2162
Jouni Malinen87fd2792011-05-16 18:35:42 +03002163 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2164 wpa_s->assoc_freq != data->assoc_info.freq) {
2165 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2166 "%u to %u MHz",
2167 wpa_s->assoc_freq, data->assoc_info.freq);
2168 wpa_supplicant_update_scan_results(wpa_s);
2169 }
2170
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002171 wpa_s->assoc_freq = data->assoc_info.freq;
2172
2173 return 0;
2174}
2175
2176
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002177static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2178{
2179 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2180
2181 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2182 return -1;
2183
2184 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2185 return 0;
2186
2187 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2188 WPA_IE_VENDOR_TYPE);
2189 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2190
2191 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2192 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2193 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2194 bss_rsn ? 2 + bss_rsn[1] : 0))
2195 return -1;
2196
2197 return 0;
2198}
2199
2200
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002201static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2202 union wpa_event_data *data)
2203{
2204#ifdef CONFIG_FST
2205 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2206 struct wpa_bss *bss = wpa_s->current_bss;
2207 const u8 *ieprb, *iebcn;
2208
2209 wpabuf_free(wpa_s->received_mb_ies);
2210 wpa_s->received_mb_ies = NULL;
2211
2212 if (ai &&
2213 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2214 wpa_printf(MSG_DEBUG,
2215 "FST: MB IEs updated from Association Response frame");
2216 return;
2217 }
2218
2219 if (ai &&
2220 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2221 wpa_printf(MSG_DEBUG,
2222 "FST: MB IEs updated from association event Beacon IEs");
2223 return;
2224 }
2225
2226 if (!bss)
2227 return;
2228
2229 ieprb = (const u8 *) (bss + 1);
2230 iebcn = ieprb + bss->ie_len;
2231
2232 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2233 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2234 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2235 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2236#endif /* CONFIG_FST */
2237}
2238
2239
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002240static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2241 union wpa_event_data *data)
2242{
2243 u8 bssid[ETH_ALEN];
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002244 int ft_completed, already_authorized;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002245 int new_bss = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002246
2247#ifdef CONFIG_AP
2248 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002249 if (!data)
2250 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002251 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2252 data->assoc_info.addr,
2253 data->assoc_info.req_ies,
2254 data->assoc_info.req_ies_len,
2255 data->assoc_info.reassoc);
2256 return;
2257 }
2258#endif /* CONFIG_AP */
2259
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002260 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2261
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002262 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2263 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2264 return;
2265
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002266 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2267 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002268 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002269 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2270 return;
2271 }
2272
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002273 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002274 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002275 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2276 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002277 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002278 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002279 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2280 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002281 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002282
2283 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2284 wpa_clear_keys(wpa_s, bssid);
2285 }
2286 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002287 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002288 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2289 return;
2290 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002291 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002292
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002293 if (wpa_s->conf->ap_scan == 1 &&
2294 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002295 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2296 wpa_msg(wpa_s, MSG_WARNING,
2297 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002298 }
2299
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002300 wpas_fst_update_mb_assoc(wpa_s, data);
2301
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002302#ifdef CONFIG_SME
2303 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2304 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002305 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306#endif /* CONFIG_SME */
2307
2308 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2309 if (wpa_s->current_ssid) {
2310 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2311 * initialized before association, but for other modes,
2312 * initialize PC/SC here, if the current configuration needs
2313 * smartcard or SIM/USIM. */
2314 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2315 }
2316 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2317 if (wpa_s->l2)
2318 l2_packet_notify_auth_start(wpa_s->l2);
2319
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002320 already_authorized = data && data->assoc_info.authorized;
2321
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002322 /*
2323 * Set portEnabled first to FALSE in order to get EAP state machine out
2324 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2325 * state machine may transit to AUTHENTICATING state based on obsolete
2326 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2327 * AUTHENTICATED without ever giving chance to EAP state machine to
2328 * reset the state.
2329 */
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002330 if (!ft_completed && !already_authorized) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002331 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2332 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2333 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002334 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed ||
2335 already_authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002336 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2337 /* 802.1X::portControl = Auto */
2338 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2339 wpa_s->eapol_received = 0;
2340 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2341 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2342 (wpa_s->current_ssid &&
2343 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002344 if (wpa_s->current_ssid &&
2345 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002346 (wpa_s->drv_flags &
2347 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2348 /*
2349 * Set the key after having received joined-IBSS event
2350 * from the driver.
2351 */
2352 wpa_supplicant_set_wpa_none_key(wpa_s,
2353 wpa_s->current_ssid);
2354 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002355 wpa_supplicant_cancel_auth_timeout(wpa_s);
2356 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2357 } else if (!ft_completed) {
2358 /* Timeout for receiving the first EAPOL packet */
2359 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2360 }
2361 wpa_supplicant_cancel_scan(wpa_s);
2362
2363 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2364 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2365 /*
2366 * We are done; the driver will take care of RSN 4-way
2367 * handshake.
2368 */
2369 wpa_supplicant_cancel_auth_timeout(wpa_s);
2370 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2371 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2372 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2373 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2374 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2375 /*
2376 * The driver will take care of RSN 4-way handshake, so we need
2377 * to allow EAPOL supplicant to complete its work without
2378 * waiting for WPA supplicant.
2379 */
2380 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2381 } else if (ft_completed) {
2382 /*
2383 * FT protocol completed - make sure EAPOL state machine ends
2384 * up in authenticated.
2385 */
2386 wpa_supplicant_cancel_auth_timeout(wpa_s);
2387 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2388 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2389 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2390 }
2391
Jouni Malinena05074c2012-12-21 21:35:35 +02002392 wpa_s->last_eapol_matches_bssid = 0;
2393
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002394 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002395 struct os_reltime now, age;
2396 os_get_reltime(&now);
2397 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002398 if (age.sec == 0 && age.usec < 100000 &&
2399 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2400 0) {
2401 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2402 "frame that was received just before "
2403 "association notification");
2404 wpa_supplicant_rx_eapol(
2405 wpa_s, wpa_s->pending_eapol_rx_src,
2406 wpabuf_head(wpa_s->pending_eapol_rx),
2407 wpabuf_len(wpa_s->pending_eapol_rx));
2408 }
2409 wpabuf_free(wpa_s->pending_eapol_rx);
2410 wpa_s->pending_eapol_rx = NULL;
2411 }
2412
2413 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2414 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002415 wpa_s->current_ssid &&
2416 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002417 /* Set static WEP keys again */
2418 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2419 }
2420
2421#ifdef CONFIG_IBSS_RSN
2422 if (wpa_s->current_ssid &&
2423 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2424 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2425 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2426 wpa_s->ibss_rsn == NULL) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07002427 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002428 if (!wpa_s->ibss_rsn) {
2429 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2430 wpa_supplicant_deauthenticate(
2431 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2432 return;
2433 }
2434
2435 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2436 }
2437#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002438
2439 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002440
2441 if (data) {
2442 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2443 data->assoc_info.resp_ies_len,
2444 &data->assoc_info.wmm_params);
2445
2446 if (wpa_s->reassoc_same_bss)
2447 wmm_ac_restore_tspecs(wpa_s);
2448 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002449}
2450
2451
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002452static int disconnect_reason_recoverable(u16 reason_code)
2453{
2454 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2455 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2456 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2457}
2458
2459
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002460static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002461 u16 reason_code,
2462 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002463{
2464 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002465
2466 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2467 /*
2468 * At least Host AP driver and a Prism3 card seemed to be
2469 * generating streams of disconnected events when configuring
2470 * IBSS for WPA-None. Ignore them for now.
2471 */
2472 return;
2473 }
2474
2475 bssid = wpa_s->bssid;
2476 if (is_zero_ether_addr(bssid))
2477 bssid = wpa_s->pending_bssid;
2478
2479 if (!is_zero_ether_addr(bssid) ||
2480 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2481 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2482 " reason=%d%s",
2483 MAC2STR(bssid), reason_code,
2484 locally_generated ? " locally_generated=1" : "");
2485 }
2486}
2487
2488
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002489static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2490 int locally_generated)
2491{
2492 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2493 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2494 return 0; /* Not in 4-way handshake with PSK */
2495
2496 /*
2497 * It looks like connection was lost while trying to go through PSK
2498 * 4-way handshake. Filter out known disconnection cases that are caused
2499 * by something else than PSK mismatch to avoid confusing reports.
2500 */
2501
2502 if (locally_generated) {
2503 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2504 return 0;
2505 }
2506
2507 return 1;
2508}
2509
2510
Jouni Malinen2b89da82012-08-31 22:04:41 +03002511static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2512 u16 reason_code,
2513 int locally_generated)
2514{
2515 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002516 int authenticating;
2517 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002518 struct wpa_bss *fast_reconnect = NULL;
2519 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002520 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002521
2522 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2523 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2524
2525 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2526 /*
2527 * At least Host AP driver and a Prism3 card seemed to be
2528 * generating streams of disconnected events when configuring
2529 * IBSS for WPA-None. Ignore them for now.
2530 */
2531 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2532 "IBSS/WPA-None mode");
2533 return;
2534 }
2535
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002536 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002537 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2538 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002539 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2540 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002541 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002542 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002543 if (!wpa_s->disconnected &&
2544 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002545 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002546 wpas_wps_searching(wpa_s) ||
2547 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002548 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002549 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002550 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002551 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002552 wpa_s->wpa_state);
2553 if (wpa_s->wpa_state == WPA_COMPLETED &&
2554 wpa_s->current_ssid &&
2555 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002556 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002557 disconnect_reason_recoverable(reason_code)) {
2558 /*
2559 * It looks like the AP has dropped association with
2560 * us, but could allow us to get back in. Try to
2561 * reconnect to the same BSS without full scan to save
2562 * time for some common cases.
2563 */
2564 fast_reconnect = wpa_s->current_bss;
2565 fast_reconnect_ssid = wpa_s->current_ssid;
2566 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002567 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002568 else
2569 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2570 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002571 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002572 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002573 "try to re-connect");
2574 wpa_s->reassociate = 0;
2575 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002576 if (!wpa_s->pno)
2577 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002578 }
2579 bssid = wpa_s->bssid;
2580 if (is_zero_ether_addr(bssid))
2581 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002582 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2583 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002584 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002585 if (locally_generated)
2586 wpa_s->disconnect_reason = -reason_code;
2587 else
2588 wpa_s->disconnect_reason = reason_code;
2589 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002590 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2591 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002592 wpa_clear_keys(wpa_s, wpa_s->bssid);
2593 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002594 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002595 wpa_supplicant_mark_disassoc(wpa_s);
2596
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002597 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002598 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002599 wpa_s->current_ssid = last_ssid;
2600 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002601
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002602 if (fast_reconnect &&
2603 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2604 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2605 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2606 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002607 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
2608 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect->bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002609#ifndef CONFIG_NO_SCAN_PROCESSING
2610 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2611 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2612 fast_reconnect_ssid) < 0) {
2613 /* Recover through full scan */
2614 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2615 }
2616#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002617 } else if (fast_reconnect) {
2618 /*
2619 * Could not reconnect to the same BSS due to network being
2620 * disabled. Use a new scan to match the alternative behavior
2621 * above, i.e., to continue automatic reconnection attempt in a
2622 * way that enforces disabled network rules.
2623 */
2624 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002625 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002626}
2627
2628
2629#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002630void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002631{
2632 struct wpa_supplicant *wpa_s = eloop_ctx;
2633
2634 if (!wpa_s->pending_mic_error_report)
2635 return;
2636
2637 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2638 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2639 wpa_s->pending_mic_error_report = 0;
2640}
2641#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2642
2643
2644static void
2645wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2646 union wpa_event_data *data)
2647{
2648 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002649 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002650
2651 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2652 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002653 os_get_reltime(&t);
2654 if ((wpa_s->last_michael_mic_error.sec &&
2655 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002656 wpa_s->pending_mic_error_report) {
2657 if (wpa_s->pending_mic_error_report) {
2658 /*
2659 * Send the pending MIC error report immediately since
2660 * we are going to start countermeasures and AP better
2661 * do the same.
2662 */
2663 wpa_sm_key_request(wpa_s->wpa, 1,
2664 wpa_s->pending_mic_error_pairwise);
2665 }
2666
2667 /* Send the new MIC error report immediately since we are going
2668 * to start countermeasures and AP better do the same.
2669 */
2670 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2671
2672 /* initialize countermeasures */
2673 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002674
2675 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2676
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002677 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2678
2679 /*
2680 * Need to wait for completion of request frame. We do not get
2681 * any callback for the message completion, so just wait a
2682 * short while and hope for the best. */
2683 os_sleep(0, 10000);
2684
2685 wpa_drv_set_countermeasures(wpa_s, 1);
2686 wpa_supplicant_deauthenticate(wpa_s,
2687 WLAN_REASON_MICHAEL_MIC_FAILURE);
2688 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2689 wpa_s, NULL);
2690 eloop_register_timeout(60, 0,
2691 wpa_supplicant_stop_countermeasures,
2692 wpa_s, NULL);
2693 /* TODO: mark the AP rejected for 60 second. STA is
2694 * allowed to associate with another AP.. */
2695 } else {
2696#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2697 if (wpa_s->mic_errors_seen) {
2698 /*
2699 * Reduce the effectiveness of Michael MIC error
2700 * reports as a means for attacking against TKIP if
2701 * more than one MIC failure is noticed with the same
2702 * PTK. We delay the transmission of the reports by a
2703 * random time between 0 and 60 seconds in order to
2704 * force the attacker wait 60 seconds before getting
2705 * the information on whether a frame resulted in a MIC
2706 * failure.
2707 */
2708 u8 rval[4];
2709 int sec;
2710
2711 if (os_get_random(rval, sizeof(rval)) < 0)
2712 sec = os_random() % 60;
2713 else
2714 sec = WPA_GET_BE32(rval) % 60;
2715 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2716 "report %d seconds", sec);
2717 wpa_s->pending_mic_error_report = 1;
2718 wpa_s->pending_mic_error_pairwise = pairwise;
2719 eloop_cancel_timeout(
2720 wpa_supplicant_delayed_mic_error_report,
2721 wpa_s, NULL);
2722 eloop_register_timeout(
2723 sec, os_random() % 1000000,
2724 wpa_supplicant_delayed_mic_error_report,
2725 wpa_s, NULL);
2726 } else {
2727 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2728 }
2729#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2730 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2731#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2732 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002733 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002734 wpa_s->mic_errors_seen++;
2735}
2736
2737
2738#ifdef CONFIG_TERMINATE_ONLASTIF
2739static int any_interfaces(struct wpa_supplicant *head)
2740{
2741 struct wpa_supplicant *wpa_s;
2742
2743 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2744 if (!wpa_s->interface_removed)
2745 return 1;
2746 return 0;
2747}
2748#endif /* CONFIG_TERMINATE_ONLASTIF */
2749
2750
2751static void
2752wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2753 union wpa_event_data *data)
2754{
2755 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2756 return;
2757
2758 switch (data->interface_status.ievent) {
2759 case EVENT_INTERFACE_ADDED:
2760 if (!wpa_s->interface_removed)
2761 break;
2762 wpa_s->interface_removed = 0;
2763 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2764 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2765 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2766 "driver after interface was added");
2767 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07002768
2769#ifdef CONFIG_P2P
2770 if (!wpa_s->global->p2p &&
2771 !wpa_s->global->p2p_disabled &&
2772 !wpa_s->conf->p2p_disabled &&
2773 (wpa_s->drv_flags &
2774 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2775 wpas_p2p_add_p2pdev_interface(
2776 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2777 wpa_printf(MSG_INFO,
2778 "P2P: Failed to enable P2P Device interface");
2779 /* Try to continue without. P2P will be disabled. */
2780 }
2781#endif /* CONFIG_P2P */
2782
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002783 break;
2784 case EVENT_INTERFACE_REMOVED:
2785 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2786 wpa_s->interface_removed = 1;
2787 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002788 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002789 l2_packet_deinit(wpa_s->l2);
2790 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07002791
2792#ifdef CONFIG_P2P
2793 if (wpa_s->global->p2p &&
2794 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2795 (wpa_s->drv_flags &
2796 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2797 wpa_dbg(wpa_s, MSG_DEBUG,
2798 "Removing P2P Device interface");
2799 wpa_supplicant_remove_iface(
2800 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2801 0);
2802 wpa_s->global->p2p_init_wpa_s = NULL;
2803 }
2804#endif /* CONFIG_P2P */
2805
Dmitry Shmidte4663042016-04-04 10:07:49 -07002806#ifdef CONFIG_MATCH_IFACE
2807 if (wpa_s->matched) {
2808 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
2809 break;
2810 }
2811#endif /* CONFIG_MATCH_IFACE */
2812
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002813#ifdef CONFIG_TERMINATE_ONLASTIF
2814 /* check if last interface */
2815 if (!any_interfaces(wpa_s->global->ifaces))
2816 eloop_terminate();
2817#endif /* CONFIG_TERMINATE_ONLASTIF */
2818 break;
2819 }
2820}
2821
2822
2823#ifdef CONFIG_PEERKEY
2824static void
2825wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2826 union wpa_event_data *data)
2827{
2828 if (data == NULL)
2829 return;
2830 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2831}
2832#endif /* CONFIG_PEERKEY */
2833
2834
2835#ifdef CONFIG_TDLS
2836static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2837 union wpa_event_data *data)
2838{
2839 if (data == NULL)
2840 return;
2841 switch (data->tdls.oper) {
2842 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002843 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2844 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2845 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2846 else
2847 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002848 break;
2849 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002850 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2851 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2852 data->tdls.reason_code);
2853 else
2854 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2855 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002856 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07002857 case TDLS_REQUEST_DISCOVER:
2858 wpa_tdls_send_discovery_request(wpa_s->wpa,
2859 data->tdls.peer);
2860 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002861 }
2862}
2863#endif /* CONFIG_TDLS */
2864
2865
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002866#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002867static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2868 union wpa_event_data *data)
2869{
2870 if (data == NULL)
2871 return;
2872 switch (data->wnm.oper) {
2873 case WNM_OPER_SLEEP:
2874 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2875 "(action=%d, intval=%d)",
2876 data->wnm.sleep_action, data->wnm.sleep_intval);
2877 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002878 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002879 break;
2880 }
2881}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002882#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002883
2884
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002885#ifdef CONFIG_IEEE80211R
2886static void
2887wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2888 union wpa_event_data *data)
2889{
2890 if (data == NULL)
2891 return;
2892
2893 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2894 data->ft_ies.ies_len,
2895 data->ft_ies.ft_action,
2896 data->ft_ies.target_ap,
2897 data->ft_ies.ric_ies,
2898 data->ft_ies.ric_ies_len) < 0) {
2899 /* TODO: prevent MLME/driver from trying to associate? */
2900 }
2901}
2902#endif /* CONFIG_IEEE80211R */
2903
2904
2905#ifdef CONFIG_IBSS_RSN
2906static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2907 union wpa_event_data *data)
2908{
2909 struct wpa_ssid *ssid;
2910 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2911 return;
2912 if (data == NULL)
2913 return;
2914 ssid = wpa_s->current_ssid;
2915 if (ssid == NULL)
2916 return;
2917 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2918 return;
2919
2920 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2921}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002922
2923
2924static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2925 union wpa_event_data *data)
2926{
2927 struct wpa_ssid *ssid = wpa_s->current_ssid;
2928
2929 if (ssid == NULL)
2930 return;
2931
2932 /* check if the ssid is correctly configured as IBSS/RSN */
2933 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2934 return;
2935
2936 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2937 data->rx_mgmt.frame_len);
2938}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002939#endif /* CONFIG_IBSS_RSN */
2940
2941
2942#ifdef CONFIG_IEEE80211R
2943static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2944 size_t len)
2945{
2946 const u8 *sta_addr, *target_ap_addr;
2947 u16 status;
2948
2949 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2950 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2951 return; /* only SME case supported for now */
2952 if (len < 1 + 2 * ETH_ALEN + 2)
2953 return;
2954 if (data[0] != 2)
2955 return; /* Only FT Action Response is supported for now */
2956 sta_addr = data + 1;
2957 target_ap_addr = data + 1 + ETH_ALEN;
2958 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2959 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2960 MACSTR " TargetAP " MACSTR " status %u",
2961 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2962
2963 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2964 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2965 " in FT Action Response", MAC2STR(sta_addr));
2966 return;
2967 }
2968
2969 if (status) {
2970 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2971 "failure (status code %d)", status);
2972 /* TODO: report error to FT code(?) */
2973 return;
2974 }
2975
2976 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2977 len - (1 + 2 * ETH_ALEN + 2), 1,
2978 target_ap_addr, NULL, 0) < 0)
2979 return;
2980
2981#ifdef CONFIG_SME
2982 {
2983 struct wpa_bss *bss;
2984 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2985 if (bss)
2986 wpa_s->sme.freq = bss->freq;
2987 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2988 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2989 WLAN_AUTH_FT);
2990 }
2991#endif /* CONFIG_SME */
2992}
2993#endif /* CONFIG_IEEE80211R */
2994
2995
2996static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2997 struct unprot_deauth *e)
2998{
2999#ifdef CONFIG_IEEE80211W
3000 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3001 "dropped: " MACSTR " -> " MACSTR
3002 " (reason code %u)",
3003 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3004 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3005#endif /* CONFIG_IEEE80211W */
3006}
3007
3008
3009static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3010 struct unprot_disassoc *e)
3011{
3012#ifdef CONFIG_IEEE80211W
3013 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3014 "dropped: " MACSTR " -> " MACSTR
3015 " (reason code %u)",
3016 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3017 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3018#endif /* CONFIG_IEEE80211W */
3019}
3020
3021
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003022static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3023 u16 reason_code, int locally_generated,
3024 const u8 *ie, size_t ie_len, int deauth)
3025{
3026#ifdef CONFIG_AP
3027 if (wpa_s->ap_iface && addr) {
3028 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3029 return;
3030 }
3031
3032 if (wpa_s->ap_iface) {
3033 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3034 return;
3035 }
3036#endif /* CONFIG_AP */
3037
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003038 if (!locally_generated)
3039 wpa_s->own_disconnect_req = 0;
3040
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003041 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3042
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003043 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3044 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3045 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3046 eapol_sm_failed(wpa_s->eapol))) &&
3047 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003048 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003049
3050#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003051 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003052 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3053 locally_generated) > 0) {
3054 /*
3055 * The interface was removed, so cannot continue
3056 * processing any additional operations after this.
3057 */
3058 return;
3059 }
3060 }
3061#endif /* CONFIG_P2P */
3062
3063 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3064 locally_generated);
3065}
3066
3067
3068static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3069 struct disassoc_info *info)
3070{
3071 u16 reason_code = 0;
3072 int locally_generated = 0;
3073 const u8 *addr = NULL;
3074 const u8 *ie = NULL;
3075 size_t ie_len = 0;
3076
3077 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3078
3079 if (info) {
3080 addr = info->addr;
3081 ie = info->ie;
3082 ie_len = info->ie_len;
3083 reason_code = info->reason_code;
3084 locally_generated = info->locally_generated;
3085 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
3086 locally_generated ? " (locally generated)" : "");
3087 if (addr)
3088 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3089 MAC2STR(addr));
3090 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3091 ie, ie_len);
3092 }
3093
3094#ifdef CONFIG_AP
3095 if (wpa_s->ap_iface && info && info->addr) {
3096 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3097 return;
3098 }
3099
3100 if (wpa_s->ap_iface) {
3101 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3102 return;
3103 }
3104#endif /* CONFIG_AP */
3105
3106#ifdef CONFIG_P2P
3107 if (info) {
3108 wpas_p2p_disassoc_notif(
3109 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3110 locally_generated);
3111 }
3112#endif /* CONFIG_P2P */
3113
3114 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3115 sme_event_disassoc(wpa_s, info);
3116
3117 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3118 ie, ie_len, 0);
3119}
3120
3121
3122static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3123 struct deauth_info *info)
3124{
3125 u16 reason_code = 0;
3126 int locally_generated = 0;
3127 const u8 *addr = NULL;
3128 const u8 *ie = NULL;
3129 size_t ie_len = 0;
3130
3131 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3132
3133 if (info) {
3134 addr = info->addr;
3135 ie = info->ie;
3136 ie_len = info->ie_len;
3137 reason_code = info->reason_code;
3138 locally_generated = info->locally_generated;
3139 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3140 reason_code,
3141 locally_generated ? " (locally generated)" : "");
3142 if (addr) {
3143 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3144 MAC2STR(addr));
3145 }
3146 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3147 ie, ie_len);
3148 }
3149
3150 wpa_reset_ft_completed(wpa_s->wpa);
3151
3152 wpas_event_disconnect(wpa_s, addr, reason_code,
3153 locally_generated, ie, ie_len, 1);
3154}
3155
3156
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003157static const char * reg_init_str(enum reg_change_initiator init)
3158{
3159 switch (init) {
3160 case REGDOM_SET_BY_CORE:
3161 return "CORE";
3162 case REGDOM_SET_BY_USER:
3163 return "USER";
3164 case REGDOM_SET_BY_DRIVER:
3165 return "DRIVER";
3166 case REGDOM_SET_BY_COUNTRY_IE:
3167 return "COUNTRY_IE";
3168 case REGDOM_BEACON_HINT:
3169 return "BEACON_HINT";
3170 }
3171 return "?";
3172}
3173
3174
3175static const char * reg_type_str(enum reg_type type)
3176{
3177 switch (type) {
3178 case REGDOM_TYPE_UNKNOWN:
3179 return "UNKNOWN";
3180 case REGDOM_TYPE_COUNTRY:
3181 return "COUNTRY";
3182 case REGDOM_TYPE_WORLD:
3183 return "WORLD";
3184 case REGDOM_TYPE_CUSTOM_WORLD:
3185 return "CUSTOM_WORLD";
3186 case REGDOM_TYPE_INTERSECTION:
3187 return "INTERSECTION";
3188 }
3189 return "?";
3190}
3191
3192
3193static void wpa_supplicant_update_channel_list(
3194 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003195{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003196 struct wpa_supplicant *ifs;
3197
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003198 /*
3199 * To allow backwards compatibility with higher level layers that
3200 * assumed the REGDOM_CHANGE event is sent over the initially added
3201 * interface. Find the highest parent of this interface and use it to
3202 * send the event.
3203 */
3204 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3205 ;
3206
3207 wpa_msg(ifs, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
Dmitry Shmidtc2817022014-07-02 10:32:10 -07003208 reg_init_str(info->initiator), reg_type_str(info->type),
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003209 info->alpha2[0] ? " alpha2=" : "",
3210 info->alpha2[0] ? info->alpha2 : "");
3211
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003212 if (wpa_s->drv_priv == NULL)
3213 return; /* Ignore event during drv initialization */
3214
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003215 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3216 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003217 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3218 ifs->ifname);
3219 free_hw_features(ifs);
3220 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3221 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003222 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003223
3224 /* Restart sched_scan with updated channel list */
3225 if (wpa_s->sched_scanning) {
3226 wpa_dbg(wpa_s, MSG_DEBUG,
3227 "Channel list changed restart sched scan.");
3228 wpa_supplicant_cancel_sched_scan(wpa_s);
3229 wpa_supplicant_req_scan(wpa_s, 0, 0);
3230 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003231
3232 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003233}
3234
3235
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003236static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003237 const u8 *frame, size_t len, int freq,
3238 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003239{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003240 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003241 const u8 *payload;
3242 size_t plen;
3243 u8 category;
3244
3245 if (len < IEEE80211_HDRLEN + 2)
3246 return;
3247
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003248 mgmt = (const struct ieee80211_mgmt *) frame;
3249 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003250 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003251 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003252
3253 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3254 " Category=%u DataLen=%d freq=%d MHz",
3255 MAC2STR(mgmt->sa), category, (int) plen, freq);
3256
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003257 if (category == WLAN_ACTION_WMM) {
3258 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3259 return;
3260 }
3261
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003262#ifdef CONFIG_IEEE80211R
3263 if (category == WLAN_ACTION_FT) {
3264 ft_rx_action(wpa_s, payload, plen);
3265 return;
3266 }
3267#endif /* CONFIG_IEEE80211R */
3268
3269#ifdef CONFIG_IEEE80211W
3270#ifdef CONFIG_SME
3271 if (category == WLAN_ACTION_SA_QUERY) {
3272 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3273 return;
3274 }
3275#endif /* CONFIG_SME */
3276#endif /* CONFIG_IEEE80211W */
3277
3278#ifdef CONFIG_WNM
3279 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3280 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3281 return;
3282 }
3283#endif /* CONFIG_WNM */
3284
3285#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003286 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3287 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003288 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003289 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003290 payload, plen, freq) == 0)
3291 return;
3292#endif /* CONFIG_GAS */
3293
3294#ifdef CONFIG_TDLS
3295 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3296 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3297 wpa_dbg(wpa_s, MSG_DEBUG,
3298 "TDLS: Received Discovery Response from " MACSTR,
3299 MAC2STR(mgmt->sa));
3300 return;
3301 }
3302#endif /* CONFIG_TDLS */
3303
3304#ifdef CONFIG_INTERWORKING
3305 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3306 payload[0] == QOS_QOS_MAP_CONFIG) {
3307 const u8 *pos = payload + 1;
3308 size_t qlen = plen - 1;
3309 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3310 MACSTR, MAC2STR(mgmt->sa));
3311 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3312 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3313 pos[1] <= qlen - 2 && pos[1] >= 16)
3314 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3315 return;
3316 }
3317#endif /* CONFIG_INTERWORKING */
3318
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003319 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003320 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
3321 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
3322 payload + 1,
3323 plen - 1);
3324 return;
3325 }
3326
3327 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003328 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3329 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3330 return;
3331 }
3332
3333 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3334 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3335 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3336 payload + 1, plen - 1,
3337 rssi);
3338 return;
3339 }
3340
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003341#ifdef CONFIG_FST
3342 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3343 fst_rx_action(wpa_s->fst, mgmt, len);
3344 return;
3345 }
3346#endif /* CONFIG_FST */
3347
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003348 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3349 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003350 if (wpa_s->ifmsh)
3351 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003352}
3353
3354
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003355static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3356 union wpa_event_data *event)
3357{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003358 struct wpa_freq_range_list *list;
3359 char *str = NULL;
3360
3361 list = &event->freq_range;
3362
3363 if (list->num)
3364 str = freq_range_list_str(list);
3365 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3366 str ? str : "");
3367
3368#ifdef CONFIG_P2P
3369 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3370 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3371 __func__);
3372 } else {
3373 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003374
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003375 /*
3376 * The update channel flow will also take care of moving a GO
3377 * from the unsafe frequency if needed.
3378 */
3379 wpas_p2p_update_channel_list(wpa_s,
3380 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003381 }
3382#endif /* CONFIG_P2P */
3383
3384 os_free(str);
3385}
3386
3387
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003388static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3389 union wpa_event_data *data)
3390{
3391 wpa_dbg(wpa_s, MSG_DEBUG,
3392 "Connection authorized by device, previous state %d",
3393 wpa_s->wpa_state);
3394 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3395 wpa_supplicant_cancel_auth_timeout(wpa_s);
3396 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3397 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3398 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3399 }
3400 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3401 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003402 data->assoc_info.ptk_kck_len,
3403 data->assoc_info.ptk_kek,
3404 data->assoc_info.ptk_kek_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003405}
3406
3407
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003408void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3409 union wpa_event_data *data)
3410{
3411 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07003412 int resched;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003413
3414 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3415 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003416 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08003417 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003418 event != EVENT_SCHED_SCAN_STOPPED) {
3419 wpa_dbg(wpa_s, MSG_DEBUG,
3420 "Ignore event %s (%d) while interface is disabled",
3421 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003422 return;
3423 }
3424
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003425#ifndef CONFIG_NO_STDOUT_DEBUG
3426{
3427 int level = MSG_DEBUG;
3428
Dmitry Shmidt04949592012-07-19 12:16:46 -07003429 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003430 const struct ieee80211_hdr *hdr;
3431 u16 fc;
3432 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3433 fc = le_to_host16(hdr->frame_control);
3434 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3435 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3436 level = MSG_EXCESSIVE;
3437 }
3438
3439 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3440 event_to_string(event), event);
3441}
3442#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003443
3444 switch (event) {
3445 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003446#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08003447 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
3448 data->auth.ies_len))
3449 wpa_printf(MSG_DEBUG,
3450 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003451#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003452 sme_event_auth(wpa_s, data);
3453 break;
3454 case EVENT_ASSOC:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003455#ifdef CONFIG_TESTING_OPTIONS
3456 if (wpa_s->ignore_auth_resp) {
3457 wpa_printf(MSG_INFO,
3458 "EVENT_ASSOC - ignore_auth_resp active!");
3459 break;
3460 }
3461#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003462 wpa_supplicant_event_assoc(wpa_s, data);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003463 if (data && data->assoc_info.authorized)
3464 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003465 if (data) {
3466 wpa_msg(wpa_s, MSG_INFO,
3467 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
3468 data->assoc_info.subnet_status);
3469 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003470 break;
3471 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003472 wpas_event_disassoc(wpa_s,
3473 data ? &data->disassoc_info : NULL);
3474 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003475 case EVENT_DEAUTH:
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003476#ifdef CONFIG_TESTING_OPTIONS
3477 if (wpa_s->ignore_auth_resp) {
3478 wpa_printf(MSG_INFO,
3479 "EVENT_DEAUTH - ignore_auth_resp active!");
3480 break;
3481 }
3482#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003483 wpas_event_deauth(wpa_s,
3484 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003485 break;
3486 case EVENT_MICHAEL_MIC_FAILURE:
3487 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3488 break;
3489#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003490 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003491 if (wpa_s->own_scan_requested ||
3492 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003493 struct os_reltime diff;
3494
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003495 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003496 os_reltime_sub(&wpa_s->scan_start_time,
3497 &wpa_s->scan_trigger_time, &diff);
3498 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3499 diff.sec, diff.usec);
3500 wpa_s->own_scan_requested = 0;
3501 wpa_s->own_scan_running = 1;
3502 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3503 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003504 wpa_msg_ctrl(wpa_s, MSG_INFO,
3505 WPA_EVENT_SCAN_STARTED "id=%u",
3506 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003507 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003508 wpa_msg_ctrl(wpa_s, MSG_INFO,
3509 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003510 }
3511 } else {
3512 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003513 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003514 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003515 }
3516 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003517 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08003518 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3519 wpa_s->scan_res_handler = NULL;
3520 wpa_s->own_scan_running = 0;
3521 wpa_s->radio->external_scan_running = 0;
3522 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
3523 break;
3524 }
3525
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003526 if (!(data && data->scan_info.external_scan) &&
3527 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003528 struct os_reltime now, diff;
3529 os_get_reltime(&now);
3530 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3531 wpa_s->scan_start_time.sec = 0;
3532 wpa_s->scan_start_time.usec = 0;
3533 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3534 diff.sec, diff.usec);
3535 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003536 if (wpa_supplicant_event_scan_results(wpa_s, data))
3537 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003538 if (!(data && data->scan_info.external_scan))
3539 wpa_s->own_scan_running = 0;
3540 if (data && data->scan_info.nl_scan_event)
3541 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003542 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003543 break;
3544#endif /* CONFIG_NO_SCAN_PROCESSING */
3545 case EVENT_ASSOCINFO:
3546 wpa_supplicant_event_associnfo(wpa_s, data);
3547 break;
3548 case EVENT_INTERFACE_STATUS:
3549 wpa_supplicant_event_interface_status(wpa_s, data);
3550 break;
3551 case EVENT_PMKID_CANDIDATE:
3552 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3553 break;
3554#ifdef CONFIG_PEERKEY
3555 case EVENT_STKSTART:
3556 wpa_supplicant_event_stkstart(wpa_s, data);
3557 break;
3558#endif /* CONFIG_PEERKEY */
3559#ifdef CONFIG_TDLS
3560 case EVENT_TDLS:
3561 wpa_supplicant_event_tdls(wpa_s, data);
3562 break;
3563#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003564#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003565 case EVENT_WNM:
3566 wpa_supplicant_event_wnm(wpa_s, data);
3567 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003568#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003569#ifdef CONFIG_IEEE80211R
3570 case EVENT_FT_RESPONSE:
3571 wpa_supplicant_event_ft_response(wpa_s, data);
3572 break;
3573#endif /* CONFIG_IEEE80211R */
3574#ifdef CONFIG_IBSS_RSN
3575 case EVENT_IBSS_RSN_START:
3576 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3577 break;
3578#endif /* CONFIG_IBSS_RSN */
3579 case EVENT_ASSOC_REJECT:
3580 if (data->assoc_reject.bssid)
3581 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07003582 "bssid=" MACSTR " status_code=%u%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003583 MAC2STR(data->assoc_reject.bssid),
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07003584 data->assoc_reject.status_code,
3585 data->assoc_reject.timed_out ? " timeout" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003586 else
3587 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07003588 "status_code=%u%s",
3589 data->assoc_reject.status_code,
3590 data->assoc_reject.timed_out ? " timeout" : "");
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003591 wpa_s->assoc_status_code = data->assoc_reject.status_code;
3592 wpas_notify_assoc_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003593 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3594 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07003595 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003596 const u8 *bssid = data->assoc_reject.bssid;
3597 if (bssid == NULL || is_zero_ether_addr(bssid))
3598 bssid = wpa_s->pending_bssid;
3599 wpas_connection_failed(wpa_s, bssid);
3600 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003601 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003602 break;
3603 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003604 /* It is possible to get this event from earlier connection */
3605 if (wpa_s->current_ssid &&
3606 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3607 wpa_dbg(wpa_s, MSG_DEBUG,
3608 "Ignore AUTH_TIMED_OUT in mesh configuration");
3609 break;
3610 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003611 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3612 sme_event_auth_timed_out(wpa_s, data);
3613 break;
3614 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003615 /* It is possible to get this event from earlier connection */
3616 if (wpa_s->current_ssid &&
3617 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3618 wpa_dbg(wpa_s, MSG_DEBUG,
3619 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3620 break;
3621 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003622 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3623 sme_event_assoc_timed_out(wpa_s, data);
3624 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003625 case EVENT_TX_STATUS:
3626 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3627 " type=%d stype=%d",
3628 MAC2STR(data->tx_status.dst),
3629 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003630#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003631 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003632#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003633 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3634 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003635 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003636 wpa_s, data->tx_status.dst,
3637 data->tx_status.data,
3638 data->tx_status.data_len,
3639 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003640 OFFCHANNEL_SEND_ACTION_SUCCESS :
3641 OFFCHANNEL_SEND_ACTION_NO_ACK);
3642#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003643 break;
3644 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003645#endif /* CONFIG_AP */
3646#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003647 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003648 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003649 /*
3650 * Catch TX status events for Action frames we sent via group
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003651 * interface in GO mode, or via standalone AP interface.
3652 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
3653 * except when the primary interface is used as a GO interface
3654 * (for drivers which do not have group interface concurrency)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003655 */
3656 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3657 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003658 os_memcmp(wpa_s->p2pdev->pending_action_dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003659 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003660 offchannel_send_action_tx_status(
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003661 wpa_s->p2pdev, data->tx_status.dst,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003662 data->tx_status.data,
3663 data->tx_status.data_len,
3664 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003665 OFFCHANNEL_SEND_ACTION_SUCCESS :
3666 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003667 break;
3668 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003669#endif /* CONFIG_OFFCHANNEL */
3670#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003671 switch (data->tx_status.type) {
3672 case WLAN_FC_TYPE_MGMT:
3673 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3674 data->tx_status.data_len,
3675 data->tx_status.stype,
3676 data->tx_status.ack);
3677 break;
3678 case WLAN_FC_TYPE_DATA:
3679 ap_tx_status(wpa_s, data->tx_status.dst,
3680 data->tx_status.data,
3681 data->tx_status.data_len,
3682 data->tx_status.ack);
3683 break;
3684 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003685#endif /* CONFIG_AP */
3686 break;
3687#ifdef CONFIG_AP
3688 case EVENT_EAPOL_TX_STATUS:
3689 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3690 data->eapol_tx_status.data,
3691 data->eapol_tx_status.data_len,
3692 data->eapol_tx_status.ack);
3693 break;
3694 case EVENT_DRIVER_CLIENT_POLL_OK:
3695 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003696 break;
3697 case EVENT_RX_FROM_UNKNOWN:
3698 if (wpa_s->ap_iface == NULL)
3699 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003700 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3701 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003702 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003703 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003704 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07003705 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003706
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07003707 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
3708 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
3709 data->ch_switch.freq,
3710 data->ch_switch.ht_enabled,
3711 data->ch_switch.ch_offset,
3712 channel_width_to_string(data->ch_switch.ch_width),
3713 data->ch_switch.cf1,
3714 data->ch_switch.cf2);
3715
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003716 wpa_s->assoc_freq = data->ch_switch.freq;
3717 wpa_s->current_ssid->frequency = data->ch_switch.freq;
3718
3719 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
3720 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
3721 wpa_s->current_ssid->mode ==
3722 WPAS_MODE_P2P_GROUP_FORMATION) {
3723 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3724 data->ch_switch.ht_enabled,
3725 data->ch_switch.ch_offset,
3726 data->ch_switch.ch_width,
3727 data->ch_switch.cf1,
3728 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003729 }
3730
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003731 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003732 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003733#ifdef NEED_AP_MLME
3734 case EVENT_DFS_RADAR_DETECTED:
3735 if (data)
3736 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3737 break;
3738 case EVENT_DFS_CAC_STARTED:
3739 if (data)
3740 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3741 break;
3742 case EVENT_DFS_CAC_FINISHED:
3743 if (data)
3744 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3745 break;
3746 case EVENT_DFS_CAC_ABORTED:
3747 if (data)
3748 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3749 break;
3750 case EVENT_DFS_NOP_FINISHED:
3751 if (data)
3752 wpas_event_dfs_cac_nop_finished(wpa_s,
3753 &data->dfs_event);
3754 break;
3755#endif /* NEED_AP_MLME */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003756#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003757 case EVENT_RX_MGMT: {
3758 u16 fc, stype;
3759 const struct ieee80211_mgmt *mgmt;
3760
Dmitry Shmidt818ea482014-03-10 13:15:21 -07003761#ifdef CONFIG_TESTING_OPTIONS
3762 if (wpa_s->ext_mgmt_frame_handling) {
3763 struct rx_mgmt *rx = &data->rx_mgmt;
3764 size_t hex_len = 2 * rx->frame_len + 1;
3765 char *hex = os_malloc(hex_len);
3766 if (hex) {
3767 wpa_snprintf_hex(hex, hex_len,
3768 rx->frame, rx->frame_len);
3769 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3770 rx->freq, rx->datarate, rx->ssi_signal,
3771 hex);
3772 os_free(hex);
3773 }
3774 break;
3775 }
3776#endif /* CONFIG_TESTING_OPTIONS */
3777
Dmitry Shmidt04949592012-07-19 12:16:46 -07003778 mgmt = (const struct ieee80211_mgmt *)
3779 data->rx_mgmt.frame;
3780 fc = le_to_host16(mgmt->frame_control);
3781 stype = WLAN_FC_GET_STYPE(fc);
3782
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003783#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003784 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003785#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003786#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003787 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003788 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003789 const u8 *src = mgmt->sa;
Dmitry Shmidte4663042016-04-04 10:07:49 -07003790 const u8 *ie;
3791 size_t ie_len;
3792
3793 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
3794 ie_len = data->rx_mgmt.frame_len -
3795 IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003796 wpas_p2p_probe_req_rx(
3797 wpa_s, src, mgmt->da,
3798 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003799 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003800 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003801 break;
3802 }
3803#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003804#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003805 if (wpa_s->current_ssid &&
3806 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3807 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003808 data->rx_mgmt.frame_len >= 30) {
3809 wpa_supplicant_event_ibss_auth(wpa_s, data);
3810 break;
3811 }
3812#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003813
3814 if (stype == WLAN_FC_STYPE_ACTION) {
3815 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003816 wpa_s, data->rx_mgmt.frame,
3817 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003818 data->rx_mgmt.freq,
3819 data->rx_mgmt.ssi_signal);
3820 break;
3821 }
3822
3823 if (wpa_s->ifmsh) {
3824 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003825 break;
3826 }
3827
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003828 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3829 "management frame in non-AP mode");
3830 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003831#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003832 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003833
3834 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003835 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
3836 const u8 *ie;
3837 size_t ie_len;
3838
3839 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
3840 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003841
3842 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3843 mgmt->bssid, ie, ie_len,
3844 data->rx_mgmt.ssi_signal);
3845 }
3846
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003847 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003848#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003849 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003850 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003851 case EVENT_RX_PROBE_REQ:
3852 if (data->rx_probe_req.sa == NULL ||
3853 data->rx_probe_req.ie == NULL)
3854 break;
3855#ifdef CONFIG_AP
3856 if (wpa_s->ap_iface) {
3857 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3858 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003859 data->rx_probe_req.da,
3860 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003861 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003862 data->rx_probe_req.ie_len,
3863 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003864 break;
3865 }
3866#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003867 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003868 data->rx_probe_req.da,
3869 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003870 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003871 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003872 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003873 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003874 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003875 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003876#ifdef CONFIG_OFFCHANNEL
3877 offchannel_remain_on_channel_cb(
3878 wpa_s, data->remain_on_channel.freq,
3879 data->remain_on_channel.duration);
3880#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003881 wpas_p2p_remain_on_channel_cb(
3882 wpa_s, data->remain_on_channel.freq,
3883 data->remain_on_channel.duration);
3884 break;
3885 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003886#ifdef CONFIG_OFFCHANNEL
3887 offchannel_cancel_remain_on_channel_cb(
3888 wpa_s, data->remain_on_channel.freq);
3889#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003890 wpas_p2p_cancel_remain_on_channel_cb(
3891 wpa_s, data->remain_on_channel.freq);
3892 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003893 case EVENT_EAPOL_RX:
3894 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3895 data->eapol_rx.data,
3896 data->eapol_rx.data_len);
3897 break;
3898 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003899 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3900 "above=%d signal=%d noise=%d txrate=%d",
3901 data->signal_change.above_threshold,
3902 data->signal_change.current_signal,
3903 data->signal_change.current_noise,
3904 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003905 wpa_bss_update_level(wpa_s->current_bss,
3906 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003907 bgscan_notify_signal_change(
3908 wpa_s, data->signal_change.above_threshold,
3909 data->signal_change.current_signal,
3910 data->signal_change.current_noise,
3911 data->signal_change.current_txrate);
3912 break;
3913 case EVENT_INTERFACE_ENABLED:
3914 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3915 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003916 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003917 if (wpa_s->p2p_mgmt) {
3918 wpa_supplicant_set_state(wpa_s,
3919 WPA_DISCONNECTED);
3920 break;
3921 }
3922
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003923#ifdef CONFIG_AP
3924 if (!wpa_s->ap_iface) {
3925 wpa_supplicant_set_state(wpa_s,
3926 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003927 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003928 wpa_supplicant_req_scan(wpa_s, 0, 0);
3929 } else
3930 wpa_supplicant_set_state(wpa_s,
3931 WPA_COMPLETED);
3932#else /* CONFIG_AP */
3933 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3934 wpa_supplicant_req_scan(wpa_s, 0, 0);
3935#endif /* CONFIG_AP */
3936 }
3937 break;
3938 case EVENT_INTERFACE_DISABLED:
3939 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003940#ifdef CONFIG_P2P
3941 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3942 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3943 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3944 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003945 * Mark interface disabled if this happens to end up not
3946 * being removed as a separate P2P group interface.
3947 */
3948 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3949 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003950 * The interface was externally disabled. Remove
3951 * it assuming an external entity will start a
3952 * new session if needed.
3953 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003954 if (wpa_s->current_ssid &&
3955 wpa_s->current_ssid->p2p_group)
3956 wpas_p2p_interface_unavailable(wpa_s);
3957 else
3958 wpas_p2p_disconnect(wpa_s);
3959 /*
3960 * wpa_s instance may have been freed, so must not use
3961 * it here anymore.
3962 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003963 break;
3964 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003965 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3966 p2p_in_progress(wpa_s->global->p2p) > 1) {
3967 /* This radio work will be cancelled, so clear P2P
3968 * state as well.
3969 */
3970 p2p_stop_find(wpa_s->global->p2p);
3971 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003972#endif /* CONFIG_P2P */
3973
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003974 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3975 /*
3976 * Indicate disconnection to keep ctrl_iface events
3977 * consistent.
3978 */
3979 wpa_supplicant_event_disassoc(
3980 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3981 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003982 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003983 wpa_bss_flush(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003984 radio_remove_works(wpa_s, NULL, 0);
3985
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003986 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3987 break;
3988 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003989 wpa_supplicant_update_channel_list(
3990 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003991 break;
3992 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003993 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003994 break;
3995 case EVENT_BEST_CHANNEL:
3996 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3997 "(%d %d %d)",
3998 data->best_chan.freq_24, data->best_chan.freq_5,
3999 data->best_chan.freq_overall);
4000 wpa_s->best_24_freq = data->best_chan.freq_24;
4001 wpa_s->best_5_freq = data->best_chan.freq_5;
4002 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004003 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
4004 data->best_chan.freq_5,
4005 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004006 break;
4007 case EVENT_UNPROT_DEAUTH:
4008 wpa_supplicant_event_unprot_deauth(wpa_s,
4009 &data->unprot_deauth);
4010 break;
4011 case EVENT_UNPROT_DISASSOC:
4012 wpa_supplicant_event_unprot_disassoc(wpa_s,
4013 &data->unprot_disassoc);
4014 break;
4015 case EVENT_STATION_LOW_ACK:
4016#ifdef CONFIG_AP
4017 if (wpa_s->ap_iface && data)
4018 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
4019 data->low_ack.addr);
4020#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004021#ifdef CONFIG_TDLS
4022 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07004023 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
4024 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004025#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004026 break;
4027 case EVENT_IBSS_PEER_LOST:
4028#ifdef CONFIG_IBSS_RSN
4029 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
4030#endif /* CONFIG_IBSS_RSN */
4031 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004032 case EVENT_DRIVER_GTK_REKEY:
4033 if (os_memcmp(data->driver_gtk_rekey.bssid,
4034 wpa_s->bssid, ETH_ALEN))
4035 break;
4036 if (!wpa_s->wpa)
4037 break;
4038 wpa_sm_update_replay_ctr(wpa_s->wpa,
4039 data->driver_gtk_rekey.replay_ctr);
4040 break;
4041 case EVENT_SCHED_SCAN_STOPPED:
4042 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004043 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004044 wpa_supplicant_notify_scanning(wpa_s, 0);
4045
4046 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4047 break;
4048
4049 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08004050 * Start a new sched scan to continue searching for more SSIDs
4051 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004052 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07004053 if (wpa_s->sched_scan_timed_out) {
4054 wpa_supplicant_req_sched_scan(wpa_s);
4055 } else if (wpa_s->pno_sched_pending) {
4056 wpa_s->pno_sched_pending = 0;
4057 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07004058 } else if (resched) {
4059 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08004060 }
4061
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004062 break;
4063 case EVENT_WPS_BUTTON_PUSHED:
4064#ifdef CONFIG_WPS
4065 wpas_wps_start_pbc(wpa_s, NULL, 0);
4066#endif /* CONFIG_WPS */
4067 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004068 case EVENT_AVOID_FREQUENCIES:
4069 wpa_supplicant_notify_avoid_freq(wpa_s, data);
4070 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004071 case EVENT_CONNECT_FAILED_REASON:
4072#ifdef CONFIG_AP
4073 if (!wpa_s->ap_iface || !data)
4074 break;
4075 hostapd_event_connect_failed_reason(
4076 wpa_s->ap_iface->bss[0],
4077 data->connect_failed_reason.addr,
4078 data->connect_failed_reason.code);
4079#endif /* CONFIG_AP */
4080 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004081 case EVENT_NEW_PEER_CANDIDATE:
4082#ifdef CONFIG_MESH
4083 if (!wpa_s->ifmsh || !data)
4084 break;
4085 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4086 data->mesh_peer.ies,
4087 data->mesh_peer.ie_len);
4088#endif /* CONFIG_MESH */
4089 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004090 case EVENT_SURVEY:
4091#ifdef CONFIG_AP
4092 if (!wpa_s->ap_iface)
4093 break;
4094 hostapd_event_get_survey(wpa_s->ap_iface,
4095 &data->survey_results);
4096#endif /* CONFIG_AP */
4097 break;
4098 case EVENT_ACS_CHANNEL_SELECTED:
4099#ifdef CONFIG_ACS
4100 if (!wpa_s->ap_iface)
4101 break;
4102 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4103 &data->acs_selected_channels);
4104#endif /* CONFIG_ACS */
4105 break;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07004106 case EVENT_P2P_LO_STOP:
4107#ifdef CONFIG_P2P
4108 wpa_s->p2p_lo_started = 0;
4109 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
4110 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
4111 data->p2p_lo_stop.reason_code);
4112#endif /* CONFIG_P2P */
4113 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004114 default:
4115 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4116 break;
4117 }
4118}
Dmitry Shmidte4663042016-04-04 10:07:49 -07004119
4120
4121void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
4122 union wpa_event_data *data)
4123{
4124 struct wpa_supplicant *wpa_s;
4125
4126 if (event != EVENT_INTERFACE_STATUS)
4127 return;
4128
4129 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
4130 if (wpa_s && wpa_s->driver->get_ifindex) {
4131 unsigned int ifindex;
4132
4133 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
4134 if (ifindex != data->interface_status.ifindex) {
4135 wpa_dbg(wpa_s, MSG_DEBUG,
4136 "interface status ifindex %d mismatch (%d)",
4137 ifindex, data->interface_status.ifindex);
4138 return;
4139 }
4140 }
4141#ifdef CONFIG_MATCH_IFACE
4142 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
4143 struct wpa_interface *wpa_i;
4144
4145 wpa_i = wpa_supplicant_match_iface(
4146 ctx, data->interface_status.ifname);
4147 if (!wpa_i)
4148 return;
4149 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
4150 os_free(wpa_i);
4151 if (wpa_s)
4152 wpa_s->matched = 1;
4153 }
4154#endif /* CONFIG_MATCH_IFACE */
4155
4156 if (wpa_s)
4157 wpa_supplicant_event(wpa_s, event, data);
4158}