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