xref: /wlan-dirver/qca-wifi-host-cmn/dp/inc/cdp_txrx_mon.h (revision f28396d060cff5c6519f883cb28ae0116ce479f1)
1 /*
2  * Copyright (c) 2016-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 /**
20  * @file cdp_txrx_mon.h
21  * @brief Define the monitor mode API functions
22  * called by the host control SW and the OS interface module
23  */
24 
25 #ifndef _CDP_TXRX_MON_H_
26 #define _CDP_TXRX_MON_H_
27 #include "cdp_txrx_handle.h"
28 
29 static inline QDF_STATUS cdp_reset_monitor_mode(ol_txrx_soc_handle soc,
30 						uint8_t pdev_id,
31 						u_int8_t smart_monitor)
32 {
33 	if (!soc || !soc->ops) {
34 		QDF_TRACE(QDF_MODULE_ID_CDP, QDF_TRACE_LEVEL_DEBUG,
35 				"%s: Invalid Instance", __func__);
36 		QDF_BUG(0);
37 		return 0;
38 	}
39 
40 	if (!soc->ops->mon_ops ||
41 	    !soc->ops->mon_ops->txrx_reset_monitor_mode)
42 		return 0;
43 
44 	return soc->ops->mon_ops->txrx_reset_monitor_mode(soc, pdev_id,
45 							  smart_monitor);
46 }
47 
48 /**
49  * cdp_deliver_tx_mgmt() - Deliver mgmt frame for tx capture
50  * @soc: Datapath SOC handle
51  * @pdev_id: id of datapath PDEV handle
52  * @nbuf: Management frame buffer
53  */
54 static inline QDF_STATUS
55 cdp_deliver_tx_mgmt(ol_txrx_soc_handle soc, uint8_t pdev_id,
56 		    qdf_nbuf_t nbuf)
57 {
58 	if (!soc || !soc->ops) {
59 		QDF_TRACE(QDF_MODULE_ID_CDP, QDF_TRACE_LEVEL_DEBUG,
60 			  "%s: Invalid Instance", __func__);
61 		QDF_BUG(0);
62 		return QDF_STATUS_E_FAILURE;
63 	}
64 
65 	if (!soc->ops->mon_ops ||
66 	    !soc->ops->mon_ops->txrx_deliver_tx_mgmt)
67 		return QDF_STATUS_E_FAILURE;
68 
69 	return soc->ops->mon_ops->txrx_deliver_tx_mgmt(soc, pdev_id, nbuf);
70 }
71 
72 #ifdef WLAN_FEATURE_PKT_CAPTURE
73 static inline void
74 cdp_pktcapture_record_channel(
75 			ol_txrx_soc_handle soc,
76 			uint8_t pdev_id,
77 			int chan_num)
78 {
79 	if (!soc || !soc->ops) {
80 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
81 			  "%s invalid instance", __func__);
82 		QDF_BUG(0);
83 		return;
84 	}
85 
86 	if (!soc->ops->pktcapture_ops ||
87 	    !soc->ops->pktcapture_ops->txrx_pktcapture_record_channel)
88 		return;
89 
90 	soc->ops->pktcapture_ops->txrx_pktcapture_record_channel(soc,
91 								 pdev_id,
92 								 chan_num);
93 }
94 
95 static inline void
96 cdp_set_packet_capture_mode(ol_txrx_soc_handle soc,
97 			    uint8_t pdev_id,
98 			    uint8_t val)
99 {
100 	if (!soc || !soc->ops) {
101 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
102 			  "%s invalid instance", __func__);
103 		QDF_BUG(0);
104 		return;
105 	}
106 
107 	if (!soc->ops->pktcapture_ops ||
108 	    !soc->ops->pktcapture_ops->txrx_pktcapture_set_mode)
109 		return;
110 
111 	soc->ops->pktcapture_ops->txrx_pktcapture_set_mode(soc, pdev_id, val);
112 }
113 
114 static inline uint8_t
115 cdp_get_packet_capture_mode(ol_txrx_soc_handle soc, uint8_t pdev_id)
116 {
117 	if (!soc || !soc->ops) {
118 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
119 			  "%s invalid instance", __func__);
120 		QDF_BUG(0);
121 		return 0;
122 	}
123 
124 	if (!soc->ops->pktcapture_ops ||
125 	    !soc->ops->pktcapture_ops->txrx_pktcapture_get_mode)
126 		return 0;
127 
128 	return soc->ops->pktcapture_ops->txrx_pktcapture_get_mode(soc,
129 								  pdev_id);
130 }
131 
132 static inline QDF_STATUS
133 cdp_register_pktcapture_cb(
134 		ol_txrx_soc_handle soc, uint8_t pdev_id, void *ctx,
135 		QDF_STATUS(txrx_pktcapture_cb)(void *, qdf_nbuf_t))
136 {
137 	if (!soc || !soc->ops) {
138 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
139 			  "%s invalid instance", __func__);
140 		return QDF_STATUS_E_INVAL;
141 	}
142 
143 	if (!soc->ops->pktcapture_ops ||
144 	    !soc->ops->pktcapture_ops->txrx_pktcapture_cb_register)
145 		return QDF_STATUS_E_INVAL;
146 
147 	return soc->ops->pktcapture_ops->txrx_pktcapture_cb_register(
148 							soc,
149 							pdev_id,
150 							ctx,
151 							txrx_pktcapture_cb);
152 }
153 
154 static inline QDF_STATUS
155 cdp_deregister_pktcapture_cb(ol_txrx_soc_handle soc, uint8_t pdev_id)
156 {
157 	if (!soc || !soc->ops) {
158 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
159 			  "%s invalid instance", __func__);
160 		return QDF_STATUS_E_INVAL;
161 	}
162 
163 	if (!soc->ops->pktcapture_ops ||
164 	    !soc->ops->pktcapture_ops->txrx_pktcapture_cb_deregister)
165 		return QDF_STATUS_E_INVAL;
166 
167 	return soc->ops->pktcapture_ops->txrx_pktcapture_cb_deregister(soc,
168 					pdev_id);
169 }
170 
171 static inline QDF_STATUS
172 cdp_pktcapture_mgmtpkt_process(
173 			ol_txrx_soc_handle soc,
174 			uint8_t pdev_id,
175 			struct mon_rx_status *txrx_status,
176 			qdf_nbuf_t nbuf,
177 			uint8_t status)
178 {
179 	if (!soc || !soc->ops) {
180 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
181 			  "%s invalid instance", __func__);
182 		return QDF_STATUS_E_INVAL;
183 	}
184 
185 	if (!soc->ops->pktcapture_ops ||
186 	    !soc->ops->pktcapture_ops->txrx_pktcapture_mgmtpkt_process)
187 		return QDF_STATUS_E_INVAL;
188 
189 	return soc->ops->pktcapture_ops->txrx_pktcapture_mgmtpkt_process(
190 							soc,
191 							pdev_id,
192 							txrx_status,
193 							nbuf,
194 							status);
195 }
196 #else
197 static inline uint8_t
198 cdp_get_packet_capture_mode(ol_txrx_soc_handle soc, uint8_t pdev_id)
199 {
200 	return 0;
201 }
202 
203 static inline void
204 cdp_pktcapture_record_channel(ol_txrx_soc_handle soc,
205 			      uint8_t pdev_id,
206 			      int chan_num)
207 {
208 }
209 #endif /* WLAN_FEATURE_PKT_CAPTURE */
210 
211 #endif
212