3 * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "common/defs.h"
19 #include "common/ieee802_11_common.h"
23 struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
25 struct wlantest_sta *sta;
28 return NULL; /* Skip group addressed frames */
30 dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
31 if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
35 sta = os_zalloc(sizeof(*sta));
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));
47 void sta_deinit(struct wlantest_sta *sta)
49 dl_list_del(&sta->list);
54 void sta_update_assoc(struct wlantest_sta *sta, struct ieee802_11_elems *elems)
56 struct wpa_ie_data data;
57 struct wlantest_bss *bss = sta->bss;
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,
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)
72 wpa_printf(MSG_INFO, "Failed to parse RSN IE from "
73 MACSTR, MAC2STR(sta->addr));
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)
82 wpa_printf(MSG_INFO, "Failed to parse WPA IE from "
83 MACSTR, MAC2STR(sta->addr));
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);
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);
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);
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));
118 wpa_printf(MSG_INFO, "STA " MACSTR
121 "key_mgmt=%s%s%s%s%s%s%s%s"
122 "rsn_capab=%s%s%s%s%s",
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 ?
139 sta->key_mgmt & WPA_KEY_MGMT_PSK_SHA256 ?
141 sta->rsn_capab & WPA_CAPABILITY_PREAUTH ? "PREAUTH " : "",
142 sta->rsn_capab & WPA_CAPABILITY_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 ?