• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/wpa_supplicant-0.7.3/src/ap/
1/*
2 * hostapd / TKIP countermeasures
3 * Copyright (c) 2002-2009, 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 "tkip_countermeasures.h"
25
26
27static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
28						void *timeout_ctx)
29{
30	struct hostapd_data *hapd = eloop_ctx;
31	hapd->tkip_countermeasures = 0;
32	hapd->drv.set_countermeasures(hapd, 0);
33	hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
34		       HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
35}
36
37
38static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
39{
40	struct sta_info *sta;
41
42	hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
43		       HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
44
45	wpa_auth_countermeasures_start(hapd->wpa_auth);
46	hapd->tkip_countermeasures = 1;
47	hapd->drv.set_countermeasures(hapd, 1);
48	wpa_gtk_rekey(hapd->wpa_auth);
49	eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
50	eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
51			       hapd, NULL);
52	for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
53		hapd->drv.sta_deauth(hapd, sta->addr,
54				     WLAN_REASON_MICHAEL_MIC_FAILURE);
55		sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
56				WLAN_STA_AUTHORIZED);
57		hapd->drv.sta_remove(hapd, sta->addr);
58	}
59}
60
61
62void michael_mic_failure(struct hostapd_data *hapd, const u8 *addr, int local)
63{
64	time_t now;
65
66	if (addr && local) {
67		struct sta_info *sta = ap_get_sta(hapd, addr);
68		if (sta != NULL) {
69			wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
70			hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
71				       HOSTAPD_LEVEL_INFO,
72				       "Michael MIC failure detected in "
73				       "received frame");
74			mlme_michaelmicfailure_indication(hapd, addr);
75		} else {
76			wpa_printf(MSG_DEBUG,
77				   "MLME-MICHAELMICFAILURE.indication "
78				   "for not associated STA (" MACSTR
79				   ") ignored", MAC2STR(addr));
80			return;
81		}
82	}
83
84	time(&now);
85	if (now > hapd->michael_mic_failure + 60) {
86		hapd->michael_mic_failures = 1;
87	} else {
88		hapd->michael_mic_failures++;
89		if (hapd->michael_mic_failures > 1)
90			ieee80211_tkip_countermeasures_start(hapd);
91	}
92	hapd->michael_mic_failure = now;
93}
94