sta.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * STA list
  3. * Copyright (c) 2010, 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 "utils/includes.h"
  15. #include "utils/common.h"
  16. #include "common/ieee802_11_common.h"
  17. #include "wlantest.h"
  18. struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
  19. {
  20. struct wlantest_sta *sta;
  21. if (addr[0] & 0x01)
  22. return NULL; /* Skip group addressed frames */
  23. dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
  24. if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
  25. return sta;
  26. }
  27. sta = os_zalloc(sizeof(*sta));
  28. if (sta == NULL)
  29. return NULL;
  30. os_memcpy(sta->addr, addr, ETH_ALEN);
  31. dl_list_add(&bss->sta, &sta->list);
  32. wpa_printf(MSG_DEBUG, "Discovered new STA " MACSTR " in BSS " MACSTR,
  33. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  34. return sta;
  35. }
  36. void sta_deinit(struct wlantest_sta *sta)
  37. {
  38. dl_list_del(&sta->list);
  39. os_free(sta);
  40. }
  41. void sta_update_assoc(struct wlantest_sta *sta, struct ieee802_11_elems *elems)
  42. {
  43. if (elems->wpa_ie && elems->rsn_ie) {
  44. wpa_printf(MSG_INFO, "Both WPA IE and RSN IE included in "
  45. "Association Request frame from " MACSTR,
  46. MAC2STR(sta->addr));
  47. }
  48. if (elems->rsn_ie) {
  49. wpa_hexdump(MSG_DEBUG, "RSN IE", elems->rsn_ie - 2,
  50. elems->rsn_ie_len + 2);
  51. os_memcpy(sta->rsnie, elems->rsn_ie - 2,
  52. elems->rsn_ie_len + 2);
  53. } else if (elems->wpa_ie) {
  54. wpa_hexdump(MSG_DEBUG, "WPA IE", elems->wpa_ie - 2,
  55. elems->wpa_ie_len + 2);
  56. os_memcpy(sta->rsnie, elems->wpa_ie - 2,
  57. elems->wpa_ie_len + 2);
  58. } else
  59. sta->rsnie[0] = 0;
  60. }