1 /* 2 * Copyright (c) 2019-2020 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: wlan_nl_to_crypto_params.c 22 * 23 * Conversion of NL param type to Crypto param type APIs implementation 24 * 25 */ 26 27 #include <linux/module.h> 28 #include <linux/kernel.h> 29 #include <linux/version.h> 30 #include <linux/netdevice.h> 31 #include <net/netlink.h> 32 #include <net/cfg80211.h> 33 34 #include <qdf_types.h> 35 #include "wlan_objmgr_vdev_obj.h" 36 #include <qdf_module.h> 37 38 #include "wlan_nl_to_crypto_params.h" 39 #include "wlan_crypto_global_def.h" 40 41 /** 42 * struct osif_akm_crypto_mapping - mapping akm type received from 43 * NL to internal crypto type 44 * @akm_suite: NL akm type 45 * @akm_type_crypto: akm crypto type 46 * 47 * mapping akm type received from NL to internal crypto type 48 */ 49 struct osif_akm_type_crypto_mapping { 50 u32 akm_suite; 51 wlan_crypto_key_mgmt akm_type_crypto; 52 }; 53 54 /** 55 * struct osif_cipher_crypto_mapping - mapping cipher type received from NL 56 * to internal crypto cipher type 57 * @cipher_suite: NL cipher type 58 * @cipher_crypto: cipher crypto type 59 * @cipher_len: Length of the cipher 60 * 61 * mapping cipher type received from NL to internal crypto cipher type 62 */ 63 struct osif_cipher_crypto_mapping { 64 u32 cipher_suite; 65 wlan_crypto_cipher_type cipher_crypto; 66 u32 cipher_len; 67 }; 68 69 /** 70 * mapping table for auth type received from NL and crypto auth type 71 */ 72 static const wlan_crypto_auth_mode 73 osif_auth_type_crypto_mapping[] = { 74 [NL80211_AUTHTYPE_AUTOMATIC] = WLAN_CRYPTO_AUTH_AUTO, 75 [NL80211_AUTHTYPE_OPEN_SYSTEM] = WLAN_CRYPTO_AUTH_OPEN, 76 [NL80211_AUTHTYPE_FT] = WLAN_CRYPTO_AUTH_OPEN, 77 [NL80211_AUTHTYPE_SHARED_KEY] = WLAN_CRYPTO_AUTH_SHARED, 78 [NL80211_AUTHTYPE_NETWORK_EAP] = WLAN_CRYPTO_AUTH_8021X, 79 #if defined(WLAN_FEATURE_FILS_SK) && \ 80 (defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \ 81 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))) 82 [NL80211_AUTHTYPE_FILS_SK] = WLAN_CRYPTO_AUTH_FILS_SK, 83 #endif 84 [NL80211_AUTHTYPE_SAE] = WLAN_CRYPTO_AUTH_SAE, 85 }; 86 87 /* mapping table for akm type received from NL and crypto akm type */ 88 static const struct osif_akm_type_crypto_mapping 89 osif_akm_type_crypto_mapping[] = { 90 { 91 .akm_suite = WLAN_AKM_SUITE_8021X, 92 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_IEEE8021X, 93 }, 94 { 95 .akm_suite = WLAN_AKM_SUITE_PSK, 96 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_PSK, 97 }, 98 { 99 .akm_suite = WLAN_AKM_SUITE_8021X_SHA256, 100 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SHA256, 101 }, 102 { 103 .akm_suite = WLAN_AKM_SUITE_PSK_SHA256, 104 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_PSK_SHA256, 105 }, 106 { 107 .akm_suite = WLAN_AKM_SUITE_SAE, 108 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_SAE, 109 }, 110 { 111 .akm_suite = WLAN_AKM_SUITE_FT_OVER_SAE, 112 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FT_SAE, 113 }, 114 #if defined(WLAN_AKM_SUITE_FT_8021X) || \ 115 defined(FEATURE_WLAN_FT_IEEE8021X) 116 { 117 .akm_suite = WLAN_AKM_SUITE_FT_8021X, 118 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FT_IEEE8021X, 119 }, 120 #endif 121 #if defined(WLAN_AKM_SUITE_FT_PSK) || \ 122 defined(FEATURE_WLAN_FT_PSK) 123 { 124 .akm_suite = WLAN_AKM_SUITE_FT_PSK, 125 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FT_PSK, 126 }, 127 #endif 128 #ifdef FEATURE_WLAN_ESE 129 { 130 #ifndef WLAN_AKM_SUITE_CCKM 131 #define WLAN_AKM_SUITE_CCKM 0x00409600 132 #endif 133 .akm_suite = WLAN_AKM_SUITE_CCKM, 134 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_CCKM, 135 }, 136 #endif 137 { 138 #ifndef WLAN_AKM_SUITE_OSEN 139 #define WLAN_AKM_SUITE_OSEN 0x506f9a01 140 #endif 141 .akm_suite = WLAN_AKM_SUITE_OSEN, 142 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_OSEN, 143 }, 144 #if defined(WLAN_AKM_SUITE_8021X_SUITE_B) || \ 145 defined(FEATURE_WLAN_IEEE8021X_SUITE_B) 146 { 147 .akm_suite = WLAN_AKM_SUITE_8021X_SUITE_B, 148 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B, 149 }, 150 #endif 151 #if defined(WLAN_AKM_SUITE_8021X_SUITE_B_192) || \ 152 defined(FEATURE_WLAN_IEEE8021X_SUITE_B) 153 { 154 .akm_suite = WLAN_AKM_SUITE_8021X_SUITE_B_192, 155 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B_192, 156 }, 157 #endif 158 #if defined(WLAN_AKM_SUITE_FILS_SHA256) || \ 159 defined(FEATURE_WLAN_FILS) 160 { 161 .akm_suite = WLAN_AKM_SUITE_FILS_SHA256, 162 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FILS_SHA256, 163 }, 164 #endif 165 #if defined(WLAN_AKM_SUITE_FILS_SHA384) || \ 166 defined(FEATURE_WLAN_FILS) 167 { 168 .akm_suite = WLAN_AKM_SUITE_FILS_SHA384, 169 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FILS_SHA384, 170 }, 171 #endif 172 #if defined(WLAN_AKM_SUITE_FT_FILS_SHA256) || \ 173 defined(FEATURE_WLAN_FILS) 174 { 175 .akm_suite = WLAN_AKM_SUITE_FT_FILS_SHA256, 176 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA256, 177 }, 178 #endif 179 #if defined(WLAN_AKM_SUITE_FT_FILS_SHA384) || \ 180 defined(FEATURE_WLAN_FILS) 181 { 182 .akm_suite = WLAN_AKM_SUITE_FT_FILS_SHA384, 183 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA384, 184 }, 185 #endif 186 { 187 #ifndef WLAN_AKM_SUITE_OWE 188 #define WLAN_AKM_SUITE_OWE 0x000FAC12 189 #endif 190 .akm_suite = WLAN_AKM_SUITE_OWE, 191 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_OWE, 192 }, 193 { 194 #ifndef WLAN_AKM_SUITE_DPP 195 #define WLAN_AKM_SUITE_DPP 0x506f9a02 196 #endif 197 .akm_suite = WLAN_AKM_SUITE_DPP, 198 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_DPP, 199 }, 200 }; 201 202 /* mapping table for cipher type received from NL and crypto cipher type */ 203 static const struct osif_cipher_crypto_mapping 204 osif_cipher_crypto_mapping[] = { 205 { 206 .cipher_suite = IW_AUTH_CIPHER_NONE, 207 .cipher_crypto = WLAN_CRYPTO_CIPHER_NONE, 208 .cipher_len = 0, 209 }, 210 { 211 .cipher_suite = WLAN_CIPHER_SUITE_WEP40, 212 .cipher_crypto = WLAN_CRYPTO_CIPHER_WEP_40, 213 .cipher_len = WLAN_CRYPTO_KEY_WEP40_LEN, 214 }, 215 { 216 .cipher_suite = WLAN_CIPHER_SUITE_TKIP, 217 .cipher_crypto = WLAN_CRYPTO_CIPHER_TKIP, 218 .cipher_len = WLAN_CRYPTO_KEY_TKIP_LEN, 219 }, 220 { 221 .cipher_suite = WLAN_CIPHER_SUITE_CCMP, 222 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_CCM, 223 .cipher_len = WLAN_CRYPTO_KEY_CCMP_LEN, 224 }, 225 { 226 .cipher_suite = WLAN_CIPHER_SUITE_WEP104, 227 .cipher_crypto = WLAN_CRYPTO_CIPHER_WEP_104, 228 .cipher_len = WLAN_CRYPTO_KEY_WEP104_LEN, 229 }, 230 { 231 .cipher_suite = WLAN_CIPHER_SUITE_GCMP, 232 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_GCM, 233 .cipher_len = WLAN_CRYPTO_KEY_GCMP_LEN, 234 }, 235 { 236 .cipher_suite = WLAN_CIPHER_SUITE_GCMP_256, 237 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_GCM_256, 238 .cipher_len = WLAN_CRYPTO_KEY_GCMP_256_LEN, 239 }, 240 { 241 .cipher_suite = WLAN_CIPHER_SUITE_CCMP_256, 242 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_CCM_256, 243 .cipher_len = WLAN_CRYPTO_KEY_CCMP_256_LEN, 244 }, 245 { 246 .cipher_suite = WLAN_CIPHER_SUITE_AES_CMAC, 247 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_CMAC, 248 .cipher_len = WLAN_CRYPTO_KEY_CCMP_LEN, 249 }, 250 #ifdef WLAN_CIPHER_SUITE_BIP_GMAC_128 251 { 252 .cipher_suite = WLAN_CIPHER_SUITE_BIP_GMAC_128, 253 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_GMAC, 254 .cipher_len = WLAN_CRYPTO_KEY_GMAC_LEN, 255 }, 256 #endif 257 #ifdef WLAN_CIPHER_SUITE_BIP_GMAC_256 258 { 259 .cipher_suite = WLAN_CIPHER_SUITE_BIP_GMAC_256, 260 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_GMAC_256, 261 .cipher_len = WLAN_CRYPTO_KEY_GMAC_256_LEN, 262 }, 263 #endif 264 #ifdef WLAN_CIPHER_SUITE_BIP_CMAC_256 265 { 266 .cipher_suite = WLAN_CIPHER_SUITE_BIP_CMAC_256, 267 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_CMAC_256, 268 .cipher_len = WLAN_CRYPTO_KEY_CCMP_256_LEN, 269 }, 270 #endif 271 #ifdef FEATURE_WLAN_WAPI 272 { 273 .cipher_suite = WLAN_CIPHER_SUITE_SMS4, 274 .cipher_crypto = WLAN_CRYPTO_CIPHER_WAPI_SMS4, 275 .cipher_len = WLAN_CRYPTO_KEY_WAPI_LEN, 276 }, 277 #endif 278 }; 279 280 wlan_crypto_auth_mode 281 osif_nl_to_crypto_auth_type(enum nl80211_auth_type auth_type) 282 { 283 wlan_crypto_auth_mode crypto_auth_type = WLAN_CRYPTO_AUTH_NONE; 284 285 if (auth_type < NL80211_AUTHTYPE_OPEN_SYSTEM || 286 auth_type >= QDF_ARRAY_SIZE(osif_auth_type_crypto_mapping)) { 287 QDF_TRACE_ERROR(QDF_MODULE_ID_OS_IF, "Unknown type: %d", 288 auth_type); 289 return crypto_auth_type; 290 } 291 292 crypto_auth_type = osif_auth_type_crypto_mapping[auth_type]; 293 QDF_TRACE_DEBUG(QDF_MODULE_ID_OS_IF, "Auth type, NL: %d, crypto: %d", 294 auth_type, crypto_auth_type); 295 296 return crypto_auth_type; 297 } 298 299 wlan_crypto_key_mgmt osif_nl_to_crypto_akm_type(u32 key_mgmt) 300 { 301 uint8_t index; 302 wlan_crypto_key_mgmt crypto_akm_type = WLAN_CRYPTO_KEY_MGMT_NONE; 303 bool akm_type_crypto_exist = false; 304 305 for (index = 0; index < QDF_ARRAY_SIZE(osif_akm_type_crypto_mapping); 306 index++) { 307 if (osif_akm_type_crypto_mapping[index].akm_suite == key_mgmt) { 308 crypto_akm_type = osif_akm_type_crypto_mapping[index]. 309 akm_type_crypto; 310 akm_type_crypto_exist = true; 311 break; 312 } 313 } 314 if (!akm_type_crypto_exist) 315 QDF_TRACE_ERROR(QDF_MODULE_ID_OS_IF, "Unknown type: %d", 316 key_mgmt); 317 else 318 QDF_TRACE_DEBUG(QDF_MODULE_ID_OS_IF, "Akm suite, NL: %d, crypto: %d", 319 key_mgmt, crypto_akm_type); 320 321 return crypto_akm_type; 322 } 323 324 enum wlan_crypto_cipher_type osif_nl_to_crypto_cipher_type(u32 cipher) 325 { 326 uint8_t index; 327 bool cipher_crypto_exist = false; 328 wlan_crypto_cipher_type crypto_cipher_type = WLAN_CRYPTO_CIPHER_NONE; 329 330 for (index = 0; index < QDF_ARRAY_SIZE(osif_cipher_crypto_mapping); 331 index++) { 332 if (osif_cipher_crypto_mapping[index].cipher_suite == cipher) { 333 crypto_cipher_type = osif_cipher_crypto_mapping[index]. 334 cipher_crypto; 335 cipher_crypto_exist = true; 336 break; 337 } 338 } 339 if (!cipher_crypto_exist) { 340 QDF_TRACE_ERROR(QDF_MODULE_ID_OS_IF, "Unknown type: %d", 341 cipher); 342 return WLAN_CRYPTO_CIPHER_INVALID; 343 } 344 QDF_TRACE_DEBUG(QDF_MODULE_ID_OS_IF, "Cipher suite, NL: %d, crypto: %d", 345 cipher, crypto_cipher_type); 346 347 return crypto_cipher_type; 348 } 349 350 int osif_nl_to_crypto_cipher_len(u32 cipher) 351 { 352 uint8_t index; 353 354 for (index = 0; index < QDF_ARRAY_SIZE(osif_cipher_crypto_mapping); 355 index++) { 356 if (osif_cipher_crypto_mapping[index].cipher_suite == cipher) 357 return osif_cipher_crypto_mapping[index].cipher_len; 358 } 359 360 return -EINVAL; 361 } 362 363