xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/crypto/src/wlan_crypto_def_i.h (revision 97f44cd39e4ff816eaa1710279d28cf6b9e65ad9)
1 /*
2  * Copyright (c) 2017-2020 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 
177 /* unalligned little endian access */
178 #ifndef LE_READ_2
179 #define LE_READ_2(p) \
180 	((uint16_t)                          \
181 	((((const uint8_t *)(p))[0]) |       \
182 	(((const uint8_t *)(p))[1] <<  8)))
183 #endif
184 
185 #ifndef LE_READ_4
186 #define LE_READ_4(p)                   \
187 	((uint32_t)                          \
188 	((((const uint8_t *)(p))[0]) |       \
189 	(((const uint8_t *)(p))[1] <<  8) |  \
190 	(((const uint8_t *)(p))[2] << 16) |  \
191 	(((const uint8_t *)(p))[3] << 24)))
192 #endif
193 
194 #ifndef BE_READ_4
195 #define BE_READ_4(p)                        \
196 	((uint32_t)                              \
197 	((((const uint8_t *)(p))[0] << 24) |     \
198 	(((const uint8_t *)(p))[1] << 16) |      \
199 	(((const uint8_t *)(p))[2] <<  8) |      \
200 	(((const uint8_t *)(p))[3])))
201 #endif
202 
203 #ifndef READ_6
204 #define READ_6(b0, b1, b2, b3, b4, b5)  ({ \
205 	uint32_t iv32 = (b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24);\
206 	uint16_t iv16 = (b4 << 0) | (b5 << 8);\
207 	(((uint64_t)iv16) << 32) | iv32;\
208 })
209 #endif
210 
211 #define OUI_SIZE   (4)
212 #define WLAN_CRYPTO_ADDSHORT(frm, v)  \
213 	do {frm[0] = (v) & 0xff; frm[1] = (v) >> 8; frm += 2; } while (0)
214 
215 #define	WLAN_CRYPTO_ADDSELECTOR(frm, sel) \
216 	do { \
217 		uint32_t value = sel;\
218 		qdf_mem_copy(frm, (uint8_t *)&value, OUI_SIZE); \
219 	frm += OUI_SIZE; } while (0)
220 
221 #define WLAN_CRYPTO_SELECTOR(a, b, c, d) \
222 	((((uint32_t) (a)) << 24) | \
223 	 (((uint32_t) (b)) << 16) | \
224 	 (((uint32_t) (c)) << 8) | \
225 		(uint32_t) (d))
226 
227 #define WPA_TYPE_OUI                    WLAN_WPA_SEL(WLAN_WPA_OUI_TYPE)
228 
229 #define WLAN_CRYPTO_WAPI_IE_LEN      20
230 #define WLAN_CRYPTO_WAPI_SMS4_CIPHER 0x01
231 
232 #define WPA_AUTH_KEY_MGMT_NONE          WLAN_WPA_SEL(WLAN_ASE_NONE)
233 #define WPA_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_WPA_SEL(WLAN_ASE_8021X_UNSPEC)
234 #define WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X \
235 					WLAN_WPA_SEL(WLAN_ASE_8021X_PSK)
236 #define WPA_AUTH_KEY_MGMT_CCKM WLAN_WPA_CCKM_AKM
237 
238 #define WPA_CIPHER_SUITE_NONE   WLAN_WPA_SEL(WLAN_CSE_NONE)
239 #define WPA_CIPHER_SUITE_WEP40  WLAN_WPA_SEL(WLAN_CSE_WEP40)
240 #define WPA_CIPHER_SUITE_WEP104 WLAN_WPA_SEL(WLAN_CSE_WEP104)
241 #define WPA_CIPHER_SUITE_TKIP   WLAN_WPA_SEL(WLAN_CSE_TKIP)
242 #define WPA_CIPHER_SUITE_CCMP   WLAN_WPA_SEL(WLAN_CSE_CCMP)
243 
244 #define RSN_AUTH_KEY_MGMT_NONE          WLAN_RSN_SEL(0)
245 #define RSN_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_RSN_SEL(1)
246 #define RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X\
247 					WLAN_RSN_SEL(2)
248 #define RSN_AUTH_KEY_MGMT_FT_802_1X     WLAN_RSN_SEL(3)
249 #define RSN_AUTH_KEY_MGMT_FT_PSK        WLAN_RSN_SEL(4)
250 #define RSN_AUTH_KEY_MGMT_802_1X_SHA256\
251 					WLAN_RSN_SEL(5)
252 #define RSN_AUTH_KEY_MGMT_PSK_SHA256    WLAN_RSN_SEL(6)
253 #define RSN_AUTH_KEY_MGMT_WPS           WLAN_RSN_SEL(7)
254 #define RSN_AUTH_KEY_MGMT_SAE           WLAN_RSN_SEL(8)
255 #define RSN_AUTH_KEY_MGMT_FT_SAE        WLAN_RSN_SEL(9)
256 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B\
257 					WLAN_RSN_SEL(11)
258 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192\
259 					WLAN_RSN_SEL(12)
260 #define RSN_AUTH_KEY_MGMT_FT_802_1X_SUITE_B_384\
261 					WLAN_RSN_SEL(13)
262 #define RSN_AUTH_KEY_MGMT_FILS_SHA256   WLAN_RSN_SEL(14)
263 #define RSN_AUTH_KEY_MGMT_FILS_SHA384   WLAN_RSN_SEL(15)
264 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA256\
265 					WLAN_RSN_SEL(16)
266 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA384\
267 					WLAN_RSN_SEL(17)
268 #define RSN_AUTH_KEY_MGMT_OWE           WLAN_RSN_SEL(18)
269 
270 #define RSN_AUTH_KEY_MGMT_CCKM          (WLAN_RSN_CCKM_AKM)
271 #define RSN_AUTH_KEY_MGMT_OSEN          (0x019a6f50)
272 #define RSN_AUTH_KEY_MGMT_DPP           (WLAN_RSN_DPP_AKM)
273 
274 #define RSN_CIPHER_SUITE_NONE           WLAN_RSN_SEL(WLAN_CSE_NONE)
275 #define RSN_CIPHER_SUITE_WEP40          WLAN_RSN_SEL(WLAN_CSE_WEP40)
276 #define RSN_CIPHER_SUITE_TKIP           WLAN_RSN_SEL(WLAN_CSE_TKIP)
277 #define RSN_CIPHER_SUITE_WEP104         WLAN_RSN_SEL(WLAN_CSE_WEP104)
278 #define RSN_CIPHER_SUITE_CCMP           WLAN_RSN_SEL(WLAN_CSE_CCMP)
279 #define RSN_CIPHER_SUITE_AES_CMAC       WLAN_RSN_SEL(WLAN_CSE_AES_CMAC)
280 #define RSN_CIPHER_SUITE_GCMP           WLAN_RSN_SEL(WLAN_CSE_GCMP_128)
281 #define RSN_CIPHER_SUITE_GCMP_256       WLAN_RSN_SEL(WLAN_CSE_GCMP_256)
282 #define RSN_CIPHER_SUITE_CCMP_256       WLAN_RSN_SEL(WLAN_CSE_CCMP_256)
283 #define RSN_CIPHER_SUITE_BIP_GMAC_128   WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_128)
284 #define RSN_CIPHER_SUITE_BIP_GMAC_256   WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_256)
285 #define RSN_CIPHER_SUITE_BIP_CMAC_256   WLAN_RSN_SEL(WLAN_CSE_BIP_CMAC_256)
286 
287 #define RESET_PARAM(__param)         ((__param) = 0)
288 #define SET_PARAM(__param, __val)    ((__param) |= (1 << (__val)))
289 #define HAS_PARAM(__param, __val)    ((__param) &  (1 << (__val)))
290 #define CLEAR_PARAM(__param, __val)  ((__param) &= ((~1) << (__val)))
291 
292 
293 #define RESET_AUTHMODE(_param)       ((_param)->authmodeset = 0)
294 
295 #define SET_AUTHMODE(_param, _mode)  ((_param)->authmodeset |= (1 << (_mode)))
296 #define HAS_AUTHMODE(_param, _mode)  ((_param)->authmodeset &  (1 << (_mode)))
297 
298 #define AUTH_IS_OPEN(_param)   HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_OPEN)
299 #define AUTH_IS_SHARED_KEY(_param)  \
300 				HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_SHARED)
301 #define AUTH_IS_8021X(_param)  HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_8021X)
302 #define AUTH_IS_WPA(_param)    HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WPA)
303 #define AUTH_IS_RSNA(_param)   HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_RSNA)
304 #define AUTH_IS_CCKM(_param)   HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_CCKM)
305 #define AUTH_IS_WAI(_param)    HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WAPI)
306 #define AUTH_IS_WPA2(_param)   AUTH_IS_RSNA(_param)
307 
308 #define AUTH_MATCH(_param1, _param2) \
309 		(((_param1)->authmodeset & (_param2)->authmodeset) != 0)
310 
311 
312 #define RESET_UCAST_CIPHERS(_param)   ((_param)->ucastcipherset = 0)
313 #define SET_UCAST_CIPHER(_param, _c)  ((_param)->ucastcipherset |= (1 << (_c)))
314 #define HAS_UCAST_CIPHER(_param, _c)  ((_param)->ucastcipherset & (1 << (_c)))
315 
316 #define UCIPHER_IS_CLEAR(_param)   \
317 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_NONE)
318 #define UCIPHER_IS_WEP(_param)     \
319 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP)
320 #define UCIPHER_IS_TKIP(_param)    \
321 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP)
322 #define UCIPHER_IS_CCMP128(_param) \
323 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM)
324 #define UCIPHER_IS_CCMP256(_param) \
325 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256)
326 #define UCIPHER_IS_GCMP128(_param) \
327 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM)
328 #define UCIPHER_IS_GCMP256(_param) \
329 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256)
330 #define UCIPHER_IS_SMS4(_param)    \
331 		HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4)
332 
333 #define RESET_MCAST_CIPHERS(_param)   ((_param)->mcastcipherset = 0)
334 #define SET_MCAST_CIPHER(_param, _c)  ((_param)->mcastcipherset |= (1 << (_c)))
335 #define HAS_MCAST_CIPHER(_param, _c)  ((_param)->mcastcipherset & (1 << (_c)))
336 #define HAS_ANY_MCAST_CIPHER(_param)  ((_param)->mcastcipherset)
337 #define CLEAR_MCAST_CIPHER(_param, _c)  \
338 			((_param)->mcastcipherset &= (~(1)<<(_c)))
339 
340 #define MCIPHER_IS_CLEAR(_param)   \
341 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_NONE)
342 #define MCIPHER_IS_WEP(_param)     \
343 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP)
344 #define MCIPHER_IS_TKIP(_param)    \
345 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP)
346 #define MCIPHER_IS_CCMP128(_param) \
347 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM)
348 #define MCIPHER_IS_CCMP256(_param) \
349 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256)
350 #define MCIPHER_IS_GCMP128(_param) \
351 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM)
352 #define MCIPHER_IS_GCMP256(_param) \
353 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256)
354 #define MCIPHER_IS_SMS4(_param)    \
355 		HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4)
356 
357 #define RESET_MGMT_CIPHERS(_param)   ((_param)->mgmtcipherset = \
358 					(1 << WLAN_CRYPTO_CIPHER_NONE))
359 #define SET_MGMT_CIPHER(_param, _c)  ((_param)->mgmtcipherset |= (1 << (_c)))
360 #define HAS_MGMT_CIPHER(_param, _c)  ((_param)->mgmtcipherset & (1 << (_c)))
361 #define IS_MGMT_CIPHER(_c)      ((_c == WLAN_CRYPTO_CIPHER_AES_CMAC) || \
362 				 (_c == WLAN_CRYPTO_CIPHER_AES_CMAC_256) || \
363 				 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC) || \
364 				 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC_256))
365 
366 #define IS_FILS_CIPHER(_c)      ((_c) == WLAN_CRYPTO_CIPHER_FILS_AEAD)
367 
368 #define MGMT_CIPHER_IS_CMAC(_param)    \
369 		HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC)
370 #define MGMT_CIPHER_IS_CMAC256(_param) \
371 		HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC_256)
372 #define MGMT_CIPHER_IS_GMAC(_param)    \
373 		HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC)
374 #define MGMT_CIPHER_IS_GMAC256(_param) \
375 		HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC_256)
376 
377 #define RESET_KEY_MGMT(_param)   ((_param)->key_mgmt = \
378 					(1 << WLAN_CRYPTO_KEY_MGMT_NONE))
379 #define SET_KEY_MGMT(_param, _c)  ((_param)->key_mgmt |= (1 << (_c)))
380 #define HAS_KEY_MGMT(_param, _c)  ((_param)->key_mgmt & (1 << (_c)))
381 
382 #define UCAST_CIPHER_MATCH(_param1, _param2)    \
383 	(((_param1)->ucastcipherset & (_param2)->ucastcipherset) != 0)
384 
385 #define MCAST_CIPHER_MATCH(_param1, _param2)    \
386 	(((_param1)->mcastcipherset & (_param2)->mcastcipherset) != 0)
387 
388 #define MGMT_CIPHER_MATCH(_param1, _param2)    \
389 	(((_param1)->mgmtcipherset & (_param2)->mgmtcipherset) != 0)
390 
391 #define KEY_MGMTSET_MATCH(_param1, _param2)      \
392 	(((_param1)->key_mgmt & (_param2)->key_mgmt) != 0 ||    \
393 	(!(_param1)->key_mgmt && !(_param2)->key_mgmt))
394 
395 #define RESET_CIPHER_CAP(_param)   ((_param)->cipher_caps = 0)
396 #define SET_CIPHER_CAP(_param, _c)  ((_param)->cipher_caps |= (1 << (_c)))
397 #define HAS_CIPHER_CAP(_param, _c)  ((_param)->cipher_caps & (1 << (_c)))
398 #define HAS_ANY_CIPHER_CAP(_param)  ((_param)->cipher_caps)
399 
400 #define crypto_err(params...) QDF_TRACE_ERROR(QDF_MODULE_ID_CRYPTO, params)
401 #define crypto_info(params...) QDF_TRACE_INFO(QDF_MODULE_ID_CRYPTO, params)
402 #define crypto_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_CRYPTO, params)
403 
404 /**
405  * struct wlan_crypto_mmie - MMIE IE
406  * @element_id:      element id
407  * @length:          length of the ie
408  * @key_id:          igtk key_id used
409  * @sequence_number: igtk PN number
410  * @mic:             MIC for the frame
411  *
412  * This structure represents Management MIC information element (IEEE 802.11w)
413  */
414 struct wlan_crypto_mmie {
415 	uint8_t  element_id;
416 	uint8_t  length;
417 	uint16_t key_id;
418 	uint8_t  sequence_number[6];
419 	uint8_t  mic[16];
420 } __packed;
421 
422 /**
423  * struct wlan_crypto_comp_priv - crypto component private structure
424  * @crypto_params:    crypto params for the peer
425  * @key:              key buffers for this peer
426  * @igtk_key:         igtk key buffer for this peer
427  * @bigtk_key:        bigtk key buffer for this peer
428  * @igtk_key_type:    igtk key type
429  * @def_tx_keyid:     default key used for this peer
430  * @def_igtk_tx_keyid default igtk key used for this peer
431  * @def_bigtk_tx_keyid default bigtk key used for this peer
432  * @fils_aead_set     fils params for this peer
433  *
434  */
435 struct wlan_crypto_comp_priv {
436 	struct wlan_crypto_params crypto_params;
437 	struct wlan_crypto_key *key[WLAN_CRYPTO_MAX_VLANKEYIX];
438 	struct wlan_crypto_key *igtk_key[WLAN_CRYPTO_MAXIGTKKEYIDX];
439 	struct wlan_crypto_key *bigtk_key[WLAN_CRYPTO_MAXBIGTKKEYIDX];
440 	enum wlan_crypto_cipher_type igtk_key_type;
441 	uint8_t def_tx_keyid;
442 	uint8_t def_igtk_tx_keyid;
443 	uint8_t def_bigtk_tx_keyid;
444 	uint8_t fils_aead_set;
445 };
446 
447 /**
448  * struct wlan_crypto_cipher - crypto cipher table
449  * @cipher_name: printable name
450  * @cipher:      cipher type WLAN_CRYPTO_CIPHER_*
451  * @header:      size of privacy header (bytes)
452  * @trailer:     size of privacy trailer (bytes)
453  * @miclen:      size of mic trailer (bytes)
454  * @keylen:      max key length
455  * @setkey:      function pointer for setkey
456  * @encap:       function pointer for encap
457  * @decap:       function pointer for decap
458  * @enmic:       function pointer for enmic
459  * @demic:       function pointer for demic
460  *
461  */
462 struct wlan_crypto_cipher {
463 	const char *cipher_name;
464 	wlan_crypto_cipher_type cipher;
465 	const uint8_t   header;
466 	const uint8_t   trailer;
467 	const uint8_t   miclen;
468 	const uint32_t  keylen;
469 	QDF_STATUS(*setkey)(struct wlan_crypto_key *);
470 	QDF_STATUS(*encap)(struct wlan_crypto_key *,
471 				qdf_nbuf_t, uint8_t,  uint8_t);
472 	QDF_STATUS(*decap)(struct wlan_crypto_key *,
473 				qdf_nbuf_t, uint8_t,  uint8_t);
474 	QDF_STATUS(*enmic)(struct wlan_crypto_key *,
475 				qdf_nbuf_t, uint8_t,  uint8_t);
476 	QDF_STATUS(*demic)(struct wlan_crypto_key *,
477 				qdf_nbuf_t, uint8_t,  uint8_t);
478 };
479 
480 
481 /**
482  * wlan_crypto_is_data_protected - check is frame is protected or not
483  * @data: frame
484  *
485  * This function check is frame is protected or not
486  *
487  * Return: TRUE/FALSE
488  */
489 static inline bool wlan_crypto_is_data_protected(const void *data)
490 {
491 	const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data;
492 	if (hdr->i_fc[1] & WLAN_FC1_ISWEP)
493 		return true;
494 	else
495 		return false;
496 }
497 
498 /**
499  * ieee80211_hdrsize - calculate frame header size
500  * @data: frame
501  *
502  * This function calculate frame header size
503  *
504  * Return: header size of the frame
505  */
506 static inline uint8_t ieee80211_hdrsize(const void *data)
507 {
508 	const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data;
509 	uint8_t size = sizeof(struct wlan_frame_hdr);
510 
511 	if ((hdr->i_fc[1] & WLAN_FC1_DIR_MASK)
512 				== (WLAN_FC1_DSTODS)) {
513 		size += QDF_MAC_ADDR_SIZE;
514 	}
515 
516 	if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0])
517 			== WLAN_FC0_STYPE_QOS_DATA))) {
518 		size += sizeof(uint16_t);
519 		/* Qos frame with Order bit set indicates an HTC frame */
520 		if (hdr->i_fc[1] & WLAN_FC1_ORDER)
521 			size += (sizeof(uint8_t)*4);
522 	}
523 	if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0])
524 			== WLAN_FC0_STYPE_ACTION))) {
525 		/* Action frame with Order bit set indicates an HTC frame */
526 		if (hdr->i_fc[1] & WLAN_FC1_ORDER)
527 			size += (sizeof(uint8_t)*4);
528 	}
529 	return size;
530 }
531 
532 /**
533  * ieee80211_hdrspace - calculate frame header size with padding
534  * @pdev: pdev
535  * @data: frame header
536  *
537  * This function returns the space occupied by the 802.11 header
538  * and any padding required by the driver. This works for a management
539  * or data frame.
540  *
541  * Return: header size of the frame with padding
542  */
543 static inline uint8_t
544 ieee80211_hdrspace(struct wlan_objmgr_pdev *pdev, const void *data)
545 {
546 	uint8_t size = ieee80211_hdrsize(data);
547 
548 	if (wlan_pdev_nif_feat_cap_get(pdev, WLAN_PDEV_F_DATAPAD))
549 		size = roundup(size, sizeof(u_int32_t));
550 
551 	return size;
552 }
553 
554 /**
555  * wlan_get_tid - get tid of the frame
556  * @data: frame
557  *
558  * This function get tid of the frame
559  *
560  * Return: tid of the frame
561  */
562 static inline int wlan_get_tid(const void *data)
563 {
564 	const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data;
565 
566 	if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0])
567 				== WLAN_FC0_STYPE_QOS_DATA))) {
568 		if ((hdr->i_fc[1] & WLAN_FC1_DIR_MASK)
569 					== (WLAN_FC1_DSTODS)) {
570 			return ((struct wlan_frame_hdr_qos_addr4 *)data)->i_qos[0]
571 							& WLAN_QOS_TID_MASK;
572 		} else {
573 			return ((struct wlan_frame_hdr_qos *)data)->i_qos[0]
574 							& WLAN_QOS_TID_MASK;
575 		}
576 	} else
577 		return WLAN_NONQOS_SEQ;
578 }
579 #endif /* end of _WLAN_CRYPTO_DEF_I_H_ */
580