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"
31 #include "common/ieee802_11_defs.h"
32 #include "blacklist.h"
33 #include "wpas_glue.h"
34 #include "wps_supplicant.h"
43 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
45 struct wpa_ssid
*ssid
, *old_ssid
;
47 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
)
50 wpa_printf(MSG_DEBUG
, "Select network based on association "
52 ssid
= wpa_supplicant_get_ssid(wpa_s
);
54 wpa_printf(MSG_INFO
, "No network configuration found for the "
60 wpa_printf(MSG_DEBUG
, "Selected network is disabled");
64 wpa_printf(MSG_DEBUG
, "Network configuration found for the current "
66 if (ssid
->key_mgmt
& (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
67 WPA_KEY_MGMT_WPA_NONE
|
68 WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
|
69 WPA_KEY_MGMT_PSK_SHA256
|
70 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
72 size_t wpa_ie_len
= sizeof(wpa_ie
);
73 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
76 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
79 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
80 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
81 old_ssid
= wpa_s
->current_ssid
;
82 wpa_s
->current_ssid
= ssid
;
83 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
84 wpa_supplicant_initiate_eapol(wpa_s
);
85 if (old_ssid
!= wpa_s
->current_ssid
)
86 wpas_notify_network_changed(wpa_s
);
92 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx
,
95 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
97 if (wpa_s
->countermeasures
) {
98 wpa_s
->countermeasures
= 0;
99 wpa_drv_set_countermeasures(wpa_s
, 0);
100 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
101 wpa_supplicant_req_scan(wpa_s
, 0, 0);
106 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
110 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
111 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
112 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
113 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
115 wpas_notify_bssid_changed(wpa_s
);
117 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
118 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
119 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
120 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
121 wpa_s
->ap_ies_from_associnfo
= 0;
125 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
127 struct wpa_ie_data ie
;
131 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
135 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
136 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
137 ie
.pmkid
+ i
* PMKID_LEN
,
139 if (pmksa_set
== 0) {
140 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
145 wpa_printf(MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from PMKSA "
146 "cache", pmksa_set
== 0 ? "" : "not ");
150 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
151 union wpa_event_data
*data
)
154 wpa_printf(MSG_DEBUG
, "RSN: No data in PMKID candidate event");
157 wpa_printf(MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
158 " index=%d preauth=%d",
159 MAC2STR(data
->pmkid_candidate
.bssid
),
160 data
->pmkid_candidate
.index
,
161 data
->pmkid_candidate
.preauth
);
163 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
164 data
->pmkid_candidate
.index
,
165 data
->pmkid_candidate
.preauth
);
169 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
171 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
172 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
175 #ifdef IEEE8021X_EAPOL
176 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
177 wpa_s
->current_ssid
&&
178 !(wpa_s
->current_ssid
->eapol_flags
&
179 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
180 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
181 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
182 * plaintext or static WEP keys). */
185 #endif /* IEEE8021X_EAPOL */
192 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
193 * @wpa_s: pointer to wpa_supplicant data
194 * @ssid: Configuration data for the network
195 * Returns: 0 on success, -1 on failure
197 * This function is called when starting authentication with a network that is
198 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
200 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
201 struct wpa_ssid
*ssid
)
203 #ifdef IEEE8021X_EAPOL
204 int aka
= 0, sim
= 0, type
;
206 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
209 if (ssid
->eap
.eap_methods
== NULL
) {
213 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
214 while (eap
->vendor
!= EAP_VENDOR_IETF
||
215 eap
->method
!= EAP_TYPE_NONE
) {
216 if (eap
->vendor
== EAP_VENDOR_IETF
) {
217 if (eap
->method
== EAP_TYPE_SIM
)
219 else if (eap
->method
== EAP_TYPE_AKA
)
226 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
228 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
232 wpa_printf(MSG_DEBUG
, "Selected network is configured to use "
233 "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
237 wpa_printf(MSG_DEBUG
, "Selected network is configured to use SIM "
238 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
240 type
= SCARD_TRY_BOTH
;
242 type
= SCARD_USIM_ONLY
;
244 type
= SCARD_GSM_SIM_ONLY
;
246 wpa_s
->scard
= scard_init(type
);
247 if (wpa_s
->scard
== NULL
) {
248 wpa_printf(MSG_WARNING
, "Failed to initialize SIM "
252 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
253 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
254 #endif /* IEEE8021X_EAPOL */
260 #ifndef CONFIG_NO_SCAN_PROCESSING
261 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
262 struct wpa_ssid
*ssid
)
266 if (ssid
->mixed_cell
)
270 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
272 #endif /* CONFIG_WPS */
274 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
275 if (ssid
->wep_key_len
[i
]) {
280 #ifdef IEEE8021X_EAPOL
281 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
282 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
283 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
285 #endif /* IEEE8021X_EAPOL */
287 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
293 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
294 struct wpa_ssid
*ssid
,
295 struct wpa_scan_res
*bss
)
297 struct wpa_ie_data ie
;
299 const u8
*rsn_ie
, *wpa_ie
;
302 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
306 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
307 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
310 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
311 wpa_printf(MSG_DEBUG
, " skip RSN IE - parse failed");
314 if (!(ie
.proto
& ssid
->proto
)) {
315 wpa_printf(MSG_DEBUG
, " skip RSN IE - proto "
320 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
321 wpa_printf(MSG_DEBUG
, " skip RSN IE - PTK cipher "
326 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
327 wpa_printf(MSG_DEBUG
, " skip RSN IE - GTK cipher "
332 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
333 wpa_printf(MSG_DEBUG
, " skip RSN IE - key mgmt "
338 #ifdef CONFIG_IEEE80211W
339 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
340 ssid
->ieee80211w
== IEEE80211W_REQUIRED
) {
341 wpa_printf(MSG_DEBUG
, " skip RSN IE - no mgmt frame "
345 #endif /* CONFIG_IEEE80211W */
347 wpa_printf(MSG_DEBUG
, " selected based on RSN IE");
351 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
352 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
355 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
356 wpa_printf(MSG_DEBUG
, " skip WPA IE - parse failed");
359 if (!(ie
.proto
& ssid
->proto
)) {
360 wpa_printf(MSG_DEBUG
, " skip WPA IE - proto "
365 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
366 wpa_printf(MSG_DEBUG
, " skip WPA IE - PTK cipher "
371 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
372 wpa_printf(MSG_DEBUG
, " skip WPA IE - GTK cipher "
377 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
378 wpa_printf(MSG_DEBUG
, " skip WPA IE - key mgmt "
383 wpa_printf(MSG_DEBUG
, " selected based on WPA IE");
387 if (proto_match
== 0)
388 wpa_printf(MSG_DEBUG
, " skip - no WPA/RSN proto match");
394 static struct wpa_bss
*
395 wpa_supplicant_select_bss_wpa(struct wpa_supplicant
*wpa_s
,
396 struct wpa_scan_results
*scan_res
,
397 struct wpa_ssid
*group
,
398 struct wpa_ssid
**selected_ssid
)
400 struct wpa_ssid
*ssid
;
401 struct wpa_scan_res
*bss
;
403 struct wpa_blacklist
*e
;
406 wpa_printf(MSG_DEBUG
, "Try to find WPA-enabled AP");
407 for (i
= 0; i
< scan_res
->num
; i
++) {
409 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
410 bss
= scan_res
->res
[i
];
412 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
413 ssid_
= ie
? ie
+ 2 : (u8
*) "";
414 ssid_len
= ie
? ie
[1] : 0;
416 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
417 wpa_ie_len
= ie
? ie
[1] : 0;
419 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
420 rsn_ie_len
= ie
? ie
[1] : 0;
422 wpa_printf(MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
423 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
424 (int) i
, MAC2STR(bss
->bssid
),
425 wpa_ssid_txt(ssid_
, ssid_len
),
426 wpa_ie_len
, rsn_ie_len
, bss
->caps
);
428 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
429 if (e
&& e
->count
> 1) {
430 wpa_printf(MSG_DEBUG
, " skip - blacklisted");
435 wpa_printf(MSG_DEBUG
, " skip - SSID not known");
439 if (wpa_ie_len
== 0 && rsn_ie_len
== 0) {
440 wpa_printf(MSG_DEBUG
, " skip - no WPA/RSN IE");
444 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
447 if (ssid
->disabled
) {
448 wpa_printf(MSG_DEBUG
, " skip - disabled");
453 if (ssid
->ssid_len
== 0 &&
454 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
456 #endif /* CONFIG_WPS */
459 (ssid_len
!= ssid
->ssid_len
||
460 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
461 wpa_printf(MSG_DEBUG
, " skip - "
466 if (ssid
->bssid_set
&&
467 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0)
469 wpa_printf(MSG_DEBUG
, " skip - "
474 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
477 wpa_printf(MSG_DEBUG
, " selected WPA AP "
480 wpa_ssid_txt(ssid_
, ssid_len
));
481 *selected_ssid
= ssid
;
482 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid_
, ssid_len
);
490 static struct wpa_bss
*
491 wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant
*wpa_s
,
492 struct wpa_scan_results
*scan_res
,
493 struct wpa_ssid
*group
,
494 struct wpa_ssid
**selected_ssid
)
496 struct wpa_ssid
*ssid
;
497 struct wpa_scan_res
*bss
;
499 struct wpa_blacklist
*e
;
502 wpa_printf(MSG_DEBUG
, "Try to find non-WPA AP");
503 for (i
= 0; i
< scan_res
->num
; i
++) {
505 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
506 bss
= scan_res
->res
[i
];
508 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
509 ssid_
= ie
? ie
+ 2 : (u8
*) "";
510 ssid_len
= ie
? ie
[1] : 0;
512 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
513 wpa_ie_len
= ie
? ie
[1] : 0;
515 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
516 rsn_ie_len
= ie
? ie
[1] : 0;
518 wpa_printf(MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
519 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
520 (int) i
, MAC2STR(bss
->bssid
),
521 wpa_ssid_txt(ssid_
, ssid_len
),
522 wpa_ie_len
, rsn_ie_len
, bss
->caps
);
524 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
525 if (e
&& e
->count
> 1) {
526 wpa_printf(MSG_DEBUG
, " skip - blacklisted");
531 wpa_printf(MSG_DEBUG
, " skip - SSID not known");
535 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
536 int check_ssid
= ssid
->ssid_len
!= 0;
538 if (ssid
->disabled
) {
539 wpa_printf(MSG_DEBUG
, " skip - disabled");
544 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
545 /* Only allow wildcard SSID match if an AP
546 * advertises active WPS operation that matches
549 if (ssid
->ssid_len
== 0 &&
550 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
,
554 #endif /* CONFIG_WPS */
557 (ssid_len
!= ssid
->ssid_len
||
558 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
559 wpa_printf(MSG_DEBUG
, " skip - "
564 if (ssid
->bssid_set
&&
565 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0)
567 wpa_printf(MSG_DEBUG
, " skip - "
572 if (!(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
573 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
574 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
))
576 wpa_printf(MSG_DEBUG
, " skip - "
577 "non-WPA network not allowed");
581 if ((ssid
->key_mgmt
&
582 (WPA_KEY_MGMT_IEEE8021X
| WPA_KEY_MGMT_PSK
|
583 WPA_KEY_MGMT_FT_IEEE8021X
| WPA_KEY_MGMT_FT_PSK
|
584 WPA_KEY_MGMT_IEEE8021X_SHA256
|
585 WPA_KEY_MGMT_PSK_SHA256
)) &&
586 (wpa_ie_len
!= 0 || rsn_ie_len
!= 0)) {
587 wpa_printf(MSG_DEBUG
, " skip - "
592 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
593 wpa_printf(MSG_DEBUG
, " skip - "
598 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
599 wpa_printf(MSG_DEBUG
, " skip - "
600 "IBSS (adhoc) network");
604 wpa_printf(MSG_DEBUG
, " selected non-WPA AP "
607 wpa_ssid_txt(ssid_
, ssid_len
));
608 *selected_ssid
= ssid
;
609 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid_
, ssid_len
);
617 static struct wpa_bss
*
618 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
619 struct wpa_scan_results
*scan_res
,
620 struct wpa_ssid
*group
,
621 struct wpa_ssid
**selected_ssid
)
623 struct wpa_bss
*selected
;
625 wpa_printf(MSG_DEBUG
, "Selecting BSS from priority group %d",
628 /* First, try to find WPA-enabled AP */
629 selected
= wpa_supplicant_select_bss_wpa(wpa_s
, scan_res
, group
,
634 /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
636 return wpa_supplicant_select_bss_non_wpa(wpa_s
, scan_res
, group
,
641 static struct wpa_bss
*
642 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
643 struct wpa_scan_results
*scan_res
,
644 struct wpa_ssid
**selected_ssid
)
646 struct wpa_bss
*selected
= NULL
;
649 while (selected
== NULL
) {
650 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
651 selected
= wpa_supplicant_select_bss(
652 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
658 if (selected
== NULL
&& wpa_s
->blacklist
) {
659 wpa_printf(MSG_DEBUG
, "No APs found - clear blacklist "
661 wpa_blacklist_clear(wpa_s
);
662 wpa_s
->blacklist_cleared
++;
663 } else if (selected
== NULL
)
671 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
674 if (wpa_s
->scan_res_tried
== 1 && wpa_s
->conf
->ap_scan
== 1) {
676 * Quick recovery if the initial scan results were not
677 * complete when fetched before the first scan request.
679 wpa_s
->scan_res_tried
++;
681 } else if (!wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
683 * No networks are enabled; short-circuit request so
684 * we don't wait timeout seconds before transitioning
687 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
690 wpa_supplicant_req_scan(wpa_s
, timeout
, 0);
694 static void wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
695 struct wpa_bss
*selected
,
696 struct wpa_ssid
*ssid
)
698 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
699 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
700 "PBC session overlap");
701 wpa_supplicant_req_new_scan(wpa_s
, 10);
706 * Do not trigger new association unless the BSSID has changed or if
707 * reassociation is requested. If we are in process of associating with
708 * the selected BSSID, do not trigger new attempt.
710 if (wpa_s
->reassociate
||
711 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
712 (wpa_s
->wpa_state
!= WPA_ASSOCIATING
||
713 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
715 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
716 wpa_supplicant_req_new_scan(wpa_s
, 10);
719 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
721 wpa_printf(MSG_DEBUG
, "Already associated with the selected "
727 static struct wpa_ssid
*
728 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
731 struct wpa_ssid
*ssid
;
733 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
734 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
738 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
739 ssid
->mode
== IEEE80211_MODE_AP
)
747 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
748 * on BSS added and BSS changed events */
749 static void wpa_supplicant_rsn_preauth_scan_results(
750 struct wpa_supplicant
*wpa_s
, struct wpa_scan_results
*scan_res
)
754 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
757 for (i
= scan_res
->num
- 1; i
>= 0; i
--) {
758 const u8
*ssid
, *rsn
;
759 struct wpa_scan_res
*r
;
761 r
= scan_res
->res
[i
];
763 ssid
= wpa_scan_get_ie(r
, WLAN_EID_SSID
);
767 rsn
= wpa_scan_get_ie(r
, WLAN_EID_RSN
);
771 rsn_preauth_scan_result(wpa_s
->wpa
, r
->bssid
, ssid
, rsn
);
777 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
778 union wpa_event_data
*data
)
780 struct wpa_bss
*selected
;
781 struct wpa_ssid
*ssid
= NULL
;
782 struct wpa_scan_results
*scan_res
;
784 wpa_supplicant_notify_scanning(wpa_s
, 0);
786 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
787 data
? &data
->scan_info
:
789 if (scan_res
== NULL
) {
790 if (wpa_s
->conf
->ap_scan
== 2)
792 wpa_printf(MSG_DEBUG
, "Failed to get scan results - try "
794 wpa_supplicant_req_new_scan(wpa_s
, 1);
799 * Don't post the results if this was the initial cached
800 * and there were no results.
802 if (wpa_s
->scan_res_tried
== 1 && wpa_s
->conf
->ap_scan
== 1 &&
803 scan_res
->num
== 0) {
804 wpa_msg(wpa_s
, MSG_DEBUG
, "Cached scan results are "
805 "empty - not posting");
807 wpa_printf(MSG_DEBUG
, "New scan results available");
808 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
809 wpas_notify_scan_results(wpa_s
);
812 wpas_notify_scan_done(wpa_s
, 1);
814 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
815 wpa_scan_results_free(scan_res
);
819 if (wpa_s
->disconnected
) {
820 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
821 wpa_scan_results_free(scan_res
);
825 if (bgscan_notify_scan(wpa_s
) == 1) {
826 wpa_scan_results_free(scan_res
);
830 wpa_supplicant_rsn_preauth_scan_results(wpa_s
, scan_res
);
832 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
833 wpa_scan_results_free(scan_res
);
836 wpa_supplicant_connect(wpa_s
, selected
, ssid
);
838 wpa_printf(MSG_DEBUG
, "No suitable network found");
839 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
841 wpa_printf(MSG_DEBUG
, "Setup a new network");
842 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
844 wpa_supplicant_req_new_scan(wpa_s
, 5);
847 #endif /* CONFIG_NO_SCAN_PROCESSING */
850 #ifdef CONFIG_IEEE80211R
851 static void wpa_assoc_set_ft_params(struct wpa_supplicant
*wpa_s
,
852 const u8
*ftie
, const u8
*mdie
)
854 const u8
*mobility_domain
= NULL
;
855 const u8
*r0kh_id
= NULL
;
856 size_t r0kh_id_len
= 0;
857 const u8
*r1kh_id
= NULL
;
858 struct rsn_ftie
*hdr
;
861 if (mdie
== NULL
|| ftie
== NULL
)
864 if (mdie
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
865 mobility_domain
= mdie
+ 2;
867 wpa_s
->sme
.ft_used
= 1;
868 os_memcpy(wpa_s
->sme
.mobility_domain
, mobility_domain
, 2);
869 #endif /* CONFIG_SME */
871 if (ftie
[1] >= sizeof(struct rsn_ftie
)) {
872 end
= ftie
+ 2 + ftie
[1];
873 hdr
= (struct rsn_ftie
*) (ftie
+ 2);
874 pos
= (const u8
*) (hdr
+ 1);
875 while (pos
+ 1 < end
) {
876 if (pos
+ 2 + pos
[1] > end
)
878 if (pos
[0] == FTIE_SUBELEM_R1KH_ID
&&
879 pos
[1] == FT_R1KH_ID_LEN
)
881 else if (pos
[0] == FTIE_SUBELEM_R0KH_ID
&&
882 pos
[1] >= 1 && pos
[1] <= FT_R0KH_ID_MAX_LEN
) {
884 r0kh_id_len
= pos
[1];
889 wpa_sm_set_ft_params(wpa_s
->wpa
, mobility_domain
, r0kh_id
,
890 r0kh_id_len
, r1kh_id
);
892 #endif /* CONFIG_IEEE80211R */
894 static void wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
895 union wpa_event_data
*data
)
897 int l
, len
, found
= 0, wpa_found
, rsn_found
;
899 #ifdef CONFIG_IEEE80211R
900 const u8
*mdie
= NULL
, *ftie
= NULL
;
901 #endif /* CONFIG_IEEE80211R */
903 wpa_printf(MSG_DEBUG
, "Association info event");
904 if (data
->assoc_info
.req_ies
)
905 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
906 data
->assoc_info
.req_ies_len
);
907 if (data
->assoc_info
.resp_ies
)
908 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
909 data
->assoc_info
.resp_ies_len
);
910 if (data
->assoc_info
.beacon_ies
)
911 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
912 data
->assoc_info
.beacon_ies
,
913 data
->assoc_info
.beacon_ies_len
);
914 if (data
->assoc_info
.freq
)
915 wpa_printf(MSG_DEBUG
, "freq=%u MHz", data
->assoc_info
.freq
);
917 p
= data
->assoc_info
.req_ies
;
918 l
= data
->assoc_info
.req_ies_len
;
920 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
921 while (p
&& l
>= 2) {
924 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
928 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
929 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
930 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
931 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
934 wpa_find_assoc_pmkid(wpa_s
);
940 if (!found
&& data
->assoc_info
.req_ies
)
941 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
943 #ifdef CONFIG_IEEE80211R
944 p
= data
->assoc_info
.resp_ies
;
945 l
= data
->assoc_info
.resp_ies_len
;
947 /* Go through the IEs and make a copy of the FT/MD IE, if present. */
948 while (p
&& l
>= 2) {
951 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
955 if (p
[0] == WLAN_EID_FAST_BSS_TRANSITION
)
957 else if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
)
963 wpa_assoc_set_ft_params(wpa_s
, ftie
, mdie
);
964 #endif /* CONFIG_IEEE80211R */
966 /* WPA/RSN IE from Beacon/ProbeResp */
967 p
= data
->assoc_info
.beacon_ies
;
968 l
= data
->assoc_info
.beacon_ies_len
;
970 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
972 wpa_found
= rsn_found
= 0;
973 while (p
&& l
>= 2) {
976 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
981 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
982 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
984 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
988 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
990 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
997 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
998 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
999 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1000 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1001 if (wpa_found
|| rsn_found
)
1002 wpa_s
->ap_ies_from_associnfo
= 1;
1004 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1008 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1009 union wpa_event_data
*data
)
1012 int ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1014 struct wpa_driver_capa capa
;
1017 wpa_supplicant_event_associnfo(wpa_s
, data
);
1019 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1020 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1021 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1022 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) ||
1023 (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1024 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
1025 wpa_msg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1026 MACSTR
, MAC2STR(bssid
));
1027 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1028 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1029 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1031 wpas_notify_bssid_changed(wpa_s
);
1033 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1034 wpa_clear_keys(wpa_s
, bssid
);
1036 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1037 wpa_supplicant_disassociate(
1038 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1041 if (wpa_s
->current_ssid
) {
1042 struct wpa_bss
*bss
= NULL
;
1043 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1044 if (ssid
->ssid_len
> 0)
1045 bss
= wpa_bss_get(wpa_s
, bssid
,
1046 ssid
->ssid
, ssid
->ssid_len
);
1048 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1050 wpa_s
->current_bss
= bss
;
1055 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1056 wpa_s
->sme
.prev_bssid_set
= 1;
1057 #endif /* CONFIG_SME */
1059 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1060 if (wpa_s
->current_ssid
) {
1061 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1062 * initialized before association, but for other modes,
1063 * initialize PC/SC here, if the current configuration needs
1064 * smartcard or SIM/USIM. */
1065 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1067 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1068 l2_packet_notify_auth_start(wpa_s
->l2
);
1071 * Set portEnabled first to FALSE in order to get EAP state machine out
1072 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1073 * state machine may transit to AUTHENTICATING state based on obsolete
1074 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1075 * AUTHENTICATED without ever giving chance to EAP state machine to
1078 if (!ft_completed
) {
1079 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1080 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1082 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1083 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1084 /* 802.1X::portControl = Auto */
1085 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1086 wpa_s
->eapol_received
= 0;
1087 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1088 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1089 (wpa_s
->current_ssid
&&
1090 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1091 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1092 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1093 } else if (!ft_completed
) {
1094 /* Timeout for receiving the first EAPOL packet */
1095 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1097 wpa_supplicant_cancel_scan(wpa_s
);
1099 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1100 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1102 * We are done; the driver will take care of RSN 4-way
1105 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1106 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1107 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1108 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1111 if (wpa_s
->pending_eapol_rx
) {
1112 struct os_time now
, age
;
1114 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1115 if (age
.sec
== 0 && age
.usec
< 100000 &&
1116 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1118 wpa_printf(MSG_DEBUG
, "Process pending EAPOL frame "
1119 "that was received just before association "
1121 wpa_supplicant_rx_eapol(
1122 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1123 wpabuf_head(wpa_s
->pending_eapol_rx
),
1124 wpabuf_len(wpa_s
->pending_eapol_rx
));
1126 wpabuf_free(wpa_s
->pending_eapol_rx
);
1127 wpa_s
->pending_eapol_rx
= NULL
;
1130 #ifdef CONFIG_BGSCAN
1131 if (wpa_s
->current_ssid
!= wpa_s
->bgscan_ssid
) {
1132 bgscan_deinit(wpa_s
);
1133 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
) {
1134 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
)) {
1135 wpa_printf(MSG_DEBUG
, "Failed to initialize "
1138 * Live without bgscan; it is only used as a
1139 * roaming optimization, so the initial
1140 * connection is not affected.
1143 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
1145 wpa_s
->bgscan_ssid
= NULL
;
1147 #endif /* CONFIG_BGSCAN */
1149 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1150 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1151 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1152 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1153 /* Set static WEP keys again */
1154 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1159 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
)
1164 u8 prev_pending_bssid
[ETH_ALEN
];
1166 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1167 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1168 #endif /* CONFIG_SME */
1170 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1172 * At least Host AP driver and a Prism3 card seemed to be
1173 * generating streams of disconnected events when configuring
1174 * IBSS for WPA-None. Ignore them for now.
1176 wpa_printf(MSG_DEBUG
, "Disconnect event - ignore in "
1177 "IBSS/WPA-None mode");
1181 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1182 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1183 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1184 "pre-shared key may be incorrect");
1186 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
)
1187 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1188 bssid
= wpa_s
->bssid
;
1189 if (is_zero_ether_addr(bssid
))
1190 bssid
= wpa_s
->pending_bssid
;
1191 wpa_blacklist_add(wpa_s
, bssid
);
1192 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1193 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"- Disconnect event - "
1195 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1196 wpa_s
->keys_cleared
= 0;
1197 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1199 wpa_supplicant_mark_disassoc(wpa_s
);
1200 bgscan_deinit(wpa_s
);
1202 if (authenticating
&&
1203 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
1205 * mac80211-workaround to force deauth on failed auth cmd,
1206 * requires us to remain in authenticating state to allow the
1207 * second authentication attempt to be continued properly.
1209 wpa_printf(MSG_DEBUG
, "SME: Allow pending authentication to "
1210 "proceed after disconnection event");
1211 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
1212 os_memcpy(wpa_s
->pending_bssid
, prev_pending_bssid
, ETH_ALEN
);
1214 #endif /* CONFIG_SME */
1218 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1219 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
,
1222 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1224 if (!wpa_s
->pending_mic_error_report
)
1227 wpa_printf(MSG_DEBUG
, "WPA: Sending pending MIC error report");
1228 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1229 wpa_s
->pending_mic_error_report
= 0;
1231 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1235 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1236 union wpa_event_data
*data
)
1241 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1242 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1244 if ((wpa_s
->last_michael_mic_error
&&
1245 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1246 wpa_s
->pending_mic_error_report
) {
1247 if (wpa_s
->pending_mic_error_report
) {
1249 * Send the pending MIC error report immediately since
1250 * we are going to start countermeasures and AP better
1253 wpa_sm_key_request(wpa_s
->wpa
, 1,
1254 wpa_s
->pending_mic_error_pairwise
);
1257 /* Send the new MIC error report immediately since we are going
1258 * to start countermeasures and AP better do the same.
1260 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1262 /* initialize countermeasures */
1263 wpa_s
->countermeasures
= 1;
1264 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1267 * Need to wait for completion of request frame. We do not get
1268 * any callback for the message completion, so just wait a
1269 * short while and hope for the best. */
1272 wpa_drv_set_countermeasures(wpa_s
, 1);
1273 wpa_supplicant_deauthenticate(wpa_s
,
1274 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1275 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1277 eloop_register_timeout(60, 0,
1278 wpa_supplicant_stop_countermeasures
,
1280 /* TODO: mark the AP rejected for 60 second. STA is
1281 * allowed to associate with another AP.. */
1283 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1284 if (wpa_s
->mic_errors_seen
) {
1286 * Reduce the effectiveness of Michael MIC error
1287 * reports as a means for attacking against TKIP if
1288 * more than one MIC failure is noticed with the same
1289 * PTK. We delay the transmission of the reports by a
1290 * random time between 0 and 60 seconds in order to
1291 * force the attacker wait 60 seconds before getting
1292 * the information on whether a frame resulted in a MIC
1298 if (os_get_random(rval
, sizeof(rval
)) < 0)
1299 sec
= os_random() % 60;
1301 sec
= WPA_GET_BE32(rval
) % 60;
1302 wpa_printf(MSG_DEBUG
, "WPA: Delay MIC error report %d "
1304 wpa_s
->pending_mic_error_report
= 1;
1305 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1306 eloop_cancel_timeout(
1307 wpa_supplicant_delayed_mic_error_report
,
1309 eloop_register_timeout(
1310 sec
, os_random() % 1000000,
1311 wpa_supplicant_delayed_mic_error_report
,
1314 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1316 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1317 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1318 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1320 wpa_s
->last_michael_mic_error
= t
.sec
;
1321 wpa_s
->mic_errors_seen
++;
1325 #ifdef CONFIG_TERMINATE_ONLASTIF
1326 static int any_interfaces(struct wpa_supplicant
*head
)
1328 struct wpa_supplicant
*wpa_s
;
1330 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1331 if (!wpa_s
->interface_removed
)
1335 #endif /* CONFIG_TERMINATE_ONLASTIF */
1339 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1340 union wpa_event_data
*data
)
1342 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1345 switch (data
->interface_status
.ievent
) {
1346 case EVENT_INTERFACE_ADDED
:
1347 if (!wpa_s
->interface_removed
)
1349 wpa_s
->interface_removed
= 0;
1350 wpa_printf(MSG_DEBUG
, "Configured interface was added.");
1351 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1352 wpa_printf(MSG_INFO
, "Failed to initialize the driver "
1353 "after interface was added.");
1356 case EVENT_INTERFACE_REMOVED
:
1357 wpa_printf(MSG_DEBUG
, "Configured interface was removed.");
1358 wpa_s
->interface_removed
= 1;
1359 wpa_supplicant_mark_disassoc(wpa_s
);
1360 l2_packet_deinit(wpa_s
->l2
);
1362 #ifdef CONFIG_TERMINATE_ONLASTIF
1363 /* check if last interface */
1364 if (!any_interfaces(wpa_s
->global
->ifaces
))
1366 #endif /* CONFIG_TERMINATE_ONLASTIF */
1372 #ifdef CONFIG_PEERKEY
1374 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1375 union wpa_event_data
*data
)
1379 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1381 #endif /* CONFIG_PEERKEY */
1384 #ifdef CONFIG_IEEE80211R
1386 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1387 union wpa_event_data
*data
)
1392 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1393 data
->ft_ies
.ies_len
,
1394 data
->ft_ies
.ft_action
,
1395 data
->ft_ies
.target_ap
,
1396 data
->ft_ies
.ric_ies
,
1397 data
->ft_ies
.ric_ies_len
) < 0) {
1398 /* TODO: prevent MLME/driver from trying to associate? */
1401 #endif /* CONFIG_IEEE80211R */
1404 #ifdef CONFIG_IBSS_RSN
1405 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1406 union wpa_event_data
*data
)
1410 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1412 #endif /* CONFIG_IBSS_RSN */
1415 void wpa_supplicant_event(void *ctx
, wpa_event_type event
,
1416 union wpa_event_data
*data
)
1418 struct wpa_supplicant
*wpa_s
= ctx
;
1422 sme_event_auth(wpa_s
, data
);
1425 wpa_supplicant_event_assoc(wpa_s
, data
);
1427 case EVENT_DISASSOC
:
1428 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1429 sme_event_disassoc(wpa_s
, data
);
1432 wpa_supplicant_event_disassoc(wpa_s
);
1434 case EVENT_MICHAEL_MIC_FAILURE
:
1435 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
1437 #ifndef CONFIG_NO_SCAN_PROCESSING
1438 case EVENT_SCAN_RESULTS
:
1439 wpa_supplicant_event_scan_results(wpa_s
, data
);
1441 #endif /* CONFIG_NO_SCAN_PROCESSING */
1442 case EVENT_ASSOCINFO
:
1443 wpa_supplicant_event_associnfo(wpa_s
, data
);
1445 case EVENT_INTERFACE_STATUS
:
1446 wpa_supplicant_event_interface_status(wpa_s
, data
);
1448 case EVENT_PMKID_CANDIDATE
:
1449 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
1451 #ifdef CONFIG_PEERKEY
1452 case EVENT_STKSTART
:
1453 wpa_supplicant_event_stkstart(wpa_s
, data
);
1455 #endif /* CONFIG_PEERKEY */
1456 #ifdef CONFIG_IEEE80211R
1457 case EVENT_FT_RESPONSE
:
1458 wpa_supplicant_event_ft_response(wpa_s
, data
);
1460 #endif /* CONFIG_IEEE80211R */
1461 #ifdef CONFIG_IBSS_RSN
1462 case EVENT_IBSS_RSN_START
:
1463 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
1465 #endif /* CONFIG_IBSS_RSN */
1466 case EVENT_ASSOC_REJECT
:
1467 sme_event_assoc_reject(wpa_s
, data
);
1469 case EVENT_AUTH_TIMED_OUT
:
1470 sme_event_auth_timed_out(wpa_s
, data
);
1472 case EVENT_ASSOC_TIMED_OUT
:
1473 sme_event_assoc_timed_out(wpa_s
, data
);
1476 case EVENT_TX_STATUS
:
1477 if (wpa_s
->ap_iface
== NULL
)
1479 switch (data
->tx_status
.type
) {
1480 case WLAN_FC_TYPE_MGMT
:
1481 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
1482 data
->tx_status
.data_len
,
1483 data
->tx_status
.stype
,
1484 data
->tx_status
.ack
);
1486 case WLAN_FC_TYPE_DATA
:
1487 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
1488 data
->tx_status
.data
,
1489 data
->tx_status
.data_len
,
1490 data
->tx_status
.ack
);
1494 case EVENT_RX_FROM_UNKNOWN
:
1495 if (wpa_s
->ap_iface
== NULL
)
1497 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.hdr
,
1498 data
->rx_from_unknown
.len
);
1501 if (wpa_s
->ap_iface
== NULL
)
1503 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
1505 #endif /* CONFIG_AP */
1506 #ifdef CONFIG_CLIENT_MLME
1507 case EVENT_MLME_RX
: {
1508 struct ieee80211_rx_status rx_status
;
1509 os_memset(&rx_status
, 0, sizeof(rx_status
));
1510 rx_status
.freq
= data
->mlme_rx
.freq
;
1511 rx_status
.channel
= data
->mlme_rx
.channel
;
1512 rx_status
.ssi
= data
->mlme_rx
.ssi
;
1513 ieee80211_sta_rx(wpa_s
, data
->mlme_rx
.buf
, data
->mlme_rx
.len
,
1517 #endif /* CONFIG_CLIENT_MLME */
1520 wpa_printf(MSG_INFO
, "Unknown event %d", event
);