bt_trace.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. #ifndef _BT_TRACE_H_
  19. #define _BT_TRACE_H_
  20. #include <stdio.h>
  21. #include "bt_types.h"
  22. #include "esp_log.h"
  23. #define TAG "BT"
  24. #define BT_PRINTF(fmt, ...) ESP_LOGE(TAG, fmt, ##__VA_ARGS__)
  25. #ifndef assert
  26. #define assert(x) do { if (!(x)) BT_PRINTF("bt host error %s %u\n", __FILE__, __LINE__); } while (0)
  27. #endif
  28. inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len)
  29. {
  30. uint16_t i;
  31. if (!data || !len) {
  32. return;
  33. }
  34. if (prefix) {
  35. BT_PRINTF("%s: len %d\n", prefix, len);
  36. }
  37. for (i = 0; i < len; i+=16) {
  38. BT_PRINTF("%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x\n",
  39. *(data + i), *(data + i + 1), *(data + i + 2), *(data + i + 3), *(data + i + 4), *(data + i + 5), *(data + i + 6), *(data + i + 7),
  40. *(data + i + 8), *(data + i + 9), *(data + i + 10), *(data + i + 11), *(data + i + 12), *(data + i + 13), *(data + i + 14), *(data + i + 15));
  41. }
  42. BT_PRINTF("\n");
  43. }
  44. #ifdef BTTRC_DUMP_BUFFER
  45. #define BTTRC_DUMP_BUFFER(_prefix, _data, _len) trc_dump_buffer(_data, _len)
  46. #else
  47. #define BTTRC_DUMP_BUFFER(_prefix, _data, _len)
  48. #endif
  49. //static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module";
  50. /* BTrgs);E tracing IDs for debug purposes */
  51. /* LayerIDs for stack */
  52. #define BTTRC_ID_STK_GKI 1
  53. #define BTTRC_ID_STK_BTU 2
  54. #define BTTRC_ID_STK_HCI 3
  55. #define BTTRC_ID_STK_L2CAP 4
  56. #define BTTRC_ID_STK_RFCM_MX 5
  57. #define BTTRC_ID_STK_RFCM_PRT 6
  58. #define BTTRC_ID_STK_OBEX_C 7
  59. #define BTTRC_ID_STK_OBEX_S 8
  60. #define BTTRC_ID_STK_AVCT 9
  61. #define BTTRC_ID_STK_AVDT 10
  62. #define BTTRC_ID_STK_AVRC 11
  63. #define BTTRC_ID_STK_BIC 12
  64. #define BTTRC_ID_STK_BIS 13
  65. #define BTTRC_ID_STK_BNEP 14
  66. #define BTTRC_ID_STK_BPP 15
  67. #define BTTRC_ID_STK_BTM_ACL 16
  68. #define BTTRC_ID_STK_BTM_PM 17
  69. #define BTTRC_ID_STK_BTM_DEV_CTRL 18
  70. #define BTTRC_ID_STK_BTM_SVC_DSC 19
  71. #define BTTRC_ID_STK_BTM_INQ 20
  72. #define BTTRC_ID_STK_BTM_SCO 21
  73. #define BTTRC_ID_STK_BTM_SEC 22
  74. #define BTTRC_ID_STK_HID 24
  75. #define BTTRC_ID_STK_HSP2 25
  76. #define BTTRC_ID_STK_CTP 26
  77. #define BTTRC_ID_STK_FTC 27
  78. #define BTTRC_ID_STK_FTS 28
  79. #define BTTRC_ID_STK_GAP 29
  80. #define BTTRC_ID_STK_HCRP 31
  81. #define BTTRC_ID_STK_ICP 32
  82. #define BTTRC_ID_STK_OPC 33
  83. #define BTTRC_ID_STK_OPS 34
  84. #define BTTRC_ID_STK_PAN 35
  85. #define BTTRC_ID_STK_SAP 36
  86. #define BTTRC_ID_STK_SDP 37
  87. #define BTTRC_ID_STK_SLIP 38
  88. #define BTTRC_ID_STK_SPP 39
  89. #define BTTRC_ID_STK_TCS 40
  90. #define BTTRC_ID_STK_VDP 41
  91. #define BTTRC_ID_STK_MCAP 42
  92. #define BTTRC_ID_STK_GATT 43
  93. #define BTTRC_ID_STK_SMP 44
  94. #define BTTRC_ID_STK_NFC 45
  95. #define BTTRC_ID_STK_NCI 46
  96. #define BTTRC_ID_STK_IDEP 47
  97. #define BTTRC_ID_STK_NDEP 48
  98. #define BTTRC_ID_STK_LLCP 49
  99. #define BTTRC_ID_STK_RW 50
  100. #define BTTRC_ID_STK_CE 51
  101. #define BTTRC_ID_STK_SNEP 52
  102. #define BTTRC_ID_STK_NDEF 53
  103. /* LayerIDs for BTA */
  104. #define BTTRC_ID_BTA_ACC 55 /* Advanced Camera Client */
  105. #define BTTRC_ID_BTA_AG 56 /* audio gateway */
  106. #define BTTRC_ID_BTA_AV 57 /* Advanced audio */
  107. #define BTTRC_ID_BTA_BIC 58 /* Basic Imaging Client */
  108. #define BTTRC_ID_BTA_BIS 59 /* Basic Imaging Server */
  109. #define BTTRC_ID_BTA_BP 60 /* Basic Printing Client */
  110. #define BTTRC_ID_BTA_CG 61
  111. #define BTTRC_ID_BTA_CT 62 /* cordless telephony terminal */
  112. #define BTTRC_ID_BTA_DG 63 /* data gateway */
  113. #define BTTRC_ID_BTA_DM 64 /* device manager */
  114. #define BTTRC_ID_BTA_DM_SRCH 65 /* device manager search */
  115. #define BTTRC_ID_BTA_DM_SEC 66 /* device manager security */
  116. #define BTTRC_ID_BTA_FM 67
  117. #define BTTRC_ID_BTA_FTC 68 /* file transfer client */
  118. #define BTTRC_ID_BTA_FTS 69 /* file transfer server */
  119. #define BTTRC_ID_BTA_HIDH 70
  120. #define BTTRC_ID_BTA_HIDD 71
  121. #define BTTRC_ID_BTA_JV 72
  122. #define BTTRC_ID_BTA_OPC 73 /* object push client */
  123. #define BTTRC_ID_BTA_OPS 74 /* object push server */
  124. #define BTTRC_ID_BTA_PAN 75 /* Personal Area Networking */
  125. #define BTTRC_ID_BTA_PR 76 /* Printer client */
  126. #define BTTRC_ID_BTA_SC 77 /* SIM Card Access server */
  127. #define BTTRC_ID_BTA_SS 78 /* synchronization server */
  128. #define BTTRC_ID_BTA_SYS 79 /* system manager */
  129. #define BTTRC_ID_AVDT_SCB 80 /* avdt scb */
  130. #define BTTRC_ID_AVDT_CCB 81 /* avdt ccb */
  131. // btla-specific ++
  132. /* LayerIDs added for BTL-A. Probably should modify bte_logmsg.c in future. */
  133. #define BTTRC_ID_STK_RFCOMM 82
  134. #define BTTRC_ID_STK_RFCOMM_DATA 83
  135. #define BTTRC_ID_STK_OBEX 84
  136. #define BTTRC_ID_STK_A2D 85
  137. #define BTTRC_ID_STK_BIP 86
  138. /* LayerIDs for BT APP */
  139. #define BTTRC_ID_BTAPP 87
  140. #define BTTRC_ID_BT_PROTOCOL 88 /* this is a temporary solution to allow dynamic
  141. enable/disable of BT_PROTOCOL_TRACE */
  142. #define BTTRC_ID_MAX_ID BTTRC_ID_BT_PROTOCOL
  143. // btla-specific --
  144. #define BTTRC_ID_ALL_LAYERS 0xFF /* all trace layers */
  145. /* Parameter datatypes used in Trace APIs */
  146. #define BTTRC_PARAM_UINT8 1
  147. #define BTTRC_PARAM_UINT16 2
  148. #define BTTRC_PARAM_UINT32 3
  149. /* Enables or disables verbose trace information. */
  150. #ifndef BT_TRACE_VERBOSE
  151. #define BT_TRACE_VERBOSE FALSE
  152. #endif
  153. /* Enables or disables all trace messages. */
  154. #ifndef BT_USE_TRACES
  155. #define BT_USE_TRACES TRUE
  156. #endif
  157. /******************************************************************************
  158. **
  159. ** Trace Levels
  160. **
  161. ** The following values may be used for different levels:
  162. ** BT_TRACE_LEVEL_NONE 0 * No trace messages to be generated
  163. ** BT_TRACE_LEVEL_ERROR 1 * Error condition trace messages
  164. ** BT_TRACE_LEVEL_WARNING 2 * Warning condition trace messages
  165. ** BT_TRACE_LEVEL_API 3 * API traces
  166. ** BT_TRACE_LEVEL_EVENT 4 * Debug messages for events
  167. ** BT_TRACE_LEVEL_DEBUG 5 * Debug messages (general)
  168. ******************************************************************************/
  169. // btla-specific ++
  170. /* Core Stack default trace levels */
  171. #ifndef HCI_INITIAL_TRACE_LEVEL
  172. #define HCI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  173. #endif
  174. #ifndef BTM_INITIAL_TRACE_LEVEL
  175. #define BTM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  176. #endif
  177. #ifndef L2CAP_INITIAL_TRACE_LEVEL
  178. #define L2CAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  179. #endif
  180. #ifndef RFCOMM_INITIAL_TRACE_LEVEL
  181. #define RFCOMM_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  182. #endif
  183. #ifndef SDP_INITIAL_TRACE_LEVEL
  184. #define SDP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  185. #endif
  186. #ifndef GAP_INITIAL_TRACE_LEVEL
  187. #define GAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  188. #endif
  189. #ifndef BNEP_INITIAL_TRACE_LEVEL
  190. #define BNEP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  191. #endif
  192. #ifndef PAN_INITIAL_TRACE_LEVEL
  193. #define PAN_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  194. #endif
  195. #ifndef A2D_INITIAL_TRACE_LEVEL
  196. #define A2D_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  197. #endif
  198. #ifndef AVDT_INITIAL_TRACE_LEVEL
  199. #define AVDT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  200. #endif
  201. #ifndef AVCT_INITIAL_TRACE_LEVEL
  202. #define AVCT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  203. #endif
  204. #ifndef AVRC_INITIAL_TRACE_LEVEL
  205. #define AVRC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  206. #endif
  207. #ifndef MCA_INITIAL_TRACE_LEVEL
  208. #define MCA_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  209. #endif
  210. #ifndef HID_INITIAL_TRACE_LEVEL
  211. #define HID_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  212. #endif
  213. #ifndef APPL_INITIAL_TRACE_LEVEL
  214. #define APPL_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  215. #endif
  216. #ifndef BT_TRACE_APPL
  217. #define BT_TRACE_APPL BT_USE_TRACES
  218. #endif
  219. #ifndef GATT_INITIAL_TRACE_LEVEL
  220. #define GATT_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  221. #endif
  222. #ifndef SMP_INITIAL_TRACE_LEVEL
  223. #define SMP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
  224. #endif
  225. // btla-specific --
  226. /* Define common tracing for all */
  227. #define LOG_LEVEL_ERROR 1
  228. #define LOG_LEVEL_WARN 2
  229. #define LOG_LEVEL_INFO 3
  230. #define LOG_LEVEL_DEBUG 4
  231. #define LOG_LEVEL_VERBOSE 5
  232. #ifndef LOG_LEVEL
  233. #define LOG_LEVEL LOG_LEVEL_INFO
  234. #endif
  235. #define LOG_ERROR(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_ERROR) BT_PRINTF(fmt,## args);} while(0)
  236. #define LOG_WARN(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_WARN) BT_PRINTF(fmt,## args);} while(0)
  237. #define LOG_INFO(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_INFO) BT_PRINTF(fmt,## args);} while(0)
  238. #define LOG_DEBUG(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_DEBUG) BT_PRINTF(fmt,## args);} while(0)
  239. #define LOG_VERBOSE(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_VERBOSE) BT_PRINTF(fmt,## args);} while(0)
  240. /* Define tracing for the HCI unit
  241. */
  242. #define HCI_TRACE_ERROR(fmt, args...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt,## args);}
  243. #define HCI_TRACE_WARNING(fmt, args...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt,## args);}
  244. #define HCI_TRACE_EVENT(fmt, args...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt,## args);}
  245. #define HCI_TRACE_DEBUG(fmt, args...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt,## args);}
  246. /* Define tracing for BTM
  247. */
  248. #define BTM_TRACE_ERROR(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  249. #define BTM_TRACE_WARNING(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  250. #define BTM_TRACE_API(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  251. #define BTM_TRACE_EVENT(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  252. #define BTM_TRACE_DEBUG(fmt, args...) {if (btm_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  253. /* Define tracing for the L2CAP unit
  254. */
  255. #define L2CAP_TRACE_ERROR(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  256. #define L2CAP_TRACE_WARNING(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  257. #define L2CAP_TRACE_API(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  258. #define L2CAP_TRACE_EVENT(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  259. #define L2CAP_TRACE_DEBUG(fmt, args...) {if (l2cb.l2cap_trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  260. /* Define tracing for the SDP unit
  261. */
  262. #define SDP_TRACE_ERROR(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  263. #define SDP_TRACE_WARNING(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  264. #define SDP_TRACE_API(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  265. #define SDP_TRACE_EVENT(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  266. #define SDP_TRACE_DEBUG(fmt, args...) {if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  267. /* Define tracing for the RFCOMM unit
  268. */
  269. #define RFCOMM_TRACE_ERROR(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  270. #define RFCOMM_TRACE_WARNING(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  271. #define RFCOMM_TRACE_API(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  272. #define RFCOMM_TRACE_EVENT(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  273. #define RFCOMM_TRACE_DEBUG(fmt, args...) {if (rfc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  274. /* Generic Access Profile traces */
  275. #define GAP_TRACE_ERROR(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  276. #define GAP_TRACE_EVENT(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  277. #define GAP_TRACE_API(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  278. #define GAP_TRACE_WARNING(fmt, args...) {if (gap_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  279. /* define traces for HID Host */
  280. #define HIDH_TRACE_ERROR(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  281. #define HIDH_TRACE_WARNING(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  282. #define HIDH_TRACE_API(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  283. #define HIDH_TRACE_EVENT(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  284. #define HIDH_TRACE_DEBUG(fmt, args...) {if (hh_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  285. /* define traces for BNEP */
  286. #define BNEP_TRACE_ERROR(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  287. #define BNEP_TRACE_WARNING(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  288. #define BNEP_TRACE_API(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  289. #define BNEP_TRACE_EVENT(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  290. #define BNEP_TRACE_DEBUG(fmt, args...) {if (bnep_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  291. /* define traces for PAN */
  292. #define PAN_TRACE_ERROR(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  293. #define PAN_TRACE_WARNING(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  294. #define PAN_TRACE_API(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  295. #define PAN_TRACE_EVENT(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  296. #define PAN_TRACE_DEBUG(fmt, args...) {if (pan_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  297. /* Define tracing for the A2DP profile
  298. */
  299. #define A2D_TRACE_ERROR(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  300. #define A2D_TRACE_WARNING(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  301. #define A2D_TRACE_EVENT(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  302. #define A2D_TRACE_DEBUG(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  303. #define A2D_TRACE_API(fmt, args...) {if (a2d_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  304. /* AVDTP
  305. */
  306. #define AVDT_TRACE_ERROR(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  307. #define AVDT_TRACE_WARNING(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  308. #define AVDT_TRACE_EVENT(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  309. #define AVDT_TRACE_DEBUG(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  310. #define AVDT_TRACE_API(fmt, args...) {if (avdt_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  311. /* Define tracing for the AVCTP protocol
  312. */
  313. #define AVCT_TRACE_ERROR(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  314. #define AVCT_TRACE_WARNING(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  315. #define AVCT_TRACE_EVENT(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  316. #define AVCT_TRACE_DEBUG(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  317. #define AVCT_TRACE_API(fmt, args...) {if (avct_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  318. /* Define tracing for the AVRCP profile
  319. */
  320. #define AVRC_TRACE_ERROR(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  321. #define AVRC_TRACE_WARNING(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  322. #define AVRC_TRACE_EVENT(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  323. #define AVRC_TRACE_DEBUG(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  324. #define AVRC_TRACE_API(fmt, args...) {if (avrc_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  325. /* MCAP
  326. */
  327. #define MCA_TRACE_ERROR(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  328. #define MCA_TRACE_WARNING(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  329. #define MCA_TRACE_EVENT(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  330. #define MCA_TRACE_DEBUG(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  331. #define MCA_TRACE_API(fmt, args...) {if (mca_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  332. /* Define tracing for the ATT/GATT unit
  333. */
  334. #define GATT_TRACE_ERROR(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  335. #define GATT_TRACE_WARNING(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  336. #define GATT_TRACE_API(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  337. #define GATT_TRACE_EVENT(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  338. #define GATT_TRACE_DEBUG(fmt, args...) {if (gatt_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  339. /* Define tracing for the SMP unit
  340. */
  341. #define SMP_TRACE_ERROR(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  342. #define SMP_TRACE_WARNING(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  343. #define SMP_TRACE_API(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  344. #define SMP_TRACE_EVENT(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  345. #define SMP_TRACE_DEBUG(fmt, args...) {if (smp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  346. extern UINT8 btif_trace_level;
  347. // define traces for application
  348. #define BTIF_TRACE_ERROR(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  349. #define BTIF_TRACE_WARNING(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  350. #define BTIF_TRACE_API(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  351. #define BTIF_TRACE_EVENT(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  352. #define BTIF_TRACE_DEBUG(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  353. #define BTIF_TRACE_VERBOSE(fmt, args...) {if (btif_trace_level >= BT_TRACE_LEVEL_VERBOSE)BT_PRINTF(fmt, ## args);}
  354. /* define traces for application */
  355. #define APPL_TRACE_ERROR(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_ERROR) BT_PRINTF(fmt, ## args);}
  356. #define APPL_TRACE_WARNING(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_WARNING) BT_PRINTF(fmt, ## args);}
  357. #define APPL_TRACE_API(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_API) BT_PRINTF(fmt, ## args);}
  358. #define APPL_TRACE_EVENT(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_EVENT) BT_PRINTF(fmt, ## args);}
  359. #define APPL_TRACE_DEBUG(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_DEBUG) BT_PRINTF(fmt, ## args);}
  360. #define APPL_TRACE_VERBOSE(fmt, args...) {if (appl_trace_level >= BT_TRACE_LEVEL_VERBOSE) BT_PRINTF(fmt, ## args);}
  361. /* Simplified Trace Helper Macro
  362. */
  363. #define bdld(fmt, args...) \
  364. do{\
  365. if((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_DEBUG) \
  366. BT_PRINTF(fmt, ## args); \
  367. }while(0)
  368. #define bdlw(fmt, args...) \
  369. do{\
  370. if((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_DEBUG) \
  371. BT_PRINTF(fmt, ## args); \
  372. }while(0)
  373. #define bdle(fmt, args...) \
  374. do{\
  375. if((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_DEBUG) \
  376. BT_PRINTF(fmt, ## args); \
  377. }while(0)
  378. #define bdla(assert_if) \
  379. do{\
  380. if(((MY_LOG_LEVEL) >= BT_TRACE_LEVEL_ERROR) && !(assert_if)) \
  381. BT_PRINTF("%s: assert failed\n", #assert_if); \
  382. }while(0)
  383. typedef UINT8 tBTTRC_PARAM_TYPE;
  384. typedef UINT8 tBTTRC_LAYER_ID;
  385. typedef UINT8 tBTTRC_TYPE;
  386. typedef struct {
  387. tBTTRC_LAYER_ID layer_id;
  388. tBTTRC_TYPE type; /* TODO: use tBTTRC_TYPE instead of "classical level 0-5" */
  389. } tBTTRC_LEVEL;
  390. typedef UINT8 (tBTTRC_SET_TRACE_LEVEL)( UINT8 );
  391. typedef struct {
  392. const tBTTRC_LAYER_ID layer_id_start;
  393. const tBTTRC_LAYER_ID layer_id_end;
  394. tBTTRC_SET_TRACE_LEVEL *p_f;
  395. const char *trc_name;
  396. UINT8 trace_level;
  397. } tBTTRC_FUNC_MAP;
  398. /* External declaration for appl_trace_level here to avoid to add the declaration in all the files using APPL_TRACExxx macros */
  399. extern UINT8 appl_trace_level;
  400. #endif /*_BT_TRACE_H_*/