blob: c09245d23b6ea3c8316392e7d72c88b585ddf910 [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"
26#include "notify.h"
27#include "common/ieee802_11_defs.h"
28#include "common/ieee802_11_common.h"
29#include "crypto/random.h"
30#include "blacklist.h"
31#include "wpas_glue.h"
32#include "wps_supplicant.h"
33#include "ibss_rsn.h"
34#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080035#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "p2p_supplicant.h"
37#include "bgscan.h"
38#include "ap.h"
39#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080041#include "offchannel.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042
43
44static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
45{
46 struct wpa_ssid *ssid, *old_ssid;
47
48 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
49 return 0;
50
51 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
52 "information");
53 ssid = wpa_supplicant_get_ssid(wpa_s);
54 if (ssid == NULL) {
55 wpa_msg(wpa_s, MSG_INFO,
56 "No network configuration found for the current AP");
57 return -1;
58 }
59
60 if (ssid->disabled) {
61 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
62 return -1;
63 }
64
65 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
66 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080067 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070068 u8 wpa_ie[80];
69 size_t wpa_ie_len = sizeof(wpa_ie);
70 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
71 wpa_ie, &wpa_ie_len);
72 } else {
73 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
74 }
75
76 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
77 eapol_sm_invalidate_cached_session(wpa_s->eapol);
78 old_ssid = wpa_s->current_ssid;
79 wpa_s->current_ssid = ssid;
80 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
81 wpa_supplicant_initiate_eapol(wpa_s);
82 if (old_ssid != wpa_s->current_ssid)
83 wpas_notify_network_changed(wpa_s);
84
85 return 0;
86}
87
88
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080089void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070090{
91 struct wpa_supplicant *wpa_s = eloop_ctx;
92
93 if (wpa_s->countermeasures) {
94 wpa_s->countermeasures = 0;
95 wpa_drv_set_countermeasures(wpa_s, 0);
96 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
97 wpa_supplicant_req_scan(wpa_s, 0, 0);
98 }
99}
100
101
102void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
103{
104 int bssid_changed;
105
106#ifdef CONFIG_IBSS_RSN
107 ibss_rsn_deinit(wpa_s->ibss_rsn);
108 wpa_s->ibss_rsn = NULL;
109#endif /* CONFIG_IBSS_RSN */
110
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700111#ifdef CONFIG_AP
112 wpa_supplicant_ap_deinit(wpa_s);
113#endif /* CONFIG_AP */
114
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700115 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
116 return;
117
118 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800119#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -0700120 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800121#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700122 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
123 os_memset(wpa_s->bssid, 0, ETH_ALEN);
124 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800125#ifdef CONFIG_P2P
126 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
127#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700128 wpa_s->current_bss = NULL;
129 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700130#ifdef CONFIG_IEEE80211R
131#ifdef CONFIG_SME
132 if (wpa_s->sme.ft_ies)
133 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
134#endif /* CONFIG_SME */
135#endif /* CONFIG_IEEE80211R */
136
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700137 if (bssid_changed)
138 wpas_notify_bssid_changed(wpa_s);
139
140 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
141 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
142 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
143 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
144 wpa_s->ap_ies_from_associnfo = 0;
145}
146
147
148static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
149{
150 struct wpa_ie_data ie;
151 int pmksa_set = -1;
152 size_t i;
153
154 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
155 ie.pmkid == NULL)
156 return;
157
158 for (i = 0; i < ie.num_pmkid; i++) {
159 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
160 ie.pmkid + i * PMKID_LEN,
161 NULL, NULL, 0);
162 if (pmksa_set == 0) {
163 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
164 break;
165 }
166 }
167
168 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
169 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
170}
171
172
173static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
174 union wpa_event_data *data)
175{
176 if (data == NULL) {
177 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
178 "event");
179 return;
180 }
181 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
182 " index=%d preauth=%d",
183 MAC2STR(data->pmkid_candidate.bssid),
184 data->pmkid_candidate.index,
185 data->pmkid_candidate.preauth);
186
187 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
188 data->pmkid_candidate.index,
189 data->pmkid_candidate.preauth);
190}
191
192
193static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
194{
195 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
196 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
197 return 0;
198
199#ifdef IEEE8021X_EAPOL
200 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
201 wpa_s->current_ssid &&
202 !(wpa_s->current_ssid->eapol_flags &
203 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
204 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
205 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
206 * plaintext or static WEP keys). */
207 return 0;
208 }
209#endif /* IEEE8021X_EAPOL */
210
211 return 1;
212}
213
214
215/**
216 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
217 * @wpa_s: pointer to wpa_supplicant data
218 * @ssid: Configuration data for the network
219 * Returns: 0 on success, -1 on failure
220 *
221 * This function is called when starting authentication with a network that is
222 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
223 */
224int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
225 struct wpa_ssid *ssid)
226{
227#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800228#ifdef PCSC_FUNCS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700229 int aka = 0, sim = 0, type;
230
231 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
232 return 0;
233
234 if (ssid->eap.eap_methods == NULL) {
235 sim = 1;
236 aka = 1;
237 } else {
238 struct eap_method_type *eap = ssid->eap.eap_methods;
239 while (eap->vendor != EAP_VENDOR_IETF ||
240 eap->method != EAP_TYPE_NONE) {
241 if (eap->vendor == EAP_VENDOR_IETF) {
242 if (eap->method == EAP_TYPE_SIM)
243 sim = 1;
244 else if (eap->method == EAP_TYPE_AKA)
245 aka = 1;
246 }
247 eap++;
248 }
249 }
250
251 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
252 sim = 0;
253 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
254 aka = 0;
255
256 if (!sim && !aka) {
257 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
258 "use SIM, but neither EAP-SIM nor EAP-AKA are "
259 "enabled");
260 return 0;
261 }
262
263 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
264 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
265 if (sim && aka)
266 type = SCARD_TRY_BOTH;
267 else if (aka)
268 type = SCARD_USIM_ONLY;
269 else
270 type = SCARD_GSM_SIM_ONLY;
271
272 wpa_s->scard = scard_init(type);
273 if (wpa_s->scard == NULL) {
274 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
275 "(pcsc-lite)");
276 return -1;
277 }
278 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
279 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800280#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281#endif /* IEEE8021X_EAPOL */
282
283 return 0;
284}
285
286
287#ifndef CONFIG_NO_SCAN_PROCESSING
288static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
289 struct wpa_ssid *ssid)
290{
291 int i, privacy = 0;
292
293 if (ssid->mixed_cell)
294 return 1;
295
296#ifdef CONFIG_WPS
297 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
298 return 1;
299#endif /* CONFIG_WPS */
300
301 for (i = 0; i < NUM_WEP_KEYS; i++) {
302 if (ssid->wep_key_len[i]) {
303 privacy = 1;
304 break;
305 }
306 }
307#ifdef IEEE8021X_EAPOL
308 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
309 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
310 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
311 privacy = 1;
312#endif /* IEEE8021X_EAPOL */
313
Jouni Malinen75ecf522011-06-27 15:19:46 -0700314 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
315 privacy = 1;
316
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317 if (bss->caps & IEEE80211_CAP_PRIVACY)
318 return privacy;
319 return !privacy;
320}
321
322
323static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
324 struct wpa_ssid *ssid,
325 struct wpa_scan_res *bss)
326{
327 struct wpa_ie_data ie;
328 int proto_match = 0;
329 const u8 *rsn_ie, *wpa_ie;
330 int ret;
331 int wep_ok;
332
333 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
334 if (ret >= 0)
335 return ret;
336
337 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
338 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
339 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
340 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
341 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
342
343 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
344 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
345 proto_match++;
346
347 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
348 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
349 "failed");
350 break;
351 }
352
353 if (wep_ok &&
354 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
355 {
356 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
357 "in RSN IE");
358 return 1;
359 }
360
361 if (!(ie.proto & ssid->proto)) {
362 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
363 "mismatch");
364 break;
365 }
366
367 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
368 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
369 "cipher mismatch");
370 break;
371 }
372
373 if (!(ie.group_cipher & ssid->group_cipher)) {
374 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
375 "cipher mismatch");
376 break;
377 }
378
379 if (!(ie.key_mgmt & ssid->key_mgmt)) {
380 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
381 "mismatch");
382 break;
383 }
384
385#ifdef CONFIG_IEEE80211W
386 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
387 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
388 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
389 "frame protection");
390 break;
391 }
392#endif /* CONFIG_IEEE80211W */
393
394 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
395 return 1;
396 }
397
398 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
399 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
400 proto_match++;
401
402 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
403 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
404 "failed");
405 break;
406 }
407
408 if (wep_ok &&
409 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
410 {
411 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
412 "in WPA IE");
413 return 1;
414 }
415
416 if (!(ie.proto & ssid->proto)) {
417 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
418 "mismatch");
419 break;
420 }
421
422 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
423 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
424 "cipher mismatch");
425 break;
426 }
427
428 if (!(ie.group_cipher & ssid->group_cipher)) {
429 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
430 "cipher mismatch");
431 break;
432 }
433
434 if (!(ie.key_mgmt & ssid->key_mgmt)) {
435 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
436 "mismatch");
437 break;
438 }
439
440 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
441 return 1;
442 }
443
444 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
445 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
446 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
447 return 0;
448 }
449
450 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
451 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
452 return 1;
453 }
454
455 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
456 "WPA/WPA2");
457
458 return 0;
459}
460
461
462static int freq_allowed(int *freqs, int freq)
463{
464 int i;
465
466 if (freqs == NULL)
467 return 1;
468
469 for (i = 0; freqs[i]; i++)
470 if (freqs[i] == freq)
471 return 1;
472 return 0;
473}
474
475
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800476static int ht_supported(const struct hostapd_hw_modes *mode)
477{
478 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
479 /*
480 * The driver did not indicate whether it supports HT. Assume
481 * it does to avoid connection issues.
482 */
483 return 1;
484 }
485
486 /*
487 * IEEE Std 802.11n-2009 20.1.1:
488 * An HT non-AP STA shall support all EQM rates for one spatial stream.
489 */
490 return mode->mcs_set[0] == 0xff;
491}
492
493
494static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss)
495{
496 const struct hostapd_hw_modes *mode = NULL, *modes;
497 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
498 const u8 *rate_ie;
499 int i, j, k;
500
501 if (bss->freq == 0)
502 return 1; /* Cannot do matching without knowing band */
503
504 modes = wpa_s->hw.modes;
505 if (modes == NULL) {
506 /*
507 * The driver does not provide any additional information
508 * about the utilized hardware, so allow the connection attempt
509 * to continue.
510 */
511 return 1;
512 }
513
514 for (i = 0; i < wpa_s->hw.num_modes; i++) {
515 for (j = 0; j < modes[i].num_channels; j++) {
516 int freq = modes[i].channels[j].freq;
517 if (freq == bss->freq) {
518 if (mode &&
519 mode->mode == HOSTAPD_MODE_IEEE80211G)
520 break; /* do not allow 802.11b replace
521 * 802.11g */
522 mode = &modes[i];
523 break;
524 }
525 }
526 }
527
528 if (mode == NULL)
529 return 0;
530
531 for (i = 0; i < (int) sizeof(scan_ie); i++) {
532 rate_ie = wpa_scan_get_ie(bss, scan_ie[i]);
533 if (rate_ie == NULL)
534 continue;
535
536 for (j = 2; j < rate_ie[1] + 2; j++) {
537 int flagged = !!(rate_ie[j] & 0x80);
538 int r = (rate_ie[j] & 0x7f) * 5;
539
540 /*
541 * IEEE Std 802.11n-2009 7.3.2.2:
542 * The new BSS Membership selector value is encoded
543 * like a legacy basic rate, but it is not a rate and
544 * only indicates if the BSS members are required to
545 * support the mandatory features of Clause 20 [HT PHY]
546 * in order to join the BSS.
547 */
548 if (flagged && ((rate_ie[j] & 0x7f) ==
549 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
550 if (!ht_supported(mode)) {
551 wpa_dbg(wpa_s, MSG_DEBUG,
552 " hardware does not support "
553 "HT PHY");
554 return 0;
555 }
556 continue;
557 }
558
559 if (!flagged)
560 continue;
561
562 /* check for legacy basic rates */
563 for (k = 0; k < mode->num_rates; k++) {
564 if (mode->rates[k] == r)
565 break;
566 }
567 if (k == mode->num_rates) {
568 /*
569 * IEEE Std 802.11-2007 7.3.2.2 demands that in
570 * order to join a BSS all required rates
571 * have to be supported by the hardware.
572 */
573 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
574 "not support required rate %d.%d Mbps",
575 r / 10, r % 10);
576 return 0;
577 }
578 }
579 }
580
581 return 1;
582}
583
584
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
586 int i, struct wpa_scan_res *bss,
587 struct wpa_ssid *group)
588{
589 const u8 *ssid_;
590 u8 wpa_ie_len, rsn_ie_len, ssid_len;
591 int wpa;
592 struct wpa_blacklist *e;
593 const u8 *ie;
594 struct wpa_ssid *ssid;
595
596 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
597 ssid_ = ie ? ie + 2 : (u8 *) "";
598 ssid_len = ie ? ie[1] : 0;
599
600 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
601 wpa_ie_len = ie ? ie[1] : 0;
602
603 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
604 rsn_ie_len = ie ? ie[1] : 0;
605
606 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
607 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
608 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
609 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
610 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
611
612 e = wpa_blacklist_get(wpa_s, bss->bssid);
613 if (e) {
614 int limit = 1;
615 if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) {
616 /*
617 * When only a single network is enabled, we can
618 * trigger blacklisting on the first failure. This
619 * should not be done with multiple enabled networks to
620 * avoid getting forced to move into a worse ESS on
621 * single error if there are no other BSSes of the
622 * current ESS.
623 */
624 limit = 0;
625 }
626 if (e->count > limit) {
627 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
628 "(count=%d limit=%d)", e->count, limit);
629 return NULL;
630 }
631 }
632
633 if (ssid_len == 0) {
634 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
635 return NULL;
636 }
637
638 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
639
640 for (ssid = group; ssid; ssid = ssid->pnext) {
641 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
642
643 if (ssid->disabled) {
644 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
645 continue;
646 }
647
648#ifdef CONFIG_WPS
649 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
650 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
651 "(WPS)");
652 continue;
653 }
654
655 if (wpa && ssid->ssid_len == 0 &&
656 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
657 check_ssid = 0;
658
659 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
660 /* Only allow wildcard SSID match if an AP
661 * advertises active WPS operation that matches
662 * with our mode. */
663 check_ssid = 1;
664 if (ssid->ssid_len == 0 &&
665 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
666 check_ssid = 0;
667 }
668#endif /* CONFIG_WPS */
669
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800670 if (ssid->bssid_set && ssid->ssid_len == 0 &&
671 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
672 check_ssid = 0;
673
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674 if (check_ssid &&
675 (ssid_len != ssid->ssid_len ||
676 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
677 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
678 continue;
679 }
680
681 if (ssid->bssid_set &&
682 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
683 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
684 continue;
685 }
686
687 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
688 continue;
689
690 if (!wpa &&
691 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
692 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
693 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
694 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
695 "not allowed");
696 continue;
697 }
698
Jouni Malinen75ecf522011-06-27 15:19:46 -0700699 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
701 "mismatch");
702 continue;
703 }
704
Jouni Malinen75ecf522011-06-27 15:19:46 -0700705 if (bss->caps & IEEE80211_CAP_IBSS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
707 "network");
708 continue;
709 }
710
711 if (!freq_allowed(ssid->freq_list, bss->freq)) {
712 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
713 "allowed");
714 continue;
715 }
716
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800717 if (!rate_match(wpa_s, bss)) {
718 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
719 "not match");
720 continue;
721 }
722
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723#ifdef CONFIG_P2P
724 /*
725 * TODO: skip the AP if its P2P IE has Group Formation
726 * bit set in the P2P Group Capability Bitmap and we
727 * are not in Group Formation with that device.
728 */
729#endif /* CONFIG_P2P */
730
731 /* Matching configuration found */
732 return ssid;
733 }
734
735 /* No matching configuration found */
736 return NULL;
737}
738
739
740static struct wpa_bss *
741wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
742 struct wpa_scan_results *scan_res,
743 struct wpa_ssid *group,
744 struct wpa_ssid **selected_ssid)
745{
746 size_t i;
747
748 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
749 group->priority);
750
751 for (i = 0; i < scan_res->num; i++) {
752 struct wpa_scan_res *bss = scan_res->res[i];
753 const u8 *ie, *ssid;
754 u8 ssid_len;
755
756 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
757 if (!*selected_ssid)
758 continue;
759
760 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
761 ssid = ie ? ie + 2 : (u8 *) "";
762 ssid_len = ie ? ie[1] : 0;
763
764 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
765 " ssid='%s'",
766 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
767 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
768 }
769
770 return NULL;
771}
772
773
774static struct wpa_bss *
775wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
776 struct wpa_scan_results *scan_res,
777 struct wpa_ssid **selected_ssid)
778{
779 struct wpa_bss *selected = NULL;
780 int prio;
781
782 while (selected == NULL) {
783 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
784 selected = wpa_supplicant_select_bss(
785 wpa_s, scan_res, wpa_s->conf->pssid[prio],
786 selected_ssid);
787 if (selected)
788 break;
789 }
790
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800791 if (selected == NULL && wpa_s->blacklist &&
792 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700793 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
794 "blacklist and try again");
795 wpa_blacklist_clear(wpa_s);
796 wpa_s->blacklist_cleared++;
797 } else if (selected == NULL)
798 break;
799 }
800
801 return selected;
802}
803
804
805static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
806 int timeout_sec, int timeout_usec)
807{
808 if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
809 /*
810 * No networks are enabled; short-circuit request so
811 * we don't wait timeout seconds before transitioning
812 * to INACTIVE state.
813 */
814 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
815 return;
816 }
817 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
818}
819
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800820
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700821int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800822 struct wpa_bss *selected,
823 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824{
825 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
826 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
827 "PBC session overlap");
828#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800829 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700830 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700831#endif /* CONFIG_P2P */
832
833#ifdef CONFIG_WPS
834 wpas_wps_cancel(wpa_s);
835#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700836 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837 }
838
839 /*
840 * Do not trigger new association unless the BSSID has changed or if
841 * reassociation is requested. If we are in process of associating with
842 * the selected BSSID, do not trigger new attempt.
843 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800844 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
846 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
847 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
848 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
849 0))) {
850 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
851 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700852 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700853 }
854 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
855 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
856 " pending: " MACSTR " wpa_state: %s",
857 wpa_s->reassociate, MAC2STR(selected->bssid),
858 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
859 wpa_supplicant_state_txt(wpa_s->wpa_state));
860 wpa_supplicant_associate(wpa_s, selected, ssid);
861 } else {
862 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
863 "selected AP");
864 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800865
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700866 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700867}
868
869
870static struct wpa_ssid *
871wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
872{
873 int prio;
874 struct wpa_ssid *ssid;
875
876 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
877 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
878 {
879 if (ssid->disabled)
880 continue;
881 if (ssid->mode == IEEE80211_MODE_IBSS ||
882 ssid->mode == IEEE80211_MODE_AP)
883 return ssid;
884 }
885 }
886 return NULL;
887}
888
889
890/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
891 * on BSS added and BSS changed events */
892static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +0300893 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894{
Jouni Malinen87fd2792011-05-16 18:35:42 +0300895 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896
897 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
898 return;
899
Jouni Malinen87fd2792011-05-16 18:35:42 +0300900 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700901 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700902
Jouni Malinen87fd2792011-05-16 18:35:42 +0300903 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700904 if (ssid == NULL)
905 continue;
906
Jouni Malinen87fd2792011-05-16 18:35:42 +0300907 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700908 if (rsn == NULL)
909 continue;
910
Jouni Malinen87fd2792011-05-16 18:35:42 +0300911 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 }
913
914}
915
916
917static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
918 struct wpa_bss *selected,
919 struct wpa_ssid *ssid,
920 struct wpa_scan_results *scan_res)
921{
922 size_t i;
923 struct wpa_scan_res *current_bss = NULL;
924 int min_diff;
925
926 if (wpa_s->reassociate)
927 return 1; /* explicit request to reassociate */
928 if (wpa_s->wpa_state < WPA_ASSOCIATED)
929 return 1; /* we are not associated; continue */
930 if (wpa_s->current_ssid == NULL)
931 return 1; /* unknown current SSID */
932 if (wpa_s->current_ssid != ssid)
933 return 1; /* different network block */
934
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800935 if (wpas_driver_bss_selection(wpa_s))
936 return 0; /* Driver-based roaming */
937
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700938 for (i = 0; i < scan_res->num; i++) {
939 struct wpa_scan_res *res = scan_res->res[i];
940 const u8 *ie;
941 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
942 continue;
943
944 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
945 if (ie == NULL)
946 continue;
947 if (ie[1] != wpa_s->current_ssid->ssid_len ||
948 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
949 continue;
950 current_bss = res;
951 break;
952 }
953
954 if (!current_bss)
955 return 1; /* current BSS not seen in scan results */
956
Dmitry Shmidt9e077672012-04-13 10:07:27 -0700957#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
959 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
960 MAC2STR(current_bss->bssid), current_bss->level);
961 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
962 MAC2STR(selected->bssid), selected->level);
963
964 if (wpa_s->current_ssid->bssid_set &&
965 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
966 0) {
967 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
968 "has preferred BSSID");
969 return 1;
970 }
971
972 min_diff = 2;
973 if (current_bss->level < 0) {
974 if (current_bss->level < -85)
975 min_diff = 1;
976 else if (current_bss->level < -80)
977 min_diff = 2;
978 else if (current_bss->level < -75)
979 min_diff = 3;
980 else if (current_bss->level < -70)
981 min_diff = 4;
982 else
983 min_diff = 5;
984 }
985 if (abs(current_bss->level - selected->level) < min_diff) {
986 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
987 "in signal level");
988 return 0;
989 }
990
991 return 1;
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -0700992#else
993 return 0;
994#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700995}
996
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800997
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700998/* Return < 0 if no scan results could be fetched. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -0800999#ifdef ANDROID_P2P
1000static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1001 union wpa_event_data *data, int suppress_event)
1002#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001003static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1004 union wpa_event_data *data)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001005#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001006{
1007 struct wpa_bss *selected;
1008 struct wpa_ssid *ssid = NULL;
1009 struct wpa_scan_results *scan_res;
1010 int ap = 0;
1011
1012#ifdef CONFIG_AP
1013 if (wpa_s->ap_iface)
1014 ap = 1;
1015#endif /* CONFIG_AP */
1016
1017 wpa_supplicant_notify_scanning(wpa_s, 0);
1018
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001019#ifdef CONFIG_P2P
1020 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
1021 wpa_s->global->p2p != NULL) {
1022 wpa_s->p2p_cb_on_scan_complete = 0;
1023 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1024 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1025 "stopped scan processing");
1026 return -1;
1027 }
1028 }
1029#endif /* CONFIG_P2P */
1030
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001031 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1032 data ? &data->scan_info :
1033 NULL, 1);
1034 if (scan_res == NULL) {
1035 if (wpa_s->conf->ap_scan == 2 || ap)
1036 return -1;
1037 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1038 "scanning again");
1039 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1040 return -1;
1041 }
1042
1043#ifndef CONFIG_NO_RANDOM_POOL
1044 size_t i, num;
1045 num = scan_res->num;
1046 if (num > 10)
1047 num = 10;
1048 for (i = 0; i < num; i++) {
1049 u8 buf[5];
1050 struct wpa_scan_res *res = scan_res->res[i];
1051 buf[0] = res->bssid[5];
1052 buf[1] = res->qual & 0xff;
1053 buf[2] = res->noise & 0xff;
1054 buf[3] = res->level & 0xff;
1055 buf[4] = res->tsf & 0xff;
1056 random_add_randomness(buf, sizeof(buf));
1057 }
1058#endif /* CONFIG_NO_RANDOM_POOL */
1059
1060 if (wpa_s->scan_res_handler) {
1061 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1062 struct wpa_scan_results *scan_res);
1063
1064 scan_res_handler = wpa_s->scan_res_handler;
1065 wpa_s->scan_res_handler = NULL;
1066 scan_res_handler(wpa_s, scan_res);
1067
1068 wpa_scan_results_free(scan_res);
1069 return 0;
1070 }
1071
1072 if (ap) {
1073 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1074#ifdef CONFIG_AP
1075 if (wpa_s->ap_iface->scan_cb)
1076 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1077#endif /* CONFIG_AP */
1078 wpa_scan_results_free(scan_res);
1079 return 0;
1080 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001081#ifdef ANDROID_P2P
1082 if(!suppress_event)
1083#endif
1084 {
1085 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1086 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1087 wpas_notify_scan_results(wpa_s);
1088 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001089
1090 wpas_notify_scan_done(wpa_s, 1);
1091
1092 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1093 wpa_scan_results_free(scan_res);
1094 return 0;
1095 }
1096
1097 if (wpa_s->disconnected) {
1098 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1099 wpa_scan_results_free(scan_res);
1100 return 0;
1101 }
1102
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001103 if (!wpas_driver_bss_selection(wpa_s) &&
1104 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105 wpa_scan_results_free(scan_res);
1106 return 0;
1107 }
1108
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1110
1111 if (selected) {
1112 int skip;
1113 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1114 scan_res);
1115 wpa_scan_results_free(scan_res);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001116 if (skip) {
1117 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001119 }
1120
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001121 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001122 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001123 return -1;
1124 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03001125 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001126 } else {
1127 wpa_scan_results_free(scan_res);
1128 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1129 ssid = wpa_supplicant_pick_new_network(wpa_s);
1130 if (ssid) {
1131 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1132 wpa_supplicant_associate(wpa_s, NULL, ssid);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001133 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001134 } else {
1135 int timeout_sec = wpa_s->scan_interval;
1136 int timeout_usec = 0;
1137#ifdef CONFIG_P2P
1138 if (wpa_s->p2p_in_provisioning) {
1139 /*
1140 * Use shorter wait during P2P Provisioning
1141 * state to speed up group formation.
1142 */
1143 timeout_sec = 0;
1144 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001145 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1146 timeout_usec);
1147 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001148 }
1149#endif /* CONFIG_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001150 if (wpa_supplicant_req_sched_scan(wpa_s))
1151 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1152 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001153 }
1154 }
1155 return 0;
1156}
1157
1158
1159static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1160 union wpa_event_data *data)
1161{
1162 const char *rn, *rn2;
1163 struct wpa_supplicant *ifs;
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001164#ifdef ANDROID_P2P
1165 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) {
1166#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001167 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001168#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001169 /*
1170 * If no scan results could be fetched, then no need to
1171 * notify those interfaces that did not actually request
1172 * this scan.
1173 */
1174 return;
1175 }
1176
1177 /*
1178 * Check other interfaces to see if they have the same radio-name. If
1179 * so, they get updated with this same scan info.
1180 */
1181 if (!wpa_s->driver->get_radio_name)
1182 return;
1183
1184 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1185 if (rn == NULL || rn[0] == '\0')
1186 return;
1187
1188 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1189 "sharing same radio (%s) in event_scan_results", rn);
1190
1191 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1192 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1193 continue;
1194
1195 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1196 if (rn2 && os_strcmp(rn, rn2) == 0) {
1197 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1198 "sibling", ifs->ifname);
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001199#ifndef ANDROID_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001200 _wpa_supplicant_event_scan_results(ifs, data);
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001201#else
1202 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1203 * no time. Avoid announcing it to application as it may not
1204 * be that useful (since results will be that of only 1,6,11).
1205 * over to any other interface as it
1206 */
1207 if((wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) && p2p_search_in_progress(wpa_s->global->p2p))
1208 _wpa_supplicant_event_scan_results(ifs, data, 1);
1209 else
1210 _wpa_supplicant_event_scan_results(ifs, data, 0);
1211#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001212 }
1213 }
1214}
1215
1216#endif /* CONFIG_NO_SCAN_PROCESSING */
1217
1218
1219static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1220 union wpa_event_data *data)
1221{
1222 int l, len, found = 0, wpa_found, rsn_found;
1223 const u8 *p;
1224
1225 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1226 if (data->assoc_info.req_ies)
1227 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1228 data->assoc_info.req_ies_len);
1229 if (data->assoc_info.resp_ies) {
1230 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1231 data->assoc_info.resp_ies_len);
1232#ifdef CONFIG_TDLS
1233 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1234 data->assoc_info.resp_ies_len);
1235#endif /* CONFIG_TDLS */
1236 }
1237 if (data->assoc_info.beacon_ies)
1238 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1239 data->assoc_info.beacon_ies,
1240 data->assoc_info.beacon_ies_len);
1241 if (data->assoc_info.freq)
1242 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1243 data->assoc_info.freq);
1244
1245 p = data->assoc_info.req_ies;
1246 l = data->assoc_info.req_ies_len;
1247
1248 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1249 while (p && l >= 2) {
1250 len = p[1] + 2;
1251 if (len > l) {
1252 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1253 p, l);
1254 break;
1255 }
1256 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1257 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1258 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1259 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1260 break;
1261 found = 1;
1262 wpa_find_assoc_pmkid(wpa_s);
1263 break;
1264 }
1265 l -= len;
1266 p += len;
1267 }
1268 if (!found && data->assoc_info.req_ies)
1269 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1270
1271#ifdef CONFIG_IEEE80211R
1272#ifdef CONFIG_SME
1273 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1274 u8 bssid[ETH_ALEN];
1275 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1276 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1277 data->assoc_info.resp_ies,
1278 data->assoc_info.resp_ies_len,
1279 bssid) < 0) {
1280 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1281 "Reassociation Response failed");
1282 wpa_supplicant_deauthenticate(
1283 wpa_s, WLAN_REASON_INVALID_IE);
1284 return -1;
1285 }
1286 }
1287
1288 p = data->assoc_info.resp_ies;
1289 l = data->assoc_info.resp_ies_len;
1290
1291#ifdef CONFIG_WPS_STRICT
1292 if (p && wpa_s->current_ssid &&
1293 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1294 struct wpabuf *wps;
1295 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1296 if (wps == NULL) {
1297 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1298 "include WPS IE in (Re)Association Response");
1299 return -1;
1300 }
1301
1302 if (wps_validate_assoc_resp(wps) < 0) {
1303 wpabuf_free(wps);
1304 wpa_supplicant_deauthenticate(
1305 wpa_s, WLAN_REASON_INVALID_IE);
1306 return -1;
1307 }
1308 wpabuf_free(wps);
1309 }
1310#endif /* CONFIG_WPS_STRICT */
1311
1312 /* Go through the IEs and make a copy of the MDIE, if present. */
1313 while (p && l >= 2) {
1314 len = p[1] + 2;
1315 if (len > l) {
1316 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1317 p, l);
1318 break;
1319 }
1320 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1321 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1322 wpa_s->sme.ft_used = 1;
1323 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1324 MOBILITY_DOMAIN_ID_LEN);
1325 break;
1326 }
1327 l -= len;
1328 p += len;
1329 }
1330#endif /* CONFIG_SME */
1331
1332 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1333 data->assoc_info.resp_ies_len);
1334#endif /* CONFIG_IEEE80211R */
1335
1336 /* WPA/RSN IE from Beacon/ProbeResp */
1337 p = data->assoc_info.beacon_ies;
1338 l = data->assoc_info.beacon_ies_len;
1339
1340 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1341 */
1342 wpa_found = rsn_found = 0;
1343 while (p && l >= 2) {
1344 len = p[1] + 2;
1345 if (len > l) {
1346 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1347 p, l);
1348 break;
1349 }
1350 if (!wpa_found &&
1351 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1352 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1353 wpa_found = 1;
1354 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1355 }
1356
1357 if (!rsn_found &&
1358 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1359 rsn_found = 1;
1360 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1361 }
1362
1363 l -= len;
1364 p += len;
1365 }
1366
1367 if (!wpa_found && data->assoc_info.beacon_ies)
1368 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1369 if (!rsn_found && data->assoc_info.beacon_ies)
1370 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1371 if (wpa_found || rsn_found)
1372 wpa_s->ap_ies_from_associnfo = 1;
1373
Jouni Malinen87fd2792011-05-16 18:35:42 +03001374 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1375 wpa_s->assoc_freq != data->assoc_info.freq) {
1376 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1377 "%u to %u MHz",
1378 wpa_s->assoc_freq, data->assoc_info.freq);
1379 wpa_supplicant_update_scan_results(wpa_s);
1380 }
1381
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001382 wpa_s->assoc_freq = data->assoc_info.freq;
1383
1384 return 0;
1385}
1386
1387
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001388static struct wpa_bss * wpa_supplicant_get_new_bss(
1389 struct wpa_supplicant *wpa_s, const u8 *bssid)
1390{
1391 struct wpa_bss *bss = NULL;
1392 struct wpa_ssid *ssid = wpa_s->current_ssid;
1393
1394 if (ssid->ssid_len > 0)
1395 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1396 if (!bss)
1397 bss = wpa_bss_get_bssid(wpa_s, bssid);
1398
1399 return bss;
1400}
1401
1402
1403static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1404{
1405 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1406
1407 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1408 return -1;
1409
1410 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1411 return 0;
1412
1413 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1414 WPA_IE_VENDOR_TYPE);
1415 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1416
1417 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1418 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1419 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1420 bss_rsn ? 2 + bss_rsn[1] : 0))
1421 return -1;
1422
1423 return 0;
1424}
1425
1426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1428 union wpa_event_data *data)
1429{
1430 u8 bssid[ETH_ALEN];
1431 int ft_completed;
1432 int bssid_changed;
1433 struct wpa_driver_capa capa;
1434
1435#ifdef CONFIG_AP
1436 if (wpa_s->ap_iface) {
1437 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1438 data->assoc_info.addr,
1439 data->assoc_info.req_ies,
1440 data->assoc_info.req_ies_len,
1441 data->assoc_info.reassoc);
1442 return;
1443 }
1444#endif /* CONFIG_AP */
1445
1446 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1447 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1448 return;
1449
1450 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001451 if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1452 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001453 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1454 MACSTR, MAC2STR(bssid));
1455 random_add_randomness(bssid, ETH_ALEN);
1456 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1457 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1458 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1459 if (bssid_changed)
1460 wpas_notify_bssid_changed(wpa_s);
1461
1462 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1463 wpa_clear_keys(wpa_s, bssid);
1464 }
1465 if (wpa_supplicant_select_config(wpa_s) < 0) {
1466 wpa_supplicant_disassociate(
1467 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1468 return;
1469 }
1470 if (wpa_s->current_ssid) {
1471 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001472
1473 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1474 if (!bss) {
1475 wpa_supplicant_update_scan_results(wpa_s);
1476
1477 /* Get the BSS from the new scan results */
1478 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1479 }
1480
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001481 if (bss)
1482 wpa_s->current_bss = bss;
1483 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001484
1485 if (wpa_s->conf->ap_scan == 1 &&
1486 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1487 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1488 wpa_msg(wpa_s, MSG_WARNING,
1489 "WPA/RSN IEs not updated");
1490 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001491 }
1492
1493#ifdef CONFIG_SME
1494 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1495 wpa_s->sme.prev_bssid_set = 1;
1496#endif /* CONFIG_SME */
1497
1498 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1499 if (wpa_s->current_ssid) {
1500 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1501 * initialized before association, but for other modes,
1502 * initialize PC/SC here, if the current configuration needs
1503 * smartcard or SIM/USIM. */
1504 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1505 }
1506 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1507 if (wpa_s->l2)
1508 l2_packet_notify_auth_start(wpa_s->l2);
1509
1510 /*
1511 * Set portEnabled first to FALSE in order to get EAP state machine out
1512 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1513 * state machine may transit to AUTHENTICATING state based on obsolete
1514 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1515 * AUTHENTICATED without ever giving chance to EAP state machine to
1516 * reset the state.
1517 */
1518 if (!ft_completed) {
1519 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1520 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1521 }
1522 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1523 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1524 /* 802.1X::portControl = Auto */
1525 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1526 wpa_s->eapol_received = 0;
1527 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1528 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1529 (wpa_s->current_ssid &&
1530 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1531 wpa_supplicant_cancel_auth_timeout(wpa_s);
1532 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1533 } else if (!ft_completed) {
1534 /* Timeout for receiving the first EAPOL packet */
1535 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1536 }
1537 wpa_supplicant_cancel_scan(wpa_s);
1538
1539 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1540 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1541 /*
1542 * We are done; the driver will take care of RSN 4-way
1543 * handshake.
1544 */
1545 wpa_supplicant_cancel_auth_timeout(wpa_s);
1546 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1547 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1548 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1549 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1550 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1551 /*
1552 * The driver will take care of RSN 4-way handshake, so we need
1553 * to allow EAPOL supplicant to complete its work without
1554 * waiting for WPA supplicant.
1555 */
1556 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1557 } else if (ft_completed) {
1558 /*
1559 * FT protocol completed - make sure EAPOL state machine ends
1560 * up in authenticated.
1561 */
1562 wpa_supplicant_cancel_auth_timeout(wpa_s);
1563 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1564 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1565 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1566 }
1567
1568 if (wpa_s->pending_eapol_rx) {
1569 struct os_time now, age;
1570 os_get_time(&now);
1571 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1572 if (age.sec == 0 && age.usec < 100000 &&
1573 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1574 0) {
1575 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1576 "frame that was received just before "
1577 "association notification");
1578 wpa_supplicant_rx_eapol(
1579 wpa_s, wpa_s->pending_eapol_rx_src,
1580 wpabuf_head(wpa_s->pending_eapol_rx),
1581 wpabuf_len(wpa_s->pending_eapol_rx));
1582 }
1583 wpabuf_free(wpa_s->pending_eapol_rx);
1584 wpa_s->pending_eapol_rx = NULL;
1585 }
1586
1587 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1588 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1589 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1590 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1591 /* Set static WEP keys again */
1592 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1593 }
1594
1595#ifdef CONFIG_IBSS_RSN
1596 if (wpa_s->current_ssid &&
1597 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1598 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1599 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1600 wpa_s->ibss_rsn == NULL) {
1601 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1602 if (!wpa_s->ibss_rsn) {
1603 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1604 wpa_supplicant_deauthenticate(
1605 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1606 return;
1607 }
1608
1609 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1610 }
1611#endif /* CONFIG_IBSS_RSN */
1612}
1613
1614
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001615static int disconnect_reason_recoverable(u16 reason_code)
1616{
1617 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1618 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1619 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1620}
1621
1622
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001624 u16 reason_code,
1625 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001626{
1627 const u8 *bssid;
1628 int authenticating;
1629 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001630 struct wpa_bss *fast_reconnect = NULL;
1631 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001632
1633 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1634 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1635
1636 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1637 /*
1638 * At least Host AP driver and a Prism3 card seemed to be
1639 * generating streams of disconnected events when configuring
1640 * IBSS for WPA-None. Ignore them for now.
1641 */
1642 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1643 "IBSS/WPA-None mode");
1644 return;
1645 }
1646
1647 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1648 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1649 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1650 "pre-shared key may be incorrect");
1651 }
1652 if (!wpa_s->auto_reconnect_disabled ||
1653 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001654 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1655 "reconnect (wps=%d wpa_state=%d)",
1656 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1657 wpa_s->wpa_state);
1658 if (wpa_s->wpa_state == WPA_COMPLETED &&
1659 wpa_s->current_ssid &&
1660 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001661 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001662 disconnect_reason_recoverable(reason_code)) {
1663 /*
1664 * It looks like the AP has dropped association with
1665 * us, but could allow us to get back in. Try to
1666 * reconnect to the same BSS without full scan to save
1667 * time for some common cases.
1668 */
1669 fast_reconnect = wpa_s->current_bss;
1670 fast_reconnect_ssid = wpa_s->current_ssid;
1671 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001672#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07001673 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001674#else
1675 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1676#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001677 else
1678 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1679 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001681 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001682 "try to re-connect");
1683 wpa_s->reassociate = 0;
1684 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001685 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001686 }
1687 bssid = wpa_s->bssid;
1688 if (is_zero_ether_addr(bssid))
1689 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001690 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1691 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001692 wpa_sm_notify_disassoc(wpa_s->wpa);
1693 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1694 " reason=%d",
1695 MAC2STR(bssid), reason_code);
1696 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1697 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1698 wpa_s->keys_cleared = 0;
1699 wpa_clear_keys(wpa_s, wpa_s->bssid);
1700 }
1701 wpa_supplicant_mark_disassoc(wpa_s);
1702
1703 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1704 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001705
1706 if (fast_reconnect) {
1707#ifndef CONFIG_NO_SCAN_PROCESSING
1708 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1709 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1710 fast_reconnect_ssid) < 0) {
1711 /* Recover through full scan */
1712 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1713 }
1714#endif /* CONFIG_NO_SCAN_PROCESSING */
1715 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001716}
1717
1718
1719#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001720void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001721{
1722 struct wpa_supplicant *wpa_s = eloop_ctx;
1723
1724 if (!wpa_s->pending_mic_error_report)
1725 return;
1726
1727 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1728 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1729 wpa_s->pending_mic_error_report = 0;
1730}
1731#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1732
1733
1734static void
1735wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1736 union wpa_event_data *data)
1737{
1738 int pairwise;
1739 struct os_time t;
1740
1741 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1742 pairwise = (data && data->michael_mic_failure.unicast);
1743 os_get_time(&t);
1744 if ((wpa_s->last_michael_mic_error &&
1745 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1746 wpa_s->pending_mic_error_report) {
1747 if (wpa_s->pending_mic_error_report) {
1748 /*
1749 * Send the pending MIC error report immediately since
1750 * we are going to start countermeasures and AP better
1751 * do the same.
1752 */
1753 wpa_sm_key_request(wpa_s->wpa, 1,
1754 wpa_s->pending_mic_error_pairwise);
1755 }
1756
1757 /* Send the new MIC error report immediately since we are going
1758 * to start countermeasures and AP better do the same.
1759 */
1760 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1761
1762 /* initialize countermeasures */
1763 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001764
1765 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1766
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001767 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1768
1769 /*
1770 * Need to wait for completion of request frame. We do not get
1771 * any callback for the message completion, so just wait a
1772 * short while and hope for the best. */
1773 os_sleep(0, 10000);
1774
1775 wpa_drv_set_countermeasures(wpa_s, 1);
1776 wpa_supplicant_deauthenticate(wpa_s,
1777 WLAN_REASON_MICHAEL_MIC_FAILURE);
1778 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1779 wpa_s, NULL);
1780 eloop_register_timeout(60, 0,
1781 wpa_supplicant_stop_countermeasures,
1782 wpa_s, NULL);
1783 /* TODO: mark the AP rejected for 60 second. STA is
1784 * allowed to associate with another AP.. */
1785 } else {
1786#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1787 if (wpa_s->mic_errors_seen) {
1788 /*
1789 * Reduce the effectiveness of Michael MIC error
1790 * reports as a means for attacking against TKIP if
1791 * more than one MIC failure is noticed with the same
1792 * PTK. We delay the transmission of the reports by a
1793 * random time between 0 and 60 seconds in order to
1794 * force the attacker wait 60 seconds before getting
1795 * the information on whether a frame resulted in a MIC
1796 * failure.
1797 */
1798 u8 rval[4];
1799 int sec;
1800
1801 if (os_get_random(rval, sizeof(rval)) < 0)
1802 sec = os_random() % 60;
1803 else
1804 sec = WPA_GET_BE32(rval) % 60;
1805 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1806 "report %d seconds", sec);
1807 wpa_s->pending_mic_error_report = 1;
1808 wpa_s->pending_mic_error_pairwise = pairwise;
1809 eloop_cancel_timeout(
1810 wpa_supplicant_delayed_mic_error_report,
1811 wpa_s, NULL);
1812 eloop_register_timeout(
1813 sec, os_random() % 1000000,
1814 wpa_supplicant_delayed_mic_error_report,
1815 wpa_s, NULL);
1816 } else {
1817 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1818 }
1819#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1820 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1821#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1822 }
1823 wpa_s->last_michael_mic_error = t.sec;
1824 wpa_s->mic_errors_seen++;
1825}
1826
1827
1828#ifdef CONFIG_TERMINATE_ONLASTIF
1829static int any_interfaces(struct wpa_supplicant *head)
1830{
1831 struct wpa_supplicant *wpa_s;
1832
1833 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1834 if (!wpa_s->interface_removed)
1835 return 1;
1836 return 0;
1837}
1838#endif /* CONFIG_TERMINATE_ONLASTIF */
1839
1840
1841static void
1842wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1843 union wpa_event_data *data)
1844{
1845 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1846 return;
1847
1848 switch (data->interface_status.ievent) {
1849 case EVENT_INTERFACE_ADDED:
1850 if (!wpa_s->interface_removed)
1851 break;
1852 wpa_s->interface_removed = 0;
1853 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
1854 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1855 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
1856 "driver after interface was added");
1857 }
1858 break;
1859 case EVENT_INTERFACE_REMOVED:
1860 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
1861 wpa_s->interface_removed = 1;
1862 wpa_supplicant_mark_disassoc(wpa_s);
1863 l2_packet_deinit(wpa_s->l2);
1864 wpa_s->l2 = NULL;
1865#ifdef CONFIG_IBSS_RSN
1866 ibss_rsn_deinit(wpa_s->ibss_rsn);
1867 wpa_s->ibss_rsn = NULL;
1868#endif /* CONFIG_IBSS_RSN */
1869#ifdef CONFIG_TERMINATE_ONLASTIF
1870 /* check if last interface */
1871 if (!any_interfaces(wpa_s->global->ifaces))
1872 eloop_terminate();
1873#endif /* CONFIG_TERMINATE_ONLASTIF */
1874 break;
1875 }
1876}
1877
1878
1879#ifdef CONFIG_PEERKEY
1880static void
1881wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1882 union wpa_event_data *data)
1883{
1884 if (data == NULL)
1885 return;
1886 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1887}
1888#endif /* CONFIG_PEERKEY */
1889
1890
1891#ifdef CONFIG_TDLS
1892static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
1893 union wpa_event_data *data)
1894{
1895 if (data == NULL)
1896 return;
1897 switch (data->tdls.oper) {
1898 case TDLS_REQUEST_SETUP:
1899 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
1900 break;
1901 case TDLS_REQUEST_TEARDOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001902 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
1903 data->tdls.reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001904 break;
1905 }
1906}
1907#endif /* CONFIG_TDLS */
1908
1909
1910#ifdef CONFIG_IEEE80211R
1911static void
1912wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1913 union wpa_event_data *data)
1914{
1915 if (data == NULL)
1916 return;
1917
1918 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1919 data->ft_ies.ies_len,
1920 data->ft_ies.ft_action,
1921 data->ft_ies.target_ap,
1922 data->ft_ies.ric_ies,
1923 data->ft_ies.ric_ies_len) < 0) {
1924 /* TODO: prevent MLME/driver from trying to associate? */
1925 }
1926}
1927#endif /* CONFIG_IEEE80211R */
1928
1929
1930#ifdef CONFIG_IBSS_RSN
1931static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1932 union wpa_event_data *data)
1933{
1934 struct wpa_ssid *ssid;
1935 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1936 return;
1937 if (data == NULL)
1938 return;
1939 ssid = wpa_s->current_ssid;
1940 if (ssid == NULL)
1941 return;
1942 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
1943 return;
1944
1945 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1946}
1947#endif /* CONFIG_IBSS_RSN */
1948
1949
1950#ifdef CONFIG_IEEE80211R
1951static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1952 size_t len)
1953{
1954 const u8 *sta_addr, *target_ap_addr;
1955 u16 status;
1956
1957 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
1958 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1959 return; /* only SME case supported for now */
1960 if (len < 1 + 2 * ETH_ALEN + 2)
1961 return;
1962 if (data[0] != 2)
1963 return; /* Only FT Action Response is supported for now */
1964 sta_addr = data + 1;
1965 target_ap_addr = data + 1 + ETH_ALEN;
1966 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
1967 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
1968 MACSTR " TargetAP " MACSTR " status %u",
1969 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
1970
1971 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1972 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1973 " in FT Action Response", MAC2STR(sta_addr));
1974 return;
1975 }
1976
1977 if (status) {
1978 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
1979 "failure (status code %d)", status);
1980 /* TODO: report error to FT code(?) */
1981 return;
1982 }
1983
1984 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
1985 len - (1 + 2 * ETH_ALEN + 2), 1,
1986 target_ap_addr, NULL, 0) < 0)
1987 return;
1988
1989#ifdef CONFIG_SME
1990 {
1991 struct wpa_bss *bss;
1992 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
1993 if (bss)
1994 wpa_s->sme.freq = bss->freq;
1995 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
1996 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
1997 WLAN_AUTH_FT);
1998 }
1999#endif /* CONFIG_SME */
2000}
2001#endif /* CONFIG_IEEE80211R */
2002
2003
2004static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2005 struct unprot_deauth *e)
2006{
2007#ifdef CONFIG_IEEE80211W
2008 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2009 "dropped: " MACSTR " -> " MACSTR
2010 " (reason code %u)",
2011 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2012 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2013#endif /* CONFIG_IEEE80211W */
2014}
2015
2016
2017static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2018 struct unprot_disassoc *e)
2019{
2020#ifdef CONFIG_IEEE80211W
2021 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2022 "dropped: " MACSTR " -> " MACSTR
2023 " (reason code %u)",
2024 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2025 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2026#endif /* CONFIG_IEEE80211W */
2027}
2028
2029
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002030static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2031{
2032 u8 action, mode;
2033 const u8 *pos, *end;
2034
2035 if (rx->data == NULL || rx->len == 0)
2036 return;
2037
2038 pos = rx->data;
2039 end = pos + rx->len;
2040 action = *pos++;
2041
2042 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2043 action, MAC2STR(rx->sa));
2044 switch (action) {
2045 case WNM_BSS_TRANS_MGMT_REQ:
2046 if (pos + 5 > end)
2047 break;
2048 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2049 "Request: dialog_token=%u request_mode=0x%x "
2050 "disassoc_timer=%u validity_interval=%u",
2051 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2052 mode = pos[1];
2053 pos += 5;
2054 if (mode & 0x08)
2055 pos += 12; /* BSS Termination Duration */
2056 if (mode & 0x10) {
2057 char url[256];
2058 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2059 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2060 "Transition Management Request "
2061 "(URL)");
2062 break;
2063 }
2064 os_memcpy(url, pos + 1, pos[0]);
2065 url[pos[0]] = '\0';
2066 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2067 "Imminent - session_info_url=%s", url);
2068 }
2069 break;
2070 }
2071}
2072
2073
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002074void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2075 union wpa_event_data *data)
2076{
2077 struct wpa_supplicant *wpa_s = ctx;
2078 u16 reason_code = 0;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002079 int locally_generated = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002080
2081 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2082 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002083 event != EVENT_INTERFACE_STATUS &&
2084 event != EVENT_SCHED_SCAN_STOPPED) {
2085 wpa_dbg(wpa_s, MSG_DEBUG,
2086 "Ignore event %s (%d) while interface is disabled",
2087 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088 return;
2089 }
2090
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002091#ifndef CONFIG_NO_STDOUT_DEBUG
2092{
2093 int level = MSG_DEBUG;
2094
2095 if (event == EVENT_RX_MGMT && data && data->rx_mgmt.frame &&
2096 data->rx_mgmt.frame_len >= 24) {
2097 const struct ieee80211_hdr *hdr;
2098 u16 fc;
2099 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2100 fc = le_to_host16(hdr->frame_control);
2101 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2102 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2103 level = MSG_EXCESSIVE;
2104 }
2105
2106 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2107 event_to_string(event), event);
2108}
2109#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002110
2111 switch (event) {
2112 case EVENT_AUTH:
2113 sme_event_auth(wpa_s, data);
2114 break;
2115 case EVENT_ASSOC:
2116 wpa_supplicant_event_assoc(wpa_s, data);
2117 break;
2118 case EVENT_DISASSOC:
2119 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2120 if (data) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002121 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2122 data->disassoc_info.reason_code,
2123 data->disassoc_info.locally_generated ?
2124 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002125 if (data->disassoc_info.addr)
2126 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2127 MAC2STR(data->disassoc_info.addr));
2128 }
2129#ifdef CONFIG_AP
2130 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2131 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2132 data->disassoc_info.addr);
2133 break;
2134 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002135 if (wpa_s->ap_iface) {
2136 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2137 "AP mode");
2138 break;
2139 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002140#endif /* CONFIG_AP */
2141 if (data) {
2142 reason_code = data->disassoc_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002143 locally_generated =
2144 data->disassoc_info.locally_generated;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002145 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2146 data->disassoc_info.ie,
2147 data->disassoc_info.ie_len);
2148#ifdef CONFIG_P2P
2149 wpas_p2p_disassoc_notif(
2150 wpa_s, data->disassoc_info.addr, reason_code,
2151 data->disassoc_info.ie,
2152 data->disassoc_info.ie_len);
2153#endif /* CONFIG_P2P */
2154 }
2155 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2156 sme_event_disassoc(wpa_s, data);
2157 /* fall through */
2158 case EVENT_DEAUTH:
2159 if (event == EVENT_DEAUTH) {
2160 wpa_dbg(wpa_s, MSG_DEBUG,
2161 "Deauthentication notification");
2162 if (data) {
2163 reason_code = data->deauth_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002164 locally_generated =
2165 data->deauth_info.locally_generated;
2166 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2167 data->deauth_info.reason_code,
2168 data->deauth_info.locally_generated ?
2169 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002170 if (data->deauth_info.addr) {
2171 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2172 MACSTR,
2173 MAC2STR(data->deauth_info.
2174 addr));
2175 }
2176 wpa_hexdump(MSG_DEBUG,
2177 "Deauthentication frame IE(s)",
2178 data->deauth_info.ie,
2179 data->deauth_info.ie_len);
2180#ifdef CONFIG_P2P
2181 wpas_p2p_deauth_notif(
2182 wpa_s, data->deauth_info.addr,
2183 reason_code,
2184 data->deauth_info.ie,
2185 data->deauth_info.ie_len);
2186#endif /* CONFIG_P2P */
2187 }
2188 }
2189#ifdef CONFIG_AP
2190 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2191 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2192 data->deauth_info.addr);
2193 break;
2194 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002195 if (wpa_s->ap_iface) {
2196 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2197 "AP mode");
2198 break;
2199 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002200#endif /* CONFIG_AP */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002201 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2202 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002203 break;
2204 case EVENT_MICHAEL_MIC_FAILURE:
2205 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2206 break;
2207#ifndef CONFIG_NO_SCAN_PROCESSING
2208 case EVENT_SCAN_RESULTS:
2209 wpa_supplicant_event_scan_results(wpa_s, data);
2210 break;
2211#endif /* CONFIG_NO_SCAN_PROCESSING */
2212 case EVENT_ASSOCINFO:
2213 wpa_supplicant_event_associnfo(wpa_s, data);
2214 break;
2215 case EVENT_INTERFACE_STATUS:
2216 wpa_supplicant_event_interface_status(wpa_s, data);
2217 break;
2218 case EVENT_PMKID_CANDIDATE:
2219 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2220 break;
2221#ifdef CONFIG_PEERKEY
2222 case EVENT_STKSTART:
2223 wpa_supplicant_event_stkstart(wpa_s, data);
2224 break;
2225#endif /* CONFIG_PEERKEY */
2226#ifdef CONFIG_TDLS
2227 case EVENT_TDLS:
2228 wpa_supplicant_event_tdls(wpa_s, data);
2229 break;
2230#endif /* CONFIG_TDLS */
2231#ifdef CONFIG_IEEE80211R
2232 case EVENT_FT_RESPONSE:
2233 wpa_supplicant_event_ft_response(wpa_s, data);
2234 break;
2235#endif /* CONFIG_IEEE80211R */
2236#ifdef CONFIG_IBSS_RSN
2237 case EVENT_IBSS_RSN_START:
2238 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2239 break;
2240#endif /* CONFIG_IBSS_RSN */
2241 case EVENT_ASSOC_REJECT:
2242 if (data->assoc_reject.bssid)
2243 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2244 "bssid=" MACSTR " status_code=%u",
2245 MAC2STR(data->assoc_reject.bssid),
2246 data->assoc_reject.status_code);
2247 else
2248 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2249 "status_code=%u",
2250 data->assoc_reject.status_code);
2251 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2252 sme_event_assoc_reject(wpa_s, data);
2253 break;
2254 case EVENT_AUTH_TIMED_OUT:
2255 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2256 sme_event_auth_timed_out(wpa_s, data);
2257 break;
2258 case EVENT_ASSOC_TIMED_OUT:
2259 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2260 sme_event_assoc_timed_out(wpa_s, data);
2261 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002262 case EVENT_TX_STATUS:
2263 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2264 " type=%d stype=%d",
2265 MAC2STR(data->tx_status.dst),
2266 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002267#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002268 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002269#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002270 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2271 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002272 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002273 wpa_s, data->tx_status.dst,
2274 data->tx_status.data,
2275 data->tx_status.data_len,
2276 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002277 OFFCHANNEL_SEND_ACTION_SUCCESS :
2278 OFFCHANNEL_SEND_ACTION_NO_ACK);
2279#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002280 break;
2281 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002282#endif /* CONFIG_AP */
2283#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002284 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2285 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2286 /*
2287 * Catch TX status events for Action frames we sent via group
2288 * interface in GO mode.
2289 */
2290 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2291 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2292 os_memcmp(wpa_s->parent->pending_action_dst,
2293 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002294 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002295 wpa_s->parent, data->tx_status.dst,
2296 data->tx_status.data,
2297 data->tx_status.data_len,
2298 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002299 OFFCHANNEL_SEND_ACTION_SUCCESS :
2300 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002301 break;
2302 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002303#endif /* CONFIG_OFFCHANNEL */
2304#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002305 switch (data->tx_status.type) {
2306 case WLAN_FC_TYPE_MGMT:
2307 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2308 data->tx_status.data_len,
2309 data->tx_status.stype,
2310 data->tx_status.ack);
2311 break;
2312 case WLAN_FC_TYPE_DATA:
2313 ap_tx_status(wpa_s, data->tx_status.dst,
2314 data->tx_status.data,
2315 data->tx_status.data_len,
2316 data->tx_status.ack);
2317 break;
2318 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002319#endif /* CONFIG_AP */
2320 break;
2321#ifdef CONFIG_AP
2322 case EVENT_EAPOL_TX_STATUS:
2323 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2324 data->eapol_tx_status.data,
2325 data->eapol_tx_status.data_len,
2326 data->eapol_tx_status.ack);
2327 break;
2328 case EVENT_DRIVER_CLIENT_POLL_OK:
2329 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002330 break;
2331 case EVENT_RX_FROM_UNKNOWN:
2332 if (wpa_s->ap_iface == NULL)
2333 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002334 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2335 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002336 break;
2337 case EVENT_RX_MGMT:
2338 if (wpa_s->ap_iface == NULL) {
2339#ifdef CONFIG_P2P
2340 u16 fc, stype;
2341 const struct ieee80211_mgmt *mgmt;
2342 mgmt = (const struct ieee80211_mgmt *)
2343 data->rx_mgmt.frame;
2344 fc = le_to_host16(mgmt->frame_control);
2345 stype = WLAN_FC_GET_STYPE(fc);
2346 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2347 data->rx_mgmt.frame_len > 24) {
2348 const u8 *src = mgmt->sa;
2349 const u8 *ie = mgmt->u.probe_req.variable;
2350 size_t ie_len = data->rx_mgmt.frame_len -
2351 (mgmt->u.probe_req.variable -
2352 data->rx_mgmt.frame);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002353 wpas_p2p_probe_req_rx(wpa_s, src, mgmt->da,
2354 mgmt->bssid, ie, ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002355 break;
2356 }
2357#endif /* CONFIG_P2P */
2358 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2359 "management frame in non-AP mode");
2360 break;
2361 }
2362 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2363 break;
2364#endif /* CONFIG_AP */
2365 case EVENT_RX_ACTION:
2366 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2367 " Category=%u DataLen=%d freq=%d MHz",
2368 MAC2STR(data->rx_action.sa),
2369 data->rx_action.category, (int) data->rx_action.len,
2370 data->rx_action.freq);
2371#ifdef CONFIG_IEEE80211R
2372 if (data->rx_action.category == WLAN_ACTION_FT) {
2373 ft_rx_action(wpa_s, data->rx_action.data,
2374 data->rx_action.len);
2375 break;
2376 }
2377#endif /* CONFIG_IEEE80211R */
2378#ifdef CONFIG_IEEE80211W
2379#ifdef CONFIG_SME
2380 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2381 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2382 data->rx_action.data,
2383 data->rx_action.len);
2384 break;
2385 }
2386#endif /* CONFIG_SME */
2387#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002388#ifdef CONFIG_GAS
2389 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2390 gas_query_rx(wpa_s->gas, data->rx_action.da,
2391 data->rx_action.sa, data->rx_action.bssid,
2392 data->rx_action.data, data->rx_action.len,
2393 data->rx_action.freq) == 0)
2394 break;
2395#endif /* CONFIG_GAS */
2396 if (data->rx_action.category == WLAN_ACTION_WNM) {
2397 wnm_action_rx(wpa_s, &data->rx_action);
2398 break;
2399 }
2400#ifdef CONFIG_TDLS
2401 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2402 data->rx_action.len >= 4 &&
2403 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2404 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2405 "Response from " MACSTR,
2406 MAC2STR(data->rx_action.sa));
2407 break;
2408 }
2409#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002410#ifdef CONFIG_P2P
2411 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2412 data->rx_action.sa,
2413 data->rx_action.bssid,
2414 data->rx_action.category,
2415 data->rx_action.data,
2416 data->rx_action.len, data->rx_action.freq);
2417#endif /* CONFIG_P2P */
2418 break;
2419 case EVENT_RX_PROBE_REQ:
2420 if (data->rx_probe_req.sa == NULL ||
2421 data->rx_probe_req.ie == NULL)
2422 break;
2423#ifdef CONFIG_AP
2424 if (wpa_s->ap_iface) {
2425 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2426 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002427 data->rx_probe_req.da,
2428 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002429 data->rx_probe_req.ie,
2430 data->rx_probe_req.ie_len);
2431 break;
2432 }
2433#endif /* CONFIG_AP */
2434#ifdef CONFIG_P2P
2435 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002436 data->rx_probe_req.da,
2437 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002438 data->rx_probe_req.ie,
2439 data->rx_probe_req.ie_len);
2440#endif /* CONFIG_P2P */
2441 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002442 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002443#ifdef CONFIG_OFFCHANNEL
2444 offchannel_remain_on_channel_cb(
2445 wpa_s, data->remain_on_channel.freq,
2446 data->remain_on_channel.duration);
2447#endif /* CONFIG_OFFCHANNEL */
2448#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002449 wpas_p2p_remain_on_channel_cb(
2450 wpa_s, data->remain_on_channel.freq,
2451 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002452#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002453 break;
2454 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002455#ifdef CONFIG_OFFCHANNEL
2456 offchannel_cancel_remain_on_channel_cb(
2457 wpa_s, data->remain_on_channel.freq);
2458#endif /* CONFIG_OFFCHANNEL */
2459#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002460 wpas_p2p_cancel_remain_on_channel_cb(
2461 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002462#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002463 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002464#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002465 case EVENT_P2P_DEV_FOUND: {
2466 struct p2p_peer_info peer_info;
2467
2468 os_memset(&peer_info, 0, sizeof(peer_info));
2469 if (data->p2p_dev_found.dev_addr)
2470 os_memcpy(peer_info.p2p_device_addr,
2471 data->p2p_dev_found.dev_addr, ETH_ALEN);
2472 if (data->p2p_dev_found.pri_dev_type)
2473 os_memcpy(peer_info.pri_dev_type,
2474 data->p2p_dev_found.pri_dev_type,
2475 sizeof(peer_info.pri_dev_type));
2476 if (data->p2p_dev_found.dev_name)
2477 os_strlcpy(peer_info.device_name,
2478 data->p2p_dev_found.dev_name,
2479 sizeof(peer_info.device_name));
2480 peer_info.config_methods = data->p2p_dev_found.config_methods;
2481 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2482 peer_info.group_capab = data->p2p_dev_found.group_capab;
2483
2484 /*
2485 * FIX: new_device=1 is not necessarily correct. We should
2486 * maintain a P2P peer database in wpa_supplicant and update
2487 * this information based on whether the peer is truly new.
2488 */
2489 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2490 break;
2491 }
2492 case EVENT_P2P_GO_NEG_REQ_RX:
2493 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2494 data->p2p_go_neg_req_rx.dev_passwd_id);
2495 break;
2496 case EVENT_P2P_GO_NEG_COMPLETED:
2497 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2498 break;
2499 case EVENT_P2P_PROV_DISC_REQUEST:
2500 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2501 data->p2p_prov_disc_req.config_methods,
2502 data->p2p_prov_disc_req.dev_addr,
2503 data->p2p_prov_disc_req.pri_dev_type,
2504 data->p2p_prov_disc_req.dev_name,
2505 data->p2p_prov_disc_req.supp_config_methods,
2506 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002507 data->p2p_prov_disc_req.group_capab,
2508 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002509 break;
2510 case EVENT_P2P_PROV_DISC_RESPONSE:
2511 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2512 data->p2p_prov_disc_resp.config_methods);
2513 break;
2514 case EVENT_P2P_SD_REQUEST:
2515 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2516 data->p2p_sd_req.sa,
2517 data->p2p_sd_req.dialog_token,
2518 data->p2p_sd_req.update_indic,
2519 data->p2p_sd_req.tlvs,
2520 data->p2p_sd_req.tlvs_len);
2521 break;
2522 case EVENT_P2P_SD_RESPONSE:
2523 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2524 data->p2p_sd_resp.update_indic,
2525 data->p2p_sd_resp.tlvs,
2526 data->p2p_sd_resp.tlvs_len);
2527 break;
2528#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002529 case EVENT_EAPOL_RX:
2530 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2531 data->eapol_rx.data,
2532 data->eapol_rx.data_len);
2533 break;
2534 case EVENT_SIGNAL_CHANGE:
2535 bgscan_notify_signal_change(
2536 wpa_s, data->signal_change.above_threshold,
2537 data->signal_change.current_signal,
2538 data->signal_change.current_noise,
2539 data->signal_change.current_txrate);
2540 break;
2541 case EVENT_INTERFACE_ENABLED:
2542 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2543 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002544 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002545#ifdef CONFIG_AP
2546 if (!wpa_s->ap_iface) {
2547 wpa_supplicant_set_state(wpa_s,
2548 WPA_DISCONNECTED);
2549 wpa_supplicant_req_scan(wpa_s, 0, 0);
2550 } else
2551 wpa_supplicant_set_state(wpa_s,
2552 WPA_COMPLETED);
2553#else /* CONFIG_AP */
2554 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2555 wpa_supplicant_req_scan(wpa_s, 0, 0);
2556#endif /* CONFIG_AP */
2557 }
2558 break;
2559 case EVENT_INTERFACE_DISABLED:
2560 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2561 wpa_supplicant_mark_disassoc(wpa_s);
2562 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2563 break;
2564 case EVENT_CHANNEL_LIST_CHANGED:
2565 if (wpa_s->drv_priv == NULL)
2566 break; /* Ignore event during drv initialization */
2567#ifdef CONFIG_P2P
2568 wpas_p2p_update_channel_list(wpa_s);
2569#endif /* CONFIG_P2P */
2570 break;
2571 case EVENT_INTERFACE_UNAVAILABLE:
2572#ifdef CONFIG_P2P
2573 wpas_p2p_interface_unavailable(wpa_s);
2574#endif /* CONFIG_P2P */
2575 break;
2576 case EVENT_BEST_CHANNEL:
2577 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2578 "(%d %d %d)",
2579 data->best_chan.freq_24, data->best_chan.freq_5,
2580 data->best_chan.freq_overall);
2581 wpa_s->best_24_freq = data->best_chan.freq_24;
2582 wpa_s->best_5_freq = data->best_chan.freq_5;
2583 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2584#ifdef CONFIG_P2P
2585 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2586 data->best_chan.freq_5,
2587 data->best_chan.freq_overall);
2588#endif /* CONFIG_P2P */
2589 break;
2590 case EVENT_UNPROT_DEAUTH:
2591 wpa_supplicant_event_unprot_deauth(wpa_s,
2592 &data->unprot_deauth);
2593 break;
2594 case EVENT_UNPROT_DISASSOC:
2595 wpa_supplicant_event_unprot_disassoc(wpa_s,
2596 &data->unprot_disassoc);
2597 break;
2598 case EVENT_STATION_LOW_ACK:
2599#ifdef CONFIG_AP
2600 if (wpa_s->ap_iface && data)
2601 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2602 data->low_ack.addr);
2603#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002604#ifdef CONFIG_TDLS
2605 if (data)
2606 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2607#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002608 break;
2609 case EVENT_IBSS_PEER_LOST:
2610#ifdef CONFIG_IBSS_RSN
2611 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2612#endif /* CONFIG_IBSS_RSN */
2613 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002614 case EVENT_DRIVER_GTK_REKEY:
2615 if (os_memcmp(data->driver_gtk_rekey.bssid,
2616 wpa_s->bssid, ETH_ALEN))
2617 break;
2618 if (!wpa_s->wpa)
2619 break;
2620 wpa_sm_update_replay_ctr(wpa_s->wpa,
2621 data->driver_gtk_rekey.replay_ctr);
2622 break;
2623 case EVENT_SCHED_SCAN_STOPPED:
2624 wpa_s->sched_scanning = 0;
2625 wpa_supplicant_notify_scanning(wpa_s, 0);
2626
2627 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2628 break;
2629
2630 /*
2631 * If we timed out, start a new sched scan to continue
2632 * searching for more SSIDs.
2633 */
2634 if (wpa_s->sched_scan_timed_out)
2635 wpa_supplicant_req_sched_scan(wpa_s);
2636 break;
2637 case EVENT_WPS_BUTTON_PUSHED:
2638#ifdef CONFIG_WPS
2639 wpas_wps_start_pbc(wpa_s, NULL, 0);
2640#endif /* CONFIG_WPS */
2641 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002642 default:
2643 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
2644 break;
2645 }
2646}