sta.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 && !bss->wpaie[0]) {
  60. wpa_printf(MSG_INFO, "WPA IE included in Association Request "
  61. "frame from " MACSTR " even though BSS does not "
  62. "use WPA - ignore IE",
  63. MAC2STR(sta->addr));
  64. elems->wpa_ie = NULL;
  65. }
  66. if (elems->rsn_ie && !bss->rsnie[0]) {
  67. wpa_printf(MSG_INFO, "RSN IE included in Association Request "
  68. "frame from " MACSTR " even though BSS does not "
  69. "use RSN - ignore IE",
  70. MAC2STR(sta->addr));
  71. elems->rsn_ie = NULL;
  72. }
  73. if (elems->wpa_ie && elems->rsn_ie) {
  74. wpa_printf(MSG_INFO, "Both WPA IE and RSN IE included in "
  75. "Association Request frame from " MACSTR,
  76. MAC2STR(sta->addr));
  77. }
  78. if (elems->rsn_ie) {
  79. wpa_hexdump(MSG_DEBUG, "RSN IE", elems->rsn_ie - 2,
  80. elems->rsn_ie_len + 2);
  81. os_memcpy(sta->rsnie, elems->rsn_ie - 2,
  82. elems->rsn_ie_len + 2);
  83. if (wpa_parse_wpa_ie_rsn(sta->rsnie, 2 + sta->rsnie[1], &data)
  84. < 0) {
  85. wpa_printf(MSG_INFO, "Failed to parse RSN IE from "
  86. MACSTR, MAC2STR(sta->addr));
  87. }
  88. } else if (elems->wpa_ie) {
  89. wpa_hexdump(MSG_DEBUG, "WPA IE", elems->wpa_ie - 2,
  90. elems->wpa_ie_len + 2);
  91. os_memcpy(sta->rsnie, elems->wpa_ie - 2,
  92. elems->wpa_ie_len + 2);
  93. if (wpa_parse_wpa_ie_wpa(sta->rsnie, 2 + sta->rsnie[1], &data)
  94. < 0) {
  95. wpa_printf(MSG_INFO, "Failed to parse WPA IE from "
  96. MACSTR, MAC2STR(sta->addr));
  97. }
  98. } else {
  99. sta->rsnie[0] = 0;
  100. sta->proto = 0;
  101. sta->pairwise_cipher = 0;
  102. sta->key_mgmt = 0;
  103. sta->rsn_capab = 0;
  104. if (sta->assocreq_capab_info & WLAN_CAPABILITY_PRIVACY)
  105. sta->pairwise_cipher = WPA_CIPHER_WEP40;
  106. goto skip_rsn_wpa;
  107. }
  108. sta->proto = data.proto;
  109. sta->pairwise_cipher = data.pairwise_cipher;
  110. sta->key_mgmt = data.key_mgmt;
  111. sta->rsn_capab = data.capabilities;
  112. if (bss->proto && (sta->proto & bss->proto) == 0) {
  113. wpa_printf(MSG_INFO, "Mismatch in WPA/WPA2 proto: STA "
  114. MACSTR " 0x%x BSS " MACSTR " 0x%x",
  115. MAC2STR(sta->addr), sta->proto,
  116. MAC2STR(bss->bssid), bss->proto);
  117. }
  118. if (bss->pairwise_cipher &&
  119. (sta->pairwise_cipher & bss->pairwise_cipher) == 0) {
  120. wpa_printf(MSG_INFO, "Mismatch in pairwise cipher: STA "
  121. MACSTR " 0x%x BSS " MACSTR " 0x%x",
  122. MAC2STR(sta->addr), sta->pairwise_cipher,
  123. MAC2STR(bss->bssid), bss->pairwise_cipher);
  124. }
  125. if (sta->proto && data.group_cipher != bss->group_cipher) {
  126. wpa_printf(MSG_INFO, "Mismatch in group cipher: STA "
  127. MACSTR " 0x%x != BSS " MACSTR " 0x%x",
  128. MAC2STR(sta->addr), data.group_cipher,
  129. MAC2STR(bss->bssid), bss->group_cipher);
  130. }
  131. if ((bss->rsn_capab & WPA_CAPABILITY_MFPR) &&
  132. !(sta->rsn_capab & WPA_CAPABILITY_MFPC)) {
  133. wpa_printf(MSG_INFO, "STA " MACSTR " tries to associate "
  134. "without MFP to BSS " MACSTR " that advertises "
  135. "MFPR", MAC2STR(sta->addr), MAC2STR(bss->bssid));
  136. }
  137. skip_rsn_wpa:
  138. wpa_printf(MSG_INFO, "STA " MACSTR
  139. " proto=%s%s%s"
  140. "pairwise=%s%s%s%s"
  141. "key_mgmt=%s%s%s%s%s%s%s%s"
  142. "rsn_capab=%s%s%s%s%s",
  143. MAC2STR(sta->addr),
  144. sta->proto == 0 ? "OPEN " : "",
  145. sta->proto & WPA_PROTO_WPA ? "WPA " : "",
  146. sta->proto & WPA_PROTO_RSN ? "WPA2 " : "",
  147. sta->pairwise_cipher == 0 ? "N/A " : "",
  148. sta->pairwise_cipher & WPA_CIPHER_NONE ? "NONE " : "",
  149. sta->pairwise_cipher & WPA_CIPHER_TKIP ? "TKIP " : "",
  150. sta->pairwise_cipher & WPA_CIPHER_CCMP ? "CCMP " : "",
  151. sta->key_mgmt == 0 ? "N/A " : "",
  152. sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X ? "EAP " : "",
  153. sta->key_mgmt & WPA_KEY_MGMT_PSK ? "PSK " : "",
  154. sta->key_mgmt & WPA_KEY_MGMT_WPA_NONE ? "WPA-NONE " : "",
  155. sta->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X ? "FT-EAP " : "",
  156. sta->key_mgmt & WPA_KEY_MGMT_FT_PSK ? "FT-PSK " : "",
  157. sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256 ?
  158. "EAP-SHA256 " : "",
  159. sta->key_mgmt & WPA_KEY_MGMT_PSK_SHA256 ?
  160. "PSK-SHA256 " : "",
  161. sta->rsn_capab & WPA_CAPABILITY_PREAUTH ? "PREAUTH " : "",
  162. sta->rsn_capab & WPA_CAPABILITY_NO_PAIRWISE ?
  163. "NO_PAIRWISE " : "",
  164. sta->rsn_capab & WPA_CAPABILITY_MFPR ? "MFPR " : "",
  165. sta->rsn_capab & WPA_CAPABILITY_MFPC ? "MFPC " : "",
  166. sta->rsn_capab & WPA_CAPABILITY_PEERKEY_ENABLED ?
  167. "PEERKEY " : "");
  168. }