| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * STA list |
| 3 | * Copyright (c) 2010-2015, 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 | (bss->beacon_seen || bss->proberesp_seen)) { |
| 71 | wpa_printf(MSG_INFO, "WPA IE included in Association Request " |
| 72 | "frame from " MACSTR " even though BSS does not " |
| 73 | "use WPA - ignore IE", |
| 74 | MAC2STR(sta->addr)); |
| 75 | elems->wpa_ie = NULL; |
| 76 | } |
| 77 | |
| 78 | if (elems->rsn_ie && !bss->rsnie[0] && |
| 79 | (bss->beacon_seen || bss->proberesp_seen)) { |
| 80 | wpa_printf(MSG_INFO, "RSN IE included in Association Request " |
| 81 | "frame from " MACSTR " even though BSS does not " |
| 82 | "use RSN - ignore IE", |
| 83 | MAC2STR(sta->addr)); |
| 84 | elems->rsn_ie = NULL; |
| 85 | } |
| 86 | |
| 87 | if (elems->osen && !bss->osenie[0] && |
| 88 | (bss->beacon_seen || bss->proberesp_seen)) { |
| 89 | wpa_printf(MSG_INFO, "OSEN IE included in Association Request " |
| 90 | "frame from " MACSTR " even though BSS does not " |
| 91 | "use OSEN - ignore IE", |
| 92 | MAC2STR(sta->addr)); |
| 93 | elems->osen = NULL; |
| 94 | } |
| 95 | |
| 96 | if (elems->wpa_ie && elems->rsn_ie) { |
| 97 | wpa_printf(MSG_INFO, "Both WPA IE and RSN IE included in " |
| 98 | "Association Request frame from " MACSTR, |
| 99 | MAC2STR(sta->addr)); |
| 100 | } |
| 101 | |
| 102 | if (elems->rsn_ie) { |
| 103 | wpa_hexdump(MSG_DEBUG, "RSN IE", elems->rsn_ie - 2, |
| 104 | elems->rsn_ie_len + 2); |
| 105 | os_memcpy(sta->rsnie, elems->rsn_ie - 2, |
| 106 | elems->rsn_ie_len + 2); |
| 107 | if (wpa_parse_wpa_ie_rsn(sta->rsnie, 2 + sta->rsnie[1], &data) |
| 108 | < 0) { |
| 109 | wpa_printf(MSG_INFO, "Failed to parse RSN IE from " |
| 110 | MACSTR, MAC2STR(sta->addr)); |
| 111 | } |
| 112 | } else if (elems->wpa_ie) { |
| 113 | wpa_hexdump(MSG_DEBUG, "WPA IE", elems->wpa_ie - 2, |
| 114 | elems->wpa_ie_len + 2); |
| 115 | os_memcpy(sta->rsnie, elems->wpa_ie - 2, |
| 116 | elems->wpa_ie_len + 2); |
| 117 | if (wpa_parse_wpa_ie_wpa(sta->rsnie, 2 + sta->rsnie[1], &data) |
| 118 | < 0) { |
| 119 | wpa_printf(MSG_INFO, "Failed to parse WPA IE from " |
| 120 | MACSTR, MAC2STR(sta->addr)); |
| 121 | } |
| 122 | } else if (elems->osen) { |
| 123 | wpa_hexdump(MSG_DEBUG, "OSEN IE", elems->osen - 2, |
| 124 | elems->osen_len + 2); |
| 125 | os_memcpy(sta->osenie, elems->osen - 2, elems->osen_len + 2); |
| 126 | sta->proto = WPA_PROTO_OSEN; |
| 127 | sta->pairwise_cipher = WPA_CIPHER_CCMP; |
| 128 | sta->key_mgmt = WPA_KEY_MGMT_OSEN; |
| 129 | sta->rsn_capab = 0; |
| 130 | goto skip_rsn_wpa; |
| 131 | } else { |
| 132 | sta->rsnie[0] = 0; |
| 133 | sta->proto = 0; |
| 134 | sta->pairwise_cipher = 0; |
| 135 | sta->key_mgmt = 0; |
| 136 | sta->rsn_capab = 0; |
| 137 | if (sta->assocreq_capab_info & WLAN_CAPABILITY_PRIVACY) |
| 138 | sta->pairwise_cipher = WPA_CIPHER_WEP40; |
| 139 | goto skip_rsn_wpa; |
| 140 | } |
| 141 | |
| 142 | sta->proto = data.proto; |
| 143 | sta->pairwise_cipher = data.pairwise_cipher; |
| 144 | sta->key_mgmt = data.key_mgmt; |
| 145 | sta->rsn_capab = data.capabilities; |
| 146 | if (bss->proto && (sta->proto & bss->proto) == 0) { |
| 147 | wpa_printf(MSG_INFO, "Mismatch in WPA/WPA2 proto: STA " |
| 148 | MACSTR " 0x%x BSS " MACSTR " 0x%x", |
| 149 | MAC2STR(sta->addr), sta->proto, |
| 150 | MAC2STR(bss->bssid), bss->proto); |
| 151 | } |
| 152 | if (bss->pairwise_cipher && |
| 153 | (sta->pairwise_cipher & bss->pairwise_cipher) == 0) { |
| 154 | wpa_printf(MSG_INFO, "Mismatch in pairwise cipher: STA " |
| 155 | MACSTR " 0x%x BSS " MACSTR " 0x%x", |
| 156 | MAC2STR(sta->addr), sta->pairwise_cipher, |
| 157 | MAC2STR(bss->bssid), bss->pairwise_cipher); |
| 158 | } |
| 159 | if (sta->proto && data.group_cipher != bss->group_cipher) { |
| 160 | wpa_printf(MSG_INFO, "Mismatch in group cipher: STA " |
| 161 | MACSTR " 0x%x != BSS " MACSTR " 0x%x", |
| 162 | MAC2STR(sta->addr), data.group_cipher, |
| 163 | MAC2STR(bss->bssid), bss->group_cipher); |
| 164 | } |
| 165 | if ((bss->rsn_capab & WPA_CAPABILITY_MFPR) && |
| 166 | !(sta->rsn_capab & WPA_CAPABILITY_MFPC)) { |
| 167 | wpa_printf(MSG_INFO, "STA " MACSTR " tries to associate " |
| 168 | "without MFP to BSS " MACSTR " that advertises " |
| 169 | "MFPR", MAC2STR(sta->addr), MAC2STR(bss->bssid)); |
| 170 | } |
| 171 | if ((sta->rsn_capab & WPA_CAPABILITY_OCVC) && |
| 172 | !(sta->rsn_capab & WPA_CAPABILITY_MFPC)) { |
| 173 | wpa_printf(MSG_INFO, "STA " MACSTR " tries to associate " |
| 174 | "without MFP to BSS " MACSTR " while supporting " |
| 175 | "OCV", MAC2STR(sta->addr), MAC2STR(bss->bssid)); |
| 176 | } |
| 177 | |
| 178 | skip_rsn_wpa: |
| 179 | wpa_printf(MSG_INFO, "STA " MACSTR |
| 180 | " proto=%s%s%s%s" |
| 181 | "pairwise=%s%s%s%s%s%s%s" |
| 182 | "key_mgmt=%s%s%s%s%s%s%s%s%s%s%s" |
| 183 | "rsn_capab=%s%s%s%s%s%s", |
| 184 | MAC2STR(sta->addr), |
| 185 | sta->proto == 0 ? "OPEN " : "", |
| 186 | sta->proto & WPA_PROTO_WPA ? "WPA " : "", |
| 187 | sta->proto & WPA_PROTO_RSN ? "WPA2 " : "", |
| 188 | sta->proto & WPA_PROTO_OSEN ? "OSEN " : "", |
| 189 | sta->pairwise_cipher == 0 ? "N/A " : "", |
| 190 | sta->pairwise_cipher & WPA_CIPHER_NONE ? "NONE " : "", |
| 191 | sta->pairwise_cipher & WPA_CIPHER_TKIP ? "TKIP " : "", |
| 192 | sta->pairwise_cipher & WPA_CIPHER_CCMP ? "CCMP " : "", |
| 193 | bss->pairwise_cipher & WPA_CIPHER_CCMP_256 ? "CCMP-256 " : |
| 194 | "", |
| 195 | bss->pairwise_cipher & WPA_CIPHER_GCMP ? "GCMP " : "", |
| 196 | bss->pairwise_cipher & WPA_CIPHER_GCMP_256 ? "GCMP-256 " : |
| 197 | "", |
| 198 | sta->key_mgmt == 0 ? "N/A " : "", |
| 199 | sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X ? "EAP " : "", |
| 200 | sta->key_mgmt & WPA_KEY_MGMT_PSK ? "PSK " : "", |
| 201 | sta->key_mgmt & WPA_KEY_MGMT_WPA_NONE ? "WPA-NONE " : "", |
| 202 | sta->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X ? "FT-EAP " : "", |
| 203 | sta->key_mgmt & WPA_KEY_MGMT_FT_PSK ? "FT-PSK " : "", |
| 204 | sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256 ? |
| 205 | "EAP-SHA256 " : "", |
| 206 | sta->key_mgmt & WPA_KEY_MGMT_PSK_SHA256 ? |
| 207 | "PSK-SHA256 " : "", |
| 208 | sta->key_mgmt & WPA_KEY_MGMT_OSEN ? "OSEN " : "", |
| 209 | sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B ? |
| 210 | "EAP-SUITE-B " : "", |
| 211 | sta->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 ? |
| 212 | "EAP-SUITE-B-192 " : "", |
| 213 | sta->rsn_capab & WPA_CAPABILITY_PREAUTH ? "PREAUTH " : "", |
| 214 | sta->rsn_capab & WPA_CAPABILITY_NO_PAIRWISE ? |
| 215 | "NO_PAIRWISE " : "", |
| 216 | sta->rsn_capab & WPA_CAPABILITY_MFPR ? "MFPR " : "", |
| 217 | sta->rsn_capab & WPA_CAPABILITY_MFPC ? "MFPC " : "", |
| 218 | sta->rsn_capab & WPA_CAPABILITY_PEERKEY_ENABLED ? |
| 219 | "PEERKEY " : "", |
| 220 | sta->rsn_capab & WPA_CAPABILITY_OCVC ? "OCVC " : ""); |
| 221 | } |