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