• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * WPA definitions shared between hostapd and wpa_supplicant
3  * Copyright (c) 2002-2018, 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 #ifndef WPA_COMMON_H
10 #define WPA_COMMON_H
11 
12 /* IEEE 802.11i */
13 #define PMKID_LEN 16
14 #define PMK_LEN 32
15 #define PMK_LEN_SUITE_B_192 48
16 #define PMK_LEN_MAX 64
17 #define WPA_REPLAY_COUNTER_LEN 8
18 #define WPA_NONCE_LEN 32
19 #define WPA_KEY_RSC_LEN 8
20 #define WPA_GMK_LEN 32
21 #define WPA_GTK_MAX_LEN 32
22 #define WPA_PASN_PMK_LEN 32
23 #define WPA_PASN_MAX_MIC_LEN 24
24 #define WPA_MAX_RSNXE_LEN 4
25 
26 #define OWE_DH_GROUP 19
27 
28 #ifdef CONFIG_NO_TKIP
29 #define WPA_ALLOWED_PAIRWISE_CIPHERS \
30 (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_NONE | \
31 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256)
32 #define WPA_ALLOWED_GROUP_CIPHERS \
33 (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | \
34 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256 | \
35 WPA_CIPHER_GTK_NOT_USED)
36 #else /* CONFIG_NO_TKIP */
37 #define WPA_ALLOWED_PAIRWISE_CIPHERS \
38 (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_TKIP | WPA_CIPHER_NONE | \
39 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256)
40 #define WPA_ALLOWED_GROUP_CIPHERS \
41 (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_TKIP | \
42 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256 | \
43 WPA_CIPHER_GTK_NOT_USED)
44 #endif /* CONFIG_NO_TKIP */
45 #define WPA_ALLOWED_GROUP_MGMT_CIPHERS \
46 (WPA_CIPHER_AES_128_CMAC | WPA_CIPHER_BIP_GMAC_128 | WPA_CIPHER_BIP_GMAC_256 | \
47 WPA_CIPHER_BIP_CMAC_256)
48 
49 #define WPA_SELECTOR_LEN 4
50 #define WPA_VERSION 1
51 #define RSN_SELECTOR_LEN 4
52 #define RSN_VERSION 1
53 
54 #define RSN_SELECTOR(a, b, c, d) \
55 	((((u32) (a)) << 24) | (((u32) (b)) << 16) | (((u32) (c)) << 8) | \
56 	 (u32) (d))
57 
58 #define WPA_AUTH_KEY_MGMT_NONE RSN_SELECTOR(0x00, 0x50, 0xf2, 0)
59 #define WPA_AUTH_KEY_MGMT_UNSPEC_802_1X RSN_SELECTOR(0x00, 0x50, 0xf2, 1)
60 #define WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X RSN_SELECTOR(0x00, 0x50, 0xf2, 2)
61 #define WPA_AUTH_KEY_MGMT_CCKM RSN_SELECTOR(0x00, 0x40, 0x96, 0)
62 #define WPA_CIPHER_SUITE_NONE RSN_SELECTOR(0x00, 0x50, 0xf2, 0)
63 #define WPA_CIPHER_SUITE_TKIP RSN_SELECTOR(0x00, 0x50, 0xf2, 2)
64 #define WPA_CIPHER_SUITE_CCMP RSN_SELECTOR(0x00, 0x50, 0xf2, 4)
65 
66 
67 #define RSN_AUTH_KEY_MGMT_UNSPEC_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
68 #define RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
69 #define RSN_AUTH_KEY_MGMT_FT_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
70 #define RSN_AUTH_KEY_MGMT_FT_PSK RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
71 #define RSN_AUTH_KEY_MGMT_802_1X_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 5)
72 #define RSN_AUTH_KEY_MGMT_PSK_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 6)
73 #define RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE RSN_SELECTOR(0x00, 0x0f, 0xac, 7)
74 #define RSN_AUTH_KEY_MGMT_SAE RSN_SELECTOR(0x00, 0x0f, 0xac, 8)
75 #define RSN_AUTH_KEY_MGMT_FT_SAE RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
76 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
77 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192 RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
78 #define RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
79 #define RSN_AUTH_KEY_MGMT_FILS_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 14)
80 #define RSN_AUTH_KEY_MGMT_FILS_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 15)
81 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 16)
82 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 17)
83 #define RSN_AUTH_KEY_MGMT_OWE RSN_SELECTOR(0x00, 0x0f, 0xac, 18)
84 #define RSN_AUTH_KEY_MGMT_FT_PSK_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 19)
85 #define RSN_AUTH_KEY_MGMT_PSK_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 20)
86 #define RSN_AUTH_KEY_MGMT_PASN RSN_SELECTOR(0x00, 0x0f, 0xac, 21)
87 #define RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384_UNRESTRICTED \
88 	RSN_SELECTOR(0x00, 0x0f, 0xac, 22)
89 #define RSN_AUTH_KEY_MGMT_802_1X_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 23)
90 #define RSN_AUTH_KEY_MGMT_SAE_EXT_KEY RSN_SELECTOR(0x00, 0x0f, 0xac, 24)
91 #define RSN_AUTH_KEY_MGMT_FT_SAE_EXT_KEY RSN_SELECTOR(0x00, 0x0f, 0xac, 25)
92 
93 #define RSN_AUTH_KEY_MGMT_CCKM RSN_SELECTOR(0x00, 0x40, 0x96, 0x00)
94 #define RSN_AUTH_KEY_MGMT_OSEN RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x01)
95 #define RSN_AUTH_KEY_MGMT_DPP RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x02)
96 
97 #define RSN_CIPHER_SUITE_NONE RSN_SELECTOR(0x00, 0x0f, 0xac, 0)
98 #define RSN_CIPHER_SUITE_WEP40 RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
99 #define RSN_CIPHER_SUITE_TKIP RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
100 #if 0
101 #define RSN_CIPHER_SUITE_WRAP RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
102 #endif
103 #define RSN_CIPHER_SUITE_CCMP RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
104 #define RSN_CIPHER_SUITE_WEP104 RSN_SELECTOR(0x00, 0x0f, 0xac, 5)
105 #define RSN_CIPHER_SUITE_AES_128_CMAC RSN_SELECTOR(0x00, 0x0f, 0xac, 6)
106 #define RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED RSN_SELECTOR(0x00, 0x0f, 0xac, 7)
107 #define RSN_CIPHER_SUITE_GCMP RSN_SELECTOR(0x00, 0x0f, 0xac, 8)
108 #define RSN_CIPHER_SUITE_GCMP_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
109 #define RSN_CIPHER_SUITE_CCMP_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 10)
110 #define RSN_CIPHER_SUITE_BIP_GMAC_128 RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
111 #define RSN_CIPHER_SUITE_BIP_GMAC_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
112 #define RSN_CIPHER_SUITE_BIP_CMAC_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
113 #define RSN_CIPHER_SUITE_SMS4 RSN_SELECTOR(0x00, 0x14, 0x72, 1)
114 #define RSN_CIPHER_SUITE_CKIP RSN_SELECTOR(0x00, 0x40, 0x96, 0)
115 #define RSN_CIPHER_SUITE_CKIP_CMIC RSN_SELECTOR(0x00, 0x40, 0x96, 1)
116 #define RSN_CIPHER_SUITE_CMIC RSN_SELECTOR(0x00, 0x40, 0x96, 2)
117 /* KRK is defined for nl80211 use only */
118 #define RSN_CIPHER_SUITE_KRK RSN_SELECTOR(0x00, 0x40, 0x96, 255)
119 
120 /* EAPOL-Key Key Data Encapsulation
121  * GroupKey and PeerKey require encryption, otherwise, encryption is optional.
122  */
123 #define RSN_KEY_DATA_GROUPKEY RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
124 #if 0
125 #define RSN_KEY_DATA_STAKEY RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
126 #endif
127 #define RSN_KEY_DATA_MAC_ADDR RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
128 #define RSN_KEY_DATA_PMKID RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
129 #define RSN_KEY_DATA_IGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
130 #define RSN_KEY_DATA_KEYID RSN_SELECTOR(0x00, 0x0f, 0xac, 10)
131 #define RSN_KEY_DATA_MULTIBAND_GTK RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
132 #define RSN_KEY_DATA_MULTIBAND_KEYID RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
133 #define RSN_KEY_DATA_OCI RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
134 #define RSN_KEY_DATA_BIGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 14)
135 #define RSN_KEY_DATA_MLO_GTK RSN_SELECTOR(0x00, 0x0f, 0xac, 16)
136 #define RSN_KEY_DATA_MLO_IGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 17)
137 #define RSN_KEY_DATA_MLO_BIGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 18)
138 #define RSN_KEY_DATA_MLO_LINK RSN_SELECTOR(0x00, 0x0f, 0xac, 19)
139 
140 #define WFA_KEY_DATA_IP_ADDR_REQ RSN_SELECTOR(0x50, 0x6f, 0x9a, 4)
141 #define WFA_KEY_DATA_IP_ADDR_ALLOC RSN_SELECTOR(0x50, 0x6f, 0x9a, 5)
142 #define WFA_KEY_DATA_TRANSITION_DISABLE RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x20)
143 #define WFA_KEY_DATA_DPP RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x21)
144 
145 #define WPA_OUI_TYPE RSN_SELECTOR(0x00, 0x50, 0xf2, 1)
146 
147 #define RSN_SELECTOR_PUT(a, val) WPA_PUT_BE32((u8 *) (a), (val))
148 #define RSN_SELECTOR_GET(a) WPA_GET_BE32((const u8 *) (a))
149 
150 #define RSN_NUM_REPLAY_COUNTERS_1 0
151 #define RSN_NUM_REPLAY_COUNTERS_2 1
152 #define RSN_NUM_REPLAY_COUNTERS_4 2
153 #define RSN_NUM_REPLAY_COUNTERS_16 3
154 
155 
156 #ifdef _MSC_VER
157 #pragma pack(push, 1)
158 #endif /* _MSC_VER */
159 
160 #define WPA_IGTK_LEN 16
161 #define WPA_IGTK_MAX_LEN 32
162 #define WPA_BIGTK_LEN 16
163 #define WPA_BIGTK_MAX_LEN 32
164 
165 
166 /* IEEE 802.11, 7.3.2.25.3 RSN Capabilities */
167 #define WPA_CAPABILITY_PREAUTH BIT(0)
168 #define WPA_CAPABILITY_NO_PAIRWISE BIT(1)
169 /* B2-B3: PTKSA Replay Counter */
170 /* B4-B5: GTKSA Replay Counter */
171 #define WPA_CAPABILITY_MFPR BIT(6)
172 #define WPA_CAPABILITY_MFPC BIT(7)
173 /* B8: Reserved */
174 #define WPA_CAPABILITY_PEERKEY_ENABLED BIT(9)
175 #define WPA_CAPABILITY_SPP_A_MSDU_CAPABLE BIT(10)
176 #define WPA_CAPABILITY_SPP_A_MSDU_REQUIRED BIT(11)
177 #define WPA_CAPABILITY_PBAC BIT(12)
178 #define WPA_CAPABILITY_EXT_KEY_ID_FOR_UNICAST BIT(13)
179 #define WPA_CAPABILITY_OCVC BIT(14)
180 /* B15: Reserved */
181 
182 
183 /* IEEE 802.11r */
184 #define MOBILITY_DOMAIN_ID_LEN 2
185 #define FT_R0KH_ID_MAX_LEN 48
186 #define FT_R1KH_ID_LEN 6
187 #define WPA_PMK_NAME_LEN 16
188 
189 /* FTE - MIC Control - RSNXE Used */
190 #define FTE_MIC_CTRL_RSNXE_USED BIT(0)
191 #define FTE_MIC_CTRL_MIC_LEN_MASK (BIT(1) | BIT(2) | BIT(3))
192 #define FTE_MIC_CTRL_MIC_LEN_SHIFT 1
193 
194 /* FTE - MIC Length subfield values */
195 enum ft_mic_len_subfield {
196 	FTE_MIC_LEN_16 = 0,
197 	FTE_MIC_LEN_24 = 1,
198 	FTE_MIC_LEN_32 = 2,
199 };
200 
201 
202 /* IEEE 802.11, 8.5.2 EAPOL-Key frames */
203 #define WPA_KEY_INFO_TYPE_MASK ((u16) (BIT(0) | BIT(1) | BIT(2)))
204 #define WPA_KEY_INFO_TYPE_AKM_DEFINED 0
205 #define WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 BIT(0)
206 #define WPA_KEY_INFO_TYPE_HMAC_SHA1_AES BIT(1)
207 #define WPA_KEY_INFO_TYPE_AES_128_CMAC 3
208 #define WPA_KEY_INFO_KEY_TYPE BIT(3) /* 1 = Pairwise, 0 = Group key */
209 /* bit4..5 is used in WPA, but is reserved in IEEE 802.11i/RSN */
210 #define WPA_KEY_INFO_KEY_INDEX_MASK (BIT(4) | BIT(5))
211 #define WPA_KEY_INFO_KEY_INDEX_SHIFT 4
212 #define WPA_KEY_INFO_INSTALL BIT(6) /* pairwise */
213 #define WPA_KEY_INFO_TXRX BIT(6) /* group */
214 #define WPA_KEY_INFO_ACK BIT(7)
215 #define WPA_KEY_INFO_MIC BIT(8)
216 #define WPA_KEY_INFO_SECURE BIT(9)
217 #define WPA_KEY_INFO_ERROR BIT(10)
218 #define WPA_KEY_INFO_REQUEST BIT(11)
219 #define WPA_KEY_INFO_ENCR_KEY_DATA BIT(12) /* IEEE 802.11i/RSN only */
220 #define WPA_KEY_INFO_SMK_MESSAGE BIT(13)
221 
222 
223 struct wpa_eapol_key {
224 	u8 type;
225 	/* Note: key_info, key_length, and key_data_length are unaligned */
226 	u8 key_info[2]; /* big endian */
227 	u8 key_length[2]; /* big endian */
228 	u8 replay_counter[WPA_REPLAY_COUNTER_LEN];
229 	u8 key_nonce[WPA_NONCE_LEN];
230 	u8 key_iv[16];
231 	u8 key_rsc[WPA_KEY_RSC_LEN];
232 	u8 key_id[8]; /* Reserved in IEEE 802.11i/RSN */
233 	/* variable length Key MIC field */
234 	/* big endian 2-octet Key Data Length field */
235 	/* followed by Key Data Length bytes of Key Data */
236 } STRUCT_PACKED;
237 
238 #define WPA_EAPOL_KEY_MIC_MAX_LEN 32
239 #define WPA_KCK_MAX_LEN 32
240 #define WPA_KEK_MAX_LEN 64
241 #define WPA_TK_MAX_LEN 32
242 #define WPA_KDK_MAX_LEN 32
243 #define FILS_ICK_MAX_LEN 48
244 #define FILS_FT_MAX_LEN 48
245 #define WPA_PASN_KCK_LEN 32
246 #define WPA_PASN_MIC_MAX_LEN 24
247 #define WPA_LTF_KEYSEED_MAX_LEN 48
248 
249 /**
250  * struct wpa_ptk - WPA Pairwise Transient Key
251  * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
252  */
253 struct wpa_ptk {
254 	u8 kck[WPA_KCK_MAX_LEN]; /* EAPOL-Key Key Confirmation Key (KCK) */
255 	u8 kek[WPA_KEK_MAX_LEN]; /* EAPOL-Key Key Encryption Key (KEK) */
256 	u8 tk[WPA_TK_MAX_LEN]; /* Temporal Key (TK) */
257 	u8 kck2[WPA_KCK_MAX_LEN]; /* FT reasoc Key Confirmation Key (KCK2) */
258 	u8 kek2[WPA_KEK_MAX_LEN]; /* FT reassoc Key Encryption Key (KEK2) */
259 	u8 kdk[WPA_KDK_MAX_LEN]; /* Key Derivation Key */
260 	u8 ltf_keyseed[WPA_LTF_KEYSEED_MAX_LEN]; /* LTF Key seed */
261 	size_t kck_len;
262 	size_t kek_len;
263 	size_t tk_len;
264 	size_t kck2_len;
265 	size_t kek2_len;
266 	size_t kdk_len;
267 	size_t ltf_keyseed_len;
268 	int installed; /* 1 if key has already been installed to driver */
269 };
270 
271 struct wpa_gtk {
272 	u8 gtk[WPA_GTK_MAX_LEN];
273 	size_t gtk_len;
274 };
275 
276 struct wpa_igtk {
277 	u8 igtk[WPA_IGTK_MAX_LEN];
278 	size_t igtk_len;
279 };
280 
281 struct wpa_bigtk {
282 	u8 bigtk[WPA_BIGTK_MAX_LEN];
283 	size_t bigtk_len;
284 };
285 
286 /* WPA IE version 1
287  * 00-50-f2:1 (OUI:OUI type)
288  * 0x01 0x00 (version; little endian)
289  * (all following fields are optional:)
290  * Group Suite Selector (4 octets) (default: TKIP)
291  * Pairwise Suite Count (2 octets, little endian) (default: 1)
292  * Pairwise Suite List (4 * n octets) (default: TKIP)
293  * Authenticated Key Management Suite Count (2 octets, little endian)
294  *    (default: 1)
295  * Authenticated Key Management Suite List (4 * n octets)
296  *    (default: unspec 802.1X)
297  * WPA Capabilities (2 octets, little endian) (default: 0)
298  */
299 
300 struct wpa_ie_hdr {
301 	u8 elem_id;
302 	u8 len;
303 	u8 oui[4]; /* 24-bit OUI followed by 8-bit OUI type */
304 	u8 version[2]; /* little endian */
305 } STRUCT_PACKED;
306 
307 
308 /* 1/4: PMKID
309  * 2/4: RSN IE
310  * 3/4: one or two RSN IEs + GTK IE (encrypted)
311  * 4/4: empty
312  * 1/2: GTK IE (encrypted)
313  * 2/2: empty
314  */
315 
316 /* RSN IE version 1
317  * 0x01 0x00 (version; little endian)
318  * (all following fields are optional:)
319  * Group Suite Selector (4 octets) (default: CCMP)
320  * Pairwise Suite Count (2 octets, little endian) (default: 1)
321  * Pairwise Suite List (4 * n octets) (default: CCMP)
322  * Authenticated Key Management Suite Count (2 octets, little endian)
323  *    (default: 1)
324  * Authenticated Key Management Suite List (4 * n octets)
325  *    (default: unspec 802.1X)
326  * RSN Capabilities (2 octets, little endian) (default: 0)
327  * PMKID Count (2 octets) (default: 0)
328  * PMKID List (16 * n octets)
329  * Management Group Cipher Suite (4 octets) (default: AES-128-CMAC)
330  */
331 
332 struct rsn_ie_hdr {
333 	u8 elem_id; /* WLAN_EID_RSN */
334 	u8 len;
335 	u8 version[2]; /* little endian */
336 } STRUCT_PACKED;
337 
338 
339 struct rsn_error_kde {
340 	be16 mui;
341 	be16 error_type;
342 } STRUCT_PACKED;
343 
344 #define WPA_IGTK_KDE_PREFIX_LEN (2 + 6)
345 struct wpa_igtk_kde {
346 	u8 keyid[2];
347 	u8 pn[6];
348 	u8 igtk[WPA_IGTK_MAX_LEN];
349 } STRUCT_PACKED;
350 
351 #define WPA_BIGTK_KDE_PREFIX_LEN (2 + 6)
352 struct wpa_bigtk_kde {
353 	u8 keyid[2];
354 	u8 pn[6];
355 	u8 bigtk[WPA_BIGTK_MAX_LEN];
356 } STRUCT_PACKED;
357 
358 #define RSN_MLO_GTK_KDE_PREFIX_LENGTH		(1 + 6)
359 #define RSN_MLO_GTK_KDE_PREFIX0_KEY_ID_MASK	0x03
360 #define RSN_MLO_GTK_KDE_PREFIX0_TX		0x04
361 #define RSN_MLO_GTK_KDE_PREFIX0_LINK_ID_SHIFT	4
362 #define RSN_MLO_GTK_KDE_PREFIX0_LINK_ID_MASK	0xF0
363 
364 #define RSN_MLO_IGTK_KDE_PREFIX_LENGTH		(2 + 6 + 1)
365 #define RSN_MLO_IGTK_KDE_PREFIX8_LINK_ID_SHIFT	4
366 #define RSN_MLO_IGTK_KDE_PREFIX8_LINK_ID_MASK	0xF0
367 struct rsn_mlo_igtk_kde {
368 	u8 keyid[2];
369 	u8 pn[6];
370 	u8 prefix8;
371 	u8 igtk[WPA_IGTK_MAX_LEN];
372 } STRUCT_PACKED;
373 
374 #define RSN_MLO_BIGTK_KDE_PREFIX_LENGTH		(2 + 6 + 1)
375 #define RSN_MLO_BIGTK_KDE_PREFIX8_LINK_ID_SHIFT	4
376 #define RSN_MLO_BIGTK_KDE_PREFIX8_LINK_ID_MASK	0xF0
377 struct rsn_mlo_bigtk_kde {
378 	u8 keyid[2];
379 	u8 pn[6];
380 	u8 prefix8;
381 	u8 bigtk[WPA_BIGTK_MAX_LEN];
382 } STRUCT_PACKED;
383 
384 #define RSN_MLO_LINK_KDE_FIXED_LENGTH		(1 + 6)
385 #define RSN_MLO_LINK_KDE_LINK_INFO_INDEX	0
386 #define RSN_MLO_LINK_KDE_LI_LINK_ID_SHIFT	0
387 #define RSN_MLO_LINK_KDE_LI_LINK_ID_MASK	0x0F
388 #define RSN_MLO_LINK_KDE_LI_RSNE_INFO		0x10
389 #define RSN_MLO_LINK_KDE_LI_RSNXE_INFO		0x20
390 #define RSN_MLO_LINK_KDE_LINK_MAC_INDEX		1
391 
392 struct rsn_mdie {
393 	u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
394 	u8 ft_capab;
395 } STRUCT_PACKED;
396 
397 #define RSN_FT_CAPAB_FT_OVER_DS BIT(0)
398 #define RSN_FT_CAPAB_FT_RESOURCE_REQ_SUPP BIT(1)
399 
400 struct rsn_ftie {
401 	u8 mic_control[2];
402 	u8 mic[16];
403 	u8 anonce[WPA_NONCE_LEN];
404 	u8 snonce[WPA_NONCE_LEN];
405 	/* followed by optional parameters */
406 } STRUCT_PACKED;
407 
408 struct rsn_ftie_sha384 {
409 	u8 mic_control[2];
410 	u8 mic[24];
411 	u8 anonce[WPA_NONCE_LEN];
412 	u8 snonce[WPA_NONCE_LEN];
413 	/* followed by optional parameters */
414 } STRUCT_PACKED;
415 
416 struct rsn_ftie_sha512 {
417 	u8 mic_control[2];
418 	u8 mic[32];
419 	u8 anonce[WPA_NONCE_LEN];
420 	u8 snonce[WPA_NONCE_LEN];
421 	/* followed by optional parameters */
422 } STRUCT_PACKED;
423 
424 #define FTIE_SUBELEM_R1KH_ID 1
425 #define FTIE_SUBELEM_GTK 2
426 #define FTIE_SUBELEM_R0KH_ID 3
427 #define FTIE_SUBELEM_IGTK 4
428 #define FTIE_SUBELEM_OCI 5
429 #define FTIE_SUBELEM_BIGTK 6
430 
431 struct rsn_rdie {
432 	u8 id;
433 	u8 descr_count;
434 	le16 status_code;
435 } STRUCT_PACKED;
436 
437 /* WFA Transition Disable KDE (using OUI_WFA) */
438 /* Transition Disable Bitmap bits */
439 #define TRANSITION_DISABLE_WPA3_PERSONAL BIT(0)
440 #define TRANSITION_DISABLE_SAE_PK BIT(1)
441 #define TRANSITION_DISABLE_WPA3_ENTERPRISE BIT(2)
442 #define TRANSITION_DISABLE_ENHANCED_OPEN BIT(3)
443 
444 /* DPP KDE Flags */
445 #define DPP_KDE_PFS_ALLOWED BIT(0)
446 #define DPP_KDE_PFS_REQUIRED BIT(1)
447 
448 #ifdef _MSC_VER
449 #pragma pack(pop)
450 #endif /* _MSC_VER */
451 
452 
453 int wpa_eapol_key_mic(const u8 *key, size_t key_len, int akmp, int ver,
454 		      const u8 *buf, size_t len, u8 *mic);
455 int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
456 		   const u8 *addr1, const u8 *addr2,
457 		   const u8 *nonce1, const u8 *nonce2,
458 		   struct wpa_ptk *ptk, int akmp, int cipher,
459 		   const u8 *z, size_t z_len, size_t kdk_len);
460 int fils_rmsk_to_pmk(int akmp, const u8 *rmsk, size_t rmsk_len,
461 		     const u8 *snonce, const u8 *anonce, const u8 *dh_ss,
462 		     size_t dh_ss_len, u8 *pmk, size_t *pmk_len);
463 int fils_pmkid_erp(int akmp, const u8 *reauth, size_t reauth_len,
464 		   u8 *pmkid);
465 int fils_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const u8 *spa, const u8 *aa,
466 		    const u8 *snonce, const u8 *anonce, const u8 *dhss,
467 		    size_t dhss_len, struct wpa_ptk *ptk,
468 		    u8 *ick, size_t *ick_len, int akmp, int cipher,
469 		    u8 *fils_ft, size_t *fils_ft_len, size_t kdk_len);
470 int fils_key_auth_sk(const u8 *ick, size_t ick_len, const u8 *snonce,
471 		     const u8 *anonce, const u8 *sta_addr, const u8 *bssid,
472 		     const u8 *g_sta, size_t g_sta_len,
473 		     const u8 *g_ap, size_t g_ap_len,
474 		     int akmp, u8 *key_auth_sta, u8 *key_auth_ap,
475 		     size_t *key_auth_len);
476 
477 #ifdef CONFIG_IEEE80211R
478 int wpa_ft_mic(int key_mgmt, const u8 *kck, size_t kck_len, const u8 *sta_addr,
479 	       const u8 *ap_addr, u8 transaction_seqnum,
480 	       const u8 *mdie, size_t mdie_len,
481 	       const u8 *ftie, size_t ftie_len,
482 	       const u8 *rsnie, size_t rsnie_len,
483 	       const u8 *ric, size_t ric_len,
484 	       const u8 *rsnxe, size_t rsnxe_len,
485 	       u8 *mic);
486 int wpa_derive_pmk_r0(const u8 *xxkey, size_t xxkey_len,
487 		      const u8 *ssid, size_t ssid_len,
488 		      const u8 *mdid, const u8 *r0kh_id, size_t r0kh_id_len,
489 		      const u8 *s0kh_id, u8 *pmk_r0, u8 *pmk_r0_name,
490 		      int key_mgmt);
491 int wpa_derive_pmk_r1_name(const u8 *pmk_r0_name, const u8 *r1kh_id,
492 			   const u8 *s1kh_id, u8 *pmk_r1_name,
493 			   size_t pmk_r1_len);
494 int wpa_derive_pmk_r1(const u8 *pmk_r0, size_t pmk_r0_len,
495 		      const u8 *pmk_r0_name,
496 		      const u8 *r1kh_id, const u8 *s1kh_id,
497 		      u8 *pmk_r1, u8 *pmk_r1_name);
498 int wpa_pmk_r1_to_ptk(const u8 *pmk_r1, size_t pmk_r1_len, const u8 *snonce,
499 		      const u8 *anonce, const u8 *sta_addr, const u8 *bssid,
500 		      const u8 *pmk_r1_name,
501 		      struct wpa_ptk *ptk, u8 *ptk_name, int akmp, int cipher,
502 		      size_t kdk_len);
503 #endif /* CONFIG_IEEE80211R */
504 
505 struct wpa_ie_data {
506 	int proto;
507 	int pairwise_cipher;
508 	int has_pairwise;
509 	int group_cipher;
510 	int has_group;
511 	int key_mgmt;
512 	int capabilities;
513 	size_t num_pmkid;
514 	const u8 *pmkid;
515 	int mgmt_group_cipher;
516 };
517 
518 
519 int wpa_parse_wpa_ie_rsn(const u8 *rsn_ie, size_t rsn_ie_len,
520 			 struct wpa_ie_data *data);
521 int wpa_parse_wpa_ie_wpa(const u8 *wpa_ie, size_t wpa_ie_len,
522 			 struct wpa_ie_data *data);
523 int wpa_default_rsn_cipher(int freq);
524 
525 void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa,
526 	       u8 *pmkid, int akmp);
527 #ifdef CONFIG_SUITEB
528 int rsn_pmkid_suite_b(const u8 *kck, size_t kck_len, const u8 *aa,
529 		       const u8 *spa, u8 *pmkid);
530 #else /* CONFIG_SUITEB */
rsn_pmkid_suite_b(const u8 * kck,size_t kck_len,const u8 * aa,const u8 * spa,u8 * pmkid)531 static inline int rsn_pmkid_suite_b(const u8 *kck, size_t kck_len, const u8 *aa,
532 				    const u8 *spa, u8 *pmkid)
533 {
534 	return -1;
535 }
536 #endif /* CONFIG_SUITEB */
537 #ifdef CONFIG_SUITEB192
538 int rsn_pmkid_suite_b_192(const u8 *kck, size_t kck_len, const u8 *aa,
539 			  const u8 *spa, u8 *pmkid);
540 #else /* CONFIG_SUITEB192 */
rsn_pmkid_suite_b_192(const u8 * kck,size_t kck_len,const u8 * aa,const u8 * spa,u8 * pmkid)541 static inline int rsn_pmkid_suite_b_192(const u8 *kck, size_t kck_len,
542 					const u8 *aa, const u8 *spa, u8 *pmkid)
543 {
544 	return -1;
545 }
546 #endif /* CONFIG_SUITEB192 */
547 
548 const char * wpa_cipher_txt(int cipher);
549 const char * wpa_key_mgmt_txt(int key_mgmt, int proto);
550 u32 wpa_akm_to_suite(int akm);
551 int wpa_compare_rsn_ie(int ft_initial_assoc,
552 		       const u8 *ie1, size_t ie1len,
553 		       const u8 *ie2, size_t ie2len);
554 int wpa_insert_pmkid(u8 *ies, size_t *ies_len, const u8 *pmkid);
555 
556 struct wpa_ft_ies {
557 	const u8 *mdie;
558 	size_t mdie_len;
559 	const u8 *ftie;
560 	size_t ftie_len;
561 	const u8 *r1kh_id;
562 	const u8 *gtk;
563 	size_t gtk_len;
564 	const u8 *r0kh_id;
565 	size_t r0kh_id_len;
566 	const u8 *fte_anonce;
567 	const u8 *fte_snonce;
568 	bool fte_rsnxe_used;
569 	unsigned int fte_elem_count;
570 	const u8 *fte_mic;
571 	size_t fte_mic_len;
572 	const u8 *rsn;
573 	size_t rsn_len;
574 	u16 rsn_capab;
575 	const u8 *rsn_pmkid;
576 	const u8 *tie;
577 	size_t tie_len;
578 	const u8 *igtk;
579 	size_t igtk_len;
580 	const u8 *bigtk;
581 	size_t bigtk_len;
582 #ifdef CONFIG_OCV
583 	const u8 *oci;
584 	size_t oci_len;
585 #endif /* CONFIG_OCV */
586 	const u8 *ric;
587 	size_t ric_len;
588 	int key_mgmt;
589 	int pairwise_cipher;
590 	const u8 *rsnxe;
591 	size_t rsnxe_len;
592 };
593 
594 /* IEEE P802.11az/D2.6 - 9.4.2.303 PASN Parameters element */
595 #define WPA_PASN_CTRL_COMEBACK_INFO_PRESENT BIT(0)
596 #define WPA_PASN_CTRL_GROUP_AND_KEY_PRESENT BIT(1)
597 
598 #define WPA_PASN_WRAPPED_DATA_NO      0
599 #define WPA_PASN_WRAPPED_DATA_FT      1
600 #define WPA_PASN_WRAPPED_DATA_FILS_SK 2
601 #define WPA_PASN_WRAPPED_DATA_SAE     3
602 
603 struct pasn_parameter_ie {
604 	u8 id;
605 	u8 len;
606 	u8 id_ext;
607 	u8 control; /* WPA_PASN_CTRL_* */
608 	u8 wrapped_data_format; /* WPA_PASN_WRAPPED_DATA_* */
609 } STRUCT_PACKED;
610 
611 struct wpa_pasn_params_data {
612 	u8 wrapped_data_format;
613 	u16 after;
614 	u8 comeback_len;
615 	const u8 *comeback;
616 	u16 group;
617 	u8 pubkey_len;
618 	const u8 *pubkey;
619 };
620 
621 /* See RFC 5480 section 2.2 */
622 #define WPA_PASN_PUBKEY_COMPRESSED_0 0x02
623 #define WPA_PASN_PUBKEY_COMPRESSED_1 0x03
624 #define WPA_PASN_PUBKEY_UNCOMPRESSED 0x04
625 
626 int wpa_ft_parse_ies(const u8 *ies, size_t ies_len, struct wpa_ft_ies *parse,
627 		     int key_mgmt);
628 
629 struct wpa_eapol_ie_parse {
630 	const u8 *wpa_ie;
631 	size_t wpa_ie_len;
632 	const u8 *rsn_ie;
633 	size_t rsn_ie_len;
634 	const u8 *pmkid;
635 	const u8 *key_id;
636 	const u8 *gtk;
637 	size_t gtk_len;
638 	const u8 *mac_addr;
639 	const u8 *igtk;
640 	size_t igtk_len;
641 	const u8 *bigtk;
642 	size_t bigtk_len;
643 	const u8 *mdie;
644 	size_t mdie_len;
645 	const u8 *ftie;
646 	size_t ftie_len;
647 	const u8 *ip_addr_req;
648 	const u8 *ip_addr_alloc;
649 	const u8 *transition_disable;
650 	size_t transition_disable_len;
651 	const u8 *dpp_kde;
652 	size_t dpp_kde_len;
653 	const u8 *oci;
654 	size_t oci_len;
655 	const u8 *osen;
656 	size_t osen_len;
657 	const u8 *rsnxe;
658 	size_t rsnxe_len;
659 	const u8 *reassoc_deadline;
660 	const u8 *key_lifetime;
661 	const u8 *lnkid;
662 	size_t lnkid_len;
663 	const u8 *ext_capab;
664 	size_t ext_capab_len;
665 	const u8 *supp_rates;
666 	size_t supp_rates_len;
667 	const u8 *ext_supp_rates;
668 	size_t ext_supp_rates_len;
669 	const u8 *ht_capabilities;
670 	const u8 *vht_capabilities;
671 	const u8 *he_capabilities;
672 	size_t he_capab_len;
673 	const u8 *he_6ghz_capabilities;
674 	const u8 *supp_channels;
675 	size_t supp_channels_len;
676 	const u8 *supp_oper_classes;
677 	size_t supp_oper_classes_len;
678 	u8 qosinfo;
679 	u16 aid;
680 	const u8 *wmm;
681 	size_t wmm_len;
682 #define MAX_NUM_MLO_LINKS 15
683 	u16 valid_mlo_gtks; /* bitmap of valid link GTK KDEs */
684 	const u8 *mlo_gtk[MAX_NUM_MLO_LINKS];
685 	size_t mlo_gtk_len[MAX_NUM_MLO_LINKS];
686 	u16 valid_mlo_igtks; /* bitmap of valid link IGTK KDEs */
687 	const u8 *mlo_igtk[MAX_NUM_MLO_LINKS];
688 	size_t mlo_igtk_len[MAX_NUM_MLO_LINKS];
689 	u16 valid_mlo_bigtks; /* bitmap of valid link BIGTK KDEs */
690 	const u8 *mlo_bigtk[MAX_NUM_MLO_LINKS];
691 	size_t mlo_bigtk_len[MAX_NUM_MLO_LINKS];
692 	u16 valid_mlo_links; /* bitmap of valid MLO link KDEs */
693 	const u8 *mlo_link[MAX_NUM_MLO_LINKS];
694 	size_t mlo_link_len[MAX_NUM_MLO_LINKS];
695 };
696 
697 int wpa_parse_kde_ies(const u8 *buf, size_t len, struct wpa_eapol_ie_parse *ie);
wpa_supplicant_parse_ies(const u8 * buf,size_t len,struct wpa_eapol_ie_parse * ie)698 static inline int wpa_supplicant_parse_ies(const u8 *buf, size_t len,
699 					   struct wpa_eapol_ie_parse *ie)
700 {
701 	return wpa_parse_kde_ies(buf, len, ie);
702 }
703 
704 
705 int wpa_cipher_key_len(int cipher);
706 int wpa_cipher_rsc_len(int cipher);
707 enum wpa_alg wpa_cipher_to_alg(int cipher);
708 int wpa_cipher_valid_group(int cipher);
709 int wpa_cipher_valid_pairwise(int cipher);
710 int wpa_cipher_valid_mgmt_group(int cipher);
711 u32 wpa_cipher_to_suite(int proto, int cipher);
712 int rsn_cipher_put_suites(u8 *pos, int ciphers);
713 int wpa_cipher_put_suites(u8 *pos, int ciphers);
714 int wpa_pick_pairwise_cipher(int ciphers, int none_allowed);
715 int wpa_pick_group_cipher(int ciphers);
716 int wpa_parse_cipher(const char *value);
717 int wpa_write_ciphers(char *start, char *end, int ciphers, const char *delim);
718 int wpa_select_ap_group_cipher(int wpa, int wpa_pairwise, int rsn_pairwise);
719 unsigned int wpa_mic_len(int akmp, size_t pmk_len);
720 int wpa_use_akm_defined(int akmp);
721 int wpa_use_cmac(int akmp);
722 int wpa_use_aes_key_wrap(int akmp);
723 int fils_domain_name_hash(const char *domain, u8 *hash);
724 
725 bool pasn_use_sha384(int akmp, int cipher);
726 int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
727 		    const u8 *spa, const u8 *bssid,
728 		    const u8 *dhss, size_t dhss_len,
729 		    struct wpa_ptk *ptk, int akmp, int cipher,
730 		    size_t kdk_len);
731 
732 u8 pasn_mic_len(int akmp, int cipher);
733 
734 int pasn_mic(const u8 *kck, int akmp, int cipher,
735 	     const u8 *addr1, const u8 *addr2,
736 	     const u8 *data, size_t data_len,
737 	     const u8 *frame, size_t frame_len, u8 *mic);
738 
739 int wpa_ltf_keyseed(struct wpa_ptk *ptk, int akmp, int cipher);
740 
741 int pasn_auth_frame_hash(int akmp, int cipher, const u8 *data, size_t len,
742 			 u8 *hash);
743 
744 void wpa_pasn_build_auth_header(struct wpabuf *buf, const u8 *bssid,
745 				const u8 *src, const u8 *dst,
746 				u8 trans_seq, u16 status);
747 
748 int wpa_pasn_add_rsne(struct wpabuf *buf, const u8 *pmkid,
749 		      int akmp, int cipher);
750 
751 void wpa_pasn_add_parameter_ie(struct wpabuf *buf, u16 pasn_group,
752 			       u8 wrapped_data_format,
753 			       const struct wpabuf *pubkey, bool compressed,
754 			       const struct wpabuf *comeback, int after);
755 
756 int wpa_pasn_add_wrapped_data(struct wpabuf *buf,
757 			      struct wpabuf *wrapped_data_buf);
758 
759 int wpa_pasn_validate_rsne(const struct wpa_ie_data *data);
760 int wpa_pasn_parse_parameter_ie(const u8 *data, u8 len, bool from_ap,
761 				struct wpa_pasn_params_data *pasn_params);
762 
763 void wpa_pasn_add_rsnxe(struct wpabuf *buf, u16 capab);
764 int wpa_pasn_add_extra_ies(struct wpabuf *buf, const u8 *extra_ies, size_t len);
765 
766 #endif /* WPA_COMMON_H */
767