1 /* 2 * Copyright (c) 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: 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 #if defined(WLAN_AKM_SUITE_8021X_SUITE_B) || \ 128 defined(FEATURE_WLAN_IEEE8021X_SUITE_B) 129 { 130 .akm_suite = WLAN_AKM_SUITE_8021X_SUITE_B, 131 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B, 132 }, 133 #endif 134 #if defined(WLAN_AKM_SUITE_8021X_SUITE_B_192) || \ 135 defined(FEATURE_WLAN_IEEE8021X_SUITE_B) 136 { 137 .akm_suite = WLAN_AKM_SUITE_8021X_SUITE_B_192, 138 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_IEEE8021X_SUITE_B_192, 139 }, 140 #endif 141 #if defined(WLAN_AKM_SUITE_FILS_SHA256) || \ 142 defined(FEATURE_WLAN_FILS) 143 { 144 .akm_suite = WLAN_AKM_SUITE_FILS_SHA256, 145 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FILS_SHA256, 146 }, 147 #endif 148 #if defined(WLAN_AKM_SUITE_FILS_SHA384) || \ 149 defined(FEATURE_WLAN_FILS) 150 { 151 .akm_suite = WLAN_AKM_SUITE_FILS_SHA384, 152 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FILS_SHA384, 153 }, 154 #endif 155 #if defined(WLAN_AKM_SUITE_FT_FILS_SHA256) || \ 156 defined(FEATURE_WLAN_FILS) 157 { 158 .akm_suite = WLAN_AKM_SUITE_FT_FILS_SHA256, 159 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA256, 160 }, 161 #endif 162 #if defined(WLAN_AKM_SUITE_FT_FILS_SHA384) || \ 163 defined(FEATURE_WLAN_FILS) 164 { 165 .akm_suite = WLAN_AKM_SUITE_FT_FILS_SHA384, 166 .akm_type_crypto = WLAN_CRYPTO_KEY_MGMT_FT_FILS_SHA384, 167 }, 168 #endif 169 }; 170 171 /* mapping table for cipher type received from NL and cryto cipher type */ 172 static const struct osif_cipher_crypto_mapping 173 osif_cipher_crypto_mapping[] = { 174 { 175 .cipher_suite = IW_AUTH_CIPHER_NONE, 176 .cipher_crypto = WLAN_CRYPTO_CIPHER_NONE, 177 .cipher_len = 0, 178 }, 179 { 180 .cipher_suite = WLAN_CIPHER_SUITE_WEP40, 181 .cipher_crypto = WLAN_CRYPTO_CIPHER_WEP_40, 182 .cipher_len = WLAN_CRYPTO_KEY_WEP40_LEN, 183 }, 184 { 185 .cipher_suite = WLAN_CIPHER_SUITE_TKIP, 186 .cipher_crypto = WLAN_CRYPTO_CIPHER_TKIP, 187 .cipher_len = WLAN_CRYPTO_KEY_TKIP_LEN, 188 }, 189 { 190 .cipher_suite = WLAN_CIPHER_SUITE_CCMP, 191 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_CCM, 192 .cipher_len = WLAN_CRYPTO_KEY_CCMP_LEN, 193 }, 194 { 195 .cipher_suite = WLAN_CIPHER_SUITE_WEP104, 196 .cipher_crypto = WLAN_CRYPTO_CIPHER_WEP_104, 197 .cipher_len = WLAN_CRYPTO_KEY_WEP104_LEN, 198 }, 199 { 200 .cipher_suite = WLAN_CIPHER_SUITE_GCMP, 201 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_GCM, 202 .cipher_len = WLAN_CRYPTO_KEY_GCMP_LEN, 203 }, 204 { 205 .cipher_suite = WLAN_CIPHER_SUITE_GCMP_256, 206 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_GCM_256, 207 .cipher_len = WLAN_CRYPTO_KEY_GCMP_256_LEN, 208 }, 209 { 210 .cipher_suite = WLAN_CIPHER_SUITE_CCMP_256, 211 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_CCM_256, 212 .cipher_len = WLAN_CRYPTO_KEY_CCMP_256_LEN, 213 }, 214 { 215 .cipher_suite = WLAN_CIPHER_SUITE_AES_CMAC, 216 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_CMAC, 217 .cipher_len = WLAN_CRYPTO_KEY_CCMP_LEN, 218 }, 219 #ifdef WLAN_CIPHER_SUITE_BIP_GMAC_128 220 { 221 .cipher_suite = WLAN_CIPHER_SUITE_BIP_GMAC_128, 222 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_GMAC, 223 .cipher_len = WLAN_CRYPTO_KEY_GMAC_LEN, 224 }, 225 #endif 226 #ifdef WLAN_CIPHER_SUITE_BIP_GMAC_256 227 { 228 .cipher_suite = WLAN_CIPHER_SUITE_BIP_GMAC_256, 229 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_GMAC_256, 230 .cipher_len = WLAN_CRYPTO_KEY_GMAC_256_LEN, 231 }, 232 #endif 233 #ifdef WLAN_CIPHER_SUITE_BIP_CMAC_256 234 { 235 .cipher_suite = WLAN_CIPHER_SUITE_BIP_CMAC_256, 236 .cipher_crypto = WLAN_CRYPTO_CIPHER_AES_CMAC_256, 237 .cipher_len = WLAN_CRYPTO_KEY_CCMP_256_LEN, 238 }, 239 #endif 240 #ifdef FEATURE_WLAN_WAPI 241 { 242 .cipher_suite = WLAN_CIPHER_SUITE_SMS4, 243 .cipher_crypto = WLAN_CRYPTO_CIPHER_WAPI_SMS4, 244 .cipher_len = WLAN_CRYPTO_KEY_WAPI_LEN, 245 }, 246 #endif 247 }; 248 249 int osif_nl_to_crypto_auth_type(enum nl80211_auth_type auth_type) 250 { 251 wlan_crypto_auth_mode crypto_auth_type = WLAN_CRYPTO_AUTH_NONE; 252 253 if (auth_type < NL80211_AUTHTYPE_OPEN_SYSTEM || 254 auth_type >= QDF_ARRAY_SIZE(osif_auth_type_crypto_mapping)) { 255 QDF_TRACE_ERROR(QDF_MODULE_ID_OS_IF, "Unknown type: %d", 256 auth_type); 257 return -EINVAL; 258 } 259 QDF_TRACE_DEBUG(QDF_MODULE_ID_OS_IF, "Auth type, NL: %d, crypto: %d", 260 auth_type, osif_auth_type_crypto_mapping[auth_type]); 261 262 return crypto_auth_type; 263 } 264 265 int osif_nl_to_crypto_akm_type(u32 key_mgmt) 266 { 267 uint8_t index; 268 wlan_crypto_key_mgmt crypto_akm_type = WLAN_CRYPTO_KEY_MGMT_NONE; 269 bool akm_type_crypto_exist = false; 270 271 for (index = 0; index < QDF_ARRAY_SIZE(osif_akm_type_crypto_mapping); 272 index++) { 273 if (osif_akm_type_crypto_mapping[index].akm_suite == key_mgmt) { 274 crypto_akm_type = osif_akm_type_crypto_mapping[index]. 275 akm_type_crypto; 276 akm_type_crypto_exist = true; 277 break; 278 } 279 } 280 if (!akm_type_crypto_exist) { 281 QDF_TRACE_ERROR(QDF_MODULE_ID_OS_IF, "Unknown type: %d", 282 key_mgmt); 283 return -EINVAL; 284 } 285 QDF_TRACE_DEBUG(QDF_MODULE_ID_OS_IF, "Akm suite, NL: %d, crypto: %d", 286 key_mgmt, crypto_akm_type); 287 288 return crypto_akm_type; 289 } 290 291 enum wlan_crypto_cipher_type osif_nl_to_crypto_cipher_type(u32 cipher) 292 { 293 uint8_t index; 294 bool cipher_crypto_exist = false; 295 wlan_crypto_cipher_type crypto_cipher_type = WLAN_CRYPTO_CIPHER_NONE; 296 297 for (index = 0; index < QDF_ARRAY_SIZE(osif_cipher_crypto_mapping); 298 index++) { 299 if (osif_cipher_crypto_mapping[index].cipher_suite == cipher) { 300 crypto_cipher_type = osif_cipher_crypto_mapping[index]. 301 cipher_crypto; 302 cipher_crypto_exist = true; 303 break; 304 } 305 } 306 if (!cipher_crypto_exist) { 307 QDF_TRACE_ERROR(QDF_MODULE_ID_OS_IF, "Unknown type: %d", 308 cipher); 309 return WLAN_CRYPTO_CIPHER_INVALID; 310 } 311 QDF_TRACE_DEBUG(QDF_MODULE_ID_OS_IF, "Cipher suite, NL: %d, crypto: %d", 312 cipher, crypto_cipher_type); 313 314 return crypto_cipher_type; 315 } 316 317 int osif_nl_to_crypto_cipher_len(u32 cipher) 318 { 319 uint8_t index; 320 321 for (index = 0; index < QDF_ARRAY_SIZE(osif_cipher_crypto_mapping); 322 index++) { 323 if (osif_cipher_crypto_mapping[index].cipher_suite == cipher) 324 return osif_cipher_crypto_mapping[index].cipher_len; 325 } 326 327 return -EINVAL; 328 } 329 330