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