1 /******************************************************************************
2 *
3 * Copyright 1999-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #pragma once
20
21 #include <stdint.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module";
28
29 /* BTE tracing IDs for debug purposes */
30 /* LayerIDs for stack */
31 #define BTTRC_ID_STK_GKI 1
32 #define BTTRC_ID_STK_BTU 2
33 #define BTTRC_ID_STK_HCI 3
34 #define BTTRC_ID_STK_L2CAP 4
35 #define BTTRC_ID_STK_RFCM_MX 5
36 #define BTTRC_ID_STK_RFCM_PRT 6
37 #define BTTRC_ID_STK_OBEX_C 7
38 #define BTTRC_ID_STK_OBEX_S 8
39 #define BTTRC_ID_STK_AVCT 9
40 #define BTTRC_ID_STK_AVDT 10
41 #define BTTRC_ID_STK_AVRC 11
42 #define BTTRC_ID_STK_BIC 12
43 #define BTTRC_ID_STK_BIS 13
44 #define BTTRC_ID_STK_BNEP 14
45 #define BTTRC_ID_STK_BPP 15
46 #define BTTRC_ID_STK_BTM_ACL 16
47 #define BTTRC_ID_STK_BTM_PM 17
48 #define BTTRC_ID_STK_BTM_DEV_CTRL 18
49 #define BTTRC_ID_STK_BTM_SVC_DSC 19
50 #define BTTRC_ID_STK_BTM_INQ 20
51 #define BTTRC_ID_STK_BTM_SCO 21
52 #define BTTRC_ID_STK_BTM_SEC 22
53 #define BTTRC_ID_STK_HID 24
54 #define BTTRC_ID_STK_HSP2 25
55 #define BTTRC_ID_STK_CTP 26
56 #define BTTRC_ID_STK_FTC 27
57 #define BTTRC_ID_STK_FTS 28
58 #define BTTRC_ID_STK_HCRP 31
59 #define BTTRC_ID_STK_ICP 32
60 #define BTTRC_ID_STK_OPC 33
61 #define BTTRC_ID_STK_OPS 34
62 #define BTTRC_ID_STK_PAN 35
63 #define BTTRC_ID_STK_SAP 36
64 #define BTTRC_ID_STK_SDP 37
65 #define BTTRC_ID_STK_SLIP 38
66 #define BTTRC_ID_STK_SPP 39
67 #define BTTRC_ID_STK_TCS 40
68 #define BTTRC_ID_STK_VDP 41
69 #define BTTRC_ID_STK_MCAP 42
70 #define BTTRC_ID_STK_GATT 43
71 #define BTTRC_ID_STK_SMP 44
72 #define BTTRC_ID_STK_NFC 45
73 #define BTTRC_ID_STK_NCI 46
74 #define BTTRC_ID_STK_IDEP 47
75 #define BTTRC_ID_STK_NDEP 48
76 #define BTTRC_ID_STK_LLCP 49
77 #define BTTRC_ID_STK_RW 50
78 #define BTTRC_ID_STK_CE 51
79 #define BTTRC_ID_STK_SNEP 52
80 #define BTTRC_ID_STK_NDEF 53
81 #define BTTRC_ID_STK_HIDD 54
82
83 /* LayerIDs for BTA */
84 #define BTTRC_ID_BTA_ACC 55 /* Advanced Camera Client */
85 #define BTTRC_ID_BTA_AG 56 /* audio gateway */
86 #define BTTRC_ID_BTA_AV 57 /* Advanced audio */
87 #define BTTRC_ID_BTA_BIC 58 /* Basic Imaging Client */
88 #define BTTRC_ID_BTA_BIS 59 /* Basic Imaging Server */
89 #define BTTRC_ID_BTA_BP 60 /* Basic Printing Client */
90 #define BTTRC_ID_BTA_CG 61
91 #define BTTRC_ID_BTA_CT 62 /* cordless telephony terminal */
92 #define BTTRC_ID_BTA_DG 63 /* data gateway */
93 #define BTTRC_ID_BTA_DM 64 /* device manager */
94 #define BTTRC_ID_BTA_DM_SRCH 65 /* device manager search */
95 #define BTTRC_ID_BTA_DM_SEC 66 /* device manager security */
96 #define BTTRC_ID_BTA_FM 67
97 #define BTTRC_ID_BTA_FTC 68 /* file transfer client */
98 #define BTTRC_ID_BTA_FTS 69 /* file transfer server */
99 #define BTTRC_ID_BTA_HIDH 70
100 #define BTTRC_ID_BTA_HIDD 71
101 #define BTTRC_ID_BTA_JV 72
102 #define BTTRC_ID_BTA_OPC 73 /* object push client */
103 #define BTTRC_ID_BTA_OPS 74 /* object push server */
104 #define BTTRC_ID_BTA_PAN 75 /* Personal Area Networking */
105 #define BTTRC_ID_BTA_PR 76 /* Printer client */
106 #define BTTRC_ID_BTA_SC 77 /* SIM Card Access server */
107 #define BTTRC_ID_BTA_SS 78 /* synchronization server */
108 #define BTTRC_ID_BTA_SYS 79 /* system manager */
109 #define BTTRC_ID_AVDT_SCB 80 /* avdt scb */
110 #define BTTRC_ID_AVDT_CCB 81 /* avdt ccb */
111
112 /* LayerIDs added for BTL-A. Probably should modify bte_logmsg.cc in future. */
113 #define BTTRC_ID_STK_RFCOMM 82
114 #define BTTRC_ID_STK_RFCOMM_DATA 83
115 #define BTTRC_ID_STK_OBEX 84
116 #define BTTRC_ID_STK_A2DP 85
117 #define BTTRC_ID_STK_BIP 86
118
119 /* LayerIDs for BT APP */
120 #define BTTRC_ID_BTAPP 87
121 /* this is a temporary solution to allow dynamic enable/disable of
122 * BT_PROTOCOL_TRACE */
123 #define BTTRC_ID_BT_PROTOCOL 88
124 #define BTTRC_ID_MAX_ID BTTRC_ID_BT_PROTOCOL
125 #define BTTRC_ID_ALL_LAYERS 0xFF /* all trace layers */
126
127 /******************************************************************************
128 *
129 * Trace Levels
130 *
131 * The following values may be used for different levels:
132 * BT_TRACE_LEVEL_NONE 0 * No trace messages to be generated
133 * BT_TRACE_LEVEL_ERROR 1 * Error condition trace messages
134 * BT_TRACE_LEVEL_WARNING 2 * Warning condition trace messages
135 * BT_TRACE_LEVEL_API 3 * API traces
136 * BT_TRACE_LEVEL_EVENT 4 * Debug messages for events
137 * BT_TRACE_LEVEL_DEBUG 5 * Debug messages (general)
138 *****************************************************************************/
139
140 /* Core Stack default trace levels */
141 #ifndef HCI_INITIAL_TRACE_LEVEL
142 #define HCI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
143 #endif
144
145 #ifndef BTM_INITIAL_TRACE_LEVEL
146 #define BTM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
147 #endif
148
149 #ifndef L2CAP_INITIAL_TRACE_LEVEL
150 #define L2CAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
151 #endif
152
153 #ifndef RFCOMM_INITIAL_TRACE_LEVEL
154 #define RFCOMM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
155 #endif
156
157 #ifndef SDP_INITIAL_TRACE_LEVEL
158 #define SDP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
159 #endif
160
161 #ifndef BNEP_INITIAL_TRACE_LEVEL
162 #define BNEP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
163 #endif
164
165 #ifndef PAN_INITIAL_TRACE_LEVEL
166 #define PAN_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
167 #endif
168
169 #ifndef A2DP_INITIAL_TRACE_LEVEL
170 #define A2DP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
171 #endif
172
173 #ifndef AVDT_INITIAL_TRACE_LEVEL
174 #define AVDT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
175 #endif
176
177 #ifndef AVCT_INITIAL_TRACE_LEVEL
178 #define AVCT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
179 #endif
180
181 #ifndef AVRC_INITIAL_TRACE_LEVEL
182 #define AVRC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
183 #endif
184
185 #ifndef MCA_INITIAL_TRACE_LEVEL
186 #define MCA_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
187 #endif
188
189 #ifndef HID_INITIAL_TRACE_LEVEL
190 #define HID_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
191 #endif
192
193 #ifndef APPL_INITIAL_TRACE_LEVEL
194 #define APPL_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
195 #endif
196
197 #ifndef GATT_INITIAL_TRACE_LEVEL
198 #define GATT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
199 #endif
200
201 #ifndef SMP_INITIAL_TRACE_LEVEL
202 #define SMP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
203 #endif
204
205 #define BT_TRACE(l, t, ...) \
206 LogMsg((TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t)), ##__VA_ARGS__)
207
208 /* Define tracing for the HCI unit */
209 #define HCI_TRACE_ERROR(...) \
210 { \
211 if (btu_trace_level >= BT_TRACE_LEVEL_ERROR) \
212 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
213 }
214 #define HCI_TRACE_WARNING(...) \
215 { \
216 if (btu_trace_level >= BT_TRACE_LEVEL_WARNING) \
217 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
218 }
219 #define HCI_TRACE_EVENT(...) \
220 { \
221 if (btu_trace_level >= BT_TRACE_LEVEL_EVENT) \
222 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
223 }
224 #define HCI_TRACE_DEBUG(...) \
225 { \
226 if (btu_trace_level >= BT_TRACE_LEVEL_DEBUG) \
227 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
228 }
229
230 /* Define tracing for BTM */
231 #define BTM_TRACE_ERROR(...) \
232 { \
233 if (btm_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
234 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
235 }
236 #define BTM_TRACE_WARNING(...) \
237 { \
238 if (btm_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
239 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
240 }
241 #define BTM_TRACE_API(...) \
242 { \
243 if (btm_cb.trace_level >= BT_TRACE_LEVEL_API) \
244 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_API, ##__VA_ARGS__); \
245 }
246 #define BTM_TRACE_EVENT(...) \
247 { \
248 if (btm_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
249 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
250 }
251 #define BTM_TRACE_DEBUG(...) \
252 { \
253 if (btm_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
254 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
255 }
256
257 /* Define tracing for the L2CAP unit */
258 #define L2CAP_TRACE_ERROR(...) \
259 { \
260 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_ERROR) \
261 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
262 }
263 #define L2CAP_TRACE_WARNING(...) \
264 { \
265 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_WARNING) \
266 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
267 }
268 #define L2CAP_TRACE_API(...) \
269 { \
270 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_API) \
271 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_API, ##__VA_ARGS__); \
272 }
273 #define L2CAP_TRACE_EVENT(...) \
274 { \
275 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_EVENT) \
276 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
277 }
278 #define L2CAP_TRACE_DEBUG(...) \
279 { \
280 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_DEBUG) \
281 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
282 }
283
284 /* Define tracing for the SDP unit */
285 #define SDP_TRACE_ERROR(...) \
286 { \
287 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
288 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
289 }
290 #define SDP_TRACE_WARNING(...) \
291 { \
292 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
293 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
294 }
295 #define SDP_TRACE_API(...) \
296 { \
297 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_API) \
298 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_API, ##__VA_ARGS__); \
299 }
300 #define SDP_TRACE_EVENT(...) \
301 { \
302 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
303 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
304 }
305 #define SDP_TRACE_DEBUG(...) \
306 { \
307 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
308 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
309 }
310
311 /* Define tracing for the RFCOMM unit */
312 #define RFCOMM_TRACE_ERROR(...) \
313 { \
314 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
315 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
316 }
317 #define RFCOMM_TRACE_WARNING(...) \
318 { \
319 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
320 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
321 }
322 #define RFCOMM_TRACE_API(...) \
323 { \
324 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_API) \
325 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_API, ##__VA_ARGS__); \
326 }
327 #define RFCOMM_TRACE_EVENT(...) \
328 { \
329 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
330 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
331 }
332 #define RFCOMM_TRACE_DEBUG(...) \
333 { \
334 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
335 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
336 }
337
338 /* define traces for HID Host */
339 #define HIDH_TRACE_ERROR(...) \
340 { \
341 if (hh_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
342 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
343 }
344 #define HIDH_TRACE_WARNING(...) \
345 { \
346 if (hh_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
347 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
348 }
349 #define HIDH_TRACE_API(...) \
350 { \
351 if (hh_cb.trace_level >= BT_TRACE_LEVEL_API) \
352 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_API, ##__VA_ARGS__); \
353 }
354 #define HIDH_TRACE_EVENT(...) \
355 { \
356 if (hh_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
357 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
358 }
359 #define HIDH_TRACE_DEBUG(...) \
360 { \
361 if (hh_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
362 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
363 }
364
365 /* define traces for HID Device */
366 #define HIDD_TRACE_ERROR(...) \
367 { \
368 if (hd_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
369 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
370 }
371 #define HIDD_TRACE_WARNING(...) \
372 { \
373 if (hd_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
374 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
375 }
376 #define HIDD_TRACE_API(...) \
377 { \
378 if (hd_cb.trace_level >= BT_TRACE_LEVEL_API) \
379 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_API, ##__VA_ARGS__); \
380 }
381 #define HIDD_TRACE_EVENT(...) \
382 { \
383 if (hd_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
384 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
385 }
386 #define HIDD_TRACE_DEBUG(...) \
387 { \
388 if (hd_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
389 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
390 }
391 #define HIDD_TRACE_VERBOSE(...) \
392 { \
393 if (hd_cb.trace_level >= BT_TRACE_LEVEL_VERBOSE) \
394 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
395 }
396
397 /* define traces for BNEP */
398 #define BNEP_TRACE_ERROR(...) \
399 { \
400 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
401 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
402 }
403 #define BNEP_TRACE_WARNING(...) \
404 { \
405 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
406 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
407 }
408 #define BNEP_TRACE_API(...) \
409 { \
410 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_API) \
411 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_API, ##__VA_ARGS__); \
412 }
413 #define BNEP_TRACE_EVENT(...) \
414 { \
415 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
416 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
417 }
418 #define BNEP_TRACE_DEBUG(...) \
419 { \
420 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
421 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
422 }
423
424 /* define traces for PAN */
425 #define PAN_TRACE_ERROR(...) \
426 { \
427 if (pan_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
428 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
429 }
430 #define PAN_TRACE_WARNING(...) \
431 { \
432 if (pan_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
433 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
434 }
435 #define PAN_TRACE_API(...) \
436 { \
437 if (pan_cb.trace_level >= BT_TRACE_LEVEL_API) \
438 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_API, ##__VA_ARGS__); \
439 }
440 #define PAN_TRACE_EVENT(...) \
441 { \
442 if (pan_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
443 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
444 }
445 #define PAN_TRACE_DEBUG(...) \
446 { \
447 if (pan_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
448 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
449 }
450
451 /* Define tracing for the A2DP profile */
452 #define A2DP_TRACE_ERROR(...) \
453 { \
454 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
455 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
456 }
457 #define A2DP_TRACE_WARNING(...) \
458 { \
459 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
460 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
461 }
462 #define A2DP_TRACE_EVENT(...) \
463 { \
464 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
465 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
466 }
467 #define A2DP_TRACE_DEBUG(...) \
468 { \
469 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
470 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
471 }
472 #define A2DP_TRACE_API(...) \
473 { \
474 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_API) \
475 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_API, ##__VA_ARGS__); \
476 }
477
478 /* AVDTP */
479 #define AVDT_TRACE_ERROR(...) \
480 { \
481 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_ERROR) \
482 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
483 }
484 #define AVDT_TRACE_WARNING(...) \
485 { \
486 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_WARNING) \
487 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
488 }
489 #define AVDT_TRACE_EVENT(...) \
490 { \
491 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_EVENT) \
492 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
493 }
494 #define AVDT_TRACE_DEBUG(...) \
495 { \
496 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_DEBUG) \
497 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
498 }
499 #define AVDT_TRACE_API(...) \
500 { \
501 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_API) \
502 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
503 }
504
505 /* Define tracing for the AVCTP protocol */
506 #define AVCT_TRACE_ERROR(...) \
507 { \
508 if (avct_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
509 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
510 }
511 #define AVCT_TRACE_WARNING(...) \
512 { \
513 if (avct_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
514 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
515 }
516 #define AVCT_TRACE_EVENT(...) \
517 { \
518 if (avct_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
519 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
520 }
521 #define AVCT_TRACE_DEBUG(...) \
522 { \
523 if (avct_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
524 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
525 }
526 #define AVCT_TRACE_API(...) \
527 { \
528 if (avct_cb.trace_level >= BT_TRACE_LEVEL_API) \
529 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
530 }
531
532 /* Define tracing for the AVRCP profile */
533 #define AVRC_TRACE_ERROR(...) \
534 { \
535 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
536 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
537 }
538 #define AVRC_TRACE_WARNING(...) \
539 { \
540 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
541 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
542 }
543 #define AVRC_TRACE_EVENT(...) \
544 { \
545 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
546 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
547 }
548 #define AVRC_TRACE_DEBUG(...) \
549 { \
550 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
551 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
552 }
553 #define AVRC_TRACE_API(...) \
554 { \
555 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_API) \
556 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
557 }
558
559 /* MCAP */
560 #define MCA_TRACE_ERROR(...) \
561 { \
562 if (mca_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
563 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
564 }
565 #define MCA_TRACE_WARNING(...) \
566 { \
567 if (mca_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
568 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
569 }
570 #define MCA_TRACE_EVENT(...) \
571 { \
572 if (mca_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
573 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
574 }
575 #define MCA_TRACE_DEBUG(...) \
576 { \
577 if (mca_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
578 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
579 }
580 #define MCA_TRACE_API(...) \
581 { \
582 if (mca_cb.trace_level >= BT_TRACE_LEVEL_API) \
583 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_API, ##__VA_ARGS__); \
584 }
585
586 /* Define tracing for the SMP unit */
587 #define SMP_TRACE_ERROR(...) \
588 { \
589 if (smp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
590 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
591 }
592 #define SMP_TRACE_WARNING(...) \
593 { \
594 if (smp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
595 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
596 }
597 #define SMP_TRACE_API(...) \
598 { \
599 if (smp_cb.trace_level >= BT_TRACE_LEVEL_API) \
600 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_API, ##__VA_ARGS__); \
601 }
602 #define SMP_TRACE_EVENT(...) \
603 { \
604 if (smp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
605 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
606 }
607 #define SMP_TRACE_DEBUG(...) \
608 { \
609 if (smp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
610 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
611 }
612
613 extern uint8_t btif_trace_level;
614
615 /* define traces for application */
616 #define BTIF_TRACE_ERROR(...) \
617 { \
618 if (btif_trace_level >= BT_TRACE_LEVEL_ERROR) \
619 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
620 TRACE_TYPE_ERROR, \
621 ##__VA_ARGS__); \
622 }
623 #define BTIF_TRACE_WARNING(...) \
624 { \
625 if (btif_trace_level >= BT_TRACE_LEVEL_WARNING) \
626 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
627 TRACE_TYPE_WARNING, \
628 ##__VA_ARGS__); \
629 }
630 #define BTIF_TRACE_API(...) \
631 { \
632 if (btif_trace_level >= BT_TRACE_LEVEL_API) \
633 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
634 TRACE_TYPE_API, \
635 ##__VA_ARGS__); \
636 }
637 #define BTIF_TRACE_EVENT(...) \
638 { \
639 if (btif_trace_level >= BT_TRACE_LEVEL_EVENT) \
640 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
641 TRACE_TYPE_EVENT, \
642 ##__VA_ARGS__); \
643 }
644 #define BTIF_TRACE_DEBUG(...) \
645 { \
646 if (btif_trace_level >= BT_TRACE_LEVEL_DEBUG) \
647 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
648 TRACE_TYPE_DEBUG, \
649 ##__VA_ARGS__); \
650 }
651 #define BTIF_TRACE_VERBOSE(...) \
652 { \
653 if (btif_trace_level >= BT_TRACE_LEVEL_VERBOSE) \
654 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
655 TRACE_TYPE_DEBUG, \
656 ##__VA_ARGS__); \
657 }
658
659 /* define traces for application */
660 #define APPL_TRACE_ERROR(...) \
661 { \
662 if (appl_trace_level >= BT_TRACE_LEVEL_ERROR) \
663 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
664 TRACE_TYPE_ERROR, \
665 ##__VA_ARGS__); \
666 }
667 #define APPL_TRACE_WARNING(...) \
668 { \
669 if (appl_trace_level >= BT_TRACE_LEVEL_WARNING) \
670 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
671 TRACE_TYPE_WARNING, \
672 ##__VA_ARGS__); \
673 }
674 #define APPL_TRACE_API(...) \
675 { \
676 if (appl_trace_level >= BT_TRACE_LEVEL_API) \
677 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
678 TRACE_TYPE_API, \
679 ##__VA_ARGS__); \
680 }
681 #define APPL_TRACE_EVENT(...) \
682 { \
683 if (appl_trace_level >= BT_TRACE_LEVEL_EVENT) \
684 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
685 TRACE_TYPE_EVENT, \
686 ##__VA_ARGS__); \
687 }
688 #define APPL_TRACE_DEBUG(...) \
689 { \
690 if (appl_trace_level >= BT_TRACE_LEVEL_DEBUG) \
691 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
692 TRACE_TYPE_DEBUG, \
693 ##__VA_ARGS__); \
694 }
695 #define APPL_TRACE_VERBOSE(...) \
696 { \
697 if (appl_trace_level >= BT_TRACE_LEVEL_VERBOSE) \
698 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
699 TRACE_TYPE_DEBUG, \
700 ##__VA_ARGS__); \
701 }
702
703 typedef uint8_t tBTTRC_LAYER_ID;
704 typedef uint8_t(tBTTRC_SET_TRACE_LEVEL)(uint8_t);
705
706 typedef struct {
707 const tBTTRC_LAYER_ID layer_id_start;
708 const tBTTRC_LAYER_ID layer_id_end;
709 tBTTRC_SET_TRACE_LEVEL* p_f;
710 const char* trc_name;
711 uint8_t trace_level;
712 } tBTTRC_FUNC_MAP;
713
714 /* External declaration for appl_trace_level here to avoid to add the
715 * declaration in all the files using APPL_TRACExxx macros */
716 extern uint8_t appl_trace_level;
717
718 void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...);
719
720 #ifdef __cplusplus
721 }
722 #endif
723
724 #ifdef __cplusplus
725
726 #include <iomanip>
727 #include <sstream>
728 #include <type_traits>
729
730 #include <base/logging.h>
731
732 /* Prints intergral parameter x as hex string, with '0' fill */
733 template <typename T>
loghex(T x)734 std::string loghex(T x) {
735 static_assert(std::is_integral<T>::value,
736 "loghex parameter must be integral.");
737 std::stringstream tmp;
738 tmp << std::showbase << std::internal << std::hex << std::setfill('0')
739 << std::setw((sizeof(T) * 2) + 2) << +x;
740 return tmp.str();
741 }
742
743 /**
744 * Obtains the string representation of a boolean value.
745 *
746 * @param value the boolean value to use
747 * @return the string representation of the boolean value: "true" or "false"
748 */
logbool(bool value)749 inline std::string logbool(bool value) {
750 std::stringstream tmp;
751 tmp << std::boolalpha << value;
752 return tmp.str();
753 }
754
755 /**
756 * Append a field name to a string.
757 *
758 * The field names are added to the string with "|" in between.
759 *
760 * @param p_result a pointer to the result string to add the field name to
761 * @param append if true the field name will be added
762 * @param name the field name to add
763 * @return the result string
764 */
AppendField(std::string * p_result,bool append,const std::string & name)765 inline std::string& AppendField(std::string* p_result, bool append,
766 const std::string& name) {
767 CHECK(p_result != nullptr);
768 if (!append) return *p_result;
769 if (!p_result->empty()) *p_result += "|";
770 *p_result += name;
771 return *p_result;
772 }
773
774 #endif
775