2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "rsn_supp/wpa.h"
22 #include "l2_packet/l2_packet.h"
23 #include "wpa_supplicant_i.h"
25 #include "pcsc_funcs.h"
26 #include "rsn_supp/preauth.h"
27 #include "rsn_supp/pmksa_cache.h"
28 #include "common/wpa_ctrl.h"
29 #include "eap_peer/eap.h"
30 #include "ap/hostapd.h"
32 #include "common/ieee802_11_defs.h"
33 #include "blacklist.h"
34 #include "wpas_glue.h"
35 #include "wps_supplicant.h"
44 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
46 struct wpa_ssid
*ssid
, *old_ssid
;
48 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
)
51 wpa_printf(MSG_DEBUG
, "Select network based on association "
53 ssid
= wpa_supplicant_get_ssid(wpa_s
);
55 wpa_printf(MSG_INFO
, "No network configuration found for the "
61 wpa_printf(MSG_DEBUG
, "Selected network is disabled");
65 wpa_printf(MSG_DEBUG
, "Network configuration found for the current "
67 if (ssid
->key_mgmt
& (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
68 WPA_KEY_MGMT_WPA_NONE
|
69 WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
|
70 WPA_KEY_MGMT_PSK_SHA256
|
71 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
73 size_t wpa_ie_len
= sizeof(wpa_ie
);
74 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
77 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
80 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
81 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
82 old_ssid
= wpa_s
->current_ssid
;
83 wpa_s
->current_ssid
= ssid
;
84 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
85 wpa_supplicant_initiate_eapol(wpa_s
);
86 if (old_ssid
!= wpa_s
->current_ssid
)
87 wpas_notify_network_changed(wpa_s
);
93 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx
,
96 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
98 if (wpa_s
->countermeasures
) {
99 wpa_s
->countermeasures
= 0;
100 wpa_drv_set_countermeasures(wpa_s
, 0);
101 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
102 wpa_supplicant_req_scan(wpa_s
, 0, 0);
107 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
111 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
112 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
113 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
114 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
116 wpas_notify_bssid_changed(wpa_s
);
118 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
119 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
120 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
121 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
122 wpa_s
->ap_ies_from_associnfo
= 0;
126 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
128 struct wpa_ie_data ie
;
132 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
136 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
137 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
138 ie
.pmkid
+ i
* PMKID_LEN
,
140 if (pmksa_set
== 0) {
141 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
146 wpa_printf(MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from PMKSA "
147 "cache", pmksa_set
== 0 ? "" : "not ");
151 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
152 union wpa_event_data
*data
)
155 wpa_printf(MSG_DEBUG
, "RSN: No data in PMKID candidate event");
158 wpa_printf(MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
159 " index=%d preauth=%d",
160 MAC2STR(data
->pmkid_candidate
.bssid
),
161 data
->pmkid_candidate
.index
,
162 data
->pmkid_candidate
.preauth
);
164 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
165 data
->pmkid_candidate
.index
,
166 data
->pmkid_candidate
.preauth
);
170 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
172 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
173 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
176 #ifdef IEEE8021X_EAPOL
177 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
178 wpa_s
->current_ssid
&&
179 !(wpa_s
->current_ssid
->eapol_flags
&
180 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
181 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
182 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
183 * plaintext or static WEP keys). */
186 #endif /* IEEE8021X_EAPOL */
193 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
194 * @wpa_s: pointer to wpa_supplicant data
195 * @ssid: Configuration data for the network
196 * Returns: 0 on success, -1 on failure
198 * This function is called when starting authentication with a network that is
199 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
201 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
202 struct wpa_ssid
*ssid
)
204 #ifdef IEEE8021X_EAPOL
205 int aka
= 0, sim
= 0, type
;
207 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
210 if (ssid
->eap
.eap_methods
== NULL
) {
214 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
215 while (eap
->vendor
!= EAP_VENDOR_IETF
||
216 eap
->method
!= EAP_TYPE_NONE
) {
217 if (eap
->vendor
== EAP_VENDOR_IETF
) {
218 if (eap
->method
== EAP_TYPE_SIM
)
220 else if (eap
->method
== EAP_TYPE_AKA
)
227 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
229 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
233 wpa_printf(MSG_DEBUG
, "Selected network is configured to use "
234 "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
238 wpa_printf(MSG_DEBUG
, "Selected network is configured to use SIM "
239 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
241 type
= SCARD_TRY_BOTH
;
243 type
= SCARD_USIM_ONLY
;
245 type
= SCARD_GSM_SIM_ONLY
;
247 wpa_s
->scard
= scard_init(type
);
248 if (wpa_s
->scard
== NULL
) {
249 wpa_printf(MSG_WARNING
, "Failed to initialize SIM "
253 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
254 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
255 #endif /* IEEE8021X_EAPOL */
261 #ifndef CONFIG_NO_SCAN_PROCESSING
262 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
263 struct wpa_ssid
*ssid
)
267 if (ssid
->mixed_cell
)
271 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
273 #endif /* CONFIG_WPS */
275 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
276 if (ssid
->wep_key_len
[i
]) {
281 #ifdef IEEE8021X_EAPOL
282 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
283 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
284 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
286 #endif /* IEEE8021X_EAPOL */
288 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
294 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
295 struct wpa_ssid
*ssid
,
296 struct wpa_scan_res
*bss
)
298 struct wpa_ie_data ie
;
300 const u8
*rsn_ie
, *wpa_ie
;
303 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
307 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
308 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
311 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
312 wpa_printf(MSG_DEBUG
, " skip RSN IE - parse failed");
315 if (!(ie
.proto
& ssid
->proto
)) {
316 wpa_printf(MSG_DEBUG
, " skip RSN IE - proto "
321 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
322 wpa_printf(MSG_DEBUG
, " skip RSN IE - PTK cipher "
327 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
328 wpa_printf(MSG_DEBUG
, " skip RSN IE - GTK cipher "
333 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
334 wpa_printf(MSG_DEBUG
, " skip RSN IE - key mgmt "
339 #ifdef CONFIG_IEEE80211W
340 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
341 ssid
->ieee80211w
== IEEE80211W_REQUIRED
) {
342 wpa_printf(MSG_DEBUG
, " skip RSN IE - no mgmt frame "
346 #endif /* CONFIG_IEEE80211W */
348 wpa_printf(MSG_DEBUG
, " selected based on RSN IE");
352 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
353 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
356 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
357 wpa_printf(MSG_DEBUG
, " skip WPA IE - parse failed");
360 if (!(ie
.proto
& ssid
->proto
)) {
361 wpa_printf(MSG_DEBUG
, " skip WPA IE - proto "
366 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
367 wpa_printf(MSG_DEBUG
, " skip WPA IE - PTK cipher "
372 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
373 wpa_printf(MSG_DEBUG
, " skip WPA IE - GTK cipher "
378 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
379 wpa_printf(MSG_DEBUG
, " skip WPA IE - key mgmt "
384 wpa_printf(MSG_DEBUG
, " selected based on WPA IE");
388 if (proto_match
== 0)
389 wpa_printf(MSG_DEBUG
, " skip - no WPA/RSN proto match");
395 static struct wpa_bss
*
396 wpa_supplicant_select_bss_wpa(struct wpa_supplicant
*wpa_s
,
397 struct wpa_scan_results
*scan_res
,
398 struct wpa_ssid
*group
,
399 struct wpa_ssid
**selected_ssid
)
401 struct wpa_ssid
*ssid
;
402 struct wpa_scan_res
*bss
;
404 struct wpa_blacklist
*e
;
407 wpa_printf(MSG_DEBUG
, "Try to find WPA-enabled AP");
408 for (i
= 0; i
< scan_res
->num
; i
++) {
410 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
411 bss
= scan_res
->res
[i
];
413 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
414 ssid_
= ie
? ie
+ 2 : (u8
*) "";
415 ssid_len
= ie
? ie
[1] : 0;
417 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
418 wpa_ie_len
= ie
? ie
[1] : 0;
420 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
421 rsn_ie_len
= ie
? ie
[1] : 0;
423 wpa_printf(MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
424 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
425 (int) i
, MAC2STR(bss
->bssid
),
426 wpa_ssid_txt(ssid_
, ssid_len
),
427 wpa_ie_len
, rsn_ie_len
, bss
->caps
);
429 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
430 if (e
&& e
->count
> 1) {
431 wpa_printf(MSG_DEBUG
, " skip - blacklisted");
436 wpa_printf(MSG_DEBUG
, " skip - SSID not known");
440 if (wpa_ie_len
== 0 && rsn_ie_len
== 0) {
441 wpa_printf(MSG_DEBUG
, " skip - no WPA/RSN IE");
445 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
448 if (ssid
->disabled
) {
449 wpa_printf(MSG_DEBUG
, " skip - disabled");
454 if (ssid
->ssid_len
== 0 &&
455 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
457 #endif /* CONFIG_WPS */
460 (ssid_len
!= ssid
->ssid_len
||
461 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
462 wpa_printf(MSG_DEBUG
, " skip - "
467 if (ssid
->bssid_set
&&
468 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0)
470 wpa_printf(MSG_DEBUG
, " skip - "
475 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
478 wpa_printf(MSG_DEBUG
, " selected WPA AP "
481 wpa_ssid_txt(ssid_
, ssid_len
));
482 *selected_ssid
= ssid
;
483 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid_
, ssid_len
);
491 static struct wpa_bss
*
492 wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant
*wpa_s
,
493 struct wpa_scan_results
*scan_res
,
494 struct wpa_ssid
*group
,
495 struct wpa_ssid
**selected_ssid
)
497 struct wpa_ssid
*ssid
;
498 struct wpa_scan_res
*bss
;
500 struct wpa_blacklist
*e
;
503 wpa_printf(MSG_DEBUG
, "Try to find non-WPA AP");
504 for (i
= 0; i
< scan_res
->num
; i
++) {
506 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
507 bss
= scan_res
->res
[i
];
509 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
510 ssid_
= ie
? ie
+ 2 : (u8
*) "";
511 ssid_len
= ie
? ie
[1] : 0;
513 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
514 wpa_ie_len
= ie
? ie
[1] : 0;
516 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
517 rsn_ie_len
= ie
? ie
[1] : 0;
519 wpa_printf(MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
520 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
521 (int) i
, MAC2STR(bss
->bssid
),
522 wpa_ssid_txt(ssid_
, ssid_len
),
523 wpa_ie_len
, rsn_ie_len
, bss
->caps
);
525 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
526 if (e
&& e
->count
> 1) {
527 wpa_printf(MSG_DEBUG
, " skip - blacklisted");
532 wpa_printf(MSG_DEBUG
, " skip - SSID not known");
536 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
537 int check_ssid
= ssid
->ssid_len
!= 0;
539 if (ssid
->disabled
) {
540 wpa_printf(MSG_DEBUG
, " skip - disabled");
545 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
546 /* Only allow wildcard SSID match if an AP
547 * advertises active WPS operation that matches
550 if (ssid
->ssid_len
== 0 &&
551 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
,
555 #endif /* CONFIG_WPS */
558 (ssid_len
!= ssid
->ssid_len
||
559 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
560 wpa_printf(MSG_DEBUG
, " skip - "
565 if (ssid
->bssid_set
&&
566 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0)
568 wpa_printf(MSG_DEBUG
, " skip - "
573 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
574 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
575 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
))
577 wpa_printf(MSG_DEBUG
, " skip - "
578 "non-WPA network not allowed");
582 if ((ssid
->key_mgmt
&
583 (WPA_KEY_MGMT_IEEE8021X
| WPA_KEY_MGMT_PSK
|
584 WPA_KEY_MGMT_FT_IEEE8021X
| WPA_KEY_MGMT_FT_PSK
|
585 WPA_KEY_MGMT_IEEE8021X_SHA256
|
586 WPA_KEY_MGMT_PSK_SHA256
)) &&
587 (wpa_ie_len
!= 0 || rsn_ie_len
!= 0)) {
588 wpa_printf(MSG_DEBUG
, " skip - "
593 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
594 wpa_printf(MSG_DEBUG
, " skip - "
599 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
600 wpa_printf(MSG_DEBUG
, " skip - "
601 "IBSS (adhoc) network");
605 wpa_printf(MSG_DEBUG
, " selected non-WPA AP "
608 wpa_ssid_txt(ssid_
, ssid_len
));
609 *selected_ssid
= ssid
;
610 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid_
, ssid_len
);
618 static struct wpa_bss
*
619 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
620 struct wpa_scan_results
*scan_res
,
621 struct wpa_ssid
*group
,
622 struct wpa_ssid
**selected_ssid
)
624 struct wpa_bss
*selected
;
626 wpa_printf(MSG_DEBUG
, "Selecting BSS from priority group %d",
629 /* First, try to find WPA-enabled AP */
630 selected
= wpa_supplicant_select_bss_wpa(wpa_s
, scan_res
, group
,
635 /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
637 return wpa_supplicant_select_bss_non_wpa(wpa_s
, scan_res
, group
,
642 static struct wpa_bss
*
643 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
644 struct wpa_scan_results
*scan_res
,
645 struct wpa_ssid
**selected_ssid
)
647 struct wpa_bss
*selected
= NULL
;
650 while (selected
== NULL
) {
651 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
652 selected
= wpa_supplicant_select_bss(
653 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
659 if (selected
== NULL
&& wpa_s
->blacklist
) {
660 wpa_printf(MSG_DEBUG
, "No APs found - clear blacklist "
662 wpa_blacklist_clear(wpa_s
);
663 wpa_s
->blacklist_cleared
++;
664 } else if (selected
== NULL
)
672 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
675 if (wpa_s
->scan_res_tried
== 1 && wpa_s
->conf
->ap_scan
== 1) {
677 * Quick recovery if the initial scan results were not
678 * complete when fetched before the first scan request.
680 wpa_s
->scan_res_tried
++;
682 } else if (!wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
684 * No networks are enabled; short-circuit request so
685 * we don't wait timeout seconds before transitioning
688 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
691 wpa_supplicant_req_scan(wpa_s
, timeout
, 0);
695 static void wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
696 struct wpa_bss
*selected
,
697 struct wpa_ssid
*ssid
)
699 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
700 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
701 "PBC session overlap");
702 wpa_supplicant_req_new_scan(wpa_s
, 10);
707 * Do not trigger new association unless the BSSID has changed or if
708 * reassociation is requested. If we are in process of associating with
709 * the selected BSSID, do not trigger new attempt.
711 if (wpa_s
->reassociate
||
712 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
713 (wpa_s
->wpa_state
!= WPA_ASSOCIATING
||
714 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
716 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
717 wpa_supplicant_req_new_scan(wpa_s
, 10);
720 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
722 wpa_printf(MSG_DEBUG
, "Already associated with the selected "
728 static struct wpa_ssid
*
729 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
732 struct wpa_ssid
*ssid
;
734 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
735 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
739 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
740 ssid
->mode
== IEEE80211_MODE_AP
)
748 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
749 * on BSS added and BSS changed events */
750 static void wpa_supplicant_rsn_preauth_scan_results(
751 struct wpa_supplicant
*wpa_s
, struct wpa_scan_results
*scan_res
)
755 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
758 for (i
= scan_res
->num
- 1; i
>= 0; i
--) {
759 const u8
*ssid
, *rsn
;
760 struct wpa_scan_res
*r
;
762 r
= scan_res
->res
[i
];
764 ssid
= wpa_scan_get_ie(r
, WLAN_EID_SSID
);
768 rsn
= wpa_scan_get_ie(r
, WLAN_EID_RSN
);
772 rsn_preauth_scan_result(wpa_s
->wpa
, r
->bssid
, ssid
, rsn
);
778 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
779 union wpa_event_data
*data
)
781 struct wpa_bss
*selected
;
782 struct wpa_ssid
*ssid
= NULL
;
783 struct wpa_scan_results
*scan_res
;
785 wpa_supplicant_notify_scanning(wpa_s
, 0);
787 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
788 data
? &data
->scan_info
:
790 if (scan_res
== NULL
) {
791 if (wpa_s
->conf
->ap_scan
== 2)
793 wpa_printf(MSG_DEBUG
, "Failed to get scan results - try "
795 wpa_supplicant_req_new_scan(wpa_s
, 1);
800 * Don't post the results if this was the initial cached
801 * and there were no results.
803 if (wpa_s
->scan_res_tried
== 1 && wpa_s
->conf
->ap_scan
== 1 &&
804 scan_res
->num
== 0) {
805 wpa_msg(wpa_s
, MSG_DEBUG
, "Cached scan results are "
806 "empty - not posting");
808 wpa_printf(MSG_DEBUG
, "New scan results available");
809 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
810 wpas_notify_scan_results(wpa_s
);
813 wpas_notify_scan_done(wpa_s
, 1);
815 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
816 wpa_scan_results_free(scan_res
);
820 if (wpa_s
->disconnected
) {
821 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
822 wpa_scan_results_free(scan_res
);
826 if (bgscan_notify_scan(wpa_s
) == 1) {
827 wpa_scan_results_free(scan_res
);
831 wpa_supplicant_rsn_preauth_scan_results(wpa_s
, scan_res
);
833 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
834 wpa_scan_results_free(scan_res
);
837 wpa_supplicant_connect(wpa_s
, selected
, ssid
);
839 wpa_printf(MSG_DEBUG
, "No suitable network found");
840 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
842 wpa_printf(MSG_DEBUG
, "Setup a new network");
843 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
845 wpa_supplicant_req_new_scan(wpa_s
, 5);
848 #endif /* CONFIG_NO_SCAN_PROCESSING */
851 #ifdef CONFIG_IEEE80211R
852 static void wpa_assoc_set_ft_params(struct wpa_supplicant
*wpa_s
,
853 const u8
*ftie
, const u8
*mdie
)
855 const u8
*mobility_domain
= NULL
;
856 const u8
*r0kh_id
= NULL
;
857 size_t r0kh_id_len
= 0;
858 const u8
*r1kh_id
= NULL
;
859 struct rsn_ftie
*hdr
;
862 if (mdie
== NULL
|| ftie
== NULL
)
865 if (mdie
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
866 mobility_domain
= mdie
+ 2;
868 wpa_s
->sme
.ft_used
= 1;
869 os_memcpy(wpa_s
->sme
.mobility_domain
, mobility_domain
, 2);
870 #endif /* CONFIG_SME */
872 if (ftie
[1] >= sizeof(struct rsn_ftie
)) {
873 end
= ftie
+ 2 + ftie
[1];
874 hdr
= (struct rsn_ftie
*) (ftie
+ 2);
875 pos
= (const u8
*) (hdr
+ 1);
876 while (pos
+ 1 < end
) {
877 if (pos
+ 2 + pos
[1] > end
)
879 if (pos
[0] == FTIE_SUBELEM_R1KH_ID
&&
880 pos
[1] == FT_R1KH_ID_LEN
)
882 else if (pos
[0] == FTIE_SUBELEM_R0KH_ID
&&
883 pos
[1] >= 1 && pos
[1] <= FT_R0KH_ID_MAX_LEN
) {
885 r0kh_id_len
= pos
[1];
890 wpa_sm_set_ft_params(wpa_s
->wpa
, mobility_domain
, r0kh_id
,
891 r0kh_id_len
, r1kh_id
);
893 #endif /* CONFIG_IEEE80211R */
895 static void wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
896 union wpa_event_data
*data
)
898 int l
, len
, found
= 0, wpa_found
, rsn_found
;
900 #ifdef CONFIG_IEEE80211R
901 const u8
*mdie
= NULL
, *ftie
= NULL
;
902 #endif /* CONFIG_IEEE80211R */
904 wpa_printf(MSG_DEBUG
, "Association info event");
905 if (data
->assoc_info
.req_ies
)
906 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
907 data
->assoc_info
.req_ies_len
);
908 if (data
->assoc_info
.resp_ies
)
909 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
910 data
->assoc_info
.resp_ies_len
);
911 if (data
->assoc_info
.beacon_ies
)
912 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
913 data
->assoc_info
.beacon_ies
,
914 data
->assoc_info
.beacon_ies_len
);
915 if (data
->assoc_info
.freq
)
916 wpa_printf(MSG_DEBUG
, "freq=%u MHz", data
->assoc_info
.freq
);
918 p
= data
->assoc_info
.req_ies
;
919 l
= data
->assoc_info
.req_ies_len
;
921 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
922 while (p
&& l
>= 2) {
925 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
929 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
930 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
931 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
932 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
935 wpa_find_assoc_pmkid(wpa_s
);
941 if (!found
&& data
->assoc_info
.req_ies
)
942 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
944 #ifdef CONFIG_IEEE80211R
945 p
= data
->assoc_info
.resp_ies
;
946 l
= data
->assoc_info
.resp_ies_len
;
948 /* Go through the IEs and make a copy of the FT/MD IE, if present. */
949 while (p
&& l
>= 2) {
952 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
956 if (p
[0] == WLAN_EID_FAST_BSS_TRANSITION
)
958 else if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
)
964 wpa_assoc_set_ft_params(wpa_s
, ftie
, mdie
);
965 #endif /* CONFIG_IEEE80211R */
967 /* WPA/RSN IE from Beacon/ProbeResp */
968 p
= data
->assoc_info
.beacon_ies
;
969 l
= data
->assoc_info
.beacon_ies_len
;
971 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
973 wpa_found
= rsn_found
= 0;
974 while (p
&& l
>= 2) {
977 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
982 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
983 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
985 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
989 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
991 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
998 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
999 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1000 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1001 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1002 if (wpa_found
|| rsn_found
)
1003 wpa_s
->ap_ies_from_associnfo
= 1;
1005 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1009 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1010 union wpa_event_data
*data
)
1015 struct wpa_driver_capa capa
;
1018 if (wpa_s
->ap_iface
) {
1019 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1020 data
->assoc_info
.addr
,
1021 data
->assoc_info
.req_ies
,
1022 data
->assoc_info
.req_ies_len
);
1025 #endif /* CONFIG_AP */
1027 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1029 wpa_supplicant_event_associnfo(wpa_s
, data
);
1031 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1032 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1033 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1034 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) ||
1035 (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1036 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
1037 wpa_msg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1038 MACSTR
, MAC2STR(bssid
));
1039 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1040 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1041 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1043 wpas_notify_bssid_changed(wpa_s
);
1045 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1046 wpa_clear_keys(wpa_s
, bssid
);
1048 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1049 wpa_supplicant_disassociate(
1050 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1053 if (wpa_s
->current_ssid
) {
1054 struct wpa_bss
*bss
= NULL
;
1055 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1056 if (ssid
->ssid_len
> 0)
1057 bss
= wpa_bss_get(wpa_s
, bssid
,
1058 ssid
->ssid
, ssid
->ssid_len
);
1060 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1062 wpa_s
->current_bss
= bss
;
1067 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1068 wpa_s
->sme
.prev_bssid_set
= 1;
1069 #endif /* CONFIG_SME */
1071 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1072 if (wpa_s
->current_ssid
) {
1073 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1074 * initialized before association, but for other modes,
1075 * initialize PC/SC here, if the current configuration needs
1076 * smartcard or SIM/USIM. */
1077 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1079 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1080 l2_packet_notify_auth_start(wpa_s
->l2
);
1083 * Set portEnabled first to FALSE in order to get EAP state machine out
1084 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1085 * state machine may transit to AUTHENTICATING state based on obsolete
1086 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1087 * AUTHENTICATED without ever giving chance to EAP state machine to
1090 if (!ft_completed
) {
1091 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1092 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1094 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1095 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1096 /* 802.1X::portControl = Auto */
1097 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1098 wpa_s
->eapol_received
= 0;
1099 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1100 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1101 (wpa_s
->current_ssid
&&
1102 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1103 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1104 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1105 } else if (!ft_completed
) {
1106 /* Timeout for receiving the first EAPOL packet */
1107 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1109 wpa_supplicant_cancel_scan(wpa_s
);
1111 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1112 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1114 * We are done; the driver will take care of RSN 4-way
1117 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1118 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1119 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1120 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1123 if (wpa_s
->pending_eapol_rx
) {
1124 struct os_time now
, age
;
1126 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1127 if (age
.sec
== 0 && age
.usec
< 100000 &&
1128 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1130 wpa_printf(MSG_DEBUG
, "Process pending EAPOL frame "
1131 "that was received just before association "
1133 wpa_supplicant_rx_eapol(
1134 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1135 wpabuf_head(wpa_s
->pending_eapol_rx
),
1136 wpabuf_len(wpa_s
->pending_eapol_rx
));
1138 wpabuf_free(wpa_s
->pending_eapol_rx
);
1139 wpa_s
->pending_eapol_rx
= NULL
;
1142 #ifdef CONFIG_BGSCAN
1143 if (wpa_s
->current_ssid
!= wpa_s
->bgscan_ssid
) {
1144 bgscan_deinit(wpa_s
);
1145 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
) {
1146 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
)) {
1147 wpa_printf(MSG_DEBUG
, "Failed to initialize "
1150 * Live without bgscan; it is only used as a
1151 * roaming optimization, so the initial
1152 * connection is not affected.
1155 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
1157 wpa_s
->bgscan_ssid
= NULL
;
1159 #endif /* CONFIG_BGSCAN */
1161 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1162 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1163 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1164 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1165 /* Set static WEP keys again */
1166 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1171 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
)
1176 u8 prev_pending_bssid
[ETH_ALEN
];
1178 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1179 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1180 #endif /* CONFIG_SME */
1182 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1184 * At least Host AP driver and a Prism3 card seemed to be
1185 * generating streams of disconnected events when configuring
1186 * IBSS for WPA-None. Ignore them for now.
1188 wpa_printf(MSG_DEBUG
, "Disconnect event - ignore in "
1189 "IBSS/WPA-None mode");
1193 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1194 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1195 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1196 "pre-shared key may be incorrect");
1198 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
)
1199 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1200 bssid
= wpa_s
->bssid
;
1201 if (is_zero_ether_addr(bssid
))
1202 bssid
= wpa_s
->pending_bssid
;
1203 wpa_blacklist_add(wpa_s
, bssid
);
1204 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1205 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"- Disconnect event - "
1207 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1208 wpa_s
->keys_cleared
= 0;
1209 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1211 wpa_supplicant_mark_disassoc(wpa_s
);
1212 bgscan_deinit(wpa_s
);
1214 if (authenticating
&&
1215 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
1217 * mac80211-workaround to force deauth on failed auth cmd,
1218 * requires us to remain in authenticating state to allow the
1219 * second authentication attempt to be continued properly.
1221 wpa_printf(MSG_DEBUG
, "SME: Allow pending authentication to "
1222 "proceed after disconnection event");
1223 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
1224 os_memcpy(wpa_s
->pending_bssid
, prev_pending_bssid
, ETH_ALEN
);
1226 #endif /* CONFIG_SME */
1230 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1231 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
,
1234 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1236 if (!wpa_s
->pending_mic_error_report
)
1239 wpa_printf(MSG_DEBUG
, "WPA: Sending pending MIC error report");
1240 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1241 wpa_s
->pending_mic_error_report
= 0;
1243 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1247 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1248 union wpa_event_data
*data
)
1253 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1254 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1256 if ((wpa_s
->last_michael_mic_error
&&
1257 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1258 wpa_s
->pending_mic_error_report
) {
1259 if (wpa_s
->pending_mic_error_report
) {
1261 * Send the pending MIC error report immediately since
1262 * we are going to start countermeasures and AP better
1265 wpa_sm_key_request(wpa_s
->wpa
, 1,
1266 wpa_s
->pending_mic_error_pairwise
);
1269 /* Send the new MIC error report immediately since we are going
1270 * to start countermeasures and AP better do the same.
1272 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1274 /* initialize countermeasures */
1275 wpa_s
->countermeasures
= 1;
1276 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1279 * Need to wait for completion of request frame. We do not get
1280 * any callback for the message completion, so just wait a
1281 * short while and hope for the best. */
1284 wpa_drv_set_countermeasures(wpa_s
, 1);
1285 wpa_supplicant_deauthenticate(wpa_s
,
1286 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1287 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1289 eloop_register_timeout(60, 0,
1290 wpa_supplicant_stop_countermeasures
,
1292 /* TODO: mark the AP rejected for 60 second. STA is
1293 * allowed to associate with another AP.. */
1295 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1296 if (wpa_s
->mic_errors_seen
) {
1298 * Reduce the effectiveness of Michael MIC error
1299 * reports as a means for attacking against TKIP if
1300 * more than one MIC failure is noticed with the same
1301 * PTK. We delay the transmission of the reports by a
1302 * random time between 0 and 60 seconds in order to
1303 * force the attacker wait 60 seconds before getting
1304 * the information on whether a frame resulted in a MIC
1310 if (os_get_random(rval
, sizeof(rval
)) < 0)
1311 sec
= os_random() % 60;
1313 sec
= WPA_GET_BE32(rval
) % 60;
1314 wpa_printf(MSG_DEBUG
, "WPA: Delay MIC error report %d "
1316 wpa_s
->pending_mic_error_report
= 1;
1317 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1318 eloop_cancel_timeout(
1319 wpa_supplicant_delayed_mic_error_report
,
1321 eloop_register_timeout(
1322 sec
, os_random() % 1000000,
1323 wpa_supplicant_delayed_mic_error_report
,
1326 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1328 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1329 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1330 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1332 wpa_s
->last_michael_mic_error
= t
.sec
;
1333 wpa_s
->mic_errors_seen
++;
1337 #ifdef CONFIG_TERMINATE_ONLASTIF
1338 static int any_interfaces(struct wpa_supplicant
*head
)
1340 struct wpa_supplicant
*wpa_s
;
1342 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1343 if (!wpa_s
->interface_removed
)
1347 #endif /* CONFIG_TERMINATE_ONLASTIF */
1351 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1352 union wpa_event_data
*data
)
1354 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1357 switch (data
->interface_status
.ievent
) {
1358 case EVENT_INTERFACE_ADDED
:
1359 if (!wpa_s
->interface_removed
)
1361 wpa_s
->interface_removed
= 0;
1362 wpa_printf(MSG_DEBUG
, "Configured interface was added.");
1363 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1364 wpa_printf(MSG_INFO
, "Failed to initialize the driver "
1365 "after interface was added.");
1368 case EVENT_INTERFACE_REMOVED
:
1369 wpa_printf(MSG_DEBUG
, "Configured interface was removed.");
1370 wpa_s
->interface_removed
= 1;
1371 wpa_supplicant_mark_disassoc(wpa_s
);
1372 l2_packet_deinit(wpa_s
->l2
);
1374 #ifdef CONFIG_TERMINATE_ONLASTIF
1375 /* check if last interface */
1376 if (!any_interfaces(wpa_s
->global
->ifaces
))
1378 #endif /* CONFIG_TERMINATE_ONLASTIF */
1384 #ifdef CONFIG_PEERKEY
1386 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1387 union wpa_event_data
*data
)
1391 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1393 #endif /* CONFIG_PEERKEY */
1396 #ifdef CONFIG_IEEE80211R
1398 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1399 union wpa_event_data
*data
)
1404 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1405 data
->ft_ies
.ies_len
,
1406 data
->ft_ies
.ft_action
,
1407 data
->ft_ies
.target_ap
,
1408 data
->ft_ies
.ric_ies
,
1409 data
->ft_ies
.ric_ies_len
) < 0) {
1410 /* TODO: prevent MLME/driver from trying to associate? */
1413 #endif /* CONFIG_IEEE80211R */
1416 #ifdef CONFIG_IBSS_RSN
1417 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1418 union wpa_event_data
*data
)
1422 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1424 #endif /* CONFIG_IBSS_RSN */
1427 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1428 union wpa_event_data
*data
)
1430 struct wpa_supplicant
*wpa_s
= ctx
;
1434 sme_event_auth(wpa_s
, data
);
1437 wpa_supplicant_event_assoc(wpa_s
, data
);
1439 case EVENT_DISASSOC
:
1441 if (wpa_s
->ap_iface
&& data
) {
1442 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1443 data
->disassoc_info
.addr
);
1446 #endif /* CONFIG_AP */
1447 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1448 sme_event_disassoc(wpa_s
, data
);
1452 if (wpa_s
->ap_iface
&& data
) {
1453 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1454 data
->deauth_info
.addr
);
1457 #endif /* CONFIG_AP */
1458 wpa_supplicant_event_disassoc(wpa_s
);
1460 case EVENT_MICHAEL_MIC_FAILURE
:
1461 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
1463 #ifndef CONFIG_NO_SCAN_PROCESSING
1464 case EVENT_SCAN_RESULTS
:
1465 wpa_supplicant_event_scan_results(wpa_s
, data
);
1467 #endif /* CONFIG_NO_SCAN_PROCESSING */
1468 case EVENT_ASSOCINFO
:
1469 wpa_supplicant_event_associnfo(wpa_s
, data
);
1471 case EVENT_INTERFACE_STATUS
:
1472 wpa_supplicant_event_interface_status(wpa_s
, data
);
1474 case EVENT_PMKID_CANDIDATE
:
1475 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
1477 #ifdef CONFIG_PEERKEY
1478 case EVENT_STKSTART
:
1479 wpa_supplicant_event_stkstart(wpa_s
, data
);
1481 #endif /* CONFIG_PEERKEY */
1482 #ifdef CONFIG_IEEE80211R
1483 case EVENT_FT_RESPONSE
:
1484 wpa_supplicant_event_ft_response(wpa_s
, data
);
1486 #endif /* CONFIG_IEEE80211R */
1487 #ifdef CONFIG_IBSS_RSN
1488 case EVENT_IBSS_RSN_START
:
1489 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
1491 #endif /* CONFIG_IBSS_RSN */
1492 case EVENT_ASSOC_REJECT
:
1493 sme_event_assoc_reject(wpa_s
, data
);
1495 case EVENT_AUTH_TIMED_OUT
:
1496 sme_event_auth_timed_out(wpa_s
, data
);
1498 case EVENT_ASSOC_TIMED_OUT
:
1499 sme_event_assoc_timed_out(wpa_s
, data
);
1502 case EVENT_TX_STATUS
:
1503 if (wpa_s
->ap_iface
== NULL
)
1505 switch (data
->tx_status
.type
) {
1506 case WLAN_FC_TYPE_MGMT
:
1507 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
1508 data
->tx_status
.data_len
,
1509 data
->tx_status
.stype
,
1510 data
->tx_status
.ack
);
1512 case WLAN_FC_TYPE_DATA
:
1513 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
1514 data
->tx_status
.data
,
1515 data
->tx_status
.data_len
,
1516 data
->tx_status
.ack
);
1520 case EVENT_RX_FROM_UNKNOWN
:
1521 if (wpa_s
->ap_iface
== NULL
)
1523 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.frame
,
1524 data
->rx_from_unknown
.len
);
1527 if (wpa_s
->ap_iface
== NULL
)
1529 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
1531 #endif /* CONFIG_AP */
1532 #ifdef CONFIG_CLIENT_MLME
1533 case EVENT_MLME_RX
: {
1534 struct ieee80211_rx_status rx_status
;
1535 os_memset(&rx_status
, 0, sizeof(rx_status
));
1536 rx_status
.freq
= data
->mlme_rx
.freq
;
1537 rx_status
.channel
= data
->mlme_rx
.channel
;
1538 rx_status
.ssi
= data
->mlme_rx
.ssi
;
1539 ieee80211_sta_rx(wpa_s
, data
->mlme_rx
.buf
, data
->mlme_rx
.len
,
1543 #endif /* CONFIG_CLIENT_MLME */
1544 case EVENT_EAPOL_RX
:
1545 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
1546 data
->eapol_rx
.data
,
1547 data
->eapol_rx
.data_len
);
1550 wpa_printf(MSG_INFO
, "Unknown event %d", event
);