1 /*
2  * Copyright (c) 2020-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 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 API implementation of pkt_capture called by north bound HDD/OSIF.
22  */
23 
24 #include "wlan_pkt_capture_objmgr.h"
25 #include "wlan_pkt_capture_main.h"
26 #include "wlan_pkt_capture_ucfg_api.h"
27 #include "wlan_pkt_capture_mon_thread.h"
28 #include "wlan_pkt_capture_mgmt_txrx.h"
29 #include "target_if_pkt_capture.h"
30 #include "wlan_pkt_capture_data_txrx.h"
31 #include "wlan_pkt_capture_tgt_api.h"
32 
ucfg_pkt_capture_get_mode(struct wlan_objmgr_psoc * psoc)33 enum pkt_capture_mode ucfg_pkt_capture_get_mode(struct wlan_objmgr_psoc *psoc)
34 {
35 	return pkt_capture_get_mode(psoc);
36 }
37 
38 QDF_STATUS
ucfg_pkt_capture_register_callbacks(struct wlan_objmgr_vdev * vdev,QDF_STATUS (* mon_cb)(void *,qdf_nbuf_t),void * context)39 ucfg_pkt_capture_register_callbacks(struct wlan_objmgr_vdev *vdev,
40 				    QDF_STATUS (*mon_cb)(void *, qdf_nbuf_t),
41 				    void *context)
42 {
43 	return pkt_capture_register_callbacks(vdev, mon_cb, context);
44 }
45 
ucfg_pkt_capture_deregister_callbacks(struct wlan_objmgr_vdev * vdev)46 QDF_STATUS ucfg_pkt_capture_deregister_callbacks(struct wlan_objmgr_vdev *vdev)
47 {
48 	return pkt_capture_deregister_callbacks(vdev);
49 }
50 
ucfg_pkt_capture_set_pktcap_mode(struct wlan_objmgr_psoc * psoc,enum pkt_capture_mode mode)51 void ucfg_pkt_capture_set_pktcap_mode(struct wlan_objmgr_psoc *psoc,
52 				      enum pkt_capture_mode mode)
53 {
54 	pkt_capture_set_pktcap_mode(psoc, mode);
55 }
56 
57 enum pkt_capture_mode
ucfg_pkt_capture_get_pktcap_mode(struct wlan_objmgr_psoc * psoc)58 ucfg_pkt_capture_get_pktcap_mode(struct wlan_objmgr_psoc *psoc)
59 {
60 	return pkt_capture_get_pktcap_mode(psoc);
61 }
62 
ucfg_pkt_capture_set_pktcap_config(struct wlan_objmgr_vdev * vdev,enum pkt_capture_config config)63 void ucfg_pkt_capture_set_pktcap_config(struct wlan_objmgr_vdev *vdev,
64 					enum pkt_capture_config config)
65 {
66 	pkt_capture_set_pktcap_config(vdev, config);
67 }
68 
69 enum pkt_capture_config
ucfg_pkt_capture_get_pktcap_config(struct wlan_objmgr_vdev * vdev)70 ucfg_pkt_capture_get_pktcap_config(struct wlan_objmgr_vdev *vdev)
71 {
72 	return pkt_capture_get_pktcap_config(vdev);
73 }
74 
ucfg_pkt_capture_init(void)75 QDF_STATUS ucfg_pkt_capture_init(void)
76 {
77 	QDF_STATUS status;
78 
79 	status = wlan_objmgr_register_psoc_create_handler(
80 				WLAN_UMAC_COMP_PKT_CAPTURE,
81 				pkt_capture_psoc_create_notification,
82 				NULL);
83 	if (QDF_IS_STATUS_ERROR(status)) {
84 		pkt_capture_err("Failed to register psoc create handler");
85 		return status;
86 	}
87 
88 	status = wlan_objmgr_register_psoc_destroy_handler(
89 				WLAN_UMAC_COMP_PKT_CAPTURE,
90 				pkt_capture_psoc_destroy_notification,
91 				NULL);
92 	if (QDF_IS_STATUS_ERROR(status)) {
93 		pkt_capture_err("Failed to register psoc delete handler");
94 		goto fail_destroy_psoc;
95 	}
96 
97 	status = wlan_objmgr_register_vdev_create_handler(
98 				WLAN_UMAC_COMP_PKT_CAPTURE,
99 				pkt_capture_vdev_create_notification, NULL);
100 	if (QDF_IS_STATUS_ERROR(status)) {
101 		pkt_capture_err("Failed to register vdev create handler");
102 		goto fail_create_vdev;
103 	}
104 
105 	status = wlan_objmgr_register_vdev_destroy_handler(
106 				WLAN_UMAC_COMP_PKT_CAPTURE,
107 				pkt_capture_vdev_destroy_notification, NULL);
108 	if (QDF_IS_STATUS_ERROR(status)) {
109 		pkt_capture_err("Failed to register vdev destroy handler");
110 		goto fail_destroy_vdev;
111 	}
112 	return status;
113 
114 fail_destroy_vdev:
115 	wlan_objmgr_unregister_vdev_create_handler(WLAN_UMAC_COMP_PKT_CAPTURE,
116 		pkt_capture_vdev_create_notification, NULL);
117 
118 fail_create_vdev:
119 	wlan_objmgr_unregister_psoc_destroy_handler(WLAN_UMAC_COMP_PKT_CAPTURE,
120 		pkt_capture_psoc_destroy_notification, NULL);
121 
122 fail_destroy_psoc:
123 	wlan_objmgr_unregister_psoc_create_handler(WLAN_UMAC_COMP_PKT_CAPTURE,
124 		pkt_capture_psoc_create_notification, NULL);
125 
126 	return status;
127 }
128 
ucfg_pkt_capture_deinit(void)129 void ucfg_pkt_capture_deinit(void)
130 {
131 	QDF_STATUS status;
132 
133 	status = wlan_objmgr_unregister_vdev_destroy_handler(
134 				WLAN_UMAC_COMP_PKT_CAPTURE,
135 				pkt_capture_vdev_destroy_notification,
136 				NULL);
137 	if (QDF_IS_STATUS_ERROR(status))
138 		pkt_capture_err("Failed to unregister vdev destroy handler");
139 
140 	status = wlan_objmgr_unregister_vdev_create_handler(
141 				WLAN_UMAC_COMP_PKT_CAPTURE,
142 				pkt_capture_vdev_create_notification, NULL);
143 	if (QDF_IS_STATUS_ERROR(status))
144 		pkt_capture_err("Failed to unregister vdev create handler");
145 
146 	status = wlan_objmgr_unregister_psoc_destroy_handler(
147 				WLAN_UMAC_COMP_PKT_CAPTURE,
148 				pkt_capture_psoc_destroy_notification,
149 				NULL);
150 	if (QDF_IS_STATUS_ERROR(status))
151 		pkt_capture_err("Failed to unregister psoc destroy handler");
152 
153 	status = wlan_objmgr_unregister_psoc_create_handler(
154 				WLAN_UMAC_COMP_PKT_CAPTURE,
155 				pkt_capture_psoc_create_notification,
156 				NULL);
157 	if (QDF_IS_STATUS_ERROR(status))
158 		pkt_capture_err("Failed to unregister psoc create handler");
159 }
160 
ucfg_pkt_capture_suspend_mon_thread(struct wlan_objmgr_vdev * vdev)161 int ucfg_pkt_capture_suspend_mon_thread(struct wlan_objmgr_vdev *vdev)
162 {
163 	return pkt_capture_suspend_mon_thread(vdev);
164 }
165 
ucfg_pkt_capture_resume_mon_thread(struct wlan_objmgr_vdev * vdev)166 void ucfg_pkt_capture_resume_mon_thread(struct wlan_objmgr_vdev *vdev)
167 {
168 	pkt_capture_resume_mon_thread(vdev);
169 }
170 
171 QDF_STATUS
ucfg_pkt_capture_process_mgmt_tx_data(struct wlan_objmgr_pdev * pdev,struct mgmt_offload_event_params * params,qdf_nbuf_t nbuf,uint8_t status)172 ucfg_pkt_capture_process_mgmt_tx_data(struct wlan_objmgr_pdev *pdev,
173 				      struct mgmt_offload_event_params *params,
174 				      qdf_nbuf_t nbuf,
175 				      uint8_t status)
176 {
177 	return pkt_capture_process_mgmt_tx_data(
178 					pdev, params, nbuf,
179 					pkt_capture_mgmt_status_map(status));
180 
181 }
182 
183 void
ucfg_pkt_capture_mgmt_tx(struct wlan_objmgr_pdev * pdev,qdf_nbuf_t nbuf,uint16_t chan_freq,uint8_t preamble_type)184 ucfg_pkt_capture_mgmt_tx(struct wlan_objmgr_pdev *pdev,
185 			 qdf_nbuf_t nbuf,
186 			 uint16_t chan_freq,
187 			 uint8_t preamble_type)
188 {
189 	pkt_capture_mgmt_tx(pdev, nbuf, chan_freq, preamble_type);
190 }
191 
192 void
ucfg_pkt_capture_mgmt_tx_completion(struct wlan_objmgr_pdev * pdev,uint32_t desc_id,uint32_t status,struct mgmt_offload_event_params * params)193 ucfg_pkt_capture_mgmt_tx_completion(struct wlan_objmgr_pdev *pdev,
194 				    uint32_t desc_id,
195 				    uint32_t status,
196 				    struct mgmt_offload_event_params *params)
197 {
198 	pkt_capture_mgmt_tx_completion(pdev, desc_id, status, params);
199 }
200 
ucfg_pkt_capture_rx_msdu_process(uint8_t * bssid,qdf_nbuf_t head_msdu,uint8_t vdev_id,htt_pdev_handle pdev)201 void ucfg_pkt_capture_rx_msdu_process(
202 				uint8_t *bssid,
203 				qdf_nbuf_t head_msdu,
204 				uint8_t vdev_id, htt_pdev_handle pdev)
205 {
206 		pkt_capture_msdu_process_pkts(bssid, head_msdu,
207 					      vdev_id, pdev, 0);
208 }
209 
ucfg_pkt_capture_rx_offloaded_pkt(qdf_nbuf_t rx_ind_msg)210 bool ucfg_pkt_capture_rx_offloaded_pkt(qdf_nbuf_t rx_ind_msg)
211 {
212 	return pkt_capture_rx_in_order_offloaded_pkt(rx_ind_msg);
213 }
214 
ucfg_pkt_capture_rx_drop_offload_pkt(qdf_nbuf_t head_msdu)215 void ucfg_pkt_capture_rx_drop_offload_pkt(qdf_nbuf_t head_msdu)
216 {
217 	pkt_capture_rx_in_order_drop_offload_pkt(head_msdu);
218 }
219 
220 void
ucfg_pkt_capture_offload_deliver_indication_handler(void * msg,uint8_t vdev_id,uint8_t * bssid,htt_pdev_handle pdev)221 ucfg_pkt_capture_offload_deliver_indication_handler(
222 					void *msg, uint8_t vdev_id,
223 					uint8_t *bssid, htt_pdev_handle pdev)
224 {
225 	pkt_capture_offload_deliver_indication_handler(msg, vdev_id,
226 						       bssid, pdev);
227 }
228 
ucfg_pkt_capture_tx_get_txcomplete_data_hdr(uint32_t * msg_word,int num_msdus)229 struct htt_tx_data_hdr_information *ucfg_pkt_capture_tx_get_txcomplete_data_hdr(
230 							uint32_t *msg_word,
231 							int num_msdus)
232 {
233 	return pkt_capture_tx_get_txcomplete_data_hdr(msg_word, num_msdus);
234 }
235 
236 void
ucfg_pkt_capture_tx_completion_process(uint8_t vdev_id,qdf_nbuf_t mon_buf_list,enum pkt_capture_data_process_type type,uint8_t tid,uint8_t status,bool pkt_format,uint8_t * bssid,htt_pdev_handle pdev,uint8_t tx_retry_cnt)237 ucfg_pkt_capture_tx_completion_process(
238 			uint8_t vdev_id,
239 			qdf_nbuf_t mon_buf_list,
240 			enum pkt_capture_data_process_type type,
241 			uint8_t tid, uint8_t status, bool pkt_format,
242 			uint8_t *bssid, htt_pdev_handle pdev,
243 			uint8_t tx_retry_cnt)
244 {
245 	pkt_capture_datapkt_process(
246 				vdev_id,
247 				mon_buf_list, TXRX_PROCESS_TYPE_DATA_TX_COMPL,
248 				tid, status, pkt_format, bssid, pdev,
249 				tx_retry_cnt);
250 }
251 
ucfg_pkt_capture_record_channel(struct wlan_objmgr_vdev * vdev)252 void ucfg_pkt_capture_record_channel(struct wlan_objmgr_vdev *vdev)
253 {
254 	pkt_capture_record_channel(vdev);
255 }
256 
257 int
ucfg_pkt_capture_register_wma_callbacks(struct wlan_objmgr_psoc * psoc,struct pkt_capture_callbacks * cb_obj)258 ucfg_pkt_capture_register_wma_callbacks(struct wlan_objmgr_psoc *psoc,
259 					struct pkt_capture_callbacks *cb_obj)
260 {
261 	struct pkt_psoc_priv *psoc_priv = pkt_capture_psoc_get_priv(psoc);
262 
263 	if (!psoc_priv) {
264 		pkt_capture_err("psoc priv is NULL");
265 		return -EINVAL;
266 	}
267 
268 	psoc_priv->cb_obj.get_rmf_status = cb_obj->get_rmf_status;
269 
270 	return 0;
271 }
272 
273 QDF_STATUS
ucfg_pkt_capture_set_filter(struct pkt_capture_frame_filter frame_filter,struct wlan_objmgr_vdev * vdev)274 ucfg_pkt_capture_set_filter(struct pkt_capture_frame_filter frame_filter,
275 			    struct wlan_objmgr_vdev *vdev)
276 {
277 	return pkt_capture_set_filter(frame_filter, vdev);
278 }
279