tkip_countermeasures.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #include "includes.h"
  15. #include "hostapd.h"
  16. #include "eloop.h"
  17. #include "driver_i.h"
  18. #include "sta_info.h"
  19. #include "mlme.h"
  20. #include "wpa.h"
  21. #include "ieee802_11_defs.h"
  22. #include "tkip_countermeasures.h"
  23. static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
  24. void *timeout_ctx)
  25. {
  26. struct hostapd_data *hapd = eloop_ctx;
  27. hapd->tkip_countermeasures = 0;
  28. hostapd_set_countermeasures(hapd, 0);
  29. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  30. HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
  31. }
  32. static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
  33. {
  34. struct sta_info *sta;
  35. hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  36. HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
  37. wpa_auth_countermeasures_start(hapd->wpa_auth);
  38. hapd->tkip_countermeasures = 1;
  39. hostapd_set_countermeasures(hapd, 1);
  40. wpa_gtk_rekey(hapd->wpa_auth);
  41. eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
  42. eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
  43. hapd, NULL);
  44. for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
  45. hostapd_sta_deauth(hapd, sta->addr,
  46. WLAN_REASON_MICHAEL_MIC_FAILURE);
  47. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
  48. WLAN_STA_AUTHORIZED);
  49. hostapd_sta_remove(hapd, sta->addr);
  50. }
  51. }
  52. void michael_mic_failure(struct hostapd_data *hapd, const u8 *addr, int local)
  53. {
  54. time_t now;
  55. if (addr && local) {
  56. struct sta_info *sta = ap_get_sta(hapd, addr);
  57. if (sta != NULL) {
  58. wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
  59. hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
  60. HOSTAPD_LEVEL_INFO,
  61. "Michael MIC failure detected in "
  62. "received frame");
  63. mlme_michaelmicfailure_indication(hapd, addr);
  64. } else {
  65. wpa_printf(MSG_DEBUG,
  66. "MLME-MICHAELMICFAILURE.indication "
  67. "for not associated STA (" MACSTR
  68. ") ignored", MAC2STR(addr));
  69. return;
  70. }
  71. }
  72. time(&now);
  73. if (now > hapd->michael_mic_failure + 60) {
  74. hapd->michael_mic_failures = 1;
  75. } else {
  76. hapd->michael_mic_failures++;
  77. if (hapd->michael_mic_failures > 1)
  78. ieee80211_tkip_countermeasures_start(hapd);
  79. }
  80. hapd->michael_mic_failure = now;
  81. }