utils.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED);
  50. }
  51. return 0;
  52. }
  53. /**
  54. * hostapd_prune_associations - Remove extraneous associations
  55. * @hapd: Pointer to BSS data for the most recent association
  56. * @addr: Associated STA address
  57. *
  58. * This function looks through all radios and BSS's for previous
  59. * (stale) associations of STA. If any are found they are removed.
  60. */
  61. void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr)
  62. {
  63. struct prune_data data;
  64. data.hapd = hapd;
  65. data.addr = addr;
  66. if (hapd->iface->interfaces &&
  67. hapd->iface->interfaces->for_each_interface)
  68. hapd->iface->interfaces->for_each_interface(
  69. hapd->iface->interfaces, prune_associations, &data);
  70. }