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