1 /******************************************************************************
3 * Copyright 1999-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
27 static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module";
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
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 */
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
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 */
127 /******************************************************************************
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 *****************************************************************************/
140 /* Core Stack default trace levels */
141 #ifndef HCI_INITIAL_TRACE_LEVEL
142 #define HCI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
145 #ifndef BTM_INITIAL_TRACE_LEVEL
146 #define BTM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
149 #ifndef L2CAP_INITIAL_TRACE_LEVEL
150 #define L2CAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
153 #ifndef RFCOMM_INITIAL_TRACE_LEVEL
154 #define RFCOMM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
157 #ifndef SDP_INITIAL_TRACE_LEVEL
158 #define SDP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
161 #ifndef BNEP_INITIAL_TRACE_LEVEL
162 #define BNEP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
165 #ifndef PAN_INITIAL_TRACE_LEVEL
166 #define PAN_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
169 #ifndef A2DP_INITIAL_TRACE_LEVEL
170 #define A2DP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
173 #ifndef AVDT_INITIAL_TRACE_LEVEL
174 #define AVDT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
177 #ifndef AVCT_INITIAL_TRACE_LEVEL
178 #define AVCT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
181 #ifndef AVRC_INITIAL_TRACE_LEVEL
182 #define AVRC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
185 #ifndef MCA_INITIAL_TRACE_LEVEL
186 #define MCA_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
189 #ifndef HID_INITIAL_TRACE_LEVEL
190 #define HID_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
193 #ifndef APPL_INITIAL_TRACE_LEVEL
194 #define APPL_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
197 #ifndef GATT_INITIAL_TRACE_LEVEL
198 #define GATT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
201 #ifndef SMP_INITIAL_TRACE_LEVEL
202 #define SMP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
205 #define BT_TRACE(l, t, ...) \
206 LogMsg((TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t)), ##__VA_ARGS__)
208 /* Define tracing for the HCI unit */
209 #define HCI_TRACE_ERROR(...) \
211 if (btu_trace_level >= BT_TRACE_LEVEL_ERROR) \
212 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
214 #define HCI_TRACE_WARNING(...) \
216 if (btu_trace_level >= BT_TRACE_LEVEL_WARNING) \
217 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
219 #define HCI_TRACE_EVENT(...) \
221 if (btu_trace_level >= BT_TRACE_LEVEL_EVENT) \
222 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
224 #define HCI_TRACE_DEBUG(...) \
226 if (btu_trace_level >= BT_TRACE_LEVEL_DEBUG) \
227 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
230 /* Define tracing for BTM */
231 #define BTM_TRACE_ERROR(...) \
233 if (btm_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
234 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
236 #define BTM_TRACE_WARNING(...) \
238 if (btm_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
239 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
241 #define BTM_TRACE_API(...) \
243 if (btm_cb.trace_level >= BT_TRACE_LEVEL_API) \
244 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_API, ##__VA_ARGS__); \
246 #define BTM_TRACE_EVENT(...) \
248 if (btm_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
249 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
251 #define BTM_TRACE_DEBUG(...) \
253 if (btm_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
254 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
257 /* Define tracing for the L2CAP unit */
258 #define L2CAP_TRACE_ERROR(...) \
260 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_ERROR) \
261 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
263 #define L2CAP_TRACE_WARNING(...) \
265 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_WARNING) \
266 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
268 #define L2CAP_TRACE_API(...) \
270 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_API) \
271 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_API, ##__VA_ARGS__); \
273 #define L2CAP_TRACE_EVENT(...) \
275 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_EVENT) \
276 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
278 #define L2CAP_TRACE_DEBUG(...) \
280 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_DEBUG) \
281 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
284 /* Define tracing for the SDP unit */
285 #define SDP_TRACE_ERROR(...) \
287 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
288 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
290 #define SDP_TRACE_WARNING(...) \
292 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
293 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
295 #define SDP_TRACE_API(...) \
297 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_API) \
298 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_API, ##__VA_ARGS__); \
300 #define SDP_TRACE_EVENT(...) \
302 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
303 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
305 #define SDP_TRACE_DEBUG(...) \
307 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
308 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
311 /* Define tracing for the RFCOMM unit */
312 #define RFCOMM_TRACE_ERROR(...) \
314 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
315 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
317 #define RFCOMM_TRACE_WARNING(...) \
319 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
320 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
322 #define RFCOMM_TRACE_API(...) \
324 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_API) \
325 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_API, ##__VA_ARGS__); \
327 #define RFCOMM_TRACE_EVENT(...) \
329 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
330 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
332 #define RFCOMM_TRACE_DEBUG(...) \
334 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
335 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
338 /* define traces for HID Host */
339 #define HIDH_TRACE_ERROR(...) \
341 if (hh_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
342 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
344 #define HIDH_TRACE_WARNING(...) \
346 if (hh_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
347 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
349 #define HIDH_TRACE_API(...) \
351 if (hh_cb.trace_level >= BT_TRACE_LEVEL_API) \
352 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_API, ##__VA_ARGS__); \
354 #define HIDH_TRACE_EVENT(...) \
356 if (hh_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
357 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
359 #define HIDH_TRACE_DEBUG(...) \
361 if (hh_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
362 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
365 /* define traces for HID Device */
366 #define HIDD_TRACE_ERROR(...) \
368 if (hd_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
369 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
371 #define HIDD_TRACE_WARNING(...) \
373 if (hd_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
374 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
376 #define HIDD_TRACE_API(...) \
378 if (hd_cb.trace_level >= BT_TRACE_LEVEL_API) \
379 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_API, ##__VA_ARGS__); \
381 #define HIDD_TRACE_EVENT(...) \
383 if (hd_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
384 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
386 #define HIDD_TRACE_DEBUG(...) \
388 if (hd_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
389 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
391 #define HIDD_TRACE_VERBOSE(...) \
393 if (hd_cb.trace_level >= BT_TRACE_LEVEL_VERBOSE) \
394 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
397 /* define traces for BNEP */
398 #define BNEP_TRACE_ERROR(...) \
400 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
401 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
403 #define BNEP_TRACE_WARNING(...) \
405 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
406 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
408 #define BNEP_TRACE_API(...) \
410 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_API) \
411 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_API, ##__VA_ARGS__); \
413 #define BNEP_TRACE_EVENT(...) \
415 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
416 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
418 #define BNEP_TRACE_DEBUG(...) \
420 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
421 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
424 /* define traces for PAN */
425 #define PAN_TRACE_ERROR(...) \
427 if (pan_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
428 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
430 #define PAN_TRACE_WARNING(...) \
432 if (pan_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
433 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
435 #define PAN_TRACE_API(...) \
437 if (pan_cb.trace_level >= BT_TRACE_LEVEL_API) \
438 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_API, ##__VA_ARGS__); \
440 #define PAN_TRACE_EVENT(...) \
442 if (pan_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
443 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
445 #define PAN_TRACE_DEBUG(...) \
447 if (pan_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
448 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
451 /* Define tracing for the A2DP profile */
452 #define A2DP_TRACE_ERROR(...) \
454 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
455 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
457 #define A2DP_TRACE_WARNING(...) \
459 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
460 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
462 #define A2DP_TRACE_EVENT(...) \
464 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
465 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
467 #define A2DP_TRACE_DEBUG(...) \
469 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
470 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
472 #define A2DP_TRACE_API(...) \
474 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_API) \
475 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_API, ##__VA_ARGS__); \
479 #define AVDT_TRACE_ERROR(...) \
481 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_ERROR) \
482 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
484 #define AVDT_TRACE_WARNING(...) \
486 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_WARNING) \
487 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
489 #define AVDT_TRACE_EVENT(...) \
491 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_EVENT) \
492 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
494 #define AVDT_TRACE_DEBUG(...) \
496 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_DEBUG) \
497 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
499 #define AVDT_TRACE_API(...) \
501 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_API) \
502 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
505 /* Define tracing for the AVCTP protocol */
506 #define AVCT_TRACE_ERROR(...) \
508 if (avct_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
509 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
511 #define AVCT_TRACE_WARNING(...) \
513 if (avct_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
514 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
516 #define AVCT_TRACE_EVENT(...) \
518 if (avct_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
519 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
521 #define AVCT_TRACE_DEBUG(...) \
523 if (avct_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
524 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
526 #define AVCT_TRACE_API(...) \
528 if (avct_cb.trace_level >= BT_TRACE_LEVEL_API) \
529 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
532 /* Define tracing for the AVRCP profile */
533 #define AVRC_TRACE_ERROR(...) \
535 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
536 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
538 #define AVRC_TRACE_WARNING(...) \
540 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
541 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
543 #define AVRC_TRACE_EVENT(...) \
545 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
546 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
548 #define AVRC_TRACE_DEBUG(...) \
550 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
551 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
553 #define AVRC_TRACE_API(...) \
555 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_API) \
556 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
560 #define MCA_TRACE_ERROR(...) \
562 if (mca_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
563 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
565 #define MCA_TRACE_WARNING(...) \
567 if (mca_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
568 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
570 #define MCA_TRACE_EVENT(...) \
572 if (mca_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
573 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
575 #define MCA_TRACE_DEBUG(...) \
577 if (mca_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
578 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
580 #define MCA_TRACE_API(...) \
582 if (mca_cb.trace_level >= BT_TRACE_LEVEL_API) \
583 BT_TRACE(TRACE_LAYER_MCA, TRACE_TYPE_API, ##__VA_ARGS__); \
586 /* Define tracing for the SMP unit */
587 #define SMP_TRACE_ERROR(...) \
589 if (smp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
590 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
592 #define SMP_TRACE_WARNING(...) \
594 if (smp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
595 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
597 #define SMP_TRACE_API(...) \
599 if (smp_cb.trace_level >= BT_TRACE_LEVEL_API) \
600 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_API, ##__VA_ARGS__); \
602 #define SMP_TRACE_EVENT(...) \
604 if (smp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
605 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
607 #define SMP_TRACE_DEBUG(...) \
609 if (smp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
610 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
613 extern uint8_t btif_trace_level;
615 /* define traces for application */
616 #define BTIF_TRACE_ERROR(...) \
618 if (btif_trace_level >= BT_TRACE_LEVEL_ERROR) \
619 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
623 #define BTIF_TRACE_WARNING(...) \
625 if (btif_trace_level >= BT_TRACE_LEVEL_WARNING) \
626 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
627 TRACE_TYPE_WARNING, \
630 #define BTIF_TRACE_API(...) \
632 if (btif_trace_level >= BT_TRACE_LEVEL_API) \
633 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
637 #define BTIF_TRACE_EVENT(...) \
639 if (btif_trace_level >= BT_TRACE_LEVEL_EVENT) \
640 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
644 #define BTIF_TRACE_DEBUG(...) \
646 if (btif_trace_level >= BT_TRACE_LEVEL_DEBUG) \
647 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
651 #define BTIF_TRACE_VERBOSE(...) \
653 if (btif_trace_level >= BT_TRACE_LEVEL_VERBOSE) \
654 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
659 /* define traces for application */
660 #define APPL_TRACE_ERROR(...) \
662 if (appl_trace_level >= BT_TRACE_LEVEL_ERROR) \
663 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
667 #define APPL_TRACE_WARNING(...) \
669 if (appl_trace_level >= BT_TRACE_LEVEL_WARNING) \
670 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
671 TRACE_TYPE_WARNING, \
674 #define APPL_TRACE_API(...) \
676 if (appl_trace_level >= BT_TRACE_LEVEL_API) \
677 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
681 #define APPL_TRACE_EVENT(...) \
683 if (appl_trace_level >= BT_TRACE_LEVEL_EVENT) \
684 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
688 #define APPL_TRACE_DEBUG(...) \
690 if (appl_trace_level >= BT_TRACE_LEVEL_DEBUG) \
691 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
695 #define APPL_TRACE_VERBOSE(...) \
697 if (appl_trace_level >= BT_TRACE_LEVEL_VERBOSE) \
698 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
703 typedef uint8_t tBTTRC_LAYER_ID;
704 typedef uint8_t(tBTTRC_SET_TRACE_LEVEL)(uint8_t);
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;
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;
718 void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...);
728 #include <type_traits>
730 #include <base/logging.h>
732 /* Prints intergral parameter x as hex string, with '0' fill */
733 template <typename T>
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;
744 * Obtains the string representation of a boolean value.
746 * @param value the boolean value to use
747 * @return the string representation of the boolean value: "true" or "false"
749 inline std::string logbool(bool value) {
750 std::stringstream tmp;
751 tmp << std::boolalpha << value;
756 * Append a field name to a string.
758 * The field names are added to the string with "|" in between.
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
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 += "|";