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