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: Private definations for handling crypto params 21 */ 22 #ifndef _WLAN_CRYPTO_DEF_I_H_ 23 #define _WLAN_CRYPTO_DEF_I_H_ 24 25 #include "wlan_crypto_aes_i.h" 26 27 /* IEEE 802.11 defines */ 28 #define WLAN_FC0_PVER 0x0003 29 #define WLAN_FC1_DIR_MASK 0x03 30 #define WLAN_FC1_TODS 0x01 31 #define WLAN_FC1_FROMDS 0x02 32 #define WLAN_FC1_DSTODS 0x03 33 #define WLAN_FC1_MOREFRAG 0x04 34 #define WLAN_FC1_RETRY 0x08 35 #define WLAN_FC1_PWRMGT 0x10 36 #define WLAN_FC1_MOREDATA 0x20 37 #define WLAN_FC1_ISWEP 0x40 38 #define WLAN_FC1_ORDER 0x80 39 40 #define WLAN_FC0_GET_TYPE(fc) (((fc) & 0x0c) >> 2) 41 #define WLAN_FC0_GET_STYPE(fc) (((fc) & 0xf0) >> 4) 42 43 #define WLAN_INVALID_MGMT_SEQ 0xffff 44 #define WLAN_SEQ_MASK 0x0fff 45 #define WLAN_QOS_TID_MASK 0x0f 46 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & (BIT(3) | BIT(2) | BIT(1) | BIT(0))) 47 #define WLAN_GET_SEQ_SEQ(seq) \ 48 (((seq) & (~(BIT(3) | BIT(2) | BIT(1) | BIT(0)))) >> 4) 49 50 #define WLAN_FC0_TYPE_MGMT 0 51 #define WLAN_FC0_TYPE_CTRL 1 52 #define WLAN_FC0_TYPE_DATA 2 53 54 /* management */ 55 #define WLAN_FC0_STYPE_ASSOC_REQ 0 56 #define WLAN_FC0_STYPE_ASSOC_RESP 1 57 #define WLAN_FC0_STYPE_REASSOC_REQ 2 58 #define WLAN_FC0_STYPE_REASSOC_RESP 3 59 #define WLAN_FC0_STYPE_PROBE_REQ 4 60 #define WLAN_FC0_STYPE_PROBE_RESP 5 61 #define WLAN_FC0_STYPE_BEACON 8 62 #define WLAN_FC0_STYPE_ATIM 9 63 #define WLAN_FC0_STYPE_DISASSOC 10 64 #define WLAN_FC0_STYPE_AUTH 11 65 #define WLAN_FC0_STYPE_DEAUTH 12 66 #define WLAN_FC0_STYPE_ACTION 13 67 68 /* control */ 69 #define WLAN_FC0_STYPE_PSPOLL 10 70 #define WLAN_FC0_STYPE_RTS 11 71 #define WLAN_FC0_STYPE_CTS 12 72 #define WLAN_FC0_STYPE_ACK 13 73 #define WLAN_FC0_STYPE_CFEND 14 74 #define WLAN_FC0_STYPE_CFENDACK 15 75 76 /* data */ 77 #define WLAN_FC0_STYPE_DATA 0 78 #define WLAN_FC0_STYPE_DATA_CFACK 1 79 #define WLAN_FC0_STYPE_DATA_CFPOLL 2 80 #define WLAN_FC0_STYPE_DATA_CFACKPOLL 3 81 #define WLAN_FC0_STYPE_NULLFUNC 4 82 #define WLAN_FC0_STYPE_CFACK 5 83 #define WLAN_FC0_STYPE_CFPOLL 6 84 #define WLAN_FC0_STYPE_CFACKPOLL 7 85 #define WLAN_FC0_STYPE_QOS_DATA 8 86 #define WLAN_FC0_STYPE_QOS_DATA_CFACK 9 87 #define WLAN_FC0_STYPE_QOS_DATA_CFPOLL 10 88 #define WLAN_FC0_STYPE_QOS_DATA_CFACKPOLL 11 89 #define WLAN_FC0_STYPE_QOS_NULL 12 90 #define WLAN_FC0_STYPE_QOS_CFPOLL 14 91 #define WLAN_FC0_STYPE_QOS_CFACKPOLL 15 92 93 #define WLAN_TID_SIZE 17 94 #define WLAN_NONQOS_SEQ 16 95 96 /* Macros for handling unaligned memory accesses */ 97 98 static inline uint16_t wlan_crypto_get_be16(const uint8_t *a) 99 { 100 return (a[0] << 8) | a[1]; 101 } 102 103 static inline void wlan_crypto_put_be16(uint8_t *a, uint16_t val) 104 { 105 a[0] = val >> 8; 106 a[1] = val & 0xff; 107 } 108 109 static inline uint16_t wlan_crypto_get_le16(const uint8_t *a) 110 { 111 return (a[1] << 8) | a[0]; 112 } 113 114 static inline void wlan_crypto_put_le16(uint8_t *a, uint16_t val) 115 { 116 a[1] = val >> 8; 117 a[0] = val & 0xff; 118 } 119 120 static inline uint32_t wlan_crypto_get_be32(const uint8_t *a) 121 { 122 return ((u32) a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]; 123 } 124 125 static inline void wlan_crypto_put_be32(uint8_t *a, uint32_t val) 126 { 127 a[0] = (val >> 24) & 0xff; 128 a[1] = (val >> 16) & 0xff; 129 a[2] = (val >> 8) & 0xff; 130 a[3] = val & 0xff; 131 } 132 133 static inline uint32_t wlan_crypto_get_le32(const uint8_t *a) 134 { 135 return ((u32) a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]; 136 } 137 138 static inline void wlan_crypto_put_le32(uint8_t *a, uint32_t val) 139 { 140 a[3] = (val >> 24) & 0xff; 141 a[2] = (val >> 16) & 0xff; 142 a[1] = (val >> 8) & 0xff; 143 a[0] = val & 0xff; 144 } 145 146 static inline void wlan_crypto_put_be64(u8 *a, u64 val) 147 { 148 a[0] = val >> 56; 149 a[1] = val >> 48; 150 a[2] = val >> 40; 151 a[3] = val >> 32; 152 a[4] = val >> 24; 153 a[5] = val >> 16; 154 a[6] = val >> 8; 155 a[7] = val & 0xff; 156 } 157 158 #define WLAN_CRYPTO_TX_OPS_ALLOCKEY(psoc) \ 159 (psoc->soc_cb.tx_ops.crypto_tx_ops.allockey) 160 #define WLAN_CRYPTO_TX_OPS_SETKEY(psoc) \ 161 (psoc->soc_cb.tx_ops.crypto_tx_ops.setkey) 162 #define WLAN_CRYPTO_TX_OPS_DELKEY(psoc) \ 163 (psoc->soc_cb.tx_ops.crypto_tx_ops.delkey) 164 #define WLAN_CRYPTO_TX_OPS_DEFAULTKEY(psoc) \ 165 (psoc->soc_cb.tx_ops.crypto_tx_ops.defaultkey) 166 167 /* unalligned little endian access */ 168 #ifndef LE_READ_2 169 #define LE_READ_2(p) \ 170 ((uint16_t) \ 171 ((((const uint8_t *)(p))[0]) | \ 172 (((const uint8_t *)(p))[1] << 8))) 173 #endif 174 175 #ifndef LE_READ_4 176 #define LE_READ_4(p) \ 177 ((uint32_t) \ 178 ((((const uint8_t *)(p))[0]) | \ 179 (((const uint8_t *)(p))[1] << 8) | \ 180 (((const uint8_t *)(p))[2] << 16) | \ 181 (((const uint8_t *)(p))[3] << 24))) 182 #endif 183 184 #ifndef BE_READ_4 185 #define BE_READ_4(p) \ 186 ((uint32_t) \ 187 ((((const uint8_t *)(p))[0] << 24) | \ 188 (((const uint8_t *)(p))[1] << 16) | \ 189 (((const uint8_t *)(p))[2] << 8) | \ 190 (((const uint8_t *)(p))[3]))) 191 #endif 192 193 #ifndef READ_6 194 #define READ_6(b0, b1, b2, b3, b4, b5) ({ \ 195 uint32_t iv32 = (b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24);\ 196 uint16_t iv16 = (b4 << 0) | (b5 << 8);\ 197 (((uint64_t)iv16) << 32) | iv32;\ 198 }) 199 #endif 200 201 #define OUI_SIZE (4) 202 #define WLAN_CRYPTO_ADDSHORT(frm, v) \ 203 do {frm[0] = (v) & 0xff; frm[1] = (v) >> 8; frm += 2; } while (0) 204 205 #define WLAN_CRYPTO_ADDSELECTOR(frm, sel) \ 206 do { \ 207 uint32_t value = sel;\ 208 qdf_mem_copy(frm, (uint8_t *)&value, OUI_SIZE); \ 209 frm += OUI_SIZE; } while (0) 210 211 #define WLAN_CRYPTO_SELECTOR(a, b, c, d) \ 212 ((((uint32_t) (a)) << 24) | \ 213 (((uint32_t) (b)) << 16) | \ 214 (((uint32_t) (c)) << 8) | \ 215 (uint32_t) (d)) 216 217 #define WPA_TYPE_OUI WLAN_WPA_SEL(WLAN_WPA_OUI_TYPE) 218 219 #define WLAN_CRYPTO_WAPI_IE_LEN 20 220 #define WLAN_CRYPTO_WAPI_SMS4_CIPHER 0x01 221 222 #define WPA_AUTH_KEY_MGMT_NONE WLAN_WPA_SEL(WLAN_ASE_NONE) 223 #define WPA_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_WPA_SEL(WLAN_ASE_8021X_UNSPEC) 224 #define WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X \ 225 WLAN_WPA_SEL(WLAN_ASE_8021X_PSK) 226 #define WPA_AUTH_KEY_MGMT_CCKM WLAN_WPA_CCKM_AKM 227 228 #define WPA_CIPHER_SUITE_NONE WLAN_WPA_SEL(WLAN_CSE_NONE) 229 #define WPA_CIPHER_SUITE_WEP40 WLAN_WPA_SEL(WLAN_CSE_WEP40) 230 #define WPA_CIPHER_SUITE_WEP104 WLAN_WPA_SEL(WLAN_CSE_WEP104) 231 #define WPA_CIPHER_SUITE_TKIP WLAN_WPA_SEL(WLAN_CSE_TKIP) 232 #define WPA_CIPHER_SUITE_CCMP WLAN_WPA_SEL(WLAN_CSE_CCMP) 233 234 #define RSN_AUTH_KEY_MGMT_NONE WLAN_RSN_SEL(0) 235 #define RSN_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_RSN_SEL(1) 236 #define RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X\ 237 WLAN_RSN_SEL(2) 238 #define RSN_AUTH_KEY_MGMT_FT_802_1X WLAN_RSN_SEL(3) 239 #define RSN_AUTH_KEY_MGMT_FT_PSK WLAN_RSN_SEL(4) 240 #define RSN_AUTH_KEY_MGMT_802_1X_SHA256\ 241 WLAN_RSN_SEL(5) 242 #define RSN_AUTH_KEY_MGMT_PSK_SHA256 WLAN_RSN_SEL(6) 243 #define RSN_AUTH_KEY_MGMT_WPS WLAN_RSN_SEL(7) 244 #define RSN_AUTH_KEY_MGMT_SAE WLAN_RSN_SEL(8) 245 #define RSN_AUTH_KEY_MGMT_FT_SAE WLAN_RSN_SEL(9) 246 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B\ 247 WLAN_RSN_SEL(11) 248 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192\ 249 WLAN_RSN_SEL(12) 250 #define RSN_AUTH_KEY_MGMT_FT_802_1X_SUITE_B_192\ 251 WLAN_RSN_SEL(13) 252 #define RSN_AUTH_KEY_MGMT_FILS_SHA256 WLAN_RSN_SEL(14) 253 #define RSN_AUTH_KEY_MGMT_FILS_SHA384 WLAN_RSN_SEL(15) 254 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA256\ 255 WLAN_RSN_SEL(16) 256 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA384\ 257 WLAN_RSN_SEL(17) 258 #define RSN_AUTH_KEY_MGMT_OWE WLAN_RSN_SEL(18) 259 260 #define RSN_AUTH_KEY_MGMT_CCKM (WLAN_RSN_CCKM_AKM) 261 #define RSN_AUTH_KEY_MGMT_OSEN (0x019a6f50) 262 #define RSN_AUTH_KEY_MGMT_DPP (WLAN_RSN_DPP_AKM) 263 264 #define RSN_CIPHER_SUITE_NONE WLAN_RSN_SEL(WLAN_CSE_NONE) 265 #define RSN_CIPHER_SUITE_WEP40 WLAN_RSN_SEL(WLAN_CSE_WEP40) 266 #define RSN_CIPHER_SUITE_TKIP WLAN_RSN_SEL(WLAN_CSE_TKIP) 267 #define RSN_CIPHER_SUITE_WEP104 WLAN_RSN_SEL(WLAN_CSE_WEP104) 268 #define RSN_CIPHER_SUITE_CCMP WLAN_RSN_SEL(WLAN_CSE_CCMP) 269 #define RSN_CIPHER_SUITE_AES_CMAC WLAN_RSN_SEL(WLAN_CSE_AES_CMAC) 270 #define RSN_CIPHER_SUITE_GCMP WLAN_RSN_SEL(WLAN_CSE_GCMP_128) 271 #define RSN_CIPHER_SUITE_GCMP_256 WLAN_RSN_SEL(WLAN_CSE_GCMP_256) 272 #define RSN_CIPHER_SUITE_CCMP_256 WLAN_RSN_SEL(WLAN_CSE_CCMP_256) 273 #define RSN_CIPHER_SUITE_BIP_GMAC_128 WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_128) 274 #define RSN_CIPHER_SUITE_BIP_GMAC_256 WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_256) 275 #define RSN_CIPHER_SUITE_BIP_CMAC_256 WLAN_RSN_SEL(WLAN_CSE_BIP_CMAC_256) 276 277 #define RESET_PARAM(__param) ((__param) = 0) 278 #define SET_PARAM(__param, __val) ((__param) |= (1 << (__val))) 279 #define HAS_PARAM(__param, __val) ((__param) & (1 << (__val))) 280 #define CLEAR_PARAM(__param, __val) ((__param) &= ((~1) << (__val))) 281 282 283 #define RESET_AUTHMODE(_param) ((_param)->authmodeset = \ 284 (1 << WLAN_CRYPTO_AUTH_OPEN)) 285 286 #define SET_AUTHMODE(_param, _mode) ((_param)->authmodeset |= (1 << (_mode))) 287 #define HAS_AUTHMODE(_param, _mode) ((_param)->authmodeset & (1 << (_mode))) 288 289 #define AUTH_IS_OPEN(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_OPEN) 290 #define AUTH_IS_SHARED_KEY(_param) \ 291 HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_SHARED) 292 #define AUTH_IS_8021X(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_8021X) 293 #define AUTH_IS_WPA(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WPA) 294 #define AUTH_IS_RSNA(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_RSNA) 295 #define AUTH_IS_CCKM(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_CCKM) 296 #define AUTH_IS_WAI(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WAPI) 297 #define AUTH_IS_WPA2(_param) AUTH_IS_RSNA(_param) 298 299 #define AUTH_MATCH(_param1, _param2) \ 300 (((_param1)->authmodeset & (_param2)->authmodeset) != 0) 301 302 303 #define RESET_UCAST_CIPHERS(_param) ((_param)->ucastcipherset =\ 304 (1 << WLAN_CRYPTO_CIPHER_NONE)) 305 #define SET_UCAST_CIPHER(_param, _c) ((_param)->ucastcipherset |= (1 << (_c))) 306 #define HAS_UCAST_CIPHER(_param, _c) ((_param)->ucastcipherset & (1 << (_c))) 307 308 #define UCIPHER_IS_CLEAR(_param) \ 309 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_NONE) 310 #define UCIPHER_IS_WEP(_param) \ 311 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP) 312 #define UCIPHER_IS_TKIP(_param) \ 313 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP) 314 #define UCIPHER_IS_CCMP128(_param) \ 315 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM) 316 #define UCIPHER_IS_CCMP256(_param) \ 317 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256) 318 #define UCIPHER_IS_GCMP128(_param) \ 319 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM) 320 #define UCIPHER_IS_GCMP256(_param) \ 321 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256) 322 #define UCIPHER_IS_SMS4(_param) \ 323 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4) 324 325 #define RESET_MCAST_CIPHERS(_param) ((_param)->mcastcipherset = \ 326 (1 << WLAN_CRYPTO_CIPHER_NONE)) 327 #define SET_MCAST_CIPHER(_param, _c) ((_param)->mcastcipherset |= (1 << (_c))) 328 #define HAS_MCAST_CIPHER(_param, _c) ((_param)->mcastcipherset & (1 << (_c))) 329 #define HAS_ANY_MCAST_CIPHER(_param) ((_param)->mcastcipherset) 330 #define CLEAR_MCAST_CIPHER(_param, _c) \ 331 ((_param)->mcastcipherset &= (~(1)<<(_c))) 332 333 #define MCIPHER_IS_CLEAR(_param) \ 334 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_NONE) 335 #define MCIPHER_IS_WEP(_param) \ 336 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP) 337 #define MCIPHER_IS_TKIP(_param) \ 338 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP) 339 #define MCIPHER_IS_CCMP128(_param) \ 340 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM) 341 #define MCIPHER_IS_CCMP256(_param) \ 342 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256) 343 #define MCIPHER_IS_GCMP128(_param) \ 344 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM) 345 #define MCIPHER_IS_GCMP256(_param) \ 346 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256) 347 #define MCIPHER_IS_SMS4(_param) \ 348 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4) 349 350 #define RESET_MGMT_CIPHERS(_param) ((_param)->mgmtcipherset = \ 351 (1 << WLAN_CRYPTO_CIPHER_NONE)) 352 #define SET_MGMT_CIPHER(_param, _c) ((_param)->mgmtcipherset |= (1 << (_c))) 353 #define HAS_MGMT_CIPHER(_param, _c) ((_param)->mgmtcipherset & (1 << (_c))) 354 #define IS_MGMT_CIPHER(_c) ((_c == WLAN_CRYPTO_CIPHER_AES_CMAC) || \ 355 (_c == WLAN_CRYPTO_CIPHER_AES_CMAC_256) || \ 356 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC) || \ 357 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC_256)) 358 359 #define IS_FILS_CIPHER(_c) ((_c) == WLAN_CRYPTO_CIPHER_FILS_AEAD) 360 361 #define MGMT_CIPHER_IS_CMAC(_param) \ 362 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC) 363 #define MGMT_CIPHER_IS_CMAC256(_param) \ 364 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC_256) 365 #define MGMT_CIPHER_IS_GMAC(_param) \ 366 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC) 367 #define MGMT_CIPHER_IS_GMAC256(_param) \ 368 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC_256) 369 370 #define RESET_KEY_MGMT(_param) ((_param)->key_mgmt = \ 371 (1 << WLAN_CRYPTO_KEY_MGMT_NONE)) 372 #define SET_KEY_MGMT(_param, _c) ((_param)->key_mgmt |= (1 << (_c))) 373 #define HAS_KEY_MGMT(_param, _c) ((_param)->key_mgmt & (1 << (_c))) 374 375 #define UCAST_CIPHER_MATCH(_param1, _param2) \ 376 (((_param1)->ucastcipherset & (_param2)->ucastcipherset) != 0) 377 378 #define MCAST_CIPHER_MATCH(_param1, _param2) \ 379 (((_param1)->mcastcipherset & (_param2)->mcastcipherset) != 0) 380 381 #define MGMT_CIPHER_MATCH(_param1, _param2) \ 382 (((_param1)->mgmtcipherset & (_param2)->mgmtcipherset) != 0) 383 384 #define KEY_MGMTSET_MATCH(_param1, _param2) \ 385 (((_param1)->key_mgmt & (_param2)->key_mgmt) != 0 || \ 386 (!(_param1)->key_mgmt && !(_param2)->key_mgmt)) 387 388 #define RESET_CIPHER_CAP(_param) ((_param)->cipher_caps = 0) 389 #define SET_CIPHER_CAP(_param, _c) ((_param)->cipher_caps |= (1 << (_c))) 390 #define HAS_CIPHER_CAP(_param, _c) ((_param)->cipher_caps & (1 << (_c))) 391 #define HAS_ANY_CIPHER_CAP(_param) ((_param)->cipher_caps) 392 393 /** 394 * struct wlan_crypto_mmie - MMIE IE 395 * @element_id: element id 396 * @length: length of the ie 397 * @key_id: igtk key_id used 398 * @sequence_number: igtk PN number 399 * @mic: MIC for the frame 400 * 401 * This structure represents Management MIC information element (IEEE 802.11w) 402 */ 403 struct wlan_crypto_mmie { 404 uint8_t element_id; 405 uint8_t length; 406 uint16_t key_id; 407 uint8_t sequence_number[6]; 408 uint8_t mic[16]; 409 } __packed; 410 411 /** 412 * struct wlan_crypto_comp_priv - crypto component private structure 413 * @crypto_params: crypto params for the peer 414 * @key: key buffers for this peer 415 * @igtk_key: igtk key buffer for this peer 416 * @igtk_key_type: igtk key type 417 * @def_tx_keyid: default key used for this peer 418 * @def_igtk_tx_keyid default igtk key used for this peer 419 * @fils_aead_set fils params for this peer 420 * 421 */ 422 struct wlan_crypto_comp_priv { 423 struct wlan_crypto_params crypto_params; 424 struct wlan_crypto_key *key[WLAN_CRYPTO_MAXKEYIDX]; 425 struct wlan_crypto_key *igtk_key[WLAN_CRYPTO_MAXIGTKKEYIDX]; 426 uint32_t igtk_key_type; 427 uint8_t def_tx_keyid; 428 uint8_t def_igtk_tx_keyid; 429 uint8_t fils_aead_set; 430 }; 431 432 /** 433 * struct wlan_crypto_cipher - crypto cipher table 434 * @cipher_name: printable name 435 * @cipher: cipher type WLAN_CRYPTO_CIPHER_* 436 * @header: size of privacy header (bytes) 437 * @trailer: size of privacy trailer (bytes) 438 * @miclen: size of mic trailer (bytes) 439 * @keylen: max key length 440 * @setkey: function pointer for setkey 441 * @encap: function pointer for encap 442 * @decap: function pointer for decap 443 * @enmic: function pointer for enmic 444 * @demic: function pointer for demic 445 * 446 */ 447 struct wlan_crypto_cipher { 448 const char *cipher_name; 449 wlan_crypto_cipher_type cipher; 450 const uint8_t header; 451 const uint8_t trailer; 452 const uint8_t miclen; 453 const uint32_t keylen; 454 QDF_STATUS(*setkey)(struct wlan_crypto_key *); 455 QDF_STATUS(*encap)(struct wlan_crypto_key *, 456 qdf_nbuf_t, uint8_t, uint8_t); 457 QDF_STATUS(*decap)(struct wlan_crypto_key *, 458 qdf_nbuf_t, uint8_t, uint8_t); 459 QDF_STATUS(*enmic)(struct wlan_crypto_key *, 460 qdf_nbuf_t, uint8_t, uint8_t); 461 QDF_STATUS(*demic)(struct wlan_crypto_key *, 462 qdf_nbuf_t, uint8_t, uint8_t); 463 }; 464 465 466 /** 467 * wlan_crypto_is_data_protected - check is frame is protected or not 468 * @data: frame 469 * 470 * This function check is frame is protected or not 471 * 472 * Return: TRUE/FALSE 473 */ 474 static inline bool wlan_crypto_is_data_protected(const void *data) 475 { 476 const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)data; 477 if (hdr->frame_control[1] & WLAN_FC1_ISWEP) 478 return true; 479 else 480 return false; 481 } 482 483 /** 484 * ieee80211_hdrsize - calculate frame header size 485 * @data: frame 486 * 487 * This function calculate frame header size 488 * 489 * Return: header size of the frame 490 */ 491 static inline uint8_t ieee80211_hdrsize(const void *data) 492 { 493 const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)data; 494 uint8_t size = sizeof(struct ieee80211_hdr); 495 496 if ((hdr->frame_control[1] & WLAN_FC1_DIR_MASK) 497 == (WLAN_FC1_DSTODS)) { 498 size += WLAN_ALEN; 499 } 500 501 if (((WLAN_FC0_GET_STYPE(hdr->frame_control[0]) 502 == WLAN_FC0_STYPE_QOS_DATA))) { 503 size += sizeof(uint16_t); 504 /* Qos frame with Order bit set indicates an HTC frame */ 505 if (hdr->frame_control[1] & WLAN_FC1_ORDER) 506 size += (sizeof(uint8_t)*4); 507 } 508 return size; 509 } 510 511 /** 512 * ieee80211_hdrspace - calculate frame header size with padding 513 * @pdev: pdev 514 * @data: frame header 515 * 516 * This function returns the space occupied by the 802.11 header 517 * and any padding required by the driver. This works for a management 518 * or data frame. 519 * 520 * Return: header size of the frame with padding 521 */ 522 static inline uint8_t 523 ieee80211_hdrspace(struct wlan_objmgr_pdev *pdev, const void *data) 524 { 525 uint8_t size = ieee80211_hdrsize(data); 526 527 if (wlan_pdev_nif_feat_cap_get(pdev, WLAN_PDEV_F_DATAPAD)) 528 size = roundup(size, sizeof(u_int32_t)); 529 530 return size; 531 } 532 533 /** 534 * wlan_get_tid - get tid of the frame 535 * @data: frame 536 * 537 * This function get tid of the frame 538 * 539 * Return: tid of the frame 540 */ 541 static inline int wlan_get_tid(const void *data) 542 { 543 const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)data; 544 545 if (((WLAN_FC0_GET_STYPE(hdr->frame_control[0]) 546 == WLAN_FC0_STYPE_QOS_DATA))) { 547 if ((hdr->frame_control[1] & WLAN_FC1_DIR_MASK) 548 == (WLAN_FC1_DSTODS)) { 549 return ((struct ieee80211_hdr_qos_addr4 *)data)->qos[0] 550 & WLAN_QOS_TID_MASK; 551 } else { 552 return ((struct ieee80211_hdr_qos *)data)->qos[0] 553 & WLAN_QOS_TID_MASK; 554 } 555 } else 556 return WLAN_NONQOS_SEQ; 557 } 558 #endif /* end of _WLAN_CRYPTO_DEF_I_H_ */ 559