1 /* 2 * Copyright (c) 2017-2019, 2021 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: Public APIs for crypto service 21 */ 22 /* include files */ 23 #include <qdf_types.h> 24 #include <wlan_cmn.h> 25 #include <wlan_objmgr_cmn.h> 26 27 #include <wlan_objmgr_global_obj.h> 28 #include <wlan_objmgr_psoc_obj.h> 29 #include <wlan_objmgr_pdev_obj.h> 30 #include <wlan_objmgr_vdev_obj.h> 31 #include <wlan_objmgr_peer_obj.h> 32 33 #include "wlan_crypto_global_def.h" 34 #include "wlan_crypto_global_api.h" 35 #include "wlan_crypto_def_i.h" 36 #include "wlan_crypto_param_handling_i.h" 37 38 static uint32_t 39 cipher2cap(int cipher) 40 { 41 switch (cipher) { 42 case WLAN_CRYPTO_CIPHER_WEP: return WLAN_CRYPTO_CAP_WEP; 43 case WLAN_CRYPTO_CIPHER_WEP_40: return WLAN_CRYPTO_CAP_WEP; 44 case WLAN_CRYPTO_CIPHER_WEP_104: return WLAN_CRYPTO_CAP_WEP; 45 case WLAN_CRYPTO_CIPHER_AES_OCB: return WLAN_CRYPTO_CAP_AES; 46 case WLAN_CRYPTO_CIPHER_AES_CCM: return WLAN_CRYPTO_CAP_AES; 47 case WLAN_CRYPTO_CIPHER_AES_CCM_256: return WLAN_CRYPTO_CAP_AES; 48 case WLAN_CRYPTO_CIPHER_AES_GCM: return WLAN_CRYPTO_CAP_AES; 49 case WLAN_CRYPTO_CIPHER_AES_GCM_256: return WLAN_CRYPTO_CAP_AES; 50 case WLAN_CRYPTO_CIPHER_CKIP: return WLAN_CRYPTO_CAP_CKIP; 51 case WLAN_CRYPTO_CIPHER_TKIP: return WLAN_CRYPTO_CAP_TKIP_MIC; 52 case WLAN_CRYPTO_CIPHER_WAPI_SMS4: return WLAN_CRYPTO_CAP_WAPI_SMS4; 53 case WLAN_CRYPTO_CIPHER_WAPI_GCM4: return WLAN_CRYPTO_CAP_WAPI_GCM4; 54 case WLAN_CRYPTO_CIPHER_FILS_AEAD: return WLAN_CRYPTO_CAP_FILS_AEAD; 55 } 56 return 0; 57 } 58 59 /** 60 * wlan_crypto_set_authmode - called by ucfg to configure authmode for vdev 61 * @vdev: vdev 62 * @authmode: authmode 63 * 64 * This function gets called from ucfg to configure authmode for vdev. 65 * 66 * Return: QDF_STATUS_SUCCESS - in case of success 67 */ 68 QDF_STATUS wlan_crypto_set_authmode(struct wlan_crypto_params *crypto_params, 69 uint32_t authmode) 70 { 71 crypto_params->authmodeset = authmode; 72 return QDF_STATUS_SUCCESS; 73 } 74 75 /** 76 * wlan_crypto_get_authmode - called by ucfg to get authmode of particular vdev 77 * @vdev: vdev 78 * 79 * This function gets called from ucfg to get authmode of particular vdev 80 * 81 * Return: authmode 82 */ 83 int32_t wlan_crypto_get_authmode(struct wlan_crypto_params *crypto_params) 84 { 85 return crypto_params->authmodeset; 86 } 87 88 /** 89 * wlan_crypto_set_mcastcipher - called by ucfg to configure mcastcipher in vdev 90 * @vdev: vdev 91 * @wlan_crypto_cipher_type: mcast cipher value. 92 * 93 * This function gets called from ucfg to configure mcastcipher in vdev 94 * 95 * Return: QDF_STATUS_SUCCESS - in case of success 96 */ 97 QDF_STATUS wlan_crypto_set_mcastcipher(struct wlan_crypto_params *crypto_params, 98 wlan_crypto_cipher_type cipher) 99 { 100 uint16_t i; 101 uint32_t cap; 102 QDF_STATUS status = QDF_STATUS_E_INVAL; 103 104 RESET_MCAST_CIPHERS(crypto_params); 105 106 for (i = 0; i < WLAN_CRYPTO_CIPHER_MAX; i++) { 107 if (HAS_PARAM(cipher, i)) { 108 cap = cipher2cap(i); 109 if (cap && HAS_CIPHER_CAP(crypto_params, cap)) { 110 SET_MCAST_CIPHER(crypto_params, i); 111 status = QDF_STATUS_SUCCESS; 112 } 113 } 114 CLEAR_PARAM(cipher, i); 115 } 116 return status; 117 } 118 /** 119 * wlan_crypto_get_mcastcipher - called by ucfg to get mcastcipher from vdev 120 * @vdev: vdev 121 * 122 * This function gets called from ucfg to get mcastcipher of particular vdev 123 * 124 * Return: mcast cipher 125 */ 126 int32_t wlan_crypto_get_mcastcipher(struct wlan_crypto_params *crypto_params) 127 { 128 return crypto_params->mcastcipherset; 129 } 130 131 /** 132 * wlan_crypto_set_ucastciphers - called by ucfg to configure 133 * unicast ciphers in vdev 134 * @vdev: vdev 135 * @ciphers: bitmap value of all supported unicast ciphers 136 * 137 * This function gets called from ucfg to configure unicast ciphers in vdev 138 * 139 * Return: QDF_STATUS_SUCCESS - in case of success 140 */ 141 QDF_STATUS wlan_crypto_set_ucastciphers( 142 struct wlan_crypto_params *crypto_params, 143 uint32_t cipher) 144 { 145 uint16_t i; 146 uint32_t cap; 147 QDF_STATUS status = QDF_STATUS_E_INVAL; 148 149 RESET_UCAST_CIPHERS(crypto_params); 150 151 for (i = 0; i < WLAN_CRYPTO_CIPHER_MAX ; i++) { 152 if (HAS_PARAM(cipher, i)) { 153 cap = cipher2cap(i); 154 if (cap && HAS_CIPHER_CAP(crypto_params, cap)) { 155 SET_UCAST_CIPHER(crypto_params, i); 156 status = QDF_STATUS_SUCCESS; 157 } 158 } 159 CLEAR_PARAM(cipher, i); 160 } 161 162 return status; 163 } 164 165 /** 166 * wlan_crypto_get_ucastciphers - called by ucfg to get ucastcipher from vdev 167 * @vdev: vdev 168 * 169 * This function gets called from ucfg to get supported unicast ciphers 170 * 171 * Return: bitmap value of all supported unicast ciphers 172 */ 173 int32_t wlan_crypto_get_ucastciphers(struct wlan_crypto_params *crypto_params) 174 { 175 return crypto_params->ucastcipherset; 176 } 177 178 /** 179 * wlan_crypto_set_mgmtcipher - called by ucfg to configure 180 * mgmt ciphers in vdev 181 * @vdev: vdev 182 * @ciphers: bitmap value of all supported group mgmt ciphers 183 * 184 * This function gets called from ucfg to configure group mgmt ciphers in vdev 185 * 186 * Return: QDF_STATUS_SUCCESS - in case of success 187 */ 188 QDF_STATUS wlan_crypto_set_mgmtcipher( 189 struct wlan_crypto_params *crypto_params, 190 uint32_t ciphers) 191 { 192 uint16_t i; 193 194 RESET_MGMT_CIPHERS(crypto_params); 195 196 for (i = 0; i < WLAN_CRYPTO_CIPHER_MAX ; i++) { 197 if (HAS_PARAM(ciphers, i) && IS_MGMT_CIPHER(i)) 198 SET_MGMT_CIPHER(crypto_params, i); 199 } 200 201 return QDF_STATUS_SUCCESS; 202 } 203 204 /** 205 * wlan_crypto_get_mgmtciphers - called by ucfg to get mgmtcipher from vdev 206 * @vdev: vdev 207 * 208 * This function gets called from ucfg to get supported unicast ciphers 209 * 210 * Return: bitmap value of all supported unicast ciphers 211 */ 212 int32_t wlan_crypto_get_mgmtciphers(struct wlan_crypto_params *crypto_params) 213 { 214 return crypto_params->mgmtcipherset; 215 } 216 217 /** 218 * wlan_crypto_set_cipher_cap - called by ucfg to configure 219 * cipher cap in vdev 220 * @vdev: vdev 221 * @ciphers: bitmap value of all supported unicast ciphers 222 * 223 * This function gets called from ucfg to configure unicast ciphers in vdev 224 * 225 * Return: QDF_STATUS_SUCCESS - in case of success 226 */ 227 QDF_STATUS wlan_crypto_set_cipher_cap( 228 struct wlan_crypto_params *crypto_params, 229 uint32_t value) 230 { 231 crypto_params->cipher_caps = value; 232 233 return QDF_STATUS_SUCCESS; 234 } 235 236 /** 237 * wlan_crypto_get_cipher_cap - called by ucfg to get cipher caps from vdev 238 * @vdev: vdev 239 * 240 * This function gets called from ucfg to get supported unicast ciphers 241 * 242 * Return: bitmap value of all supported unicast ciphers 243 */ 244 int32_t wlan_crypto_get_cipher_cap(struct wlan_crypto_params *crypto_params) 245 { 246 return crypto_params->cipher_caps; 247 } 248 249 /** 250 * wlan_crypto_set_rsn_cap - called by ucfg to configure 251 * cipher cap in vdev 252 * @vdev: vdev 253 * @ciphers: bitmap value of all supported unicast ciphers 254 * 255 * This function gets called from ucfg to configure unicast ciphers in vdev 256 * 257 * Return: QDF_STATUS_SUCCESS - in case of success 258 */ 259 QDF_STATUS wlan_crypto_set_rsn_cap( 260 struct wlan_crypto_params *crypto_params, 261 uint32_t value) 262 { 263 crypto_params->rsn_caps = value; 264 265 return QDF_STATUS_SUCCESS; 266 } 267 268 /** 269 * wlan_crypto_get_rsn_cap - called by ucfg to get rsn caps from vdev 270 * @vdev: vdev 271 * 272 * This function gets called from ucfg to get supported unicast ciphers 273 * 274 * Return: bitmap value of all supported unicast ciphers 275 */ 276 int32_t wlan_crypto_get_rsn_cap(struct wlan_crypto_params *crypto_params) 277 { 278 return crypto_params->rsn_caps; 279 } 280 281 282 /** 283 * wlan_crypto_set_key_mgmt - called by ucfg to configure 284 * key_mgmt in vdev 285 * @vdev: vdev 286 * @ciphers: bitmap value of all supported unicast ciphers 287 * 288 * This function gets called from ucfg to configure unicast ciphers in vdev 289 * 290 * Return: QDF_STATUS_SUCCESS - in case of success 291 */ 292 QDF_STATUS wlan_crypto_set_key_mgmt( 293 struct wlan_crypto_params *crypto_params, 294 uint32_t value) 295 { 296 crypto_params->key_mgmt = value; 297 298 return QDF_STATUS_SUCCESS; 299 } 300 301 /** 302 * wlan_crypto_get_key_mgmt - called by ucfg to get key mgmt from vdev 303 * @vdev: vdev 304 * 305 * This function gets called from ucfg to get supported unicast ciphers 306 * 307 * Return: bitmap value of all supported unicast ciphers 308 */ 309 int32_t wlan_crypto_get_key_mgmt(struct wlan_crypto_params *crypto_params) 310 { 311 return crypto_params->key_mgmt; 312 } 313