2 * hostapd / TKIP countermeasures
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "radius/radius.h"
19 #include "ap_drv_ops.h"
20 #include "tkip_countermeasures.h"
23 static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
26 struct hostapd_data *hapd = eloop_ctx;
27 hapd->tkip_countermeasures = 0;
28 hostapd_drv_set_countermeasures(hapd, 0);
29 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
30 HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
34 static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
38 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
39 HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
41 wpa_auth_countermeasures_start(hapd->wpa_auth);
42 hapd->tkip_countermeasures = 1;
43 hostapd_drv_set_countermeasures(hapd, 1);
44 wpa_gtk_rekey(hapd->wpa_auth);
45 eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
46 eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
48 while ((sta = hapd->sta_list)) {
49 sta->acct_terminate_cause =
50 RADIUS_ACCT_TERMINATE_CAUSE_ADMIN_RESET;
51 if (sta->flags & WLAN_STA_AUTH) {
52 mlme_deauthenticate_indication(
54 WLAN_REASON_MICHAEL_MIC_FAILURE);
56 hostapd_drv_sta_deauth(hapd, sta->addr,
57 WLAN_REASON_MICHAEL_MIC_FAILURE);
58 ap_free_sta(hapd, sta);
63 void ieee80211_tkip_countermeasures_deinit(struct hostapd_data *hapd)
65 eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
69 int michael_mic_failure(struct hostapd_data *hapd, const u8 *addr, int local)
75 struct sta_info *sta = ap_get_sta(hapd, addr);
77 wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
78 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
80 "Michael MIC failure detected in "
82 mlme_michaelmicfailure_indication(hapd, addr);
85 "MLME-MICHAELMICFAILURE.indication "
86 "for not associated STA (" MACSTR
87 ") ignored", MAC2STR(addr));
93 if (now.sec > hapd->michael_mic_failure + 60) {
94 hapd->michael_mic_failures = 1;
96 hapd->michael_mic_failures++;
97 if (hapd->michael_mic_failures > 1) {
98 ieee80211_tkip_countermeasures_start(hapd);
102 hapd->michael_mic_failure = now.sec;