ctrl_iface_ap.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Control interface for shared AP commands
  3. * Copyright (c) 2004-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 "ieee802_1x.h"
  17. #include "wpa.h"
  18. #include "ieee802_11.h"
  19. #include "sta_info.h"
  20. #include "wps_hostapd.h"
  21. #include "ctrl_iface_ap.h"
  22. static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
  23. struct sta_info *sta,
  24. char *buf, size_t buflen)
  25. {
  26. int len, res, ret;
  27. if (sta == NULL) {
  28. ret = os_snprintf(buf, buflen, "FAIL\n");
  29. if (ret < 0 || (size_t) ret >= buflen)
  30. return 0;
  31. return ret;
  32. }
  33. len = 0;
  34. ret = os_snprintf(buf + len, buflen - len, MACSTR "\n",
  35. MAC2STR(sta->addr));
  36. if (ret < 0 || (size_t) ret >= buflen - len)
  37. return len;
  38. len += ret;
  39. res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len);
  40. if (res >= 0)
  41. len += res;
  42. res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len);
  43. if (res >= 0)
  44. len += res;
  45. res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
  46. if (res >= 0)
  47. len += res;
  48. res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len,
  49. buflen - len);
  50. if (res >= 0)
  51. len += res;
  52. return len;
  53. }
  54. int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
  55. char *buf, size_t buflen)
  56. {
  57. return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
  58. }
  59. int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
  60. char *buf, size_t buflen)
  61. {
  62. u8 addr[ETH_ALEN];
  63. int ret;
  64. if (hwaddr_aton(txtaddr, addr)) {
  65. ret = os_snprintf(buf, buflen, "FAIL\n");
  66. if (ret < 0 || (size_t) ret >= buflen)
  67. return 0;
  68. return ret;
  69. }
  70. return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr),
  71. buf, buflen);
  72. }
  73. int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
  74. char *buf, size_t buflen)
  75. {
  76. u8 addr[ETH_ALEN];
  77. struct sta_info *sta;
  78. int ret;
  79. if (hwaddr_aton(txtaddr, addr) ||
  80. (sta = ap_get_sta(hapd, addr)) == NULL) {
  81. ret = os_snprintf(buf, buflen, "FAIL\n");
  82. if (ret < 0 || (size_t) ret >= buflen)
  83. return 0;
  84. return ret;
  85. }
  86. return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
  87. }