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.
21 #include "wpa_supplicant.h"
23 #include "l2_packet.h"
24 #include "wpa_supplicant_i.h"
25 #include "pcsc_funcs.h"
27 #include "pmksa_cache.h"
30 #include "ctrl_iface_dbus.h"
33 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
35 struct wpa_ssid *ssid;
37 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
40 ssid = wpa_supplicant_get_ssid(wpa_s);
42 wpa_printf(MSG_INFO, "No network configuration found for the "
48 wpa_printf(MSG_DEBUG, "Selected network is disabled");
52 wpa_printf(MSG_DEBUG, "Network configuration found for the current "
54 if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
55 WPA_KEY_MGMT_WPA_NONE)) {
57 size_t wpa_ie_len = sizeof(wpa_ie);
58 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
61 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
64 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
65 eapol_sm_invalidate_cached_session(wpa_s->eapol);
66 wpa_s->current_ssid = ssid;
67 wpa_sm_set_config(wpa_s->wpa, wpa_s->current_ssid);
68 wpa_supplicant_initiate_eapol(wpa_s);
74 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
77 struct wpa_supplicant *wpa_s = eloop_ctx;
79 if (wpa_s->countermeasures) {
80 wpa_s->countermeasures = 0;
81 wpa_drv_set_countermeasures(wpa_s, 0);
82 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
83 wpa_supplicant_req_scan(wpa_s, 0, 0);
88 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
90 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
91 os_memset(wpa_s->bssid, 0, ETH_ALEN);
92 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
93 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
94 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
95 if (wpa_s->key_mgmt == WPA_KEY_MGMT_PSK)
96 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
100 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
102 struct wpa_ie_data ie;
103 int i, pmksa_set = -1;
105 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
109 for (i = 0; i < ie.num_pmkid; i++) {
110 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
111 ie.pmkid + i * PMKID_LEN,
113 if (pmksa_set == 0) {
114 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
119 wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA "
120 "cache", pmksa_set == 0 ? "" : "not ");
124 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
125 union wpa_event_data *data)
128 wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event");
131 wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
132 " index=%d preauth=%d",
133 MAC2STR(data->pmkid_candidate.bssid),
134 data->pmkid_candidate.index,
135 data->pmkid_candidate.preauth);
137 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
138 data->pmkid_candidate.index,
139 data->pmkid_candidate.preauth);
143 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
145 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
146 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
149 #ifdef IEEE8021X_EAPOL
150 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
151 wpa_s->current_ssid &&
152 !(wpa_s->current_ssid->eapol_flags &
153 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
154 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
155 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
156 * plaintext or static WEP keys). */
159 #endif /* IEEE8021X_EAPOL */
166 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
167 * @wpa_s: pointer to wpa_supplicant data
168 * @ssid: Configuration data for the network
169 * Returns: 0 on success, -1 on failure
171 * This function is called when starting authentication with a network that is
172 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
174 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
175 struct wpa_ssid *ssid)
177 #ifdef IEEE8021X_EAPOL
178 int aka = 0, sim = 0, type;
180 if (ssid->pcsc == NULL || wpa_s->scard != NULL)
183 if (ssid->eap_methods == NULL) {
187 struct eap_method_type *eap = ssid->eap_methods;
188 while (eap->vendor != EAP_VENDOR_IETF ||
189 eap->method != EAP_TYPE_NONE) {
190 if (eap->vendor == EAP_VENDOR_IETF) {
191 if (eap->method == EAP_TYPE_SIM)
193 else if (eap->method == EAP_TYPE_AKA)
200 if (eap_sm_get_eap_methods(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
202 if (eap_sm_get_eap_methods(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
206 wpa_printf(MSG_DEBUG, "Selected network is configured to use "
207 "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
211 wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
212 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
214 type = SCARD_TRY_BOTH;
216 type = SCARD_USIM_ONLY;
218 type = SCARD_GSM_SIM_ONLY;
220 wpa_s->scard = scard_init(type);
221 if (wpa_s->scard == NULL) {
222 wpa_printf(MSG_WARNING, "Failed to initialize SIM "
226 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
227 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
228 #endif /* IEEE8021X_EAPOL */
234 static int wpa_supplicant_match_privacy(struct wpa_scan_result *bss,
235 struct wpa_ssid *ssid)
239 if (ssid->mixed_cell)
242 for (i = 0; i < NUM_WEP_KEYS; i++) {
243 if (ssid->wep_key_len[i]) {
248 #ifdef IEEE8021X_EAPOL
249 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
250 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
251 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
253 #endif /* IEEE8021X_EAPOL */
255 if (bss->caps & IEEE80211_CAP_PRIVACY)
261 static int wpa_supplicant_ssid_bss_match(struct wpa_ssid *ssid,
262 struct wpa_scan_result *bss)
264 struct wpa_ie_data ie;
267 while ((ssid->proto & WPA_PROTO_RSN) && bss->rsn_ie_len > 0) {
270 if (wpa_parse_wpa_ie(bss->rsn_ie, bss->rsn_ie_len, &ie)) {
271 wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed");
274 if (!(ie.proto & ssid->proto)) {
275 wpa_printf(MSG_DEBUG, " skip RSN IE - proto "
280 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
281 wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher "
286 if (!(ie.group_cipher & ssid->group_cipher)) {
287 wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher "
292 if (!(ie.key_mgmt & ssid->key_mgmt)) {
293 wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt "
298 #ifdef CONFIG_IEEE80211W
299 if (!(ie.capabilities & WPA_CAPABILITY_MGMT_FRAME_PROTECTION)
300 && ssid->ieee80211w == IEEE80211W_REQUIRED) {
301 wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame "
305 #endif /* CONFIG_IEEE80211W */
307 wpa_printf(MSG_DEBUG, " selected based on RSN IE");
311 while ((ssid->proto & WPA_PROTO_WPA) && bss->wpa_ie_len > 0) {
314 if (wpa_parse_wpa_ie(bss->wpa_ie, bss->wpa_ie_len, &ie)) {
315 wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed");
318 if (!(ie.proto & ssid->proto)) {
319 wpa_printf(MSG_DEBUG, " skip WPA IE - proto "
324 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
325 wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher "
330 if (!(ie.group_cipher & ssid->group_cipher)) {
331 wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher "
336 if (!(ie.key_mgmt & ssid->key_mgmt)) {
337 wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt "
342 wpa_printf(MSG_DEBUG, " selected based on WPA IE");
346 if (proto_match == 0)
347 wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match");
353 static struct wpa_scan_result *
354 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, struct wpa_ssid *group,
355 struct wpa_scan_result *results, int num,
356 struct wpa_ssid **selected_ssid)
358 struct wpa_ssid *ssid;
359 struct wpa_scan_result *bss, *selected = NULL;
361 struct wpa_blacklist *e;
363 wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
368 /* First, try to find WPA-enabled AP */
369 wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP");
370 for (i = 0; i < num && !selected; i++) {
372 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
373 "wpa_ie_len=%lu rsn_ie_len=%lu caps=0x%x",
374 i, MAC2STR(bss->bssid),
375 wpa_ssid_txt(bss->ssid, bss->ssid_len),
376 (unsigned long) bss->wpa_ie_len,
377 (unsigned long) bss->rsn_ie_len, bss->caps);
378 e = wpa_blacklist_get(wpa_s, bss->bssid);
379 if (e && e->count > 1) {
380 wpa_printf(MSG_DEBUG, " skip - blacklisted");
384 if (bss->wpa_ie_len == 0 && bss->rsn_ie_len == 0) {
385 wpa_printf(MSG_DEBUG, " skip - no WPA/RSN IE");
389 for (ssid = group; ssid; ssid = ssid->pnext) {
390 if (ssid->disabled) {
391 wpa_printf(MSG_DEBUG, " skip - disabled");
394 if (bss->ssid_len != ssid->ssid_len ||
395 os_memcmp(bss->ssid, ssid->ssid,
396 bss->ssid_len) != 0) {
397 wpa_printf(MSG_DEBUG, " skip - "
401 if (ssid->bssid_set &&
402 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
404 wpa_printf(MSG_DEBUG, " skip - "
408 if (wpa_supplicant_ssid_bss_match(ssid, bss)) {
410 *selected_ssid = ssid;
411 wpa_printf(MSG_DEBUG, " selected WPA AP "
414 wpa_ssid_txt(bss->ssid,
421 /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
423 wpa_printf(MSG_DEBUG, "Try to find non-WPA AP");
424 for (i = 0; i < num && !selected; i++) {
426 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
427 "wpa_ie_len=%lu rsn_ie_len=%lu caps=0x%x",
428 i, MAC2STR(bss->bssid),
429 wpa_ssid_txt(bss->ssid, bss->ssid_len),
430 (unsigned long) bss->wpa_ie_len,
431 (unsigned long) bss->rsn_ie_len, bss->caps);
432 e = wpa_blacklist_get(wpa_s, bss->bssid);
433 if (e && e->count > 1) {
434 wpa_printf(MSG_DEBUG, " skip - blacklisted");
437 for (ssid = group; ssid; ssid = ssid->pnext) {
438 if (ssid->disabled) {
439 wpa_printf(MSG_DEBUG, " skip - disabled");
442 if (ssid->ssid_len != 0 &&
443 (bss->ssid_len != ssid->ssid_len ||
444 os_memcmp(bss->ssid, ssid->ssid,
445 bss->ssid_len) != 0)) {
446 wpa_printf(MSG_DEBUG, " skip - "
451 if (ssid->bssid_set &&
452 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
454 wpa_printf(MSG_DEBUG, " skip - "
459 if (!(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
460 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA))
462 wpa_printf(MSG_DEBUG, " skip - "
463 "non-WPA network not allowed");
467 if ((ssid->key_mgmt &
468 (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK)) &&
469 (bss->wpa_ie_len != 0 || bss->rsn_ie_len != 0)) {
470 wpa_printf(MSG_DEBUG, " skip - "
475 if (!wpa_supplicant_match_privacy(bss, ssid)) {
476 wpa_printf(MSG_DEBUG, " skip - "
481 if (bss->caps & IEEE80211_CAP_IBSS) {
482 wpa_printf(MSG_DEBUG, " skip - "
483 "IBSS (adhoc) network");
488 *selected_ssid = ssid;
489 wpa_printf(MSG_DEBUG, " selected non-WPA AP "
492 wpa_ssid_txt(bss->ssid, bss->ssid_len));
501 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
503 int num, prio, timeout;
504 struct wpa_scan_result *selected = NULL;
505 struct wpa_ssid *ssid = NULL;
506 struct wpa_scan_result *results;
508 wpa_s->scan_ongoing = 0;
509 if (wpa_supplicant_get_scan_results(wpa_s) < 0) {
510 if (wpa_s->conf->ap_scan == 2)
512 wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
518 wpa_supplicant_dbus_notify_scan_results(wpa_s);
519 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS " Ready");
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.");
567 timeout = wpa_s->scan_interval;
577 if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) {
579 * Quick recovery if the initial scan results were not
580 * complete when fetched before the first scan request.
582 wpa_s->scan_res_tried++;
585 wpa_supplicant_req_scan(wpa_s, timeout, 0);
589 static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
590 union wpa_event_data *data)
592 int l, len, found = 0, wpa_found, rsn_found;
595 wpa_printf(MSG_DEBUG, "Association info event");
596 if (data->assoc_info.req_ies)
597 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
598 data->assoc_info.req_ies_len);
599 if (data->assoc_info.resp_ies)
600 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
601 data->assoc_info.resp_ies_len);
602 if (data->assoc_info.beacon_ies)
603 wpa_hexdump(MSG_DEBUG, "beacon_ies",
604 data->assoc_info.beacon_ies,
605 data->assoc_info.beacon_ies_len);
607 p = data->assoc_info.req_ies;
608 l = data->assoc_info.req_ies_len;
610 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
611 while (p && l >= 2) {
614 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
618 if ((p[0] == GENERIC_INFO_ELEM && p[1] >= 6 &&
619 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
620 (p[0] == RSN_INFO_ELEM && p[1] >= 2)) {
621 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
624 wpa_find_assoc_pmkid(wpa_s);
630 if (!found && data->assoc_info.req_ies)
631 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
633 /* WPA/RSN IE from Beacon/ProbeResp */
634 p = data->assoc_info.beacon_ies;
635 l = data->assoc_info.beacon_ies_len;
637 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
639 wpa_found = rsn_found = 0;
640 while (p && l >= 2) {
643 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
648 p[0] == GENERIC_INFO_ELEM && p[1] >= 6 &&
649 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
651 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
655 p[0] == RSN_INFO_ELEM && p[1] >= 2) {
657 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
665 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
667 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
671 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
672 union wpa_event_data *data)
677 wpa_supplicant_event_associnfo(wpa_s, data);
679 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
680 if (wpa_s->use_client_mlme)
681 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
682 if (wpa_s->use_client_mlme ||
683 (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
684 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
685 wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
686 MACSTR, MAC2STR(bssid));
687 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
688 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
689 if (wpa_supplicant_dynamic_keys(wpa_s)) {
690 wpa_clear_keys(wpa_s, bssid);
692 if (wpa_supplicant_select_config(wpa_s) < 0) {
693 wpa_supplicant_disassociate(wpa_s,
694 REASON_DEAUTH_LEAVING);
699 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
700 if (wpa_s->current_ssid) {
701 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
702 * initialized before association, but for other modes,
703 * initialize PC/SC here, if the current configuration needs
704 * smartcard or SIM/USIM. */
705 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
707 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
708 l2_packet_notify_auth_start(wpa_s->l2);
711 * Set portEnabled first to FALSE in order to get EAP state machine out
712 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
713 * state machine may transit to AUTHENTICATING state based on obsolete
714 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
715 * AUTHENTICATED without ever giving chance to EAP state machine to
718 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
719 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
720 if (wpa_s->key_mgmt == WPA_KEY_MGMT_PSK)
721 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
722 /* 802.1X::portControl = Auto */
723 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
724 wpa_s->eapol_received = 0;
725 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
726 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
727 wpa_supplicant_cancel_auth_timeout(wpa_s);
728 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
730 /* Timeout for receiving the first EAPOL packet */
731 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
733 wpa_supplicant_cancel_scan(wpa_s);
737 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s)
741 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
743 * At least Host AP driver and a Prism3 card seemed to be
744 * generating streams of disconnected events when configuring
745 * IBSS for WPA-None. Ignore them for now.
747 wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
748 "IBSS/WPA-None mode");
752 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
753 wpa_s->key_mgmt == WPA_KEY_MGMT_PSK) {
754 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
755 "pre-shared key may be incorrect");
757 if (wpa_s->wpa_state >= WPA_ASSOCIATED)
758 wpa_supplicant_req_scan(wpa_s, 0, 100000);
759 bssid = wpa_s->bssid;
760 if (os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
761 bssid = wpa_s->pending_bssid;
762 wpa_blacklist_add(wpa_s, bssid);
763 wpa_sm_notify_disassoc(wpa_s->wpa);
764 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "- Disconnect event - "
766 if (wpa_supplicant_dynamic_keys(wpa_s)) {
767 wpa_s->keys_cleared = 0;
768 wpa_clear_keys(wpa_s, wpa_s->bssid);
770 wpa_supplicant_mark_disassoc(wpa_s);
775 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
776 union wpa_event_data *data)
781 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
782 pairwise = (data && data->michael_mic_failure.unicast);
783 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
785 if (wpa_s->last_michael_mic_error &&
786 t.sec - wpa_s->last_michael_mic_error <= 60) {
787 /* initialize countermeasures */
788 wpa_s->countermeasures = 1;
789 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
792 * Need to wait for completion of request frame. We do not get
793 * any callback for the message completion, so just wait a
794 * short while and hope for the best. */
797 wpa_drv_set_countermeasures(wpa_s, 1);
798 wpa_supplicant_deauthenticate(wpa_s,
799 REASON_MICHAEL_MIC_FAILURE);
800 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
802 eloop_register_timeout(60, 0,
803 wpa_supplicant_stop_countermeasures,
805 /* TODO: mark the AP rejected for 60 second. STA is
806 * allowed to associate with another AP.. */
808 wpa_s->last_michael_mic_error = t.sec;
813 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
814 union wpa_event_data *data)
816 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
819 switch (data->interface_status.ievent) {
820 case EVENT_INTERFACE_ADDED:
821 if (!wpa_s->interface_removed)
823 wpa_s->interface_removed = 0;
824 wpa_printf(MSG_DEBUG, "Configured interface was added.");
825 if (wpa_supplicant_driver_init(wpa_s, 1) < 0) {
826 wpa_printf(MSG_INFO, "Failed to initialize the driver "
827 "after interface was added.");
830 case EVENT_INTERFACE_REMOVED:
831 wpa_printf(MSG_DEBUG, "Configured interface was removed.");
832 wpa_s->interface_removed = 1;
833 wpa_supplicant_mark_disassoc(wpa_s);
834 l2_packet_deinit(wpa_s->l2);
841 #ifdef CONFIG_PEERKEY
843 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
844 union wpa_event_data *data)
848 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
850 #endif /* CONFIG_PEERKEY */
853 void wpa_supplicant_event(struct wpa_supplicant *wpa_s, wpa_event_type event,
854 union wpa_event_data *data)
858 wpa_supplicant_event_assoc(wpa_s, data);
861 wpa_supplicant_event_disassoc(wpa_s);
863 case EVENT_MICHAEL_MIC_FAILURE:
864 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
866 case EVENT_SCAN_RESULTS:
867 wpa_supplicant_event_scan_results(wpa_s);
869 case EVENT_ASSOCINFO:
870 wpa_supplicant_event_associnfo(wpa_s, data);
872 case EVENT_INTERFACE_STATUS:
873 wpa_supplicant_event_interface_status(wpa_s, data);
875 case EVENT_PMKID_CANDIDATE:
876 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
878 #ifdef CONFIG_PEERKEY
880 wpa_supplicant_event_stkstart(wpa_s, data);
882 #endif /* CONFIG_PEERKEY */
884 wpa_printf(MSG_INFO, "Unknown event %d", event);