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