2009-01-09 16:12:33 +01:00
|
|
|
/*
|
|
|
|
* hostapd / TKIP countermeasures
|
2011-10-30 11:43:30 +01:00
|
|
|
* Copyright (c) 2002-2011, Jouni Malinen <j@w1.fi>
|
2009-01-09 16:12:33 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of BSD
|
|
|
|
* license.
|
|
|
|
*
|
|
|
|
* See README and COPYING for more details.
|
|
|
|
*/
|
|
|
|
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "utils/includes.h"
|
2009-01-09 16:12:33 +01:00
|
|
|
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
|
|
|
#include "common/ieee802_11_defs.h"
|
2009-01-09 16:12:33 +01:00
|
|
|
#include "hostapd.h"
|
|
|
|
#include "sta_info.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "ap_mlme.h"
|
|
|
|
#include "wpa_auth.h"
|
2010-11-24 14:26:44 +01:00
|
|
|
#include "ap_drv_ops.h"
|
2009-01-11 09:42:07 +01:00
|
|
|
#include "tkip_countermeasures.h"
|
2009-01-09 16:12:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
|
|
|
|
void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = eloop_ctx;
|
|
|
|
hapd->tkip_countermeasures = 0;
|
2010-11-24 14:26:44 +01:00
|
|
|
hostapd_drv_set_countermeasures(hapd, 0);
|
2009-01-09 16:12:33 +01:00
|
|
|
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
|
|
|
|
|
|
|
|
wpa_auth_countermeasures_start(hapd->wpa_auth);
|
|
|
|
hapd->tkip_countermeasures = 1;
|
2010-11-24 14:26:44 +01:00
|
|
|
hostapd_drv_set_countermeasures(hapd, 1);
|
2009-01-09 16:12:33 +01:00
|
|
|
wpa_gtk_rekey(hapd->wpa_auth);
|
|
|
|
eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
|
|
|
|
eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
|
|
|
|
hapd, NULL);
|
|
|
|
for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
|
2010-11-24 14:36:02 +01:00
|
|
|
hostapd_drv_sta_deauth(hapd, sta->addr,
|
|
|
|
WLAN_REASON_MICHAEL_MIC_FAILURE);
|
2011-02-02 15:52:32 +01:00
|
|
|
ap_sta_set_authorized(hapd, sta, 0);
|
|
|
|
sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
|
2010-11-24 14:36:02 +01:00
|
|
|
hostapd_drv_sta_remove(hapd, sta->addr);
|
2009-01-09 16:12:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-30 11:43:30 +01:00
|
|
|
void ieee80211_tkip_countermeasures_deinit(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-09 16:12:33 +01:00
|
|
|
void michael_mic_failure(struct hostapd_data *hapd, const u8 *addr, int local)
|
|
|
|
{
|
2011-09-12 21:14:30 +02:00
|
|
|
struct os_time now;
|
2009-01-09 16:12:33 +01:00
|
|
|
|
|
|
|
if (addr && local) {
|
|
|
|
struct sta_info *sta = ap_get_sta(hapd, addr);
|
|
|
|
if (sta != NULL) {
|
|
|
|
wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
|
|
|
|
hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO,
|
|
|
|
"Michael MIC failure detected in "
|
|
|
|
"received frame");
|
|
|
|
mlme_michaelmicfailure_indication(hapd, addr);
|
|
|
|
} else {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"MLME-MICHAELMICFAILURE.indication "
|
|
|
|
"for not associated STA (" MACSTR
|
|
|
|
") ignored", MAC2STR(addr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 21:14:30 +02:00
|
|
|
os_get_time(&now);
|
|
|
|
if (now.sec > hapd->michael_mic_failure + 60) {
|
2009-01-09 16:12:33 +01:00
|
|
|
hapd->michael_mic_failures = 1;
|
|
|
|
} else {
|
|
|
|
hapd->michael_mic_failures++;
|
|
|
|
if (hapd->michael_mic_failures > 1)
|
|
|
|
ieee80211_tkip_countermeasures_start(hapd);
|
|
|
|
}
|
2011-09-12 21:14:30 +02:00
|
|
|
hapd->michael_mic_failure = now.sec;
|
2009-01-09 16:12:33 +01:00
|
|
|
}
|