1 /*
2  * Copyright (c) 2018-2020 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  * DOC: Target interface file for disa component to
20  * Implement api's which shall be used by disa component
21  * in target if internally.
22  */
23 
24 #include "target_if.h"
25 #include "target_if_disa.h"
26 #include "wlan_disa_tgt_api.h"
27 #include "wlan_disa_public_struct.h"
28 #include <wmi_unified_api.h>
29 
30 int
target_if_encrypt_decrypt_event_handler(ol_scn_t scn_handle,uint8_t * data,uint32_t data_len)31 target_if_encrypt_decrypt_event_handler(ol_scn_t scn_handle, uint8_t *data,
32 					uint32_t data_len)
33 {
34 	struct disa_encrypt_decrypt_resp_params resp;
35 	struct wlan_objmgr_psoc *psoc;
36 	wmi_unified_t wmi_handle;
37 
38 	if (!data) {
39 		target_if_err("Invalid pointer");
40 		return -EINVAL;
41 	}
42 
43 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
44 	if (!psoc) {
45 		target_if_err("psoc ptr is NULL");
46 		return -EINVAL;
47 	}
48 
49 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
50 	if (!wmi_handle) {
51 		target_if_err("Invalid wmi handle");
52 		return -EINVAL;
53 	}
54 
55 	if (wmi_extract_encrypt_decrypt_resp_params(wmi_handle, data, &resp) !=
56 						    QDF_STATUS_SUCCESS) {
57 		target_if_err("Extraction of encrypt decrypt resp params failed");
58 		return -EINVAL;
59 	}
60 
61 	tgt_disa_encrypt_decrypt_resp(psoc, &resp);
62 
63 	return 0;
64 }
65 
66 QDF_STATUS
target_if_disa_register_ev_handlers(struct wlan_objmgr_psoc * psoc)67 target_if_disa_register_ev_handlers(struct wlan_objmgr_psoc *psoc)
68 {
69 	QDF_STATUS status;
70 	wmi_unified_t wmi_handle;
71 
72 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
73 	if (!wmi_handle) {
74 		target_if_err("Invalid wmi handle");
75 		return QDF_STATUS_E_INVAL;
76 	}
77 
78 	status = wmi_unified_register_event(wmi_handle,
79 				wmi_vdev_encrypt_decrypt_data_rsp_event_id,
80 				target_if_encrypt_decrypt_event_handler);
81 	if (QDF_IS_STATUS_ERROR(status)) {
82 		target_if_err("Failed to register Scan match event cb");
83 		return QDF_STATUS_E_FAILURE;
84 	}
85 
86 	return status;
87 }
88 
89 QDF_STATUS
target_if_disa_unregister_ev_handlers(struct wlan_objmgr_psoc * psoc)90 target_if_disa_unregister_ev_handlers(struct wlan_objmgr_psoc *psoc)
91 {
92 	QDF_STATUS status;
93 	wmi_unified_t wmi_handle;
94 
95 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
96 	if (!wmi_handle) {
97 		target_if_err("Invalid wmi handle");
98 		return QDF_STATUS_E_INVAL;
99 	}
100 
101 	status = wmi_unified_unregister_event(wmi_handle,
102 				wmi_vdev_encrypt_decrypt_data_rsp_event_id);
103 	if (status) {
104 		target_if_err("Failed to unregister Scan match event cb");
105 		return QDF_STATUS_E_FAILURE;
106 	}
107 
108 	return status;
109 }
110 
111 QDF_STATUS
target_if_disa_encrypt_decrypt_req(struct wlan_objmgr_psoc * psoc,struct disa_encrypt_decrypt_req_params * req)112 target_if_disa_encrypt_decrypt_req(struct wlan_objmgr_psoc *psoc,
113 		struct disa_encrypt_decrypt_req_params *req)
114 {
115 	wmi_unified_t wmi_handle;
116 
117 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
118 	if (!wmi_handle) {
119 		target_if_err("Invalid wmi handle");
120 		return QDF_STATUS_E_INVAL;
121 	}
122 
123 	return wmi_unified_encrypt_decrypt_send_cmd(wmi_handle, req);
124 }
125 
126 
target_if_disa_register_tx_ops(struct wlan_disa_tx_ops * disa_tx_ops)127 void target_if_disa_register_tx_ops(struct wlan_disa_tx_ops *disa_tx_ops)
128 {
129 	if (!disa_tx_ops) {
130 		target_if_err("disa_tx_ops is null");
131 		return;
132 	}
133 
134 	disa_tx_ops->disa_encrypt_decrypt_req =
135 		target_if_disa_encrypt_decrypt_req;
136 	disa_tx_ops->disa_register_ev_handlers =
137 		target_if_disa_register_ev_handlers;
138 	disa_tx_ops->disa_unregister_ev_handlers =
139 		target_if_disa_unregister_ev_handlers;
140 }
141