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