blob: a89ab298be8a4aafc217331564b36591573269d7 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003 * Copyright (c) 2003-2014, 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 Shmidt61d9df32012-08-29 16:22:06 -070026#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "notify.h"
28#include "common/ieee802_11_defs.h"
29#include "common/ieee802_11_common.h"
30#include "crypto/random.h"
31#include "blacklist.h"
32#include "wpas_glue.h"
33#include "wps_supplicant.h"
34#include "ibss_rsn.h"
35#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080036#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "p2p_supplicant.h"
38#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070039#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "ap.h"
41#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080043#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070044#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080045#include "mesh.h"
46#include "mesh_mpm.h"
47#include "wmm_ac.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048
49
Dmitry Shmidt34af3062013-07-11 10:46:32 -070050#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070051static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080052 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070053#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080054
55
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070056static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
57 struct wpa_ssid *ssid)
58{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080059 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070060
61 if (ssid == NULL || ssid->disabled_until.sec == 0)
62 return 0;
63
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080064 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070065 if (ssid->disabled_until.sec > now.sec)
66 return ssid->disabled_until.sec - now.sec;
67
68 wpas_clear_temp_disabled(wpa_s, ssid, 0);
69
70 return 0;
71}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070072
73
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080074static struct wpa_bss * wpa_supplicant_get_new_bss(
75 struct wpa_supplicant *wpa_s, const u8 *bssid)
76{
77 struct wpa_bss *bss = NULL;
78 struct wpa_ssid *ssid = wpa_s->current_ssid;
79
80 if (ssid->ssid_len > 0)
81 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
82 if (!bss)
83 bss = wpa_bss_get_bssid(wpa_s, bssid);
84
85 return bss;
86}
87
88
Jouni Malinen5c879ee2014-08-18 11:04:56 -070089static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
90{
91 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
92
93 if (!bss) {
94 wpa_supplicant_update_scan_results(wpa_s);
95
96 /* Get the BSS from the new scan results */
97 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
98 }
99
100 if (bss)
101 wpa_s->current_bss = bss;
102}
103
104
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
106{
107 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700108 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700110 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
111 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112 return 0;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700113 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114
115 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
116 "information");
117 ssid = wpa_supplicant_get_ssid(wpa_s);
118 if (ssid == NULL) {
119 wpa_msg(wpa_s, MSG_INFO,
120 "No network configuration found for the current AP");
121 return -1;
122 }
123
Dmitry Shmidt04949592012-07-19 12:16:46 -0700124 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700125 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
126 return -1;
127 }
128
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800129 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
130 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
131 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
132 return -1;
133 }
134
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700135 res = wpas_temp_disabled(wpa_s, ssid);
136 if (res > 0) {
137 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
138 "disabled for %d second(s)", res);
139 return -1;
140 }
141
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700142 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
143 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800144 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700145 u8 wpa_ie[80];
146 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800147 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
148 wpa_ie, &wpa_ie_len) < 0)
149 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150 } else {
151 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
152 }
153
154 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
155 eapol_sm_invalidate_cached_session(wpa_s->eapol);
156 old_ssid = wpa_s->current_ssid;
157 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800158
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700159 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
162 wpa_supplicant_initiate_eapol(wpa_s);
163 if (old_ssid != wpa_s->current_ssid)
164 wpas_notify_network_changed(wpa_s);
165
166 return 0;
167}
168
169
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800170void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171{
172 struct wpa_supplicant *wpa_s = eloop_ctx;
173
174 if (wpa_s->countermeasures) {
175 wpa_s->countermeasures = 0;
176 wpa_drv_set_countermeasures(wpa_s, 0);
177 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
178 wpa_supplicant_req_scan(wpa_s, 0, 0);
179 }
180}
181
182
183void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
184{
185 int bssid_changed;
186
Dmitry Shmidt04949592012-07-19 12:16:46 -0700187 wnm_bss_keep_alive_deinit(wpa_s);
188
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189#ifdef CONFIG_IBSS_RSN
190 ibss_rsn_deinit(wpa_s->ibss_rsn);
191 wpa_s->ibss_rsn = NULL;
192#endif /* CONFIG_IBSS_RSN */
193
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700194#ifdef CONFIG_AP
195 wpa_supplicant_ap_deinit(wpa_s);
196#endif /* CONFIG_AP */
197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
199 return;
200
201 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
202 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
203 os_memset(wpa_s->bssid, 0, ETH_ALEN);
204 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800205 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800206#ifdef CONFIG_P2P
207 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
208#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700209 wpa_s->current_bss = NULL;
210 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700211
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700212 if (bssid_changed)
213 wpas_notify_bssid_changed(wpa_s);
214
215 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
216 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
217 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
218 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
219 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700220 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700221 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700222 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800223
224 wpas_rrm_reset(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700225}
226
227
228static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
229{
230 struct wpa_ie_data ie;
231 int pmksa_set = -1;
232 size_t i;
233
234 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
235 ie.pmkid == NULL)
236 return;
237
238 for (i = 0; i < ie.num_pmkid; i++) {
239 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
240 ie.pmkid + i * PMKID_LEN,
241 NULL, NULL, 0);
242 if (pmksa_set == 0) {
243 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
244 break;
245 }
246 }
247
248 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
249 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
250}
251
252
253static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
254 union wpa_event_data *data)
255{
256 if (data == NULL) {
257 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
258 "event");
259 return;
260 }
261 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
262 " index=%d preauth=%d",
263 MAC2STR(data->pmkid_candidate.bssid),
264 data->pmkid_candidate.index,
265 data->pmkid_candidate.preauth);
266
267 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
268 data->pmkid_candidate.index,
269 data->pmkid_candidate.preauth);
270}
271
272
273static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
274{
275 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
276 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
277 return 0;
278
279#ifdef IEEE8021X_EAPOL
280 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
281 wpa_s->current_ssid &&
282 !(wpa_s->current_ssid->eapol_flags &
283 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
284 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
285 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
286 * plaintext or static WEP keys). */
287 return 0;
288 }
289#endif /* IEEE8021X_EAPOL */
290
291 return 1;
292}
293
294
295/**
296 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
297 * @wpa_s: pointer to wpa_supplicant data
298 * @ssid: Configuration data for the network
299 * Returns: 0 on success, -1 on failure
300 *
301 * This function is called when starting authentication with a network that is
302 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
303 */
304int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
305 struct wpa_ssid *ssid)
306{
307#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800308#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700309 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700311 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
312 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700313 return 0;
314
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700315 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 sim = 1;
317 aka = 1;
318 } else {
319 struct eap_method_type *eap = ssid->eap.eap_methods;
320 while (eap->vendor != EAP_VENDOR_IETF ||
321 eap->method != EAP_TYPE_NONE) {
322 if (eap->vendor == EAP_VENDOR_IETF) {
323 if (eap->method == EAP_TYPE_SIM)
324 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700325 else if (eap->method == EAP_TYPE_AKA ||
326 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700327 aka = 1;
328 }
329 eap++;
330 }
331 }
332
333 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
334 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700335 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
336 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
337 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338 aka = 0;
339
340 if (!sim && !aka) {
341 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
342 "use SIM, but neither EAP-SIM nor EAP-AKA are "
343 "enabled");
344 return 0;
345 }
346
347 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
348 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700349
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700350 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351 if (wpa_s->scard == NULL) {
352 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
353 "(pcsc-lite)");
354 return -1;
355 }
356 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
357 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800358#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359#endif /* IEEE8021X_EAPOL */
360
361 return 0;
362}
363
364
365#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700366
367static int has_wep_key(struct wpa_ssid *ssid)
368{
369 int i;
370
371 for (i = 0; i < NUM_WEP_KEYS; i++) {
372 if (ssid->wep_key_len[i])
373 return 1;
374 }
375
376 return 0;
377}
378
379
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700380static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381 struct wpa_ssid *ssid)
382{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700383 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700384
385 if (ssid->mixed_cell)
386 return 1;
387
388#ifdef CONFIG_WPS
389 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
390 return 1;
391#endif /* CONFIG_WPS */
392
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700393 if (has_wep_key(ssid))
394 privacy = 1;
395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396#ifdef IEEE8021X_EAPOL
397 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
398 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
399 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
400 privacy = 1;
401#endif /* IEEE8021X_EAPOL */
402
Jouni Malinen75ecf522011-06-27 15:19:46 -0700403 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
404 privacy = 1;
405
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800406 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
407 privacy = 1;
408
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700409 if (bss->caps & IEEE80211_CAP_PRIVACY)
410 return privacy;
411 return !privacy;
412}
413
414
415static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
416 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700417 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700418{
419 struct wpa_ie_data ie;
420 int proto_match = 0;
421 const u8 *rsn_ie, *wpa_ie;
422 int ret;
423 int wep_ok;
424
425 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
426 if (ret >= 0)
427 return ret;
428
429 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
430 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
431 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
432 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
433 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
434
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700435 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
437 proto_match++;
438
439 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
440 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
441 "failed");
442 break;
443 }
444
445 if (wep_ok &&
446 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
447 {
448 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
449 "in RSN IE");
450 return 1;
451 }
452
453 if (!(ie.proto & ssid->proto)) {
454 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
455 "mismatch");
456 break;
457 }
458
459 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
460 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
461 "cipher mismatch");
462 break;
463 }
464
465 if (!(ie.group_cipher & ssid->group_cipher)) {
466 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
467 "cipher mismatch");
468 break;
469 }
470
471 if (!(ie.key_mgmt & ssid->key_mgmt)) {
472 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
473 "mismatch");
474 break;
475 }
476
477#ifdef CONFIG_IEEE80211W
478 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800479 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
480 wpa_s->conf->pmf : ssid->ieee80211w) ==
481 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
483 "frame protection");
484 break;
485 }
486#endif /* CONFIG_IEEE80211W */
487
488 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
489 return 1;
490 }
491
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700492 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
494 proto_match++;
495
496 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
497 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
498 "failed");
499 break;
500 }
501
502 if (wep_ok &&
503 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
504 {
505 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
506 "in WPA IE");
507 return 1;
508 }
509
510 if (!(ie.proto & ssid->proto)) {
511 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
512 "mismatch");
513 break;
514 }
515
516 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
517 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
518 "cipher mismatch");
519 break;
520 }
521
522 if (!(ie.group_cipher & ssid->group_cipher)) {
523 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
524 "cipher mismatch");
525 break;
526 }
527
528 if (!(ie.key_mgmt & ssid->key_mgmt)) {
529 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
530 "mismatch");
531 break;
532 }
533
534 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
535 return 1;
536 }
537
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700538 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
539 !rsn_ie) {
540 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
541 return 1;
542 }
543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
545 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
546 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
547 return 0;
548 }
549
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800550 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
551 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
552 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
553 return 1;
554 }
555
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
557 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
558 return 1;
559 }
560
561 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
562 "WPA/WPA2");
563
564 return 0;
565}
566
567
568static int freq_allowed(int *freqs, int freq)
569{
570 int i;
571
572 if (freqs == NULL)
573 return 1;
574
575 for (i = 0; freqs[i]; i++)
576 if (freqs[i] == freq)
577 return 1;
578 return 0;
579}
580
581
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700582static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800583{
584 const struct hostapd_hw_modes *mode = NULL, *modes;
585 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
586 const u8 *rate_ie;
587 int i, j, k;
588
589 if (bss->freq == 0)
590 return 1; /* Cannot do matching without knowing band */
591
592 modes = wpa_s->hw.modes;
593 if (modes == NULL) {
594 /*
595 * The driver does not provide any additional information
596 * about the utilized hardware, so allow the connection attempt
597 * to continue.
598 */
599 return 1;
600 }
601
602 for (i = 0; i < wpa_s->hw.num_modes; i++) {
603 for (j = 0; j < modes[i].num_channels; j++) {
604 int freq = modes[i].channels[j].freq;
605 if (freq == bss->freq) {
606 if (mode &&
607 mode->mode == HOSTAPD_MODE_IEEE80211G)
608 break; /* do not allow 802.11b replace
609 * 802.11g */
610 mode = &modes[i];
611 break;
612 }
613 }
614 }
615
616 if (mode == NULL)
617 return 0;
618
619 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700620 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800621 if (rate_ie == NULL)
622 continue;
623
624 for (j = 2; j < rate_ie[1] + 2; j++) {
625 int flagged = !!(rate_ie[j] & 0x80);
626 int r = (rate_ie[j] & 0x7f) * 5;
627
628 /*
629 * IEEE Std 802.11n-2009 7.3.2.2:
630 * The new BSS Membership selector value is encoded
631 * like a legacy basic rate, but it is not a rate and
632 * only indicates if the BSS members are required to
633 * support the mandatory features of Clause 20 [HT PHY]
634 * in order to join the BSS.
635 */
636 if (flagged && ((rate_ie[j] & 0x7f) ==
637 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
638 if (!ht_supported(mode)) {
639 wpa_dbg(wpa_s, MSG_DEBUG,
640 " hardware does not support "
641 "HT PHY");
642 return 0;
643 }
644 continue;
645 }
646
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700647 /* There's also a VHT selector for 802.11ac */
648 if (flagged && ((rate_ie[j] & 0x7f) ==
649 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
650 if (!vht_supported(mode)) {
651 wpa_dbg(wpa_s, MSG_DEBUG,
652 " hardware does not support "
653 "VHT PHY");
654 return 0;
655 }
656 continue;
657 }
658
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800659 if (!flagged)
660 continue;
661
662 /* check for legacy basic rates */
663 for (k = 0; k < mode->num_rates; k++) {
664 if (mode->rates[k] == r)
665 break;
666 }
667 if (k == mode->num_rates) {
668 /*
669 * IEEE Std 802.11-2007 7.3.2.2 demands that in
670 * order to join a BSS all required rates
671 * have to be supported by the hardware.
672 */
673 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
674 "not support required rate %d.%d Mbps",
675 r / 10, r % 10);
676 return 0;
677 }
678 }
679 }
680
681 return 1;
682}
683
684
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800685/*
686 * Test whether BSS is in an ESS.
687 * This is done differently in DMG (60 GHz) and non-DMG bands
688 */
689static int bss_is_ess(struct wpa_bss *bss)
690{
691 if (bss_is_dmg(bss)) {
692 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
693 IEEE80211_CAP_DMG_AP;
694 }
695
696 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
697 IEEE80211_CAP_ESS);
698}
699
700
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800701static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
702{
703 size_t i;
704
705 for (i = 0; i < ETH_ALEN; i++) {
706 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
707 return 0;
708 }
709 return 1;
710}
711
712
713static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
714{
715 size_t i;
716
717 for (i = 0; i < num; i++) {
718 const u8 *a = list + i * ETH_ALEN * 2;
719 const u8 *m = a + ETH_ALEN;
720
721 if (match_mac_mask(a, addr, m))
722 return 1;
723 }
724 return 0;
725}
726
727
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700729 int i, struct wpa_bss *bss,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800730 struct wpa_ssid *group,
731 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700732{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700733 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700734 int wpa;
735 struct wpa_blacklist *e;
736 const u8 *ie;
737 struct wpa_ssid *ssid;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800738 int osen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700739
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700740 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700741 wpa_ie_len = ie ? ie[1] : 0;
742
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700743 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744 rsn_ie_len = ie ? ie[1] : 0;
745
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800746 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
747 osen = ie != NULL;
748
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800750 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700751 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700753 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
754 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
755 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800756 " p2p" : "",
757 osen ? " osen=1" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700758
759 e = wpa_blacklist_get(wpa_s, bss->bssid);
760 if (e) {
761 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700762 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 /*
764 * When only a single network is enabled, we can
765 * trigger blacklisting on the first failure. This
766 * should not be done with multiple enabled networks to
767 * avoid getting forced to move into a worse ESS on
768 * single error if there are no other BSSes of the
769 * current ESS.
770 */
771 limit = 0;
772 }
773 if (e->count > limit) {
774 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
775 "(count=%d limit=%d)", e->count, limit);
776 return NULL;
777 }
778 }
779
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700780 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
782 return NULL;
783 }
784
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800785 if (disallowed_bssid(wpa_s, bss->bssid)) {
786 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
787 return NULL;
788 }
789
790 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
791 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
792 return NULL;
793 }
794
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700795 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
796
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800797 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700799 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700800
Dmitry Shmidt04949592012-07-19 12:16:46 -0700801 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
803 continue;
804 }
805
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700806 res = wpas_temp_disabled(wpa_s, ssid);
807 if (res > 0) {
808 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
809 "temporarily for %d second(s)", res);
810 continue;
811 }
812
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813#ifdef CONFIG_WPS
814 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
815 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
816 "(WPS)");
817 continue;
818 }
819
820 if (wpa && ssid->ssid_len == 0 &&
821 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
822 check_ssid = 0;
823
824 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
825 /* Only allow wildcard SSID match if an AP
826 * advertises active WPS operation that matches
827 * with our mode. */
828 check_ssid = 1;
829 if (ssid->ssid_len == 0 &&
830 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
831 check_ssid = 0;
832 }
833#endif /* CONFIG_WPS */
834
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800835 if (ssid->bssid_set && ssid->ssid_len == 0 &&
836 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
837 check_ssid = 0;
838
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700839 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700840 (bss->ssid_len != ssid->ssid_len ||
841 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
843 continue;
844 }
845
846 if (ssid->bssid_set &&
847 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
848 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
849 continue;
850 }
851
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800852 /* check blacklist */
853 if (ssid->num_bssid_blacklist &&
854 addr_in_list(bss->bssid, ssid->bssid_blacklist,
855 ssid->num_bssid_blacklist)) {
856 wpa_dbg(wpa_s, MSG_DEBUG,
857 " skip - BSSID blacklisted");
858 continue;
859 }
860
861 /* if there is a whitelist, only accept those APs */
862 if (ssid->num_bssid_whitelist &&
863 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
864 ssid->num_bssid_whitelist)) {
865 wpa_dbg(wpa_s, MSG_DEBUG,
866 " skip - BSSID not in whitelist");
867 continue;
868 }
869
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
871 continue;
872
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800873 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
875 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
876 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
877 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
878 "not allowed");
879 continue;
880 }
881
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700882 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
883 has_wep_key(ssid)) {
884 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
885 continue;
886 }
887
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800888 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
889 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
890 "not allowed");
891 continue;
892 }
893
Jouni Malinen75ecf522011-06-27 15:19:46 -0700894 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
896 "mismatch");
897 continue;
898 }
899
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800900 if (!bss_is_ess(bss)) {
901 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700902 continue;
903 }
904
905 if (!freq_allowed(ssid->freq_list, bss->freq)) {
906 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
907 "allowed");
908 continue;
909 }
910
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800911 if (!rate_match(wpa_s, bss)) {
912 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
913 "not match");
914 continue;
915 }
916
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -0700918 if (ssid->p2p_group &&
919 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
920 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
921 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
922 continue;
923 }
924
Dmitry Shmidt54605472013-11-08 11:10:19 -0800925 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
926 struct wpabuf *p2p_ie;
927 u8 dev_addr[ETH_ALEN];
928
929 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
930 if (ie == NULL) {
931 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
932 continue;
933 }
934 p2p_ie = wpa_bss_get_vendor_ie_multi(
935 bss, P2P_IE_VENDOR_TYPE);
936 if (p2p_ie == NULL) {
937 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
938 continue;
939 }
940
941 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
942 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
943 ETH_ALEN) != 0) {
944 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
945 wpabuf_free(p2p_ie);
946 continue;
947 }
948 wpabuf_free(p2p_ie);
949 }
950
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 /*
952 * TODO: skip the AP if its P2P IE has Group Formation
953 * bit set in the P2P Group Capability Bitmap and we
954 * are not in Group Formation with that device.
955 */
956#endif /* CONFIG_P2P */
957
958 /* Matching configuration found */
959 return ssid;
960 }
961
962 /* No matching configuration found */
963 return NULL;
964}
965
966
967static struct wpa_bss *
968wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700969 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800970 struct wpa_ssid **selected_ssid,
971 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700972{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700973 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700974
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800975 if (only_first_ssid)
976 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
977 group->id);
978 else
979 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
980 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700981
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700982 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
983 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800984 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
985 only_first_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986 if (!*selected_ssid)
987 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
989 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700990 MAC2STR(bss->bssid),
991 wpa_ssid_txt(bss->ssid, bss->ssid_len));
992 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700993 }
994
995 return NULL;
996}
997
998
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700999struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1000 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001001{
1002 struct wpa_bss *selected = NULL;
1003 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001004 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001006 if (wpa_s->last_scan_res == NULL ||
1007 wpa_s->last_scan_res_used == 0)
1008 return NULL; /* no scan results from last update */
1009
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001010 if (wpa_s->next_ssid) {
1011 struct wpa_ssid *ssid;
1012
1013 /* check that next_ssid is still valid */
1014 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1015 if (ssid == wpa_s->next_ssid)
1016 break;
1017 }
1018 next_ssid = ssid;
1019 wpa_s->next_ssid = NULL;
1020 }
1021
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001022 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001023 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1024 if (next_ssid && next_ssid->priority ==
1025 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001026 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001027 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001028 if (selected)
1029 break;
1030 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001031 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001032 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001033 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 if (selected)
1035 break;
1036 }
1037
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001038 if (selected == NULL && wpa_s->blacklist &&
1039 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1041 "blacklist and try again");
1042 wpa_blacklist_clear(wpa_s);
1043 wpa_s->blacklist_cleared++;
1044 } else if (selected == NULL)
1045 break;
1046 }
1047
1048 return selected;
1049}
1050
1051
1052static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1053 int timeout_sec, int timeout_usec)
1054{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001055 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001056 /*
1057 * No networks are enabled; short-circuit request so
1058 * we don't wait timeout seconds before transitioning
1059 * to INACTIVE state.
1060 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001061 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1062 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001063 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1064 return;
1065 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001066
1067 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001068 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1069}
1070
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001071
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001072int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001073 struct wpa_bss *selected,
1074 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075{
1076 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1077 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1078 "PBC session overlap");
1079#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001080 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1081 wpa_s->p2p_in_provisioning) {
1082 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1083 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001084 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001085 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086#endif /* CONFIG_P2P */
1087
1088#ifdef CONFIG_WPS
1089 wpas_wps_cancel(wpa_s);
1090#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001091 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001092 }
1093
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001094 wpa_msg(wpa_s, MSG_DEBUG,
1095 "Considering connect request: reassociate: %d selected: "
1096 MACSTR " bssid: " MACSTR " pending: " MACSTR
1097 " wpa_state: %s ssid=%p current_ssid=%p",
1098 wpa_s->reassociate, MAC2STR(selected->bssid),
1099 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1100 wpa_supplicant_state_txt(wpa_s->wpa_state),
1101 ssid, wpa_s->current_ssid);
1102
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 /*
1104 * Do not trigger new association unless the BSSID has changed or if
1105 * reassociation is requested. If we are in process of associating with
1106 * the selected BSSID, do not trigger new attempt.
1107 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001108 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1110 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1111 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001112 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1113 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1114 0) ||
1115 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1116 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001117 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1118 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001119 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001120 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001121 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1122 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123 wpa_supplicant_associate(wpa_s, selected, ssid);
1124 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001125 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1126 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001128
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001129 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130}
1131
1132
1133static struct wpa_ssid *
1134wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1135{
1136 int prio;
1137 struct wpa_ssid *ssid;
1138
1139 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1140 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1141 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001142 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001143 continue;
1144 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001145 ssid->mode == IEEE80211_MODE_AP ||
1146 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001147 return ssid;
1148 }
1149 }
1150 return NULL;
1151}
1152
1153
1154/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1155 * on BSS added and BSS changed events */
1156static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001157 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001159 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001160
1161 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1162 return;
1163
Jouni Malinen87fd2792011-05-16 18:35:42 +03001164 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001165 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001166
Jouni Malinen87fd2792011-05-16 18:35:42 +03001167 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001168 if (ssid == NULL)
1169 continue;
1170
Jouni Malinen87fd2792011-05-16 18:35:42 +03001171 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001172 if (rsn == NULL)
1173 continue;
1174
Jouni Malinen87fd2792011-05-16 18:35:42 +03001175 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001176 }
1177
1178}
1179
1180
1181static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1182 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001183 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001185 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001186 int min_diff;
1187
1188 if (wpa_s->reassociate)
1189 return 1; /* explicit request to reassociate */
1190 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1191 return 1; /* we are not associated; continue */
1192 if (wpa_s->current_ssid == NULL)
1193 return 1; /* unknown current SSID */
1194 if (wpa_s->current_ssid != ssid)
1195 return 1; /* different network block */
1196
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197 if (wpas_driver_bss_selection(wpa_s))
1198 return 0; /* Driver-based roaming */
1199
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001200 if (wpa_s->current_ssid->ssid)
1201 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1202 wpa_s->current_ssid->ssid,
1203 wpa_s->current_ssid->ssid_len);
1204 if (!current_bss)
1205 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001206
1207 if (!current_bss)
1208 return 1; /* current BSS not seen in scan results */
1209
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001210 if (current_bss == selected)
1211 return 0;
1212
1213 if (selected->last_update_idx > current_bss->last_update_idx)
1214 return 1; /* current BSS not seen in the last scan */
1215
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001216#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1218 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1219 MAC2STR(current_bss->bssid), current_bss->level);
1220 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1221 MAC2STR(selected->bssid), selected->level);
1222
1223 if (wpa_s->current_ssid->bssid_set &&
1224 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1225 0) {
1226 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1227 "has preferred BSSID");
1228 return 1;
1229 }
1230
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001231 if (current_bss->level < 0 && current_bss->level > selected->level) {
1232 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1233 "signal level");
1234 return 0;
1235 }
1236
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237 min_diff = 2;
1238 if (current_bss->level < 0) {
1239 if (current_bss->level < -85)
1240 min_diff = 1;
1241 else if (current_bss->level < -80)
1242 min_diff = 2;
1243 else if (current_bss->level < -75)
1244 min_diff = 3;
1245 else if (current_bss->level < -70)
1246 min_diff = 4;
1247 else
1248 min_diff = 5;
1249 }
1250 if (abs(current_bss->level - selected->level) < min_diff) {
1251 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1252 "in signal level");
1253 return 0;
1254 }
1255
1256 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001257#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001258 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001259#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001260}
1261
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001262
Jouni Malinen89ca7022012-09-14 13:03:12 -07001263/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001264 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001265static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001266 union wpa_event_data *data,
1267 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001268{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001269 struct wpa_scan_results *scan_res = NULL;
1270 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001272#ifndef CONFIG_NO_RANDOM_POOL
1273 size_t i, num;
1274#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001275
1276#ifdef CONFIG_AP
1277 if (wpa_s->ap_iface)
1278 ap = 1;
1279#endif /* CONFIG_AP */
1280
1281 wpa_supplicant_notify_scanning(wpa_s, 0);
1282
1283 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1284 data ? &data->scan_info :
1285 NULL, 1);
1286 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001287 if (wpa_s->conf->ap_scan == 2 || ap ||
1288 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001290 if (!own_request)
1291 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001292 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1293 "scanning again");
1294 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001295 ret = -1;
1296 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001297 }
1298
1299#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300 num = scan_res->num;
1301 if (num > 10)
1302 num = 10;
1303 for (i = 0; i < num; i++) {
1304 u8 buf[5];
1305 struct wpa_scan_res *res = scan_res->res[i];
1306 buf[0] = res->bssid[5];
1307 buf[1] = res->qual & 0xff;
1308 buf[2] = res->noise & 0xff;
1309 buf[3] = res->level & 0xff;
1310 buf[4] = res->tsf & 0xff;
1311 random_add_randomness(buf, sizeof(buf));
1312 }
1313#endif /* CONFIG_NO_RANDOM_POOL */
1314
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001315 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001316 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001317 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1318 struct wpa_scan_results *scan_res);
1319
1320 scan_res_handler = wpa_s->scan_res_handler;
1321 wpa_s->scan_res_handler = NULL;
1322 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001323 ret = -2;
1324 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001325 }
1326
1327 if (ap) {
1328 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1329#ifdef CONFIG_AP
1330 if (wpa_s->ap_iface->scan_cb)
1331 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1332#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001333 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001334 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001335
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001336 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001337 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001338 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1339 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1340 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1341 wpa_s->manual_scan_id);
1342 wpa_s->manual_scan_use_id = 0;
1343 } else {
1344 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1345 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001346 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001347
1348 wpas_notify_scan_done(wpa_s, 1);
1349
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001350 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001351 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 -07001352 wpa_scan_results_free(scan_res);
1353 return 0;
1354 }
1355
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001356 if (wnm_scan_process(wpa_s, 1) > 0)
1357 goto scan_work_done;
1358
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001359 if (sme_proc_obss_scan(wpa_s) > 0)
1360 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001361
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001362 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1363 goto scan_work_done;
1364
1365 if (autoscan_notify_scan(wpa_s, scan_res))
1366 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001367
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001368 if (wpa_s->disconnected) {
1369 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001370 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001371 }
1372
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001373 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001374 bgscan_notify_scan(wpa_s, scan_res) == 1)
1375 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001376
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001377 wpas_wps_update_ap_info(wpa_s, scan_res);
1378
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001379 wpa_scan_results_free(scan_res);
1380
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001381 if (wpa_s->scan_work) {
1382 struct wpa_radio_work *work = wpa_s->scan_work;
1383 wpa_s->scan_work = NULL;
1384 radio_work_done(work);
1385 }
1386
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001387 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001388
1389scan_work_done:
1390 wpa_scan_results_free(scan_res);
1391 if (wpa_s->scan_work) {
1392 struct wpa_radio_work *work = wpa_s->scan_work;
1393 wpa_s->scan_work = NULL;
1394 radio_work_done(work);
1395 }
1396 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001397}
1398
1399
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001400static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001401 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001402{
1403 struct wpa_bss *selected;
1404 struct wpa_ssid *ssid = NULL;
1405
1406 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001407
1408 if (selected) {
1409 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001410 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001411 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001412 if (new_scan)
1413 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001415 }
1416
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001417 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001418 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001419 return -1;
1420 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001421 if (new_scan)
1422 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001423 /*
1424 * Do not notify other virtual radios of scan results since we do not
1425 * want them to start other associations at the same time.
1426 */
1427 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001428 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001429#ifdef CONFIG_MESH
1430 if (wpa_s->ifmsh) {
1431 wpa_msg(wpa_s, MSG_INFO,
1432 "Avoiding join because we already joined a mesh group");
1433 return 0;
1434 }
1435#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001436 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1437 ssid = wpa_supplicant_pick_new_network(wpa_s);
1438 if (ssid) {
1439 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1440 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001441 if (new_scan)
1442 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001443 } else if (own_request) {
1444 /*
1445 * No SSID found. If SCAN results are as a result of
1446 * own scan request and not due to a scan request on
1447 * another shared interface, try another scan.
1448 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001449 int timeout_sec = wpa_s->scan_interval;
1450 int timeout_usec = 0;
1451#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001452 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1453 return 0;
1454
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001455 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07001456 wpa_s->show_group_started ||
1457 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001458 /*
1459 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001460 * state and during P2P join-a-group operation
1461 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462 */
1463 timeout_sec = 0;
1464 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001465 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1466 timeout_usec);
1467 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001468 }
1469#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001470#ifdef CONFIG_INTERWORKING
1471 if (wpa_s->conf->auto_interworking &&
1472 wpa_s->conf->interworking &&
1473 wpa_s->conf->cred) {
1474 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1475 "start ANQP fetch since no matching "
1476 "networks found");
1477 wpa_s->network_select = 1;
1478 wpa_s->auto_network_select = 1;
1479 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001480 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001481 }
1482#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001483#ifdef CONFIG_WPS
1484 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1485 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1486 timeout_sec = 0;
1487 timeout_usec = 500000;
1488 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1489 timeout_usec);
1490 return 0;
1491 }
1492#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001493 if (wpa_supplicant_req_sched_scan(wpa_s))
1494 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1495 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001496 }
1497 }
1498 return 0;
1499}
1500
1501
1502static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1503 union wpa_event_data *data)
1504{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001505 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001506
1507 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001508 /*
1509 * If no scan results could be fetched, then no need to
1510 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001511 * this scan. Similarly, if scan results started a new operation on this
1512 * interface, do not notify other interfaces to avoid concurrent
1513 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001514 */
1515 return;
1516 }
1517
1518 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001519 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001520 * so, they get updated with this same scan info.
1521 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001522 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1523 radio_list) {
1524 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001525 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1526 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001527 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528 }
1529 }
1530}
1531
1532#endif /* CONFIG_NO_SCAN_PROCESSING */
1533
1534
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001535int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1536{
1537#ifdef CONFIG_NO_SCAN_PROCESSING
1538 return -1;
1539#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001540 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001541
1542 if (wpa_s->last_scan_res_used <= 0)
1543 return -1;
1544
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001545 os_get_reltime(&now);
1546 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001547 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1548 return -1;
1549 }
1550
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001551 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001552#endif /* CONFIG_NO_SCAN_PROCESSING */
1553}
1554
Dmitry Shmidt04949592012-07-19 12:16:46 -07001555#ifdef CONFIG_WNM
1556
1557static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1558{
1559 struct wpa_supplicant *wpa_s = eloop_ctx;
1560
1561 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1562 return;
1563
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001564 if (!wpa_s->no_keep_alive) {
1565 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1566 MAC2STR(wpa_s->bssid));
1567 /* TODO: could skip this if normal data traffic has been sent */
1568 /* TODO: Consider using some more appropriate data frame for
1569 * this */
1570 if (wpa_s->l2)
1571 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1572 (u8 *) "", 0);
1573 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001574
1575#ifdef CONFIG_SME
1576 if (wpa_s->sme.bss_max_idle_period) {
1577 unsigned int msec;
1578 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1579 if (msec > 100)
1580 msec -= 100;
1581 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1582 wnm_bss_keep_alive, wpa_s, NULL);
1583 }
1584#endif /* CONFIG_SME */
1585}
1586
1587
1588static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1589 const u8 *ies, size_t ies_len)
1590{
1591 struct ieee802_11_elems elems;
1592
1593 if (ies == NULL)
1594 return;
1595
1596 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1597 return;
1598
1599#ifdef CONFIG_SME
1600 if (elems.bss_max_idle_period) {
1601 unsigned int msec;
1602 wpa_s->sme.bss_max_idle_period =
1603 WPA_GET_LE16(elems.bss_max_idle_period);
1604 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1605 "TU)%s", wpa_s->sme.bss_max_idle_period,
1606 (elems.bss_max_idle_period[2] & 0x01) ?
1607 " (protected keep-live required)" : "");
1608 if (wpa_s->sme.bss_max_idle_period == 0)
1609 wpa_s->sme.bss_max_idle_period = 1;
1610 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1611 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1612 /* msec times 1000 */
1613 msec = wpa_s->sme.bss_max_idle_period * 1024;
1614 if (msec > 100)
1615 msec -= 100;
1616 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1617 wnm_bss_keep_alive, wpa_s,
1618 NULL);
1619 }
1620 }
1621#endif /* CONFIG_SME */
1622}
1623
1624#endif /* CONFIG_WNM */
1625
1626
1627void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1628{
1629#ifdef CONFIG_WNM
1630 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1631#endif /* CONFIG_WNM */
1632}
1633
1634
Dmitry Shmidt051af732013-10-22 13:52:46 -07001635#ifdef CONFIG_INTERWORKING
1636
1637static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1638 size_t len)
1639{
1640 int res;
1641
1642 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1643 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1644 if (res) {
1645 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1646 }
1647
1648 return res;
1649}
1650
1651
1652static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1653 const u8 *ies, size_t ies_len)
1654{
1655 struct ieee802_11_elems elems;
1656
1657 if (ies == NULL)
1658 return;
1659
1660 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1661 return;
1662
1663 if (elems.qos_map_set) {
1664 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1665 elems.qos_map_set_len);
1666 }
1667}
1668
1669#endif /* CONFIG_INTERWORKING */
1670
1671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1673 union wpa_event_data *data)
1674{
1675 int l, len, found = 0, wpa_found, rsn_found;
1676 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001677#ifdef CONFIG_IEEE80211R
1678 u8 bssid[ETH_ALEN];
1679#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680
1681 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1682 if (data->assoc_info.req_ies)
1683 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1684 data->assoc_info.req_ies_len);
1685 if (data->assoc_info.resp_ies) {
1686 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1687 data->assoc_info.resp_ies_len);
1688#ifdef CONFIG_TDLS
1689 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1690 data->assoc_info.resp_ies_len);
1691#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001692#ifdef CONFIG_WNM
1693 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1694 data->assoc_info.resp_ies_len);
1695#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001696#ifdef CONFIG_INTERWORKING
1697 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1698 data->assoc_info.resp_ies_len);
1699#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001700 }
1701 if (data->assoc_info.beacon_ies)
1702 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1703 data->assoc_info.beacon_ies,
1704 data->assoc_info.beacon_ies_len);
1705 if (data->assoc_info.freq)
1706 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1707 data->assoc_info.freq);
1708
1709 p = data->assoc_info.req_ies;
1710 l = data->assoc_info.req_ies_len;
1711
1712 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1713 while (p && l >= 2) {
1714 len = p[1] + 2;
1715 if (len > l) {
1716 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1717 p, l);
1718 break;
1719 }
1720 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1721 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1722 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1723 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1724 break;
1725 found = 1;
1726 wpa_find_assoc_pmkid(wpa_s);
1727 break;
1728 }
1729 l -= len;
1730 p += len;
1731 }
1732 if (!found && data->assoc_info.req_ies)
1733 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1734
1735#ifdef CONFIG_IEEE80211R
1736#ifdef CONFIG_SME
1737 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001738 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1739 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1740 data->assoc_info.resp_ies,
1741 data->assoc_info.resp_ies_len,
1742 bssid) < 0) {
1743 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1744 "Reassociation Response failed");
1745 wpa_supplicant_deauthenticate(
1746 wpa_s, WLAN_REASON_INVALID_IE);
1747 return -1;
1748 }
1749 }
1750
1751 p = data->assoc_info.resp_ies;
1752 l = data->assoc_info.resp_ies_len;
1753
1754#ifdef CONFIG_WPS_STRICT
1755 if (p && wpa_s->current_ssid &&
1756 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1757 struct wpabuf *wps;
1758 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1759 if (wps == NULL) {
1760 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1761 "include WPS IE in (Re)Association Response");
1762 return -1;
1763 }
1764
1765 if (wps_validate_assoc_resp(wps) < 0) {
1766 wpabuf_free(wps);
1767 wpa_supplicant_deauthenticate(
1768 wpa_s, WLAN_REASON_INVALID_IE);
1769 return -1;
1770 }
1771 wpabuf_free(wps);
1772 }
1773#endif /* CONFIG_WPS_STRICT */
1774
1775 /* Go through the IEs and make a copy of the MDIE, if present. */
1776 while (p && l >= 2) {
1777 len = p[1] + 2;
1778 if (len > l) {
1779 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1780 p, l);
1781 break;
1782 }
1783 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1784 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1785 wpa_s->sme.ft_used = 1;
1786 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1787 MOBILITY_DOMAIN_ID_LEN);
1788 break;
1789 }
1790 l -= len;
1791 p += len;
1792 }
1793#endif /* CONFIG_SME */
1794
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001795 /* Process FT when SME is in the driver */
1796 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1797 wpa_ft_is_completed(wpa_s->wpa)) {
1798 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1799 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1800 data->assoc_info.resp_ies,
1801 data->assoc_info.resp_ies_len,
1802 bssid) < 0) {
1803 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1804 "Reassociation Response failed");
1805 wpa_supplicant_deauthenticate(
1806 wpa_s, WLAN_REASON_INVALID_IE);
1807 return -1;
1808 }
1809 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1810 }
1811
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001812 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1813 data->assoc_info.resp_ies_len);
1814#endif /* CONFIG_IEEE80211R */
1815
1816 /* WPA/RSN IE from Beacon/ProbeResp */
1817 p = data->assoc_info.beacon_ies;
1818 l = data->assoc_info.beacon_ies_len;
1819
1820 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1821 */
1822 wpa_found = rsn_found = 0;
1823 while (p && l >= 2) {
1824 len = p[1] + 2;
1825 if (len > l) {
1826 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1827 p, l);
1828 break;
1829 }
1830 if (!wpa_found &&
1831 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1832 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1833 wpa_found = 1;
1834 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1835 }
1836
1837 if (!rsn_found &&
1838 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1839 rsn_found = 1;
1840 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1841 }
1842
1843 l -= len;
1844 p += len;
1845 }
1846
1847 if (!wpa_found && data->assoc_info.beacon_ies)
1848 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1849 if (!rsn_found && data->assoc_info.beacon_ies)
1850 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1851 if (wpa_found || rsn_found)
1852 wpa_s->ap_ies_from_associnfo = 1;
1853
Jouni Malinen87fd2792011-05-16 18:35:42 +03001854 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1855 wpa_s->assoc_freq != data->assoc_info.freq) {
1856 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1857 "%u to %u MHz",
1858 wpa_s->assoc_freq, data->assoc_info.freq);
1859 wpa_supplicant_update_scan_results(wpa_s);
1860 }
1861
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001862 wpa_s->assoc_freq = data->assoc_info.freq;
1863
1864 return 0;
1865}
1866
1867
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001868static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1869{
1870 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1871
1872 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1873 return -1;
1874
1875 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1876 return 0;
1877
1878 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1879 WPA_IE_VENDOR_TYPE);
1880 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1881
1882 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1883 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1884 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1885 bss_rsn ? 2 + bss_rsn[1] : 0))
1886 return -1;
1887
1888 return 0;
1889}
1890
1891
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001892static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1893 union wpa_event_data *data)
1894{
1895 u8 bssid[ETH_ALEN];
1896 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001897
1898#ifdef CONFIG_AP
1899 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001900 if (!data)
1901 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001902 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1903 data->assoc_info.addr,
1904 data->assoc_info.req_ies,
1905 data->assoc_info.req_ies_len,
1906 data->assoc_info.reassoc);
1907 return;
1908 }
1909#endif /* CONFIG_AP */
1910
1911 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1912 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1913 return;
1914
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001915 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1916 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001917 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001918 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1919 return;
1920 }
1921
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001922 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001923 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001924 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1925 MACSTR, MAC2STR(bssid));
1926 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001927 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1928 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001929 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001930
1931 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1932 wpa_clear_keys(wpa_s, bssid);
1933 }
1934 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001935 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001936 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1937 return;
1938 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001939
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001940#ifdef ANDROID
1941 if (wpa_s->conf->ap_scan == 1) {
1942#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001943 if (wpa_s->conf->ap_scan == 1 &&
1944 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001945#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001946 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1947 wpa_msg(wpa_s, MSG_WARNING,
1948 "WPA/RSN IEs not updated");
1949 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001950 }
1951
1952#ifdef CONFIG_SME
1953 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1954 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07001955 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001956#endif /* CONFIG_SME */
1957
1958 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1959 if (wpa_s->current_ssid) {
1960 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1961 * initialized before association, but for other modes,
1962 * initialize PC/SC here, if the current configuration needs
1963 * smartcard or SIM/USIM. */
1964 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1965 }
1966 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1967 if (wpa_s->l2)
1968 l2_packet_notify_auth_start(wpa_s->l2);
1969
1970 /*
1971 * Set portEnabled first to FALSE in order to get EAP state machine out
1972 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1973 * state machine may transit to AUTHENTICATING state based on obsolete
1974 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1975 * AUTHENTICATED without ever giving chance to EAP state machine to
1976 * reset the state.
1977 */
1978 if (!ft_completed) {
1979 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1980 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1981 }
1982 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1983 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1984 /* 802.1X::portControl = Auto */
1985 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1986 wpa_s->eapol_received = 0;
1987 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1988 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1989 (wpa_s->current_ssid &&
1990 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001991 if (wpa_s->current_ssid &&
1992 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001993 (wpa_s->drv_flags &
1994 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1995 /*
1996 * Set the key after having received joined-IBSS event
1997 * from the driver.
1998 */
1999 wpa_supplicant_set_wpa_none_key(wpa_s,
2000 wpa_s->current_ssid);
2001 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002002 wpa_supplicant_cancel_auth_timeout(wpa_s);
2003 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2004 } else if (!ft_completed) {
2005 /* Timeout for receiving the first EAPOL packet */
2006 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2007 }
2008 wpa_supplicant_cancel_scan(wpa_s);
2009
2010 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2011 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2012 /*
2013 * We are done; the driver will take care of RSN 4-way
2014 * handshake.
2015 */
2016 wpa_supplicant_cancel_auth_timeout(wpa_s);
2017 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2018 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2019 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2020 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2021 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2022 /*
2023 * The driver will take care of RSN 4-way handshake, so we need
2024 * to allow EAPOL supplicant to complete its work without
2025 * waiting for WPA supplicant.
2026 */
2027 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2028 } else if (ft_completed) {
2029 /*
2030 * FT protocol completed - make sure EAPOL state machine ends
2031 * up in authenticated.
2032 */
2033 wpa_supplicant_cancel_auth_timeout(wpa_s);
2034 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2035 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2036 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2037 }
2038
Jouni Malinena05074c2012-12-21 21:35:35 +02002039 wpa_s->last_eapol_matches_bssid = 0;
2040
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002041 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002042 struct os_reltime now, age;
2043 os_get_reltime(&now);
2044 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002045 if (age.sec == 0 && age.usec < 100000 &&
2046 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2047 0) {
2048 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2049 "frame that was received just before "
2050 "association notification");
2051 wpa_supplicant_rx_eapol(
2052 wpa_s, wpa_s->pending_eapol_rx_src,
2053 wpabuf_head(wpa_s->pending_eapol_rx),
2054 wpabuf_len(wpa_s->pending_eapol_rx));
2055 }
2056 wpabuf_free(wpa_s->pending_eapol_rx);
2057 wpa_s->pending_eapol_rx = NULL;
2058 }
2059
2060 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2061 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002062 wpa_s->current_ssid &&
2063 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002064 /* Set static WEP keys again */
2065 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2066 }
2067
2068#ifdef CONFIG_IBSS_RSN
2069 if (wpa_s->current_ssid &&
2070 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2071 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2072 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2073 wpa_s->ibss_rsn == NULL) {
2074 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2075 if (!wpa_s->ibss_rsn) {
2076 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2077 wpa_supplicant_deauthenticate(
2078 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2079 return;
2080 }
2081
2082 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2083 }
2084#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002085
2086 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002087
2088 if (data) {
2089 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2090 data->assoc_info.resp_ies_len,
2091 &data->assoc_info.wmm_params);
2092
2093 if (wpa_s->reassoc_same_bss)
2094 wmm_ac_restore_tspecs(wpa_s);
2095 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002096}
2097
2098
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002099static int disconnect_reason_recoverable(u16 reason_code)
2100{
2101 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2102 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2103 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2104}
2105
2106
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002107static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002108 u16 reason_code,
2109 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002110{
2111 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002112
2113 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2114 /*
2115 * At least Host AP driver and a Prism3 card seemed to be
2116 * generating streams of disconnected events when configuring
2117 * IBSS for WPA-None. Ignore them for now.
2118 */
2119 return;
2120 }
2121
2122 bssid = wpa_s->bssid;
2123 if (is_zero_ether_addr(bssid))
2124 bssid = wpa_s->pending_bssid;
2125
2126 if (!is_zero_ether_addr(bssid) ||
2127 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2128 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2129 " reason=%d%s",
2130 MAC2STR(bssid), reason_code,
2131 locally_generated ? " locally_generated=1" : "");
2132 }
2133}
2134
2135
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002136static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2137 int locally_generated)
2138{
2139 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2140 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2141 return 0; /* Not in 4-way handshake with PSK */
2142
2143 /*
2144 * It looks like connection was lost while trying to go through PSK
2145 * 4-way handshake. Filter out known disconnection cases that are caused
2146 * by something else than PSK mismatch to avoid confusing reports.
2147 */
2148
2149 if (locally_generated) {
2150 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2151 return 0;
2152 }
2153
2154 return 1;
2155}
2156
2157
Jouni Malinen2b89da82012-08-31 22:04:41 +03002158static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2159 u16 reason_code,
2160 int locally_generated)
2161{
2162 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002163 int authenticating;
2164 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002165 struct wpa_bss *fast_reconnect = NULL;
2166 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002167 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002168
2169 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2170 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2171
2172 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2173 /*
2174 * At least Host AP driver and a Prism3 card seemed to be
2175 * generating streams of disconnected events when configuring
2176 * IBSS for WPA-None. Ignore them for now.
2177 */
2178 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2179 "IBSS/WPA-None mode");
2180 return;
2181 }
2182
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002183 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002184 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2185 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002186 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2187 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002188 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002189 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002190 if (!wpa_s->disconnected &&
2191 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002192 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2193 wpas_wps_searching(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002194 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002195 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002196 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002197 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002198 wpa_s->wpa_state);
2199 if (wpa_s->wpa_state == WPA_COMPLETED &&
2200 wpa_s->current_ssid &&
2201 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002202 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002203 disconnect_reason_recoverable(reason_code)) {
2204 /*
2205 * It looks like the AP has dropped association with
2206 * us, but could allow us to get back in. Try to
2207 * reconnect to the same BSS without full scan to save
2208 * time for some common cases.
2209 */
2210 fast_reconnect = wpa_s->current_bss;
2211 fast_reconnect_ssid = wpa_s->current_ssid;
2212 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002213 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002214 else
2215 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2216 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002218 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002219 "try to re-connect");
2220 wpa_s->reassociate = 0;
2221 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002222 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002223 }
2224 bssid = wpa_s->bssid;
2225 if (is_zero_ether_addr(bssid))
2226 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002227 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2228 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002229 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002230 if (locally_generated)
2231 wpa_s->disconnect_reason = -reason_code;
2232 else
2233 wpa_s->disconnect_reason = reason_code;
2234 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002235 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2236 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002237 wpa_clear_keys(wpa_s, wpa_s->bssid);
2238 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002239 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002240 wpa_supplicant_mark_disassoc(wpa_s);
2241
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002242 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002243 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002244 wpa_s->current_ssid = last_ssid;
2245 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002246
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002247 if (fast_reconnect &&
2248 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2249 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2250 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2251 fast_reconnect->ssid_len) &&
2252 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002253#ifndef CONFIG_NO_SCAN_PROCESSING
2254 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2255 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2256 fast_reconnect_ssid) < 0) {
2257 /* Recover through full scan */
2258 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2259 }
2260#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002261 } else if (fast_reconnect) {
2262 /*
2263 * Could not reconnect to the same BSS due to network being
2264 * disabled. Use a new scan to match the alternative behavior
2265 * above, i.e., to continue automatic reconnection attempt in a
2266 * way that enforces disabled network rules.
2267 */
2268 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002269 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002270}
2271
2272
2273#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002274void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002275{
2276 struct wpa_supplicant *wpa_s = eloop_ctx;
2277
2278 if (!wpa_s->pending_mic_error_report)
2279 return;
2280
2281 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2282 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2283 wpa_s->pending_mic_error_report = 0;
2284}
2285#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2286
2287
2288static void
2289wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2290 union wpa_event_data *data)
2291{
2292 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002293 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002294
2295 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2296 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002297 os_get_reltime(&t);
2298 if ((wpa_s->last_michael_mic_error.sec &&
2299 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002300 wpa_s->pending_mic_error_report) {
2301 if (wpa_s->pending_mic_error_report) {
2302 /*
2303 * Send the pending MIC error report immediately since
2304 * we are going to start countermeasures and AP better
2305 * do the same.
2306 */
2307 wpa_sm_key_request(wpa_s->wpa, 1,
2308 wpa_s->pending_mic_error_pairwise);
2309 }
2310
2311 /* Send the new MIC error report immediately since we are going
2312 * to start countermeasures and AP better do the same.
2313 */
2314 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2315
2316 /* initialize countermeasures */
2317 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002318
2319 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2320
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002321 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2322
2323 /*
2324 * Need to wait for completion of request frame. We do not get
2325 * any callback for the message completion, so just wait a
2326 * short while and hope for the best. */
2327 os_sleep(0, 10000);
2328
2329 wpa_drv_set_countermeasures(wpa_s, 1);
2330 wpa_supplicant_deauthenticate(wpa_s,
2331 WLAN_REASON_MICHAEL_MIC_FAILURE);
2332 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2333 wpa_s, NULL);
2334 eloop_register_timeout(60, 0,
2335 wpa_supplicant_stop_countermeasures,
2336 wpa_s, NULL);
2337 /* TODO: mark the AP rejected for 60 second. STA is
2338 * allowed to associate with another AP.. */
2339 } else {
2340#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2341 if (wpa_s->mic_errors_seen) {
2342 /*
2343 * Reduce the effectiveness of Michael MIC error
2344 * reports as a means for attacking against TKIP if
2345 * more than one MIC failure is noticed with the same
2346 * PTK. We delay the transmission of the reports by a
2347 * random time between 0 and 60 seconds in order to
2348 * force the attacker wait 60 seconds before getting
2349 * the information on whether a frame resulted in a MIC
2350 * failure.
2351 */
2352 u8 rval[4];
2353 int sec;
2354
2355 if (os_get_random(rval, sizeof(rval)) < 0)
2356 sec = os_random() % 60;
2357 else
2358 sec = WPA_GET_BE32(rval) % 60;
2359 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2360 "report %d seconds", sec);
2361 wpa_s->pending_mic_error_report = 1;
2362 wpa_s->pending_mic_error_pairwise = pairwise;
2363 eloop_cancel_timeout(
2364 wpa_supplicant_delayed_mic_error_report,
2365 wpa_s, NULL);
2366 eloop_register_timeout(
2367 sec, os_random() % 1000000,
2368 wpa_supplicant_delayed_mic_error_report,
2369 wpa_s, NULL);
2370 } else {
2371 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2372 }
2373#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2374 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2375#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2376 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002377 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002378 wpa_s->mic_errors_seen++;
2379}
2380
2381
2382#ifdef CONFIG_TERMINATE_ONLASTIF
2383static int any_interfaces(struct wpa_supplicant *head)
2384{
2385 struct wpa_supplicant *wpa_s;
2386
2387 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2388 if (!wpa_s->interface_removed)
2389 return 1;
2390 return 0;
2391}
2392#endif /* CONFIG_TERMINATE_ONLASTIF */
2393
2394
2395static void
2396wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2397 union wpa_event_data *data)
2398{
2399 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2400 return;
2401
2402 switch (data->interface_status.ievent) {
2403 case EVENT_INTERFACE_ADDED:
2404 if (!wpa_s->interface_removed)
2405 break;
2406 wpa_s->interface_removed = 0;
2407 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2408 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2409 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2410 "driver after interface was added");
2411 }
2412 break;
2413 case EVENT_INTERFACE_REMOVED:
2414 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2415 wpa_s->interface_removed = 1;
2416 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002417 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418 l2_packet_deinit(wpa_s->l2);
2419 wpa_s->l2 = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002420#ifdef CONFIG_TERMINATE_ONLASTIF
2421 /* check if last interface */
2422 if (!any_interfaces(wpa_s->global->ifaces))
2423 eloop_terminate();
2424#endif /* CONFIG_TERMINATE_ONLASTIF */
2425 break;
2426 }
2427}
2428
2429
2430#ifdef CONFIG_PEERKEY
2431static void
2432wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2433 union wpa_event_data *data)
2434{
2435 if (data == NULL)
2436 return;
2437 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2438}
2439#endif /* CONFIG_PEERKEY */
2440
2441
2442#ifdef CONFIG_TDLS
2443static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2444 union wpa_event_data *data)
2445{
2446 if (data == NULL)
2447 return;
2448 switch (data->tdls.oper) {
2449 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002450 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2451 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2452 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2453 else
2454 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002455 break;
2456 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002457 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2458 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2459 data->tdls.reason_code);
2460 else
2461 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2462 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002463 break;
2464 }
2465}
2466#endif /* CONFIG_TDLS */
2467
2468
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002469#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002470static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2471 union wpa_event_data *data)
2472{
2473 if (data == NULL)
2474 return;
2475 switch (data->wnm.oper) {
2476 case WNM_OPER_SLEEP:
2477 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2478 "(action=%d, intval=%d)",
2479 data->wnm.sleep_action, data->wnm.sleep_intval);
2480 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002481 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002482 break;
2483 }
2484}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002485#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002486
2487
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002488#ifdef CONFIG_IEEE80211R
2489static void
2490wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2491 union wpa_event_data *data)
2492{
2493 if (data == NULL)
2494 return;
2495
2496 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2497 data->ft_ies.ies_len,
2498 data->ft_ies.ft_action,
2499 data->ft_ies.target_ap,
2500 data->ft_ies.ric_ies,
2501 data->ft_ies.ric_ies_len) < 0) {
2502 /* TODO: prevent MLME/driver from trying to associate? */
2503 }
2504}
2505#endif /* CONFIG_IEEE80211R */
2506
2507
2508#ifdef CONFIG_IBSS_RSN
2509static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2510 union wpa_event_data *data)
2511{
2512 struct wpa_ssid *ssid;
2513 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2514 return;
2515 if (data == NULL)
2516 return;
2517 ssid = wpa_s->current_ssid;
2518 if (ssid == NULL)
2519 return;
2520 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2521 return;
2522
2523 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2524}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002525
2526
2527static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2528 union wpa_event_data *data)
2529{
2530 struct wpa_ssid *ssid = wpa_s->current_ssid;
2531
2532 if (ssid == NULL)
2533 return;
2534
2535 /* check if the ssid is correctly configured as IBSS/RSN */
2536 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2537 return;
2538
2539 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2540 data->rx_mgmt.frame_len);
2541}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002542#endif /* CONFIG_IBSS_RSN */
2543
2544
2545#ifdef CONFIG_IEEE80211R
2546static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2547 size_t len)
2548{
2549 const u8 *sta_addr, *target_ap_addr;
2550 u16 status;
2551
2552 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2553 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2554 return; /* only SME case supported for now */
2555 if (len < 1 + 2 * ETH_ALEN + 2)
2556 return;
2557 if (data[0] != 2)
2558 return; /* Only FT Action Response is supported for now */
2559 sta_addr = data + 1;
2560 target_ap_addr = data + 1 + ETH_ALEN;
2561 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2562 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2563 MACSTR " TargetAP " MACSTR " status %u",
2564 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2565
2566 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2567 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2568 " in FT Action Response", MAC2STR(sta_addr));
2569 return;
2570 }
2571
2572 if (status) {
2573 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2574 "failure (status code %d)", status);
2575 /* TODO: report error to FT code(?) */
2576 return;
2577 }
2578
2579 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2580 len - (1 + 2 * ETH_ALEN + 2), 1,
2581 target_ap_addr, NULL, 0) < 0)
2582 return;
2583
2584#ifdef CONFIG_SME
2585 {
2586 struct wpa_bss *bss;
2587 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2588 if (bss)
2589 wpa_s->sme.freq = bss->freq;
2590 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2591 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2592 WLAN_AUTH_FT);
2593 }
2594#endif /* CONFIG_SME */
2595}
2596#endif /* CONFIG_IEEE80211R */
2597
2598
2599static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2600 struct unprot_deauth *e)
2601{
2602#ifdef CONFIG_IEEE80211W
2603 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2604 "dropped: " MACSTR " -> " MACSTR
2605 " (reason code %u)",
2606 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2607 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2608#endif /* CONFIG_IEEE80211W */
2609}
2610
2611
2612static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2613 struct unprot_disassoc *e)
2614{
2615#ifdef CONFIG_IEEE80211W
2616 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2617 "dropped: " MACSTR " -> " MACSTR
2618 " (reason code %u)",
2619 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2620 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2621#endif /* CONFIG_IEEE80211W */
2622}
2623
2624
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002625static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2626 u16 reason_code, int locally_generated,
2627 const u8 *ie, size_t ie_len, int deauth)
2628{
2629#ifdef CONFIG_AP
2630 if (wpa_s->ap_iface && addr) {
2631 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2632 return;
2633 }
2634
2635 if (wpa_s->ap_iface) {
2636 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2637 return;
2638 }
2639#endif /* CONFIG_AP */
2640
2641 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2642
Dmitry Shmidt344abd32014-01-14 13:17:00 -08002643 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2644 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2645 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2646 eapol_sm_failed(wpa_s->eapol))) &&
2647 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002648 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002649
2650#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002651 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002652 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2653 locally_generated) > 0) {
2654 /*
2655 * The interface was removed, so cannot continue
2656 * processing any additional operations after this.
2657 */
2658 return;
2659 }
2660 }
2661#endif /* CONFIG_P2P */
2662
2663 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2664 locally_generated);
2665}
2666
2667
2668static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2669 struct disassoc_info *info)
2670{
2671 u16 reason_code = 0;
2672 int locally_generated = 0;
2673 const u8 *addr = NULL;
2674 const u8 *ie = NULL;
2675 size_t ie_len = 0;
2676
2677 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2678
2679 if (info) {
2680 addr = info->addr;
2681 ie = info->ie;
2682 ie_len = info->ie_len;
2683 reason_code = info->reason_code;
2684 locally_generated = info->locally_generated;
2685 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2686 locally_generated ? " (locally generated)" : "");
2687 if (addr)
2688 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2689 MAC2STR(addr));
2690 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2691 ie, ie_len);
2692 }
2693
2694#ifdef CONFIG_AP
2695 if (wpa_s->ap_iface && info && info->addr) {
2696 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2697 return;
2698 }
2699
2700 if (wpa_s->ap_iface) {
2701 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2702 return;
2703 }
2704#endif /* CONFIG_AP */
2705
2706#ifdef CONFIG_P2P
2707 if (info) {
2708 wpas_p2p_disassoc_notif(
2709 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2710 locally_generated);
2711 }
2712#endif /* CONFIG_P2P */
2713
2714 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2715 sme_event_disassoc(wpa_s, info);
2716
2717 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2718 ie, ie_len, 0);
2719}
2720
2721
2722static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2723 struct deauth_info *info)
2724{
2725 u16 reason_code = 0;
2726 int locally_generated = 0;
2727 const u8 *addr = NULL;
2728 const u8 *ie = NULL;
2729 size_t ie_len = 0;
2730
2731 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2732
2733 if (info) {
2734 addr = info->addr;
2735 ie = info->ie;
2736 ie_len = info->ie_len;
2737 reason_code = info->reason_code;
2738 locally_generated = info->locally_generated;
2739 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2740 reason_code,
2741 locally_generated ? " (locally generated)" : "");
2742 if (addr) {
2743 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2744 MAC2STR(addr));
2745 }
2746 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2747 ie, ie_len);
2748 }
2749
2750 wpa_reset_ft_completed(wpa_s->wpa);
2751
2752 wpas_event_disconnect(wpa_s, addr, reason_code,
2753 locally_generated, ie, ie_len, 1);
2754}
2755
2756
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002757static const char * reg_init_str(enum reg_change_initiator init)
2758{
2759 switch (init) {
2760 case REGDOM_SET_BY_CORE:
2761 return "CORE";
2762 case REGDOM_SET_BY_USER:
2763 return "USER";
2764 case REGDOM_SET_BY_DRIVER:
2765 return "DRIVER";
2766 case REGDOM_SET_BY_COUNTRY_IE:
2767 return "COUNTRY_IE";
2768 case REGDOM_BEACON_HINT:
2769 return "BEACON_HINT";
2770 }
2771 return "?";
2772}
2773
2774
2775static const char * reg_type_str(enum reg_type type)
2776{
2777 switch (type) {
2778 case REGDOM_TYPE_UNKNOWN:
2779 return "UNKNOWN";
2780 case REGDOM_TYPE_COUNTRY:
2781 return "COUNTRY";
2782 case REGDOM_TYPE_WORLD:
2783 return "WORLD";
2784 case REGDOM_TYPE_CUSTOM_WORLD:
2785 return "CUSTOM_WORLD";
2786 case REGDOM_TYPE_INTERSECTION:
2787 return "INTERSECTION";
2788 }
2789 return "?";
2790}
2791
2792
2793static void wpa_supplicant_update_channel_list(
2794 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002795{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002796 struct wpa_supplicant *ifs;
2797
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002798 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
Dmitry Shmidtc2817022014-07-02 10:32:10 -07002799 reg_init_str(info->initiator), reg_type_str(info->type),
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002800 info->alpha2[0] ? " alpha2=" : "",
2801 info->alpha2[0] ? info->alpha2 : "");
2802
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002803 if (wpa_s->drv_priv == NULL)
2804 return; /* Ignore event during drv initialization */
2805
2806 free_hw_features(wpa_s);
2807 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2808 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2809
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002810 wpas_p2p_update_channel_list(wpa_s);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002811
2812 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002813 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002814 * so, they get updated with this same hw mode info.
2815 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002816 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2817 radio_list) {
2818 if (ifs != wpa_s) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002819 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2820 ifs->ifname);
2821 free_hw_features(ifs);
2822 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2823 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2824 }
2825 }
2826}
2827
2828
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002829static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002830 const u8 *frame, size_t len, int freq,
2831 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002832{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002833 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002834 const u8 *payload;
2835 size_t plen;
2836 u8 category;
2837
2838 if (len < IEEE80211_HDRLEN + 2)
2839 return;
2840
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002841 mgmt = (const struct ieee80211_mgmt *) frame;
2842 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002843 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002844 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002845
2846 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2847 " Category=%u DataLen=%d freq=%d MHz",
2848 MAC2STR(mgmt->sa), category, (int) plen, freq);
2849
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002850 if (category == WLAN_ACTION_WMM) {
2851 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
2852 return;
2853 }
2854
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002855#ifdef CONFIG_IEEE80211R
2856 if (category == WLAN_ACTION_FT) {
2857 ft_rx_action(wpa_s, payload, plen);
2858 return;
2859 }
2860#endif /* CONFIG_IEEE80211R */
2861
2862#ifdef CONFIG_IEEE80211W
2863#ifdef CONFIG_SME
2864 if (category == WLAN_ACTION_SA_QUERY) {
2865 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2866 return;
2867 }
2868#endif /* CONFIG_SME */
2869#endif /* CONFIG_IEEE80211W */
2870
2871#ifdef CONFIG_WNM
2872 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2873 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2874 return;
2875 }
2876#endif /* CONFIG_WNM */
2877
2878#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08002879 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2880 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002881 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08002882 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002883 payload, plen, freq) == 0)
2884 return;
2885#endif /* CONFIG_GAS */
2886
2887#ifdef CONFIG_TDLS
2888 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2889 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2890 wpa_dbg(wpa_s, MSG_DEBUG,
2891 "TDLS: Received Discovery Response from " MACSTR,
2892 MAC2STR(mgmt->sa));
2893 return;
2894 }
2895#endif /* CONFIG_TDLS */
2896
2897#ifdef CONFIG_INTERWORKING
2898 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2899 payload[0] == QOS_QOS_MAP_CONFIG) {
2900 const u8 *pos = payload + 1;
2901 size_t qlen = plen - 1;
2902 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2903 MACSTR, MAC2STR(mgmt->sa));
2904 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2905 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2906 pos[1] <= qlen - 2 && pos[1] >= 16)
2907 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2908 return;
2909 }
2910#endif /* CONFIG_INTERWORKING */
2911
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002912 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2913 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
2914 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
2915 return;
2916 }
2917
2918 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2919 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
2920 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
2921 payload + 1, plen - 1,
2922 rssi);
2923 return;
2924 }
2925
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002926 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2927 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002928 if (wpa_s->ifmsh)
2929 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002930}
2931
2932
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08002933static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2934 union wpa_event_data *event)
2935{
2936#ifdef CONFIG_P2P
2937 struct wpa_supplicant *ifs;
2938#endif /* CONFIG_P2P */
2939 struct wpa_freq_range_list *list;
2940 char *str = NULL;
2941
2942 list = &event->freq_range;
2943
2944 if (list->num)
2945 str = freq_range_list_str(list);
2946 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2947 str ? str : "");
2948
2949#ifdef CONFIG_P2P
2950 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
2951 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
2952 __func__);
2953 } else {
2954 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
2955 wpas_p2p_update_channel_list(wpa_s);
2956 }
2957
2958 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2959 int freq;
2960 if (!ifs->current_ssid ||
2961 !ifs->current_ssid->p2p_group ||
2962 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
2963 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
2964 continue;
2965
2966 freq = ifs->current_ssid->frequency;
2967 if (!freq_range_list_includes(list, freq)) {
2968 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
2969 freq);
2970 continue;
2971 }
2972
2973 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
2974 freq);
2975 /* TODO: Consider using CSA or removing the group within
2976 * wpa_supplicant */
2977 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
2978 }
2979#endif /* CONFIG_P2P */
2980
2981 os_free(str);
2982}
2983
2984
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002985static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
2986 union wpa_event_data *data)
2987{
2988 wpa_dbg(wpa_s, MSG_DEBUG,
2989 "Connection authorized by device, previous state %d",
2990 wpa_s->wpa_state);
2991 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
2992 wpa_supplicant_cancel_auth_timeout(wpa_s);
2993 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2994 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2995 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2996 }
2997 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
2998 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
2999 data->assoc_info.ptk_kek);
3000}
3001
3002
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003003void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3004 union wpa_event_data *data)
3005{
3006 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003007
3008 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3009 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003010 event != EVENT_INTERFACE_STATUS &&
3011 event != EVENT_SCHED_SCAN_STOPPED) {
3012 wpa_dbg(wpa_s, MSG_DEBUG,
3013 "Ignore event %s (%d) while interface is disabled",
3014 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003015 return;
3016 }
3017
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003018#ifndef CONFIG_NO_STDOUT_DEBUG
3019{
3020 int level = MSG_DEBUG;
3021
Dmitry Shmidt04949592012-07-19 12:16:46 -07003022 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003023 const struct ieee80211_hdr *hdr;
3024 u16 fc;
3025 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3026 fc = le_to_host16(hdr->frame_control);
3027 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3028 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3029 level = MSG_EXCESSIVE;
3030 }
3031
3032 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3033 event_to_string(event), event);
3034}
3035#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003036
3037 switch (event) {
3038 case EVENT_AUTH:
3039 sme_event_auth(wpa_s, data);
3040 break;
3041 case EVENT_ASSOC:
3042 wpa_supplicant_event_assoc(wpa_s, data);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003043 if (data && data->assoc_info.authorized)
3044 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003045 break;
3046 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003047 wpas_event_disassoc(wpa_s,
3048 data ? &data->disassoc_info : NULL);
3049 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003050 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003051 wpas_event_deauth(wpa_s,
3052 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003053 break;
3054 case EVENT_MICHAEL_MIC_FAILURE:
3055 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3056 break;
3057#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003058 case EVENT_SCAN_STARTED:
3059 os_get_reltime(&wpa_s->scan_start_time);
3060 if (wpa_s->own_scan_requested) {
3061 struct os_reltime diff;
3062
3063 os_reltime_sub(&wpa_s->scan_start_time,
3064 &wpa_s->scan_trigger_time, &diff);
3065 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3066 diff.sec, diff.usec);
3067 wpa_s->own_scan_requested = 0;
3068 wpa_s->own_scan_running = 1;
3069 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3070 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003071 wpa_msg_ctrl(wpa_s, MSG_INFO,
3072 WPA_EVENT_SCAN_STARTED "id=%u",
3073 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003074 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003075 wpa_msg_ctrl(wpa_s, MSG_INFO,
3076 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003077 }
3078 } else {
3079 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003080 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003081 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003082 }
3083 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003084 case EVENT_SCAN_RESULTS:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003085 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3086 struct os_reltime now, diff;
3087 os_get_reltime(&now);
3088 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3089 wpa_s->scan_start_time.sec = 0;
3090 wpa_s->scan_start_time.usec = 0;
3091 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3092 diff.sec, diff.usec);
3093 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003094 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003095 wpa_s->own_scan_running = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003096 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003097 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003098 break;
3099#endif /* CONFIG_NO_SCAN_PROCESSING */
3100 case EVENT_ASSOCINFO:
3101 wpa_supplicant_event_associnfo(wpa_s, data);
3102 break;
3103 case EVENT_INTERFACE_STATUS:
3104 wpa_supplicant_event_interface_status(wpa_s, data);
3105 break;
3106 case EVENT_PMKID_CANDIDATE:
3107 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3108 break;
3109#ifdef CONFIG_PEERKEY
3110 case EVENT_STKSTART:
3111 wpa_supplicant_event_stkstart(wpa_s, data);
3112 break;
3113#endif /* CONFIG_PEERKEY */
3114#ifdef CONFIG_TDLS
3115 case EVENT_TDLS:
3116 wpa_supplicant_event_tdls(wpa_s, data);
3117 break;
3118#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003119#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003120 case EVENT_WNM:
3121 wpa_supplicant_event_wnm(wpa_s, data);
3122 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003123#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003124#ifdef CONFIG_IEEE80211R
3125 case EVENT_FT_RESPONSE:
3126 wpa_supplicant_event_ft_response(wpa_s, data);
3127 break;
3128#endif /* CONFIG_IEEE80211R */
3129#ifdef CONFIG_IBSS_RSN
3130 case EVENT_IBSS_RSN_START:
3131 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3132 break;
3133#endif /* CONFIG_IBSS_RSN */
3134 case EVENT_ASSOC_REJECT:
3135 if (data->assoc_reject.bssid)
3136 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3137 "bssid=" MACSTR " status_code=%u",
3138 MAC2STR(data->assoc_reject.bssid),
3139 data->assoc_reject.status_code);
3140 else
3141 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3142 "status_code=%u",
3143 data->assoc_reject.status_code);
3144 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3145 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07003146 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003147 const u8 *bssid = data->assoc_reject.bssid;
3148 if (bssid == NULL || is_zero_ether_addr(bssid))
3149 bssid = wpa_s->pending_bssid;
3150 wpas_connection_failed(wpa_s, bssid);
3151 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003152 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003153 break;
3154 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003155 /* It is possible to get this event from earlier connection */
3156 if (wpa_s->current_ssid &&
3157 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3158 wpa_dbg(wpa_s, MSG_DEBUG,
3159 "Ignore AUTH_TIMED_OUT in mesh configuration");
3160 break;
3161 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003162 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3163 sme_event_auth_timed_out(wpa_s, data);
3164 break;
3165 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003166 /* It is possible to get this event from earlier connection */
3167 if (wpa_s->current_ssid &&
3168 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3169 wpa_dbg(wpa_s, MSG_DEBUG,
3170 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3171 break;
3172 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003173 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3174 sme_event_assoc_timed_out(wpa_s, data);
3175 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003176 case EVENT_TX_STATUS:
3177 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3178 " type=%d stype=%d",
3179 MAC2STR(data->tx_status.dst),
3180 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003181#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003182 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003183#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003184 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3185 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003186 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003187 wpa_s, data->tx_status.dst,
3188 data->tx_status.data,
3189 data->tx_status.data_len,
3190 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003191 OFFCHANNEL_SEND_ACTION_SUCCESS :
3192 OFFCHANNEL_SEND_ACTION_NO_ACK);
3193#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003194 break;
3195 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003196#endif /* CONFIG_AP */
3197#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003198 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3199 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3200 /*
3201 * Catch TX status events for Action frames we sent via group
3202 * interface in GO mode.
3203 */
3204 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3205 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3206 os_memcmp(wpa_s->parent->pending_action_dst,
3207 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003208 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003209 wpa_s->parent, data->tx_status.dst,
3210 data->tx_status.data,
3211 data->tx_status.data_len,
3212 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003213 OFFCHANNEL_SEND_ACTION_SUCCESS :
3214 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003215 break;
3216 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003217#endif /* CONFIG_OFFCHANNEL */
3218#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003219 switch (data->tx_status.type) {
3220 case WLAN_FC_TYPE_MGMT:
3221 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3222 data->tx_status.data_len,
3223 data->tx_status.stype,
3224 data->tx_status.ack);
3225 break;
3226 case WLAN_FC_TYPE_DATA:
3227 ap_tx_status(wpa_s, data->tx_status.dst,
3228 data->tx_status.data,
3229 data->tx_status.data_len,
3230 data->tx_status.ack);
3231 break;
3232 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003233#endif /* CONFIG_AP */
3234 break;
3235#ifdef CONFIG_AP
3236 case EVENT_EAPOL_TX_STATUS:
3237 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3238 data->eapol_tx_status.data,
3239 data->eapol_tx_status.data_len,
3240 data->eapol_tx_status.ack);
3241 break;
3242 case EVENT_DRIVER_CLIENT_POLL_OK:
3243 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003244 break;
3245 case EVENT_RX_FROM_UNKNOWN:
3246 if (wpa_s->ap_iface == NULL)
3247 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003248 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3249 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003250 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003251 case EVENT_CH_SWITCH:
3252 if (!data)
3253 break;
3254 if (!wpa_s->ap_iface) {
3255 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3256 "event in non-AP mode");
3257 break;
3258 }
3259
Dmitry Shmidt04949592012-07-19 12:16:46 -07003260 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3261 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08003262 data->ch_switch.ch_offset,
3263 data->ch_switch.ch_width,
3264 data->ch_switch.cf1,
3265 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003266 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003267#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003268 case EVENT_RX_MGMT: {
3269 u16 fc, stype;
3270 const struct ieee80211_mgmt *mgmt;
3271
Dmitry Shmidt818ea482014-03-10 13:15:21 -07003272#ifdef CONFIG_TESTING_OPTIONS
3273 if (wpa_s->ext_mgmt_frame_handling) {
3274 struct rx_mgmt *rx = &data->rx_mgmt;
3275 size_t hex_len = 2 * rx->frame_len + 1;
3276 char *hex = os_malloc(hex_len);
3277 if (hex) {
3278 wpa_snprintf_hex(hex, hex_len,
3279 rx->frame, rx->frame_len);
3280 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3281 rx->freq, rx->datarate, rx->ssi_signal,
3282 hex);
3283 os_free(hex);
3284 }
3285 break;
3286 }
3287#endif /* CONFIG_TESTING_OPTIONS */
3288
Dmitry Shmidt04949592012-07-19 12:16:46 -07003289 mgmt = (const struct ieee80211_mgmt *)
3290 data->rx_mgmt.frame;
3291 fc = le_to_host16(mgmt->frame_control);
3292 stype = WLAN_FC_GET_STYPE(fc);
3293
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003294#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003295 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003296#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003297#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003298 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3299 data->rx_mgmt.frame_len > 24) {
3300 const u8 *src = mgmt->sa;
3301 const u8 *ie = mgmt->u.probe_req.variable;
3302 size_t ie_len = data->rx_mgmt.frame_len -
3303 (mgmt->u.probe_req.variable -
3304 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003305 wpas_p2p_probe_req_rx(
3306 wpa_s, src, mgmt->da,
3307 mgmt->bssid, ie, ie_len,
3308 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003309 break;
3310 }
3311#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003312#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003313 if (wpa_s->current_ssid &&
3314 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3315 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003316 data->rx_mgmt.frame_len >= 30) {
3317 wpa_supplicant_event_ibss_auth(wpa_s, data);
3318 break;
3319 }
3320#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003321
3322 if (stype == WLAN_FC_STYPE_ACTION) {
3323 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003324 wpa_s, data->rx_mgmt.frame,
3325 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003326 data->rx_mgmt.freq,
3327 data->rx_mgmt.ssi_signal);
3328 break;
3329 }
3330
3331 if (wpa_s->ifmsh) {
3332 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003333 break;
3334 }
3335
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003336 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3337 "management frame in non-AP mode");
3338 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003339#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003340 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003341
3342 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3343 data->rx_mgmt.frame_len > 24) {
3344 const u8 *ie = mgmt->u.probe_req.variable;
3345 size_t ie_len = data->rx_mgmt.frame_len -
3346 (mgmt->u.probe_req.variable -
3347 data->rx_mgmt.frame);
3348
3349 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3350 mgmt->bssid, ie, ie_len,
3351 data->rx_mgmt.ssi_signal);
3352 }
3353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003354 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003355#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003356 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003357 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003358 case EVENT_RX_PROBE_REQ:
3359 if (data->rx_probe_req.sa == NULL ||
3360 data->rx_probe_req.ie == NULL)
3361 break;
3362#ifdef CONFIG_AP
3363 if (wpa_s->ap_iface) {
3364 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3365 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003366 data->rx_probe_req.da,
3367 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003368 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003369 data->rx_probe_req.ie_len,
3370 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003371 break;
3372 }
3373#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003374 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003375 data->rx_probe_req.da,
3376 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003377 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003378 data->rx_probe_req.ie_len,
3379 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003380 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003381 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003382#ifdef CONFIG_OFFCHANNEL
3383 offchannel_remain_on_channel_cb(
3384 wpa_s, data->remain_on_channel.freq,
3385 data->remain_on_channel.duration);
3386#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003387 wpas_p2p_remain_on_channel_cb(
3388 wpa_s, data->remain_on_channel.freq,
3389 data->remain_on_channel.duration);
3390 break;
3391 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003392#ifdef CONFIG_OFFCHANNEL
3393 offchannel_cancel_remain_on_channel_cb(
3394 wpa_s, data->remain_on_channel.freq);
3395#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003396 wpas_p2p_cancel_remain_on_channel_cb(
3397 wpa_s, data->remain_on_channel.freq);
3398 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003399 case EVENT_EAPOL_RX:
3400 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3401 data->eapol_rx.data,
3402 data->eapol_rx.data_len);
3403 break;
3404 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003405 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3406 "above=%d signal=%d noise=%d txrate=%d",
3407 data->signal_change.above_threshold,
3408 data->signal_change.current_signal,
3409 data->signal_change.current_noise,
3410 data->signal_change.current_txrate);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003411 bgscan_notify_signal_change(
3412 wpa_s, data->signal_change.above_threshold,
3413 data->signal_change.current_signal,
3414 data->signal_change.current_noise,
3415 data->signal_change.current_txrate);
3416 break;
3417 case EVENT_INTERFACE_ENABLED:
3418 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3419 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003420 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003421 if (wpa_s->p2p_mgmt) {
3422 wpa_supplicant_set_state(wpa_s,
3423 WPA_DISCONNECTED);
3424 break;
3425 }
3426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003427#ifdef CONFIG_AP
3428 if (!wpa_s->ap_iface) {
3429 wpa_supplicant_set_state(wpa_s,
3430 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003431 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003432 wpa_supplicant_req_scan(wpa_s, 0, 0);
3433 } else
3434 wpa_supplicant_set_state(wpa_s,
3435 WPA_COMPLETED);
3436#else /* CONFIG_AP */
3437 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3438 wpa_supplicant_req_scan(wpa_s, 0, 0);
3439#endif /* CONFIG_AP */
3440 }
3441 break;
3442 case EVENT_INTERFACE_DISABLED:
3443 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003444#ifdef CONFIG_P2P
3445 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3446 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3447 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3448 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003449 * Mark interface disabled if this happens to end up not
3450 * being removed as a separate P2P group interface.
3451 */
3452 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3453 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003454 * The interface was externally disabled. Remove
3455 * it assuming an external entity will start a
3456 * new session if needed.
3457 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003458 if (wpa_s->current_ssid &&
3459 wpa_s->current_ssid->p2p_group)
3460 wpas_p2p_interface_unavailable(wpa_s);
3461 else
3462 wpas_p2p_disconnect(wpa_s);
3463 /*
3464 * wpa_s instance may have been freed, so must not use
3465 * it here anymore.
3466 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003467 break;
3468 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003469 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3470 p2p_in_progress(wpa_s->global->p2p) > 1) {
3471 /* This radio work will be cancelled, so clear P2P
3472 * state as well.
3473 */
3474 p2p_stop_find(wpa_s->global->p2p);
3475 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003476#endif /* CONFIG_P2P */
3477
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003478 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3479 /*
3480 * Indicate disconnection to keep ctrl_iface events
3481 * consistent.
3482 */
3483 wpa_supplicant_event_disassoc(
3484 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3485 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003486 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003487 radio_remove_works(wpa_s, NULL, 0);
3488
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003489 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3490 break;
3491 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003492 wpa_supplicant_update_channel_list(
3493 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003494 break;
3495 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003496 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003497 break;
3498 case EVENT_BEST_CHANNEL:
3499 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3500 "(%d %d %d)",
3501 data->best_chan.freq_24, data->best_chan.freq_5,
3502 data->best_chan.freq_overall);
3503 wpa_s->best_24_freq = data->best_chan.freq_24;
3504 wpa_s->best_5_freq = data->best_chan.freq_5;
3505 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003506 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3507 data->best_chan.freq_5,
3508 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003509 break;
3510 case EVENT_UNPROT_DEAUTH:
3511 wpa_supplicant_event_unprot_deauth(wpa_s,
3512 &data->unprot_deauth);
3513 break;
3514 case EVENT_UNPROT_DISASSOC:
3515 wpa_supplicant_event_unprot_disassoc(wpa_s,
3516 &data->unprot_disassoc);
3517 break;
3518 case EVENT_STATION_LOW_ACK:
3519#ifdef CONFIG_AP
3520 if (wpa_s->ap_iface && data)
3521 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3522 data->low_ack.addr);
3523#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003524#ifdef CONFIG_TDLS
3525 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07003526 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3527 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003528#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003529 break;
3530 case EVENT_IBSS_PEER_LOST:
3531#ifdef CONFIG_IBSS_RSN
3532 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3533#endif /* CONFIG_IBSS_RSN */
3534 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003535 case EVENT_DRIVER_GTK_REKEY:
3536 if (os_memcmp(data->driver_gtk_rekey.bssid,
3537 wpa_s->bssid, ETH_ALEN))
3538 break;
3539 if (!wpa_s->wpa)
3540 break;
3541 wpa_sm_update_replay_ctr(wpa_s->wpa,
3542 data->driver_gtk_rekey.replay_ctr);
3543 break;
3544 case EVENT_SCHED_SCAN_STOPPED:
Dmitry Shmidt18463232014-01-24 12:29:41 -08003545 wpa_s->pno = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003546 wpa_s->sched_scanning = 0;
3547 wpa_supplicant_notify_scanning(wpa_s, 0);
3548
3549 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3550 break;
3551
3552 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08003553 * Start a new sched scan to continue searching for more SSIDs
3554 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003555 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07003556 if (wpa_s->sched_scan_timed_out) {
3557 wpa_supplicant_req_sched_scan(wpa_s);
3558 } else if (wpa_s->pno_sched_pending) {
3559 wpa_s->pno_sched_pending = 0;
3560 wpas_start_pno(wpa_s);
Dmitry Shmidt18463232014-01-24 12:29:41 -08003561 }
3562
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003563 break;
3564 case EVENT_WPS_BUTTON_PUSHED:
3565#ifdef CONFIG_WPS
3566 wpas_wps_start_pbc(wpa_s, NULL, 0);
3567#endif /* CONFIG_WPS */
3568 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003569 case EVENT_AVOID_FREQUENCIES:
3570 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3571 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003572 case EVENT_CONNECT_FAILED_REASON:
3573#ifdef CONFIG_AP
3574 if (!wpa_s->ap_iface || !data)
3575 break;
3576 hostapd_event_connect_failed_reason(
3577 wpa_s->ap_iface->bss[0],
3578 data->connect_failed_reason.addr,
3579 data->connect_failed_reason.code);
3580#endif /* CONFIG_AP */
3581 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003582 case EVENT_NEW_PEER_CANDIDATE:
3583#ifdef CONFIG_MESH
3584 if (!wpa_s->ifmsh || !data)
3585 break;
3586 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3587 data->mesh_peer.ies,
3588 data->mesh_peer.ie_len);
3589#endif /* CONFIG_MESH */
3590 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003591 default:
3592 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3593 break;
3594 }
3595}