xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/crypto/inc/wlan_crypto_global_def.h (revision dd4dc88b837a295134aa9869114a2efee0f4894b)
1 /*
2  * Copyright (c) 2017-2019 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: Public definations  for crypto service
21  */
22 
23 #ifndef _WLAN_CRYPTO_GLOBAL_DEF_H_
24 #define _WLAN_CRYPTO_GLOBAL_DEF_H_
25 
26 #include <wlan_cmn.h>
27 #ifdef WLAN_CRYPTO_SUPPORT_FILS
28 #include "wlan_crypto_fils_def.h"
29 #endif
30 #include <wlan_objmgr_cmn.h>
31 #include <wlan_cmn_ieee80211.h>
32 
33 #define WLAN_CRYPTO_TID_SIZE         (17)
34 #define WLAN_CRYPTO_RSC_SIZE         (16)
35 #define WLAN_CRYPTO_KEYBUF_SIZE      (32)
36 #define WLAN_CRYPTO_MICBUF_SIZE      (16)
37 #define WLAN_CRYPTO_MIC_LEN          (8)
38 #define WLAN_CRYPTO_IV_SIZE          (16)
39 #define WLAN_CRYPTO_MIC256_LEN       (16)
40 #define WLAN_CRYPTO_TXMIC_OFFSET     (0)
41 #define WLAN_CRYPTO_RXMIC_OFFSET     (WLAN_CRYPTO_TXMIC_OFFSET + \
42 					WLAN_CRYPTO_MIC_LEN)
43 #define WLAN_CRYPTO_WAPI_IV_SIZE     (16)
44 #define WLAN_CRYPTO_CRC_LEN          (4)
45 #define WLAN_CRYPTO_IV_LEN           (3)
46 #define WLAN_CRYPTO_KEYID_LEN        (1)
47 #define WLAN_CRYPTO_EXT_IV_LEN       (4)
48 #define WLAN_CRYPTO_EXT_IV_BIT       (0x20)
49 #define WLAN_CRYPTO_KEYIX_NONE       ((uint16_t)-1)
50 #define WLAN_CRYPTO_MAXKEYIDX        (4)
51 #define WLAN_CRYPTO_MAXIGTKKEYIDX    (2)
52 #define WLAN_CRYPTO_MAX_PMKID        (3)
53 
54 /* 40 bit wep key len */
55 #define WLAN_CRYPTO_KEY_WEP40_LEN    (5)
56 /* 104 bit wep key len */
57 #define WLAN_CRYPTO_KEY_WEP104_LEN   (13)
58 /* 128 bit wep key len */
59 #define WLAN_CRYPTO_KEY_WEP128_LEN   (16)
60 
61 #define WLAN_CRYPTO_KEY_TKIP_LEN     (32)
62 #define WLAN_CRYPTO_KEY_CCMP_LEN     (16)
63 #define WLAN_CRYPTO_KEY_CCMP_256_LEN (32)
64 #define WLAN_CRYPTO_KEY_GCMP_LEN     (16)
65 #define WLAN_CRYPTO_KEY_GCMP_256_LEN (32)
66 #define WLAN_CRYPTO_KEY_WAPI_LEN     (32)
67 #define WLAN_CRYPTO_KEY_GMAC_LEN     (16)
68 #define WLAN_CRYPTO_KEY_GMAC_256_LEN (32)
69 #define WLAN_CRYPTO_WPI_SMS4_IVLEN   (16)
70 #define WLAN_CRYPTO_WPI_SMS4_KIDLEN  (1)
71 #define WLAN_CRYPTO_WPI_SMS4_PADLEN  (1)
72 #define WLAN_CRYPTO_WPI_SMS4_MICLEN  (16)
73 
74 /* key used for xmit */
75 #define WLAN_CRYPTO_KEY_XMIT         (0x01)
76 /* key used for recv */
77 #define WLAN_CRYPTO_KEY_RECV         (0x02)
78 /* key used for WPA group operation */
79 #define WLAN_CRYPTO_KEY_GROUP        (0x04)
80 /* key also used for management frames */
81 #define WLAN_CRYPTO_KEY_MFP          (0x08)
82 /* host-based encryption */
83 #define WLAN_CRYPTO_KEY_SWENCRYPT    (0x10)
84 /* host-based enmic */
85 #define WLAN_CRYPTO_KEY_SWENMIC      (0x20)
86 /* do not remove unless OS commands us to do so */
87 #define WLAN_CRYPTO_KEY_PERSISTENT   (0x40)
88 /* per STA default key */
89 #define WLAN_CRYPTO_KEY_DEFAULT      (0x80)
90 /* host-based decryption */
91 #define WLAN_CRYPTO_KEY_SWDECRYPT    (0x100)
92 /* host-based demic */
93 #define WLAN_CRYPTO_KEY_SWDEMIC      (0x200)
94 
95 #define WLAN_CRYPTO_KEY_SWCRYPT      (WLAN_CRYPTO_KEY_SWENCRYPT \
96 						| WLAN_CRYPTO_KEY_SWDECRYPT)
97 
98 #define WLAN_CRYPTO_KEY_SWMIC        (WLAN_CRYPTO_KEY_SWENMIC \
99 						| WLAN_CRYPTO_KEY_SWDEMIC)
100 
101 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
102 #define WLAN_AKM_SUITE_FT_8021X         0x000FAC03
103 #define WLAN_AKM_SUITE_FT_PSK           0x000FAC04
104 #endif
105 
106 /*
107  * Cipher types
108  */
109 typedef enum wlan_crypto_cipher_type {
110 	WLAN_CRYPTO_CIPHER_WEP             = 0,
111 	WLAN_CRYPTO_CIPHER_TKIP            = 1,
112 	WLAN_CRYPTO_CIPHER_AES_OCB         = 2,
113 	WLAN_CRYPTO_CIPHER_AES_CCM         = 3,
114 	WLAN_CRYPTO_CIPHER_WAPI_SMS4       = 4,
115 	WLAN_CRYPTO_CIPHER_CKIP            = 5,
116 	WLAN_CRYPTO_CIPHER_AES_CMAC        = 6,
117 	WLAN_CRYPTO_CIPHER_AES_CCM_256     = 7,
118 	WLAN_CRYPTO_CIPHER_AES_CMAC_256    = 8,
119 	WLAN_CRYPTO_CIPHER_AES_GCM         = 9,
120 	WLAN_CRYPTO_CIPHER_AES_GCM_256     = 10,
121 	WLAN_CRYPTO_CIPHER_AES_GMAC        = 11,
122 	WLAN_CRYPTO_CIPHER_AES_GMAC_256    = 12,
123 	WLAN_CRYPTO_CIPHER_WAPI_GCM4       = 13,
124 	WLAN_CRYPTO_CIPHER_FILS_AEAD       = 14,
125 	WLAN_CRYPTO_CIPHER_WEP_40          = 15,
126 	WLAN_CRYPTO_CIPHER_WEP_104         = 16,
127 	WLAN_CRYPTO_CIPHER_NONE            = 17,
128 	WLAN_CRYPTO_CIPHER_MAX             = (WLAN_CRYPTO_CIPHER_NONE + 1),
129 	WLAN_CRYPTO_CIPHER_INVALID,
130 } wlan_crypto_cipher_type;
131 
132 /* Auth types */
133 typedef enum wlan_crypto_auth_mode {
134 	WLAN_CRYPTO_AUTH_NONE     = 0,
135 	WLAN_CRYPTO_AUTH_OPEN     = 1,
136 	WLAN_CRYPTO_AUTH_SHARED   = 2,
137 	WLAN_CRYPTO_AUTH_8021X    = 3,
138 	WLAN_CRYPTO_AUTH_AUTO     = 4,
139 	WLAN_CRYPTO_AUTH_WPA      = 5,
140 	WLAN_CRYPTO_AUTH_RSNA     = 6,
141 	WLAN_CRYPTO_AUTH_CCKM     = 7,
142 	WLAN_CRYPTO_AUTH_WAPI     = 8,
143 	WLAN_CRYPTO_AUTH_SAE      = 9,
144 	WLAN_CRYPTO_AUTH_FILS_SK  = 10,
145 	/** Keep WLAN_CRYPTO_AUTH_MAX at the end. */
146 	WLAN_CRYPTO_AUTH_MAX      = WLAN_CRYPTO_AUTH_FILS_SK,
147 } wlan_crypto_auth_mode;
148 
149 /* crypto capabilities */
150 typedef enum wlan_crypto_cap {
151 	WLAN_CRYPTO_CAP_PRIVACY          = 0,
152 	WLAN_CRYPTO_CAP_WPA1             = 1,
153 	WLAN_CRYPTO_CAP_WPA2             = 2,
154 	WLAN_CRYPTO_CAP_WPA              = 3,
155 	WLAN_CRYPTO_CAP_AES              = 4,
156 	WLAN_CRYPTO_CAP_WEP              = 5,
157 	WLAN_CRYPTO_CAP_CKIP             = 6,
158 	WLAN_CRYPTO_CAP_TKIP_MIC         = 7,
159 	WLAN_CRYPTO_CAP_CCM256           = 8,
160 	WLAN_CRYPTO_CAP_GCM              = 9,
161 	WLAN_CRYPTO_CAP_GCM_256          = 10,
162 	WLAN_CRYPTO_CAP_WAPI_SMS4        = 11,
163 	WLAN_CRYPTO_CAP_WAPI_GCM4        = 12,
164 	WLAN_CRYPTO_CAP_KEY_MGMT_OFFLOAD = 13,
165 	WLAN_CRYPTO_CAP_PMF_OFFLOAD      = 14,
166 	WLAN_CRYPTO_CAP_PN_TID_BASED     = 15,
167 	WLAN_CRYPTO_CAP_FILS_AEAD        = 16,
168 } wlan_crypto_cap;
169 
170 typedef enum wlan_crypto_rsn_cap {
171 	WLAN_CRYPTO_RSN_CAP_PREAUTH       = 0x01,
172 	WLAN_CRYPTO_RSN_CAP_MFP_ENABLED   = 0x80,
173 	WLAN_CRYPTO_RSN_CAP_MFP_REQUIRED  = 0x40,
174 } wlan_crypto_rsn_cap;
175 
176 typedef enum wlan_crypto_key_mgmt {
177 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X             = 0,
178 	WLAN_CRYPTO_KEY_MGMT_PSK                   = 1,
179 	WLAN_CRYPTO_KEY_MGMT_NONE                  = 2,
180 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X_NO_WPA      = 3,
181 	WLAN_CRYPTO_KEY_MGMT_WPA_NONE              = 4,
182 	WLAN_CRYPTO_KEY_MGMT_FT_IEEE8021X          = 5,
183 	WLAN_CRYPTO_KEY_MGMT_FT_PSK                = 6,
184 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SHA256      = 7,
185 	WLAN_CRYPTO_KEY_MGMT_PSK_SHA256            = 8,
186 	WLAN_CRYPTO_KEY_MGMT_WPS                   = 9,
187 	WLAN_CRYPTO_KEY_MGMT_SAE                   = 10,
188 	WLAN_CRYPTO_KEY_MGMT_FT_SAE                = 11,
189 	WLAN_CRYPTO_KEY_MGMT_WAPI_PSK              = 12,
190 	WLAN_CRYPTO_KEY_MGMT_WAPI_CERT             = 13,
191 	WLAN_CRYPTO_KEY_MGMT_CCKM                  = 14,
192 	WLAN_CRYPTO_KEY_MGMT_OSEN                  = 15,
193 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B     = 16,
194 	WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B_192 = 17,
195 	WLAN_CRYPTO_KEY_MGMT_FILS_SHA256           = 18,
196 	WLAN_CRYPTO_KEY_MGMT_FILS_SHA384           = 19,
197 	WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA256        = 20,
198 	WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA384        = 21,
199 	WLAN_CRYPTO_KEY_MGMT_OWE                   = 22,
200 	WLAN_CRYPTO_KEY_MGMT_DPP                   = 23,
201 	/** Keep WLAN_CRYPTO_KEY_MGMT_MAX at the end. */
202 	WLAN_CRYPTO_KEY_MGMT_MAX                   = WLAN_CRYPTO_KEY_MGMT_DPP,
203 } wlan_crypto_key_mgmt;
204 
205 enum wlan_crypto_key_type {
206 	WLAN_CRYPTO_KEY_TYPE_UNICAST,
207 	WLAN_CRYPTO_KEY_TYPE_GROUP,
208 };
209 
210 #define IS_WEP_CIPHER(_c)      ((_c == WLAN_CRYPTO_CIPHER_WEP) || \
211 				(_c == WLAN_CRYPTO_CIPHER_WEP_40) || \
212 				(_c == WLAN_CRYPTO_CIPHER_WEP_104))
213 /**
214  * struct wlan_crypto_pmksa - structure of crypto to contain pmkid
215  * @bssid: bssid for which pmkid is saved
216  * @pmkid: pmkid info
217  * @pmk: pmk info
218  * @pmk_len: pmk len
219  */
220 
221 struct wlan_crypto_pmksa {
222 	struct qdf_mac_addr bssid;
223 	uint8_t    pmkid[PMKID_LEN];
224 	uint8_t    pmk[MAX_PMK_LEN];
225 	uint8_t    pmk_len;
226 };
227 
228 /**
229  * struct wlan_crypto_params - holds crypto params
230  * @authmodeset:        authentication mode
231  * @ucastcipherset:     unicast ciphers
232  * @mcastcipherset:     multicast cipher
233  * @mgmtcipherset:      mgmt cipher
234  * @cipher_caps:        cipher capability
235  * @key_mgmt:           key mgmt
236  * @pmksa:              pmksa
237  * @rsn_caps:           rsn_capability
238  *
239  * This structure holds crypto params for peer or vdev
240  */
241 struct wlan_crypto_params {
242 	uint32_t authmodeset;
243 	uint32_t ucastcipherset;
244 	uint32_t mcastcipherset;
245 	uint32_t mgmtcipherset;
246 	uint32_t cipher_caps;
247 	uint32_t key_mgmt;
248 	struct   wlan_crypto_pmksa *pmksa[WLAN_CRYPTO_MAX_PMKID];
249 	uint16_t rsn_caps;
250 };
251 
252 typedef enum wlan_crypto_param_type {
253 	WLAN_CRYPTO_PARAM_AUTH_MODE,
254 	WLAN_CRYPTO_PARAM_UCAST_CIPHER,
255 	WLAN_CRYPTO_PARAM_MCAST_CIPHER,
256 	WLAN_CRYPTO_PARAM_MGMT_CIPHER,
257 	WLAN_CRYPTO_PARAM_CIPHER_CAP,
258 	WLAN_CRYPTO_PARAM_RSN_CAP,
259 	WLAN_CRYPTO_PARAM_KEY_MGMT,
260 	WLAN_CRYPTO_PARAM_PMKSA,
261 } wlan_crypto_param_type;
262 
263 /**
264  * struct wlan_crypto_key - key structure
265  * @keylen:         length of the key
266  * @valid:          is key valid or not
267  * @flags:          key flags
268  * @keyix:          key id
269  * @cipher_type:    cipher type being used for this key
270  * @mac_addr:       MAC address of the peer
271  * @cipher_table:   table which stores cipher related info
272  * @private:        private pointer to save cipher context
273  * @keylock:        spin lock
274  * @recviv:         WAPI key receive sequence counter
275  * @txiv:           WAPI key transmit sequence counter
276  * @keytsc:         key transmit sequence counter
277  * @keyrsc:         key receive sequence counter
278  * @keyrsc_suspect: key receive sequence counter under
279  *                  suspect when pN jump is detected
280  * @keyglobal:      key receive global sequence counter used with suspect
281  * @keyval:         key value buffer
282  *
283  * This key structure to key related details.
284  */
285 struct wlan_crypto_key {
286 	uint8_t     keylen;
287 	bool        valid;
288 	uint16_t    flags;
289 	uint16_t    keyix;
290 	enum wlan_crypto_cipher_type cipher_type;
291 	uint8_t     macaddr[QDF_MAC_ADDR_SIZE];
292 	void        *cipher_table;
293 	void        *private;
294 	qdf_spinlock_t	keylock;
295 	uint8_t     recviv[WLAN_CRYPTO_WAPI_IV_SIZE];
296 	uint8_t     txiv[WLAN_CRYPTO_WAPI_IV_SIZE];
297 	uint64_t    keytsc;
298 	uint64_t    keyrsc[WLAN_CRYPTO_TID_SIZE];
299 	uint64_t    keyrsc_suspect[WLAN_CRYPTO_TID_SIZE];
300 	uint64_t    keyglobal;
301 	uint8_t     keyval[WLAN_CRYPTO_KEYBUF_SIZE
302 				+ WLAN_CRYPTO_MICBUF_SIZE];
303 #define txmic    (keyval + WLAN_CRYPTO_KEYBUF_SIZE \
304 				+ WLAN_CRYPTO_TXMIC_OFFSET)
305 #define rxmic    (keyval + WLAN_CRYPTO_KEYBUF_SIZE \
306 				+ WLAN_CRYPTO_RXMIC_OFFSET)
307 };
308 
309 /**
310  * struct wlan_crypto_req_key - key request structure
311  * @type:                       key/cipher type
312  * @pad:                        padding member
313  * @keyix:                      key index
314  * @keylen:                     length of the key value
315  * @flags:                      key flags
316  * @macaddr:                    macaddr of the key
317  * @keyrsc:                     key receive sequence counter
318  * @keytsc:                     key transmit sequence counter
319  * @keydata:                    key value
320  * @txiv:                       wapi key tx iv
321  * @rxiv:                       wapi key rx iv
322  * @filsaad:                    FILS AEAD data
323  *
324  * Key request structure used for setkey, getkey or delkey
325  */
326 struct wlan_crypto_req_key {
327 	uint8_t    type;
328 	uint8_t    pad;
329 	uint16_t   keyix;
330 	uint8_t    keylen;
331 	uint16_t    flags;
332 	uint8_t    macaddr[QDF_MAC_ADDR_SIZE];
333 	uint64_t   keyrsc;
334 	uint64_t   keytsc;
335 	uint8_t    keydata[WLAN_CRYPTO_KEYBUF_SIZE + WLAN_CRYPTO_MICBUF_SIZE];
336 	uint8_t    txiv[WLAN_CRYPTO_WAPI_IV_SIZE];
337 	uint8_t    recviv[WLAN_CRYPTO_WAPI_IV_SIZE];
338 #ifdef WLAN_CRYPTO_SUPPORT_FILS
339 	struct     wlan_crypto_fils_aad_key   filsaad;
340 #endif
341 };
342 
343 /**
344  * struct wlan_lmac_if_crypto_tx_ops - structure of crypto function
345  *                  pointers
346  * @allockey: function pointer to alloc key in hw
347  * @setkey:  function pointer to setkey in hw
348  * @delkey: function pointer to delkey in hw
349  * @defaultkey: function pointer to set default key
350  * @set_key: converged function pointer to set key in hw
351  */
352 
353 struct wlan_lmac_if_crypto_tx_ops {
354 	QDF_STATUS (*allockey)(struct wlan_objmgr_vdev *vdev,
355 			       struct wlan_crypto_key *key,
356 			       uint8_t *macaddr, uint32_t key_type);
357 	QDF_STATUS (*setkey)(struct wlan_objmgr_vdev *vdev,
358 			     struct wlan_crypto_key *key,
359 			     uint8_t *macaddr, uint32_t key_type);
360 	QDF_STATUS (*delkey)(struct wlan_objmgr_vdev *vdev,
361 			     struct wlan_crypto_key *key,
362 			     uint8_t *macaddr, uint32_t key_type);
363 	QDF_STATUS (*defaultkey)(struct wlan_objmgr_vdev *vdev,
364 				 uint8_t keyix, uint8_t *macaddr);
365 	QDF_STATUS (*set_key)(struct wlan_objmgr_vdev *vdev,
366 			      struct wlan_crypto_key *key,
367 			      enum wlan_crypto_key_type key_type);
368 };
369 
370 /**
371  * struct wlan_lmac_if_crypto_rx_ops - structure of crypto rx  function
372  *                  pointers
373  * @encap: function pointer to encap tx frame
374  * @decap:  function pointer to decap rx frame in hw
375  * @enmic: function pointer to enmic tx frame
376  * @demic: function pointer to demic rx frame
377  */
378 
379 struct wlan_lmac_if_crypto_rx_ops {
380 	QDF_STATUS(*crypto_encap)(struct wlan_objmgr_vdev *vdev,
381 					qdf_nbuf_t wbuf, uint8_t *macaddr,
382 					uint8_t encapdone);
383 	QDF_STATUS(*crypto_decap)(struct wlan_objmgr_vdev *vdev,
384 					qdf_nbuf_t wbuf, uint8_t *macaddr,
385 					uint8_t tid);
386 	QDF_STATUS(*crypto_enmic)(struct wlan_objmgr_vdev *vdev,
387 					qdf_nbuf_t wbuf, uint8_t *macaddr,
388 					uint8_t encapdone);
389 	QDF_STATUS(*crypto_demic)(struct wlan_objmgr_vdev *vdev,
390 					qdf_nbuf_t wbuf, uint8_t *macaddr,
391 					uint8_t tid, uint8_t keyid);
392 	QDF_STATUS(*set_peer_wep_keys)(struct wlan_objmgr_vdev *vdev,
393 					struct wlan_objmgr_peer *peer);
394 };
395 
396 #define WLAN_CRYPTO_RX_OPS_ENCAP(crypto_rx_ops) \
397 				(crypto_rx_ops->crypto_encap)
398 #define WLAN_CRYPTO_RX_OPS_DECAP(crypto_rx_ops) \
399 				(crypto_rx_ops->crypto_decap)
400 #define WLAN_CRYPTO_RX_OPS_ENMIC(crypto_rx_ops) \
401 				(crypto_rx_ops->crypto_enmic)
402 #define WLAN_CRYPTO_RX_OPS_DEMIC(crypto_rx_ops) \
403 				(crypto_rx_ops->crypto_demic)
404 #define WLAN_CRYPTO_RX_OPS_SET_PEER_WEP_KEYS(crypto_rx_ops) \
405 				(crypto_rx_ops->set_peer_wep_keys)
406 
407 #endif /* end of _WLAN_CRYPTO_GLOBAL_DEF_H_ */
408