utils.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * AP mode helper functions
  3. * Copyright (c) 2009, 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 "includes.h"
  9. #include "common.h"
  10. #include "common/ieee802_11_defs.h"
  11. #include "sta_info.h"
  12. #include "hostapd.h"
  13. int hostapd_register_probereq_cb(struct hostapd_data *hapd,
  14. int (*cb)(void *ctx, const u8 *sa,
  15. const u8 *da, const u8 *bssid,
  16. const u8 *ie, size_t ie_len,
  17. int ssi_signal),
  18. void *ctx)
  19. {
  20. struct hostapd_probereq_cb *n;
  21. n = os_realloc_array(hapd->probereq_cb, hapd->num_probereq_cb + 1,
  22. sizeof(struct hostapd_probereq_cb));
  23. if (n == NULL)
  24. return -1;
  25. hapd->probereq_cb = n;
  26. n = &hapd->probereq_cb[hapd->num_probereq_cb];
  27. hapd->num_probereq_cb++;
  28. n->cb = cb;
  29. n->ctx = ctx;
  30. return 0;
  31. }
  32. struct prune_data {
  33. struct hostapd_data *hapd;
  34. const u8 *addr;
  35. };
  36. static int prune_associations(struct hostapd_iface *iface, void *ctx)
  37. {
  38. struct prune_data *data = ctx;
  39. struct sta_info *osta;
  40. struct hostapd_data *ohapd;
  41. size_t j;
  42. for (j = 0; j < iface->num_bss; j++) {
  43. ohapd = iface->bss[j];
  44. if (ohapd == data->hapd)
  45. continue;
  46. osta = ap_get_sta(ohapd, data->addr);
  47. if (!osta)
  48. continue;
  49. wpa_printf(MSG_INFO, "%s: Prune association for " MACSTR,
  50. ohapd->conf->iface, MAC2STR(osta->addr));
  51. ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED);
  52. }
  53. return 0;
  54. }
  55. /**
  56. * hostapd_prune_associations - Remove extraneous associations
  57. * @hapd: Pointer to BSS data for the most recent association
  58. * @addr: Associated STA address
  59. *
  60. * This function looks through all radios and BSS's for previous
  61. * (stale) associations of STA. If any are found they are removed.
  62. */
  63. void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr)
  64. {
  65. struct prune_data data;
  66. data.hapd = hapd;
  67. data.addr = addr;
  68. if (hapd->iface->interfaces &&
  69. hapd->iface->interfaces->for_each_interface)
  70. hapd->iface->interfaces->for_each_interface(
  71. hapd->iface->interfaces, prune_associations, &data);
  72. }