xref: /wlan-dirver/qca-wifi-host-cmn/utils/host_diag_log/src/host_diag_log.c (revision 9c7c6259caebb6343ad4f3e96049fb50a48d75e7)
1 /*
2  * Copyright (c) 2014-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:         host_diag_log.c
21 
22    OVERVIEW:     This source file contains definitions for WLAN UTIL diag APIs
23 
24    DEPENDENCIES:
25    ============================================================================*/
26 
27 #include "qdf_types.h"
28 #include "i_host_diag_core_log.h"
29 #include "host_diag_core_event.h"
30 #include "wlan_nlink_common.h"
31 #include "cds_sched.h"
32 #include "wlan_ptt_sock_svc.h"
33 #include "wlan_nlink_srv.h"
34 #include "cds_api.h"
35 #include "wlan_ps_wow_diag.h"
36 #include "qdf_str.h"
37 
38 #define PTT_MSG_DIAG_CMDS_TYPE   (0x5050)
39 
40 #define DIAG_TYPE_LOGS   (1)
41 #define DIAG_TYPE_EVENTS (2)
42 
43 #define DIAG_SWAP16(A) ((((uint16_t)(A) & 0xff00) >> 8) | (((uint16_t)(A) & 0x00ff) << 8))
44 
45 typedef struct event_report_s {
46 	uint32_t diag_type;
47 	uint16_t event_id;
48 	uint16_t length;
49 } event_report_t;
50 
51 /**---------------------------------------------------------------------------
52 
53    \brief host_diag_log_set_code() -
54 
55    This function sets the logging code in the given log record.
56 
57    \param  - ptr - Pointer to the log header type.
58 		- code - log code.
59    \return - None
60 
61    --------------------------------------------------------------------------*/
62 
63 void host_diag_log_set_code(void *ptr, uint16_t code)
64 {
65 	if (ptr) {
66 		/* All log packets are required to start with 'log_header_type' */
67 		((log_hdr_type *) ptr)->code = code;
68 	}
69 }
70 
71 /**---------------------------------------------------------------------------
72 
73    \brief host_diag_log_set_length() -
74 
75    This function sets the length field in the given log record.
76 
77    \param  - ptr - Pointer to the log header type.
78 		- length - log length.
79 
80    \return - None
81 
82    --------------------------------------------------------------------------*/
83 
84 void host_diag_log_set_length(void *ptr, uint16_t length)
85 {
86 	if (ptr) {
87 		/* All log packets are required to start with 'log_header_type' */
88 		((log_hdr_type *) ptr)->len = (uint16_t) length;
89 	}
90 }
91 
92 /**---------------------------------------------------------------------------
93 
94    \brief host_diag_log_submit() -
95 
96    This function sends the log data to the ptt socket app only if it is registered with the driver.
97 
98    \param  - ptr - Pointer to the log header type.
99 
100    \return - None
101 
102    --------------------------------------------------------------------------*/
103 
104 void host_diag_log_submit(void *plog_hdr_ptr)
105 {
106 	log_hdr_type *pHdr = (log_hdr_type *) plog_hdr_ptr;
107 	tAniHdr *wmsg = NULL;
108 	uint8_t *pBuf;
109 	uint16_t data_len;
110 	uint16_t total_len;
111 
112 	if (cds_is_load_or_unload_in_progress())
113 		return;
114 
115 	if (nl_srv_is_initialized() != 0)
116 		return;
117 
118 	if (cds_is_multicast_logging()) {
119 		data_len = pHdr->len;
120 
121 		total_len = sizeof(tAniHdr) + sizeof(uint32_t) + data_len;
122 
123 		pBuf = (uint8_t *) qdf_mem_malloc(total_len);
124 
125 		if (!pBuf)
126 			return;
127 
128 		wmsg = (tAniHdr *) pBuf;
129 		wmsg->type = PTT_MSG_DIAG_CMDS_TYPE;
130 		wmsg->length = total_len;
131 		wmsg->length = DIAG_SWAP16(wmsg->length);
132 		pBuf += sizeof(tAniHdr);
133 
134 		/*  Diag Type events or log */
135 		*(uint32_t *) pBuf = DIAG_TYPE_LOGS;
136 		pBuf += sizeof(uint32_t);
137 
138 		memcpy(pBuf, pHdr, data_len);
139 		ptt_sock_send_msg_to_app (wmsg, 0, ANI_NL_MSG_PUMAC,
140 			INVALID_PID);
141 		qdf_mem_free((void *)wmsg);
142 	}
143 	return;
144 }
145 
146 /**
147  * host_diag_log_wlock() - This function is used to send wake lock diag events
148  * @reason: Reason why the wakelock was taken or released
149  * @wake_lock_name: Function in which the wakelock was taken or released
150  * @timeout: Timeout value in case of timed wakelocks
151  * @status: Status field indicating whether the wake lock was taken/released
152  *
153  * This function is used to send wake lock diag events to user space
154  *
155  * Return: None
156  *
157  */
158 void host_diag_log_wlock(uint32_t reason, const char *wake_lock_name,
159 		uint32_t timeout, uint32_t status)
160 {
161 	WLAN_HOST_DIAG_EVENT_DEF(wlan_diag_event,
162 			struct host_event_wlan_wake_lock);
163 
164 	if ((nl_srv_is_initialized() != 0) ||
165 	    (cds_is_wakelock_enabled() == false))
166 		return;
167 
168 	wlan_diag_event.status = status;
169 	wlan_diag_event.reason = reason;
170 	wlan_diag_event.timeout = timeout;
171 	wlan_diag_event.name_len = strlen(wake_lock_name);
172 	strlcpy(&wlan_diag_event.name[0],
173 			wake_lock_name,
174 			wlan_diag_event.name_len+1);
175 
176 	WLAN_HOST_DIAG_EVENT_REPORT(&wlan_diag_event, EVENT_WLAN_WAKE_LOCK);
177 }
178 
179 /**---------------------------------------------------------------------------
180 
181    \brief host_diag_event_report_payload() -
182 
183    This function sends the event data to the ptt socket app only if it is
184    registered with the driver.
185 
186    \param  - ptr - Pointer to the log header type.
187 
188    \return - None
189 
190    --------------------------------------------------------------------------*/
191 
192 void host_diag_event_report_payload(uint16_t event_Id, uint16_t length,
193 				    void *pPayload)
194 {
195 	tAniHdr *wmsg = NULL;
196 	uint8_t *pBuf;
197 	event_report_t *pEvent_report;
198 	uint16_t total_len;
199 
200 	if (cds_is_load_or_unload_in_progress())
201 		return;
202 
203 	if (nl_srv_is_initialized() != 0)
204 		return;
205 
206 	if (cds_is_multicast_logging()) {
207 		total_len = sizeof(tAniHdr) + sizeof(event_report_t) + length;
208 
209 		pBuf = (uint8_t *) qdf_mem_malloc(total_len);
210 
211 		if (!pBuf)
212 			return;
213 
214 		wmsg = (tAniHdr *) pBuf;
215 		wmsg->type = PTT_MSG_DIAG_CMDS_TYPE;
216 		wmsg->length = total_len;
217 		wmsg->length = DIAG_SWAP16(wmsg->length);
218 		pBuf += sizeof(tAniHdr);
219 
220 		pEvent_report = (event_report_t *) pBuf;
221 		pEvent_report->diag_type = DIAG_TYPE_EVENTS;
222 		pEvent_report->event_id = event_Id;
223 		pEvent_report->length = length;
224 
225 		pBuf += sizeof(event_report_t);
226 
227 		memcpy(pBuf, pPayload, length);
228 
229 		if (ptt_sock_send_msg_to_app
230 			    (wmsg, 0, ANI_NL_MSG_PUMAC, INVALID_PID) < 0) {
231 			QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_WARN,
232 				  "Ptt Socket error sending message to the app!!");
233 			qdf_mem_free((void *)wmsg);
234 			return;
235 		}
236 
237 		qdf_mem_free((void *)wmsg);
238 	}
239 
240 	return;
241 
242 }
243 
244 /**
245  * host_log_low_resource_failure() - This function is used to send low
246  * resource failure event
247  * @event_sub_type: Reason why the failure was observed
248  *
249  * This function is used to send low resource failure events to user space
250  *
251  * Return: None
252  *
253  */
254 void host_log_low_resource_failure(uint8_t event_sub_type)
255 {
256 	WLAN_HOST_DIAG_EVENT_DEF(wlan_diag_event,
257 			struct host_event_wlan_low_resource_failure);
258 
259 	wlan_diag_event.event_sub_type = event_sub_type;
260 
261 	WLAN_HOST_DIAG_EVENT_REPORT(&wlan_diag_event,
262 					EVENT_WLAN_LOW_RESOURCE_FAILURE);
263 }
264 
265 void host_log_rsn_info(uint8_t *ucast_cipher, uint8_t *mcast_cipher,
266 		       uint8_t *akm_suite, uint8_t *group_mgmt)
267 {
268 	WLAN_HOST_DIAG_EVENT_DEF(wlan_diag_event,
269 				 struct event_wlan_csr_rsn_info);
270 
271 	qdf_mem_copy(wlan_diag_event.ucast_cipher, ucast_cipher,
272 		     RSN_OUI_SIZE);
273 	qdf_mem_copy(wlan_diag_event.mcast_cipher, mcast_cipher,
274 		     RSN_OUI_SIZE);
275 	qdf_mem_copy(wlan_diag_event.akm_suite, akm_suite,
276 		     RSN_OUI_SIZE);
277 	qdf_mem_copy(wlan_diag_event.group_mgmt, group_mgmt,
278 		     RSN_OUI_SIZE);
279 
280 	WLAN_HOST_DIAG_EVENT_REPORT(&wlan_diag_event,
281 				    EVENT_WLAN_RSN_INFO);
282 }
283 
284 void
285 host_log_wlan_auth_info(uint16_t auth_algo_num, uint16_t auth_tx_seq_num,
286 			uint16_t auth_status_code)
287 {
288 	WLAN_HOST_DIAG_EVENT_DEF(wlan_diag_event,
289 				 struct event_wlan_lim_auth_info);
290 
291 	wlan_diag_event.auth_algo_num = auth_algo_num;
292 	wlan_diag_event.auth_transaction_seq_num = auth_tx_seq_num;
293 	wlan_diag_event.auth_status_code = auth_status_code;
294 
295 	WLAN_HOST_DIAG_EVENT_REPORT(&wlan_diag_event,
296 				    EVENT_WLAN_AUTH_INFO);
297 }
298 
299 #ifdef FEATURE_WLAN_DIAG_SUPPORT
300 /**
301  * qdf_wow_wakeup_host_event()- send wow wakeup event
302  * @wow_wakeup_cause: WOW wakeup reason code
303  *
304  * This function sends wow wakeup reason code diag event
305  *
306  * Return: void.
307  */
308 void qdf_wow_wakeup_host_event(uint8_t wow_wakeup_cause)
309 {
310 	WLAN_HOST_DIAG_EVENT_DEF(wowRequest,
311 		host_event_wlan_powersave_wow_payload_type);
312 	qdf_mem_zero(&wowRequest, sizeof(wowRequest));
313 
314 	wowRequest.event_subtype = WLAN_WOW_WAKEUP;
315 	wowRequest.wow_wakeup_cause = wow_wakeup_cause;
316 	WLAN_HOST_DIAG_EVENT_REPORT(&wowRequest,
317 		EVENT_WLAN_POWERSAVE_WOW);
318 }
319 
320 void host_log_acs_req_event(uint8_t *intf, const uint8_t *hw_mode, uint16_t bw,
321 			    uint8_t ht, uint8_t vht, uint16_t chan_start,
322 			    uint16_t chan_end)
323 {
324 	WLAN_HOST_DIAG_EVENT_DEF(acs_req, struct host_event_wlan_acs_req);
325 
326 	qdf_str_lcopy(acs_req.intf, intf, HOST_EVENT_INTF_STR_LEN);
327 	qdf_str_lcopy(acs_req.hw_mode, hw_mode, HOST_EVENT_HW_MODE_STR_LEN);
328 	acs_req.bw = bw;
329 	acs_req.ht = ht;
330 	acs_req.vht = vht;
331 	acs_req.chan_start = chan_start;
332 	acs_req.chan_end = chan_end;
333 
334 	WLAN_HOST_DIAG_EVENT_REPORT(&acs_req, EVENT_WLAN_ACS_REQ);
335 }
336 
337 void host_log_acs_scan_start(uint32_t scan_id, uint8_t vdev_id)
338 {
339 	WLAN_HOST_DIAG_EVENT_DEF(acs_scan_start,
340 				 struct host_event_wlan_acs_scan_start);
341 
342 	acs_scan_start.scan_id = scan_id;
343 	acs_scan_start.vdev_id = vdev_id;
344 
345 	WLAN_HOST_DIAG_EVENT_REPORT(&acs_scan_start,
346 				    EVENT_WLAN_ACS_SCAN_START);
347 }
348 
349 void host_log_acs_scan_done(const uint8_t *status,
350 			    uint8_t vdev_id, uint32_t scan_id)
351 {
352 	WLAN_HOST_DIAG_EVENT_DEF(acs_scan_done,
353 				 struct host_event_wlan_acs_scan_done);
354 
355 	qdf_str_lcopy(acs_scan_done.status, status, HOST_EVENT_STATUS_STR_LEN);
356 	acs_scan_done.vdev_id = vdev_id;
357 	acs_scan_done.scan_id = scan_id;
358 
359 	WLAN_HOST_DIAG_EVENT_REPORT(&acs_scan_done, EVENT_WLAN_ACS_SCAN_DONE);
360 }
361 
362 void host_log_acs_chan_spect_weight(uint16_t chan, uint16_t weight,
363 				    int32_t rssi, uint16_t bss_count)
364 {
365 	WLAN_HOST_DIAG_EVENT_DEF(
366 		acs_chan_spect_weight,
367 		struct host_event_wlan_acs_chan_spectral_weight);
368 
369 	acs_chan_spect_weight.chan = chan;
370 	acs_chan_spect_weight.weight = weight;
371 	acs_chan_spect_weight.rssi = rssi;
372 	acs_chan_spect_weight.bss_count = bss_count;
373 
374 	WLAN_HOST_DIAG_EVENT_REPORT(&acs_chan_spect_weight,
375 				    EVENT_WLAN_ACS_CHANNEL_SPECTRAL_WEIGHT);
376 }
377 
378 void host_log_acs_best_chan(uint16_t chan, uint16_t weight)
379 {
380 	WLAN_HOST_DIAG_EVENT_DEF(acs_best_chan,
381 				 struct host_event_wlan_acs_best_chan);
382 
383 	acs_best_chan.chan = chan;
384 	acs_best_chan.weight = weight;
385 
386 	WLAN_HOST_DIAG_EVENT_REPORT(&acs_best_chan,
387 				    EVENT_WLAN_ACS_BEST_CHANNEL);
388 }
389 
390 #endif
391