3 * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "common/defs.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/ieee802_11_common.h"
18 struct wlantest_sta * sta_find(struct wlantest_bss *bss, const u8 *addr)
20 struct wlantest_sta *sta;
22 dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
23 if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
31 struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
33 struct wlantest_sta *sta;
36 return NULL; /* Skip group addressed frames */
38 sta = sta_find(bss, addr);
42 sta = os_zalloc(sizeof(*sta));
45 os_memset(sta->seq_ctrl_to_sta, 0xff, sizeof(sta->seq_ctrl_to_sta));
46 os_memset(sta->seq_ctrl_to_ap, 0xff, sizeof(sta->seq_ctrl_to_ap));
48 os_memcpy(sta->addr, addr, ETH_ALEN);
49 dl_list_add(&bss->sta, &sta->list);
50 wpa_printf(MSG_DEBUG, "Discovered new STA " MACSTR " in BSS " MACSTR,
51 MAC2STR(sta->addr), MAC2STR(bss->bssid));
56 void sta_deinit(struct wlantest_sta *sta)
58 dl_list_del(&sta->list);
59 os_free(sta->assocreq_ies);
64 void sta_update_assoc(struct wlantest_sta *sta, struct ieee802_11_elems *elems)
66 struct wpa_ie_data data;
67 struct wlantest_bss *bss = sta->bss;
69 if (elems->wpa_ie && !bss->wpaie[0]) {
70 wpa_printf(MSG_INFO, "WPA IE included in Association Request "
71 "frame from " MACSTR " even though BSS does not "
72 "use WPA - ignore IE",
77 if (elems->rsn_ie && !bss->rsnie[0]) {
78 wpa_printf(MSG_INFO, "RSN IE included in Association Request "
79 "frame from " MACSTR " even though BSS does not "
80 "use RSN - ignore IE",
85 if (elems->wpa_ie && elems->rsn_ie) {
86 wpa_printf(MSG_INFO, "Both WPA IE and RSN IE included in "
87 "Association Request frame from " MACSTR,
92 wpa_hexdump(MSG_DEBUG, "RSN IE", elems->rsn_ie - 2,
93 elems->rsn_ie_len + 2);
94 os_memcpy(sta->rsnie, elems->rsn_ie - 2,
95 elems->rsn_ie_len + 2);
96 if (wpa_parse_wpa_ie_rsn(sta->rsnie, 2 + sta->rsnie[1], &data)
98 wpa_printf(MSG_INFO, "Failed to parse RSN IE from "
99 MACSTR, MAC2STR(sta->addr));
101 } else if (elems->wpa_ie) {
102 wpa_hexdump(MSG_DEBUG, "WPA IE", elems->wpa_ie - 2,
103 elems->wpa_ie_len + 2);
104 os_memcpy(sta->rsnie, elems->wpa_ie - 2,
105 elems->wpa_ie_len + 2);
106 if (wpa_parse_wpa_ie_wpa(sta->rsnie, 2 + sta->rsnie[1], &data)
108 wpa_printf(MSG_INFO, "Failed to parse WPA IE from "
109 MACSTR, MAC2STR(sta->addr));
114 sta->pairwise_cipher = 0;
117 if (sta->assocreq_capab_info & WLAN_CAPABILITY_PRIVACY)
118 sta->pairwise_cipher = WPA_CIPHER_WEP40;
122 sta->proto = data.proto;
123 sta->pairwise_cipher = data.pairwise_cipher;
124 sta->key_mgmt = data.key_mgmt;
125 sta->rsn_capab = data.capabilities;
126 if (bss->proto && (sta->proto & bss->proto) == 0) {
127 wpa_printf(MSG_INFO, "Mismatch in WPA/WPA2 proto: STA "
128 MACSTR " 0x%x BSS " MACSTR " 0x%x",
129 MAC2STR(sta->addr), sta->proto,
130 MAC2STR(bss->bssid), bss->proto);
132 if (bss->pairwise_cipher &&
133 (sta->pairwise_cipher & bss->pairwise_cipher) == 0) {
134 wpa_printf(MSG_INFO, "Mismatch in pairwise cipher: STA "
135 MACSTR " 0x%x BSS " MACSTR " 0x%x",
136 MAC2STR(sta->addr), sta->pairwise_cipher,
137 MAC2STR(bss->bssid), bss->pairwise_cipher);
139 if (sta->proto && data.group_cipher != bss->group_cipher) {
140 wpa_printf(MSG_INFO, "Mismatch in group cipher: STA "
141 MACSTR " 0x%x != BSS " MACSTR " 0x%x",
142 MAC2STR(sta->addr), data.group_cipher,
143 MAC2STR(bss->bssid), bss->group_cipher);
145 if ((bss->rsn_capab & WPA_CAPABILITY_MFPR) &&
146 !(sta->rsn_capab & WPA_CAPABILITY_MFPC)) {
147 wpa_printf(MSG_INFO, "STA " MACSTR " tries to associate "
148 "without MFP to BSS " MACSTR " that advertises "
149 "MFPR", MAC2STR(sta->addr), MAC2STR(bss->bssid));
153 wpa_printf(MSG_INFO, "STA " MACSTR
156 "key_mgmt=%s%s%s%s%s%s%s%s"
157 "rsn_capab=%s%s%s%s%s",
159 sta->proto == 0 ? "OPEN " : "",
160 sta->proto & WPA_PROTO_WPA ? "WPA " : "",
161 sta->proto & WPA_PROTO_RSN ? "WPA2 " : "",
162 sta->pairwise_cipher == 0 ? "N/A " : "",
163 sta->pairwise_cipher & WPA_CIPHER_NONE ? "NONE " : "",
164 sta->pairwise_cipher & WPA_CIPHER_TKIP ? "TKIP " : "",
165 sta->pairwise_cipher & WPA_CIPHER_CCMP ? "CCMP " : "",
166 sta->key_mgmt == 0 ? "N/A " : "",
167 sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X ? "EAP " : "",
168 sta->key_mgmt & WPA_KEY_MGMT_PSK ? "PSK " : "",
169 sta->key_mgmt & WPA_KEY_MGMT_WPA_NONE ? "WPA-NONE " : "",
170 sta->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X ? "FT-EAP " : "",
171 sta->key_mgmt & WPA_KEY_MGMT_FT_PSK ? "FT-PSK " : "",
172 sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256 ?
174 sta->key_mgmt & WPA_KEY_MGMT_PSK_SHA256 ?
176 sta->rsn_capab & WPA_CAPABILITY_PREAUTH ? "PREAUTH " : "",
177 sta->rsn_capab & WPA_CAPABILITY_NO_PAIRWISE ?
179 sta->rsn_capab & WPA_CAPABILITY_MFPR ? "MFPR " : "",
180 sta->rsn_capab & WPA_CAPABILITY_MFPC ? "MFPC " : "",
181 sta->rsn_capab & WPA_CAPABILITY_PEERKEY_ENABLED ?