]>
Commit | Line | Data |
---|---|---|
422ef7d2 JM |
1 | /* |
2 | * STA list | |
3 | * Copyright (c) 2010, Jouni Malinen <j@w1.fi> | |
4 | * | |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
422ef7d2 JM |
7 | */ |
8 | ||
9 | #include "utils/includes.h" | |
10 | ||
11 | #include "utils/common.h" | |
327f7160 | 12 | #include "common/defs.h" |
2e479416 | 13 | #include "common/ieee802_11_defs.h" |
021a6fe4 | 14 | #include "common/ieee802_11_common.h" |
422ef7d2 JM |
15 | #include "wlantest.h" |
16 | ||
17 | ||
57f7d03f | 18 | struct wlantest_sta * sta_find(struct wlantest_bss *bss, const u8 *addr) |
422ef7d2 JM |
19 | { |
20 | struct wlantest_sta *sta; | |
21 | ||
422ef7d2 JM |
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 | ||
57f7d03f JM |
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 | ||
422ef7d2 JM |
42 | sta = os_zalloc(sizeof(*sta)); |
43 | if (sta == NULL) | |
44 | return NULL; | |
a912dd16 JM |
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)); | |
327f7160 | 47 | sta->bss = bss; |
422ef7d2 JM |
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); | |
990153b4 | 59 | os_free(sta->assocreq_ies); |
422ef7d2 JM |
60 | os_free(sta); |
61 | } | |
021a6fe4 JM |
62 | |
63 | ||
64 | void sta_update_assoc(struct wlantest_sta *sta, struct ieee802_11_elems *elems) | |
65 | { | |
327f7160 JM |
66 | struct wpa_ie_data data; |
67 | struct wlantest_bss *bss = sta->bss; | |
68 | ||
2caf6924 JM |
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 | ||
021a6fe4 JM |
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, | |
88 | MAC2STR(sta->addr)); | |
89 | } | |
90 | ||
91 | if (elems->rsn_ie) { | |
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); | |
327f7160 JM |
96 | if (wpa_parse_wpa_ie_rsn(sta->rsnie, 2 + sta->rsnie[1], &data) |
97 | < 0) { | |
98 | wpa_printf(MSG_INFO, "Failed to parse RSN IE from " | |
99 | MACSTR, MAC2STR(sta->addr)); | |
100 | } | |
021a6fe4 JM |
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); | |
327f7160 JM |
106 | if (wpa_parse_wpa_ie_wpa(sta->rsnie, 2 + sta->rsnie[1], &data) |
107 | < 0) { | |
108 | wpa_printf(MSG_INFO, "Failed to parse WPA IE from " | |
109 | MACSTR, MAC2STR(sta->addr)); | |
110 | } | |
2e479416 | 111 | } else { |
021a6fe4 | 112 | sta->rsnie[0] = 0; |
2e479416 JM |
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 | } | |
327f7160 JM |
121 | |
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); | |
131 | } | |
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); | |
138 | } | |
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); | |
144 | } | |
070d6173 JM |
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)); | |
150 | } | |
327f7160 | 151 | |
2e479416 | 152 | skip_rsn_wpa: |
327f7160 JM |
153 | wpa_printf(MSG_INFO, "STA " MACSTR |
154 | " proto=%s%s%s" | |
155 | "pairwise=%s%s%s%s" | |
156 | "key_mgmt=%s%s%s%s%s%s%s%s" | |
157 | "rsn_capab=%s%s%s%s%s", | |
158 | MAC2STR(sta->addr), | |
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 ? | |
173 | "EAP-SHA256 " : "", | |
174 | sta->key_mgmt & WPA_KEY_MGMT_PSK_SHA256 ? | |
175 | "PSK-SHA256 " : "", | |
176 | sta->rsn_capab & WPA_CAPABILITY_PREAUTH ? "PREAUTH " : "", | |
177 | sta->rsn_capab & WPA_CAPABILITY_NO_PAIRWISE ? | |
178 | "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 ? | |
182 | "PEERKEY " : ""); | |
021a6fe4 | 183 | } |