tkip_countermeasures.c revision 1f69aa52ea2e0a73ac502565df8c666ee49cab6a
1/* 2 * hostapd / TKIP countermeasures 3 * Copyright (c) 2002-2011, Jouni Malinen <j@w1.fi> 4 * 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. 8 * 9 * Alternatively, this software may be distributed under the terms of BSD 10 * license. 11 * 12 * See README and COPYING for more details. 13 */ 14 15#include "utils/includes.h" 16 17#include "utils/common.h" 18#include "utils/eloop.h" 19#include "common/ieee802_11_defs.h" 20#include "hostapd.h" 21#include "sta_info.h" 22#include "ap_mlme.h" 23#include "wpa_auth.h" 24#include "ap_drv_ops.h" 25#include "tkip_countermeasures.h" 26 27 28static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx, 29 void *timeout_ctx) 30{ 31 struct hostapd_data *hapd = eloop_ctx; 32 hapd->tkip_countermeasures = 0; 33 hostapd_drv_set_countermeasures(hapd, 0); 34 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, 35 HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended"); 36} 37 38 39static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd) 40{ 41 struct sta_info *sta; 42 43 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, 44 HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated"); 45 46 wpa_auth_countermeasures_start(hapd->wpa_auth); 47 hapd->tkip_countermeasures = 1; 48 hostapd_drv_set_countermeasures(hapd, 1); 49 wpa_gtk_rekey(hapd->wpa_auth); 50 eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL); 51 eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop, 52 hapd, NULL); 53 for (sta = hapd->sta_list; sta != NULL; sta = sta->next) { 54 hostapd_drv_sta_deauth(hapd, sta->addr, 55 WLAN_REASON_MICHAEL_MIC_FAILURE); 56 ap_sta_set_authorized(hapd, sta, 0); 57 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); 58 hostapd_drv_sta_remove(hapd, sta->addr); 59 } 60} 61 62 63void ieee80211_tkip_countermeasures_deinit(struct hostapd_data *hapd) 64{ 65 eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL); 66} 67 68 69void michael_mic_failure(struct hostapd_data *hapd, const u8 *addr, int local) 70{ 71 struct os_time now; 72 73 if (addr && local) { 74 struct sta_info *sta = ap_get_sta(hapd, addr); 75 if (sta != NULL) { 76 wpa_auth_sta_local_mic_failure_report(sta->wpa_sm); 77 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, 78 HOSTAPD_LEVEL_INFO, 79 "Michael MIC failure detected in " 80 "received frame"); 81 mlme_michaelmicfailure_indication(hapd, addr); 82 } else { 83 wpa_printf(MSG_DEBUG, 84 "MLME-MICHAELMICFAILURE.indication " 85 "for not associated STA (" MACSTR 86 ") ignored", MAC2STR(addr)); 87 return; 88 } 89 } 90 91 os_get_time(&now); 92 if (now.sec > hapd->michael_mic_failure + 60) { 93 hapd->michael_mic_failures = 1; 94 } else { 95 hapd->michael_mic_failures++; 96 if (hapd->michael_mic_failures > 1) 97 ieee80211_tkip_countermeasures_start(hapd); 98 } 99 hapd->michael_mic_failure = now.sec; 100} 101