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
->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",
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
,
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
)
106 wpa_printf(MSG_INFO
, "Failed to parse RSN IE from "
107 MACSTR
, MAC2STR(sta
->addr
));
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
)
116 wpa_printf(MSG_INFO
, "Failed to parse WPA IE from "
117 MACSTR
, MAC2STR(sta
->addr
));
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
;
131 sta
->pairwise_cipher
= 0;
134 if (sta
->assocreq_capab_info
& WLAN_CAPABILITY_PRIVACY
)
135 sta
->pairwise_cipher
= WPA_CIPHER_WEP40
;
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
);
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
);
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
);
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
));
170 wpa_printf(MSG_INFO
, "STA " MACSTR
172 "pairwise=%s%s%s%s%s%s%s"
173 "key_mgmt=%s%s%s%s%s%s%s%s%s%s"
174 "rsn_capab=%s%s%s%s%s",
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 " :
186 bss
->pairwise_cipher
& WPA_CIPHER_GCMP
? "GCMP " : "",
187 bss
->pairwise_cipher
& WPA_CIPHER_GCMP_256
? "GCMP-256 " :
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
?
197 sta
->key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
?
199 sta
->key_mgmt
& WPA_KEY_MGMT_OSEN
? "OSEN " : "",
200 sta
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
?
202 sta
->rsn_capab
& WPA_CAPABILITY_PREAUTH
? "PREAUTH " : "",
203 sta
->rsn_capab
& WPA_CAPABILITY_NO_PAIRWISE
?
205 sta
->rsn_capab
& WPA_CAPABILITY_MFPR
? "MFPR " : "",
206 sta
->rsn_capab
& WPA_CAPABILITY_MFPC
? "MFPC " : "",
207 sta
->rsn_capab
& WPA_CAPABILITY_PEERKEY_ENABLED
?