2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2006, 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.
23 #include "wpa_supplicant.h"
25 #include "l2_packet.h"
26 #include "wpa_supplicant_i.h"
27 #include "pcsc_funcs.h"
29 #include "pmksa_cache.h"
32 #include "ctrl_iface_dbus.h"
35 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
37 struct wpa_ssid *ssid;
39 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
42 ssid = wpa_supplicant_get_ssid(wpa_s);
44 wpa_printf(MSG_INFO, "No network configuration found for the "
50 wpa_printf(MSG_DEBUG, "Selected network is disabled");
54 wpa_printf(MSG_DEBUG, "Network configuration found for the current "
56 if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
57 WPA_KEY_MGMT_WPA_NONE)) {
59 size_t wpa_ie_len = sizeof(wpa_ie);
60 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
63 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
66 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
67 eapol_sm_invalidate_cached_session(wpa_s->eapol);
68 wpa_s->current_ssid = ssid;
69 wpa_sm_set_config(wpa_s->wpa, wpa_s->current_ssid);
70 wpa_supplicant_initiate_eapol(wpa_s);
76 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
79 struct wpa_supplicant *wpa_s = eloop_ctx;
81 if (wpa_s->countermeasures) {
82 wpa_s->countermeasures = 0;
83 wpa_drv_set_countermeasures(wpa_s, 0);
84 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
85 wpa_supplicant_req_scan(wpa_s, 0, 0);
90 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
92 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
93 os_memset(wpa_s->bssid, 0, ETH_ALEN);
94 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
95 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
96 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
97 if (wpa_s->key_mgmt == WPA_KEY_MGMT_PSK)
98 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
102 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
104 struct wpa_ie_data ie;
105 int i, pmksa_set = -1;
107 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
111 for (i = 0; i < ie.num_pmkid; i++) {
112 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
113 ie.pmkid + i * PMKID_LEN,
115 if (pmksa_set == 0) {
116 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
121 wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA "
122 "cache", pmksa_set == 0 ? "" : "not ");
126 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
127 union wpa_event_data *data)
130 wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event");
133 wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
134 " index=%d preauth=%d",
135 MAC2STR(data->pmkid_candidate.bssid),
136 data->pmkid_candidate.index,
137 data->pmkid_candidate.preauth);
139 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
140 data->pmkid_candidate.index,
141 data->pmkid_candidate.preauth);
145 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
147 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
148 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
151 #ifdef IEEE8021X_EAPOL
152 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
153 wpa_s->current_ssid &&
154 !(wpa_s->current_ssid->eapol_flags &
155 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
156 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
157 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
158 * plaintext or static WEP keys). */
161 #endif /* IEEE8021X_EAPOL */
168 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
169 * @wpa_s: pointer to wpa_supplicant data
170 * @ssid: Configuration data for the network
171 * Returns: 0 on success, -1 on failure
173 * This function is called when starting authentication with a network that is
174 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
176 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
177 struct wpa_ssid *ssid)
179 #ifdef IEEE8021X_EAPOL
180 int aka = 0, sim = 0, type;
182 if (ssid->pcsc == NULL || wpa_s->scard != NULL)
185 if (ssid->eap_methods == NULL) {
189 struct eap_method_type *eap = ssid->eap_methods;
190 while (eap->vendor != EAP_VENDOR_IETF ||
191 eap->method != EAP_TYPE_NONE) {
192 if (eap->vendor == EAP_VENDOR_IETF) {
193 if (eap->method == EAP_TYPE_SIM)
195 else if (eap->method == EAP_TYPE_AKA)
202 if (eap_sm_get_eap_methods(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
204 if (eap_sm_get_eap_methods(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
208 wpa_printf(MSG_DEBUG, "Selected network is configured to use "
209 "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
213 wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
214 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
216 type = SCARD_TRY_BOTH;
218 type = SCARD_USIM_ONLY;
220 type = SCARD_GSM_SIM_ONLY;
222 wpa_s->scard = scard_init(type);
223 if (wpa_s->scard == NULL) {
224 wpa_printf(MSG_WARNING, "Failed to initialize SIM "
228 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
229 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
230 #endif /* IEEE8021X_EAPOL */
236 static int wpa_supplicant_match_privacy(struct wpa_scan_result *bss,
237 struct wpa_ssid *ssid)
241 if (ssid->mixed_cell)
244 for (i = 0; i < NUM_WEP_KEYS; i++) {
245 if (ssid->wep_key_len[i]) {
250 #ifdef IEEE8021X_EAPOL
251 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
252 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
253 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
255 #endif /* IEEE8021X_EAPOL */
257 if (bss->caps & IEEE80211_CAP_PRIVACY)
263 static int wpa_supplicant_ssid_bss_match(struct wpa_ssid *ssid,
264 struct wpa_scan_result *bss)
266 struct wpa_ie_data ie;
269 while ((ssid->proto & WPA_PROTO_RSN) && bss->rsn_ie_len > 0) {
272 if (wpa_parse_wpa_ie(bss->rsn_ie, bss->rsn_ie_len, &ie)) {
273 wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed");
276 if (!(ie.proto & ssid->proto)) {
277 wpa_printf(MSG_DEBUG, " skip RSN IE - proto "
282 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
283 wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher "
288 if (!(ie.group_cipher & ssid->group_cipher)) {
289 wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher "
294 if (!(ie.key_mgmt & ssid->key_mgmt)) {
295 wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt "
300 #ifdef CONFIG_IEEE80211W
301 if (!(ie.capabilities & WPA_CAPABILITY_MGMT_FRAME_PROTECTION)
302 && ssid->ieee80211w == IEEE80211W_REQUIRED) {
303 wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame "
307 #endif /* CONFIG_IEEE80211W */
309 wpa_printf(MSG_DEBUG, " selected based on RSN IE");
313 while ((ssid->proto & WPA_PROTO_WPA) && bss->wpa_ie_len > 0) {
316 if (wpa_parse_wpa_ie(bss->wpa_ie, bss->wpa_ie_len, &ie)) {
317 wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed");
320 if (!(ie.proto & ssid->proto)) {
321 wpa_printf(MSG_DEBUG, " skip WPA IE - proto "
326 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
327 wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher "
332 if (!(ie.group_cipher & ssid->group_cipher)) {
333 wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher "
338 if (!(ie.key_mgmt & ssid->key_mgmt)) {
339 wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt "
344 wpa_printf(MSG_DEBUG, " selected based on WPA IE");
348 if (proto_match == 0)
349 wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match");
355 static struct wpa_scan_result *
356 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, struct wpa_ssid *group,
357 struct wpa_scan_result *results, int num,
358 struct wpa_ssid **selected_ssid)
360 struct wpa_ssid *ssid;
361 struct wpa_scan_result *bss, *selected = NULL;
363 struct wpa_blacklist *e;
365 wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
370 /* First, try to find WPA-enabled AP */
371 wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP");
372 for (i = 0; i < num && !selected; i++) {
374 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
375 "wpa_ie_len=%lu rsn_ie_len=%lu caps=0x%x",
376 i, MAC2STR(bss->bssid),
377 wpa_ssid_txt(bss->ssid, bss->ssid_len),
378 (unsigned long) bss->wpa_ie_len,
379 (unsigned long) bss->rsn_ie_len, bss->caps);
380 e = wpa_blacklist_get(wpa_s, bss->bssid);
381 if (e && e->count > 1) {
382 wpa_printf(MSG_DEBUG, " skip - blacklisted");
386 if (bss->wpa_ie_len == 0 && bss->rsn_ie_len == 0) {
387 wpa_printf(MSG_DEBUG, " skip - no WPA/RSN IE");
391 for (ssid = group; ssid; ssid = ssid->pnext) {
392 if (ssid->disabled) {
393 wpa_printf(MSG_DEBUG, " skip - disabled");
396 if (bss->ssid_len != ssid->ssid_len ||
397 os_memcmp(bss->ssid, ssid->ssid,
398 bss->ssid_len) != 0) {
399 wpa_printf(MSG_DEBUG, " skip - "
403 if (ssid->bssid_set &&
404 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
406 wpa_printf(MSG_DEBUG, " skip - "
410 if (wpa_supplicant_ssid_bss_match(ssid, bss)) {
412 *selected_ssid = ssid;
413 wpa_printf(MSG_DEBUG, " selected WPA AP "
416 wpa_ssid_txt(bss->ssid,
423 /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
425 wpa_printf(MSG_DEBUG, "Try to find non-WPA AP");
426 for (i = 0; i < num && !selected; i++) {
428 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
429 "wpa_ie_len=%lu rsn_ie_len=%lu caps=0x%x",
430 i, MAC2STR(bss->bssid),
431 wpa_ssid_txt(bss->ssid, bss->ssid_len),
432 (unsigned long) bss->wpa_ie_len,
433 (unsigned long) bss->rsn_ie_len, bss->caps);
434 e = wpa_blacklist_get(wpa_s, bss->bssid);
435 if (e && e->count > 1) {
436 wpa_printf(MSG_DEBUG, " skip - blacklisted");
439 for (ssid = group; ssid; ssid = ssid->pnext) {
440 if (ssid->disabled) {
441 wpa_printf(MSG_DEBUG, " skip - disabled");
444 if (ssid->ssid_len != 0 &&
445 (bss->ssid_len != ssid->ssid_len ||
446 os_memcmp(bss->ssid, ssid->ssid,
447 bss->ssid_len) != 0)) {
448 wpa_printf(MSG_DEBUG, " skip - "
453 if (ssid->bssid_set &&
454 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
456 wpa_printf(MSG_DEBUG, " skip - "
461 if (!(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
462 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA))
464 wpa_printf(MSG_DEBUG, " skip - "
465 "non-WPA network not allowed");
469 if ((ssid->key_mgmt &
470 (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK)) &&
471 (bss->wpa_ie_len != 0 || bss->rsn_ie_len != 0)) {
472 wpa_printf(MSG_DEBUG, " skip - "
477 if (!wpa_supplicant_match_privacy(bss, ssid)) {
478 wpa_printf(MSG_DEBUG, " skip - "
483 if (bss->caps & IEEE80211_CAP_IBSS) {
484 wpa_printf(MSG_DEBUG, " skip - "
485 "IBSS (adhoc) network");
490 *selected_ssid = ssid;
491 wpa_printf(MSG_DEBUG, " selected non-WPA AP "
494 wpa_ssid_txt(bss->ssid, bss->ssid_len));
503 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
505 int num, prio, timeout;
506 struct wpa_scan_result *selected = NULL;
507 struct wpa_ssid *ssid = NULL;
508 struct wpa_scan_result *results;
510 if (wpa_supplicant_get_scan_results(wpa_s) < 0) {
511 if (wpa_s->conf->ap_scan == 2)
513 wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
519 wpa_supplicant_dbus_notify_scan_results(wpa_s);
521 if (wpa_s->conf->ap_scan == 2 || wpa_s->disconnected)
523 results = wpa_s->scan_results;
524 num = wpa_s->num_scan_results;
526 while (selected == NULL) {
527 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
528 selected = wpa_supplicant_select_bss(
529 wpa_s, wpa_s->conf->pssid[prio], results, num,
535 if (selected == NULL && wpa_s->blacklist) {
536 wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
538 wpa_blacklist_clear(wpa_s);
539 } else if (selected == NULL) {
545 /* Do not trigger new association unless the BSSID has changed
546 * or if reassociation is requested. If we are in process of
547 * associating with the selected BSSID, do not trigger new
549 if (wpa_s->reassociate ||
550 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
551 (wpa_s->wpa_state != WPA_ASSOCIATING ||
552 os_memcmp(selected->bssid, wpa_s->pending_bssid,
554 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
555 wpa_supplicant_req_scan(wpa_s, 10, 0);
558 wpa_supplicant_associate(wpa_s, selected, ssid);
560 wpa_printf(MSG_DEBUG, "Already associated with the "
563 rsn_preauth_scan_results(wpa_s->wpa, results, num);
565 wpa_printf(MSG_DEBUG, "No suitable AP found.");
573 if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) {
575 * Quick recovery if the initial scan results were not
576 * complete when fetched before the first scan request.
578 wpa_s->scan_res_tried++;
581 wpa_supplicant_req_scan(wpa_s, timeout, 0);
585 static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
586 union wpa_event_data *data)
588 int l, len, found = 0, wpa_found, rsn_found;
591 wpa_printf(MSG_DEBUG, "Association info event");
592 if (data->assoc_info.req_ies)
593 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
594 data->assoc_info.req_ies_len);
595 if (data->assoc_info.resp_ies)
596 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
597 data->assoc_info.resp_ies_len);
598 if (data->assoc_info.beacon_ies)
599 wpa_hexdump(MSG_DEBUG, "beacon_ies",
600 data->assoc_info.beacon_ies,
601 data->assoc_info.beacon_ies_len);
603 p = data->assoc_info.req_ies;
604 l = data->assoc_info.req_ies_len;
606 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
607 while (p && l >= 2) {
610 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
614 if ((p[0] == GENERIC_INFO_ELEM && p[1] >= 6 &&
615 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
616 (p[0] == RSN_INFO_ELEM && p[1] >= 2)) {
617 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
620 wpa_find_assoc_pmkid(wpa_s);
626 if (!found && data->assoc_info.req_ies)
627 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
629 /* WPA/RSN IE from Beacon/ProbeResp */
630 p = data->assoc_info.beacon_ies;
631 l = data->assoc_info.beacon_ies_len;
633 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
635 wpa_found = rsn_found = 0;
636 while (p && l >= 2) {
639 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
644 p[0] == GENERIC_INFO_ELEM && p[1] >= 6 &&
645 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
647 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
651 p[0] == RSN_INFO_ELEM && p[1] >= 2) {
653 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
660 if (!wpa_found && data->assoc_info.beacon_ies)
661 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
662 if (!rsn_found && data->assoc_info.beacon_ies)
663 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
667 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
668 union wpa_event_data *data)
673 wpa_supplicant_event_associnfo(wpa_s, data);
675 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
676 if (wpa_s->use_client_mlme)
677 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
678 if (wpa_s->use_client_mlme ||
679 (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
680 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
681 wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
682 MACSTR, MAC2STR(bssid));
683 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
684 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
685 if (wpa_supplicant_dynamic_keys(wpa_s)) {
686 wpa_clear_keys(wpa_s, bssid);
688 if (wpa_supplicant_select_config(wpa_s) < 0) {
689 wpa_supplicant_disassociate(wpa_s,
690 REASON_DEAUTH_LEAVING);
695 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
696 if (wpa_s->current_ssid) {
697 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
698 * initialized before association, but for other modes,
699 * initialize PC/SC here, if the current configuration needs
700 * smartcard or SIM/USIM. */
701 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
703 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
704 l2_packet_notify_auth_start(wpa_s->l2);
707 * Set portEnabled first to FALSE in order to get EAP state machine out
708 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
709 * state machine may transit to AUTHENTICATING state based on obsolete
710 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
711 * AUTHENTICATED without ever giving chance to EAP state machine to
714 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
715 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
716 if (wpa_s->key_mgmt == WPA_KEY_MGMT_PSK)
717 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
718 /* 802.1X::portControl = Auto */
719 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
720 wpa_s->eapol_received = 0;
721 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
722 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
723 wpa_supplicant_cancel_auth_timeout(wpa_s);
724 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
726 /* Timeout for receiving the first EAPOL packet */
727 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
729 wpa_supplicant_cancel_scan(wpa_s);
733 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s)
737 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
739 * At least Host AP driver and a Prism3 card seemed to be
740 * generating streams of disconnected events when configuring
741 * IBSS for WPA-None. Ignore them for now.
743 wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
744 "IBSS/WPA-None mode");
748 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
749 wpa_s->key_mgmt == WPA_KEY_MGMT_PSK) {
750 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
751 "pre-shared key may be incorrect");
753 if (wpa_s->wpa_state >= WPA_ASSOCIATED)
754 wpa_supplicant_req_scan(wpa_s, 0, 100000);
755 bssid = wpa_s->bssid;
756 if (os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
757 bssid = wpa_s->pending_bssid;
758 wpa_blacklist_add(wpa_s, bssid);
759 wpa_sm_notify_disassoc(wpa_s->wpa);
760 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "- Disconnect event - "
762 if (wpa_supplicant_dynamic_keys(wpa_s)) {
763 wpa_s->keys_cleared = 0;
764 wpa_clear_keys(wpa_s, wpa_s->bssid);
766 wpa_supplicant_mark_disassoc(wpa_s);
771 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
772 union wpa_event_data *data)
777 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
778 pairwise = (data && data->michael_mic_failure.unicast);
779 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
781 if (wpa_s->last_michael_mic_error &&
782 t.sec - wpa_s->last_michael_mic_error <= 60) {
783 /* initialize countermeasures */
784 wpa_s->countermeasures = 1;
785 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
788 * Need to wait for completion of request frame. We do not get
789 * any callback for the message completion, so just wait a
790 * short while and hope for the best. */
793 wpa_drv_set_countermeasures(wpa_s, 1);
794 wpa_supplicant_deauthenticate(wpa_s,
795 REASON_MICHAEL_MIC_FAILURE);
796 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
798 eloop_register_timeout(60, 0,
799 wpa_supplicant_stop_countermeasures,
801 /* TODO: mark the AP rejected for 60 second. STA is
802 * allowed to associate with another AP.. */
804 wpa_s->last_michael_mic_error = t.sec;
808 #ifdef CONFIG_TERMINATE_ONLASTIF
809 static int any_interfaces(struct wpa_supplicant *head)
811 struct wpa_supplicant *wpa_s;
813 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
814 if (!wpa_s->interface_removed)
818 #endif /* CONFIG_TERMINATE_ONLASTIF */
821 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
822 union wpa_event_data *data)
824 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
827 switch (data->interface_status.ievent) {
828 case EVENT_INTERFACE_ADDED:
829 if (!wpa_s->interface_removed)
831 wpa_s->interface_removed = 0;
832 wpa_printf(MSG_DEBUG, "Configured interface was added.");
833 if (wpa_supplicant_driver_init(wpa_s, 1) < 0) {
834 wpa_printf(MSG_INFO, "Failed to initialize the driver "
835 "after interface was added.");
838 case EVENT_INTERFACE_REMOVED:
839 wpa_printf(MSG_DEBUG, "Configured interface was removed.");
840 wpa_s->interface_removed = 1;
841 wpa_supplicant_mark_disassoc(wpa_s);
842 l2_packet_deinit(wpa_s->l2);
844 #ifdef CONFIG_TERMINATE_ONLASTIF
845 /* check if last interface */
846 if (!any_interfaces(wpa_s->global->ifaces))
848 #endif /* CONFIG_TERMINATE_ONLASTIF */
854 #ifdef CONFIG_PEERKEY
856 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
857 union wpa_event_data *data)
861 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
863 #endif /* CONFIG_PEERKEY */
866 void wpa_supplicant_event(struct wpa_supplicant *wpa_s, wpa_event_type event,
867 union wpa_event_data *data)
871 wpa_supplicant_event_assoc(wpa_s, data);
874 wpa_supplicant_event_disassoc(wpa_s);
876 case EVENT_MICHAEL_MIC_FAILURE:
877 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
879 case EVENT_SCAN_RESULTS:
880 wpa_supplicant_event_scan_results(wpa_s);
882 case EVENT_ASSOCINFO:
883 wpa_supplicant_event_associnfo(wpa_s, data);
885 case EVENT_INTERFACE_STATUS:
886 wpa_supplicant_event_interface_status(wpa_s, data);
888 case EVENT_PMKID_CANDIDATE:
889 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
891 #ifdef CONFIG_PEERKEY
893 wpa_supplicant_event_stkstart(wpa_s, data);
895 #endif /* CONFIG_PEERKEY */
897 wpa_printf(MSG_INFO, "Unknown event %d", event);