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 #ifndef _BT_TRACE_H_
20 #define _BT_TRACE_H_
21
22 #include <assert.h>
23 #include <stdio.h>
24 #include "bluedroid_user_config.h"
25 #include "stack/bt_types.h"
26 #include "bt_common.h"
27
trc_dump_buffer(const char * prefix,uint8_t * data,uint16_t len)28 static inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len)
29 {
30 uint16_t i;
31
32 if (!data || !len) {
33 return;
34 }
35
36 if (prefix) {
37 printf("%s: len %d\r\n", prefix, len);
38 }
39
40 for (i = 0; i < len; i+=16) {
41 printf("%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x\r\n",
42 *(data + i), *(data + i + 1), *(data + i + 2), *(data + i + 3), *(data + i + 4), *(data + i + 5), *(data + i + 6), *(data + i + 7),
43 *(data + i + 8), *(data + i + 9), *(data + i + 10), *(data + i + 11), *(data + i + 12), *(data + i + 13), *(data + i + 14), *(data + i + 15));
44 }
45 printf("\r\n");
46 }
47
48 #ifdef BTTRC_DUMP_BUFFER
49 #define BTTRC_DUMP_BUFFER(_prefix, _data, _len) trc_dump_buffer(_prefix, _data, _len)
50 #else
51 #define BTTRC_DUMP_BUFFER(_prefix, _data, _len)
52 #endif
53
54 //static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module";
55
56 /* BTrgs);E tracing IDs for debug purposes */
57 /* LayerIDs for stack */
58 #define BTTRC_ID_STK_GKI 1
59 #define BTTRC_ID_STK_BTU 2
60 #define BTTRC_ID_STK_HCI 3
61 #define BTTRC_ID_STK_L2CAP 4
62 #define BTTRC_ID_STK_RFCM_MX 5
63 #define BTTRC_ID_STK_RFCM_PRT 6
64 #define BTTRC_ID_STK_OBEX_C 7
65 #define BTTRC_ID_STK_OBEX_S 8
66 #define BTTRC_ID_STK_AVCT 9
67 #define BTTRC_ID_STK_AVDT 10
68 #define BTTRC_ID_STK_AVRC 11
69 #define BTTRC_ID_STK_BIC 12
70 #define BTTRC_ID_STK_BIS 13
71 #define BTTRC_ID_STK_BNEP 14
72 #define BTTRC_ID_STK_BPP 15
73 #define BTTRC_ID_STK_BTM_ACL 16
74 #define BTTRC_ID_STK_BTM_PM 17
75 #define BTTRC_ID_STK_BTM_DEV_CTRL 18
76 #define BTTRC_ID_STK_BTM_SVC_DSC 19
77 #define BTTRC_ID_STK_BTM_INQ 20
78 #define BTTRC_ID_STK_BTM_SCO 21
79 #define BTTRC_ID_STK_BTM_SEC 22
80 #define BTTRC_ID_STK_HID 24
81 #define BTTRC_ID_STK_HSP2 25
82 #define BTTRC_ID_STK_CTP 26
83 #define BTTRC_ID_STK_FTC 27
84 #define BTTRC_ID_STK_FTS 28
85 #define BTTRC_ID_STK_GAP 29
86 #define BTTRC_ID_STK_HCRP 31
87 #define BTTRC_ID_STK_ICP 32
88 #define BTTRC_ID_STK_OPC 33
89 #define BTTRC_ID_STK_OPS 34
90 #define BTTRC_ID_STK_PAN 35
91 #define BTTRC_ID_STK_SAP 36
92 #define BTTRC_ID_STK_SDP 37
93 #define BTTRC_ID_STK_SLIP 38
94 #define BTTRC_ID_STK_SPP 39
95 #define BTTRC_ID_STK_TCS 40
96 #define BTTRC_ID_STK_VDP 41
97 #define BTTRC_ID_STK_MCAP 42
98 #define BTTRC_ID_STK_GATT 43
99 #define BTTRC_ID_STK_SMP 44
100 #define BTTRC_ID_STK_NFC 45
101 #define BTTRC_ID_STK_NCI 46
102 #define BTTRC_ID_STK_IDEP 47
103 #define BTTRC_ID_STK_NDEP 48
104 #define BTTRC_ID_STK_LLCP 49
105 #define BTTRC_ID_STK_RW 50
106 #define BTTRC_ID_STK_CE 51
107 #define BTTRC_ID_STK_SNEP 52
108 #define BTTRC_ID_STK_NDEF 53
109
110 /* LayerIDs for BTA */
111 #define BTTRC_ID_BTA_ACC 55 /* Advanced Camera Client */
112 #define BTTRC_ID_BTA_AG 56 /* audio gateway */
113 #define BTTRC_ID_BTA_AV 57 /* Advanced audio */
114 #define BTTRC_ID_BTA_BIC 58 /* Basic Imaging Client */
115 #define BTTRC_ID_BTA_BIS 59 /* Basic Imaging Server */
116 #define BTTRC_ID_BTA_BP 60 /* Basic Printing Client */
117 #define BTTRC_ID_BTA_CG 61
118 #define BTTRC_ID_BTA_CT 62 /* cordless telephony terminal */
119 #define BTTRC_ID_BTA_DG 63 /* data gateway */
120 #define BTTRC_ID_BTA_DM 64 /* device manager */
121 #define BTTRC_ID_BTA_DM_SRCH 65 /* device manager search */
122 #define BTTRC_ID_BTA_DM_SEC 66 /* device manager security */
123 #define BTTRC_ID_BTA_FM 67
124 #define BTTRC_ID_BTA_FTC 68 /* file transfer client */
125 #define BTTRC_ID_BTA_FTS 69 /* file transfer server */
126 #define BTTRC_ID_BTA_HIDH 70
127 #define BTTRC_ID_BTA_HIDD 71
128 #define BTTRC_ID_BTA_JV 72
129 #define BTTRC_ID_BTA_OPC 73 /* object push client */
130 #define BTTRC_ID_BTA_OPS 74 /* object push server */
131 #define BTTRC_ID_BTA_PAN 75 /* Personal Area Networking */
132 #define BTTRC_ID_BTA_PR 76 /* Printer client */
133 #define BTTRC_ID_BTA_SC 77 /* SIM Card Access server */
134 #define BTTRC_ID_BTA_SS 78 /* synchronization server */
135 #define BTTRC_ID_BTA_SYS 79 /* system manager */
136 #define BTTRC_ID_AVDT_SCB 80 /* avdt scb */
137 #define BTTRC_ID_AVDT_CCB 81 /* avdt ccb */
138
139 // btla-specific ++
140 /* LayerIDs added for BTL-A. Probably should modify bte_logmsg.c in future. */
141 #define BTTRC_ID_STK_RFCOMM 82
142 #define BTTRC_ID_STK_RFCOMM_DATA 83
143 #define BTTRC_ID_STK_OBEX 84
144 #define BTTRC_ID_STK_A2D 85
145 #define BTTRC_ID_STK_BIP 86
146
147 /* LayerIDs for BT APP */
148 #define BTTRC_ID_BTAPP 87
149 #define BTTRC_ID_BT_PROTOCOL 88 /* this is a temporary solution to allow dynamic
150 enable/disable of BT_PROTOCOL_TRACE */
151 #define BTTRC_ID_MAX_ID BTTRC_ID_BT_PROTOCOL
152 // btla-specific --
153 #define BTTRC_ID_ALL_LAYERS 0xFF /* all trace layers */
154 /* Parameter datatypes used in Trace APIs */
155 #define BTTRC_PARAM_UINT8 1
156 #define BTTRC_PARAM_UINT16 2
157 #define BTTRC_PARAM_UINT32 3
158
159 /* Enables or disables verbose trace information. */
160 #ifndef BT_TRACE_VERBOSE
161 #define BT_TRACE_VERBOSE 0
162 #endif
163
164 /* Enables or disables all trace messages. */
165 #ifndef BT_USE_TRACES
166 #define BT_USE_TRACES 0
167 #endif
168
169 #ifndef BT_TRACE_APPL
170 #define BT_TRACE_APPL BT_USE_TRACES
171 #endif
172
173 /******************************************************************************
174 **
175 ** Trace Levels
176 **
177 ** The following values may be used for different levels:
178 ** BT_TRACE_LEVEL_NONE 0 * No trace messages to be generated
179 ** BT_TRACE_LEVEL_ERROR 1 * Error condition trace messages
180 ** BT_TRACE_LEVEL_WARNING 2 * Warning condition trace messages
181 ** BT_TRACE_LEVEL_API 3 * API traces
182 ** BT_TRACE_LEVEL_EVENT 4 * Debug messages for events
183 ** BT_TRACE_LEVEL_DEBUG 5 * Debug messages (general)
184 ******************************************************************************/
185
186 // btla-specific ++
187 /* Core Stack default trace levels */
188 #define HCI_INITIAL_TRACE_LEVEL UC_BT_LOG_HCI_TRACE_LEVEL
189 #define BTM_INITIAL_TRACE_LEVEL UC_BT_LOG_BTM_TRACE_LEVEL
190 #define L2CAP_INITIAL_TRACE_LEVEL UC_BT_LOG_L2CAP_TRACE_LEVEL
191 #define RFCOMM_INITIAL_TRACE_LEVEL UC_BT_LOG_RFCOMM_TRACE_LEVEL
192 #define SDP_INITIAL_TRACE_LEVEL UC_BT_LOG_SDP_TRACE_LEVEL
193 #define GAP_INITIAL_TRACE_LEVEL UC_BT_LOG_GAP_TRACE_LEVEL
194 #define BNEP_INITIAL_TRACE_LEVEL UC_BT_LOG_BNEP_TRACE_LEVEL
195 #define PAN_INITIAL_TRACE_LEVEL UC_BT_LOG_PAN_TRACE_LEVEL
196 #define A2D_INITIAL_TRACE_LEVEL UC_BT_LOG_A2D_TRACE_LEVEL
197 #define AVDT_INITIAL_TRACE_LEVEL UC_BT_LOG_AVDT_TRACE_LEVEL
198 #define AVCT_INITIAL_TRACE_LEVEL UC_BT_LOG_AVCT_TRACE_LEVEL
199 #define AVRC_INITIAL_TRACE_LEVEL UC_BT_LOG_AVRC_TRACE_LEVEL
200 #define MCA_INITIAL_TRACE_LEVEL UC_BT_LOG_MCA_TRACE_LEVEL
201 #define HIDH_INITIAL_TRACE_LEVEL UC_BT_LOG_HIDH_TRACE_LEVEL
202 #define APPL_INITIAL_TRACE_LEVEL UC_BT_LOG_APPL_TRACE_LEVEL
203 #define GATT_INITIAL_TRACE_LEVEL UC_BT_LOG_GATT_TRACE_LEVEL
204 #define SMP_INITIAL_TRACE_LEVEL UC_BT_LOG_SMP_TRACE_LEVEL
205 #define BTIF_INITIAL_TRACE_LEVEL UC_BT_LOG_BTIF_TRACE_LEVEL
206
207 // btla-specific --
208
209 #if !UC_BT_STACK_NO_LOG
210 #define LOG_ERROR(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) esp_log_write(ESP_LOG_ERROR, "BT_LOG", LOG_FORMAT(E, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
211 #define LOG_WARN(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) esp_log_write(ESP_LOG_WARN, "BT_LOG", LOG_FORMAT(W, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
212 #define LOG_INFO(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) esp_log_write(ESP_LOG_INFO, "BT_LOG", LOG_FORMAT(I, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
213 #define LOG_DEBUG(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) esp_log_write(ESP_LOG_DEBUG, "BT_LOG", LOG_FORMAT(D, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
214 #define LOG_VERBOSE(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) esp_log_write(ESP_LOG_VERBOSE, "BT_LOG", LOG_FORMAT(V, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
215
216 /* Define tracing for BTM
217 */
218 #define BTM_TRACE_ERROR(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(BTM, ERROR)) BT_PRINT_E("BT_BTM", fmt, ## args);}
219 #define BTM_TRACE_WARNING(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(BTM, WARNING)) BT_PRINT_W("BT_BTM", fmt, ## args);}
220 #define BTM_TRACE_API(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(BTM,API)) BT_PRINT_I("BT_BTM", fmt, ## args);}
221 #define BTM_TRACE_EVENT(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(BTM,EVENT)) BT_PRINT_D("BT_BTM", fmt, ## args);}
222 #define BTM_TRACE_DEBUG(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(BTM,DEBUG)) BT_PRINT_D("BT_BTM", fmt, ## args);}
223
224 /* Define tracing for the L2CAP unit
225 */
226 #define L2CAP_TRACE_ERROR(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(L2CAP, ERROR)) BT_PRINT_E("BT_L2CAP", fmt, ## args);}
227 #define L2CAP_TRACE_WARNING(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(L2CAP, WARNING)) BT_PRINT_W("BT_L2CAP", fmt, ## args);}
228 #define L2CAP_TRACE_API(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(L2CAP,API)) BT_PRINT_I("BT_L2CAP", fmt, ## args);}
229 #define L2CAP_TRACE_EVENT(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(L2CAP,EVENT)) BT_PRINT_D("BT_L2CAP", fmt, ## args);}
230 #define L2CAP_TRACE_DEBUG(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(L2CAP,DEBUG)) BT_PRINT_D("BT_L2CAP", fmt, ## args);}
231
232 /* Define tracing for the SDP unit
233 */
234 #define SDP_TRACE_ERROR(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(SDP, ERROR)) BT_PRINT_E("BT_SDP", fmt, ## args);}
235 #define SDP_TRACE_WARNING(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(SDP, WARNING)) BT_PRINT_W("BT_SDP", fmt, ## args);}
236 #define SDP_TRACE_API(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(SDP,API)) BT_PRINT_I("BT_SDP", fmt, ## args);}
237 #define SDP_TRACE_EVENT(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(SDP,EVENT)) BT_PRINT_D("BT_SDP", fmt, ## args);}
238 #define SDP_TRACE_DEBUG(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(SDP,DEBUG)) BT_PRINT_D("BT_SDP", fmt, ## args);}
239
240 /* Define tracing for the RFCOMM unit
241 */
242 #define RFCOMM_TRACE_ERROR(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(RFCOMM, ERROR)) BT_PRINT_E("BT_RFCOMM", fmt, ## args);}
243 #define RFCOMM_TRACE_WARNING(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(RFCOMM, WARNING)) BT_PRINT_W("BT_RFCOMM", fmt, ## args);}
244 #define RFCOMM_TRACE_API(fmt, args...) {if (rfc_cb.trace_level >=BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(RFCOMM,API)) BT_PRINT_I("BT_RFCOMM", fmt, ## args);}
245 #define RFCOMM_TRACE_EVENT(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(RFCOMM,EVENT)) BT_PRINT_D("BT_RFCOMM", fmt, ## args);}
246 #define RFCOMM_TRACE_DEBUG(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(RFCOMM,DEBUG)) BT_PRINT_D("BT_RFCOMM", fmt, ## args);}
247
248 /* Generic Access Profile traces */
249 #define GAP_TRACE_ERROR(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(GAP, ERROR)) BT_PRINT_E("BT_GAP", fmt, ## args);}
250 #define GAP_TRACE_API(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(GAP,API)) BT_PRINT_I("BT_GAP", fmt, ## args);}
251 #define GAP_TRACE_EVENT(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(GAP,EVENT)) BT_PRINT_D("BT_GAP", fmt, ## args);}
252 #define GAP_TRACE_WARNING(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(GAP, WARNING)) BT_PRINT_W("BT_GAP", fmt, ## args);}
253
254 /* define traces for HID Host */
255 #define HIDH_TRACE_ERROR(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(HIDH, ERROR)) BT_PRINT_E("BT_HIDH", fmt, ## args);}
256 #define HIDH_TRACE_WARNING(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(HIDH, WARNING)) BT_PRINT_W("BT_HIDH", fmt, ## args);}
257 #define HIDH_TRACE_API(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(HIDH,API)) BT_PRINT_I("BT_HIDH", fmt, ## args);}
258 #define HIDH_TRACE_EVENT(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(HIDH,EVENT)) BT_PRINT_D("BT_HIDH", fmt, ## args);}
259 #define HIDH_TRACE_DEBUG(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(HIDH,DEBUG)) BT_PRINT_D("BT_HIDH", fmt, ## args);}
260
261 /* define traces for BNEP */
262
263 #define BNEP_TRACE_ERROR(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(BNEP, ERROR)) BT_PRINT_E("BT_BNEP", fmt, ## args);}
264 #define BNEP_TRACE_WARNING(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(BNEP, WARNING)) BT_PRINT_W("BT_BNEP", fmt, ## args);}
265 #define BNEP_TRACE_API(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(BNEP,API)) BT_PRINT_I("BT_BNEP", fmt, ## args);}
266 #define BNEP_TRACE_EVENT(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(BNEP,EVENT)) BT_PRINT_D("BT_BNEP", fmt, ## args);}
267 #define BNEP_TRACE_DEBUG(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(BNEP,DEBUG)) BT_PRINT_D("BT_BNEP", fmt, ## args);}
268
269 /* define traces for PAN */
270
271 #define PAN_TRACE_ERROR(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(PAN, ERROR)) BT_PRINT_E("BT_PAN", fmt, ## args);}
272 #define PAN_TRACE_WARNING(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(PAN, WARNING)) BT_PRINT_W("BT_PAN", fmt, ## args);}
273 #define PAN_TRACE_API(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(PAN,API)) BT_PRINT_I("BT_PAN", fmt, ## args);}
274 #define PAN_TRACE_EVENT(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(PAN,EVENT)) BT_PRINT_D("BT_PAN", fmt, ## args);}
275 #define PAN_TRACE_DEBUG(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(PAN,DEBUG)) BT_PRINT_D("BT_PAN", fmt, ## args);}
276
277 /* Define tracing for the A2DP profile
278 */
279 #define A2D_TRACE_ERROR(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(A2D, ERROR)) BT_PRINT_E("BT_A2D", fmt, ## args);}
280 #define A2D_TRACE_WARNING(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(A2D, WARNING)) BT_PRINT_W("BT_A2D", fmt, ## args);}
281 #define A2D_TRACE_API(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(A2D,API)) BT_PRINT_I("BT_A2D", fmt, ## args);}
282 #define A2D_TRACE_EVENT(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(A2D,EVENT)) BT_PRINT_D("BT_A2D", fmt, ## args);}
283 #define A2D_TRACE_DEBUG(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(A2D,DEBUG)) BT_PRINT_D("BT_A2D", fmt, ## args);}
284
285 /* AVDTP
286 */
287 #define AVDT_TRACE_ERROR(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(AVDT, ERROR)) BT_PRINT_E("BT_AVDT", fmt, ## args);}
288 #define AVDT_TRACE_WARNING(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(AVDT, WARNING)) BT_PRINT_W("BT_AVDT", fmt, ## args);}
289 #define AVDT_TRACE_API(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(AVDT,API)) BT_PRINT_I("BT_AVDT", fmt, ## args);}
290 #define AVDT_TRACE_EVENT(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(AVDT,EVENT)) BT_PRINT_D("BT_AVDT", fmt, ## args);}
291 #define AVDT_TRACE_DEBUG(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(AVDT,DEBUG)) BT_PRINT_D("BT_AVDT", fmt, ## args);}
292
293 /* Define tracing for the AVCTP protocol
294 */
295 #define AVCT_TRACE_ERROR(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(AVCT, ERROR)) BT_PRINT_E("BT_AVCT", fmt, ## args);}
296 #define AVCT_TRACE_WARNING(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(AVCT, WARNING)) BT_PRINT_W("BT_AVCT", fmt, ## args);}
297 #define AVCT_TRACE_API(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(AVCT,API)) BT_PRINT_I("BT_AVCT", fmt, ## args);}
298 #define AVCT_TRACE_EVENT(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(AVCT,EVENT)) BT_PRINT_D("BT_AVCT", fmt, ## args);}
299 #define AVCT_TRACE_DEBUG(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(AVCT,DEBUG)) BT_PRINT_D("BT_AVCT", fmt, ## args);}
300
301 /* Define tracing for the AVRCP profile
302 */
303 #define AVRC_TRACE_ERROR(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(AVRC, ERROR)) BT_PRINT_E("BT_AVRC", fmt, ## args);}
304 #define AVRC_TRACE_WARNING(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(AVRC, WARNING)) BT_PRINT_W("BT_AVRC", fmt, ## args);}
305 #define AVRC_TRACE_API(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(AVRC,API)) BT_PRINT_I("BT_AVRC", fmt, ## args);}
306 #define AVRC_TRACE_EVENT(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(AVRC,EVENT)) BT_PRINT_D("BT_AVRC", fmt, ## args);}
307 #define AVRC_TRACE_DEBUG(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(AVRC,DEBUG)) BT_PRINT_D("BT_AVRC", fmt, ## args);}
308
309 /* MCAP
310 */
311 #define MCA_TRACE_ERROR(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(MCA, ERROR)) BT_PRINT_E("BT_MCA", fmt, ## args);}
312 #define MCA_TRACE_WARNING(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(MCA, WARNING)) BT_PRINT_W("BT_MCA", fmt, ## args);}
313 #define MCA_TRACE_API(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(MCA,API)) BT_PRINT_I("BT_MCA", fmt, ## args);}
314 #define MCA_TRACE_EVENT(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(MCA,EVENT)) BT_PRINT_D("BT_MCA", fmt, ## args);}
315 #define MCA_TRACE_DEBUG(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(MCA,DEBUG)) BT_PRINT_D("BT_MCA", fmt, ## args);}
316
317 /* Define tracing for the ATT/GATT unit
318 */
319 #define GATT_TRACE_ERROR(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(GATT, ERROR)) BT_PRINT_E("BT_GATT", fmt, ## args);}
320 #define GATT_TRACE_WARNING(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(GATT, WARNING)) BT_PRINT_W("BT_GATT", fmt, ## args);}
321 #define GATT_TRACE_API(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(GATT,API)) BT_PRINT_I("BT_GATT", fmt, ## args);}
322 #define GATT_TRACE_EVENT(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(GATT,EVENT)) BT_PRINT_D("BT_GATT", fmt, ## args);}
323 #define GATT_TRACE_DEBUG(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(GATT,DEBUG)) BT_PRINT_D("BT_GATT", fmt, ## args);}
324
325 /* Define tracing for the SMP unit
326 */
327 #define SMP_TRACE_ERROR(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(SMP, ERROR)) BT_PRINT_E("BT_SMP", fmt, ## args);}
328 #define SMP_TRACE_WARNING(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(SMP, WARNING)) BT_PRINT_W("BT_SMP", fmt, ## args);}
329 #define SMP_TRACE_API(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(SMP,API)) BT_PRINT_I("BT_SMP", fmt, ## args);}
330 #define SMP_TRACE_EVENT(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(SMP,EVENT)) BT_PRINT_D("BT_SMP", fmt, ## args);}
331 #define SMP_TRACE_DEBUG(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(SMP,DEBUG)) BT_PRINT_D("BT_SMP", fmt, ## args);}
332
333
334 extern UINT8 btif_trace_level;
335
336 // define traces for application
337 #define BTIF_TRACE_ERROR(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(BTIF, ERROR)) BT_PRINT_E("BT_BTIF", fmt, ## args);}
338 #define BTIF_TRACE_WARNING(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(BTIF, WARNING)) BT_PRINT_W("BT_BTIF", fmt, ## args);}
339 #define BTIF_TRACE_API(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(BTIF,API)) BT_PRINT_I("BT_BTIF", fmt, ## args);}
340 #define BTIF_TRACE_EVENT(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(BTIF,EVENT)) BT_PRINT_D("BT_BTIF", fmt, ## args);}
341 #define BTIF_TRACE_DEBUG(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(BTIF,DEBUG)) BT_PRINT_D("BT_BTIF", fmt, ## args);}
342 #define BTIF_TRACE_VERBOSE(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_VERBOSE && BT_LOG_LEVEL_CHECK(BTIF,VERBOSE)) BT_PRINT_V("BT_BTIF", fmt, ## args);}
343
344 /* define traces for application */
345
346 #define APPL_TRACE_ERROR(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(APPL, ERROR)) BT_PRINT_E("BT_APPL", fmt, ## args);}
347 #define APPL_TRACE_WARNING(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(APPL, WARNING)) BT_PRINT_W("BT_APPL", fmt, ## args);}
348 #define APPL_TRACE_API(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(APPL,API)) BT_PRINT_I("BT_APPL", fmt, ## args);}
349 #define APPL_TRACE_EVENT(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(APPL,EVENT)) BT_PRINT_D("BT_APPL", fmt, ## args);}
350 #define APPL_TRACE_DEBUG(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(APPL,DEBUG)) BT_PRINT_D("BT_APPL", fmt, ## args);}
351 #define APPL_TRACE_VERBOSE(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_VERBOSE && BT_LOG_LEVEL_CHECK(APPL,VERBOSE)) BT_PRINT_V("BT_APPL", fmt, ## args);}
352
353 /* Define tracing for the HCI unit
354 * Modified from `btu_cb.trace_level` to `HCI_INITIAL_TRACE_LEVEL`,
355 * to use HCI_TRACE_XXXX in hci_layer.c without including `btu.h`
356 */
357 #define HCI_TRACE_ERROR(fmt, args...) {if (HCI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(HCI, ERROR)) BT_PRINT_E("BT_HCI", fmt,## args);}
358 #define HCI_TRACE_WARNING(fmt, args...) {if (HCI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(HCI, WARNING)) BT_PRINT_W("BT_HCI", fmt,## args);}
359 #define HCI_TRACE_EVENT(fmt, args...) {if (HCI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(HCI,EVENT)) BT_PRINT_D("BT_HCI", fmt,## args);}
360 #define HCI_TRACE_DEBUG(fmt, args...) {if (HCI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(HCI,DEBUG)) BT_PRINT_D("BT_HCI", fmt,## args);}
361
362 #else
363 #define LOG_ERROR(fmt, args...)
364 #define LOG_WARN(fmt, args...)
365 #define LOG_INFO(fmt, args...)
366 #define LOG_DEBUG(fmt, args...)
367 #define LOG_VERBOSE(fmt, args...)
368
369 /* Define tracing for the HCI unit
370 */
371 #define HCI_TRACE_ERROR(fmt, args...)
372 #define HCI_TRACE_WARNING(fmt, args...)
373 #define HCI_TRACE_EVENT(fmt, args...)
374 #define HCI_TRACE_DEBUG(fmt, args...)
375
376 /* Define tracing for BTM
377 */
378 #define BTM_TRACE_ERROR(fmt, args...)
379 #define BTM_TRACE_WARNING(fmt, args...)
380 #define BTM_TRACE_API(fmt, args...)
381 #define BTM_TRACE_EVENT(fmt, args...)
382 #define BTM_TRACE_DEBUG(fmt, args...)
383
384 /* Define tracing for the L2CAP unit
385 */
386 #define L2CAP_TRACE_ERROR(fmt, args...)
387 #define L2CAP_TRACE_WARNING(fmt, args...)
388 #define L2CAP_TRACE_API(fmt, args...)
389 #define L2CAP_TRACE_EVENT(fmt, args...)
390 #define L2CAP_TRACE_DEBUG(fmt, args...)
391
392 /* Define tracing for the SDP unit
393 */
394 #define SDP_TRACE_ERROR(fmt, args...)
395 #define SDP_TRACE_WARNING(fmt, args...)
396 #define SDP_TRACE_API(fmt, args...)
397 #define SDP_TRACE_EVENT(fmt, args...)
398 #define SDP_TRACE_DEBUG(fmt, args...)
399
400 /* Define tracing for the RFCOMM unit
401 */
402 #define RFCOMM_TRACE_ERROR(fmt, args...)
403 #define RFCOMM_TRACE_WARNING(fmt, args...)
404 #define RFCOMM_TRACE_API(fmt, args...)
405 #define RFCOMM_TRACE_EVENT(fmt, args...)
406 #define RFCOMM_TRACE_DEBUG(fmt, args...)
407
408 /* Generic Access Profile traces */
409 #define GAP_TRACE_ERROR(fmt, args...)
410 #define GAP_TRACE_EVENT(fmt, args...)
411 #define GAP_TRACE_API(fmt, args...)
412 #define GAP_TRACE_WARNING(fmt, args...)
413
414 /* define traces for HID Host */
415 #define HIDH_TRACE_ERROR(fmt, args...)
416 #define HIDH_TRACE_WARNING(fmt, args...)
417 #define HIDH_TRACE_API(fmt, args...)
418 #define HIDH_TRACE_EVENT(fmt, args...)
419 #define HIDH_TRACE_DEBUG(fmt, args...)
420
421 /* define traces for BNEP */
422
423 #define BNEP_TRACE_ERROR(fmt, args...)
424 #define BNEP_TRACE_WARNING(fmt, args...)
425 #define BNEP_TRACE_API(fmt, args...)
426 #define BNEP_TRACE_EVENT(fmt, args...)
427 #define BNEP_TRACE_DEBUG(fmt, args...)
428
429 /* define traces for PAN */
430
431 #define PAN_TRACE_ERROR(fmt, args...)
432 #define PAN_TRACE_WARNING(fmt, args...)
433 #define PAN_TRACE_API(fmt, args...)
434 #define PAN_TRACE_EVENT(fmt, args...)
435 #define PAN_TRACE_DEBUG(fmt, args...)
436
437 /* Define tracing for the A2DP profile
438 */
439 #define A2D_TRACE_ERROR(fmt, args...)
440 #define A2D_TRACE_WARNING(fmt, args...)
441 #define A2D_TRACE_EVENT(fmt, args...)
442 #define A2D_TRACE_DEBUG(fmt, args...)
443 #define A2D_TRACE_API(fmt, args...)
444
445 /* AVDTP
446 */
447 #define AVDT_TRACE_ERROR(fmt, args...)
448 #define AVDT_TRACE_WARNING(fmt, args...)
449 #define AVDT_TRACE_EVENT(fmt, args...)
450 #define AVDT_TRACE_DEBUG(fmt, args...)
451 #define AVDT_TRACE_API(fmt, args...)
452
453 /* Define tracing for the AVCTP protocol
454 */
455 #define AVCT_TRACE_ERROR(fmt, args...)
456 #define AVCT_TRACE_WARNING(fmt, args...)
457 #define AVCT_TRACE_EVENT(fmt, args...)
458 #define AVCT_TRACE_DEBUG(fmt, args...)
459 #define AVCT_TRACE_API(fmt, args...)
460
461 /* Define tracing for the AVRCP profile
462 */
463 #define AVRC_TRACE_ERROR(fmt, args...)
464 #define AVRC_TRACE_WARNING(fmt, args...)
465 #define AVRC_TRACE_EVENT(fmt, args...)
466 #define AVRC_TRACE_DEBUG(fmt, args...)
467 #define AVRC_TRACE_API(fmt, args...)
468
469 /* MCAP
470 */
471 #define MCA_TRACE_ERROR(fmt, args...)
472 #define MCA_TRACE_WARNING(fmt, args...)
473 #define MCA_TRACE_EVENT(fmt, args...)
474 #define MCA_TRACE_DEBUG(fmt, args...)
475 #define MCA_TRACE_API(fmt, args...)
476
477 /* Define tracing for the ATT/GATT unit
478 */
479 #define GATT_TRACE_ERROR(fmt, args...)
480 #define GATT_TRACE_WARNING(fmt, args...)
481 #define GATT_TRACE_API(fmt, args...)
482 #define GATT_TRACE_EVENT(fmt, args...)
483 #define GATT_TRACE_DEBUG(fmt, args...)
484
485 /* Define tracing for the SMP unit
486 */
487 #define SMP_TRACE_ERROR(fmt, args...)
488 #define SMP_TRACE_WARNING(fmt, args...)
489 #define SMP_TRACE_API(fmt, args...)
490 #define SMP_TRACE_EVENT(fmt, args...)
491 #define SMP_TRACE_DEBUG(fmt, args...)
492
493 extern UINT8 btif_trace_level;
494
495 // define traces for application
496 #define BTIF_TRACE_ERROR(fmt, args...)
497 #define BTIF_TRACE_WARNING(fmt, args...)
498 #define BTIF_TRACE_API(fmt, args...)
499 #define BTIF_TRACE_EVENT(fmt, args...)
500 #define BTIF_TRACE_DEBUG(fmt, args...)
501 #define BTIF_TRACE_VERBOSE(fmt, args...)
502
503 /* define traces for application */
504
505 #define APPL_TRACE_ERROR(fmt, args...)
506 #define APPL_TRACE_WARNING(fmt, args...)
507 #define APPL_TRACE_API(fmt, args...)
508 #define APPL_TRACE_EVENT(fmt, args...)
509 #define APPL_TRACE_DEBUG(fmt, args...)
510 #define APPL_TRACE_VERBOSE(fmt, args...)
511
512 #endif ///!UC_BT_STACK_NO_LOG
513
514
515 /* Simplified Trace Helper Macro
516 */
517 #define bdld(fmt, args...) \
518 do{\
519 if((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_DEBUG) \
520 BT_PRINT_D(fmt, ## args); \
521 }while(0)
522
523 #define bdlw(fmt, args...) \
524 do{\
525 if((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_WARNING) \
526 BT_PRINT_W(fmt, ## args); \
527 }while(0)
528
529 #define bdle(fmt, args...) \
530 do{\
531 if((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_ERROR) \
532 BT_PRINT_E(fmt, ## args); \
533 }while(0)
534
535 #define bdla(assert_if) \
536 do{\
537 if(((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_ERROR) && !(assert_if)) \
538 BT_PRINT_E("%s: assert failed\n", #assert_if); \
539 }while(0)
540
541 typedef UINT8 tBTTRC_PARAM_TYPE;
542 typedef UINT8 tBTTRC_LAYER_ID;
543 typedef UINT8 tBTTRC_TYPE;
544
545 typedef struct {
546 tBTTRC_LAYER_ID layer_id;
547 tBTTRC_TYPE type; /* TODO: use tBTTRC_TYPE instead of "classical level 0-5" */
548 } tBTTRC_LEVEL;
549
550 typedef UINT8 (tBTTRC_SET_TRACE_LEVEL)( UINT8 );
551
552 typedef struct {
553 const tBTTRC_LAYER_ID layer_id_start;
554 const tBTTRC_LAYER_ID layer_id_end;
555 tBTTRC_SET_TRACE_LEVEL *p_f;
556 const char *trc_name;
557 UINT8 trace_level;
558 } tBTTRC_FUNC_MAP;
559
560 /* External declaration for appl_trace_level here to avoid to add the declaration in all the files using APPL_TRACExxx macros */
561 extern UINT8 appl_trace_level;
562
563 #endif /*_BT_TRACE_H_*/
564