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