blob: 6be345d80ae4ddd21426a49c35a051044512aa0e [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;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001065#ifndef CONFIG_NO_RANDOM_POOL
1066 size_t i, num;
1067#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001068
1069#ifdef CONFIG_AP
1070 if (wpa_s->ap_iface)
1071 ap = 1;
1072#endif /* CONFIG_AP */
1073
1074 wpa_supplicant_notify_scanning(wpa_s, 0);
1075
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001076#ifdef CONFIG_P2P
1077 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001078 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001079 wpa_s->p2p_cb_on_scan_complete = 0;
1080 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1081 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1082 "stopped scan processing");
1083 return -1;
1084 }
1085 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001086 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001087#endif /* CONFIG_P2P */
1088
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001089 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1090 data ? &data->scan_info :
1091 NULL, 1);
1092 if (scan_res == NULL) {
1093 if (wpa_s->conf->ap_scan == 2 || ap)
1094 return -1;
1095 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1096 "scanning again");
1097 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1098 return -1;
1099 }
1100
1101#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102 num = scan_res->num;
1103 if (num > 10)
1104 num = 10;
1105 for (i = 0; i < num; i++) {
1106 u8 buf[5];
1107 struct wpa_scan_res *res = scan_res->res[i];
1108 buf[0] = res->bssid[5];
1109 buf[1] = res->qual & 0xff;
1110 buf[2] = res->noise & 0xff;
1111 buf[3] = res->level & 0xff;
1112 buf[4] = res->tsf & 0xff;
1113 random_add_randomness(buf, sizeof(buf));
1114 }
1115#endif /* CONFIG_NO_RANDOM_POOL */
1116
1117 if (wpa_s->scan_res_handler) {
1118 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1119 struct wpa_scan_results *scan_res);
1120
1121 scan_res_handler = wpa_s->scan_res_handler;
1122 wpa_s->scan_res_handler = NULL;
1123 scan_res_handler(wpa_s, scan_res);
1124
1125 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001126 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127 }
1128
1129 if (ap) {
1130 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1131#ifdef CONFIG_AP
1132 if (wpa_s->ap_iface->scan_cb)
1133 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1134#endif /* CONFIG_AP */
1135 wpa_scan_results_free(scan_res);
1136 return 0;
1137 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001138#ifdef ANDROID_P2P
1139 if(!suppress_event)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001140 {
1141 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1142 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1143 wpas_notify_scan_results(wpa_s);
1144 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001145#else
1146 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1147 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1148 wpas_notify_scan_results(wpa_s);
1149#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150
1151 wpas_notify_scan_done(wpa_s, 1);
1152
Dmitry Shmidt04949592012-07-19 12:16:46 -07001153 if (sme_proc_obss_scan(wpa_s) > 0) {
1154 wpa_scan_results_free(scan_res);
1155 return 0;
1156 }
1157
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1159 wpa_scan_results_free(scan_res);
1160 return 0;
1161 }
1162
Dmitry Shmidt04949592012-07-19 12:16:46 -07001163 if (autoscan_notify_scan(wpa_s, scan_res)) {
1164 wpa_scan_results_free(scan_res);
1165 return 0;
1166 }
1167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001168 if (wpa_s->disconnected) {
1169 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1170 wpa_scan_results_free(scan_res);
1171 return 0;
1172 }
1173
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001174 if (!wpas_driver_bss_selection(wpa_s) &&
1175 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001176 wpa_scan_results_free(scan_res);
1177 return 0;
1178 }
1179
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001180 wpas_wps_update_ap_info(wpa_s, scan_res);
1181
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001182 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1183
1184 if (selected) {
1185 int skip;
1186 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1187 scan_res);
1188 wpa_scan_results_free(scan_res);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001189 if (skip) {
1190 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001192 }
1193
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001194 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001195 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001196 return -1;
1197 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03001198 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 } else {
1200 wpa_scan_results_free(scan_res);
1201 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1202 ssid = wpa_supplicant_pick_new_network(wpa_s);
1203 if (ssid) {
1204 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1205 wpa_supplicant_associate(wpa_s, NULL, ssid);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001206 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207 } else {
1208 int timeout_sec = wpa_s->scan_interval;
1209 int timeout_usec = 0;
1210#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001211 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1212 return 0;
1213
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001214 if (wpa_s->p2p_in_provisioning) {
1215 /*
1216 * Use shorter wait during P2P Provisioning
1217 * state to speed up group formation.
1218 */
1219 timeout_sec = 0;
1220 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001221 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1222 timeout_usec);
1223 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001224 }
1225#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001226#ifdef CONFIG_INTERWORKING
1227 if (wpa_s->conf->auto_interworking &&
1228 wpa_s->conf->interworking &&
1229 wpa_s->conf->cred) {
1230 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1231 "start ANQP fetch since no matching "
1232 "networks found");
1233 wpa_s->network_select = 1;
1234 wpa_s->auto_network_select = 1;
1235 interworking_start_fetch_anqp(wpa_s);
1236 return 0;
1237 }
1238#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001239 if (wpa_supplicant_req_sched_scan(wpa_s))
1240 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1241 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001242 }
1243 }
1244 return 0;
1245}
1246
1247
1248static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1249 union wpa_event_data *data)
1250{
1251 const char *rn, *rn2;
1252 struct wpa_supplicant *ifs;
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001253#ifdef ANDROID_P2P
1254 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) {
1255#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001256 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001257#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001258 /*
1259 * If no scan results could be fetched, then no need to
1260 * notify those interfaces that did not actually request
1261 * this scan.
1262 */
1263 return;
1264 }
1265
1266 /*
1267 * Check other interfaces to see if they have the same radio-name. If
1268 * so, they get updated with this same scan info.
1269 */
1270 if (!wpa_s->driver->get_radio_name)
1271 return;
1272
1273 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1274 if (rn == NULL || rn[0] == '\0')
1275 return;
1276
1277 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1278 "sharing same radio (%s) in event_scan_results", rn);
1279
1280 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1281 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1282 continue;
1283
1284 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1285 if (rn2 && os_strcmp(rn, rn2) == 0) {
1286 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1287 "sibling", ifs->ifname);
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001288#ifdef ANDROID_P2P
1289 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) {
1290 /* Do not update the scan results from STA interface to p2p interfaces */
1291 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from "
1292 "sibling %s", ifs->ifname, wpa_s->ifname);
1293 continue;
1294 }
1295 else {
1296 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1297 * no time. Avoid announcing it to application as it may not
1298 * be that useful (since results will be that of only 1,6,11).
1299 * over to any other interface as it
1300 */
1301 if(p2p_search_in_progress(wpa_s->global->p2p))
1302 _wpa_supplicant_event_scan_results(ifs, data, 1);
1303 else
1304 _wpa_supplicant_event_scan_results(ifs, data, 0);
1305 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001306#else
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001307 _wpa_supplicant_event_scan_results(ifs, data);
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001308#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001309 }
1310 }
1311}
1312
1313#endif /* CONFIG_NO_SCAN_PROCESSING */
1314
1315
Dmitry Shmidt04949592012-07-19 12:16:46 -07001316#ifdef CONFIG_WNM
1317
1318static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1319{
1320 struct wpa_supplicant *wpa_s = eloop_ctx;
1321
1322 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1323 return;
1324
1325 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1326 MAC2STR(wpa_s->bssid));
1327 /* TODO: could skip this if normal data traffic has been sent */
1328 /* TODO: Consider using some more appropriate data frame for this */
1329 if (wpa_s->l2)
1330 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1331
1332#ifdef CONFIG_SME
1333 if (wpa_s->sme.bss_max_idle_period) {
1334 unsigned int msec;
1335 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1336 if (msec > 100)
1337 msec -= 100;
1338 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1339 wnm_bss_keep_alive, wpa_s, NULL);
1340 }
1341#endif /* CONFIG_SME */
1342}
1343
1344
1345static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1346 const u8 *ies, size_t ies_len)
1347{
1348 struct ieee802_11_elems elems;
1349
1350 if (ies == NULL)
1351 return;
1352
1353 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1354 return;
1355
1356#ifdef CONFIG_SME
1357 if (elems.bss_max_idle_period) {
1358 unsigned int msec;
1359 wpa_s->sme.bss_max_idle_period =
1360 WPA_GET_LE16(elems.bss_max_idle_period);
1361 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1362 "TU)%s", wpa_s->sme.bss_max_idle_period,
1363 (elems.bss_max_idle_period[2] & 0x01) ?
1364 " (protected keep-live required)" : "");
1365 if (wpa_s->sme.bss_max_idle_period == 0)
1366 wpa_s->sme.bss_max_idle_period = 1;
1367 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1368 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1369 /* msec times 1000 */
1370 msec = wpa_s->sme.bss_max_idle_period * 1024;
1371 if (msec > 100)
1372 msec -= 100;
1373 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1374 wnm_bss_keep_alive, wpa_s,
1375 NULL);
1376 }
1377 }
1378#endif /* CONFIG_SME */
1379}
1380
1381#endif /* CONFIG_WNM */
1382
1383
1384void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1385{
1386#ifdef CONFIG_WNM
1387 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1388#endif /* CONFIG_WNM */
1389}
1390
1391
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001392static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1393 union wpa_event_data *data)
1394{
1395 int l, len, found = 0, wpa_found, rsn_found;
1396 const u8 *p;
1397
1398 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1399 if (data->assoc_info.req_ies)
1400 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1401 data->assoc_info.req_ies_len);
1402 if (data->assoc_info.resp_ies) {
1403 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1404 data->assoc_info.resp_ies_len);
1405#ifdef CONFIG_TDLS
1406 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1407 data->assoc_info.resp_ies_len);
1408#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001409#ifdef CONFIG_WNM
1410 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1411 data->assoc_info.resp_ies_len);
1412#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001413 }
1414 if (data->assoc_info.beacon_ies)
1415 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1416 data->assoc_info.beacon_ies,
1417 data->assoc_info.beacon_ies_len);
1418 if (data->assoc_info.freq)
1419 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1420 data->assoc_info.freq);
1421
1422 p = data->assoc_info.req_ies;
1423 l = data->assoc_info.req_ies_len;
1424
1425 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1426 while (p && l >= 2) {
1427 len = p[1] + 2;
1428 if (len > l) {
1429 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1430 p, l);
1431 break;
1432 }
1433 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1434 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1435 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1436 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1437 break;
1438 found = 1;
1439 wpa_find_assoc_pmkid(wpa_s);
1440 break;
1441 }
1442 l -= len;
1443 p += len;
1444 }
1445 if (!found && data->assoc_info.req_ies)
1446 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1447
1448#ifdef CONFIG_IEEE80211R
1449#ifdef CONFIG_SME
1450 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1451 u8 bssid[ETH_ALEN];
1452 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1453 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1454 data->assoc_info.resp_ies,
1455 data->assoc_info.resp_ies_len,
1456 bssid) < 0) {
1457 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1458 "Reassociation Response failed");
1459 wpa_supplicant_deauthenticate(
1460 wpa_s, WLAN_REASON_INVALID_IE);
1461 return -1;
1462 }
1463 }
1464
1465 p = data->assoc_info.resp_ies;
1466 l = data->assoc_info.resp_ies_len;
1467
1468#ifdef CONFIG_WPS_STRICT
1469 if (p && wpa_s->current_ssid &&
1470 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1471 struct wpabuf *wps;
1472 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1473 if (wps == NULL) {
1474 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1475 "include WPS IE in (Re)Association Response");
1476 return -1;
1477 }
1478
1479 if (wps_validate_assoc_resp(wps) < 0) {
1480 wpabuf_free(wps);
1481 wpa_supplicant_deauthenticate(
1482 wpa_s, WLAN_REASON_INVALID_IE);
1483 return -1;
1484 }
1485 wpabuf_free(wps);
1486 }
1487#endif /* CONFIG_WPS_STRICT */
1488
1489 /* Go through the IEs and make a copy of the MDIE, if present. */
1490 while (p && l >= 2) {
1491 len = p[1] + 2;
1492 if (len > l) {
1493 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1494 p, l);
1495 break;
1496 }
1497 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1498 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1499 wpa_s->sme.ft_used = 1;
1500 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1501 MOBILITY_DOMAIN_ID_LEN);
1502 break;
1503 }
1504 l -= len;
1505 p += len;
1506 }
1507#endif /* CONFIG_SME */
1508
1509 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1510 data->assoc_info.resp_ies_len);
1511#endif /* CONFIG_IEEE80211R */
1512
1513 /* WPA/RSN IE from Beacon/ProbeResp */
1514 p = data->assoc_info.beacon_ies;
1515 l = data->assoc_info.beacon_ies_len;
1516
1517 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1518 */
1519 wpa_found = rsn_found = 0;
1520 while (p && l >= 2) {
1521 len = p[1] + 2;
1522 if (len > l) {
1523 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1524 p, l);
1525 break;
1526 }
1527 if (!wpa_found &&
1528 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1529 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1530 wpa_found = 1;
1531 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1532 }
1533
1534 if (!rsn_found &&
1535 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1536 rsn_found = 1;
1537 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1538 }
1539
1540 l -= len;
1541 p += len;
1542 }
1543
1544 if (!wpa_found && data->assoc_info.beacon_ies)
1545 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1546 if (!rsn_found && data->assoc_info.beacon_ies)
1547 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1548 if (wpa_found || rsn_found)
1549 wpa_s->ap_ies_from_associnfo = 1;
1550
Jouni Malinen87fd2792011-05-16 18:35:42 +03001551 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1552 wpa_s->assoc_freq != data->assoc_info.freq) {
1553 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1554 "%u to %u MHz",
1555 wpa_s->assoc_freq, data->assoc_info.freq);
1556 wpa_supplicant_update_scan_results(wpa_s);
1557 }
1558
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001559 wpa_s->assoc_freq = data->assoc_info.freq;
1560
1561 return 0;
1562}
1563
1564
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001565static struct wpa_bss * wpa_supplicant_get_new_bss(
1566 struct wpa_supplicant *wpa_s, const u8 *bssid)
1567{
1568 struct wpa_bss *bss = NULL;
1569 struct wpa_ssid *ssid = wpa_s->current_ssid;
1570
1571 if (ssid->ssid_len > 0)
1572 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1573 if (!bss)
1574 bss = wpa_bss_get_bssid(wpa_s, bssid);
1575
1576 return bss;
1577}
1578
1579
1580static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1581{
1582 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1583
1584 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1585 return -1;
1586
1587 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1588 return 0;
1589
1590 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1591 WPA_IE_VENDOR_TYPE);
1592 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1593
1594 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1595 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1596 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1597 bss_rsn ? 2 + bss_rsn[1] : 0))
1598 return -1;
1599
1600 return 0;
1601}
1602
1603
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001604static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1605 union wpa_event_data *data)
1606{
1607 u8 bssid[ETH_ALEN];
1608 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001609 struct wpa_driver_capa capa;
1610
1611#ifdef CONFIG_AP
1612 if (wpa_s->ap_iface) {
1613 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1614 data->assoc_info.addr,
1615 data->assoc_info.req_ies,
1616 data->assoc_info.req_ies_len,
1617 data->assoc_info.reassoc);
1618 return;
1619 }
1620#endif /* CONFIG_AP */
1621
1622 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1623 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1624 return;
1625
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001626 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1627 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1628 wpa_supplicant_disassociate(
1629 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1630 return;
1631 }
1632
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001633 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001634 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1636 MACSTR, MAC2STR(bssid));
1637 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001638 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1639 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001640 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001641
1642 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1643 wpa_clear_keys(wpa_s, bssid);
1644 }
1645 if (wpa_supplicant_select_config(wpa_s) < 0) {
1646 wpa_supplicant_disassociate(
1647 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1648 return;
1649 }
1650 if (wpa_s->current_ssid) {
1651 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001652
1653 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1654 if (!bss) {
1655 wpa_supplicant_update_scan_results(wpa_s);
1656
1657 /* Get the BSS from the new scan results */
1658 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1659 }
1660
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001661 if (bss)
1662 wpa_s->current_bss = bss;
1663 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001664
1665 if (wpa_s->conf->ap_scan == 1 &&
1666 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1667 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1668 wpa_msg(wpa_s, MSG_WARNING,
1669 "WPA/RSN IEs not updated");
1670 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001671 }
1672
1673#ifdef CONFIG_SME
1674 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1675 wpa_s->sme.prev_bssid_set = 1;
1676#endif /* CONFIG_SME */
1677
1678 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1679 if (wpa_s->current_ssid) {
1680 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1681 * initialized before association, but for other modes,
1682 * initialize PC/SC here, if the current configuration needs
1683 * smartcard or SIM/USIM. */
1684 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1685 }
1686 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1687 if (wpa_s->l2)
1688 l2_packet_notify_auth_start(wpa_s->l2);
1689
1690 /*
1691 * Set portEnabled first to FALSE in order to get EAP state machine out
1692 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1693 * state machine may transit to AUTHENTICATING state based on obsolete
1694 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1695 * AUTHENTICATED without ever giving chance to EAP state machine to
1696 * reset the state.
1697 */
1698 if (!ft_completed) {
1699 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1700 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1701 }
1702 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1703 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1704 /* 802.1X::portControl = Auto */
1705 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1706 wpa_s->eapol_received = 0;
1707 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1708 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1709 (wpa_s->current_ssid &&
1710 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1711 wpa_supplicant_cancel_auth_timeout(wpa_s);
1712 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1713 } else if (!ft_completed) {
1714 /* Timeout for receiving the first EAPOL packet */
1715 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1716 }
1717 wpa_supplicant_cancel_scan(wpa_s);
1718
1719 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1720 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1721 /*
1722 * We are done; the driver will take care of RSN 4-way
1723 * handshake.
1724 */
1725 wpa_supplicant_cancel_auth_timeout(wpa_s);
1726 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1727 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1728 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1729 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1730 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1731 /*
1732 * The driver will take care of RSN 4-way handshake, so we need
1733 * to allow EAPOL supplicant to complete its work without
1734 * waiting for WPA supplicant.
1735 */
1736 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1737 } else if (ft_completed) {
1738 /*
1739 * FT protocol completed - make sure EAPOL state machine ends
1740 * up in authenticated.
1741 */
1742 wpa_supplicant_cancel_auth_timeout(wpa_s);
1743 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1744 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1745 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1746 }
1747
1748 if (wpa_s->pending_eapol_rx) {
1749 struct os_time now, age;
1750 os_get_time(&now);
1751 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1752 if (age.sec == 0 && age.usec < 100000 &&
1753 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1754 0) {
1755 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1756 "frame that was received just before "
1757 "association notification");
1758 wpa_supplicant_rx_eapol(
1759 wpa_s, wpa_s->pending_eapol_rx_src,
1760 wpabuf_head(wpa_s->pending_eapol_rx),
1761 wpabuf_len(wpa_s->pending_eapol_rx));
1762 }
1763 wpabuf_free(wpa_s->pending_eapol_rx);
1764 wpa_s->pending_eapol_rx = NULL;
1765 }
1766
1767 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1768 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1769 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1770 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1771 /* Set static WEP keys again */
1772 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1773 }
1774
1775#ifdef CONFIG_IBSS_RSN
1776 if (wpa_s->current_ssid &&
1777 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1778 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1779 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1780 wpa_s->ibss_rsn == NULL) {
1781 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1782 if (!wpa_s->ibss_rsn) {
1783 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1784 wpa_supplicant_deauthenticate(
1785 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1786 return;
1787 }
1788
1789 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1790 }
1791#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001792
1793 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001794}
1795
1796
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001797static int disconnect_reason_recoverable(u16 reason_code)
1798{
1799 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1800 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1801 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1802}
1803
1804
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001806 u16 reason_code,
1807 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001808{
1809 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03001810
1811 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1812 /*
1813 * At least Host AP driver and a Prism3 card seemed to be
1814 * generating streams of disconnected events when configuring
1815 * IBSS for WPA-None. Ignore them for now.
1816 */
1817 return;
1818 }
1819
1820 bssid = wpa_s->bssid;
1821 if (is_zero_ether_addr(bssid))
1822 bssid = wpa_s->pending_bssid;
1823
1824 if (!is_zero_ether_addr(bssid) ||
1825 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1826 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1827 " reason=%d%s",
1828 MAC2STR(bssid), reason_code,
1829 locally_generated ? " locally_generated=1" : "");
1830 }
1831}
1832
1833
1834static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1835 u16 reason_code,
1836 int locally_generated)
1837{
1838 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001839 int authenticating;
1840 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001841 struct wpa_bss *fast_reconnect = NULL;
1842 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001843 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001844
1845 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1846 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1847
1848 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1849 /*
1850 * At least Host AP driver and a Prism3 card seemed to be
1851 * generating streams of disconnected events when configuring
1852 * IBSS for WPA-None. Ignore them for now.
1853 */
1854 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1855 "IBSS/WPA-None mode");
1856 return;
1857 }
1858
1859 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1860 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1861 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1862 "pre-shared key may be incorrect");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001863 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001864 }
1865 if (!wpa_s->auto_reconnect_disabled ||
1866 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001867 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1868 "reconnect (wps=%d wpa_state=%d)",
1869 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1870 wpa_s->wpa_state);
1871 if (wpa_s->wpa_state == WPA_COMPLETED &&
1872 wpa_s->current_ssid &&
1873 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001874 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001875 disconnect_reason_recoverable(reason_code)) {
1876 /*
1877 * It looks like the AP has dropped association with
1878 * us, but could allow us to get back in. Try to
1879 * reconnect to the same BSS without full scan to save
1880 * time for some common cases.
1881 */
1882 fast_reconnect = wpa_s->current_bss;
1883 fast_reconnect_ssid = wpa_s->current_ssid;
1884 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001885#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07001886 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001887#else
1888 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1889#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001890 else
1891 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1892 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001893 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001894 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001895 "try to re-connect");
1896 wpa_s->reassociate = 0;
1897 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001898 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001899 }
1900 bssid = wpa_s->bssid;
1901 if (is_zero_ether_addr(bssid))
1902 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001903 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1904 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001905 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001906 if (locally_generated)
1907 wpa_s->disconnect_reason = -reason_code;
1908 else
1909 wpa_s->disconnect_reason = reason_code;
1910 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001911 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1912 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1913 wpa_s->keys_cleared = 0;
1914 wpa_clear_keys(wpa_s, wpa_s->bssid);
1915 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001916 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001917 wpa_supplicant_mark_disassoc(wpa_s);
1918
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001919 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001920 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001921 wpa_s->current_ssid = last_ssid;
1922 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001923
1924 if (fast_reconnect) {
1925#ifndef CONFIG_NO_SCAN_PROCESSING
1926 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1927 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1928 fast_reconnect_ssid) < 0) {
1929 /* Recover through full scan */
1930 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1931 }
1932#endif /* CONFIG_NO_SCAN_PROCESSING */
1933 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001934}
1935
1936
1937#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001938void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001939{
1940 struct wpa_supplicant *wpa_s = eloop_ctx;
1941
1942 if (!wpa_s->pending_mic_error_report)
1943 return;
1944
1945 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1946 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1947 wpa_s->pending_mic_error_report = 0;
1948}
1949#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1950
1951
1952static void
1953wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1954 union wpa_event_data *data)
1955{
1956 int pairwise;
1957 struct os_time t;
1958
1959 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1960 pairwise = (data && data->michael_mic_failure.unicast);
1961 os_get_time(&t);
1962 if ((wpa_s->last_michael_mic_error &&
1963 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1964 wpa_s->pending_mic_error_report) {
1965 if (wpa_s->pending_mic_error_report) {
1966 /*
1967 * Send the pending MIC error report immediately since
1968 * we are going to start countermeasures and AP better
1969 * do the same.
1970 */
1971 wpa_sm_key_request(wpa_s->wpa, 1,
1972 wpa_s->pending_mic_error_pairwise);
1973 }
1974
1975 /* Send the new MIC error report immediately since we are going
1976 * to start countermeasures and AP better do the same.
1977 */
1978 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1979
1980 /* initialize countermeasures */
1981 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001982
1983 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1984
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001985 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1986
1987 /*
1988 * Need to wait for completion of request frame. We do not get
1989 * any callback for the message completion, so just wait a
1990 * short while and hope for the best. */
1991 os_sleep(0, 10000);
1992
1993 wpa_drv_set_countermeasures(wpa_s, 1);
1994 wpa_supplicant_deauthenticate(wpa_s,
1995 WLAN_REASON_MICHAEL_MIC_FAILURE);
1996 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1997 wpa_s, NULL);
1998 eloop_register_timeout(60, 0,
1999 wpa_supplicant_stop_countermeasures,
2000 wpa_s, NULL);
2001 /* TODO: mark the AP rejected for 60 second. STA is
2002 * allowed to associate with another AP.. */
2003 } else {
2004#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2005 if (wpa_s->mic_errors_seen) {
2006 /*
2007 * Reduce the effectiveness of Michael MIC error
2008 * reports as a means for attacking against TKIP if
2009 * more than one MIC failure is noticed with the same
2010 * PTK. We delay the transmission of the reports by a
2011 * random time between 0 and 60 seconds in order to
2012 * force the attacker wait 60 seconds before getting
2013 * the information on whether a frame resulted in a MIC
2014 * failure.
2015 */
2016 u8 rval[4];
2017 int sec;
2018
2019 if (os_get_random(rval, sizeof(rval)) < 0)
2020 sec = os_random() % 60;
2021 else
2022 sec = WPA_GET_BE32(rval) % 60;
2023 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2024 "report %d seconds", sec);
2025 wpa_s->pending_mic_error_report = 1;
2026 wpa_s->pending_mic_error_pairwise = pairwise;
2027 eloop_cancel_timeout(
2028 wpa_supplicant_delayed_mic_error_report,
2029 wpa_s, NULL);
2030 eloop_register_timeout(
2031 sec, os_random() % 1000000,
2032 wpa_supplicant_delayed_mic_error_report,
2033 wpa_s, NULL);
2034 } else {
2035 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2036 }
2037#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2038 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2039#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2040 }
2041 wpa_s->last_michael_mic_error = t.sec;
2042 wpa_s->mic_errors_seen++;
2043}
2044
2045
2046#ifdef CONFIG_TERMINATE_ONLASTIF
2047static int any_interfaces(struct wpa_supplicant *head)
2048{
2049 struct wpa_supplicant *wpa_s;
2050
2051 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2052 if (!wpa_s->interface_removed)
2053 return 1;
2054 return 0;
2055}
2056#endif /* CONFIG_TERMINATE_ONLASTIF */
2057
2058
2059static void
2060wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2061 union wpa_event_data *data)
2062{
2063 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2064 return;
2065
2066 switch (data->interface_status.ievent) {
2067 case EVENT_INTERFACE_ADDED:
2068 if (!wpa_s->interface_removed)
2069 break;
2070 wpa_s->interface_removed = 0;
2071 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2072 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2073 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2074 "driver after interface was added");
2075 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002076 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077 break;
2078 case EVENT_INTERFACE_REMOVED:
2079 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2080 wpa_s->interface_removed = 1;
2081 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002082 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002083 l2_packet_deinit(wpa_s->l2);
2084 wpa_s->l2 = NULL;
2085#ifdef CONFIG_IBSS_RSN
2086 ibss_rsn_deinit(wpa_s->ibss_rsn);
2087 wpa_s->ibss_rsn = NULL;
2088#endif /* CONFIG_IBSS_RSN */
2089#ifdef CONFIG_TERMINATE_ONLASTIF
2090 /* check if last interface */
2091 if (!any_interfaces(wpa_s->global->ifaces))
2092 eloop_terminate();
2093#endif /* CONFIG_TERMINATE_ONLASTIF */
2094 break;
2095 }
2096}
2097
2098
2099#ifdef CONFIG_PEERKEY
2100static void
2101wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2102 union wpa_event_data *data)
2103{
2104 if (data == NULL)
2105 return;
2106 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2107}
2108#endif /* CONFIG_PEERKEY */
2109
2110
2111#ifdef CONFIG_TDLS
2112static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2113 union wpa_event_data *data)
2114{
2115 if (data == NULL)
2116 return;
2117 switch (data->tdls.oper) {
2118 case TDLS_REQUEST_SETUP:
2119 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2120 break;
2121 case TDLS_REQUEST_TEARDOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002122 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2123 data->tdls.reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002124 break;
2125 }
2126}
2127#endif /* CONFIG_TDLS */
2128
2129
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002130#ifdef CONFIG_IEEE80211V
2131static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2132 union wpa_event_data *data)
2133{
2134 if (data == NULL)
2135 return;
2136 switch (data->wnm.oper) {
2137 case WNM_OPER_SLEEP:
2138 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2139 "(action=%d, intval=%d)",
2140 data->wnm.sleep_action, data->wnm.sleep_intval);
2141 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2142 data->wnm.sleep_intval);
2143 break;
2144 }
2145}
2146#endif /* CONFIG_IEEE80211V */
2147
2148
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002149#ifdef CONFIG_IEEE80211R
2150static void
2151wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2152 union wpa_event_data *data)
2153{
2154 if (data == NULL)
2155 return;
2156
2157 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2158 data->ft_ies.ies_len,
2159 data->ft_ies.ft_action,
2160 data->ft_ies.target_ap,
2161 data->ft_ies.ric_ies,
2162 data->ft_ies.ric_ies_len) < 0) {
2163 /* TODO: prevent MLME/driver from trying to associate? */
2164 }
2165}
2166#endif /* CONFIG_IEEE80211R */
2167
2168
2169#ifdef CONFIG_IBSS_RSN
2170static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2171 union wpa_event_data *data)
2172{
2173 struct wpa_ssid *ssid;
2174 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2175 return;
2176 if (data == NULL)
2177 return;
2178 ssid = wpa_s->current_ssid;
2179 if (ssid == NULL)
2180 return;
2181 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2182 return;
2183
2184 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2185}
2186#endif /* CONFIG_IBSS_RSN */
2187
2188
2189#ifdef CONFIG_IEEE80211R
2190static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2191 size_t len)
2192{
2193 const u8 *sta_addr, *target_ap_addr;
2194 u16 status;
2195
2196 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2197 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2198 return; /* only SME case supported for now */
2199 if (len < 1 + 2 * ETH_ALEN + 2)
2200 return;
2201 if (data[0] != 2)
2202 return; /* Only FT Action Response is supported for now */
2203 sta_addr = data + 1;
2204 target_ap_addr = data + 1 + ETH_ALEN;
2205 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2206 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2207 MACSTR " TargetAP " MACSTR " status %u",
2208 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2209
2210 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2211 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2212 " in FT Action Response", MAC2STR(sta_addr));
2213 return;
2214 }
2215
2216 if (status) {
2217 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2218 "failure (status code %d)", status);
2219 /* TODO: report error to FT code(?) */
2220 return;
2221 }
2222
2223 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2224 len - (1 + 2 * ETH_ALEN + 2), 1,
2225 target_ap_addr, NULL, 0) < 0)
2226 return;
2227
2228#ifdef CONFIG_SME
2229 {
2230 struct wpa_bss *bss;
2231 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2232 if (bss)
2233 wpa_s->sme.freq = bss->freq;
2234 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2235 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2236 WLAN_AUTH_FT);
2237 }
2238#endif /* CONFIG_SME */
2239}
2240#endif /* CONFIG_IEEE80211R */
2241
2242
2243static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2244 struct unprot_deauth *e)
2245{
2246#ifdef CONFIG_IEEE80211W
2247 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2248 "dropped: " MACSTR " -> " MACSTR
2249 " (reason code %u)",
2250 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2251 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2252#endif /* CONFIG_IEEE80211W */
2253}
2254
2255
2256static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2257 struct unprot_disassoc *e)
2258{
2259#ifdef CONFIG_IEEE80211W
2260 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2261 "dropped: " MACSTR " -> " MACSTR
2262 " (reason code %u)",
2263 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2264 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2265#endif /* CONFIG_IEEE80211W */
2266}
2267
2268
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002269static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2270{
2271 u8 action, mode;
2272 const u8 *pos, *end;
2273
2274 if (rx->data == NULL || rx->len == 0)
2275 return;
2276
2277 pos = rx->data;
2278 end = pos + rx->len;
2279 action = *pos++;
2280
2281 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2282 action, MAC2STR(rx->sa));
2283 switch (action) {
2284 case WNM_BSS_TRANS_MGMT_REQ:
2285 if (pos + 5 > end)
2286 break;
2287 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2288 "Request: dialog_token=%u request_mode=0x%x "
2289 "disassoc_timer=%u validity_interval=%u",
2290 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2291 mode = pos[1];
2292 pos += 5;
2293 if (mode & 0x08)
2294 pos += 12; /* BSS Termination Duration */
2295 if (mode & 0x10) {
2296 char url[256];
2297 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2298 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2299 "Transition Management Request "
2300 "(URL)");
2301 break;
2302 }
2303 os_memcpy(url, pos + 1, pos[0]);
2304 url[pos[0]] = '\0';
2305 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2306 "Imminent - session_info_url=%s", url);
2307 }
2308 break;
2309 }
2310}
2311
2312
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002313void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2314 union wpa_event_data *data)
2315{
2316 struct wpa_supplicant *wpa_s = ctx;
2317 u16 reason_code = 0;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002318 int locally_generated = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002319
2320 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2321 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002322 event != EVENT_INTERFACE_STATUS &&
2323 event != EVENT_SCHED_SCAN_STOPPED) {
2324 wpa_dbg(wpa_s, MSG_DEBUG,
2325 "Ignore event %s (%d) while interface is disabled",
2326 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002327 return;
2328 }
2329
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002330#ifndef CONFIG_NO_STDOUT_DEBUG
2331{
2332 int level = MSG_DEBUG;
2333
Dmitry Shmidt04949592012-07-19 12:16:46 -07002334 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002335 const struct ieee80211_hdr *hdr;
2336 u16 fc;
2337 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2338 fc = le_to_host16(hdr->frame_control);
2339 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2340 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2341 level = MSG_EXCESSIVE;
2342 }
2343
2344 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2345 event_to_string(event), event);
2346}
2347#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002348
2349 switch (event) {
2350 case EVENT_AUTH:
2351 sme_event_auth(wpa_s, data);
2352 break;
2353 case EVENT_ASSOC:
2354 wpa_supplicant_event_assoc(wpa_s, data);
2355 break;
2356 case EVENT_DISASSOC:
2357 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2358 if (data) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002359 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2360 data->disassoc_info.reason_code,
2361 data->disassoc_info.locally_generated ?
2362 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002363 if (data->disassoc_info.addr)
2364 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2365 MAC2STR(data->disassoc_info.addr));
2366 }
2367#ifdef CONFIG_AP
2368 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2369 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2370 data->disassoc_info.addr);
2371 break;
2372 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002373 if (wpa_s->ap_iface) {
2374 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2375 "AP mode");
2376 break;
2377 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002378#endif /* CONFIG_AP */
2379 if (data) {
2380 reason_code = data->disassoc_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002381 locally_generated =
2382 data->disassoc_info.locally_generated;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002383 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2384 data->disassoc_info.ie,
2385 data->disassoc_info.ie_len);
2386#ifdef CONFIG_P2P
2387 wpas_p2p_disassoc_notif(
2388 wpa_s, data->disassoc_info.addr, reason_code,
2389 data->disassoc_info.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002390 data->disassoc_info.ie_len,
2391 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002392#endif /* CONFIG_P2P */
2393 }
2394 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2395 sme_event_disassoc(wpa_s, data);
2396 /* fall through */
2397 case EVENT_DEAUTH:
2398 if (event == EVENT_DEAUTH) {
2399 wpa_dbg(wpa_s, MSG_DEBUG,
2400 "Deauthentication notification");
2401 if (data) {
2402 reason_code = data->deauth_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002403 locally_generated =
2404 data->deauth_info.locally_generated;
2405 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2406 data->deauth_info.reason_code,
2407 data->deauth_info.locally_generated ?
2408 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002409 if (data->deauth_info.addr) {
2410 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2411 MACSTR,
2412 MAC2STR(data->deauth_info.
2413 addr));
2414 }
2415 wpa_hexdump(MSG_DEBUG,
2416 "Deauthentication frame IE(s)",
2417 data->deauth_info.ie,
2418 data->deauth_info.ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002419 }
2420 }
2421#ifdef CONFIG_AP
2422 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2423 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2424 data->deauth_info.addr);
2425 break;
2426 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002427 if (wpa_s->ap_iface) {
2428 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2429 "AP mode");
2430 break;
2431 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002432#endif /* CONFIG_AP */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002433 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2434 locally_generated);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002435 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2436 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2437 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2438 eapol_sm_failed(wpa_s->eapol)))
2439 wpas_auth_failed(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002440#ifdef CONFIG_P2P
2441 if (event == EVENT_DEAUTH && data) {
Jouni Malinen2b89da82012-08-31 22:04:41 +03002442 if (wpas_p2p_deauth_notif(wpa_s,
2443 data->deauth_info.addr,
2444 reason_code,
2445 data->deauth_info.ie,
2446 data->deauth_info.ie_len,
2447 locally_generated) > 0) {
2448 /*
2449 * The interface was removed, so cannot
2450 * continue processing any additional
2451 * operations after this.
2452 */
2453 break;
2454 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002455 }
2456#endif /* CONFIG_P2P */
Jouni Malinen2b89da82012-08-31 22:04:41 +03002457 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2458 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002459 break;
2460 case EVENT_MICHAEL_MIC_FAILURE:
2461 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2462 break;
2463#ifndef CONFIG_NO_SCAN_PROCESSING
2464 case EVENT_SCAN_RESULTS:
2465 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002466#ifdef CONFIG_P2P
2467 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2468 wpa_s->global->p2p != NULL &&
2469 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2470 wpa_s->wpa_state != WPA_ASSOCIATING) {
2471 wpa_s->p2p_cb_on_scan_complete = 0;
2472 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2473 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2474 "continued after scan result processing");
2475 }
2476 }
2477#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002478 break;
2479#endif /* CONFIG_NO_SCAN_PROCESSING */
2480 case EVENT_ASSOCINFO:
2481 wpa_supplicant_event_associnfo(wpa_s, data);
2482 break;
2483 case EVENT_INTERFACE_STATUS:
2484 wpa_supplicant_event_interface_status(wpa_s, data);
2485 break;
2486 case EVENT_PMKID_CANDIDATE:
2487 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2488 break;
2489#ifdef CONFIG_PEERKEY
2490 case EVENT_STKSTART:
2491 wpa_supplicant_event_stkstart(wpa_s, data);
2492 break;
2493#endif /* CONFIG_PEERKEY */
2494#ifdef CONFIG_TDLS
2495 case EVENT_TDLS:
2496 wpa_supplicant_event_tdls(wpa_s, data);
2497 break;
2498#endif /* CONFIG_TDLS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002499#ifdef CONFIG_IEEE80211V
2500 case EVENT_WNM:
2501 wpa_supplicant_event_wnm(wpa_s, data);
2502 break;
2503#endif /* CONFIG_IEEE80211V */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002504#ifdef CONFIG_IEEE80211R
2505 case EVENT_FT_RESPONSE:
2506 wpa_supplicant_event_ft_response(wpa_s, data);
2507 break;
2508#endif /* CONFIG_IEEE80211R */
2509#ifdef CONFIG_IBSS_RSN
2510 case EVENT_IBSS_RSN_START:
2511 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2512 break;
2513#endif /* CONFIG_IBSS_RSN */
2514 case EVENT_ASSOC_REJECT:
2515 if (data->assoc_reject.bssid)
2516 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2517 "bssid=" MACSTR " status_code=%u",
2518 MAC2STR(data->assoc_reject.bssid),
2519 data->assoc_reject.status_code);
2520 else
2521 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2522 "status_code=%u",
2523 data->assoc_reject.status_code);
2524 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2525 sme_event_assoc_reject(wpa_s, data);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002526#ifdef ANDROID_P2P
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002527#ifdef CONFIG_P2P
2528 else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002529 if(!wpa_s->current_ssid) {
2530 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2531 break;
2532 }
2533 /* If assoc reject is reported by the driver, then avoid
2534 * waiting for the authentication timeout. Cancel the
2535 * authentication timeout and retry the assoc.
2536 */
2537 if(wpa_s->current_ssid->assoc_retry++ < 5) {
2538 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2539 wpa_s->current_ssid->assoc_retry);
2540 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002541
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002542 /* Clear the states */
2543 wpa_sm_notify_disassoc(wpa_s->wpa);
2544 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2545
2546 wpa_s->reassociate = 1;
2547 wpa_supplicant_req_scan(wpa_s, 1, 0);
2548 } else {
2549 /* If we ASSOC_REJECT's hits threshold, disable the
2550 * network
2551 */
2552 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2553 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002554 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002555 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002556 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002557 }
2558 }
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002559#endif
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002560#endif /* ANDROID_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002561 break;
2562 case EVENT_AUTH_TIMED_OUT:
2563 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2564 sme_event_auth_timed_out(wpa_s, data);
2565 break;
2566 case EVENT_ASSOC_TIMED_OUT:
2567 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2568 sme_event_assoc_timed_out(wpa_s, data);
2569 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002570 case EVENT_TX_STATUS:
2571 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2572 " type=%d stype=%d",
2573 MAC2STR(data->tx_status.dst),
2574 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002575#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002577#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002578 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2579 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002580 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002581 wpa_s, data->tx_status.dst,
2582 data->tx_status.data,
2583 data->tx_status.data_len,
2584 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002585 OFFCHANNEL_SEND_ACTION_SUCCESS :
2586 OFFCHANNEL_SEND_ACTION_NO_ACK);
2587#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002588 break;
2589 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002590#endif /* CONFIG_AP */
2591#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002592 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2593 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2594 /*
2595 * Catch TX status events for Action frames we sent via group
2596 * interface in GO mode.
2597 */
2598 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2599 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2600 os_memcmp(wpa_s->parent->pending_action_dst,
2601 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002602 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002603 wpa_s->parent, data->tx_status.dst,
2604 data->tx_status.data,
2605 data->tx_status.data_len,
2606 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002607 OFFCHANNEL_SEND_ACTION_SUCCESS :
2608 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002609 break;
2610 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002611#endif /* CONFIG_OFFCHANNEL */
2612#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002613 switch (data->tx_status.type) {
2614 case WLAN_FC_TYPE_MGMT:
2615 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2616 data->tx_status.data_len,
2617 data->tx_status.stype,
2618 data->tx_status.ack);
2619 break;
2620 case WLAN_FC_TYPE_DATA:
2621 ap_tx_status(wpa_s, data->tx_status.dst,
2622 data->tx_status.data,
2623 data->tx_status.data_len,
2624 data->tx_status.ack);
2625 break;
2626 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002627#endif /* CONFIG_AP */
2628 break;
2629#ifdef CONFIG_AP
2630 case EVENT_EAPOL_TX_STATUS:
2631 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2632 data->eapol_tx_status.data,
2633 data->eapol_tx_status.data_len,
2634 data->eapol_tx_status.ack);
2635 break;
2636 case EVENT_DRIVER_CLIENT_POLL_OK:
2637 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002638 break;
2639 case EVENT_RX_FROM_UNKNOWN:
2640 if (wpa_s->ap_iface == NULL)
2641 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002642 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2643 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002644 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002645 case EVENT_CH_SWITCH:
2646 if (!data)
2647 break;
2648 if (!wpa_s->ap_iface) {
2649 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2650 "event in non-AP mode");
2651 break;
2652 }
2653
2654#ifdef CONFIG_AP
2655 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2656 data->ch_switch.ht_enabled,
2657 data->ch_switch.ch_offset);
2658#endif /* CONFIG_AP */
2659 break;
2660 case EVENT_RX_MGMT: {
2661 u16 fc, stype;
2662 const struct ieee80211_mgmt *mgmt;
2663
2664 mgmt = (const struct ieee80211_mgmt *)
2665 data->rx_mgmt.frame;
2666 fc = le_to_host16(mgmt->frame_control);
2667 stype = WLAN_FC_GET_STYPE(fc);
2668
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002669 if (wpa_s->ap_iface == NULL) {
2670#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002671 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2672 data->rx_mgmt.frame_len > 24) {
2673 const u8 *src = mgmt->sa;
2674 const u8 *ie = mgmt->u.probe_req.variable;
2675 size_t ie_len = data->rx_mgmt.frame_len -
2676 (mgmt->u.probe_req.variable -
2677 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002678 wpas_p2p_probe_req_rx(
2679 wpa_s, src, mgmt->da,
2680 mgmt->bssid, ie, ie_len,
2681 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002682 break;
2683 }
2684#endif /* CONFIG_P2P */
2685 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2686 "management frame in non-AP mode");
2687 break;
2688 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002689
2690 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2691 data->rx_mgmt.frame_len > 24) {
2692 const u8 *ie = mgmt->u.probe_req.variable;
2693 size_t ie_len = data->rx_mgmt.frame_len -
2694 (mgmt->u.probe_req.variable -
2695 data->rx_mgmt.frame);
2696
2697 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2698 mgmt->bssid, ie, ie_len,
2699 data->rx_mgmt.ssi_signal);
2700 }
2701
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002702 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2703 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002704 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002705#endif /* CONFIG_AP */
2706 case EVENT_RX_ACTION:
2707 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2708 " Category=%u DataLen=%d freq=%d MHz",
2709 MAC2STR(data->rx_action.sa),
2710 data->rx_action.category, (int) data->rx_action.len,
2711 data->rx_action.freq);
2712#ifdef CONFIG_IEEE80211R
2713 if (data->rx_action.category == WLAN_ACTION_FT) {
2714 ft_rx_action(wpa_s, data->rx_action.data,
2715 data->rx_action.len);
2716 break;
2717 }
2718#endif /* CONFIG_IEEE80211R */
2719#ifdef CONFIG_IEEE80211W
2720#ifdef CONFIG_SME
2721 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2722 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2723 data->rx_action.data,
2724 data->rx_action.len);
2725 break;
2726 }
2727#endif /* CONFIG_SME */
2728#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002729#ifdef CONFIG_IEEE80211V
2730 if (data->rx_action.category == WLAN_ACTION_WNM) {
2731 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2732 break;
2733 }
2734#endif /* CONFIG_IEEE80211V */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002735#ifdef CONFIG_GAS
2736 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2737 gas_query_rx(wpa_s->gas, data->rx_action.da,
2738 data->rx_action.sa, data->rx_action.bssid,
2739 data->rx_action.data, data->rx_action.len,
2740 data->rx_action.freq) == 0)
2741 break;
2742#endif /* CONFIG_GAS */
2743 if (data->rx_action.category == WLAN_ACTION_WNM) {
2744 wnm_action_rx(wpa_s, &data->rx_action);
2745 break;
2746 }
2747#ifdef CONFIG_TDLS
2748 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2749 data->rx_action.len >= 4 &&
2750 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2751 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2752 "Response from " MACSTR,
2753 MAC2STR(data->rx_action.sa));
2754 break;
2755 }
2756#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002757#ifdef CONFIG_P2P
2758 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2759 data->rx_action.sa,
2760 data->rx_action.bssid,
2761 data->rx_action.category,
2762 data->rx_action.data,
2763 data->rx_action.len, data->rx_action.freq);
2764#endif /* CONFIG_P2P */
2765 break;
2766 case EVENT_RX_PROBE_REQ:
2767 if (data->rx_probe_req.sa == NULL ||
2768 data->rx_probe_req.ie == NULL)
2769 break;
2770#ifdef CONFIG_AP
2771 if (wpa_s->ap_iface) {
2772 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2773 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002774 data->rx_probe_req.da,
2775 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002777 data->rx_probe_req.ie_len,
2778 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002779 break;
2780 }
2781#endif /* CONFIG_AP */
2782#ifdef CONFIG_P2P
2783 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002784 data->rx_probe_req.da,
2785 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002786 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002787 data->rx_probe_req.ie_len,
2788 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002789#endif /* CONFIG_P2P */
2790 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002791 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002792#ifdef CONFIG_OFFCHANNEL
2793 offchannel_remain_on_channel_cb(
2794 wpa_s, data->remain_on_channel.freq,
2795 data->remain_on_channel.duration);
2796#endif /* CONFIG_OFFCHANNEL */
2797#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002798 wpas_p2p_remain_on_channel_cb(
2799 wpa_s, data->remain_on_channel.freq,
2800 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002801#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002802 break;
2803 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002804#ifdef CONFIG_OFFCHANNEL
2805 offchannel_cancel_remain_on_channel_cb(
2806 wpa_s, data->remain_on_channel.freq);
2807#endif /* CONFIG_OFFCHANNEL */
2808#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002809 wpas_p2p_cancel_remain_on_channel_cb(
2810 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002811#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002812 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002813#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002814 case EVENT_P2P_DEV_FOUND: {
2815 struct p2p_peer_info peer_info;
2816
2817 os_memset(&peer_info, 0, sizeof(peer_info));
2818 if (data->p2p_dev_found.dev_addr)
2819 os_memcpy(peer_info.p2p_device_addr,
2820 data->p2p_dev_found.dev_addr, ETH_ALEN);
2821 if (data->p2p_dev_found.pri_dev_type)
2822 os_memcpy(peer_info.pri_dev_type,
2823 data->p2p_dev_found.pri_dev_type,
2824 sizeof(peer_info.pri_dev_type));
2825 if (data->p2p_dev_found.dev_name)
2826 os_strlcpy(peer_info.device_name,
2827 data->p2p_dev_found.dev_name,
2828 sizeof(peer_info.device_name));
2829 peer_info.config_methods = data->p2p_dev_found.config_methods;
2830 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2831 peer_info.group_capab = data->p2p_dev_found.group_capab;
2832
2833 /*
2834 * FIX: new_device=1 is not necessarily correct. We should
2835 * maintain a P2P peer database in wpa_supplicant and update
2836 * this information based on whether the peer is truly new.
2837 */
2838 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2839 break;
2840 }
2841 case EVENT_P2P_GO_NEG_REQ_RX:
2842 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2843 data->p2p_go_neg_req_rx.dev_passwd_id);
2844 break;
2845 case EVENT_P2P_GO_NEG_COMPLETED:
2846 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2847 break;
2848 case EVENT_P2P_PROV_DISC_REQUEST:
2849 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2850 data->p2p_prov_disc_req.config_methods,
2851 data->p2p_prov_disc_req.dev_addr,
2852 data->p2p_prov_disc_req.pri_dev_type,
2853 data->p2p_prov_disc_req.dev_name,
2854 data->p2p_prov_disc_req.supp_config_methods,
2855 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002856 data->p2p_prov_disc_req.group_capab,
2857 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002858 break;
2859 case EVENT_P2P_PROV_DISC_RESPONSE:
2860 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2861 data->p2p_prov_disc_resp.config_methods);
2862 break;
2863 case EVENT_P2P_SD_REQUEST:
2864 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2865 data->p2p_sd_req.sa,
2866 data->p2p_sd_req.dialog_token,
2867 data->p2p_sd_req.update_indic,
2868 data->p2p_sd_req.tlvs,
2869 data->p2p_sd_req.tlvs_len);
2870 break;
2871 case EVENT_P2P_SD_RESPONSE:
2872 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2873 data->p2p_sd_resp.update_indic,
2874 data->p2p_sd_resp.tlvs,
2875 data->p2p_sd_resp.tlvs_len);
2876 break;
2877#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878 case EVENT_EAPOL_RX:
2879 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2880 data->eapol_rx.data,
2881 data->eapol_rx.data_len);
2882 break;
2883 case EVENT_SIGNAL_CHANGE:
2884 bgscan_notify_signal_change(
2885 wpa_s, data->signal_change.above_threshold,
2886 data->signal_change.current_signal,
2887 data->signal_change.current_noise,
2888 data->signal_change.current_txrate);
2889 break;
2890 case EVENT_INTERFACE_ENABLED:
2891 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2892 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002893 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002894#ifdef CONFIG_AP
2895 if (!wpa_s->ap_iface) {
2896 wpa_supplicant_set_state(wpa_s,
2897 WPA_DISCONNECTED);
2898 wpa_supplicant_req_scan(wpa_s, 0, 0);
2899 } else
2900 wpa_supplicant_set_state(wpa_s,
2901 WPA_COMPLETED);
2902#else /* CONFIG_AP */
2903 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2904 wpa_supplicant_req_scan(wpa_s, 0, 0);
2905#endif /* CONFIG_AP */
2906 }
2907 break;
2908 case EVENT_INTERFACE_DISABLED:
2909 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2910 wpa_supplicant_mark_disassoc(wpa_s);
2911 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2912 break;
2913 case EVENT_CHANNEL_LIST_CHANGED:
2914 if (wpa_s->drv_priv == NULL)
2915 break; /* Ignore event during drv initialization */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002916
2917 free_hw_features(wpa_s);
2918 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2919 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2920
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002921#ifdef CONFIG_P2P
2922 wpas_p2p_update_channel_list(wpa_s);
2923#endif /* CONFIG_P2P */
2924 break;
2925 case EVENT_INTERFACE_UNAVAILABLE:
2926#ifdef CONFIG_P2P
2927 wpas_p2p_interface_unavailable(wpa_s);
2928#endif /* CONFIG_P2P */
2929 break;
2930 case EVENT_BEST_CHANNEL:
2931 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2932 "(%d %d %d)",
2933 data->best_chan.freq_24, data->best_chan.freq_5,
2934 data->best_chan.freq_overall);
2935 wpa_s->best_24_freq = data->best_chan.freq_24;
2936 wpa_s->best_5_freq = data->best_chan.freq_5;
2937 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2938#ifdef CONFIG_P2P
2939 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2940 data->best_chan.freq_5,
2941 data->best_chan.freq_overall);
2942#endif /* CONFIG_P2P */
2943 break;
2944 case EVENT_UNPROT_DEAUTH:
2945 wpa_supplicant_event_unprot_deauth(wpa_s,
2946 &data->unprot_deauth);
2947 break;
2948 case EVENT_UNPROT_DISASSOC:
2949 wpa_supplicant_event_unprot_disassoc(wpa_s,
2950 &data->unprot_disassoc);
2951 break;
2952 case EVENT_STATION_LOW_ACK:
2953#ifdef CONFIG_AP
2954 if (wpa_s->ap_iface && data)
2955 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2956 data->low_ack.addr);
2957#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002958#ifdef CONFIG_TDLS
2959 if (data)
2960 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2961#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002962 break;
2963 case EVENT_IBSS_PEER_LOST:
2964#ifdef CONFIG_IBSS_RSN
2965 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2966#endif /* CONFIG_IBSS_RSN */
2967 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002968 case EVENT_DRIVER_GTK_REKEY:
2969 if (os_memcmp(data->driver_gtk_rekey.bssid,
2970 wpa_s->bssid, ETH_ALEN))
2971 break;
2972 if (!wpa_s->wpa)
2973 break;
2974 wpa_sm_update_replay_ctr(wpa_s->wpa,
2975 data->driver_gtk_rekey.replay_ctr);
2976 break;
2977 case EVENT_SCHED_SCAN_STOPPED:
2978 wpa_s->sched_scanning = 0;
2979 wpa_supplicant_notify_scanning(wpa_s, 0);
2980
2981 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2982 break;
2983
2984 /*
2985 * If we timed out, start a new sched scan to continue
2986 * searching for more SSIDs.
2987 */
2988 if (wpa_s->sched_scan_timed_out)
2989 wpa_supplicant_req_sched_scan(wpa_s);
2990 break;
2991 case EVENT_WPS_BUTTON_PUSHED:
2992#ifdef CONFIG_WPS
2993 wpas_wps_start_pbc(wpa_s, NULL, 0);
2994#endif /* CONFIG_WPS */
2995 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002996 default:
2997 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
2998 break;
2999 }
3000}