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