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 /* OBSOLETE */
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 HID_INITIAL_TRACE_LEVEL
186 #define HID_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
189 #ifndef APPL_INITIAL_TRACE_LEVEL
190 #define APPL_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
193 #ifndef GATT_INITIAL_TRACE_LEVEL
194 #define GATT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
197 #ifndef SMP_INITIAL_TRACE_LEVEL
198 #define SMP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
201 #define BT_TRACE(l, t, ...) \
202 LogMsg((TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t)), ##__VA_ARGS__)
204 /* Define tracing for the HCI unit */
205 #define HCI_TRACE_ERROR(...) \
207 if (btu_trace_level >= BT_TRACE_LEVEL_ERROR) \
208 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
210 #define HCI_TRACE_WARNING(...) \
212 if (btu_trace_level >= BT_TRACE_LEVEL_WARNING) \
213 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
215 #define HCI_TRACE_EVENT(...) \
217 if (btu_trace_level >= BT_TRACE_LEVEL_EVENT) \
218 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
220 #define HCI_TRACE_DEBUG(...) \
222 if (btu_trace_level >= BT_TRACE_LEVEL_DEBUG) \
223 BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
226 /* Define tracing for BTM */
227 #define BTM_TRACE_ERROR(...) \
229 if (btm_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
230 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
232 #define BTM_TRACE_WARNING(...) \
234 if (btm_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
235 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
237 #define BTM_TRACE_API(...) \
239 if (btm_cb.trace_level >= BT_TRACE_LEVEL_API) \
240 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_API, ##__VA_ARGS__); \
242 #define BTM_TRACE_EVENT(...) \
244 if (btm_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
245 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
247 #define BTM_TRACE_DEBUG(...) \
249 if (btm_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
250 BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
253 /* Define tracing for the L2CAP unit */
254 #define L2CAP_TRACE_ERROR(...) \
256 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_ERROR) \
257 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
259 #define L2CAP_TRACE_WARNING(...) \
261 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_WARNING) \
262 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
264 #define L2CAP_TRACE_API(...) \
266 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_API) \
267 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_API, ##__VA_ARGS__); \
269 #define L2CAP_TRACE_EVENT(...) \
271 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_EVENT) \
272 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
274 #define L2CAP_TRACE_DEBUG(...) \
276 if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_DEBUG) \
277 BT_TRACE(TRACE_LAYER_L2CAP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
280 /* Define tracing for the SDP unit */
281 #define SDP_TRACE_ERROR(...) \
283 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
284 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
286 #define SDP_TRACE_WARNING(...) \
288 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
289 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
291 #define SDP_TRACE_API(...) \
293 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_API) \
294 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_API, ##__VA_ARGS__); \
296 #define SDP_TRACE_EVENT(...) \
298 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
299 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
301 #define SDP_TRACE_DEBUG(...) \
303 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
304 BT_TRACE(TRACE_LAYER_SDP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
307 /* Define tracing for the RFCOMM unit */
308 #define RFCOMM_TRACE_ERROR(...) \
310 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
311 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
313 #define RFCOMM_TRACE_WARNING(...) \
315 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
316 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
318 #define RFCOMM_TRACE_API(...) \
320 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_API) \
321 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_API, ##__VA_ARGS__); \
323 #define RFCOMM_TRACE_EVENT(...) \
325 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
326 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
328 #define RFCOMM_TRACE_DEBUG(...) \
330 if (rfc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
331 BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
334 /* define traces for HID Host */
335 #define HIDH_TRACE_ERROR(...) \
337 if (hh_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
338 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
340 #define HIDH_TRACE_WARNING(...) \
342 if (hh_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
343 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
345 #define HIDH_TRACE_API(...) \
347 if (hh_cb.trace_level >= BT_TRACE_LEVEL_API) \
348 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_API, ##__VA_ARGS__); \
350 #define HIDH_TRACE_EVENT(...) \
352 if (hh_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
353 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
355 #define HIDH_TRACE_DEBUG(...) \
357 if (hh_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
358 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
361 /* define traces for HID Device */
362 #define HIDD_TRACE_ERROR(...) \
364 if (hd_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
365 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
367 #define HIDD_TRACE_WARNING(...) \
369 if (hd_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
370 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
372 #define HIDD_TRACE_API(...) \
374 if (hd_cb.trace_level >= BT_TRACE_LEVEL_API) \
375 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_API, ##__VA_ARGS__); \
377 #define HIDD_TRACE_EVENT(...) \
379 if (hd_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
380 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
382 #define HIDD_TRACE_DEBUG(...) \
384 if (hd_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
385 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
387 #define HIDD_TRACE_VERBOSE(...) \
389 if (hd_cb.trace_level >= BT_TRACE_LEVEL_VERBOSE) \
390 BT_TRACE(TRACE_LAYER_HID, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
393 /* define traces for BNEP */
394 #define BNEP_TRACE_ERROR(...) \
396 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
397 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
399 #define BNEP_TRACE_WARNING(...) \
401 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
402 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
404 #define BNEP_TRACE_API(...) \
406 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_API) \
407 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_API, ##__VA_ARGS__); \
409 #define BNEP_TRACE_EVENT(...) \
411 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
412 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
414 #define BNEP_TRACE_DEBUG(...) \
416 if (bnep_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
417 BT_TRACE(TRACE_LAYER_BNEP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
420 /* define traces for PAN */
421 #define PAN_TRACE_ERROR(...) \
423 if (pan_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
424 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
426 #define PAN_TRACE_WARNING(...) \
428 if (pan_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
429 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
431 #define PAN_TRACE_API(...) \
433 if (pan_cb.trace_level >= BT_TRACE_LEVEL_API) \
434 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_API, ##__VA_ARGS__); \
436 #define PAN_TRACE_EVENT(...) \
438 if (pan_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
439 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
441 #define PAN_TRACE_DEBUG(...) \
443 if (pan_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
444 BT_TRACE(TRACE_LAYER_PAN, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
447 /* Define tracing for the A2DP profile */
448 #define A2DP_TRACE_ERROR(...) \
450 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
451 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
453 #define A2DP_TRACE_WARNING(...) \
455 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
456 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
458 #define A2DP_TRACE_EVENT(...) \
460 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
461 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
463 #define A2DP_TRACE_DEBUG(...) \
465 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
466 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
468 #define A2DP_TRACE_API(...) \
470 if (a2dp_cb.trace_level >= BT_TRACE_LEVEL_API) \
471 BT_TRACE(TRACE_LAYER_A2DP, TRACE_TYPE_API, ##__VA_ARGS__); \
475 #define AVDT_TRACE_ERROR(...) \
477 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_ERROR) \
478 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
480 #define AVDT_TRACE_WARNING(...) \
482 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_WARNING) \
483 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
485 #define AVDT_TRACE_EVENT(...) \
487 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_EVENT) \
488 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
490 #define AVDT_TRACE_DEBUG(...) \
492 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_DEBUG) \
493 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
495 #define AVDT_TRACE_API(...) \
497 if (avdtp_cb.TraceLevel() >= BT_TRACE_LEVEL_API) \
498 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
501 /* Define tracing for the AVCTP protocol */
502 #define AVCT_TRACE_ERROR(...) \
504 if (avct_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
505 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
507 #define AVCT_TRACE_WARNING(...) \
509 if (avct_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
510 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
512 #define AVCT_TRACE_EVENT(...) \
514 if (avct_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
515 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
517 #define AVCT_TRACE_DEBUG(...) \
519 if (avct_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
520 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
522 #define AVCT_TRACE_API(...) \
524 if (avct_cb.trace_level >= BT_TRACE_LEVEL_API) \
525 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
528 /* Define tracing for the AVRCP profile */
529 #define AVRC_TRACE_ERROR(...) \
531 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
532 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
534 #define AVRC_TRACE_WARNING(...) \
536 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
537 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
539 #define AVRC_TRACE_EVENT(...) \
541 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
542 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
544 #define AVRC_TRACE_DEBUG(...) \
546 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
547 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
549 #define AVRC_TRACE_API(...) \
551 if (avrc_cb.trace_level >= BT_TRACE_LEVEL_API) \
552 BT_TRACE(TRACE_LAYER_AVP, TRACE_TYPE_API, ##__VA_ARGS__); \
555 /* Define tracing for the SMP unit */
556 #define SMP_TRACE_ERROR(...) \
558 if (smp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) \
559 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
561 #define SMP_TRACE_WARNING(...) \
563 if (smp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) \
564 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
566 #define SMP_TRACE_API(...) \
568 if (smp_cb.trace_level >= BT_TRACE_LEVEL_API) \
569 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_API, ##__VA_ARGS__); \
571 #define SMP_TRACE_EVENT(...) \
573 if (smp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) \
574 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
576 #define SMP_TRACE_DEBUG(...) \
578 if (smp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) \
579 BT_TRACE(TRACE_LAYER_SMP, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
582 extern uint8_t btif_trace_level;
584 /* define traces for application */
585 #define BTIF_TRACE_ERROR(...) \
587 if (btif_trace_level >= BT_TRACE_LEVEL_ERROR) \
588 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
592 #define BTIF_TRACE_WARNING(...) \
594 if (btif_trace_level >= BT_TRACE_LEVEL_WARNING) \
595 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
596 TRACE_TYPE_WARNING, \
599 #define BTIF_TRACE_API(...) \
601 if (btif_trace_level >= BT_TRACE_LEVEL_API) \
602 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
606 #define BTIF_TRACE_EVENT(...) \
608 if (btif_trace_level >= BT_TRACE_LEVEL_EVENT) \
609 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
613 #define BTIF_TRACE_DEBUG(...) \
615 if (btif_trace_level >= BT_TRACE_LEVEL_DEBUG) \
616 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
620 #define BTIF_TRACE_VERBOSE(...) \
622 if (btif_trace_level >= BT_TRACE_LEVEL_VERBOSE) \
623 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
628 /* define traces for application */
629 #define APPL_TRACE_ERROR(...) \
631 if (appl_trace_level >= BT_TRACE_LEVEL_ERROR) \
632 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
636 #define APPL_TRACE_WARNING(...) \
638 if (appl_trace_level >= BT_TRACE_LEVEL_WARNING) \
639 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
640 TRACE_TYPE_WARNING, \
643 #define APPL_TRACE_API(...) \
645 if (appl_trace_level >= BT_TRACE_LEVEL_API) \
646 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
650 #define APPL_TRACE_EVENT(...) \
652 if (appl_trace_level >= BT_TRACE_LEVEL_EVENT) \
653 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
657 #define APPL_TRACE_DEBUG(...) \
659 if (appl_trace_level >= BT_TRACE_LEVEL_DEBUG) \
660 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
664 #define APPL_TRACE_VERBOSE(...) \
666 if (appl_trace_level >= BT_TRACE_LEVEL_VERBOSE) \
667 LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_NONE | TRACE_ORG_APPL | \
672 typedef uint8_t tBTTRC_LAYER_ID;
673 typedef uint8_t(tBTTRC_SET_TRACE_LEVEL)(uint8_t);
676 const tBTTRC_LAYER_ID layer_id_start;
677 const tBTTRC_LAYER_ID layer_id_end;
678 tBTTRC_SET_TRACE_LEVEL* p_f;
679 const char* trc_name;
683 /* External declaration for appl_trace_level here to avoid to add the
684 * declaration in all the files using APPL_TRACExxx macros */
685 extern uint8_t appl_trace_level;
687 void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...);
697 #include <type_traits>
699 #include <base/logging.h>
701 /* Prints integral parameter x as hex string, with '0' fill */
702 template <typename T>
703 std::string loghex(T x) {
704 static_assert(std::is_integral<T>::value,
705 "loghex parameter must be integral.");
706 std::stringstream tmp;
707 tmp << std::showbase << std::internal << std::hex << std::setfill('0')
708 << std::setw((sizeof(T) * 2) + 2) << +x;
712 /* Prints integral array as hex string, with '0' fill */
713 template <typename T, size_t N>
714 std::string loghex(std::array<T, N> array) {
715 static_assert(std::is_integral<T>::value,
716 "type stored in array must be integral.");
717 std::stringstream tmp;
718 for (const auto& x : array) {
719 tmp << std::internal << std::hex << std::setfill('0')
720 << std::setw((sizeof(uint8_t) * 2) + 2) << +x;
726 * Obtains the string representation of a boolean value.
728 * @param value the boolean value to use
729 * @return the string representation of the boolean value: "true" or "false"
731 inline std::string logbool(bool value) {
732 std::stringstream tmp;
733 tmp << std::boolalpha << value;
738 * Append a field name to a string.
740 * The field names are added to the string with "|" in between.
742 * @param p_result a pointer to the result string to add the field name to
743 * @param append if true the field name will be added
744 * @param name the field name to add
745 * @return the result string
747 inline std::string& AppendField(std::string* p_result, bool append,
748 const std::string& name) {
749 CHECK(p_result != nullptr);
750 if (!append) return *p_result;
751 if (!p_result->empty()) *p_result += "|";
756 // This object puts the stream in a state where every time that a new line
757 // occurs, the next line is indented a certain number of spaces. The stream is
758 // reset to its previous state when the object is destroyed.
761 ScopedIndent(std::ostream& stream, int indent_size = DEFAULT_TAB)
762 : indented_buf_(stream, indent_size) {
763 old_stream_ = &stream;
764 old_stream_buf_ = stream.rdbuf();
765 stream.rdbuf(&indented_buf_);
768 ~ScopedIndent() { old_stream_->rdbuf(old_stream_buf_); }
770 static const size_t DEFAULT_TAB = 2;
773 class IndentedStreamBuf : public std::streambuf {
775 IndentedStreamBuf(std::ostream& stream, int indent_size)
776 : wrapped_buf_(stream.rdbuf()),
777 indent_size_(indent_size),
778 indent_next_line_(true){};
781 virtual int overflow(int character) override {
782 if (indent_next_line_ && character != '\n') {
783 for (int i = 0; i < indent_size_; i++) wrapped_buf_->sputc(' ');
786 indent_next_line_ = false;
787 if (character == '\n') {
788 indent_next_line_ = true;
791 return wrapped_buf_->sputc(character);
795 std::streambuf* wrapped_buf_;
797 bool indent_next_line_;
800 std::ostream* old_stream_;
801 std::streambuf* old_stream_buf_;
802 IndentedStreamBuf indented_buf_;