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