1 /* 2 * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /** 21 * DOC: Private definitions for handling crypto params 22 */ 23 #ifndef _WLAN_CRYPTO_DEF_I_H_ 24 #define _WLAN_CRYPTO_DEF_I_H_ 25 26 #include <wlan_cmn_ieee80211.h> 27 #ifdef WLAN_CRYPTO_AES 28 #include "wlan_crypto_aes_i.h" 29 #endif 30 31 32 /* Number of bits per byte */ 33 #define CRYPTO_NBBY 8 34 35 /* Macros for handling unaligned memory accesses */ 36 37 static inline uint16_t wlan_crypto_get_be16(const uint8_t *a) 38 { 39 return (a[0] << 8) | a[1]; 40 } 41 42 static inline void wlan_crypto_put_be16(uint8_t *a, uint16_t val) 43 { 44 a[0] = val >> 8; 45 a[1] = val & 0xff; 46 } 47 48 static inline uint16_t wlan_crypto_get_le16(const uint8_t *a) 49 { 50 return (a[1] << 8) | a[0]; 51 } 52 53 static inline void wlan_crypto_put_le16(uint8_t *a, uint16_t val) 54 { 55 a[1] = val >> 8; 56 a[0] = val & 0xff; 57 } 58 59 static inline uint32_t wlan_crypto_get_be32(const uint8_t *a) 60 { 61 return ((u32) a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]; 62 } 63 64 static inline void wlan_crypto_put_be32(uint8_t *a, uint32_t val) 65 { 66 a[0] = (val >> 24) & 0xff; 67 a[1] = (val >> 16) & 0xff; 68 a[2] = (val >> 8) & 0xff; 69 a[3] = val & 0xff; 70 } 71 72 static inline uint32_t wlan_crypto_get_le32(const uint8_t *a) 73 { 74 return ((u32) a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]; 75 } 76 77 static inline void wlan_crypto_put_le32(uint8_t *a, uint32_t val) 78 { 79 a[3] = (val >> 24) & 0xff; 80 a[2] = (val >> 16) & 0xff; 81 a[1] = (val >> 8) & 0xff; 82 a[0] = val & 0xff; 83 } 84 85 static inline void wlan_crypto_put_be64(u8 *a, u64 val) 86 { 87 a[0] = val >> 56; 88 a[1] = val >> 48; 89 a[2] = val >> 40; 90 a[3] = val >> 32; 91 a[4] = val >> 24; 92 a[5] = val >> 16; 93 a[6] = val >> 8; 94 a[7] = val & 0xff; 95 } 96 97 #define WLAN_CRYPTO_TX_OPS_ALLOCKEY(tx_ops) \ 98 ((tx_ops)->crypto_tx_ops.allockey) 99 #define WLAN_CRYPTO_TX_OPS_SETKEY(tx_ops) \ 100 ((tx_ops)->crypto_tx_ops.setkey) 101 #define WLAN_CRYPTO_TX_OPS_DELKEY(tx_ops) \ 102 ((tx_ops)->crypto_tx_ops.delkey) 103 #define WLAN_CRYPTO_TX_OPS_DEFAULTKEY(tx_ops) \ 104 ((tx_ops)->crypto_tx_ops.defaultkey) 105 #define WLAN_CRYPTO_TX_OPS_SET_KEY(tx_ops) \ 106 ((tx_ops)->crypto_tx_ops.set_key) 107 #define WLAN_CRYPTO_TX_OPS_SET_VDEV_PARAM(tx_ops) \ 108 ((tx_ops)->crypto_tx_ops.set_vdev_param) 109 #define WLAN_CRYPTO_TX_OPS_GETPN(tx_ops) \ 110 ((tx_ops)->crypto_tx_ops.getpn) 111 #define WLAN_CRYPTO_TX_OPS_SET_LTF_KEYSEED(tx_ops) \ 112 ((tx_ops)->crypto_tx_ops.set_ltf_keyseed) 113 #define WLAN_CRYPTO_TX_OPS_REGISTER_EVENTS(tx_ops) \ 114 ((tx_ops)->crypto_tx_ops.register_events) 115 #define WLAN_CRYPTO_TX_OPS_DEREGISTER_EVENTS(tx_ops) \ 116 ((tx_ops)->crypto_tx_ops.deregister_events) 117 118 /* unaligned little endian access */ 119 #ifndef LE_READ_2 120 #define LE_READ_2(p) \ 121 ((uint16_t) \ 122 ((((const uint8_t *)(p))[0]) | \ 123 (((const uint8_t *)(p))[1] << 8))) 124 #endif 125 126 #ifndef LE_READ_4 127 #define LE_READ_4(p) \ 128 ((uint32_t) \ 129 ((((const uint8_t *)(p))[0]) | \ 130 (((const uint8_t *)(p))[1] << 8) | \ 131 (((const uint8_t *)(p))[2] << 16) | \ 132 (((const uint8_t *)(p))[3] << 24))) 133 #endif 134 135 #ifndef BE_READ_4 136 #define BE_READ_4(p) \ 137 ((uint32_t) \ 138 ((((const uint8_t *)(p))[0] << 24) | \ 139 (((const uint8_t *)(p))[1] << 16) | \ 140 (((const uint8_t *)(p))[2] << 8) | \ 141 (((const uint8_t *)(p))[3]))) 142 #endif 143 144 #ifndef READ_6 145 #define READ_6(b0, b1, b2, b3, b4, b5) ({ \ 146 uint32_t iv32 = (b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24);\ 147 uint16_t iv16 = (b4 << 0) | (b5 << 8);\ 148 (((uint64_t)iv16) << 32) | iv32;\ 149 }) 150 #endif 151 152 #define OUI_SIZE (4) 153 #define WLAN_CRYPTO_ADDSHORT(frm, v) \ 154 do {frm[0] = (v) & 0xff; frm[1] = (v) >> 8; frm += 2; } while (0) 155 156 #define WLAN_CRYPTO_ADDSELECTOR(frm, sel) \ 157 do { \ 158 uint32_t value = sel;\ 159 qdf_mem_copy(frm, (uint8_t *)&value, OUI_SIZE); \ 160 frm += OUI_SIZE; } while (0) 161 162 #define WLAN_CRYPTO_SELECTOR(a, b, c, d) \ 163 ((((uint32_t) (a)) << 24) | \ 164 (((uint32_t) (b)) << 16) | \ 165 (((uint32_t) (c)) << 8) | \ 166 (uint32_t) (d)) 167 168 #define WPA_TYPE_OUI WLAN_WPA_SEL(WLAN_WPA_OUI_TYPE) 169 170 #define WLAN_CRYPTO_WAPI_IE_LEN 20 171 #define WLAN_CRYPTO_WAPI_SMS4_CIPHER 0x01 172 173 #define WPA_AUTH_KEY_MGMT_NONE WLAN_WPA_SEL(WLAN_ASE_NONE) 174 #define WPA_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_WPA_SEL(WLAN_ASE_8021X_UNSPEC) 175 #define WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X \ 176 WLAN_WPA_SEL(WLAN_ASE_8021X_PSK) 177 #define WPA_AUTH_KEY_MGMT_CCKM WLAN_WPA_CCKM_AKM 178 179 #define WPA_CIPHER_SUITE_NONE WLAN_WPA_SEL(WLAN_CSE_NONE) 180 #define WPA_CIPHER_SUITE_WEP40 WLAN_WPA_SEL(WLAN_CSE_WEP40) 181 #define WPA_CIPHER_SUITE_WEP104 WLAN_WPA_SEL(WLAN_CSE_WEP104) 182 #define WPA_CIPHER_SUITE_TKIP WLAN_WPA_SEL(WLAN_CSE_TKIP) 183 #define WPA_CIPHER_SUITE_CCMP WLAN_WPA_SEL(WLAN_CSE_CCMP) 184 185 #define RSN_AUTH_KEY_MGMT_NONE WLAN_RSN_SEL(0) 186 #define RSN_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_RSN_SEL(1) 187 #define RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X\ 188 WLAN_RSN_SEL(2) 189 #define RSN_AUTH_KEY_MGMT_FT_802_1X WLAN_RSN_SEL(3) 190 #define RSN_AUTH_KEY_MGMT_FT_PSK WLAN_RSN_SEL(4) 191 #define RSN_AUTH_KEY_MGMT_802_1X_SHA256\ 192 WLAN_RSN_SEL(5) 193 #define RSN_AUTH_KEY_MGMT_PSK_SHA256 WLAN_RSN_SEL(6) 194 #define RSN_AUTH_KEY_MGMT_WPS WLAN_RSN_SEL(7) 195 #define RSN_AUTH_KEY_MGMT_SAE WLAN_RSN_SEL(8) 196 #define RSN_AUTH_KEY_MGMT_FT_SAE WLAN_RSN_SEL(9) 197 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B\ 198 WLAN_RSN_SEL(11) 199 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192\ 200 WLAN_RSN_SEL(12) 201 #define RSN_AUTH_KEY_MGMT_FT_802_1X_SUITE_B_384\ 202 WLAN_RSN_SEL(13) 203 #define RSN_AUTH_KEY_MGMT_FILS_SHA256 WLAN_RSN_SEL(14) 204 #define RSN_AUTH_KEY_MGMT_FILS_SHA384 WLAN_RSN_SEL(15) 205 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA256\ 206 WLAN_RSN_SEL(16) 207 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA384\ 208 WLAN_RSN_SEL(17) 209 #define RSN_AUTH_KEY_MGMT_OWE WLAN_RSN_SEL(18) 210 #define RSN_AUTH_KEY_MGMT_FT_PSK_SHA384 WLAN_RSN_SEL(19) 211 #define RSN_AUTH_KEY_MGMT_PSK_SHA384 WLAN_RSN_SEL(20) 212 #define RSN_AUTH_KEY_MGMT_SAE_EXT_KEY WLAN_RSN_SEL(24) 213 214 #define RSN_AUTH_KEY_MGMT_CCKM (WLAN_RSN_CCKM_AKM) 215 #define RSN_AUTH_KEY_MGMT_OSEN (0x019a6f50) 216 #define RSN_AUTH_KEY_MGMT_DPP (WLAN_RSN_DPP_AKM) 217 218 #define RSN_CIPHER_SUITE_NONE WLAN_RSN_SEL(WLAN_CSE_NONE) 219 #define RSN_CIPHER_SUITE_WEP40 WLAN_RSN_SEL(WLAN_CSE_WEP40) 220 #define RSN_CIPHER_SUITE_TKIP WLAN_RSN_SEL(WLAN_CSE_TKIP) 221 #define RSN_CIPHER_SUITE_WEP104 WLAN_RSN_SEL(WLAN_CSE_WEP104) 222 #define RSN_CIPHER_SUITE_CCMP WLAN_RSN_SEL(WLAN_CSE_CCMP) 223 #define RSN_CIPHER_SUITE_AES_CMAC WLAN_RSN_SEL(WLAN_CSE_AES_CMAC) 224 #define RSN_CIPHER_SUITE_GCMP WLAN_RSN_SEL(WLAN_CSE_GCMP_128) 225 #define RSN_CIPHER_SUITE_GCMP_256 WLAN_RSN_SEL(WLAN_CSE_GCMP_256) 226 #define RSN_CIPHER_SUITE_CCMP_256 WLAN_RSN_SEL(WLAN_CSE_CCMP_256) 227 #define RSN_CIPHER_SUITE_BIP_GMAC_128 WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_128) 228 #define RSN_CIPHER_SUITE_BIP_GMAC_256 WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_256) 229 #define RSN_CIPHER_SUITE_BIP_CMAC_256 WLAN_RSN_SEL(WLAN_CSE_BIP_CMAC_256) 230 231 #define RESET_PARAM(__param) ((__param) = 0) 232 #define SET_PARAM(__param, __val) ((__param) |= (1 << (__val))) 233 #define HAS_PARAM(__param, __val) ((__param) & (1 << (__val))) 234 #define CLEAR_PARAM(__param, __val) ((__param) &= (~(1 << (__val)))) 235 236 237 #define RESET_AUTHMODE(_param) ((_param)->authmodeset = 0) 238 239 #define SET_AUTHMODE(_param, _mode) ((_param)->authmodeset |= (1 << (_mode))) 240 #define HAS_AUTHMODE(_param, _mode) ((_param)->authmodeset & (1 << (_mode))) 241 242 #define AUTH_IS_OPEN(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_OPEN) 243 #define AUTH_IS_SHARED_KEY(_param) \ 244 HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_SHARED) 245 #define AUTH_IS_8021X(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_8021X) 246 #define AUTH_IS_WPA(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WPA) 247 #define AUTH_IS_RSNA(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_RSNA) 248 #define AUTH_IS_CCKM(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_CCKM) 249 #define AUTH_IS_WAI(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WAPI) 250 #define AUTH_IS_WPA2(_param) AUTH_IS_RSNA(_param) 251 252 #define AUTH_MATCH(_param1, _param2) \ 253 (((_param1)->authmodeset & (_param2)->authmodeset) != 0) 254 255 256 #define RESET_UCAST_CIPHERS(_param) ((_param)->ucastcipherset = 0) 257 #define SET_UCAST_CIPHER(_param, _c) ((_param)->ucastcipherset |= (1 << (_c))) 258 #define HAS_UCAST_CIPHER(_param, _c) ((_param)->ucastcipherset & (1 << (_c))) 259 260 #define UCIPHER_IS_CLEAR(_param) \ 261 ((_param)->ucastcipherset == 0) 262 #define UCIPHER_IS_WEP(_param) \ 263 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP) 264 #define UCIPHER_IS_TKIP(_param) \ 265 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP) 266 #define UCIPHER_IS_CCMP128(_param) \ 267 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM) 268 #define UCIPHER_IS_CCMP256(_param) \ 269 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256) 270 #define UCIPHER_IS_GCMP128(_param) \ 271 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM) 272 #define UCIPHER_IS_GCMP256(_param) \ 273 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256) 274 #define UCIPHER_IS_SMS4(_param) \ 275 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4) 276 277 #define RESET_MCAST_CIPHERS(_param) ((_param)->mcastcipherset = 0) 278 #define SET_MCAST_CIPHER(_param, _c) ((_param)->mcastcipherset |= (1 << (_c))) 279 #define HAS_MCAST_CIPHER(_param, _c) ((_param)->mcastcipherset & (1 << (_c))) 280 #define HAS_ANY_MCAST_CIPHER(_param) ((_param)->mcastcipherset) 281 #define CLEAR_MCAST_CIPHER(_param, _c) \ 282 ((_param)->mcastcipherset &= (~(1)<<(_c))) 283 284 #define MCIPHER_IS_CLEAR(_param) \ 285 ((_param)->mcastcipherset == 0) 286 #define MCIPHER_IS_WEP(_param) \ 287 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP) 288 #define MCIPHER_IS_TKIP(_param) \ 289 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP) 290 #define MCIPHER_IS_CCMP128(_param) \ 291 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM) 292 #define MCIPHER_IS_CCMP256(_param) \ 293 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256) 294 #define MCIPHER_IS_GCMP128(_param) \ 295 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM) 296 #define MCIPHER_IS_GCMP256(_param) \ 297 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256) 298 #define MCIPHER_IS_SMS4(_param) \ 299 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4) 300 301 #define RESET_MGMT_CIPHERS(_param) ((_param)->mgmtcipherset = 0) 302 #define SET_MGMT_CIPHER(_param, _c) ((_param)->mgmtcipherset |= (1 << (_c))) 303 #define HAS_MGMT_CIPHER(_param, _c) ((_param)->mgmtcipherset & (1 << (_c))) 304 #define IS_MGMT_CIPHER(_c) ((_c == WLAN_CRYPTO_CIPHER_AES_CMAC) || \ 305 (_c == WLAN_CRYPTO_CIPHER_AES_CMAC_256) || \ 306 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC) || \ 307 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC_256)) 308 309 #define IS_FILS_CIPHER(_c) ((_c) == WLAN_CRYPTO_CIPHER_FILS_AEAD) 310 311 #define MGMT_CIPHER_IS_CLEAR(_param) \ 312 ((_param)->mgmtcipherset == 0) 313 #define MGMT_CIPHER_IS_CMAC(_param) \ 314 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC) 315 #define MGMT_CIPHER_IS_CMAC256(_param) \ 316 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC_256) 317 #define MGMT_CIPHER_IS_GMAC(_param) \ 318 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC) 319 #define MGMT_CIPHER_IS_GMAC256(_param) \ 320 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC_256) 321 322 #define RESET_KEY_MGMT(_param) ((_param)->key_mgmt = 0) 323 #define SET_KEY_MGMT(_param, _c) ((_param)->key_mgmt |= (1 << (_c))) 324 #define HAS_KEY_MGMT(_param, _c) ((_param)->key_mgmt & (1 << (_c))) 325 326 #define UCAST_CIPHER_MATCH(_param1, _param2) \ 327 (((_param1)->ucastcipherset & (_param2)->ucastcipherset) != 0) 328 329 #define MCAST_CIPHER_MATCH(_param1, _param2) \ 330 (((_param1)->mcastcipherset & (_param2)->mcastcipherset) != 0) 331 332 #define MGMT_CIPHER_MATCH(_param1, _param2) \ 333 (((_param1)->mgmtcipherset & (_param2)->mgmtcipherset) != 0) 334 335 #define KEY_MGMTSET_MATCH(_param1, _param2) \ 336 (((_param1)->key_mgmt & (_param2)->key_mgmt) != 0 || \ 337 (!(_param1)->key_mgmt && !(_param2)->key_mgmt)) 338 339 #define RESET_CIPHER_CAP(_param) ((_param)->cipher_caps = 0) 340 #define SET_CIPHER_CAP(_param, _c) ((_param)->cipher_caps |= (1 << (_c))) 341 #define HAS_CIPHER_CAP(_param, _c) ((_param)->cipher_caps & (1 << (_c))) 342 #define HAS_ANY_CIPHER_CAP(_param) ((_param)->cipher_caps) 343 344 #define crypto_err(params...) QDF_TRACE_ERROR(QDF_MODULE_ID_CRYPTO, params) 345 #define crypto_info(params...) QDF_TRACE_INFO(QDF_MODULE_ID_CRYPTO, params) 346 #define crypto_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_CRYPTO, params) 347 348 /** 349 * struct wlan_crypto_mmie - MMIE IE 350 * @element_id: element id 351 * @length: length of the ie 352 * @key_id: igtk key_id used 353 * @sequence_number: igtk PN number 354 * @mic: MIC for the frame 355 * 356 * This structure represents Management MIC information element (IEEE 802.11w) 357 */ 358 struct wlan_crypto_mmie { 359 uint8_t element_id; 360 uint8_t length; 361 uint16_t key_id; 362 uint8_t sequence_number[6]; 363 uint8_t mic[16]; 364 } __packed; 365 366 /** 367 * struct crypto_add_key_result - add key result structure 368 * @vdev_id: unique id identifying the VDEV 369 * @key_ix: key index 370 * @key_flags: key flags 371 * @status: status of add key 372 * @peer_macaddr: MAC address of the peer 373 * 374 * Structure used for add key result. 375 */ 376 struct crypto_add_key_result { 377 uint32_t vdev_id; 378 uint32_t key_ix; 379 uint32_t key_flags; 380 uint32_t status; 381 uint8_t peer_macaddr[QDF_MAC_ADDR_SIZE]; 382 }; 383 384 /** 385 * typedef crypto_add_key_callback - add key callback 386 * @context: opaque context that the client can use to associate the 387 * callback with the request 388 * @result: result of add key 389 */ 390 typedef void (*crypto_add_key_callback)(void *context, 391 struct crypto_add_key_result *result); 392 393 /** 394 * struct wlan_crypto_comp_priv - crypto component private structure 395 * @crypto_params: crypto params for the peer 396 * @key: key buffers for this peer 397 * @igtk_key: igtk key buffer for this peer 398 * @bigtk_key: bigtk key buffer for this peer 399 * @igtk_key_type: igtk key type 400 * @def_tx_keyid: default key used for this peer 401 * @def_igtk_tx_keyid default igtk key used for this peer 402 * @def_bigtk_tx_keyid default bigtk key used for this peer 403 * @fils_aead_set fils params for this peer 404 * @add_key_ctx: Opaque context to be used by the caller to associate the 405 * add key request with the response 406 * @add_key_cb: Callback function to be called with the add key result 407 * 408 */ 409 struct wlan_crypto_comp_priv { 410 struct wlan_crypto_params crypto_params; 411 struct wlan_crypto_key *key[WLAN_CRYPTO_MAX_VLANKEYIX]; 412 struct wlan_crypto_key *igtk_key[WLAN_CRYPTO_MAXIGTKKEYIDX]; 413 struct wlan_crypto_key *bigtk_key[WLAN_CRYPTO_MAXBIGTKKEYIDX]; 414 enum wlan_crypto_cipher_type igtk_key_type; 415 uint8_t def_tx_keyid; 416 uint8_t def_igtk_tx_keyid; 417 uint8_t def_bigtk_tx_keyid; 418 uint8_t fils_aead_set; 419 void *add_key_ctx; 420 crypto_add_key_callback add_key_cb; 421 }; 422 423 /** 424 * struct wlan_crypto_cipher - crypto cipher table 425 * @cipher_name: printable name 426 * @cipher: cipher type WLAN_CRYPTO_CIPHER_* 427 * @header: size of privacy header (bytes) 428 * @trailer: size of privacy trailer (bytes) 429 * @miclen: size of mic trailer (bytes) 430 * @keylen: max key length 431 * @setkey: function pointer for setkey 432 * @encap: function pointer for encap 433 * @decap: function pointer for decap 434 * @enmic: function pointer for enmic 435 * @demic: function pointer for demic 436 * 437 */ 438 struct wlan_crypto_cipher { 439 const char *cipher_name; 440 wlan_crypto_cipher_type cipher; 441 const uint8_t header; 442 const uint8_t trailer; 443 const uint8_t miclen; 444 const uint32_t keylen; 445 QDF_STATUS(*setkey)(struct wlan_crypto_key *); 446 QDF_STATUS(*encap)(struct wlan_crypto_key *, 447 qdf_nbuf_t, uint8_t, uint8_t); 448 QDF_STATUS(*decap)(struct wlan_crypto_key *, 449 qdf_nbuf_t, uint8_t, uint8_t); 450 QDF_STATUS(*enmic)(struct wlan_crypto_key *, 451 qdf_nbuf_t, uint8_t, uint8_t); 452 QDF_STATUS(*demic)(struct wlan_crypto_key *, 453 qdf_nbuf_t, uint8_t, uint8_t); 454 }; 455 456 457 /** 458 * wlan_crypto_is_data_protected - check is frame is protected or not 459 * @data: frame 460 * 461 * This function check is frame is protected or not 462 * 463 * Return: TRUE/FALSE 464 */ 465 static inline bool wlan_crypto_is_data_protected(const void *data) 466 { 467 const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data; 468 if (hdr->i_fc[1] & WLAN_FC1_ISWEP) 469 return true; 470 else 471 return false; 472 } 473 474 /** 475 * ieee80211_hdrsize - calculate frame header size 476 * @data: frame 477 * 478 * This function calculate frame header size 479 * 480 * Return: header size of the frame 481 */ 482 static inline uint8_t ieee80211_hdrsize(const void *data) 483 { 484 const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data; 485 uint8_t size = sizeof(struct wlan_frame_hdr); 486 487 if ((hdr->i_fc[1] & WLAN_FC1_DIR_MASK) 488 == (WLAN_FC1_DSTODS)) { 489 size += QDF_MAC_ADDR_SIZE; 490 } 491 492 if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0]) 493 == WLAN_FC0_STYPE_QOS_DATA))) { 494 size += sizeof(uint16_t); 495 /* Qos frame with Order bit set indicates an HTC frame */ 496 if (hdr->i_fc[1] & WLAN_FC1_ORDER) 497 size += (sizeof(uint8_t)*4); 498 } 499 if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0]) 500 == WLAN_FC0_STYPE_ACTION))) { 501 /* Action frame with Order bit set indicates an HTC frame */ 502 if (hdr->i_fc[1] & WLAN_FC1_ORDER) 503 size += (sizeof(uint8_t)*4); 504 } 505 return size; 506 } 507 508 /** 509 * ieee80211_hdrspace - calculate frame header size with padding 510 * @pdev: pdev 511 * @data: frame header 512 * 513 * This function returns the space occupied by the 802.11 header 514 * and any padding required by the driver. This works for a management 515 * or data frame. 516 * 517 * Return: header size of the frame with padding 518 */ 519 static inline uint8_t 520 ieee80211_hdrspace(struct wlan_objmgr_pdev *pdev, const void *data) 521 { 522 uint8_t size = ieee80211_hdrsize(data); 523 524 if (wlan_pdev_nif_feat_cap_get(pdev, WLAN_PDEV_F_DATAPAD)) 525 size = roundup(size, sizeof(u_int32_t)); 526 527 return size; 528 } 529 530 /** 531 * wlan_get_tid - get tid of the frame 532 * @data: frame 533 * 534 * This function get tid of the frame 535 * 536 * Return: tid of the frame 537 */ 538 static inline int wlan_get_tid(const void *data) 539 { 540 const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data; 541 542 if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0]) 543 == WLAN_FC0_STYPE_QOS_DATA))) { 544 if ((hdr->i_fc[1] & WLAN_FC1_DIR_MASK) 545 == (WLAN_FC1_DSTODS)) { 546 return ((struct wlan_frame_hdr_qos_addr4 *)data)->i_qos[0] 547 & WLAN_QOS_TID_MASK; 548 } else { 549 return ((struct wlan_frame_hdr_qos *)data)->i_qos[0] 550 & WLAN_QOS_TID_MASK; 551 } 552 } else 553 return WLAN_NONQOS_SEQ; 554 } 555 #endif /* end of _WLAN_CRYPTO_DEF_I_H_ */ 556