1 /*
2  * Copyright (c) 2020-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-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: Declare private API which shall be used internally only
22  * in pkt_capture component. This file shall include prototypes of
23  * various notification handlers and logging functions.
24  *
25  * Note: This API should be never accessed out of pkt_capture component.
26  */
27 
28 #ifndef _WLAN_PKT_CAPTURE_MAIN_H_
29 #define _WLAN_PKT_CAPTURE_MAIN_H_
30 
31 #include <qdf_types.h>
32 #include "wlan_pkt_capture_priv.h"
33 #include "wlan_pkt_capture_objmgr.h"
34 #include "wlan_objmgr_vdev_obj.h"
35 #ifdef WLAN_FEATURE_PKT_CAPTURE_V2
36 #include "cdp_txrx_stats_struct.h"
37 #endif
38 
39 #define pkt_capture_log(level, args...) \
40 	QDF_TRACE(QDF_MODULE_ID_PKT_CAPTURE, level, ## args)
41 
42 #define pkt_capture_logfl(level, format, args...) \
43 	pkt_capture_log(level, FL(format), ## args)
44 
45 #define pkt_capture_fatal(format, args...) \
46 		pkt_capture_logfl(QDF_TRACE_LEVEL_FATAL, format, ## args)
47 #define pkt_capture_err(format, args...) \
48 		pkt_capture_logfl(QDF_TRACE_LEVEL_ERROR, format, ## args)
49 #define pkt_capture_warn(format, args...) \
50 		pkt_capture_logfl(QDF_TRACE_LEVEL_WARN, format, ## args)
51 #define pkt_capture_info(format, args...) \
52 		pkt_capture_logfl(QDF_TRACE_LEVEL_INFO, format, ## args)
53 #define pkt_capture_debug(format, args...) \
54 		pkt_capture_logfl(QDF_TRACE_LEVEL_DEBUG, format, ## args)
55 
56 #define PKT_CAPTURE_ENTER() pkt_capture_debug("enter")
57 #define PKT_CAPTURE_EXIT() pkt_capture_debug("exit")
58 
59 /**
60  * enum pkt_capture_tx_status - packet capture tx status
61  * @pkt_capture_tx_status_ok: successfully sent + acked
62  * @pkt_capture_tx_status_discard: discard - not sent
63  * @pkt_capture_tx_status_no_ack: no_ack - sent, but no ack
64  *
65  * This enum has tx status types for packet capture mode
66  */
67 enum pkt_capture_tx_status {
68 	pkt_capture_tx_status_ok,
69 	pkt_capture_tx_status_discard,
70 	pkt_capture_tx_status_no_ack,
71 };
72 
73 /**
74  * pkt_capture_get_vdev() - Get pkt capture objmgr vdev.
75  *
76  * Return: pkt capture objmgr vdev
77  */
78 struct wlan_objmgr_vdev *pkt_capture_get_vdev(void);
79 
80 /**
81  * pkt_capture_vdev_create_notification() - Handler for vdev create notify.
82  * @vdev: vdev which is going to be created by objmgr
83  * @arg: argument for notification handler.
84  *
85  * Allocate and attach vdev private object.
86  *
87  * Return: QDF_STATUS
88  */
89 QDF_STATUS
90 pkt_capture_vdev_create_notification(struct wlan_objmgr_vdev *vdev, void *arg);
91 
92 /**
93  * pkt_capture_vdev_destroy_notification() - Handler for vdev destroy notify.
94  * @vdev: vdev which is going to be destroyed by objmgr
95  * @arg: argument for notification handler.
96  *
97  * Deallocate and detach vdev private object.
98  *
99  * Return: QDF_STATUS
100  */
101 QDF_STATUS
102 pkt_capture_vdev_destroy_notification(struct wlan_objmgr_vdev *vdev, void *arg);
103 
104 /**
105  * pkt_capture_get_mode() - get packet capture mode
106  * @psoc: pointer to psoc object
107  *
108  * Return: enum pkt_capture_mode
109  */
110 enum pkt_capture_mode pkt_capture_get_mode(struct wlan_objmgr_psoc *psoc);
111 
112 /**
113  * pkt_capture_psoc_create_notification() - Handler for psoc create notify.
114  * @psoc: psoc which is going to be created by objmgr
115  * @arg: argument for notification handler.
116  *
117  * Allocate and attach psoc private object.
118  *
119  * Return: QDF_STATUS
120  */
121 QDF_STATUS
122 pkt_capture_psoc_create_notification(struct wlan_objmgr_psoc *psoc, void *arg);
123 
124 /**
125  * pkt_capture_psoc_destroy_notification() - Handler for psoc destroy notify.
126  * @psoc: psoc which is going to be destroyed by objmgr
127  * @arg: argument for notification handler.
128  *
129  * Deallocate and detach psoc private object.
130  *
131  * Return: QDF_STATUS
132  */
133 QDF_STATUS
134 pkt_capture_psoc_destroy_notification(struct wlan_objmgr_psoc *psoc, void *arg);
135 
136 /**
137  * pkt_capture_register_callbacks - Register packet capture callbacks
138  * @vdev: pointer to wlan vdev object manager
139  * @mon_cb: callback to call
140  * @context: callback context
141  *
142  * Return: QDF_STATUS
143  */
144 QDF_STATUS
145 pkt_capture_register_callbacks(struct wlan_objmgr_vdev *vdev,
146 			       QDF_STATUS (*mon_cb)(void *, qdf_nbuf_t),
147 			       void *context);
148 
149 /**
150  * pkt_capture_deregister_callbacks - De-register packet capture callbacks
151  * @vdev: pointer to wlan vdev object manager
152  *
153  * Return: QDF_STATUS
154  */
155 QDF_STATUS pkt_capture_deregister_callbacks(struct wlan_objmgr_vdev *vdev);
156 
157 /**
158  * pkt_capture_set_pktcap_mode - Set packet capture mode
159  * @psoc: pointer to psoc object
160  * @mode: mode to be set
161  *
162  * Return: None
163  */
164 void pkt_capture_set_pktcap_mode(struct wlan_objmgr_psoc *psoc,
165 				 enum pkt_capture_mode mode);
166 
167 /**
168  * pkt_capture_get_pktcap_mode - Get packet capture mode
169  * @psoc: pointer to psoc object
170  *
171  * Return: enum pkt_capture_mode
172  */
173 enum pkt_capture_mode
174 pkt_capture_get_pktcap_mode(struct wlan_objmgr_psoc *psoc);
175 
176 /**
177  * pkt_capture_set_pktcap_config - Set packet capture config
178  * @vdev: pointer to vdev object
179  * @config: config to be set
180  *
181  * Return: None
182  */
183 void pkt_capture_set_pktcap_config(struct wlan_objmgr_vdev *vdev,
184 				   enum pkt_capture_config config);
185 
186 /**
187  * pkt_capture_get_pktcap_config - Get packet capture config
188  * @vdev: pointer to vdev object
189  *
190  * Return: config value
191  */
192 enum pkt_capture_config
193 pkt_capture_get_pktcap_config(struct wlan_objmgr_vdev *vdev);
194 
195 /**
196  * pkt_capture_drop_nbuf_list() - drop an nbuf list
197  * @buf_list: buffer list to be dropepd
198  *
199  * Return: number of buffers dropped
200  */
201 uint32_t pkt_capture_drop_nbuf_list(qdf_nbuf_t buf_list);
202 
203 /**
204  * pkt_capture_record_channel() - Update Channel Information
205  * for packet capture mode
206  * @vdev: pointer to vdev
207  *
208  * Return: None
209  */
210 void pkt_capture_record_channel(struct wlan_objmgr_vdev *vdev);
211 
212 /**
213  * pkt_capture_mon() - Wrapper function to invoke mon cb
214  * @cb_ctx: packet capture callback context
215  * @msdu: packet
216  * @vdev: pointer to vdev
217  * @ch_freq: channel frequency
218  *
219  * Return: None
220  */
221 void pkt_capture_mon(struct pkt_capture_cb_context *cb_ctx, qdf_nbuf_t msdu,
222 		     struct wlan_objmgr_vdev *vdev, uint16_t ch_freq);
223 
224 /**
225  * pkt_capture_set_filter - Set packet capture frame filter
226  * @frame_filter: pkt capture frame filter data
227  * @vdev: pointer to vdev
228  *
229  * Return: QDF_STATUS
230  */
231 QDF_STATUS pkt_capture_set_filter(struct pkt_capture_frame_filter frame_filter,
232 				  struct wlan_objmgr_vdev *vdev);
233 
234 /**
235  * pkt_capture_is_tx_mgmt_enable - Check if tx mgmt frames enabled
236  * @pdev: pointer to pdev
237  *
238  * Return: bool
239  */
240 bool pkt_capture_is_tx_mgmt_enable(struct wlan_objmgr_pdev *pdev);
241 
242 /**
243  * pkt_capture_is_frame_filter_set - Check if filter type set by user and packet
244  * type matches
245  * @buf: netbuf
246  * @frame_filter: filter set by user via vendor command
247  * @direction: Tx or Rx
248  *
249  * Return: bool
250  */
251 bool
252 pkt_capture_is_frame_filter_set(qdf_nbuf_t buf,
253 				struct pkt_capture_frame_filter *frame_filter,
254 				bool direction);
255 
256 #ifdef WLAN_FEATURE_PKT_CAPTURE_V2
257 /**
258  * pkt_capture_get_pktcap_mode_v2 - Get packet capture mode
259  *
260  * Return: enum pkt_capture_mode
261  */
262 enum pkt_capture_mode
263 pkt_capture_get_pktcap_mode_v2(void);
264 
265 /**
266  * pkt_capture_callback() - callback function for dp wdi events
267  * @soc: dp_soc handle
268  * @event: wdi event
269  * @log_data: nbuf data
270  * @peer_id: peer id
271  * @status: status
272  *
273  * Return: None
274  */
275 void pkt_capture_callback(void *soc, enum WDI_EVENT event, void *log_data,
276 			  u_int16_t peer_id, uint32_t status);
277 #endif
278 #endif /* end of _WLAN_PKT_CAPTURE_MAIN_H_ */
279