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