xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/crypto/src/wlan_crypto_def_i.h (revision 2f4b444fb7e689b83a4ab0e7b3b38f0bf4def8e0)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19  /**
20  * DOC: Private definations for handling crypto params
21  */
22 #ifndef _WLAN_CRYPTO_DEF_I_H_
23 #define _WLAN_CRYPTO_DEF_I_H_
24 
25 #include <wlan_cmn_ieee80211.h>
26 #ifdef WLAN_CRYPTO_AES
27 #include "wlan_crypto_aes_i.h"
28 #endif
29 
30 /* IEEE 802.11 defines */
31 #define WLAN_FC0_PVER      0x0003
32 #define WLAN_FC1_DIR_MASK  0x03
33 #define WLAN_FC1_TODS      0x01
34 #define WLAN_FC1_FROMDS    0x02
35 #define WLAN_FC1_DSTODS    0x03
36 #define WLAN_FC1_MOREFRAG  0x04
37 #define WLAN_FC1_RETRY     0x08
38 #define WLAN_FC1_PWRMGT    0x10
39 #define WLAN_FC1_MOREDATA  0x20
40 #define WLAN_FC1_ISWEP     0x40
41 #define WLAN_FC1_ORDER     0x80
42 
43 #define WLAN_FC0_GET_TYPE(fc)    (((fc) & 0x0c) >> 2)
44 #define WLAN_FC0_GET_STYPE(fc)   (((fc) & 0xf0) >> 4)
45 
46 #define WLAN_INVALID_MGMT_SEQ   0xffff
47 #define WLAN_SEQ_MASK           0x0fff
48 #define WLAN_QOS_TID_MASK       0x0f
49 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & (BIT(3) | BIT(2) | BIT(1) | BIT(0)))
50 #define WLAN_GET_SEQ_SEQ(seq) \
51 	(((seq) & (~(BIT(3) | BIT(2) | BIT(1) | BIT(0)))) >> 4)
52 
53 #define WLAN_FC0_TYPE_MGMT        0
54 #define WLAN_FC0_TYPE_CTRL        1
55 #define WLAN_FC0_TYPE_DATA        2
56 
57 /* management */
58 #define WLAN_FC0_STYPE_ASSOC_REQ      0
59 #define WLAN_FC0_STYPE_ASSOC_RESP     1
60 #define WLAN_FC0_STYPE_REASSOC_REQ    2
61 #define WLAN_FC0_STYPE_REASSOC_RESP   3
62 #define WLAN_FC0_STYPE_PROBE_REQ      4
63 #define WLAN_FC0_STYPE_PROBE_RESP     5
64 #define WLAN_FC0_STYPE_BEACON         8
65 #define WLAN_FC0_STYPE_ATIM           9
66 #define WLAN_FC0_STYPE_DISASSOC      10
67 #define WLAN_FC0_STYPE_AUTH          11
68 #define WLAN_FC0_STYPE_DEAUTH        12
69 #define WLAN_FC0_STYPE_ACTION        13
70 
71 /* control */
72 #define WLAN_FC0_STYPE_PSPOLL        10
73 #define WLAN_FC0_STYPE_RTS           11
74 #define WLAN_FC0_STYPE_CTS           12
75 #define WLAN_FC0_STYPE_ACK           13
76 #define WLAN_FC0_STYPE_CFEND         14
77 #define WLAN_FC0_STYPE_CFENDACK      15
78 
79 /* data */
80 #define WLAN_FC0_STYPE_DATA                0
81 #define WLAN_FC0_STYPE_DATA_CFACK          1
82 #define WLAN_FC0_STYPE_DATA_CFPOLL         2
83 #define WLAN_FC0_STYPE_DATA_CFACKPOLL      3
84 #define WLAN_FC0_STYPE_NULLFUNC            4
85 #define WLAN_FC0_STYPE_CFACK               5
86 #define WLAN_FC0_STYPE_CFPOLL              6
87 #define WLAN_FC0_STYPE_CFACKPOLL           7
88 #define WLAN_FC0_STYPE_QOS_DATA            8
89 #define WLAN_FC0_STYPE_QOS_DATA_CFACK      9
90 #define WLAN_FC0_STYPE_QOS_DATA_CFPOLL    10
91 #define WLAN_FC0_STYPE_QOS_DATA_CFACKPOLL 11
92 #define WLAN_FC0_STYPE_QOS_NULL           12
93 #define WLAN_FC0_STYPE_QOS_CFPOLL         14
94 #define WLAN_FC0_STYPE_QOS_CFACKPOLL      15
95 
96 #define WLAN_TID_SIZE                    17
97 #define WLAN_NONQOS_SEQ                  16
98 
99 /* Number of bits per byte */
100 #define CRYPTO_NBBY  8
101 
102 /* Macros for handling unaligned memory accesses */
103 
104 static inline uint16_t wlan_crypto_get_be16(const uint8_t *a)
105 {
106 	return (a[0] << 8) | a[1];
107 }
108 
109 static inline void wlan_crypto_put_be16(uint8_t *a, uint16_t val)
110 {
111 	a[0] = val >> 8;
112 	a[1] = val & 0xff;
113 }
114 
115 static inline uint16_t wlan_crypto_get_le16(const uint8_t *a)
116 {
117 	return (a[1] << 8) | a[0];
118 }
119 
120 static inline void wlan_crypto_put_le16(uint8_t *a, uint16_t val)
121 {
122 	a[1] = val >> 8;
123 	a[0] = val & 0xff;
124 }
125 
126 static inline uint32_t wlan_crypto_get_be32(const uint8_t *a)
127 {
128 	return ((u32) a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3];
129 }
130 
131 static inline void wlan_crypto_put_be32(uint8_t *a, uint32_t val)
132 {
133 	a[0] = (val >> 24) & 0xff;
134 	a[1] = (val >> 16) & 0xff;
135 	a[2] = (val >> 8) & 0xff;
136 	a[3] = val & 0xff;
137 }
138 
139 static inline uint32_t wlan_crypto_get_le32(const uint8_t *a)
140 {
141 	return ((u32) a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0];
142 }
143 
144 static inline void wlan_crypto_put_le32(uint8_t *a, uint32_t val)
145 {
146 	a[3] = (val >> 24) & 0xff;
147 	a[2] = (val >> 16) & 0xff;
148 	a[1] = (val >> 8) & 0xff;
149 	a[0] = val & 0xff;
150 }
151 
152 static inline void wlan_crypto_put_be64(u8 *a, u64 val)
153 {
154 	a[0] = val >> 56;
155 	a[1] = val >> 48;
156 	a[2] = val >> 40;
157 	a[3] = val >> 32;
158 	a[4] = val >> 24;
159 	a[5] = val >> 16;
160 	a[6] = val >> 8;
161 	a[7] = val & 0xff;
162 }
163 
164 #define WLAN_CRYPTO_TX_OPS_ALLOCKEY(tx_ops) \
165 	((tx_ops)->crypto_tx_ops.allockey)
166 #define WLAN_CRYPTO_TX_OPS_SETKEY(tx_ops) \
167 	((tx_ops)->crypto_tx_ops.setkey)
168 #define WLAN_CRYPTO_TX_OPS_DELKEY(tx_ops) \
169 	((tx_ops)->crypto_tx_ops.delkey)
170 #define WLAN_CRYPTO_TX_OPS_DEFAULTKEY(tx_ops) \
171 	((tx_ops)->crypto_tx_ops.defaultkey)
172 #define WLAN_CRYPTO_TX_OPS_SET_KEY(tx_ops) \
173 	((tx_ops)->crypto_tx_ops.set_key)
174 #define WLAN_CRYPTO_TX_OPS_GETPN(tx_ops) \
175 	((tx_ops)->crypto_tx_ops.getpn)
176 #define WLAN_CRYPTO_TX_OPS_REGISTER_EVENTS(tx_ops) \
177 	((tx_ops)->crypto_tx_ops.register_events)
178 #define WLAN_CRYPTO_TX_OPS_DEREGISTER_EVENTS(tx_ops) \
179 	((tx_ops)->crypto_tx_ops.deregister_events)
180 
181 /* unalligned little endian access */
182 #ifndef LE_READ_2
183 #define LE_READ_2(p) \
184 	((uint16_t)                          \
185 	((((const uint8_t *)(p))[0]) |       \
186 	(((const uint8_t *)(p))[1] <<  8)))
187 #endif
188 
189 #ifndef LE_READ_4
190 #define LE_READ_4(p)                   \
191 	((uint32_t)                          \
192 	((((const uint8_t *)(p))[0]) |       \
193 	(((const uint8_t *)(p))[1] <<  8) |  \
194 	(((const uint8_t *)(p))[2] << 16) |  \
195 	(((const uint8_t *)(p))[3] << 24)))
196 #endif
197 
198 #ifndef BE_READ_4
199 #define BE_READ_4(p)                        \
200 	((uint32_t)                              \
201 	((((const uint8_t *)(p))[0] << 24) |     \
202 	(((const uint8_t *)(p))[1] << 16) |      \
203 	(((const uint8_t *)(p))[2] <<  8) |      \
204 	(((const uint8_t *)(p))[3])))
205 #endif
206 
207 #ifndef READ_6
208 #define READ_6(b0, b1, b2, b3, b4, b5)  ({ \
209 	uint32_t iv32 = (b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24);\
210 	uint16_t iv16 = (b4 << 0) | (b5 << 8);\
211 	(((uint64_t)iv16) << 32) | iv32;\
212 })
213 #endif
214 
215 #define OUI_SIZE   (4)
216 #define WLAN_CRYPTO_ADDSHORT(frm, v)  \
217 	do {frm[0] = (v) & 0xff; frm[1] = (v) >> 8; frm += 2; } while (0)
218 
219 #define	WLAN_CRYPTO_ADDSELECTOR(frm, sel) \
220 	do { \
221 		uint32_t value = sel;\
222 		qdf_mem_copy(frm, (uint8_t *)&value, OUI_SIZE); \
223 	frm += OUI_SIZE; } while (0)
224 
225 #define WLAN_CRYPTO_SELECTOR(a, b, c, d) \
226 	((((uint32_t) (a)) << 24) | \
227 	 (((uint32_t) (b)) << 16) | \
228 	 (((uint32_t) (c)) << 8) | \
229 		(uint32_t) (d))
230 
231 #define WPA_TYPE_OUI                    WLAN_WPA_SEL(WLAN_WPA_OUI_TYPE)
232 
233 #define WLAN_CRYPTO_WAPI_IE_LEN      20
234 #define WLAN_CRYPTO_WAPI_SMS4_CIPHER 0x01
235 
236 #define WPA_AUTH_KEY_MGMT_NONE          WLAN_WPA_SEL(WLAN_ASE_NONE)
237 #define WPA_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_WPA_SEL(WLAN_ASE_8021X_UNSPEC)
238 #define WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X \
239 					WLAN_WPA_SEL(WLAN_ASE_8021X_PSK)
240 #define WPA_AUTH_KEY_MGMT_CCKM WLAN_WPA_CCKM_AKM
241 
242 #define WPA_CIPHER_SUITE_NONE   WLAN_WPA_SEL(WLAN_CSE_NONE)
243 #define WPA_CIPHER_SUITE_WEP40  WLAN_WPA_SEL(WLAN_CSE_WEP40)
244 #define WPA_CIPHER_SUITE_WEP104 WLAN_WPA_SEL(WLAN_CSE_WEP104)
245 #define WPA_CIPHER_SUITE_TKIP   WLAN_WPA_SEL(WLAN_CSE_TKIP)
246 #define WPA_CIPHER_SUITE_CCMP   WLAN_WPA_SEL(WLAN_CSE_CCMP)
247 
248 #define RSN_AUTH_KEY_MGMT_NONE          WLAN_RSN_SEL(0)
249 #define RSN_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_RSN_SEL(1)
250 #define RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X\
251 					WLAN_RSN_SEL(2)
252 #define RSN_AUTH_KEY_MGMT_FT_802_1X     WLAN_RSN_SEL(3)
253 #define RSN_AUTH_KEY_MGMT_FT_PSK        WLAN_RSN_SEL(4)
254 #define RSN_AUTH_KEY_MGMT_802_1X_SHA256\
255 					WLAN_RSN_SEL(5)
256 #define RSN_AUTH_KEY_MGMT_PSK_SHA256    WLAN_RSN_SEL(6)
257 #define RSN_AUTH_KEY_MGMT_WPS           WLAN_RSN_SEL(7)
258 #define RSN_AUTH_KEY_MGMT_SAE           WLAN_RSN_SEL(8)
259 #define RSN_AUTH_KEY_MGMT_FT_SAE        WLAN_RSN_SEL(9)
260 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B\
261 					WLAN_RSN_SEL(11)
262 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192\
263 					WLAN_RSN_SEL(12)
264 #define RSN_AUTH_KEY_MGMT_FT_802_1X_SUITE_B_384\
265 					WLAN_RSN_SEL(13)
266 #define RSN_AUTH_KEY_MGMT_FILS_SHA256   WLAN_RSN_SEL(14)
267 #define RSN_AUTH_KEY_MGMT_FILS_SHA384   WLAN_RSN_SEL(15)
268 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA256\
269 					WLAN_RSN_SEL(16)
270 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA384\
271 					WLAN_RSN_SEL(17)
272 #define RSN_AUTH_KEY_MGMT_OWE           WLAN_RSN_SEL(18)
273 #define RSN_AUTH_KEY_MGMT_FT_PSK_SHA384 WLAN_RSN_SEL(19)
274 #define RSN_AUTH_KEY_MGMT_PSK_SHA384    WLAN_RSN_SEL(20)
275 
276 #define RSN_AUTH_KEY_MGMT_CCKM          (WLAN_RSN_CCKM_AKM)
277 #define RSN_AUTH_KEY_MGMT_OSEN          (0x019a6f50)
278 #define RSN_AUTH_KEY_MGMT_DPP           (WLAN_RSN_DPP_AKM)
279 
280 #define RSN_CIPHER_SUITE_NONE           WLAN_RSN_SEL(WLAN_CSE_NONE)
281 #define RSN_CIPHER_SUITE_WEP40          WLAN_RSN_SEL(WLAN_CSE_WEP40)
282 #define RSN_CIPHER_SUITE_TKIP           WLAN_RSN_SEL(WLAN_CSE_TKIP)
283 #define RSN_CIPHER_SUITE_WEP104         WLAN_RSN_SEL(WLAN_CSE_WEP104)
284 #define RSN_CIPHER_SUITE_CCMP           WLAN_RSN_SEL(WLAN_CSE_CCMP)
285 #define RSN_CIPHER_SUITE_AES_CMAC       WLAN_RSN_SEL(WLAN_CSE_AES_CMAC)
286 #define RSN_CIPHER_SUITE_GCMP           WLAN_RSN_SEL(WLAN_CSE_GCMP_128)
287 #define RSN_CIPHER_SUITE_GCMP_256       WLAN_RSN_SEL(WLAN_CSE_GCMP_256)
288 #define RSN_CIPHER_SUITE_CCMP_256       WLAN_RSN_SEL(WLAN_CSE_CCMP_256)
289 #define RSN_CIPHER_SUITE_BIP_GMAC_128   WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_128)
290 #define RSN_CIPHER_SUITE_BIP_GMAC_256   WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_256)
291 #define RSN_CIPHER_SUITE_BIP_CMAC_256   WLAN_RSN_SEL(WLAN_CSE_BIP_CMAC_256)
292 
293 #define RESET_PARAM(__param)         ((__param) = 0)
294 #define SET_PARAM(__param, __val)    ((__param) |= (1 << (__val)))
295 #define HAS_PARAM(__param, __val)    ((__param) &  (1 << (__val)))
296 #define CLEAR_PARAM(__param, __val)  ((__param) &= ((~1) << (__val)))
297 
298 
299 #define RESET_AUTHMODE(_param)       ((_param)->authmodeset = 0)
300 
301 #define SET_AUTHMODE(_param, _mode)  ((_param)->authmodeset |= (1 << (_mode)))
302 #define HAS_AUTHMODE(_param, _mode)  ((_param)->authmodeset &  (1 << (_mode)))
303 
304 #define AUTH_IS_OPEN(_param)   HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_OPEN)
305 #define AUTH_IS_SHARED_KEY(_param)  \
306 				HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_SHARED)
307 #define AUTH_IS_8021X(_param)  HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_8021X)
308 #define AUTH_IS_WPA(_param)    HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WPA)
309 #define AUTH_IS_RSNA(_param)   HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_RSNA)
310 #define AUTH_IS_CCKM(_param)   HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_CCKM)
311 #define AUTH_IS_WAI(_param)    HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WAPI)
312 #define AUTH_IS_WPA2(_param)   AUTH_IS_RSNA(_param)
313 
314 #define AUTH_MATCH(_param1, _param2) \
315 		(((_param1)->authmodeset & (_param2)->authmodeset) != 0)
316 
317 
318 #define RESET_UCAST_CIPHERS(_param)   ((_param)->ucastcipherset = 0)
319 #define SET_UCAST_CIPHER(_param, _c)  ((_param)->ucastcipherset |= (1 << (_c)))
320 #define HAS_UCAST_CIPHER(_param, _c)  ((_param)->ucastcipherset & (1 << (_c)))
321 
322 #define UCIPHER_IS_CLEAR(_param)   \
323 		((_param)->ucastcipherset == 0)
324 #define UCIPHER_IS_WEP(_param)     \
325 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP)
326 #define UCIPHER_IS_TKIP(_param)    \
327 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP)
328 #define UCIPHER_IS_CCMP128(_param) \
329 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM)
330 #define UCIPHER_IS_CCMP256(_param) \
331 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256)
332 #define UCIPHER_IS_GCMP128(_param) \
333 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM)
334 #define UCIPHER_IS_GCMP256(_param) \
335 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256)
336 #define UCIPHER_IS_SMS4(_param)    \
337 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4)
338 
339 #define RESET_MCAST_CIPHERS(_param)   ((_param)->mcastcipherset = 0)
340 #define SET_MCAST_CIPHER(_param, _c)  ((_param)->mcastcipherset |= (1 << (_c)))
341 #define HAS_MCAST_CIPHER(_param, _c)  ((_param)->mcastcipherset & (1 << (_c)))
342 #define HAS_ANY_MCAST_CIPHER(_param)  ((_param)->mcastcipherset)
343 #define CLEAR_MCAST_CIPHER(_param, _c)  \
344 			((_param)->mcastcipherset &= (~(1)<<(_c)))
345 
346 #define MCIPHER_IS_CLEAR(_param)   \
347 		((_param)->mcastcipherset == 0)
348 #define MCIPHER_IS_WEP(_param)     \
349 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP)
350 #define MCIPHER_IS_TKIP(_param)    \
351 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP)
352 #define MCIPHER_IS_CCMP128(_param) \
353 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM)
354 #define MCIPHER_IS_CCMP256(_param) \
355 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256)
356 #define MCIPHER_IS_GCMP128(_param) \
357 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM)
358 #define MCIPHER_IS_GCMP256(_param) \
359 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256)
360 #define MCIPHER_IS_SMS4(_param)    \
361 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4)
362 
363 #define RESET_MGMT_CIPHERS(_param)   ((_param)->mgmtcipherset = 0)
364 #define SET_MGMT_CIPHER(_param, _c)  ((_param)->mgmtcipherset |= (1 << (_c)))
365 #define HAS_MGMT_CIPHER(_param, _c)  ((_param)->mgmtcipherset & (1 << (_c)))
366 #define IS_MGMT_CIPHER(_c)      ((_c == WLAN_CRYPTO_CIPHER_AES_CMAC) || \
367 				 (_c == WLAN_CRYPTO_CIPHER_AES_CMAC_256) || \
368 				 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC) || \
369 				 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC_256))
370 
371 #define IS_FILS_CIPHER(_c)      ((_c) == WLAN_CRYPTO_CIPHER_FILS_AEAD)
372 
373 #define MGMT_CIPHER_IS_CLEAR(_param)   \
374 		((_param)->mgmtcipherset == 0)
375 #define MGMT_CIPHER_IS_CMAC(_param)    \
376 		HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC)
377 #define MGMT_CIPHER_IS_CMAC256(_param) \
378 		HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC_256)
379 #define MGMT_CIPHER_IS_GMAC(_param)    \
380 		HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC)
381 #define MGMT_CIPHER_IS_GMAC256(_param) \
382 		HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC_256)
383 
384 #define RESET_KEY_MGMT(_param)   ((_param)->key_mgmt = 0)
385 #define SET_KEY_MGMT(_param, _c)  ((_param)->key_mgmt |= (1 << (_c)))
386 #define HAS_KEY_MGMT(_param, _c)  ((_param)->key_mgmt & (1 << (_c)))
387 
388 #define UCAST_CIPHER_MATCH(_param1, _param2)    \
389 	(((_param1)->ucastcipherset & (_param2)->ucastcipherset) != 0)
390 
391 #define MCAST_CIPHER_MATCH(_param1, _param2)    \
392 	(((_param1)->mcastcipherset & (_param2)->mcastcipherset) != 0)
393 
394 #define MGMT_CIPHER_MATCH(_param1, _param2)    \
395 	(((_param1)->mgmtcipherset & (_param2)->mgmtcipherset) != 0)
396 
397 #define KEY_MGMTSET_MATCH(_param1, _param2)      \
398 	(((_param1)->key_mgmt & (_param2)->key_mgmt) != 0 ||    \
399 	(!(_param1)->key_mgmt && !(_param2)->key_mgmt))
400 
401 #define RESET_CIPHER_CAP(_param)   ((_param)->cipher_caps = 0)
402 #define SET_CIPHER_CAP(_param, _c)  ((_param)->cipher_caps |= (1 << (_c)))
403 #define HAS_CIPHER_CAP(_param, _c)  ((_param)->cipher_caps & (1 << (_c)))
404 #define HAS_ANY_CIPHER_CAP(_param)  ((_param)->cipher_caps)
405 
406 #define crypto_err(params...) QDF_TRACE_ERROR(QDF_MODULE_ID_CRYPTO, params)
407 #define crypto_info(params...) QDF_TRACE_INFO(QDF_MODULE_ID_CRYPTO, params)
408 #define crypto_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_CRYPTO, params)
409 
410 /**
411  * struct wlan_crypto_mmie - MMIE IE
412  * @element_id:      element id
413  * @length:          length of the ie
414  * @key_id:          igtk key_id used
415  * @sequence_number: igtk PN number
416  * @mic:             MIC for the frame
417  *
418  * This structure represents Management MIC information element (IEEE 802.11w)
419  */
420 struct wlan_crypto_mmie {
421 	uint8_t  element_id;
422 	uint8_t  length;
423 	uint16_t key_id;
424 	uint8_t  sequence_number[6];
425 	uint8_t  mic[16];
426 } __packed;
427 
428 /**
429  * struct crypto_add_key_result - add key result structure
430  * @vdev_id: unique id identifying the VDEV
431  * @key_ix: key index
432  * @key_flags: key flags
433  * @status: status of add key
434  * @peer_macaddr: MAC address of the peer
435  *
436  * Structure used for add key result.
437  */
438 struct crypto_add_key_result {
439 	uint32_t vdev_id;
440 	uint32_t key_ix;
441 	uint32_t key_flags;
442 	uint32_t status;
443 	uint8_t peer_macaddr[QDF_MAC_ADDR_SIZE];
444 };
445 
446 /**
447  * typedef crypto_add_key_callback - add key callback
448  * @context: opaque context that the client can use to associate the
449  *  callback with the request
450  * @result: result of add key
451  */
452 typedef void (*crypto_add_key_callback)(void *context,
453 					struct crypto_add_key_result *result);
454 
455 /**
456  * struct wlan_crypto_comp_priv - crypto component private structure
457  * @crypto_params:    crypto params for the peer
458  * @key:              key buffers for this peer
459  * @igtk_key:         igtk key buffer for this peer
460  * @bigtk_key:        bigtk key buffer for this peer
461  * @igtk_key_type:    igtk key type
462  * @def_tx_keyid:     default key used for this peer
463  * @def_igtk_tx_keyid default igtk key used for this peer
464  * @def_bigtk_tx_keyid default bigtk key used for this peer
465  * @fils_aead_set     fils params for this peer
466  * @add_key_ctx: Opaque context to be used by the caller to associate the
467  *  add key request with the response
468  * @add_key_cb: Callback function to be called with the add key result
469  *
470  */
471 struct wlan_crypto_comp_priv {
472 	struct wlan_crypto_params crypto_params;
473 	struct wlan_crypto_key *key[WLAN_CRYPTO_MAX_VLANKEYIX];
474 	struct wlan_crypto_key *igtk_key[WLAN_CRYPTO_MAXIGTKKEYIDX];
475 	struct wlan_crypto_key *bigtk_key[WLAN_CRYPTO_MAXBIGTKKEYIDX];
476 	enum wlan_crypto_cipher_type igtk_key_type;
477 	uint8_t def_tx_keyid;
478 	uint8_t def_igtk_tx_keyid;
479 	uint8_t def_bigtk_tx_keyid;
480 	uint8_t fils_aead_set;
481 	void *add_key_ctx;
482 	crypto_add_key_callback add_key_cb;
483 };
484 
485 /**
486  * struct wlan_crypto_cipher - crypto cipher table
487  * @cipher_name: printable name
488  * @cipher:      cipher type WLAN_CRYPTO_CIPHER_*
489  * @header:      size of privacy header (bytes)
490  * @trailer:     size of privacy trailer (bytes)
491  * @miclen:      size of mic trailer (bytes)
492  * @keylen:      max key length
493  * @setkey:      function pointer for setkey
494  * @encap:       function pointer for encap
495  * @decap:       function pointer for decap
496  * @enmic:       function pointer for enmic
497  * @demic:       function pointer for demic
498  *
499  */
500 struct wlan_crypto_cipher {
501 	const char *cipher_name;
502 	wlan_crypto_cipher_type cipher;
503 	const uint8_t   header;
504 	const uint8_t   trailer;
505 	const uint8_t   miclen;
506 	const uint32_t  keylen;
507 	QDF_STATUS(*setkey)(struct wlan_crypto_key *);
508 	QDF_STATUS(*encap)(struct wlan_crypto_key *,
509 				qdf_nbuf_t, uint8_t,  uint8_t);
510 	QDF_STATUS(*decap)(struct wlan_crypto_key *,
511 				qdf_nbuf_t, uint8_t,  uint8_t);
512 	QDF_STATUS(*enmic)(struct wlan_crypto_key *,
513 				qdf_nbuf_t, uint8_t,  uint8_t);
514 	QDF_STATUS(*demic)(struct wlan_crypto_key *,
515 				qdf_nbuf_t, uint8_t,  uint8_t);
516 };
517 
518 
519 /**
520  * wlan_crypto_is_data_protected - check is frame is protected or not
521  * @data: frame
522  *
523  * This function check is frame is protected or not
524  *
525  * Return: TRUE/FALSE
526  */
527 static inline bool wlan_crypto_is_data_protected(const void *data)
528 {
529 	const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data;
530 	if (hdr->i_fc[1] & WLAN_FC1_ISWEP)
531 		return true;
532 	else
533 		return false;
534 }
535 
536 /**
537  * ieee80211_hdrsize - calculate frame header size
538  * @data: frame
539  *
540  * This function calculate frame header size
541  *
542  * Return: header size of the frame
543  */
544 static inline uint8_t ieee80211_hdrsize(const void *data)
545 {
546 	const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data;
547 	uint8_t size = sizeof(struct wlan_frame_hdr);
548 
549 	if ((hdr->i_fc[1] & WLAN_FC1_DIR_MASK)
550 				== (WLAN_FC1_DSTODS)) {
551 		size += QDF_MAC_ADDR_SIZE;
552 	}
553 
554 	if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0])
555 			== WLAN_FC0_STYPE_QOS_DATA))) {
556 		size += sizeof(uint16_t);
557 		/* Qos frame with Order bit set indicates an HTC frame */
558 		if (hdr->i_fc[1] & WLAN_FC1_ORDER)
559 			size += (sizeof(uint8_t)*4);
560 	}
561 	if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0])
562 			== WLAN_FC0_STYPE_ACTION))) {
563 		/* Action frame with Order bit set indicates an HTC frame */
564 		if (hdr->i_fc[1] & WLAN_FC1_ORDER)
565 			size += (sizeof(uint8_t)*4);
566 	}
567 	return size;
568 }
569 
570 /**
571  * ieee80211_hdrspace - calculate frame header size with padding
572  * @pdev: pdev
573  * @data: frame header
574  *
575  * This function returns the space occupied by the 802.11 header
576  * and any padding required by the driver. This works for a management
577  * or data frame.
578  *
579  * Return: header size of the frame with padding
580  */
581 static inline uint8_t
582 ieee80211_hdrspace(struct wlan_objmgr_pdev *pdev, const void *data)
583 {
584 	uint8_t size = ieee80211_hdrsize(data);
585 
586 	if (wlan_pdev_nif_feat_cap_get(pdev, WLAN_PDEV_F_DATAPAD))
587 		size = roundup(size, sizeof(u_int32_t));
588 
589 	return size;
590 }
591 
592 /**
593  * wlan_get_tid - get tid of the frame
594  * @data: frame
595  *
596  * This function get tid of the frame
597  *
598  * Return: tid of the frame
599  */
600 static inline int wlan_get_tid(const void *data)
601 {
602 	const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data;
603 
604 	if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0])
605 				== WLAN_FC0_STYPE_QOS_DATA))) {
606 		if ((hdr->i_fc[1] & WLAN_FC1_DIR_MASK)
607 					== (WLAN_FC1_DSTODS)) {
608 			return ((struct wlan_frame_hdr_qos_addr4 *)data)->i_qos[0]
609 							& WLAN_QOS_TID_MASK;
610 		} else {
611 			return ((struct wlan_frame_hdr_qos *)data)->i_qos[0]
612 							& WLAN_QOS_TID_MASK;
613 		}
614 	} else
615 		return WLAN_NONQOS_SEQ;
616 }
617 #endif /* end of _WLAN_CRYPTO_DEF_I_H_ */
618