xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/crypto/src/wlan_crypto_param_handling.c (revision 8cfe6b10058a04cafb17eed051f2ddf11bee8931)
1 /*
2  * Copyright (c) 2017-2019, 2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: Public APIs for crypto service
22  */
23 /* include files */
24 #include <qdf_types.h>
25 #include <wlan_cmn.h>
26 #include <wlan_objmgr_cmn.h>
27 
28 #include <wlan_objmgr_global_obj.h>
29 #include <wlan_objmgr_psoc_obj.h>
30 #include <wlan_objmgr_pdev_obj.h>
31 #include <wlan_objmgr_vdev_obj.h>
32 #include <wlan_objmgr_peer_obj.h>
33 
34 #include "wlan_crypto_global_def.h"
35 #include "wlan_crypto_global_api.h"
36 #include "wlan_crypto_def_i.h"
37 #include "wlan_crypto_param_handling_i.h"
38 
39 static uint32_t
40 cipher2cap(int cipher)
41 {
42 	switch (cipher)	{
43 	case WLAN_CRYPTO_CIPHER_WEP:  return WLAN_CRYPTO_CAP_WEP;
44 	case WLAN_CRYPTO_CIPHER_WEP_40:  return WLAN_CRYPTO_CAP_WEP;
45 	case WLAN_CRYPTO_CIPHER_WEP_104:  return WLAN_CRYPTO_CAP_WEP;
46 	case WLAN_CRYPTO_CIPHER_AES_OCB:  return WLAN_CRYPTO_CAP_AES;
47 	case WLAN_CRYPTO_CIPHER_AES_CCM:  return WLAN_CRYPTO_CAP_AES;
48 	case WLAN_CRYPTO_CIPHER_AES_CCM_256:  return WLAN_CRYPTO_CAP_AES;
49 	case WLAN_CRYPTO_CIPHER_AES_GCM:  return WLAN_CRYPTO_CAP_AES;
50 	case WLAN_CRYPTO_CIPHER_AES_GCM_256:  return WLAN_CRYPTO_CAP_AES;
51 	case WLAN_CRYPTO_CIPHER_CKIP: return WLAN_CRYPTO_CAP_CKIP;
52 	case WLAN_CRYPTO_CIPHER_TKIP: return WLAN_CRYPTO_CAP_TKIP_MIC;
53 	case WLAN_CRYPTO_CIPHER_WAPI_SMS4: return WLAN_CRYPTO_CAP_WAPI_SMS4;
54 	case WLAN_CRYPTO_CIPHER_WAPI_GCM4: return WLAN_CRYPTO_CAP_WAPI_GCM4;
55 	case WLAN_CRYPTO_CIPHER_FILS_AEAD: return WLAN_CRYPTO_CAP_FILS_AEAD;
56 	}
57 	return 0;
58 }
59 
60 QDF_STATUS wlan_crypto_set_authmode(struct wlan_crypto_params *crypto_params,
61 					uint32_t authmode)
62 {
63 	crypto_params->authmodeset = authmode;
64 	return QDF_STATUS_SUCCESS;
65 }
66 
67 int32_t wlan_crypto_get_authmode(struct wlan_crypto_params *crypto_params)
68 {
69 	return crypto_params->authmodeset;
70 }
71 
72 QDF_STATUS wlan_crypto_set_mcastcipher(struct wlan_crypto_params *crypto_params,
73 					wlan_crypto_cipher_type cipher)
74 {
75 	uint16_t i;
76 	uint32_t cap;
77 	QDF_STATUS status = QDF_STATUS_E_INVAL;
78 
79 	RESET_MCAST_CIPHERS(crypto_params);
80 
81 	for (i = 0; i < WLAN_CRYPTO_CIPHER_MAX; i++) {
82 		if (HAS_PARAM(cipher, i)) {
83 			cap = cipher2cap(i);
84 			if (cap && HAS_CIPHER_CAP(crypto_params, cap)) {
85 				SET_MCAST_CIPHER(crypto_params, i);
86 				status = QDF_STATUS_SUCCESS;
87 			}
88 		}
89 		CLEAR_PARAM(cipher, i);
90 	}
91 	return status;
92 }
93 
94 int32_t wlan_crypto_get_mcastcipher(struct wlan_crypto_params *crypto_params)
95 {
96 	return crypto_params->mcastcipherset;
97 }
98 
99 QDF_STATUS wlan_crypto_set_ucastciphers(
100 				struct wlan_crypto_params *crypto_params,
101 				uint32_t cipher)
102 {
103 	uint16_t i;
104 	uint32_t cap;
105 	QDF_STATUS status = QDF_STATUS_E_INVAL;
106 
107 	RESET_UCAST_CIPHERS(crypto_params);
108 
109 	for (i = 0; i < WLAN_CRYPTO_CIPHER_MAX ; i++) {
110 		if (HAS_PARAM(cipher, i)) {
111 			cap = cipher2cap(i);
112 			if (cap && HAS_CIPHER_CAP(crypto_params, cap)) {
113 				SET_UCAST_CIPHER(crypto_params, i);
114 				status = QDF_STATUS_SUCCESS;
115 			}
116 		}
117 		CLEAR_PARAM(cipher, i);
118 	}
119 
120 	return status;
121 }
122 
123 int32_t wlan_crypto_get_ucastciphers(struct wlan_crypto_params *crypto_params)
124 {
125 	return crypto_params->ucastcipherset;
126 }
127 
128 QDF_STATUS wlan_crypto_set_mgmtcipher(
129 				struct wlan_crypto_params *crypto_params,
130 				uint32_t ciphers)
131 {
132 	uint16_t i;
133 
134 	RESET_MGMT_CIPHERS(crypto_params);
135 
136 	for (i = 0; i < WLAN_CRYPTO_CIPHER_MAX ; i++) {
137 		if (HAS_PARAM(ciphers, i) && IS_MGMT_CIPHER(i))
138 			SET_MGMT_CIPHER(crypto_params, i);
139 	}
140 
141 	return QDF_STATUS_SUCCESS;
142 }
143 
144 int32_t wlan_crypto_get_mgmtciphers(struct wlan_crypto_params *crypto_params)
145 {
146 	return crypto_params->mgmtcipherset;
147 }
148 
149 QDF_STATUS wlan_crypto_set_cipher_cap(
150 				struct wlan_crypto_params *crypto_params,
151 				uint32_t value)
152 {
153 	crypto_params->cipher_caps = value;
154 
155 	return QDF_STATUS_SUCCESS;
156 }
157 
158 int32_t wlan_crypto_get_cipher_cap(struct wlan_crypto_params *crypto_params)
159 {
160 	return crypto_params->cipher_caps;
161 }
162 
163 QDF_STATUS wlan_crypto_set_rsn_cap(
164 				struct wlan_crypto_params *crypto_params,
165 				uint32_t value)
166 {
167 	crypto_params->rsn_caps = value;
168 
169 	return QDF_STATUS_SUCCESS;
170 }
171 
172 int32_t wlan_crypto_get_rsn_cap(struct wlan_crypto_params *crypto_params)
173 {
174 	return crypto_params->rsn_caps;
175 }
176 
177 QDF_STATUS wlan_crypto_set_key_mgmt(
178 				struct wlan_crypto_params *crypto_params,
179 				uint32_t value)
180 {
181 	crypto_params->key_mgmt = value;
182 
183 	return QDF_STATUS_SUCCESS;
184 }
185 
186 int32_t wlan_crypto_get_key_mgmt(struct wlan_crypto_params *crypto_params)
187 {
188 	return crypto_params->key_mgmt;
189 }
190