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