1 /*
2  * Copyright (c) 2013-2020 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 
22    \file  lim_trace.c
23 
24    \brief implementation for trace related APIs
25 
26    \author Sunit Bhatia
27 
28    ========================================================================*/
29 
30 /*--------------------------------------------------------------------------
31    Include Files
32    ------------------------------------------------------------------------*/
33 
34 #include "ani_global.h"          /* for struct mac_context **/
35 
36 #include "lim_trace.h"
37 #include "lim_timer_utils.h"
38 #include "qdf_trace.h"
39 
40 #ifdef LIM_TRACE_RECORD
41 
42 #define LIM_TRACE_MAX_SUBTYPES 14
43 
__lim_trace_get_timer_string(uint16_t timerId)44 static uint8_t *__lim_trace_get_timer_string(uint16_t timerId)
45 {
46 	switch (timerId) {
47 		CASE_RETURN_STRING(eLIM_MIN_CHANNEL_TIMER);
48 		CASE_RETURN_STRING(eLIM_MAX_CHANNEL_TIMER);
49 		CASE_RETURN_STRING(eLIM_JOIN_FAIL_TIMER);
50 		CASE_RETURN_STRING(eLIM_AUTH_FAIL_TIMER);
51 		CASE_RETURN_STRING(eLIM_AUTH_RESP_TIMER);
52 		CASE_RETURN_STRING(eLIM_ASSOC_FAIL_TIMER);
53 		CASE_RETURN_STRING(eLIM_REASSOC_FAIL_TIMER);
54 		CASE_RETURN_STRING(eLIM_PRE_AUTH_CLEANUP_TIMER);
55 		CASE_RETURN_STRING(eLIM_CNF_WAIT_TIMER);
56 		CASE_RETURN_STRING(eLIM_AUTH_RSP_TIMER);
57 		CASE_RETURN_STRING(eLIM_UPDATE_OLBC_CACHE_TIMER);
58 		CASE_RETURN_STRING(eLIM_ADDTS_RSP_TIMER);
59 		CASE_RETURN_STRING(eLIM_CHANNEL_SWITCH_TIMER);
60 		CASE_RETURN_STRING(eLIM_WPS_OVERLAP_TIMER);
61 		CASE_RETURN_STRING(eLIM_FT_PREAUTH_RSP_TIMER);
62 		CASE_RETURN_STRING(eLIM_REMAIN_CHN_TIMER);
63 		CASE_RETURN_STRING(eLIM_DISASSOC_ACK_TIMER);
64 		CASE_RETURN_STRING(eLIM_DEAUTH_ACK_TIMER);
65 		CASE_RETURN_STRING(eLIM_PERIODIC_JOIN_PROBE_REQ_TIMER);
66 		CASE_RETURN_STRING(eLIM_AUTH_RETRY_TIMER);
67 		CASE_RETURN_STRING(eLIM_RRM_STA_STATS_RSP_TIMER);
68 	default:
69 		return "UNKNOWN";
70 		break;
71 	}
72 }
73 
__lim_trace_get_mgmt_drop_reason_string(uint16_t dropReason)74 static uint8_t *__lim_trace_get_mgmt_drop_reason_string(uint16_t dropReason)
75 {
76 
77 	switch (dropReason) {
78 		CASE_RETURN_STRING(eMGMT_DROP_INFRA_BCN_IN_IBSS);
79 		CASE_RETURN_STRING(eMGMT_DROP_INVALID_SIZE);
80 		CASE_RETURN_STRING(eMGMT_DROP_NON_SCAN_MODE_FRAME);
81 		CASE_RETURN_STRING(eMGMT_DROP_NOT_LAST_IBSS_BCN);
82 		CASE_RETURN_STRING(eMGMT_DROP_NO_DROP);
83 		CASE_RETURN_STRING(eMGMT_DROP_SCAN_MODE_FRAME);
84 		CASE_RETURN_STRING(eMGMT_DROP_SPURIOUS_FRAME);
85 
86 	default:
87 		return "UNKNOWN";
88 		break;
89 	}
90 }
91 
lim_trace_init(struct mac_context * mac)92 void lim_trace_init(struct mac_context *mac)
93 {
94 	qdf_trace_register(QDF_MODULE_ID_PE, &lim_trace_dump);
95 }
96 
lim_trace_dump(void * mac,tp_qdf_trace_record pRecord,uint16_t recIndex)97 void lim_trace_dump(void *mac, tp_qdf_trace_record pRecord,
98 		    uint16_t recIndex)
99 {
100 	static char *frameSubtypeStr[LIM_TRACE_MAX_SUBTYPES] = {
101 		"Association request",
102 		"Association response",
103 		"Reassociation request",
104 		"Reassociation response",
105 		"Probe request",
106 		"Probe response",
107 		NULL,
108 		NULL,
109 		"Beacon",
110 		"ATIM",
111 		"Disassociation",
112 		"Authentication",
113 		"Deauthentication",
114 		"Action"
115 	};
116 
117 	switch (pRecord->code) {
118 	case TRACE_CODE_MLM_STATE:
119 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
120 			      pRecord->qtime, pRecord->time, pRecord->session,
121 			     "MLM State:",
122 			      lim_trace_get_mlm_state_string(
123 						(uint16_t)pRecord->data),
124 			      pRecord->data);
125 		break;
126 	case TRACE_CODE_SME_STATE:
127 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
128 			      pRecord->qtime, pRecord->time, pRecord->session,
129 			     "SME State:",
130 			     lim_trace_get_sme_state_string(
131 						(uint16_t)pRecord->data),
132 			     pRecord->data);
133 		break;
134 	case TRACE_CODE_TX_MGMT:
135 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
136 			      pRecord->qtime, pRecord->time, pRecord->session,
137 			      "TX Mgmt:", frameSubtypeStr[pRecord->data],
138 			      pRecord->data);
139 		break;
140 
141 	case TRACE_CODE_RX_MGMT:
142 		if (LIM_TRACE_MAX_SUBTYPES <=
143 		    LIM_TRACE_GET_SUBTYPE(pRecord->data))
144 			pe_nofl_debug("Wrong Subtype - %d",
145 				      LIM_TRACE_GET_SUBTYPE(pRecord->data));
146 		else
147 			pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(%d) SN: %d",
148 				      recIndex, pRecord->qtime, pRecord->time,
149 				      pRecord->session, "RX Mgmt:",
150 				      frameSubtypeStr[LIM_TRACE_GET_SUBTYPE
151 							(pRecord->data)],
152 				      LIM_TRACE_GET_SUBTYPE(pRecord->data),
153 				      LIM_TRACE_GET_SSN(pRecord->data));
154 		break;
155 	case TRACE_CODE_RX_MGMT_DROP:
156 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(%d)",
157 			      recIndex, pRecord->qtime, pRecord->time,
158 			      pRecord->session, "Drop RX Mgmt:",
159 			      __lim_trace_get_mgmt_drop_reason_string(
160 					(uint16_t)pRecord->data),
161 			      pRecord->data);
162 		break;
163 
164 	case TRACE_CODE_RX_MGMT_TSF:
165 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s0x%x(%d)",
166 			      recIndex, pRecord->qtime, pRecord->time,
167 			      pRecord->session, "RX Mgmt TSF:", " ",
168 			      pRecord->data, pRecord->data);
169 		break;
170 
171 	case TRACE_CODE_TX_COMPLETE:
172 		pe_nofl_debug("%04d %012llu %s S%d %-14s %d", recIndex,
173 			      pRecord->qtime, pRecord->time, pRecord->session,
174 			      "TX Complete", pRecord->data);
175 		break;
176 
177 	case TRACE_CODE_TX_SME_MSG:
178 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
179 			      pRecord->qtime, pRecord->time, pRecord->session,
180 			      "TX SME Msg:",
181 			      mac_trace_get_sme_msg_string((uint16_t)pRecord->data),
182 			      pRecord->data);
183 		break;
184 	case TRACE_CODE_RX_SME_MSG:
185 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
186 			      pRecord->qtime, pRecord->time, pRecord->session,
187 			      LIM_TRACE_GET_DEFRD_OR_DROPPED(
188 			      pRecord->data) ? "Def/Drp LIM Msg:" : "RX Sme Msg:",
189 			      mac_trace_get_sme_msg_string((uint16_t)pRecord->data),
190 			      pRecord->data);
191 		break;
192 
193 	case TRACE_CODE_TX_WMA_MSG:
194 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
195 			      pRecord->qtime, pRecord->time, pRecord->session,
196 			      "TX WMA Msg:",
197 			      mac_trace_get_wma_msg_string((uint16_t)pRecord->data),
198 			      pRecord->data);
199 		break;
200 
201 	case TRACE_CODE_RX_WMA_MSG:
202 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
203 			      pRecord->qtime, pRecord->time, pRecord->session,
204 			      LIM_TRACE_GET_DEFRD_OR_DROPPED(
205 			      pRecord->data) ? "Def/Drp LIM Msg:" : "RX WMA Msg:",
206 			      mac_trace_get_wma_msg_string((uint16_t)pRecord->data),
207 			      pRecord->data);
208 		break;
209 
210 	case TRACE_CODE_TX_LIM_MSG:
211 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
212 			      pRecord->qtime, pRecord->time, pRecord->session,
213 			      "TX LIM Msg:",
214 			      mac_trace_get_lim_msg_string((uint16_t)pRecord->data),
215 			      pRecord->data);
216 		break;
217 	case TRACE_CODE_RX_LIM_MSG:
218 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
219 			      pRecord->qtime, pRecord->time, pRecord->session,
220 			      LIM_TRACE_GET_DEFRD_OR_DROPPED(
221 			      pRecord->data) ? "Def/Drp LIM Msg:" : "RX LIM Msg",
222 			      mac_trace_get_lim_msg_string((uint16_t)pRecord->data),
223 			      pRecord->data);
224 		break;
225 	case TRACE_CODE_TIMER_ACTIVATE:
226 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
227 			      pRecord->qtime, pRecord->time, pRecord->session,
228 			      "Timer Actvtd",
229 			      __lim_trace_get_timer_string((uint16_t)pRecord->data),
230 			      pRecord->data);
231 		break;
232 	case TRACE_CODE_TIMER_DEACTIVATE:
233 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)", recIndex,
234 			      pRecord->qtime, pRecord->time, pRecord->session,
235 			      "Timer DeActvtd",
236 			      __lim_trace_get_timer_string((uint16_t)pRecord->data),
237 			      pRecord->data);
238 		break;
239 
240 	case TRACE_CODE_INFO_LOG:
241 		pe_nofl_debug("%04d %012llu %s S%d %-14s %-30s(0x%x)",
242 			      recIndex, pRecord->qtime, pRecord->time,
243 			      pRecord->session, "INFORMATION_LOG",
244 			      mac_trace_get_info_log_string((uint16_t)pRecord->data),
245 			      pRecord->data);
246 		break;
247 	default:
248 		pe_nofl_debug("%04d %012llu %s S%d %-14s(%d) (0x%x)",
249 			      recIndex, pRecord->qtime, pRecord->time,
250 			      pRecord->session, "Unknown Code",
251 			      pRecord->code, pRecord->data);
252 		break;
253 	}
254 }
255 
mac_trace_msg_tx(struct mac_context * mac,uint8_t session,uint32_t data)256 void mac_trace_msg_tx(struct mac_context *mac, uint8_t session, uint32_t data)
257 {
258 
259 	uint16_t msgId = (uint16_t) MAC_TRACE_GET_MSG_ID(data);
260 	uint8_t module_id = (uint8_t) MAC_TRACE_GET_MODULE_ID(data);
261 
262 	switch (module_id) {
263 	case SIR_LIM_MODULE_ID:
264 		if (msgId >= SIR_LIM_ITC_MSG_TYPES_BEGIN)
265 			mac_trace(mac, TRACE_CODE_TX_LIM_MSG, session, data);
266 		else
267 			mac_trace(mac, TRACE_CODE_TX_SME_MSG, session, data);
268 		break;
269 	case SIR_WMA_MODULE_ID:
270 		mac_trace(mac, TRACE_CODE_TX_WMA_MSG, session, data);
271 		break;
272 	default:
273 		mac_trace(mac, module_id, session, data);
274 		break;
275 	}
276 }
277 
278 /*
279  * bit31: Rx message deferred or not
280  * bit 0-15: message ID:
281  */
mac_trace_msg_rx(struct mac_context * mac,uint8_t session,uint32_t data)282 void mac_trace_msg_rx(struct mac_context *mac, uint8_t session, uint32_t data)
283 {
284 	uint16_t msgId = (uint16_t) MAC_TRACE_GET_MSG_ID(data);
285 	uint8_t module_id = (uint8_t) MAC_TRACE_GET_MODULE_ID(data);
286 
287 	switch (module_id) {
288 	case SIR_LIM_MODULE_ID:
289 		if (msgId >= SIR_LIM_ITC_MSG_TYPES_BEGIN)
290 			mac_trace(mac, TRACE_CODE_RX_LIM_MSG, session, data);
291 		else
292 			mac_trace(mac, TRACE_CODE_RX_SME_MSG, session, data);
293 		break;
294 	case SIR_WMA_MODULE_ID:
295 		mac_trace(mac, TRACE_CODE_RX_WMA_MSG, session, data);
296 		break;
297 	default:
298 		mac_trace(mac, msgId, session, data);
299 		break;
300 	}
301 }
302 
lim_trace_get_mlm_state_string(uint32_t mlmState)303 uint8_t *lim_trace_get_mlm_state_string(uint32_t mlmState)
304 {
305 	switch (mlmState) {
306 		CASE_RETURN_STRING(eLIM_MLM_OFFLINE_STATE);
307 		CASE_RETURN_STRING(eLIM_MLM_IDLE_STATE);
308 		CASE_RETURN_STRING(eLIM_MLM_WT_JOIN_BEACON_STATE);
309 		CASE_RETURN_STRING(eLIM_MLM_JOINED_STATE);
310 		CASE_RETURN_STRING(eLIM_MLM_BSS_STARTED_STATE);
311 		CASE_RETURN_STRING(eLIM_MLM_WT_AUTH_FRAME2_STATE);
312 		CASE_RETURN_STRING(eLIM_MLM_WT_AUTH_FRAME3_STATE);
313 		CASE_RETURN_STRING(eLIM_MLM_WT_AUTH_FRAME4_STATE);
314 		CASE_RETURN_STRING(eLIM_MLM_AUTH_RSP_TIMEOUT_STATE);
315 		CASE_RETURN_STRING(eLIM_MLM_AUTHENTICATED_STATE);
316 		CASE_RETURN_STRING(eLIM_MLM_WT_ASSOC_RSP_STATE);
317 		CASE_RETURN_STRING(eLIM_MLM_WT_REASSOC_RSP_STATE);
318 		CASE_RETURN_STRING(eLIM_MLM_ASSOCIATED_STATE);
319 		CASE_RETURN_STRING(eLIM_MLM_REASSOCIATED_STATE);
320 		CASE_RETURN_STRING(eLIM_MLM_LINK_ESTABLISHED_STATE);
321 		CASE_RETURN_STRING(eLIM_MLM_WT_ASSOC_CNF_STATE);
322 		CASE_RETURN_STRING(eLIM_MLM_WT_ADD_BSS_RSP_STATE);
323 		CASE_RETURN_STRING(eLIM_MLM_WT_DEL_BSS_RSP_STATE);
324 		CASE_RETURN_STRING(eLIM_MLM_WT_ADD_BSS_RSP_ASSOC_STATE);
325 		CASE_RETURN_STRING(eLIM_MLM_WT_ADD_BSS_RSP_PREASSOC_STATE);
326 		CASE_RETURN_STRING(eLIM_MLM_WT_ADD_BSS_RSP_REASSOC_STATE);
327 		CASE_RETURN_STRING(eLIM_MLM_WT_ADD_STA_RSP_STATE);
328 		CASE_RETURN_STRING(eLIM_MLM_WT_DEL_STA_RSP_STATE);
329 		CASE_RETURN_STRING(eLIM_MLM_WT_ASSOC_DEL_STA_RSP_STATE);
330 		CASE_RETURN_STRING(eLIM_MLM_WT_SET_BSS_KEY_STATE);
331 		CASE_RETURN_STRING(eLIM_MLM_WT_SET_STA_KEY_STATE);
332 		CASE_RETURN_STRING(eLIM_MLM_WT_SET_STA_BCASTKEY_STATE);
333 		CASE_RETURN_STRING(eLIM_MLM_WT_ADD_BSS_RSP_FT_REASSOC_STATE);
334 		CASE_RETURN_STRING(eLIM_MLM_WT_FT_REASSOC_RSP_STATE);
335 	default:
336 		return "UNKNOWN";
337 		break;
338 	}
339 }
340 
lim_trace_get_sme_state_string(uint32_t smeState)341 uint8_t *lim_trace_get_sme_state_string(uint32_t smeState)
342 {
343 	switch (smeState) {
344 
345 		CASE_RETURN_STRING(eLIM_SME_OFFLINE_STATE);
346 		CASE_RETURN_STRING(eLIM_SME_IDLE_STATE);
347 		CASE_RETURN_STRING(eLIM_SME_SUSPEND_STATE);
348 		CASE_RETURN_STRING(eLIM_SME_WT_JOIN_STATE);
349 		CASE_RETURN_STRING(eLIM_SME_WT_AUTH_STATE);
350 		CASE_RETURN_STRING(eLIM_SME_WT_ASSOC_STATE);
351 		CASE_RETURN_STRING(eLIM_SME_WT_REASSOC_STATE);
352 		CASE_RETURN_STRING(eLIM_SME_JOIN_FAILURE_STATE);
353 		CASE_RETURN_STRING(eLIM_SME_ASSOCIATED_STATE);
354 		CASE_RETURN_STRING(eLIM_SME_REASSOCIATED_STATE);
355 		CASE_RETURN_STRING(eLIM_SME_LINK_EST_STATE);
356 		CASE_RETURN_STRING(eLIM_SME_WT_PRE_AUTH_STATE);
357 		CASE_RETURN_STRING(eLIM_SME_WT_DISASSOC_STATE);
358 		CASE_RETURN_STRING(eLIM_SME_WT_DEAUTH_STATE);
359 		CASE_RETURN_STRING(eLIM_SME_WT_START_BSS_STATE);
360 		CASE_RETURN_STRING(eLIM_SME_WT_STOP_BSS_STATE);
361 		CASE_RETURN_STRING(eLIM_SME_NORMAL_STATE);
362 	default:
363 		return "UNKNOWN";
364 		break;
365 	}
366 }
367 
368 #endif
369