tkip_countermeasures.c 2.8 KB

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