sta.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/defs.h"
  17. #include "common/ieee802_11_defs.h"
  18. #include "common/ieee802_11_common.h"
  19. #include "wlantest.h"
  20. struct wlantest_sta * sta_find(struct wlantest_bss *bss, const u8 *addr)
  21. {
  22. struct wlantest_sta *sta;
  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. return NULL;
  28. }
  29. struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
  30. {
  31. struct wlantest_sta *sta;
  32. if (addr[0] & 0x01)
  33. return NULL; /* Skip group addressed frames */
  34. sta = sta_find(bss, addr);
  35. if (sta)
  36. return sta;
  37. sta = os_zalloc(sizeof(*sta));
  38. if (sta == NULL)
  39. return NULL;
  40. os_memset(sta->seq_ctrl_to_sta, 0xff, sizeof(sta->seq_ctrl_to_sta));
  41. os_memset(sta->seq_ctrl_to_ap, 0xff, sizeof(sta->seq_ctrl_to_ap));
  42. sta->bss = bss;
  43. os_memcpy(sta->addr, addr, ETH_ALEN);
  44. dl_list_add(&bss->sta, &sta->list);
  45. wpa_printf(MSG_DEBUG, "Discovered new STA " MACSTR " in BSS " MACSTR,
  46. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  47. return sta;
  48. }
  49. void sta_deinit(struct wlantest_sta *sta)
  50. {
  51. dl_list_del(&sta->list);
  52. os_free(sta->assocreq_ies);
  53. os_free(sta);
  54. }
  55. void sta_update_assoc(struct wlantest_sta *sta, struct ieee802_11_elems *elems)
  56. {
  57. struct wpa_ie_data data;
  58. struct wlantest_bss *bss = sta->bss;
  59. if (elems->wpa_ie && elems->rsn_ie) {
  60. wpa_printf(MSG_INFO, "Both WPA IE and RSN IE included in "
  61. "Association Request frame from " MACSTR,
  62. MAC2STR(sta->addr));
  63. }
  64. if (elems->rsn_ie) {
  65. wpa_hexdump(MSG_DEBUG, "RSN IE", elems->rsn_ie - 2,
  66. elems->rsn_ie_len + 2);
  67. os_memcpy(sta->rsnie, elems->rsn_ie - 2,
  68. elems->rsn_ie_len + 2);
  69. if (wpa_parse_wpa_ie_rsn(sta->rsnie, 2 + sta->rsnie[1], &data)
  70. < 0) {
  71. wpa_printf(MSG_INFO, "Failed to parse RSN IE from "
  72. MACSTR, MAC2STR(sta->addr));
  73. }
  74. } else if (elems->wpa_ie) {
  75. wpa_hexdump(MSG_DEBUG, "WPA IE", elems->wpa_ie - 2,
  76. elems->wpa_ie_len + 2);
  77. os_memcpy(sta->rsnie, elems->wpa_ie - 2,
  78. elems->wpa_ie_len + 2);
  79. if (wpa_parse_wpa_ie_wpa(sta->rsnie, 2 + sta->rsnie[1], &data)
  80. < 0) {
  81. wpa_printf(MSG_INFO, "Failed to parse WPA IE from "
  82. MACSTR, MAC2STR(sta->addr));
  83. }
  84. } else {
  85. sta->rsnie[0] = 0;
  86. sta->proto = 0;
  87. sta->pairwise_cipher = 0;
  88. sta->key_mgmt = 0;
  89. sta->rsn_capab = 0;
  90. if (sta->assocreq_capab_info & WLAN_CAPABILITY_PRIVACY)
  91. sta->pairwise_cipher = WPA_CIPHER_WEP40;
  92. goto skip_rsn_wpa;
  93. }
  94. sta->proto = data.proto;
  95. sta->pairwise_cipher = data.pairwise_cipher;
  96. sta->key_mgmt = data.key_mgmt;
  97. sta->rsn_capab = data.capabilities;
  98. if (bss->proto && (sta->proto & bss->proto) == 0) {
  99. wpa_printf(MSG_INFO, "Mismatch in WPA/WPA2 proto: STA "
  100. MACSTR " 0x%x BSS " MACSTR " 0x%x",
  101. MAC2STR(sta->addr), sta->proto,
  102. MAC2STR(bss->bssid), bss->proto);
  103. }
  104. if (bss->pairwise_cipher &&
  105. (sta->pairwise_cipher & bss->pairwise_cipher) == 0) {
  106. wpa_printf(MSG_INFO, "Mismatch in pairwise cipher: STA "
  107. MACSTR " 0x%x BSS " MACSTR " 0x%x",
  108. MAC2STR(sta->addr), sta->pairwise_cipher,
  109. MAC2STR(bss->bssid), bss->pairwise_cipher);
  110. }
  111. if (sta->proto && data.group_cipher != bss->group_cipher) {
  112. wpa_printf(MSG_INFO, "Mismatch in group cipher: STA "
  113. MACSTR " 0x%x != BSS " MACSTR " 0x%x",
  114. MAC2STR(sta->addr), data.group_cipher,
  115. MAC2STR(bss->bssid), bss->group_cipher);
  116. }
  117. if ((bss->rsn_capab & WPA_CAPABILITY_MFPR) &&
  118. !(sta->rsn_capab & WPA_CAPABILITY_MFPC)) {
  119. wpa_printf(MSG_INFO, "STA " MACSTR " tries to associate "
  120. "without MFP to BSS " MACSTR " that advertises "
  121. "MFPR", MAC2STR(sta->addr), MAC2STR(bss->bssid));
  122. }
  123. skip_rsn_wpa:
  124. wpa_printf(MSG_INFO, "STA " MACSTR
  125. " proto=%s%s%s"
  126. "pairwise=%s%s%s%s"
  127. "key_mgmt=%s%s%s%s%s%s%s%s"
  128. "rsn_capab=%s%s%s%s%s",
  129. MAC2STR(sta->addr),
  130. sta->proto == 0 ? "OPEN " : "",
  131. sta->proto & WPA_PROTO_WPA ? "WPA " : "",
  132. sta->proto & WPA_PROTO_RSN ? "WPA2 " : "",
  133. sta->pairwise_cipher == 0 ? "N/A " : "",
  134. sta->pairwise_cipher & WPA_CIPHER_NONE ? "NONE " : "",
  135. sta->pairwise_cipher & WPA_CIPHER_TKIP ? "TKIP " : "",
  136. sta->pairwise_cipher & WPA_CIPHER_CCMP ? "CCMP " : "",
  137. sta->key_mgmt == 0 ? "N/A " : "",
  138. sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X ? "EAP " : "",
  139. sta->key_mgmt & WPA_KEY_MGMT_PSK ? "PSK " : "",
  140. sta->key_mgmt & WPA_KEY_MGMT_WPA_NONE ? "WPA-NONE " : "",
  141. sta->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X ? "FT-EAP " : "",
  142. sta->key_mgmt & WPA_KEY_MGMT_FT_PSK ? "FT-PSK " : "",
  143. sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256 ?
  144. "EAP-SHA256 " : "",
  145. sta->key_mgmt & WPA_KEY_MGMT_PSK_SHA256 ?
  146. "PSK-SHA256 " : "",
  147. sta->rsn_capab & WPA_CAPABILITY_PREAUTH ? "PREAUTH " : "",
  148. sta->rsn_capab & WPA_CAPABILITY_NO_PAIRWISE ?
  149. "NO_PAIRWISE " : "",
  150. sta->rsn_capab & WPA_CAPABILITY_MFPR ? "MFPR " : "",
  151. sta->rsn_capab & WPA_CAPABILITY_MFPC ? "MFPC " : "",
  152. sta->rsn_capab & WPA_CAPABILITY_PEERKEY_ENABLED ?
  153. "PEERKEY " : "");
  154. }