xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/crypto/inc/wlan_crypto_global_def.h (revision dd5f5c1afa4ab969b68717be955752f19527fb17)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 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: Public definitions  for crypto service
22  */
23 
24 #ifndef _WLAN_CRYPTO_GLOBAL_DEF_H_
25 #define _WLAN_CRYPTO_GLOBAL_DEF_H_
26 
27 #include <wlan_cmn.h>
28 #ifdef WLAN_CRYPTO_SUPPORT_FILS
29 #include "wlan_crypto_fils_def.h"
30 #endif
31 #include <wlan_objmgr_cmn.h>
32 #include <wlan_cmn_ieee80211.h>
33 
34 #define WLAN_CRYPTO_TID_SIZE         (17)
35 #define WLAN_CRYPTO_RSC_SIZE         (16)
36 #define WLAN_CRYPTO_KEYBUF_SIZE      (32)
37 #define WLAN_CRYPTO_MICBUF_SIZE      (16)
38 #define WLAN_CRYPTO_MIC_LEN          (8)
39 #define WLAN_CRYPTO_IV_SIZE          (16)
40 #define WLAN_CRYPTO_MIC256_LEN       (16)
41 #define WLAN_CRYPTO_TXMIC_OFFSET     (0)
42 #define WLAN_CRYPTO_RXMIC_OFFSET     (WLAN_CRYPTO_TXMIC_OFFSET + \
43 					WLAN_CRYPTO_MIC_LEN)
44 #define WLAN_CRYPTO_WAPI_IV_SIZE     (16)
45 #define WLAN_CRYPTO_CRC_LEN          (4)
46 #define WLAN_CRYPTO_IV_LEN           (3)
47 #define WLAN_CRYPTO_KEYID_LEN        (1)
48 #define WLAN_CRYPTO_EXT_IV_LEN       (4)
49 #define WLAN_CRYPTO_EXT_IV_BIT       (0x20)
50 #define WLAN_CRYPTO_KEYIX_NONE       ((uint16_t)-1)
51 #define WLAN_CRYPTO_MAXKEYIDX        (4)
52 #define WLAN_CRYPTO_MAXIGTKKEYIDX    (2)
53 #define WLAN_CRYPTO_MAXBIGTKKEYIDX   (2)
54 #ifndef WLAN_CRYPTO_MAX_VLANKEYIX
55 #define WLAN_CRYPTO_MAX_VLANKEYIX    WLAN_CRYPTO_MAXKEYIDX
56 #endif
57 #define WLAN_CRYPTO_MAX_PMKID        (16)
58 
59 /* 40 bit wep key len */
60 #define WLAN_CRYPTO_KEY_WEP40_LEN    (5)
61 /* 104 bit wep key len */
62 #define WLAN_CRYPTO_KEY_WEP104_LEN   (13)
63 /* 128 bit wep key len */
64 #define WLAN_CRYPTO_KEY_WEP128_LEN   (16)
65 
66 #define WLAN_CRYPTO_KEY_TKIP_LEN     (32)
67 #define WLAN_CRYPTO_KEY_CCMP_LEN     (16)
68 #define WLAN_CRYPTO_KEY_CCMP_256_LEN (32)
69 #define WLAN_CRYPTO_KEY_GCMP_LEN     (16)
70 #define WLAN_CRYPTO_KEY_GCMP_256_LEN (32)
71 #define WLAN_CRYPTO_KEY_WAPI_LEN     (32)
72 #define WLAN_CRYPTO_KEY_GMAC_LEN     (16)
73 #define WLAN_CRYPTO_KEY_GMAC_256_LEN (32)
74 #define WLAN_CRYPTO_WPI_SMS4_IVLEN   (16)
75 #define WLAN_CRYPTO_WPI_SMS4_KIDLEN  (1)
76 #define WLAN_CRYPTO_WPI_SMS4_PADLEN  (1)
77 #define WLAN_CRYPTO_WPI_SMS4_MICLEN  (16)
78 
79 /* FILS definitions */
80 #define WLAN_CRYPTO_FILS_OPTIONAL_DATA_LEN 3
81 #define WLAN_CRYPTO_FILS_RIK_LABEL "Re-authentication Integrity Key@ietf.org"
82 
83 /* key used for xmit */
84 #define WLAN_CRYPTO_KEY_XMIT         (0x01)
85 /* key used for recv */
86 #define WLAN_CRYPTO_KEY_RECV         (0x02)
87 /* key used for WPA group operation */
88 #define WLAN_CRYPTO_KEY_GROUP        (0x04)
89 /* key also used for management frames */
90 #define WLAN_CRYPTO_KEY_MFP          (0x08)
91 /* host-based encryption */
92 #define WLAN_CRYPTO_KEY_SWENCRYPT    (0x10)
93 /* host-based enmic */
94 #define WLAN_CRYPTO_KEY_SWENMIC      (0x20)
95 /* do not remove unless OS commands us to do so */
96 #define WLAN_CRYPTO_KEY_PERSISTENT   (0x40)
97 /* per STA default key */
98 #define WLAN_CRYPTO_KEY_DEFAULT      (0x80)
99 /* host-based decryption */
100 #define WLAN_CRYPTO_KEY_SWDECRYPT    (0x100)
101 /* host-based demic */
102 #define WLAN_CRYPTO_KEY_SWDEMIC      (0x200)
103 /* get pn from fw for key */
104 #define WLAN_CRYPTO_KEY_GET_PN       (0x400)
105 
106 #define WLAN_CRYPTO_KEY_SWCRYPT      (WLAN_CRYPTO_KEY_SWENCRYPT \
107 						| WLAN_CRYPTO_KEY_SWDECRYPT)
108 
109 #define WLAN_CRYPTO_KEY_SWMIC        (WLAN_CRYPTO_KEY_SWENMIC \
110 						| WLAN_CRYPTO_KEY_SWDEMIC)
111 
112 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
113 #define WLAN_AKM_SUITE_FT_8021X         0x000FAC03
114 #define WLAN_AKM_SUITE_FT_PSK           0x000FAC04
115 #endif
116 
117 /* Maximum lifetime for a PMKID entry - 12 Hrs */
118 #define WLAN_CRYPTO_MAX_PMKID_LIFETIME 43200
119 #define WLAN_CRYPTO_MAX_PMKID_LIFETIME_THRESHOLD 100
120 
121 /*
122  * Cipher types
123  */
124 typedef enum wlan_crypto_cipher_type {
125 	WLAN_CRYPTO_CIPHER_WEP             = 0,
126 	WLAN_CRYPTO_CIPHER_TKIP            = 1,
127 	WLAN_CRYPTO_CIPHER_AES_OCB         = 2,
128 	WLAN_CRYPTO_CIPHER_AES_CCM         = 3,
129 	WLAN_CRYPTO_CIPHER_WAPI_SMS4       = 4,
130 	WLAN_CRYPTO_CIPHER_CKIP            = 5,
131 	WLAN_CRYPTO_CIPHER_AES_CMAC        = 6,
132 	WLAN_CRYPTO_CIPHER_AES_CCM_256     = 7,
133 	WLAN_CRYPTO_CIPHER_AES_CMAC_256    = 8,
134 	WLAN_CRYPTO_CIPHER_AES_GCM         = 9,
135 	WLAN_CRYPTO_CIPHER_AES_GCM_256     = 10,
136 	WLAN_CRYPTO_CIPHER_AES_GMAC        = 11,
137 	WLAN_CRYPTO_CIPHER_AES_GMAC_256    = 12,
138 	WLAN_CRYPTO_CIPHER_WAPI_GCM4       = 13,
139 	WLAN_CRYPTO_CIPHER_FILS_AEAD       = 14,
140 	WLAN_CRYPTO_CIPHER_WEP_40          = 15,
141 	WLAN_CRYPTO_CIPHER_WEP_104         = 16,
142 	WLAN_CRYPTO_CIPHER_NONE            = 17,
143 	WLAN_CRYPTO_CIPHER_MAX             = (WLAN_CRYPTO_CIPHER_NONE + 1),
144 	WLAN_CRYPTO_CIPHER_INVALID,
145 } wlan_crypto_cipher_type;
146 
147 /* Auth types */
148 typedef enum wlan_crypto_auth_mode {
149 	WLAN_CRYPTO_AUTH_NONE     = 0,
150 	WLAN_CRYPTO_AUTH_OPEN     = 1,
151 	WLAN_CRYPTO_AUTH_SHARED   = 2,
152 	WLAN_CRYPTO_AUTH_8021X    = 3,
153 	WLAN_CRYPTO_AUTH_AUTO     = 4,
154 	WLAN_CRYPTO_AUTH_WPA      = 5,
155 	WLAN_CRYPTO_AUTH_RSNA     = 6,
156 	WLAN_CRYPTO_AUTH_CCKM     = 7,
157 	WLAN_CRYPTO_AUTH_WAPI     = 8,
158 	WLAN_CRYPTO_AUTH_SAE      = 9,
159 	WLAN_CRYPTO_AUTH_FILS_SK  = 10,
160 	/** Keep WLAN_CRYPTO_AUTH_MAX at the end. */
161 	WLAN_CRYPTO_AUTH_MAX,
162 } wlan_crypto_auth_mode;
163 
164 /* crypto capabilities */
165 typedef enum wlan_crypto_cap {
166 	WLAN_CRYPTO_CAP_PRIVACY          = 0,
167 	WLAN_CRYPTO_CAP_WPA1             = 1,
168 	WLAN_CRYPTO_CAP_WPA2             = 2,
169 	WLAN_CRYPTO_CAP_WPA              = 3,
170 	WLAN_CRYPTO_CAP_AES              = 4,
171 	WLAN_CRYPTO_CAP_WEP              = 5,
172 	WLAN_CRYPTO_CAP_CKIP             = 6,
173 	WLAN_CRYPTO_CAP_TKIP_MIC         = 7,
174 	WLAN_CRYPTO_CAP_CCM256           = 8,
175 	WLAN_CRYPTO_CAP_GCM              = 9,
176 	WLAN_CRYPTO_CAP_GCM_256          = 10,
177 	WLAN_CRYPTO_CAP_WAPI_SMS4        = 11,
178 	WLAN_CRYPTO_CAP_WAPI_GCM4        = 12,
179 	WLAN_CRYPTO_CAP_KEY_MGMT_OFFLOAD = 13,
180 	WLAN_CRYPTO_CAP_PMF_OFFLOAD      = 14,
181 	WLAN_CRYPTO_CAP_PN_TID_BASED     = 15,
182 	WLAN_CRYPTO_CAP_FILS_AEAD        = 16,
183 } wlan_crypto_cap;
184 
185 typedef enum wlan_crypto_rsn_cap {
186 	WLAN_CRYPTO_RSN_CAP_PREAUTH       = 0x01,
187 	WLAN_CRYPTO_RSN_CAP_MFP_ENABLED   = 0x80,
188 	WLAN_CRYPTO_RSN_CAP_MFP_REQUIRED  = 0x40,
189 	WLAN_CRYPTO_RSN_CAP_OCV_SUPPORTED  = 0x4000,
190 } wlan_crypto_rsn_cap;
191 
192 /**
193  * enum wlan_crypto_rsnx_cap - RSNXE capabilities
194  * @WLAN_CRYPTO_RSNX_CAP_PROTECTED_TWT: Protected TWT
195  * @WLAN_CRYPTO_RSNX_CAP_SAE_H2E: SAE Hash to Element
196  * @WLAN_CRYPTO_RSNX_CAP_SAE_PK: SAE PK
197  * @WLAN_CRYPTO_RSNX_CAP_SECURE_LTF: Secure LTF
198  * @WLAN_CRYPTO_RSNX_CAP_SECURE_RTT: Secure RTT
199  * @WLAN_CRYPTO_RSNX_CAP_URNM_MFPR: Unassociated Range
200  * Negotiation and Measurement MFP Required
201  *
202  * Definition: (IEEE Std 802.11-2020, 9.4.2.241, Table 9-780)
203  * The Extended RSN Capabilities field, except its first 4 bits, is a
204  * bit field indicating the extended RSN capabilities being advertised
205  * by the STA transmitting the element. The length of the Extended
206  * RSN Capabilities field is a variable n, in octets, as indicated by
207  * the first 4 bits in the field.
208  */
209 enum wlan_crypto_rsnx_cap {
210 	WLAN_CRYPTO_RSNX_CAP_PROTECTED_TWT = 0x10,
211 	WLAN_CRYPTO_RSNX_CAP_SAE_H2E = 0x20,
212 	WLAN_CRYPTO_RSNX_CAP_SAE_PK = 0x40,
213 	WLAN_CRYPTO_RSNX_CAP_SECURE_LTF = 0x100,
214 	WLAN_CRYPTO_RSNX_CAP_SECURE_RTT = 0x200,
215 	WLAN_CRYPTO_RSNX_CAP_URNM_MFPR = 0x8000,
216 };
217 
218 /**
219  * enum wlan_crypto_vdev_pasn_caps  - PASN peer related vdev
220  * crypto parameters
221  * @WLAN_CRYPTO_URNM_MFPR: URNM MFP required in RSNXE
222  * @WLAN_CRYPTO_MFPC: MFP capable bit from RSN IE
223  * @WLAN_CRYPTO_MFPR: MFP required from RSNIE
224  */
225 enum wlan_crypto_vdev_pasn_caps {
226 	WLAN_CRYPTO_URNM_MFPR = BIT(0),
227 	WLAN_CRYPTO_MFPC = BIT(1),
228 	WLAN_CRYPTO_MFPR = BIT(2),
229 };
230 
231 typedef enum wlan_crypto_key_mgmt {
232 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X             = 0,
233 	WLAN_CRYPTO_KEY_MGMT_PSK                   = 1,
234 	WLAN_CRYPTO_KEY_MGMT_NONE                  = 2,
235 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X_NO_WPA      = 3,
236 	WLAN_CRYPTO_KEY_MGMT_WPA_NONE              = 4,
237 	WLAN_CRYPTO_KEY_MGMT_FT_IEEE8021X          = 5,
238 	WLAN_CRYPTO_KEY_MGMT_FT_PSK                = 6,
239 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SHA256      = 7,
240 	WLAN_CRYPTO_KEY_MGMT_PSK_SHA256            = 8,
241 	WLAN_CRYPTO_KEY_MGMT_WPS                   = 9,
242 	WLAN_CRYPTO_KEY_MGMT_SAE                   = 10,
243 	WLAN_CRYPTO_KEY_MGMT_FT_SAE                = 11,
244 	WLAN_CRYPTO_KEY_MGMT_WAPI_PSK              = 12,
245 	WLAN_CRYPTO_KEY_MGMT_WAPI_CERT             = 13,
246 	WLAN_CRYPTO_KEY_MGMT_CCKM                  = 14,
247 	WLAN_CRYPTO_KEY_MGMT_OSEN                  = 15,
248 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B     = 16,
249 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B_192 = 17,
250 	WLAN_CRYPTO_KEY_MGMT_FILS_SHA256           = 18,
251 	WLAN_CRYPTO_KEY_MGMT_FILS_SHA384           = 19,
252 	WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA256        = 20,
253 	WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA384        = 21,
254 	WLAN_CRYPTO_KEY_MGMT_OWE                   = 22,
255 	WLAN_CRYPTO_KEY_MGMT_DPP                   = 23,
256 	WLAN_CRYPTO_KEY_MGMT_FT_IEEE8021X_SHA384   = 24,
257 	WLAN_CRYPTO_KEY_MGMT_FT_PSK_SHA384         = 25,
258 	WLAN_CRYPTO_KEY_MGMT_PSK_SHA384            = 26,
259 	WLAN_CRYPTO_KEY_MGMT_SAE_EXT_KEY           = 27,
260 	WLAN_CRYPTO_KEY_MGMT_FT_SAE_EXT_KEY        = 28,
261 	/** Keep WLAN_CRYPTO_KEY_MGMT_MAX at the end. */
262 	WLAN_CRYPTO_KEY_MGMT_MAX,
263 } wlan_crypto_key_mgmt;
264 
265 enum wlan_crypto_key_type {
266 	WLAN_CRYPTO_KEY_TYPE_UNICAST,
267 	WLAN_CRYPTO_KEY_TYPE_GROUP,
268 };
269 
270 #define IS_WEP_CIPHER(_c)      ((_c == WLAN_CRYPTO_CIPHER_WEP) || \
271 				(_c == WLAN_CRYPTO_CIPHER_WEP_40) || \
272 				(_c == WLAN_CRYPTO_CIPHER_WEP_104))
273 
274 #define DEFAULT_KEYMGMT_6G_MASK 0xFFFFFFFF
275 
276 /* AKM wlan_crypto_key_mgmt 1, 6, 8, 25 and 26 are not allowed. */
277 #define ALLOWED_KEYMGMT_6G_MASK 0x19FFFEBD
278 
279 /*
280  * enum fils_erp_cryptosuite: this enum defines the cryptosuites used
281  * to calculate auth tag and auth tag length as defined by RFC 6696 5.3.1
282  * @HMAC_SHA256_64: sha256 with auth tag len as 64 bits
283  * @HMAC_SHA256_128: sha256 with auth tag len as 128 bits
284  * @HMAC_SHA256_256: sha256 with auth tag len as 256 bits
285  */
286 enum fils_erp_cryptosuite {
287 	INVALID_CRYPTO = 0, /* reserved */
288 	HMAC_SHA256_64,
289 	HMAC_SHA256_128,
290 	HMAC_SHA256_256,
291 };
292 
293 /**
294  * struct mobility_domain_params - structure containing
295  *				   mobility domain info
296  * @mdie_present: mobility domain present or not
297  * @mobility_domain: mobility domain
298  */
299 struct mobility_domain_params {
300 	uint8_t mdie_present;
301 	uint16_t mobility_domain;
302 };
303 
304 /**
305  * struct wlan_crypto_pmksa - structure of crypto to contain pmkid
306  * @bssid: bssid for which pmkid is saved
307  * @pmkid: pmkid info
308  * @pmk: pmk info
309  * @pmk_len: pmk len
310  * @ssid_len: ssid length
311  * @ssid: ssid information
312  * @cache_id: cache id
313  * @pmk_lifetime: Duration in seconds for which the pmk is valid
314  * @pmk_lifetime_threshold: Percentage of pmk lifetime within which
315  * full authentication is expected to avoid disconnection.
316  * @pmk_entry_ts: System timestamp at which the PMK entry was created.
317  * @single_pmk_supported: SAE single pmk supported BSS
318  * @mdid: structure to contain mobility domain parameters
319  */
320 struct wlan_crypto_pmksa {
321 	struct qdf_mac_addr bssid;
322 	uint8_t    pmkid[PMKID_LEN];
323 	uint8_t    pmk[MAX_PMK_LEN];
324 	uint8_t    pmk_len;
325 	uint8_t    ssid_len;
326 	uint8_t    ssid[WLAN_SSID_MAX_LEN];
327 	uint8_t    cache_id[WLAN_CACHE_ID_LEN];
328 	uint32_t   pmk_lifetime;
329 	uint8_t    pmk_lifetime_threshold;
330 	qdf_time_t pmk_entry_ts;
331 #if defined(WLAN_SAE_SINGLE_PMK) && defined(WLAN_FEATURE_ROAM_OFFLOAD)
332 	bool       single_pmk_supported;
333 #endif
334 	struct mobility_domain_params mdid;
335 };
336 
337 #ifdef WLAN_ADAPTIVE_11R
338 /**
339  * struct key_mgmt_list - structure to store AKM(s) present in RSN IE of
340  * Beacon/Probe response
341  * @key_mgmt: AKM(s) present in RSN IE of Beacon/Probe response
342  */
343 struct key_mgmt_list {
344 	uint32_t key_mgmt;
345 };
346 #endif
347 
348 /**
349  * struct wlan_crypto_params - holds crypto params
350  * @authmodeset:        authentication mode
351  * @ucastcipherset:     unicast ciphers
352  * @mcastcipherset:     multicast cipher
353  * @mgmtcipherset:      mgmt cipher
354  * @cipher_caps:        cipher capability
355  * @key_mgmt:           key mgmt
356  * @pmksa:              pmksa
357  * @rsn_caps:           rsn_capability
358  * @akm_list:           order of AKM present in RSN IE of Beacon/Probe response
359  *
360  * This structure holds crypto params for peer or vdev
361  */
362 struct wlan_crypto_params {
363 	uint32_t authmodeset;
364 	uint32_t ucastcipherset;
365 	uint32_t mcastcipherset;
366 	uint32_t mgmtcipherset;
367 	uint32_t cipher_caps;
368 	uint32_t key_mgmt;
369 	struct   wlan_crypto_pmksa *pmksa[WLAN_CRYPTO_MAX_PMKID];
370 	uint16_t rsn_caps;
371 #ifdef WLAN_ADAPTIVE_11R
372 	struct key_mgmt_list akm_list[WLAN_CRYPTO_KEY_MGMT_MAX];
373 #endif
374 };
375 
376 /**
377  * struct wlan_crypto_ltf_keyseed_data - LTF keyseed parameters
378  * @vdev_id: Vdev id
379  * @peer_mac_addr: Peer mac address
380  * @src_mac_addr: Source mac address
381  * @rsn_authmode: Cipher suite
382  * @key_seed: Secure LTF key seed
383  * @key_seed_len: Key seed length
384  */
385 struct wlan_crypto_ltf_keyseed_data {
386 	uint8_t vdev_id;
387 	struct qdf_mac_addr peer_mac_addr;
388 	struct qdf_mac_addr src_mac_addr;
389 	uint8_t rsn_authmode;
390 	uint8_t key_seed[WLAN_MAX_SECURE_LTF_KEYSEED_LEN];
391 	uint16_t key_seed_len;
392 };
393 
394 typedef enum wlan_crypto_param_type {
395 	WLAN_CRYPTO_PARAM_AUTH_MODE,
396 	WLAN_CRYPTO_PARAM_UCAST_CIPHER,
397 	WLAN_CRYPTO_PARAM_MCAST_CIPHER,
398 	WLAN_CRYPTO_PARAM_MGMT_CIPHER,
399 	WLAN_CRYPTO_PARAM_CIPHER_CAP,
400 	WLAN_CRYPTO_PARAM_RSN_CAP,
401 	WLAN_CRYPTO_PARAM_KEY_MGMT,
402 	WLAN_CRYPTO_PARAM_PMKSA,
403 } wlan_crypto_param_type;
404 
405 /**
406  * struct wlan_crypto_key - key structure
407  * @keylen:         length of the key
408  * @valid:          is key valid or not
409  * @flags:          key flags
410  * @keyix:          key id
411  * @cipher_type:    cipher type being used for this key
412  * @key_type:       unicast or broadcast key
413  * @macaddr:        MAC address of the peer
414  * @src_addr:       Source mac address associated with the key
415  * @cipher_table:   table which stores cipher related info
416  * @private:        private pointer to save cipher context
417  * @keylock:        spin lock
418  * @recviv:         WAPI key receive sequence counter
419  * @txiv:           WAPI key transmit sequence counter
420  * @keytsc:         key transmit sequence counter
421  * @keyrsc:         key receive sequence counter
422  * @keyrsc_suspect: key receive sequence counter under
423  *                  suspect when pN jump is detected
424  * @keyglobal:      key receive global sequence counter used with suspect
425  * @keyval:         key value buffer
426  *
427  * This key structure to key related details.
428  */
429 struct wlan_crypto_key {
430 	uint8_t     keylen;
431 	bool        valid;
432 	uint16_t    flags;
433 	uint16_t    keyix;
434 	enum wlan_crypto_cipher_type cipher_type;
435 	enum wlan_crypto_key_type key_type;
436 	uint8_t     macaddr[QDF_MAC_ADDR_SIZE];
437 	struct qdf_mac_addr src_addr;
438 	void        *cipher_table;
439 	void        *private;
440 	qdf_spinlock_t	keylock;
441 	uint8_t     recviv[WLAN_CRYPTO_WAPI_IV_SIZE];
442 	uint8_t     txiv[WLAN_CRYPTO_WAPI_IV_SIZE];
443 	uint64_t    keytsc;
444 	uint64_t    keyrsc[WLAN_CRYPTO_TID_SIZE];
445 	uint64_t    keyrsc_suspect[WLAN_CRYPTO_TID_SIZE];
446 	uint64_t    keyglobal;
447 	uint8_t     keyval[WLAN_CRYPTO_KEYBUF_SIZE
448 				+ WLAN_CRYPTO_MICBUF_SIZE];
449 #define txmic    (keyval + WLAN_CRYPTO_KEYBUF_SIZE \
450 				+ WLAN_CRYPTO_TXMIC_OFFSET)
451 #define rxmic    (keyval + WLAN_CRYPTO_KEYBUF_SIZE \
452 				+ WLAN_CRYPTO_RXMIC_OFFSET)
453 };
454 
455 /**
456  * struct wlan_crypto_req_key - key request structure
457  * @type:                       key/cipher type
458  * @pad:                        padding member
459  * @keyix:                      key index
460  * @keylen:                     length of the key value
461  * @flags:                      key flags
462  * @macaddr:                    macaddr of the key
463  * @keyrsc:                     key receive sequence counter
464  * @keytsc:                     key transmit sequence counter
465  * @keydata:                    key value
466  * @txiv:                       wapi key tx iv
467  * @recviv:                     wapi key rx iv
468  * @filsaad:                    FILS AEAD data
469  *
470  * Key request structure used for setkey, getkey or delkey
471  */
472 struct wlan_crypto_req_key {
473 	uint8_t    type;
474 	uint8_t    pad;
475 	uint16_t   keyix;
476 	uint8_t    keylen;
477 	uint16_t    flags;
478 	uint8_t    macaddr[QDF_MAC_ADDR_SIZE];
479 	uint64_t   keyrsc;
480 	uint64_t   keytsc;
481 	uint8_t    keydata[WLAN_CRYPTO_KEYBUF_SIZE + WLAN_CRYPTO_MICBUF_SIZE];
482 	uint8_t    txiv[WLAN_CRYPTO_WAPI_IV_SIZE];
483 	uint8_t    recviv[WLAN_CRYPTO_WAPI_IV_SIZE];
484 #ifdef WLAN_CRYPTO_SUPPORT_FILS
485 	struct     wlan_crypto_fils_aad_key   filsaad;
486 #endif
487 };
488 
489 /**
490  * struct wlan_lmac_if_crypto_tx_ops - structure of crypto function
491  *                  pointers
492  * @allockey: function pointer to alloc key in hw
493  * @setkey:  function pointer to setkey in hw
494  * @delkey: function pointer to delkey in hw
495  * @defaultkey: function pointer to set default key
496  * @set_key: converged function pointer to set key in hw
497  * @getpn: function pointer to get current pn value of peer
498  * @set_ltf_keyseed: Set LTF keyseed
499  * @set_vdev_param: Set the vdev crypto parameter
500  * @register_events: function pointer to register wmi event handler
501  * @deregister_events: function pointer to deregister wmi event handler
502  */
503 struct wlan_lmac_if_crypto_tx_ops {
504 	QDF_STATUS (*allockey)(struct wlan_objmgr_vdev *vdev,
505 			       struct wlan_crypto_key *key,
506 			       uint8_t *macaddr, uint32_t key_type);
507 	QDF_STATUS (*setkey)(struct wlan_objmgr_vdev *vdev,
508 			     struct wlan_crypto_key *key,
509 			     uint8_t *macaddr, uint32_t key_type);
510 	QDF_STATUS (*delkey)(struct wlan_objmgr_vdev *vdev,
511 			     struct wlan_crypto_key *key,
512 			     uint8_t *macaddr, uint32_t key_type);
513 	QDF_STATUS (*defaultkey)(struct wlan_objmgr_vdev *vdev,
514 				 uint8_t keyix, uint8_t *macaddr);
515 	QDF_STATUS (*set_key)(struct wlan_objmgr_vdev *vdev,
516 			      struct wlan_crypto_key *key,
517 			      enum wlan_crypto_key_type key_type);
518 	QDF_STATUS(*getpn)(struct wlan_objmgr_vdev *vdev,
519 			   uint8_t *macaddr, uint8_t keyix, uint32_t key_type);
520 	QDF_STATUS (*set_ltf_keyseed)(struct wlan_objmgr_psoc *psoc,
521 				      struct wlan_crypto_ltf_keyseed_data *ks);
522 	QDF_STATUS (*set_vdev_param)(struct wlan_objmgr_psoc *psoc,
523 				     uint32_t vdev_id, uint32_t param_id,
524 				     uint32_t param_value);
525 	QDF_STATUS (*register_events)(struct wlan_objmgr_psoc *psoc);
526 	QDF_STATUS (*deregister_events)(struct wlan_objmgr_psoc *psoc);
527 };
528 
529 /**
530  * struct wlan_lmac_if_crypto_rx_ops - structure of crypto rx  function
531  *                  pointers
532  * @crypto_encap: function pointer to encap tx frame
533  * @crypto_decap:  function pointer to decap rx frame in hw
534  * @crypto_enmic: function pointer to enmic tx frame
535  * @crypto_demic: function pointer to demic rx frame
536  * @set_peer_wep_keys: function pointer to set WEP keys
537  * @get_rxpn: function pointer to get current Rx pn value of peer
538  */
539 
540 struct wlan_lmac_if_crypto_rx_ops {
541 	QDF_STATUS(*crypto_encap)(struct wlan_objmgr_vdev *vdev,
542 					qdf_nbuf_t wbuf, uint8_t *macaddr,
543 					uint8_t encapdone);
544 	QDF_STATUS(*crypto_decap)(struct wlan_objmgr_vdev *vdev,
545 					qdf_nbuf_t wbuf, uint8_t *macaddr,
546 					uint8_t tid);
547 	QDF_STATUS(*crypto_enmic)(struct wlan_objmgr_vdev *vdev,
548 					qdf_nbuf_t wbuf, uint8_t *macaddr,
549 					uint8_t encapdone);
550 	QDF_STATUS(*crypto_demic)(struct wlan_objmgr_vdev *vdev,
551 					qdf_nbuf_t wbuf, uint8_t *macaddr,
552 					uint8_t tid, uint8_t keyid);
553 	QDF_STATUS(*set_peer_wep_keys)(struct wlan_objmgr_vdev *vdev,
554 					struct wlan_objmgr_peer *peer);
555 	QDF_STATUS (*get_rxpn)(struct wlan_objmgr_vdev *vdev,
556 			       uint8_t *macaddr, uint16_t keyix);
557 };
558 
559 #define WLAN_CRYPTO_RX_OPS_ENCAP(crypto_rx_ops) \
560 				(crypto_rx_ops->crypto_encap)
561 #define WLAN_CRYPTO_RX_OPS_DECAP(crypto_rx_ops) \
562 				(crypto_rx_ops->crypto_decap)
563 #define WLAN_CRYPTO_RX_OPS_ENMIC(crypto_rx_ops) \
564 				(crypto_rx_ops->crypto_enmic)
565 #define WLAN_CRYPTO_RX_OPS_DEMIC(crypto_rx_ops) \
566 				(crypto_rx_ops->crypto_demic)
567 #define WLAN_CRYPTO_RX_OPS_SET_PEER_WEP_KEYS(crypto_rx_ops) \
568 				(crypto_rx_ops->set_peer_wep_keys)
569 #define WLAN_CRYPTO_RX_OPS_GET_RXPN(crypto_rx_ops) \
570 				((crypto_rx_ops)->get_rxpn)
571 
572 #define WLAN_CRYPTO_IS_WPA_WPA2(akm) \
573 	(QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_IEEE8021X) || \
574 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_PSK) || \
575 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_FT_IEEE8021X) || \
576 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_FT_PSK) || \
577 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SHA256) || \
578 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_PSK_SHA256) || \
579 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_WPS) || \
580 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_WAPI_PSK) || \
581 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_WAPI_CERT) || \
582 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_CCKM) || \
583 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_OSEN) || \
584 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B) || \
585 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_FILS_SHA256) || \
586 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_FILS_SHA384) || \
587 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA256) || \
588 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA384) || \
589 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_FT_PSK_SHA384) || \
590 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_PSK_SHA384))
591 
592 #define WLAN_CRYPTO_IS_WPA3(akm) \
593 	(QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_SAE) || \
594 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_FT_SAE) || \
595 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B_192) || \
596 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_OWE) || \
597 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_DPP) || \
598 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_FT_IEEE8021X_SHA384) || \
599 	 QDF_HAS_PARAM(akm, WLAN_CRYPTO_KEY_MGMT_SAE_EXT_KEY))
600 
601 #endif /* end of _WLAN_CRYPTO_GLOBAL_DEF_H_ */
602