Advertisement
teknoraver

hostapd_ban

Sep 5th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.27 KB | None | 0 0
  1. diff --git a/hostapd/config_file.c b/hostapd/config_file.c
  2. index 32e3c49..f42186e 100644
  3. --- a/hostapd/config_file.c
  4. +++ b/hostapd/config_file.c
  5. @@ -109,7 +109,7 @@ static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
  6.  #endif /* CONFIG_NO_VLAN */
  7.  
  8.  
  9. -static int hostapd_acl_comp(const void *a, const void *b)
  10. +int hostapd_acl_comp(const void *a, const void *b)
  11.  {
  12.     const struct mac_acl_entry *aa = a;
  13.     const struct mac_acl_entry *bb = b;
  14. diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
  15. index 9ce7829..3986040 100644
  16. --- a/hostapd/ctrl_iface.c
  17. +++ b/hostapd/ctrl_iface.c
  18. @@ -1455,6 +1455,9 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
  19.     } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
  20.         if (hostapd_ctrl_iface_disassociate(hapd, buf + 13))
  21.             reply_len = -1;
  22. +   } else if (os_strncmp(buf, "BAN ", 4) == 0) {
  23. +       if (hostapd_ctrl_iface_ban(hapd, buf + 4))
  24. +           reply_len = -1;
  25.  #ifdef CONFIG_IEEE80211W
  26.  #ifdef NEED_AP_MLME
  27.     } else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
  28. diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
  29. index 09b7284..b0a7520 100644
  30. --- a/hostapd/hostapd_cli.c
  31. +++ b/hostapd/hostapd_cli.c
  32. @@ -64,6 +64,7 @@ static const char *commands_help =
  33.  "   new_sta <addr>       add a new station\n"
  34.  "   deauthenticate <addr>  deauthenticate a station\n"
  35.  "   disassociate <addr>  disassociate a station\n"
  36. +"   ban <addr>           ban a station\n"
  37.  #ifdef CONFIG_IEEE80211W
  38.  "   sa_query <addr>      send SA Query to a station\n"
  39.  #endif /* CONFIG_IEEE80211W */
  40. @@ -346,6 +347,23 @@ static int hostapd_cli_cmd_disassociate(struct wpa_ctrl *ctrl, int argc,
  41.  }
  42.  
  43.  
  44. +static int hostapd_cli_cmd_ban(struct wpa_ctrl *ctrl, int argc,
  45. +                     char *argv[])
  46. +{
  47. +   char buf[64];
  48. +   if (argc < 1) {
  49. +       printf("Invalid 'ban' command - exactly one "
  50. +              "argument, STA address, is required.\n");
  51. +       return -1;
  52. +   }
  53. +   if (argc > 1)
  54. +       os_snprintf(buf, sizeof(buf), "BAN %s %s",
  55. +               argv[0], argv[1]);
  56. +   else
  57. +       os_snprintf(buf, sizeof(buf), "BAN %s", argv[0]);
  58. +   return wpa_ctrl_command(ctrl, buf);
  59. +}
  60. +
  61.  #ifdef CONFIG_IEEE80211W
  62.  static int hostapd_cli_cmd_sa_query(struct wpa_ctrl *ctrl, int argc,
  63.                     char *argv[])
  64. @@ -978,6 +996,7 @@ static struct hostapd_cli_cmd hostapd_cli_commands[] = {
  65.     { "new_sta", hostapd_cli_cmd_new_sta },
  66.     { "deauthenticate", hostapd_cli_cmd_deauthenticate },
  67.     { "disassociate", hostapd_cli_cmd_disassociate },
  68. +   { "ban", hostapd_cli_cmd_ban },
  69.  #ifdef CONFIG_IEEE80211W
  70.     { "sa_query", hostapd_cli_cmd_sa_query },
  71.  #endif /* CONFIG_IEEE80211W */
  72. diff --git a/src/ap/ctrl_iface_ap.c b/src/ap/ctrl_iface_ap.c
  73. index 39edbd7..84bd589 100644
  74. --- a/src/ap/ctrl_iface_ap.c
  75. +++ b/src/ap/ctrl_iface_ap.c
  76. @@ -387,6 +387,33 @@ int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
  77.     return 0;
  78.  }
  79.  
  80. +extern int hostapd_acl_comp(const void *a, const void *b);
  81. +
  82. +int hostapd_ctrl_iface_ban(struct hostapd_data *hapd,
  83. +              const char *txtaddr)
  84. +{
  85. +   u8 addr[ETH_ALEN];
  86. +   struct mac_acl_entry *acl = hapd->conf->deny_mac;
  87. +   int num_acl = hapd->conf->num_deny_mac + 1;
  88. +
  89. +   wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE BAN %s",
  90. +       txtaddr);
  91. +
  92. +   if (hwaddr_aton(txtaddr, addr))
  93. +       return -1;
  94. +
  95. +   hapd->conf->macaddr_acl = 0;
  96. +
  97. +   acl = os_realloc_array(acl, num_acl, sizeof(*acl));
  98. +   os_memcpy(acl[num_acl - 1].addr, addr, ETH_ALEN);
  99. +   acl[num_acl - 1].vlan_id = 0;
  100. +   qsort(acl, num_acl, sizeof(*acl), hostapd_acl_comp);
  101. +
  102. +   hapd->conf->deny_mac = acl;
  103. +   hapd->conf->num_deny_mac = num_acl;
  104. +
  105. +   return hostapd_ctrl_iface_disassociate(hapd, txtaddr);
  106. +}
  107.  
  108.  int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
  109.                   size_t buflen)
  110. diff --git a/src/ap/ctrl_iface_ap.h b/src/ap/ctrl_iface_ap.h
  111. index ee58b4c..5544b70 100644
  112. --- a/src/ap/ctrl_iface_ap.h
  113. +++ b/src/ap/ctrl_iface_ap.h
  114. @@ -19,6 +19,8 @@ int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
  115.                       const char *txtaddr);
  116.  int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
  117.                     const char *txtaddr);
  118. +int hostapd_ctrl_iface_ban(struct hostapd_data *hapd,
  119. +                   const char *txtaddr);
  120.  int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
  121.                   size_t buflen);
  122.  int hostapd_parse_csa_settings(const char *pos,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement