blob: c3acad4ce869a82fad80df643819687f57f49505 [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
47static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
48 struct wpa_ssid *ssid)
49{
50 struct os_time now;
51
52 if (ssid == NULL || ssid->disabled_until.sec == 0)
53 return 0;
54
55 os_get_time(&now);
56 if (ssid->disabled_until.sec > now.sec)
57 return ssid->disabled_until.sec - now.sec;
58
59 wpas_clear_temp_disabled(wpa_s, ssid, 0);
60
61 return 0;
62}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070063
64
65static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
66{
67 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070068 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069
70 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
71 return 0;
72
73 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
74 "information");
75 ssid = wpa_supplicant_get_ssid(wpa_s);
76 if (ssid == NULL) {
77 wpa_msg(wpa_s, MSG_INFO,
78 "No network configuration found for the current AP");
79 return -1;
80 }
81
Dmitry Shmidt04949592012-07-19 12:16:46 -070082 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
84 return -1;
85 }
86
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070087 res = wpas_temp_disabled(wpa_s, ssid);
88 if (res > 0) {
89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
90 "disabled for %d second(s)", res);
91 return -1;
92 }
93
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070094 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
95 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080096 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 u8 wpa_ie[80];
98 size_t wpa_ie_len = sizeof(wpa_ie);
99 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
100 wpa_ie, &wpa_ie_len);
101 } else {
102 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
103 }
104
105 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
106 eapol_sm_invalidate_cached_session(wpa_s->eapol);
107 old_ssid = wpa_s->current_ssid;
108 wpa_s->current_ssid = ssid;
109 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
110 wpa_supplicant_initiate_eapol(wpa_s);
111 if (old_ssid != wpa_s->current_ssid)
112 wpas_notify_network_changed(wpa_s);
113
114 return 0;
115}
116
117
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800118void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700119{
120 struct wpa_supplicant *wpa_s = eloop_ctx;
121
122 if (wpa_s->countermeasures) {
123 wpa_s->countermeasures = 0;
124 wpa_drv_set_countermeasures(wpa_s, 0);
125 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
126 wpa_supplicant_req_scan(wpa_s, 0, 0);
127 }
128}
129
130
131void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
132{
133 int bssid_changed;
134
Dmitry Shmidt04949592012-07-19 12:16:46 -0700135 wnm_bss_keep_alive_deinit(wpa_s);
136
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700137#ifdef CONFIG_IBSS_RSN
138 ibss_rsn_deinit(wpa_s->ibss_rsn);
139 wpa_s->ibss_rsn = NULL;
140#endif /* CONFIG_IBSS_RSN */
141
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700142#ifdef CONFIG_AP
143 wpa_supplicant_ap_deinit(wpa_s);
144#endif /* CONFIG_AP */
145
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700146 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
147 return;
148
149 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800150#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -0700151 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800152#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700153 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
154 os_memset(wpa_s->bssid, 0, ETH_ALEN);
155 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700156#ifdef CONFIG_SME
157 wpa_s->sme.prev_bssid_set = 0;
158#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800159#ifdef CONFIG_P2P
160 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
161#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162 wpa_s->current_bss = NULL;
163 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700164#ifdef CONFIG_IEEE80211R
165#ifdef CONFIG_SME
166 if (wpa_s->sme.ft_ies)
167 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
168#endif /* CONFIG_SME */
169#endif /* CONFIG_IEEE80211R */
170
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171 if (bssid_changed)
172 wpas_notify_bssid_changed(wpa_s);
173
174 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
175 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
176 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
177 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
178 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700179 wpa_s->current_ssid = NULL;
180 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181}
182
183
184static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
185{
186 struct wpa_ie_data ie;
187 int pmksa_set = -1;
188 size_t i;
189
190 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
191 ie.pmkid == NULL)
192 return;
193
194 for (i = 0; i < ie.num_pmkid; i++) {
195 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
196 ie.pmkid + i * PMKID_LEN,
197 NULL, NULL, 0);
198 if (pmksa_set == 0) {
199 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
200 break;
201 }
202 }
203
204 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
205 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
206}
207
208
209static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
210 union wpa_event_data *data)
211{
212 if (data == NULL) {
213 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
214 "event");
215 return;
216 }
217 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
218 " index=%d preauth=%d",
219 MAC2STR(data->pmkid_candidate.bssid),
220 data->pmkid_candidate.index,
221 data->pmkid_candidate.preauth);
222
223 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
224 data->pmkid_candidate.index,
225 data->pmkid_candidate.preauth);
226}
227
228
229static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
230{
231 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
232 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
233 return 0;
234
235#ifdef IEEE8021X_EAPOL
236 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
237 wpa_s->current_ssid &&
238 !(wpa_s->current_ssid->eapol_flags &
239 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
240 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
241 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
242 * plaintext or static WEP keys). */
243 return 0;
244 }
245#endif /* IEEE8021X_EAPOL */
246
247 return 1;
248}
249
250
251/**
252 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
253 * @wpa_s: pointer to wpa_supplicant data
254 * @ssid: Configuration data for the network
255 * Returns: 0 on success, -1 on failure
256 *
257 * This function is called when starting authentication with a network that is
258 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
259 */
260int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
261 struct wpa_ssid *ssid)
262{
263#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264#ifdef PCSC_FUNCS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 int aka = 0, sim = 0, type;
266
267 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
268 return 0;
269
270 if (ssid->eap.eap_methods == NULL) {
271 sim = 1;
272 aka = 1;
273 } else {
274 struct eap_method_type *eap = ssid->eap.eap_methods;
275 while (eap->vendor != EAP_VENDOR_IETF ||
276 eap->method != EAP_TYPE_NONE) {
277 if (eap->vendor == EAP_VENDOR_IETF) {
278 if (eap->method == EAP_TYPE_SIM)
279 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700280 else if (eap->method == EAP_TYPE_AKA ||
281 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700282 aka = 1;
283 }
284 eap++;
285 }
286 }
287
288 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
289 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700290 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
291 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
292 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700293 aka = 0;
294
295 if (!sim && !aka) {
296 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
297 "use SIM, but neither EAP-SIM nor EAP-AKA are "
298 "enabled");
299 return 0;
300 }
301
302 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
303 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
304 if (sim && aka)
305 type = SCARD_TRY_BOTH;
306 else if (aka)
307 type = SCARD_USIM_ONLY;
308 else
309 type = SCARD_GSM_SIM_ONLY;
310
Dmitry Shmidt04949592012-07-19 12:16:46 -0700311 wpa_s->scard = scard_init(type, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312 if (wpa_s->scard == NULL) {
313 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
314 "(pcsc-lite)");
315 return -1;
316 }
317 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
318 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800319#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320#endif /* IEEE8021X_EAPOL */
321
322 return 0;
323}
324
325
326#ifndef CONFIG_NO_SCAN_PROCESSING
327static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
328 struct wpa_ssid *ssid)
329{
330 int i, privacy = 0;
331
332 if (ssid->mixed_cell)
333 return 1;
334
335#ifdef CONFIG_WPS
336 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
337 return 1;
338#endif /* CONFIG_WPS */
339
340 for (i = 0; i < NUM_WEP_KEYS; i++) {
341 if (ssid->wep_key_len[i]) {
342 privacy = 1;
343 break;
344 }
345 }
346#ifdef IEEE8021X_EAPOL
347 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
348 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
349 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
350 privacy = 1;
351#endif /* IEEE8021X_EAPOL */
352
Jouni Malinen75ecf522011-06-27 15:19:46 -0700353 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
354 privacy = 1;
355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700356 if (bss->caps & IEEE80211_CAP_PRIVACY)
357 return privacy;
358 return !privacy;
359}
360
361
362static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
363 struct wpa_ssid *ssid,
364 struct wpa_scan_res *bss)
365{
366 struct wpa_ie_data ie;
367 int proto_match = 0;
368 const u8 *rsn_ie, *wpa_ie;
369 int ret;
370 int wep_ok;
371
372 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
373 if (ret >= 0)
374 return ret;
375
376 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
377 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
378 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
379 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
380 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
381
382 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
383 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
384 proto_match++;
385
386 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
387 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
388 "failed");
389 break;
390 }
391
392 if (wep_ok &&
393 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
394 {
395 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
396 "in RSN IE");
397 return 1;
398 }
399
400 if (!(ie.proto & ssid->proto)) {
401 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
402 "mismatch");
403 break;
404 }
405
406 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
407 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
408 "cipher mismatch");
409 break;
410 }
411
412 if (!(ie.group_cipher & ssid->group_cipher)) {
413 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
414 "cipher mismatch");
415 break;
416 }
417
418 if (!(ie.key_mgmt & ssid->key_mgmt)) {
419 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
420 "mismatch");
421 break;
422 }
423
424#ifdef CONFIG_IEEE80211W
425 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
426 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
427 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
428 "frame protection");
429 break;
430 }
431#endif /* CONFIG_IEEE80211W */
432
433 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
434 return 1;
435 }
436
437 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
438 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
439 proto_match++;
440
441 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
442 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
443 "failed");
444 break;
445 }
446
447 if (wep_ok &&
448 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
449 {
450 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
451 "in WPA IE");
452 return 1;
453 }
454
455 if (!(ie.proto & ssid->proto)) {
456 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
457 "mismatch");
458 break;
459 }
460
461 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
462 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
463 "cipher mismatch");
464 break;
465 }
466
467 if (!(ie.group_cipher & ssid->group_cipher)) {
468 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
469 "cipher mismatch");
470 break;
471 }
472
473 if (!(ie.key_mgmt & ssid->key_mgmt)) {
474 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
475 "mismatch");
476 break;
477 }
478
479 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
480 return 1;
481 }
482
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700483 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
484 !rsn_ie) {
485 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
486 return 1;
487 }
488
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700489 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
490 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
491 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
492 return 0;
493 }
494
495 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
496 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
497 return 1;
498 }
499
500 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
501 "WPA/WPA2");
502
503 return 0;
504}
505
506
507static int freq_allowed(int *freqs, int freq)
508{
509 int i;
510
511 if (freqs == NULL)
512 return 1;
513
514 for (i = 0; freqs[i]; i++)
515 if (freqs[i] == freq)
516 return 1;
517 return 0;
518}
519
520
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800521static int ht_supported(const struct hostapd_hw_modes *mode)
522{
523 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
524 /*
525 * The driver did not indicate whether it supports HT. Assume
526 * it does to avoid connection issues.
527 */
528 return 1;
529 }
530
531 /*
532 * IEEE Std 802.11n-2009 20.1.1:
533 * An HT non-AP STA shall support all EQM rates for one spatial stream.
534 */
535 return mode->mcs_set[0] == 0xff;
536}
537
538
539static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss)
540{
541 const struct hostapd_hw_modes *mode = NULL, *modes;
542 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
543 const u8 *rate_ie;
544 int i, j, k;
545
546 if (bss->freq == 0)
547 return 1; /* Cannot do matching without knowing band */
548
549 modes = wpa_s->hw.modes;
550 if (modes == NULL) {
551 /*
552 * The driver does not provide any additional information
553 * about the utilized hardware, so allow the connection attempt
554 * to continue.
555 */
556 return 1;
557 }
558
559 for (i = 0; i < wpa_s->hw.num_modes; i++) {
560 for (j = 0; j < modes[i].num_channels; j++) {
561 int freq = modes[i].channels[j].freq;
562 if (freq == bss->freq) {
563 if (mode &&
564 mode->mode == HOSTAPD_MODE_IEEE80211G)
565 break; /* do not allow 802.11b replace
566 * 802.11g */
567 mode = &modes[i];
568 break;
569 }
570 }
571 }
572
573 if (mode == NULL)
574 return 0;
575
576 for (i = 0; i < (int) sizeof(scan_ie); i++) {
577 rate_ie = wpa_scan_get_ie(bss, scan_ie[i]);
578 if (rate_ie == NULL)
579 continue;
580
581 for (j = 2; j < rate_ie[1] + 2; j++) {
582 int flagged = !!(rate_ie[j] & 0x80);
583 int r = (rate_ie[j] & 0x7f) * 5;
584
585 /*
586 * IEEE Std 802.11n-2009 7.3.2.2:
587 * The new BSS Membership selector value is encoded
588 * like a legacy basic rate, but it is not a rate and
589 * only indicates if the BSS members are required to
590 * support the mandatory features of Clause 20 [HT PHY]
591 * in order to join the BSS.
592 */
593 if (flagged && ((rate_ie[j] & 0x7f) ==
594 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
595 if (!ht_supported(mode)) {
596 wpa_dbg(wpa_s, MSG_DEBUG,
597 " hardware does not support "
598 "HT PHY");
599 return 0;
600 }
601 continue;
602 }
603
604 if (!flagged)
605 continue;
606
607 /* check for legacy basic rates */
608 for (k = 0; k < mode->num_rates; k++) {
609 if (mode->rates[k] == r)
610 break;
611 }
612 if (k == mode->num_rates) {
613 /*
614 * IEEE Std 802.11-2007 7.3.2.2 demands that in
615 * order to join a BSS all required rates
616 * have to be supported by the hardware.
617 */
618 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
619 "not support required rate %d.%d Mbps",
620 r / 10, r % 10);
621 return 0;
622 }
623 }
624 }
625
626 return 1;
627}
628
629
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700630static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
631 int i, struct wpa_scan_res *bss,
632 struct wpa_ssid *group)
633{
634 const u8 *ssid_;
635 u8 wpa_ie_len, rsn_ie_len, ssid_len;
636 int wpa;
637 struct wpa_blacklist *e;
638 const u8 *ie;
639 struct wpa_ssid *ssid;
640
641 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
642 ssid_ = ie ? ie + 2 : (u8 *) "";
643 ssid_len = ie ? ie[1] : 0;
644
645 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
646 wpa_ie_len = ie ? ie[1] : 0;
647
648 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
649 rsn_ie_len = ie ? ie[1] : 0;
650
651 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
652 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
653 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
654 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
655 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
656
657 e = wpa_blacklist_get(wpa_s, bss->bssid);
658 if (e) {
659 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700660 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 /*
662 * When only a single network is enabled, we can
663 * trigger blacklisting on the first failure. This
664 * should not be done with multiple enabled networks to
665 * avoid getting forced to move into a worse ESS on
666 * single error if there are no other BSSes of the
667 * current ESS.
668 */
669 limit = 0;
670 }
671 if (e->count > limit) {
672 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
673 "(count=%d limit=%d)", e->count, limit);
674 return NULL;
675 }
676 }
677
678 if (ssid_len == 0) {
679 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
680 return NULL;
681 }
682
683 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
684
685 for (ssid = group; ssid; ssid = ssid->pnext) {
686 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700687 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700688
Dmitry Shmidt04949592012-07-19 12:16:46 -0700689 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
691 continue;
692 }
693
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700694 res = wpas_temp_disabled(wpa_s, ssid);
695 if (res > 0) {
696 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
697 "temporarily for %d second(s)", res);
698 continue;
699 }
700
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701#ifdef CONFIG_WPS
702 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
703 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
704 "(WPS)");
705 continue;
706 }
707
708 if (wpa && ssid->ssid_len == 0 &&
709 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
710 check_ssid = 0;
711
712 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
713 /* Only allow wildcard SSID match if an AP
714 * advertises active WPS operation that matches
715 * with our mode. */
716 check_ssid = 1;
717 if (ssid->ssid_len == 0 &&
718 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
719 check_ssid = 0;
720 }
721#endif /* CONFIG_WPS */
722
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800723 if (ssid->bssid_set && ssid->ssid_len == 0 &&
724 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
725 check_ssid = 0;
726
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700727 if (check_ssid &&
728 (ssid_len != ssid->ssid_len ||
729 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
730 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
731 continue;
732 }
733
734 if (ssid->bssid_set &&
735 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
736 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
737 continue;
738 }
739
740 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
741 continue;
742
743 if (!wpa &&
744 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
745 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
746 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
747 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
748 "not allowed");
749 continue;
750 }
751
Jouni Malinen75ecf522011-06-27 15:19:46 -0700752 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700753 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
754 "mismatch");
755 continue;
756 }
757
Jouni Malinen75ecf522011-06-27 15:19:46 -0700758 if (bss->caps & IEEE80211_CAP_IBSS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
760 "network");
761 continue;
762 }
763
764 if (!freq_allowed(ssid->freq_list, bss->freq)) {
765 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
766 "allowed");
767 continue;
768 }
769
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800770 if (!rate_match(wpa_s, bss)) {
771 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
772 "not match");
773 continue;
774 }
775
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776#ifdef CONFIG_P2P
777 /*
778 * TODO: skip the AP if its P2P IE has Group Formation
779 * bit set in the P2P Group Capability Bitmap and we
780 * are not in Group Formation with that device.
781 */
782#endif /* CONFIG_P2P */
783
784 /* Matching configuration found */
785 return ssid;
786 }
787
788 /* No matching configuration found */
789 return NULL;
790}
791
792
793static struct wpa_bss *
794wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
795 struct wpa_scan_results *scan_res,
796 struct wpa_ssid *group,
797 struct wpa_ssid **selected_ssid)
798{
799 size_t i;
800
801 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
802 group->priority);
803
804 for (i = 0; i < scan_res->num; i++) {
805 struct wpa_scan_res *bss = scan_res->res[i];
806 const u8 *ie, *ssid;
807 u8 ssid_len;
808
809 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
810 if (!*selected_ssid)
811 continue;
812
813 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
814 ssid = ie ? ie + 2 : (u8 *) "";
815 ssid_len = ie ? ie[1] : 0;
816
817 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
818 " ssid='%s'",
819 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
820 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
821 }
822
823 return NULL;
824}
825
826
827static struct wpa_bss *
828wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
829 struct wpa_scan_results *scan_res,
830 struct wpa_ssid **selected_ssid)
831{
832 struct wpa_bss *selected = NULL;
833 int prio;
834
835 while (selected == NULL) {
836 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
837 selected = wpa_supplicant_select_bss(
838 wpa_s, scan_res, wpa_s->conf->pssid[prio],
839 selected_ssid);
840 if (selected)
841 break;
842 }
843
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800844 if (selected == NULL && wpa_s->blacklist &&
845 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
847 "blacklist and try again");
848 wpa_blacklist_clear(wpa_s);
849 wpa_s->blacklist_cleared++;
850 } else if (selected == NULL)
851 break;
852 }
853
854 return selected;
855}
856
857
858static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
859 int timeout_sec, int timeout_usec)
860{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700861 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862 /*
863 * No networks are enabled; short-circuit request so
864 * we don't wait timeout seconds before transitioning
865 * to INACTIVE state.
866 */
867 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
868 return;
869 }
870 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
871}
872
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800873
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700874int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800875 struct wpa_bss *selected,
876 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877{
878 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
879 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
880 "PBC session overlap");
881#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800882 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700883 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700884#endif /* CONFIG_P2P */
885
886#ifdef CONFIG_WPS
887 wpas_wps_cancel(wpa_s);
888#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700889 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700890 }
891
892 /*
893 * Do not trigger new association unless the BSSID has changed or if
894 * reassociation is requested. If we are in process of associating with
895 * the selected BSSID, do not trigger new attempt.
896 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800897 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
899 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
900 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
901 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
902 0))) {
903 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
904 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700905 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906 }
907 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
908 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
909 " pending: " MACSTR " wpa_state: %s",
910 wpa_s->reassociate, MAC2STR(selected->bssid),
911 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
912 wpa_supplicant_state_txt(wpa_s->wpa_state));
913 wpa_supplicant_associate(wpa_s, selected, ssid);
914 } else {
915 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
916 "selected AP");
917 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800918
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700919 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700920}
921
922
923static struct wpa_ssid *
924wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
925{
926 int prio;
927 struct wpa_ssid *ssid;
928
929 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
930 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
931 {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700932 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700933 continue;
934 if (ssid->mode == IEEE80211_MODE_IBSS ||
935 ssid->mode == IEEE80211_MODE_AP)
936 return ssid;
937 }
938 }
939 return NULL;
940}
941
942
943/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
944 * on BSS added and BSS changed events */
945static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +0300946 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947{
Jouni Malinen87fd2792011-05-16 18:35:42 +0300948 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700949
950 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
951 return;
952
Jouni Malinen87fd2792011-05-16 18:35:42 +0300953 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700954 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700955
Jouni Malinen87fd2792011-05-16 18:35:42 +0300956 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957 if (ssid == NULL)
958 continue;
959
Jouni Malinen87fd2792011-05-16 18:35:42 +0300960 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961 if (rsn == NULL)
962 continue;
963
Jouni Malinen87fd2792011-05-16 18:35:42 +0300964 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700965 }
966
967}
968
969
970static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
971 struct wpa_bss *selected,
972 struct wpa_ssid *ssid,
973 struct wpa_scan_results *scan_res)
974{
975 size_t i;
976 struct wpa_scan_res *current_bss = NULL;
977 int min_diff;
978
979 if (wpa_s->reassociate)
980 return 1; /* explicit request to reassociate */
981 if (wpa_s->wpa_state < WPA_ASSOCIATED)
982 return 1; /* we are not associated; continue */
983 if (wpa_s->current_ssid == NULL)
984 return 1; /* unknown current SSID */
985 if (wpa_s->current_ssid != ssid)
986 return 1; /* different network block */
987
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800988 if (wpas_driver_bss_selection(wpa_s))
989 return 0; /* Driver-based roaming */
990
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700991 for (i = 0; i < scan_res->num; i++) {
992 struct wpa_scan_res *res = scan_res->res[i];
993 const u8 *ie;
994 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
995 continue;
996
997 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
998 if (ie == NULL)
999 continue;
1000 if (ie[1] != wpa_s->current_ssid->ssid_len ||
1001 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
1002 continue;
1003 current_bss = res;
1004 break;
1005 }
1006
1007 if (!current_bss)
1008 return 1; /* current BSS not seen in scan results */
1009
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001010#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001011 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1012 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1013 MAC2STR(current_bss->bssid), current_bss->level);
1014 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1015 MAC2STR(selected->bssid), selected->level);
1016
1017 if (wpa_s->current_ssid->bssid_set &&
1018 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1019 0) {
1020 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1021 "has preferred BSSID");
1022 return 1;
1023 }
1024
1025 min_diff = 2;
1026 if (current_bss->level < 0) {
1027 if (current_bss->level < -85)
1028 min_diff = 1;
1029 else if (current_bss->level < -80)
1030 min_diff = 2;
1031 else if (current_bss->level < -75)
1032 min_diff = 3;
1033 else if (current_bss->level < -70)
1034 min_diff = 4;
1035 else
1036 min_diff = 5;
1037 }
1038 if (abs(current_bss->level - selected->level) < min_diff) {
1039 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1040 "in signal level");
1041 return 0;
1042 }
1043
1044 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001045#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001046 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001047#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048}
1049
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001050
Dmitry Shmidt04949592012-07-19 12:16:46 -07001051/* Return < 0 if no scan results could be fetched or if scan results should not
1052 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001053#ifdef ANDROID_P2P
1054static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1055 union wpa_event_data *data, int suppress_event)
1056#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001057static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1058 union wpa_event_data *data)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001059#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001060{
1061 struct wpa_bss *selected;
1062 struct wpa_ssid *ssid = NULL;
1063 struct wpa_scan_results *scan_res;
1064 int ap = 0;
1065
1066#ifdef CONFIG_AP
1067 if (wpa_s->ap_iface)
1068 ap = 1;
1069#endif /* CONFIG_AP */
1070
1071 wpa_supplicant_notify_scanning(wpa_s, 0);
1072
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001073#ifdef CONFIG_P2P
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001074#ifdef ANDROID_P2P
1075 if (p2p_search_pending(wpa_s->global->p2p) && !wpa_s->global->p2p_disabled &&
1076#else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001077 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001078#endif
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001079 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001080 wpa_s->p2p_cb_on_scan_complete = 0;
1081 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1082 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1083 "stopped scan processing");
1084 return -1;
1085 }
1086 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001087 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001088#endif /* CONFIG_P2P */
1089
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001090 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1091 data ? &data->scan_info :
1092 NULL, 1);
1093 if (scan_res == NULL) {
1094 if (wpa_s->conf->ap_scan == 2 || ap)
1095 return -1;
1096 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1097 "scanning again");
1098 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1099 return -1;
1100 }
1101
1102#ifndef CONFIG_NO_RANDOM_POOL
1103 size_t i, num;
1104 num = scan_res->num;
1105 if (num > 10)
1106 num = 10;
1107 for (i = 0; i < num; i++) {
1108 u8 buf[5];
1109 struct wpa_scan_res *res = scan_res->res[i];
1110 buf[0] = res->bssid[5];
1111 buf[1] = res->qual & 0xff;
1112 buf[2] = res->noise & 0xff;
1113 buf[3] = res->level & 0xff;
1114 buf[4] = res->tsf & 0xff;
1115 random_add_randomness(buf, sizeof(buf));
1116 }
1117#endif /* CONFIG_NO_RANDOM_POOL */
1118
1119 if (wpa_s->scan_res_handler) {
1120 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1121 struct wpa_scan_results *scan_res);
1122
1123 scan_res_handler = wpa_s->scan_res_handler;
1124 wpa_s->scan_res_handler = NULL;
1125 scan_res_handler(wpa_s, scan_res);
1126
1127 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001128 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129 }
1130
1131 if (ap) {
1132 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1133#ifdef CONFIG_AP
1134 if (wpa_s->ap_iface->scan_cb)
1135 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1136#endif /* CONFIG_AP */
1137 wpa_scan_results_free(scan_res);
1138 return 0;
1139 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001140#ifdef ANDROID_P2P
1141 if(!suppress_event)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001142 {
1143 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1144 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1145 wpas_notify_scan_results(wpa_s);
1146 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001147#else
1148 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1149 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1150 wpas_notify_scan_results(wpa_s);
1151#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152
1153 wpas_notify_scan_done(wpa_s, 1);
1154
Dmitry Shmidt04949592012-07-19 12:16:46 -07001155 if (sme_proc_obss_scan(wpa_s) > 0) {
1156 wpa_scan_results_free(scan_res);
1157 return 0;
1158 }
1159
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001160 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1161 wpa_scan_results_free(scan_res);
1162 return 0;
1163 }
1164
Dmitry Shmidt04949592012-07-19 12:16:46 -07001165 if (autoscan_notify_scan(wpa_s, scan_res)) {
1166 wpa_scan_results_free(scan_res);
1167 return 0;
1168 }
1169
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001170 if (wpa_s->disconnected) {
1171 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1172 wpa_scan_results_free(scan_res);
1173 return 0;
1174 }
1175
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001176 if (!wpas_driver_bss_selection(wpa_s) &&
1177 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178 wpa_scan_results_free(scan_res);
1179 return 0;
1180 }
1181
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001182 wpas_wps_update_ap_info(wpa_s, scan_res);
1183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1185
1186 if (selected) {
1187 int skip;
1188 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1189 scan_res);
1190 wpa_scan_results_free(scan_res);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001191 if (skip) {
1192 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001193 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001194 }
1195
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001196 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001198 return -1;
1199 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03001200 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001201 } else {
1202 wpa_scan_results_free(scan_res);
1203 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1204 ssid = wpa_supplicant_pick_new_network(wpa_s);
1205 if (ssid) {
1206 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1207 wpa_supplicant_associate(wpa_s, NULL, ssid);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001208 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001209 } else {
1210 int timeout_sec = wpa_s->scan_interval;
1211 int timeout_usec = 0;
1212#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001213 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1214 return 0;
1215
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 if (wpa_s->p2p_in_provisioning) {
1217 /*
1218 * Use shorter wait during P2P Provisioning
1219 * state to speed up group formation.
1220 */
1221 timeout_sec = 0;
1222 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001223 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1224 timeout_usec);
1225 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 }
1227#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001228#ifdef CONFIG_INTERWORKING
1229 if (wpa_s->conf->auto_interworking &&
1230 wpa_s->conf->interworking &&
1231 wpa_s->conf->cred) {
1232 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1233 "start ANQP fetch since no matching "
1234 "networks found");
1235 wpa_s->network_select = 1;
1236 wpa_s->auto_network_select = 1;
1237 interworking_start_fetch_anqp(wpa_s);
1238 return 0;
1239 }
1240#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001241 if (wpa_supplicant_req_sched_scan(wpa_s))
1242 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1243 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244 }
1245 }
1246 return 0;
1247}
1248
1249
1250static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1251 union wpa_event_data *data)
1252{
1253 const char *rn, *rn2;
1254 struct wpa_supplicant *ifs;
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001255#ifdef ANDROID_P2P
1256 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) {
1257#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001258 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001259#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001260 /*
1261 * If no scan results could be fetched, then no need to
1262 * notify those interfaces that did not actually request
1263 * this scan.
1264 */
1265 return;
1266 }
1267
1268 /*
1269 * Check other interfaces to see if they have the same radio-name. If
1270 * so, they get updated with this same scan info.
1271 */
1272 if (!wpa_s->driver->get_radio_name)
1273 return;
1274
1275 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1276 if (rn == NULL || rn[0] == '\0')
1277 return;
1278
1279 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1280 "sharing same radio (%s) in event_scan_results", rn);
1281
1282 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1283 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1284 continue;
1285
1286 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1287 if (rn2 && os_strcmp(rn, rn2) == 0) {
1288 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1289 "sibling", ifs->ifname);
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001290#ifdef ANDROID_P2P
1291 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) {
1292 /* Do not update the scan results from STA interface to p2p interfaces */
1293 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from "
1294 "sibling %s", ifs->ifname, wpa_s->ifname);
1295 continue;
1296 }
1297 else {
1298 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1299 * no time. Avoid announcing it to application as it may not
1300 * be that useful (since results will be that of only 1,6,11).
1301 * over to any other interface as it
1302 */
1303 if(p2p_search_in_progress(wpa_s->global->p2p))
1304 _wpa_supplicant_event_scan_results(ifs, data, 1);
1305 else
1306 _wpa_supplicant_event_scan_results(ifs, data, 0);
1307 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001308#else
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001309 _wpa_supplicant_event_scan_results(ifs, data);
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001310#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001311 }
1312 }
1313}
1314
1315#endif /* CONFIG_NO_SCAN_PROCESSING */
1316
1317
Dmitry Shmidt04949592012-07-19 12:16:46 -07001318#ifdef CONFIG_WNM
1319
1320static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1321{
1322 struct wpa_supplicant *wpa_s = eloop_ctx;
1323
1324 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1325 return;
1326
1327 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1328 MAC2STR(wpa_s->bssid));
1329 /* TODO: could skip this if normal data traffic has been sent */
1330 /* TODO: Consider using some more appropriate data frame for this */
1331 if (wpa_s->l2)
1332 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1333
1334#ifdef CONFIG_SME
1335 if (wpa_s->sme.bss_max_idle_period) {
1336 unsigned int msec;
1337 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1338 if (msec > 100)
1339 msec -= 100;
1340 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1341 wnm_bss_keep_alive, wpa_s, NULL);
1342 }
1343#endif /* CONFIG_SME */
1344}
1345
1346
1347static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1348 const u8 *ies, size_t ies_len)
1349{
1350 struct ieee802_11_elems elems;
1351
1352 if (ies == NULL)
1353 return;
1354
1355 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1356 return;
1357
1358#ifdef CONFIG_SME
1359 if (elems.bss_max_idle_period) {
1360 unsigned int msec;
1361 wpa_s->sme.bss_max_idle_period =
1362 WPA_GET_LE16(elems.bss_max_idle_period);
1363 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1364 "TU)%s", wpa_s->sme.bss_max_idle_period,
1365 (elems.bss_max_idle_period[2] & 0x01) ?
1366 " (protected keep-live required)" : "");
1367 if (wpa_s->sme.bss_max_idle_period == 0)
1368 wpa_s->sme.bss_max_idle_period = 1;
1369 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1370 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1371 /* msec times 1000 */
1372 msec = wpa_s->sme.bss_max_idle_period * 1024;
1373 if (msec > 100)
1374 msec -= 100;
1375 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1376 wnm_bss_keep_alive, wpa_s,
1377 NULL);
1378 }
1379 }
1380#endif /* CONFIG_SME */
1381}
1382
1383#endif /* CONFIG_WNM */
1384
1385
1386void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1387{
1388#ifdef CONFIG_WNM
1389 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1390#endif /* CONFIG_WNM */
1391}
1392
1393
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001394static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1395 union wpa_event_data *data)
1396{
1397 int l, len, found = 0, wpa_found, rsn_found;
1398 const u8 *p;
1399
1400 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1401 if (data->assoc_info.req_ies)
1402 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1403 data->assoc_info.req_ies_len);
1404 if (data->assoc_info.resp_ies) {
1405 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1406 data->assoc_info.resp_ies_len);
1407#ifdef CONFIG_TDLS
1408 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1409 data->assoc_info.resp_ies_len);
1410#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001411#ifdef CONFIG_WNM
1412 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1413 data->assoc_info.resp_ies_len);
1414#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001415 }
1416 if (data->assoc_info.beacon_ies)
1417 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1418 data->assoc_info.beacon_ies,
1419 data->assoc_info.beacon_ies_len);
1420 if (data->assoc_info.freq)
1421 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1422 data->assoc_info.freq);
1423
1424 p = data->assoc_info.req_ies;
1425 l = data->assoc_info.req_ies_len;
1426
1427 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1428 while (p && l >= 2) {
1429 len = p[1] + 2;
1430 if (len > l) {
1431 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1432 p, l);
1433 break;
1434 }
1435 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1436 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1437 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1438 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1439 break;
1440 found = 1;
1441 wpa_find_assoc_pmkid(wpa_s);
1442 break;
1443 }
1444 l -= len;
1445 p += len;
1446 }
1447 if (!found && data->assoc_info.req_ies)
1448 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1449
1450#ifdef CONFIG_IEEE80211R
1451#ifdef CONFIG_SME
1452 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1453 u8 bssid[ETH_ALEN];
1454 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1455 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1456 data->assoc_info.resp_ies,
1457 data->assoc_info.resp_ies_len,
1458 bssid) < 0) {
1459 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1460 "Reassociation Response failed");
1461 wpa_supplicant_deauthenticate(
1462 wpa_s, WLAN_REASON_INVALID_IE);
1463 return -1;
1464 }
1465 }
1466
1467 p = data->assoc_info.resp_ies;
1468 l = data->assoc_info.resp_ies_len;
1469
1470#ifdef CONFIG_WPS_STRICT
1471 if (p && wpa_s->current_ssid &&
1472 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1473 struct wpabuf *wps;
1474 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1475 if (wps == NULL) {
1476 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1477 "include WPS IE in (Re)Association Response");
1478 return -1;
1479 }
1480
1481 if (wps_validate_assoc_resp(wps) < 0) {
1482 wpabuf_free(wps);
1483 wpa_supplicant_deauthenticate(
1484 wpa_s, WLAN_REASON_INVALID_IE);
1485 return -1;
1486 }
1487 wpabuf_free(wps);
1488 }
1489#endif /* CONFIG_WPS_STRICT */
1490
1491 /* Go through the IEs and make a copy of the MDIE, if present. */
1492 while (p && l >= 2) {
1493 len = p[1] + 2;
1494 if (len > l) {
1495 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1496 p, l);
1497 break;
1498 }
1499 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1500 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1501 wpa_s->sme.ft_used = 1;
1502 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1503 MOBILITY_DOMAIN_ID_LEN);
1504 break;
1505 }
1506 l -= len;
1507 p += len;
1508 }
1509#endif /* CONFIG_SME */
1510
1511 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1512 data->assoc_info.resp_ies_len);
1513#endif /* CONFIG_IEEE80211R */
1514
1515 /* WPA/RSN IE from Beacon/ProbeResp */
1516 p = data->assoc_info.beacon_ies;
1517 l = data->assoc_info.beacon_ies_len;
1518
1519 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1520 */
1521 wpa_found = rsn_found = 0;
1522 while (p && l >= 2) {
1523 len = p[1] + 2;
1524 if (len > l) {
1525 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1526 p, l);
1527 break;
1528 }
1529 if (!wpa_found &&
1530 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1531 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1532 wpa_found = 1;
1533 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1534 }
1535
1536 if (!rsn_found &&
1537 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1538 rsn_found = 1;
1539 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1540 }
1541
1542 l -= len;
1543 p += len;
1544 }
1545
1546 if (!wpa_found && data->assoc_info.beacon_ies)
1547 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1548 if (!rsn_found && data->assoc_info.beacon_ies)
1549 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1550 if (wpa_found || rsn_found)
1551 wpa_s->ap_ies_from_associnfo = 1;
1552
Jouni Malinen87fd2792011-05-16 18:35:42 +03001553 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1554 wpa_s->assoc_freq != data->assoc_info.freq) {
1555 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1556 "%u to %u MHz",
1557 wpa_s->assoc_freq, data->assoc_info.freq);
1558 wpa_supplicant_update_scan_results(wpa_s);
1559 }
1560
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001561 wpa_s->assoc_freq = data->assoc_info.freq;
1562
1563 return 0;
1564}
1565
1566
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001567static struct wpa_bss * wpa_supplicant_get_new_bss(
1568 struct wpa_supplicant *wpa_s, const u8 *bssid)
1569{
1570 struct wpa_bss *bss = NULL;
1571 struct wpa_ssid *ssid = wpa_s->current_ssid;
1572
1573 if (ssid->ssid_len > 0)
1574 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1575 if (!bss)
1576 bss = wpa_bss_get_bssid(wpa_s, bssid);
1577
1578 return bss;
1579}
1580
1581
1582static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1583{
1584 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1585
1586 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1587 return -1;
1588
1589 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1590 return 0;
1591
1592 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1593 WPA_IE_VENDOR_TYPE);
1594 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1595
1596 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1597 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1598 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1599 bss_rsn ? 2 + bss_rsn[1] : 0))
1600 return -1;
1601
1602 return 0;
1603}
1604
1605
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001606static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1607 union wpa_event_data *data)
1608{
1609 u8 bssid[ETH_ALEN];
1610 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001611 struct wpa_driver_capa capa;
1612
1613#ifdef CONFIG_AP
1614 if (wpa_s->ap_iface) {
1615 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1616 data->assoc_info.addr,
1617 data->assoc_info.req_ies,
1618 data->assoc_info.req_ies_len,
1619 data->assoc_info.reassoc);
1620 return;
1621 }
1622#endif /* CONFIG_AP */
1623
1624 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1625 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1626 return;
1627
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001628 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1629 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1630 wpa_supplicant_disassociate(
1631 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1632 return;
1633 }
1634
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001636 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001637 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1638 MACSTR, MAC2STR(bssid));
1639 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001640 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1641 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001642 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001643
1644 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1645 wpa_clear_keys(wpa_s, bssid);
1646 }
1647 if (wpa_supplicant_select_config(wpa_s) < 0) {
1648 wpa_supplicant_disassociate(
1649 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1650 return;
1651 }
1652 if (wpa_s->current_ssid) {
1653 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001654
1655 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1656 if (!bss) {
1657 wpa_supplicant_update_scan_results(wpa_s);
1658
1659 /* Get the BSS from the new scan results */
1660 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1661 }
1662
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001663 if (bss)
1664 wpa_s->current_bss = bss;
1665 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001666
1667 if (wpa_s->conf->ap_scan == 1 &&
1668 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1669 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1670 wpa_msg(wpa_s, MSG_WARNING,
1671 "WPA/RSN IEs not updated");
1672 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001673 }
1674
1675#ifdef CONFIG_SME
1676 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1677 wpa_s->sme.prev_bssid_set = 1;
1678#endif /* CONFIG_SME */
1679
1680 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1681 if (wpa_s->current_ssid) {
1682 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1683 * initialized before association, but for other modes,
1684 * initialize PC/SC here, if the current configuration needs
1685 * smartcard or SIM/USIM. */
1686 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1687 }
1688 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1689 if (wpa_s->l2)
1690 l2_packet_notify_auth_start(wpa_s->l2);
1691
1692 /*
1693 * Set portEnabled first to FALSE in order to get EAP state machine out
1694 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1695 * state machine may transit to AUTHENTICATING state based on obsolete
1696 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1697 * AUTHENTICATED without ever giving chance to EAP state machine to
1698 * reset the state.
1699 */
1700 if (!ft_completed) {
1701 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1702 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1703 }
1704 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1705 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1706 /* 802.1X::portControl = Auto */
1707 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1708 wpa_s->eapol_received = 0;
1709 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1710 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1711 (wpa_s->current_ssid &&
1712 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1713 wpa_supplicant_cancel_auth_timeout(wpa_s);
1714 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1715 } else if (!ft_completed) {
1716 /* Timeout for receiving the first EAPOL packet */
1717 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1718 }
1719 wpa_supplicant_cancel_scan(wpa_s);
1720
1721 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1722 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1723 /*
1724 * We are done; the driver will take care of RSN 4-way
1725 * handshake.
1726 */
1727 wpa_supplicant_cancel_auth_timeout(wpa_s);
1728 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1729 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1730 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1731 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1732 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1733 /*
1734 * The driver will take care of RSN 4-way handshake, so we need
1735 * to allow EAPOL supplicant to complete its work without
1736 * waiting for WPA supplicant.
1737 */
1738 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1739 } else if (ft_completed) {
1740 /*
1741 * FT protocol completed - make sure EAPOL state machine ends
1742 * up in authenticated.
1743 */
1744 wpa_supplicant_cancel_auth_timeout(wpa_s);
1745 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1746 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1747 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1748 }
1749
1750 if (wpa_s->pending_eapol_rx) {
1751 struct os_time now, age;
1752 os_get_time(&now);
1753 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1754 if (age.sec == 0 && age.usec < 100000 &&
1755 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1756 0) {
1757 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1758 "frame that was received just before "
1759 "association notification");
1760 wpa_supplicant_rx_eapol(
1761 wpa_s, wpa_s->pending_eapol_rx_src,
1762 wpabuf_head(wpa_s->pending_eapol_rx),
1763 wpabuf_len(wpa_s->pending_eapol_rx));
1764 }
1765 wpabuf_free(wpa_s->pending_eapol_rx);
1766 wpa_s->pending_eapol_rx = NULL;
1767 }
1768
1769 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1770 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1771 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1772 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1773 /* Set static WEP keys again */
1774 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1775 }
1776
1777#ifdef CONFIG_IBSS_RSN
1778 if (wpa_s->current_ssid &&
1779 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1780 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1781 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1782 wpa_s->ibss_rsn == NULL) {
1783 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1784 if (!wpa_s->ibss_rsn) {
1785 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1786 wpa_supplicant_deauthenticate(
1787 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1788 return;
1789 }
1790
1791 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1792 }
1793#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001794
1795 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001796}
1797
1798
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001799static int disconnect_reason_recoverable(u16 reason_code)
1800{
1801 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1802 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1803 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1804}
1805
1806
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001807static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001808 u16 reason_code,
1809 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810{
1811 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03001812
1813 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1814 /*
1815 * At least Host AP driver and a Prism3 card seemed to be
1816 * generating streams of disconnected events when configuring
1817 * IBSS for WPA-None. Ignore them for now.
1818 */
1819 return;
1820 }
1821
1822 bssid = wpa_s->bssid;
1823 if (is_zero_ether_addr(bssid))
1824 bssid = wpa_s->pending_bssid;
1825
1826 if (!is_zero_ether_addr(bssid) ||
1827 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1828 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1829 " reason=%d%s",
1830 MAC2STR(bssid), reason_code,
1831 locally_generated ? " locally_generated=1" : "");
1832 }
1833}
1834
1835
1836static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1837 u16 reason_code,
1838 int locally_generated)
1839{
1840 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 int authenticating;
1842 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001843 struct wpa_bss *fast_reconnect = NULL;
1844 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001845 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001846
1847 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1848 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1849
1850 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1851 /*
1852 * At least Host AP driver and a Prism3 card seemed to be
1853 * generating streams of disconnected events when configuring
1854 * IBSS for WPA-None. Ignore them for now.
1855 */
1856 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1857 "IBSS/WPA-None mode");
1858 return;
1859 }
1860
1861 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1862 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1863 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1864 "pre-shared key may be incorrect");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001865 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001866 }
1867 if (!wpa_s->auto_reconnect_disabled ||
1868 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001869 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1870 "reconnect (wps=%d wpa_state=%d)",
1871 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1872 wpa_s->wpa_state);
1873 if (wpa_s->wpa_state == WPA_COMPLETED &&
1874 wpa_s->current_ssid &&
1875 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001876 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001877 disconnect_reason_recoverable(reason_code)) {
1878 /*
1879 * It looks like the AP has dropped association with
1880 * us, but could allow us to get back in. Try to
1881 * reconnect to the same BSS without full scan to save
1882 * time for some common cases.
1883 */
1884 fast_reconnect = wpa_s->current_bss;
1885 fast_reconnect_ssid = wpa_s->current_ssid;
1886 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001887#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07001888 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001889#else
1890 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1891#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001892 else
1893 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1894 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001895 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001896 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001897 "try to re-connect");
1898 wpa_s->reassociate = 0;
1899 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001900 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001901 }
1902 bssid = wpa_s->bssid;
1903 if (is_zero_ether_addr(bssid))
1904 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001905 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1906 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001907 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001908 if (locally_generated)
1909 wpa_s->disconnect_reason = -reason_code;
1910 else
1911 wpa_s->disconnect_reason = reason_code;
1912 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001913 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1914 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1915 wpa_s->keys_cleared = 0;
1916 wpa_clear_keys(wpa_s, wpa_s->bssid);
1917 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001918 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001919 wpa_supplicant_mark_disassoc(wpa_s);
1920
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001921 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001922 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001923 wpa_s->current_ssid = last_ssid;
1924 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001925
1926 if (fast_reconnect) {
1927#ifndef CONFIG_NO_SCAN_PROCESSING
1928 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1929 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1930 fast_reconnect_ssid) < 0) {
1931 /* Recover through full scan */
1932 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1933 }
1934#endif /* CONFIG_NO_SCAN_PROCESSING */
1935 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001936}
1937
1938
1939#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001940void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001941{
1942 struct wpa_supplicant *wpa_s = eloop_ctx;
1943
1944 if (!wpa_s->pending_mic_error_report)
1945 return;
1946
1947 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1948 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1949 wpa_s->pending_mic_error_report = 0;
1950}
1951#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1952
1953
1954static void
1955wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1956 union wpa_event_data *data)
1957{
1958 int pairwise;
1959 struct os_time t;
1960
1961 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1962 pairwise = (data && data->michael_mic_failure.unicast);
1963 os_get_time(&t);
1964 if ((wpa_s->last_michael_mic_error &&
1965 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1966 wpa_s->pending_mic_error_report) {
1967 if (wpa_s->pending_mic_error_report) {
1968 /*
1969 * Send the pending MIC error report immediately since
1970 * we are going to start countermeasures and AP better
1971 * do the same.
1972 */
1973 wpa_sm_key_request(wpa_s->wpa, 1,
1974 wpa_s->pending_mic_error_pairwise);
1975 }
1976
1977 /* Send the new MIC error report immediately since we are going
1978 * to start countermeasures and AP better do the same.
1979 */
1980 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1981
1982 /* initialize countermeasures */
1983 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001984
1985 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1986
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001987 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1988
1989 /*
1990 * Need to wait for completion of request frame. We do not get
1991 * any callback for the message completion, so just wait a
1992 * short while and hope for the best. */
1993 os_sleep(0, 10000);
1994
1995 wpa_drv_set_countermeasures(wpa_s, 1);
1996 wpa_supplicant_deauthenticate(wpa_s,
1997 WLAN_REASON_MICHAEL_MIC_FAILURE);
1998 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1999 wpa_s, NULL);
2000 eloop_register_timeout(60, 0,
2001 wpa_supplicant_stop_countermeasures,
2002 wpa_s, NULL);
2003 /* TODO: mark the AP rejected for 60 second. STA is
2004 * allowed to associate with another AP.. */
2005 } else {
2006#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2007 if (wpa_s->mic_errors_seen) {
2008 /*
2009 * Reduce the effectiveness of Michael MIC error
2010 * reports as a means for attacking against TKIP if
2011 * more than one MIC failure is noticed with the same
2012 * PTK. We delay the transmission of the reports by a
2013 * random time between 0 and 60 seconds in order to
2014 * force the attacker wait 60 seconds before getting
2015 * the information on whether a frame resulted in a MIC
2016 * failure.
2017 */
2018 u8 rval[4];
2019 int sec;
2020
2021 if (os_get_random(rval, sizeof(rval)) < 0)
2022 sec = os_random() % 60;
2023 else
2024 sec = WPA_GET_BE32(rval) % 60;
2025 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2026 "report %d seconds", sec);
2027 wpa_s->pending_mic_error_report = 1;
2028 wpa_s->pending_mic_error_pairwise = pairwise;
2029 eloop_cancel_timeout(
2030 wpa_supplicant_delayed_mic_error_report,
2031 wpa_s, NULL);
2032 eloop_register_timeout(
2033 sec, os_random() % 1000000,
2034 wpa_supplicant_delayed_mic_error_report,
2035 wpa_s, NULL);
2036 } else {
2037 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2038 }
2039#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2040 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2041#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2042 }
2043 wpa_s->last_michael_mic_error = t.sec;
2044 wpa_s->mic_errors_seen++;
2045}
2046
2047
2048#ifdef CONFIG_TERMINATE_ONLASTIF
2049static int any_interfaces(struct wpa_supplicant *head)
2050{
2051 struct wpa_supplicant *wpa_s;
2052
2053 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2054 if (!wpa_s->interface_removed)
2055 return 1;
2056 return 0;
2057}
2058#endif /* CONFIG_TERMINATE_ONLASTIF */
2059
2060
2061static void
2062wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2063 union wpa_event_data *data)
2064{
2065 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2066 return;
2067
2068 switch (data->interface_status.ievent) {
2069 case EVENT_INTERFACE_ADDED:
2070 if (!wpa_s->interface_removed)
2071 break;
2072 wpa_s->interface_removed = 0;
2073 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2074 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2075 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2076 "driver after interface was added");
2077 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002078 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002079 break;
2080 case EVENT_INTERFACE_REMOVED:
2081 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2082 wpa_s->interface_removed = 1;
2083 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002084 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002085 l2_packet_deinit(wpa_s->l2);
2086 wpa_s->l2 = NULL;
2087#ifdef CONFIG_IBSS_RSN
2088 ibss_rsn_deinit(wpa_s->ibss_rsn);
2089 wpa_s->ibss_rsn = NULL;
2090#endif /* CONFIG_IBSS_RSN */
2091#ifdef CONFIG_TERMINATE_ONLASTIF
2092 /* check if last interface */
2093 if (!any_interfaces(wpa_s->global->ifaces))
2094 eloop_terminate();
2095#endif /* CONFIG_TERMINATE_ONLASTIF */
2096 break;
2097 }
2098}
2099
2100
2101#ifdef CONFIG_PEERKEY
2102static void
2103wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2104 union wpa_event_data *data)
2105{
2106 if (data == NULL)
2107 return;
2108 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2109}
2110#endif /* CONFIG_PEERKEY */
2111
2112
2113#ifdef CONFIG_TDLS
2114static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2115 union wpa_event_data *data)
2116{
2117 if (data == NULL)
2118 return;
2119 switch (data->tdls.oper) {
2120 case TDLS_REQUEST_SETUP:
2121 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2122 break;
2123 case TDLS_REQUEST_TEARDOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002124 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2125 data->tdls.reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126 break;
2127 }
2128}
2129#endif /* CONFIG_TDLS */
2130
2131
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002132#ifdef CONFIG_IEEE80211V
2133static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2134 union wpa_event_data *data)
2135{
2136 if (data == NULL)
2137 return;
2138 switch (data->wnm.oper) {
2139 case WNM_OPER_SLEEP:
2140 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2141 "(action=%d, intval=%d)",
2142 data->wnm.sleep_action, data->wnm.sleep_intval);
2143 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2144 data->wnm.sleep_intval);
2145 break;
2146 }
2147}
2148#endif /* CONFIG_IEEE80211V */
2149
2150
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002151#ifdef CONFIG_IEEE80211R
2152static void
2153wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2154 union wpa_event_data *data)
2155{
2156 if (data == NULL)
2157 return;
2158
2159 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2160 data->ft_ies.ies_len,
2161 data->ft_ies.ft_action,
2162 data->ft_ies.target_ap,
2163 data->ft_ies.ric_ies,
2164 data->ft_ies.ric_ies_len) < 0) {
2165 /* TODO: prevent MLME/driver from trying to associate? */
2166 }
2167}
2168#endif /* CONFIG_IEEE80211R */
2169
2170
2171#ifdef CONFIG_IBSS_RSN
2172static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2173 union wpa_event_data *data)
2174{
2175 struct wpa_ssid *ssid;
2176 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2177 return;
2178 if (data == NULL)
2179 return;
2180 ssid = wpa_s->current_ssid;
2181 if (ssid == NULL)
2182 return;
2183 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2184 return;
2185
2186 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2187}
2188#endif /* CONFIG_IBSS_RSN */
2189
2190
2191#ifdef CONFIG_IEEE80211R
2192static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2193 size_t len)
2194{
2195 const u8 *sta_addr, *target_ap_addr;
2196 u16 status;
2197
2198 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2199 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2200 return; /* only SME case supported for now */
2201 if (len < 1 + 2 * ETH_ALEN + 2)
2202 return;
2203 if (data[0] != 2)
2204 return; /* Only FT Action Response is supported for now */
2205 sta_addr = data + 1;
2206 target_ap_addr = data + 1 + ETH_ALEN;
2207 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2208 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2209 MACSTR " TargetAP " MACSTR " status %u",
2210 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2211
2212 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2213 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2214 " in FT Action Response", MAC2STR(sta_addr));
2215 return;
2216 }
2217
2218 if (status) {
2219 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2220 "failure (status code %d)", status);
2221 /* TODO: report error to FT code(?) */
2222 return;
2223 }
2224
2225 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2226 len - (1 + 2 * ETH_ALEN + 2), 1,
2227 target_ap_addr, NULL, 0) < 0)
2228 return;
2229
2230#ifdef CONFIG_SME
2231 {
2232 struct wpa_bss *bss;
2233 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2234 if (bss)
2235 wpa_s->sme.freq = bss->freq;
2236 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2237 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2238 WLAN_AUTH_FT);
2239 }
2240#endif /* CONFIG_SME */
2241}
2242#endif /* CONFIG_IEEE80211R */
2243
2244
2245static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2246 struct unprot_deauth *e)
2247{
2248#ifdef CONFIG_IEEE80211W
2249 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2250 "dropped: " MACSTR " -> " MACSTR
2251 " (reason code %u)",
2252 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2253 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2254#endif /* CONFIG_IEEE80211W */
2255}
2256
2257
2258static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2259 struct unprot_disassoc *e)
2260{
2261#ifdef CONFIG_IEEE80211W
2262 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2263 "dropped: " MACSTR " -> " MACSTR
2264 " (reason code %u)",
2265 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2266 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2267#endif /* CONFIG_IEEE80211W */
2268}
2269
2270
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002271static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2272{
2273 u8 action, mode;
2274 const u8 *pos, *end;
2275
2276 if (rx->data == NULL || rx->len == 0)
2277 return;
2278
2279 pos = rx->data;
2280 end = pos + rx->len;
2281 action = *pos++;
2282
2283 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2284 action, MAC2STR(rx->sa));
2285 switch (action) {
2286 case WNM_BSS_TRANS_MGMT_REQ:
2287 if (pos + 5 > end)
2288 break;
2289 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2290 "Request: dialog_token=%u request_mode=0x%x "
2291 "disassoc_timer=%u validity_interval=%u",
2292 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2293 mode = pos[1];
2294 pos += 5;
2295 if (mode & 0x08)
2296 pos += 12; /* BSS Termination Duration */
2297 if (mode & 0x10) {
2298 char url[256];
2299 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2300 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2301 "Transition Management Request "
2302 "(URL)");
2303 break;
2304 }
2305 os_memcpy(url, pos + 1, pos[0]);
2306 url[pos[0]] = '\0';
2307 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2308 "Imminent - session_info_url=%s", url);
2309 }
2310 break;
2311 }
2312}
2313
2314
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002315void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2316 union wpa_event_data *data)
2317{
2318 struct wpa_supplicant *wpa_s = ctx;
2319 u16 reason_code = 0;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002320 int locally_generated = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002321
2322 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2323 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002324 event != EVENT_INTERFACE_STATUS &&
2325 event != EVENT_SCHED_SCAN_STOPPED) {
2326 wpa_dbg(wpa_s, MSG_DEBUG,
2327 "Ignore event %s (%d) while interface is disabled",
2328 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002329 return;
2330 }
2331
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002332#ifndef CONFIG_NO_STDOUT_DEBUG
2333{
2334 int level = MSG_DEBUG;
2335
Dmitry Shmidt04949592012-07-19 12:16:46 -07002336 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002337 const struct ieee80211_hdr *hdr;
2338 u16 fc;
2339 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2340 fc = le_to_host16(hdr->frame_control);
2341 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2342 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2343 level = MSG_EXCESSIVE;
2344 }
2345
2346 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2347 event_to_string(event), event);
2348}
2349#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002350
2351 switch (event) {
2352 case EVENT_AUTH:
2353 sme_event_auth(wpa_s, data);
2354 break;
2355 case EVENT_ASSOC:
2356 wpa_supplicant_event_assoc(wpa_s, data);
2357 break;
2358 case EVENT_DISASSOC:
2359 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2360 if (data) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002361 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2362 data->disassoc_info.reason_code,
2363 data->disassoc_info.locally_generated ?
2364 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002365 if (data->disassoc_info.addr)
2366 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2367 MAC2STR(data->disassoc_info.addr));
2368 }
2369#ifdef CONFIG_AP
2370 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2371 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2372 data->disassoc_info.addr);
2373 break;
2374 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002375 if (wpa_s->ap_iface) {
2376 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2377 "AP mode");
2378 break;
2379 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002380#endif /* CONFIG_AP */
2381 if (data) {
2382 reason_code = data->disassoc_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002383 locally_generated =
2384 data->disassoc_info.locally_generated;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002385 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2386 data->disassoc_info.ie,
2387 data->disassoc_info.ie_len);
2388#ifdef CONFIG_P2P
2389 wpas_p2p_disassoc_notif(
2390 wpa_s, data->disassoc_info.addr, reason_code,
2391 data->disassoc_info.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002392 data->disassoc_info.ie_len,
2393 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002394#endif /* CONFIG_P2P */
2395 }
2396 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2397 sme_event_disassoc(wpa_s, data);
2398 /* fall through */
2399 case EVENT_DEAUTH:
2400 if (event == EVENT_DEAUTH) {
2401 wpa_dbg(wpa_s, MSG_DEBUG,
2402 "Deauthentication notification");
2403 if (data) {
2404 reason_code = data->deauth_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002405 locally_generated =
2406 data->deauth_info.locally_generated;
2407 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2408 data->deauth_info.reason_code,
2409 data->deauth_info.locally_generated ?
2410 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002411 if (data->deauth_info.addr) {
2412 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2413 MACSTR,
2414 MAC2STR(data->deauth_info.
2415 addr));
2416 }
2417 wpa_hexdump(MSG_DEBUG,
2418 "Deauthentication frame IE(s)",
2419 data->deauth_info.ie,
2420 data->deauth_info.ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002421 }
2422 }
2423#ifdef CONFIG_AP
2424 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2425 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2426 data->deauth_info.addr);
2427 break;
2428 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002429 if (wpa_s->ap_iface) {
2430 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2431 "AP mode");
2432 break;
2433 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002434#endif /* CONFIG_AP */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002435 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2436 locally_generated);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002437 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2438 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2439 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2440 eapol_sm_failed(wpa_s->eapol)))
2441 wpas_auth_failed(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002442#ifdef CONFIG_P2P
2443 if (event == EVENT_DEAUTH && data) {
Jouni Malinen2b89da82012-08-31 22:04:41 +03002444 if (wpas_p2p_deauth_notif(wpa_s,
2445 data->deauth_info.addr,
2446 reason_code,
2447 data->deauth_info.ie,
2448 data->deauth_info.ie_len,
2449 locally_generated) > 0) {
2450 /*
2451 * The interface was removed, so cannot
2452 * continue processing any additional
2453 * operations after this.
2454 */
2455 break;
2456 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002457 }
2458#endif /* CONFIG_P2P */
Jouni Malinen2b89da82012-08-31 22:04:41 +03002459 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2460 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002461 break;
2462 case EVENT_MICHAEL_MIC_FAILURE:
2463 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2464 break;
2465#ifndef CONFIG_NO_SCAN_PROCESSING
2466 case EVENT_SCAN_RESULTS:
2467 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002468#ifdef CONFIG_P2P
2469 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2470 wpa_s->global->p2p != NULL &&
2471 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2472 wpa_s->wpa_state != WPA_ASSOCIATING) {
2473 wpa_s->p2p_cb_on_scan_complete = 0;
2474 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2475 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2476 "continued after scan result processing");
2477 }
2478 }
2479#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002480 break;
2481#endif /* CONFIG_NO_SCAN_PROCESSING */
2482 case EVENT_ASSOCINFO:
2483 wpa_supplicant_event_associnfo(wpa_s, data);
2484 break;
2485 case EVENT_INTERFACE_STATUS:
2486 wpa_supplicant_event_interface_status(wpa_s, data);
2487 break;
2488 case EVENT_PMKID_CANDIDATE:
2489 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2490 break;
2491#ifdef CONFIG_PEERKEY
2492 case EVENT_STKSTART:
2493 wpa_supplicant_event_stkstart(wpa_s, data);
2494 break;
2495#endif /* CONFIG_PEERKEY */
2496#ifdef CONFIG_TDLS
2497 case EVENT_TDLS:
2498 wpa_supplicant_event_tdls(wpa_s, data);
2499 break;
2500#endif /* CONFIG_TDLS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002501#ifdef CONFIG_IEEE80211V
2502 case EVENT_WNM:
2503 wpa_supplicant_event_wnm(wpa_s, data);
2504 break;
2505#endif /* CONFIG_IEEE80211V */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002506#ifdef CONFIG_IEEE80211R
2507 case EVENT_FT_RESPONSE:
2508 wpa_supplicant_event_ft_response(wpa_s, data);
2509 break;
2510#endif /* CONFIG_IEEE80211R */
2511#ifdef CONFIG_IBSS_RSN
2512 case EVENT_IBSS_RSN_START:
2513 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2514 break;
2515#endif /* CONFIG_IBSS_RSN */
2516 case EVENT_ASSOC_REJECT:
2517 if (data->assoc_reject.bssid)
2518 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2519 "bssid=" MACSTR " status_code=%u",
2520 MAC2STR(data->assoc_reject.bssid),
2521 data->assoc_reject.status_code);
2522 else
2523 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2524 "status_code=%u",
2525 data->assoc_reject.status_code);
2526 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2527 sme_event_assoc_reject(wpa_s, data);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002528#ifdef ANDROID_P2P
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002529#ifdef CONFIG_P2P
2530 else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002531 if(!wpa_s->current_ssid) {
2532 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2533 break;
2534 }
2535 /* If assoc reject is reported by the driver, then avoid
2536 * waiting for the authentication timeout. Cancel the
2537 * authentication timeout and retry the assoc.
2538 */
2539 if(wpa_s->current_ssid->assoc_retry++ < 5) {
2540 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2541 wpa_s->current_ssid->assoc_retry);
2542 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002543
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002544 /* Clear the states */
2545 wpa_sm_notify_disassoc(wpa_s->wpa);
2546 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2547
2548 wpa_s->reassociate = 1;
2549 wpa_supplicant_req_scan(wpa_s, 1, 0);
2550 } else {
2551 /* If we ASSOC_REJECT's hits threshold, disable the
2552 * network
2553 */
2554 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2555 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002556 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002557 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002558 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002559 }
2560 }
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002561#endif
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002562#endif /* ANDROID_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002563 break;
2564 case EVENT_AUTH_TIMED_OUT:
2565 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2566 sme_event_auth_timed_out(wpa_s, data);
2567 break;
2568 case EVENT_ASSOC_TIMED_OUT:
2569 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2570 sme_event_assoc_timed_out(wpa_s, data);
2571 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002572 case EVENT_TX_STATUS:
2573 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2574 " type=%d stype=%d",
2575 MAC2STR(data->tx_status.dst),
2576 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002577#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002578 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002579#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002580 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2581 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002582 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002583 wpa_s, data->tx_status.dst,
2584 data->tx_status.data,
2585 data->tx_status.data_len,
2586 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002587 OFFCHANNEL_SEND_ACTION_SUCCESS :
2588 OFFCHANNEL_SEND_ACTION_NO_ACK);
2589#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002590 break;
2591 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002592#endif /* CONFIG_AP */
2593#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002594 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2595 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2596 /*
2597 * Catch TX status events for Action frames we sent via group
2598 * interface in GO mode.
2599 */
2600 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2601 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2602 os_memcmp(wpa_s->parent->pending_action_dst,
2603 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002604 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002605 wpa_s->parent, data->tx_status.dst,
2606 data->tx_status.data,
2607 data->tx_status.data_len,
2608 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002609 OFFCHANNEL_SEND_ACTION_SUCCESS :
2610 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002611 break;
2612 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002613#endif /* CONFIG_OFFCHANNEL */
2614#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002615 switch (data->tx_status.type) {
2616 case WLAN_FC_TYPE_MGMT:
2617 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2618 data->tx_status.data_len,
2619 data->tx_status.stype,
2620 data->tx_status.ack);
2621 break;
2622 case WLAN_FC_TYPE_DATA:
2623 ap_tx_status(wpa_s, data->tx_status.dst,
2624 data->tx_status.data,
2625 data->tx_status.data_len,
2626 data->tx_status.ack);
2627 break;
2628 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002629#endif /* CONFIG_AP */
2630 break;
2631#ifdef CONFIG_AP
2632 case EVENT_EAPOL_TX_STATUS:
2633 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2634 data->eapol_tx_status.data,
2635 data->eapol_tx_status.data_len,
2636 data->eapol_tx_status.ack);
2637 break;
2638 case EVENT_DRIVER_CLIENT_POLL_OK:
2639 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002640 break;
2641 case EVENT_RX_FROM_UNKNOWN:
2642 if (wpa_s->ap_iface == NULL)
2643 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002644 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2645 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002646 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002647 case EVENT_CH_SWITCH:
2648 if (!data)
2649 break;
2650 if (!wpa_s->ap_iface) {
2651 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2652 "event in non-AP mode");
2653 break;
2654 }
2655
2656#ifdef CONFIG_AP
2657 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2658 data->ch_switch.ht_enabled,
2659 data->ch_switch.ch_offset);
2660#endif /* CONFIG_AP */
2661 break;
2662 case EVENT_RX_MGMT: {
2663 u16 fc, stype;
2664 const struct ieee80211_mgmt *mgmt;
2665
2666 mgmt = (const struct ieee80211_mgmt *)
2667 data->rx_mgmt.frame;
2668 fc = le_to_host16(mgmt->frame_control);
2669 stype = WLAN_FC_GET_STYPE(fc);
2670
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002671 if (wpa_s->ap_iface == NULL) {
2672#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002673 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2674 data->rx_mgmt.frame_len > 24) {
2675 const u8 *src = mgmt->sa;
2676 const u8 *ie = mgmt->u.probe_req.variable;
2677 size_t ie_len = data->rx_mgmt.frame_len -
2678 (mgmt->u.probe_req.variable -
2679 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002680 wpas_p2p_probe_req_rx(
2681 wpa_s, src, mgmt->da,
2682 mgmt->bssid, ie, ie_len,
2683 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002684 break;
2685 }
2686#endif /* CONFIG_P2P */
2687 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2688 "management frame in non-AP mode");
2689 break;
2690 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002691
2692 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2693 data->rx_mgmt.frame_len > 24) {
2694 const u8 *ie = mgmt->u.probe_req.variable;
2695 size_t ie_len = data->rx_mgmt.frame_len -
2696 (mgmt->u.probe_req.variable -
2697 data->rx_mgmt.frame);
2698
2699 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2700 mgmt->bssid, ie, ie_len,
2701 data->rx_mgmt.ssi_signal);
2702 }
2703
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2705 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002706 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002707#endif /* CONFIG_AP */
2708 case EVENT_RX_ACTION:
2709 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2710 " Category=%u DataLen=%d freq=%d MHz",
2711 MAC2STR(data->rx_action.sa),
2712 data->rx_action.category, (int) data->rx_action.len,
2713 data->rx_action.freq);
2714#ifdef CONFIG_IEEE80211R
2715 if (data->rx_action.category == WLAN_ACTION_FT) {
2716 ft_rx_action(wpa_s, data->rx_action.data,
2717 data->rx_action.len);
2718 break;
2719 }
2720#endif /* CONFIG_IEEE80211R */
2721#ifdef CONFIG_IEEE80211W
2722#ifdef CONFIG_SME
2723 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2724 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2725 data->rx_action.data,
2726 data->rx_action.len);
2727 break;
2728 }
2729#endif /* CONFIG_SME */
2730#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002731#ifdef CONFIG_IEEE80211V
2732 if (data->rx_action.category == WLAN_ACTION_WNM) {
2733 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2734 break;
2735 }
2736#endif /* CONFIG_IEEE80211V */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002737#ifdef CONFIG_GAS
2738 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2739 gas_query_rx(wpa_s->gas, data->rx_action.da,
2740 data->rx_action.sa, data->rx_action.bssid,
2741 data->rx_action.data, data->rx_action.len,
2742 data->rx_action.freq) == 0)
2743 break;
2744#endif /* CONFIG_GAS */
2745 if (data->rx_action.category == WLAN_ACTION_WNM) {
2746 wnm_action_rx(wpa_s, &data->rx_action);
2747 break;
2748 }
2749#ifdef CONFIG_TDLS
2750 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2751 data->rx_action.len >= 4 &&
2752 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2753 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2754 "Response from " MACSTR,
2755 MAC2STR(data->rx_action.sa));
2756 break;
2757 }
2758#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002759#ifdef CONFIG_P2P
2760 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2761 data->rx_action.sa,
2762 data->rx_action.bssid,
2763 data->rx_action.category,
2764 data->rx_action.data,
2765 data->rx_action.len, data->rx_action.freq);
2766#endif /* CONFIG_P2P */
2767 break;
2768 case EVENT_RX_PROBE_REQ:
2769 if (data->rx_probe_req.sa == NULL ||
2770 data->rx_probe_req.ie == NULL)
2771 break;
2772#ifdef CONFIG_AP
2773 if (wpa_s->ap_iface) {
2774 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2775 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002776 data->rx_probe_req.da,
2777 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002778 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002779 data->rx_probe_req.ie_len,
2780 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002781 break;
2782 }
2783#endif /* CONFIG_AP */
2784#ifdef CONFIG_P2P
2785 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002786 data->rx_probe_req.da,
2787 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002788 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002789 data->rx_probe_req.ie_len,
2790 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002791#endif /* CONFIG_P2P */
2792 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002793 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002794#ifdef CONFIG_OFFCHANNEL
2795 offchannel_remain_on_channel_cb(
2796 wpa_s, data->remain_on_channel.freq,
2797 data->remain_on_channel.duration);
2798#endif /* CONFIG_OFFCHANNEL */
2799#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002800 wpas_p2p_remain_on_channel_cb(
2801 wpa_s, data->remain_on_channel.freq,
2802 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002803#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002804 break;
2805 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002806#ifdef CONFIG_OFFCHANNEL
2807 offchannel_cancel_remain_on_channel_cb(
2808 wpa_s, data->remain_on_channel.freq);
2809#endif /* CONFIG_OFFCHANNEL */
2810#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002811 wpas_p2p_cancel_remain_on_channel_cb(
2812 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002813#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002814 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002815#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002816 case EVENT_P2P_DEV_FOUND: {
2817 struct p2p_peer_info peer_info;
2818
2819 os_memset(&peer_info, 0, sizeof(peer_info));
2820 if (data->p2p_dev_found.dev_addr)
2821 os_memcpy(peer_info.p2p_device_addr,
2822 data->p2p_dev_found.dev_addr, ETH_ALEN);
2823 if (data->p2p_dev_found.pri_dev_type)
2824 os_memcpy(peer_info.pri_dev_type,
2825 data->p2p_dev_found.pri_dev_type,
2826 sizeof(peer_info.pri_dev_type));
2827 if (data->p2p_dev_found.dev_name)
2828 os_strlcpy(peer_info.device_name,
2829 data->p2p_dev_found.dev_name,
2830 sizeof(peer_info.device_name));
2831 peer_info.config_methods = data->p2p_dev_found.config_methods;
2832 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2833 peer_info.group_capab = data->p2p_dev_found.group_capab;
2834
2835 /*
2836 * FIX: new_device=1 is not necessarily correct. We should
2837 * maintain a P2P peer database in wpa_supplicant and update
2838 * this information based on whether the peer is truly new.
2839 */
2840 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2841 break;
2842 }
2843 case EVENT_P2P_GO_NEG_REQ_RX:
2844 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2845 data->p2p_go_neg_req_rx.dev_passwd_id);
2846 break;
2847 case EVENT_P2P_GO_NEG_COMPLETED:
2848 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2849 break;
2850 case EVENT_P2P_PROV_DISC_REQUEST:
2851 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2852 data->p2p_prov_disc_req.config_methods,
2853 data->p2p_prov_disc_req.dev_addr,
2854 data->p2p_prov_disc_req.pri_dev_type,
2855 data->p2p_prov_disc_req.dev_name,
2856 data->p2p_prov_disc_req.supp_config_methods,
2857 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002858 data->p2p_prov_disc_req.group_capab,
2859 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002860 break;
2861 case EVENT_P2P_PROV_DISC_RESPONSE:
2862 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2863 data->p2p_prov_disc_resp.config_methods);
2864 break;
2865 case EVENT_P2P_SD_REQUEST:
2866 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2867 data->p2p_sd_req.sa,
2868 data->p2p_sd_req.dialog_token,
2869 data->p2p_sd_req.update_indic,
2870 data->p2p_sd_req.tlvs,
2871 data->p2p_sd_req.tlvs_len);
2872 break;
2873 case EVENT_P2P_SD_RESPONSE:
2874 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2875 data->p2p_sd_resp.update_indic,
2876 data->p2p_sd_resp.tlvs,
2877 data->p2p_sd_resp.tlvs_len);
2878 break;
2879#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002880 case EVENT_EAPOL_RX:
2881 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2882 data->eapol_rx.data,
2883 data->eapol_rx.data_len);
2884 break;
2885 case EVENT_SIGNAL_CHANGE:
2886 bgscan_notify_signal_change(
2887 wpa_s, data->signal_change.above_threshold,
2888 data->signal_change.current_signal,
2889 data->signal_change.current_noise,
2890 data->signal_change.current_txrate);
2891 break;
2892 case EVENT_INTERFACE_ENABLED:
2893 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2894 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002895 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002896#ifdef CONFIG_AP
2897 if (!wpa_s->ap_iface) {
2898 wpa_supplicant_set_state(wpa_s,
2899 WPA_DISCONNECTED);
2900 wpa_supplicant_req_scan(wpa_s, 0, 0);
2901 } else
2902 wpa_supplicant_set_state(wpa_s,
2903 WPA_COMPLETED);
2904#else /* CONFIG_AP */
2905 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2906 wpa_supplicant_req_scan(wpa_s, 0, 0);
2907#endif /* CONFIG_AP */
2908 }
2909 break;
2910 case EVENT_INTERFACE_DISABLED:
2911 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2912 wpa_supplicant_mark_disassoc(wpa_s);
2913 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2914 break;
2915 case EVENT_CHANNEL_LIST_CHANGED:
2916 if (wpa_s->drv_priv == NULL)
2917 break; /* Ignore event during drv initialization */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002918
2919 free_hw_features(wpa_s);
2920 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2921 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2922
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002923#ifdef CONFIG_P2P
2924 wpas_p2p_update_channel_list(wpa_s);
2925#endif /* CONFIG_P2P */
2926 break;
2927 case EVENT_INTERFACE_UNAVAILABLE:
2928#ifdef CONFIG_P2P
2929 wpas_p2p_interface_unavailable(wpa_s);
2930#endif /* CONFIG_P2P */
2931 break;
2932 case EVENT_BEST_CHANNEL:
2933 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2934 "(%d %d %d)",
2935 data->best_chan.freq_24, data->best_chan.freq_5,
2936 data->best_chan.freq_overall);
2937 wpa_s->best_24_freq = data->best_chan.freq_24;
2938 wpa_s->best_5_freq = data->best_chan.freq_5;
2939 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2940#ifdef CONFIG_P2P
2941 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2942 data->best_chan.freq_5,
2943 data->best_chan.freq_overall);
2944#endif /* CONFIG_P2P */
2945 break;
2946 case EVENT_UNPROT_DEAUTH:
2947 wpa_supplicant_event_unprot_deauth(wpa_s,
2948 &data->unprot_deauth);
2949 break;
2950 case EVENT_UNPROT_DISASSOC:
2951 wpa_supplicant_event_unprot_disassoc(wpa_s,
2952 &data->unprot_disassoc);
2953 break;
2954 case EVENT_STATION_LOW_ACK:
2955#ifdef CONFIG_AP
2956 if (wpa_s->ap_iface && data)
2957 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2958 data->low_ack.addr);
2959#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002960#ifdef CONFIG_TDLS
2961 if (data)
2962 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2963#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002964 break;
2965 case EVENT_IBSS_PEER_LOST:
2966#ifdef CONFIG_IBSS_RSN
2967 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2968#endif /* CONFIG_IBSS_RSN */
2969 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002970 case EVENT_DRIVER_GTK_REKEY:
2971 if (os_memcmp(data->driver_gtk_rekey.bssid,
2972 wpa_s->bssid, ETH_ALEN))
2973 break;
2974 if (!wpa_s->wpa)
2975 break;
2976 wpa_sm_update_replay_ctr(wpa_s->wpa,
2977 data->driver_gtk_rekey.replay_ctr);
2978 break;
2979 case EVENT_SCHED_SCAN_STOPPED:
2980 wpa_s->sched_scanning = 0;
2981 wpa_supplicant_notify_scanning(wpa_s, 0);
2982
2983 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2984 break;
2985
2986 /*
2987 * If we timed out, start a new sched scan to continue
2988 * searching for more SSIDs.
2989 */
2990 if (wpa_s->sched_scan_timed_out)
2991 wpa_supplicant_req_sched_scan(wpa_s);
2992 break;
2993 case EVENT_WPS_BUTTON_PUSHED:
2994#ifdef CONFIG_WPS
2995 wpas_wps_start_pbc(wpa_s, NULL, 0);
2996#endif /* CONFIG_WPS */
2997 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002998 default:
2999 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3000 break;
3001 }
3002}