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_NONE = 15, 106 WLAN_CRYPTO_CIPHER_MAX = WLAN_CRYPTO_CIPHER_NONE, 107 } wlan_crypto_cipher_type; 108 109 /* Auth types */ 110 typedef enum wlan_crypto_auth_mode { 111 WLAN_CRYPTO_AUTH_NONE = 0, 112 WLAN_CRYPTO_AUTH_OPEN = 1, 113 WLAN_CRYPTO_AUTH_SHARED = 2, 114 WLAN_CRYPTO_AUTH_8021X = 3, 115 WLAN_CRYPTO_AUTH_AUTO = 4, 116 WLAN_CRYPTO_AUTH_WPA = 5, 117 WLAN_CRYPTO_AUTH_RSNA = 6, 118 WLAN_CRYPTO_AUTH_CCKM = 7, 119 WLAN_CRYPTO_AUTH_WAPI = 8, 120 } wlan_crypto_auth_mode; 121 122 /* crypto capabilities */ 123 typedef enum wlan_crypto_cap { 124 WLAN_CRYPTO_CAP_PRIVACY = 0, 125 WLAN_CRYPTO_CAP_WPA1 = 1, 126 WLAN_CRYPTO_CAP_WPA2 = 2, 127 WLAN_CRYPTO_CAP_WPA = 3, 128 WLAN_CRYPTO_CAP_AES = 4, 129 WLAN_CRYPTO_CAP_WEP = 5, 130 WLAN_CRYPTO_CAP_CKIP = 6, 131 WLAN_CRYPTO_CAP_TKIP_MIC = 7, 132 WLAN_CRYPTO_CAP_CCM256 = 8, 133 WLAN_CRYPTO_CAP_GCM = 9, 134 WLAN_CRYPTO_CAP_GCM_256 = 10, 135 WLAN_CRYPTO_CAP_WAPI_SMS4 = 11, 136 WLAN_CRYPTO_CAP_WAPI_GCM4 = 12, 137 WLAN_CRYPTO_CAP_KEY_MGMT_OFFLOAD = 13, 138 WLAN_CRYPTO_CAP_PMF_OFFLOAD = 14, 139 WLAN_CRYPTO_CAP_PN_TID_BASED = 15, 140 WLAN_CRYPTO_CAP_FILS_AEAD = 16, 141 } wlan_crypto_cap; 142 143 typedef enum wlan_crypto_rsn_cap { 144 WLAN_CRYPTO_RSN_CAP_PREAUTH = 0x01, 145 WLAN_CRYPTO_RSN_CAP_MFP_ENABLED = 0x80, 146 WLAN_CRYPTO_RSN_CAP_MFP_REQUIRED = 0x40, 147 } wlan_crypto_rsn_cap; 148 149 typedef enum wlan_crypto_key_mgmt { 150 WLAN_CRYPTO_KEY_MGMT_IEEE8021X = 0, 151 WLAN_CRYPTO_KEY_MGMT_PSK = 1, 152 WLAN_CRYPTO_KEY_MGMT_NONE = 2, 153 WLAN_CRYPTO_KEY_MGMT_IEEE8021X_NO_WPA = 3, 154 WLAN_CRYPTO_KEY_MGMT_WPA_NONE = 4, 155 WLAN_CRYPTO_KEY_MGMT_FT_IEEE8021X = 5, 156 WLAN_CRYPTO_KEY_MGMT_FT_PSK = 6, 157 WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SHA256 = 7, 158 WLAN_CRYPTO_KEY_MGMT_PSK_SHA256 = 8, 159 WLAN_CRYPTO_KEY_MGMT_WPS = 9, 160 WLAN_CRYPTO_KEY_MGMT_SAE = 10, 161 WLAN_CRYPTO_KEY_MGMT_FT_SAE = 11, 162 WLAN_CRYPTO_KEY_MGMT_WAPI_PSK = 12, 163 WLAN_CRYPTO_KEY_MGMT_WAPI_CERT = 13, 164 WLAN_CRYPTO_KEY_MGMT_CCKM = 14, 165 WLAN_CRYPTO_KEY_MGMT_OSEN = 15, 166 WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B = 16, 167 WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B_192 = 17, 168 WLAN_CRYPTO_KEY_MGMT_FILS_SHA256 = 18, 169 WLAN_CRYPTO_KEY_MGMT_FILS_SHA384 = 19, 170 WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA256 = 20, 171 WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA384 = 21, 172 WLAN_CRYPTO_KEY_MGMT_OWE = 22, 173 WLAN_CRYPTO_KEY_MGMT_DPP = 23, 174 } wlan_crypto_key_mgmt; 175 176 /** 177 * struct wlan_crypto_params - holds crypto params 178 * @authmodeset: authentication mode 179 * @ucastcipherset: unicast ciphers 180 * @mcastcipherset: multicast cipher 181 * @mgmtcipherset: mgmt cipher 182 * @cipher_caps: cipher capability 183 * @rsn_caps: rsn_capability 184 * @key_mgmt: key mgmt 185 * 186 * This structure holds crypto params for peer or vdev 187 */ 188 struct wlan_crypto_params { 189 uint32_t authmodeset; 190 uint32_t ucastcipherset; 191 uint32_t mcastcipherset; 192 uint32_t mgmtcipherset; 193 uint32_t cipher_caps; 194 uint16_t rsn_caps; 195 uint16_t key_mgmt; 196 }; 197 198 typedef enum wlan_crypto_param_type { 199 WLAN_CRYPTO_PARAM_AUTH_MODE, 200 WLAN_CRYPTO_PARAM_UCAST_CIPHER, 201 WLAN_CRYPTO_PARAM_MCAST_CIPHER, 202 WLAN_CRYPTO_PARAM_MGMT_CIPHER, 203 WLAN_CRYPTO_PARAM_CIPHER_CAP, 204 WLAN_CRYPTO_PARAM_RSN_CAP, 205 WLAN_CRYPTO_PARAM_KEY_MGMT, 206 } wlan_crypto_param_type; 207 208 /** 209 * struct wlan_crypto_key - key structure 210 * @keylen: length of the key 211 * @valid: is key valid or not 212 * @flags: key flags 213 * @keyix: key id 214 * @cipher_table: table which stores cipher related info 215 * @private: private pointer to save cipher context 216 * @keylock: spin lock 217 * @recviv: WAPI key receive sequence counter 218 * @txiv: WAPI key transmit sequence counter 219 * @keytsc: key transmit sequence counter 220 * @keyrsc: key receive sequence counter 221 * @keyrsc_suspect: key receive sequence counter under 222 * suspect when pN jump is detected 223 * @keyglobal: key receive global sequence counter used with suspect 224 * @keyval: key value buffer 225 * 226 * This key structure to key related details. 227 */ 228 struct wlan_crypto_key { 229 uint8_t keylen; 230 bool valid; 231 uint16_t flags; 232 uint16_t keyix; 233 void *cipher_table; 234 void *private; 235 qdf_spinlock_t keylock; 236 uint8_t recviv[WLAN_CRYPTO_WAPI_IV_SIZE]; 237 uint8_t txiv[WLAN_CRYPTO_WAPI_IV_SIZE]; 238 uint64_t keytsc; 239 uint64_t keyrsc[WLAN_CRYPTO_TID_SIZE]; 240 uint64_t keyrsc_suspect[WLAN_CRYPTO_TID_SIZE]; 241 uint64_t keyglobal; 242 uint8_t keyval[WLAN_CRYPTO_KEYBUF_SIZE 243 + WLAN_CRYPTO_MICBUF_SIZE]; 244 #define txmic (keyval + WLAN_CRYPTO_KEYBUF_SIZE \ 245 + WLAN_CRYPTO_TXMIC_OFFSET) 246 #define rxmic (keyval + WLAN_CRYPTO_KEYBUF_SIZE \ 247 + WLAN_CRYPTO_RXMIC_OFFSET) 248 }; 249 250 /** 251 * struct wlan_crypto_req_key - key request structure 252 * @type: key/cipher type 253 * @pad: padding member 254 * @keyix: key index 255 * @keylen: length of the key value 256 * @flags: key flags 257 * @macaddr: macaddr of the key 258 * @keyrsc: key receive sequence counter 259 * @keytsc: key transmit sequence counter 260 * @keydata: key value 261 * @txiv: wapi key tx iv 262 * @rxiv: wapi key rx iv 263 * @filsaad: FILS AEAD data 264 * 265 * Key request structure used for setkey, getkey or delkey 266 */ 267 struct wlan_crypto_req_key { 268 uint8_t type; 269 uint8_t pad; 270 uint16_t keyix; 271 uint8_t keylen; 272 uint16_t flags; 273 uint8_t macaddr[QDF_MAC_ADDR_SIZE]; 274 uint64_t keyrsc; 275 uint64_t keytsc; 276 uint8_t keydata[WLAN_CRYPTO_KEYBUF_SIZE + WLAN_CRYPTO_MICBUF_SIZE]; 277 uint8_t txiv[WLAN_CRYPTO_WAPI_IV_SIZE]; 278 uint8_t recviv[WLAN_CRYPTO_WAPI_IV_SIZE]; 279 struct wlan_crypto_fils_aad_key filsaad; 280 }; 281 282 /** 283 * struct wlan_lmac_if_crypto_tx_ops - structure of crypto function 284 * pointers 285 * @allockey: function pointer to alloc key in hw 286 * @setkey: function pointer to setkey in hw 287 * @delkey: function pointer to delkey in hw 288 * @defaultkey: function pointer to set default key 289 */ 290 291 struct wlan_lmac_if_crypto_tx_ops { 292 QDF_STATUS(*allockey)(struct wlan_objmgr_vdev *vdev, 293 struct wlan_crypto_key *key, 294 uint8_t *macaddr, uint32_t key_type); 295 QDF_STATUS(*setkey)(struct wlan_objmgr_vdev *vdev, 296 struct wlan_crypto_key *key, 297 uint8_t *macaddr, uint32_t key_type); 298 QDF_STATUS(*delkey)(struct wlan_objmgr_vdev *vdev, 299 struct wlan_crypto_key *key, 300 uint8_t *macaddr, uint32_t key_type); 301 QDF_STATUS(*defaultkey)(struct wlan_objmgr_vdev *vdev, 302 uint8_t keyix, uint8_t *macaddr); 303 }; 304 305 306 /** 307 * struct wlan_lmac_if_crypto_rx_ops - structure of crypto rx function 308 * pointers 309 * @encap: function pointer to encap tx frame 310 * @decap: function pointer to decap rx frame in hw 311 * @enmic: function pointer to enmic tx frame 312 * @demic: function pointer to demic rx frame 313 */ 314 315 struct wlan_lmac_if_crypto_rx_ops { 316 QDF_STATUS(*crypto_encap)(struct wlan_objmgr_vdev *vdev, 317 qdf_nbuf_t wbuf, uint8_t *macaddr, 318 uint8_t encapdone); 319 QDF_STATUS(*crypto_decap)(struct wlan_objmgr_vdev *vdev, 320 qdf_nbuf_t wbuf, uint8_t *macaddr, 321 uint8_t tid); 322 QDF_STATUS(*crypto_enmic)(struct wlan_objmgr_vdev *vdev, 323 qdf_nbuf_t wbuf, uint8_t *macaddr, 324 uint8_t encapdone); 325 QDF_STATUS(*crypto_demic)(struct wlan_objmgr_vdev *vdev, 326 qdf_nbuf_t wbuf, uint8_t *macaddr, 327 uint8_t tid, uint8_t keyid); 328 QDF_STATUS(*set_peer_wep_keys)(struct wlan_objmgr_vdev *vdev, 329 struct wlan_objmgr_peer *peer); 330 }; 331 332 #define WLAN_CRYPTO_RX_OPS_ENCAP(crypto_rx_ops) \ 333 (crypto_rx_ops->crypto_encap) 334 #define WLAN_CRYPTO_RX_OPS_DECAP(crypto_rx_ops) \ 335 (crypto_rx_ops->crypto_decap) 336 #define WLAN_CRYPTO_RX_OPS_ENMIC(crypto_rx_ops) \ 337 (crypto_rx_ops->crypto_enmic) 338 #define WLAN_CRYPTO_RX_OPS_DEMIC(crypto_rx_ops) \ 339 (crypto_rx_ops->crypto_demic) 340 #define WLAN_CRYPTO_RX_OPS_SET_PEER_WEP_KEYS(crypto_rx_ops) \ 341 (crypto_rx_ops->set_peer_wep_keys) 342 343 #endif /* end of _WLAN_CRYPTO_GLOBAL_DEF_H_ */ 344