blob: c28c55d3aab64283a5bea691506435a9ca9dcf52 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA definitions shared between hostapd and wpa_supplicant
Roshan Pius3a1667e2018-07-03 15:17:14 -07003 * Copyright (c) 2002-2018, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#ifndef WPA_COMMON_H
10#define WPA_COMMON_H
11
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012/* IEEE 802.11i */
13#define PMKID_LEN 16
14#define PMK_LEN 32
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080015#define PMK_LEN_SUITE_B_192 48
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070016#define PMK_LEN_MAX 64
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#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
Hai Shalom60840252021-02-19 19:02:11 -080022#define WPA_PASN_PMK_LEN 32
23#define WPA_PASN_MAX_MIC_LEN 24
24#define WPA_MAX_RSNXE_LEN 4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070026#define OWE_DH_GROUP 19
27
Hai Shalomb755a2a2020-04-23 21:49:02 -070028#ifdef CONFIG_NO_TKIP
29#define WPA_ALLOWED_PAIRWISE_CIPHERS \
30(WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_NONE | \
31WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256)
32#define WPA_ALLOWED_GROUP_CIPHERS \
33(WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | \
34WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256 | \
35WPA_CIPHER_GTK_NOT_USED)
36#else /* CONFIG_NO_TKIP */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080037#define WPA_ALLOWED_PAIRWISE_CIPHERS \
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080038(WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_TKIP | WPA_CIPHER_NONE | \
39WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080040#define WPA_ALLOWED_GROUP_CIPHERS \
Dmitry Shmidt41712582015-06-29 11:02:15 -070041(WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_TKIP | \
42WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256 | \
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080043WPA_CIPHER_GTK_NOT_USED)
Hai Shalomb755a2a2020-04-23 21:49:02 -070044#endif /* CONFIG_NO_TKIP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070045#define WPA_ALLOWED_GROUP_MGMT_CIPHERS \
46(WPA_CIPHER_AES_128_CMAC | WPA_CIPHER_BIP_GMAC_128 | WPA_CIPHER_BIP_GMAC_256 | \
47WPA_CIPHER_BIP_CMAC_256)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080048
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070049#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)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080061#define WPA_AUTH_KEY_MGMT_CCKM RSN_SELECTOR(0x00, 0x40, 0x96, 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070062#define WPA_CIPHER_SUITE_NONE RSN_SELECTOR(0x00, 0x50, 0xf2, 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070063#define WPA_CIPHER_SUITE_TKIP RSN_SELECTOR(0x00, 0x50, 0xf2, 2)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070064#define WPA_CIPHER_SUITE_CCMP RSN_SELECTOR(0x00, 0x50, 0xf2, 4)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070065
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)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069#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)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070071#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)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080074#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)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080076#define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B RSN_SELECTOR(0x00, 0x0f, 0xac, 11)
Dmitry Shmidt807291d2015-01-27 13:40:23 -080077#define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192 RSN_SELECTOR(0x00, 0x0f, 0xac, 12)
Roshan Pius3a1667e2018-07-03 15:17:14 -070078#define RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384 RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080079#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)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070083#define RSN_AUTH_KEY_MGMT_OWE RSN_SELECTOR(0x00, 0x0f, 0xac, 18)
Hai Shalom60840252021-02-19 19:02:11 -080084
85#define RSN_AUTH_KEY_MGMT_PASN RSN_SELECTOR(0x00, 0x0f, 0xac, 21)
86
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080087#define RSN_AUTH_KEY_MGMT_CCKM RSN_SELECTOR(0x00, 0x40, 0x96, 0x00)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080088#define RSN_AUTH_KEY_MGMT_OSEN RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x01)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070089#define RSN_AUTH_KEY_MGMT_DPP RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x02)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070090
91#define RSN_CIPHER_SUITE_NONE RSN_SELECTOR(0x00, 0x0f, 0xac, 0)
Paul Stewart092955c2017-02-06 09:13:09 -080092#define RSN_CIPHER_SUITE_WEP40 RSN_SELECTOR(0x00, 0x0f, 0xac, 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070093#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)
Paul Stewart092955c2017-02-06 09:13:09 -080098#define RSN_CIPHER_SUITE_WEP104 RSN_SELECTOR(0x00, 0x0f, 0xac, 5)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070099#define RSN_CIPHER_SUITE_AES_128_CMAC RSN_SELECTOR(0x00, 0x0f, 0xac, 6)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700100#define RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED RSN_SELECTOR(0x00, 0x0f, 0xac, 7)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700101#define RSN_CIPHER_SUITE_GCMP RSN_SELECTOR(0x00, 0x0f, 0xac, 8)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800102#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)
Paul Stewart092955c2017-02-06 09:13:09 -0800107#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)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700113
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)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700123#define RSN_KEY_DATA_IGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 9)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700124#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)
Hai Shalom74f70d42019-02-11 14:42:39 -0800127#define RSN_KEY_DATA_OCI RSN_SELECTOR(0x00, 0x0f, 0xac, 13)
Hai Shalomfdcde762020-04-02 11:19:20 -0700128#define RSN_KEY_DATA_BIGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 14)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700129
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800130#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)
Hai Shalomfdcde762020-04-02 11:19:20 -0700132#define WFA_KEY_DATA_TRANSITION_DISABLE RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x20)
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700133#define WFA_KEY_DATA_DPP RSN_SELECTOR(0x50, 0x6f, 0x9a, 0x21)
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800134
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700135#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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150#define WPA_IGTK_LEN 16
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700151#define WPA_IGTK_MAX_LEN 32
Hai Shalomfdcde762020-04-02 11:19:20 -0700152#define WPA_BIGTK_LEN 16
153#define WPA_BIGTK_MAX_LEN 32
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154
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)
Hai Shalom74f70d42019-02-11 14:42:39 -0800169#define WPA_CAPABILITY_OCVC BIT(14)
170/* B15: Reserved */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171
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)))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800182#define WPA_KEY_INFO_TYPE_AKM_DEFINED 0
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183#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
201struct 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 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800211 /* variable length Key MIC field */
212 /* big endian 2-octet Key Data Length field */
213 /* followed by Key Data Length bytes of Key Data */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800214} STRUCT_PACKED;
215
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700216#define WPA_EAPOL_KEY_MIC_MAX_LEN 32
217#define WPA_KCK_MAX_LEN 32
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800218#define WPA_KEK_MAX_LEN 64
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800219#define WPA_TK_MAX_LEN 32
Hai Shalom60840252021-02-19 19:02:11 -0800220#define WPA_KDK_MAX_LEN 32
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800221#define FILS_ICK_MAX_LEN 48
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700222#define FILS_FT_MAX_LEN 48
Hai Shalom60840252021-02-19 19:02:11 -0800223#define WPA_PASN_KCK_LEN 32
224#define WPA_PASN_MIC_MAX_LEN 24
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226/**
227 * struct wpa_ptk - WPA Pairwise Transient Key
228 * IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy
229 */
230struct wpa_ptk {
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800231 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) */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700234 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) */
Hai Shalom60840252021-02-19 19:02:11 -0800236 u8 kdk[WPA_KDK_MAX_LEN]; /* Key Derivation Key */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800237 size_t kck_len;
238 size_t kek_len;
239 size_t tk_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700240 size_t kck2_len;
241 size_t kek2_len;
Hai Shalom60840252021-02-19 19:02:11 -0800242 size_t kdk_len;
Mathy Vanhoefc66556c2017-09-29 04:22:51 +0200243 int installed; /* 1 if key has already been installed to driver */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800244};
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245
Mathy Vanhoef10bfd642017-07-12 16:03:24 +0200246struct wpa_gtk {
247 u8 gtk[WPA_GTK_MAX_LEN];
248 size_t gtk_len;
249};
250
Mathy Vanhoef10bfd642017-07-12 16:03:24 +0200251struct wpa_igtk {
252 u8 igtk[WPA_IGTK_MAX_LEN];
253 size_t igtk_len;
254};
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700255
Hai Shalomfdcde762020-04-02 11:19:20 -0700256struct wpa_bigtk {
257 u8 bigtk[WPA_BIGTK_MAX_LEN];
258 size_t bigtk_len;
259};
260
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700261/* 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
275struct 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
307struct rsn_ie_hdr {
308 u8 elem_id; /* WLAN_EID_RSN */
309 u8 len;
310 u8 version[2]; /* little endian */
311} STRUCT_PACKED;
312
313
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314struct rsn_error_kde {
315 be16 mui;
316 be16 error_type;
317} STRUCT_PACKED;
318
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700319#define WPA_IGTK_KDE_PREFIX_LEN (2 + 6)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320struct wpa_igtk_kde {
321 u8 keyid[2];
322 u8 pn[6];
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700323 u8 igtk[WPA_IGTK_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324} STRUCT_PACKED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325
Hai Shalomfdcde762020-04-02 11:19:20 -0700326#define WPA_BIGTK_KDE_PREFIX_LEN (2 + 6)
327struct wpa_bigtk_kde {
328 u8 keyid[2];
329 u8 pn[6];
330 u8 bigtk[WPA_BIGTK_MAX_LEN];
331} STRUCT_PACKED;
332
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333struct 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
341struct 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
Roshan Pius3a1667e2018-07-03 15:17:14 -0700349struct 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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357#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
Hai Shalom74f70d42019-02-11 14:42:39 -0800361#define FTIE_SUBELEM_OCI 5
Hai Shalomfdcde762020-04-02 11:19:20 -0700362#define FTIE_SUBELEM_BIGTK 6
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363
364struct rsn_rdie {
365 u8 id;
366 u8 descr_count;
367 le16 status_code;
368} STRUCT_PACKED;
369
Hai Shalomfdcde762020-04-02 11:19:20 -0700370/* 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)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700377/* DPP KDE Flags */
378#define DPP_KDE_PFS_ALLOWED BIT(0)
379#define DPP_KDE_PFS_REQUIRED BIT(1)
380
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381#ifdef _MSC_VER
382#pragma pack(pop)
383#endif /* _MSC_VER */
384
385
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800386int wpa_eapol_key_mic(const u8 *key, size_t key_len, int akmp, int ver,
387 const u8 *buf, size_t len, u8 *mic);
388int 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,
Hai Shalom021b0b52019-04-10 11:17:58 -0700391 struct wpa_ptk *ptk, int akmp, int cipher,
Hai Shalom60840252021-02-19 19:02:11 -0800392 const u8 *z, size_t z_len, size_t kdk_len);
Paul Stewart092955c2017-02-06 09:13:09 -0800393int 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);
396int fils_pmkid_erp(int akmp, const u8 *reauth, size_t reauth_len,
397 u8 *pmkid);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800398int fils_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const u8 *spa, const u8 *aa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700399 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,
Hai Shalom60840252021-02-19 19:02:11 -0800402 u8 *fils_ft, size_t *fils_ft_len, size_t kdk_len);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800403int 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);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700409
410#ifdef CONFIG_IEEE80211R
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800411int 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,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 const u8 *ftie, size_t ftie_len,
415 const u8 *rsnie, size_t rsnie_len,
Hai Shalomc3565922019-10-28 11:58:20 -0700416 const u8 *ric, size_t ric_len,
417 const u8 *rsnxe, size_t rsnxe_len,
418 u8 *mic);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800419int 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,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700422 const u8 *s0kh_id, u8 *pmk_r0, u8 *pmk_r0_name,
423 int use_sha384);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800424int wpa_derive_pmk_r1_name(const u8 *pmk_r0_name, const u8 *r1kh_id,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700425 const u8 *s1kh_id, u8 *pmk_r1_name, int use_sha384);
426int wpa_derive_pmk_r1(const u8 *pmk_r0, size_t pmk_r0_len,
427 const u8 *pmk_r0_name,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800428 const u8 *r1kh_id, const u8 *s1kh_id,
429 u8 *pmk_r1, u8 *pmk_r1_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700430int 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,
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800432 const u8 *pmk_r1_name,
Hai Shalom60840252021-02-19 19:02:11 -0800433 struct wpa_ptk *ptk, u8 *ptk_name, int akmp, int cipher,
434 size_t kdk_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700435#endif /* CONFIG_IEEE80211R */
436
437struct wpa_ie_data {
438 int proto;
439 int pairwise_cipher;
Hai Shalom021b0b52019-04-10 11:17:58 -0700440 int has_pairwise;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441 int group_cipher;
Hai Shalom021b0b52019-04-10 11:17:58 -0700442 int has_group;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700443 int key_mgmt;
444 int capabilities;
445 size_t num_pmkid;
446 const u8 *pmkid;
447 int mgmt_group_cipher;
448};
449
450
451int wpa_parse_wpa_ie_rsn(const u8 *rsn_ie, size_t rsn_ie_len,
452 struct wpa_ie_data *data);
453int wpa_parse_wpa_ie_wpa(const u8 *wpa_ie, size_t wpa_ie_len,
454 struct wpa_ie_data *data);
Hai Shalom021b0b52019-04-10 11:17:58 -0700455int wpa_default_rsn_cipher(int freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700456
457void rsn_pmkid(const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700458 u8 *pmkid, int akmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800459#ifdef CONFIG_SUITEB
460int rsn_pmkid_suite_b(const u8 *kck, size_t kck_len, const u8 *aa,
461 const u8 *spa, u8 *pmkid);
462#else /* CONFIG_SUITEB */
463static 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 */
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800469#ifdef CONFIG_SUITEB192
470int 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 */
473static 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 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479
480const char * wpa_cipher_txt(int cipher);
481const char * wpa_key_mgmt_txt(int key_mgmt, int proto);
Dmitry Shmidt03658832014-08-13 11:03:49 -0700482u32 wpa_akm_to_suite(int akm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700483int wpa_compare_rsn_ie(int ft_initial_assoc,
484 const u8 *ie1, size_t ie1len,
485 const u8 *ie2, size_t ie2len);
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800486int wpa_insert_pmkid(u8 *ies, size_t *ies_len, const u8 *pmkid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800488struct 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;
Hai Shalomc3565922019-10-28 11:58:20 -0700498 const u8 *fte_anonce;
499 const u8 *fte_snonce;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800500 const u8 *rsn;
501 size_t rsn_len;
Hai Shalomc3565922019-10-28 11:58:20 -0700502 u16 rsn_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800503 const u8 *rsn_pmkid;
504 const u8 *tie;
505 size_t tie_len;
506 const u8 *igtk;
507 size_t igtk_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700508 const u8 *bigtk;
509 size_t bigtk_len;
Hai Shalom74f70d42019-02-11 14:42:39 -0800510#ifdef CONFIG_OCV
511 const u8 *oci;
512 size_t oci_len;
513#endif /* CONFIG_OCV */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800514 const u8 *ric;
515 size_t ric_len;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800516 int key_mgmt;
517 int pairwise_cipher;
Hai Shalomc3565922019-10-28 11:58:20 -0700518 const u8 *rsnxe;
519 size_t rsnxe_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800520};
521
Hai Shalom60840252021-02-19 19:02:11 -0800522/* 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
531struct 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
539struct 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
Hai Shaloma20dcd72022-02-04 13:43:00 -0800549/* See RFC 5480 section 2.2 */
550#define WPA_PASN_PUBKEY_COMPRESSED_0 0x02
551#define WPA_PASN_PUBKEY_COMPRESSED_1 0x03
552#define WPA_PASN_PUBKEY_UNCOMPRESSED 0x04
553
Roshan Pius3a1667e2018-07-03 15:17:14 -0700554int wpa_ft_parse_ies(const u8 *ies, size_t ies_len, struct wpa_ft_ies *parse,
555 int use_sha384);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800556
Hai Shalomc3565922019-10-28 11:58:20 -0700557struct wpa_eapol_ie_parse {
558 const u8 *wpa_ie;
559 size_t wpa_ie_len;
560 const u8 *rsn_ie;
561 size_t rsn_ie_len;
562 const u8 *pmkid;
Hai Shalomfdcde762020-04-02 11:19:20 -0700563 const u8 *key_id;
Hai Shalomc3565922019-10-28 11:58:20 -0700564 const u8 *gtk;
565 size_t gtk_len;
566 const u8 *mac_addr;
567 size_t mac_addr_len;
568 const u8 *igtk;
569 size_t igtk_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700570 const u8 *bigtk;
571 size_t bigtk_len;
Hai Shalomc3565922019-10-28 11:58:20 -0700572 const u8 *mdie;
573 size_t mdie_len;
574 const u8 *ftie;
575 size_t ftie_len;
576 const u8 *ip_addr_req;
577 const u8 *ip_addr_alloc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700578 const u8 *transition_disable;
579 size_t transition_disable_len;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700580 const u8 *dpp_kde;
581 size_t dpp_kde_len;
Hai Shalomc3565922019-10-28 11:58:20 -0700582 const u8 *oci;
583 size_t oci_len;
584 const u8 *osen;
585 size_t osen_len;
586 const u8 *rsnxe;
587 size_t rsnxe_len;
588 const u8 *reassoc_deadline;
589 const u8 *key_lifetime;
590 const u8 *lnkid;
591 size_t lnkid_len;
592 const u8 *ext_capab;
593 size_t ext_capab_len;
594 const u8 *supp_rates;
595 size_t supp_rates_len;
596 const u8 *ext_supp_rates;
597 size_t ext_supp_rates_len;
598 const u8 *ht_capabilities;
599 const u8 *vht_capabilities;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800600 const u8 *he_capabilities;
601 size_t he_capab_len;
602 const u8 *he_6ghz_capabilities;
Hai Shalomc3565922019-10-28 11:58:20 -0700603 const u8 *supp_channels;
604 size_t supp_channels_len;
605 const u8 *supp_oper_classes;
606 size_t supp_oper_classes_len;
607 u8 qosinfo;
608 u16 aid;
609 const u8 *wmm;
610 size_t wmm_len;
611};
612
613int wpa_parse_kde_ies(const u8 *buf, size_t len, struct wpa_eapol_ie_parse *ie);
614static inline int wpa_supplicant_parse_ies(const u8 *buf, size_t len,
615 struct wpa_eapol_ie_parse *ie)
616{
617 return wpa_parse_kde_ies(buf, len, ie);
618}
619
620
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700621int wpa_cipher_key_len(int cipher);
622int wpa_cipher_rsc_len(int cipher);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800623enum wpa_alg wpa_cipher_to_alg(int cipher);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800624int wpa_cipher_valid_group(int cipher);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700625int wpa_cipher_valid_pairwise(int cipher);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700626int wpa_cipher_valid_mgmt_group(int cipher);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700627u32 wpa_cipher_to_suite(int proto, int cipher);
628int rsn_cipher_put_suites(u8 *pos, int ciphers);
629int wpa_cipher_put_suites(u8 *pos, int ciphers);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800630int wpa_pick_pairwise_cipher(int ciphers, int none_allowed);
631int wpa_pick_group_cipher(int ciphers);
632int wpa_parse_cipher(const char *value);
633int wpa_write_ciphers(char *start, char *end, int ciphers, const char *delim);
634int wpa_select_ap_group_cipher(int wpa, int wpa_pairwise, int rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700635unsigned int wpa_mic_len(int akmp, size_t pmk_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700636int wpa_use_akm_defined(int akmp);
637int wpa_use_cmac(int akmp);
638int wpa_use_aes_key_wrap(int akmp);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800639int fils_domain_name_hash(const char *domain, u8 *hash);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700640
Hai Shalom60840252021-02-19 19:02:11 -0800641int pasn_pmk_to_ptk(const u8 *pmk, size_t pmk_len,
642 const u8 *spa, const u8 *bssid,
643 const u8 *dhss, size_t dhss_len,
644 struct wpa_ptk *ptk, int akmp, int cipher,
645 size_t kdk_len);
646
647u8 pasn_mic_len(int akmp, int cipher);
648
649int pasn_mic(const u8 *kck, int akmp, int cipher,
650 const u8 *addr1, const u8 *addr2,
651 const u8 *data, size_t data_len,
652 const u8 *frame, size_t frame_len, u8 *mic);
653
654int pasn_auth_frame_hash(int akmp, int cipher, const u8 *data, size_t len,
655 u8 *hash);
656
657void wpa_pasn_build_auth_header(struct wpabuf *buf, const u8 *bssid,
658 const u8 *src, const u8 *dst,
659 u8 trans_seq, u16 status);
660
661int wpa_pasn_add_rsne(struct wpabuf *buf, const u8 *pmkid,
662 int akmp, int cipher);
663
664void wpa_pasn_add_parameter_ie(struct wpabuf *buf, u16 pasn_group,
665 u8 wrapped_data_format,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800666 const struct wpabuf *pubkey, bool compressed,
667 const struct wpabuf *comeback, int after);
Hai Shalom60840252021-02-19 19:02:11 -0800668
669int wpa_pasn_add_wrapped_data(struct wpabuf *buf,
670 struct wpabuf *wrapped_data_buf);
671
672int wpa_pasn_validate_rsne(const struct wpa_ie_data *data);
673int wpa_pasn_parse_parameter_ie(const u8 *data, u8 len, bool from_ap,
674 struct wpa_pasn_params_data *pasn_params);
675
676void wpa_pasn_add_rsnxe(struct wpabuf *buf, u16 capab);
677
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678#endif /* WPA_COMMON_H */