2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2008, 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"
21 #include "drivers/driver.h"
23 #include "l2_packet/l2_packet.h"
24 #include "wpa_supplicant_i.h"
25 #include "pcsc_funcs.h"
27 #include "pmksa_cache.h"
29 #include "eap_peer/eap.h"
30 #include "ctrl_iface_dbus.h"
31 #include "ieee802_11_defs.h"
32 #include "blacklist.h"
33 #include "wpas_glue.h"
34 #include "wps_supplicant.h"
38 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
40 struct wpa_ssid
*ssid
;
42 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
)
45 wpa_printf(MSG_DEBUG
, "Select network based on association "
47 ssid
= wpa_supplicant_get_ssid(wpa_s
);
49 wpa_printf(MSG_INFO
, "No network configuration found for the "
55 wpa_printf(MSG_DEBUG
, "Selected network is disabled");
59 wpa_printf(MSG_DEBUG
, "Network configuration found for the current "
61 if (ssid
->key_mgmt
& (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
62 WPA_KEY_MGMT_WPA_NONE
|
63 WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
|
64 WPA_KEY_MGMT_PSK_SHA256
|
65 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
67 size_t wpa_ie_len
= sizeof(wpa_ie
);
68 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
71 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
74 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
75 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
76 wpa_s
->current_ssid
= ssid
;
77 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
78 wpa_supplicant_initiate_eapol(wpa_s
);
84 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx
,
87 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
89 if (wpa_s
->countermeasures
) {
90 wpa_s
->countermeasures
= 0;
91 wpa_drv_set_countermeasures(wpa_s
, 0);
92 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
93 wpa_supplicant_req_scan(wpa_s
, 0, 0);
98 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
100 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
101 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
102 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
103 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
104 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
105 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
106 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
107 wpa_s
->ap_ies_from_associnfo
= 0;
111 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
113 struct wpa_ie_data ie
;
117 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
121 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
122 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
123 ie
.pmkid
+ i
* PMKID_LEN
,
125 if (pmksa_set
== 0) {
126 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
131 wpa_printf(MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from PMKSA "
132 "cache", pmksa_set
== 0 ? "" : "not ");
136 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
137 union wpa_event_data
*data
)
140 wpa_printf(MSG_DEBUG
, "RSN: No data in PMKID candidate event");
143 wpa_printf(MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
144 " index=%d preauth=%d",
145 MAC2STR(data
->pmkid_candidate
.bssid
),
146 data
->pmkid_candidate
.index
,
147 data
->pmkid_candidate
.preauth
);
149 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
150 data
->pmkid_candidate
.index
,
151 data
->pmkid_candidate
.preauth
);
155 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
157 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
158 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
161 #ifdef IEEE8021X_EAPOL
162 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
163 wpa_s
->current_ssid
&&
164 !(wpa_s
->current_ssid
->eapol_flags
&
165 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
166 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
167 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
168 * plaintext or static WEP keys). */
171 #endif /* IEEE8021X_EAPOL */
178 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
179 * @wpa_s: pointer to wpa_supplicant data
180 * @ssid: Configuration data for the network
181 * Returns: 0 on success, -1 on failure
183 * This function is called when starting authentication with a network that is
184 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
186 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
187 struct wpa_ssid
*ssid
)
189 #ifdef IEEE8021X_EAPOL
190 int aka
= 0, sim
= 0, type
;
192 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
195 if (ssid
->eap
.eap_methods
== NULL
) {
199 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
200 while (eap
->vendor
!= EAP_VENDOR_IETF
||
201 eap
->method
!= EAP_TYPE_NONE
) {
202 if (eap
->vendor
== EAP_VENDOR_IETF
) {
203 if (eap
->method
== EAP_TYPE_SIM
)
205 else if (eap
->method
== EAP_TYPE_AKA
)
212 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
214 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
218 wpa_printf(MSG_DEBUG
, "Selected network is configured to use "
219 "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
223 wpa_printf(MSG_DEBUG
, "Selected network is configured to use SIM "
224 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
226 type
= SCARD_TRY_BOTH
;
228 type
= SCARD_USIM_ONLY
;
230 type
= SCARD_GSM_SIM_ONLY
;
232 wpa_s
->scard
= scard_init(type
);
233 if (wpa_s
->scard
== NULL
) {
234 wpa_printf(MSG_WARNING
, "Failed to initialize SIM "
238 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
239 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
240 #endif /* IEEE8021X_EAPOL */
246 #ifndef CONFIG_NO_SCAN_PROCESSING
247 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
248 struct wpa_ssid
*ssid
)
252 if (ssid
->mixed_cell
)
255 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
256 if (ssid
->wep_key_len
[i
]) {
261 #ifdef IEEE8021X_EAPOL
262 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
263 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
264 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
266 #endif /* IEEE8021X_EAPOL */
268 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
274 static int wpa_supplicant_ssid_bss_match(struct wpa_ssid
*ssid
,
275 struct wpa_scan_res
*bss
)
277 struct wpa_ie_data ie
;
279 const u8
*rsn_ie
, *wpa_ie
;
282 ret
= wpas_wps_ssid_bss_match(ssid
, bss
);
286 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
287 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
290 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
291 wpa_printf(MSG_DEBUG
, " skip RSN IE - parse failed");
294 if (!(ie
.proto
& ssid
->proto
)) {
295 wpa_printf(MSG_DEBUG
, " skip RSN IE - proto "
300 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
301 wpa_printf(MSG_DEBUG
, " skip RSN IE - PTK cipher "
306 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
307 wpa_printf(MSG_DEBUG
, " skip RSN IE - GTK cipher "
312 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
313 wpa_printf(MSG_DEBUG
, " skip RSN IE - key mgmt "
318 #ifdef CONFIG_IEEE80211W
319 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
320 ssid
->ieee80211w
== IEEE80211W_REQUIRED
) {
321 wpa_printf(MSG_DEBUG
, " skip RSN IE - no mgmt frame "
325 #endif /* CONFIG_IEEE80211W */
327 wpa_printf(MSG_DEBUG
, " selected based on RSN IE");
331 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
332 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
335 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
336 wpa_printf(MSG_DEBUG
, " skip WPA IE - parse failed");
339 if (!(ie
.proto
& ssid
->proto
)) {
340 wpa_printf(MSG_DEBUG
, " skip WPA IE - proto "
345 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
346 wpa_printf(MSG_DEBUG
, " skip WPA IE - PTK cipher "
351 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
352 wpa_printf(MSG_DEBUG
, " skip WPA IE - GTK cipher "
357 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
358 wpa_printf(MSG_DEBUG
, " skip WPA IE - key mgmt "
363 wpa_printf(MSG_DEBUG
, " selected based on WPA IE");
367 if (proto_match
== 0)
368 wpa_printf(MSG_DEBUG
, " skip - no WPA/RSN proto match");
374 static struct wpa_scan_res
*
375 wpa_supplicant_select_bss_wpa(struct wpa_supplicant
*wpa_s
,
376 struct wpa_ssid
*group
,
377 struct wpa_ssid
**selected_ssid
)
379 struct wpa_ssid
*ssid
;
380 struct wpa_scan_res
*bss
;
382 struct wpa_blacklist
*e
;
385 wpa_printf(MSG_DEBUG
, "Try to find WPA-enabled AP");
386 for (i
= 0; i
< wpa_s
->scan_res
->num
; i
++) {
388 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
389 bss
= wpa_s
->scan_res
->res
[i
];
391 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
392 ssid_
= ie
? ie
+ 2 : (u8
*) "";
393 ssid_len
= ie
? ie
[1] : 0;
395 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
396 wpa_ie_len
= ie
? ie
[1] : 0;
398 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
399 rsn_ie_len
= ie
? ie
[1] : 0;
401 wpa_printf(MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
402 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
403 (int) i
, MAC2STR(bss
->bssid
),
404 wpa_ssid_txt(ssid_
, ssid_len
),
405 wpa_ie_len
, rsn_ie_len
, bss
->caps
);
407 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
408 if (e
&& e
->count
> 1) {
409 wpa_printf(MSG_DEBUG
, " skip - blacklisted");
413 if (wpa_ie_len
== 0 && rsn_ie_len
== 0) {
414 wpa_printf(MSG_DEBUG
, " skip - no WPA/RSN IE");
418 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
421 if (ssid
->disabled
) {
422 wpa_printf(MSG_DEBUG
, " skip - disabled");
427 if (ssid
->ssid_len
== 0 &&
428 wpas_wps_ssid_wildcard_ok(ssid
, bss
))
430 #endif /* CONFIG_WPS */
433 (ssid_len
!= ssid
->ssid_len
||
434 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
435 wpa_printf(MSG_DEBUG
, " skip - "
440 if (ssid
->bssid_set
&&
441 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0)
443 wpa_printf(MSG_DEBUG
, " skip - "
448 if (!wpa_supplicant_ssid_bss_match(ssid
, bss
))
451 wpa_printf(MSG_DEBUG
, " selected WPA AP "
454 wpa_ssid_txt(ssid_
, ssid_len
));
455 *selected_ssid
= ssid
;
464 static struct wpa_scan_res
*
465 wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant
*wpa_s
,
466 struct wpa_ssid
*group
,
467 struct wpa_ssid
**selected_ssid
)
469 struct wpa_ssid
*ssid
;
470 struct wpa_scan_res
*bss
;
472 struct wpa_blacklist
*e
;
475 wpa_printf(MSG_DEBUG
, "Try to find non-WPA AP");
476 for (i
= 0; i
< wpa_s
->scan_res
->num
; i
++) {
478 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
479 bss
= wpa_s
->scan_res
->res
[i
];
481 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
482 ssid_
= ie
? ie
+ 2 : (u8
*) "";
483 ssid_len
= ie
? ie
[1] : 0;
485 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
486 wpa_ie_len
= ie
? ie
[1] : 0;
488 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
489 rsn_ie_len
= ie
? ie
[1] : 0;
491 wpa_printf(MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
492 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
493 (int) i
, MAC2STR(bss
->bssid
),
494 wpa_ssid_txt(ssid_
, ssid_len
),
495 wpa_ie_len
, rsn_ie_len
, bss
->caps
);
497 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
498 if (e
&& e
->count
> 1) {
499 wpa_printf(MSG_DEBUG
, " skip - blacklisted");
503 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
504 int check_ssid
= ssid
->ssid_len
!= 0;
506 if (ssid
->disabled
) {
507 wpa_printf(MSG_DEBUG
, " skip - disabled");
512 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
513 /* Only allow wildcard SSID match if an AP
514 * advertises active WPS operation that matches
517 if (ssid
->ssid_len
== 0 &&
518 wpas_wps_ssid_wildcard_ok(ssid
, bss
))
521 #endif /* CONFIG_WPS */
524 (ssid_len
!= ssid
->ssid_len
||
525 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
526 wpa_printf(MSG_DEBUG
, " skip - "
531 if (ssid
->bssid_set
&&
532 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0)
534 wpa_printf(MSG_DEBUG
, " skip - "
539 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
540 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
541 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
))
543 wpa_printf(MSG_DEBUG
, " skip - "
544 "non-WPA network not allowed");
548 if ((ssid
->key_mgmt
&
549 (WPA_KEY_MGMT_IEEE8021X
| WPA_KEY_MGMT_PSK
|
550 WPA_KEY_MGMT_FT_IEEE8021X
| WPA_KEY_MGMT_FT_PSK
|
551 WPA_KEY_MGMT_IEEE8021X_SHA256
|
552 WPA_KEY_MGMT_PSK_SHA256
)) &&
553 (wpa_ie_len
!= 0 || rsn_ie_len
!= 0)) {
554 wpa_printf(MSG_DEBUG
, " skip - "
559 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
560 wpa_printf(MSG_DEBUG
, " skip - "
565 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
566 wpa_printf(MSG_DEBUG
, " skip - "
567 "IBSS (adhoc) network");
571 wpa_printf(MSG_DEBUG
, " selected non-WPA AP "
574 wpa_ssid_txt(ssid_
, ssid_len
));
575 *selected_ssid
= ssid
;
584 static struct wpa_scan_res
*
585 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*group
,
586 struct wpa_ssid
**selected_ssid
)
588 struct wpa_scan_res
*selected
;
590 wpa_printf(MSG_DEBUG
, "Selecting BSS from priority group %d",
593 /* First, try to find WPA-enabled AP */
594 selected
= wpa_supplicant_select_bss_wpa(wpa_s
, group
, selected_ssid
);
598 /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
600 return wpa_supplicant_select_bss_non_wpa(wpa_s
, group
, selected_ssid
);
604 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
)
607 struct wpa_scan_res
*selected
= NULL
;
608 struct wpa_ssid
*ssid
= NULL
;
610 if (wpa_supplicant_get_scan_results(wpa_s
) < 0) {
611 if (wpa_s
->conf
->ap_scan
== 2)
613 wpa_printf(MSG_DEBUG
, "Failed to get scan results - try "
620 * Don't post the results if this was the initial cached
621 * and there were no results.
623 if (wpa_s
->scan_res_tried
== 1 && wpa_s
->conf
->ap_scan
== 1 &&
624 wpa_s
->scan_res
->num
== 0) {
625 wpa_msg(wpa_s
, MSG_DEBUG
, "Cached scan results are "
626 "empty - not posting");
628 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
629 wpa_supplicant_dbus_notify_scan_results(wpa_s
);
630 wpas_wps_notify_scan_results(wpa_s
);
633 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)) ||
637 while (selected
== NULL
) {
638 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
639 selected
= wpa_supplicant_select_bss(
640 wpa_s
, wpa_s
->conf
->pssid
[prio
], &ssid
);
645 if (selected
== NULL
&& wpa_s
->blacklist
) {
646 wpa_printf(MSG_DEBUG
, "No APs found - clear blacklist "
648 wpa_blacklist_clear(wpa_s
);
649 } else if (selected
== NULL
) {
655 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
656 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
657 "PBC session overlap");
662 /* Do not trigger new association unless the BSSID has changed
663 * or if reassociation is requested. If we are in process of
664 * associating with the selected BSSID, do not trigger new
666 if (wpa_s
->reassociate
||
667 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
668 (wpa_s
->wpa_state
!= WPA_ASSOCIATING
||
669 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
,
671 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
672 wpa_supplicant_req_scan(wpa_s
, 10, 0);
675 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
677 wpa_printf(MSG_DEBUG
, "Already associated with the "
680 rsn_preauth_scan_results(wpa_s
->wpa
, wpa_s
->scan_res
);
682 wpa_printf(MSG_DEBUG
, "No suitable AP found.");
690 if (wpa_s
->scan_res_tried
== 1 && wpa_s
->conf
->ap_scan
== 1) {
692 * Quick recovery if the initial scan results were not
693 * complete when fetched before the first scan request.
695 wpa_s
->scan_res_tried
++;
698 wpa_supplicant_req_scan(wpa_s
, timeout
, 0);
700 #endif /* CONFIG_NO_SCAN_PROCESSING */
703 static void wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
704 union wpa_event_data
*data
)
706 int l
, len
, found
= 0, wpa_found
, rsn_found
;
709 wpa_printf(MSG_DEBUG
, "Association info event");
710 if (data
->assoc_info
.req_ies
)
711 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
712 data
->assoc_info
.req_ies_len
);
713 if (data
->assoc_info
.resp_ies
)
714 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
715 data
->assoc_info
.resp_ies_len
);
716 if (data
->assoc_info
.beacon_ies
)
717 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
718 data
->assoc_info
.beacon_ies
,
719 data
->assoc_info
.beacon_ies_len
);
721 p
= data
->assoc_info
.req_ies
;
722 l
= data
->assoc_info
.req_ies_len
;
724 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
725 while (p
&& l
>= 2) {
728 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
732 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
733 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
734 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
735 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
738 wpa_find_assoc_pmkid(wpa_s
);
744 if (!found
&& data
->assoc_info
.req_ies
)
745 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
747 /* WPA/RSN IE from Beacon/ProbeResp */
748 p
= data
->assoc_info
.beacon_ies
;
749 l
= data
->assoc_info
.beacon_ies_len
;
751 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
753 wpa_found
= rsn_found
= 0;
754 while (p
&& l
>= 2) {
757 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
762 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
763 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
765 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
769 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
771 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
778 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
779 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
780 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
781 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
782 if (wpa_found
|| rsn_found
)
783 wpa_s
->ap_ies_from_associnfo
= 1;
787 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
788 union wpa_event_data
*data
)
791 int ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
794 wpa_supplicant_event_associnfo(wpa_s
, data
);
796 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
797 if (wpa_s
->use_client_mlme
)
798 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
799 if (wpa_s
->use_client_mlme
||
800 (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
801 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
802 wpa_msg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
803 MACSTR
, MAC2STR(bssid
));
804 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
805 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
806 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
807 wpa_clear_keys(wpa_s
, bssid
);
809 if (wpa_supplicant_select_config(wpa_s
) < 0) {
810 wpa_supplicant_disassociate(
811 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
816 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
817 if (wpa_s
->current_ssid
) {
818 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
819 * initialized before association, but for other modes,
820 * initialize PC/SC here, if the current configuration needs
821 * smartcard or SIM/USIM. */
822 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
824 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
825 l2_packet_notify_auth_start(wpa_s
->l2
);
828 * Set portEnabled first to FALSE in order to get EAP state machine out
829 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
830 * state machine may transit to AUTHENTICATING state based on obsolete
831 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
832 * AUTHENTICATED without ever giving chance to EAP state machine to
836 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
837 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
839 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
840 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
841 /* 802.1X::portControl = Auto */
842 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
843 wpa_s
->eapol_received
= 0;
844 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
845 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
846 wpa_supplicant_cancel_auth_timeout(wpa_s
);
847 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
848 } else if (!ft_completed
) {
849 /* Timeout for receiving the first EAPOL packet */
850 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
852 wpa_supplicant_cancel_scan(wpa_s
);
854 if (wpa_s
->driver_4way_handshake
&&
855 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
857 * We are done; the driver will take care of RSN 4-way
860 wpa_supplicant_cancel_auth_timeout(wpa_s
);
861 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
862 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
863 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
868 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
)
872 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
874 * At least Host AP driver and a Prism3 card seemed to be
875 * generating streams of disconnected events when configuring
876 * IBSS for WPA-None. Ignore them for now.
878 wpa_printf(MSG_DEBUG
, "Disconnect event - ignore in "
879 "IBSS/WPA-None mode");
883 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
884 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
885 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
886 "pre-shared key may be incorrect");
888 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
)
889 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
890 bssid
= wpa_s
->bssid
;
891 if (is_zero_ether_addr(bssid
))
892 bssid
= wpa_s
->pending_bssid
;
893 wpa_blacklist_add(wpa_s
, bssid
);
894 wpa_sm_notify_disassoc(wpa_s
->wpa
);
895 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"- Disconnect event - "
897 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
898 wpa_s
->keys_cleared
= 0;
899 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
901 wpa_supplicant_mark_disassoc(wpa_s
);
905 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
906 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
,
909 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
911 if (!wpa_s
->pending_mic_error_report
)
914 wpa_printf(MSG_DEBUG
, "WPA: Sending pending MIC error report");
915 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
916 wpa_s
->pending_mic_error_report
= 0;
918 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
922 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
923 union wpa_event_data
*data
)
928 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
929 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
931 if ((wpa_s
->last_michael_mic_error
&&
932 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
933 wpa_s
->pending_mic_error_report
) {
934 if (wpa_s
->pending_mic_error_report
) {
936 * Send the pending MIC error report immediately since
937 * we are going to start countermeasures and AP better
940 wpa_sm_key_request(wpa_s
->wpa
, 1,
941 wpa_s
->pending_mic_error_pairwise
);
944 /* Send the new MIC error report immediately since we are going
945 * to start countermeasures and AP better do the same.
947 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
949 /* initialize countermeasures */
950 wpa_s
->countermeasures
= 1;
951 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
954 * Need to wait for completion of request frame. We do not get
955 * any callback for the message completion, so just wait a
956 * short while and hope for the best. */
959 wpa_drv_set_countermeasures(wpa_s
, 1);
960 wpa_supplicant_deauthenticate(wpa_s
,
961 WLAN_REASON_MICHAEL_MIC_FAILURE
);
962 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
964 eloop_register_timeout(60, 0,
965 wpa_supplicant_stop_countermeasures
,
967 /* TODO: mark the AP rejected for 60 second. STA is
968 * allowed to associate with another AP.. */
970 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
971 if (wpa_s
->mic_errors_seen
) {
973 * Reduce the effectiveness of Michael MIC error
974 * reports as a means for attacking against TKIP if
975 * more than one MIC failure is noticed with the same
976 * PTK. We delay the transmission of the reports by a
977 * random time between 0 and 60 seconds in order to
978 * force the attacker wait 60 seconds before getting
979 * the information on whether a frame resulted in a MIC
985 if (os_get_random(rval
, sizeof(rval
)) < 0)
986 sec
= os_random() % 60;
988 sec
= WPA_GET_BE32(rval
) % 60;
989 wpa_printf(MSG_DEBUG
, "WPA: Delay MIC error report %d "
991 wpa_s
->pending_mic_error_report
= 1;
992 wpa_s
->pending_mic_error_pairwise
= pairwise
;
993 eloop_cancel_timeout(
994 wpa_supplicant_delayed_mic_error_report
,
996 eloop_register_timeout(
997 sec
, os_random() % 1000000,
998 wpa_supplicant_delayed_mic_error_report
,
1001 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1003 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1004 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1005 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1007 wpa_s
->last_michael_mic_error
= t
.sec
;
1008 wpa_s
->mic_errors_seen
++;
1013 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1014 union wpa_event_data
*data
)
1016 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1019 switch (data
->interface_status
.ievent
) {
1020 case EVENT_INTERFACE_ADDED
:
1021 if (!wpa_s
->interface_removed
)
1023 wpa_s
->interface_removed
= 0;
1024 wpa_printf(MSG_DEBUG
, "Configured interface was added.");
1025 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1026 wpa_printf(MSG_INFO
, "Failed to initialize the driver "
1027 "after interface was added.");
1030 case EVENT_INTERFACE_REMOVED
:
1031 wpa_printf(MSG_DEBUG
, "Configured interface was removed.");
1032 wpa_s
->interface_removed
= 1;
1033 wpa_supplicant_mark_disassoc(wpa_s
);
1034 l2_packet_deinit(wpa_s
->l2
);
1041 #ifdef CONFIG_PEERKEY
1043 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1044 union wpa_event_data
*data
)
1048 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1050 #endif /* CONFIG_PEERKEY */
1053 #ifdef CONFIG_IEEE80211R
1055 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1056 union wpa_event_data
*data
)
1061 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1062 data
->ft_ies
.ies_len
,
1063 data
->ft_ies
.ft_action
,
1064 data
->ft_ies
.target_ap
) < 0) {
1065 /* TODO: prevent MLME/driver from trying to associate? */
1068 #endif /* CONFIG_IEEE80211R */
1071 #ifdef CONFIG_IBSS_RSN
1072 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1073 union wpa_event_data
*data
)
1077 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1079 #endif /* CONFIG_IBSS_RSN */
1082 void wpa_supplicant_event(void *ctx
, wpa_event_type event
,
1083 union wpa_event_data
*data
)
1085 struct wpa_supplicant
*wpa_s
= ctx
;
1089 wpa_supplicant_event_assoc(wpa_s
, data
);
1091 case EVENT_DISASSOC
:
1092 wpa_supplicant_event_disassoc(wpa_s
);
1094 case EVENT_MICHAEL_MIC_FAILURE
:
1095 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
1097 #ifndef CONFIG_NO_SCAN_PROCESSING
1098 case EVENT_SCAN_RESULTS
:
1099 wpa_supplicant_event_scan_results(wpa_s
);
1101 #endif /* CONFIG_NO_SCAN_PROCESSING */
1102 case EVENT_ASSOCINFO
:
1103 wpa_supplicant_event_associnfo(wpa_s
, data
);
1105 case EVENT_INTERFACE_STATUS
:
1106 wpa_supplicant_event_interface_status(wpa_s
, data
);
1108 case EVENT_PMKID_CANDIDATE
:
1109 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
1111 #ifdef CONFIG_PEERKEY
1112 case EVENT_STKSTART
:
1113 wpa_supplicant_event_stkstart(wpa_s
, data
);
1115 #endif /* CONFIG_PEERKEY */
1116 #ifdef CONFIG_IEEE80211R
1117 case EVENT_FT_RESPONSE
:
1118 wpa_supplicant_event_ft_response(wpa_s
, data
);
1120 #endif /* CONFIG_IEEE80211R */
1121 #ifdef CONFIG_IBSS_RSN
1122 case EVENT_IBSS_RSN_START
:
1123 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
1125 #endif /* CONFIG_IBSS_RSN */
1127 wpa_printf(MSG_INFO
, "Unknown event %d", event
);