xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/include/wpa.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Fundamental types and constants relating to WPA
3  *
4  * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
5  *
6  * Copyright (C) 1999-2017, Broadcom Corporation
7  *
8  *      Unless you and Broadcom execute a separate written software license
9  * agreement governing use of this software, this software is licensed to you
10  * under the terms of the GNU General Public License version 2 (the "GPL"),
11  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12  * following added to such license:
13  *
14  *      As a special exception, the copyright holders of this software give you
15  * permission to link this software with independent modules, and to copy and
16  * distribute the resulting executable under terms of your choice, provided that
17  * you also meet, for each linked independent module, the terms and conditions of
18  * the license of that module.  An independent module is a module which is not
19  * derived from this software.  The special exception does not apply to any
20  * modifications of the software.
21  *
22  *      Notwithstanding the above, under no circumstances may you combine this
23  * software in any way with any other Broadcom software provided under a license
24  * other than the GPL, without Broadcom's express prior written consent.
25  *
26  *
27  * <<Broadcom-WL-IPTag/Open:>>
28  *
29  * $Id$
30  */
31 
32 #ifndef _proto_wpa_h_
33 #define _proto_wpa_h_
34 
35 #include <typedefs.h>
36 #include <ethernet.h>
37 
38 /* This marks the start of a packed structure section. */
39 #include <packed_section_start.h>
40 
41 /* Reason Codes */
42 
43 /* 13 through 23 taken from IEEE Std 802.11i-2004 */
44 #define DOT11_RC_INVALID_WPA_IE		13	/* Invalid info. element */
45 #define DOT11_RC_MIC_FAILURE		14	/* Michael failure */
46 #define DOT11_RC_4WH_TIMEOUT		15	/* 4-way handshake timeout */
47 #define DOT11_RC_GTK_UPDATE_TIMEOUT	16	/* Group key update timeout */
48 #define DOT11_RC_WPA_IE_MISMATCH	17	/* WPA IE in 4-way handshake differs from
49 						 * (re-)assoc. request/probe response
50 						 */
51 #define DOT11_RC_INVALID_MC_CIPHER	18	/* Invalid multicast cipher */
52 #define DOT11_RC_INVALID_UC_CIPHER	19	/* Invalid unicast cipher */
53 #define DOT11_RC_INVALID_AKMP		20	/* Invalid authenticated key management protocol */
54 #define DOT11_RC_BAD_WPA_VERSION	21	/* Unsupported WPA version */
55 #define DOT11_RC_INVALID_WPA_CAP	22	/* Invalid WPA IE capabilities */
56 #define DOT11_RC_8021X_AUTH_FAIL	23	/* 802.1X authentication failure */
57 
58 #define WPA2_PMKID_LEN	16
59 
60 /* WPA IE fixed portion */
61 typedef BWL_PRE_PACKED_STRUCT struct
62 {
63 	uint8 tag;	/* TAG */
64 	uint8 length;	/* TAG length */
65 	uint8 oui[3];	/* IE OUI */
66 	uint8 oui_type;	/* OUI type */
67 	BWL_PRE_PACKED_STRUCT struct {
68 		uint8 low;
69 		uint8 high;
70 	} BWL_POST_PACKED_STRUCT version;	/* IE version */
71 } BWL_POST_PACKED_STRUCT wpa_ie_fixed_t;
72 #define WPA_IE_OUITYPE_LEN	4
73 #define WPA_IE_FIXED_LEN	8
74 #define WPA_IE_TAG_FIXED_LEN	6
75 
76 #define BIP_OUI_TYPE WPA2_OUI "\x06"
77 #define BIP_GMAC_256_OUI_TYPE WPA2_OUI "\x0c"
78 
79 typedef BWL_PRE_PACKED_STRUCT struct {
80 	uint8 tag;	/* TAG */
81 	uint8 length;	/* TAG length */
82 	BWL_PRE_PACKED_STRUCT struct {
83 		uint8 low;
84 		uint8 high;
85 	} BWL_POST_PACKED_STRUCT version;	/* IE version */
86 } BWL_POST_PACKED_STRUCT wpa_rsn_ie_fixed_t;
87 #define WPA_RSN_IE_FIXED_LEN	4
88 #define WPA_RSN_IE_TAG_FIXED_LEN	2
89 typedef uint8 wpa_pmkid_t[WPA2_PMKID_LEN];
90 
91 #define WFA_OSEN_IE_FIXED_LEN	6
92 
93 /* WPA suite/multicast suite */
94 typedef BWL_PRE_PACKED_STRUCT struct
95 {
96 	uint8 oui[3];
97 	uint8 type;
98 } BWL_POST_PACKED_STRUCT wpa_suite_t, wpa_suite_mcast_t;
99 #define WPA_SUITE_LEN	4
100 
101 /* WPA unicast suite list/key management suite list */
102 typedef BWL_PRE_PACKED_STRUCT struct
103 {
104 	BWL_PRE_PACKED_STRUCT struct {
105 		uint8 low;
106 		uint8 high;
107 	} BWL_POST_PACKED_STRUCT count;
108 	wpa_suite_t list[1];
109 } BWL_POST_PACKED_STRUCT wpa_suite_ucast_t, wpa_suite_auth_key_mgmt_t;
110 #define WPA_IE_SUITE_COUNT_LEN	2
111 typedef BWL_PRE_PACKED_STRUCT struct
112 {
113 	BWL_PRE_PACKED_STRUCT struct {
114 		uint8 low;
115 		uint8 high;
116 	} BWL_POST_PACKED_STRUCT count;
117 	wpa_pmkid_t list[1];
118 } BWL_POST_PACKED_STRUCT wpa_pmkid_list_t;
119 
120 /* WPA cipher suites */
121 #define WPA_CIPHER_NONE		0	/* None */
122 #define WPA_CIPHER_WEP_40	1	/* WEP (40-bit) */
123 #define WPA_CIPHER_TKIP		2	/* TKIP: default for WPA */
124 #define WPA_CIPHER_AES_OCB	3	/* AES (OCB) */
125 #define WPA_CIPHER_AES_CCM	4	/* AES (CCM) */
126 #define WPA_CIPHER_WEP_104	5	/* WEP (104-bit) */
127 #define WPA_CIPHER_BIP		6	/* WEP (104-bit) */
128 #define WPA_CIPHER_TPK		7	/* Group addressed traffic not allowed */
129 #ifdef BCMCCX
130 #define WPA_CIPHER_CKIP		8	/* KP with no MIC */
131 #define WPA_CIPHER_CKIP_MMH	9	/* KP with MIC ("CKIP/MMH", "CKIP+CMIC") */
132 #define WPA_CIPHER_WEP_MMH	10	/* MIC with no KP ("WEP/MMH", "CMIC") */
133 
134 #define IS_CCX_CIPHER(cipher)	((cipher) == WPA_CIPHER_CKIP || \
135 				 (cipher) == WPA_CIPHER_CKIP_MMH || \
136 				 (cipher) == WPA_CIPHER_WEP_MMH)
137 #endif /* BCMCCX */
138 
139 #define WPA_CIPHER_AES_GCM	8	/* AES (GCM) */
140 #define WPA_CIPHER_AES_GCM256	9	/* AES (GCM256) */
141 #define WPA_CIPHER_CCMP_256 	10	/* CCMP-256 */
142 #define WPA_CIPHER_BIP_GMAC_128	11	/* BIP_GMAC_128 */
143 #define WPA_CIPHER_BIP_GMAC_256 12	/* BIP_GMAC_256 */
144 #define WPA_CIPHER_BIP_CMAC_256 13	/* BIP_CMAC_256 */
145 
146 #define WAPI_CIPHER_NONE	WPA_CIPHER_NONE
147 #define WAPI_CIPHER_SMS4	11
148 
149 #define WAPI_CSE_WPI_SMS4	1
150 
151 #define IS_WPA_CIPHER(cipher)	((cipher) == WPA_CIPHER_NONE || \
152 				 (cipher) == WPA_CIPHER_WEP_40 || \
153 				 (cipher) == WPA_CIPHER_WEP_104 || \
154 				 (cipher) == WPA_CIPHER_TKIP || \
155 				 (cipher) == WPA_CIPHER_AES_OCB || \
156 				 (cipher) == WPA_CIPHER_AES_CCM || \
157 				 (cipher) == WPA_CIPHER_AES_GCM || \
158 				 (cipher) == WPA_CIPHER_AES_GCM256 || \
159 				 (cipher) == WPA_CIPHER_TPK)
160 
161 #define IS_WAPI_CIPHER(cipher)	((cipher) == WAPI_CIPHER_NONE || \
162 				 (cipher) == WAPI_CSE_WPI_SMS4)
163 
164 /* convert WAPI_CSE_WPI_XXX to WAPI_CIPHER_XXX */
165 #define WAPI_CSE_WPI_2_CIPHER(cse) ((cse) == WAPI_CSE_WPI_SMS4 ? \
166 				WAPI_CIPHER_SMS4 : WAPI_CIPHER_NONE)
167 
168 #define WAPI_CIPHER_2_CSE_WPI(cipher) ((cipher) == WAPI_CIPHER_SMS4 ? \
169 				WAPI_CSE_WPI_SMS4 : WAPI_CIPHER_NONE)
170 
171 #define IS_VALID_AKM(akm) ((akm) == RSN_AKM_NONE || \
172 			(akm) == RSN_AKM_UNSPECIFIED || \
173 			(akm) == RSN_AKM_PSK || \
174 			(akm) == RSN_AKM_FBT_1X || \
175 			(akm) == RSN_AKM_FBT_PSK || \
176 			(akm) == RSN_AKM_MFP_1X || \
177 			(akm) == RSN_AKM_MFP_PSK || \
178 			(akm) == RSN_AKM_SHA256_1X || \
179 			(akm) == RSN_AKM_SHA256_PSK || \
180 			(akm) == RSN_AKM_TPK || \
181 			(akm) == RSN_AKM_SAE_PSK || \
182 			(akm) == RSN_AKM_SAE_FBT || \
183 			(akm) == RSN_AKM_FILS_SHA256 || \
184 			(akm) == RSN_AKM_FILS_SHA384 || \
185 			(akm) == RSN_AKM_OWE || \
186 			(akm) == RSN_AKM_SUITEB_SHA256_1X || \
187 			(akm) == RSN_AKM_SUITEB_SHA384_1X)
188 
189 #define IS_VALID_BIP_CIPHER(cipher) ((cipher) == WPA_CIPHER_BIP || \
190 					(cipher) == WPA_CIPHER_BIP_GMAC_128 || \
191 					(cipher) == WPA_CIPHER_BIP_GMAC_256 || \
192 					(cipher) == WPA_CIPHER_BIP_CMAC_256)
193 
194 /* Unicast deprecated/invalid ciphers */
195 #define IS_UNICAST_DEPRECATED_CIPHER(cipher) \
196 					((cipher) == WPA_CIPHER_WEP_40 || \
197 					(cipher) == WPA_CIPHER_WEP_104 || \
198 					(cipher) == WPA_CIPHER_TKIP)
199 
200 /* WPA TKIP countermeasures parameters */
201 #define WPA_TKIP_CM_DETECT	60	/* multiple MIC failure window (seconds) */
202 #define WPA_TKIP_CM_BLOCK	60	/* countermeasures active window (seconds) */
203 
204 /* RSN IE defines */
205 #define RSN_CAP_LEN		2	/* Length of RSN capabilities field (2 octets) */
206 
207 /* RSN Capabilities defined in 802.11i */
208 #define RSN_CAP_PREAUTH			0x0001
209 #define RSN_CAP_NOPAIRWISE		0x0002
210 #define RSN_CAP_PTK_REPLAY_CNTR_MASK	0x000C
211 #define RSN_CAP_PTK_REPLAY_CNTR_SHIFT	2
212 #define RSN_CAP_GTK_REPLAY_CNTR_MASK	0x0030
213 #define RSN_CAP_GTK_REPLAY_CNTR_SHIFT	4
214 #define RSN_CAP_1_REPLAY_CNTR		0
215 #define RSN_CAP_2_REPLAY_CNTRS		1
216 #define RSN_CAP_4_REPLAY_CNTRS		2
217 #define RSN_CAP_16_REPLAY_CNTRS		3
218 #define RSN_CAP_MFPR			0x0040
219 #define RSN_CAP_MFPC			0x0080
220 #define RSN_CAP_SPPC			0x0400
221 #define RSN_CAP_SPPR			0x0800
222 
223 /* WPA capabilities defined in 802.11i */
224 #define WPA_CAP_4_REPLAY_CNTRS		RSN_CAP_4_REPLAY_CNTRS
225 #define WPA_CAP_16_REPLAY_CNTRS		RSN_CAP_16_REPLAY_CNTRS
226 #define WPA_CAP_REPLAY_CNTR_SHIFT	RSN_CAP_PTK_REPLAY_CNTR_SHIFT
227 #define WPA_CAP_REPLAY_CNTR_MASK	RSN_CAP_PTK_REPLAY_CNTR_MASK
228 
229 /* WPA capabilities defined in 802.11zD9.0 */
230 #define WPA_CAP_PEER_KEY_ENABLE		(0x1 << 1)	/* bit 9 */
231 
232 /* WPA Specific defines */
233 #define WPA_CAP_LEN	RSN_CAP_LEN	/* Length of RSN capabilities in RSN IE (2 octets) */
234 #define WPA_PMKID_CNT_LEN	2 	/* Length of RSN PMKID count (2 octests) */
235 
236 #define	WPA_CAP_WPA2_PREAUTH		RSN_CAP_PREAUTH
237 
238 #define WPA2_PMKID_COUNT_LEN	2
239 
240 /* RSN dev type in rsn_info struct */
241 typedef enum {
242 	DEV_NONE = 0,
243 	DEV_STA = 1,
244 	DEV_AP = 2
245 } device_type_t;
246 
247 typedef uint32 rsn_akm_mask_t;			/* RSN_AKM_... see 802.11.h */
248 typedef uint8  rsn_cipher_t;			/* WPA_CIPHER_xxx */
249 typedef uint32 rsn_ciphers_t;			/* mask of rsn_cipher_t */
250 typedef uint8 rsn_akm_t;
251 typedef uint8 auth_ie_type_mask_t;
252 
253 typedef struct rsn_ie_info {
254 	uint8 version;
255 	rsn_cipher_t g_cipher;
256 	uint8 p_count;
257 	uint8 akm_count;
258 	uint8 pmkid_count;
259 	rsn_akm_t sta_akm;			/* single STA akm */
260 	uint16 caps;
261 	rsn_ciphers_t p_ciphers;
262 	rsn_akm_mask_t akms;
263 	uint8 pmkids_offset;			/* offset into the IE */
264 	rsn_cipher_t g_mgmt_cipher;
265 	device_type_t dev_type;			/* AP or STA */
266 	rsn_cipher_t sta_cipher;		/* single STA cipher */
267 	uint16 key_desc;			/* key descriptor version as STA */
268 	int parse_status;
269 	uint16 mic_len;				/* unused. keep for ROM compatibility. */
270 	auth_ie_type_mask_t auth_ie_type;	/* bit field of WPA, WPA2 and (not yet) CCX WAPI */
271 	uint8 pmk_len;				/* EAPOL PMK */
272 	uint8 kck_mic_len;			/* EAPOL MIC (by KCK) */
273 	uint8 kck_len;				/* EAPOL KCK */
274 	uint8 kek_len;				/* EAPOL KEK */
275 	uint8 tk_len;				/* EAPOL TK */
276 	uint8 ptk_len;				/* EAPOL PTK */
277 } rsn_ie_info_t;
278 
279 #define WAPI_CAP_PREAUTH		RSN_CAP_PREAUTH
280 
281 /* Other WAI definition */
282 #define WAPI_WAI_REQUEST		0x00F1
283 #define WAPI_UNICAST_REKEY		0x00F2
284 #define WAPI_STA_AGING			0x00F3
285 #define WAPI_MUTIL_REKEY		0x00F4
286 #define WAPI_STA_STATS			0x00F5
287 
288 #define WAPI_USK_REKEY_COUNT		0x4000000 /* 0xA00000 */
289 #define WAPI_MSK_REKEY_COUNT		0x4000000 /* 0xA00000 */
290 
291 /* This marks the end of a packed structure section. */
292 #include <packed_section_end.h>
293 
294 #endif /* _proto_wpa_h_ */
295