utils.c 2.0 KB

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