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 #define WLAN_CRYPTO_TX_OPS_GETPN(psoc) \ 175 ((psoc)->soc_cb.tx_ops.crypto_tx_ops.getpn) 176 177 /* unalligned little endian access */ 178 #ifndef LE_READ_2 179 #define LE_READ_2(p) \ 180 ((uint16_t) \ 181 ((((const uint8_t *)(p))[0]) | \ 182 (((const uint8_t *)(p))[1] << 8))) 183 #endif 184 185 #ifndef LE_READ_4 186 #define LE_READ_4(p) \ 187 ((uint32_t) \ 188 ((((const uint8_t *)(p))[0]) | \ 189 (((const uint8_t *)(p))[1] << 8) | \ 190 (((const uint8_t *)(p))[2] << 16) | \ 191 (((const uint8_t *)(p))[3] << 24))) 192 #endif 193 194 #ifndef BE_READ_4 195 #define BE_READ_4(p) \ 196 ((uint32_t) \ 197 ((((const uint8_t *)(p))[0] << 24) | \ 198 (((const uint8_t *)(p))[1] << 16) | \ 199 (((const uint8_t *)(p))[2] << 8) | \ 200 (((const uint8_t *)(p))[3]))) 201 #endif 202 203 #ifndef READ_6 204 #define READ_6(b0, b1, b2, b3, b4, b5) ({ \ 205 uint32_t iv32 = (b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24);\ 206 uint16_t iv16 = (b4 << 0) | (b5 << 8);\ 207 (((uint64_t)iv16) << 32) | iv32;\ 208 }) 209 #endif 210 211 #define OUI_SIZE (4) 212 #define WLAN_CRYPTO_ADDSHORT(frm, v) \ 213 do {frm[0] = (v) & 0xff; frm[1] = (v) >> 8; frm += 2; } while (0) 214 215 #define WLAN_CRYPTO_ADDSELECTOR(frm, sel) \ 216 do { \ 217 uint32_t value = sel;\ 218 qdf_mem_copy(frm, (uint8_t *)&value, OUI_SIZE); \ 219 frm += OUI_SIZE; } while (0) 220 221 #define WLAN_CRYPTO_SELECTOR(a, b, c, d) \ 222 ((((uint32_t) (a)) << 24) | \ 223 (((uint32_t) (b)) << 16) | \ 224 (((uint32_t) (c)) << 8) | \ 225 (uint32_t) (d)) 226 227 #define WPA_TYPE_OUI WLAN_WPA_SEL(WLAN_WPA_OUI_TYPE) 228 229 #define WLAN_CRYPTO_WAPI_IE_LEN 20 230 #define WLAN_CRYPTO_WAPI_SMS4_CIPHER 0x01 231 232 #define WPA_AUTH_KEY_MGMT_NONE WLAN_WPA_SEL(WLAN_ASE_NONE) 233 #define WPA_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_WPA_SEL(WLAN_ASE_8021X_UNSPEC) 234 #define WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X \ 235 WLAN_WPA_SEL(WLAN_ASE_8021X_PSK) 236 #define WPA_AUTH_KEY_MGMT_CCKM WLAN_WPA_CCKM_AKM 237 238 #define WPA_CIPHER_SUITE_NONE WLAN_WPA_SEL(WLAN_CSE_NONE) 239 #define WPA_CIPHER_SUITE_WEP40 WLAN_WPA_SEL(WLAN_CSE_WEP40) 240 #define WPA_CIPHER_SUITE_WEP104 WLAN_WPA_SEL(WLAN_CSE_WEP104) 241 #define WPA_CIPHER_SUITE_TKIP WLAN_WPA_SEL(WLAN_CSE_TKIP) 242 #define WPA_CIPHER_SUITE_CCMP WLAN_WPA_SEL(WLAN_CSE_CCMP) 243 244 #define RSN_AUTH_KEY_MGMT_NONE WLAN_RSN_SEL(0) 245 #define RSN_AUTH_KEY_MGMT_UNSPEC_802_1X WLAN_RSN_SEL(1) 246 #define RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X\ 247 WLAN_RSN_SEL(2) 248 #define RSN_AUTH_KEY_MGMT_FT_802_1X WLAN_RSN_SEL(3) 249 #define RSN_AUTH_KEY_MGMT_FT_PSK WLAN_RSN_SEL(4) 250 #define RSN_AUTH_KEY_MGMT_802_1X_SHA256\ 251 WLAN_RSN_SEL(5) 252 #define RSN_AUTH_KEY_MGMT_PSK_SHA256 WLAN_RSN_SEL(6) 253 #define RSN_AUTH_KEY_MGMT_WPS WLAN_RSN_SEL(7) 254 #define RSN_AUTH_KEY_MGMT_SAE WLAN_RSN_SEL(8) 255 #define RSN_AUTH_KEY_MGMT_FT_SAE WLAN_RSN_SEL(9) 256 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B\ 257 WLAN_RSN_SEL(11) 258 #define RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192\ 259 WLAN_RSN_SEL(12) 260 #define RSN_AUTH_KEY_MGMT_FT_802_1X_SUITE_B_384\ 261 WLAN_RSN_SEL(13) 262 #define RSN_AUTH_KEY_MGMT_FILS_SHA256 WLAN_RSN_SEL(14) 263 #define RSN_AUTH_KEY_MGMT_FILS_SHA384 WLAN_RSN_SEL(15) 264 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA256\ 265 WLAN_RSN_SEL(16) 266 #define RSN_AUTH_KEY_MGMT_FT_FILS_SHA384\ 267 WLAN_RSN_SEL(17) 268 #define RSN_AUTH_KEY_MGMT_OWE WLAN_RSN_SEL(18) 269 270 #define RSN_AUTH_KEY_MGMT_CCKM (WLAN_RSN_CCKM_AKM) 271 #define RSN_AUTH_KEY_MGMT_OSEN (0x019a6f50) 272 #define RSN_AUTH_KEY_MGMT_DPP (WLAN_RSN_DPP_AKM) 273 274 #define RSN_CIPHER_SUITE_NONE WLAN_RSN_SEL(WLAN_CSE_NONE) 275 #define RSN_CIPHER_SUITE_WEP40 WLAN_RSN_SEL(WLAN_CSE_WEP40) 276 #define RSN_CIPHER_SUITE_TKIP WLAN_RSN_SEL(WLAN_CSE_TKIP) 277 #define RSN_CIPHER_SUITE_WEP104 WLAN_RSN_SEL(WLAN_CSE_WEP104) 278 #define RSN_CIPHER_SUITE_CCMP WLAN_RSN_SEL(WLAN_CSE_CCMP) 279 #define RSN_CIPHER_SUITE_AES_CMAC WLAN_RSN_SEL(WLAN_CSE_AES_CMAC) 280 #define RSN_CIPHER_SUITE_GCMP WLAN_RSN_SEL(WLAN_CSE_GCMP_128) 281 #define RSN_CIPHER_SUITE_GCMP_256 WLAN_RSN_SEL(WLAN_CSE_GCMP_256) 282 #define RSN_CIPHER_SUITE_CCMP_256 WLAN_RSN_SEL(WLAN_CSE_CCMP_256) 283 #define RSN_CIPHER_SUITE_BIP_GMAC_128 WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_128) 284 #define RSN_CIPHER_SUITE_BIP_GMAC_256 WLAN_RSN_SEL(WLAN_CSE_BIP_GMAC_256) 285 #define RSN_CIPHER_SUITE_BIP_CMAC_256 WLAN_RSN_SEL(WLAN_CSE_BIP_CMAC_256) 286 287 #define RESET_PARAM(__param) ((__param) = 0) 288 #define SET_PARAM(__param, __val) ((__param) |= (1 << (__val))) 289 #define HAS_PARAM(__param, __val) ((__param) & (1 << (__val))) 290 #define CLEAR_PARAM(__param, __val) ((__param) &= ((~1) << (__val))) 291 292 293 #define RESET_AUTHMODE(_param) ((_param)->authmodeset = \ 294 (1 << WLAN_CRYPTO_AUTH_OPEN)) 295 296 #define SET_AUTHMODE(_param, _mode) ((_param)->authmodeset |= (1 << (_mode))) 297 #define HAS_AUTHMODE(_param, _mode) ((_param)->authmodeset & (1 << (_mode))) 298 299 #define AUTH_IS_OPEN(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_OPEN) 300 #define AUTH_IS_SHARED_KEY(_param) \ 301 HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_SHARED) 302 #define AUTH_IS_8021X(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_8021X) 303 #define AUTH_IS_WPA(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WPA) 304 #define AUTH_IS_RSNA(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_RSNA) 305 #define AUTH_IS_CCKM(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_CCKM) 306 #define AUTH_IS_WAI(_param) HAS_AUTHMODE((_param), WLAN_CRYPTO_AUTH_WAPI) 307 #define AUTH_IS_WPA2(_param) AUTH_IS_RSNA(_param) 308 309 #define AUTH_MATCH(_param1, _param2) \ 310 (((_param1)->authmodeset & (_param2)->authmodeset) != 0) 311 312 313 #define RESET_UCAST_CIPHERS(_param) ((_param)->ucastcipherset =\ 314 (1 << WLAN_CRYPTO_CIPHER_NONE)) 315 #define SET_UCAST_CIPHER(_param, _c) ((_param)->ucastcipherset |= (1 << (_c))) 316 #define HAS_UCAST_CIPHER(_param, _c) ((_param)->ucastcipherset & (1 << (_c))) 317 318 #define UCIPHER_IS_CLEAR(_param) \ 319 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_NONE) 320 #define UCIPHER_IS_WEP(_param) \ 321 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP) 322 #define UCIPHER_IS_TKIP(_param) \ 323 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP) 324 #define UCIPHER_IS_CCMP128(_param) \ 325 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM) 326 #define UCIPHER_IS_CCMP256(_param) \ 327 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256) 328 #define UCIPHER_IS_GCMP128(_param) \ 329 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM) 330 #define UCIPHER_IS_GCMP256(_param) \ 331 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256) 332 #define UCIPHER_IS_SMS4(_param) \ 333 HAS_UCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4) 334 335 #define RESET_MCAST_CIPHERS(_param) ((_param)->mcastcipherset = \ 336 (1 << WLAN_CRYPTO_CIPHER_NONE)) 337 #define SET_MCAST_CIPHER(_param, _c) ((_param)->mcastcipherset |= (1 << (_c))) 338 #define HAS_MCAST_CIPHER(_param, _c) ((_param)->mcastcipherset & (1 << (_c))) 339 #define HAS_ANY_MCAST_CIPHER(_param) ((_param)->mcastcipherset) 340 #define CLEAR_MCAST_CIPHER(_param, _c) \ 341 ((_param)->mcastcipherset &= (~(1)<<(_c))) 342 343 #define MCIPHER_IS_CLEAR(_param) \ 344 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_NONE) 345 #define MCIPHER_IS_WEP(_param) \ 346 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WEP) 347 #define MCIPHER_IS_TKIP(_param) \ 348 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_TKIP) 349 #define MCIPHER_IS_CCMP128(_param) \ 350 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM) 351 #define MCIPHER_IS_CCMP256(_param) \ 352 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CCM_256) 353 #define MCIPHER_IS_GCMP128(_param) \ 354 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM) 355 #define MCIPHER_IS_GCMP256(_param) \ 356 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GCM_256) 357 #define MCIPHER_IS_SMS4(_param) \ 358 HAS_MCAST_CIPHER((_param), WLAN_CRYPTO_CIPHER_WAPI_SMS4) 359 360 #define RESET_MGMT_CIPHERS(_param) ((_param)->mgmtcipherset = \ 361 (1 << WLAN_CRYPTO_CIPHER_NONE)) 362 #define SET_MGMT_CIPHER(_param, _c) ((_param)->mgmtcipherset |= (1 << (_c))) 363 #define HAS_MGMT_CIPHER(_param, _c) ((_param)->mgmtcipherset & (1 << (_c))) 364 #define IS_MGMT_CIPHER(_c) ((_c == WLAN_CRYPTO_CIPHER_AES_CMAC) || \ 365 (_c == WLAN_CRYPTO_CIPHER_AES_CMAC_256) || \ 366 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC) || \ 367 (_c == WLAN_CRYPTO_CIPHER_AES_GMAC_256)) 368 369 #define IS_FILS_CIPHER(_c) ((_c) == WLAN_CRYPTO_CIPHER_FILS_AEAD) 370 371 #define MGMT_CIPHER_IS_CMAC(_param) \ 372 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC) 373 #define MGMT_CIPHER_IS_CMAC256(_param) \ 374 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_CMAC_256) 375 #define MGMT_CIPHER_IS_GMAC(_param) \ 376 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC) 377 #define MGMT_CIPHER_IS_GMAC256(_param) \ 378 HAS_MGMT_CIPHER((_param), WLAN_CRYPTO_CIPHER_AES_GMAC_256) 379 380 #define RESET_KEY_MGMT(_param) ((_param)->key_mgmt = \ 381 (1 << WLAN_CRYPTO_KEY_MGMT_NONE)) 382 #define SET_KEY_MGMT(_param, _c) ((_param)->key_mgmt |= (1 << (_c))) 383 #define HAS_KEY_MGMT(_param, _c) ((_param)->key_mgmt & (1 << (_c))) 384 385 #define UCAST_CIPHER_MATCH(_param1, _param2) \ 386 (((_param1)->ucastcipherset & (_param2)->ucastcipherset) != 0) 387 388 #define MCAST_CIPHER_MATCH(_param1, _param2) \ 389 (((_param1)->mcastcipherset & (_param2)->mcastcipherset) != 0) 390 391 #define MGMT_CIPHER_MATCH(_param1, _param2) \ 392 (((_param1)->mgmtcipherset & (_param2)->mgmtcipherset) != 0) 393 394 #define KEY_MGMTSET_MATCH(_param1, _param2) \ 395 (((_param1)->key_mgmt & (_param2)->key_mgmt) != 0 || \ 396 (!(_param1)->key_mgmt && !(_param2)->key_mgmt)) 397 398 #define RESET_CIPHER_CAP(_param) ((_param)->cipher_caps = 0) 399 #define SET_CIPHER_CAP(_param, _c) ((_param)->cipher_caps |= (1 << (_c))) 400 #define HAS_CIPHER_CAP(_param, _c) ((_param)->cipher_caps & (1 << (_c))) 401 #define HAS_ANY_CIPHER_CAP(_param) ((_param)->cipher_caps) 402 403 #define crypto_err(params...) QDF_TRACE_ERROR(QDF_MODULE_ID_CRYPTO, params) 404 #define crypto_info(params...) QDF_TRACE_INFO(QDF_MODULE_ID_CRYPTO, params) 405 #define crypto_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_CRYPTO, params) 406 407 /** 408 * struct wlan_crypto_mmie - MMIE IE 409 * @element_id: element id 410 * @length: length of the ie 411 * @key_id: igtk key_id used 412 * @sequence_number: igtk PN number 413 * @mic: MIC for the frame 414 * 415 * This structure represents Management MIC information element (IEEE 802.11w) 416 */ 417 struct wlan_crypto_mmie { 418 uint8_t element_id; 419 uint8_t length; 420 uint16_t key_id; 421 uint8_t sequence_number[6]; 422 uint8_t mic[16]; 423 } __packed; 424 425 /** 426 * struct wlan_crypto_comp_priv - crypto component private structure 427 * @crypto_params: crypto params for the peer 428 * @key: key buffers for this peer 429 * @igtk_key: igtk key buffer for this peer 430 * @igtk_key_type: igtk key type 431 * @def_tx_keyid: default key used for this peer 432 * @def_igtk_tx_keyid default igtk key used for this peer 433 * @fils_aead_set fils params for this peer 434 * 435 */ 436 struct wlan_crypto_comp_priv { 437 struct wlan_crypto_params crypto_params; 438 struct wlan_crypto_key *key[WLAN_CRYPTO_MAX_VLANKEYIX]; 439 struct wlan_crypto_key *igtk_key[WLAN_CRYPTO_MAXIGTKKEYIDX]; 440 uint32_t igtk_key_type; 441 uint8_t def_tx_keyid; 442 uint8_t def_igtk_tx_keyid; 443 uint8_t fils_aead_set; 444 }; 445 446 /** 447 * struct wlan_crypto_cipher - crypto cipher table 448 * @cipher_name: printable name 449 * @cipher: cipher type WLAN_CRYPTO_CIPHER_* 450 * @header: size of privacy header (bytes) 451 * @trailer: size of privacy trailer (bytes) 452 * @miclen: size of mic trailer (bytes) 453 * @keylen: max key length 454 * @setkey: function pointer for setkey 455 * @encap: function pointer for encap 456 * @decap: function pointer for decap 457 * @enmic: function pointer for enmic 458 * @demic: function pointer for demic 459 * 460 */ 461 struct wlan_crypto_cipher { 462 const char *cipher_name; 463 wlan_crypto_cipher_type cipher; 464 const uint8_t header; 465 const uint8_t trailer; 466 const uint8_t miclen; 467 const uint32_t keylen; 468 QDF_STATUS(*setkey)(struct wlan_crypto_key *); 469 QDF_STATUS(*encap)(struct wlan_crypto_key *, 470 qdf_nbuf_t, uint8_t, uint8_t); 471 QDF_STATUS(*decap)(struct wlan_crypto_key *, 472 qdf_nbuf_t, uint8_t, uint8_t); 473 QDF_STATUS(*enmic)(struct wlan_crypto_key *, 474 qdf_nbuf_t, uint8_t, uint8_t); 475 QDF_STATUS(*demic)(struct wlan_crypto_key *, 476 qdf_nbuf_t, uint8_t, uint8_t); 477 }; 478 479 480 /** 481 * wlan_crypto_is_data_protected - check is frame is protected or not 482 * @data: frame 483 * 484 * This function check is frame is protected or not 485 * 486 * Return: TRUE/FALSE 487 */ 488 static inline bool wlan_crypto_is_data_protected(const void *data) 489 { 490 const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data; 491 if (hdr->i_fc[1] & WLAN_FC1_ISWEP) 492 return true; 493 else 494 return false; 495 } 496 497 /** 498 * ieee80211_hdrsize - calculate frame header size 499 * @data: frame 500 * 501 * This function calculate frame header size 502 * 503 * Return: header size of the frame 504 */ 505 static inline uint8_t ieee80211_hdrsize(const void *data) 506 { 507 const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data; 508 uint8_t size = sizeof(struct wlan_frame_hdr); 509 510 if ((hdr->i_fc[1] & WLAN_FC1_DIR_MASK) 511 == (WLAN_FC1_DSTODS)) { 512 size += QDF_MAC_ADDR_SIZE; 513 } 514 515 if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0]) 516 == WLAN_FC0_STYPE_QOS_DATA))) { 517 size += sizeof(uint16_t); 518 /* Qos frame with Order bit set indicates an HTC frame */ 519 if (hdr->i_fc[1] & WLAN_FC1_ORDER) 520 size += (sizeof(uint8_t)*4); 521 } 522 return size; 523 } 524 525 /** 526 * ieee80211_hdrspace - calculate frame header size with padding 527 * @pdev: pdev 528 * @data: frame header 529 * 530 * This function returns the space occupied by the 802.11 header 531 * and any padding required by the driver. This works for a management 532 * or data frame. 533 * 534 * Return: header size of the frame with padding 535 */ 536 static inline uint8_t 537 ieee80211_hdrspace(struct wlan_objmgr_pdev *pdev, const void *data) 538 { 539 uint8_t size = ieee80211_hdrsize(data); 540 541 if (wlan_pdev_nif_feat_cap_get(pdev, WLAN_PDEV_F_DATAPAD)) 542 size = roundup(size, sizeof(u_int32_t)); 543 544 return size; 545 } 546 547 /** 548 * wlan_get_tid - get tid of the frame 549 * @data: frame 550 * 551 * This function get tid of the frame 552 * 553 * Return: tid of the frame 554 */ 555 static inline int wlan_get_tid(const void *data) 556 { 557 const struct wlan_frame_hdr *hdr = (const struct wlan_frame_hdr *)data; 558 559 if (((WLAN_FC0_GET_STYPE(hdr->i_fc[0]) 560 == WLAN_FC0_STYPE_QOS_DATA))) { 561 if ((hdr->i_fc[1] & WLAN_FC1_DIR_MASK) 562 == (WLAN_FC1_DSTODS)) { 563 return ((struct wlan_frame_hdr_qos_addr4 *)data)->i_qos[0] 564 & WLAN_QOS_TID_MASK; 565 } else { 566 return ((struct wlan_frame_hdr_qos *)data)->i_qos[0] 567 & WLAN_QOS_TID_MASK; 568 } 569 } else 570 return WLAN_NONQOS_SEQ; 571 } 572 #endif /* end of _WLAN_CRYPTO_DEF_I_H_ */ 573