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