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