wlantest: Verify MFP use in association with MFPR BSS
[mech_eap.git] / wlantest / sta.c
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
15 #include "utils/includes.h"
16
17 #include "utils/common.h"
18 #include "common/defs.h"
19 #include "common/ieee802_11_common.h"
20 #include "wlantest.h"
21
22
23 struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
24 {
25         struct wlantest_sta *sta;
26
27         if (addr[0] & 0x01)
28                 return NULL; /* Skip group addressed frames */
29
30         dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
31                 if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
32                         return sta;
33         }
34
35         sta = os_zalloc(sizeof(*sta));
36         if (sta == NULL)
37                 return NULL;
38         sta->bss = bss;
39         os_memcpy(sta->addr, addr, ETH_ALEN);
40         dl_list_add(&bss->sta, &sta->list);
41         wpa_printf(MSG_DEBUG, "Discovered new STA " MACSTR " in BSS " MACSTR,
42                    MAC2STR(sta->addr), MAC2STR(bss->bssid));
43         return sta;
44 }
45
46
47 void sta_deinit(struct wlantest_sta *sta)
48 {
49         dl_list_del(&sta->list);
50         os_free(sta);
51 }
52
53
54 void sta_update_assoc(struct wlantest_sta *sta, struct ieee802_11_elems *elems)
55 {
56         struct wpa_ie_data data;
57         struct wlantest_bss *bss = sta->bss;
58
59         if (elems->wpa_ie && elems->rsn_ie) {
60                 wpa_printf(MSG_INFO, "Both WPA IE and RSN IE included in "
61                            "Association Request frame from " MACSTR,
62                            MAC2STR(sta->addr));
63         }
64
65         if (elems->rsn_ie) {
66                 wpa_hexdump(MSG_DEBUG, "RSN IE", elems->rsn_ie - 2,
67                             elems->rsn_ie_len + 2);
68                 os_memcpy(sta->rsnie, elems->rsn_ie - 2,
69                           elems->rsn_ie_len + 2);
70                 if (wpa_parse_wpa_ie_rsn(sta->rsnie, 2 + sta->rsnie[1], &data)
71                     < 0) {
72                         wpa_printf(MSG_INFO, "Failed to parse RSN IE from "
73                                    MACSTR, MAC2STR(sta->addr));
74                 }
75         } else if (elems->wpa_ie) {
76                 wpa_hexdump(MSG_DEBUG, "WPA IE", elems->wpa_ie - 2,
77                             elems->wpa_ie_len + 2);
78                 os_memcpy(sta->rsnie, elems->wpa_ie - 2,
79                           elems->wpa_ie_len + 2);
80                 if (wpa_parse_wpa_ie_wpa(sta->rsnie, 2 + sta->rsnie[1], &data)
81                     < 0) {
82                         wpa_printf(MSG_INFO, "Failed to parse WPA IE from "
83                                    MACSTR, MAC2STR(sta->addr));
84                 }
85         } else
86                 sta->rsnie[0] = 0;
87
88         sta->proto = data.proto;
89         sta->pairwise_cipher = data.pairwise_cipher;
90         sta->key_mgmt = data.key_mgmt;
91         sta->rsn_capab = data.capabilities;
92         if (bss->proto && (sta->proto & bss->proto) == 0) {
93                 wpa_printf(MSG_INFO, "Mismatch in WPA/WPA2 proto: STA "
94                            MACSTR " 0x%x  BSS " MACSTR " 0x%x",
95                            MAC2STR(sta->addr), sta->proto,
96                            MAC2STR(bss->bssid), bss->proto);
97         }
98         if (bss->pairwise_cipher &&
99             (sta->pairwise_cipher & bss->pairwise_cipher) == 0) {
100                 wpa_printf(MSG_INFO, "Mismatch in pairwise cipher: STA "
101                            MACSTR " 0x%x  BSS " MACSTR " 0x%x",
102                            MAC2STR(sta->addr), sta->pairwise_cipher,
103                            MAC2STR(bss->bssid), bss->pairwise_cipher);
104         }
105         if (sta->proto && data.group_cipher != bss->group_cipher) {
106                 wpa_printf(MSG_INFO, "Mismatch in group cipher: STA "
107                            MACSTR " 0x%x != BSS " MACSTR " 0x%x",
108                            MAC2STR(sta->addr), data.group_cipher,
109                            MAC2STR(bss->bssid), bss->group_cipher);
110         }
111         if ((bss->rsn_capab & WPA_CAPABILITY_MFPR) &&
112             !(sta->rsn_capab & WPA_CAPABILITY_MFPC)) {
113                 wpa_printf(MSG_INFO, "STA " MACSTR " tries to associate "
114                            "without MFP to BSS " MACSTR " that advertises "
115                            "MFPR", MAC2STR(sta->addr), MAC2STR(bss->bssid));
116         }
117
118         wpa_printf(MSG_INFO, "STA " MACSTR
119                    " proto=%s%s%s"
120                    "pairwise=%s%s%s%s"
121                    "key_mgmt=%s%s%s%s%s%s%s%s"
122                    "rsn_capab=%s%s%s%s%s",
123                    MAC2STR(sta->addr),
124                    sta->proto == 0 ? "OPEN " : "",
125                    sta->proto & WPA_PROTO_WPA ? "WPA " : "",
126                    sta->proto & WPA_PROTO_RSN ? "WPA2 " : "",
127                    sta->pairwise_cipher == 0 ? "N/A " : "",
128                    sta->pairwise_cipher & WPA_CIPHER_NONE ? "NONE " : "",
129                    sta->pairwise_cipher & WPA_CIPHER_TKIP ? "TKIP " : "",
130                    sta->pairwise_cipher & WPA_CIPHER_CCMP ? "CCMP " : "",
131                    sta->key_mgmt == 0 ? "N/A " : "",
132                    sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X ? "EAP " : "",
133                    sta->key_mgmt & WPA_KEY_MGMT_PSK ? "PSK " : "",
134                    sta->key_mgmt & WPA_KEY_MGMT_WPA_NONE ? "WPA-NONE " : "",
135                    sta->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X ? "FT-EAP " : "",
136                    sta->key_mgmt & WPA_KEY_MGMT_FT_PSK ? "FT-PSK " : "",
137                    sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256 ?
138                    "EAP-SHA256 " : "",
139                    sta->key_mgmt & WPA_KEY_MGMT_PSK_SHA256 ?
140                    "PSK-SHA256 " : "",
141                    sta->rsn_capab & WPA_CAPABILITY_PREAUTH ? "PREAUTH " : "",
142                    sta->rsn_capab & WPA_CAPABILITY_NO_PAIRWISE ?
143                    "NO_PAIRWISE " : "",
144                    sta->rsn_capab & WPA_CAPABILITY_MFPR ? "MFPR " : "",
145                    sta->rsn_capab & WPA_CAPABILITY_MFPC ? "MFPC " : "",
146                    sta->rsn_capab & WPA_CAPABILITY_PEERKEY_ENABLED ?
147                    "PEERKEY " : "");
148 }