blob: 9a5ee1aa5f4c4b5969474ff00ddd024f1995d154 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003 * Copyright (c) 2003-2012, 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"
45
46
Dmitry Shmidt34af3062013-07-11 10:46:32 -070047#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070048static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
49 int new_scan);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070050#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080051
52
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070053static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
54 struct wpa_ssid *ssid)
55{
56 struct os_time now;
57
58 if (ssid == NULL || ssid->disabled_until.sec == 0)
59 return 0;
60
61 os_get_time(&now);
62 if (ssid->disabled_until.sec > now.sec)
63 return ssid->disabled_until.sec - now.sec;
64
65 wpas_clear_temp_disabled(wpa_s, ssid, 0);
66
67 return 0;
68}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069
70
71static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
72{
73 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070074 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070075
76 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
77 return 0;
78
79 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
80 "information");
81 ssid = wpa_supplicant_get_ssid(wpa_s);
82 if (ssid == NULL) {
83 wpa_msg(wpa_s, MSG_INFO,
84 "No network configuration found for the current AP");
85 return -1;
86 }
87
Dmitry Shmidt04949592012-07-19 12:16:46 -070088 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
90 return -1;
91 }
92
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080093 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
94 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
96 return -1;
97 }
98
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070099 res = wpas_temp_disabled(wpa_s, ssid);
100 if (res > 0) {
101 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
102 "disabled for %d second(s)", res);
103 return -1;
104 }
105
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
107 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800108 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 u8 wpa_ie[80];
110 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800111 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
112 wpa_ie, &wpa_ie_len) < 0)
113 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 } else {
115 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
116 }
117
118 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
119 eapol_sm_invalidate_cached_session(wpa_s->eapol);
120 old_ssid = wpa_s->current_ssid;
121 wpa_s->current_ssid = ssid;
122 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
123 wpa_supplicant_initiate_eapol(wpa_s);
124 if (old_ssid != wpa_s->current_ssid)
125 wpas_notify_network_changed(wpa_s);
126
127 return 0;
128}
129
130
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800131void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700132{
133 struct wpa_supplicant *wpa_s = eloop_ctx;
134
135 if (wpa_s->countermeasures) {
136 wpa_s->countermeasures = 0;
137 wpa_drv_set_countermeasures(wpa_s, 0);
138 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
139 wpa_supplicant_req_scan(wpa_s, 0, 0);
140 }
141}
142
143
144void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
145{
146 int bssid_changed;
147
Dmitry Shmidt04949592012-07-19 12:16:46 -0700148 wnm_bss_keep_alive_deinit(wpa_s);
149
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150#ifdef CONFIG_IBSS_RSN
151 ibss_rsn_deinit(wpa_s->ibss_rsn);
152 wpa_s->ibss_rsn = NULL;
153#endif /* CONFIG_IBSS_RSN */
154
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700155#ifdef CONFIG_AP
156 wpa_supplicant_ap_deinit(wpa_s);
157#endif /* CONFIG_AP */
158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
160 return;
161
162 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
163 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
164 os_memset(wpa_s->bssid, 0, ETH_ALEN);
165 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700166#ifdef CONFIG_SME
167 wpa_s->sme.prev_bssid_set = 0;
168#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800169#ifdef CONFIG_P2P
170 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
171#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172 wpa_s->current_bss = NULL;
173 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700174#ifdef CONFIG_IEEE80211R
175#ifdef CONFIG_SME
176 if (wpa_s->sme.ft_ies)
177 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
178#endif /* CONFIG_SME */
179#endif /* CONFIG_IEEE80211R */
180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181 if (bssid_changed)
182 wpas_notify_bssid_changed(wpa_s);
183
184 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
185 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
186 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
187 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
188 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700189 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700190 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700191 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192}
193
194
195static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
196{
197 struct wpa_ie_data ie;
198 int pmksa_set = -1;
199 size_t i;
200
201 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
202 ie.pmkid == NULL)
203 return;
204
205 for (i = 0; i < ie.num_pmkid; i++) {
206 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
207 ie.pmkid + i * PMKID_LEN,
208 NULL, NULL, 0);
209 if (pmksa_set == 0) {
210 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
211 break;
212 }
213 }
214
215 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
216 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
217}
218
219
220static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
221 union wpa_event_data *data)
222{
223 if (data == NULL) {
224 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
225 "event");
226 return;
227 }
228 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
229 " index=%d preauth=%d",
230 MAC2STR(data->pmkid_candidate.bssid),
231 data->pmkid_candidate.index,
232 data->pmkid_candidate.preauth);
233
234 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
235 data->pmkid_candidate.index,
236 data->pmkid_candidate.preauth);
237}
238
239
240static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
241{
242 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
243 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
244 return 0;
245
246#ifdef IEEE8021X_EAPOL
247 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
248 wpa_s->current_ssid &&
249 !(wpa_s->current_ssid->eapol_flags &
250 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
251 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
252 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
253 * plaintext or static WEP keys). */
254 return 0;
255 }
256#endif /* IEEE8021X_EAPOL */
257
258 return 1;
259}
260
261
262/**
263 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
264 * @wpa_s: pointer to wpa_supplicant data
265 * @ssid: Configuration data for the network
266 * Returns: 0 on success, -1 on failure
267 *
268 * This function is called when starting authentication with a network that is
269 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
270 */
271int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
272 struct wpa_ssid *ssid)
273{
274#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800275#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700276 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277
Dmitry Shmidt051af732013-10-22 13:52:46 -0700278 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL ||
279 wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280 return 0;
281
282 if (ssid->eap.eap_methods == NULL) {
283 sim = 1;
284 aka = 1;
285 } else {
286 struct eap_method_type *eap = ssid->eap.eap_methods;
287 while (eap->vendor != EAP_VENDOR_IETF ||
288 eap->method != EAP_TYPE_NONE) {
289 if (eap->vendor == EAP_VENDOR_IETF) {
290 if (eap->method == EAP_TYPE_SIM)
291 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700292 else if (eap->method == EAP_TYPE_AKA ||
293 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 aka = 1;
295 }
296 eap++;
297 }
298 }
299
300 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
301 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700302 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
303 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
304 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 aka = 0;
306
307 if (!sim && !aka) {
308 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
309 "use SIM, but neither EAP-SIM nor EAP-AKA are "
310 "enabled");
311 return 0;
312 }
313
314 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
315 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700317 wpa_s->scard = scard_init((!sim && aka) ? SCARD_USIM_ONLY :
318 SCARD_TRY_BOTH, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 if (wpa_s->scard == NULL) {
320 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
321 "(pcsc-lite)");
322 return -1;
323 }
324 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
325 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800326#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700327#endif /* IEEE8021X_EAPOL */
328
329 return 0;
330}
331
332
333#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700334
335static int has_wep_key(struct wpa_ssid *ssid)
336{
337 int i;
338
339 for (i = 0; i < NUM_WEP_KEYS; i++) {
340 if (ssid->wep_key_len[i])
341 return 1;
342 }
343
344 return 0;
345}
346
347
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700348static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700349 struct wpa_ssid *ssid)
350{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700351 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352
353 if (ssid->mixed_cell)
354 return 1;
355
356#ifdef CONFIG_WPS
357 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
358 return 1;
359#endif /* CONFIG_WPS */
360
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700361 if (has_wep_key(ssid))
362 privacy = 1;
363
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364#ifdef IEEE8021X_EAPOL
365 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
366 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
367 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
368 privacy = 1;
369#endif /* IEEE8021X_EAPOL */
370
Jouni Malinen75ecf522011-06-27 15:19:46 -0700371 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
372 privacy = 1;
373
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700374 if (bss->caps & IEEE80211_CAP_PRIVACY)
375 return privacy;
376 return !privacy;
377}
378
379
380static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
381 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700382 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700383{
384 struct wpa_ie_data ie;
385 int proto_match = 0;
386 const u8 *rsn_ie, *wpa_ie;
387 int ret;
388 int wep_ok;
389
390 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
391 if (ret >= 0)
392 return ret;
393
394 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
395 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
396 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
397 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
398 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
399
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700400 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700401 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
402 proto_match++;
403
404 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
405 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
406 "failed");
407 break;
408 }
409
410 if (wep_ok &&
411 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
412 {
413 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
414 "in RSN IE");
415 return 1;
416 }
417
418 if (!(ie.proto & ssid->proto)) {
419 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
420 "mismatch");
421 break;
422 }
423
424 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
425 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
426 "cipher mismatch");
427 break;
428 }
429
430 if (!(ie.group_cipher & ssid->group_cipher)) {
431 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
432 "cipher mismatch");
433 break;
434 }
435
436 if (!(ie.key_mgmt & ssid->key_mgmt)) {
437 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
438 "mismatch");
439 break;
440 }
441
442#ifdef CONFIG_IEEE80211W
443 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800444 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
445 wpa_s->conf->pmf : ssid->ieee80211w) ==
446 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
448 "frame protection");
449 break;
450 }
451#endif /* CONFIG_IEEE80211W */
452
453 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
454 return 1;
455 }
456
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700457 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700458 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
459 proto_match++;
460
461 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
462 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
463 "failed");
464 break;
465 }
466
467 if (wep_ok &&
468 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
469 {
470 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
471 "in WPA IE");
472 return 1;
473 }
474
475 if (!(ie.proto & ssid->proto)) {
476 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
477 "mismatch");
478 break;
479 }
480
481 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
482 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
483 "cipher mismatch");
484 break;
485 }
486
487 if (!(ie.group_cipher & ssid->group_cipher)) {
488 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
489 "cipher mismatch");
490 break;
491 }
492
493 if (!(ie.key_mgmt & ssid->key_mgmt)) {
494 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
495 "mismatch");
496 break;
497 }
498
499 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
500 return 1;
501 }
502
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700503 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
504 !rsn_ie) {
505 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
506 return 1;
507 }
508
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700509 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
510 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
511 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
512 return 0;
513 }
514
515 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
516 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
517 return 1;
518 }
519
520 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
521 "WPA/WPA2");
522
523 return 0;
524}
525
526
527static int freq_allowed(int *freqs, int freq)
528{
529 int i;
530
531 if (freqs == NULL)
532 return 1;
533
534 for (i = 0; freqs[i]; i++)
535 if (freqs[i] == freq)
536 return 1;
537 return 0;
538}
539
540
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800541static int ht_supported(const struct hostapd_hw_modes *mode)
542{
543 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
544 /*
545 * The driver did not indicate whether it supports HT. Assume
546 * it does to avoid connection issues.
547 */
548 return 1;
549 }
550
551 /*
552 * IEEE Std 802.11n-2009 20.1.1:
553 * An HT non-AP STA shall support all EQM rates for one spatial stream.
554 */
555 return mode->mcs_set[0] == 0xff;
556}
557
558
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700559static int vht_supported(const struct hostapd_hw_modes *mode)
560{
561 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
562 /*
563 * The driver did not indicate whether it supports VHT. Assume
564 * it does to avoid connection issues.
565 */
566 return 1;
567 }
568
569 /*
570 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
571 * TODO: Verify if this complies with the standard
572 */
573 return (mode->vht_mcs_set[0] & 0x3) != 3;
574}
575
576
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700577static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800578{
579 const struct hostapd_hw_modes *mode = NULL, *modes;
580 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
581 const u8 *rate_ie;
582 int i, j, k;
583
584 if (bss->freq == 0)
585 return 1; /* Cannot do matching without knowing band */
586
587 modes = wpa_s->hw.modes;
588 if (modes == NULL) {
589 /*
590 * The driver does not provide any additional information
591 * about the utilized hardware, so allow the connection attempt
592 * to continue.
593 */
594 return 1;
595 }
596
597 for (i = 0; i < wpa_s->hw.num_modes; i++) {
598 for (j = 0; j < modes[i].num_channels; j++) {
599 int freq = modes[i].channels[j].freq;
600 if (freq == bss->freq) {
601 if (mode &&
602 mode->mode == HOSTAPD_MODE_IEEE80211G)
603 break; /* do not allow 802.11b replace
604 * 802.11g */
605 mode = &modes[i];
606 break;
607 }
608 }
609 }
610
611 if (mode == NULL)
612 return 0;
613
614 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700615 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800616 if (rate_ie == NULL)
617 continue;
618
619 for (j = 2; j < rate_ie[1] + 2; j++) {
620 int flagged = !!(rate_ie[j] & 0x80);
621 int r = (rate_ie[j] & 0x7f) * 5;
622
623 /*
624 * IEEE Std 802.11n-2009 7.3.2.2:
625 * The new BSS Membership selector value is encoded
626 * like a legacy basic rate, but it is not a rate and
627 * only indicates if the BSS members are required to
628 * support the mandatory features of Clause 20 [HT PHY]
629 * in order to join the BSS.
630 */
631 if (flagged && ((rate_ie[j] & 0x7f) ==
632 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
633 if (!ht_supported(mode)) {
634 wpa_dbg(wpa_s, MSG_DEBUG,
635 " hardware does not support "
636 "HT PHY");
637 return 0;
638 }
639 continue;
640 }
641
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700642 /* There's also a VHT selector for 802.11ac */
643 if (flagged && ((rate_ie[j] & 0x7f) ==
644 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
645 if (!vht_supported(mode)) {
646 wpa_dbg(wpa_s, MSG_DEBUG,
647 " hardware does not support "
648 "VHT PHY");
649 return 0;
650 }
651 continue;
652 }
653
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800654 if (!flagged)
655 continue;
656
657 /* check for legacy basic rates */
658 for (k = 0; k < mode->num_rates; k++) {
659 if (mode->rates[k] == r)
660 break;
661 }
662 if (k == mode->num_rates) {
663 /*
664 * IEEE Std 802.11-2007 7.3.2.2 demands that in
665 * order to join a BSS all required rates
666 * have to be supported by the hardware.
667 */
668 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
669 "not support required rate %d.%d Mbps",
670 r / 10, r % 10);
671 return 0;
672 }
673 }
674 }
675
676 return 1;
677}
678
679
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800680static int bss_is_dmg(struct wpa_bss *bss)
681{
682 return bss->freq > 45000;
683}
684
685
686/*
687 * Test whether BSS is in an ESS.
688 * This is done differently in DMG (60 GHz) and non-DMG bands
689 */
690static int bss_is_ess(struct wpa_bss *bss)
691{
692 if (bss_is_dmg(bss)) {
693 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
694 IEEE80211_CAP_DMG_AP;
695 }
696
697 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
698 IEEE80211_CAP_ESS);
699}
700
701
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700702static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700703 int i, struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700704 struct wpa_ssid *group)
705{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700706 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707 int wpa;
708 struct wpa_blacklist *e;
709 const u8 *ie;
710 struct wpa_ssid *ssid;
711
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700712 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700713 wpa_ie_len = ie ? ie[1] : 0;
714
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700715 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700716 rsn_ie_len = ie ? ie[1] : 0;
717
718 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidt96571392013-10-14 12:54:46 -0700719 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700720 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700722 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
723 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
724 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
725 " p2p" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700726
727 e = wpa_blacklist_get(wpa_s, bss->bssid);
728 if (e) {
729 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700730 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700731 /*
732 * When only a single network is enabled, we can
733 * trigger blacklisting on the first failure. This
734 * should not be done with multiple enabled networks to
735 * avoid getting forced to move into a worse ESS on
736 * single error if there are no other BSSes of the
737 * current ESS.
738 */
739 limit = 0;
740 }
741 if (e->count > limit) {
742 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
743 "(count=%d limit=%d)", e->count, limit);
744 return NULL;
745 }
746 }
747
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700748 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
750 return NULL;
751 }
752
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800753 if (disallowed_bssid(wpa_s, bss->bssid)) {
754 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
755 return NULL;
756 }
757
758 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
759 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
760 return NULL;
761 }
762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
764
765 for (ssid = group; ssid; ssid = ssid->pnext) {
766 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700767 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768
Dmitry Shmidt04949592012-07-19 12:16:46 -0700769 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
771 continue;
772 }
773
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700774 res = wpas_temp_disabled(wpa_s, ssid);
775 if (res > 0) {
776 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
777 "temporarily for %d second(s)", res);
778 continue;
779 }
780
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781#ifdef CONFIG_WPS
782 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
783 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
784 "(WPS)");
785 continue;
786 }
787
788 if (wpa && ssid->ssid_len == 0 &&
789 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
790 check_ssid = 0;
791
792 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
793 /* Only allow wildcard SSID match if an AP
794 * advertises active WPS operation that matches
795 * with our mode. */
796 check_ssid = 1;
797 if (ssid->ssid_len == 0 &&
798 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
799 check_ssid = 0;
800 }
801#endif /* CONFIG_WPS */
802
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800803 if (ssid->bssid_set && ssid->ssid_len == 0 &&
804 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
805 check_ssid = 0;
806
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700808 (bss->ssid_len != ssid->ssid_len ||
809 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
811 continue;
812 }
813
814 if (ssid->bssid_set &&
815 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
816 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
817 continue;
818 }
819
820 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
821 continue;
822
823 if (!wpa &&
824 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
825 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
826 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
827 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
828 "not allowed");
829 continue;
830 }
831
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700832 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
833 has_wep_key(ssid)) {
834 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
835 continue;
836 }
837
Jouni Malinen75ecf522011-06-27 15:19:46 -0700838 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700839 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
840 "mismatch");
841 continue;
842 }
843
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800844 if (!bss_is_ess(bss)) {
845 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846 continue;
847 }
848
849 if (!freq_allowed(ssid->freq_list, bss->freq)) {
850 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
851 "allowed");
852 continue;
853 }
854
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800855 if (!rate_match(wpa_s, bss)) {
856 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
857 "not match");
858 continue;
859 }
860
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700861#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -0700862 if (ssid->p2p_group &&
863 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
864 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
865 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
866 continue;
867 }
868
Dmitry Shmidt54605472013-11-08 11:10:19 -0800869 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
870 struct wpabuf *p2p_ie;
871 u8 dev_addr[ETH_ALEN];
872
873 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
874 if (ie == NULL) {
875 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
876 continue;
877 }
878 p2p_ie = wpa_bss_get_vendor_ie_multi(
879 bss, P2P_IE_VENDOR_TYPE);
880 if (p2p_ie == NULL) {
881 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
882 continue;
883 }
884
885 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
886 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
887 ETH_ALEN) != 0) {
888 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
889 wpabuf_free(p2p_ie);
890 continue;
891 }
892 wpabuf_free(p2p_ie);
893 }
894
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895 /*
896 * TODO: skip the AP if its P2P IE has Group Formation
897 * bit set in the P2P Group Capability Bitmap and we
898 * are not in Group Formation with that device.
899 */
900#endif /* CONFIG_P2P */
901
902 /* Matching configuration found */
903 return ssid;
904 }
905
906 /* No matching configuration found */
907 return NULL;
908}
909
910
911static struct wpa_bss *
912wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913 struct wpa_ssid *group,
914 struct wpa_ssid **selected_ssid)
915{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700916 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917
918 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
919 group->priority);
920
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700921 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
922 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700923 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
924 if (!*selected_ssid)
925 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700926 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
927 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700928 MAC2STR(bss->bssid),
929 wpa_ssid_txt(bss->ssid, bss->ssid_len));
930 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 }
932
933 return NULL;
934}
935
936
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700937struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
938 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939{
940 struct wpa_bss *selected = NULL;
941 int prio;
942
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700943 if (wpa_s->last_scan_res == NULL ||
944 wpa_s->last_scan_res_used == 0)
945 return NULL; /* no scan results from last update */
946
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947 while (selected == NULL) {
948 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
949 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700950 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 selected_ssid);
952 if (selected)
953 break;
954 }
955
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800956 if (selected == NULL && wpa_s->blacklist &&
957 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
959 "blacklist and try again");
960 wpa_blacklist_clear(wpa_s);
961 wpa_s->blacklist_cleared++;
962 } else if (selected == NULL)
963 break;
964 }
965
966 return selected;
967}
968
969
970static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
971 int timeout_sec, int timeout_usec)
972{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700973 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700974 /*
975 * No networks are enabled; short-circuit request so
976 * we don't wait timeout seconds before transitioning
977 * to INACTIVE state.
978 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700979 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
980 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700981 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700982#ifdef CONFIG_P2P
983 wpa_s->sta_scan_pending = 0;
984#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985 return;
986 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800987
988 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700989 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
990}
991
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800992
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700993int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800994 struct wpa_bss *selected,
995 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996{
997 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
998 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
999 "PBC session overlap");
1000#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001001 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001002 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001003#endif /* CONFIG_P2P */
1004
1005#ifdef CONFIG_WPS
1006 wpas_wps_cancel(wpa_s);
1007#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001008 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001009 }
1010
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001011 wpa_msg(wpa_s, MSG_DEBUG,
1012 "Considering connect request: reassociate: %d selected: "
1013 MACSTR " bssid: " MACSTR " pending: " MACSTR
1014 " wpa_state: %s ssid=%p current_ssid=%p",
1015 wpa_s->reassociate, MAC2STR(selected->bssid),
1016 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1017 wpa_supplicant_state_txt(wpa_s->wpa_state),
1018 ssid, wpa_s->current_ssid);
1019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020 /*
1021 * Do not trigger new association unless the BSSID has changed or if
1022 * reassociation is requested. If we are in process of associating with
1023 * the selected BSSID, do not trigger new attempt.
1024 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001025 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1027 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1028 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001029 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1030 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1031 0) ||
1032 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1033 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1035 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001036 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001038 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1039 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040 wpa_supplicant_associate(wpa_s, selected, ssid);
1041 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001042 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1043 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001044 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001045
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001046 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047}
1048
1049
1050static struct wpa_ssid *
1051wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1052{
1053 int prio;
1054 struct wpa_ssid *ssid;
1055
1056 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1057 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1058 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001059 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001060 continue;
1061 if (ssid->mode == IEEE80211_MODE_IBSS ||
1062 ssid->mode == IEEE80211_MODE_AP)
1063 return ssid;
1064 }
1065 }
1066 return NULL;
1067}
1068
1069
1070/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1071 * on BSS added and BSS changed events */
1072static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001073 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001075 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076
1077 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1078 return;
1079
Jouni Malinen87fd2792011-05-16 18:35:42 +03001080 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001082
Jouni Malinen87fd2792011-05-16 18:35:42 +03001083 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084 if (ssid == NULL)
1085 continue;
1086
Jouni Malinen87fd2792011-05-16 18:35:42 +03001087 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 if (rsn == NULL)
1089 continue;
1090
Jouni Malinen87fd2792011-05-16 18:35:42 +03001091 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001092 }
1093
1094}
1095
1096
1097static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1098 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001099 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001100{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001101 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102 int min_diff;
1103
1104 if (wpa_s->reassociate)
1105 return 1; /* explicit request to reassociate */
1106 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1107 return 1; /* we are not associated; continue */
1108 if (wpa_s->current_ssid == NULL)
1109 return 1; /* unknown current SSID */
1110 if (wpa_s->current_ssid != ssid)
1111 return 1; /* different network block */
1112
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001113 if (wpas_driver_bss_selection(wpa_s))
1114 return 0; /* Driver-based roaming */
1115
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001116 if (wpa_s->current_ssid->ssid)
1117 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1118 wpa_s->current_ssid->ssid,
1119 wpa_s->current_ssid->ssid_len);
1120 if (!current_bss)
1121 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001122
1123 if (!current_bss)
1124 return 1; /* current BSS not seen in scan results */
1125
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001126 if (current_bss == selected)
1127 return 0;
1128
1129 if (selected->last_update_idx > current_bss->last_update_idx)
1130 return 1; /* current BSS not seen in the last scan */
1131
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001132#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001133 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1134 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1135 MAC2STR(current_bss->bssid), current_bss->level);
1136 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1137 MAC2STR(selected->bssid), selected->level);
1138
1139 if (wpa_s->current_ssid->bssid_set &&
1140 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1141 0) {
1142 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1143 "has preferred BSSID");
1144 return 1;
1145 }
1146
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001147 if (current_bss->level < 0 && current_bss->level > selected->level) {
1148 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1149 "signal level");
1150 return 0;
1151 }
1152
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001153 min_diff = 2;
1154 if (current_bss->level < 0) {
1155 if (current_bss->level < -85)
1156 min_diff = 1;
1157 else if (current_bss->level < -80)
1158 min_diff = 2;
1159 else if (current_bss->level < -75)
1160 min_diff = 3;
1161 else if (current_bss->level < -70)
1162 min_diff = 4;
1163 else
1164 min_diff = 5;
1165 }
1166 if (abs(current_bss->level - selected->level) < min_diff) {
1167 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1168 "in signal level");
1169 return 0;
1170 }
1171
1172 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001173#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001174 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001175#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001176}
1177
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001178
Jouni Malinen89ca7022012-09-14 13:03:12 -07001179/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001180 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001181static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001182 union wpa_event_data *data,
1183 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001185 struct wpa_scan_results *scan_res;
1186 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001187#ifndef CONFIG_NO_RANDOM_POOL
1188 size_t i, num;
1189#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001190
1191#ifdef CONFIG_AP
1192 if (wpa_s->ap_iface)
1193 ap = 1;
1194#endif /* CONFIG_AP */
1195
1196 wpa_supplicant_notify_scanning(wpa_s, 0);
1197
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001198#ifdef CONFIG_P2P
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001199 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
Jouni Malinendc7b7132012-09-14 12:53:47 -07001200 !wpa_s->global->p2p_disabled &&
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001201 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1202 !wpa_s->scan_res_handler) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001203 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001204 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1205 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1206 "stopped scan processing");
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001207 wpa_s->sta_scan_pending = 1;
1208 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001209 return -1;
1210 }
1211 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001212 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001213#endif /* CONFIG_P2P */
1214
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001215 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1216 data ? &data->scan_info :
1217 NULL, 1);
1218 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001219 if (wpa_s->conf->ap_scan == 2 || ap ||
1220 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001221 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001222 if (!own_request)
1223 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001224 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1225 "scanning again");
1226 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1227 return -1;
1228 }
1229
1230#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231 num = scan_res->num;
1232 if (num > 10)
1233 num = 10;
1234 for (i = 0; i < num; i++) {
1235 u8 buf[5];
1236 struct wpa_scan_res *res = scan_res->res[i];
1237 buf[0] = res->bssid[5];
1238 buf[1] = res->qual & 0xff;
1239 buf[2] = res->noise & 0xff;
1240 buf[3] = res->level & 0xff;
1241 buf[4] = res->tsf & 0xff;
1242 random_add_randomness(buf, sizeof(buf));
1243 }
1244#endif /* CONFIG_NO_RANDOM_POOL */
1245
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001246 if (own_request && wpa_s->scan_res_handler) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001247 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1248 struct wpa_scan_results *scan_res);
1249
1250 scan_res_handler = wpa_s->scan_res_handler;
1251 wpa_s->scan_res_handler = NULL;
1252 scan_res_handler(wpa_s, scan_res);
1253
1254 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001255 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001256 }
1257
1258 if (ap) {
1259 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1260#ifdef CONFIG_AP
1261 if (wpa_s->ap_iface->scan_cb)
1262 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1263#endif /* CONFIG_AP */
1264 wpa_scan_results_free(scan_res);
1265 return 0;
1266 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001267
Dmitry Shmidt04949592012-07-19 12:16:46 -07001268 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1269 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1270 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271
1272 wpas_notify_scan_done(wpa_s, 1);
1273
Dmitry Shmidt04949592012-07-19 12:16:46 -07001274 if (sme_proc_obss_scan(wpa_s) > 0) {
1275 wpa_scan_results_free(scan_res);
1276 return 0;
1277 }
1278
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001279 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1280 wpa_scan_results_free(scan_res);
1281 return 0;
1282 }
1283
Dmitry Shmidt04949592012-07-19 12:16:46 -07001284 if (autoscan_notify_scan(wpa_s, scan_res)) {
1285 wpa_scan_results_free(scan_res);
1286 return 0;
1287 }
1288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289 if (wpa_s->disconnected) {
1290 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1291 wpa_scan_results_free(scan_res);
1292 return 0;
1293 }
1294
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001295 if (!wpas_driver_bss_selection(wpa_s) &&
1296 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001297 wpa_scan_results_free(scan_res);
1298 return 0;
1299 }
1300
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001301 wpas_wps_update_ap_info(wpa_s, scan_res);
1302
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001303 wpa_scan_results_free(scan_res);
1304
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001305 return wpas_select_network_from_last_scan(wpa_s, 1);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001306}
1307
1308
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001309static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1310 int new_scan)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001311{
1312 struct wpa_bss *selected;
1313 struct wpa_ssid *ssid = NULL;
1314
1315 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316
1317 if (selected) {
1318 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001319 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001320 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001321 if (new_scan)
1322 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001323 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001324 }
1325
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001326 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001327 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001328 return -1;
1329 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001330 if (new_scan)
1331 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001332 /*
1333 * Do not notify other virtual radios of scan results since we do not
1334 * want them to start other associations at the same time.
1335 */
1336 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001338 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1339 ssid = wpa_supplicant_pick_new_network(wpa_s);
1340 if (ssid) {
1341 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1342 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001343 if (new_scan)
1344 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 } else {
1346 int timeout_sec = wpa_s->scan_interval;
1347 int timeout_usec = 0;
1348#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001349 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1350 return 0;
1351
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352 if (wpa_s->p2p_in_provisioning) {
1353 /*
1354 * Use shorter wait during P2P Provisioning
1355 * state to speed up group formation.
1356 */
1357 timeout_sec = 0;
1358 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001359 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1360 timeout_usec);
1361 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001362 }
1363#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001364#ifdef CONFIG_INTERWORKING
1365 if (wpa_s->conf->auto_interworking &&
1366 wpa_s->conf->interworking &&
1367 wpa_s->conf->cred) {
1368 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1369 "start ANQP fetch since no matching "
1370 "networks found");
1371 wpa_s->network_select = 1;
1372 wpa_s->auto_network_select = 1;
1373 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001374 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001375 }
1376#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001377 if (wpa_supplicant_req_sched_scan(wpa_s))
1378 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1379 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001380 }
1381 }
1382 return 0;
1383}
1384
1385
1386static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1387 union wpa_event_data *data)
1388{
1389 const char *rn, *rn2;
1390 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001391
1392 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001393 /*
1394 * If no scan results could be fetched, then no need to
1395 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001396 * this scan. Similarly, if scan results started a new operation on this
1397 * interface, do not notify other interfaces to avoid concurrent
1398 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399 */
1400 return;
1401 }
1402
1403 /*
1404 * Check other interfaces to see if they have the same radio-name. If
1405 * so, they get updated with this same scan info.
1406 */
1407 if (!wpa_s->driver->get_radio_name)
1408 return;
1409
1410 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1411 if (rn == NULL || rn[0] == '\0')
1412 return;
1413
1414 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1415 "sharing same radio (%s) in event_scan_results", rn);
1416
1417 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1418 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1419 continue;
1420
1421 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1422 if (rn2 && os_strcmp(rn, rn2) == 0) {
1423 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1424 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001425 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001426 }
1427 }
1428}
1429
1430#endif /* CONFIG_NO_SCAN_PROCESSING */
1431
1432
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001433int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1434{
1435#ifdef CONFIG_NO_SCAN_PROCESSING
1436 return -1;
1437#else /* CONFIG_NO_SCAN_PROCESSING */
1438 struct os_time now;
1439
1440 if (wpa_s->last_scan_res_used <= 0)
1441 return -1;
1442
1443 os_get_time(&now);
1444 if (now.sec - wpa_s->last_scan.sec > 5) {
1445 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1446 return -1;
1447 }
1448
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001449 return wpas_select_network_from_last_scan(wpa_s, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001450#endif /* CONFIG_NO_SCAN_PROCESSING */
1451}
1452
Dmitry Shmidt04949592012-07-19 12:16:46 -07001453#ifdef CONFIG_WNM
1454
1455static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1456{
1457 struct wpa_supplicant *wpa_s = eloop_ctx;
1458
1459 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1460 return;
1461
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001462 if (!wpa_s->no_keep_alive) {
1463 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1464 MAC2STR(wpa_s->bssid));
1465 /* TODO: could skip this if normal data traffic has been sent */
1466 /* TODO: Consider using some more appropriate data frame for
1467 * this */
1468 if (wpa_s->l2)
1469 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1470 (u8 *) "", 0);
1471 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001472
1473#ifdef CONFIG_SME
1474 if (wpa_s->sme.bss_max_idle_period) {
1475 unsigned int msec;
1476 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1477 if (msec > 100)
1478 msec -= 100;
1479 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1480 wnm_bss_keep_alive, wpa_s, NULL);
1481 }
1482#endif /* CONFIG_SME */
1483}
1484
1485
1486static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1487 const u8 *ies, size_t ies_len)
1488{
1489 struct ieee802_11_elems elems;
1490
1491 if (ies == NULL)
1492 return;
1493
1494 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1495 return;
1496
1497#ifdef CONFIG_SME
1498 if (elems.bss_max_idle_period) {
1499 unsigned int msec;
1500 wpa_s->sme.bss_max_idle_period =
1501 WPA_GET_LE16(elems.bss_max_idle_period);
1502 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1503 "TU)%s", wpa_s->sme.bss_max_idle_period,
1504 (elems.bss_max_idle_period[2] & 0x01) ?
1505 " (protected keep-live required)" : "");
1506 if (wpa_s->sme.bss_max_idle_period == 0)
1507 wpa_s->sme.bss_max_idle_period = 1;
1508 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1509 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1510 /* msec times 1000 */
1511 msec = wpa_s->sme.bss_max_idle_period * 1024;
1512 if (msec > 100)
1513 msec -= 100;
1514 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1515 wnm_bss_keep_alive, wpa_s,
1516 NULL);
1517 }
1518 }
1519#endif /* CONFIG_SME */
1520}
1521
1522#endif /* CONFIG_WNM */
1523
1524
1525void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1526{
1527#ifdef CONFIG_WNM
1528 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1529#endif /* CONFIG_WNM */
1530}
1531
1532
Dmitry Shmidt051af732013-10-22 13:52:46 -07001533#ifdef CONFIG_INTERWORKING
1534
1535static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1536 size_t len)
1537{
1538 int res;
1539
1540 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1541 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1542 if (res) {
1543 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1544 }
1545
1546 return res;
1547}
1548
1549
1550static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1551 const u8 *ies, size_t ies_len)
1552{
1553 struct ieee802_11_elems elems;
1554
1555 if (ies == NULL)
1556 return;
1557
1558 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1559 return;
1560
1561 if (elems.qos_map_set) {
1562 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1563 elems.qos_map_set_len);
1564 }
1565}
1566
1567#endif /* CONFIG_INTERWORKING */
1568
1569
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001570static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1571 union wpa_event_data *data)
1572{
1573 int l, len, found = 0, wpa_found, rsn_found;
1574 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001575#ifdef CONFIG_IEEE80211R
1576 u8 bssid[ETH_ALEN];
1577#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001578
1579 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1580 if (data->assoc_info.req_ies)
1581 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1582 data->assoc_info.req_ies_len);
1583 if (data->assoc_info.resp_ies) {
1584 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1585 data->assoc_info.resp_ies_len);
1586#ifdef CONFIG_TDLS
1587 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1588 data->assoc_info.resp_ies_len);
1589#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001590#ifdef CONFIG_WNM
1591 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1592 data->assoc_info.resp_ies_len);
1593#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001594#ifdef CONFIG_INTERWORKING
1595 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1596 data->assoc_info.resp_ies_len);
1597#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001598 }
1599 if (data->assoc_info.beacon_ies)
1600 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1601 data->assoc_info.beacon_ies,
1602 data->assoc_info.beacon_ies_len);
1603 if (data->assoc_info.freq)
1604 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1605 data->assoc_info.freq);
1606
1607 p = data->assoc_info.req_ies;
1608 l = data->assoc_info.req_ies_len;
1609
1610 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1611 while (p && l >= 2) {
1612 len = p[1] + 2;
1613 if (len > l) {
1614 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1615 p, l);
1616 break;
1617 }
1618 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1619 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1620 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1621 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1622 break;
1623 found = 1;
1624 wpa_find_assoc_pmkid(wpa_s);
1625 break;
1626 }
1627 l -= len;
1628 p += len;
1629 }
1630 if (!found && data->assoc_info.req_ies)
1631 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1632
1633#ifdef CONFIG_IEEE80211R
1634#ifdef CONFIG_SME
1635 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001636 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1637 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1638 data->assoc_info.resp_ies,
1639 data->assoc_info.resp_ies_len,
1640 bssid) < 0) {
1641 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1642 "Reassociation Response failed");
1643 wpa_supplicant_deauthenticate(
1644 wpa_s, WLAN_REASON_INVALID_IE);
1645 return -1;
1646 }
1647 }
1648
1649 p = data->assoc_info.resp_ies;
1650 l = data->assoc_info.resp_ies_len;
1651
1652#ifdef CONFIG_WPS_STRICT
1653 if (p && wpa_s->current_ssid &&
1654 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1655 struct wpabuf *wps;
1656 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1657 if (wps == NULL) {
1658 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1659 "include WPS IE in (Re)Association Response");
1660 return -1;
1661 }
1662
1663 if (wps_validate_assoc_resp(wps) < 0) {
1664 wpabuf_free(wps);
1665 wpa_supplicant_deauthenticate(
1666 wpa_s, WLAN_REASON_INVALID_IE);
1667 return -1;
1668 }
1669 wpabuf_free(wps);
1670 }
1671#endif /* CONFIG_WPS_STRICT */
1672
1673 /* Go through the IEs and make a copy of the MDIE, if present. */
1674 while (p && l >= 2) {
1675 len = p[1] + 2;
1676 if (len > l) {
1677 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1678 p, l);
1679 break;
1680 }
1681 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1682 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1683 wpa_s->sme.ft_used = 1;
1684 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1685 MOBILITY_DOMAIN_ID_LEN);
1686 break;
1687 }
1688 l -= len;
1689 p += len;
1690 }
1691#endif /* CONFIG_SME */
1692
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001693 /* Process FT when SME is in the driver */
1694 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1695 wpa_ft_is_completed(wpa_s->wpa)) {
1696 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1697 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1698 data->assoc_info.resp_ies,
1699 data->assoc_info.resp_ies_len,
1700 bssid) < 0) {
1701 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1702 "Reassociation Response failed");
1703 wpa_supplicant_deauthenticate(
1704 wpa_s, WLAN_REASON_INVALID_IE);
1705 return -1;
1706 }
1707 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1708 }
1709
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001710 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1711 data->assoc_info.resp_ies_len);
1712#endif /* CONFIG_IEEE80211R */
1713
1714 /* WPA/RSN IE from Beacon/ProbeResp */
1715 p = data->assoc_info.beacon_ies;
1716 l = data->assoc_info.beacon_ies_len;
1717
1718 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1719 */
1720 wpa_found = rsn_found = 0;
1721 while (p && l >= 2) {
1722 len = p[1] + 2;
1723 if (len > l) {
1724 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1725 p, l);
1726 break;
1727 }
1728 if (!wpa_found &&
1729 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1730 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1731 wpa_found = 1;
1732 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1733 }
1734
1735 if (!rsn_found &&
1736 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1737 rsn_found = 1;
1738 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1739 }
1740
1741 l -= len;
1742 p += len;
1743 }
1744
1745 if (!wpa_found && data->assoc_info.beacon_ies)
1746 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1747 if (!rsn_found && data->assoc_info.beacon_ies)
1748 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1749 if (wpa_found || rsn_found)
1750 wpa_s->ap_ies_from_associnfo = 1;
1751
Jouni Malinen87fd2792011-05-16 18:35:42 +03001752 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1753 wpa_s->assoc_freq != data->assoc_info.freq) {
1754 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1755 "%u to %u MHz",
1756 wpa_s->assoc_freq, data->assoc_info.freq);
1757 wpa_supplicant_update_scan_results(wpa_s);
1758 }
1759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001760 wpa_s->assoc_freq = data->assoc_info.freq;
1761
1762 return 0;
1763}
1764
1765
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001766static struct wpa_bss * wpa_supplicant_get_new_bss(
1767 struct wpa_supplicant *wpa_s, const u8 *bssid)
1768{
1769 struct wpa_bss *bss = NULL;
1770 struct wpa_ssid *ssid = wpa_s->current_ssid;
1771
1772 if (ssid->ssid_len > 0)
1773 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1774 if (!bss)
1775 bss = wpa_bss_get_bssid(wpa_s, bssid);
1776
1777 return bss;
1778}
1779
1780
1781static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1782{
1783 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1784
1785 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1786 return -1;
1787
1788 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1789 return 0;
1790
1791 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1792 WPA_IE_VENDOR_TYPE);
1793 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1794
1795 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1796 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1797 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1798 bss_rsn ? 2 + bss_rsn[1] : 0))
1799 return -1;
1800
1801 return 0;
1802}
1803
1804
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1806 union wpa_event_data *data)
1807{
1808 u8 bssid[ETH_ALEN];
1809 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810
1811#ifdef CONFIG_AP
1812 if (wpa_s->ap_iface) {
1813 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1814 data->assoc_info.addr,
1815 data->assoc_info.req_ies,
1816 data->assoc_info.req_ies_len,
1817 data->assoc_info.reassoc);
1818 return;
1819 }
1820#endif /* CONFIG_AP */
1821
1822 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1823 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1824 return;
1825
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001826 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1827 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001828 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001829 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1830 return;
1831 }
1832
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001833 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001834 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1836 MACSTR, MAC2STR(bssid));
1837 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1839 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001840 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841
1842 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1843 wpa_clear_keys(wpa_s, bssid);
1844 }
1845 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001846 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001847 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1848 return;
1849 }
1850 if (wpa_s->current_ssid) {
1851 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001852
1853 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1854 if (!bss) {
1855 wpa_supplicant_update_scan_results(wpa_s);
1856
1857 /* Get the BSS from the new scan results */
1858 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1859 }
1860
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001861 if (bss)
1862 wpa_s->current_bss = bss;
1863 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001864
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001865#ifdef ANDROID
1866 if (wpa_s->conf->ap_scan == 1) {
1867#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001868 if (wpa_s->conf->ap_scan == 1 &&
1869 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001870#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001871 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1872 wpa_msg(wpa_s, MSG_WARNING,
1873 "WPA/RSN IEs not updated");
1874 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001875 }
1876
1877#ifdef CONFIG_SME
1878 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1879 wpa_s->sme.prev_bssid_set = 1;
1880#endif /* CONFIG_SME */
1881
1882 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1883 if (wpa_s->current_ssid) {
1884 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1885 * initialized before association, but for other modes,
1886 * initialize PC/SC here, if the current configuration needs
1887 * smartcard or SIM/USIM. */
1888 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1889 }
1890 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1891 if (wpa_s->l2)
1892 l2_packet_notify_auth_start(wpa_s->l2);
1893
1894 /*
1895 * Set portEnabled first to FALSE in order to get EAP state machine out
1896 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1897 * state machine may transit to AUTHENTICATING state based on obsolete
1898 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1899 * AUTHENTICATED without ever giving chance to EAP state machine to
1900 * reset the state.
1901 */
1902 if (!ft_completed) {
1903 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1904 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1905 }
1906 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1907 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1908 /* 802.1X::portControl = Auto */
1909 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1910 wpa_s->eapol_received = 0;
1911 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1912 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1913 (wpa_s->current_ssid &&
1914 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001915 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1916 (wpa_s->drv_flags &
1917 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1918 /*
1919 * Set the key after having received joined-IBSS event
1920 * from the driver.
1921 */
1922 wpa_supplicant_set_wpa_none_key(wpa_s,
1923 wpa_s->current_ssid);
1924 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001925 wpa_supplicant_cancel_auth_timeout(wpa_s);
1926 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1927 } else if (!ft_completed) {
1928 /* Timeout for receiving the first EAPOL packet */
1929 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1930 }
1931 wpa_supplicant_cancel_scan(wpa_s);
1932
1933 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1934 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1935 /*
1936 * We are done; the driver will take care of RSN 4-way
1937 * handshake.
1938 */
1939 wpa_supplicant_cancel_auth_timeout(wpa_s);
1940 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1941 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1942 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1943 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1944 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1945 /*
1946 * The driver will take care of RSN 4-way handshake, so we need
1947 * to allow EAPOL supplicant to complete its work without
1948 * waiting for WPA supplicant.
1949 */
1950 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1951 } else if (ft_completed) {
1952 /*
1953 * FT protocol completed - make sure EAPOL state machine ends
1954 * up in authenticated.
1955 */
1956 wpa_supplicant_cancel_auth_timeout(wpa_s);
1957 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1958 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1959 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1960 }
1961
Jouni Malinena05074c2012-12-21 21:35:35 +02001962 wpa_s->last_eapol_matches_bssid = 0;
1963
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001964 if (wpa_s->pending_eapol_rx) {
1965 struct os_time now, age;
1966 os_get_time(&now);
1967 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1968 if (age.sec == 0 && age.usec < 100000 &&
1969 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1970 0) {
1971 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1972 "frame that was received just before "
1973 "association notification");
1974 wpa_supplicant_rx_eapol(
1975 wpa_s, wpa_s->pending_eapol_rx_src,
1976 wpabuf_head(wpa_s->pending_eapol_rx),
1977 wpabuf_len(wpa_s->pending_eapol_rx));
1978 }
1979 wpabuf_free(wpa_s->pending_eapol_rx);
1980 wpa_s->pending_eapol_rx = NULL;
1981 }
1982
1983 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1984 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001985 wpa_s->current_ssid &&
1986 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001987 /* Set static WEP keys again */
1988 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1989 }
1990
1991#ifdef CONFIG_IBSS_RSN
1992 if (wpa_s->current_ssid &&
1993 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1994 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1995 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1996 wpa_s->ibss_rsn == NULL) {
1997 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1998 if (!wpa_s->ibss_rsn) {
1999 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2000 wpa_supplicant_deauthenticate(
2001 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2002 return;
2003 }
2004
2005 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2006 }
2007#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002008
2009 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002010}
2011
2012
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002013static int disconnect_reason_recoverable(u16 reason_code)
2014{
2015 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2016 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2017 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2018}
2019
2020
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002021static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002022 u16 reason_code,
2023 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002024{
2025 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002026
2027 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2028 /*
2029 * At least Host AP driver and a Prism3 card seemed to be
2030 * generating streams of disconnected events when configuring
2031 * IBSS for WPA-None. Ignore them for now.
2032 */
2033 return;
2034 }
2035
2036 bssid = wpa_s->bssid;
2037 if (is_zero_ether_addr(bssid))
2038 bssid = wpa_s->pending_bssid;
2039
2040 if (!is_zero_ether_addr(bssid) ||
2041 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2042 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2043 " reason=%d%s",
2044 MAC2STR(bssid), reason_code,
2045 locally_generated ? " locally_generated=1" : "");
2046 }
2047}
2048
2049
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002050static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2051 int locally_generated)
2052{
2053 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2054 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2055 return 0; /* Not in 4-way handshake with PSK */
2056
2057 /*
2058 * It looks like connection was lost while trying to go through PSK
2059 * 4-way handshake. Filter out known disconnection cases that are caused
2060 * by something else than PSK mismatch to avoid confusing reports.
2061 */
2062
2063 if (locally_generated) {
2064 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2065 return 0;
2066 }
2067
2068 return 1;
2069}
2070
2071
Jouni Malinen2b89da82012-08-31 22:04:41 +03002072static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2073 u16 reason_code,
2074 int locally_generated)
2075{
2076 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077 int authenticating;
2078 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002079 struct wpa_bss *fast_reconnect = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002080#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002081 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002082#endif /* CONFIG_NO_SCAN_PROCESSING */
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002083 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002084
2085 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2086 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2087
2088 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2089 /*
2090 * At least Host AP driver and a Prism3 card seemed to be
2091 * generating streams of disconnected events when configuring
2092 * IBSS for WPA-None. Ignore them for now.
2093 */
2094 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2095 "IBSS/WPA-None mode");
2096 return;
2097 }
2098
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002099 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002100 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2101 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002102 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2103 return; /* P2P group removed */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002104 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002105 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002106 if (!wpa_s->disconnected &&
2107 (!wpa_s->auto_reconnect_disabled ||
2108 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002109 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2110 "reconnect (wps=%d wpa_state=%d)",
2111 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2112 wpa_s->wpa_state);
2113 if (wpa_s->wpa_state == WPA_COMPLETED &&
2114 wpa_s->current_ssid &&
2115 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002116 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002117 disconnect_reason_recoverable(reason_code)) {
2118 /*
2119 * It looks like the AP has dropped association with
2120 * us, but could allow us to get back in. Try to
2121 * reconnect to the same BSS without full scan to save
2122 * time for some common cases.
2123 */
2124 fast_reconnect = wpa_s->current_bss;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002125#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002126 fast_reconnect_ssid = wpa_s->current_ssid;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002127#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002128 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002129#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07002130 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002131#else
2132 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2133#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002134 else
2135 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2136 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002137 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002138 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002139 "try to re-connect");
2140 wpa_s->reassociate = 0;
2141 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002142 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002143 }
2144 bssid = wpa_s->bssid;
2145 if (is_zero_ether_addr(bssid))
2146 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002147 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2148 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002149 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002150 if (locally_generated)
2151 wpa_s->disconnect_reason = -reason_code;
2152 else
2153 wpa_s->disconnect_reason = reason_code;
2154 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2156 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2157 wpa_s->keys_cleared = 0;
2158 wpa_clear_keys(wpa_s, wpa_s->bssid);
2159 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002160 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002161 wpa_supplicant_mark_disassoc(wpa_s);
2162
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002163 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002165 wpa_s->current_ssid = last_ssid;
2166 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002167
2168 if (fast_reconnect) {
2169#ifndef CONFIG_NO_SCAN_PROCESSING
2170 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2171 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2172 fast_reconnect_ssid) < 0) {
2173 /* Recover through full scan */
2174 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2175 }
2176#endif /* CONFIG_NO_SCAN_PROCESSING */
2177 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002178}
2179
2180
2181#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002182void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002183{
2184 struct wpa_supplicant *wpa_s = eloop_ctx;
2185
2186 if (!wpa_s->pending_mic_error_report)
2187 return;
2188
2189 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2190 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2191 wpa_s->pending_mic_error_report = 0;
2192}
2193#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2194
2195
2196static void
2197wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2198 union wpa_event_data *data)
2199{
2200 int pairwise;
2201 struct os_time t;
2202
2203 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2204 pairwise = (data && data->michael_mic_failure.unicast);
2205 os_get_time(&t);
2206 if ((wpa_s->last_michael_mic_error &&
2207 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2208 wpa_s->pending_mic_error_report) {
2209 if (wpa_s->pending_mic_error_report) {
2210 /*
2211 * Send the pending MIC error report immediately since
2212 * we are going to start countermeasures and AP better
2213 * do the same.
2214 */
2215 wpa_sm_key_request(wpa_s->wpa, 1,
2216 wpa_s->pending_mic_error_pairwise);
2217 }
2218
2219 /* Send the new MIC error report immediately since we are going
2220 * to start countermeasures and AP better do the same.
2221 */
2222 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2223
2224 /* initialize countermeasures */
2225 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002226
2227 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002229 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2230
2231 /*
2232 * Need to wait for completion of request frame. We do not get
2233 * any callback for the message completion, so just wait a
2234 * short while and hope for the best. */
2235 os_sleep(0, 10000);
2236
2237 wpa_drv_set_countermeasures(wpa_s, 1);
2238 wpa_supplicant_deauthenticate(wpa_s,
2239 WLAN_REASON_MICHAEL_MIC_FAILURE);
2240 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2241 wpa_s, NULL);
2242 eloop_register_timeout(60, 0,
2243 wpa_supplicant_stop_countermeasures,
2244 wpa_s, NULL);
2245 /* TODO: mark the AP rejected for 60 second. STA is
2246 * allowed to associate with another AP.. */
2247 } else {
2248#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2249 if (wpa_s->mic_errors_seen) {
2250 /*
2251 * Reduce the effectiveness of Michael MIC error
2252 * reports as a means for attacking against TKIP if
2253 * more than one MIC failure is noticed with the same
2254 * PTK. We delay the transmission of the reports by a
2255 * random time between 0 and 60 seconds in order to
2256 * force the attacker wait 60 seconds before getting
2257 * the information on whether a frame resulted in a MIC
2258 * failure.
2259 */
2260 u8 rval[4];
2261 int sec;
2262
2263 if (os_get_random(rval, sizeof(rval)) < 0)
2264 sec = os_random() % 60;
2265 else
2266 sec = WPA_GET_BE32(rval) % 60;
2267 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2268 "report %d seconds", sec);
2269 wpa_s->pending_mic_error_report = 1;
2270 wpa_s->pending_mic_error_pairwise = pairwise;
2271 eloop_cancel_timeout(
2272 wpa_supplicant_delayed_mic_error_report,
2273 wpa_s, NULL);
2274 eloop_register_timeout(
2275 sec, os_random() % 1000000,
2276 wpa_supplicant_delayed_mic_error_report,
2277 wpa_s, NULL);
2278 } else {
2279 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2280 }
2281#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2282 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2283#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2284 }
2285 wpa_s->last_michael_mic_error = t.sec;
2286 wpa_s->mic_errors_seen++;
2287}
2288
2289
2290#ifdef CONFIG_TERMINATE_ONLASTIF
2291static int any_interfaces(struct wpa_supplicant *head)
2292{
2293 struct wpa_supplicant *wpa_s;
2294
2295 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2296 if (!wpa_s->interface_removed)
2297 return 1;
2298 return 0;
2299}
2300#endif /* CONFIG_TERMINATE_ONLASTIF */
2301
2302
2303static void
2304wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2305 union wpa_event_data *data)
2306{
2307 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2308 return;
2309
2310 switch (data->interface_status.ievent) {
2311 case EVENT_INTERFACE_ADDED:
2312 if (!wpa_s->interface_removed)
2313 break;
2314 wpa_s->interface_removed = 0;
2315 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2316 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2317 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2318 "driver after interface was added");
2319 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002320 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002321 break;
2322 case EVENT_INTERFACE_REMOVED:
2323 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2324 wpa_s->interface_removed = 1;
2325 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002326 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002327 l2_packet_deinit(wpa_s->l2);
2328 wpa_s->l2 = NULL;
2329#ifdef CONFIG_IBSS_RSN
2330 ibss_rsn_deinit(wpa_s->ibss_rsn);
2331 wpa_s->ibss_rsn = NULL;
2332#endif /* CONFIG_IBSS_RSN */
2333#ifdef CONFIG_TERMINATE_ONLASTIF
2334 /* check if last interface */
2335 if (!any_interfaces(wpa_s->global->ifaces))
2336 eloop_terminate();
2337#endif /* CONFIG_TERMINATE_ONLASTIF */
2338 break;
2339 }
2340}
2341
2342
2343#ifdef CONFIG_PEERKEY
2344static void
2345wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2346 union wpa_event_data *data)
2347{
2348 if (data == NULL)
2349 return;
2350 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2351}
2352#endif /* CONFIG_PEERKEY */
2353
2354
2355#ifdef CONFIG_TDLS
2356static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2357 union wpa_event_data *data)
2358{
2359 if (data == NULL)
2360 return;
2361 switch (data->tdls.oper) {
2362 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002363 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2364 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2365 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2366 else
2367 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002368 break;
2369 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002370 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2371 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2372 data->tdls.reason_code);
2373 else
2374 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2375 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002376 break;
2377 }
2378}
2379#endif /* CONFIG_TDLS */
2380
2381
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002382#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002383static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2384 union wpa_event_data *data)
2385{
2386 if (data == NULL)
2387 return;
2388 switch (data->wnm.oper) {
2389 case WNM_OPER_SLEEP:
2390 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2391 "(action=%d, intval=%d)",
2392 data->wnm.sleep_action, data->wnm.sleep_intval);
2393 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002394 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002395 break;
2396 }
2397}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002398#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002399
2400
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002401#ifdef CONFIG_IEEE80211R
2402static void
2403wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2404 union wpa_event_data *data)
2405{
2406 if (data == NULL)
2407 return;
2408
2409 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2410 data->ft_ies.ies_len,
2411 data->ft_ies.ft_action,
2412 data->ft_ies.target_ap,
2413 data->ft_ies.ric_ies,
2414 data->ft_ies.ric_ies_len) < 0) {
2415 /* TODO: prevent MLME/driver from trying to associate? */
2416 }
2417}
2418#endif /* CONFIG_IEEE80211R */
2419
2420
2421#ifdef CONFIG_IBSS_RSN
2422static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2423 union wpa_event_data *data)
2424{
2425 struct wpa_ssid *ssid;
2426 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2427 return;
2428 if (data == NULL)
2429 return;
2430 ssid = wpa_s->current_ssid;
2431 if (ssid == NULL)
2432 return;
2433 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2434 return;
2435
2436 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2437}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002438
2439
2440static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2441 union wpa_event_data *data)
2442{
2443 struct wpa_ssid *ssid = wpa_s->current_ssid;
2444
2445 if (ssid == NULL)
2446 return;
2447
2448 /* check if the ssid is correctly configured as IBSS/RSN */
2449 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2450 return;
2451
2452 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2453 data->rx_mgmt.frame_len);
2454}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002455#endif /* CONFIG_IBSS_RSN */
2456
2457
2458#ifdef CONFIG_IEEE80211R
2459static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2460 size_t len)
2461{
2462 const u8 *sta_addr, *target_ap_addr;
2463 u16 status;
2464
2465 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2466 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2467 return; /* only SME case supported for now */
2468 if (len < 1 + 2 * ETH_ALEN + 2)
2469 return;
2470 if (data[0] != 2)
2471 return; /* Only FT Action Response is supported for now */
2472 sta_addr = data + 1;
2473 target_ap_addr = data + 1 + ETH_ALEN;
2474 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2475 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2476 MACSTR " TargetAP " MACSTR " status %u",
2477 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2478
2479 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2480 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2481 " in FT Action Response", MAC2STR(sta_addr));
2482 return;
2483 }
2484
2485 if (status) {
2486 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2487 "failure (status code %d)", status);
2488 /* TODO: report error to FT code(?) */
2489 return;
2490 }
2491
2492 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2493 len - (1 + 2 * ETH_ALEN + 2), 1,
2494 target_ap_addr, NULL, 0) < 0)
2495 return;
2496
2497#ifdef CONFIG_SME
2498 {
2499 struct wpa_bss *bss;
2500 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2501 if (bss)
2502 wpa_s->sme.freq = bss->freq;
2503 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2504 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2505 WLAN_AUTH_FT);
2506 }
2507#endif /* CONFIG_SME */
2508}
2509#endif /* CONFIG_IEEE80211R */
2510
2511
2512static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2513 struct unprot_deauth *e)
2514{
2515#ifdef CONFIG_IEEE80211W
2516 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2517 "dropped: " MACSTR " -> " MACSTR
2518 " (reason code %u)",
2519 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2520 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2521#endif /* CONFIG_IEEE80211W */
2522}
2523
2524
2525static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2526 struct unprot_disassoc *e)
2527{
2528#ifdef CONFIG_IEEE80211W
2529 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2530 "dropped: " MACSTR " -> " MACSTR
2531 " (reason code %u)",
2532 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2533 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2534#endif /* CONFIG_IEEE80211W */
2535}
2536
2537
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002538static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2539 u16 reason_code, int locally_generated,
2540 const u8 *ie, size_t ie_len, int deauth)
2541{
2542#ifdef CONFIG_AP
2543 if (wpa_s->ap_iface && addr) {
2544 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2545 return;
2546 }
2547
2548 if (wpa_s->ap_iface) {
2549 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2550 return;
2551 }
2552#endif /* CONFIG_AP */
2553
2554 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2555
2556 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2557 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2558 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2559 eapol_sm_failed(wpa_s->eapol)))
2560 wpas_auth_failed(wpa_s);
2561
2562#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002563 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002564 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2565 locally_generated) > 0) {
2566 /*
2567 * The interface was removed, so cannot continue
2568 * processing any additional operations after this.
2569 */
2570 return;
2571 }
2572 }
2573#endif /* CONFIG_P2P */
2574
2575 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2576 locally_generated);
2577}
2578
2579
2580static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2581 struct disassoc_info *info)
2582{
2583 u16 reason_code = 0;
2584 int locally_generated = 0;
2585 const u8 *addr = NULL;
2586 const u8 *ie = NULL;
2587 size_t ie_len = 0;
2588
2589 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2590
2591 if (info) {
2592 addr = info->addr;
2593 ie = info->ie;
2594 ie_len = info->ie_len;
2595 reason_code = info->reason_code;
2596 locally_generated = info->locally_generated;
2597 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2598 locally_generated ? " (locally generated)" : "");
2599 if (addr)
2600 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2601 MAC2STR(addr));
2602 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2603 ie, ie_len);
2604 }
2605
2606#ifdef CONFIG_AP
2607 if (wpa_s->ap_iface && info && info->addr) {
2608 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2609 return;
2610 }
2611
2612 if (wpa_s->ap_iface) {
2613 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2614 return;
2615 }
2616#endif /* CONFIG_AP */
2617
2618#ifdef CONFIG_P2P
2619 if (info) {
2620 wpas_p2p_disassoc_notif(
2621 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2622 locally_generated);
2623 }
2624#endif /* CONFIG_P2P */
2625
2626 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2627 sme_event_disassoc(wpa_s, info);
2628
2629 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2630 ie, ie_len, 0);
2631}
2632
2633
2634static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2635 struct deauth_info *info)
2636{
2637 u16 reason_code = 0;
2638 int locally_generated = 0;
2639 const u8 *addr = NULL;
2640 const u8 *ie = NULL;
2641 size_t ie_len = 0;
2642
2643 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2644
2645 if (info) {
2646 addr = info->addr;
2647 ie = info->ie;
2648 ie_len = info->ie_len;
2649 reason_code = info->reason_code;
2650 locally_generated = info->locally_generated;
2651 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2652 reason_code,
2653 locally_generated ? " (locally generated)" : "");
2654 if (addr) {
2655 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2656 MAC2STR(addr));
2657 }
2658 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2659 ie, ie_len);
2660 }
2661
2662 wpa_reset_ft_completed(wpa_s->wpa);
2663
2664 wpas_event_disconnect(wpa_s, addr, reason_code,
2665 locally_generated, ie, ie_len, 1);
2666}
2667
2668
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002669static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2670{
2671 const char *rn, *rn2;
2672 struct wpa_supplicant *ifs;
2673
2674 if (wpa_s->drv_priv == NULL)
2675 return; /* Ignore event during drv initialization */
2676
2677 free_hw_features(wpa_s);
2678 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2679 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2680
2681#ifdef CONFIG_P2P
2682 wpas_p2p_update_channel_list(wpa_s);
2683#endif /* CONFIG_P2P */
2684
2685 /*
2686 * Check other interfaces to see if they have the same radio-name. If
2687 * so, they get updated with this same hw mode info.
2688 */
2689 if (!wpa_s->driver->get_radio_name)
2690 return;
2691
2692 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
2693 if (rn == NULL || rn[0] == '\0')
2694 return;
2695
2696 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
2697 "sharing same radio (%s) in event_channel_list_change", rn);
2698
2699 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2700 if (ifs == wpa_s || !ifs->driver->get_radio_name)
2701 continue;
2702
2703 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
2704 if (rn2 && os_strcmp(rn, rn2) == 0) {
2705 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2706 ifs->ifname);
2707 free_hw_features(ifs);
2708 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2709 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2710 }
2711 }
2712}
2713
2714
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002715void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2716 union wpa_event_data *data)
2717{
2718 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002719
2720 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2721 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002722 event != EVENT_INTERFACE_STATUS &&
2723 event != EVENT_SCHED_SCAN_STOPPED) {
2724 wpa_dbg(wpa_s, MSG_DEBUG,
2725 "Ignore event %s (%d) while interface is disabled",
2726 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002727 return;
2728 }
2729
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002730#ifndef CONFIG_NO_STDOUT_DEBUG
2731{
2732 int level = MSG_DEBUG;
2733
Dmitry Shmidt04949592012-07-19 12:16:46 -07002734 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002735 const struct ieee80211_hdr *hdr;
2736 u16 fc;
2737 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2738 fc = le_to_host16(hdr->frame_control);
2739 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2740 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2741 level = MSG_EXCESSIVE;
2742 }
2743
2744 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2745 event_to_string(event), event);
2746}
2747#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748
2749 switch (event) {
2750 case EVENT_AUTH:
2751 sme_event_auth(wpa_s, data);
2752 break;
2753 case EVENT_ASSOC:
2754 wpa_supplicant_event_assoc(wpa_s, data);
2755 break;
2756 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002757 wpas_event_disassoc(wpa_s,
2758 data ? &data->disassoc_info : NULL);
2759 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002760 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002761 wpas_event_deauth(wpa_s,
2762 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002763 break;
2764 case EVENT_MICHAEL_MIC_FAILURE:
2765 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2766 break;
2767#ifndef CONFIG_NO_SCAN_PROCESSING
2768 case EVENT_SCAN_RESULTS:
2769 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002770 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2771 wpa_s->wpa_state != WPA_ASSOCIATING)
2772 wpas_p2p_continue_after_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002773 break;
2774#endif /* CONFIG_NO_SCAN_PROCESSING */
2775 case EVENT_ASSOCINFO:
2776 wpa_supplicant_event_associnfo(wpa_s, data);
2777 break;
2778 case EVENT_INTERFACE_STATUS:
2779 wpa_supplicant_event_interface_status(wpa_s, data);
2780 break;
2781 case EVENT_PMKID_CANDIDATE:
2782 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2783 break;
2784#ifdef CONFIG_PEERKEY
2785 case EVENT_STKSTART:
2786 wpa_supplicant_event_stkstart(wpa_s, data);
2787 break;
2788#endif /* CONFIG_PEERKEY */
2789#ifdef CONFIG_TDLS
2790 case EVENT_TDLS:
2791 wpa_supplicant_event_tdls(wpa_s, data);
2792 break;
2793#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002794#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002795 case EVENT_WNM:
2796 wpa_supplicant_event_wnm(wpa_s, data);
2797 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002798#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002799#ifdef CONFIG_IEEE80211R
2800 case EVENT_FT_RESPONSE:
2801 wpa_supplicant_event_ft_response(wpa_s, data);
2802 break;
2803#endif /* CONFIG_IEEE80211R */
2804#ifdef CONFIG_IBSS_RSN
2805 case EVENT_IBSS_RSN_START:
2806 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2807 break;
2808#endif /* CONFIG_IBSS_RSN */
2809 case EVENT_ASSOC_REJECT:
2810 if (data->assoc_reject.bssid)
2811 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2812 "bssid=" MACSTR " status_code=%u",
2813 MAC2STR(data->assoc_reject.bssid),
2814 data->assoc_reject.status_code);
2815 else
2816 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2817 "status_code=%u",
2818 data->assoc_reject.status_code);
2819 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2820 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002821 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002822#ifdef ANDROID_P2P
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002823 if(!wpa_s->current_ssid) {
2824 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2825 break;
2826 }
2827 /* If assoc reject is reported by the driver, then avoid
2828 * waiting for the authentication timeout. Cancel the
2829 * authentication timeout and retry the assoc.
2830 */
Jeff Johnsonb485b182012-10-21 18:19:27 -07002831 if(wpa_s->current_ssid->assoc_retry++ < 10) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002832 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2833 wpa_s->current_ssid->assoc_retry);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002834
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002835 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002836
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002837 /* Clear the states */
2838 wpa_sm_notify_disassoc(wpa_s->wpa);
2839 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2840
2841 wpa_s->reassociate = 1;
Jeff Johnsonb485b182012-10-21 18:19:27 -07002842 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
Dmitry Shmidt54cb0f62012-10-29 13:12:24 -07002843 const u8 *bl_bssid = data->assoc_reject.bssid;
2844 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2845 bl_bssid = wpa_s->pending_bssid;
2846 wpa_blacklist_add(wpa_s, bl_bssid);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002847 wpa_supplicant_req_scan(wpa_s, 0, 0);
2848 } else {
2849 wpa_supplicant_req_scan(wpa_s, 1, 0);
2850 }
2851 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002852 /* If we ASSOC_REJECT's hits threshold, disable the
2853 * network
2854 */
2855 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2856 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002857 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002858 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002859 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002860 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002861#else
2862 const u8 *bssid = data->assoc_reject.bssid;
2863 if (bssid == NULL || is_zero_ether_addr(bssid))
2864 bssid = wpa_s->pending_bssid;
2865 wpas_connection_failed(wpa_s, bssid);
2866 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002867#endif /* ANDROID_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002868 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002869 break;
2870 case EVENT_AUTH_TIMED_OUT:
2871 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2872 sme_event_auth_timed_out(wpa_s, data);
2873 break;
2874 case EVENT_ASSOC_TIMED_OUT:
2875 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2876 sme_event_assoc_timed_out(wpa_s, data);
2877 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878 case EVENT_TX_STATUS:
2879 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2880 " type=%d stype=%d",
2881 MAC2STR(data->tx_status.dst),
2882 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002883#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002884 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002885#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002886 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2887 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002888 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002889 wpa_s, data->tx_status.dst,
2890 data->tx_status.data,
2891 data->tx_status.data_len,
2892 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002893 OFFCHANNEL_SEND_ACTION_SUCCESS :
2894 OFFCHANNEL_SEND_ACTION_NO_ACK);
2895#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002896 break;
2897 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002898#endif /* CONFIG_AP */
2899#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002900 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2901 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2902 /*
2903 * Catch TX status events for Action frames we sent via group
2904 * interface in GO mode.
2905 */
2906 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2907 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2908 os_memcmp(wpa_s->parent->pending_action_dst,
2909 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002910 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002911 wpa_s->parent, data->tx_status.dst,
2912 data->tx_status.data,
2913 data->tx_status.data_len,
2914 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002915 OFFCHANNEL_SEND_ACTION_SUCCESS :
2916 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002917 break;
2918 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002919#endif /* CONFIG_OFFCHANNEL */
2920#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002921 switch (data->tx_status.type) {
2922 case WLAN_FC_TYPE_MGMT:
2923 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2924 data->tx_status.data_len,
2925 data->tx_status.stype,
2926 data->tx_status.ack);
2927 break;
2928 case WLAN_FC_TYPE_DATA:
2929 ap_tx_status(wpa_s, data->tx_status.dst,
2930 data->tx_status.data,
2931 data->tx_status.data_len,
2932 data->tx_status.ack);
2933 break;
2934 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002935#endif /* CONFIG_AP */
2936 break;
2937#ifdef CONFIG_AP
2938 case EVENT_EAPOL_TX_STATUS:
2939 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2940 data->eapol_tx_status.data,
2941 data->eapol_tx_status.data_len,
2942 data->eapol_tx_status.ack);
2943 break;
2944 case EVENT_DRIVER_CLIENT_POLL_OK:
2945 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002946 break;
2947 case EVENT_RX_FROM_UNKNOWN:
2948 if (wpa_s->ap_iface == NULL)
2949 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002950 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2951 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002952 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002953 case EVENT_CH_SWITCH:
2954 if (!data)
2955 break;
2956 if (!wpa_s->ap_iface) {
2957 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2958 "event in non-AP mode");
2959 break;
2960 }
2961
Dmitry Shmidt04949592012-07-19 12:16:46 -07002962 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2963 data->ch_switch.ht_enabled,
2964 data->ch_switch.ch_offset);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002965 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002966#endif /* CONFIG_AP */
2967#if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002968 case EVENT_RX_MGMT: {
2969 u16 fc, stype;
2970 const struct ieee80211_mgmt *mgmt;
2971
2972 mgmt = (const struct ieee80211_mgmt *)
2973 data->rx_mgmt.frame;
2974 fc = le_to_host16(mgmt->frame_control);
2975 stype = WLAN_FC_GET_STYPE(fc);
2976
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002977#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002978 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002979#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002980#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002981 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2982 data->rx_mgmt.frame_len > 24) {
2983 const u8 *src = mgmt->sa;
2984 const u8 *ie = mgmt->u.probe_req.variable;
2985 size_t ie_len = data->rx_mgmt.frame_len -
2986 (mgmt->u.probe_req.variable -
2987 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002988 wpas_p2p_probe_req_rx(
2989 wpa_s, src, mgmt->da,
2990 mgmt->bssid, ie, ie_len,
2991 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002992 break;
2993 }
2994#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002995#ifdef CONFIG_IBSS_RSN
2996 if (stype == WLAN_FC_STYPE_AUTH &&
2997 data->rx_mgmt.frame_len >= 30) {
2998 wpa_supplicant_event_ibss_auth(wpa_s, data);
2999 break;
3000 }
3001#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003002 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3003 "management frame in non-AP mode");
3004 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003005#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003006 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003007
3008 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3009 data->rx_mgmt.frame_len > 24) {
3010 const u8 *ie = mgmt->u.probe_req.variable;
3011 size_t ie_len = data->rx_mgmt.frame_len -
3012 (mgmt->u.probe_req.variable -
3013 data->rx_mgmt.frame);
3014
3015 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3016 mgmt->bssid, ie, ie_len,
3017 data->rx_mgmt.ssi_signal);
3018 }
3019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003020 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003021#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003022 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003023 }
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003024#endif /* CONFIG_AP || CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003025 case EVENT_RX_ACTION:
3026 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3027 " Category=%u DataLen=%d freq=%d MHz",
3028 MAC2STR(data->rx_action.sa),
3029 data->rx_action.category, (int) data->rx_action.len,
3030 data->rx_action.freq);
3031#ifdef CONFIG_IEEE80211R
3032 if (data->rx_action.category == WLAN_ACTION_FT) {
3033 ft_rx_action(wpa_s, data->rx_action.data,
3034 data->rx_action.len);
3035 break;
3036 }
3037#endif /* CONFIG_IEEE80211R */
3038#ifdef CONFIG_IEEE80211W
3039#ifdef CONFIG_SME
3040 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
3041 sme_sa_query_rx(wpa_s, data->rx_action.sa,
3042 data->rx_action.data,
3043 data->rx_action.len);
3044 break;
3045 }
3046#endif /* CONFIG_SME */
3047#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003048#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003049 if (data->rx_action.category == WLAN_ACTION_WNM) {
3050 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
3051 break;
3052 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003053#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003054#ifdef CONFIG_GAS
3055 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3056 gas_query_rx(wpa_s->gas, data->rx_action.da,
3057 data->rx_action.sa, data->rx_action.bssid,
3058 data->rx_action.data, data->rx_action.len,
3059 data->rx_action.freq) == 0)
3060 break;
3061#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003062#ifdef CONFIG_TDLS
3063 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3064 data->rx_action.len >= 4 &&
3065 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3066 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
3067 "Response from " MACSTR,
3068 MAC2STR(data->rx_action.sa));
3069 break;
3070 }
3071#endif /* CONFIG_TDLS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003072#ifdef CONFIG_INTERWORKING
3073 if (data->rx_action.category == WLAN_ACTION_QOS &&
3074 data->rx_action.len >= 1 &&
3075 data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
3076 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3077 MACSTR, MAC2STR(data->rx_action.sa));
3078 if (os_memcmp(data->rx_action.sa, wpa_s->bssid, ETH_ALEN)
3079 == 0)
3080 wpas_qos_map_set(wpa_s, data->rx_action.data + 1,
3081 data->rx_action.len - 1);
3082 break;
3083 }
3084#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003085#ifdef CONFIG_P2P
3086 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
3087 data->rx_action.sa,
3088 data->rx_action.bssid,
3089 data->rx_action.category,
3090 data->rx_action.data,
3091 data->rx_action.len, data->rx_action.freq);
3092#endif /* CONFIG_P2P */
3093 break;
3094 case EVENT_RX_PROBE_REQ:
3095 if (data->rx_probe_req.sa == NULL ||
3096 data->rx_probe_req.ie == NULL)
3097 break;
3098#ifdef CONFIG_AP
3099 if (wpa_s->ap_iface) {
3100 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3101 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003102 data->rx_probe_req.da,
3103 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003104 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003105 data->rx_probe_req.ie_len,
3106 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003107 break;
3108 }
3109#endif /* CONFIG_AP */
3110#ifdef CONFIG_P2P
3111 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003112 data->rx_probe_req.da,
3113 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003114 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003115 data->rx_probe_req.ie_len,
3116 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003117#endif /* CONFIG_P2P */
3118 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003119 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003120#ifdef CONFIG_OFFCHANNEL
3121 offchannel_remain_on_channel_cb(
3122 wpa_s, data->remain_on_channel.freq,
3123 data->remain_on_channel.duration);
3124#endif /* CONFIG_OFFCHANNEL */
3125#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003126 wpas_p2p_remain_on_channel_cb(
3127 wpa_s, data->remain_on_channel.freq,
3128 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003129#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003130 break;
3131 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003132#ifdef CONFIG_OFFCHANNEL
3133 offchannel_cancel_remain_on_channel_cb(
3134 wpa_s, data->remain_on_channel.freq);
3135#endif /* CONFIG_OFFCHANNEL */
3136#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003137 wpas_p2p_cancel_remain_on_channel_cb(
3138 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003139#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003140 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003141#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003142 case EVENT_P2P_DEV_FOUND: {
3143 struct p2p_peer_info peer_info;
3144
3145 os_memset(&peer_info, 0, sizeof(peer_info));
3146 if (data->p2p_dev_found.dev_addr)
3147 os_memcpy(peer_info.p2p_device_addr,
3148 data->p2p_dev_found.dev_addr, ETH_ALEN);
3149 if (data->p2p_dev_found.pri_dev_type)
3150 os_memcpy(peer_info.pri_dev_type,
3151 data->p2p_dev_found.pri_dev_type,
3152 sizeof(peer_info.pri_dev_type));
3153 if (data->p2p_dev_found.dev_name)
3154 os_strlcpy(peer_info.device_name,
3155 data->p2p_dev_found.dev_name,
3156 sizeof(peer_info.device_name));
3157 peer_info.config_methods = data->p2p_dev_found.config_methods;
3158 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
3159 peer_info.group_capab = data->p2p_dev_found.group_capab;
3160
3161 /*
3162 * FIX: new_device=1 is not necessarily correct. We should
3163 * maintain a P2P peer database in wpa_supplicant and update
3164 * this information based on whether the peer is truly new.
3165 */
3166 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3167 break;
3168 }
3169 case EVENT_P2P_GO_NEG_REQ_RX:
3170 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
3171 data->p2p_go_neg_req_rx.dev_passwd_id);
3172 break;
3173 case EVENT_P2P_GO_NEG_COMPLETED:
3174 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
3175 break;
3176 case EVENT_P2P_PROV_DISC_REQUEST:
3177 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
3178 data->p2p_prov_disc_req.config_methods,
3179 data->p2p_prov_disc_req.dev_addr,
3180 data->p2p_prov_disc_req.pri_dev_type,
3181 data->p2p_prov_disc_req.dev_name,
3182 data->p2p_prov_disc_req.supp_config_methods,
3183 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003184 data->p2p_prov_disc_req.group_capab,
3185 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003186 break;
3187 case EVENT_P2P_PROV_DISC_RESPONSE:
3188 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3189 data->p2p_prov_disc_resp.config_methods);
3190 break;
3191 case EVENT_P2P_SD_REQUEST:
3192 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3193 data->p2p_sd_req.sa,
3194 data->p2p_sd_req.dialog_token,
3195 data->p2p_sd_req.update_indic,
3196 data->p2p_sd_req.tlvs,
3197 data->p2p_sd_req.tlvs_len);
3198 break;
3199 case EVENT_P2P_SD_RESPONSE:
3200 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3201 data->p2p_sd_resp.update_indic,
3202 data->p2p_sd_resp.tlvs,
3203 data->p2p_sd_resp.tlvs_len);
3204 break;
3205#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003206 case EVENT_EAPOL_RX:
3207 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3208 data->eapol_rx.data,
3209 data->eapol_rx.data_len);
3210 break;
3211 case EVENT_SIGNAL_CHANGE:
3212 bgscan_notify_signal_change(
3213 wpa_s, data->signal_change.above_threshold,
3214 data->signal_change.current_signal,
3215 data->signal_change.current_noise,
3216 data->signal_change.current_txrate);
3217 break;
3218 case EVENT_INTERFACE_ENABLED:
3219 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3220 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003221 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003222#ifdef CONFIG_AP
3223 if (!wpa_s->ap_iface) {
3224 wpa_supplicant_set_state(wpa_s,
3225 WPA_DISCONNECTED);
3226 wpa_supplicant_req_scan(wpa_s, 0, 0);
3227 } else
3228 wpa_supplicant_set_state(wpa_s,
3229 WPA_COMPLETED);
3230#else /* CONFIG_AP */
3231 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3232 wpa_supplicant_req_scan(wpa_s, 0, 0);
3233#endif /* CONFIG_AP */
3234 }
3235 break;
3236 case EVENT_INTERFACE_DISABLED:
3237 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3238 wpa_supplicant_mark_disassoc(wpa_s);
3239 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3240 break;
3241 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003242 wpa_supplicant_update_channel_list(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003243 break;
3244 case EVENT_INTERFACE_UNAVAILABLE:
3245#ifdef CONFIG_P2P
3246 wpas_p2p_interface_unavailable(wpa_s);
3247#endif /* CONFIG_P2P */
3248 break;
3249 case EVENT_BEST_CHANNEL:
3250 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3251 "(%d %d %d)",
3252 data->best_chan.freq_24, data->best_chan.freq_5,
3253 data->best_chan.freq_overall);
3254 wpa_s->best_24_freq = data->best_chan.freq_24;
3255 wpa_s->best_5_freq = data->best_chan.freq_5;
3256 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3257#ifdef CONFIG_P2P
3258 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3259 data->best_chan.freq_5,
3260 data->best_chan.freq_overall);
3261#endif /* CONFIG_P2P */
3262 break;
3263 case EVENT_UNPROT_DEAUTH:
3264 wpa_supplicant_event_unprot_deauth(wpa_s,
3265 &data->unprot_deauth);
3266 break;
3267 case EVENT_UNPROT_DISASSOC:
3268 wpa_supplicant_event_unprot_disassoc(wpa_s,
3269 &data->unprot_disassoc);
3270 break;
3271 case EVENT_STATION_LOW_ACK:
3272#ifdef CONFIG_AP
3273 if (wpa_s->ap_iface && data)
3274 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3275 data->low_ack.addr);
3276#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003277#ifdef CONFIG_TDLS
3278 if (data)
3279 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3280#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003281 break;
3282 case EVENT_IBSS_PEER_LOST:
3283#ifdef CONFIG_IBSS_RSN
3284 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3285#endif /* CONFIG_IBSS_RSN */
3286 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003287 case EVENT_DRIVER_GTK_REKEY:
3288 if (os_memcmp(data->driver_gtk_rekey.bssid,
3289 wpa_s->bssid, ETH_ALEN))
3290 break;
3291 if (!wpa_s->wpa)
3292 break;
3293 wpa_sm_update_replay_ctr(wpa_s->wpa,
3294 data->driver_gtk_rekey.replay_ctr);
3295 break;
3296 case EVENT_SCHED_SCAN_STOPPED:
3297 wpa_s->sched_scanning = 0;
3298 wpa_supplicant_notify_scanning(wpa_s, 0);
3299
3300 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3301 break;
3302
3303 /*
3304 * If we timed out, start a new sched scan to continue
3305 * searching for more SSIDs.
3306 */
3307 if (wpa_s->sched_scan_timed_out)
3308 wpa_supplicant_req_sched_scan(wpa_s);
3309 break;
3310 case EVENT_WPS_BUTTON_PUSHED:
3311#ifdef CONFIG_WPS
3312 wpas_wps_start_pbc(wpa_s, NULL, 0);
3313#endif /* CONFIG_WPS */
3314 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003315 case EVENT_CONNECT_FAILED_REASON:
3316#ifdef CONFIG_AP
3317 if (!wpa_s->ap_iface || !data)
3318 break;
3319 hostapd_event_connect_failed_reason(
3320 wpa_s->ap_iface->bss[0],
3321 data->connect_failed_reason.addr,
3322 data->connect_failed_reason.code);
3323#endif /* CONFIG_AP */
3324 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003325 default:
3326 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3327 break;
3328 }
3329}