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