1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * 802.1x EAPOL definitions 4 * 5 * See 6 * IEEE Std 802.1X-2001 7 * IEEE 802.1X RADIUS Usage Guidelines 8 * 9 * Copyright (C) 1999-2019, Broadcom. 10 * 11 * Unless you and Broadcom execute a separate written software license 12 * agreement governing use of this software, this software is licensed to you 13 * under the terms of the GNU General Public License version 2 (the "GPL"), 14 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 15 * following added to such license: 16 * 17 * As a special exception, the copyright holders of this software give you 18 * permission to link this software with independent modules, and to copy and 19 * distribute the resulting executable under terms of your choice, provided that 20 * you also meet, for each linked independent module, the terms and conditions of 21 * the license of that module. An independent module is a module which is not 22 * derived from this software. The special exception does not apply to any 23 * modifications of the software. 24 * 25 * Notwithstanding the above, under no circumstances may you combine this 26 * software in any way with any other Broadcom software provided under a license 27 * other than the GPL, without Broadcom's express prior written consent. 28 * 29 * 30 * <<Broadcom-WL-IPTag/Open:>> 31 * 32 * $Id: eapol.h 809460 2019-03-14 00:35:24Z $ 33 */ 34 35 #ifndef _eapol_h_ 36 #define _eapol_h_ 37 38 #ifndef _TYPEDEFS_H_ 39 #include <typedefs.h> 40 #endif // endif 41 42 /* This marks the start of a packed structure section. */ 43 #include <packed_section_start.h> 44 45 #if !defined(BCMCRYPTO_COMPONENT) 46 #include <bcmcrypto/aeskeywrap.h> 47 #endif /* !BCMCRYPTO_COMPONENT */ 48 49 /* EAPOL for 802.3/Ethernet */ 50 typedef BWL_PRE_PACKED_STRUCT struct { 51 struct ether_header eth; /* 802.3/Ethernet header */ 52 unsigned char version; /* EAPOL protocol version */ 53 unsigned char type; /* EAPOL type */ 54 unsigned short length; /* Length of body */ 55 unsigned char body[1]; /* Body (optional) */ 56 } BWL_POST_PACKED_STRUCT eapol_header_t; 57 58 #define EAPOL_HEADER_LEN 18 59 60 typedef struct { 61 unsigned char version; /* EAPOL protocol version */ 62 unsigned char type; /* EAPOL type */ 63 unsigned short length; /* Length of body */ 64 } eapol_hdr_t; 65 66 #define EAPOL_HDR_LEN 4u 67 68 /* EAPOL version */ 69 #define WPA2_EAPOL_VERSION 2u 70 #define WPA_EAPOL_VERSION 1u 71 #define LEAP_EAPOL_VERSION 1u 72 #define SES_EAPOL_VERSION 1u 73 74 /* EAPOL types */ 75 #define EAP_PACKET 0 76 #define EAPOL_START 1u 77 #define EAPOL_LOGOFF 2u 78 #define EAPOL_KEY 3u 79 #define EAPOL_ASF 4u 80 81 /* EAPOL-Key types */ 82 #define EAPOL_RC4_KEY 1u 83 #define EAPOL_WPA2_KEY 2u /* 802.11i/WPA2 */ 84 #define EAPOL_WPA_KEY 254u /* WPA */ 85 86 /* RC4 EAPOL-Key header field sizes */ 87 #define EAPOL_KEY_REPLAY_LEN 8u 88 #define EAPOL_KEY_IV_LEN 16u 89 #define EAPOL_KEY_SIG_LEN 16u 90 91 /* RC4 EAPOL-Key */ 92 typedef BWL_PRE_PACKED_STRUCT struct { 93 unsigned char type; /* Key Descriptor Type */ 94 unsigned short length; /* Key Length (unaligned) */ 95 unsigned char replay[EAPOL_KEY_REPLAY_LEN]; /* Replay Counter */ 96 unsigned char iv[EAPOL_KEY_IV_LEN]; /* Key IV */ 97 unsigned char index; /* Key Flags & Index */ 98 unsigned char signature[EAPOL_KEY_SIG_LEN]; /* Key Signature */ 99 unsigned char key[1]; /* Key (optional) */ 100 } BWL_POST_PACKED_STRUCT eapol_key_header_t; 101 102 #define EAPOL_KEY_HEADER_LEN 44u 103 104 /* RC4 EAPOL-Key flags */ 105 #define EAPOL_KEY_FLAGS_MASK 0x80u 106 #define EAPOL_KEY_BROADCAST 0u 107 #define EAPOL_KEY_UNICAST 0x80u 108 109 /* RC4 EAPOL-Key index */ 110 #define EAPOL_KEY_INDEX_MASK 0x7fu 111 112 /* WPA/802.11i/WPA2 EAPOL-Key header field sizes */ 113 #define EAPOL_AKW_BLOCK_LEN 8 114 #define EAPOL_WPA_KEY_REPLAY_LEN 8u 115 #define EAPOL_WPA_KEY_NONCE_LEN 32u 116 #define EAPOL_WPA_KEY_IV_LEN 16u 117 #define EAPOL_WPA_KEY_RSC_LEN 8u 118 #define EAPOL_WPA_KEY_ID_LEN 8u 119 #define EAPOL_WPA_KEY_DATA_LEN (EAPOL_WPA_MAX_KEY_SIZE + EAPOL_AKW_BLOCK_LEN) 120 #define EAPOL_WPA_MAX_KEY_SIZE 32u 121 #define EAPOL_WPA_KEY_MAX_MIC_LEN 32u 122 #define EAPOL_WPA_ENCR_KEY_MAX_LEN 64u 123 #define EAPOL_WPA_TEMP_ENCR_KEY_MAX_LEN 32u 124 125 #define EAPOL_WPA_PMK_MAX_LEN 64u 126 #define EAPOL_WPA_PMK_SHA384_LEN 48u 127 #define EAPOL_WPA_PMK_DEFAULT_LEN 32u 128 #define EAPOL_WPA_KCK_DEFAULT_LEN 16u 129 #define EAPOL_WPA_KCK_SHA384_LEN 24u 130 #define EAPOL_WPA_KCK_MIC_DEFAULT_LEN 16u 131 #define EAPOL_WPA_KCK_MIC_SHA384_LEN 24u 132 #define EAPOL_WPA_ENCR_KEY_DEFAULT_LEN 16u 133 134 #define EAPOL_WPA_KEK2_SHA256_LEN 16u 135 #define EAPOL_WPA_KEK2_SHA384_LEN 32u 136 #define EAPOL_WPA_KCK2_SHA256_LEN 16u 137 #define EAPOL_WPA_KCK2_SHA384_LEN 24u 138 139 #ifndef EAPOL_KEY_HDR_VER_V2 140 #define EAPOL_WPA_KEY_MIC_LEN 16u /* deprecated */ 141 #define EAPOL_WPA_KEY_LEN 95u /* deprecated */ 142 #endif // endif 143 144 #define EAPOL_PTK_KEY_MAX_LEN (EAPOL_WPA_KEY_MAX_MIC_LEN +\ 145 EAPOL_WPA_ENCR_KEY_MAX_LEN +\ 146 EAPOL_WPA_TEMP_ENCR_KEY_MAX_LEN +\ 147 EAPOL_WPA_KCK2_SHA384_LEN +\ 148 EAPOL_WPA_KEK2_SHA384_LEN) 149 150 #ifndef EAPOL_KEY_HDR_VER_V2 151 152 /* WPA EAPOL-Key : deprecated */ 153 typedef BWL_PRE_PACKED_STRUCT struct { 154 unsigned char type; /* Key Descriptor Type */ 155 unsigned short key_info; /* Key Information (unaligned) */ 156 unsigned short key_len; /* Key Length (unaligned) */ 157 unsigned char replay[EAPOL_WPA_KEY_REPLAY_LEN]; /* Replay Counter */ 158 unsigned char nonce[EAPOL_WPA_KEY_NONCE_LEN]; /* Nonce */ 159 unsigned char iv[EAPOL_WPA_KEY_IV_LEN]; /* Key IV */ 160 unsigned char rsc[EAPOL_WPA_KEY_RSC_LEN]; /* Key RSC */ 161 unsigned char id[EAPOL_WPA_KEY_ID_LEN]; /* WPA:Key ID, 802.11i/WPA2: Reserved */ 162 unsigned char mic[EAPOL_WPA_KEY_MIC_LEN]; /* Key MIC */ 163 unsigned short data_len; /* Key Data Length */ 164 unsigned char data[EAPOL_WPA_KEY_DATA_LEN]; /* Key data */ 165 } BWL_POST_PACKED_STRUCT eapol_wpa_key_header_t; 166 #else 167 /* WPA EAPOL-Key : new structure to consider dynamic MIC length */ 168 typedef BWL_PRE_PACKED_STRUCT struct { 169 unsigned char type; /* Key Descriptor Type */ 170 unsigned short key_info; /* Key Information (unaligned) */ 171 unsigned short key_len; /* Key Length (unaligned) */ 172 unsigned char replay[EAPOL_WPA_KEY_REPLAY_LEN]; /* Replay Counter */ 173 unsigned char nonce[EAPOL_WPA_KEY_NONCE_LEN]; /* Nonce */ 174 unsigned char iv[EAPOL_WPA_KEY_IV_LEN]; /* Key IV */ 175 unsigned char rsc[EAPOL_WPA_KEY_RSC_LEN]; /* Key RSC */ 176 unsigned char id[EAPOL_WPA_KEY_ID_LEN]; /* WPA:Key ID, 802.11i/WPA2: Reserved */ 177 } BWL_POST_PACKED_STRUCT eapol_wpa_key_header_v2_t; 178 179 typedef eapol_wpa_key_header_v2_t eapol_wpa_key_header_t; 180 #endif /* EAPOL_KEY_HDR_VER_V2 */ 181 182 #define EAPOL_WPA_KEY_DATA_LEN_SIZE 2u 183 184 #ifdef EAPOL_KEY_HDR_VER_V2 185 #define EAPOL_WPA_KEY_HDR_SIZE(mic_len) (sizeof(eapol_wpa_key_header_v2_t) \ 186 + mic_len + EAPOL_WPA_KEY_DATA_LEN_SIZE) 187 188 /* WPA EAPOL-Key header macros to reach out mic/data_len/data field */ 189 #define EAPOL_WPA_KEY_HDR_MIC_PTR(pos) ((uint8 *)pos + sizeof(eapol_wpa_key_header_v2_t)) 190 #define EAPOL_WPA_KEY_HDR_DATA_LEN_PTR(pos, mic_len) \ 191 ((uint8 *)pos + sizeof(eapol_wpa_key_header_v2_t) + mic_len) 192 #define EAPOL_WPA_KEY_HDR_DATA_PTR(pos, mic_len) \ 193 ((uint8 *)pos + EAPOL_WPA_KEY_HDR_SIZE(mic_len)) 194 #else 195 #define EAPOL_WPA_KEY_HDR_SIZE(mic_len) EAPOL_WPA_KEY_LEN 196 #define EAPOL_WPA_KEY_HDR_MIC_PTR(pos) ((uint8 *)&pos->mic) 197 #define EAPOL_WPA_KEY_HDR_DATA_LEN_PTR(pos, mic_len) ((uint8 *)&pos->data_len) 198 #define EAPOL_WPA_KEY_HDR_DATA_PTR(pos, mic_len) ((uint8 *)&pos->data) 199 #endif /* EAPOL_KEY_HDR_VER_V2 */ 200 201 /* WPA/802.11i/WPA2 KEY KEY_INFO bits */ 202 #define WPA_KEY_DESC_OSEN 0x0 203 #define WPA_KEY_DESC_V0 0x0 204 #define WPA_KEY_DESC_V1 0x01 205 #define WPA_KEY_DESC_V2 0x02 206 #define WPA_KEY_DESC_V3 0x03 207 #define WPA_KEY_PAIRWISE 0x08 208 #define WPA_KEY_INSTALL 0x40 209 #define WPA_KEY_ACK 0x80 210 #define WPA_KEY_MIC 0x100 211 #define WPA_KEY_SECURE 0x200 212 #define WPA_KEY_ERROR 0x400 213 #define WPA_KEY_REQ 0x800 214 #define WPA_KEY_ENC_KEY_DATA 0x01000 /* Encrypted Key Data */ 215 #define WPA_KEY_SMK_MESSAGE 0x02000 /* SMK Message */ 216 #define WPA_KEY_DESC_VER(_ki) ((_ki) & 0x03u) 217 218 #define WPA_KEY_DESC_V2_OR_V3 WPA_KEY_DESC_V2 219 220 /* WPA-only KEY KEY_INFO bits */ 221 #define WPA_KEY_INDEX_0 0x00 222 #define WPA_KEY_INDEX_1 0x10 223 #define WPA_KEY_INDEX_2 0x20 224 #define WPA_KEY_INDEX_3 0x30 225 #define WPA_KEY_INDEX_MASK 0x30 226 #define WPA_KEY_INDEX_SHIFT 0x04 227 228 /* 802.11i/WPA2-only KEY KEY_INFO bits */ 229 #define WPA_KEY_ENCRYPTED_DATA 0x1000 230 231 /* Key Data encapsulation */ 232 typedef BWL_PRE_PACKED_STRUCT struct { 233 uint8 type; 234 uint8 length; 235 uint8 oui[3]; 236 uint8 subtype; 237 uint8 data[1]; 238 } BWL_POST_PACKED_STRUCT eapol_wpa2_encap_data_t; 239 240 #define EAPOL_WPA2_ENCAP_DATA_HDR_LEN 6 241 242 #define WPA2_KEY_DATA_SUBTYPE_GTK 1 243 #define WPA2_KEY_DATA_SUBTYPE_STAKEY 2 244 #define WPA2_KEY_DATA_SUBTYPE_MAC 3 245 #define WPA2_KEY_DATA_SUBTYPE_PMKID 4 246 #define WPA2_KEY_DATA_SUBTYPE_IGTK 9 247 248 /* GTK encapsulation */ 249 typedef BWL_PRE_PACKED_STRUCT struct { 250 uint8 flags; 251 uint8 reserved; 252 uint8 gtk[EAPOL_WPA_MAX_KEY_SIZE]; 253 } BWL_POST_PACKED_STRUCT eapol_wpa2_key_gtk_encap_t; 254 255 #define EAPOL_WPA2_KEY_GTK_ENCAP_HDR_LEN 2 256 257 #define WPA2_GTK_INDEX_MASK 0x03 258 #define WPA2_GTK_INDEX_SHIFT 0x00 259 260 #define WPA2_GTK_TRANSMIT 0x04 261 262 /* IGTK encapsulation */ 263 typedef BWL_PRE_PACKED_STRUCT struct { 264 uint16 key_id; 265 uint8 ipn[6]; 266 uint8 key[EAPOL_WPA_MAX_KEY_SIZE]; 267 } BWL_POST_PACKED_STRUCT eapol_wpa2_key_igtk_encap_t; 268 269 #define EAPOL_WPA2_KEY_IGTK_ENCAP_HDR_LEN 8 270 271 /* STAKey encapsulation */ 272 typedef BWL_PRE_PACKED_STRUCT struct { 273 uint8 reserved[2]; 274 uint8 mac[ETHER_ADDR_LEN]; 275 uint8 stakey[EAPOL_WPA_MAX_KEY_SIZE]; 276 } BWL_POST_PACKED_STRUCT eapol_wpa2_key_stakey_encap_t; 277 278 #define WPA2_KEY_DATA_PAD 0xdd 279 280 /* This marks the end of a packed structure section. */ 281 #include <packed_section_end.h> 282 283 #endif /* _eapol_h_ */ 284