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 (bss->ssid_len != ssid->ssid_len ||
445 os_memcmp(bss->ssid, ssid->ssid,
446 bss->ssid_len) != 0) {
447 wpa_printf(MSG_DEBUG, " skip - "
452 if (ssid->bssid_set &&
453 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
455 wpa_printf(MSG_DEBUG, " skip - "
460 if (!(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
461 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA))
463 wpa_printf(MSG_DEBUG, " skip - "
464 "non-WPA network not allowed");
468 if ((ssid->key_mgmt &
469 (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK)) ||
470 bss->wpa_ie_len != 0 || bss->rsn_ie_len != 0) {
471 wpa_printf(MSG_DEBUG, " skip - "
476 if (!wpa_supplicant_match_privacy(bss, ssid)) {
477 wpa_printf(MSG_DEBUG, " skip - "
482 if (bss->caps & IEEE80211_CAP_IBSS) {
483 wpa_printf(MSG_DEBUG, " skip - "
484 "IBSS (adhoc) network");
489 *selected_ssid = ssid;
490 wpa_printf(MSG_DEBUG, " selected non-WPA AP "
493 wpa_ssid_txt(bss->ssid, bss->ssid_len));
502 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
504 int num, prio, timeout;
505 struct wpa_scan_result *selected = NULL;
506 struct wpa_ssid *ssid = NULL;
507 struct wpa_scan_result *results;
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);
520 if (wpa_s->conf->ap_scan == 2)
522 results = wpa_s->scan_results;
523 num = wpa_s->num_scan_results;
525 while (selected == NULL) {
526 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
527 selected = wpa_supplicant_select_bss(
528 wpa_s, wpa_s->conf->pssid[prio], results, num,
534 if (selected == NULL && wpa_s->blacklist) {
535 wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
537 wpa_blacklist_clear(wpa_s);
538 } else if (selected == NULL) {
544 /* Do not trigger new association unless the BSSID has changed
545 * or if reassociation is requested. If we are in process of
546 * associating with the selected BSSID, do not trigger new
548 if (wpa_s->reassociate ||
549 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
550 (wpa_s->wpa_state != WPA_ASSOCIATING ||
551 os_memcmp(selected->bssid, wpa_s->pending_bssid,
553 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
554 wpa_supplicant_req_scan(wpa_s, 10, 0);
557 wpa_supplicant_associate(wpa_s, selected, ssid);
559 wpa_printf(MSG_DEBUG, "Already associated with the "
562 rsn_preauth_scan_results(wpa_s->wpa, results, num);
564 wpa_printf(MSG_DEBUG, "No suitable AP found.");
572 if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) {
574 * Quick recovery if the initial scan results were not
575 * complete when fetched before the first scan request.
577 wpa_s->scan_res_tried++;
580 wpa_supplicant_req_scan(wpa_s, timeout, 0);
584 static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
585 union wpa_event_data *data)
587 int l, len, found = 0, wpa_found, rsn_found;
590 wpa_printf(MSG_DEBUG, "Association info event");
591 if (data->assoc_info.req_ies)
592 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
593 data->assoc_info.req_ies_len);
594 if (data->assoc_info.resp_ies)
595 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
596 data->assoc_info.resp_ies_len);
597 if (data->assoc_info.beacon_ies)
598 wpa_hexdump(MSG_DEBUG, "beacon_ies",
599 data->assoc_info.beacon_ies,
600 data->assoc_info.beacon_ies_len);
602 p = data->assoc_info.req_ies;
603 l = data->assoc_info.req_ies_len;
605 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
606 while (p && l >= 2) {
609 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
613 if ((p[0] == GENERIC_INFO_ELEM && p[1] >= 6 &&
614 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
615 (p[0] == RSN_INFO_ELEM && p[1] >= 2)) {
616 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
619 wpa_find_assoc_pmkid(wpa_s);
625 if (!found && data->assoc_info.req_ies)
626 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
628 /* WPA/RSN IE from Beacon/ProbeResp */
629 p = data->assoc_info.beacon_ies;
630 l = data->assoc_info.beacon_ies_len;
632 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
634 wpa_found = rsn_found = 0;
635 while (p && l >= 2) {
638 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
643 p[0] == GENERIC_INFO_ELEM && p[1] >= 6 &&
644 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
646 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
650 p[0] == RSN_INFO_ELEM && p[1] >= 2) {
652 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
659 if (!wpa_found && data->assoc_info.beacon_ies)
660 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
661 if (!rsn_found && data->assoc_info.beacon_ies)
662 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
666 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
667 union wpa_event_data *data)
672 wpa_supplicant_event_associnfo(wpa_s, data);
674 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
675 if (wpa_s->use_client_mlme)
676 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
677 if (wpa_s->use_client_mlme ||
678 (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
679 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
680 wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
681 MACSTR, MAC2STR(bssid));
682 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
683 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
684 if (wpa_supplicant_dynamic_keys(wpa_s)) {
685 wpa_clear_keys(wpa_s, bssid);
687 if (wpa_supplicant_select_config(wpa_s) < 0) {
688 wpa_supplicant_disassociate(wpa_s,
689 REASON_DEAUTH_LEAVING);
694 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
695 if (wpa_s->current_ssid) {
696 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
697 * initialized before association, but for other modes,
698 * initialize PC/SC here, if the current configuration needs
699 * smartcard or SIM/USIM. */
700 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
702 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
703 l2_packet_notify_auth_start(wpa_s->l2);
706 * Set portEnabled first to FALSE in order to get EAP state machine out
707 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
708 * state machine may transit to AUTHENTICATING state based on obsolete
709 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
710 * AUTHENTICATED without ever giving chance to EAP state machine to
713 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
714 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
715 if (wpa_s->key_mgmt == WPA_KEY_MGMT_PSK)
716 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
717 /* 802.1X::portControl = Auto */
718 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
719 wpa_s->eapol_received = 0;
720 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
721 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
722 wpa_supplicant_cancel_auth_timeout(wpa_s);
723 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
725 /* Timeout for receiving the first EAPOL packet */
726 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
728 wpa_supplicant_cancel_scan(wpa_s);
732 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s)
736 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
738 * At least Host AP driver and a Prism3 card seemed to be
739 * generating streams of disconnected events when configuring
740 * IBSS for WPA-None. Ignore them for now.
742 wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
743 "IBSS/WPA-None mode");
747 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
748 wpa_s->key_mgmt == WPA_KEY_MGMT_PSK) {
749 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
750 "pre-shared key may be incorrect");
752 if (wpa_s->wpa_state >= WPA_ASSOCIATED)
753 wpa_supplicant_req_scan(wpa_s, 0, 100000);
754 bssid = wpa_s->bssid;
755 if (os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
756 bssid = wpa_s->pending_bssid;
757 wpa_blacklist_add(wpa_s, bssid);
758 wpa_sm_notify_disassoc(wpa_s->wpa);
759 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "- Disconnect event - "
761 if (wpa_supplicant_dynamic_keys(wpa_s)) {
762 wpa_s->keys_cleared = 0;
763 wpa_clear_keys(wpa_s, wpa_s->bssid);
765 wpa_supplicant_mark_disassoc(wpa_s);
770 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
771 union wpa_event_data *data)
776 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
777 pairwise = (data && data->michael_mic_failure.unicast);
778 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
780 if (wpa_s->last_michael_mic_error &&
781 t.sec - wpa_s->last_michael_mic_error <= 60) {
782 /* initialize countermeasures */
783 wpa_s->countermeasures = 1;
784 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
787 * Need to wait for completion of request frame. We do not get
788 * any callback for the message completion, so just wait a
789 * short while and hope for the best. */
792 wpa_drv_set_countermeasures(wpa_s, 1);
793 wpa_supplicant_deauthenticate(wpa_s,
794 REASON_MICHAEL_MIC_FAILURE);
795 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
797 eloop_register_timeout(60, 0,
798 wpa_supplicant_stop_countermeasures,
800 /* TODO: mark the AP rejected for 60 second. STA is
801 * allowed to associate with another AP.. */
803 wpa_s->last_michael_mic_error = t.sec;
807 #ifdef CONFIG_TERMINATE_ONLASTIF
808 static int any_interfaces(struct wpa_supplicant *head)
810 struct wpa_supplicant *wpa_s;
812 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
813 if (!wpa_s->interface_removed)
817 #endif /* CONFIG_TERMINATE_ONLASTIF */
820 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
821 union wpa_event_data *data)
823 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
826 switch (data->interface_status.ievent) {
827 case EVENT_INTERFACE_ADDED:
828 if (!wpa_s->interface_removed)
830 wpa_s->interface_removed = 0;
831 wpa_printf(MSG_DEBUG, "Configured interface was added.");
832 if (wpa_supplicant_driver_init(wpa_s, 1) < 0) {
833 wpa_printf(MSG_INFO, "Failed to initialize the driver "
834 "after interface was added.");
837 case EVENT_INTERFACE_REMOVED:
838 wpa_printf(MSG_DEBUG, "Configured interface was removed.");
839 wpa_s->interface_removed = 1;
840 wpa_supplicant_mark_disassoc(wpa_s);
841 l2_packet_deinit(wpa_s->l2);
843 #ifdef CONFIG_TERMINATE_ONLASTIF
844 /* check if last interface */
845 if (!any_interfaces(wpa_s->global->ifaces))
847 #endif /* CONFIG_TERMINATE_ONLASTIF */
853 #ifdef CONFIG_PEERKEY
855 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
856 union wpa_event_data *data)
860 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
862 #endif /* CONFIG_PEERKEY */
865 void wpa_supplicant_event(struct wpa_supplicant *wpa_s, wpa_event_type event,
866 union wpa_event_data *data)
870 wpa_supplicant_event_assoc(wpa_s, data);
873 wpa_supplicant_event_disassoc(wpa_s);
875 case EVENT_MICHAEL_MIC_FAILURE:
876 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
878 case EVENT_SCAN_RESULTS:
879 wpa_supplicant_event_scan_results(wpa_s);
881 case EVENT_ASSOCINFO:
882 wpa_supplicant_event_associnfo(wpa_s, data);
884 case EVENT_INTERFACE_STATUS:
885 wpa_supplicant_event_interface_status(wpa_s, data);
887 case EVENT_PMKID_CANDIDATE:
888 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
890 #ifdef CONFIG_PEERKEY
892 wpa_supplicant_event_stkstart(wpa_s, data);
894 #endif /* CONFIG_PEERKEY */
896 wpa_printf(MSG_INFO, "Unknown event %d", event);