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(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(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 SET_MGMT_CIPHER(crypto_params, value); 191 return QDF_STATUS_SUCCESS; 192 } 193 194 /** 195 * wlan_crypto_get_mgmtciphers - called by ucfg to get mgmtcipher from vdev 196 * @vdev: vdev 197 * 198 * This function gets called from ucfg to get supported unicast ciphers 199 * 200 * Return: bitmap value of all supported unicast ciphers 201 */ 202 int32_t wlan_crypto_get_mgmtciphers(struct wlan_crypto_params *crypto_params) 203 { 204 return crypto_params->mgmtcipherset; 205 } 206 207 /** 208 * wlan_crypto_set_cipher_cap - called by ucfg to configure 209 * cipher cap in vdev 210 * @vdev: vdev 211 * @ciphers: bitmap value of all supported unicast ciphers 212 * 213 * This function gets called from ucfg to configure unicast ciphers in vdev 214 * 215 * Return: QDF_STATUS_SUCCESS - in case of success 216 */ 217 QDF_STATUS wlan_crypto_set_cipher_cap( 218 struct wlan_crypto_params *crypto_params, 219 uint32_t value) 220 { 221 crypto_params->cipher_caps = value; 222 223 return QDF_STATUS_SUCCESS; 224 } 225 226 /** 227 * wlan_crypto_get_cipher_cap - called by ucfg to get cipher caps from vdev 228 * @vdev: vdev 229 * 230 * This function gets called from ucfg to get supported unicast ciphers 231 * 232 * Return: bitmap value of all supported unicast ciphers 233 */ 234 int32_t wlan_crypto_get_cipher_cap(struct wlan_crypto_params *crypto_params) 235 { 236 return crypto_params->cipher_caps; 237 } 238 239 /** 240 * wlan_crypto_set_rsn_cap - called by ucfg to configure 241 * cipher cap in vdev 242 * @vdev: vdev 243 * @ciphers: bitmap value of all supported unicast ciphers 244 * 245 * This function gets called from ucfg to configure unicast ciphers in vdev 246 * 247 * Return: QDF_STATUS_SUCCESS - in case of success 248 */ 249 QDF_STATUS wlan_crypto_set_rsn_cap( 250 struct wlan_crypto_params *crypto_params, 251 uint32_t value) 252 { 253 crypto_params->rsn_caps = value; 254 255 return QDF_STATUS_SUCCESS; 256 } 257 258 /** 259 * wlan_crypto_get_rsn_cap - called by ucfg to get rsn caps from vdev 260 * @vdev: vdev 261 * 262 * This function gets called from ucfg to get supported unicast ciphers 263 * 264 * Return: bitmap value of all supported unicast ciphers 265 */ 266 int32_t wlan_crypto_get_rsn_cap(struct wlan_crypto_params *crypto_params) 267 { 268 return crypto_params->rsn_caps; 269 } 270 271 272 /** 273 * wlan_crypto_set_key_mgmt - called by ucfg to configure 274 * key_mgmt in vdev 275 * @vdev: vdev 276 * @ciphers: bitmap value of all supported unicast ciphers 277 * 278 * This function gets called from ucfg to configure unicast ciphers in vdev 279 * 280 * Return: QDF_STATUS_SUCCESS - in case of success 281 */ 282 QDF_STATUS wlan_crypto_set_key_mgmt( 283 struct wlan_crypto_params *crypto_params, 284 uint32_t value) 285 { 286 crypto_params->key_mgmt = value; 287 288 return QDF_STATUS_SUCCESS; 289 } 290 291 /** 292 * wlan_crypto_get_key_mgmt - called by ucfg to get key mgmt from vdev 293 * @vdev: vdev 294 * 295 * This function gets called from ucfg to get supported unicast ciphers 296 * 297 * Return: bitmap value of all supported unicast ciphers 298 */ 299 int32_t wlan_crypto_get_key_mgmt(struct wlan_crypto_params *crypto_params) 300 { 301 return crypto_params->key_mgmt; 302 } 303