• 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 
85 #define RSN_AUTH_KEY_MGMT_PASN RSN_SELECTOR(0x00, 0x0f, 0xac, 21)
86 
87 #define RSN_AUTH_KEY_MGMT_CCKM RSN_SELECTOR(0x00, 0x40, 0x96, 0x00)
88 #define RSN_AUTH_KEY_MGMT_OSEN RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x01)
89 #define RSN_AUTH_KEY_MGMT_DPP RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x02)
90 
91 #define RSN_CIPHER_SUITE_NONE RSN_SELECTOR(0x00, 0x0f, 0xac, 0)
92 #define RSN_CIPHER_SUITE_WEP40 RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
93 #define RSN_CIPHER_SUITE_TKIP RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
94 #if 0
95 #define RSN_CIPHER_SUITE_WRAP RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
96 #endif
97 #define RSN_CIPHER_SUITE_CCMP RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
98 #define RSN_CIPHER_SUITE_WEP104 RSN_SELECTOR(0x00, 0x0f, 0xac, 5)
99 #define RSN_CIPHER_SUITE_AES_128_CMAC RSN_SELECTOR(0x00, 0x0f, 0xac, 6)
100 #define RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED RSN_SELECTOR(0x00, 0x0f, 0xac, 7)
101 #define RSN_CIPHER_SUITE_GCMP RSN_SELECTOR(0x00, 0x0f, 0xac, 8)
102 #define RSN_CIPHER_SUITE_GCMP_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
103 #define RSN_CIPHER_SUITE_CCMP_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 10)
104 #define RSN_CIPHER_SUITE_BIP_GMAC_128 RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
105 #define RSN_CIPHER_SUITE_BIP_GMAC_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
106 #define RSN_CIPHER_SUITE_BIP_CMAC_256 RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
107 #define RSN_CIPHER_SUITE_SMS4 RSN_SELECTOR(0x00, 0x14, 0x72, 1)
108 #define RSN_CIPHER_SUITE_CKIP RSN_SELECTOR(0x00, 0x40, 0x96, 0)
109 #define RSN_CIPHER_SUITE_CKIP_CMIC RSN_SELECTOR(0x00, 0x40, 0x96, 1)
110 #define RSN_CIPHER_SUITE_CMIC RSN_SELECTOR(0x00, 0x40, 0x96, 2)
111 /* KRK is defined for nl80211 use only */
112 #define RSN_CIPHER_SUITE_KRK RSN_SELECTOR(0x00, 0x40, 0x96, 255)
113 
114 /* EAPOL-Key Key Data Encapsulation
115  * GroupKey and PeerKey require encryption, otherwise, encryption is optional.
116  */
117 #define RSN_KEY_DATA_GROUPKEY RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
118 #if 0
119 #define RSN_KEY_DATA_STAKEY RSN_SELECTOR(0x00, 0x0f, 0xac, 2)
120 #endif
121 #define RSN_KEY_DATA_MAC_ADDR RSN_SELECTOR(0x00, 0x0f, 0xac, 3)
122 #define RSN_KEY_DATA_PMKID RSN_SELECTOR(0x00, 0x0f, 0xac, 4)
123 #define RSN_KEY_DATA_IGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
124 #define RSN_KEY_DATA_KEYID RSN_SELECTOR(0x00, 0x0f, 0xac, 10)
125 #define RSN_KEY_DATA_MULTIBAND_GTK RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
126 #define RSN_KEY_DATA_MULTIBAND_KEYID RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
127 #define RSN_KEY_DATA_OCI RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
128 #define RSN_KEY_DATA_BIGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 14)
129 
130 #define WFA_KEY_DATA_IP_ADDR_REQ RSN_SELECTOR(0x50, 0x6f, 0x9a, 4)
131 #define WFA_KEY_DATA_IP_ADDR_ALLOC RSN_SELECTOR(0x50, 0x6f, 0x9a, 5)
132 #define WFA_KEY_DATA_TRANSITION_DISABLE RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x20)
133 #define WFA_KEY_DATA_DPP RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x21)
134 
135 #define WPA_OUI_TYPE RSN_SELECTOR(0x00, 0x50, 0xf2, 1)
136 
137 #define RSN_SELECTOR_PUT(a, val) WPA_PUT_BE32((u8 *) (a), (val))
138 #define RSN_SELECTOR_GET(a) WPA_GET_BE32((const u8 *) (a))
139 
140 #define RSN_NUM_REPLAY_COUNTERS_1 0
141 #define RSN_NUM_REPLAY_COUNTERS_2 1
142 #define RSN_NUM_REPLAY_COUNTERS_4 2
143 #define RSN_NUM_REPLAY_COUNTERS_16 3
144 
145 
146 #ifdef _MSC_VER
147 #pragma pack(push, 1)
148 #endif /* _MSC_VER */
149 
150 #define WPA_IGTK_LEN 16
151 #define WPA_IGTK_MAX_LEN 32
152 #define WPA_BIGTK_LEN 16
153 #define WPA_BIGTK_MAX_LEN 32
154 
155 
156 /* IEEE 802.11, 7.3.2.25.3 RSN Capabilities */
157 #define WPA_CAPABILITY_PREAUTH BIT(0)
158 #define WPA_CAPABILITY_NO_PAIRWISE BIT(1)
159 /* B2-B3: PTKSA Replay Counter */
160 /* B4-B5: GTKSA Replay Counter */
161 #define WPA_CAPABILITY_MFPR BIT(6)
162 #define WPA_CAPABILITY_MFPC BIT(7)
163 /* B8: Reserved */
164 #define WPA_CAPABILITY_PEERKEY_ENABLED BIT(9)
165 #define WPA_CAPABILITY_SPP_A_MSDU_CAPABLE BIT(10)
166 #define WPA_CAPABILITY_SPP_A_MSDU_REQUIRED BIT(11)
167 #define WPA_CAPABILITY_PBAC BIT(12)
168 #define WPA_CAPABILITY_EXT_KEY_ID_FOR_UNICAST BIT(13)
169 #define WPA_CAPABILITY_OCVC BIT(14)
170 /* B15: Reserved */
171 
172 
173 /* IEEE 802.11r */
174 #define MOBILITY_DOMAIN_ID_LEN 2
175 #define FT_R0KH_ID_MAX_LEN 48
176 #define FT_R1KH_ID_LEN 6
177 #define WPA_PMK_NAME_LEN 16
178 
179 
180 /* IEEE 802.11, 8.5.2 EAPOL-Key frames */
181 #define WPA_KEY_INFO_TYPE_MASK ((u16) (BIT(0) | BIT(1) | BIT(2)))
182 #define WPA_KEY_INFO_TYPE_AKM_DEFINED 0
183 #define WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 BIT(0)
184 #define WPA_KEY_INFO_TYPE_HMAC_SHA1_AES BIT(1)
185 #define WPA_KEY_INFO_TYPE_AES_128_CMAC 3
186 #define WPA_KEY_INFO_KEY_TYPE BIT(3) /* 1 = Pairwise, 0 = Group key */
187 /* bit4..5 is used in WPA, but is reserved in IEEE 802.11i/RSN */
188 #define WPA_KEY_INFO_KEY_INDEX_MASK (BIT(4) | BIT(5))
189 #define WPA_KEY_INFO_KEY_INDEX_SHIFT 4
190 #define WPA_KEY_INFO_INSTALL BIT(6) /* pairwise */
191 #define WPA_KEY_INFO_TXRX BIT(6) /* group */
192 #define WPA_KEY_INFO_ACK BIT(7)
193 #define WPA_KEY_INFO_MIC BIT(8)
194 #define WPA_KEY_INFO_SECURE BIT(9)
195 #define WPA_KEY_INFO_ERROR BIT(10)
196 #define WPA_KEY_INFO_REQUEST BIT(11)
197 #define WPA_KEY_INFO_ENCR_KEY_DATA BIT(12) /* IEEE 802.11i/RSN only */
198 #define WPA_KEY_INFO_SMK_MESSAGE BIT(13)
199 
200 
201 struct wpa_eapol_key {
202 	u8 type;
203 	/* Note: key_info, key_length, and key_data_length are unaligned */
204 	u8 key_info[2]; /* big endian */
205 	u8 key_length[2]; /* big endian */
206 	u8 replay_counter[WPA_REPLAY_COUNTER_LEN];
207 	u8 key_nonce[WPA_NONCE_LEN];
208 	u8 key_iv[16];
209 	u8 key_rsc[WPA_KEY_RSC_LEN];
210 	u8 key_id[8]; /* Reserved in IEEE 802.11i/RSN */
211 	/* variable length Key MIC field */
212 	/* big endian 2-octet Key Data Length field */
213 	/* followed by Key Data Length bytes of Key Data */
214 } STRUCT_PACKED;
215 
216 #define WPA_EAPOL_KEY_MIC_MAX_LEN 32
217 #define WPA_KCK_MAX_LEN 32
218 #define WPA_KEK_MAX_LEN 64
219 #define WPA_TK_MAX_LEN 32
220 #define WPA_KDK_MAX_LEN 32
221 #define FILS_ICK_MAX_LEN 48
222 #define FILS_FT_MAX_LEN 48
223 #define WPA_PASN_KCK_LEN 32
224 #define WPA_PASN_MIC_MAX_LEN 24
225 
226 /**
227  * struct wpa_ptk - WPA Pairwise Transient Key
228  * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
229  */
230 struct wpa_ptk {
231 	u8 kck[WPA_KCK_MAX_LEN]; /* EAPOL-Key Key Confirmation Key (KCK) */
232 	u8 kek[WPA_KEK_MAX_LEN]; /* EAPOL-Key Key Encryption Key (KEK) */
233 	u8 tk[WPA_TK_MAX_LEN]; /* Temporal Key (TK) */
234 	u8 kck2[WPA_KCK_MAX_LEN]; /* FT reasoc Key Confirmation Key (KCK2) */
235 	u8 kek2[WPA_KEK_MAX_LEN]; /* FT reassoc Key Encryption Key (KEK2) */
236 	u8 kdk[WPA_KDK_MAX_LEN]; /* Key Derivation Key */
237 	size_t kck_len;
238 	size_t kek_len;
239 	size_t tk_len;
240 	size_t kck2_len;
241 	size_t kek2_len;
242 	size_t kdk_len;
243 	int installed; /* 1 if key has already been installed to driver */
244 };
245 
246 struct wpa_gtk {
247 	u8 gtk[WPA_GTK_MAX_LEN];
248 	size_t gtk_len;
249 };
250 
251 struct wpa_igtk {
252 	u8 igtk[WPA_IGTK_MAX_LEN];
253 	size_t igtk_len;
254 };
255 
256 struct wpa_bigtk {
257 	u8 bigtk[WPA_BIGTK_MAX_LEN];
258 	size_t bigtk_len;
259 };
260 
261 /* WPA IE version 1
262  * 00-50-f2:1 (OUI:OUI type)
263  * 0x01 0x00 (version; little endian)
264  * (all following fields are optional:)
265  * Group Suite Selector (4 octets) (default: TKIP)
266  * Pairwise Suite Count (2 octets, little endian) (default: 1)
267  * Pairwise Suite List (4 * n octets) (default: TKIP)
268  * Authenticated Key Management Suite Count (2 octets, little endian)
269  *    (default: 1)
270  * Authenticated Key Management Suite List (4 * n octets)
271  *    (default: unspec 802.1X)
272  * WPA Capabilities (2 octets, little endian) (default: 0)
273  */
274 
275 struct wpa_ie_hdr {
276 	u8 elem_id;
277 	u8 len;
278 	u8 oui[4]; /* 24-bit OUI followed by 8-bit OUI type */
279 	u8 version[2]; /* little endian */
280 } STRUCT_PACKED;
281 
282 
283 /* 1/4: PMKID
284  * 2/4: RSN IE
285  * 3/4: one or two RSN IEs + GTK IE (encrypted)
286  * 4/4: empty
287  * 1/2: GTK IE (encrypted)
288  * 2/2: empty
289  */
290 
291 /* RSN IE version 1
292  * 0x01 0x00 (version; little endian)
293  * (all following fields are optional:)
294  * Group Suite Selector (4 octets) (default: CCMP)
295  * Pairwise Suite Count (2 octets, little endian) (default: 1)
296  * Pairwise Suite List (4 * n octets) (default: CCMP)
297  * Authenticated Key Management Suite Count (2 octets, little endian)
298  *    (default: 1)
299  * Authenticated Key Management Suite List (4 * n octets)
300  *    (default: unspec 802.1X)
301  * RSN Capabilities (2 octets, little endian) (default: 0)
302  * PMKID Count (2 octets) (default: 0)
303  * PMKID List (16 * n octets)
304  * Management Group Cipher Suite (4 octets) (default: AES-128-CMAC)
305  */
306 
307 struct rsn_ie_hdr {
308 	u8 elem_id; /* WLAN_EID_RSN */
309 	u8 len;
310 	u8 version[2]; /* little endian */
311 } STRUCT_PACKED;
312 
313 
314 struct rsn_error_kde {
315 	be16 mui;
316 	be16 error_type;
317 } STRUCT_PACKED;
318 
319 #define WPA_IGTK_KDE_PREFIX_LEN (2 + 6)
320 struct wpa_igtk_kde {
321 	u8 keyid[2];
322 	u8 pn[6];
323 	u8 igtk[WPA_IGTK_MAX_LEN];
324 } STRUCT_PACKED;
325 
326 #define WPA_BIGTK_KDE_PREFIX_LEN (2 + 6)
327 struct wpa_bigtk_kde {
328 	u8 keyid[2];
329 	u8 pn[6];
330 	u8 bigtk[WPA_BIGTK_MAX_LEN];
331 } STRUCT_PACKED;
332 
333 struct rsn_mdie {
334 	u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
335 	u8 ft_capab;
336 } STRUCT_PACKED;
337 
338 #define RSN_FT_CAPAB_FT_OVER_DS BIT(0)
339 #define RSN_FT_CAPAB_FT_RESOURCE_REQ_SUPP BIT(1)
340 
341 struct rsn_ftie {
342 	u8 mic_control[2];
343 	u8 mic[16];
344 	u8 anonce[WPA_NONCE_LEN];
345 	u8 snonce[WPA_NONCE_LEN];
346 	/* followed by optional parameters */
347 } STRUCT_PACKED;
348 
349 struct rsn_ftie_sha384 {
350 	u8 mic_control[2];
351 	u8 mic[24];
352 	u8 anonce[WPA_NONCE_LEN];
353 	u8 snonce[WPA_NONCE_LEN];
354 	/* followed by optional parameters */
355 } STRUCT_PACKED;
356 
357 #define FTIE_SUBELEM_R1KH_ID 1
358 #define FTIE_SUBELEM_GTK 2
359 #define FTIE_SUBELEM_R0KH_ID 3
360 #define FTIE_SUBELEM_IGTK 4
361 #define FTIE_SUBELEM_OCI 5
362 #define FTIE_SUBELEM_BIGTK 6
363 
364 struct rsn_rdie {
365 	u8 id;
366 	u8 descr_count;
367 	le16 status_code;
368 } STRUCT_PACKED;
369 
370 /* WFA Transition Disable KDE (using OUI_WFA) */
371 /* Transition Disable Bitmap bits */
372 #define TRANSITION_DISABLE_WPA3_PERSONAL BIT(0)
373 #define TRANSITION_DISABLE_SAE_PK BIT(1)
374 #define TRANSITION_DISABLE_WPA3_ENTERPRISE BIT(2)
375 #define TRANSITION_DISABLE_ENHANCED_OPEN BIT(3)
376 
377 /* DPP KDE Flags */
378 #define DPP_KDE_PFS_ALLOWED BIT(0)
379 #define DPP_KDE_PFS_REQUIRED BIT(1)
380 
381 #ifdef _MSC_VER
382 #pragma pack(pop)
383 #endif /* _MSC_VER */
384 
385 
386 int wpa_eapol_key_mic(const u8 *key, size_t key_len, int akmp, int ver,
387 		      const u8 *buf, size_t len, u8 *mic);
388 int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label,
389 		   const u8 *addr1, const u8 *addr2,
390 		   const u8 *nonce1, const u8 *nonce2,
391 		   struct wpa_ptk *ptk, int akmp, int cipher,
392 		   const u8 *z, size_t z_len, size_t kdk_len);
393 int fils_rmsk_to_pmk(int akmp, const u8 *rmsk, size_t rmsk_len,
394 		     const u8 *snonce, const u8 *anonce, const u8 *dh_ss,
395 		     size_t dh_ss_len, u8 *pmk, size_t *pmk_len);
396 int fils_pmkid_erp(int akmp, const u8 *reauth, size_t reauth_len,
397 		   u8 *pmkid);
398 int fils_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const u8 *spa, const u8 *aa,
399 		    const u8 *snonce, const u8 *anonce, const u8 *dhss,
400 		    size_t dhss_len, struct wpa_ptk *ptk,
401 		    u8 *ick, size_t *ick_len, int akmp, int cipher,
402 		    u8 *fils_ft, size_t *fils_ft_len, size_t kdk_len);
403 int fils_key_auth_sk(const u8 *ick, size_t ick_len, const u8 *snonce,
404 		     const u8 *anonce, const u8 *sta_addr, const u8 *bssid,
405 		     const u8 *g_sta, size_t g_sta_len,
406 		     const u8 *g_ap, size_t g_ap_len,
407 		     int akmp, u8 *key_auth_sta, u8 *key_auth_ap,
408 		     size_t *key_auth_len);
409 
410 #ifdef CONFIG_IEEE80211R
411 int wpa_ft_mic(const u8 *kck, size_t kck_len, const u8 *sta_addr,
412 	       const u8 *ap_addr, u8 transaction_seqnum,
413 	       const u8 *mdie, size_t mdie_len,
414 	       const u8 *ftie, size_t ftie_len,
415 	       const u8 *rsnie, size_t rsnie_len,
416 	       const u8 *ric, size_t ric_len,
417 	       const u8 *rsnxe, size_t rsnxe_len,
418 	       u8 *mic);
419 int wpa_derive_pmk_r0(const u8 *xxkey, size_t xxkey_len,
420 		      const u8 *ssid, size_t ssid_len,
421 		      const u8 *mdid, const u8 *r0kh_id, size_t r0kh_id_len,
422 		      const u8 *s0kh_id, u8 *pmk_r0, u8 *pmk_r0_name,
423 		      int use_sha384);
424 int wpa_derive_pmk_r1_name(const u8 *pmk_r0_name, const u8 *r1kh_id,
425 			   const u8 *s1kh_id, u8 *pmk_r1_name, int use_sha384);
426 int wpa_derive_pmk_r1(const u8 *pmk_r0, size_t pmk_r0_len,
427 		      const u8 *pmk_r0_name,
428 		      const u8 *r1kh_id, const u8 *s1kh_id,
429 		      u8 *pmk_r1, u8 *pmk_r1_name);
430 int wpa_pmk_r1_to_ptk(const u8 *pmk_r1, size_t pmk_r1_len, const u8 *snonce,
431 		      const u8 *anonce, const u8 *sta_addr, const u8 *bssid,
432 		      const u8 *pmk_r1_name,
433 		      struct wpa_ptk *ptk, u8 *ptk_name, int akmp, int cipher,
434 		      size_t kdk_len);
435 #endif /* CONFIG_IEEE80211R */
436 
437 struct wpa_ie_data {
438 	int proto;
439 	int pairwise_cipher;
440 	int has_pairwise;
441 	int group_cipher;
442 	int has_group;
443 	int key_mgmt;
444 	int capabilities;
445 	size_t num_pmkid;
446 	const u8 *pmkid;
447 	int mgmt_group_cipher;
448 };
449 
450 
451 int wpa_parse_wpa_ie_rsn(const u8 *rsn_ie, size_t rsn_ie_len,
452 			 struct wpa_ie_data *data);
453 int wpa_parse_wpa_ie_wpa(const u8 *wpa_ie, size_t wpa_ie_len,
454 			 struct wpa_ie_data *data);
455 int wpa_default_rsn_cipher(int freq);
456 
457 void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa,
458 	       u8 *pmkid, int akmp);
459 #ifdef CONFIG_SUITEB
460 int rsn_pmkid_suite_b(const u8 *kck, size_t kck_len, const u8 *aa,
461 		       const u8 *spa, u8 *pmkid);
462 #else /* CONFIG_SUITEB */
rsn_pmkid_suite_b(const u8 * kck,size_t kck_len,const u8 * aa,const u8 * spa,u8 * pmkid)463 static inline int rsn_pmkid_suite_b(const u8 *kck, size_t kck_len, const u8 *aa,
464 				    const u8 *spa, u8 *pmkid)
465 {
466 	return -1;
467 }
468 #endif /* CONFIG_SUITEB */
469 #ifdef CONFIG_SUITEB192
470 int rsn_pmkid_suite_b_192(const u8 *kck, size_t kck_len, const u8 *aa,
471 			  const u8 *spa, u8 *pmkid);
472 #else /* CONFIG_SUITEB192 */
rsn_pmkid_suite_b_192(const u8 * kck,size_t kck_len,const u8 * aa,const u8 * spa,u8 * pmkid)473 static inline int rsn_pmkid_suite_b_192(const u8 *kck, size_t kck_len,
474 					const u8 *aa, const u8 *spa, u8 *pmkid)
475 {
476 	return -1;
477 }
478 #endif /* CONFIG_SUITEB192 */
479 
480 const char * wpa_cipher_txt(int cipher);
481 const char * wpa_key_mgmt_txt(int key_mgmt, int proto);
482 u32 wpa_akm_to_suite(int akm);
483 int wpa_compare_rsn_ie(int ft_initial_assoc,
484 		       const u8 *ie1, size_t ie1len,
485 		       const u8 *ie2, size_t ie2len);
486 int wpa_insert_pmkid(u8 *ies, size_t *ies_len, const u8 *pmkid);
487 
488 struct wpa_ft_ies {
489 	const u8 *mdie;
490 	size_t mdie_len;
491 	const u8 *ftie;
492 	size_t ftie_len;
493 	const u8 *r1kh_id;
494 	const u8 *gtk;
495 	size_t gtk_len;
496 	const u8 *r0kh_id;
497 	size_t r0kh_id_len;
498 	const u8 *fte_anonce;
499 	const u8 *fte_snonce;
500 	const u8 *rsn;
501 	size_t rsn_len;
502 	u16 rsn_capab;
503 	const u8 *rsn_pmkid;
504 	const u8 *tie;
505 	size_t tie_len;
506 	const u8 *igtk;
507 	size_t igtk_len;
508 	const u8 *bigtk;
509 	size_t bigtk_len;
510 #ifdef CONFIG_OCV
511 	const u8 *oci;
512 	size_t oci_len;
513 #endif /* CONFIG_OCV */
514 	const u8 *ric;
515 	size_t ric_len;
516 	int key_mgmt;
517 	int pairwise_cipher;
518 	const u8 *rsnxe;
519 	size_t rsnxe_len;
520 };
521 
522 /* IEEE P802.11az/D2.6 - 9.4.2.303 PASN Parameters element */
523 #define WPA_PASN_CTRL_COMEBACK_INFO_PRESENT BIT(0)
524 #define WPA_PASN_CTRL_GROUP_AND_KEY_PRESENT BIT(1)
525 
526 #define WPA_PASN_WRAPPED_DATA_NO      0
527 #define WPA_PASN_WRAPPED_DATA_FT      1
528 #define WPA_PASN_WRAPPED_DATA_FILS_SK 2
529 #define WPA_PASN_WRAPPED_DATA_SAE     3
530 
531 struct pasn_parameter_ie {
532 	u8 id;
533 	u8 len;
534 	u8 id_ext;
535 	u8 control; /* WPA_PASN_CTRL_* */
536 	u8 wrapped_data_format; /* WPA_PASN_WRAPPED_DATA_* */
537 } STRUCT_PACKED;
538 
539 struct wpa_pasn_params_data {
540 	u8 wrapped_data_format;
541 	u16 after;
542 	u8 comeback_len;
543 	const u8 *comeback;
544 	u16 group;
545 	u8 pubkey_len;
546 	const u8 *pubkey;
547 };
548 
549 int wpa_ft_parse_ies(const u8 *ies, size_t ies_len, struct wpa_ft_ies *parse,
550 		     int use_sha384);
551 
552 struct wpa_eapol_ie_parse {
553 	const u8 *wpa_ie;
554 	size_t wpa_ie_len;
555 	const u8 *rsn_ie;
556 	size_t rsn_ie_len;
557 	const u8 *pmkid;
558 	const u8 *key_id;
559 	const u8 *gtk;
560 	size_t gtk_len;
561 	const u8 *mac_addr;
562 	size_t mac_addr_len;
563 	const u8 *igtk;
564 	size_t igtk_len;
565 	const u8 *bigtk;
566 	size_t bigtk_len;
567 	const u8 *mdie;
568 	size_t mdie_len;
569 	const u8 *ftie;
570 	size_t ftie_len;
571 	const u8 *ip_addr_req;
572 	const u8 *ip_addr_alloc;
573 	const u8 *transition_disable;
574 	size_t transition_disable_len;
575 	const u8 *dpp_kde;
576 	size_t dpp_kde_len;
577 	const u8 *oci;
578 	size_t oci_len;
579 	const u8 *osen;
580 	size_t osen_len;
581 	const u8 *rsnxe;
582 	size_t rsnxe_len;
583 	const u8 *reassoc_deadline;
584 	const u8 *key_lifetime;
585 	const u8 *lnkid;
586 	size_t lnkid_len;
587 	const u8 *ext_capab;
588 	size_t ext_capab_len;
589 	const u8 *supp_rates;
590 	size_t supp_rates_len;
591 	const u8 *ext_supp_rates;
592 	size_t ext_supp_rates_len;
593 	const u8 *ht_capabilities;
594 	const u8 *vht_capabilities;
595 	const u8 *supp_channels;
596 	size_t supp_channels_len;
597 	const u8 *supp_oper_classes;
598 	size_t supp_oper_classes_len;
599 	u8 qosinfo;
600 	u16 aid;
601 	const u8 *wmm;
602 	size_t wmm_len;
603 };
604 
605 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)606 static inline int wpa_supplicant_parse_ies(const u8 *buf, size_t len,
607 					   struct wpa_eapol_ie_parse *ie)
608 {
609 	return wpa_parse_kde_ies(buf, len, ie);
610 }
611 
612 
613 int wpa_cipher_key_len(int cipher);
614 int wpa_cipher_rsc_len(int cipher);
615 enum wpa_alg wpa_cipher_to_alg(int cipher);
616 int wpa_cipher_valid_group(int cipher);
617 int wpa_cipher_valid_pairwise(int cipher);
618 int wpa_cipher_valid_mgmt_group(int cipher);
619 u32 wpa_cipher_to_suite(int proto, int cipher);
620 int rsn_cipher_put_suites(u8 *pos, int ciphers);
621 int wpa_cipher_put_suites(u8 *pos, int ciphers);
622 int wpa_pick_pairwise_cipher(int ciphers, int none_allowed);
623 int wpa_pick_group_cipher(int ciphers);
624 int wpa_parse_cipher(const char *value);
625 int wpa_write_ciphers(char *start, char *end, int ciphers, const char *delim);
626 int wpa_select_ap_group_cipher(int wpa, int wpa_pairwise, int rsn_pairwise);
627 unsigned int wpa_mic_len(int akmp, size_t pmk_len);
628 int wpa_use_akm_defined(int akmp);
629 int wpa_use_cmac(int akmp);
630 int wpa_use_aes_key_wrap(int akmp);
631 int fils_domain_name_hash(const char *domain, u8 *hash);
632 
633 int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
634 		    const u8 *spa, const u8 *bssid,
635 		    const u8 *dhss, size_t dhss_len,
636 		    struct wpa_ptk *ptk, int akmp, int cipher,
637 		    size_t kdk_len);
638 
639 u8 pasn_mic_len(int akmp, int cipher);
640 
641 int pasn_mic(const u8 *kck, int akmp, int cipher,
642 	     const u8 *addr1, const u8 *addr2,
643 	     const u8 *data, size_t data_len,
644 	     const u8 *frame, size_t frame_len, u8 *mic);
645 
646 int pasn_auth_frame_hash(int akmp, int cipher, const u8 *data, size_t len,
647 			 u8 *hash);
648 
649 void wpa_pasn_build_auth_header(struct wpabuf *buf, const u8 *bssid,
650 				const u8 *src, const u8 *dst,
651 				u8 trans_seq, u16 status);
652 
653 int wpa_pasn_add_rsne(struct wpabuf *buf, const u8 *pmkid,
654 		      int akmp, int cipher);
655 
656 void wpa_pasn_add_parameter_ie(struct wpabuf *buf, u16 pasn_group,
657 			       u8 wrapped_data_format,
658 			       struct wpabuf *pubkey,
659 			       struct wpabuf *comeback, int after);
660 
661 int wpa_pasn_add_wrapped_data(struct wpabuf *buf,
662 			      struct wpabuf *wrapped_data_buf);
663 
664 int wpa_pasn_validate_rsne(const struct wpa_ie_data *data);
665 int wpa_pasn_parse_parameter_ie(const u8 *data, u8 len, bool from_ap,
666 				struct wpa_pasn_params_data *pasn_params);
667 
668 void wpa_pasn_add_rsnxe(struct wpabuf *buf, u16 capab);
669 
670 #endif /* WPA_COMMON_H */
671