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