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