blob: f1f8864ebe480d6e0bb6fd9e5bf128ca6f85680c [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry 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 Shmidt807291d2015-01-27 13:40:23 -0800479 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800480 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700481 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
482 "frame protection");
483 break;
484 }
485#endif /* CONFIG_IEEE80211W */
486
487 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
488 return 1;
489 }
490
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700491 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700492 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
493 proto_match++;
494
495 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
496 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
497 "failed");
498 break;
499 }
500
501 if (wep_ok &&
502 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
503 {
504 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
505 "in WPA IE");
506 return 1;
507 }
508
509 if (!(ie.proto & ssid->proto)) {
510 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
511 "mismatch");
512 break;
513 }
514
515 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
516 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
517 "cipher mismatch");
518 break;
519 }
520
521 if (!(ie.group_cipher & ssid->group_cipher)) {
522 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
523 "cipher mismatch");
524 break;
525 }
526
527 if (!(ie.key_mgmt & ssid->key_mgmt)) {
528 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
529 "mismatch");
530 break;
531 }
532
533 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
534 return 1;
535 }
536
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700537 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
538 !rsn_ie) {
539 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
540 return 1;
541 }
542
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
544 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
545 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
546 return 0;
547 }
548
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800549 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
550 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
551 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
552 return 1;
553 }
554
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
556 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
557 return 1;
558 }
559
560 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
561 "WPA/WPA2");
562
563 return 0;
564}
565
566
567static int freq_allowed(int *freqs, int freq)
568{
569 int i;
570
571 if (freqs == NULL)
572 return 1;
573
574 for (i = 0; freqs[i]; i++)
575 if (freqs[i] == freq)
576 return 1;
577 return 0;
578}
579
580
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700581static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800582{
583 const struct hostapd_hw_modes *mode = NULL, *modes;
584 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
585 const u8 *rate_ie;
586 int i, j, k;
587
588 if (bss->freq == 0)
589 return 1; /* Cannot do matching without knowing band */
590
591 modes = wpa_s->hw.modes;
592 if (modes == NULL) {
593 /*
594 * The driver does not provide any additional information
595 * about the utilized hardware, so allow the connection attempt
596 * to continue.
597 */
598 return 1;
599 }
600
601 for (i = 0; i < wpa_s->hw.num_modes; i++) {
602 for (j = 0; j < modes[i].num_channels; j++) {
603 int freq = modes[i].channels[j].freq;
604 if (freq == bss->freq) {
605 if (mode &&
606 mode->mode == HOSTAPD_MODE_IEEE80211G)
607 break; /* do not allow 802.11b replace
608 * 802.11g */
609 mode = &modes[i];
610 break;
611 }
612 }
613 }
614
615 if (mode == NULL)
616 return 0;
617
618 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700619 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800620 if (rate_ie == NULL)
621 continue;
622
623 for (j = 2; j < rate_ie[1] + 2; j++) {
624 int flagged = !!(rate_ie[j] & 0x80);
625 int r = (rate_ie[j] & 0x7f) * 5;
626
627 /*
628 * IEEE Std 802.11n-2009 7.3.2.2:
629 * The new BSS Membership selector value is encoded
630 * like a legacy basic rate, but it is not a rate and
631 * only indicates if the BSS members are required to
632 * support the mandatory features of Clause 20 [HT PHY]
633 * in order to join the BSS.
634 */
635 if (flagged && ((rate_ie[j] & 0x7f) ==
636 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
637 if (!ht_supported(mode)) {
638 wpa_dbg(wpa_s, MSG_DEBUG,
639 " hardware does not support "
640 "HT PHY");
641 return 0;
642 }
643 continue;
644 }
645
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700646 /* There's also a VHT selector for 802.11ac */
647 if (flagged && ((rate_ie[j] & 0x7f) ==
648 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
649 if (!vht_supported(mode)) {
650 wpa_dbg(wpa_s, MSG_DEBUG,
651 " hardware does not support "
652 "VHT PHY");
653 return 0;
654 }
655 continue;
656 }
657
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800658 if (!flagged)
659 continue;
660
661 /* check for legacy basic rates */
662 for (k = 0; k < mode->num_rates; k++) {
663 if (mode->rates[k] == r)
664 break;
665 }
666 if (k == mode->num_rates) {
667 /*
668 * IEEE Std 802.11-2007 7.3.2.2 demands that in
669 * order to join a BSS all required rates
670 * have to be supported by the hardware.
671 */
672 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
673 "not support required rate %d.%d Mbps",
674 r / 10, r % 10);
675 return 0;
676 }
677 }
678 }
679
680 return 1;
681}
682
683
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800684/*
685 * Test whether BSS is in an ESS.
686 * This is done differently in DMG (60 GHz) and non-DMG bands
687 */
688static int bss_is_ess(struct wpa_bss *bss)
689{
690 if (bss_is_dmg(bss)) {
691 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
692 IEEE80211_CAP_DMG_AP;
693 }
694
695 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
696 IEEE80211_CAP_ESS);
697}
698
699
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800700static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
701{
702 size_t i;
703
704 for (i = 0; i < ETH_ALEN; i++) {
705 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
706 return 0;
707 }
708 return 1;
709}
710
711
712static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
713{
714 size_t i;
715
716 for (i = 0; i < num; i++) {
717 const u8 *a = list + i * ETH_ALEN * 2;
718 const u8 *m = a + ETH_ALEN;
719
720 if (match_mac_mask(a, addr, m))
721 return 1;
722 }
723 return 0;
724}
725
726
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700727static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700728 int i, struct wpa_bss *bss,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800729 struct wpa_ssid *group,
730 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700731{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700732 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 int wpa;
734 struct wpa_blacklist *e;
735 const u8 *ie;
736 struct wpa_ssid *ssid;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800737 int osen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700738
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700739 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740 wpa_ie_len = ie ? ie[1] : 0;
741
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700742 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700743 rsn_ie_len = ie ? ie[1] : 0;
744
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800745 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
746 osen = ie != NULL;
747
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800749 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700750 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700751 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700752 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
753 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
754 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800755 " p2p" : "",
756 osen ? " osen=1" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757
758 e = wpa_blacklist_get(wpa_s, bss->bssid);
759 if (e) {
760 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700761 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 /*
763 * When only a single network is enabled, we can
764 * trigger blacklisting on the first failure. This
765 * should not be done with multiple enabled networks to
766 * avoid getting forced to move into a worse ESS on
767 * single error if there are no other BSSes of the
768 * current ESS.
769 */
770 limit = 0;
771 }
772 if (e->count > limit) {
773 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
774 "(count=%d limit=%d)", e->count, limit);
775 return NULL;
776 }
777 }
778
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700779 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
781 return NULL;
782 }
783
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800784 if (disallowed_bssid(wpa_s, bss->bssid)) {
785 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
786 return NULL;
787 }
788
789 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
790 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
791 return NULL;
792 }
793
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
795
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800796 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700797 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700798 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700799
Dmitry Shmidt04949592012-07-19 12:16:46 -0700800 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
802 continue;
803 }
804
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700805 res = wpas_temp_disabled(wpa_s, ssid);
806 if (res > 0) {
807 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
808 "temporarily for %d second(s)", res);
809 continue;
810 }
811
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700812#ifdef CONFIG_WPS
813 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
814 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
815 "(WPS)");
816 continue;
817 }
818
819 if (wpa && ssid->ssid_len == 0 &&
820 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
821 check_ssid = 0;
822
823 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
824 /* Only allow wildcard SSID match if an AP
825 * advertises active WPS operation that matches
826 * with our mode. */
827 check_ssid = 1;
828 if (ssid->ssid_len == 0 &&
829 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
830 check_ssid = 0;
831 }
832#endif /* CONFIG_WPS */
833
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800834 if (ssid->bssid_set && ssid->ssid_len == 0 &&
835 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
836 check_ssid = 0;
837
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700839 (bss->ssid_len != ssid->ssid_len ||
840 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
842 continue;
843 }
844
845 if (ssid->bssid_set &&
846 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
847 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
848 continue;
849 }
850
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800851 /* check blacklist */
852 if (ssid->num_bssid_blacklist &&
853 addr_in_list(bss->bssid, ssid->bssid_blacklist,
854 ssid->num_bssid_blacklist)) {
855 wpa_dbg(wpa_s, MSG_DEBUG,
856 " skip - BSSID blacklisted");
857 continue;
858 }
859
860 /* if there is a whitelist, only accept those APs */
861 if (ssid->num_bssid_whitelist &&
862 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
863 ssid->num_bssid_whitelist)) {
864 wpa_dbg(wpa_s, MSG_DEBUG,
865 " skip - BSSID not in whitelist");
866 continue;
867 }
868
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
870 continue;
871
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800872 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700873 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
874 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
875 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
876 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
877 "not allowed");
878 continue;
879 }
880
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700881 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
882 has_wep_key(ssid)) {
883 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
884 continue;
885 }
886
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800887 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
888 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
889 "not allowed");
890 continue;
891 }
892
Jouni Malinen75ecf522011-06-27 15:19:46 -0700893 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
895 "mismatch");
896 continue;
897 }
898
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800899 if (!bss_is_ess(bss)) {
900 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700901 continue;
902 }
903
904 if (!freq_allowed(ssid->freq_list, bss->freq)) {
905 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
906 "allowed");
907 continue;
908 }
909
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800910 if (!rate_match(wpa_s, bss)) {
911 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
912 "not match");
913 continue;
914 }
915
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -0700917 if (ssid->p2p_group &&
918 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
919 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
920 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
921 continue;
922 }
923
Dmitry Shmidt54605472013-11-08 11:10:19 -0800924 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
925 struct wpabuf *p2p_ie;
926 u8 dev_addr[ETH_ALEN];
927
928 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
929 if (ie == NULL) {
930 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
931 continue;
932 }
933 p2p_ie = wpa_bss_get_vendor_ie_multi(
934 bss, P2P_IE_VENDOR_TYPE);
935 if (p2p_ie == NULL) {
936 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
937 continue;
938 }
939
940 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
941 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
942 ETH_ALEN) != 0) {
943 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
944 wpabuf_free(p2p_ie);
945 continue;
946 }
947 wpabuf_free(p2p_ie);
948 }
949
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 /*
951 * TODO: skip the AP if its P2P IE has Group Formation
952 * bit set in the P2P Group Capability Bitmap and we
953 * are not in Group Formation with that device.
954 */
955#endif /* CONFIG_P2P */
956
957 /* Matching configuration found */
958 return ssid;
959 }
960
961 /* No matching configuration found */
962 return NULL;
963}
964
965
966static struct wpa_bss *
967wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700968 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800969 struct wpa_ssid **selected_ssid,
970 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700972 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700973
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800974 if (only_first_ssid)
975 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
976 group->id);
977 else
978 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
979 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700981 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
982 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800983 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
984 only_first_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985 if (!*selected_ssid)
986 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700987 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
988 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700989 MAC2STR(bss->bssid),
990 wpa_ssid_txt(bss->ssid, bss->ssid_len));
991 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 }
993
994 return NULL;
995}
996
997
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700998struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
999 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000{
1001 struct wpa_bss *selected = NULL;
1002 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001003 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001005 if (wpa_s->last_scan_res == NULL ||
1006 wpa_s->last_scan_res_used == 0)
1007 return NULL; /* no scan results from last update */
1008
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001009 if (wpa_s->next_ssid) {
1010 struct wpa_ssid *ssid;
1011
1012 /* check that next_ssid is still valid */
1013 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1014 if (ssid == wpa_s->next_ssid)
1015 break;
1016 }
1017 next_ssid = ssid;
1018 wpa_s->next_ssid = NULL;
1019 }
1020
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001021 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001022 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1023 if (next_ssid && next_ssid->priority ==
1024 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001025 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001026 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001027 if (selected)
1028 break;
1029 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001031 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001032 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033 if (selected)
1034 break;
1035 }
1036
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001037 if (selected == NULL && wpa_s->blacklist &&
1038 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001039 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1040 "blacklist and try again");
1041 wpa_blacklist_clear(wpa_s);
1042 wpa_s->blacklist_cleared++;
1043 } else if (selected == NULL)
1044 break;
1045 }
1046
1047 return selected;
1048}
1049
1050
1051static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1052 int timeout_sec, int timeout_usec)
1053{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001054 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055 /*
1056 * No networks are enabled; short-circuit request so
1057 * we don't wait timeout seconds before transitioning
1058 * to INACTIVE state.
1059 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001060 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1061 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001062 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1063 return;
1064 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001065
1066 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001067 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1068}
1069
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001070
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001071int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001072 struct wpa_bss *selected,
1073 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074{
1075 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1076 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1077 "PBC session overlap");
1078#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001079 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1080 wpa_s->p2p_in_provisioning) {
1081 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1082 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001083 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001084 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001085#endif /* CONFIG_P2P */
1086
1087#ifdef CONFIG_WPS
1088 wpas_wps_cancel(wpa_s);
1089#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001090 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091 }
1092
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001093 wpa_msg(wpa_s, MSG_DEBUG,
1094 "Considering connect request: reassociate: %d selected: "
1095 MACSTR " bssid: " MACSTR " pending: " MACSTR
1096 " wpa_state: %s ssid=%p current_ssid=%p",
1097 wpa_s->reassociate, MAC2STR(selected->bssid),
1098 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1099 wpa_supplicant_state_txt(wpa_s->wpa_state),
1100 ssid, wpa_s->current_ssid);
1101
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102 /*
1103 * Do not trigger new association unless the BSSID has changed or if
1104 * reassociation is requested. If we are in process of associating with
1105 * the selected BSSID, do not trigger new attempt.
1106 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001107 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001108 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1109 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1110 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001111 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1112 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1113 0) ||
1114 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1115 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001116 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1117 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001118 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001119 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001120 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1121 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001122 wpa_supplicant_associate(wpa_s, selected, ssid);
1123 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001124 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1125 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001126 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001127
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001128 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129}
1130
1131
1132static struct wpa_ssid *
1133wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1134{
1135 int prio;
1136 struct wpa_ssid *ssid;
1137
1138 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1139 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1140 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001141 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001142 continue;
1143 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001144 ssid->mode == IEEE80211_MODE_AP ||
1145 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001146 return ssid;
1147 }
1148 }
1149 return NULL;
1150}
1151
1152
1153/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1154 * on BSS added and BSS changed events */
1155static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001156 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001158 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001159
1160 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1161 return;
1162
Jouni Malinen87fd2792011-05-16 18:35:42 +03001163 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001165
Jouni Malinen87fd2792011-05-16 18:35:42 +03001166 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001167 if (ssid == NULL)
1168 continue;
1169
Jouni Malinen87fd2792011-05-16 18:35:42 +03001170 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001171 if (rsn == NULL)
1172 continue;
1173
Jouni Malinen87fd2792011-05-16 18:35:42 +03001174 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001175 }
1176
1177}
1178
1179
1180static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1181 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001182 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001184 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001185 int min_diff;
1186
1187 if (wpa_s->reassociate)
1188 return 1; /* explicit request to reassociate */
1189 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1190 return 1; /* we are not associated; continue */
1191 if (wpa_s->current_ssid == NULL)
1192 return 1; /* unknown current SSID */
1193 if (wpa_s->current_ssid != ssid)
1194 return 1; /* different network block */
1195
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001196 if (wpas_driver_bss_selection(wpa_s))
1197 return 0; /* Driver-based roaming */
1198
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001199 if (wpa_s->current_ssid->ssid)
1200 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1201 wpa_s->current_ssid->ssid,
1202 wpa_s->current_ssid->ssid_len);
1203 if (!current_bss)
1204 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001205
1206 if (!current_bss)
1207 return 1; /* current BSS not seen in scan results */
1208
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001209 if (current_bss == selected)
1210 return 0;
1211
1212 if (selected->last_update_idx > current_bss->last_update_idx)
1213 return 1; /* current BSS not seen in the last scan */
1214
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001215#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1217 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1218 MAC2STR(current_bss->bssid), current_bss->level);
1219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1220 MAC2STR(selected->bssid), selected->level);
1221
1222 if (wpa_s->current_ssid->bssid_set &&
1223 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1224 0) {
1225 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1226 "has preferred BSSID");
1227 return 1;
1228 }
1229
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001230 if (current_bss->level < 0 && current_bss->level > selected->level) {
1231 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1232 "signal level");
1233 return 0;
1234 }
1235
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001236 min_diff = 2;
1237 if (current_bss->level < 0) {
1238 if (current_bss->level < -85)
1239 min_diff = 1;
1240 else if (current_bss->level < -80)
1241 min_diff = 2;
1242 else if (current_bss->level < -75)
1243 min_diff = 3;
1244 else if (current_bss->level < -70)
1245 min_diff = 4;
1246 else
1247 min_diff = 5;
1248 }
1249 if (abs(current_bss->level - selected->level) < min_diff) {
1250 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1251 "in signal level");
1252 return 0;
1253 }
1254
1255 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001256#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001257 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001258#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259}
1260
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001261
Jouni Malinen89ca7022012-09-14 13:03:12 -07001262/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001263 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001264static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001265 union wpa_event_data *data,
1266 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001268 struct wpa_scan_results *scan_res = NULL;
1269 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001271#ifndef CONFIG_NO_RANDOM_POOL
1272 size_t i, num;
1273#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001274
1275#ifdef CONFIG_AP
1276 if (wpa_s->ap_iface)
1277 ap = 1;
1278#endif /* CONFIG_AP */
1279
1280 wpa_supplicant_notify_scanning(wpa_s, 0);
1281
1282 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1283 data ? &data->scan_info :
1284 NULL, 1);
1285 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001286 if (wpa_s->conf->ap_scan == 2 || ap ||
1287 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001288 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001289 if (!own_request)
1290 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001291 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1292 "scanning again");
1293 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001294 ret = -1;
1295 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001296 }
1297
1298#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001299 num = scan_res->num;
1300 if (num > 10)
1301 num = 10;
1302 for (i = 0; i < num; i++) {
1303 u8 buf[5];
1304 struct wpa_scan_res *res = scan_res->res[i];
1305 buf[0] = res->bssid[5];
1306 buf[1] = res->qual & 0xff;
1307 buf[2] = res->noise & 0xff;
1308 buf[3] = res->level & 0xff;
1309 buf[4] = res->tsf & 0xff;
1310 random_add_randomness(buf, sizeof(buf));
1311 }
1312#endif /* CONFIG_NO_RANDOM_POOL */
1313
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001314 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001315 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1317 struct wpa_scan_results *scan_res);
1318
1319 scan_res_handler = wpa_s->scan_res_handler;
1320 wpa_s->scan_res_handler = NULL;
1321 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001322 ret = -2;
1323 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001324 }
1325
1326 if (ap) {
1327 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1328#ifdef CONFIG_AP
1329 if (wpa_s->ap_iface->scan_cb)
1330 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1331#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001332 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001333 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001334
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001335 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001336 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001337 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1338 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1339 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1340 wpa_s->manual_scan_id);
1341 wpa_s->manual_scan_use_id = 0;
1342 } else {
1343 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1344 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001345 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001346
1347 wpas_notify_scan_done(wpa_s, 1);
1348
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001349 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001350 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 -07001351 wpa_scan_results_free(scan_res);
1352 return 0;
1353 }
1354
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001355 if (wnm_scan_process(wpa_s, 1) > 0)
1356 goto scan_work_done;
1357
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001358 if (sme_proc_obss_scan(wpa_s) > 0)
1359 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001360
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001361 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1362 goto scan_work_done;
1363
1364 if (autoscan_notify_scan(wpa_s, scan_res))
1365 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001366
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001367 if (wpa_s->disconnected) {
1368 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001369 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001370 }
1371
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001372 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001373 bgscan_notify_scan(wpa_s, scan_res) == 1)
1374 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001376 wpas_wps_update_ap_info(wpa_s, scan_res);
1377
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001378 wpa_scan_results_free(scan_res);
1379
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001380 if (wpa_s->scan_work) {
1381 struct wpa_radio_work *work = wpa_s->scan_work;
1382 wpa_s->scan_work = NULL;
1383 radio_work_done(work);
1384 }
1385
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001386 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001387
1388scan_work_done:
1389 wpa_scan_results_free(scan_res);
1390 if (wpa_s->scan_work) {
1391 struct wpa_radio_work *work = wpa_s->scan_work;
1392 wpa_s->scan_work = NULL;
1393 radio_work_done(work);
1394 }
1395 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001396}
1397
1398
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001399static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001400 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001401{
1402 struct wpa_bss *selected;
1403 struct wpa_ssid *ssid = NULL;
1404
1405 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001406
1407 if (selected) {
1408 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001409 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001410 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001411 if (new_scan)
1412 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001413 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001414 }
1415
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001416 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001417 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001418 return -1;
1419 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001420 if (new_scan)
1421 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001422 /*
1423 * Do not notify other virtual radios of scan results since we do not
1424 * want them to start other associations at the same time.
1425 */
1426 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001428#ifdef CONFIG_MESH
1429 if (wpa_s->ifmsh) {
1430 wpa_msg(wpa_s, MSG_INFO,
1431 "Avoiding join because we already joined a mesh group");
1432 return 0;
1433 }
1434#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001435 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1436 ssid = wpa_supplicant_pick_new_network(wpa_s);
1437 if (ssid) {
1438 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1439 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001440 if (new_scan)
1441 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001442 } else if (own_request) {
1443 /*
1444 * No SSID found. If SCAN results are as a result of
1445 * own scan request and not due to a scan request on
1446 * another shared interface, try another scan.
1447 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001448 int timeout_sec = wpa_s->scan_interval;
1449 int timeout_usec = 0;
1450#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001451 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1452 return 0;
1453
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001454 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07001455 wpa_s->show_group_started ||
1456 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457 /*
1458 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001459 * state and during P2P join-a-group operation
1460 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001461 */
1462 timeout_sec = 0;
1463 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001464 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1465 timeout_usec);
1466 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001467 }
1468#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001469#ifdef CONFIG_INTERWORKING
1470 if (wpa_s->conf->auto_interworking &&
1471 wpa_s->conf->interworking &&
1472 wpa_s->conf->cred) {
1473 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1474 "start ANQP fetch since no matching "
1475 "networks found");
1476 wpa_s->network_select = 1;
1477 wpa_s->auto_network_select = 1;
1478 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001479 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001480 }
1481#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001482#ifdef CONFIG_WPS
1483 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1484 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1485 timeout_sec = 0;
1486 timeout_usec = 500000;
1487 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1488 timeout_usec);
1489 return 0;
1490 }
1491#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001492 if (wpa_supplicant_req_sched_scan(wpa_s))
1493 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1494 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001495 }
1496 }
1497 return 0;
1498}
1499
1500
1501static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1502 union wpa_event_data *data)
1503{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001504 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001505
1506 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001507 /*
1508 * If no scan results could be fetched, then no need to
1509 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001510 * this scan. Similarly, if scan results started a new operation on this
1511 * interface, do not notify other interfaces to avoid concurrent
1512 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513 */
1514 return;
1515 }
1516
1517 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001518 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001519 * so, they get updated with this same scan info.
1520 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001521 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1522 radio_list) {
1523 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001524 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1525 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001526 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001527 }
1528 }
1529}
1530
1531#endif /* CONFIG_NO_SCAN_PROCESSING */
1532
1533
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001534int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1535{
1536#ifdef CONFIG_NO_SCAN_PROCESSING
1537 return -1;
1538#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001539 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001540
1541 if (wpa_s->last_scan_res_used <= 0)
1542 return -1;
1543
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001544 os_get_reltime(&now);
1545 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001546 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1547 return -1;
1548 }
1549
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001550 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001551#endif /* CONFIG_NO_SCAN_PROCESSING */
1552}
1553
Dmitry Shmidt04949592012-07-19 12:16:46 -07001554#ifdef CONFIG_WNM
1555
1556static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1557{
1558 struct wpa_supplicant *wpa_s = eloop_ctx;
1559
1560 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1561 return;
1562
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001563 if (!wpa_s->no_keep_alive) {
1564 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1565 MAC2STR(wpa_s->bssid));
1566 /* TODO: could skip this if normal data traffic has been sent */
1567 /* TODO: Consider using some more appropriate data frame for
1568 * this */
1569 if (wpa_s->l2)
1570 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1571 (u8 *) "", 0);
1572 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001573
1574#ifdef CONFIG_SME
1575 if (wpa_s->sme.bss_max_idle_period) {
1576 unsigned int msec;
1577 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1578 if (msec > 100)
1579 msec -= 100;
1580 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1581 wnm_bss_keep_alive, wpa_s, NULL);
1582 }
1583#endif /* CONFIG_SME */
1584}
1585
1586
1587static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1588 const u8 *ies, size_t ies_len)
1589{
1590 struct ieee802_11_elems elems;
1591
1592 if (ies == NULL)
1593 return;
1594
1595 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1596 return;
1597
1598#ifdef CONFIG_SME
1599 if (elems.bss_max_idle_period) {
1600 unsigned int msec;
1601 wpa_s->sme.bss_max_idle_period =
1602 WPA_GET_LE16(elems.bss_max_idle_period);
1603 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1604 "TU)%s", wpa_s->sme.bss_max_idle_period,
1605 (elems.bss_max_idle_period[2] & 0x01) ?
1606 " (protected keep-live required)" : "");
1607 if (wpa_s->sme.bss_max_idle_period == 0)
1608 wpa_s->sme.bss_max_idle_period = 1;
1609 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1610 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1611 /* msec times 1000 */
1612 msec = wpa_s->sme.bss_max_idle_period * 1024;
1613 if (msec > 100)
1614 msec -= 100;
1615 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1616 wnm_bss_keep_alive, wpa_s,
1617 NULL);
1618 }
1619 }
1620#endif /* CONFIG_SME */
1621}
1622
1623#endif /* CONFIG_WNM */
1624
1625
1626void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1627{
1628#ifdef CONFIG_WNM
1629 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1630#endif /* CONFIG_WNM */
1631}
1632
1633
Dmitry Shmidt051af732013-10-22 13:52:46 -07001634#ifdef CONFIG_INTERWORKING
1635
1636static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1637 size_t len)
1638{
1639 int res;
1640
1641 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1642 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1643 if (res) {
1644 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1645 }
1646
1647 return res;
1648}
1649
1650
1651static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1652 const u8 *ies, size_t ies_len)
1653{
1654 struct ieee802_11_elems elems;
1655
1656 if (ies == NULL)
1657 return;
1658
1659 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1660 return;
1661
1662 if (elems.qos_map_set) {
1663 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1664 elems.qos_map_set_len);
1665 }
1666}
1667
1668#endif /* CONFIG_INTERWORKING */
1669
1670
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001671static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1672 union wpa_event_data *data)
1673{
1674 int l, len, found = 0, wpa_found, rsn_found;
1675 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001676#ifdef CONFIG_IEEE80211R
1677 u8 bssid[ETH_ALEN];
1678#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679
1680 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1681 if (data->assoc_info.req_ies)
1682 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1683 data->assoc_info.req_ies_len);
1684 if (data->assoc_info.resp_ies) {
1685 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1686 data->assoc_info.resp_ies_len);
1687#ifdef CONFIG_TDLS
1688 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1689 data->assoc_info.resp_ies_len);
1690#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001691#ifdef CONFIG_WNM
1692 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1693 data->assoc_info.resp_ies_len);
1694#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001695#ifdef CONFIG_INTERWORKING
1696 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1697 data->assoc_info.resp_ies_len);
1698#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001699 }
1700 if (data->assoc_info.beacon_ies)
1701 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1702 data->assoc_info.beacon_ies,
1703 data->assoc_info.beacon_ies_len);
1704 if (data->assoc_info.freq)
1705 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1706 data->assoc_info.freq);
1707
1708 p = data->assoc_info.req_ies;
1709 l = data->assoc_info.req_ies_len;
1710
1711 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1712 while (p && l >= 2) {
1713 len = p[1] + 2;
1714 if (len > l) {
1715 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1716 p, l);
1717 break;
1718 }
1719 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1720 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1721 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1722 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1723 break;
1724 found = 1;
1725 wpa_find_assoc_pmkid(wpa_s);
1726 break;
1727 }
1728 l -= len;
1729 p += len;
1730 }
1731 if (!found && data->assoc_info.req_ies)
1732 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1733
1734#ifdef CONFIG_IEEE80211R
1735#ifdef CONFIG_SME
1736 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001737 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1738 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1739 data->assoc_info.resp_ies,
1740 data->assoc_info.resp_ies_len,
1741 bssid) < 0) {
1742 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1743 "Reassociation Response failed");
1744 wpa_supplicant_deauthenticate(
1745 wpa_s, WLAN_REASON_INVALID_IE);
1746 return -1;
1747 }
1748 }
1749
1750 p = data->assoc_info.resp_ies;
1751 l = data->assoc_info.resp_ies_len;
1752
1753#ifdef CONFIG_WPS_STRICT
1754 if (p && wpa_s->current_ssid &&
1755 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1756 struct wpabuf *wps;
1757 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1758 if (wps == NULL) {
1759 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1760 "include WPS IE in (Re)Association Response");
1761 return -1;
1762 }
1763
1764 if (wps_validate_assoc_resp(wps) < 0) {
1765 wpabuf_free(wps);
1766 wpa_supplicant_deauthenticate(
1767 wpa_s, WLAN_REASON_INVALID_IE);
1768 return -1;
1769 }
1770 wpabuf_free(wps);
1771 }
1772#endif /* CONFIG_WPS_STRICT */
1773
1774 /* Go through the IEs and make a copy of the MDIE, if present. */
1775 while (p && l >= 2) {
1776 len = p[1] + 2;
1777 if (len > l) {
1778 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1779 p, l);
1780 break;
1781 }
1782 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1783 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1784 wpa_s->sme.ft_used = 1;
1785 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1786 MOBILITY_DOMAIN_ID_LEN);
1787 break;
1788 }
1789 l -= len;
1790 p += len;
1791 }
1792#endif /* CONFIG_SME */
1793
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001794 /* Process FT when SME is in the driver */
1795 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1796 wpa_ft_is_completed(wpa_s->wpa)) {
1797 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1798 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1799 data->assoc_info.resp_ies,
1800 data->assoc_info.resp_ies_len,
1801 bssid) < 0) {
1802 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1803 "Reassociation Response failed");
1804 wpa_supplicant_deauthenticate(
1805 wpa_s, WLAN_REASON_INVALID_IE);
1806 return -1;
1807 }
1808 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1809 }
1810
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001811 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1812 data->assoc_info.resp_ies_len);
1813#endif /* CONFIG_IEEE80211R */
1814
1815 /* WPA/RSN IE from Beacon/ProbeResp */
1816 p = data->assoc_info.beacon_ies;
1817 l = data->assoc_info.beacon_ies_len;
1818
1819 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1820 */
1821 wpa_found = rsn_found = 0;
1822 while (p && l >= 2) {
1823 len = p[1] + 2;
1824 if (len > l) {
1825 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1826 p, l);
1827 break;
1828 }
1829 if (!wpa_found &&
1830 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1831 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1832 wpa_found = 1;
1833 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1834 }
1835
1836 if (!rsn_found &&
1837 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1838 rsn_found = 1;
1839 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1840 }
1841
1842 l -= len;
1843 p += len;
1844 }
1845
1846 if (!wpa_found && data->assoc_info.beacon_ies)
1847 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1848 if (!rsn_found && data->assoc_info.beacon_ies)
1849 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1850 if (wpa_found || rsn_found)
1851 wpa_s->ap_ies_from_associnfo = 1;
1852
Jouni Malinen87fd2792011-05-16 18:35:42 +03001853 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1854 wpa_s->assoc_freq != data->assoc_info.freq) {
1855 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1856 "%u to %u MHz",
1857 wpa_s->assoc_freq, data->assoc_info.freq);
1858 wpa_supplicant_update_scan_results(wpa_s);
1859 }
1860
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001861 wpa_s->assoc_freq = data->assoc_info.freq;
1862
1863 return 0;
1864}
1865
1866
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001867static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1868{
1869 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1870
1871 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1872 return -1;
1873
1874 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1875 return 0;
1876
1877 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1878 WPA_IE_VENDOR_TYPE);
1879 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1880
1881 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1882 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1883 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1884 bss_rsn ? 2 + bss_rsn[1] : 0))
1885 return -1;
1886
1887 return 0;
1888}
1889
1890
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001891static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1892 union wpa_event_data *data)
1893{
1894 u8 bssid[ETH_ALEN];
1895 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001896
1897#ifdef CONFIG_AP
1898 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001899 if (!data)
1900 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001901 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1902 data->assoc_info.addr,
1903 data->assoc_info.req_ies,
1904 data->assoc_info.req_ies_len,
1905 data->assoc_info.reassoc);
1906 return;
1907 }
1908#endif /* CONFIG_AP */
1909
1910 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1911 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1912 return;
1913
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001914 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1915 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001916 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001917 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1918 return;
1919 }
1920
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001921 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001922 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001923 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1924 MACSTR, MAC2STR(bssid));
1925 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001926 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1927 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001928 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001929
1930 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1931 wpa_clear_keys(wpa_s, bssid);
1932 }
1933 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001934 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001935 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1936 return;
1937 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001938
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001939#ifdef ANDROID
1940 if (wpa_s->conf->ap_scan == 1) {
1941#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001942 if (wpa_s->conf->ap_scan == 1 &&
1943 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001944#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001945 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1946 wpa_msg(wpa_s, MSG_WARNING,
1947 "WPA/RSN IEs not updated");
1948 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001949 }
1950
1951#ifdef CONFIG_SME
1952 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1953 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07001954 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001955#endif /* CONFIG_SME */
1956
1957 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1958 if (wpa_s->current_ssid) {
1959 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1960 * initialized before association, but for other modes,
1961 * initialize PC/SC here, if the current configuration needs
1962 * smartcard or SIM/USIM. */
1963 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1964 }
1965 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1966 if (wpa_s->l2)
1967 l2_packet_notify_auth_start(wpa_s->l2);
1968
1969 /*
1970 * Set portEnabled first to FALSE in order to get EAP state machine out
1971 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1972 * state machine may transit to AUTHENTICATING state based on obsolete
1973 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1974 * AUTHENTICATED without ever giving chance to EAP state machine to
1975 * reset the state.
1976 */
1977 if (!ft_completed) {
1978 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1979 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1980 }
1981 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1982 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1983 /* 802.1X::portControl = Auto */
1984 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1985 wpa_s->eapol_received = 0;
1986 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1987 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1988 (wpa_s->current_ssid &&
1989 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001990 if (wpa_s->current_ssid &&
1991 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001992 (wpa_s->drv_flags &
1993 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1994 /*
1995 * Set the key after having received joined-IBSS event
1996 * from the driver.
1997 */
1998 wpa_supplicant_set_wpa_none_key(wpa_s,
1999 wpa_s->current_ssid);
2000 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002001 wpa_supplicant_cancel_auth_timeout(wpa_s);
2002 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2003 } else if (!ft_completed) {
2004 /* Timeout for receiving the first EAPOL packet */
2005 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2006 }
2007 wpa_supplicant_cancel_scan(wpa_s);
2008
2009 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2010 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2011 /*
2012 * We are done; the driver will take care of RSN 4-way
2013 * handshake.
2014 */
2015 wpa_supplicant_cancel_auth_timeout(wpa_s);
2016 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2017 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2018 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2019 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2020 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2021 /*
2022 * The driver will take care of RSN 4-way handshake, so we need
2023 * to allow EAPOL supplicant to complete its work without
2024 * waiting for WPA supplicant.
2025 */
2026 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2027 } else if (ft_completed) {
2028 /*
2029 * FT protocol completed - make sure EAPOL state machine ends
2030 * up in authenticated.
2031 */
2032 wpa_supplicant_cancel_auth_timeout(wpa_s);
2033 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2034 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2035 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2036 }
2037
Jouni Malinena05074c2012-12-21 21:35:35 +02002038 wpa_s->last_eapol_matches_bssid = 0;
2039
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002040 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002041 struct os_reltime now, age;
2042 os_get_reltime(&now);
2043 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002044 if (age.sec == 0 && age.usec < 100000 &&
2045 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2046 0) {
2047 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2048 "frame that was received just before "
2049 "association notification");
2050 wpa_supplicant_rx_eapol(
2051 wpa_s, wpa_s->pending_eapol_rx_src,
2052 wpabuf_head(wpa_s->pending_eapol_rx),
2053 wpabuf_len(wpa_s->pending_eapol_rx));
2054 }
2055 wpabuf_free(wpa_s->pending_eapol_rx);
2056 wpa_s->pending_eapol_rx = NULL;
2057 }
2058
2059 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2060 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002061 wpa_s->current_ssid &&
2062 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002063 /* Set static WEP keys again */
2064 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2065 }
2066
2067#ifdef CONFIG_IBSS_RSN
2068 if (wpa_s->current_ssid &&
2069 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2070 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2071 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2072 wpa_s->ibss_rsn == NULL) {
2073 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2074 if (!wpa_s->ibss_rsn) {
2075 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2076 wpa_supplicant_deauthenticate(
2077 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2078 return;
2079 }
2080
2081 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2082 }
2083#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002084
2085 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002086
2087 if (data) {
2088 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2089 data->assoc_info.resp_ies_len,
2090 &data->assoc_info.wmm_params);
2091
2092 if (wpa_s->reassoc_same_bss)
2093 wmm_ac_restore_tspecs(wpa_s);
2094 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002095}
2096
2097
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002098static int disconnect_reason_recoverable(u16 reason_code)
2099{
2100 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2101 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2102 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2103}
2104
2105
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002106static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002107 u16 reason_code,
2108 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002109{
2110 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002111
2112 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2113 /*
2114 * At least Host AP driver and a Prism3 card seemed to be
2115 * generating streams of disconnected events when configuring
2116 * IBSS for WPA-None. Ignore them for now.
2117 */
2118 return;
2119 }
2120
2121 bssid = wpa_s->bssid;
2122 if (is_zero_ether_addr(bssid))
2123 bssid = wpa_s->pending_bssid;
2124
2125 if (!is_zero_ether_addr(bssid) ||
2126 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2127 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2128 " reason=%d%s",
2129 MAC2STR(bssid), reason_code,
2130 locally_generated ? " locally_generated=1" : "");
2131 }
2132}
2133
2134
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002135static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2136 int locally_generated)
2137{
2138 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2139 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2140 return 0; /* Not in 4-way handshake with PSK */
2141
2142 /*
2143 * It looks like connection was lost while trying to go through PSK
2144 * 4-way handshake. Filter out known disconnection cases that are caused
2145 * by something else than PSK mismatch to avoid confusing reports.
2146 */
2147
2148 if (locally_generated) {
2149 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2150 return 0;
2151 }
2152
2153 return 1;
2154}
2155
2156
Jouni Malinen2b89da82012-08-31 22:04:41 +03002157static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2158 u16 reason_code,
2159 int locally_generated)
2160{
2161 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162 int authenticating;
2163 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002164 struct wpa_bss *fast_reconnect = NULL;
2165 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002166 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002167
2168 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2169 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2170
2171 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2172 /*
2173 * At least Host AP driver and a Prism3 card seemed to be
2174 * generating streams of disconnected events when configuring
2175 * IBSS for WPA-None. Ignore them for now.
2176 */
2177 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2178 "IBSS/WPA-None mode");
2179 return;
2180 }
2181
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002182 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002183 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2184 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002185 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2186 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002187 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002188 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002189 if (!wpa_s->disconnected &&
2190 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002191 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2192 wpas_wps_searching(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002193 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002194 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002195 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002196 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002197 wpa_s->wpa_state);
2198 if (wpa_s->wpa_state == WPA_COMPLETED &&
2199 wpa_s->current_ssid &&
2200 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002201 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002202 disconnect_reason_recoverable(reason_code)) {
2203 /*
2204 * It looks like the AP has dropped association with
2205 * us, but could allow us to get back in. Try to
2206 * reconnect to the same BSS without full scan to save
2207 * time for some common cases.
2208 */
2209 fast_reconnect = wpa_s->current_bss;
2210 fast_reconnect_ssid = wpa_s->current_ssid;
2211 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002212 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002213 else
2214 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2215 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002216 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002217 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002218 "try to re-connect");
2219 wpa_s->reassociate = 0;
2220 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002221 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002222 }
2223 bssid = wpa_s->bssid;
2224 if (is_zero_ether_addr(bssid))
2225 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002226 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2227 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002228 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002229 if (locally_generated)
2230 wpa_s->disconnect_reason = -reason_code;
2231 else
2232 wpa_s->disconnect_reason = reason_code;
2233 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2235 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002236 wpa_clear_keys(wpa_s, wpa_s->bssid);
2237 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002238 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239 wpa_supplicant_mark_disassoc(wpa_s);
2240
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002241 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002243 wpa_s->current_ssid = last_ssid;
2244 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002245
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002246 if (fast_reconnect &&
2247 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2248 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2249 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2250 fast_reconnect->ssid_len) &&
2251 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002252#ifndef CONFIG_NO_SCAN_PROCESSING
2253 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2254 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2255 fast_reconnect_ssid) < 0) {
2256 /* Recover through full scan */
2257 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2258 }
2259#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002260 } else if (fast_reconnect) {
2261 /*
2262 * Could not reconnect to the same BSS due to network being
2263 * disabled. Use a new scan to match the alternative behavior
2264 * above, i.e., to continue automatic reconnection attempt in a
2265 * way that enforces disabled network rules.
2266 */
2267 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002268 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002269}
2270
2271
2272#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002273void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274{
2275 struct wpa_supplicant *wpa_s = eloop_ctx;
2276
2277 if (!wpa_s->pending_mic_error_report)
2278 return;
2279
2280 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2281 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2282 wpa_s->pending_mic_error_report = 0;
2283}
2284#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2285
2286
2287static void
2288wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2289 union wpa_event_data *data)
2290{
2291 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002292 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002293
2294 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2295 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002296 os_get_reltime(&t);
2297 if ((wpa_s->last_michael_mic_error.sec &&
2298 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002299 wpa_s->pending_mic_error_report) {
2300 if (wpa_s->pending_mic_error_report) {
2301 /*
2302 * Send the pending MIC error report immediately since
2303 * we are going to start countermeasures and AP better
2304 * do the same.
2305 */
2306 wpa_sm_key_request(wpa_s->wpa, 1,
2307 wpa_s->pending_mic_error_pairwise);
2308 }
2309
2310 /* Send the new MIC error report immediately since we are going
2311 * to start countermeasures and AP better do the same.
2312 */
2313 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2314
2315 /* initialize countermeasures */
2316 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002317
2318 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2319
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002320 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2321
2322 /*
2323 * Need to wait for completion of request frame. We do not get
2324 * any callback for the message completion, so just wait a
2325 * short while and hope for the best. */
2326 os_sleep(0, 10000);
2327
2328 wpa_drv_set_countermeasures(wpa_s, 1);
2329 wpa_supplicant_deauthenticate(wpa_s,
2330 WLAN_REASON_MICHAEL_MIC_FAILURE);
2331 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2332 wpa_s, NULL);
2333 eloop_register_timeout(60, 0,
2334 wpa_supplicant_stop_countermeasures,
2335 wpa_s, NULL);
2336 /* TODO: mark the AP rejected for 60 second. STA is
2337 * allowed to associate with another AP.. */
2338 } else {
2339#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2340 if (wpa_s->mic_errors_seen) {
2341 /*
2342 * Reduce the effectiveness of Michael MIC error
2343 * reports as a means for attacking against TKIP if
2344 * more than one MIC failure is noticed with the same
2345 * PTK. We delay the transmission of the reports by a
2346 * random time between 0 and 60 seconds in order to
2347 * force the attacker wait 60 seconds before getting
2348 * the information on whether a frame resulted in a MIC
2349 * failure.
2350 */
2351 u8 rval[4];
2352 int sec;
2353
2354 if (os_get_random(rval, sizeof(rval)) < 0)
2355 sec = os_random() % 60;
2356 else
2357 sec = WPA_GET_BE32(rval) % 60;
2358 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2359 "report %d seconds", sec);
2360 wpa_s->pending_mic_error_report = 1;
2361 wpa_s->pending_mic_error_pairwise = pairwise;
2362 eloop_cancel_timeout(
2363 wpa_supplicant_delayed_mic_error_report,
2364 wpa_s, NULL);
2365 eloop_register_timeout(
2366 sec, os_random() % 1000000,
2367 wpa_supplicant_delayed_mic_error_report,
2368 wpa_s, NULL);
2369 } else {
2370 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2371 }
2372#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2373 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2374#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2375 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002376 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002377 wpa_s->mic_errors_seen++;
2378}
2379
2380
2381#ifdef CONFIG_TERMINATE_ONLASTIF
2382static int any_interfaces(struct wpa_supplicant *head)
2383{
2384 struct wpa_supplicant *wpa_s;
2385
2386 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2387 if (!wpa_s->interface_removed)
2388 return 1;
2389 return 0;
2390}
2391#endif /* CONFIG_TERMINATE_ONLASTIF */
2392
2393
2394static void
2395wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2396 union wpa_event_data *data)
2397{
2398 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2399 return;
2400
2401 switch (data->interface_status.ievent) {
2402 case EVENT_INTERFACE_ADDED:
2403 if (!wpa_s->interface_removed)
2404 break;
2405 wpa_s->interface_removed = 0;
2406 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2407 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2408 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2409 "driver after interface was added");
2410 }
2411 break;
2412 case EVENT_INTERFACE_REMOVED:
2413 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2414 wpa_s->interface_removed = 1;
2415 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002416 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002417 l2_packet_deinit(wpa_s->l2);
2418 wpa_s->l2 = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002419#ifdef CONFIG_TERMINATE_ONLASTIF
2420 /* check if last interface */
2421 if (!any_interfaces(wpa_s->global->ifaces))
2422 eloop_terminate();
2423#endif /* CONFIG_TERMINATE_ONLASTIF */
2424 break;
2425 }
2426}
2427
2428
2429#ifdef CONFIG_PEERKEY
2430static void
2431wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2432 union wpa_event_data *data)
2433{
2434 if (data == NULL)
2435 return;
2436 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2437}
2438#endif /* CONFIG_PEERKEY */
2439
2440
2441#ifdef CONFIG_TDLS
2442static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2443 union wpa_event_data *data)
2444{
2445 if (data == NULL)
2446 return;
2447 switch (data->tdls.oper) {
2448 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002449 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2450 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2451 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2452 else
2453 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002454 break;
2455 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002456 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2457 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2458 data->tdls.reason_code);
2459 else
2460 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2461 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002462 break;
2463 }
2464}
2465#endif /* CONFIG_TDLS */
2466
2467
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002468#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002469static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2470 union wpa_event_data *data)
2471{
2472 if (data == NULL)
2473 return;
2474 switch (data->wnm.oper) {
2475 case WNM_OPER_SLEEP:
2476 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2477 "(action=%d, intval=%d)",
2478 data->wnm.sleep_action, data->wnm.sleep_intval);
2479 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002480 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002481 break;
2482 }
2483}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002484#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002485
2486
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002487#ifdef CONFIG_IEEE80211R
2488static void
2489wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2490 union wpa_event_data *data)
2491{
2492 if (data == NULL)
2493 return;
2494
2495 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2496 data->ft_ies.ies_len,
2497 data->ft_ies.ft_action,
2498 data->ft_ies.target_ap,
2499 data->ft_ies.ric_ies,
2500 data->ft_ies.ric_ies_len) < 0) {
2501 /* TODO: prevent MLME/driver from trying to associate? */
2502 }
2503}
2504#endif /* CONFIG_IEEE80211R */
2505
2506
2507#ifdef CONFIG_IBSS_RSN
2508static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2509 union wpa_event_data *data)
2510{
2511 struct wpa_ssid *ssid;
2512 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2513 return;
2514 if (data == NULL)
2515 return;
2516 ssid = wpa_s->current_ssid;
2517 if (ssid == NULL)
2518 return;
2519 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2520 return;
2521
2522 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2523}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002524
2525
2526static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2527 union wpa_event_data *data)
2528{
2529 struct wpa_ssid *ssid = wpa_s->current_ssid;
2530
2531 if (ssid == NULL)
2532 return;
2533
2534 /* check if the ssid is correctly configured as IBSS/RSN */
2535 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2536 return;
2537
2538 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2539 data->rx_mgmt.frame_len);
2540}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002541#endif /* CONFIG_IBSS_RSN */
2542
2543
2544#ifdef CONFIG_IEEE80211R
2545static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2546 size_t len)
2547{
2548 const u8 *sta_addr, *target_ap_addr;
2549 u16 status;
2550
2551 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2552 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2553 return; /* only SME case supported for now */
2554 if (len < 1 + 2 * ETH_ALEN + 2)
2555 return;
2556 if (data[0] != 2)
2557 return; /* Only FT Action Response is supported for now */
2558 sta_addr = data + 1;
2559 target_ap_addr = data + 1 + ETH_ALEN;
2560 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2561 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2562 MACSTR " TargetAP " MACSTR " status %u",
2563 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2564
2565 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2566 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2567 " in FT Action Response", MAC2STR(sta_addr));
2568 return;
2569 }
2570
2571 if (status) {
2572 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2573 "failure (status code %d)", status);
2574 /* TODO: report error to FT code(?) */
2575 return;
2576 }
2577
2578 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2579 len - (1 + 2 * ETH_ALEN + 2), 1,
2580 target_ap_addr, NULL, 0) < 0)
2581 return;
2582
2583#ifdef CONFIG_SME
2584 {
2585 struct wpa_bss *bss;
2586 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2587 if (bss)
2588 wpa_s->sme.freq = bss->freq;
2589 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2590 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2591 WLAN_AUTH_FT);
2592 }
2593#endif /* CONFIG_SME */
2594}
2595#endif /* CONFIG_IEEE80211R */
2596
2597
2598static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2599 struct unprot_deauth *e)
2600{
2601#ifdef CONFIG_IEEE80211W
2602 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2603 "dropped: " MACSTR " -> " MACSTR
2604 " (reason code %u)",
2605 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2606 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2607#endif /* CONFIG_IEEE80211W */
2608}
2609
2610
2611static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2612 struct unprot_disassoc *e)
2613{
2614#ifdef CONFIG_IEEE80211W
2615 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2616 "dropped: " MACSTR " -> " MACSTR
2617 " (reason code %u)",
2618 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2619 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2620#endif /* CONFIG_IEEE80211W */
2621}
2622
2623
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002624static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2625 u16 reason_code, int locally_generated,
2626 const u8 *ie, size_t ie_len, int deauth)
2627{
2628#ifdef CONFIG_AP
2629 if (wpa_s->ap_iface && addr) {
2630 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2631 return;
2632 }
2633
2634 if (wpa_s->ap_iface) {
2635 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2636 return;
2637 }
2638#endif /* CONFIG_AP */
2639
2640 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2641
Dmitry Shmidt344abd32014-01-14 13:17:00 -08002642 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2643 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2644 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2645 eapol_sm_failed(wpa_s->eapol))) &&
2646 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002647 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002648
2649#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002650 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002651 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2652 locally_generated) > 0) {
2653 /*
2654 * The interface was removed, so cannot continue
2655 * processing any additional operations after this.
2656 */
2657 return;
2658 }
2659 }
2660#endif /* CONFIG_P2P */
2661
2662 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2663 locally_generated);
2664}
2665
2666
2667static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2668 struct disassoc_info *info)
2669{
2670 u16 reason_code = 0;
2671 int locally_generated = 0;
2672 const u8 *addr = NULL;
2673 const u8 *ie = NULL;
2674 size_t ie_len = 0;
2675
2676 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2677
2678 if (info) {
2679 addr = info->addr;
2680 ie = info->ie;
2681 ie_len = info->ie_len;
2682 reason_code = info->reason_code;
2683 locally_generated = info->locally_generated;
2684 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2685 locally_generated ? " (locally generated)" : "");
2686 if (addr)
2687 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2688 MAC2STR(addr));
2689 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2690 ie, ie_len);
2691 }
2692
2693#ifdef CONFIG_AP
2694 if (wpa_s->ap_iface && info && info->addr) {
2695 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2696 return;
2697 }
2698
2699 if (wpa_s->ap_iface) {
2700 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2701 return;
2702 }
2703#endif /* CONFIG_AP */
2704
2705#ifdef CONFIG_P2P
2706 if (info) {
2707 wpas_p2p_disassoc_notif(
2708 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2709 locally_generated);
2710 }
2711#endif /* CONFIG_P2P */
2712
2713 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2714 sme_event_disassoc(wpa_s, info);
2715
2716 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2717 ie, ie_len, 0);
2718}
2719
2720
2721static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2722 struct deauth_info *info)
2723{
2724 u16 reason_code = 0;
2725 int locally_generated = 0;
2726 const u8 *addr = NULL;
2727 const u8 *ie = NULL;
2728 size_t ie_len = 0;
2729
2730 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2731
2732 if (info) {
2733 addr = info->addr;
2734 ie = info->ie;
2735 ie_len = info->ie_len;
2736 reason_code = info->reason_code;
2737 locally_generated = info->locally_generated;
2738 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2739 reason_code,
2740 locally_generated ? " (locally generated)" : "");
2741 if (addr) {
2742 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2743 MAC2STR(addr));
2744 }
2745 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2746 ie, ie_len);
2747 }
2748
2749 wpa_reset_ft_completed(wpa_s->wpa);
2750
2751 wpas_event_disconnect(wpa_s, addr, reason_code,
2752 locally_generated, ie, ie_len, 1);
2753}
2754
2755
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002756static const char * reg_init_str(enum reg_change_initiator init)
2757{
2758 switch (init) {
2759 case REGDOM_SET_BY_CORE:
2760 return "CORE";
2761 case REGDOM_SET_BY_USER:
2762 return "USER";
2763 case REGDOM_SET_BY_DRIVER:
2764 return "DRIVER";
2765 case REGDOM_SET_BY_COUNTRY_IE:
2766 return "COUNTRY_IE";
2767 case REGDOM_BEACON_HINT:
2768 return "BEACON_HINT";
2769 }
2770 return "?";
2771}
2772
2773
2774static const char * reg_type_str(enum reg_type type)
2775{
2776 switch (type) {
2777 case REGDOM_TYPE_UNKNOWN:
2778 return "UNKNOWN";
2779 case REGDOM_TYPE_COUNTRY:
2780 return "COUNTRY";
2781 case REGDOM_TYPE_WORLD:
2782 return "WORLD";
2783 case REGDOM_TYPE_CUSTOM_WORLD:
2784 return "CUSTOM_WORLD";
2785 case REGDOM_TYPE_INTERSECTION:
2786 return "INTERSECTION";
2787 }
2788 return "?";
2789}
2790
2791
2792static void wpa_supplicant_update_channel_list(
2793 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002794{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002795 struct wpa_supplicant *ifs;
2796
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002797 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
Dmitry Shmidtc2817022014-07-02 10:32:10 -07002798 reg_init_str(info->initiator), reg_type_str(info->type),
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002799 info->alpha2[0] ? " alpha2=" : "",
2800 info->alpha2[0] ? info->alpha2 : "");
2801
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002802 if (wpa_s->drv_priv == NULL)
2803 return; /* Ignore event during drv initialization */
2804
2805 free_hw_features(wpa_s);
2806 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2807 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2808
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002809 wpas_p2p_update_channel_list(wpa_s);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002810
2811 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002812 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002813 * so, they get updated with this same hw mode info.
2814 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002815 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2816 radio_list) {
2817 if (ifs != wpa_s) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002818 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2819 ifs->ifname);
2820 free_hw_features(ifs);
2821 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2822 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2823 }
2824 }
2825}
2826
2827
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002828static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002829 const u8 *frame, size_t len, int freq,
2830 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002831{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002832 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002833 const u8 *payload;
2834 size_t plen;
2835 u8 category;
2836
2837 if (len < IEEE80211_HDRLEN + 2)
2838 return;
2839
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002840 mgmt = (const struct ieee80211_mgmt *) frame;
2841 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002842 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002843 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002844
2845 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2846 " Category=%u DataLen=%d freq=%d MHz",
2847 MAC2STR(mgmt->sa), category, (int) plen, freq);
2848
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002849 if (category == WLAN_ACTION_WMM) {
2850 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
2851 return;
2852 }
2853
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002854#ifdef CONFIG_IEEE80211R
2855 if (category == WLAN_ACTION_FT) {
2856 ft_rx_action(wpa_s, payload, plen);
2857 return;
2858 }
2859#endif /* CONFIG_IEEE80211R */
2860
2861#ifdef CONFIG_IEEE80211W
2862#ifdef CONFIG_SME
2863 if (category == WLAN_ACTION_SA_QUERY) {
2864 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2865 return;
2866 }
2867#endif /* CONFIG_SME */
2868#endif /* CONFIG_IEEE80211W */
2869
2870#ifdef CONFIG_WNM
2871 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2872 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2873 return;
2874 }
2875#endif /* CONFIG_WNM */
2876
2877#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08002878 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2879 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002880 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08002881 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002882 payload, plen, freq) == 0)
2883 return;
2884#endif /* CONFIG_GAS */
2885
2886#ifdef CONFIG_TDLS
2887 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2888 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2889 wpa_dbg(wpa_s, MSG_DEBUG,
2890 "TDLS: Received Discovery Response from " MACSTR,
2891 MAC2STR(mgmt->sa));
2892 return;
2893 }
2894#endif /* CONFIG_TDLS */
2895
2896#ifdef CONFIG_INTERWORKING
2897 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2898 payload[0] == QOS_QOS_MAP_CONFIG) {
2899 const u8 *pos = payload + 1;
2900 size_t qlen = plen - 1;
2901 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2902 MACSTR, MAC2STR(mgmt->sa));
2903 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2904 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2905 pos[1] <= qlen - 2 && pos[1] >= 16)
2906 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2907 return;
2908 }
2909#endif /* CONFIG_INTERWORKING */
2910
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002911 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2912 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
2913 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
2914 return;
2915 }
2916
2917 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2918 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
2919 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
2920 payload + 1, plen - 1,
2921 rssi);
2922 return;
2923 }
2924
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002925 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2926 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002927 if (wpa_s->ifmsh)
2928 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002929}
2930
2931
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08002932static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2933 union wpa_event_data *event)
2934{
2935#ifdef CONFIG_P2P
2936 struct wpa_supplicant *ifs;
2937#endif /* CONFIG_P2P */
2938 struct wpa_freq_range_list *list;
2939 char *str = NULL;
2940
2941 list = &event->freq_range;
2942
2943 if (list->num)
2944 str = freq_range_list_str(list);
2945 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2946 str ? str : "");
2947
2948#ifdef CONFIG_P2P
2949 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
2950 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
2951 __func__);
2952 } else {
2953 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
2954 wpas_p2p_update_channel_list(wpa_s);
2955 }
2956
2957 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2958 int freq;
2959 if (!ifs->current_ssid ||
2960 !ifs->current_ssid->p2p_group ||
2961 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
2962 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
2963 continue;
2964
2965 freq = ifs->current_ssid->frequency;
2966 if (!freq_range_list_includes(list, freq)) {
2967 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
2968 freq);
2969 continue;
2970 }
2971
2972 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
2973 freq);
2974 /* TODO: Consider using CSA or removing the group within
2975 * wpa_supplicant */
2976 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
2977 }
2978#endif /* CONFIG_P2P */
2979
2980 os_free(str);
2981}
2982
2983
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002984static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
2985 union wpa_event_data *data)
2986{
2987 wpa_dbg(wpa_s, MSG_DEBUG,
2988 "Connection authorized by device, previous state %d",
2989 wpa_s->wpa_state);
2990 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
2991 wpa_supplicant_cancel_auth_timeout(wpa_s);
2992 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2993 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2994 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2995 }
2996 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
2997 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002998 data->assoc_info.ptk_kck_len,
2999 data->assoc_info.ptk_kek,
3000 data->assoc_info.ptk_kek_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003001}
3002
3003
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003004void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3005 union wpa_event_data *data)
3006{
3007 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003008
3009 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3010 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003011 event != EVENT_INTERFACE_STATUS &&
3012 event != EVENT_SCHED_SCAN_STOPPED) {
3013 wpa_dbg(wpa_s, MSG_DEBUG,
3014 "Ignore event %s (%d) while interface is disabled",
3015 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003016 return;
3017 }
3018
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003019#ifndef CONFIG_NO_STDOUT_DEBUG
3020{
3021 int level = MSG_DEBUG;
3022
Dmitry Shmidt04949592012-07-19 12:16:46 -07003023 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003024 const struct ieee80211_hdr *hdr;
3025 u16 fc;
3026 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3027 fc = le_to_host16(hdr->frame_control);
3028 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3029 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3030 level = MSG_EXCESSIVE;
3031 }
3032
3033 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3034 event_to_string(event), event);
3035}
3036#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003037
3038 switch (event) {
3039 case EVENT_AUTH:
3040 sme_event_auth(wpa_s, data);
3041 break;
3042 case EVENT_ASSOC:
3043 wpa_supplicant_event_assoc(wpa_s, data);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003044 if (data && data->assoc_info.authorized)
3045 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003046 break;
3047 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003048 wpas_event_disassoc(wpa_s,
3049 data ? &data->disassoc_info : NULL);
3050 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003051 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003052 wpas_event_deauth(wpa_s,
3053 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003054 break;
3055 case EVENT_MICHAEL_MIC_FAILURE:
3056 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3057 break;
3058#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003059 case EVENT_SCAN_STARTED:
3060 os_get_reltime(&wpa_s->scan_start_time);
3061 if (wpa_s->own_scan_requested) {
3062 struct os_reltime diff;
3063
3064 os_reltime_sub(&wpa_s->scan_start_time,
3065 &wpa_s->scan_trigger_time, &diff);
3066 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3067 diff.sec, diff.usec);
3068 wpa_s->own_scan_requested = 0;
3069 wpa_s->own_scan_running = 1;
3070 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3071 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003072 wpa_msg_ctrl(wpa_s, MSG_INFO,
3073 WPA_EVENT_SCAN_STARTED "id=%u",
3074 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003075 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003076 wpa_msg_ctrl(wpa_s, MSG_INFO,
3077 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003078 }
3079 } else {
3080 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003081 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003082 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003083 }
3084 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003085 case EVENT_SCAN_RESULTS:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003086 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3087 struct os_reltime now, diff;
3088 os_get_reltime(&now);
3089 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3090 wpa_s->scan_start_time.sec = 0;
3091 wpa_s->scan_start_time.usec = 0;
3092 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3093 diff.sec, diff.usec);
3094 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003095 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003096 wpa_s->own_scan_running = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003097 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003098 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003099 break;
3100#endif /* CONFIG_NO_SCAN_PROCESSING */
3101 case EVENT_ASSOCINFO:
3102 wpa_supplicant_event_associnfo(wpa_s, data);
3103 break;
3104 case EVENT_INTERFACE_STATUS:
3105 wpa_supplicant_event_interface_status(wpa_s, data);
3106 break;
3107 case EVENT_PMKID_CANDIDATE:
3108 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3109 break;
3110#ifdef CONFIG_PEERKEY
3111 case EVENT_STKSTART:
3112 wpa_supplicant_event_stkstart(wpa_s, data);
3113 break;
3114#endif /* CONFIG_PEERKEY */
3115#ifdef CONFIG_TDLS
3116 case EVENT_TDLS:
3117 wpa_supplicant_event_tdls(wpa_s, data);
3118 break;
3119#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003120#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003121 case EVENT_WNM:
3122 wpa_supplicant_event_wnm(wpa_s, data);
3123 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003124#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003125#ifdef CONFIG_IEEE80211R
3126 case EVENT_FT_RESPONSE:
3127 wpa_supplicant_event_ft_response(wpa_s, data);
3128 break;
3129#endif /* CONFIG_IEEE80211R */
3130#ifdef CONFIG_IBSS_RSN
3131 case EVENT_IBSS_RSN_START:
3132 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3133 break;
3134#endif /* CONFIG_IBSS_RSN */
3135 case EVENT_ASSOC_REJECT:
3136 if (data->assoc_reject.bssid)
3137 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3138 "bssid=" MACSTR " status_code=%u",
3139 MAC2STR(data->assoc_reject.bssid),
3140 data->assoc_reject.status_code);
3141 else
3142 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3143 "status_code=%u",
3144 data->assoc_reject.status_code);
3145 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3146 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07003147 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003148 const u8 *bssid = data->assoc_reject.bssid;
3149 if (bssid == NULL || is_zero_ether_addr(bssid))
3150 bssid = wpa_s->pending_bssid;
3151 wpas_connection_failed(wpa_s, bssid);
3152 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003153 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154 break;
3155 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003156 /* It is possible to get this event from earlier connection */
3157 if (wpa_s->current_ssid &&
3158 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3159 wpa_dbg(wpa_s, MSG_DEBUG,
3160 "Ignore AUTH_TIMED_OUT in mesh configuration");
3161 break;
3162 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003163 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3164 sme_event_auth_timed_out(wpa_s, data);
3165 break;
3166 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003167 /* It is possible to get this event from earlier connection */
3168 if (wpa_s->current_ssid &&
3169 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3170 wpa_dbg(wpa_s, MSG_DEBUG,
3171 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3172 break;
3173 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003174 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3175 sme_event_assoc_timed_out(wpa_s, data);
3176 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003177 case EVENT_TX_STATUS:
3178 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3179 " type=%d stype=%d",
3180 MAC2STR(data->tx_status.dst),
3181 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003182#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003183 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003184#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003185 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3186 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003187 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003188 wpa_s, data->tx_status.dst,
3189 data->tx_status.data,
3190 data->tx_status.data_len,
3191 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003192 OFFCHANNEL_SEND_ACTION_SUCCESS :
3193 OFFCHANNEL_SEND_ACTION_NO_ACK);
3194#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003195 break;
3196 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003197#endif /* CONFIG_AP */
3198#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003199 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3200 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3201 /*
3202 * Catch TX status events for Action frames we sent via group
3203 * interface in GO mode.
3204 */
3205 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3206 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3207 os_memcmp(wpa_s->parent->pending_action_dst,
3208 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003209 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003210 wpa_s->parent, data->tx_status.dst,
3211 data->tx_status.data,
3212 data->tx_status.data_len,
3213 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003214 OFFCHANNEL_SEND_ACTION_SUCCESS :
3215 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003216 break;
3217 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003218#endif /* CONFIG_OFFCHANNEL */
3219#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003220 switch (data->tx_status.type) {
3221 case WLAN_FC_TYPE_MGMT:
3222 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3223 data->tx_status.data_len,
3224 data->tx_status.stype,
3225 data->tx_status.ack);
3226 break;
3227 case WLAN_FC_TYPE_DATA:
3228 ap_tx_status(wpa_s, data->tx_status.dst,
3229 data->tx_status.data,
3230 data->tx_status.data_len,
3231 data->tx_status.ack);
3232 break;
3233 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003234#endif /* CONFIG_AP */
3235 break;
3236#ifdef CONFIG_AP
3237 case EVENT_EAPOL_TX_STATUS:
3238 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3239 data->eapol_tx_status.data,
3240 data->eapol_tx_status.data_len,
3241 data->eapol_tx_status.ack);
3242 break;
3243 case EVENT_DRIVER_CLIENT_POLL_OK:
3244 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003245 break;
3246 case EVENT_RX_FROM_UNKNOWN:
3247 if (wpa_s->ap_iface == NULL)
3248 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003249 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3250 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003251 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003252 case EVENT_CH_SWITCH:
3253 if (!data)
3254 break;
3255 if (!wpa_s->ap_iface) {
3256 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3257 "event in non-AP mode");
3258 break;
3259 }
3260
Dmitry Shmidt04949592012-07-19 12:16:46 -07003261 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3262 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08003263 data->ch_switch.ch_offset,
3264 data->ch_switch.ch_width,
3265 data->ch_switch.cf1,
3266 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003267 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003268#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003269 case EVENT_RX_MGMT: {
3270 u16 fc, stype;
3271 const struct ieee80211_mgmt *mgmt;
3272
Dmitry Shmidt818ea482014-03-10 13:15:21 -07003273#ifdef CONFIG_TESTING_OPTIONS
3274 if (wpa_s->ext_mgmt_frame_handling) {
3275 struct rx_mgmt *rx = &data->rx_mgmt;
3276 size_t hex_len = 2 * rx->frame_len + 1;
3277 char *hex = os_malloc(hex_len);
3278 if (hex) {
3279 wpa_snprintf_hex(hex, hex_len,
3280 rx->frame, rx->frame_len);
3281 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3282 rx->freq, rx->datarate, rx->ssi_signal,
3283 hex);
3284 os_free(hex);
3285 }
3286 break;
3287 }
3288#endif /* CONFIG_TESTING_OPTIONS */
3289
Dmitry Shmidt04949592012-07-19 12:16:46 -07003290 mgmt = (const struct ieee80211_mgmt *)
3291 data->rx_mgmt.frame;
3292 fc = le_to_host16(mgmt->frame_control);
3293 stype = WLAN_FC_GET_STYPE(fc);
3294
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003295#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003296 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003297#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003298#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003299 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3300 data->rx_mgmt.frame_len > 24) {
3301 const u8 *src = mgmt->sa;
3302 const u8 *ie = mgmt->u.probe_req.variable;
3303 size_t ie_len = data->rx_mgmt.frame_len -
3304 (mgmt->u.probe_req.variable -
3305 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003306 wpas_p2p_probe_req_rx(
3307 wpa_s, src, mgmt->da,
3308 mgmt->bssid, ie, ie_len,
3309 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003310 break;
3311 }
3312#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003313#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003314 if (wpa_s->current_ssid &&
3315 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3316 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003317 data->rx_mgmt.frame_len >= 30) {
3318 wpa_supplicant_event_ibss_auth(wpa_s, data);
3319 break;
3320 }
3321#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003322
3323 if (stype == WLAN_FC_STYPE_ACTION) {
3324 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003325 wpa_s, data->rx_mgmt.frame,
3326 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003327 data->rx_mgmt.freq,
3328 data->rx_mgmt.ssi_signal);
3329 break;
3330 }
3331
3332 if (wpa_s->ifmsh) {
3333 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003334 break;
3335 }
3336
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003337 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3338 "management frame in non-AP mode");
3339 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003340#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003341 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003342
3343 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3344 data->rx_mgmt.frame_len > 24) {
3345 const u8 *ie = mgmt->u.probe_req.variable;
3346 size_t ie_len = data->rx_mgmt.frame_len -
3347 (mgmt->u.probe_req.variable -
3348 data->rx_mgmt.frame);
3349
3350 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3351 mgmt->bssid, ie, ie_len,
3352 data->rx_mgmt.ssi_signal);
3353 }
3354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003355 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003356#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003357 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003358 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003359 case EVENT_RX_PROBE_REQ:
3360 if (data->rx_probe_req.sa == NULL ||
3361 data->rx_probe_req.ie == NULL)
3362 break;
3363#ifdef CONFIG_AP
3364 if (wpa_s->ap_iface) {
3365 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3366 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003367 data->rx_probe_req.da,
3368 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003369 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003370 data->rx_probe_req.ie_len,
3371 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003372 break;
3373 }
3374#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003375 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003376 data->rx_probe_req.da,
3377 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003378 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003379 data->rx_probe_req.ie_len,
3380 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003381 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003382 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003383#ifdef CONFIG_OFFCHANNEL
3384 offchannel_remain_on_channel_cb(
3385 wpa_s, data->remain_on_channel.freq,
3386 data->remain_on_channel.duration);
3387#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003388 wpas_p2p_remain_on_channel_cb(
3389 wpa_s, data->remain_on_channel.freq,
3390 data->remain_on_channel.duration);
3391 break;
3392 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003393#ifdef CONFIG_OFFCHANNEL
3394 offchannel_cancel_remain_on_channel_cb(
3395 wpa_s, data->remain_on_channel.freq);
3396#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003397 wpas_p2p_cancel_remain_on_channel_cb(
3398 wpa_s, data->remain_on_channel.freq);
3399 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003400 case EVENT_EAPOL_RX:
3401 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3402 data->eapol_rx.data,
3403 data->eapol_rx.data_len);
3404 break;
3405 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003406 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3407 "above=%d signal=%d noise=%d txrate=%d",
3408 data->signal_change.above_threshold,
3409 data->signal_change.current_signal,
3410 data->signal_change.current_noise,
3411 data->signal_change.current_txrate);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003412 bgscan_notify_signal_change(
3413 wpa_s, data->signal_change.above_threshold,
3414 data->signal_change.current_signal,
3415 data->signal_change.current_noise,
3416 data->signal_change.current_txrate);
3417 break;
3418 case EVENT_INTERFACE_ENABLED:
3419 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3420 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003421 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003422 if (wpa_s->p2p_mgmt) {
3423 wpa_supplicant_set_state(wpa_s,
3424 WPA_DISCONNECTED);
3425 break;
3426 }
3427
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003428#ifdef CONFIG_AP
3429 if (!wpa_s->ap_iface) {
3430 wpa_supplicant_set_state(wpa_s,
3431 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003432 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003433 wpa_supplicant_req_scan(wpa_s, 0, 0);
3434 } else
3435 wpa_supplicant_set_state(wpa_s,
3436 WPA_COMPLETED);
3437#else /* CONFIG_AP */
3438 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3439 wpa_supplicant_req_scan(wpa_s, 0, 0);
3440#endif /* CONFIG_AP */
3441 }
3442 break;
3443 case EVENT_INTERFACE_DISABLED:
3444 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003445#ifdef CONFIG_P2P
3446 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3447 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3448 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3449 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003450 * Mark interface disabled if this happens to end up not
3451 * being removed as a separate P2P group interface.
3452 */
3453 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3454 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003455 * The interface was externally disabled. Remove
3456 * it assuming an external entity will start a
3457 * new session if needed.
3458 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003459 if (wpa_s->current_ssid &&
3460 wpa_s->current_ssid->p2p_group)
3461 wpas_p2p_interface_unavailable(wpa_s);
3462 else
3463 wpas_p2p_disconnect(wpa_s);
3464 /*
3465 * wpa_s instance may have been freed, so must not use
3466 * it here anymore.
3467 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003468 break;
3469 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003470 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3471 p2p_in_progress(wpa_s->global->p2p) > 1) {
3472 /* This radio work will be cancelled, so clear P2P
3473 * state as well.
3474 */
3475 p2p_stop_find(wpa_s->global->p2p);
3476 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003477#endif /* CONFIG_P2P */
3478
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003479 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3480 /*
3481 * Indicate disconnection to keep ctrl_iface events
3482 * consistent.
3483 */
3484 wpa_supplicant_event_disassoc(
3485 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3486 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003487 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003488 radio_remove_works(wpa_s, NULL, 0);
3489
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003490 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3491 break;
3492 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003493 wpa_supplicant_update_channel_list(
3494 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003495 break;
3496 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003497 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003498 break;
3499 case EVENT_BEST_CHANNEL:
3500 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3501 "(%d %d %d)",
3502 data->best_chan.freq_24, data->best_chan.freq_5,
3503 data->best_chan.freq_overall);
3504 wpa_s->best_24_freq = data->best_chan.freq_24;
3505 wpa_s->best_5_freq = data->best_chan.freq_5;
3506 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003507 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3508 data->best_chan.freq_5,
3509 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003510 break;
3511 case EVENT_UNPROT_DEAUTH:
3512 wpa_supplicant_event_unprot_deauth(wpa_s,
3513 &data->unprot_deauth);
3514 break;
3515 case EVENT_UNPROT_DISASSOC:
3516 wpa_supplicant_event_unprot_disassoc(wpa_s,
3517 &data->unprot_disassoc);
3518 break;
3519 case EVENT_STATION_LOW_ACK:
3520#ifdef CONFIG_AP
3521 if (wpa_s->ap_iface && data)
3522 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3523 data->low_ack.addr);
3524#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003525#ifdef CONFIG_TDLS
3526 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07003527 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3528 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003529#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003530 break;
3531 case EVENT_IBSS_PEER_LOST:
3532#ifdef CONFIG_IBSS_RSN
3533 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3534#endif /* CONFIG_IBSS_RSN */
3535 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003536 case EVENT_DRIVER_GTK_REKEY:
3537 if (os_memcmp(data->driver_gtk_rekey.bssid,
3538 wpa_s->bssid, ETH_ALEN))
3539 break;
3540 if (!wpa_s->wpa)
3541 break;
3542 wpa_sm_update_replay_ctr(wpa_s->wpa,
3543 data->driver_gtk_rekey.replay_ctr);
3544 break;
3545 case EVENT_SCHED_SCAN_STOPPED:
Dmitry Shmidt18463232014-01-24 12:29:41 -08003546 wpa_s->pno = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003547 wpa_s->sched_scanning = 0;
3548 wpa_supplicant_notify_scanning(wpa_s, 0);
3549
3550 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3551 break;
3552
3553 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08003554 * Start a new sched scan to continue searching for more SSIDs
3555 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003556 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07003557 if (wpa_s->sched_scan_timed_out) {
3558 wpa_supplicant_req_sched_scan(wpa_s);
3559 } else if (wpa_s->pno_sched_pending) {
3560 wpa_s->pno_sched_pending = 0;
3561 wpas_start_pno(wpa_s);
Dmitry Shmidt18463232014-01-24 12:29:41 -08003562 }
3563
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003564 break;
3565 case EVENT_WPS_BUTTON_PUSHED:
3566#ifdef CONFIG_WPS
3567 wpas_wps_start_pbc(wpa_s, NULL, 0);
3568#endif /* CONFIG_WPS */
3569 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003570 case EVENT_AVOID_FREQUENCIES:
3571 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3572 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003573 case EVENT_CONNECT_FAILED_REASON:
3574#ifdef CONFIG_AP
3575 if (!wpa_s->ap_iface || !data)
3576 break;
3577 hostapd_event_connect_failed_reason(
3578 wpa_s->ap_iface->bss[0],
3579 data->connect_failed_reason.addr,
3580 data->connect_failed_reason.code);
3581#endif /* CONFIG_AP */
3582 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003583 case EVENT_NEW_PEER_CANDIDATE:
3584#ifdef CONFIG_MESH
3585 if (!wpa_s->ifmsh || !data)
3586 break;
3587 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3588 data->mesh_peer.ies,
3589 data->mesh_peer.ie_len);
3590#endif /* CONFIG_MESH */
3591 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003592 default:
3593 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3594 break;
3595 }
3596}