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