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