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