tkip_countermeasures.c 2.5 KB

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