sta.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * STA list
  3. * Copyright (c) 2010-2015, 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 "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "common/defs.h"
  11. #include "common/ieee802_11_defs.h"
  12. #include "common/ieee802_11_common.h"
  13. #include "wlantest.h"
  14. struct wlantest_sta * sta_find(struct wlantest_bss *bss, const u8 *addr)
  15. {
  16. struct wlantest_sta *sta;
  17. dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
  18. if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
  19. return sta;
  20. }
  21. return NULL;
  22. }
  23. struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
  24. {
  25. struct wlantest_sta *sta;
  26. if (addr[0] & 0x01)
  27. return NULL; /* Skip group addressed frames */
  28. sta = sta_find(bss, addr);
  29. if (sta)
  30. return sta;
  31. sta = os_zalloc(sizeof(*sta));
  32. if (sta == NULL)
  33. return NULL;
  34. os_memset(sta->seq_ctrl_to_sta, 0xff, sizeof(sta->seq_ctrl_to_sta));
  35. os_memset(sta->seq_ctrl_to_ap, 0xff, sizeof(sta->seq_ctrl_to_ap));
  36. sta->bss = bss;
  37. os_memcpy(sta->addr, addr, ETH_ALEN);
  38. dl_list_add(&bss->sta, &sta->list);
  39. wpa_printf(MSG_DEBUG, "Discovered new STA " MACSTR " in BSS " MACSTR,
  40. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  41. return sta;
  42. }
  43. void sta_deinit(struct wlantest_sta *sta)
  44. {
  45. dl_list_del(&sta->list);
  46. os_free(sta->assocreq_ies);
  47. os_free(sta);
  48. }
  49. void sta_update_assoc(struct wlantest_sta *sta, struct ieee802_11_elems *elems)
  50. {
  51. struct wpa_ie_data data;
  52. struct wlantest_bss *bss = sta->bss;
  53. if (elems->wpa_ie && !bss->wpaie[0] &&
  54. (bss->beacon_seen || bss->proberesp_seen)) {
  55. wpa_printf(MSG_INFO, "WPA IE included in Association Request "
  56. "frame from " MACSTR " even though BSS does not "
  57. "use WPA - ignore IE",
  58. MAC2STR(sta->addr));
  59. elems->wpa_ie = NULL;
  60. }
  61. if (elems->rsn_ie && !bss->rsnie[0] &&
  62. (bss->beacon_seen || bss->proberesp_seen)) {
  63. wpa_printf(MSG_INFO, "RSN IE included in Association Request "
  64. "frame from " MACSTR " even though BSS does not "
  65. "use RSN - ignore IE",
  66. MAC2STR(sta->addr));
  67. elems->rsn_ie = NULL;
  68. }
  69. if (elems->osen && !bss->osenie[0] &&
  70. (bss->beacon_seen || bss->proberesp_seen)) {
  71. wpa_printf(MSG_INFO, "OSEN IE included in Association Request "
  72. "frame from " MACSTR " even though BSS does not "
  73. "use OSEN - ignore IE",
  74. MAC2STR(sta->addr));
  75. elems->osen = NULL;
  76. }
  77. if (elems->wpa_ie && elems->rsn_ie) {
  78. wpa_printf(MSG_INFO, "Both WPA IE and RSN IE included in "
  79. "Association Request frame from " MACSTR,
  80. MAC2STR(sta->addr));
  81. }
  82. if (elems->rsn_ie) {
  83. wpa_hexdump(MSG_DEBUG, "RSN IE", elems->rsn_ie - 2,
  84. elems->rsn_ie_len + 2);
  85. os_memcpy(sta->rsnie, elems->rsn_ie - 2,
  86. elems->rsn_ie_len + 2);
  87. if (wpa_parse_wpa_ie_rsn(sta->rsnie, 2 + sta->rsnie[1], &data)
  88. < 0) {
  89. wpa_printf(MSG_INFO, "Failed to parse RSN IE from "
  90. MACSTR, MAC2STR(sta->addr));
  91. }
  92. } else if (elems->wpa_ie) {
  93. wpa_hexdump(MSG_DEBUG, "WPA IE", elems->wpa_ie - 2,
  94. elems->wpa_ie_len + 2);
  95. os_memcpy(sta->rsnie, elems->wpa_ie - 2,
  96. elems->wpa_ie_len + 2);
  97. if (wpa_parse_wpa_ie_wpa(sta->rsnie, 2 + sta->rsnie[1], &data)
  98. < 0) {
  99. wpa_printf(MSG_INFO, "Failed to parse WPA IE from "
  100. MACSTR, MAC2STR(sta->addr));
  101. }
  102. } else if (elems->osen) {
  103. wpa_hexdump(MSG_DEBUG, "OSEN IE", elems->osen - 2,
  104. elems->osen_len + 2);
  105. os_memcpy(sta->osenie, elems->osen - 2, elems->osen_len + 2);
  106. sta->proto = WPA_PROTO_OSEN;
  107. sta->pairwise_cipher = WPA_CIPHER_CCMP;
  108. sta->key_mgmt = WPA_KEY_MGMT_OSEN;
  109. sta->rsn_capab = 0;
  110. goto skip_rsn_wpa;
  111. } else {
  112. sta->rsnie[0] = 0;
  113. sta->proto = 0;
  114. sta->pairwise_cipher = 0;
  115. sta->key_mgmt = 0;
  116. sta->rsn_capab = 0;
  117. if (sta->assocreq_capab_info & WLAN_CAPABILITY_PRIVACY)
  118. sta->pairwise_cipher = WPA_CIPHER_WEP40;
  119. goto skip_rsn_wpa;
  120. }
  121. sta->proto = data.proto;
  122. sta->pairwise_cipher = data.pairwise_cipher;
  123. sta->key_mgmt = data.key_mgmt;
  124. sta->rsn_capab = data.capabilities;
  125. if (bss->proto && (sta->proto & bss->proto) == 0) {
  126. wpa_printf(MSG_INFO, "Mismatch in WPA/WPA2 proto: STA "
  127. MACSTR " 0x%x BSS " MACSTR " 0x%x",
  128. MAC2STR(sta->addr), sta->proto,
  129. MAC2STR(bss->bssid), bss->proto);
  130. }
  131. if (bss->pairwise_cipher &&
  132. (sta->pairwise_cipher & bss->pairwise_cipher) == 0) {
  133. wpa_printf(MSG_INFO, "Mismatch in pairwise cipher: STA "
  134. MACSTR " 0x%x BSS " MACSTR " 0x%x",
  135. MAC2STR(sta->addr), sta->pairwise_cipher,
  136. MAC2STR(bss->bssid), bss->pairwise_cipher);
  137. }
  138. if (sta->proto && data.group_cipher != bss->group_cipher) {
  139. wpa_printf(MSG_INFO, "Mismatch in group cipher: STA "
  140. MACSTR " 0x%x != BSS " MACSTR " 0x%x",
  141. MAC2STR(sta->addr), data.group_cipher,
  142. MAC2STR(bss->bssid), bss->group_cipher);
  143. }
  144. if ((bss->rsn_capab & WPA_CAPABILITY_MFPR) &&
  145. !(sta->rsn_capab & WPA_CAPABILITY_MFPC)) {
  146. wpa_printf(MSG_INFO, "STA " MACSTR " tries to associate "
  147. "without MFP to BSS " MACSTR " that advertises "
  148. "MFPR", MAC2STR(sta->addr), MAC2STR(bss->bssid));
  149. }
  150. skip_rsn_wpa:
  151. wpa_printf(MSG_INFO, "STA " MACSTR
  152. " proto=%s%s%s%s"
  153. "pairwise=%s%s%s%s%s%s%s"
  154. "key_mgmt=%s%s%s%s%s%s%s%s%s%s%s"
  155. "rsn_capab=%s%s%s%s%s",
  156. MAC2STR(sta->addr),
  157. sta->proto == 0 ? "OPEN " : "",
  158. sta->proto & WPA_PROTO_WPA ? "WPA " : "",
  159. sta->proto & WPA_PROTO_RSN ? "WPA2 " : "",
  160. sta->proto & WPA_PROTO_OSEN ? "OSEN " : "",
  161. sta->pairwise_cipher == 0 ? "N/A " : "",
  162. sta->pairwise_cipher & WPA_CIPHER_NONE ? "NONE " : "",
  163. sta->pairwise_cipher & WPA_CIPHER_TKIP ? "TKIP " : "",
  164. sta->pairwise_cipher & WPA_CIPHER_CCMP ? "CCMP " : "",
  165. bss->pairwise_cipher & WPA_CIPHER_CCMP_256 ? "CCMP-256 " :
  166. "",
  167. bss->pairwise_cipher & WPA_CIPHER_GCMP ? "GCMP " : "",
  168. bss->pairwise_cipher & WPA_CIPHER_GCMP_256 ? "GCMP-256 " :
  169. "",
  170. sta->key_mgmt == 0 ? "N/A " : "",
  171. sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X ? "EAP " : "",
  172. sta->key_mgmt & WPA_KEY_MGMT_PSK ? "PSK " : "",
  173. sta->key_mgmt & WPA_KEY_MGMT_WPA_NONE ? "WPA-NONE " : "",
  174. sta->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X ? "FT-EAP " : "",
  175. sta->key_mgmt & WPA_KEY_MGMT_FT_PSK ? "FT-PSK " : "",
  176. sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256 ?
  177. "EAP-SHA256 " : "",
  178. sta->key_mgmt & WPA_KEY_MGMT_PSK_SHA256 ?
  179. "PSK-SHA256 " : "",
  180. sta->key_mgmt & WPA_KEY_MGMT_OSEN ? "OSEN " : "",
  181. sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B ?
  182. "EAP-SUITE-B " : "",
  183. sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 ?
  184. "EAP-SUITE-B-192 " : "",
  185. sta->rsn_capab & WPA_CAPABILITY_PREAUTH ? "PREAUTH " : "",
  186. sta->rsn_capab & WPA_CAPABILITY_NO_PAIRWISE ?
  187. "NO_PAIRWISE " : "",
  188. sta->rsn_capab & WPA_CAPABILITY_MFPR ? "MFPR " : "",
  189. sta->rsn_capab & WPA_CAPABILITY_MFPC ? "MFPC " : "",
  190. sta->rsn_capab & WPA_CAPABILITY_PEERKEY_ENABLED ?
  191. "PEERKEY " : "");
  192. }