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; 169 170 /** 171 * struct wlan_crypto_params - holds crypto params 172 * @authmodeset: authentication mode 173 * @ucastcipherset: unicast ciphers 174 * @mcastcipherset: multicast cipher 175 * @mgmtcipherset: mgmt cipher 176 * @cipher_caps: cipher capability 177 * @rsn_caps: rsn_capability 178 * @key_mgmt: key mgmt 179 * 180 * This structure holds crypto params for peer or vdev 181 */ 182 struct wlan_crypto_params { 183 uint32_t authmodeset; 184 uint32_t ucastcipherset; 185 uint32_t mcastcipherset; 186 uint32_t mgmtcipherset; 187 uint32_t cipher_caps; 188 uint16_t rsn_caps; 189 uint16_t key_mgmt; 190 }; 191 192 typedef enum wlan_crypto_param_type { 193 WLAN_CRYPTO_PARAM_AUTH_MODE, 194 WLAN_CRYPTO_PARAM_UCAST_CIPHER, 195 WLAN_CRYPTO_PARAM_MCAST_CIPHER, 196 WLAN_CRYPTO_PARAM_MGMT_CIPHER, 197 WLAN_CRYPTO_PARAM_CIPHER_CAP, 198 WLAN_CRYPTO_PARAM_RSN_CAP, 199 WLAN_CRYPTO_PARAM_KEY_MGMT, 200 } wlan_crypto_param_type; 201 202 /** 203 * struct wlan_crypto_key - key structure 204 * @keylen: length of the key 205 * @valid: is key valid or not 206 * @flags: key flags 207 * @keyix: key id 208 * @cipher_table: table which stores cipher related info 209 * @private: private pointer to save cipher context 210 * @keylock: spin lock 211 * @recviv: WAPI key receive sequence counter 212 * @txiv: WAPI key transmit sequence counter 213 * @keytsc: key transmit sequence counter 214 * @keyrsc: key receive sequence counter 215 * @keyrsc_suspect: key receive sequence counter under 216 * suspect when pN jump is detected 217 * @keyglobal: key receive global sequence counter used with suspect 218 * @keyval: key value buffer 219 * 220 * This key structure to key related details. 221 */ 222 struct wlan_crypto_key { 223 uint8_t keylen; 224 bool valid; 225 uint16_t flags; 226 uint16_t keyix; 227 void *cipher_table; 228 void *private; 229 qdf_spinlock_t keylock; 230 uint8_t recviv[WLAN_CRYPTO_WAPI_IV_SIZE]; 231 uint8_t txiv[WLAN_CRYPTO_WAPI_IV_SIZE]; 232 uint64_t keytsc; 233 uint64_t keyrsc[WLAN_CRYPTO_TID_SIZE]; 234 uint64_t keyrsc_suspect[WLAN_CRYPTO_TID_SIZE]; 235 uint64_t keyglobal; 236 uint8_t keyval[WLAN_CRYPTO_KEYBUF_SIZE 237 + WLAN_CRYPTO_MICBUF_SIZE]; 238 #define txmic (keyval + WLAN_CRYPTO_KEYBUF_SIZE \ 239 + WLAN_CRYPTO_TXMIC_OFFSET) 240 #define rxmic (keyval + WLAN_CRYPTO_KEYBUF_SIZE \ 241 + WLAN_CRYPTO_RXMIC_OFFSET) 242 }; 243 244 /** 245 * struct wlan_crypto_req_key - key request structure 246 * @type: key/cipher type 247 * @pad: padding member 248 * @keyix: key index 249 * @keylen: length of the key value 250 * @flags: key flags 251 * @macaddr: macaddr of the key 252 * @keyrsc: key receive sequence counter 253 * @keytsc: key transmit sequence counter 254 * @keydata: key value 255 * @txiv: wapi key tx iv 256 * @rxiv: wapi key rx iv 257 * @filsaad: FILS AEAD data 258 * 259 * Key request structure used for setkey, getkey or delkey 260 */ 261 struct wlan_crypto_req_key { 262 uint8_t type; 263 uint8_t pad; 264 uint16_t keyix; 265 uint8_t keylen; 266 uint16_t flags; 267 uint8_t macaddr[QDF_MAC_ADDR_SIZE]; 268 uint64_t keyrsc; 269 uint64_t keytsc; 270 uint8_t keydata[WLAN_CRYPTO_KEYBUF_SIZE + WLAN_CRYPTO_MICBUF_SIZE]; 271 uint8_t txiv[WLAN_CRYPTO_WAPI_IV_SIZE]; 272 uint8_t recviv[WLAN_CRYPTO_WAPI_IV_SIZE]; 273 struct wlan_crypto_fils_aad_key filsaad; 274 }; 275 276 /** 277 * struct wlan_lmac_if_crypto_tx_ops - structure of crypto function 278 * pointers 279 * @allockey: function pointer to alloc key in hw 280 * @setkey: function pointer to setkey in hw 281 * @delkey: function pointer to delkey in hw 282 * @defaultkey: function pointer to set default key 283 */ 284 285 struct wlan_lmac_if_crypto_tx_ops { 286 QDF_STATUS(*allockey)(struct wlan_objmgr_vdev *vdev, 287 struct wlan_crypto_key *key, 288 uint8_t *macaddr, uint32_t key_type); 289 QDF_STATUS(*setkey)(struct wlan_objmgr_vdev *vdev, 290 struct wlan_crypto_key *key, 291 uint8_t *macaddr, uint32_t key_type); 292 QDF_STATUS(*delkey)(struct wlan_objmgr_vdev *vdev, 293 struct wlan_crypto_key *key, 294 uint8_t *macaddr, uint32_t key_type); 295 QDF_STATUS(*defaultkey)(struct wlan_objmgr_vdev *vdev, 296 uint8_t keyix, uint8_t *macaddr); 297 }; 298 299 300 /** 301 * struct wlan_lmac_if_crypto_rx_ops - structure of crypto rx function 302 * pointers 303 * @encap: function pointer to encap tx frame 304 * @decap: function pointer to decap rx frame in hw 305 * @enmic: function pointer to enmic tx frame 306 * @demic: function pointer to demic rx frame 307 */ 308 309 struct wlan_lmac_if_crypto_rx_ops { 310 QDF_STATUS(*crypto_encap)(struct wlan_objmgr_vdev *vdev, 311 qdf_nbuf_t wbuf, uint8_t *macaddr, 312 uint8_t encapdone); 313 QDF_STATUS(*crypto_decap)(struct wlan_objmgr_vdev *vdev, 314 qdf_nbuf_t wbuf, uint8_t *macaddr, 315 uint8_t tid); 316 QDF_STATUS(*crypto_enmic)(struct wlan_objmgr_vdev *vdev, 317 qdf_nbuf_t wbuf, uint8_t *macaddr, 318 uint8_t encapdone); 319 QDF_STATUS(*crypto_demic)(struct wlan_objmgr_vdev *vdev, 320 qdf_nbuf_t wbuf, uint8_t *macaddr, 321 uint8_t tid); 322 QDF_STATUS(*set_peer_wep_keys)(struct wlan_objmgr_vdev *vdev, 323 struct wlan_objmgr_peer *peer); 324 }; 325 326 #define WLAN_CRYPTO_RX_OPS_ENCAP(crypto_rx_ops) \ 327 (crypto_rx_ops->crypto_encap) 328 #define WLAN_CRYPTO_RX_OPS_DECAP(crypto_rx_ops) \ 329 (crypto_rx_ops->crypto_decap) 330 #define WLAN_CRYPTO_RX_OPS_ENMIC(crypto_rx_ops) \ 331 (crypto_rx_ops->crypto_enmic) 332 #define WLAN_CRYPTO_RX_OPS_DEMIC(crypto_rx_ops) \ 333 (crypto_rx_ops->crypto_demic) 334 #define WLAN_CRYPTO_RX_OPS_SET_PEER_WEP_KEYS(crypto_rx_ops) \ 335 (crypto_rx_ops->set_peer_wep_keys) 336 337 #endif /* end of _WLAN_CRYPTO_GLOBAL_DEF_H_ */ 338